3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 9adee0d..5e9cfb2 100644
7 @@ -232,6 +232,7 @@ source "fs/pstore/Kconfig"
8 source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/exofs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 79f5225..a7c7f16 100644
19 @@ -126,3 +126,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 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index ebd10e6..32152e7 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -59,6 +59,7 @@ header-y += atmsvc.h
30 header-y += atm_zatm.h
32 +header-y += aufs_type.h
33 header-y += auto_fs4.h
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index 6ee06ea..3147250 100644
42 @@ -2082,6 +2082,19 @@ F: include/linux/audit.h
43 F: include/uapi/linux/audit.h
46 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
47 +M: "J. R. Okajima" <hooanon05g@gmail.com>
48 +L: linux-unionfs@vger.kernel.org
49 +L: aufs-users@lists.sourceforge.net (members only)
50 +W: http://aufs.sourceforge.net
51 +T: git://github.com/sfjro/aufs4-linux.git
53 +F: Documentation/filesystems/aufs/
54 +F: Documentation/ABI/testing/debugfs-aufs
55 +F: Documentation/ABI/testing/sysfs-aufs
57 +F: include/uapi/linux/aufs_type.h
59 AUXILIARY DISPLAY DRIVERS
60 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
61 W: http://miguelojeda.es/auxdisplay.htm
62 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
63 index 423f4ca..0b816b2 100644
64 --- a/drivers/block/loop.c
65 +++ b/drivers/block/loop.c
66 @@ -706,6 +706,24 @@ static inline int is_loop_device(struct file *file)
67 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
72 + * no get/put for file.
74 +struct file *loop_backing_file(struct super_block *sb)
77 + struct loop_device *l;
80 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
81 + l = sb->s_bdev->bd_disk->private_data;
82 + ret = l->lo_backing_file;
86 +EXPORT_SYMBOL_GPL(loop_backing_file);
88 /* loop sysfs attributes */
90 static ssize_t loop_attr_show(struct device *dev, char *page,
91 diff --git a/fs/dcache.c b/fs/dcache.c
92 index 2398f9f9..318c329 100644
95 @@ -1156,7 +1156,7 @@ enum d_walk_ret {
97 * The @enter() and @finish() callbacks are called with d_lock held.
99 -static void d_walk(struct dentry *parent, void *data,
100 +void d_walk(struct dentry *parent, void *data,
101 enum d_walk_ret (*enter)(void *, struct dentry *),
102 void (*finish)(void *))
104 diff --git a/fs/fcntl.c b/fs/fcntl.c
105 index 350a2c8..6f42279 100644
110 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
112 -static int setfl(int fd, struct file * filp, unsigned long arg)
113 +int setfl(int fd, struct file * filp, unsigned long arg)
115 struct inode * inode = file_inode(filp);
117 @@ -60,6 +60,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
119 if (filp->f_op->check_flags)
120 error = filp->f_op->check_flags(arg);
121 + if (!error && filp->f_op->setfl)
122 + error = filp->f_op->setfl(filp, arg);
126 diff --git a/fs/read_write.c b/fs/read_write.c
127 index dadf24e..c8b5b7a 100644
128 --- a/fs/read_write.c
129 +++ b/fs/read_write.c
130 @@ -534,6 +534,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
132 EXPORT_SYMBOL(__vfs_write);
134 +vfs_readf_t vfs_readf(struct file *file)
136 + const struct file_operations *fop = file->f_op;
140 + if (fop->read_iter)
141 + return new_sync_read;
142 + return ERR_PTR(-ENOSYS);
145 +vfs_writef_t vfs_writef(struct file *file)
147 + const struct file_operations *fop = file->f_op;
151 + if (fop->write_iter)
152 + return new_sync_write;
153 + return ERR_PTR(-ENOSYS);
156 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
159 diff --git a/fs/splice.c b/fs/splice.c
160 index 82bc0d6..93aee51 100644
163 @@ -1108,8 +1108,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
165 * Attempt to initiate a splice from pipe to file.
167 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
168 - loff_t *ppos, size_t len, unsigned int flags)
169 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
170 + loff_t *ppos, size_t len, unsigned int flags)
172 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
173 loff_t *, size_t, unsigned int);
174 @@ -1125,9 +1125,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
176 * Attempt to initiate a splice from a file to a pipe.
178 -static long do_splice_to(struct file *in, loff_t *ppos,
179 - struct pipe_inode_info *pipe, size_t len,
180 - unsigned int flags)
181 +long do_splice_to(struct file *in, loff_t *ppos,
182 + struct pipe_inode_info *pipe, size_t len,
183 + unsigned int flags)
185 ssize_t (*splice_read)(struct file *, loff_t *,
186 struct pipe_inode_info *, size_t, unsigned int);
187 diff --git a/include/linux/file.h b/include/linux/file.h
188 index f87d308..9a290b3 100644
189 --- a/include/linux/file.h
190 +++ b/include/linux/file.h
191 @@ -19,6 +19,7 @@ struct dentry;
193 extern struct file *alloc_file(struct path *, fmode_t mode,
194 const struct file_operations *fop);
195 +extern struct file *get_empty_filp(void);
197 static inline void fput_light(struct file *file, int fput_needed)
199 diff --git a/include/linux/fs.h b/include/linux/fs.h
200 index ae68100..99fc2bd 100644
201 --- a/include/linux/fs.h
202 +++ b/include/linux/fs.h
203 @@ -1260,6 +1260,7 @@ extern void fasync_free(struct fasync_struct *);
204 /* can be called from interrupts */
205 extern void kill_fasync(struct fasync_struct **, int, int);
207 +extern int setfl(int fd, struct file * filp, unsigned long arg);
208 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
209 extern void f_setown(struct file *filp, unsigned long arg, int force);
210 extern void f_delown(struct file *filp);
211 @@ -1646,6 +1647,7 @@ struct file_operations {
212 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
213 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
214 int (*check_flags)(int);
215 + int (*setfl)(struct file *, unsigned long);
216 int (*flock) (struct file *, int, struct file_lock *);
217 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
218 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
219 @@ -1704,6 +1706,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
220 struct iovec *fast_pointer,
221 struct iovec **ret_pointer);
223 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
224 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
226 +vfs_readf_t vfs_readf(struct file *file);
227 +vfs_writef_t vfs_writef(struct file *file);
229 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
230 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
231 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
232 diff --git a/include/linux/splice.h b/include/linux/splice.h
233 index da2751d..2e0fca6 100644
234 --- a/include/linux/splice.h
235 +++ b/include/linux/splice.h
236 @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
237 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
239 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
241 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
242 + loff_t *ppos, size_t len, unsigned int flags);
243 +extern long do_splice_to(struct file *in, loff_t *ppos,
244 + struct pipe_inode_info *pipe, size_t len,
245 + unsigned int flags);
249 diff --git a/fs/proc/base.c b/fs/proc/base.c
250 index 4f764c2..229de5e 100644
253 @@ -1933,7 +1933,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
254 down_read(&mm->mmap_sem);
255 vma = find_exact_vma(mm, vm_start, vm_end);
256 if (vma && vma->vm_file) {
257 - *path = vma->vm_file->f_path;
258 + *path = vma_pr_or_file(vma)->f_path;
262 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
263 index f8595e8..cb8eda0 100644
264 --- a/fs/proc/nommu.c
265 +++ b/fs/proc/nommu.c
266 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
267 file = region->vm_file;
270 - struct inode *inode = file_inode(region->vm_file);
271 + struct inode *inode;
273 + file = vmr_pr_or_file(region);
274 + inode = file_inode(file);
275 dev = inode->i_sb->s_dev;
278 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
279 index fa95ab2..d440354 100644
280 --- a/fs/proc/task_mmu.c
281 +++ b/fs/proc/task_mmu.c
282 @@ -298,7 +298,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
283 const char *name = NULL;
286 - struct inode *inode = file_inode(vma->vm_file);
287 + struct inode *inode;
289 + file = vma_pr_or_file(vma);
290 + inode = file_inode(file);
291 dev = inode->i_sb->s_dev;
293 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
294 @@ -1576,7 +1579,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
295 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
296 struct vm_area_struct *vma = v;
297 struct numa_maps *md = &numa_priv->md;
298 - struct file *file = vma->vm_file;
299 + struct file *file = vma_pr_or_file(vma);
300 struct mm_struct *mm = vma->vm_mm;
301 struct mm_walk walk = {
302 .hugetlb_entry = gather_hugetlb_stats,
303 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
304 index faacb0c..17b43be 100644
305 --- a/fs/proc/task_nommu.c
306 +++ b/fs/proc/task_nommu.c
307 @@ -163,7 +163,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
311 - struct inode *inode = file_inode(vma->vm_file);
312 + struct inode *inode;
314 + file = vma_pr_or_file(vma);
315 + inode = file_inode(file);
316 dev = inode->i_sb->s_dev;
318 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
319 diff --git a/include/linux/mm.h b/include/linux/mm.h
320 index 516e149..ddd5454 100644
321 --- a/include/linux/mm.h
322 +++ b/include/linux/mm.h
323 @@ -1217,6 +1217,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
327 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
328 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
330 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
331 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
333 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
335 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
337 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
338 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
341 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
342 +extern void vmr_do_fput(struct vm_region *, const char[], int);
344 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
346 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
347 +#endif /* !CONFIG_MMU */
349 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
350 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
351 void *buf, int len, int write);
352 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
353 index 624b78b..1be91c5 100644
354 --- a/include/linux/mm_types.h
355 +++ b/include/linux/mm_types.h
356 @@ -269,6 +269,7 @@ struct vm_region {
357 unsigned long vm_top; /* region allocated to here */
358 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
359 struct file *vm_file; /* the backing file or NULL */
360 + struct file *vm_prfile; /* the virtual backing file or NULL */
362 int vm_usage; /* region usage count (access under nommu_region_sem) */
363 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
364 @@ -343,6 +344,7 @@ struct vm_area_struct {
365 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
366 units, *not* PAGE_CACHE_SIZE */
367 struct file * vm_file; /* File we map to (can be NULL). */
368 + struct file *vm_prfile; /* shadow of vm_file */
369 void * vm_private_data; /* was vm_pte (shared mem) */
372 diff --git a/kernel/fork.c b/kernel/fork.c
373 index 2e391c7..6c4215c 100644
376 @@ -464,7 +464,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
377 struct inode *inode = file_inode(file);
378 struct address_space *mapping = file->f_mapping;
382 if (tmp->vm_flags & VM_DENYWRITE)
383 atomic_dec(&inode->i_writecount);
384 i_mmap_lock_write(mapping);
385 diff --git a/mm/Makefile b/mm/Makefile
386 index 2ed4319..e3a53f5 100644
389 @@ -21,7 +21,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
390 mm_init.o mmu_context.o percpu.o slab_common.o \
391 compaction.o vmacache.o \
392 interval_tree.o list_lru.o workingset.o \
394 + prfile.o debug.o $(mmu-y)
398 diff --git a/mm/filemap.c b/mm/filemap.c
399 index da7a35d..f800f87 100644
402 @@ -2229,7 +2229,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
403 int ret = VM_FAULT_LOCKED;
405 sb_start_pagefault(inode->i_sb);
406 - file_update_time(vma->vm_file);
407 + vma_file_update_time(vma);
409 if (page->mapping != inode->i_mapping) {
411 diff --git a/mm/memory.c b/mm/memory.c
412 index 8132787..3f7de66 100644
415 @@ -2042,7 +2042,7 @@ static inline int wp_page_reuse(struct mm_struct *mm,
419 - file_update_time(vma->vm_file);
420 + vma_file_update_time(vma);
423 return VM_FAULT_WRITE;
424 diff --git a/mm/mmap.c b/mm/mmap.c
425 index 76d1ec2..fdd163e 100644
428 @@ -290,7 +290,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
429 if (vma->vm_ops && vma->vm_ops->close)
430 vma->vm_ops->close(vma);
432 - fput(vma->vm_file);
434 mpol_put(vma_policy(vma));
435 kmem_cache_free(vm_area_cachep, vma);
437 @@ -909,7 +909,7 @@ again: remove_next = 1 + (end > next->vm_end);
440 uprobe_munmap(next, next->vm_start, next->vm_end);
445 anon_vma_merge(vma, next);
446 @@ -1683,8 +1683,8 @@ out:
454 /* Undo any partial mapping done by a device driver. */
455 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
456 @@ -2479,7 +2479,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
460 - get_file(new->vm_file);
463 if (new->vm_ops && new->vm_ops->open)
464 new->vm_ops->open(new);
465 @@ -2498,7 +2498,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
466 if (new->vm_ops && new->vm_ops->close)
467 new->vm_ops->close(new);
469 - fput(new->vm_file);
471 unlink_anon_vmas(new);
473 mpol_put(vma_policy(new));
474 @@ -2640,7 +2640,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
475 struct vm_area_struct *vma;
476 unsigned long populate = 0;
477 unsigned long ret = -EINVAL;
480 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
481 "See Documentation/vm/remap_file_pages.txt.\n",
482 @@ -2708,10 +2707,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
486 - file = get_file(vma->vm_file);
488 ret = do_mmap_pgoff(vma->vm_file, start, size,
489 prot, flags, pgoff, &populate);
493 up_write(&mm->mmap_sem);
495 @@ -2982,7 +2981,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
496 if (anon_vma_clone(new_vma, vma))
497 goto out_free_mempol;
498 if (new_vma->vm_file)
499 - get_file(new_vma->vm_file);
500 + vma_get_file(new_vma);
501 if (new_vma->vm_ops && new_vma->vm_ops->open)
502 new_vma->vm_ops->open(new_vma);
503 vma_link(mm, new_vma, prev, rb_link, rb_parent);
504 diff --git a/mm/nommu.c b/mm/nommu.c
505 index fbf6f0f1..1a4a06d 100644
508 @@ -671,7 +671,7 @@ static void __put_nommu_region(struct vm_region *region)
509 up_write(&nommu_region_sem);
512 - fput(region->vm_file);
515 /* IO memory and memory shared directly out of the pagecache
516 * from ramfs/tmpfs mustn't be released here */
517 @@ -829,7 +829,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
518 if (vma->vm_ops && vma->vm_ops->close)
519 vma->vm_ops->close(vma);
521 - fput(vma->vm_file);
523 put_nommu_region(vma->vm_region);
524 kmem_cache_free(vm_area_cachep, vma);
526 @@ -1355,7 +1355,7 @@ unsigned long do_mmap(struct file *file,
527 goto error_just_free;
530 - fput(region->vm_file);
532 kmem_cache_free(vm_region_jar, region);
535 @@ -1430,10 +1430,10 @@ error_just_free:
536 up_write(&nommu_region_sem);
539 - fput(region->vm_file);
541 kmem_cache_free(vm_region_jar, region);
543 - fput(vma->vm_file);
545 kmem_cache_free(vm_area_cachep, vma);
548 diff --git a/mm/prfile.c b/mm/prfile.c
550 index 0000000..b323b8a
555 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
556 + * in /proc/PID/maps.
557 + * Call these functions via macros defined in linux/mm.h.
559 + * See Documentation/filesystems/aufs/design/06mmap.txt
561 + * Copyright (c) 2014 Junjro R. Okajima
562 + * Copyright (c) 2014 Ian Campbell
565 +#include <linux/mm.h>
566 +#include <linux/file.h>
567 +#include <linux/fs.h>
569 +/* #define PRFILE_TRACE */
570 +static inline void prfile_trace(struct file *f, struct file *pr,
571 + const char func[], int line, const char func2[])
575 + pr_info("%s:%d: %s, %s\n", func, line, func2,
576 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
580 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
583 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
585 + prfile_trace(f, pr, func, line, __func__);
586 + file_update_time(f);
588 + file_update_time(pr);
591 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
594 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
596 + prfile_trace(f, pr, func, line, __func__);
597 + return (f && pr) ? pr : f;
600 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
602 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
604 + prfile_trace(f, pr, func, line, __func__);
610 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
612 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
614 + prfile_trace(f, pr, func, line, __func__);
621 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
624 + struct file *f = region->vm_file, *pr = region->vm_prfile;
626 + prfile_trace(f, pr, func, line, __func__);
627 + return (f && pr) ? pr : f;
630 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
632 + struct file *f = region->vm_file, *pr = region->vm_prfile;
634 + prfile_trace(f, pr, func, line, __func__);
639 +#endif /* !CONFIG_MMU */
640 aufs4.5 standalone patch
642 diff --git a/fs/dcache.c b/fs/dcache.c
643 index 318c329..72d3cc8 100644
646 @@ -1261,6 +1261,7 @@ rename_retry:
650 +EXPORT_SYMBOL_GPL(d_walk);
653 * Search for at least 1 mount point in the dentry's subdirs.
654 diff --git a/fs/exec.c b/fs/exec.c
655 index dcd4ac7..09a7818 100644
658 @@ -103,6 +103,7 @@ bool path_noexec(const struct path *path)
659 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
660 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
662 +EXPORT_SYMBOL_GPL(path_noexec);
666 diff --git a/fs/fcntl.c b/fs/fcntl.c
667 index 6f42279..04fd33c 100644
670 @@ -82,6 +82,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
674 +EXPORT_SYMBOL_GPL(setfl);
676 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
678 diff --git a/fs/file_table.c b/fs/file_table.c
679 index ad17e05..ae9f267 100644
680 --- a/fs/file_table.c
681 +++ b/fs/file_table.c
682 @@ -147,6 +147,7 @@ over:
684 return ERR_PTR(-ENFILE);
686 +EXPORT_SYMBOL_GPL(get_empty_filp);
689 * alloc_file - allocate and initialize a 'struct file'
690 @@ -258,6 +259,7 @@ void flush_delayed_fput(void)
694 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
696 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
698 @@ -300,6 +302,7 @@ void __fput_sync(struct file *file)
702 +EXPORT_SYMBOL_GPL(__fput_sync);
704 void put_filp(struct file *file)
706 @@ -308,6 +311,7 @@ void put_filp(struct file *file)
710 +EXPORT_SYMBOL_GPL(put_filp);
712 void __init files_init(void)
714 diff --git a/fs/namespace.c b/fs/namespace.c
715 index 4fb1691..97654d2 100644
718 @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
719 mnt_dec_writers(real_mount(mnt));
722 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
725 * mnt_drop_write - give up write access to a mount
726 @@ -1811,6 +1812,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
730 +EXPORT_SYMBOL_GPL(iterate_mounts);
732 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
734 diff --git a/fs/notify/group.c b/fs/notify/group.c
735 index d16b62c..53e45b6 100644
736 --- a/fs/notify/group.c
737 +++ b/fs/notify/group.c
739 #include <linux/srcu.h>
740 #include <linux/rculist.h>
741 #include <linux/wait.h>
742 +#include <linux/module.h>
744 #include <linux/fsnotify_backend.h>
745 #include "fsnotify.h"
746 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
748 atomic_inc(&group->refcnt);
750 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
753 * Drop a reference to a group. Free it if it's through.
754 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
755 if (atomic_dec_and_test(&group->refcnt))
756 fsnotify_final_destroy_group(group);
758 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
761 * Create a new fsnotify_group and hold a reference for the group returned.
762 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
766 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
768 int fsnotify_fasync(int fd, struct file *file, int on)
770 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
771 index 7115c5d..ac2bd69 100644
772 --- a/fs/notify/mark.c
773 +++ b/fs/notify/mark.c
774 @@ -113,6 +113,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
775 mark->free_mark(mark);
778 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
780 /* Calculate mask of events for a list of marks */
781 u32 fsnotify_recalc_mask(struct hlist_head *head)
782 @@ -213,6 +214,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
783 mutex_unlock(&group->mark_mutex);
784 fsnotify_free_mark(mark);
786 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
788 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
790 @@ -398,6 +400,7 @@ err:
794 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
796 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
797 struct inode *inode, struct vfsmount *mnt, int allow_dups)
798 @@ -498,6 +501,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
799 atomic_set(&mark->refcnt, 1);
800 mark->free_mark = free_mark;
802 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
804 static void fsnotify_mark_destroy(struct work_struct *work)
806 diff --git a/fs/open.c b/fs/open.c
807 index 55bdc75..fd1df73 100644
810 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
811 inode_unlock(dentry->d_inode);
814 +EXPORT_SYMBOL_GPL(do_truncate);
816 long vfs_truncate(struct path *path, loff_t length)
818 @@ -678,6 +679,7 @@ int open_check_o_direct(struct file *f)
822 +EXPORT_SYMBOL_GPL(open_check_o_direct);
824 static int do_dentry_open(struct file *f,
826 diff --git a/fs/read_write.c b/fs/read_write.c
827 index c8b5b7a..9461d12 100644
828 --- a/fs/read_write.c
829 +++ b/fs/read_write.c
830 @@ -544,6 +544,7 @@ vfs_readf_t vfs_readf(struct file *file)
831 return new_sync_read;
832 return ERR_PTR(-ENOSYS);
834 +EXPORT_SYMBOL_GPL(vfs_readf);
836 vfs_writef_t vfs_writef(struct file *file)
838 @@ -555,6 +556,7 @@ vfs_writef_t vfs_writef(struct file *file)
839 return new_sync_write;
840 return ERR_PTR(-ENOSYS);
842 +EXPORT_SYMBOL_GPL(vfs_writef);
844 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
846 diff --git a/fs/splice.c b/fs/splice.c
847 index 93aee51..52d2f5b 100644
850 @@ -1121,6 +1121,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
852 return splice_write(pipe, out, ppos, len, flags);
854 +EXPORT_SYMBOL_GPL(do_splice_from);
857 * Attempt to initiate a splice from a file to a pipe.
858 @@ -1147,6 +1148,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
860 return splice_read(in, ppos, pipe, len, flags);
862 +EXPORT_SYMBOL_GPL(do_splice_to);
865 * splice_direct_to_actor - splices data directly between two non-pipes
866 diff --git a/fs/xattr.c b/fs/xattr.c
867 index 4861322..c4bb039 100644
870 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
871 *xattr_value = value;
874 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
877 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
878 diff --git a/kernel/task_work.c b/kernel/task_work.c
879 index 53fa971..bce3211 100644
880 --- a/kernel/task_work.c
881 +++ b/kernel/task_work.c
882 @@ -118,3 +118,4 @@ void task_work_run(void)
886 +EXPORT_SYMBOL_GPL(task_work_run);
887 diff --git a/security/commoncap.c b/security/commoncap.c
888 index 48071ed..50a1a40 100644
889 --- a/security/commoncap.c
890 +++ b/security/commoncap.c
891 @@ -1058,12 +1058,14 @@ int cap_mmap_addr(unsigned long addr)
895 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
897 int cap_mmap_file(struct file *file, unsigned long reqprot,
898 unsigned long prot, unsigned long flags)
902 +EXPORT_SYMBOL_GPL(cap_mmap_file);
904 #ifdef CONFIG_SECURITY
906 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
907 index 03c1652..f88c84b 100644
908 --- a/security/device_cgroup.c
909 +++ b/security/device_cgroup.c
911 #include <linux/device_cgroup.h>
912 #include <linux/cgroup.h>
913 #include <linux/ctype.h>
914 +#include <linux/export.h>
915 #include <linux/list.h>
916 #include <linux/uaccess.h>
917 #include <linux/seq_file.h>
918 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
919 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
922 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
924 int devcgroup_inode_mknod(int mode, dev_t dev)
926 diff --git a/security/security.c b/security/security.c
927 index e8ffd92..51fa026 100644
928 --- a/security/security.c
929 +++ b/security/security.c
930 @@ -433,6 +433,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
932 return call_int_hook(path_rmdir, 0, dir, dentry);
934 +EXPORT_SYMBOL_GPL(security_path_rmdir);
936 int security_path_unlink(struct path *dir, struct dentry *dentry)
938 @@ -449,6 +450,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
940 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
942 +EXPORT_SYMBOL_GPL(security_path_symlink);
944 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
945 struct dentry *new_dentry)
946 @@ -457,6 +459,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
948 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
950 +EXPORT_SYMBOL_GPL(security_path_link);
952 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
953 struct path *new_dir, struct dentry *new_dentry,
954 @@ -484,6 +487,7 @@ int security_path_truncate(struct path *path)
956 return call_int_hook(path_truncate, 0, path);
958 +EXPORT_SYMBOL_GPL(security_path_truncate);
960 int security_path_chmod(struct path *path, umode_t mode)
962 @@ -491,6 +495,7 @@ int security_path_chmod(struct path *path, umode_t mode)
964 return call_int_hook(path_chmod, 0, path, mode);
966 +EXPORT_SYMBOL_GPL(security_path_chmod);
968 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
970 @@ -498,6 +503,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
972 return call_int_hook(path_chown, 0, path, uid, gid);
974 +EXPORT_SYMBOL_GPL(security_path_chown);
976 int security_path_chroot(struct path *path)
978 @@ -583,6 +589,7 @@ int security_inode_readlink(struct dentry *dentry)
980 return call_int_hook(inode_readlink, 0, dentry);
982 +EXPORT_SYMBOL_GPL(security_inode_readlink);
984 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
986 @@ -598,6 +605,7 @@ int security_inode_permission(struct inode *inode, int mask)
988 return call_int_hook(inode_permission, 0, inode, mask);
990 +EXPORT_SYMBOL_GPL(security_inode_permission);
992 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
994 @@ -736,6 +744,7 @@ int security_file_permission(struct file *file, int mask)
996 return fsnotify_perm(file, mask);
998 +EXPORT_SYMBOL_GPL(security_file_permission);
1000 int security_file_alloc(struct file *file)
1002 @@ -795,6 +804,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1004 return ima_file_mmap(file, prot);
1006 +EXPORT_SYMBOL_GPL(security_mmap_file);
1008 int security_mmap_addr(unsigned long addr)
1010 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1011 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1012 +++ linux/Documentation/ABI/testing/debugfs-aufs 2016-04-24 18:32:51.390353525 +0200
1014 +What: /debug/aufs/si_<id>/
1016 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1018 + Under /debug/aufs, a directory named si_<id> is created
1019 + per aufs mount, where <id> is a unique id generated
1022 +What: /debug/aufs/si_<id>/plink
1024 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1026 + It has three lines and shows the information about the
1027 + pseudo-link. The first line is a single number
1028 + representing a number of buckets. The second line is a
1029 + number of pseudo-links per buckets (separated by a
1030 + blank). The last line is a single number representing a
1031 + total number of psedo-links.
1032 + When the aufs mount option 'noplink' is specified, it
1033 + will show "1\n0\n0\n".
1035 +What: /debug/aufs/si_<id>/xib
1037 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1039 + It shows the consumed blocks by xib (External Inode Number
1040 + Bitmap), its block size and file size.
1041 + When the aufs mount option 'noxino' is specified, it
1042 + will be empty. About XINO files, see the aufs manual.
1044 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1046 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1048 + It shows the consumed blocks by xino (External Inode Number
1049 + Translation Table), its link count, block size and file
1051 + When the aufs mount option 'noxino' is specified, it
1052 + will be empty. About XINO files, see the aufs manual.
1054 +What: /debug/aufs/si_<id>/xigen
1056 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1058 + It shows the consumed blocks by xigen (External Inode
1059 + Generation Table), its block size and file size.
1060 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1062 + When the aufs mount option 'noxino' is specified, it
1063 + will be empty. About XINO files, see the aufs manual.
1064 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1065 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1066 +++ linux/Documentation/ABI/testing/sysfs-aufs 2016-04-24 18:32:51.390353525 +0200
1068 +What: /sys/fs/aufs/si_<id>/
1070 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1072 + Under /sys/fs/aufs, a directory named si_<id> is created
1073 + per aufs mount, where <id> is a unique id generated
1076 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1078 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1080 + It shows the abolute path of a member directory (which
1081 + is called branch) in aufs, and its permission.
1083 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1085 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1087 + It shows the id of a member directory (which is called
1090 +What: /sys/fs/aufs/si_<id>/xi_path
1092 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1094 + It shows the abolute path of XINO (External Inode Number
1095 + Bitmap, Translation Table and Generation Table) file
1096 + even if it is the default path.
1097 + When the aufs mount option 'noxino' is specified, it
1098 + will be empty. About XINO files, see the aufs manual.
1099 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1100 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1101 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2016-04-24 18:32:51.390353525 +0200
1104 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1106 +# This program is free software; you can redistribute it and/or modify
1107 +# it under the terms of the GNU General Public License as published by
1108 +# the Free Software Foundation; either version 2 of the License, or
1109 +# (at your option) any later version.
1111 +# This program is distributed in the hope that it will be useful,
1112 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1113 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1114 +# GNU General Public License for more details.
1116 +# You should have received a copy of the GNU General Public License
1117 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1120 +----------------------------------------
1122 +aufs [ei ju: ef es] | [a u f s]
1123 +1. abbrev. for "advanced multi-layered unification filesystem".
1124 +2. abbrev. for "another unionfs".
1125 +3. abbrev. for "auf das" in German which means "on the" in English.
1126 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1127 + But "Filesystem aufs Filesystem" is hard to understand.
1129 +AUFS is a filesystem with features:
1130 +- multi layered stackable unification filesystem, the member directory
1131 + is called as a branch.
1132 +- branch permission and attribute, 'readonly', 'real-readonly',
1133 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1135 +- internal "file copy-on-write".
1136 +- logical deletion, whiteout.
1137 +- dynamic branch manipulation, adding, deleting and changing permission.
1138 +- allow bypassing aufs, user's direct branch access.
1139 +- external inode number translation table and bitmap which maintains the
1140 + persistent aufs inode number.
1141 +- seekable directory, including NFS readdir.
1142 +- file mapping, mmap and sharing pages.
1143 +- pseudo-link, hardlink over branches.
1144 +- loopback mounted filesystem as a branch.
1145 +- several policies to select one among multiple writable branches.
1146 +- revert a single systemcall when an error occurs in aufs.
1150 +Multi Layered Stackable Unification Filesystem
1151 +----------------------------------------------------------------------
1152 +Most people already knows what it is.
1153 +It is a filesystem which unifies several directories and provides a
1154 +merged single directory. When users access a file, the access will be
1155 +passed/re-directed/converted (sorry, I am not sure which English word is
1156 +correct) to the real file on the member filesystem. The member
1157 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1158 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1159 +readonly branch is handled by creating 'whiteout' on the upper writable
1162 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1163 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1164 +different approaches to implement the merged-view.
1165 +The former tries putting it into VFS, and the latter implements as a
1166 +separate filesystem.
1167 +(If I misunderstand about these implementations, please let me know and
1168 +I shall correct it. Because it is a long time ago when I read their
1169 +source files last time).
1171 +UnionMount's approach will be able to small, but may be hard to share
1172 +branches between several UnionMount since the whiteout in it is
1173 +implemented in the inode on branch filesystem and always
1174 +shared. According to Bharata's post, readdir does not seems to be
1176 +There are several missing features known in this implementations such as
1177 +- for users, the inode number may change silently. eg. copy-up.
1178 +- link(2) may break by copy-up.
1179 +- read(2) may get an obsoleted filedata (fstat(2) too).
1180 +- fcntl(F_SETLK) may be broken by copy-up.
1181 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1184 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1185 +merged into mainline. This is another implementation of UnionMount as a
1186 +separated filesystem. All the limitations and known problems which
1187 +UnionMount are equally inherited to "overlay" filesystem.
1189 +Unionfs has a longer history. When I started implementing a stackable
1190 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1191 +inode, dentry and file objects and they have an array pointing lower
1192 +same kind objects. After contributing many patches for Unionfs, I
1193 +re-started my project AUFS (Jun 2006).
1195 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1196 +implemented my own ideas, approaches and enhancements and it became
1197 +totally different one.
1199 +Comparing DM snapshot and fs based implementation
1200 +- the number of bytes to be copied between devices is much smaller.
1201 +- the type of filesystem must be one and only.
1202 +- the fs must be writable, no readonly fs, even for the lower original
1203 + device. so the compression fs will not be usable. but if we use
1204 + loopback mount, we may address this issue.
1206 + mount /cdrom/squashfs.img /sq
1207 + losetup /sq/ext2.img
1208 + losetup /somewhere/cow
1209 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1210 +- it will be difficult (or needs more operations) to extract the
1211 + difference between the original device and COW.
1212 +- DM snapshot-merge may help a lot when users try merging. in the
1213 + fs-layer union, users will use rsync(1).
1215 +You may want to read my old paper "Filesystems in LiveCD"
1216 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1219 +Several characters/aspects/persona of aufs
1220 +----------------------------------------------------------------------
1222 +Aufs has several characters, aspects or persona.
1223 +1. a filesystem, callee of VFS helper
1224 +2. sub-VFS, caller of VFS helper for branches
1225 +3. a virtual filesystem which maintains persistent inode number
1226 +4. reader/writer of files on branches such like an application
1228 +1. Callee of VFS Helper
1229 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1230 +unlink(2) from an application reaches sys_unlink() kernel function and
1231 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1232 +calls filesystem specific unlink operation. Actually aufs implements the
1233 +unlink operation but it behaves like a redirector.
1235 +2. Caller of VFS Helper for Branches
1236 +aufs_unlink() passes the unlink request to the branch filesystem as if
1237 +it were called from VFS. So the called unlink operation of the branch
1238 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1239 +every necessary pre/post operation for the branch filesystem.
1240 +- acquire the lock for the parent dir on a branch
1241 +- lookup in a branch
1242 +- revalidate dentry on a branch
1243 +- mnt_want_write() for a branch
1244 +- vfs_unlink() for a branch
1245 +- mnt_drop_write() for a branch
1246 +- release the lock on a branch
1248 +3. Persistent Inode Number
1249 +One of the most important issue for a filesystem is to maintain inode
1250 +numbers. This is particularly important to support exporting a
1251 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1252 +backend block device for its own. But some storage is necessary to
1253 +keep and maintain the inode numbers. It may be a large space and may not
1254 +suit to keep in memory. Aufs rents some space from its first writable
1255 +branch filesystem (by default) and creates file(s) on it. These files
1256 +are created by aufs internally and removed soon (currently) keeping
1258 +Note: Because these files are removed, they are totally gone after
1259 + unmounting aufs. It means the inode numbers are not persistent
1260 + across unmount or reboot. I have a plan to make them really
1261 + persistent which will be important for aufs on NFS server.
1263 +4. Read/Write Files Internally (copy-on-write)
1264 +Because a branch can be readonly, when you write a file on it, aufs will
1265 +"copy-up" it to the upper writable branch internally. And then write the
1266 +originally requested thing to the file. Generally kernel doesn't
1267 +open/read/write file actively. In aufs, even a single write may cause a
1268 +internal "file copy". This behaviour is very similar to cp(1) command.
1270 +Some people may think it is better to pass such work to user space
1271 +helper, instead of doing in kernel space. Actually I am still thinking
1272 +about it. But currently I have implemented it in kernel space.
1273 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1274 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1275 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2016-04-24 18:32:51.390353525 +0200
1278 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1280 +# This program is free software; you can redistribute it and/or modify
1281 +# it under the terms of the GNU General Public License as published by
1282 +# the Free Software Foundation; either version 2 of the License, or
1283 +# (at your option) any later version.
1285 +# This program is distributed in the hope that it will be useful,
1286 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1287 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1288 +# GNU General Public License for more details.
1290 +# You should have received a copy of the GNU General Public License
1291 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1293 +Basic Aufs Internal Structure
1295 +Superblock/Inode/Dentry/File Objects
1296 +----------------------------------------------------------------------
1297 +As like an ordinary filesystem, aufs has its own
1298 +superblock/inode/dentry/file objects. All these objects have a
1299 +dynamically allocated array and store the same kind of pointers to the
1300 +lower filesystem, branch.
1301 +For example, when you build a union with one readwrite branch and one
1302 +readonly, mounted /au, /rw and /ro respectively.
1304 +- /ro/fileA exists but /rw/fileA
1306 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1307 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1308 +- [0] = NULL (because /rw/fileA doesn't exist)
1311 +This style of an array is essentially same to the aufs
1312 +superblock/inode/dentry/file objects.
1314 +Because aufs supports manipulating branches, ie. add/delete/change
1315 +branches dynamically, these objects has its own generation. When
1316 +branches are changed, the generation in aufs superblock is
1317 +incremented. And a generation in other object are compared when it is
1318 +accessed. When a generation in other objects are obsoleted, aufs
1319 +refreshes the internal array.
1323 +----------------------------------------------------------------------
1324 +Additionally aufs superblock has some data for policies to select one
1325 +among multiple writable branches, XIB files, pseudo-links and kobject.
1326 +See below in detail.
1327 +About the policies which supports copy-down a directory, see
1328 +wbr_policy.txt too.
1331 +Branch and XINO(External Inode Number Translation Table)
1332 +----------------------------------------------------------------------
1333 +Every branch has its own xino (external inode number translation table)
1334 +file. The xino file is created and unlinked by aufs internally. When two
1335 +members of a union exist on the same filesystem, they share the single
1337 +The struct of a xino file is simple, just a sequence of aufs inode
1338 +numbers which is indexed by the lower inode number.
1339 +In the above sample, assume the inode number of /ro/fileA is i111 and
1340 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1341 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1343 +When the inode numbers are not contiguous, the xino file will be sparse
1344 +which has a hole in it and doesn't consume as much disk space as it
1345 +might appear. If your branch filesystem consumes disk space for such
1346 +holes, then you should specify 'xino=' option at mounting aufs.
1348 +Aufs has a mount option to free the disk blocks for such holes in XINO
1349 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1350 +meet a problem of disk shortage due to XINO files, then you should try
1351 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1352 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1353 +the holes in XINO files.
1355 +Also a writable branch has three kinds of "whiteout bases". All these
1356 +are existed when the branch is joined to aufs, and their names are
1357 +whiteout-ed doubly, so that users will never see their names in aufs
1359 +1. a regular file which will be hardlinked to all whiteouts.
1360 +2. a directory to store a pseudo-link.
1361 +3. a directory to store an "orphan"-ed file temporary.
1364 + When you remove a file on a readonly branch, aufs handles it as a
1365 + logical deletion and creates a whiteout on the upper writable branch
1366 + as a hardlink of this file in order not to consume inode on the
1369 + See below, Pseudo-link.
1371 + When "fileC" exists on the lower readonly branch only and it is
1372 + opened and removed with its parent dir, and then user writes
1373 + something into it, then aufs copies-up fileC to this
1374 + directory. Because there is no other dir to store fileC. After
1375 + creating a file under this dir, the file is unlinked.
1377 +Because aufs supports manipulating branches, ie. add/delete/change
1378 +dynamically, a branch has its own id. When the branch order changes,
1379 +aufs finds the new index by searching the branch id.
1383 +----------------------------------------------------------------------
1384 +Assume "fileA" exists on the lower readonly branch only and it is
1385 +hardlinked to "fileB" on the branch. When you write something to fileA,
1386 +aufs copies-up it to the upper writable branch. Additionally aufs
1387 +creates a hardlink under the Pseudo-link Directory of the writable
1388 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1389 +simple list. If fileB is read after unlinking fileA, aufs returns
1390 +filedata from the pseudo-link instead of the lower readonly
1391 +branch. Because the pseudo-link is based upon the inode, to keep the
1392 +inode number by xino (see above) is essentially necessary.
1394 +All the hardlinks under the Pseudo-link Directory of the writable branch
1395 +should be restored in a proper location later. Aufs provides a utility
1396 +to do this. The userspace helpers executed at remounting and unmounting
1398 +During this utility is running, it puts aufs into the pseudo-link
1399 +maintenance mode. In this mode, only the process which began the
1400 +maintenance mode (and its child processes) is allowed to operate in
1401 +aufs. Some other processes which are not related to the pseudo-link will
1402 +be allowed to run too, but the rest have to return an error or wait
1403 +until the maintenance mode ends. If a process already acquires an inode
1404 +mutex (in VFS), it has to return an error.
1407 +XIB(external inode number bitmap)
1408 +----------------------------------------------------------------------
1409 +Addition to the xino file per a branch, aufs has an external inode number
1410 +bitmap in a superblock object. It is also an internal file such like a
1412 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1414 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1416 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1417 +reduce the number of consumed disk blocks for these files.
1420 +Virtual or Vertical Dir, and Readdir in Userspace
1421 +----------------------------------------------------------------------
1422 +In order to support multiple layers (branches), aufs readdir operation
1423 +constructs a virtual dir block on memory. For readdir, aufs calls
1424 +vfs_readdir() internally for each dir on branches, merges their entries
1425 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1426 +object. So the file object has its entry list until it is closed. The
1427 +entry list will be updated when the file position is zero and becomes
1428 +obsoleted. This decision is made in aufs automatically.
1430 +The dynamically allocated memory block for the name of entries has a
1431 +unit of 512 bytes (by default) and stores the names contiguously (no
1432 +padding). Another block for each entry is handled by kmem_cache too.
1433 +During building dir blocks, aufs creates hash list and judging whether
1434 +the entry is whiteouted by its upper branch or already listed.
1435 +The merged result is cached in the corresponding inode object and
1436 +maintained by a customizable life-time option.
1438 +Some people may call it can be a security hole or invite DoS attack
1439 +since the opened and once readdir-ed dir (file object) holds its entry
1440 +list and becomes a pressure for system memory. But I'd say it is similar
1441 +to files under /proc or /sys. The virtual files in them also holds a
1442 +memory page (generally) while they are opened. When an idea to reduce
1443 +memory for them is introduced, it will be applied to aufs too.
1444 +For those who really hate this situation, I've developed readdir(3)
1445 +library which operates this merging in userspace. You just need to set
1446 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1447 +kernel space for readdir(3).
1451 +----------------------------------------------------------------------
1452 +Aufs sometimes requires privilege access to a branch. For instance,
1453 +in copy-up/down operation. When a user process is going to make changes
1454 +to a file which exists in the lower readonly branch only, and the mode
1455 +of one of ancestor directories may not be writable by a user
1456 +process. Here aufs copy-up the file with its ancestors and they may
1457 +require privilege to set its owner/group/mode/etc.
1458 +This is a typical case of a application character of aufs (see
1461 +Aufs uses workqueue synchronously for this case. It creates its own
1462 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1463 +passes the request to call mkdir or write (for example), and wait for
1464 +its completion. This approach solves a problem of a signal handler
1466 +If aufs didn't adopt the workqueue and changed the privilege of the
1467 +process, then the process may receive the unexpected SIGXFSZ or other
1470 +Also aufs uses the system global workqueue ("events" kernel thread) too
1471 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1472 +whiteout base and etc. This is unrelated to a privilege.
1473 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1474 +superblock at the beginning, at the same time waits for the completion
1475 +of all queued asynchronous tasks.
1479 +----------------------------------------------------------------------
1480 +The whiteout in aufs is very similar to Unionfs's. That is represented
1481 +by its filename. UnionMount takes an approach of a file mode, but I am
1482 +afraid several utilities (find(1) or something) will have to support it.
1484 +Basically the whiteout represents "logical deletion" which stops aufs to
1485 +lookup further, but also it represents "dir is opaque" which also stop
1488 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1489 +In order to make several functions in a single systemcall to be
1490 +revertible, aufs adopts an approach to rename a directory to a temporary
1491 +unique whiteouted name.
1492 +For example, in rename(2) dir where the target dir already existed, aufs
1493 +renames the target dir to a temporary unique whiteouted name before the
1494 +actual rename on a branch, and then handles other actions (make it opaque,
1495 +update the attributes, etc). If an error happens in these actions, aufs
1496 +simply renames the whiteouted name back and returns an error. If all are
1497 +succeeded, aufs registers a function to remove the whiteouted unique
1498 +temporary name completely and asynchronously to the system global
1503 +----------------------------------------------------------------------
1504 +It is a well-known feature or concept.
1505 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1506 +internally and makes change to the new file on the upper writable branch.
1507 +When the trigger systemcall does not update the timestamps of the parent
1508 +dir, aufs reverts it after copy-up.
1511 +Move-down (aufs3.9 and later)
1512 +----------------------------------------------------------------------
1513 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1514 +the lower readonly branch to the upper writable branch when a user
1515 +changes something about the file.
1516 +"Move-down" is an opposite action of copy-up. Basically this action is
1517 +ran manually instead of automatically and internally.
1518 +For desgin and implementation, aufs has to consider these issues.
1519 +- whiteout for the file may exist on the lower branch.
1520 +- ancestor directories may not exist on the lower branch.
1521 +- diropq for the ancestor directories may exist on the upper branch.
1522 +- free space on the lower branch will reduce.
1523 +- another access to the file may happen during moving-down, including
1524 + UDBA (see "Revalidate Dentry and UDBA").
1525 +- the file should not be hard-linked nor pseudo-linked. they should be
1526 + handled by auplink utility later.
1528 +Sometimes users want to move-down a file from the upper writable branch
1529 +to the lower readonly or writable branch. For instance,
1530 +- the free space of the upper writable branch is going to run out.
1531 +- create a new intermediate branch between the upper and lower branch.
1534 +For this purpose, use "aumvdown" command in aufs-util.git.
1535 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1536 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1537 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2016-04-24 18:32:51.390353525 +0200
1540 +# Copyright (C) 2015-2016 Junjiro R. Okajima
1542 +# This program is free software; you can redistribute it and/or modify
1543 +# it under the terms of the GNU General Public License as published by
1544 +# the Free Software Foundation; either version 2 of the License, or
1545 +# (at your option) any later version.
1547 +# This program is distributed in the hope that it will be useful,
1548 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1549 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1550 +# GNU General Public License for more details.
1552 +# You should have received a copy of the GNU General Public License
1553 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1555 +Support for a branch who has its ->atomic_open()
1556 +----------------------------------------------------------------------
1557 +The filesystems who implement its ->atomic_open() are not majority. For
1558 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1559 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1560 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1561 +sure whether all filesystems who have ->atomic_open() behave like this,
1562 +but NFSv4 surely returns the error.
1564 +In order to support ->atomic_open() for aufs, there are a few
1567 +A. Introduce aufs_atomic_open()
1568 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1570 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1571 + an aufs user Pip Cet's approach
1572 + - calls aufs_create(), VFS finish_open() and notify_change().
1573 + - pass fake-mode to finish_open(), and then correct the mode by
1575 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1576 + - no aufs_atomic_open().
1577 + - aufs_lookup() registers the TID to an aufs internal object.
1578 + - aufs_create() does nothing when the matching TID is registered, but
1579 + registers the mode.
1580 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1581 + TID is registered.
1582 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1584 + - no aufs_atomic_open().
1585 + - aufs_create() registers the TID to an internal object. this info
1586 + represents "this process created this file just now."
1587 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1588 + registered TID and re-try open() with superuser's credential.
1590 +Pros and cons for each approach.
1593 + - straightforward but highly depends upon VFS internal.
1594 + - the atomic behavaiour is kept.
1595 + - some of parameters such as nameidata are hard to reproduce for
1599 + - easy to implement.
1600 + - the atomic behavaiour is lost.
1602 + - the atomic behavaiour is kept.
1603 + - dirty and tricky.
1604 + - VFS checks whether the file is created correctly after calling
1605 + ->create(), which means this approach doesn't work.
1607 + - easy to implement.
1608 + - the atomic behavaiour is lost.
1609 + - to open a file with superuser's credential and give it to a user
1610 + process is a bad idea, since the file object keeps the credential
1611 + in it. It may affect LSM or something. This approach doesn't work
1614 +The approach A is ideal, but it hard to implement. So here is a
1615 +variation of A, which is to be implemented.
1617 +A-1. Introduce aufs_atomic_open()
1618 + - calls branch fs ->atomic_open() if exists. otherwise calls
1619 + vfs_create() and finish_open().
1620 + - the demerit is that the several checks after branch fs
1621 + ->atomic_open() are lost. in the ordinary case, the checks are
1622 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1623 + be implemented in aufs, but not all I am afraid.
1624 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1625 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1626 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2016-04-24 18:32:51.390353525 +0200
1629 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1631 +# This program is free software; you can redistribute it and/or modify
1632 +# it under the terms of the GNU General Public License as published by
1633 +# the Free Software Foundation; either version 2 of the License, or
1634 +# (at your option) any later version.
1636 +# This program is distributed in the hope that it will be useful,
1637 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1638 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1639 +# GNU General Public License for more details.
1641 +# You should have received a copy of the GNU General Public License
1642 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1645 +----------------------------------------------------------------------
1646 +Since aufs has a character of sub-VFS (see Introduction), it operates
1647 +lookup for branches as VFS does. It may be a heavy work. But almost all
1648 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1649 +directly connected to its parent. Digging down the directory hierarchy
1650 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1653 +When a branch is a remote filesystem, aufs basically relies upon its
1654 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1656 +For d_revalidate, aufs implements three levels of revalidate tests. See
1657 +"Revalidate Dentry and UDBA" in detail.
1660 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1661 +----------------------------------------------------------------------
1662 +Let's try case study.
1663 +- aufs has two branches, upper readwrite and lower readonly.
1665 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1666 +- user invoked "chmod a+rx /au/dirA"
1667 +- the internal copy-up is activated and "/rw/dirA" is created and its
1668 + permission bits are set to world readable.
1669 +- then "/au/dirA" becomes world readable?
1671 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1672 +or it may be a natively readonly filesystem. If aufs respects the lower
1673 +branch, it should not respond readdir request from other users. But user
1674 +allowed it by chmod. Should really aufs rejects showing the entries
1677 +To be honest, I don't have a good solution for this case. So aufs
1678 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1680 +When dirperm1 is specified, aufs checks only the highest one for the
1681 +directory permission, and shows the entries. Otherwise, as usual, checks
1682 +every dir existing on all branches and rejects the request.
1684 +As a side effect, dirperm1 option improves the performance of aufs
1685 +because the number of permission check is reduced when the number of
1689 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1690 +----------------------------------------------------------------------
1691 +Generally VFS helpers re-validate a dentry as a part of lookup.
1692 +0. digging down the directory hierarchy.
1693 +1. lock the parent dir by its i_mutex.
1694 +2. lookup the final (child) entry.
1696 +4. call the actual operation (create, unlink, etc.)
1697 +5. unlock the parent dir
1699 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1700 +called. Actually aufs implements it and checks the dentry on a branch is
1702 +But it is not enough. Because aufs has to release the lock for the
1703 +parent dir on a branch at the end of ->lookup() (step 2) and
1704 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1706 +If the file on a branch is changed directly, eg. bypassing aufs, after
1707 +aufs released the lock, then the subsequent operation may cause
1708 +something unpleasant result.
1710 +This situation is a result of VFS architecture, ->lookup() and
1711 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1712 +design from VFS's point of view. It is just not suitable for sub-VFS
1715 +Aufs supports such case by three level of revalidation which is
1716 +selectable by user.
1717 +1. Simple Revalidate
1718 + Addition to the native flow in VFS's, confirm the child-parent
1719 + relationship on the branch just after locking the parent dir on the
1720 + branch in the "actual operation" (step 4). When this validation
1721 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1722 + checks the validation of the dentry on branches.
1723 +2. Monitor Changes Internally by Inotify/Fsnotify
1724 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1725 + the dentry on the branch, and returns EBUSY if it finds different
1727 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1728 + during it is in cache. When the event is notified, aufs registers a
1729 + function to kernel 'events' thread by schedule_work(). And the
1730 + function sets some special status to the cached aufs dentry and inode
1731 + private data. If they are not cached, then aufs has nothing to
1732 + do. When the same file is accessed through aufs (step 0-3) later,
1733 + aufs will detect the status and refresh all necessary data.
1734 + In this mode, aufs has to ignore the event which is fired by aufs
1736 +3. No Extra Validation
1737 + This is the simplest test and doesn't add any additional revalidation
1738 + test, and skip the revalidation in step 4. It is useful and improves
1739 + aufs performance when system surely hide the aufs branches from user,
1740 + by over-mounting something (or another method).
1741 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1742 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1743 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2016-04-24 18:32:51.390353525 +0200
1746 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1748 +# This program is free software; you can redistribute it and/or modify
1749 +# it under the terms of the GNU General Public License as published by
1750 +# the Free Software Foundation; either version 2 of the License, or
1751 +# (at your option) any later version.
1753 +# This program is distributed in the hope that it will be useful,
1754 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1755 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1756 +# GNU General Public License for more details.
1758 +# You should have received a copy of the GNU General Public License
1759 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1761 +Branch Manipulation
1763 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1764 +and changing its permission/attribute, there are a lot of works to do.
1768 +----------------------------------------------------------------------
1769 +o Confirm the adding dir exists outside of aufs, including loopback
1770 + mount, and its various attributes.
1771 +o Initialize the xino file and whiteout bases if necessary.
1774 +o Check the owner/group/mode of the directory
1775 + When the owner/group/mode of the adding directory differs from the
1776 + existing branch, aufs issues a warning because it may impose a
1778 + For example, when a upper writable branch has a world writable empty
1779 + top directory, a malicious user can create any files on the writable
1780 + branch directly, like copy-up and modify manually. If something like
1781 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1782 + writable branch, and the writable branch is world-writable, then a
1783 + malicious guy may create /etc/passwd on the writable branch directly
1784 + and the infected file will be valid in aufs.
1785 + I am afraid it can be a security issue, but aufs can do nothing except
1786 + producing a warning.
1790 +----------------------------------------------------------------------
1791 +o Confirm the deleting branch is not busy
1792 + To be general, there is one merit to adopt "remount" interface to
1793 + manipulate branches. It is to discard caches. At deleting a branch,
1794 + aufs checks the still cached (and connected) dentries and inodes. If
1795 + there are any, then they are all in-use. An inode without its
1796 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1798 + For the cached one, aufs checks whether the same named entry exists on
1800 + If the cached one is a directory, because aufs provides a merged view
1801 + to users, as long as one dir is left on any branch aufs can show the
1802 + dir to users. In this case, the branch can be removed from aufs.
1803 + Otherwise aufs rejects deleting the branch.
1805 + If any file on the deleting branch is opened by aufs, then aufs
1809 +Modify the Permission of a Branch
1810 +----------------------------------------------------------------------
1811 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1814 +o rw --> ro: Confirm the modifying branch is not busy
1815 + Aufs rejects the request if any of these conditions are true.
1816 + - a file on the branch is mmap-ed.
1817 + - a regular file on the branch is opened for write and there is no
1818 + same named entry on the upper branch.
1819 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1820 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1821 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2016-04-24 18:32:51.390353525 +0200
1824 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1826 +# This program is free software; you can redistribute it and/or modify
1827 +# it under the terms of the GNU General Public License as published by
1828 +# the Free Software Foundation; either version 2 of the License, or
1829 +# (at your option) any later version.
1831 +# This program is distributed in the hope that it will be useful,
1832 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1833 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1834 +# GNU General Public License for more details.
1836 +# You should have received a copy of the GNU General Public License
1837 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1839 +Policies to Select One among Multiple Writable Branches
1840 +----------------------------------------------------------------------
1841 +When the number of writable branch is more than one, aufs has to decide
1842 +the target branch for file creation or copy-up. By default, the highest
1843 +writable branch which has the parent (or ancestor) dir of the target
1844 +file is chosen (top-down-parent policy).
1845 +By user's request, aufs implements some other policies to select the
1846 +writable branch, for file creation several policies, round-robin,
1847 +most-free-space, and other policies. For copy-up, top-down-parent,
1848 +bottom-up-parent, bottom-up and others.
1850 +As expected, the round-robin policy selects the branch in circular. When
1851 +you have two writable branches and creates 10 new files, 5 files will be
1852 +created for each branch. mkdir(2) systemcall is an exception. When you
1853 +create 10 new directories, all will be created on the same branch.
1854 +And the most-free-space policy selects the one which has most free
1855 +space among the writable branches. The amount of free space will be
1856 +checked by aufs internally, and users can specify its time interval.
1858 +The policies for copy-up is more simple,
1859 +top-down-parent is equivalent to the same named on in create policy,
1860 +bottom-up-parent selects the writable branch where the parent dir
1861 +exists and the nearest upper one from the copyup-source,
1862 +bottom-up selects the nearest upper writable branch from the
1863 +copyup-source, regardless the existence of the parent dir.
1865 +There are some rules or exceptions to apply these policies.
1866 +- If there is a readonly branch above the policy-selected branch and
1867 + the parent dir is marked as opaque (a variation of whiteout), or the
1868 + target (creating) file is whiteout-ed on the upper readonly branch,
1869 + then the result of the policy is ignored and the target file will be
1870 + created on the nearest upper writable branch than the readonly branch.
1871 +- If there is a writable branch above the policy-selected branch and
1872 + the parent dir is marked as opaque or the target file is whiteouted
1873 + on the branch, then the result of the policy is ignored and the target
1874 + file will be created on the highest one among the upper writable
1875 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1877 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1878 + They try selecting the branch where the source exists as possible
1879 + since copyup a large file will take long time. If it can't be,
1880 + ie. the branch where the source exists is readonly, then they will
1881 + follow the copyup policy.
1882 +- There is an exception for rename(2) when the target exists.
1883 + If the rename target exists, aufs compares the index of the branches
1884 + where the source and the target exists and selects the higher
1885 + one. If the selected branch is readonly, then aufs follows the
1887 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1888 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1889 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2016-04-24 18:32:51.390353525 +0200
1892 +# Copyright (C) 2011-2016 Junjiro R. Okajima
1894 +# This program is free software; you can redistribute it and/or modify
1895 +# it under the terms of the GNU General Public License as published by
1896 +# the Free Software Foundation; either version 2 of the License, or
1897 +# (at your option) any later version.
1899 +# This program is distributed in the hope that it will be useful,
1900 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1901 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1902 +# GNU General Public License for more details.
1904 +# You should have received a copy of the GNU General Public License
1905 +# along with this program; if not, write to the Free Software
1906 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1909 +File-based Hierarchical Storage Management (FHSM)
1910 +----------------------------------------------------------------------
1911 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1912 +storage world. Aufs provides this feature as file-based with multiple
1913 +writable branches, based upon the principle of "Colder, the Lower".
1914 +Here the word "colder" means that the less used files, and "lower" means
1915 +that the position in the order of the stacked branches vertically.
1916 +These multiple writable branches are prioritized, ie. the topmost one
1917 +should be the fastest drive and be used heavily.
1919 +o Characters in aufs FHSM story
1920 +- aufs itself and a new branch attribute.
1921 +- a new ioctl interface to move-down and to establish a connection with
1922 + the daemon ("move-down" is a converse of "copy-up").
1923 +- userspace tool and daemon.
1925 +The userspace daemon establishes a connection with aufs and waits for
1926 +the notification. The notified information is very similar to struct
1927 +statfs containing the number of consumed blocks and inodes.
1928 +When the consumed blocks/inodes of a branch exceeds the user-specified
1929 +upper watermark, the daemon activates its move-down process until the
1930 +consumed blocks/inodes reaches the user-specified lower watermark.
1932 +The actual move-down is done by aufs based upon the request from
1933 +user-space since we need to maintain the inode number and the internal
1934 +pointer arrays in aufs.
1936 +Currently aufs FHSM handles the regular files only. Additionally they
1937 +must not be hard-linked nor pseudo-linked.
1940 +o Cowork of aufs and the user-space daemon
1941 + During the userspace daemon established the connection, aufs sends a
1942 + small notification to it whenever aufs writes something into the
1943 + writable branch. But it may cost high since aufs issues statfs(2)
1944 + internally. So user can specify a new option to cache the
1945 + info. Actually the notification is controlled by these factors.
1946 + + the specified cache time.
1947 + + classified as "force" by aufs internally.
1948 + Until the specified time expires, aufs doesn't send the info
1949 + except the forced cases. When aufs decide forcing, the info is always
1950 + notified to userspace.
1951 + For example, the number of free inodes is generally large enough and
1952 + the shortage of it happens rarely. So aufs doesn't force the
1953 + notification when creating a new file, directory and others. This is
1954 + the typical case which aufs doesn't force.
1955 + When aufs writes the actual filedata and the files consumes any of new
1956 + blocks, the aufs forces notifying.
1959 +o Interfaces in aufs
1960 +- New branch attribute.
1962 + Specifies that the branch is managed by FHSM feature. In other word,
1963 + participant in the FHSM.
1964 + When nofhsm is set to the branch, it will not be the source/target
1965 + branch of the move-down operation. This attribute is set
1966 + independently from coo and moo attributes, and if you want full
1967 + FHSM, you should specify them as well.
1968 +- New mount option.
1970 + Specifies a second to suppress many less important info to be
1973 + + AUFS_CTL_FHSM_FD
1974 + create a new file descriptor which userspace can read the notification
1975 + (a subset of struct statfs) from aufs.
1976 +- Module parameter 'brs'
1977 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1979 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1980 + When there are two or more branches with fhsm attributes,
1981 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1982 + terminates it. As a result of remounting and branch-manipulation, the
1983 + number of branches with fhsm attribute can be one. In this case,
1984 + /sbin/mount.aufs will terminate the user-space daemon.
1987 +Finally the operation is done as these steps in kernel-space.
1989 + + no one else is using the file.
1990 + + the file is not hard-linked.
1991 + + the file is not pseudo-linked.
1992 + + the file is a regular file.
1993 + + the parent dir is not opaqued.
1994 +- find the target writable branch.
1995 +- make sure the file is not whiteout-ed by the upper (than the target)
1997 +- make the parent dir on the target branch.
1998 +- mutex lock the inode on the branch.
1999 +- unlink the whiteout on the target branch (if exists).
2000 +- lookup and create the whiteout-ed temporary name on the target branch.
2001 +- copy the file as the whiteout-ed temporary name on the target branch.
2002 +- rename the whiteout-ed temporary name to the original name.
2003 +- unlink the file on the source branch.
2004 +- maintain the internal pointer array and the external inode number
2006 +- maintain the timestamps and other attributes of the parent dir and the
2009 +And of course, in every step, an error may happen. So the operation
2010 +should restore the original file state after an error happens.
2011 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2012 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2013 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2016-04-24 18:32:51.390353525 +0200
2016 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2018 +# This program is free software; you can redistribute it and/or modify
2019 +# it under the terms of the GNU General Public License as published by
2020 +# the Free Software Foundation; either version 2 of the License, or
2021 +# (at your option) any later version.
2023 +# This program is distributed in the hope that it will be useful,
2024 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2025 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2026 +# GNU General Public License for more details.
2028 +# You should have received a copy of the GNU General Public License
2029 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2031 +mmap(2) -- File Memory Mapping
2032 +----------------------------------------------------------------------
2033 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2034 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2036 +This approach is simple and good, but there is one problem.
2037 +Under /proc, several entries show the mmapped files by its path (with
2038 +device and inode number), and the printed path will be the path on the
2039 +branch fs's instead of virtual aufs's.
2040 +This is not a problem in most cases, but some utilities lsof(1) (and its
2041 +user) may expect the path on aufs.
2043 +To address this issue, aufs adds a new member called vm_prfile in struct
2044 +vm_area_struct (and struct vm_region). The original vm_file points to
2045 +the file on the branch fs in order to handle everything correctly as
2046 +usual. The new vm_prfile points to a virtual file in aufs, and the
2047 +show-functions in procfs refers to vm_prfile if it is set.
2048 +Also we need to maintain several other places where touching vm_file
2050 +- fork()/clone() copies vma and the reference count of vm_file is
2052 +- merging vma maintains the ref count too.
2054 +This is not a good approach. It just fakes the printed path. But it
2055 +leaves all behaviour around f_mapping unchanged. This is surely an
2057 +Actually aufs had adopted another complicated approach which calls
2058 +generic_file_mmap() and handles struct vm_operations_struct. In this
2059 +approach, aufs met a hard problem and I could not solve it without
2060 +switching the approach.
2062 +There may be one more another approach which is
2063 +- bind-mount the branch-root onto the aufs-root internally
2064 +- grab the new vfsmount (ie. struct mount)
2065 +- lazy-umount the branch-root internally
2066 +- in open(2) the aufs-file, open the branch-file with the hidden
2067 + vfsmount (instead of the original branch's vfsmount)
2068 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2069 + but it may be possible from userspace by the mount helper.
2071 +Adding the internal hidden vfsmount and using it in opening a file, the
2072 +file path under /proc will be printed correctly. This approach looks
2073 +smarter, but is not possible I am afraid.
2074 +- aufs-root may be bind-mount later. when it happens, another hidden
2075 + vfsmount will be required.
2076 +- it is hard to get the chance to bind-mount and lazy-umount
2077 + + in kernel-space, FS can have vfsmount in open(2) via
2078 + file->f_path, and aufs can know its vfsmount. But several locks are
2079 + already acquired, and if aufs tries to bind-mount and lazy-umount
2080 + here, then it may cause a deadlock.
2081 + + in user-space, bind-mount doesn't invoke the mount helper.
2082 +- since /proc shows dev and ino, aufs has to give vma these info. it
2083 + means a new member vm_prinode will be necessary. this is essentially
2084 + equivalent to vm_prfile described above.
2086 +I have to give up this "looks-smater" approach.
2087 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2088 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2089 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2016-04-24 18:32:51.390353525 +0200
2092 +# Copyright (C) 2014-2016 Junjiro R. Okajima
2094 +# This program is free software; you can redistribute it and/or modify
2095 +# it under the terms of the GNU General Public License as published by
2096 +# the Free Software Foundation; either version 2 of the License, or
2097 +# (at your option) any later version.
2099 +# This program is distributed in the hope that it will be useful,
2100 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2101 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2102 +# GNU General Public License for more details.
2104 +# You should have received a copy of the GNU General Public License
2105 +# along with this program; if not, write to the Free Software
2106 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2109 +Listing XATTR/EA and getting the value
2110 +----------------------------------------------------------------------
2111 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2112 +shows the values from the topmost existing file. This behaviour is good
2113 +for the non-dir entries since the bahaviour exactly matches the shown
2114 +information. But for the directories, aufs considers all the same named
2115 +entries on the lower branches. Which means, if one of the lower entry
2116 +rejects readdir call, then aufs returns an error even if the topmost
2117 +entry allows it. This behaviour is necessary to respect the branch fs's
2118 +security, but can make users confused since the user-visible standard
2119 +attributes don't match the behaviour.
2120 +To address this issue, aufs has a mount option called dirperm1 which
2121 +checks the permission for the topmost entry only, and ignores the lower
2122 +entry's permission.
2124 +A similar issue can happen around XATTR.
2125 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2126 +always set. Otherwise these very unpleasant situation would happen.
2127 +- listxattr(2) may return the duplicated entries.
2128 +- users may not be able to remove or reset the XATTR forever,
2131 +XATTR/EA support in the internal (copy,move)-(up,down)
2132 +----------------------------------------------------------------------
2133 +Generally the extended attributes of inode are categorized as these.
2134 +- "security" for LSM and capability.
2135 +- "system" for posix ACL, 'acl' mount option is required for the branch
2137 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2138 +- "user" for userspace, 'user_xattr' mount option is required for the
2139 + branch fs generally.
2141 +Moreover there are some other categories. Aufs handles these rather
2142 +unpopular categories as the ordinary ones, ie. there is no special
2143 +condition nor exception.
2145 +In copy-up, the support for XATTR on the dst branch may differ from the
2146 +src branch. In this case, the copy-up operation will get an error and
2147 +the original user operation which triggered the copy-up will fail. It
2148 +can happen that even all copy-up will fail.
2149 +When both of src and dst branches support XATTR and if an error occurs
2150 +during copying XATTR, then the copy-up should fail obviously. That is a
2151 +good reason and aufs should return an error to userspace. But when only
2152 +the src branch support that XATTR, aufs should not return an error.
2153 +For example, the src branch supports ACL but the dst branch doesn't
2154 +because the dst branch may natively un-support it or temporary
2155 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2156 +may NOT return an error even if the XATTR is not supported. It is
2157 +totally up to the branch fs.
2159 +Anyway when the aufs internal copy-up gets an error from the dst branch
2160 +fs, then aufs tries removing the just copied entry and returns the error
2161 +to the userspace. The worst case of this situation will be all copy-up
2164 +For the copy-up operation, there two basic approaches.
2165 +- copy the specified XATTR only (by category above), and return the
2166 + error unconditionally if it happens.
2167 +- copy all XATTR, and ignore the error on the specified category only.
2169 +In order to support XATTR and to implement the correct behaviour, aufs
2170 +chooses the latter approach and introduces some new branch attributes,
2171 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2172 +They correspond to the XATTR namespaces (see above). Additionally, to be
2173 +convenient, "icex" is also provided which means all "icex*" attributes
2174 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2176 +The meaning of these attributes is to ignore the error from setting
2177 +XATTR on that branch.
2178 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2179 +error from the dst branch according to the specified attributes.
2181 +Some XATTR may have its default value. The default value may come from
2182 +the parent dir or the environment. If the default value is set at the
2183 +file creating-time, it will be overwritten by copy-up.
2184 +Some contradiction may happen I am afraid.
2185 +Do we need another attribute to stop copying XATTR? I am unsure. For
2186 +now, aufs implements the branch attributes to ignore the error.
2187 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2188 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2189 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2016-04-24 18:32:51.390353525 +0200
2192 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2194 +# This program is free software; you can redistribute it and/or modify
2195 +# it under the terms of the GNU General Public License as published by
2196 +# the Free Software Foundation; either version 2 of the License, or
2197 +# (at your option) any later version.
2199 +# This program is distributed in the hope that it will be useful,
2200 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2201 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2202 +# GNU General Public License for more details.
2204 +# You should have received a copy of the GNU General Public License
2205 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2207 +Export Aufs via NFS
2208 +----------------------------------------------------------------------
2209 +Here is an approach.
2210 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2212 +- iget_locked(): initialize aufs inode generation for a new inode, and
2213 + store it in xigen file.
2214 +- destroy_inode(): increment aufs inode generation and store it in xigen
2215 + file. it is necessary even if it is not unlinked, because any data of
2216 + inode may be changed by UDBA.
2217 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2218 + build file handle by
2219 + + branch id (4 bytes)
2220 + + superblock generation (4 bytes)
2221 + + inode number (4 or 8 bytes)
2222 + + parent dir inode number (4 or 8 bytes)
2223 + + inode generation (4 bytes))
2224 + + return value of exportfs_encode_fh() for the parent on a branch (4
2226 + + file handle for a branch (by exportfs_encode_fh())
2228 + + find the index of a branch from its id in handle, and check it is
2229 + still exist in aufs.
2230 + + 1st level: get the inode number from handle and search it in cache.
2231 + + 2nd level: if not found in cache, get the parent inode number from
2232 + the handle and search it in cache. and then open the found parent
2233 + dir, find the matching inode number by vfs_readdir() and get its
2234 + name, and call lookup_one_len() for the target dentry.
2235 + + 3rd level: if the parent dir is not cached, call
2236 + exportfs_decode_fh() for a branch and get the parent on a branch,
2237 + build a pathname of it, convert it a pathname in aufs, call
2238 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2240 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2241 + for every branch, but not itself. to get this, (currently) aufs
2242 + searches in current->nsproxy->mnt_ns list. it may not be a good
2243 + idea, but I didn't get other approach.
2244 + + test the generation of the gotten inode.
2245 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2246 + convert it into ESTALE for NFSD.
2247 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2248 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2249 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2250 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2251 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2016-04-24 18:32:51.390353525 +0200
2254 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2256 +# This program is free software; you can redistribute it and/or modify
2257 +# it under the terms of the GNU General Public License as published by
2258 +# the Free Software Foundation; either version 2 of the License, or
2259 +# (at your option) any later version.
2261 +# This program is distributed in the hope that it will be useful,
2262 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2263 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2264 +# GNU General Public License for more details.
2266 +# You should have received a copy of the GNU General Public License
2267 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2269 +Show Whiteout Mode (shwh)
2270 +----------------------------------------------------------------------
2271 +Generally aufs hides the name of whiteouts. But in some cases, to show
2272 +them is very useful for users. For instance, creating a new middle layer
2273 +(branch) by merging existing layers.
2275 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2276 +When you have three branches,
2277 +- Bottom: 'system', squashfs (underlying base system), read-only
2278 +- Middle: 'mods', squashfs, read-only
2279 +- Top: 'overlay', ram (tmpfs), read-write
2281 +The top layer is loaded at boot time and saved at shutdown, to preserve
2282 +the changes made to the system during the session.
2283 +When larger changes have been made, or smaller changes have accumulated,
2284 +the size of the saved top layer data grows. At this point, it would be
2285 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2286 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2287 +restoring save and load speed.
2289 +This merging is simplified by the use of another aufs mount, of just the
2290 +two overlay branches using the 'shwh' option.
2291 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2292 + aufs /livesys/merge_union
2294 +A merged view of these two branches is then available at
2295 +/livesys/merge_union, and the new feature is that the whiteouts are
2297 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2298 +writing to all branches. Also the default mode for all branches is 'ro'.
2299 +It is now possible to save the combined contents of the two overlay
2300 +branches to a new squashfs, e.g.:
2301 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2303 +This new squashfs archive can be stored on the boot device and the
2304 +initramfs will use it to replace the old one at the next boot.
2305 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2306 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2307 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2016-04-24 18:32:51.390353525 +0200
2310 +# Copyright (C) 2010-2016 Junjiro R. Okajima
2312 +# This program is free software; you can redistribute it and/or modify
2313 +# it under the terms of the GNU General Public License as published by
2314 +# the Free Software Foundation; either version 2 of the License, or
2315 +# (at your option) any later version.
2317 +# This program is distributed in the hope that it will be useful,
2318 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2319 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2320 +# GNU General Public License for more details.
2322 +# You should have received a copy of the GNU General Public License
2323 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2325 +Dynamically customizable FS operations
2326 +----------------------------------------------------------------------
2327 +Generally FS operations (struct inode_operations, struct
2328 +address_space_operations, struct file_operations, etc.) are defined as
2329 +"static const", but it never means that FS have only one set of
2330 +operation. Some FS have multiple sets of them. For instance, ext2 has
2331 +three sets, one for XIP, for NOBH, and for normal.
2332 +Since aufs overrides and redirects these operations, sometimes aufs has
2333 +to change its behaviour according to the branch FS type. More importantly
2334 +VFS acts differently if a function (member in the struct) is set or
2335 +not. It means aufs should have several sets of operations and select one
2336 +among them according to the branch FS definition.
2338 +In order to solve this problem and not to affect the behaviour of VFS,
2339 +aufs defines these operations dynamically. For instance, aufs defines
2340 +dummy direct_IO function for struct address_space_operations, but it may
2341 +not be set to the address_space_operations actually. When the branch FS
2342 +doesn't have it, aufs doesn't set it to its address_space_operations
2343 +while the function definition itself is still alive. So the behaviour
2344 +itself will not change, and it will return an error when direct_IO is
2347 +The lifetime of these dynamically generated operation object is
2348 +maintained by aufs branch object. When the branch is removed from aufs,
2349 +the reference counter of the object is decremented. When it reaches
2350 +zero, the dynamically generated operation object will be freed.
2352 +This approach is designed to support AIO (io_submit), Direct I/O and
2354 +Currently this approach is applied to address_space_operations for
2355 +regular files only.
2356 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2357 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2358 +++ linux/Documentation/filesystems/aufs/README 2016-04-24 18:32:51.390353525 +0200
2361 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2367 +----------------------------------------
2368 +In the early days, aufs was entirely re-designed and re-implemented
2369 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2370 +improvements and implementations, it becomes totally different from
2371 +Unionfs while keeping the basic features.
2372 +Recently, Unionfs Version 2.x series begin taking some of the same
2373 +approaches to aufs1's.
2374 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2375 +University and his team.
2377 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2378 +If you want older kernel version support, try aufs2-2.6.git or
2379 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2381 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2382 + According to Christoph Hellwig, linux rejects all union-type
2383 + filesystems but UnionMount.
2384 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2386 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2387 + UnionMount, and he pointed out an issue around a directory mutex
2388 + lock and aufs addressed it. But it is still unsure whether aufs will
2389 + be merged (or any other union solution).
2390 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2394 +----------------------------------------
2395 +- unite several directories into a single virtual filesystem. The member
2396 + directory is called as a branch.
2397 +- you can specify the permission flags to the branch, which are 'readonly',
2398 + 'readwrite' and 'whiteout-able.'
2399 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2400 + readonly branch are modifiable logically.
2401 +- dynamic branch manipulation, add, del.
2404 +Also there are many enhancements in aufs, such as:
2405 +- test only the highest one for the directory permission (dirperm1)
2406 +- copyup on open (coo=)
2407 +- 'move' policy for copy-up between two writable branches, after
2408 + checking free space.
2410 +- readdir(3) in userspace.
2411 +- keep inode number by external inode number table
2412 +- keep the timestamps of file/dir in internal copyup operation
2413 +- seekable directory, supporting NFS readdir.
2414 +- whiteout is hardlinked in order to reduce the consumption of inodes
2416 +- do not copyup, nor create a whiteout when it is unnecessary
2417 +- revert a single systemcall when an error occurs in aufs
2418 +- remount interface instead of ioctl
2419 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2420 +- loopback mounted filesystem as a branch
2421 +- kernel thread for removing the dir who has a plenty of whiteouts
2422 +- support copyup sparse file (a file which has a 'hole' in it)
2423 +- default permission flags for branches
2424 +- selectable permission flags for ro branch, whether whiteout can
2427 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2428 +- support multiple writable branches, some policies to select one
2429 + among multiple writable branches.
2430 +- a new semantics for link(2) and rename(2) to support multiple
2431 + writable branches.
2432 +- no glibc changes are required.
2433 +- pseudo hardlink (hardlink over branches)
2434 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2435 + including NFS or remote filesystem branch.
2436 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2439 +Currently these features are dropped temporary from aufs4.
2440 +See design/08plan.txt in detail.
2441 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2443 +- statistics of aufs thread (/sys/fs/aufs/stat)
2445 +Features or just an idea in the future (see also design/*.txt),
2446 +- reorder the branch index without del/re-add.
2447 +- permanent xino files for NFSD
2448 +- an option for refreshing the opened files after add/del branches
2449 +- light version, without branch manipulation. (unnecessary?)
2450 +- copyup in userspace
2451 +- inotify in userspace
2456 +----------------------------------------
2457 +There are three GIT trees for aufs4, aufs4-linux.git,
2458 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2460 +While the aufs-util is always necessary, you need either of aufs4-linux
2461 +or aufs4-standalone.
2463 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2464 +git://git.kernel.org/.../torvalds/linux.git.
2465 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2466 +build aufs4 as an external kernel module.
2467 +Several extra patches are not included in this tree. Only
2468 +aufs4-standalone tree contains them. They are described in the later
2469 +section "Configuration and Compilation."
2471 +On the other hand, the aufs4-standalone tree has only aufs source files
2472 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2473 +But you need to apply all aufs patches manually.
2475 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2476 +represents the linux kernel version, "linux-4.x". For instance,
2477 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2478 +"aufs4.x-rcN" branch.
2481 +$ git clone --reference /your/linux/git/tree \
2482 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2483 +- if you don't have linux GIT tree, then remove "--reference ..."
2484 +$ cd aufs4-linux.git
2485 +$ git checkout origin/aufs4.0
2487 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2488 +leave the patch-work to GIT.
2489 +$ cd /your/linux/git/tree
2490 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2492 +$ git checkout -b my4.0 v4.0
2493 +$ (add your local change...)
2494 +$ git pull aufs4 aufs4.0
2495 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2496 +- you may need to solve some conflicts between your_changes and
2497 + aufs4.0. in this case, git-rerere is recommended so that you can
2498 + solve the similar conflicts automatically when you upgrade to 4.1 or
2499 + later in the future.
2501 +o aufs4-standalone tree
2502 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2503 +$ cd aufs4-standalone.git
2504 +$ git checkout origin/aufs4.0
2507 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2508 +- note that the public aufs-util.git is on SourceForge instead of
2511 +$ git checkout origin/aufs4.0
2513 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2514 +The minor version number, 'x' in '4.x', of aufs may not always
2515 +follow the minor version number of the kernel.
2516 +Because changes in the kernel that cause the use of a new
2517 +minor version number do not always require changes to aufs-util.
2519 +Since aufs-util has its own minor version number, you may not be
2520 +able to find a GIT branch in aufs-util for your kernel's
2521 +exact minor version number.
2522 +In this case, you should git-checkout the branch for the
2523 +nearest lower number.
2525 +For (an unreleased) example:
2526 +If you are using "linux-4.10" and the "aufs4.10" branch
2527 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2528 +or something numerically smaller is the branch for your kernel.
2530 +Also you can view all branches by
2534 +3. Configuration and Compilation
2535 +----------------------------------------
2536 +Make sure you have git-checkout'ed the correct branch.
2538 +For aufs4-linux tree,
2539 +- enable CONFIG_AUFS_FS.
2540 +- set other aufs configurations if necessary.
2542 +For aufs4-standalone tree,
2543 +There are several ways to build.
2546 +- apply ./aufs4-kbuild.patch to your kernel source files.
2547 +- apply ./aufs4-base.patch too.
2548 +- apply ./aufs4-mmap.patch too.
2549 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2550 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2551 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2552 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2553 +- enable CONFIG_AUFS_FS, you can select either
2555 +- and build your kernel as usual.
2556 +- install the built kernel.
2557 + Note: Since linux-3.9, every filesystem module requires an alias
2558 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2559 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2560 +- install the header files too by "make headers_install" to the
2561 + directory where you specify. By default, it is $PWD/usr.
2562 + "make help" shows a brief note for headers_install.
2563 +- and reboot your system.
2566 +- module only (CONFIG_AUFS_FS=m).
2567 +- apply ./aufs4-base.patch to your kernel source files.
2568 +- apply ./aufs4-mmap.patch too.
2569 +- apply ./aufs4-standalone.patch too.
2570 +- build your kernel, don't forget "make headers_install", and reboot.
2571 +- edit ./config.mk and set other aufs configurations if necessary.
2572 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2573 + every aufs configurations.
2574 +- build the module by simple "make".
2575 + Note: Since linux-3.9, every filesystem module requires an alias
2576 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2577 + modules.aliases file.
2578 +- you can specify ${KDIR} make variable which points to your kernel
2580 +- install the files
2581 + + run "make install" to install the aufs module, or copy the built
2582 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2583 + + run "make install_headers" (instead of headers_install) to install
2584 + the modified aufs header file (you can specify DESTDIR which is
2585 + available in aufs standalone version's Makefile only), or copy
2586 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2587 + you like manually. By default, the target directory is $PWD/usr.
2588 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2589 + kernel source tree.
2591 +Note: The header file aufs_type.h is necessary to build aufs-util
2592 + as well as "make headers_install" in the kernel source tree.
2593 + headers_install is subject to be forgotten, but it is essentially
2594 + necessary, not only for building aufs-util.
2595 + You may not meet problems without headers_install in some older
2599 +- read README in aufs-util, build and install it
2600 +- note that your distribution may contain an obsoleted version of
2601 + aufs_type.h in /usr/include/linux or something. When you build aufs
2602 + utilities, make sure that your compiler refers the correct aufs header
2603 + file which is built by "make headers_install."
2604 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2605 + then run "make install_ulib" too. And refer to the aufs manual in
2608 +There several other patches in aufs4-standalone.git. They are all
2609 +optional. When you meet some problems, they will help you.
2610 +- aufs4-loopback.patch
2611 + Supports a nested loopback mount in a branch-fs. This patch is
2612 + unnecessary until aufs produces a message like "you may want to try
2613 + another patch for loopback file".
2615 + Modifies a system global kernel internal function get_next_ino() in
2616 + order to stop assigning 0 for an inode-number. Not directly related to
2617 + aufs, but recommended generally.
2619 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2620 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2621 + duplication of inode number, which is important for backup tools and
2622 + other utilities. When you find aufs XINO files for tmpfs branch
2623 + growing too much, try this patch.
2624 +- lockdep-debug.patch
2625 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2626 + also a caller of VFS functions for branch filesystems, subclassing of
2627 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2628 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2629 + need to apply this debug patch to expand several constant values.
2630 + If don't know what LOCKDEP, then you don't have apply this patch.
2634 +----------------------------------------
2635 +At first, make sure aufs-util are installed, and please read the aufs
2636 +manual, aufs.5 in aufs-util.git tree.
2640 +$ mkdir /tmp/rw /tmp/aufs
2641 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2643 +Here is another example. The result is equivalent.
2644 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2646 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2647 +# mount -o remount,append:${HOME} /tmp/aufs
2649 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2650 +you modify a file under /tmp/aufs, the one on your home directory is
2651 +not affected, instead the same named file will be newly created under
2652 +/tmp/rw. And all of your modification to a file will be applied to
2653 +the one under /tmp/rw. This is called the file based Copy on Write
2655 +Aufs mount options are described in aufs.5.
2656 +If you run chroot or something and make your aufs as a root directory,
2657 +then you need to customize the shutdown script. See the aufs manual in
2660 +Additionally, there are some sample usages of aufs which are a
2661 +diskless system with network booting, and LiveCD over NFS.
2662 +See sample dir in CVS tree on SourceForge.
2666 +----------------------------------------
2667 +When you have any problems or strange behaviour in aufs, please let me
2669 +- /proc/mounts (instead of the output of mount(8))
2670 +- /sys/module/aufs/*
2671 +- /sys/fs/aufs/* (if you have them)
2672 +- /debug/aufs/* (if you have them)
2673 +- linux kernel version
2674 + if your kernel is not plain, for example modified by distributor,
2675 + the url where i can download its source is necessary too.
2676 +- aufs version which was printed at loading the module or booting the
2677 + system, instead of the date you downloaded.
2678 +- configuration (define/undefine CONFIG_AUFS_xxx)
2679 +- kernel configuration or /proc/config.gz (if you have it)
2680 +- behaviour which you think to be incorrect
2681 +- actual operation, reproducible one is better
2682 +- mailto: aufs-users at lists.sourceforge.net
2684 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2685 +and Feature Requests) on SourceForge. Please join and write to
2689 +6. Acknowledgements
2690 +----------------------------------------
2691 +Thanks to everyone who have tried and are using aufs, whoever
2692 +have reported a bug or any feedback.
2694 +Especially donators:
2695 +Tomas Matejicek(slax.org) made a donation (much more than once).
2696 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2697 + scripts) is making "doubling" donations.
2698 + Unfortunately I cannot list all of the donators, but I really
2700 + It ends Aug 2010, but the ordinary donation URL is still available.
2701 + <http://sourceforge.net/donate/index.php?group_id=167503>
2702 +Dai Itasaka made a donation (2007/8).
2703 +Chuck Smith made a donation (2008/4, 10 and 12).
2704 +Henk Schoneveld made a donation (2008/9).
2705 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2706 +Francois Dupoux made a donation (2008/11).
2707 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2708 + aufs2 GIT tree (2009/2).
2709 +William Grant made a donation (2009/3).
2710 +Patrick Lane made a donation (2009/4).
2711 +The Mail Archive (mail-archive.com) made donations (2009/5).
2712 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2713 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2714 +Pavel Pronskiy made a donation (2011/2).
2715 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2716 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2717 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2719 +Sam Liddicott made a donation (2011/9).
2720 +Era Scarecrow made a donation (2013/4).
2721 +Bor Ratajc made a donation (2013/4).
2722 +Alessandro Gorreta made a donation (2013/4).
2723 +POIRETTE Marc made a donation (2013/4).
2724 +Alessandro Gorreta made a donation (2013/4).
2725 +lauri kasvandik made a donation (2013/5).
2726 +"pemasu from Finland" made a donation (2013/7).
2727 +The Parted Magic Project made a donation (2013/9 and 11).
2728 +Pavel Barta made a donation (2013/10).
2729 +Nikolay Pertsev made a donation (2014/5).
2730 +James B made a donation (2014/7 and 2015/7).
2731 +Stefano Di Biase made a donation (2014/8).
2732 +Daniel Epellei made a donation (2015/1).
2733 +OmegaPhil made a donation (2016/1).
2735 +Thank you very much.
2736 +Donations are always, including future donations, very important and
2737 +helpful for me to keep on developing aufs.
2741 +----------------------------------------
2742 +If you are an experienced user, no explanation is needed. Aufs is
2743 +just a linux filesystem.
2748 +# Local variables: ;
2751 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2752 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2753 +++ linux/fs/aufs/aufs.h 2016-04-24 18:32:51.390353525 +0200
2756 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2758 + * This program, aufs is free software; you can redistribute it and/or modify
2759 + * it under the terms of the GNU General Public License as published by
2760 + * the Free Software Foundation; either version 2 of the License, or
2761 + * (at your option) any later version.
2763 + * This program is distributed in the hope that it will be useful,
2764 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2765 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2766 + * GNU General Public License for more details.
2768 + * You should have received a copy of the GNU General Public License
2769 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2773 + * all header files
2781 +#define AuStub(type, name, body, ...) \
2782 + static inline type name(__VA_ARGS__) { body; }
2784 +#define AuStubVoid(name, ...) \
2785 + AuStub(void, name, , __VA_ARGS__)
2786 +#define AuStubInt0(name, ...) \
2787 + AuStub(int, name, return 0, __VA_ARGS__)
2791 +#include "branch.h"
2794 +#include "dbgaufs.h"
2795 +#include "dentry.h"
2799 +#include "fstype.h"
2802 +#include "module.h"
2807 +#include "sysaufs.h"
2812 +#endif /* __KERNEL__ */
2813 +#endif /* __AUFS_H__ */
2814 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2815 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2816 +++ linux/fs/aufs/branch.c 2016-04-24 18:32:51.390353525 +0200
2819 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2821 + * This program, aufs is free software; you can redistribute it and/or modify
2822 + * it under the terms of the GNU General Public License as published by
2823 + * the Free Software Foundation; either version 2 of the License, or
2824 + * (at your option) any later version.
2826 + * This program is distributed in the hope that it will be useful,
2827 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2828 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2829 + * GNU General Public License for more details.
2831 + * You should have received a copy of the GNU General Public License
2832 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2836 + * branch management
2839 +#include <linux/compat.h>
2840 +#include <linux/statfs.h>
2844 + * free a single branch
2846 +static void au_br_do_free(struct au_branch *br)
2849 + struct au_wbr *wbr;
2850 + struct au_dykey **key;
2852 + au_hnotify_fin_br(br);
2854 + if (br->br_xino.xi_file)
2855 + fput(br->br_xino.xi_file);
2856 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2858 + AuDebugOn(atomic_read(&br->br_count));
2862 + for (i = 0; i < AuBrWh_Last; i++)
2863 + dput(wbr->wbr_wh[i]);
2864 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2865 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2868 + if (br->br_fhsm) {
2869 + au_br_fhsm_fin(br->br_fhsm);
2870 + kfree(br->br_fhsm);
2873 + key = br->br_dykey;
2874 + for (i = 0; i < AuBrDynOp; i++, key++)
2880 + /* recursive lock, s_umount of branch's */
2882 + path_put(&br->br_path);
2889 + * frees all branches
2891 +void au_br_free(struct au_sbinfo *sbinfo)
2893 + aufs_bindex_t bmax;
2894 + struct au_branch **br;
2896 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2898 + bmax = sbinfo->si_bend + 1;
2899 + br = sbinfo->si_branch;
2901 + au_br_do_free(*br++);
2905 + * find the index of a branch which is specified by @br_id.
2907 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2909 + aufs_bindex_t bindex, bend;
2911 + bend = au_sbend(sb);
2912 + for (bindex = 0; bindex <= bend; bindex++)
2913 + if (au_sbr_id(sb, bindex) == br_id)
2918 +/* ---------------------------------------------------------------------- */
2924 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2925 + struct dentry *h_root)
2927 + if (unlikely(h_adding == h_root
2928 + || au_test_loopback_overlap(sb, h_adding)))
2930 + if (h_adding->d_sb != h_root->d_sb)
2932 + return au_test_subdir(h_adding, h_root)
2933 + || au_test_subdir(h_root, h_adding);
2937 + * returns a newly allocated branch. @new_nbranch is a number of branches
2938 + * after adding a branch.
2940 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2943 + struct au_branch *add_branch;
2944 + struct dentry *root;
2945 + struct inode *inode;
2949 + root = sb->s_root;
2950 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
2951 + if (unlikely(!add_branch))
2954 + err = au_hnotify_init_br(add_branch, perm);
2955 + if (unlikely(err))
2958 + if (au_br_writable(perm)) {
2959 + /* may be freed separately at changing the branch permission */
2960 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
2962 + if (unlikely(!add_branch->br_wbr))
2966 + if (au_br_fhsm(perm)) {
2967 + err = au_fhsm_br_alloc(add_branch);
2968 + if (unlikely(err))
2972 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2974 + err = au_di_realloc(au_di(root), new_nbranch);
2976 + inode = d_inode(root);
2977 + err = au_ii_realloc(au_ii(inode), new_nbranch);
2980 + return add_branch; /* success */
2983 + kfree(add_branch->br_wbr);
2985 + au_hnotify_fin_br(add_branch);
2987 + kfree(add_branch);
2989 + return ERR_PTR(err);
2993 + * test if the branch permission is legal or not.
2995 +static int test_br(struct inode *inode, int brperm, char *path)
2999 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3004 + pr_err("write permission for readonly mount or inode, %s\n", path);
3012 + * 0: success, the caller will add it
3013 + * plus: success, it is already unified, the caller should ignore it
3016 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3019 + aufs_bindex_t bend, bindex;
3020 + struct dentry *root, *h_dentry;
3021 + struct inode *inode, *h_inode;
3023 + root = sb->s_root;
3024 + bend = au_sbend(sb);
3025 + if (unlikely(bend >= 0
3026 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3030 + pr_err("%s duplicated\n", add->pathname);
3035 + err = -ENOSPC; /* -E2BIG; */
3036 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3037 + || AUFS_BRANCH_MAX - 1 <= bend)) {
3038 + pr_err("number of branches exceeded %s\n", add->pathname);
3043 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
3044 + pr_err("bad index %d\n", add->bindex);
3048 + inode = d_inode(add->path.dentry);
3050 + if (unlikely(!inode->i_nlink)) {
3051 + pr_err("no existence %s\n", add->pathname);
3056 + if (unlikely(inode->i_sb == sb)) {
3057 + pr_err("%s must be outside\n", add->pathname);
3061 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3062 + pr_err("unsupported filesystem, %s (%s)\n",
3063 + add->pathname, au_sbtype(inode->i_sb));
3067 + if (unlikely(inode->i_sb->s_stack_depth)) {
3068 + pr_err("already stacked, %s (%s)\n",
3069 + add->pathname, au_sbtype(inode->i_sb));
3073 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3074 + if (unlikely(err))
3078 + return 0; /* success */
3081 + for (bindex = 0; bindex <= bend; bindex++)
3082 + if (unlikely(test_overlap(sb, add->path.dentry,
3083 + au_h_dptr(root, bindex)))) {
3084 + pr_err("%s is overlapped\n", add->pathname);
3089 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3090 + h_dentry = au_h_dptr(root, 0);
3091 + h_inode = d_inode(h_dentry);
3092 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3093 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3094 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3095 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3097 + i_uid_read(inode), i_gid_read(inode),
3098 + (inode->i_mode & S_IALLUGO),
3099 + i_uid_read(h_inode), i_gid_read(h_inode),
3100 + (h_inode->i_mode & S_IALLUGO));
3108 + * initialize or clean the whiteouts for an adding branch
3110 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3113 + int err, old_perm;
3114 + aufs_bindex_t bindex;
3115 + struct inode *h_inode;
3116 + struct au_wbr *wbr;
3117 + struct au_hinode *hdir;
3118 + struct dentry *h_dentry;
3120 + err = vfsub_mnt_want_write(au_br_mnt(br));
3121 + if (unlikely(err))
3125 + old_perm = br->br_perm;
3126 + br->br_perm = new_perm;
3129 + bindex = au_br_index(sb, br->br_id);
3130 + if (0 <= bindex) {
3131 + hdir = au_hi(d_inode(sb->s_root), bindex);
3132 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
3134 + h_dentry = au_br_dentry(br);
3135 + h_inode = d_inode(h_dentry);
3136 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3139 + err = au_wh_init(br, sb);
3141 + wbr_wh_write_lock(wbr);
3142 + err = au_wh_init(br, sb);
3143 + wbr_wh_write_unlock(wbr);
3146 + au_hn_imtx_unlock(hdir);
3148 + inode_unlock(h_inode);
3149 + vfsub_mnt_drop_write(au_br_mnt(br));
3150 + br->br_perm = old_perm;
3152 + if (!err && wbr && !au_br_writable(new_perm)) {
3154 + br->br_wbr = NULL;
3161 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3165 + struct kstatfs kst;
3166 + struct au_wbr *wbr;
3169 + au_rw_init(&wbr->wbr_wh_rwsem);
3170 + atomic_set(&wbr->wbr_wh_running, 0);
3173 + * a limit for rmdir/rename a dir
3174 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3176 + err = vfs_statfs(&br->br_path, &kst);
3177 + if (unlikely(err))
3180 + if (kst.f_namelen >= NAME_MAX)
3181 + err = au_br_init_wh(sb, br, perm);
3183 + pr_err("%pd(%s), unsupported namelen %ld\n",
3185 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3191 +/* initialize a new branch */
3192 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3193 + struct au_opt_add *add)
3196 + struct inode *h_inode;
3199 + mutex_init(&br->br_xino.xi_nondir_mtx);
3200 + br->br_perm = add->perm;
3201 + br->br_path = add->path; /* set first, path_get() later */
3202 + spin_lock_init(&br->br_dykey_lock);
3203 + atomic_set(&br->br_count, 0);
3204 + atomic_set(&br->br_xino_running, 0);
3205 + br->br_id = au_new_br_id(sb);
3206 + AuDebugOn(br->br_id < 0);
3208 + if (au_br_writable(add->perm)) {
3209 + err = au_wbr_init(br, sb, add->perm);
3210 + if (unlikely(err))
3214 + if (au_opt_test(au_mntflags(sb), XINO)) {
3215 + h_inode = d_inode(add->path.dentry);
3216 + err = au_xino_br(sb, br, h_inode->i_ino,
3217 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3218 + if (unlikely(err)) {
3219 + AuDebugOn(br->br_xino.xi_file);
3224 + sysaufs_br_init(br);
3225 + path_get(&br->br_path);
3226 + goto out; /* success */
3229 + memset(&br->br_path, 0, sizeof(br->br_path));
3234 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3235 + struct au_branch *br, aufs_bindex_t bend,
3236 + aufs_bindex_t amount)
3238 + struct au_branch **brp;
3240 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3242 + brp = sbinfo->si_branch + bindex;
3243 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3245 + sbinfo->si_bend++;
3246 + if (unlikely(bend < 0))
3247 + sbinfo->si_bend = 0;
3250 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3251 + aufs_bindex_t bend, aufs_bindex_t amount)
3253 + struct au_hdentry *hdp;
3255 + AuRwMustWriteLock(&dinfo->di_rwsem);
3257 + hdp = dinfo->di_hdentry + bindex;
3258 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3259 + au_h_dentry_init(hdp);
3261 + if (unlikely(bend < 0))
3262 + dinfo->di_bstart = 0;
3265 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3266 + aufs_bindex_t bend, aufs_bindex_t amount)
3268 + struct au_hinode *hip;
3270 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3272 + hip = iinfo->ii_hinode + bindex;
3273 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3274 + hip->hi_inode = NULL;
3277 + if (unlikely(bend < 0))
3278 + iinfo->ii_bstart = 0;
3281 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3282 + aufs_bindex_t bindex)
3284 + struct dentry *root, *h_dentry;
3285 + struct inode *root_inode, *h_inode;
3286 + aufs_bindex_t bend, amount;
3288 + root = sb->s_root;
3289 + root_inode = d_inode(root);
3290 + bend = au_sbend(sb);
3291 + amount = bend + 1 - bindex;
3292 + h_dentry = au_br_dentry(br);
3293 + au_sbilist_lock();
3294 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3295 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3296 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3297 + au_set_h_dptr(root, bindex, dget(h_dentry));
3298 + h_inode = d_inode(h_dentry);
3299 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3300 + au_sbilist_unlock();
3303 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3306 + aufs_bindex_t bend, add_bindex;
3307 + struct dentry *root, *h_dentry;
3308 + struct inode *root_inode;
3309 + struct au_branch *add_branch;
3311 + root = sb->s_root;
3312 + root_inode = d_inode(root);
3313 + IMustLock(root_inode);
3314 + err = test_add(sb, add, remount);
3315 + if (unlikely(err < 0))
3319 + goto out; /* success */
3322 + bend = au_sbend(sb);
3323 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3324 + err = PTR_ERR(add_branch);
3325 + if (IS_ERR(add_branch))
3328 + err = au_br_init(add_branch, sb, add);
3329 + if (unlikely(err)) {
3330 + au_br_do_free(add_branch);
3334 + add_bindex = add->bindex;
3336 + au_br_do_add(sb, add_branch, add_bindex);
3338 + sysaufs_brs_del(sb, add_bindex);
3339 + au_br_do_add(sb, add_branch, add_bindex);
3340 + sysaufs_brs_add(sb, add_bindex);
3343 + h_dentry = add->path.dentry;
3344 + if (!add_bindex) {
3345 + au_cpup_attr_all(root_inode, /*force*/1);
3346 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3348 + au_add_nlink(root_inode, d_inode(h_dentry));
3351 + * this test/set prevents aufs from handling unnecesary notify events
3352 + * of xino files, in case of re-adding a writable branch which was
3353 + * once detached from aufs.
3355 + if (au_xino_brid(sb) < 0
3356 + && au_br_writable(add_branch->br_perm)
3357 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3358 + && add_branch->br_xino.xi_file
3359 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3360 + au_xino_brid_set(sb, add_branch->br_id);
3366 +/* ---------------------------------------------------------------------- */
3368 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3369 + unsigned long long max __maybe_unused,
3372 + unsigned long long n;
3373 + struct file **p, *f;
3374 + struct au_sphlhead *files;
3375 + struct au_finfo *finfo;
3379 + files = &au_sbi(sb)->si_files;
3380 + spin_lock(&files->spin);
3381 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3382 + f = finfo->fi_file;
3384 + && !special_file(file_inode(f)->i_mode)) {
3388 + AuDebugOn(n > max);
3391 + spin_unlock(&files->spin);
3396 +static struct file **au_farray_alloc(struct super_block *sb,
3397 + unsigned long long *max)
3399 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3400 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3403 +static void au_farray_free(struct file **a, unsigned long long max)
3405 + unsigned long long ull;
3407 + for (ull = 0; ull < max; ull++)
3413 +/* ---------------------------------------------------------------------- */
3419 +/* to show the line number, do not make it inlined function */
3420 +#define AuVerbose(do_info, fmt, ...) do { \
3422 + pr_info(fmt, ##__VA_ARGS__); \
3425 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3426 + aufs_bindex_t bend)
3428 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3431 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3432 + aufs_bindex_t bend)
3434 + return au_test_ibusy(d_inode(dentry), bstart, bend);
3438 + * test if the branch is deletable or not.
3440 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3441 + unsigned int sigen, const unsigned int verbose)
3443 + int err, i, j, ndentry;
3444 + aufs_bindex_t bstart, bend;
3445 + struct au_dcsub_pages dpages;
3446 + struct au_dpage *dpage;
3449 + err = au_dpages_init(&dpages, GFP_NOFS);
3450 + if (unlikely(err))
3452 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3453 + if (unlikely(err))
3456 + for (i = 0; !err && i < dpages.ndpage; i++) {
3457 + dpage = dpages.dpages + i;
3458 + ndentry = dpage->ndentry;
3459 + for (j = 0; !err && j < ndentry; j++) {
3460 + d = dpage->dentries[j];
3461 + AuDebugOn(au_dcount(d) <= 0);
3462 + if (!au_digen_test(d, sigen)) {
3463 + di_read_lock_child(d, AuLock_IR);
3464 + if (unlikely(au_dbrange_test(d))) {
3465 + di_read_unlock(d, AuLock_IR);
3469 + di_write_lock_child(d);
3470 + if (unlikely(au_dbrange_test(d))) {
3471 + di_write_unlock(d);
3474 + err = au_reval_dpath(d, sigen);
3476 + di_downgrade_lock(d, AuLock_IR);
3478 + di_write_unlock(d);
3483 + /* AuDbgDentry(d); */
3484 + bstart = au_dbstart(d);
3485 + bend = au_dbend(d);
3486 + if (bstart <= bindex
3488 + && au_h_dptr(d, bindex)
3489 + && au_test_dbusy(d, bstart, bend)) {
3491 + AuVerbose(verbose, "busy %pd\n", d);
3494 + di_read_unlock(d, AuLock_IR);
3499 + au_dpages_free(&dpages);
3504 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3505 + unsigned int sigen, const unsigned int verbose)
3508 + unsigned long long max, ull;
3509 + struct inode *i, **array;
3510 + aufs_bindex_t bstart, bend;
3512 + array = au_iarray_alloc(sb, &max);
3513 + err = PTR_ERR(array);
3514 + if (IS_ERR(array))
3518 + AuDbg("b%d\n", bindex);
3519 + for (ull = 0; !err && ull < max; ull++) {
3523 + if (i->i_ino == AUFS_ROOT_INO)
3526 + /* AuDbgInode(i); */
3527 + if (au_iigen(i, NULL) == sigen)
3528 + ii_read_lock_child(i);
3530 + ii_write_lock_child(i);
3531 + err = au_refresh_hinode_self(i);
3534 + ii_downgrade_lock(i);
3536 + ii_write_unlock(i);
3541 + bstart = au_ibstart(i);
3542 + bend = au_ibend(i);
3543 + if (bstart <= bindex
3545 + && au_h_iptr(i, bindex)
3546 + && au_test_ibusy(i, bstart, bend)) {
3548 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3551 + ii_read_unlock(i);
3553 + au_iarray_free(array, max);
3559 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3560 + const unsigned int verbose)
3563 + unsigned int sigen;
3565 + sigen = au_sigen(root->d_sb);
3566 + DiMustNoWaiters(root);
3567 + IiMustNoWaiters(d_inode(root));
3568 + di_write_unlock(root);
3569 + err = test_dentry_busy(root, bindex, sigen, verbose);
3571 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3572 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3577 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3578 + struct file **to_free, int *idx)
3581 + unsigned char matched, root;
3582 + aufs_bindex_t bindex, bend;
3583 + struct au_fidir *fidir;
3584 + struct au_hfile *hfile;
3587 + root = IS_ROOT(file->f_path.dentry);
3590 + to_free[*idx] = file;
3596 + fidir = au_fi(file)->fi_hdir;
3597 + AuDebugOn(!fidir);
3598 + bend = au_fbend_dir(file);
3599 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3600 + hfile = fidir->fd_hfile + bindex;
3601 + if (!hfile->hf_file)
3604 + if (hfile->hf_br->br_id == br_id) {
3616 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3617 + struct file **to_free, int opened)
3620 + unsigned long long ull, max;
3621 + aufs_bindex_t bstart;
3622 + struct file *file, **array;
3623 + struct dentry *root;
3624 + struct au_hfile *hfile;
3626 + array = au_farray_alloc(sb, &max);
3627 + err = PTR_ERR(array);
3628 + if (IS_ERR(array))
3633 + root = sb->s_root;
3634 + di_write_unlock(root);
3635 + for (ull = 0; ull < max; ull++) {
3636 + file = array[ull];
3637 + if (unlikely(!file))
3640 + /* AuDbg("%pD\n", file); */
3641 + fi_read_lock(file);
3642 + bstart = au_fbstart(file);
3643 + if (!d_is_dir(file->f_path.dentry)) {
3644 + hfile = &au_fi(file)->fi_htop;
3645 + if (hfile->hf_br->br_id == br_id)
3648 + err = test_dir_busy(file, br_id, to_free, &idx);
3649 + fi_read_unlock(file);
3650 + if (unlikely(err))
3653 + di_write_lock_child(root);
3654 + au_farray_free(array, max);
3655 + AuDebugOn(idx > opened);
3661 +static void br_del_file(struct file **to_free, unsigned long long opened,
3662 + aufs_bindex_t br_id)
3664 + unsigned long long ull;
3665 + aufs_bindex_t bindex, bstart, bend, bfound;
3666 + struct file *file;
3667 + struct au_fidir *fidir;
3668 + struct au_hfile *hfile;
3670 + for (ull = 0; ull < opened; ull++) {
3671 + file = to_free[ull];
3672 + if (unlikely(!file))
3675 + /* AuDbg("%pD\n", file); */
3676 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3678 + fidir = au_fi(file)->fi_hdir;
3679 + AuDebugOn(!fidir);
3680 + fi_write_lock(file);
3681 + bstart = au_fbstart(file);
3682 + bend = au_fbend_dir(file);
3683 + for (bindex = bstart; bindex <= bend; bindex++) {
3684 + hfile = fidir->fd_hfile + bindex;
3685 + if (!hfile->hf_file)
3688 + if (hfile->hf_br->br_id == br_id) {
3693 + AuDebugOn(bfound < 0);
3694 + au_set_h_fptr(file, bfound, NULL);
3695 + if (bfound == bstart) {
3696 + for (bstart++; bstart <= bend; bstart++)
3697 + if (au_hf_dir(file, bstart)) {
3698 + au_set_fbstart(file, bstart);
3702 + fi_write_unlock(file);
3706 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3707 + const aufs_bindex_t bindex,
3708 + const aufs_bindex_t bend)
3710 + struct au_branch **brp, **p;
3712 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3714 + brp = sbinfo->si_branch + bindex;
3715 + if (bindex < bend)
3716 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3717 + sbinfo->si_branch[0 + bend] = NULL;
3718 + sbinfo->si_bend--;
3720 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3722 + sbinfo->si_branch = p;
3723 + /* harmless error */
3726 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3727 + const aufs_bindex_t bend)
3729 + struct au_hdentry *hdp, *p;
3731 + AuRwMustWriteLock(&dinfo->di_rwsem);
3733 + hdp = dinfo->di_hdentry;
3734 + if (bindex < bend)
3735 + memmove(hdp + bindex, hdp + bindex + 1,
3736 + sizeof(*hdp) * (bend - bindex));
3737 + hdp[0 + bend].hd_dentry = NULL;
3740 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3742 + dinfo->di_hdentry = p;
3743 + /* harmless error */
3746 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3747 + const aufs_bindex_t bend)
3749 + struct au_hinode *hip, *p;
3751 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3753 + hip = iinfo->ii_hinode + bindex;
3754 + if (bindex < bend)
3755 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3756 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3757 + au_hn_init(iinfo->ii_hinode + bend);
3760 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3762 + iinfo->ii_hinode = p;
3763 + /* harmless error */
3766 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3767 + struct au_branch *br)
3769 + aufs_bindex_t bend;
3770 + struct au_sbinfo *sbinfo;
3771 + struct dentry *root, *h_root;
3772 + struct inode *inode, *h_inode;
3773 + struct au_hinode *hinode;
3775 + SiMustWriteLock(sb);
3777 + root = sb->s_root;
3778 + inode = d_inode(root);
3779 + sbinfo = au_sbi(sb);
3780 + bend = sbinfo->si_bend;
3782 + h_root = au_h_dptr(root, bindex);
3783 + hinode = au_hi(inode, bindex);
3784 + h_inode = au_igrab(hinode->hi_inode);
3787 + au_sbilist_lock();
3788 + au_br_do_del_brp(sbinfo, bindex, bend);
3789 + au_br_do_del_hdp(au_di(root), bindex, bend);
3790 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3791 + au_sbilist_unlock();
3795 + au_br_do_free(br);
3798 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3799 + unsigned long long max, void *arg)
3804 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3807 + unsigned long long opened;
3808 + unsigned int mnt_flags;
3809 + aufs_bindex_t bindex, bend, br_id;
3810 + unsigned char do_wh, verbose;
3811 + struct au_branch *br;
3812 + struct au_wbr *wbr;
3813 + struct dentry *root;
3814 + struct file **to_free;
3819 + root = sb->s_root;
3820 + bindex = au_find_dbindex(root, del->h_path.dentry);
3823 + goto out; /* success */
3825 + pr_err("%s no such branch\n", del->pathname);
3828 + AuDbg("bindex b%d\n", bindex);
3831 + mnt_flags = au_mntflags(sb);
3832 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3833 + bend = au_sbend(sb);
3834 + if (unlikely(!bend)) {
3835 + AuVerbose(verbose, "no more branches left\n");
3838 + br = au_sbr(sb, bindex);
3839 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3841 + br_id = br->br_id;
3842 + opened = atomic_read(&br->br_count);
3843 + if (unlikely(opened)) {
3844 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3845 + err = PTR_ERR(to_free);
3846 + if (IS_ERR(to_free))
3849 + err = test_file_busy(sb, br_id, to_free, opened);
3850 + if (unlikely(err)) {
3851 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3857 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3859 + /* instead of WbrWhMustWriteLock(wbr) */
3860 + SiMustWriteLock(sb);
3861 + for (i = 0; i < AuBrWh_Last; i++) {
3862 + dput(wbr->wbr_wh[i]);
3863 + wbr->wbr_wh[i] = NULL;
3867 + err = test_children_busy(root, bindex, verbose);
3868 + if (unlikely(err)) {
3877 + * now we confirmed the branch is deletable.
3878 + * let's free the remaining opened dirs on the branch.
3880 + di_write_unlock(root);
3881 + br_del_file(to_free, opened, br_id);
3882 + di_write_lock_child(root);
3886 + au_br_do_del(sb, bindex, br);
3888 + sysaufs_brs_del(sb, bindex);
3889 + au_br_do_del(sb, bindex, br);
3890 + sysaufs_brs_add(sb, bindex);
3894 + au_cpup_attr_all(d_inode(root), /*force*/1);
3895 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3897 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3898 + if (au_opt_test(mnt_flags, PLINK))
3899 + au_plink_half_refresh(sb, br_id);
3901 + if (au_xino_brid(sb) == br_id)
3902 + au_xino_brid_set(sb, -1);
3903 + goto out; /* success */
3907 + rerr = au_br_init_wh(sb, br, br->br_perm);
3909 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3910 + del->pathname, rerr);
3913 + au_farray_free(to_free, opened);
3917 +/* ---------------------------------------------------------------------- */
3919 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3922 + aufs_bindex_t bstart, bend;
3923 + struct aufs_ibusy ibusy;
3924 + struct inode *inode, *h_inode;
3927 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3930 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3932 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3933 + if (unlikely(err)) {
3940 + si_read_lock(sb, AuLock_FLUSH);
3941 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3945 + ibusy.h_ino = 0; /* invalid */
3946 + inode = ilookup(sb, ibusy.ino);
3948 + || inode->i_ino == AUFS_ROOT_INO
3949 + || is_bad_inode(inode))
3952 + ii_read_lock_child(inode);
3953 + bstart = au_ibstart(inode);
3954 + bend = au_ibend(inode);
3955 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3956 + h_inode = au_h_iptr(inode, ibusy.bindex);
3957 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3958 + ibusy.h_ino = h_inode->i_ino;
3960 + ii_read_unlock(inode);
3964 + si_read_unlock(sb);
3966 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3967 + if (unlikely(err)) {
3976 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3978 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
3981 +#ifdef CONFIG_COMPAT
3982 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3984 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
3988 +/* ---------------------------------------------------------------------- */
3991 + * change a branch permission
3994 +static void au_warn_ima(void)
3997 + /* since it doesn't support mark_files_ro() */
3998 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4002 +static int do_need_sigen_inc(int a, int b)
4004 + return au_br_whable(a) && !au_br_whable(b);
4007 +static int need_sigen_inc(int old, int new)
4009 + return do_need_sigen_inc(old, new)
4010 + || do_need_sigen_inc(new, old);
4013 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4016 + unsigned int mnt_flags;
4017 + unsigned long long ull, max;
4018 + aufs_bindex_t br_id;
4019 + unsigned char verbose, writer;
4020 + struct file *file, *hf, **array;
4021 + struct au_hfile *hfile;
4023 + mnt_flags = au_mntflags(sb);
4024 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4026 + array = au_farray_alloc(sb, &max);
4027 + err = PTR_ERR(array);
4028 + if (IS_ERR(array))
4032 + br_id = au_sbr_id(sb, bindex);
4033 + for (ull = 0; ull < max; ull++) {
4034 + file = array[ull];
4035 + if (unlikely(!file))
4038 + /* AuDbg("%pD\n", file); */
4039 + fi_read_lock(file);
4040 + if (unlikely(au_test_mmapped(file))) {
4042 + AuVerbose(verbose, "mmapped %pD\n", file);
4044 + FiMustNoWaiters(file);
4045 + fi_read_unlock(file);
4049 + hfile = &au_fi(file)->fi_htop;
4050 + hf = hfile->hf_file;
4051 + if (!d_is_reg(file->f_path.dentry)
4052 + || !(file->f_mode & FMODE_WRITE)
4053 + || hfile->hf_br->br_id != br_id
4054 + || !(hf->f_mode & FMODE_WRITE))
4055 + array[ull] = NULL;
4061 + FiMustNoWaiters(file);
4062 + fi_read_unlock(file);
4070 + for (ull = 0; ull < max; ull++) {
4071 + file = array[ull];
4075 + /* todo: already flushed? */
4077 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4078 + * approach which resets f_mode and calls mnt_drop_write() and
4079 + * file_release_write() for each file, because the branch
4080 + * attribute in aufs world is totally different from the native
4083 + /* fi_read_lock(file); */
4084 + hfile = &au_fi(file)->fi_htop;
4085 + hf = hfile->hf_file;
4086 + /* fi_read_unlock(file); */
4087 + spin_lock(&hf->f_lock);
4088 + writer = !!(hf->f_mode & FMODE_WRITER);
4089 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4090 + spin_unlock(&hf->f_lock);
4092 + put_write_access(file_inode(hf));
4093 + __mnt_drop_write(hf->f_path.mnt);
4098 + au_farray_free(array, max);
4104 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4108 + aufs_bindex_t bindex;
4109 + struct dentry *root;
4110 + struct au_branch *br;
4111 + struct au_br_fhsm *bf;
4113 + root = sb->s_root;
4114 + bindex = au_find_dbindex(root, mod->h_root);
4117 + return 0; /* success */
4119 + pr_err("%s no such branch\n", mod->path);
4122 + AuDbg("bindex b%d\n", bindex);
4124 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4125 + if (unlikely(err))
4128 + br = au_sbr(sb, bindex);
4129 + AuDebugOn(mod->h_root != au_br_dentry(br));
4130 + if (br->br_perm == mod->perm)
4131 + return 0; /* success */
4133 + /* pre-allocate for non-fhsm --> fhsm */
4135 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4136 + err = au_fhsm_br_alloc(br);
4137 + if (unlikely(err))
4140 + br->br_fhsm = NULL;
4143 + if (au_br_writable(br->br_perm)) {
4144 + /* remove whiteout base */
4145 + err = au_br_init_wh(sb, br, mod->perm);
4146 + if (unlikely(err))
4149 + if (!au_br_writable(mod->perm)) {
4150 + /* rw --> ro, file might be mmapped */
4151 + DiMustNoWaiters(root);
4152 + IiMustNoWaiters(d_inode(root));
4153 + di_write_unlock(root);
4154 + err = au_br_mod_files_ro(sb, bindex);
4155 + /* aufs_write_lock() calls ..._child() */
4156 + di_write_lock_child(root);
4158 + if (unlikely(err)) {
4160 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4163 + rerr = au_wbr_init(br, sb, br->br_perm);
4164 + if (unlikely(rerr)) {
4165 + AuIOErr("nested error %d (%d)\n",
4167 + br->br_perm = mod->perm;
4171 + } else if (au_br_writable(mod->perm)) {
4174 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4176 + err = au_wbr_init(br, sb, mod->perm);
4177 + if (unlikely(err)) {
4178 + kfree(br->br_wbr);
4179 + br->br_wbr = NULL;
4183 + if (unlikely(err))
4186 + if (au_br_fhsm(br->br_perm)) {
4187 + if (!au_br_fhsm(mod->perm)) {
4188 + /* fhsm --> non-fhsm */
4189 + au_br_fhsm_fin(br->br_fhsm);
4190 + kfree(br->br_fhsm);
4191 + br->br_fhsm = NULL;
4193 + } else if (au_br_fhsm(mod->perm))
4194 + /* non-fhsm --> fhsm */
4197 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4198 + br->br_perm = mod->perm;
4199 + goto out; /* success */
4208 +/* ---------------------------------------------------------------------- */
4210 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4213 + struct kstatfs kstfs;
4215 + err = vfs_statfs(&br->br_path, &kstfs);
4217 + stfs->f_blocks = kstfs.f_blocks;
4218 + stfs->f_bavail = kstfs.f_bavail;
4219 + stfs->f_files = kstfs.f_files;
4220 + stfs->f_ffree = kstfs.f_ffree;
4225 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4226 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4227 +++ linux/fs/aufs/branch.h 2016-04-24 18:32:51.390353525 +0200
4230 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4232 + * This program, aufs is free software; you can redistribute it and/or modify
4233 + * it under the terms of the GNU General Public License as published by
4234 + * the Free Software Foundation; either version 2 of the License, or
4235 + * (at your option) any later version.
4237 + * This program is distributed in the hope that it will be useful,
4238 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4239 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4240 + * GNU General Public License for more details.
4242 + * You should have received a copy of the GNU General Public License
4243 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4247 + * branch filesystems and xino for them
4250 +#ifndef __AUFS_BRANCH_H__
4251 +#define __AUFS_BRANCH_H__
4255 +#include <linux/mount.h>
4260 +/* ---------------------------------------------------------------------- */
4263 +struct au_xino_file {
4264 + struct file *xi_file;
4265 + struct mutex xi_nondir_mtx;
4267 + /* todo: make xino files an array to support huge inode number */
4269 +#ifdef CONFIG_DEBUG_FS
4270 + struct dentry *xi_dbgaufs;
4274 +/* File-based Hierarchical Storage Management */
4275 +struct au_br_fhsm {
4276 +#ifdef CONFIG_AUFS_FHSM
4277 + struct mutex bf_lock;
4278 + unsigned long bf_jiffy;
4279 + struct aufs_stfs bf_stfs;
4284 +/* members for writable branch only */
4285 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4287 + struct au_rwsem wbr_wh_rwsem;
4288 + struct dentry *wbr_wh[AuBrWh_Last];
4289 + atomic_t wbr_wh_running;
4290 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4291 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4292 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4295 + unsigned long long wbr_bytes;
4298 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4299 +#define AuBrDynOp (AuDyLast * 4)
4301 +#ifdef CONFIG_AUFS_HFSNOTIFY
4302 +/* support for asynchronous destruction */
4303 +struct au_br_hfsnotify {
4304 + struct fsnotify_group *hfsn_group;
4308 +/* sysfs entries */
4309 +struct au_brsysfs {
4311 + struct attribute attr;
4320 +/* protected by superblock rwsem */
4322 + struct au_xino_file br_xino;
4324 + aufs_bindex_t br_id;
4327 + struct path br_path;
4328 + spinlock_t br_dykey_lock;
4329 + struct au_dykey *br_dykey[AuBrDynOp];
4330 + atomic_t br_count;
4332 + struct au_wbr *br_wbr;
4333 + struct au_br_fhsm *br_fhsm;
4335 + /* xino truncation */
4336 + atomic_t br_xino_running;
4338 +#ifdef CONFIG_AUFS_HFSNOTIFY
4339 + struct au_br_hfsnotify *br_hfsn;
4342 +#ifdef CONFIG_SYSFS
4343 + /* entries under sysfs per mount-point */
4344 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4348 +/* ---------------------------------------------------------------------- */
4350 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4352 + return br->br_path.mnt;
4355 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4357 + return br->br_path.dentry;
4360 +static inline struct super_block *au_br_sb(struct au_branch *br)
4362 + return au_br_mnt(br)->mnt_sb;
4365 +static inline int au_br_rdonly(struct au_branch *br)
4367 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4368 + || !au_br_writable(br->br_perm))
4372 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4374 +#ifdef CONFIG_AUFS_HNOTIFY
4375 + return !(brperm & AuBrPerm_RR);
4381 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4383 + int err, exec_flag;
4386 + exec_flag = oflag & __FMODE_EXEC;
4387 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4393 +/* ---------------------------------------------------------------------- */
4397 +void au_br_free(struct au_sbinfo *sinfo);
4398 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4400 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4402 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4403 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4404 +#ifdef CONFIG_COMPAT
4405 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4408 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4411 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4414 +static const loff_t au_loff_max = LLONG_MAX;
4416 +int au_xib_trunc(struct super_block *sb);
4417 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4419 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4420 + size_t size, loff_t *pos);
4421 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4422 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4423 +ino_t au_xino_new_ino(struct super_block *sb);
4424 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4425 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4427 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4429 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4430 + struct file *base_file, int do_test);
4431 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4433 +struct au_opt_xino;
4434 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4435 +void au_xino_clr(struct super_block *sb);
4436 +struct file *au_xino_def(struct super_block *sb);
4437 +int au_xino_path(struct seq_file *seq, struct file *file);
4439 +/* ---------------------------------------------------------------------- */
4441 +/* Superblock to branch */
4443 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4445 + return au_sbr(sb, bindex)->br_id;
4449 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4451 + return au_br_mnt(au_sbr(sb, bindex));
4455 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4457 + return au_br_sb(au_sbr(sb, bindex));
4460 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4462 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4465 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4467 + return au_sbr(sb, bindex)->br_perm;
4470 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4472 + return au_br_whable(au_sbr_perm(sb, bindex));
4475 +/* ---------------------------------------------------------------------- */
4478 + * wbr_wh_read_lock, wbr_wh_write_lock
4479 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4481 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4483 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4484 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4485 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4487 +/* ---------------------------------------------------------------------- */
4489 +#ifdef CONFIG_AUFS_FHSM
4490 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4492 + mutex_init(&brfhsm->bf_lock);
4493 + brfhsm->bf_jiffy = 0;
4494 + brfhsm->bf_readable = 0;
4497 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4499 + mutex_destroy(&brfhsm->bf_lock);
4502 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4503 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4506 +#endif /* __KERNEL__ */
4507 +#endif /* __AUFS_BRANCH_H__ */
4508 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4509 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4510 +++ linux/fs/aufs/conf.mk 2016-04-24 18:32:51.390353525 +0200
4513 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4517 +AuConfStr += ${1}=${${1}}
4521 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4523 + HNOTIFY HFSNOTIFY \
4534 +$(foreach i, ${AuConfAll}, \
4535 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4537 +AuConfName = ${obj}/conf.str
4538 +${AuConfName}.tmp: FORCE
4539 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4540 +${AuConfName}: ${AuConfName}.tmp
4541 + @diff -q $< $@ > /dev/null 2>&1 || { \
4542 + echo ' GEN ' $@; \
4546 +clean-files += ${AuConfName} ${AuConfName}.tmp
4547 +${obj}/sysfs.o: ${AuConfName}
4549 +-include ${srctree}/${src}/conf_priv.mk
4550 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4551 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4552 +++ linux/fs/aufs/cpup.c 2016-04-24 18:32:51.390353525 +0200
4555 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4557 + * This program, aufs is free software; you can redistribute it and/or modify
4558 + * it under the terms of the GNU General Public License as published by
4559 + * the Free Software Foundation; either version 2 of the License, or
4560 + * (at your option) any later version.
4562 + * This program is distributed in the hope that it will be useful,
4563 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4564 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4565 + * GNU General Public License for more details.
4567 + * You should have received a copy of the GNU General Public License
4568 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4572 + * copy-up functions, see wbr_policy.c for copy-down
4575 +#include <linux/fs_stack.h>
4576 +#include <linux/mm.h>
4577 +#include <linux/task_work.h>
4580 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4582 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4583 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4585 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4587 + dst->i_flags |= iflags & ~mask;
4588 + if (au_test_fs_notime(dst->i_sb))
4589 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4592 +void au_cpup_attr_timesizes(struct inode *inode)
4594 + struct inode *h_inode;
4596 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4597 + fsstack_copy_attr_times(inode, h_inode);
4598 + fsstack_copy_inode_size(inode, h_inode);
4601 +void au_cpup_attr_nlink(struct inode *inode, int force)
4603 + struct inode *h_inode;
4604 + struct super_block *sb;
4605 + aufs_bindex_t bindex, bend;
4608 + bindex = au_ibstart(inode);
4609 + h_inode = au_h_iptr(inode, bindex);
4611 + && !S_ISDIR(h_inode->i_mode)
4612 + && au_opt_test(au_mntflags(sb), PLINK)
4613 + && au_plink_test(inode))
4617 + * 0 can happen in revalidating.
4618 + * h_inode->i_mutex may not be held here, but it is harmless since once
4619 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4621 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4622 + * the incorrect link count.
4624 + set_nlink(inode, h_inode->i_nlink);
4627 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4628 + * it may includes whplink directory.
4630 + if (S_ISDIR(h_inode->i_mode)) {
4631 + bend = au_ibend(inode);
4632 + for (bindex++; bindex <= bend; bindex++) {
4633 + h_inode = au_h_iptr(inode, bindex);
4635 + au_add_nlink(inode, h_inode);
4640 +void au_cpup_attr_changeable(struct inode *inode)
4642 + struct inode *h_inode;
4644 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4645 + inode->i_mode = h_inode->i_mode;
4646 + inode->i_uid = h_inode->i_uid;
4647 + inode->i_gid = h_inode->i_gid;
4648 + au_cpup_attr_timesizes(inode);
4649 + au_cpup_attr_flags(inode, h_inode->i_flags);
4652 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4654 + struct au_iinfo *iinfo = au_ii(inode);
4656 + IiMustWriteLock(inode);
4658 + iinfo->ii_higen = h_inode->i_generation;
4659 + iinfo->ii_hsb1 = h_inode->i_sb;
4662 +void au_cpup_attr_all(struct inode *inode, int force)
4664 + struct inode *h_inode;
4666 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4667 + au_cpup_attr_changeable(inode);
4668 + if (inode->i_nlink > 0)
4669 + au_cpup_attr_nlink(inode, force);
4670 + inode->i_rdev = h_inode->i_rdev;
4671 + inode->i_blkbits = h_inode->i_blkbits;
4672 + au_cpup_igen(inode, h_inode);
4675 +/* ---------------------------------------------------------------------- */
4677 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4679 +/* keep the timestamps of the parent dir when cpup */
4680 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4681 + struct path *h_path)
4683 + struct inode *h_inode;
4685 + dt->dt_dentry = dentry;
4686 + dt->dt_h_path = *h_path;
4687 + h_inode = d_inode(h_path->dentry);
4688 + dt->dt_atime = h_inode->i_atime;
4689 + dt->dt_mtime = h_inode->i_mtime;
4693 +void au_dtime_revert(struct au_dtime *dt)
4695 + struct iattr attr;
4698 + attr.ia_atime = dt->dt_atime;
4699 + attr.ia_mtime = dt->dt_mtime;
4700 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4701 + | ATTR_ATIME | ATTR_ATIME_SET;
4703 + /* no delegation since this is a directory */
4704 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4705 + if (unlikely(err))
4706 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4709 +/* ---------------------------------------------------------------------- */
4711 +/* internal use only */
4712 +struct au_cpup_reg_attr {
4715 + unsigned int iflags; /* inode->i_flags */
4718 +static noinline_for_stack
4719 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4720 + struct au_cpup_reg_attr *h_src_attr)
4722 + int err, sbits, icex;
4723 + unsigned int mnt_flags;
4724 + unsigned char verbose;
4726 + struct path h_path;
4727 + struct inode *h_isrc, *h_idst;
4728 + struct kstat *h_st;
4729 + struct au_branch *br;
4731 + h_path.dentry = au_h_dptr(dst, bindex);
4732 + h_idst = d_inode(h_path.dentry);
4733 + br = au_sbr(dst->d_sb, bindex);
4734 + h_path.mnt = au_br_mnt(br);
4735 + h_isrc = d_inode(h_src);
4736 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4737 + | ATTR_ATIME | ATTR_MTIME
4738 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4739 + if (h_src_attr && h_src_attr->valid) {
4740 + h_st = &h_src_attr->st;
4741 + ia.ia_uid = h_st->uid;
4742 + ia.ia_gid = h_st->gid;
4743 + ia.ia_atime = h_st->atime;
4744 + ia.ia_mtime = h_st->mtime;
4745 + if (h_idst->i_mode != h_st->mode
4746 + && !S_ISLNK(h_idst->i_mode)) {
4747 + ia.ia_valid |= ATTR_MODE;
4748 + ia.ia_mode = h_st->mode;
4750 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4751 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4753 + ia.ia_uid = h_isrc->i_uid;
4754 + ia.ia_gid = h_isrc->i_gid;
4755 + ia.ia_atime = h_isrc->i_atime;
4756 + ia.ia_mtime = h_isrc->i_mtime;
4757 + if (h_idst->i_mode != h_isrc->i_mode
4758 + && !S_ISLNK(h_idst->i_mode)) {
4759 + ia.ia_valid |= ATTR_MODE;
4760 + ia.ia_mode = h_isrc->i_mode;
4762 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4763 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4765 + /* no delegation since it is just created */
4766 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4768 + /* is this nfs only? */
4769 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4770 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4771 + ia.ia_mode = h_isrc->i_mode;
4772 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4775 + icex = br->br_perm & AuBrAttr_ICEX;
4777 + mnt_flags = au_mntflags(dst->d_sb);
4778 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4779 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4785 +/* ---------------------------------------------------------------------- */
4787 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4788 + char *buf, unsigned long blksize)
4791 + size_t sz, rbytes, wbytes;
4792 + unsigned char all_zero;
4794 + struct inode *h_inode;
4795 + /* reduce stack usage */
4798 + zp = page_address(ZERO_PAGE(0));
4799 + if (unlikely(!zp))
4800 + return -ENOMEM; /* possible? */
4805 + AuDbg("len %lld\n", len);
4807 + if (len < blksize)
4811 + /* todo: signal_pending? */
4812 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4813 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4816 + if (unlikely(err < 0))
4820 + if (len >= rbytes && rbytes == blksize)
4821 + all_zero = !memcmp(buf, zp, rbytes);
4828 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4830 + /* todo: signal_pending? */
4831 + if (unlikely(err == -EAGAIN || err == -EINTR))
4833 + if (unlikely(err < 0))
4838 + if (unlikely(err < 0))
4844 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4846 + if (unlikely(res < 0))
4853 + /* the last block may be a hole */
4854 + if (!err && all_zero) {
4855 + AuLabel(last hole);
4858 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4859 + /* nfs requires this step to make last hole */
4860 + /* is this only nfs? */
4862 + /* todo: signal_pending? */
4863 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4864 + } while (err == -EAGAIN || err == -EINTR);
4871 + ia->ia_size = dst->f_pos;
4872 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4873 + ia->ia_file = dst;
4874 + h_inode = file_inode(dst);
4875 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
4876 + /* no delegation since it is just created */
4877 + err = vfsub_notify_change(&dst->f_path, ia,
4878 + /*delegated*/NULL);
4879 + inode_unlock(h_inode);
4886 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4889 + unsigned long blksize;
4890 + unsigned char do_kfree;
4894 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4895 + if (!blksize || PAGE_SIZE < blksize)
4896 + blksize = PAGE_SIZE;
4897 + AuDbg("blksize %lu\n", blksize);
4898 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4900 + buf = kmalloc(blksize, GFP_NOFS);
4902 + buf = (void *)__get_free_page(GFP_NOFS);
4903 + if (unlikely(!buf))
4906 + if (len > (1 << 22))
4907 + AuDbg("copying a large file %lld\n", (long long)len);
4911 + err = au_do_copy_file(dst, src, len, buf, blksize);
4915 + free_page((unsigned long)buf);
4922 + * to support a sparse file which is opened with O_APPEND,
4923 + * we need to close the file.
4925 +static int au_cp_regular(struct au_cp_generic *cpg)
4928 + enum { SRC, DST };
4930 + aufs_bindex_t bindex;
4931 + unsigned int flags;
4932 + struct dentry *dentry;
4934 + struct file *file;
4938 + .bindex = cpg->bsrc,
4939 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4943 + .bindex = cpg->bdst,
4944 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4945 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4946 + .label = &&out_src
4949 + struct super_block *sb;
4950 + struct task_struct *tsk = current;
4952 + /* bsrc branch can be ro/rw. */
4953 + sb = cpg->dentry->d_sb;
4955 + for (i = 0; i < 2; i++, f++) {
4956 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4957 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4958 + /*file*/NULL, f->force_wr);
4959 + err = PTR_ERR(f->file);
4960 + if (IS_ERR(f->file))
4964 + /* try stopping to update while we copyup */
4965 + IMustLock(d_inode(file[SRC].dentry));
4966 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4968 + /* i wonder if we had O_NO_DELAY_FPUT flag */
4969 + if (tsk->flags & PF_KTHREAD)
4970 + __fput_sync(file[DST].file);
4972 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
4974 + fput(file[DST].file);
4977 + * we have to call both since we don't know which place the file
4981 + flush_delayed_fput();
4983 + au_sbr_put(sb, file[DST].bindex);
4986 + fput(file[SRC].file);
4987 + au_sbr_put(sb, file[SRC].bindex);
4992 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4993 + struct au_cpup_reg_attr *h_src_attr)
4997 + struct path h_path;
4998 + struct inode *h_src_inode, *h_dst_inode;
5001 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5002 + l = i_size_read(h_src_inode);
5003 + if (cpg->len == -1 || l < cpg->len)
5006 + /* try stopping to update while we are referencing */
5007 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5008 + au_pin_hdir_unlock(cpg->pin);
5010 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5011 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5012 + h_src_attr->iflags = h_src_inode->i_flags;
5013 + if (!au_test_nfs(h_src_inode->i_sb))
5014 + err = vfs_getattr(&h_path, &h_src_attr->st);
5016 + inode_unlock(h_src_inode);
5017 + err = vfs_getattr(&h_path, &h_src_attr->st);
5018 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5020 + if (unlikely(err)) {
5021 + inode_unlock(h_src_inode);
5024 + h_src_attr->valid = 1;
5025 + err = au_cp_regular(cpg);
5026 + inode_unlock(h_src_inode);
5027 + rerr = au_pin_hdir_relock(cpg->pin);
5031 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5032 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5033 + h_dst_inode = d_inode(h_path.dentry);
5034 + spin_lock(&h_dst_inode->i_lock);
5035 + h_dst_inode->i_state |= I_LINKABLE;
5036 + spin_unlock(&h_dst_inode->i_lock);
5043 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5044 + struct inode *h_dir)
5047 + mm_segment_t old_fs;
5052 + struct inode *h_inode = d_inode(h_src);
5053 + const struct inode_operations *h_iop = h_inode->i_op;
5056 + if (unlikely(!h_iop->readlink))
5060 + sym.k = (void *)__get_free_page(GFP_NOFS);
5061 + if (unlikely(!sym.k))
5064 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5065 + old_fs = get_fs();
5066 + set_fs(KERNEL_DS);
5067 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
5072 + sym.k[symlen] = 0;
5073 + err = vfsub_symlink(h_dir, h_path, sym.k);
5075 + free_page((unsigned long)sym.k);
5082 + * regardless 'acl' option, reset all ACL.
5083 + * All ACL will be copied up later from the original entry on the lower branch.
5085 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5088 + struct dentry *h_dentry;
5089 + struct inode *h_inode;
5091 + h_dentry = h_path->dentry;
5092 + h_inode = d_inode(h_dentry);
5093 + /* forget_all_cached_acls(h_inode)); */
5094 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5096 + if (err == -EOPNOTSUPP)
5099 + err = vfsub_acl_chmod(h_inode, mode);
5105 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5106 + struct inode *h_dir, struct path *h_path)
5109 + struct inode *dir, *inode;
5111 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5113 + if (err == -EOPNOTSUPP)
5115 + if (unlikely(err))
5119 + * strange behaviour from the users view,
5120 + * particularry setattr case
5122 + dir = d_inode(dst_parent);
5123 + if (au_ibstart(dir) == cpg->bdst)
5124 + au_cpup_attr_nlink(dir, /*force*/1);
5125 + inode = d_inode(cpg->dentry);
5126 + au_cpup_attr_nlink(inode, /*force*/1);
5132 +static noinline_for_stack
5133 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5134 + struct au_cpup_reg_attr *h_src_attr)
5138 + unsigned int mnt_flags;
5139 + unsigned char isdir, isreg, force;
5140 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5141 + struct au_dtime dt;
5142 + struct path h_path;
5143 + struct dentry *h_src, *h_dst, *h_parent;
5144 + struct inode *h_inode, *h_dir;
5145 + struct super_block *sb;
5147 + /* bsrc branch can be ro/rw. */
5148 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5149 + h_inode = d_inode(h_src);
5150 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5152 + /* try stopping to be referenced while we are creating */
5153 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5154 + if (au_ftest_cpup(cpg->flags, RENAME))
5155 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5156 + AUFS_WH_PFX_LEN));
5157 + h_parent = h_dst->d_parent; /* dir inode is locked */
5158 + h_dir = d_inode(h_parent);
5160 + AuDebugOn(h_parent != h_dst->d_parent);
5162 + sb = cpg->dentry->d_sb;
5163 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5165 + h_path.dentry = h_parent;
5166 + au_dtime_store(&dt, dst_parent, &h_path);
5168 + h_path.dentry = h_dst;
5172 + mode = h_inode->i_mode;
5173 + switch (mode & S_IFMT) {
5176 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5177 + /*want_excl*/true);
5179 + err = au_do_cpup_regular(cpg, h_src_attr);
5183 + err = vfsub_mkdir(h_dir, &h_path, mode);
5185 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5188 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5192 + AuDebugOn(!capable(CAP_MKNOD));
5196 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5199 + AuIOErr("Unknown inode type 0%o\n", mode);
5203 + err = au_reset_acl(h_dir, &h_path, mode);
5205 + mnt_flags = au_mntflags(sb);
5206 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5208 + && au_opt_test(mnt_flags, XINO)
5209 + && (h_inode->i_nlink == 1
5210 + || (h_inode->i_state & I_LINKABLE))
5211 + /* todo: unnecessary? */
5212 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5213 + && cpg->bdst < cpg->bsrc
5214 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5215 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5216 + /* ignore this error */
5221 + force = !!cpg->len;
5222 + if (cpg->len == -1)
5223 + force = !!i_size_read(h_inode);
5225 + au_fhsm_wrote(sb, cpg->bdst, force);
5229 + au_dtime_revert(&dt);
5233 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5236 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5237 + struct inode *h_dir;
5238 + aufs_bindex_t bdst;
5240 + dentry = cpg->dentry;
5242 + h_dentry = au_h_dptr(dentry, bdst);
5243 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5245 + au_set_h_dptr(dentry, bdst, NULL);
5246 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5248 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5249 + au_set_h_dptr(dentry, bdst, h_dentry);
5252 + parent = dget_parent(dentry);
5253 + h_parent = au_h_dptr(parent, bdst);
5255 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5256 + if (IS_ERR(h_path->dentry))
5257 + err = PTR_ERR(h_path->dentry);
5259 + if (unlikely(err))
5262 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5263 + h_dir = d_inode(h_parent);
5265 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5266 + /* no delegation since it is just created */
5267 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5268 + dput(h_path->dentry);
5275 + * copyup the @dentry from @bsrc to @bdst.
5276 + * the caller must set the both of lower dentries.
5277 + * @len is for truncating when it is -1 copyup the entire file.
5278 + * in link/rename cases, @dst_parent may be different from the real one.
5279 + * basic->bsrc can be larger than basic->bdst.
5281 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5284 + aufs_bindex_t old_ibstart;
5285 + unsigned char isdir, plink;
5286 + struct dentry *h_src, *h_dst, *h_parent;
5287 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5288 + struct super_block *sb;
5289 + struct au_branch *br;
5290 + /* to reuduce stack size */
5292 + struct au_dtime dt;
5293 + struct path h_path;
5294 + struct au_cpup_reg_attr h_src_attr;
5298 + a = kmalloc(sizeof(*a), GFP_NOFS);
5301 + a->h_src_attr.valid = 0;
5303 + sb = cpg->dentry->d_sb;
5304 + br = au_sbr(sb, cpg->bdst);
5305 + a->h_path.mnt = au_br_mnt(br);
5306 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5307 + h_parent = h_dst->d_parent; /* dir inode is locked */
5308 + h_dir = d_inode(h_parent);
5311 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5312 + inode = d_inode(cpg->dentry);
5315 + dst_parent = dget_parent(cpg->dentry);
5319 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5320 + dst_inode = au_h_iptr(inode, cpg->bdst);
5322 + if (unlikely(!plink)) {
5324 + AuIOErr("hi%lu(i%lu) exists on b%d "
5325 + "but plink is disabled\n",
5326 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5330 + if (dst_inode->i_nlink) {
5331 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5333 + h_src = au_plink_lkup(inode, cpg->bdst);
5334 + err = PTR_ERR(h_src);
5335 + if (IS_ERR(h_src))
5337 + if (unlikely(d_is_negative(h_src))) {
5339 + AuIOErr("i%lu exists on b%d "
5340 + "but not pseudo-linked\n",
5341 + inode->i_ino, cpg->bdst);
5347 + a->h_path.dentry = h_parent;
5348 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5351 + a->h_path.dentry = h_dst;
5353 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5354 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5355 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5357 + au_dtime_revert(&a->dt);
5358 + if (unlikely(err == -EWOULDBLOCK)) {
5359 + pr_warn("cannot retry for NFSv4 delegation"
5360 + " for an internal link\n");
5366 + /* todo: cpup_wh_file? */
5368 + au_update_ibrange(inode, /*do_put_zero*/1);
5371 + isdir = S_ISDIR(inode->i_mode);
5372 + old_ibstart = au_ibstart(inode);
5373 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5374 + if (unlikely(err))
5376 + dst_inode = d_inode(h_dst);
5377 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5378 + /* todo: necessary? */
5379 + /* au_pin_hdir_unlock(cpg->pin); */
5381 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5382 + if (unlikely(err)) {
5383 + /* todo: necessary? */
5384 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5385 + inode_unlock(dst_inode);
5389 + if (cpg->bdst < old_ibstart) {
5390 + if (S_ISREG(inode->i_mode)) {
5391 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5392 + if (unlikely(err)) {
5393 + /* ignore an error */
5394 + /* au_pin_hdir_relock(cpg->pin); */
5395 + inode_unlock(dst_inode);
5399 + au_set_ibstart(inode, cpg->bdst);
5401 + au_set_ibend(inode, cpg->bdst);
5402 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5403 + au_hi_flags(inode, isdir));
5405 + /* todo: necessary? */
5406 + /* err = au_pin_hdir_relock(cpg->pin); */
5407 + inode_unlock(dst_inode);
5408 + if (unlikely(err))
5411 + src_inode = d_inode(h_src);
5413 + && (src_inode->i_nlink > 1
5414 + || src_inode->i_state & I_LINKABLE)
5416 + au_plink_append(inode, cpg->bdst, h_dst);
5418 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5419 + a->h_path.dentry = h_dst;
5420 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5423 + goto out_parent; /* success */
5427 + a->h_path.dentry = h_parent;
5428 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5429 + a->h_path.dentry = h_dst;
5431 + if (d_is_positive(h_dst)) {
5433 + /* no delegation since it is just created */
5434 + rerr = vfsub_unlink(h_dir, &a->h_path,
5435 + /*delegated*/NULL, /*force*/0);
5437 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5439 + au_dtime_revert(&a->dt);
5441 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5451 +#if 0 /* reserved */
5452 +struct au_cpup_single_args {
5454 + struct au_cp_generic *cpg;
5455 + struct dentry *dst_parent;
5458 +static void au_call_cpup_single(void *args)
5460 + struct au_cpup_single_args *a = args;
5462 + au_pin_hdir_acquire_nest(a->cpg->pin);
5463 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5464 + au_pin_hdir_release(a->cpg->pin);
5469 + * prevent SIGXFSZ in copy-up.
5470 + * testing CAP_MKNOD is for generic fs,
5471 + * but CAP_FSETID is for xfs only, currently.
5473 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5476 + struct super_block *sb;
5477 + struct inode *h_dir;
5480 + sb = au_pinned_parent(pin)->d_sb;
5481 + if (!au_wkq_test()
5482 + && (!au_sbi(sb)->si_plink_maint_pid
5483 + || au_plink_maint(sb, AuLock_NOPLM))) {
5484 + switch (mode & S_IFMT) {
5486 + /* no condition about RLIMIT_FSIZE and the file size */
5491 + do_sio = !capable(CAP_MKNOD);
5495 + do_sio = ((mode & (S_ISUID | S_ISGID))
5496 + && !capable(CAP_FSETID));
5497 + /* this workaround may be removed in the future */
5499 + h_dir = au_pinned_h_dir(pin);
5500 + do_sio = h_dir->i_mode & S_ISVTX;
5507 +#if 0 /* reserved */
5508 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5511 + struct dentry *h_dentry;
5513 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5514 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5515 + err = au_cpup_single(cpg, dst_parent);
5517 + struct au_cpup_single_args args = {
5520 + .dst_parent = dst_parent
5522 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5523 + if (unlikely(wkq_err))
5532 + * copyup the @dentry from the first active lower branch to @bdst,
5533 + * using au_cpup_single().
5535 +static int au_cpup_simple(struct au_cp_generic *cpg)
5538 + unsigned int flags_orig;
5539 + struct dentry *dentry;
5541 + AuDebugOn(cpg->bsrc < 0);
5543 + dentry = cpg->dentry;
5544 + DiMustWriteLock(dentry);
5546 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5548 + flags_orig = cpg->flags;
5549 + au_fset_cpup(cpg->flags, RENAME);
5550 + err = au_cpup_single(cpg, NULL);
5551 + cpg->flags = flags_orig;
5553 + return 0; /* success */
5556 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5557 + au_set_dbstart(dentry, cpg->bsrc);
5563 +struct au_cpup_simple_args {
5565 + struct au_cp_generic *cpg;
5568 +static void au_call_cpup_simple(void *args)
5570 + struct au_cpup_simple_args *a = args;
5572 + au_pin_hdir_acquire_nest(a->cpg->pin);
5573 + *a->errp = au_cpup_simple(a->cpg);
5574 + au_pin_hdir_release(a->cpg->pin);
5577 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5580 + struct dentry *dentry, *parent;
5581 + struct file *h_file;
5582 + struct inode *h_dir;
5584 + dentry = cpg->dentry;
5586 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5587 + AuDebugOn(cpg->bsrc < 0);
5588 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5589 + err = PTR_ERR(h_file);
5590 + if (IS_ERR(h_file))
5594 + parent = dget_parent(dentry);
5595 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5596 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5597 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5598 + err = au_cpup_simple(cpg);
5600 + struct au_cpup_simple_args args = {
5604 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5605 + if (unlikely(wkq_err))
5611 + au_h_open_post(dentry, cpg->bsrc, h_file);
5617 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5619 + aufs_bindex_t bsrc, bend;
5620 + struct dentry *dentry, *h_dentry;
5622 + if (cpg->bsrc < 0) {
5623 + dentry = cpg->dentry;
5624 + bend = au_dbend(dentry);
5625 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5626 + h_dentry = au_h_dptr(dentry, bsrc);
5628 + AuDebugOn(d_is_negative(h_dentry));
5632 + AuDebugOn(bsrc > bend);
5635 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5636 + return au_do_sio_cpup_simple(cpg);
5639 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5641 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5642 + return au_do_sio_cpup_simple(cpg);
5645 +/* ---------------------------------------------------------------------- */
5648 + * copyup the deleted file for writing.
5650 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5651 + struct file *file)
5654 + unsigned int flags_orig;
5655 + aufs_bindex_t bsrc_orig;
5656 + struct dentry *h_d_dst, *h_d_start;
5657 + struct au_dinfo *dinfo;
5658 + struct au_hdentry *hdp;
5660 + dinfo = au_di(cpg->dentry);
5661 + AuRwMustWriteLock(&dinfo->di_rwsem);
5663 + bsrc_orig = cpg->bsrc;
5664 + cpg->bsrc = dinfo->di_bstart;
5665 + hdp = dinfo->di_hdentry;
5666 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5667 + dinfo->di_bstart = cpg->bdst;
5668 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5671 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5672 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry;
5674 + flags_orig = cpg->flags;
5675 + cpg->flags = !AuCpup_DTIME;
5676 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5677 + cpg->flags = flags_orig;
5680 + err = au_reopen_nondir(file);
5681 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5683 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5684 + dinfo->di_bstart = cpg->bsrc;
5685 + cpg->bsrc = bsrc_orig;
5690 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5693 + aufs_bindex_t bdst;
5694 + struct au_dtime dt;
5695 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5696 + struct au_branch *br;
5697 + struct path h_path;
5699 + dentry = cpg->dentry;
5701 + br = au_sbr(dentry->d_sb, bdst);
5702 + parent = dget_parent(dentry);
5703 + h_parent = au_h_dptr(parent, bdst);
5704 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5705 + err = PTR_ERR(wh_dentry);
5706 + if (IS_ERR(wh_dentry))
5709 + h_path.dentry = h_parent;
5710 + h_path.mnt = au_br_mnt(br);
5711 + au_dtime_store(&dt, parent, &h_path);
5712 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5713 + if (unlikely(err))
5717 + h_path.dentry = wh_dentry;
5718 + if (!d_is_dir(wh_dentry)) {
5719 + /* no delegation since it is just created */
5720 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5721 + /*delegated*/NULL, /*force*/0);
5723 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5724 + if (unlikely(err)) {
5725 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5729 + au_dtime_revert(&dt);
5730 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5739 +struct au_cpup_wh_args {
5741 + struct au_cp_generic *cpg;
5742 + struct file *file;
5745 +static void au_call_cpup_wh(void *args)
5747 + struct au_cpup_wh_args *a = args;
5749 + au_pin_hdir_acquire_nest(a->cpg->pin);
5750 + *a->errp = au_cpup_wh(a->cpg, a->file);
5751 + au_pin_hdir_release(a->cpg->pin);
5754 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5757 + aufs_bindex_t bdst;
5758 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5759 + struct inode *dir, *h_dir, *h_tmpdir;
5760 + struct au_wbr *wbr;
5761 + struct au_pin wh_pin, *pin_orig;
5763 + dentry = cpg->dentry;
5765 + parent = dget_parent(dentry);
5766 + dir = d_inode(parent);
5769 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5772 + if (!h_dir->i_nlink) {
5773 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5774 + h_orph = wbr->wbr_orph;
5776 + h_parent = dget(au_h_dptr(parent, bdst));
5777 + au_set_h_dptr(parent, bdst, dget(h_orph));
5778 + h_tmpdir = d_inode(h_orph);
5779 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5781 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
5782 + /* todo: au_h_open_pre()? */
5784 + pin_orig = cpg->pin;
5785 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5786 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5787 + cpg->pin = &wh_pin;
5790 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5791 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5792 + err = au_cpup_wh(cpg, file);
5794 + struct au_cpup_wh_args args = {
5799 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5800 + if (unlikely(wkq_err))
5805 + inode_unlock(h_tmpdir);
5806 + /* todo: au_h_open_post()? */
5807 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5808 + au_set_h_dptr(parent, bdst, h_parent);
5809 + AuDebugOn(!pin_orig);
5810 + cpg->pin = pin_orig;
5818 +/* ---------------------------------------------------------------------- */
5821 + * generic routine for both of copy-up and copy-down.
5823 +/* cf. revalidate function in file.c */
5824 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5825 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5826 + struct au_pin *pin,
5827 + struct dentry *h_parent, void *arg),
5831 + struct au_pin pin;
5832 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5835 + parent = dget_parent(dentry);
5836 + if (IS_ROOT(parent))
5839 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5840 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5842 + /* do not use au_dpage */
5843 + real_parent = parent;
5846 + parent = dget_parent(dentry);
5847 + h_parent = au_h_dptr(parent, bdst);
5849 + goto out; /* success */
5851 + /* find top dir which is necessary to cpup */
5855 + parent = dget_parent(d);
5856 + di_read_lock_parent3(parent, !AuLock_IR);
5857 + h_parent = au_h_dptr(parent, bdst);
5858 + di_read_unlock(parent, !AuLock_IR);
5859 + } while (!h_parent);
5861 + if (d != real_parent)
5862 + di_write_lock_child3(d);
5864 + /* somebody else might create while we were sleeping */
5865 + h_dentry = au_h_dptr(d, bdst);
5866 + if (!h_dentry || d_is_negative(h_dentry)) {
5868 + au_update_dbstart(d);
5870 + au_pin_set_dentry(&pin, d);
5871 + err = au_do_pin(&pin);
5873 + err = cp(d, bdst, &pin, h_parent, arg);
5878 + if (d != real_parent)
5879 + di_write_unlock(d);
5880 + if (unlikely(err))
5889 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5890 + struct au_pin *pin,
5891 + struct dentry *h_parent __maybe_unused,
5892 + void *arg __maybe_unused)
5894 + struct au_cp_generic cpg = {
5900 + .flags = AuCpup_DTIME
5902 + return au_sio_cpup_simple(&cpg);
5905 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5907 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5910 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5913 + struct dentry *parent;
5914 + struct inode *dir;
5916 + parent = dget_parent(dentry);
5917 + dir = d_inode(parent);
5919 + if (au_h_iptr(dir, bdst))
5922 + di_read_unlock(parent, AuLock_IR);
5923 + di_write_lock_parent(parent);
5924 + /* someone else might change our inode while we were sleeping */
5925 + if (!au_h_iptr(dir, bdst))
5926 + err = au_cpup_dirs(dentry, bdst);
5927 + di_downgrade_lock(parent, AuLock_IR);
5933 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5934 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5935 +++ linux/fs/aufs/cpup.h 2016-04-24 18:32:51.390353525 +0200
5938 + * Copyright (C) 2005-2016 Junjiro R. Okajima
5940 + * This program, aufs is free software; you can redistribute it and/or modify
5941 + * it under the terms of the GNU General Public License as published by
5942 + * the Free Software Foundation; either version 2 of the License, or
5943 + * (at your option) any later version.
5945 + * This program is distributed in the hope that it will be useful,
5946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5948 + * GNU General Public License for more details.
5950 + * You should have received a copy of the GNU General Public License
5951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5955 + * copy-up/down functions
5958 +#ifndef __AUFS_CPUP_H__
5959 +#define __AUFS_CPUP_H__
5963 +#include <linux/path.h>
5969 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5970 +void au_cpup_attr_timesizes(struct inode *inode);
5971 +void au_cpup_attr_nlink(struct inode *inode, int force);
5972 +void au_cpup_attr_changeable(struct inode *inode);
5973 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5974 +void au_cpup_attr_all(struct inode *inode, int force);
5976 +/* ---------------------------------------------------------------------- */
5978 +struct au_cp_generic {
5979 + struct dentry *dentry;
5980 + aufs_bindex_t bdst, bsrc;
5982 + struct au_pin *pin;
5983 + unsigned int flags;
5987 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5988 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5990 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5991 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5993 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5995 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5996 + the branch is marked as RO */
5998 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5999 +#define au_fset_cpup(flags, name) \
6000 + do { (flags) |= AuCpup_##name; } while (0)
6001 +#define au_fclr_cpup(flags, name) \
6002 + do { (flags) &= ~AuCpup_##name; } while (0)
6004 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6005 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6006 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6007 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6009 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6010 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6011 + struct au_pin *pin,
6012 + struct dentry *h_parent, void *arg),
6014 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6015 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6017 +/* ---------------------------------------------------------------------- */
6019 +/* keep timestamps when copyup */
6021 + struct dentry *dt_dentry;
6022 + struct path dt_h_path;
6023 + struct timespec dt_atime, dt_mtime;
6025 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6026 + struct path *h_path);
6027 +void au_dtime_revert(struct au_dtime *dt);
6029 +#endif /* __KERNEL__ */
6030 +#endif /* __AUFS_CPUP_H__ */
6031 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6032 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6033 +++ linux/fs/aufs/dbgaufs.c 2016-04-24 18:32:51.390353525 +0200
6036 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6038 + * This program, aufs is free software; you can redistribute it and/or modify
6039 + * it under the terms of the GNU General Public License as published by
6040 + * the Free Software Foundation; either version 2 of the License, or
6041 + * (at your option) any later version.
6043 + * This program is distributed in the hope that it will be useful,
6044 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6045 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6046 + * GNU General Public License for more details.
6048 + * You should have received a copy of the GNU General Public License
6049 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6053 + * debugfs interface
6056 +#include <linux/debugfs.h>
6059 +#ifndef CONFIG_SYSFS
6060 +#error DEBUG_FS depends upon SYSFS
6063 +static struct dentry *dbgaufs;
6064 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6066 +/* 20 is max digits length of ulong 64 */
6067 +struct dbgaufs_arg {
6073 + * common function for all XINO files
6075 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6076 + struct file *file)
6078 + kfree(file->private_data);
6082 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6086 + struct dbgaufs_arg *p;
6089 + p = kmalloc(sizeof(*p), GFP_NOFS);
6095 + file->private_data = p;
6099 + err = vfs_getattr(&xf->f_path, &st);
6103 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
6104 + (long)file_count(xf), st.blocks, st.blksize,
6105 + (long long)st.size);
6107 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
6108 + st.blocks, st.blksize,
6109 + (long long)st.size);
6110 + AuDebugOn(p->n >= sizeof(p->a));
6112 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6121 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6122 + size_t count, loff_t *ppos)
6124 + struct dbgaufs_arg *p;
6126 + p = file->private_data;
6127 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6130 +/* ---------------------------------------------------------------------- */
6132 +struct dbgaufs_plink_arg {
6137 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6138 + struct file *file)
6140 + free_page((unsigned long)file->private_data);
6144 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6146 + int err, i, limit;
6147 + unsigned long n, sum;
6148 + struct dbgaufs_plink_arg *p;
6149 + struct au_sbinfo *sbinfo;
6150 + struct super_block *sb;
6151 + struct au_sphlhead *sphl;
6154 + p = (void *)get_zeroed_page(GFP_NOFS);
6159 + sbinfo = inode->i_private;
6160 + sb = sbinfo->si_sb;
6161 + si_noflush_read_lock(sb);
6162 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6163 + limit = PAGE_SIZE - sizeof(p->n);
6165 + /* the number of buckets */
6166 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6171 + for (i = 0, sphl = sbinfo->si_plink;
6172 + i < AuPlink_NHASH;
6174 + n = au_sphl_count(sphl);
6177 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6180 + if (unlikely(limit <= 0))
6183 + p->a[p->n - 1] = '\n';
6185 + /* the sum of plinks */
6186 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6189 + if (unlikely(limit <= 0))
6192 +#define str "1\n0\n0\n"
6193 + p->n = sizeof(str) - 1;
6194 + strcpy(p->a, str);
6197 + si_read_unlock(sb);
6200 + file->private_data = p;
6201 + goto out; /* success */
6204 + free_page((unsigned long)p);
6209 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6210 + size_t count, loff_t *ppos)
6212 + struct dbgaufs_plink_arg *p;
6214 + p = file->private_data;
6215 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6218 +static const struct file_operations dbgaufs_plink_fop = {
6219 + .owner = THIS_MODULE,
6220 + .open = dbgaufs_plink_open,
6221 + .release = dbgaufs_plink_release,
6222 + .read = dbgaufs_plink_read
6225 +/* ---------------------------------------------------------------------- */
6227 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6230 + struct au_sbinfo *sbinfo;
6231 + struct super_block *sb;
6233 + sbinfo = inode->i_private;
6234 + sb = sbinfo->si_sb;
6235 + si_noflush_read_lock(sb);
6236 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6237 + si_read_unlock(sb);
6241 +static const struct file_operations dbgaufs_xib_fop = {
6242 + .owner = THIS_MODULE,
6243 + .open = dbgaufs_xib_open,
6244 + .release = dbgaufs_xi_release,
6245 + .read = dbgaufs_xi_read
6248 +/* ---------------------------------------------------------------------- */
6250 +#define DbgaufsXi_PREFIX "xi"
6252 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6256 + struct au_sbinfo *sbinfo;
6257 + struct super_block *sb;
6259 + struct qstr *name;
6263 + name = &file->f_path.dentry->d_name;
6264 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6265 + || memcmp(name->name, DbgaufsXi_PREFIX,
6266 + sizeof(DbgaufsXi_PREFIX) - 1)))
6268 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6269 + if (unlikely(err))
6272 + sbinfo = inode->i_private;
6273 + sb = sbinfo->si_sb;
6274 + si_noflush_read_lock(sb);
6275 + if (l <= au_sbend(sb)) {
6276 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6277 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6280 + si_read_unlock(sb);
6286 +static const struct file_operations dbgaufs_xino_fop = {
6287 + .owner = THIS_MODULE,
6288 + .open = dbgaufs_xino_open,
6289 + .release = dbgaufs_xi_release,
6290 + .read = dbgaufs_xi_read
6293 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6295 + aufs_bindex_t bend;
6296 + struct au_branch *br;
6297 + struct au_xino_file *xi;
6299 + if (!au_sbi(sb)->si_dbgaufs)
6302 + bend = au_sbend(sb);
6303 + for (; bindex <= bend; bindex++) {
6304 + br = au_sbr(sb, bindex);
6305 + xi = &br->br_xino;
6306 + debugfs_remove(xi->xi_dbgaufs);
6307 + xi->xi_dbgaufs = NULL;
6311 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6313 + struct au_sbinfo *sbinfo;
6314 + struct dentry *parent;
6315 + struct au_branch *br;
6316 + struct au_xino_file *xi;
6317 + aufs_bindex_t bend;
6318 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6320 + sbinfo = au_sbi(sb);
6321 + parent = sbinfo->si_dbgaufs;
6325 + bend = au_sbend(sb);
6326 + for (; bindex <= bend; bindex++) {
6327 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6328 + br = au_sbr(sb, bindex);
6329 + xi = &br->br_xino;
6330 + AuDebugOn(xi->xi_dbgaufs);
6331 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6332 + sbinfo, &dbgaufs_xino_fop);
6333 + /* ignore an error */
6334 + if (unlikely(!xi->xi_dbgaufs))
6335 + AuWarn1("failed %s under debugfs\n", name);
6339 +/* ---------------------------------------------------------------------- */
6341 +#ifdef CONFIG_AUFS_EXPORT
6342 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6345 + struct au_sbinfo *sbinfo;
6346 + struct super_block *sb;
6348 + sbinfo = inode->i_private;
6349 + sb = sbinfo->si_sb;
6350 + si_noflush_read_lock(sb);
6351 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6352 + si_read_unlock(sb);
6356 +static const struct file_operations dbgaufs_xigen_fop = {
6357 + .owner = THIS_MODULE,
6358 + .open = dbgaufs_xigen_open,
6359 + .release = dbgaufs_xi_release,
6360 + .read = dbgaufs_xi_read
6363 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6368 + * This function is a dynamic '__init' function actually,
6369 + * so the tiny check for si_rwsem is unnecessary.
6371 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6374 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6375 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6376 + &dbgaufs_xigen_fop);
6377 + if (sbinfo->si_dbgaufs_xigen)
6383 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6387 +#endif /* CONFIG_AUFS_EXPORT */
6389 +/* ---------------------------------------------------------------------- */
6391 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6394 + * This function is a dynamic '__fin' function actually,
6395 + * so the tiny check for si_rwsem is unnecessary.
6397 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6399 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6400 + sbinfo->si_dbgaufs = NULL;
6401 + kobject_put(&sbinfo->si_kobj);
6404 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6407 + char name[SysaufsSiNameLen];
6410 + * This function is a dynamic '__init' function actually,
6411 + * so the tiny check for si_rwsem is unnecessary.
6413 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6417 + AuErr1("/debug/aufs is uninitialized\n");
6422 + sysaufs_name(sbinfo, name);
6423 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6424 + if (unlikely(!sbinfo->si_dbgaufs))
6426 + kobject_get(&sbinfo->si_kobj);
6428 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6429 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6430 + &dbgaufs_xib_fop);
6431 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6434 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6435 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6436 + &dbgaufs_plink_fop);
6437 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6440 + err = dbgaufs_xigen_init(sbinfo);
6442 + goto out; /* success */
6445 + dbgaufs_si_fin(sbinfo);
6450 +/* ---------------------------------------------------------------------- */
6452 +void dbgaufs_fin(void)
6454 + debugfs_remove(dbgaufs);
6457 +int __init dbgaufs_init(void)
6462 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6467 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6468 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6469 +++ linux/fs/aufs/dbgaufs.h 2016-04-24 18:32:51.390353525 +0200
6472 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6474 + * This program, aufs is free software; you can redistribute it and/or modify
6475 + * it under the terms of the GNU General Public License as published by
6476 + * the Free Software Foundation; either version 2 of the License, or
6477 + * (at your option) any later version.
6479 + * This program is distributed in the hope that it will be useful,
6480 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6481 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6482 + * GNU General Public License for more details.
6484 + * You should have received a copy of the GNU General Public License
6485 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6489 + * debugfs interface
6492 +#ifndef __DBGAUFS_H__
6493 +#define __DBGAUFS_H__
6497 +struct super_block;
6500 +#ifdef CONFIG_DEBUG_FS
6502 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6503 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6504 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6505 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6506 +void dbgaufs_fin(void);
6507 +int __init dbgaufs_init(void);
6509 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6510 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6511 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6512 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6513 +AuStubVoid(dbgaufs_fin, void)
6514 +AuStubInt0(__init dbgaufs_init, void)
6515 +#endif /* CONFIG_DEBUG_FS */
6517 +#endif /* __KERNEL__ */
6518 +#endif /* __DBGAUFS_H__ */
6519 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6520 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6521 +++ linux/fs/aufs/dcsub.c 2016-04-24 18:32:51.390353525 +0200
6524 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6526 + * This program, aufs is free software; you can redistribute it and/or modify
6527 + * it under the terms of the GNU General Public License as published by
6528 + * the Free Software Foundation; either version 2 of the License, or
6529 + * (at your option) any later version.
6531 + * This program is distributed in the hope that it will be useful,
6532 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6533 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6534 + * GNU General Public License for more details.
6536 + * You should have received a copy of the GNU General Public License
6537 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6541 + * sub-routines for dentry cache
6546 +static void au_dpage_free(struct au_dpage *dpage)
6549 + struct dentry **p;
6551 + p = dpage->dentries;
6552 + for (i = 0; i < dpage->ndentry; i++)
6554 + free_page((unsigned long)dpage->dentries);
6557 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6563 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6564 + if (unlikely(!dpages->dpages))
6567 + p = (void *)__get_free_page(gfp);
6571 + dpages->dpages[0].ndentry = 0;
6572 + dpages->dpages[0].dentries = p;
6573 + dpages->ndpage = 1;
6574 + return 0; /* success */
6577 + kfree(dpages->dpages);
6582 +void au_dpages_free(struct au_dcsub_pages *dpages)
6585 + struct au_dpage *p;
6587 + p = dpages->dpages;
6588 + for (i = 0; i < dpages->ndpage; i++)
6589 + au_dpage_free(p++);
6590 + kfree(dpages->dpages);
6593 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6594 + struct dentry *dentry, gfp_t gfp)
6597 + struct au_dpage *dpage;
6600 + dpage = dpages->dpages + dpages->ndpage - 1;
6601 + sz = PAGE_SIZE / sizeof(dentry);
6602 + if (unlikely(dpage->ndentry >= sz)) {
6603 + AuLabel(new dpage);
6605 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6606 + p = au_kzrealloc(dpages->dpages, sz,
6607 + sz + sizeof(*dpages->dpages), gfp);
6611 + dpages->dpages = p;
6612 + dpage = dpages->dpages + dpages->ndpage;
6613 + p = (void *)__get_free_page(gfp);
6617 + dpage->ndentry = 0;
6618 + dpage->dentries = p;
6622 + AuDebugOn(au_dcount(dentry) <= 0);
6623 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6624 + return 0; /* success */
6630 +/* todo: BAD approach */
6631 +/* copied from linux/fs/dcache.c */
6639 +extern void d_walk(struct dentry *parent, void *data,
6640 + enum d_walk_ret (*enter)(void *, struct dentry *),
6641 + void (*finish)(void *));
6643 +struct ac_dpages_arg {
6645 + struct au_dcsub_pages *dpages;
6646 + struct super_block *sb;
6647 + au_dpages_test test;
6651 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6653 + enum d_walk_ret ret;
6654 + struct ac_dpages_arg *arg = _arg;
6656 + ret = D_WALK_CONTINUE;
6657 + if (dentry->d_sb == arg->sb
6658 + && !IS_ROOT(dentry)
6659 + && au_dcount(dentry) > 0
6661 + && (!arg->test || arg->test(dentry, arg->arg))) {
6662 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6663 + if (unlikely(arg->err))
6664 + ret = D_WALK_QUIT;
6670 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6671 + au_dpages_test test, void *arg)
6673 + struct ac_dpages_arg args = {
6681 + d_walk(root, &args, au_call_dpages_append, NULL);
6686 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6687 + int do_include, au_dpages_test test, void *arg)
6692 + write_seqlock(&rename_lock);
6693 + spin_lock(&dentry->d_lock);
6695 + && au_dcount(dentry) > 0
6696 + && (!test || test(dentry, arg)))
6697 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6698 + spin_unlock(&dentry->d_lock);
6699 + if (unlikely(err))
6703 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6706 + while (!IS_ROOT(dentry)) {
6707 + dentry = dentry->d_parent; /* rename_lock is locked */
6708 + spin_lock(&dentry->d_lock);
6709 + if (au_dcount(dentry) > 0
6710 + && (!test || test(dentry, arg)))
6711 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6712 + spin_unlock(&dentry->d_lock);
6713 + if (unlikely(err))
6718 + write_sequnlock(&rename_lock);
6722 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6724 + return au_di(dentry) && dentry->d_sb == arg;
6727 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6728 + struct dentry *dentry, int do_include)
6730 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6731 + au_dcsub_dpages_aufs, dentry->d_sb);
6734 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6736 + struct path path[2] = {
6745 + return path_is_under(path + 0, path + 1);
6747 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6748 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6749 +++ linux/fs/aufs/dcsub.h 2016-04-24 18:32:51.390353525 +0200
6752 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6754 + * This program, aufs is free software; you can redistribute it and/or modify
6755 + * it under the terms of the GNU General Public License as published by
6756 + * the Free Software Foundation; either version 2 of the License, or
6757 + * (at your option) any later version.
6759 + * This program is distributed in the hope that it will be useful,
6760 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6761 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6762 + * GNU General Public License for more details.
6764 + * You should have received a copy of the GNU General Public License
6765 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6769 + * sub-routines for dentry cache
6772 +#ifndef __AUFS_DCSUB_H__
6773 +#define __AUFS_DCSUB_H__
6777 +#include <linux/dcache.h>
6778 +#include <linux/fs.h>
6782 + struct dentry **dentries;
6785 +struct au_dcsub_pages {
6787 + struct au_dpage *dpages;
6790 +/* ---------------------------------------------------------------------- */
6793 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6794 +void au_dpages_free(struct au_dcsub_pages *dpages);
6795 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6796 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6797 + au_dpages_test test, void *arg);
6798 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6799 + int do_include, au_dpages_test test, void *arg);
6800 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6801 + struct dentry *dentry, int do_include);
6802 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6804 +/* ---------------------------------------------------------------------- */
6807 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6808 + * include/linux/dcache.h. Try them (in the future).
6811 +static inline int au_d_hashed_positive(struct dentry *d)
6814 + struct inode *inode = d_inode(d);
6817 + if (unlikely(d_unhashed(d)
6818 + || d_is_negative(d)
6819 + || !inode->i_nlink))
6824 +static inline int au_d_linkable(struct dentry *d)
6827 + struct inode *inode = d_inode(d);
6829 + err = au_d_hashed_positive(d);
6831 + && d_is_positive(d)
6832 + && (inode->i_state & I_LINKABLE))
6837 +static inline int au_d_alive(struct dentry *d)
6840 + struct inode *inode;
6844 + err = au_d_hashed_positive(d);
6846 + inode = d_inode(d);
6847 + if (unlikely(d_unlinked(d)
6848 + || d_is_negative(d)
6849 + || !inode->i_nlink))
6855 +static inline int au_alive_dir(struct dentry *d)
6859 + err = au_d_alive(d);
6860 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6865 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6867 + return a->len == b->len
6868 + && !memcmp(a->name, b->name, a->len);
6873 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6875 + * the type of d_lockref.count became int, but the inlined function d_count()
6876 + * still returns unsigned int.
6877 + * I don't know why. Maybe it is for every d_count() users?
6878 + * Anyway au_dcount() lives on.
6880 +static inline int au_dcount(struct dentry *d)
6882 + return (int)d_count(d);
6885 +#endif /* __KERNEL__ */
6886 +#endif /* __AUFS_DCSUB_H__ */
6887 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6888 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6889 +++ linux/fs/aufs/debug.c 2016-04-24 18:32:51.390353525 +0200
6892 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6894 + * This program, aufs is free software; you can redistribute it and/or modify
6895 + * it under the terms of the GNU General Public License as published by
6896 + * the Free Software Foundation; either version 2 of the License, or
6897 + * (at your option) any later version.
6899 + * This program is distributed in the hope that it will be useful,
6900 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6901 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6902 + * GNU General Public License for more details.
6904 + * You should have received a copy of the GNU General Public License
6905 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6909 + * debug print functions
6914 +/* Returns 0, or -errno. arg is in kp->arg. */
6915 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6919 + err = kstrtoint(val, 0, &n);
6929 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6930 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6935 + return sprintf(buffer, "%d", atomic_read(a));
6938 +static struct kernel_param_ops param_ops_atomic_t = {
6939 + .set = param_atomic_t_set,
6940 + .get = param_atomic_t_get
6941 + /* void (*free)(void *arg) */
6944 +atomic_t aufs_debug = ATOMIC_INIT(0);
6945 +MODULE_PARM_DESC(debug, "debug print");
6946 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6948 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6949 +char *au_plevel = KERN_DEBUG;
6950 +#define dpri(fmt, ...) do { \
6952 + && strcmp(au_plevel, KERN_DEBUG)) \
6953 + || au_debug_test()) \
6954 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6957 +/* ---------------------------------------------------------------------- */
6959 +void au_dpri_whlist(struct au_nhash *whlist)
6961 + unsigned long ul, n;
6962 + struct hlist_head *head;
6963 + struct au_vdir_wh *pos;
6965 + n = whlist->nh_num;
6966 + head = whlist->nh_head;
6967 + for (ul = 0; ul < n; ul++) {
6968 + hlist_for_each_entry(pos, head, wh_hash)
6969 + dpri("b%d, %.*s, %d\n",
6971 + pos->wh_str.len, pos->wh_str.name,
6977 +void au_dpri_vdir(struct au_vdir *vdir)
6980 + union au_vdir_deblk_p p;
6983 + if (!vdir || IS_ERR(vdir)) {
6984 + dpri("err %ld\n", PTR_ERR(vdir));
6988 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6989 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6990 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6991 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6992 + p.deblk = vdir->vd_deblk[ul];
6994 + dpri("[%lu]: %p\n", ul, o);
6998 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6999 + struct dentry *wh)
7004 + if (!inode || IS_ERR(inode)) {
7005 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7009 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7010 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7011 + && sizeof(inode->i_blocks) != sizeof(u64));
7013 + n = (void *)wh->d_name.name;
7014 + l = wh->d_name.len;
7017 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7018 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7020 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7021 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7022 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7023 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7024 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7025 + inode->i_state, inode->i_flags, inode->i_version,
7026 + inode->i_generation,
7027 + l ? ", wh " : "", l, n);
7031 +void au_dpri_inode(struct inode *inode)
7033 + struct au_iinfo *iinfo;
7034 + aufs_bindex_t bindex;
7037 + err = do_pri_inode(-1, inode, -1, NULL);
7038 + if (err || !au_test_aufs(inode->i_sb))
7041 + iinfo = au_ii(inode);
7044 + dpri("i-1: bstart %d, bend %d, gen %d\n",
7045 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
7046 + if (iinfo->ii_bstart < 0)
7049 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
7050 + hn = !!au_hn(iinfo->ii_hinode + bindex);
7051 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
7052 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
7056 +void au_dpri_dalias(struct inode *inode)
7060 + spin_lock(&inode->i_lock);
7061 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7062 + au_dpri_dentry(d);
7063 + spin_unlock(&inode->i_lock);
7066 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7068 + struct dentry *wh = NULL;
7070 + struct au_iinfo *iinfo;
7072 + if (!dentry || IS_ERR(dentry)) {
7073 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7076 + /* do not call dget_parent() here */
7077 + /* note: access d_xxx without d_lock */
7078 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7079 + bindex, dentry, dentry,
7080 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7081 + au_dcount(dentry), dentry->d_flags,
7082 + d_unhashed(dentry) ? "un" : "");
7085 + && d_is_positive(dentry)
7086 + && au_test_aufs(dentry->d_sb)) {
7087 + iinfo = au_ii(d_inode(dentry));
7089 + hn = !!au_hn(iinfo->ii_hinode + bindex);
7090 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
7093 + do_pri_inode(bindex, d_inode(dentry), hn, wh);
7097 +void au_dpri_dentry(struct dentry *dentry)
7099 + struct au_dinfo *dinfo;
7100 + aufs_bindex_t bindex;
7102 + struct au_hdentry *hdp;
7104 + err = do_pri_dentry(-1, dentry);
7105 + if (err || !au_test_aufs(dentry->d_sb))
7108 + dinfo = au_di(dentry);
7111 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7112 + dinfo->di_bstart, dinfo->di_bend,
7113 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7114 + dinfo->di_tmpfile);
7115 + if (dinfo->di_bstart < 0)
7117 + hdp = dinfo->di_hdentry;
7118 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
7119 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
7122 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7126 + if (!file || IS_ERR(file)) {
7127 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7132 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7133 + && au_test_aufs(file->f_path.dentry->d_sb)
7135 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7136 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7137 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7138 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7139 + file->f_version, file->f_pos, a);
7140 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7141 + do_pri_dentry(bindex, file->f_path.dentry);
7145 +void au_dpri_file(struct file *file)
7147 + struct au_finfo *finfo;
7148 + struct au_fidir *fidir;
7149 + struct au_hfile *hfile;
7150 + aufs_bindex_t bindex;
7153 + err = do_pri_file(-1, file);
7155 + || IS_ERR_OR_NULL(file->f_path.dentry)
7156 + || !au_test_aufs(file->f_path.dentry->d_sb))
7159 + finfo = au_fi(file);
7162 + if (finfo->fi_btop < 0)
7164 + fidir = finfo->fi_hdir;
7166 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7168 + for (bindex = finfo->fi_btop;
7169 + bindex >= 0 && bindex <= fidir->fd_bbot;
7171 + hfile = fidir->fd_hfile + bindex;
7172 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7176 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7178 + struct vfsmount *mnt;
7179 + struct super_block *sb;
7181 + if (!br || IS_ERR(br))
7183 + mnt = au_br_mnt(br);
7184 + if (!mnt || IS_ERR(mnt))
7187 + if (!sb || IS_ERR(sb))
7190 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
7191 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7193 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
7194 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7195 + sb->s_flags, sb->s_count,
7196 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7200 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7204 +void au_dpri_sb(struct super_block *sb)
7206 + struct au_sbinfo *sbinfo;
7207 + aufs_bindex_t bindex;
7209 + /* to reuduce stack size */
7211 + struct vfsmount mnt;
7212 + struct au_branch fake;
7215 + /* this function can be called from magic sysrq */
7216 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7217 + if (unlikely(!a)) {
7218 + dpri("no memory\n");
7222 + a->mnt.mnt_sb = sb;
7223 + a->fake.br_path.mnt = &a->mnt;
7224 + atomic_set(&a->fake.br_count, 0);
7225 + smp_mb(); /* atomic_set */
7226 + err = do_pri_br(-1, &a->fake);
7228 + dpri("dev 0x%x\n", sb->s_dev);
7229 + if (err || !au_test_aufs(sb))
7232 + sbinfo = au_sbi(sb);
7235 + dpri("nw %d, gen %u, kobj %d\n",
7236 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7237 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7238 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
7239 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7242 +/* ---------------------------------------------------------------------- */
7244 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7246 + struct inode *h_inode, *inode = d_inode(dentry);
7247 + struct dentry *h_dentry;
7248 + aufs_bindex_t bindex, bend, bi;
7250 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7253 + bend = au_dbend(dentry);
7254 + bi = au_ibend(inode);
7257 + bindex = au_dbstart(dentry);
7258 + bi = au_ibstart(inode);
7262 + for (; bindex <= bend; bindex++) {
7263 + h_dentry = au_h_dptr(dentry, bindex);
7266 + h_inode = au_h_iptr(inode, bindex);
7267 + if (unlikely(h_inode != d_inode(h_dentry))) {
7269 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7270 + AuDbgDentry(dentry);
7271 + AuDbgInode(inode);
7278 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7281 + struct au_dcsub_pages dpages;
7282 + struct au_dpage *dpage;
7283 + struct dentry **dentries;
7285 + err = au_dpages_init(&dpages, GFP_NOFS);
7287 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7289 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7290 + dpage = dpages.dpages + i;
7291 + dentries = dpage->dentries;
7292 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7293 + AuDebugOn(au_digen_test(dentries[j], sigen));
7295 + au_dpages_free(&dpages);
7298 +void au_dbg_verify_kthread(void)
7300 + if (au_wkq_test()) {
7303 + * It may be recursive, but udba=notify between two aufs mounts,
7304 + * where a single ro branch is shared, is not a problem.
7310 +/* ---------------------------------------------------------------------- */
7312 +int __init au_debug_init(void)
7314 + aufs_bindex_t bindex;
7315 + struct au_vdir_destr destr;
7318 + AuDebugOn(bindex >= 0);
7321 + AuDebugOn(destr.len < NAME_MAX);
7323 +#ifdef CONFIG_4KSTACKS
7324 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7329 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7330 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7331 +++ linux/fs/aufs/debug.h 2016-04-24 18:32:51.390353525 +0200
7334 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7336 + * This program, aufs is free software; you can redistribute it and/or modify
7337 + * it under the terms of the GNU General Public License as published by
7338 + * the Free Software Foundation; either version 2 of the License, or
7339 + * (at your option) any later version.
7341 + * This program is distributed in the hope that it will be useful,
7342 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7343 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7344 + * GNU General Public License for more details.
7346 + * You should have received a copy of the GNU General Public License
7347 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7351 + * debug print functions
7354 +#ifndef __AUFS_DEBUG_H__
7355 +#define __AUFS_DEBUG_H__
7359 +#include <linux/atomic.h>
7360 +#include <linux/module.h>
7361 +#include <linux/kallsyms.h>
7362 +#include <linux/sysrq.h>
7364 +#ifdef CONFIG_AUFS_DEBUG
7365 +#define AuDebugOn(a) BUG_ON(a)
7367 +/* module parameter */
7368 +extern atomic_t aufs_debug;
7369 +static inline void au_debug_on(void)
7371 + atomic_inc(&aufs_debug);
7373 +static inline void au_debug_off(void)
7375 + atomic_dec_if_positive(&aufs_debug);
7378 +static inline int au_debug_test(void)
7380 + return atomic_read(&aufs_debug) > 0;
7383 +#define AuDebugOn(a) do {} while (0)
7384 +AuStubVoid(au_debug_on, void)
7385 +AuStubVoid(au_debug_off, void)
7386 +AuStubInt0(au_debug_test, void)
7387 +#endif /* CONFIG_AUFS_DEBUG */
7389 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7391 +/* ---------------------------------------------------------------------- */
7395 +#define AuDbg(fmt, ...) do { \
7396 + if (au_debug_test()) \
7397 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7399 +#define AuLabel(l) AuDbg(#l "\n")
7400 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7401 +#define AuWarn1(fmt, ...) do { \
7402 + static unsigned char _c; \
7404 + pr_warn(fmt, ##__VA_ARGS__); \
7407 +#define AuErr1(fmt, ...) do { \
7408 + static unsigned char _c; \
7410 + pr_err(fmt, ##__VA_ARGS__); \
7413 +#define AuIOErr1(fmt, ...) do { \
7414 + static unsigned char _c; \
7416 + AuIOErr(fmt, ##__VA_ARGS__); \
7419 +#define AuUnsupportMsg "This operation is not supported." \
7420 + " Please report this application to aufs-users ML."
7421 +#define AuUnsupport(fmt, ...) do { \
7422 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7426 +#define AuTraceErr(e) do { \
7427 + if (unlikely((e) < 0)) \
7428 + AuDbg("err %d\n", (int)(e)); \
7431 +#define AuTraceErrPtr(p) do { \
7433 + AuDbg("err %ld\n", PTR_ERR(p)); \
7436 +/* dirty macros for debug print, use with "%.*s" and caution */
7437 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7439 +/* ---------------------------------------------------------------------- */
7442 +#ifdef CONFIG_AUFS_DEBUG
7443 +extern struct mutex au_dbg_mtx;
7444 +extern char *au_plevel;
7446 +void au_dpri_whlist(struct au_nhash *whlist);
7448 +void au_dpri_vdir(struct au_vdir *vdir);
7450 +void au_dpri_inode(struct inode *inode);
7451 +void au_dpri_dalias(struct inode *inode);
7452 +void au_dpri_dentry(struct dentry *dentry);
7454 +void au_dpri_file(struct file *filp);
7455 +struct super_block;
7456 +void au_dpri_sb(struct super_block *sb);
7458 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7459 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7460 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7461 +void au_dbg_verify_kthread(void);
7463 +int __init au_debug_init(void);
7465 +#define AuDbgWhlist(w) do { \
7466 + mutex_lock(&au_dbg_mtx); \
7468 + au_dpri_whlist(w); \
7469 + mutex_unlock(&au_dbg_mtx); \
7472 +#define AuDbgVdir(v) do { \
7473 + mutex_lock(&au_dbg_mtx); \
7475 + au_dpri_vdir(v); \
7476 + mutex_unlock(&au_dbg_mtx); \
7479 +#define AuDbgInode(i) do { \
7480 + mutex_lock(&au_dbg_mtx); \
7482 + au_dpri_inode(i); \
7483 + mutex_unlock(&au_dbg_mtx); \
7486 +#define AuDbgDAlias(i) do { \
7487 + mutex_lock(&au_dbg_mtx); \
7489 + au_dpri_dalias(i); \
7490 + mutex_unlock(&au_dbg_mtx); \
7493 +#define AuDbgDentry(d) do { \
7494 + mutex_lock(&au_dbg_mtx); \
7496 + au_dpri_dentry(d); \
7497 + mutex_unlock(&au_dbg_mtx); \
7500 +#define AuDbgFile(f) do { \
7501 + mutex_lock(&au_dbg_mtx); \
7503 + au_dpri_file(f); \
7504 + mutex_unlock(&au_dbg_mtx); \
7507 +#define AuDbgSb(sb) do { \
7508 + mutex_lock(&au_dbg_mtx); \
7509 + AuDbg(#sb "\n"); \
7511 + mutex_unlock(&au_dbg_mtx); \
7514 +#define AuDbgSym(addr) do { \
7515 + char sym[KSYM_SYMBOL_LEN]; \
7516 + sprint_symbol(sym, (unsigned long)addr); \
7517 + AuDbg("%s\n", sym); \
7520 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7521 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7522 +AuStubVoid(au_dbg_verify_kthread, void)
7523 +AuStubInt0(__init au_debug_init, void)
7525 +#define AuDbgWhlist(w) do {} while (0)
7526 +#define AuDbgVdir(v) do {} while (0)
7527 +#define AuDbgInode(i) do {} while (0)
7528 +#define AuDbgDAlias(i) do {} while (0)
7529 +#define AuDbgDentry(d) do {} while (0)
7530 +#define AuDbgFile(f) do {} while (0)
7531 +#define AuDbgSb(sb) do {} while (0)
7532 +#define AuDbgSym(addr) do {} while (0)
7533 +#endif /* CONFIG_AUFS_DEBUG */
7535 +/* ---------------------------------------------------------------------- */
7537 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7538 +int __init au_sysrq_init(void);
7539 +void au_sysrq_fin(void);
7541 +#ifdef CONFIG_HW_CONSOLE
7542 +#define au_dbg_blocked() do { \
7544 + handle_sysrq('w'); \
7547 +AuStubVoid(au_dbg_blocked, void)
7551 +AuStubInt0(__init au_sysrq_init, void)
7552 +AuStubVoid(au_sysrq_fin, void)
7553 +AuStubVoid(au_dbg_blocked, void)
7554 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7556 +#endif /* __KERNEL__ */
7557 +#endif /* __AUFS_DEBUG_H__ */
7558 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7559 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7560 +++ linux/fs/aufs/dentry.c 2016-04-24 18:32:51.390353525 +0200
7563 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7565 + * This program, aufs is free software; you can redistribute it and/or modify
7566 + * it under the terms of the GNU General Public License as published by
7567 + * the Free Software Foundation; either version 2 of the License, or
7568 + * (at your option) any later version.
7570 + * This program is distributed in the hope that it will be useful,
7571 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7572 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7573 + * GNU General Public License for more details.
7575 + * You should have received a copy of the GNU General Public License
7576 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7580 + * lookup and dentry operations
7583 +#include <linux/namei.h>
7586 +#define AuLkup_ALLOW_NEG 1
7587 +#define AuLkup_IGNORE_PERM (1 << 1)
7588 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7589 +#define au_fset_lkup(flags, name) \
7590 + do { (flags) |= AuLkup_##name; } while (0)
7591 +#define au_fclr_lkup(flags, name) \
7592 + do { (flags) &= ~AuLkup_##name; } while (0)
7594 +struct au_do_lookup_args {
7595 + unsigned int flags;
7600 + * returns positive/negative dentry, NULL or an error.
7601 + * NULL means whiteout-ed or not-found.
7603 +static struct dentry*
7604 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7605 + aufs_bindex_t bindex, struct qstr *wh_name,
7606 + struct au_do_lookup_args *args)
7608 + struct dentry *h_dentry;
7609 + struct inode *h_inode;
7610 + struct au_branch *br;
7611 + int wh_found, opq;
7612 + unsigned char wh_able;
7613 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7614 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7618 + br = au_sbr(dentry->d_sb, bindex);
7619 + wh_able = !!au_br_whable(br->br_perm);
7621 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7622 + h_dentry = ERR_PTR(wh_found);
7625 + if (unlikely(wh_found < 0))
7628 + /* We found a whiteout */
7629 + /* au_set_dbend(dentry, bindex); */
7630 + au_set_dbwh(dentry, bindex);
7632 + return NULL; /* success */
7636 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7638 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7639 + if (IS_ERR(h_dentry)) {
7640 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7646 + h_inode = d_inode(h_dentry);
7647 + if (d_is_negative(h_dentry)) {
7650 + } else if (wh_found
7651 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7654 + if (au_dbend(dentry) <= bindex)
7655 + au_set_dbend(dentry, bindex);
7656 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7657 + au_set_dbstart(dentry, bindex);
7658 + au_set_h_dptr(dentry, bindex, h_dentry);
7660 + if (!d_is_dir(h_dentry)
7662 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7663 + goto out; /* success */
7665 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
7666 + opq = au_diropq_test(h_dentry);
7667 + inode_unlock(h_inode);
7669 + au_set_dbdiropq(dentry, bindex);
7670 + else if (unlikely(opq < 0)) {
7671 + au_set_h_dptr(dentry, bindex, NULL);
7672 + h_dentry = ERR_PTR(opq);
7683 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7685 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7686 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7692 + * returns the number of lower positive dentries,
7693 + * otherwise an error.
7694 + * can be called at unlinking with @type is zero.
7696 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7698 + int npositive, err;
7699 + aufs_bindex_t bindex, btail, bdiropq;
7700 + unsigned char isdir, dirperm1;
7701 + struct qstr whname;
7702 + struct au_do_lookup_args args = {
7706 + const struct qstr *name = &dentry->d_name;
7707 + struct dentry *parent;
7708 + struct super_block *sb;
7710 + sb = dentry->d_sb;
7711 + err = au_test_shwh(sb, name);
7712 + if (unlikely(err))
7715 + err = au_wh_name_alloc(&whname, name);
7716 + if (unlikely(err))
7719 + isdir = !!d_is_dir(dentry);
7721 + au_fset_lkup(args.flags, ALLOW_NEG);
7722 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7725 + parent = dget_parent(dentry);
7726 + btail = au_dbtaildir(parent);
7727 + for (bindex = bstart; bindex <= btail; bindex++) {
7728 + struct dentry *h_parent, *h_dentry;
7729 + struct inode *h_inode, *h_dir;
7731 + h_dentry = au_h_dptr(dentry, bindex);
7733 + if (d_is_positive(h_dentry))
7735 + if (type != S_IFDIR)
7739 + h_parent = au_h_dptr(parent, bindex);
7740 + if (!h_parent || !d_is_dir(h_parent))
7743 + h_dir = d_inode(h_parent);
7744 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
7745 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7747 + inode_unlock(h_dir);
7748 + err = PTR_ERR(h_dentry);
7749 + if (IS_ERR(h_dentry))
7752 + au_fclr_lkup(args.flags, ALLOW_NEG);
7754 + au_fset_lkup(args.flags, IGNORE_PERM);
7756 + if (au_dbwh(dentry) == bindex)
7760 + if (d_is_negative(h_dentry))
7762 + h_inode = d_inode(h_dentry);
7765 + args.type = h_inode->i_mode & S_IFMT;
7766 + if (args.type != S_IFDIR)
7769 + /* the type of lower may be different */
7770 + bdiropq = au_dbdiropq(dentry);
7771 + if (bdiropq >= 0 && bdiropq <= bindex)
7777 + AuLabel(positive);
7778 + au_update_dbstart(dentry);
7781 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7782 + && au_dbstart(dentry) < 0)) {
7784 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7790 + kfree(whname.name);
7795 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7797 + struct dentry *dentry;
7800 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7801 + dentry = vfsub_lkup_one(name, parent);
7803 + struct vfsub_lkup_one_args args = {
7809 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7810 + if (unlikely(wkq_err))
7811 + dentry = ERR_PTR(wkq_err);
7818 + * lookup @dentry on @bindex which should be negative.
7820 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7823 + struct dentry *parent, *h_parent, *h_dentry;
7824 + struct au_branch *br;
7826 + parent = dget_parent(dentry);
7827 + h_parent = au_h_dptr(parent, bindex);
7828 + br = au_sbr(dentry->d_sb, bindex);
7830 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7832 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7833 + err = PTR_ERR(h_dentry);
7834 + if (IS_ERR(h_dentry))
7836 + if (unlikely(d_is_positive(h_dentry))) {
7838 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7844 + if (bindex < au_dbstart(dentry))
7845 + au_set_dbstart(dentry, bindex);
7846 + if (au_dbend(dentry) < bindex)
7847 + au_set_dbend(dentry, bindex);
7848 + au_set_h_dptr(dentry, bindex, h_dentry);
7855 +/* ---------------------------------------------------------------------- */
7857 +/* subset of struct inode */
7859 + unsigned long i_ino;
7860 + /* unsigned int i_nlink; */
7866 + blkcnt_t i_blocks;
7871 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7873 + ia->i_ino = h_inode->i_ino;
7874 + /* ia->i_nlink = h_inode->i_nlink; */
7875 + ia->i_uid = h_inode->i_uid;
7876 + ia->i_gid = h_inode->i_gid;
7877 + ia->i_version = h_inode->i_version;
7879 + ia->i_size = h_inode->i_size;
7880 + ia->i_blocks = h_inode->i_blocks;
7882 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7885 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7887 + return ia->i_ino != h_inode->i_ino
7888 + /* || ia->i_nlink != h_inode->i_nlink */
7889 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7890 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7891 + || ia->i_version != h_inode->i_version
7893 + || ia->i_size != h_inode->i_size
7894 + || ia->i_blocks != h_inode->i_blocks
7896 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7899 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7900 + struct au_branch *br)
7903 + struct au_iattr ia;
7904 + struct inode *h_inode;
7905 + struct dentry *h_d;
7906 + struct super_block *h_sb;
7909 + memset(&ia, -1, sizeof(ia));
7910 + h_sb = h_dentry->d_sb;
7912 + if (d_is_positive(h_dentry)) {
7913 + h_inode = d_inode(h_dentry);
7914 + au_iattr_save(&ia, h_inode);
7915 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7916 + /* nfs d_revalidate may return 0 for negative dentry */
7917 + /* fuse d_revalidate always return 0 for negative dentry */
7920 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7921 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7922 + err = PTR_ERR(h_d);
7927 + if (unlikely(h_d != h_dentry
7928 + || d_inode(h_d) != h_inode
7929 + || (h_inode && au_iattr_test(&ia, h_inode))))
7930 + err = au_busy_or_stale();
7938 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7939 + struct dentry *h_parent, struct au_branch *br)
7944 + if (udba == AuOpt_UDBA_REVAL
7945 + && !au_test_fs_remote(h_dentry->d_sb)) {
7947 + err = (d_inode(h_dentry->d_parent) != h_dir);
7948 + } else if (udba != AuOpt_UDBA_NONE)
7949 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7954 +/* ---------------------------------------------------------------------- */
7956 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7959 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7960 + struct au_hdentry tmp, *p, *q;
7961 + struct au_dinfo *dinfo;
7962 + struct super_block *sb;
7964 + DiMustWriteLock(dentry);
7966 + sb = dentry->d_sb;
7967 + dinfo = au_di(dentry);
7968 + bend = dinfo->di_bend;
7969 + bwh = dinfo->di_bwh;
7970 + bdiropq = dinfo->di_bdiropq;
7971 + p = dinfo->di_hdentry + dinfo->di_bstart;
7972 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7973 + if (!p->hd_dentry)
7976 + new_bindex = au_br_index(sb, p->hd_id);
7977 + if (new_bindex == bindex)
7980 + if (dinfo->di_bwh == bindex)
7982 + if (dinfo->di_bdiropq == bindex)
7983 + bdiropq = new_bindex;
7984 + if (new_bindex < 0) {
7986 + p->hd_dentry = NULL;
7990 + /* swap two lower dentries, and loop again */
7991 + q = dinfo->di_hdentry + new_bindex;
7995 + if (tmp.hd_dentry) {
8001 + dinfo->di_bwh = -1;
8002 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
8003 + dinfo->di_bwh = bwh;
8005 + dinfo->di_bdiropq = -1;
8007 + && bdiropq <= au_sbend(sb)
8008 + && au_sbr_whable(sb, bdiropq))
8009 + dinfo->di_bdiropq = bdiropq;
8012 + dinfo->di_bstart = -1;
8013 + dinfo->di_bend = -1;
8014 + bend = au_dbend(parent);
8015 + p = dinfo->di_hdentry;
8016 + for (bindex = 0; bindex <= bend; bindex++, p++)
8017 + if (p->hd_dentry) {
8018 + dinfo->di_bstart = bindex;
8022 + if (dinfo->di_bstart >= 0) {
8023 + p = dinfo->di_hdentry + bend;
8024 + for (bindex = bend; bindex >= 0; bindex--, p--)
8025 + if (p->hd_dentry) {
8026 + dinfo->di_bend = bindex;
8035 +static void au_do_hide(struct dentry *dentry)
8037 + struct inode *inode;
8039 + if (d_really_is_positive(dentry)) {
8040 + inode = d_inode(dentry);
8041 + if (!d_is_dir(dentry)) {
8042 + if (inode->i_nlink && !d_unhashed(dentry))
8043 + drop_nlink(inode);
8045 + clear_nlink(inode);
8046 + /* stop next lookup */
8047 + inode->i_flags |= S_DEAD;
8049 + smp_mb(); /* necessary? */
8054 +static int au_hide_children(struct dentry *parent)
8056 + int err, i, j, ndentry;
8057 + struct au_dcsub_pages dpages;
8058 + struct au_dpage *dpage;
8059 + struct dentry *dentry;
8061 + err = au_dpages_init(&dpages, GFP_NOFS);
8062 + if (unlikely(err))
8064 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8065 + if (unlikely(err))
8068 + /* in reverse order */
8069 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8070 + dpage = dpages.dpages + i;
8071 + ndentry = dpage->ndentry;
8072 + for (j = ndentry - 1; j >= 0; j--) {
8073 + dentry = dpage->dentries[j];
8074 + if (dentry != parent)
8075 + au_do_hide(dentry);
8080 + au_dpages_free(&dpages);
8085 +static void au_hide(struct dentry *dentry)
8089 + AuDbgDentry(dentry);
8090 + if (d_is_dir(dentry)) {
8091 + /* shrink_dcache_parent(dentry); */
8092 + err = au_hide_children(dentry);
8093 + if (unlikely(err))
8094 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8097 + au_do_hide(dentry);
8101 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8103 + * a dirty branch is added
8104 + * - on the top of layers
8105 + * - in the middle of layers
8106 + * - to the bottom of layers
8108 + * on the added branch there exists
8111 + * - a same named entry
8113 + * * negative --> positive
8114 + * * positive --> positive
8115 + * - type is unchanged
8116 + * - type is changed
8118 + * * negative --> negative
8119 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8122 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8123 + struct au_dinfo *tmp)
8126 + aufs_bindex_t bindex, bend;
8128 + struct dentry *dentry;
8129 + struct inode *inode;
8131 + } orig_h, tmp_h = {
8134 + struct au_hdentry *hd;
8135 + struct inode *inode, *h_inode;
8136 + struct dentry *h_dentry;
8139 + AuDebugOn(dinfo->di_bstart < 0);
8141 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
8142 + orig_h.inode = NULL;
8143 + if (d_is_positive(orig_h.dentry)) {
8144 + orig_h.inode = d_inode(orig_h.dentry);
8145 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8147 + if (tmp->di_bstart >= 0) {
8148 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
8149 + if (d_is_positive(tmp_h.dentry)) {
8150 + tmp_h.inode = d_inode(tmp_h.dentry);
8151 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8156 + if (d_really_is_positive(dentry))
8157 + inode = d_inode(dentry);
8158 + if (!orig_h.inode) {
8159 + AuDbg("nagative originally\n");
8165 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8166 + AuDebugOn(dinfo->di_bdiropq != -1);
8168 + if (!tmp_h.inode) {
8169 + AuDbg("negative --> negative\n");
8170 + /* should have only one negative lower */
8171 + if (tmp->di_bstart >= 0
8172 + && tmp->di_bstart < dinfo->di_bstart) {
8173 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
8174 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8175 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
8176 + au_di_cp(dinfo, tmp);
8177 + hd = tmp->di_hdentry + tmp->di_bstart;
8178 + au_set_h_dptr(dentry, tmp->di_bstart,
8179 + dget(hd->hd_dentry));
8181 + au_dbg_verify_dinode(dentry);
8183 + AuDbg("negative --> positive\n");
8185 + * similar to the behaviour of creating with bypassing
8187 + * unhash it in order to force an error in the
8188 + * succeeding create operation.
8189 + * we should not set S_DEAD here.
8192 + /* au_di_swap(tmp, dinfo); */
8193 + au_dbg_verify_dinode(dentry);
8196 + AuDbg("positive originally\n");
8197 + /* inode may be NULL */
8198 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8199 + if (!tmp_h.inode) {
8200 + AuDbg("positive --> negative\n");
8201 + /* or bypassing aufs */
8203 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
8204 + dinfo->di_bwh = tmp->di_bwh;
8206 + err = au_refresh_hinode_self(inode);
8207 + au_dbg_verify_dinode(dentry);
8208 + } else if (orig_h.mode == tmp_h.mode) {
8209 + AuDbg("positive --> positive, same type\n");
8210 + if (!S_ISDIR(orig_h.mode)
8211 + && dinfo->di_bstart > tmp->di_bstart) {
8213 + * similar to the behaviour of removing and
8218 + err = au_refresh_hinode_self(inode);
8219 + au_dbg_verify_dinode(dentry);
8221 + /* fill empty slots */
8222 + if (dinfo->di_bstart > tmp->di_bstart)
8223 + dinfo->di_bstart = tmp->di_bstart;
8224 + if (dinfo->di_bend < tmp->di_bend)
8225 + dinfo->di_bend = tmp->di_bend;
8226 + dinfo->di_bwh = tmp->di_bwh;
8227 + dinfo->di_bdiropq = tmp->di_bdiropq;
8228 + hd = tmp->di_hdentry;
8229 + bend = dinfo->di_bend;
8230 + for (bindex = tmp->di_bstart; bindex <= bend;
8232 + if (au_h_dptr(dentry, bindex))
8234 + h_dentry = hd[bindex].hd_dentry;
8237 + AuDebugOn(d_is_negative(h_dentry));
8238 + h_inode = d_inode(h_dentry);
8239 + AuDebugOn(orig_h.mode
8240 + != (h_inode->i_mode
8242 + au_set_h_dptr(dentry, bindex,
8245 + err = au_refresh_hinode(inode, dentry);
8246 + au_dbg_verify_dinode(dentry);
8249 + AuDbg("positive --> positive, different type\n");
8250 + /* similar to the behaviour of removing and creating */
8253 + err = au_refresh_hinode_self(inode);
8254 + au_dbg_verify_dinode(dentry);
8262 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8264 + const struct dentry_operations *dop
8265 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8266 + static const unsigned int mask
8267 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8269 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8271 + if (dentry->d_op == dop)
8274 + AuDbg("%pd\n", dentry);
8275 + spin_lock(&dentry->d_lock);
8276 + if (dop == &aufs_dop)
8277 + dentry->d_flags |= mask;
8279 + dentry->d_flags &= ~mask;
8280 + dentry->d_op = dop;
8281 + spin_unlock(&dentry->d_lock);
8284 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8287 + unsigned int sigen;
8288 + struct au_dinfo *dinfo, *tmp;
8289 + struct super_block *sb;
8290 + struct inode *inode;
8292 + DiMustWriteLock(dentry);
8293 + AuDebugOn(IS_ROOT(dentry));
8294 + AuDebugOn(d_really_is_negative(parent));
8296 + sb = dentry->d_sb;
8297 + sigen = au_sigen(sb);
8298 + err = au_digen_test(parent, sigen);
8299 + if (unlikely(err))
8302 + dinfo = au_di(dentry);
8303 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
8304 + if (unlikely(err))
8306 + ebrange = au_dbrange_test(dentry);
8308 + ebrange = au_do_refresh_hdentry(dentry, parent);
8310 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8311 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8312 + if (d_really_is_positive(dentry)) {
8313 + inode = d_inode(dentry);
8314 + err = au_refresh_hinode_self(inode);
8316 + au_dbg_verify_dinode(dentry);
8318 + goto out_dgen; /* success */
8322 + /* temporary dinfo */
8323 + AuDbgDentry(dentry);
8325 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8326 + if (unlikely(!tmp))
8328 + au_di_swap(tmp, dinfo);
8329 + /* returns the number of positive dentries */
8331 + * if current working dir is removed, it returns an error.
8332 + * but the dentry is legal.
8334 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8335 + AuDbgDentry(dentry);
8336 + au_di_swap(tmp, dinfo);
8337 + if (err == -ENOENT)
8340 + /* compare/refresh by dinfo */
8341 + AuDbgDentry(dentry);
8342 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8343 + au_dbg_verify_dinode(dentry);
8346 + au_rw_write_unlock(&tmp->di_rwsem);
8348 + if (unlikely(err))
8352 + au_update_digen(dentry);
8354 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8355 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8356 + AuDbgDentry(dentry);
8362 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8363 + struct dentry *dentry, aufs_bindex_t bindex)
8368 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8371 + AuDbg("b%d\n", bindex);
8373 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8374 + * due to whiteout and branch permission.
8376 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8377 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8378 + /* it may return tri-state */
8379 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8381 + if (unlikely(valid < 0))
8391 +/* todo: remove this */
8392 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8393 + unsigned int flags, int do_udba)
8396 + umode_t mode, h_mode;
8397 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8398 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8399 + struct inode *h_inode, *h_cached_inode;
8400 + struct dentry *h_dentry;
8401 + struct qstr *name, *h_name;
8408 + unhashed = !!d_unhashed(dentry);
8409 + is_root = !!IS_ROOT(dentry);
8410 + name = &dentry->d_name;
8411 + tmpfile = au_di(dentry)->di_tmpfile;
8414 + * Theoretically, REVAL test should be unnecessary in case of
8416 + * But {fs,i}notify doesn't fire some necessary events,
8417 + * IN_ATTRIB for atime/nlink/pageio
8418 + * Let's do REVAL test too.
8420 + if (do_udba && inode) {
8421 + mode = (inode->i_mode & S_IFMT);
8422 + plus = (inode->i_nlink > 0);
8423 + ibs = au_ibstart(inode);
8424 + ibe = au_ibend(inode);
8427 + bstart = au_dbstart(dentry);
8429 + if (inode && S_ISDIR(inode->i_mode))
8430 + btail = au_dbtaildir(dentry);
8431 + for (bindex = bstart; bindex <= btail; bindex++) {
8432 + h_dentry = au_h_dptr(dentry, bindex);
8436 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8437 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8438 + spin_lock(&h_dentry->d_lock);
8439 + h_name = &h_dentry->d_name;
8440 + if (unlikely(do_udba
8443 + && (unhashed != !!d_unhashed(h_dentry)
8445 + && !au_qstreq(name, h_name))
8448 + && !(flags & LOOKUP_OPEN)
8449 + && (h_dentry->d_flags
8450 + & DCACHE_NFSFS_RENAMED)))
8454 + h_unhashed = d_unhashed(h_dentry);
8455 + spin_unlock(&h_dentry->d_lock);
8456 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8457 + unhashed, h_unhashed, dentry, h_dentry);
8460 + spin_unlock(&h_dentry->d_lock);
8462 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8463 + if (unlikely(err))
8464 + /* do not goto err, to keep the errno */
8467 + /* todo: plink too? */
8472 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8476 + if (d_is_positive(h_dentry))
8477 + h_inode = d_inode(h_dentry);
8480 + h_cached_inode = h_inode;
8482 + h_mode = (h_inode->i_mode & S_IFMT);
8483 + h_plus = (h_inode->i_nlink > 0);
8485 + if (inode && ibs <= bindex && bindex <= ibe)
8486 + h_cached_inode = au_h_iptr(inode, bindex);
8489 + if (unlikely(plus != h_plus && !tmpfile))
8492 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8494 + && !IS_ROOT(h_dentry)
8495 + && unhashed != d_unhashed(h_dentry)))
8498 + if (unlikely(mode != h_mode
8499 + || h_cached_inode != h_inode))
8512 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8513 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8516 + struct dentry *parent;
8518 + if (!au_digen_test(dentry, sigen))
8521 + parent = dget_parent(dentry);
8522 + di_read_lock_parent(parent, AuLock_IR);
8523 + AuDebugOn(au_digen_test(parent, sigen));
8524 + au_dbg_verify_gen(parent, sigen);
8525 + err = au_refresh_dentry(dentry, parent);
8526 + di_read_unlock(parent, AuLock_IR);
8532 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8535 + struct dentry *d, *parent;
8537 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8538 + return simple_reval_dpath(dentry, sigen);
8540 + /* slow loop, keep it simple and stupid */
8541 + /* cf: au_cpup_dirs() */
8544 + while (au_digen_test(dentry, sigen)) {
8548 + parent = dget_parent(d);
8549 + if (!au_digen_test(parent, sigen))
8555 + di_write_lock_child2(d);
8557 + /* someone might update our dentry while we were sleeping */
8558 + if (au_digen_test(d, sigen)) {
8560 + * todo: consolidate with simple_reval_dpath(),
8561 + * do_refresh() and au_reval_for_attr().
8563 + di_read_lock_parent(parent, AuLock_IR);
8564 + err = au_refresh_dentry(d, parent);
8565 + di_read_unlock(parent, AuLock_IR);
8569 + di_write_unlock(d);
8571 + if (unlikely(err))
8579 + * if valid returns 1, otherwise 0.
8581 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8584 + unsigned int sigen;
8585 + unsigned char do_udba;
8586 + struct super_block *sb;
8587 + struct inode *inode;
8589 + /* todo: support rcu-walk? */
8590 + if (flags & LOOKUP_RCU)
8594 + if (unlikely(!au_di(dentry)))
8598 + sb = dentry->d_sb;
8601 + * i_mutex of parent dir may be held,
8602 + * but we should not return 'invalid' due to busy.
8604 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8605 + if (unlikely(err)) {
8611 + if (d_really_is_positive(dentry))
8612 + inode = d_inode(dentry);
8613 + if (unlikely(inode && is_bad_inode(inode))) {
8618 + if (unlikely(au_dbrange_test(dentry))) {
8624 + sigen = au_sigen(sb);
8625 + if (au_digen_test(dentry, sigen)) {
8626 + AuDebugOn(IS_ROOT(dentry));
8627 + err = au_reval_dpath(dentry, sigen);
8628 + if (unlikely(err)) {
8633 + di_downgrade_lock(dentry, AuLock_IR);
8636 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8638 + && !(inode->i_state && I_LINKABLE)
8639 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8644 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8645 + if (do_udba && inode) {
8646 + aufs_bindex_t bstart = au_ibstart(inode);
8647 + struct inode *h_inode;
8649 + if (bstart >= 0) {
8650 + h_inode = au_h_iptr(inode, bstart);
8651 + if (h_inode && au_test_higen(inode, h_inode)) {
8658 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8659 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8661 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8667 + di_downgrade_lock(dentry, AuLock_IR);
8669 + aufs_read_unlock(dentry, AuLock_IR);
8674 + AuDbg("%pd invalid, %d\n", dentry, valid);
8680 +static void aufs_d_release(struct dentry *dentry)
8682 + if (au_di(dentry)) {
8683 + au_di_fin(dentry);
8684 + au_hn_di_reinit(dentry);
8688 +const struct dentry_operations aufs_dop = {
8689 + .d_revalidate = aufs_d_revalidate,
8690 + .d_weak_revalidate = aufs_d_revalidate,
8691 + .d_release = aufs_d_release
8694 +/* aufs_dop without d_revalidate */
8695 +const struct dentry_operations aufs_dop_noreval = {
8696 + .d_release = aufs_d_release
8698 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8699 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8700 +++ linux/fs/aufs/dentry.h 2016-04-24 18:32:51.390353525 +0200
8703 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8705 + * This program, aufs is free software; you can redistribute it and/or modify
8706 + * it under the terms of the GNU General Public License as published by
8707 + * the Free Software Foundation; either version 2 of the License, or
8708 + * (at your option) any later version.
8710 + * This program is distributed in the hope that it will be useful,
8711 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8713 + * GNU General Public License for more details.
8715 + * You should have received a copy of the GNU General Public License
8716 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8720 + * lookup and dentry operations
8723 +#ifndef __AUFS_DENTRY_H__
8724 +#define __AUFS_DENTRY_H__
8728 +#include <linux/dcache.h>
8731 +struct au_hdentry {
8732 + struct dentry *hd_dentry;
8733 + aufs_bindex_t hd_id;
8737 + atomic_t di_generation;
8739 + struct au_rwsem di_rwsem;
8740 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8741 + unsigned char di_tmpfile; /* to allow the different name */
8742 + struct au_hdentry *di_hdentry;
8743 +} ____cacheline_aligned_in_smp;
8745 +/* ---------------------------------------------------------------------- */
8748 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8750 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8751 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8752 + struct dentry *h_parent, struct au_branch *br);
8754 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8755 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8756 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8757 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8758 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8761 +void au_di_init_once(void *_di);
8762 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8763 +void au_di_free(struct au_dinfo *dinfo);
8764 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8765 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8766 +int au_di_init(struct dentry *dentry);
8767 +void au_di_fin(struct dentry *dentry);
8768 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8770 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8771 +void di_read_unlock(struct dentry *d, int flags);
8772 +void di_downgrade_lock(struct dentry *d, int flags);
8773 +void di_write_lock(struct dentry *d, unsigned int lsc);
8774 +void di_write_unlock(struct dentry *d);
8775 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8776 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8777 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8779 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8780 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8781 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8782 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8784 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8785 + struct dentry *h_dentry);
8786 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8787 +int au_dbrange_test(struct dentry *dentry);
8788 +void au_update_digen(struct dentry *dentry);
8789 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8790 +void au_update_dbstart(struct dentry *dentry);
8791 +void au_update_dbend(struct dentry *dentry);
8792 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8794 +/* ---------------------------------------------------------------------- */
8796 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8798 + return dentry->d_fsdata;
8801 +/* ---------------------------------------------------------------------- */
8803 +/* lock subclass for dinfo */
8805 + AuLsc_DI_CHILD, /* child first */
8806 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8807 + AuLsc_DI_CHILD3, /* copyup dirs */
8811 + AuLsc_DI_TMP /* temp for replacing dinfo */
8815 + * di_read_lock_child, di_write_lock_child,
8816 + * di_read_lock_child2, di_write_lock_child2,
8817 + * di_read_lock_child3, di_write_lock_child3,
8818 + * di_read_lock_parent, di_write_lock_parent,
8819 + * di_read_lock_parent2, di_write_lock_parent2,
8820 + * di_read_lock_parent3, di_write_lock_parent3,
8822 +#define AuReadLockFunc(name, lsc) \
8823 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8824 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8826 +#define AuWriteLockFunc(name, lsc) \
8827 +static inline void di_write_lock_##name(struct dentry *d) \
8828 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8830 +#define AuRWLockFuncs(name, lsc) \
8831 + AuReadLockFunc(name, lsc) \
8832 + AuWriteLockFunc(name, lsc)
8834 +AuRWLockFuncs(child, CHILD);
8835 +AuRWLockFuncs(child2, CHILD2);
8836 +AuRWLockFuncs(child3, CHILD3);
8837 +AuRWLockFuncs(parent, PARENT);
8838 +AuRWLockFuncs(parent2, PARENT2);
8839 +AuRWLockFuncs(parent3, PARENT3);
8841 +#undef AuReadLockFunc
8842 +#undef AuWriteLockFunc
8843 +#undef AuRWLockFuncs
8845 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8846 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8847 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8849 +/* ---------------------------------------------------------------------- */
8851 +/* todo: memory barrier? */
8852 +static inline unsigned int au_digen(struct dentry *d)
8854 + return atomic_read(&au_di(d)->di_generation);
8857 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8859 + hdentry->hd_dentry = NULL;
8862 +static inline void au_hdput(struct au_hdentry *hd)
8865 + dput(hd->hd_dentry);
8868 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8870 + DiMustAnyLock(dentry);
8871 + return au_di(dentry)->di_bstart;
8874 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8876 + DiMustAnyLock(dentry);
8877 + return au_di(dentry)->di_bend;
8880 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8882 + DiMustAnyLock(dentry);
8883 + return au_di(dentry)->di_bwh;
8886 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8888 + DiMustAnyLock(dentry);
8889 + return au_di(dentry)->di_bdiropq;
8892 +/* todo: hard/soft set? */
8893 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8895 + DiMustWriteLock(dentry);
8896 + au_di(dentry)->di_bstart = bindex;
8899 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8901 + DiMustWriteLock(dentry);
8902 + au_di(dentry)->di_bend = bindex;
8905 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8907 + DiMustWriteLock(dentry);
8908 + /* dbwh can be outside of bstart - bend range */
8909 + au_di(dentry)->di_bwh = bindex;
8912 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8914 + DiMustWriteLock(dentry);
8915 + au_di(dentry)->di_bdiropq = bindex;
8918 +/* ---------------------------------------------------------------------- */
8920 +#ifdef CONFIG_AUFS_HNOTIFY
8921 +static inline void au_digen_dec(struct dentry *d)
8923 + atomic_dec(&au_di(d)->di_generation);
8926 +static inline void au_hn_di_reinit(struct dentry *dentry)
8928 + dentry->d_fsdata = NULL;
8931 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8932 +#endif /* CONFIG_AUFS_HNOTIFY */
8934 +#endif /* __KERNEL__ */
8935 +#endif /* __AUFS_DENTRY_H__ */
8936 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8937 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8938 +++ linux/fs/aufs/dinfo.c 2016-04-24 18:32:51.390353525 +0200
8941 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8943 + * This program, aufs is free software; you can redistribute it and/or modify
8944 + * it under the terms of the GNU General Public License as published by
8945 + * the Free Software Foundation; either version 2 of the License, or
8946 + * (at your option) any later version.
8948 + * This program is distributed in the hope that it will be useful,
8949 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8950 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8951 + * GNU General Public License for more details.
8953 + * You should have received a copy of the GNU General Public License
8954 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8958 + * dentry private data
8963 +void au_di_init_once(void *_dinfo)
8965 + struct au_dinfo *dinfo = _dinfo;
8966 + static struct lock_class_key aufs_di;
8968 + au_rw_init(&dinfo->di_rwsem);
8969 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8972 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8974 + struct au_dinfo *dinfo;
8977 + dinfo = au_cache_alloc_dinfo();
8978 + if (unlikely(!dinfo))
8981 + nbr = au_sbend(sb) + 1;
8984 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8985 + if (dinfo->di_hdentry) {
8986 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8987 + dinfo->di_bstart = -1;
8988 + dinfo->di_bend = -1;
8989 + dinfo->di_bwh = -1;
8990 + dinfo->di_bdiropq = -1;
8991 + dinfo->di_tmpfile = 0;
8992 + for (i = 0; i < nbr; i++)
8993 + dinfo->di_hdentry[i].hd_id = -1;
8997 + au_cache_free_dinfo(dinfo);
9004 +void au_di_free(struct au_dinfo *dinfo)
9006 + struct au_hdentry *p;
9007 + aufs_bindex_t bend, bindex;
9009 + /* dentry may not be revalidated */
9010 + bindex = dinfo->di_bstart;
9011 + if (bindex >= 0) {
9012 + bend = dinfo->di_bend;
9013 + p = dinfo->di_hdentry + bindex;
9014 + while (bindex++ <= bend)
9017 + kfree(dinfo->di_hdentry);
9018 + au_cache_free_dinfo(dinfo);
9021 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9023 + struct au_hdentry *p;
9026 + AuRwMustWriteLock(&a->di_rwsem);
9027 + AuRwMustWriteLock(&b->di_rwsem);
9029 +#define DiSwap(v, name) \
9031 + v = a->di_##name; \
9032 + a->di_##name = b->di_##name; \
9033 + b->di_##name = v; \
9036 + DiSwap(p, hdentry);
9037 + DiSwap(bi, bstart);
9040 + DiSwap(bi, bdiropq);
9046 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9048 + AuRwMustWriteLock(&dst->di_rwsem);
9049 + AuRwMustWriteLock(&src->di_rwsem);
9051 + dst->di_bstart = src->di_bstart;
9052 + dst->di_bend = src->di_bend;
9053 + dst->di_bwh = src->di_bwh;
9054 + dst->di_bdiropq = src->di_bdiropq;
9058 +int au_di_init(struct dentry *dentry)
9061 + struct super_block *sb;
9062 + struct au_dinfo *dinfo;
9065 + sb = dentry->d_sb;
9066 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9068 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9069 + /* smp_mb(); */ /* atomic_set */
9070 + dentry->d_fsdata = dinfo;
9077 +void au_di_fin(struct dentry *dentry)
9079 + struct au_dinfo *dinfo;
9081 + dinfo = au_di(dentry);
9082 + AuRwDestroy(&dinfo->di_rwsem);
9083 + au_di_free(dinfo);
9086 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
9089 + struct au_hdentry *hdp;
9091 + AuRwMustWriteLock(&dinfo->di_rwsem);
9094 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
9096 + sz = sizeof(*hdp);
9097 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
9099 + dinfo->di_hdentry = hdp;
9106 +/* ---------------------------------------------------------------------- */
9108 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9111 + case AuLsc_DI_CHILD:
9112 + ii_write_lock_child(inode);
9114 + case AuLsc_DI_CHILD2:
9115 + ii_write_lock_child2(inode);
9117 + case AuLsc_DI_CHILD3:
9118 + ii_write_lock_child3(inode);
9120 + case AuLsc_DI_PARENT:
9121 + ii_write_lock_parent(inode);
9123 + case AuLsc_DI_PARENT2:
9124 + ii_write_lock_parent2(inode);
9126 + case AuLsc_DI_PARENT3:
9127 + ii_write_lock_parent3(inode);
9134 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9137 + case AuLsc_DI_CHILD:
9138 + ii_read_lock_child(inode);
9140 + case AuLsc_DI_CHILD2:
9141 + ii_read_lock_child2(inode);
9143 + case AuLsc_DI_CHILD3:
9144 + ii_read_lock_child3(inode);
9146 + case AuLsc_DI_PARENT:
9147 + ii_read_lock_parent(inode);
9149 + case AuLsc_DI_PARENT2:
9150 + ii_read_lock_parent2(inode);
9152 + case AuLsc_DI_PARENT3:
9153 + ii_read_lock_parent3(inode);
9160 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9162 + struct inode *inode;
9164 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9165 + if (d_really_is_positive(d)) {
9166 + inode = d_inode(d);
9167 + if (au_ftest_lock(flags, IW))
9168 + do_ii_write_lock(inode, lsc);
9169 + else if (au_ftest_lock(flags, IR))
9170 + do_ii_read_lock(inode, lsc);
9174 +void di_read_unlock(struct dentry *d, int flags)
9176 + struct inode *inode;
9178 + if (d_really_is_positive(d)) {
9179 + inode = d_inode(d);
9180 + if (au_ftest_lock(flags, IW)) {
9181 + au_dbg_verify_dinode(d);
9182 + ii_write_unlock(inode);
9183 + } else if (au_ftest_lock(flags, IR)) {
9184 + au_dbg_verify_dinode(d);
9185 + ii_read_unlock(inode);
9188 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9191 +void di_downgrade_lock(struct dentry *d, int flags)
9193 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9194 + ii_downgrade_lock(d_inode(d));
9195 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9198 +void di_write_lock(struct dentry *d, unsigned int lsc)
9200 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9201 + if (d_really_is_positive(d))
9202 + do_ii_write_lock(d_inode(d), lsc);
9205 +void di_write_unlock(struct dentry *d)
9207 + au_dbg_verify_dinode(d);
9208 + if (d_really_is_positive(d))
9209 + ii_write_unlock(d_inode(d));
9210 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9213 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9215 + AuDebugOn(d1 == d2
9216 + || d_inode(d1) == d_inode(d2)
9217 + || d1->d_sb != d2->d_sb);
9219 + if (isdir && au_test_subdir(d1, d2)) {
9220 + di_write_lock_child(d1);
9221 + di_write_lock_child2(d2);
9223 + /* there should be no races */
9224 + di_write_lock_child(d2);
9225 + di_write_lock_child2(d1);
9229 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9231 + AuDebugOn(d1 == d2
9232 + || d_inode(d1) == d_inode(d2)
9233 + || d1->d_sb != d2->d_sb);
9235 + if (isdir && au_test_subdir(d1, d2)) {
9236 + di_write_lock_parent(d1);
9237 + di_write_lock_parent2(d2);
9239 + /* there should be no races */
9240 + di_write_lock_parent(d2);
9241 + di_write_lock_parent2(d1);
9245 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9247 + di_write_unlock(d1);
9248 + if (d_inode(d1) == d_inode(d2))
9249 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9251 + di_write_unlock(d2);
9254 +/* ---------------------------------------------------------------------- */
9256 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9260 + DiMustAnyLock(dentry);
9262 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
9264 + AuDebugOn(bindex < 0);
9265 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
9266 + AuDebugOn(d && au_dcount(d) <= 0);
9271 + * extended version of au_h_dptr().
9272 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9275 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9277 + struct dentry *h_dentry;
9278 + struct inode *inode, *h_inode;
9280 + AuDebugOn(d_really_is_negative(dentry));
9283 + if (au_dbstart(dentry) <= bindex
9284 + && bindex <= au_dbend(dentry))
9285 + h_dentry = au_h_dptr(dentry, bindex);
9286 + if (h_dentry && !au_d_linkable(h_dentry)) {
9288 + goto out; /* success */
9291 + inode = d_inode(dentry);
9292 + AuDebugOn(bindex < au_ibstart(inode));
9293 + AuDebugOn(au_ibend(inode) < bindex);
9294 + h_inode = au_h_iptr(inode, bindex);
9295 + h_dentry = d_find_alias(h_inode);
9297 + if (!IS_ERR(h_dentry)) {
9298 + if (!au_d_linkable(h_dentry))
9299 + goto out; /* success */
9305 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9306 + h_dentry = au_plink_lkup(inode, bindex);
9307 + AuDebugOn(!h_dentry);
9308 + if (!IS_ERR(h_dentry)) {
9309 + if (!au_d_hashed_positive(h_dentry))
9310 + goto out; /* success */
9317 + AuDbgDentry(h_dentry);
9321 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9323 + aufs_bindex_t bend, bwh;
9325 + bend = au_dbend(dentry);
9327 + bwh = au_dbwh(dentry);
9330 + if (0 < bwh && bwh < bend)
9336 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9338 + aufs_bindex_t bend, bopq;
9340 + bend = au_dbtail(dentry);
9342 + bopq = au_dbdiropq(dentry);
9343 + if (0 <= bopq && bopq < bend)
9349 +/* ---------------------------------------------------------------------- */
9351 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9352 + struct dentry *h_dentry)
9354 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9355 + struct au_branch *br;
9357 + DiMustWriteLock(dentry);
9360 + hd->hd_dentry = h_dentry;
9362 + br = au_sbr(dentry->d_sb, bindex);
9363 + hd->hd_id = br->br_id;
9367 +int au_dbrange_test(struct dentry *dentry)
9370 + aufs_bindex_t bstart, bend;
9373 + bstart = au_dbstart(dentry);
9374 + bend = au_dbend(dentry);
9376 + AuDebugOn(bend < 0 && bstart > bend);
9379 + AuDebugOn(bend >= 0);
9385 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9390 + if (unlikely(au_digen(dentry) != sigen
9391 + || au_iigen_test(d_inode(dentry), sigen)))
9397 +void au_update_digen(struct dentry *dentry)
9399 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9400 + /* smp_mb(); */ /* atomic_set */
9403 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9405 + struct au_dinfo *dinfo;
9406 + struct dentry *h_d;
9407 + struct au_hdentry *hdp;
9409 + DiMustWriteLock(dentry);
9411 + dinfo = au_di(dentry);
9412 + if (!dinfo || dinfo->di_bstart < 0)
9415 + hdp = dinfo->di_hdentry;
9416 + if (do_put_zero) {
9417 + aufs_bindex_t bindex, bend;
9419 + bend = dinfo->di_bend;
9420 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9421 + h_d = hdp[0 + bindex].hd_dentry;
9422 + if (h_d && d_is_negative(h_d))
9423 + au_set_h_dptr(dentry, bindex, NULL);
9427 + dinfo->di_bstart = -1;
9428 + while (++dinfo->di_bstart <= dinfo->di_bend)
9429 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9431 + if (dinfo->di_bstart > dinfo->di_bend) {
9432 + dinfo->di_bstart = -1;
9433 + dinfo->di_bend = -1;
9438 + while (0 <= --dinfo->di_bend)
9439 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9441 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9444 +void au_update_dbstart(struct dentry *dentry)
9446 + aufs_bindex_t bindex, bend;
9447 + struct dentry *h_dentry;
9449 + bend = au_dbend(dentry);
9450 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9451 + h_dentry = au_h_dptr(dentry, bindex);
9454 + if (d_is_positive(h_dentry)) {
9455 + au_set_dbstart(dentry, bindex);
9458 + au_set_h_dptr(dentry, bindex, NULL);
9462 +void au_update_dbend(struct dentry *dentry)
9464 + aufs_bindex_t bindex, bstart;
9465 + struct dentry *h_dentry;
9467 + bstart = au_dbstart(dentry);
9468 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9469 + h_dentry = au_h_dptr(dentry, bindex);
9472 + if (d_is_positive(h_dentry)) {
9473 + au_set_dbend(dentry, bindex);
9476 + au_set_h_dptr(dentry, bindex, NULL);
9480 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9482 + aufs_bindex_t bindex, bend;
9484 + bend = au_dbend(dentry);
9485 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9486 + if (au_h_dptr(dentry, bindex) == h_dentry)
9490 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9491 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9492 +++ linux/fs/aufs/dir.c 2016-04-24 18:32:51.390353525 +0200
9495 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9497 + * This program, aufs is free software; you can redistribute it and/or modify
9498 + * it under the terms of the GNU General Public License as published by
9499 + * the Free Software Foundation; either version 2 of the License, or
9500 + * (at your option) any later version.
9502 + * This program is distributed in the hope that it will be useful,
9503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9505 + * GNU General Public License for more details.
9507 + * You should have received a copy of the GNU General Public License
9508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9512 + * directory operations
9515 +#include <linux/fs_stack.h>
9518 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9520 + unsigned int nlink;
9522 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9524 + nlink = dir->i_nlink;
9525 + nlink += h_dir->i_nlink - 2;
9526 + if (h_dir->i_nlink < 2)
9528 + smp_mb(); /* for i_nlink */
9529 + /* 0 can happen in revaliding */
9530 + set_nlink(dir, nlink);
9533 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9535 + unsigned int nlink;
9537 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9539 + nlink = dir->i_nlink;
9540 + nlink -= h_dir->i_nlink - 2;
9541 + if (h_dir->i_nlink < 2)
9543 + smp_mb(); /* for i_nlink */
9544 + /* nlink == 0 means the branch-fs is broken */
9545 + set_nlink(dir, nlink);
9548 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9551 + aufs_bindex_t bindex, bend;
9552 + struct file *h_file;
9553 + struct dentry *h_dentry;
9557 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9559 + bend = au_fbend_dir(file);
9560 + for (bindex = au_fbstart(file);
9561 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9563 + h_file = au_hf_dir(file, bindex);
9564 + if (h_file && file_inode(h_file))
9565 + sz += vfsub_f_size_read(h_file);
9568 + AuDebugOn(!dentry);
9569 + AuDebugOn(!d_is_dir(dentry));
9571 + bend = au_dbtaildir(dentry);
9572 + for (bindex = au_dbstart(dentry);
9573 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9575 + h_dentry = au_h_dptr(dentry, bindex);
9576 + if (h_dentry && d_is_positive(h_dentry))
9577 + sz += i_size_read(d_inode(h_dentry));
9580 + if (sz < KMALLOC_MAX_SIZE)
9581 + sz = roundup_pow_of_two(sz);
9582 + if (sz > KMALLOC_MAX_SIZE)
9583 + sz = KMALLOC_MAX_SIZE;
9584 + else if (sz < NAME_MAX) {
9585 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9586 + sz = AUFS_RDBLK_DEF;
9591 +struct au_dir_ts_arg {
9592 + struct dentry *dentry;
9593 + aufs_bindex_t brid;
9596 +static void au_do_dir_ts(void *arg)
9598 + struct au_dir_ts_arg *a = arg;
9599 + struct au_dtime dt;
9600 + struct path h_path;
9601 + struct inode *dir, *h_dir;
9602 + struct super_block *sb;
9603 + struct au_branch *br;
9604 + struct au_hinode *hdir;
9606 + aufs_bindex_t bstart, bindex;
9608 + sb = a->dentry->d_sb;
9609 + if (d_really_is_negative(a->dentry))
9611 + /* no dir->i_mutex lock */
9612 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9614 + dir = d_inode(a->dentry);
9615 + bstart = au_ibstart(dir);
9616 + bindex = au_br_index(sb, a->brid);
9617 + if (bindex < bstart)
9620 + br = au_sbr(sb, bindex);
9621 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9622 + if (!h_path.dentry)
9624 + h_path.mnt = au_br_mnt(br);
9625 + au_dtime_store(&dt, a->dentry, &h_path);
9627 + br = au_sbr(sb, bstart);
9628 + if (!au_br_writable(br->br_perm))
9630 + h_path.dentry = au_h_dptr(a->dentry, bstart);
9631 + h_path.mnt = au_br_mnt(br);
9632 + err = vfsub_mnt_want_write(h_path.mnt);
9635 + hdir = au_hi(dir, bstart);
9636 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
9637 + h_dir = au_h_iptr(dir, bstart);
9638 + if (h_dir->i_nlink
9639 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9640 + dt.dt_h_path = h_path;
9641 + au_dtime_revert(&dt);
9643 + au_hn_imtx_unlock(hdir);
9644 + vfsub_mnt_drop_write(h_path.mnt);
9645 + au_cpup_attr_timesizes(dir);
9648 + aufs_read_unlock(a->dentry, AuLock_DW);
9651 + au_nwt_done(&au_sbi(sb)->si_nowait);
9655 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9657 + int perm, wkq_err;
9658 + aufs_bindex_t bstart;
9659 + struct au_dir_ts_arg *arg;
9660 + struct dentry *dentry;
9661 + struct super_block *sb;
9665 + dentry = d_find_any_alias(dir);
9666 + AuDebugOn(!dentry);
9667 + sb = dentry->d_sb;
9668 + bstart = au_ibstart(dir);
9669 + if (bstart == bindex) {
9670 + au_cpup_attr_timesizes(dir);
9674 + perm = au_sbr_perm(sb, bstart);
9675 + if (!au_br_writable(perm))
9678 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9682 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9683 + arg->brid = au_sbr_id(sb, bindex);
9684 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9685 + if (unlikely(wkq_err)) {
9686 + pr_err("wkq %d\n", wkq_err);
9695 +/* ---------------------------------------------------------------------- */
9697 +static int reopen_dir(struct file *file)
9700 + unsigned int flags;
9701 + aufs_bindex_t bindex, btail, bstart;
9702 + struct dentry *dentry, *h_dentry;
9703 + struct file *h_file;
9705 + /* open all lower dirs */
9706 + dentry = file->f_path.dentry;
9707 + bstart = au_dbstart(dentry);
9708 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9709 + au_set_h_fptr(file, bindex, NULL);
9710 + au_set_fbstart(file, bstart);
9712 + btail = au_dbtaildir(dentry);
9713 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9714 + au_set_h_fptr(file, bindex, NULL);
9715 + au_set_fbend_dir(file, btail);
9717 + flags = vfsub_file_flags(file);
9718 + for (bindex = bstart; bindex <= btail; bindex++) {
9719 + h_dentry = au_h_dptr(dentry, bindex);
9722 + h_file = au_hf_dir(file, bindex);
9726 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9727 + err = PTR_ERR(h_file);
9728 + if (IS_ERR(h_file))
9729 + goto out; /* close all? */
9730 + au_set_h_fptr(file, bindex, h_file);
9732 + au_update_figen(file);
9733 + /* todo: necessary? */
9734 + /* file->f_ra = h_file->f_ra; */
9741 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9744 + aufs_bindex_t bindex, btail;
9745 + struct dentry *dentry, *h_dentry;
9746 + struct vfsmount *mnt;
9748 + FiMustWriteLock(file);
9749 + AuDebugOn(h_file);
9752 + mnt = file->f_path.mnt;
9753 + dentry = file->f_path.dentry;
9754 + file->f_version = d_inode(dentry)->i_version;
9755 + bindex = au_dbstart(dentry);
9756 + au_set_fbstart(file, bindex);
9757 + btail = au_dbtaildir(dentry);
9758 + au_set_fbend_dir(file, btail);
9759 + for (; !err && bindex <= btail; bindex++) {
9760 + h_dentry = au_h_dptr(dentry, bindex);
9764 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9765 + if (unlikely(err))
9767 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9768 + if (IS_ERR(h_file)) {
9769 + err = PTR_ERR(h_file);
9772 + au_set_h_fptr(file, bindex, h_file);
9774 + au_update_figen(file);
9775 + /* todo: necessary? */
9776 + /* file->f_ra = h_file->f_ra; */
9778 + return 0; /* success */
9781 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9782 + au_set_h_fptr(file, bindex, NULL);
9783 + au_set_fbstart(file, -1);
9784 + au_set_fbend_dir(file, -1);
9789 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9790 + struct file *file)
9793 + struct super_block *sb;
9794 + struct au_fidir *fidir;
9797 + sb = file->f_path.dentry->d_sb;
9798 + si_read_lock(sb, AuLock_FLUSH);
9799 + fidir = au_fidir_alloc(sb);
9801 + struct au_do_open_args args = {
9802 + .open = do_open_dir,
9805 + err = au_do_open(file, &args);
9806 + if (unlikely(err))
9809 + si_read_unlock(sb);
9813 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9814 + struct file *file)
9816 + struct au_vdir *vdir_cache;
9817 + struct au_finfo *finfo;
9818 + struct au_fidir *fidir;
9819 + aufs_bindex_t bindex, bend;
9821 + finfo = au_fi(file);
9822 + fidir = finfo->fi_hdir;
9824 + au_sphl_del(&finfo->fi_hlist,
9825 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9826 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9828 + au_vdir_free(vdir_cache);
9830 + bindex = finfo->fi_btop;
9831 + if (bindex >= 0) {
9833 + * calls fput() instead of filp_close(),
9834 + * since no dnotify or lock for the lower file.
9836 + bend = fidir->fd_bbot;
9837 + for (; bindex <= bend; bindex++)
9838 + au_set_h_fptr(file, bindex, NULL);
9841 + finfo->fi_hdir = NULL;
9843 + au_finfo_fin(file);
9847 +/* ---------------------------------------------------------------------- */
9849 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9852 + aufs_bindex_t bindex, bend;
9853 + struct file *h_file;
9856 + bend = au_fbend_dir(file);
9857 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9858 + h_file = au_hf_dir(file, bindex);
9860 + err = vfsub_flush(h_file, id);
9865 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9867 + return au_do_flush(file, id, au_do_flush_dir);
9870 +/* ---------------------------------------------------------------------- */
9872 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9875 + aufs_bindex_t bend, bindex;
9876 + struct inode *inode;
9877 + struct super_block *sb;
9880 + sb = dentry->d_sb;
9881 + inode = d_inode(dentry);
9883 + bend = au_dbend(dentry);
9884 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9885 + struct path h_path;
9887 + if (au_test_ro(sb, bindex, inode))
9889 + h_path.dentry = au_h_dptr(dentry, bindex);
9890 + if (!h_path.dentry)
9893 + h_path.mnt = au_sbr_mnt(sb, bindex);
9894 + err = vfsub_fsync(NULL, &h_path, datasync);
9900 +static int au_do_fsync_dir(struct file *file, int datasync)
9903 + aufs_bindex_t bend, bindex;
9904 + struct file *h_file;
9905 + struct super_block *sb;
9906 + struct inode *inode;
9908 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9909 + if (unlikely(err))
9912 + inode = file_inode(file);
9914 + bend = au_fbend_dir(file);
9915 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9916 + h_file = au_hf_dir(file, bindex);
9917 + if (!h_file || au_test_ro(sb, bindex, inode))
9920 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9928 + * @file may be NULL
9930 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9934 + struct dentry *dentry;
9935 + struct inode *inode;
9936 + struct super_block *sb;
9939 + dentry = file->f_path.dentry;
9940 + inode = d_inode(dentry);
9941 + inode_lock(inode);
9942 + sb = dentry->d_sb;
9943 + si_noflush_read_lock(sb);
9945 + err = au_do_fsync_dir(file, datasync);
9947 + di_write_lock_child(dentry);
9948 + err = au_do_fsync_dir_no_file(dentry, datasync);
9950 + au_cpup_attr_timesizes(inode);
9951 + di_write_unlock(dentry);
9953 + fi_write_unlock(file);
9955 + si_read_unlock(sb);
9956 + inode_unlock(inode);
9960 +/* ---------------------------------------------------------------------- */
9962 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9965 + struct dentry *dentry;
9966 + struct inode *inode, *h_inode;
9967 + struct super_block *sb;
9969 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9971 + dentry = file->f_path.dentry;
9972 + inode = d_inode(dentry);
9975 + sb = dentry->d_sb;
9976 + si_read_lock(sb, AuLock_FLUSH);
9977 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9978 + if (unlikely(err))
9980 + err = au_alive_dir(dentry);
9982 + err = au_vdir_init(file);
9983 + di_downgrade_lock(dentry, AuLock_IR);
9984 + if (unlikely(err))
9987 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9988 + if (!au_test_nfsd()) {
9989 + err = au_vdir_fill_de(file, ctx);
9990 + fsstack_copy_attr_atime(inode, h_inode);
9993 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9994 + * encode_fh() and others.
9996 + atomic_inc(&h_inode->i_count);
9997 + di_read_unlock(dentry, AuLock_IR);
9998 + si_read_unlock(sb);
9999 + err = au_vdir_fill_de(file, ctx);
10000 + fsstack_copy_attr_atime(inode, h_inode);
10001 + fi_write_unlock(file);
10009 + di_read_unlock(dentry, AuLock_IR);
10010 + fi_write_unlock(file);
10012 + si_read_unlock(sb);
10016 +/* ---------------------------------------------------------------------- */
10018 +#define AuTestEmpty_WHONLY 1
10019 +#define AuTestEmpty_CALLED (1 << 1)
10020 +#define AuTestEmpty_SHWH (1 << 2)
10021 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10022 +#define au_fset_testempty(flags, name) \
10023 + do { (flags) |= AuTestEmpty_##name; } while (0)
10024 +#define au_fclr_testempty(flags, name) \
10025 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10027 +#ifndef CONFIG_AUFS_SHWH
10028 +#undef AuTestEmpty_SHWH
10029 +#define AuTestEmpty_SHWH 0
10032 +struct test_empty_arg {
10033 + struct dir_context ctx;
10034 + struct au_nhash *whlist;
10035 + unsigned int flags;
10037 + aufs_bindex_t bindex;
10040 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10041 + int namelen, loff_t offset __maybe_unused, u64 ino,
10042 + unsigned int d_type)
10044 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10046 + char *name = (void *)__name;
10049 + au_fset_testempty(arg->flags, CALLED);
10051 + if (name[0] == '.'
10052 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10053 + goto out; /* success */
10055 + if (namelen <= AUFS_WH_PFX_LEN
10056 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10057 + if (au_ftest_testempty(arg->flags, WHONLY)
10058 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10059 + arg->err = -ENOTEMPTY;
10063 + name += AUFS_WH_PFX_LEN;
10064 + namelen -= AUFS_WH_PFX_LEN;
10065 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10066 + arg->err = au_nhash_append_wh
10067 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10068 + au_ftest_testempty(arg->flags, SHWH));
10072 + AuTraceErr(arg->err);
10076 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10079 + struct file *h_file;
10081 + h_file = au_h_open(dentry, arg->bindex,
10082 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10083 + /*file*/NULL, /*force_wr*/0);
10084 + err = PTR_ERR(h_file);
10085 + if (IS_ERR(h_file))
10089 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10090 + && !file_inode(h_file)->i_nlink)
10095 + au_fclr_testempty(arg->flags, CALLED);
10097 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10100 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10104 + au_sbr_put(dentry->d_sb, arg->bindex);
10109 +struct do_test_empty_args {
10111 + struct dentry *dentry;
10112 + struct test_empty_arg *arg;
10115 +static void call_do_test_empty(void *args)
10117 + struct do_test_empty_args *a = args;
10118 + *a->errp = do_test_empty(a->dentry, a->arg);
10121 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10123 + int err, wkq_err;
10124 + struct dentry *h_dentry;
10125 + struct inode *h_inode;
10127 + h_dentry = au_h_dptr(dentry, arg->bindex);
10128 + h_inode = d_inode(h_dentry);
10129 + /* todo: i_mode changes anytime? */
10130 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
10131 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10132 + inode_unlock(h_inode);
10134 + err = do_test_empty(dentry, arg);
10136 + struct do_test_empty_args args = {
10138 + .dentry = dentry,
10141 + unsigned int flags = arg->flags;
10143 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10144 + if (unlikely(wkq_err))
10146 + arg->flags = flags;
10152 +int au_test_empty_lower(struct dentry *dentry)
10155 + unsigned int rdhash;
10156 + aufs_bindex_t bindex, bstart, btail;
10157 + struct au_nhash whlist;
10158 + struct test_empty_arg arg = {
10160 + .actor = test_empty_cb
10163 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10165 + SiMustAnyLock(dentry->d_sb);
10167 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10169 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10170 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10171 + if (unlikely(err))
10175 + arg.whlist = &whlist;
10176 + bstart = au_dbstart(dentry);
10177 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10178 + au_fset_testempty(arg.flags, SHWH);
10179 + test_empty = do_test_empty;
10180 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10181 + test_empty = sio_test_empty;
10182 + arg.bindex = bstart;
10183 + err = test_empty(dentry, &arg);
10184 + if (unlikely(err))
10187 + au_fset_testempty(arg.flags, WHONLY);
10188 + btail = au_dbtaildir(dentry);
10189 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
10190 + struct dentry *h_dentry;
10192 + h_dentry = au_h_dptr(dentry, bindex);
10193 + if (h_dentry && d_is_positive(h_dentry)) {
10194 + arg.bindex = bindex;
10195 + err = test_empty(dentry, &arg);
10200 + au_nhash_wh_free(&whlist);
10205 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10208 + struct test_empty_arg arg = {
10210 + .actor = test_empty_cb
10213 + aufs_bindex_t bindex, btail;
10216 + arg.whlist = whlist;
10217 + arg.flags = AuTestEmpty_WHONLY;
10218 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10219 + au_fset_testempty(arg.flags, SHWH);
10220 + btail = au_dbtaildir(dentry);
10221 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
10222 + struct dentry *h_dentry;
10224 + h_dentry = au_h_dptr(dentry, bindex);
10225 + if (h_dentry && d_is_positive(h_dentry)) {
10226 + arg.bindex = bindex;
10227 + err = sio_test_empty(dentry, &arg);
10234 +/* ---------------------------------------------------------------------- */
10236 +const struct file_operations aufs_dir_fop = {
10237 + .owner = THIS_MODULE,
10238 + .llseek = default_llseek,
10239 + .read = generic_read_dir,
10240 + .iterate = aufs_iterate,
10241 + .unlocked_ioctl = aufs_ioctl_dir,
10242 +#ifdef CONFIG_COMPAT
10243 + .compat_ioctl = aufs_compat_ioctl_dir,
10245 + .open = aufs_open_dir,
10246 + .release = aufs_release_dir,
10247 + .flush = aufs_flush_dir,
10248 + .fsync = aufs_fsync_dir
10250 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10251 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10252 +++ linux/fs/aufs/dir.h 2016-04-24 18:32:51.390353525 +0200
10255 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10257 + * This program, aufs is free software; you can redistribute it and/or modify
10258 + * it under the terms of the GNU General Public License as published by
10259 + * the Free Software Foundation; either version 2 of the License, or
10260 + * (at your option) any later version.
10262 + * This program is distributed in the hope that it will be useful,
10263 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10264 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10265 + * GNU General Public License for more details.
10267 + * You should have received a copy of the GNU General Public License
10268 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10272 + * directory operations
10275 +#ifndef __AUFS_DIR_H__
10276 +#define __AUFS_DIR_H__
10280 +#include <linux/fs.h>
10282 +/* ---------------------------------------------------------------------- */
10284 +/* need to be faster and smaller */
10287 + unsigned int nh_num;
10288 + struct hlist_head *nh_head;
10291 +struct au_vdir_destr {
10292 + unsigned char len;
10293 + unsigned char name[0];
10296 +struct au_vdir_dehstr {
10297 + struct hlist_node hash;
10298 + struct au_vdir_destr *str;
10299 +} ____cacheline_aligned_in_smp;
10301 +struct au_vdir_de {
10303 + unsigned char de_type;
10304 + /* caution: packed */
10305 + struct au_vdir_destr de_str;
10308 +struct au_vdir_wh {
10309 + struct hlist_node wh_hash;
10310 +#ifdef CONFIG_AUFS_SHWH
10312 + aufs_bindex_t wh_bindex;
10313 + unsigned char wh_type;
10315 + aufs_bindex_t wh_bindex;
10317 + /* caution: packed */
10318 + struct au_vdir_destr wh_str;
10321 +union au_vdir_deblk_p {
10322 + unsigned char *deblk;
10323 + struct au_vdir_de *de;
10327 + unsigned char **vd_deblk;
10328 + unsigned long vd_nblk;
10330 + unsigned long ul;
10331 + union au_vdir_deblk_p p;
10334 + unsigned long vd_version;
10335 + unsigned int vd_deblk_sz;
10336 + unsigned long vd_jiffy;
10337 +} ____cacheline_aligned_in_smp;
10339 +/* ---------------------------------------------------------------------- */
10342 +extern const struct file_operations aufs_dir_fop;
10343 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10344 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10345 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10346 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10347 +int au_test_empty_lower(struct dentry *dentry);
10348 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10351 +unsigned int au_rdhash_est(loff_t sz);
10352 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10353 +void au_nhash_wh_free(struct au_nhash *whlist);
10354 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10356 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10357 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10358 + unsigned int d_type, aufs_bindex_t bindex,
10359 + unsigned char shwh);
10360 +void au_vdir_free(struct au_vdir *vdir);
10361 +int au_vdir_init(struct file *file);
10362 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10365 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10367 +#ifdef CONFIG_AUFS_RDU
10369 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10370 +#ifdef CONFIG_COMPAT
10371 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10372 + unsigned long arg);
10375 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10376 + unsigned int cmd, unsigned long arg)
10377 +#ifdef CONFIG_COMPAT
10378 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10379 + unsigned int cmd, unsigned long arg)
10383 +#endif /* __KERNEL__ */
10384 +#endif /* __AUFS_DIR_H__ */
10385 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10386 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10387 +++ linux/fs/aufs/dynop.c 2016-04-24 18:32:51.390353525 +0200
10390 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10392 + * This program, aufs is free software; you can redistribute it and/or modify
10393 + * it under the terms of the GNU General Public License as published by
10394 + * the Free Software Foundation; either version 2 of the License, or
10395 + * (at your option) any later version.
10397 + * This program is distributed in the hope that it will be useful,
10398 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10399 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10400 + * GNU General Public License for more details.
10402 + * You should have received a copy of the GNU General Public License
10403 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10407 + * dynamically customizable operations for regular files
10412 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10415 + * How large will these lists be?
10416 + * Usually just a few elements, 20-30 at most for each, I guess.
10418 +static struct au_splhead dynop[AuDyLast];
10420 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
10422 + struct au_dykey *key, *tmp;
10423 + struct list_head *head;
10426 + head = &spl->head;
10428 + list_for_each_entry_rcu(tmp, head, dk_list)
10429 + if (tmp->dk_op.dy_hop == h_op) {
10431 + kref_get(&key->dk_kref);
10434 + rcu_read_unlock();
10439 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10441 + struct au_dykey **k, *found;
10442 + const void *h_op = key->dk_op.dy_hop;
10446 + k = br->br_dykey;
10447 + for (i = 0; i < AuBrDynOp; i++)
10449 + if (k[i]->dk_op.dy_hop == h_op) {
10456 + spin_lock(&br->br_dykey_lock);
10457 + for (; i < AuBrDynOp; i++)
10459 + if (k[i]->dk_op.dy_hop == h_op) {
10467 + spin_unlock(&br->br_dykey_lock);
10468 + BUG_ON(i == AuBrDynOp); /* expand the array */
10474 +/* kref_get() if @key is already added */
10475 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10477 + struct au_dykey *tmp, *found;
10478 + struct list_head *head;
10479 + const void *h_op = key->dk_op.dy_hop;
10482 + head = &spl->head;
10483 + spin_lock(&spl->spin);
10484 + list_for_each_entry(tmp, head, dk_list)
10485 + if (tmp->dk_op.dy_hop == h_op) {
10486 + kref_get(&tmp->dk_kref);
10491 + list_add_rcu(&key->dk_list, head);
10492 + spin_unlock(&spl->spin);
10499 +static void dy_free_rcu(struct rcu_head *rcu)
10501 + struct au_dykey *key;
10503 + key = container_of(rcu, struct au_dykey, dk_rcu);
10508 +static void dy_free(struct kref *kref)
10510 + struct au_dykey *key;
10511 + struct au_splhead *spl;
10513 + key = container_of(kref, struct au_dykey, dk_kref);
10514 + spl = dynop + key->dk_op.dy_type;
10515 + au_spl_del_rcu(&key->dk_list, spl);
10516 + call_rcu(&key->dk_rcu, dy_free_rcu);
10519 +void au_dy_put(struct au_dykey *key)
10521 + kref_put(&key->dk_kref, dy_free);
10524 +/* ---------------------------------------------------------------------- */
10526 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10528 +#ifdef CONFIG_AUFS_DEBUG
10529 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10530 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10532 +#define DyDbgDeclare(cnt) do {} while (0)
10533 +#define DyDbgInc(cnt) do {} while (0)
10536 +#define DySet(func, dst, src, h_op, h_sb) do { \
10538 + if (h_op->func) { \
10540 + dst.func = src.func; \
10542 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10546 +#define DySetForce(func, dst, src) do { \
10547 + AuDebugOn(!src.func); \
10549 + dst.func = src.func; \
10552 +#define DySetAop(func) \
10553 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10554 +#define DySetAopForce(func) \
10555 + DySetForce(func, dyaop->da_op, aufs_aop)
10557 +static void dy_aop(struct au_dykey *key, const void *h_op,
10558 + struct super_block *h_sb __maybe_unused)
10560 + struct au_dyaop *dyaop = (void *)key;
10561 + const struct address_space_operations *h_aop = h_op;
10562 + DyDbgDeclare(cnt);
10564 + AuDbg("%s\n", au_sbtype(h_sb));
10566 + DySetAop(writepage);
10567 + DySetAopForce(readpage); /* force */
10568 + DySetAop(writepages);
10569 + DySetAop(set_page_dirty);
10570 + DySetAop(readpages);
10571 + DySetAop(write_begin);
10572 + DySetAop(write_end);
10574 + DySetAop(invalidatepage);
10575 + DySetAop(releasepage);
10576 + DySetAop(freepage);
10577 + /* this one will be changed according to an aufs mount option */
10578 + DySetAop(direct_IO);
10579 + DySetAop(migratepage);
10580 + DySetAop(launder_page);
10581 + DySetAop(is_partially_uptodate);
10582 + DySetAop(is_dirty_writeback);
10583 + DySetAop(error_remove_page);
10584 + DySetAop(swap_activate);
10585 + DySetAop(swap_deactivate);
10587 + DyDbgSize(cnt, *h_aop);
10590 +/* ---------------------------------------------------------------------- */
10592 +static void dy_bug(struct kref *kref)
10597 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10599 + struct au_dykey *key, *old;
10600 + struct au_splhead *spl;
10603 + void (*set)(struct au_dykey *key, const void *h_op,
10604 + struct super_block *h_sb __maybe_unused);
10606 + static const struct op a[] = {
10608 + .sz = sizeof(struct au_dyaop),
10612 + const struct op *p;
10614 + spl = dynop + op->dy_type;
10615 + key = dy_gfind_get(spl, op->dy_hop);
10617 + goto out_add; /* success */
10619 + p = a + op->dy_type;
10620 + key = kzalloc(p->sz, GFP_NOFS);
10621 + if (unlikely(!key)) {
10622 + key = ERR_PTR(-ENOMEM);
10626 + key->dk_op.dy_hop = op->dy_hop;
10627 + kref_init(&key->dk_kref);
10628 + p->set(key, op->dy_hop, au_br_sb(br));
10629 + old = dy_gadd(spl, key);
10636 + old = dy_bradd(br, key);
10638 + /* its ref-count should never be zero here */
10639 + kref_put(&key->dk_kref, dy_bug);
10644 +/* ---------------------------------------------------------------------- */
10646 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10647 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10648 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10649 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10650 + * See the aufs manual in detail.
10652 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10655 + dyaop->da_op.direct_IO = NULL;
10657 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10660 +static struct au_dyaop *dy_aget(struct au_branch *br,
10661 + const struct address_space_operations *h_aop,
10664 + struct au_dyaop *dyaop;
10665 + struct au_dynop op;
10667 + op.dy_type = AuDy_AOP;
10668 + op.dy_haop = h_aop;
10669 + dyaop = (void *)dy_get(&op, br);
10670 + if (IS_ERR(dyaop))
10672 + dy_adx(dyaop, do_dx);
10678 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10679 + struct inode *h_inode)
10682 + struct super_block *sb;
10683 + struct au_branch *br;
10684 + struct au_dyaop *dyaop;
10686 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10687 + IiMustWriteLock(inode);
10689 + sb = inode->i_sb;
10690 + br = au_sbr(sb, bindex);
10691 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10692 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10693 + err = PTR_ERR(dyaop);
10694 + if (IS_ERR(dyaop))
10695 + /* unnecessary to call dy_fput() */
10699 + inode->i_mapping->a_ops = &dyaop->da_op;
10706 + * Is it safe to replace a_ops during the inode/file is in operation?
10707 + * Yes, I hope so.
10709 +int au_dy_irefresh(struct inode *inode)
10712 + aufs_bindex_t bstart;
10713 + struct inode *h_inode;
10716 + if (S_ISREG(inode->i_mode)) {
10717 + bstart = au_ibstart(inode);
10718 + h_inode = au_h_iptr(inode, bstart);
10719 + err = au_dy_iaop(inode, bstart, h_inode);
10724 +void au_dy_arefresh(int do_dx)
10726 + struct au_splhead *spl;
10727 + struct list_head *head;
10728 + struct au_dykey *key;
10730 + spl = dynop + AuDy_AOP;
10731 + head = &spl->head;
10732 + spin_lock(&spl->spin);
10733 + list_for_each_entry(key, head, dk_list)
10734 + dy_adx((void *)key, do_dx);
10735 + spin_unlock(&spl->spin);
10738 +/* ---------------------------------------------------------------------- */
10740 +void __init au_dy_init(void)
10744 + /* make sure that 'struct au_dykey *' can be any type */
10745 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10747 + for (i = 0; i < AuDyLast; i++)
10748 + au_spl_init(dynop + i);
10751 +void au_dy_fin(void)
10755 + for (i = 0; i < AuDyLast; i++)
10756 + WARN_ON(!list_empty(&dynop[i].head));
10758 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10759 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10760 +++ linux/fs/aufs/dynop.h 2016-04-24 18:32:51.393686895 +0200
10763 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10765 + * This program, aufs is free software; you can redistribute it and/or modify
10766 + * it under the terms of the GNU General Public License as published by
10767 + * the Free Software Foundation; either version 2 of the License, or
10768 + * (at your option) any later version.
10770 + * This program is distributed in the hope that it will be useful,
10771 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10772 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10773 + * GNU General Public License for more details.
10775 + * You should have received a copy of the GNU General Public License
10776 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10780 + * dynamically customizable operations (for regular files only)
10783 +#ifndef __AUFS_DYNOP_H__
10784 +#define __AUFS_DYNOP_H__
10788 +#include <linux/fs.h>
10789 +#include <linux/kref.h>
10791 +enum {AuDy_AOP, AuDyLast};
10796 + const void *dy_hop;
10797 + const struct address_space_operations *dy_haop;
10803 + struct list_head dk_list;
10804 + struct rcu_head dk_rcu;
10806 + struct au_dynop dk_op;
10809 + * during I am in the branch local array, kref is gotten. when the
10810 + * branch is removed, kref is put.
10812 + struct kref dk_kref;
10815 +/* stop unioning since their sizes are very different from each other */
10817 + struct au_dykey da_key;
10818 + struct address_space_operations da_op; /* not const */
10821 +/* ---------------------------------------------------------------------- */
10825 +void au_dy_put(struct au_dykey *key);
10826 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10827 + struct inode *h_inode);
10828 +int au_dy_irefresh(struct inode *inode);
10829 +void au_dy_arefresh(int do_dio);
10831 +void __init au_dy_init(void);
10832 +void au_dy_fin(void);
10834 +#endif /* __KERNEL__ */
10835 +#endif /* __AUFS_DYNOP_H__ */
10836 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10837 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10838 +++ linux/fs/aufs/export.c 2016-04-24 18:32:51.393686895 +0200
10841 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10843 + * This program, aufs is free software; you can redistribute it and/or modify
10844 + * it under the terms of the GNU General Public License as published by
10845 + * the Free Software Foundation; either version 2 of the License, or
10846 + * (at your option) any later version.
10848 + * This program is distributed in the hope that it will be useful,
10849 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10850 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10851 + * GNU General Public License for more details.
10853 + * You should have received a copy of the GNU General Public License
10854 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10861 +#include <linux/exportfs.h>
10862 +#include <linux/fs_struct.h>
10863 +#include <linux/namei.h>
10864 +#include <linux/nsproxy.h>
10865 +#include <linux/random.h>
10866 +#include <linux/writeback.h>
10867 +#include "../fs/mount.h"
10871 +#ifdef CONFIG_AUFS_INO_T_64
10879 +static ino_t decode_ino(__u32 *a)
10883 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10885 +#ifdef CONFIG_AUFS_INO_T_64
10891 +static void encode_ino(__u32 *a, ino_t ino)
10897 +#ifdef CONFIG_AUFS_INO_T_64
10902 +/* NFS file handle */
10906 +#ifdef CONFIG_AUFS_INO_T_64
10907 + /* support 64bit inode number */
10920 + Fh_ino = Fh_ino1,
10921 + Fh_dir_ino = Fh_dir_ino1
10924 +static int au_test_anon(struct dentry *dentry)
10926 + /* note: read d_flags without d_lock */
10927 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10930 +int au_test_nfsd(void)
10933 + struct task_struct *tsk = current;
10934 + char comm[sizeof(tsk->comm)];
10937 + if (tsk->flags & PF_KTHREAD) {
10938 + get_task_comm(comm, tsk);
10939 + ret = !strcmp(comm, "nfsd");
10945 +/* ---------------------------------------------------------------------- */
10946 +/* inode generation external table */
10948 +void au_xigen_inc(struct inode *inode)
10953 + struct super_block *sb;
10954 + struct au_sbinfo *sbinfo;
10956 + sb = inode->i_sb;
10957 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10959 + sbinfo = au_sbi(sb);
10960 + pos = inode->i_ino;
10961 + pos *= sizeof(igen);
10962 + igen = inode->i_generation + 1;
10963 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10964 + sizeof(igen), &pos);
10965 + if (sz == sizeof(igen))
10966 + return; /* success */
10968 + if (unlikely(sz >= 0))
10969 + AuIOErr("xigen error (%zd)\n", sz);
10972 +int au_xigen_new(struct inode *inode)
10977 + struct super_block *sb;
10978 + struct au_sbinfo *sbinfo;
10979 + struct file *file;
10982 + /* todo: dirty, at mount time */
10983 + if (inode->i_ino == AUFS_ROOT_INO)
10985 + sb = inode->i_sb;
10986 + SiMustAnyLock(sb);
10987 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10991 + pos = inode->i_ino;
10992 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10993 + AuIOErr1("too large i%lld\n", pos);
10996 + pos *= sizeof(inode->i_generation);
10999 + sbinfo = au_sbi(sb);
11000 + file = sbinfo->si_xigen;
11003 + if (vfsub_f_size_read(file)
11004 + < pos + sizeof(inode->i_generation)) {
11005 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
11006 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
11007 + sizeof(inode->i_generation), &pos);
11009 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
11010 + sizeof(inode->i_generation), &pos);
11011 + if (sz == sizeof(inode->i_generation))
11012 + goto out; /* success */
11015 + if (unlikely(sz >= 0)) {
11017 + AuIOErr("xigen error (%zd)\n", sz);
11024 +int au_xigen_set(struct super_block *sb, struct file *base)
11027 + struct au_sbinfo *sbinfo;
11028 + struct file *file;
11030 + SiMustWriteLock(sb);
11032 + sbinfo = au_sbi(sb);
11033 + file = au_xino_create2(base, sbinfo->si_xigen);
11034 + err = PTR_ERR(file);
11035 + if (IS_ERR(file))
11038 + if (sbinfo->si_xigen)
11039 + fput(sbinfo->si_xigen);
11040 + sbinfo->si_xigen = file;
11046 +void au_xigen_clr(struct super_block *sb)
11048 + struct au_sbinfo *sbinfo;
11050 + SiMustWriteLock(sb);
11052 + sbinfo = au_sbi(sb);
11053 + if (sbinfo->si_xigen) {
11054 + fput(sbinfo->si_xigen);
11055 + sbinfo->si_xigen = NULL;
11059 +/* ---------------------------------------------------------------------- */
11061 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11064 + struct dentry *dentry, *d;
11065 + struct inode *inode;
11066 + unsigned int sigen;
11069 + inode = ilookup(sb, ino);
11073 + dentry = ERR_PTR(-ESTALE);
11074 + sigen = au_sigen(sb);
11075 + if (unlikely(is_bad_inode(inode)
11076 + || IS_DEADDIR(inode)
11077 + || sigen != au_iigen(inode, NULL)))
11081 + if (!dir_ino || S_ISDIR(inode->i_mode))
11082 + dentry = d_find_alias(inode);
11084 + spin_lock(&inode->i_lock);
11085 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11086 + spin_lock(&d->d_lock);
11087 + if (!au_test_anon(d)
11088 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11089 + dentry = dget_dlock(d);
11090 + spin_unlock(&d->d_lock);
11093 + spin_unlock(&d->d_lock);
11095 + spin_unlock(&inode->i_lock);
11097 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11098 + /* need to refresh */
11106 + AuTraceErrPtr(dentry);
11110 +/* ---------------------------------------------------------------------- */
11112 +/* todo: dirty? */
11113 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11115 +struct au_compare_mnt_args {
11117 + struct super_block *sb;
11120 + struct vfsmount *mnt;
11123 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11125 + struct au_compare_mnt_args *a = arg;
11127 + if (mnt->mnt_sb != a->sb)
11129 + a->mnt = mntget(mnt);
11133 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11136 + struct path root;
11137 + struct au_compare_mnt_args args = {
11141 + get_fs_root(current->fs, &root);
11143 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11144 + rcu_read_unlock();
11147 + AuDebugOn(!args.mnt);
11151 +struct au_nfsd_si_lock {
11152 + unsigned int sigen;
11153 + aufs_bindex_t bindex, br_id;
11154 + unsigned char force_lock;
11157 +static int si_nfsd_read_lock(struct super_block *sb,
11158 + struct au_nfsd_si_lock *nsi_lock)
11161 + aufs_bindex_t bindex;
11163 + si_read_lock(sb, AuLock_FLUSH);
11165 + /* branch id may be wrapped around */
11167 + bindex = au_br_index(sb, nsi_lock->br_id);
11168 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11169 + goto out; /* success */
11173 + if (!nsi_lock->force_lock)
11174 + si_read_unlock(sb);
11177 + nsi_lock->bindex = bindex;
11181 +struct find_name_by_ino {
11182 + struct dir_context ctx;
11183 + int called, found;
11190 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11191 + loff_t offset, u64 ino, unsigned int d_type)
11193 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11197 + if (a->ino != ino)
11200 + memcpy(a->name, name, namelen);
11201 + a->namelen = namelen;
11206 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11207 + struct au_nfsd_si_lock *nsi_lock)
11209 + struct dentry *dentry, *parent;
11210 + struct file *file;
11211 + struct inode *dir;
11212 + struct find_name_by_ino arg = {
11214 + .actor = find_name_by_ino
11219 + parent = path->dentry;
11221 + si_read_unlock(parent->d_sb);
11222 + file = vfsub_dentry_open(path, au_dir_roflags);
11223 + dentry = (void *)file;
11224 + if (IS_ERR(file))
11227 + dentry = ERR_PTR(-ENOMEM);
11228 + arg.name = (void *)__get_free_page(GFP_NOFS);
11229 + if (unlikely(!arg.name))
11236 + err = vfsub_iterate_dir(file, &arg.ctx);
11237 + } while (!err && !arg.found && arg.called);
11238 + dentry = ERR_PTR(err);
11239 + if (unlikely(err))
11241 + /* instead of ENOENT */
11242 + dentry = ERR_PTR(-ESTALE);
11246 + /* do not call vfsub_lkup_one() */
11247 + dir = d_inode(parent);
11248 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
11249 + AuTraceErrPtr(dentry);
11250 + if (IS_ERR(dentry))
11252 + AuDebugOn(au_test_anon(dentry));
11253 + if (unlikely(d_really_is_negative(dentry))) {
11255 + dentry = ERR_PTR(-ENOENT);
11259 + free_page((unsigned long)arg.name);
11263 + if (unlikely(nsi_lock
11264 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11265 + if (!IS_ERR(dentry)) {
11267 + dentry = ERR_PTR(-ESTALE);
11269 + AuTraceErrPtr(dentry);
11273 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11275 + struct au_nfsd_si_lock *nsi_lock)
11277 + struct dentry *dentry;
11278 + struct path path;
11280 + if (dir_ino != AUFS_ROOT_INO) {
11281 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11282 + dentry = path.dentry;
11283 + if (!path.dentry || IS_ERR(path.dentry))
11285 + AuDebugOn(au_test_anon(path.dentry));
11287 + path.dentry = dget(sb->s_root);
11289 + path.mnt = au_mnt_get(sb);
11290 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11294 + AuTraceErrPtr(dentry);
11298 +/* ---------------------------------------------------------------------- */
11300 +static int h_acceptable(void *expv, struct dentry *dentry)
11305 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11306 + char *buf, int len, struct super_block *sb)
11310 + struct path path;
11312 + p = d_path(h_rootpath, buf, len);
11317 + path.mnt = h_rootpath->mnt;
11318 + path.dentry = h_parent;
11319 + p = d_path(&path, buf, len);
11325 + path.mnt = au_mnt_get(sb);
11326 + path.dentry = sb->s_root;
11327 + p = d_path(&path, buf, len - strlen(p));
11328 + mntput(path.mnt);
11332 + p[strlen(p)] = '/';
11335 + AuTraceErrPtr(p);
11340 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11341 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11343 + struct dentry *dentry, *h_parent, *root;
11344 + struct super_block *h_sb;
11345 + char *pathname, *p;
11346 + struct vfsmount *h_mnt;
11347 + struct au_branch *br;
11349 + struct path path;
11351 + br = au_sbr(sb, nsi_lock->bindex);
11352 + h_mnt = au_br_mnt(br);
11353 + h_sb = h_mnt->mnt_sb;
11354 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11355 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11356 + fh_len - Fh_tail, fh[Fh_h_type],
11357 + h_acceptable, /*context*/NULL);
11358 + dentry = h_parent;
11359 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11360 + AuWarn1("%s decode_fh failed, %ld\n",
11361 + au_sbtype(h_sb), PTR_ERR(h_parent));
11365 + if (unlikely(au_test_anon(h_parent))) {
11366 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11367 + au_sbtype(h_sb));
11368 + goto out_h_parent;
11371 + dentry = ERR_PTR(-ENOMEM);
11372 + pathname = (void *)__get_free_page(GFP_NOFS);
11373 + if (unlikely(!pathname))
11374 + goto out_h_parent;
11376 + root = sb->s_root;
11377 + path.mnt = h_mnt;
11378 + di_read_lock_parent(root, !AuLock_IR);
11379 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11380 + di_read_unlock(root, !AuLock_IR);
11381 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11382 + dentry = (void *)p;
11384 + goto out_pathname;
11386 + si_read_unlock(sb);
11387 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11388 + dentry = ERR_PTR(err);
11389 + if (unlikely(err))
11392 + dentry = ERR_PTR(-ENOENT);
11393 + AuDebugOn(au_test_anon(path.dentry));
11394 + if (unlikely(d_really_is_negative(path.dentry)))
11397 + if (ino != d_inode(path.dentry)->i_ino)
11398 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11400 + dentry = dget(path.dentry);
11405 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11406 + if (!IS_ERR(dentry)) {
11408 + dentry = ERR_PTR(-ESTALE);
11411 + free_page((unsigned long)pathname);
11415 + AuTraceErrPtr(dentry);
11419 +/* ---------------------------------------------------------------------- */
11421 +static struct dentry *
11422 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11425 + struct dentry *dentry;
11426 + __u32 *fh = fid->raw;
11427 + struct au_branch *br;
11428 + ino_t ino, dir_ino;
11429 + struct au_nfsd_si_lock nsi_lock = {
11433 + dentry = ERR_PTR(-ESTALE);
11434 + /* it should never happen, but the file handle is unreliable */
11435 + if (unlikely(fh_len < Fh_tail))
11437 + nsi_lock.sigen = fh[Fh_sigen];
11438 + nsi_lock.br_id = fh[Fh_br_id];
11440 + /* branch id may be wrapped around */
11442 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11444 + nsi_lock.force_lock = 1;
11446 + /* is this inode still cached? */
11447 + ino = decode_ino(fh + Fh_ino);
11448 + /* it should never happen */
11449 + if (unlikely(ino == AUFS_ROOT_INO))
11452 + dir_ino = decode_ino(fh + Fh_dir_ino);
11453 + dentry = decode_by_ino(sb, ino, dir_ino);
11454 + if (IS_ERR(dentry))
11459 + /* is the parent dir cached? */
11460 + br = au_sbr(sb, nsi_lock.bindex);
11461 + atomic_inc(&br->br_count);
11462 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11463 + if (IS_ERR(dentry))
11468 + /* lookup path */
11469 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11470 + if (IS_ERR(dentry))
11472 + if (unlikely(!dentry))
11473 + /* todo?: make it ESTALE */
11477 + if (!au_digen_test(dentry, au_sigen(sb))
11478 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11479 + goto out_unlock; /* success */
11482 + dentry = ERR_PTR(-ESTALE);
11485 + atomic_dec(&br->br_count);
11486 + si_read_unlock(sb);
11488 + AuTraceErrPtr(dentry);
11492 +#if 0 /* reserved for future use */
11493 +/* support subtreecheck option */
11494 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11495 + int fh_len, int fh_type)
11497 + struct dentry *parent;
11498 + __u32 *fh = fid->raw;
11501 + dir_ino = decode_ino(fh + Fh_dir_ino);
11502 + parent = decode_by_ino(sb, dir_ino, 0);
11503 + if (IS_ERR(parent))
11506 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11507 + dir_ino, fh, fh_len);
11510 + AuTraceErrPtr(parent);
11515 +/* ---------------------------------------------------------------------- */
11517 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11518 + struct inode *dir)
11521 + aufs_bindex_t bindex;
11522 + struct super_block *sb, *h_sb;
11523 + struct dentry *dentry, *parent, *h_parent;
11524 + struct inode *h_dir;
11525 + struct au_branch *br;
11528 + if (unlikely(*max_len <= Fh_tail)) {
11529 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11533 + err = FILEID_ROOT;
11534 + if (inode->i_ino == AUFS_ROOT_INO) {
11535 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11540 + sb = inode->i_sb;
11541 + err = si_read_lock(sb, AuLock_FLUSH);
11542 + if (unlikely(err))
11545 +#ifdef CONFIG_AUFS_DEBUG
11546 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11547 + AuWarn1("NFS-exporting requires xino\n");
11551 + ii_read_lock_child(inode);
11552 + bindex = au_ibstart(inode);
11554 + dentry = d_find_any_alias(inode);
11555 + if (unlikely(!dentry))
11557 + AuDebugOn(au_test_anon(dentry));
11558 + parent = dget_parent(dentry);
11560 + if (unlikely(!parent))
11562 + if (d_really_is_positive(parent))
11563 + dir = d_inode(parent);
11566 + ii_read_lock_parent(dir);
11567 + h_dir = au_h_iptr(dir, bindex);
11568 + ii_read_unlock(dir);
11569 + if (unlikely(!h_dir))
11571 + h_parent = d_find_any_alias(h_dir);
11572 + if (unlikely(!h_parent))
11573 + goto out_hparent;
11576 + br = au_sbr(sb, bindex);
11577 + h_sb = au_br_sb(br);
11578 + if (unlikely(!h_sb->s_export_op)) {
11579 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11580 + goto out_hparent;
11583 + fh[Fh_br_id] = br->br_id;
11584 + fh[Fh_sigen] = au_sigen(sb);
11585 + encode_ino(fh + Fh_ino, inode->i_ino);
11586 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11587 + fh[Fh_igen] = inode->i_generation;
11589 + *max_len -= Fh_tail;
11590 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11592 + /*connectable or subtreecheck*/0);
11593 + err = fh[Fh_h_type];
11594 + *max_len += Fh_tail;
11595 + /* todo: macros? */
11596 + if (err != FILEID_INVALID)
11599 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11606 + ii_read_unlock(inode);
11607 + si_read_unlock(sb);
11609 + if (unlikely(err < 0))
11610 + err = FILEID_INVALID;
11614 +/* ---------------------------------------------------------------------- */
11616 +static int aufs_commit_metadata(struct inode *inode)
11619 + aufs_bindex_t bindex;
11620 + struct super_block *sb;
11621 + struct inode *h_inode;
11622 + int (*f)(struct inode *inode);
11624 + sb = inode->i_sb;
11625 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11626 + ii_write_lock_child(inode);
11627 + bindex = au_ibstart(inode);
11628 + AuDebugOn(bindex < 0);
11629 + h_inode = au_h_iptr(inode, bindex);
11631 + f = h_inode->i_sb->s_export_op->commit_metadata;
11633 + err = f(h_inode);
11635 + struct writeback_control wbc = {
11636 + .sync_mode = WB_SYNC_ALL,
11637 + .nr_to_write = 0 /* metadata only */
11640 + err = sync_inode(h_inode, &wbc);
11643 + au_cpup_attr_timesizes(inode);
11644 + ii_write_unlock(inode);
11645 + si_read_unlock(sb);
11649 +/* ---------------------------------------------------------------------- */
11651 +static struct export_operations aufs_export_op = {
11652 + .fh_to_dentry = aufs_fh_to_dentry,
11653 + /* .fh_to_parent = aufs_fh_to_parent, */
11654 + .encode_fh = aufs_encode_fh,
11655 + .commit_metadata = aufs_commit_metadata
11658 +void au_export_init(struct super_block *sb)
11660 + struct au_sbinfo *sbinfo;
11663 + sb->s_export_op = &aufs_export_op;
11664 + sbinfo = au_sbi(sb);
11665 + sbinfo->si_xigen = NULL;
11666 + get_random_bytes(&u, sizeof(u));
11667 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11668 + atomic_set(&sbinfo->si_xigen_next, u);
11670 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11671 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11672 +++ linux/fs/aufs/fhsm.c 2016-04-24 18:32:51.393686895 +0200
11675 + * Copyright (C) 2011-2016 Junjiro R. Okajima
11677 + * This program, aufs is free software; you can redistribute it and/or modify
11678 + * it under the terms of the GNU General Public License as published by
11679 + * the Free Software Foundation; either version 2 of the License, or
11680 + * (at your option) any later version.
11682 + * This program is distributed in the hope that it will be useful,
11683 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11684 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11685 + * GNU General Public License for more details.
11687 + * You should have received a copy of the GNU General Public License
11688 + * along with this program; if not, write to the Free Software
11689 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11693 + * File-based Hierarchy Storage Management
11696 +#include <linux/anon_inodes.h>
11697 +#include <linux/poll.h>
11698 +#include <linux/seq_file.h>
11699 +#include <linux/statfs.h>
11702 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11704 + struct au_sbinfo *sbinfo;
11705 + struct au_fhsm *fhsm;
11707 + SiMustAnyLock(sb);
11709 + sbinfo = au_sbi(sb);
11710 + fhsm = &sbinfo->si_fhsm;
11711 + AuDebugOn(!fhsm);
11712 + return fhsm->fhsm_bottom;
11715 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11717 + struct au_sbinfo *sbinfo;
11718 + struct au_fhsm *fhsm;
11720 + SiMustWriteLock(sb);
11722 + sbinfo = au_sbi(sb);
11723 + fhsm = &sbinfo->si_fhsm;
11724 + AuDebugOn(!fhsm);
11725 + fhsm->fhsm_bottom = bindex;
11728 +/* ---------------------------------------------------------------------- */
11730 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11732 + struct au_br_fhsm *bf;
11734 + bf = br->br_fhsm;
11735 + MtxMustLock(&bf->bf_lock);
11737 + return !bf->bf_readable
11738 + || time_after(jiffies,
11739 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11742 +/* ---------------------------------------------------------------------- */
11744 +static void au_fhsm_notify(struct super_block *sb, int val)
11746 + struct au_sbinfo *sbinfo;
11747 + struct au_fhsm *fhsm;
11749 + SiMustAnyLock(sb);
11751 + sbinfo = au_sbi(sb);
11752 + fhsm = &sbinfo->si_fhsm;
11753 + if (au_fhsm_pid(fhsm)
11754 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11755 + atomic_set(&fhsm->fhsm_readable, val);
11757 + wake_up(&fhsm->fhsm_wqh);
11761 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11762 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11765 + struct au_branch *br;
11766 + struct au_br_fhsm *bf;
11768 + br = au_sbr(sb, bindex);
11769 + AuDebugOn(au_br_rdonly(br));
11770 + bf = br->br_fhsm;
11774 + mutex_lock(&bf->bf_lock);
11776 + MtxMustLock(&bf->bf_lock);
11778 + /* sb->s_root for NFS is unreliable */
11779 + err = au_br_stfs(br, &bf->bf_stfs);
11780 + if (unlikely(err)) {
11781 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11785 + bf->bf_jiffy = jiffies;
11786 + bf->bf_readable = 1;
11788 + au_fhsm_notify(sb, /*val*/1);
11790 + *rstfs = bf->bf_stfs;
11794 + mutex_unlock(&bf->bf_lock);
11795 + au_fhsm_notify(sb, /*val*/1);
11800 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11803 + struct au_sbinfo *sbinfo;
11804 + struct au_fhsm *fhsm;
11805 + struct au_branch *br;
11806 + struct au_br_fhsm *bf;
11808 + AuDbg("b%d, force %d\n", bindex, force);
11809 + SiMustAnyLock(sb);
11811 + sbinfo = au_sbi(sb);
11812 + fhsm = &sbinfo->si_fhsm;
11813 + if (!au_ftest_si(sbinfo, FHSM)
11814 + || fhsm->fhsm_bottom == bindex)
11817 + br = au_sbr(sb, bindex);
11818 + bf = br->br_fhsm;
11820 + mutex_lock(&bf->bf_lock);
11822 + || au_fhsm_pid(fhsm)
11823 + || au_fhsm_test_jiffy(sbinfo, br))
11824 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11826 + mutex_unlock(&bf->bf_lock);
11829 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11831 + aufs_bindex_t bindex, bend;
11832 + struct au_branch *br;
11834 + /* exclude the bottom */
11835 + bend = au_fhsm_bottom(sb);
11836 + for (bindex = 0; bindex < bend; bindex++) {
11837 + br = au_sbr(sb, bindex);
11838 + if (au_br_fhsm(br->br_perm))
11839 + au_fhsm_wrote(sb, bindex, force);
11843 +/* ---------------------------------------------------------------------- */
11845 +static unsigned int au_fhsm_poll(struct file *file,
11846 + struct poll_table_struct *wait)
11848 + unsigned int mask;
11849 + struct au_sbinfo *sbinfo;
11850 + struct au_fhsm *fhsm;
11853 + sbinfo = file->private_data;
11854 + fhsm = &sbinfo->si_fhsm;
11855 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11856 + if (atomic_read(&fhsm->fhsm_readable))
11857 + mask = POLLIN /* | POLLRDNORM */;
11859 + AuTraceErr((int)mask);
11863 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11864 + struct aufs_stfs *stfs, __s16 brid)
11868 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11870 + err = __put_user(brid, &stbr->brid);
11871 + if (unlikely(err))
11877 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11878 + struct aufs_stbr __user *stbr, size_t count)
11882 + aufs_bindex_t bindex, bend;
11883 + struct au_branch *br;
11884 + struct au_br_fhsm *bf;
11886 + /* except the bottom branch */
11889 + bend = au_fhsm_bottom(sb);
11890 + for (bindex = 0; !err && bindex < bend; bindex++) {
11891 + br = au_sbr(sb, bindex);
11892 + if (!au_br_fhsm(br->br_perm))
11895 + bf = br->br_fhsm;
11896 + mutex_lock(&bf->bf_lock);
11897 + if (bf->bf_readable) {
11899 + if (count >= sizeof(*stbr))
11900 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11903 + bf->bf_readable = 0;
11904 + count -= sizeof(*stbr);
11908 + mutex_unlock(&bf->bf_lock);
11911 + err = sizeof(*stbr) * nstbr;
11916 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11921 + aufs_bindex_t nfhsm, bindex, bend;
11922 + struct au_sbinfo *sbinfo;
11923 + struct au_fhsm *fhsm;
11924 + struct au_branch *br;
11925 + struct super_block *sb;
11928 + sbinfo = file->private_data;
11929 + fhsm = &sbinfo->si_fhsm;
11931 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11932 + if (!atomic_read(&fhsm->fhsm_readable)) {
11933 + if (vfsub_file_flags(file) & O_NONBLOCK)
11936 + err = wait_event_interruptible_locked_irq
11938 + atomic_read(&fhsm->fhsm_readable));
11940 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11941 + if (unlikely(err))
11944 + /* sb may already be dead */
11945 + au_rw_read_lock(&sbinfo->si_rwsem);
11946 + readable = atomic_read(&fhsm->fhsm_readable);
11947 + if (readable > 0) {
11948 + sb = sbinfo->si_sb;
11950 + /* exclude the bottom branch */
11952 + bend = au_fhsm_bottom(sb);
11953 + for (bindex = 0; bindex < bend; bindex++) {
11954 + br = au_sbr(sb, bindex);
11955 + if (au_br_fhsm(br->br_perm))
11959 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11960 + atomic_set(&fhsm->fhsm_readable, 0);
11961 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11965 + au_rw_read_unlock(&sbinfo->si_rwsem);
11973 +static int au_fhsm_release(struct inode *inode, struct file *file)
11975 + struct au_sbinfo *sbinfo;
11976 + struct au_fhsm *fhsm;
11978 + /* sb may already be dead */
11979 + sbinfo = file->private_data;
11980 + fhsm = &sbinfo->si_fhsm;
11981 + spin_lock(&fhsm->fhsm_spin);
11982 + fhsm->fhsm_pid = 0;
11983 + spin_unlock(&fhsm->fhsm_spin);
11984 + kobject_put(&sbinfo->si_kobj);
11989 +static const struct file_operations au_fhsm_fops = {
11990 + .owner = THIS_MODULE,
11991 + .llseek = noop_llseek,
11992 + .read = au_fhsm_read,
11993 + .poll = au_fhsm_poll,
11994 + .release = au_fhsm_release
11997 +int au_fhsm_fd(struct super_block *sb, int oflags)
12000 + struct au_sbinfo *sbinfo;
12001 + struct au_fhsm *fhsm;
12004 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12008 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12012 + sbinfo = au_sbi(sb);
12013 + fhsm = &sbinfo->si_fhsm;
12014 + spin_lock(&fhsm->fhsm_spin);
12015 + if (!fhsm->fhsm_pid)
12016 + fhsm->fhsm_pid = current->pid;
12019 + spin_unlock(&fhsm->fhsm_spin);
12020 + if (unlikely(err))
12023 + oflags |= O_RDONLY;
12024 + /* oflags |= FMODE_NONOTIFY; */
12025 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12027 + if (unlikely(fd < 0))
12030 + /* succeed reglardless 'fhsm' status */
12031 + kobject_get(&sbinfo->si_kobj);
12032 + si_noflush_read_lock(sb);
12033 + if (au_ftest_si(sbinfo, FHSM))
12034 + au_fhsm_wrote_all(sb, /*force*/0);
12035 + si_read_unlock(sb);
12036 + goto out; /* success */
12039 + spin_lock(&fhsm->fhsm_spin);
12040 + fhsm->fhsm_pid = 0;
12041 + spin_unlock(&fhsm->fhsm_spin);
12047 +/* ---------------------------------------------------------------------- */
12049 +int au_fhsm_br_alloc(struct au_branch *br)
12054 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12056 + au_br_fhsm_init(br->br_fhsm);
12063 +/* ---------------------------------------------------------------------- */
12065 +void au_fhsm_fin(struct super_block *sb)
12067 + au_fhsm_notify(sb, /*val*/-1);
12070 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12072 + struct au_fhsm *fhsm;
12074 + fhsm = &sbinfo->si_fhsm;
12075 + spin_lock_init(&fhsm->fhsm_spin);
12076 + init_waitqueue_head(&fhsm->fhsm_wqh);
12077 + atomic_set(&fhsm->fhsm_readable, 0);
12078 + fhsm->fhsm_expire
12079 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12080 + fhsm->fhsm_bottom = -1;
12083 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12085 + sbinfo->si_fhsm.fhsm_expire
12086 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12089 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12093 + if (!au_ftest_si(sbinfo, FHSM))
12096 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12097 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12098 + seq_printf(seq, ",fhsm_sec=%u", u);
12100 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12101 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12102 +++ linux/fs/aufs/file.c 2016-04-24 18:32:51.393686895 +0200
12105 + * Copyright (C) 2005-2016 Junjiro R. Okajima
12107 + * This program, aufs is free software; you can redistribute it and/or modify
12108 + * it under the terms of the GNU General Public License as published by
12109 + * the Free Software Foundation; either version 2 of the License, or
12110 + * (at your option) any later version.
12112 + * This program is distributed in the hope that it will be useful,
12113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12115 + * GNU General Public License for more details.
12117 + * You should have received a copy of the GNU General Public License
12118 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12122 + * handling file/dir, and address_space operation
12125 +#ifdef CONFIG_AUFS_DEBUG
12126 +#include <linux/migrate.h>
12128 +#include <linux/pagemap.h>
12131 +/* drop flags for writing */
12132 +unsigned int au_file_roflags(unsigned int flags)
12134 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12135 + flags |= O_RDONLY | O_NOATIME;
12139 +/* common functions to regular file and dir */
12140 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12141 + struct file *file, int force_wr)
12143 + struct file *h_file;
12144 + struct dentry *h_dentry;
12145 + struct inode *h_inode;
12146 + struct super_block *sb;
12147 + struct au_branch *br;
12148 + struct path h_path;
12151 + /* a race condition can happen between open and unlink/rmdir */
12152 + h_file = ERR_PTR(-ENOENT);
12153 + h_dentry = au_h_dptr(dentry, bindex);
12154 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12156 + h_inode = d_inode(h_dentry);
12157 + spin_lock(&h_dentry->d_lock);
12158 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12159 + /* || !d_inode(dentry)->i_nlink */
12161 + spin_unlock(&h_dentry->d_lock);
12162 + if (unlikely(err))
12165 + sb = dentry->d_sb;
12166 + br = au_sbr(sb, bindex);
12167 + err = au_br_test_oflag(flags, br);
12168 + h_file = ERR_PTR(err);
12169 + if (unlikely(err))
12172 + /* drop flags for writing */
12173 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12174 + if (force_wr && !(flags & O_WRONLY))
12176 + flags = au_file_roflags(flags);
12178 + h_file = ERR_PTR(-EROFS);
12179 + flags = au_file_roflags(flags);
12180 + if (unlikely(vfsub_native_ro(h_inode)
12181 + || IS_APPEND(h_inode)))
12183 + flags &= ~O_ACCMODE;
12184 + flags |= O_WRONLY;
12187 + flags &= ~O_CREAT;
12188 + atomic_inc(&br->br_count);
12189 + h_path.dentry = h_dentry;
12190 + h_path.mnt = au_br_mnt(br);
12191 + h_file = vfsub_dentry_open(&h_path, flags);
12192 + if (IS_ERR(h_file))
12195 + if (flags & __FMODE_EXEC) {
12196 + err = deny_write_access(h_file);
12197 + if (unlikely(err)) {
12199 + h_file = ERR_PTR(err);
12203 + fsnotify_open(h_file);
12204 + goto out; /* success */
12207 + atomic_dec(&br->br_count);
12212 +static int au_cmoo(struct dentry *dentry)
12215 + unsigned int udba;
12216 + struct path h_path;
12217 + struct au_pin pin;
12218 + struct au_cp_generic cpg = {
12219 + .dentry = dentry,
12224 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12226 + struct inode *delegated;
12227 + struct super_block *sb;
12228 + struct au_sbinfo *sbinfo;
12229 + struct au_fhsm *fhsm;
12231 + struct au_branch *br;
12232 + struct dentry *parent;
12233 + struct au_hinode *hdir;
12235 + DiMustWriteLock(dentry);
12236 + IiMustWriteLock(d_inode(dentry));
12239 + if (IS_ROOT(dentry))
12241 + cpg.bsrc = au_dbstart(dentry);
12245 + sb = dentry->d_sb;
12246 + sbinfo = au_sbi(sb);
12247 + fhsm = &sbinfo->si_fhsm;
12248 + pid = au_fhsm_pid(fhsm);
12250 + && (current->pid == pid
12251 + || current->real_parent->pid == pid))
12254 + br = au_sbr(sb, cpg.bsrc);
12255 + cmoo = au_br_cmoo(br->br_perm);
12258 + if (!d_is_reg(dentry))
12259 + cmoo &= AuBrAttr_COO_ALL;
12263 + parent = dget_parent(dentry);
12264 + di_write_lock_parent(parent);
12265 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12267 + if (unlikely(err < 0)) {
12268 + err = 0; /* there is no upper writable branch */
12271 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12273 + /* do not respect the coo attrib for the target branch */
12274 + err = au_cpup_dirs(dentry, cpg.bdst);
12275 + if (unlikely(err))
12278 + di_downgrade_lock(parent, AuLock_IR);
12279 + udba = au_opt_udba(sb);
12280 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12281 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12282 + if (unlikely(err))
12285 + err = au_sio_cpup_simple(&cpg);
12287 + if (unlikely(err))
12289 + if (!(cmoo & AuBrWAttr_MOO))
12290 + goto out_parent; /* success */
12292 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12293 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12294 + if (unlikely(err))
12297 + h_path.mnt = au_br_mnt(br);
12298 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12299 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12300 + delegated = NULL;
12301 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12303 + /* todo: keep h_dentry or not? */
12304 + if (unlikely(err == -EWOULDBLOCK)) {
12305 + pr_warn("cannot retry for NFSv4 delegation"
12306 + " for an internal unlink\n");
12309 + if (unlikely(err)) {
12310 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12314 + goto out_parent; /* success */
12317 + di_downgrade_lock(parent, AuLock_IR);
12319 + di_read_unlock(parent, AuLock_IR);
12326 +int au_do_open(struct file *file, struct au_do_open_args *args)
12328 + int err, no_lock = args->no_lock;
12329 + struct dentry *dentry;
12330 + struct au_finfo *finfo;
12333 + err = au_finfo_init(file, args->fidir);
12336 + err = au_finfo_init(file, args->fidir);
12339 + if (unlikely(err))
12342 + dentry = file->f_path.dentry;
12343 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12345 + di_write_lock_child(dentry);
12346 + err = au_cmoo(dentry);
12347 + di_downgrade_lock(dentry, AuLock_IR);
12349 + err = args->open(file, vfsub_file_flags(file), NULL);
12350 + di_read_unlock(dentry, AuLock_IR);
12352 + err = au_cmoo(dentry);
12354 + err = args->open(file, vfsub_file_flags(file),
12356 + if (!err && au_fbstart(file) != au_dbstart(dentry))
12358 + * cmoo happens after h_file was opened.
12359 + * need to refresh file later.
12361 + atomic_dec(&au_fi(file)->fi_generation);
12364 + finfo = au_fi(file);
12366 + finfo->fi_file = file;
12367 + au_sphl_add(&finfo->fi_hlist,
12368 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12371 + fi_write_unlock(file);
12374 + fi_write_unlock(file);
12377 + if (unlikely(err)) {
12378 + finfo->fi_hdir = NULL;
12379 + au_finfo_fin(file);
12386 +int au_reopen_nondir(struct file *file)
12389 + aufs_bindex_t bstart;
12390 + struct dentry *dentry;
12391 + struct file *h_file, *h_file_tmp;
12393 + dentry = file->f_path.dentry;
12394 + bstart = au_dbstart(dentry);
12395 + h_file_tmp = NULL;
12396 + if (au_fbstart(file) == bstart) {
12397 + h_file = au_hf_top(file);
12398 + if (file->f_mode == h_file->f_mode)
12399 + return 0; /* success */
12400 + h_file_tmp = h_file;
12401 + get_file(h_file_tmp);
12402 + au_set_h_fptr(file, bstart, NULL);
12404 + AuDebugOn(au_fi(file)->fi_hdir);
12407 + * file exists on both of rw and ro
12408 + * open --> dbstart and fbstart are both 0
12409 + * prepend a branch as rw, "rw" become ro
12411 + * delete the top branch, "rw" becomes rw again
12412 + * --> dbstart is 1, fbstart is still 0
12413 + * write --> fbstart is 0 but dbstart is 1
12415 + /* AuDebugOn(au_fbstart(file) < bstart); */
12417 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
12418 + file, /*force_wr*/0);
12419 + err = PTR_ERR(h_file);
12420 + if (IS_ERR(h_file)) {
12421 + if (h_file_tmp) {
12422 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
12423 + au_set_h_fptr(file, bstart, h_file_tmp);
12424 + h_file_tmp = NULL;
12426 + goto out; /* todo: close all? */
12430 + au_set_fbstart(file, bstart);
12431 + au_set_h_fptr(file, bstart, h_file);
12432 + au_update_figen(file);
12433 + /* todo: necessary? */
12434 + /* file->f_ra = h_file->f_ra; */
12438 + fput(h_file_tmp);
12442 +/* ---------------------------------------------------------------------- */
12444 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12445 + struct dentry *hi_wh)
12448 + aufs_bindex_t bstart;
12449 + struct au_dinfo *dinfo;
12450 + struct dentry *h_dentry;
12451 + struct au_hdentry *hdp;
12453 + dinfo = au_di(file->f_path.dentry);
12454 + AuRwMustWriteLock(&dinfo->di_rwsem);
12456 + bstart = dinfo->di_bstart;
12457 + dinfo->di_bstart = btgt;
12458 + hdp = dinfo->di_hdentry;
12459 + h_dentry = hdp[0 + btgt].hd_dentry;
12460 + hdp[0 + btgt].hd_dentry = hi_wh;
12461 + err = au_reopen_nondir(file);
12462 + hdp[0 + btgt].hd_dentry = h_dentry;
12463 + dinfo->di_bstart = bstart;
12468 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12469 + aufs_bindex_t bcpup, struct au_pin *pin)
12472 + struct inode *inode, *h_inode;
12473 + struct dentry *h_dentry, *hi_wh;
12474 + struct au_cp_generic cpg = {
12475 + .dentry = file->f_path.dentry,
12482 + au_update_dbstart(cpg.dentry);
12483 + inode = d_inode(cpg.dentry);
12485 + if (au_dbstart(cpg.dentry) <= bcpup
12486 + && au_dbend(cpg.dentry) >= bcpup) {
12487 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12488 + if (h_dentry && d_is_positive(h_dentry))
12489 + h_inode = d_inode(h_dentry);
12491 + hi_wh = au_hi_wh(inode, bcpup);
12492 + if (!hi_wh && !h_inode)
12493 + err = au_sio_cpup_wh(&cpg, file);
12495 + /* already copied-up after unlink */
12496 + err = au_reopen_wh(file, bcpup, hi_wh);
12499 + && (inode->i_nlink > 1
12500 + || (inode->i_state & I_LINKABLE))
12501 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12502 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12508 + * prepare the @file for writing.
12510 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12513 + aufs_bindex_t dbstart;
12514 + struct dentry *parent;
12515 + struct inode *inode;
12516 + struct super_block *sb;
12517 + struct file *h_file;
12518 + struct au_cp_generic cpg = {
12519 + .dentry = file->f_path.dentry,
12524 + .flags = AuCpup_DTIME
12527 + sb = cpg.dentry->d_sb;
12528 + inode = d_inode(cpg.dentry);
12529 + cpg.bsrc = au_fbstart(file);
12530 + err = au_test_ro(sb, cpg.bsrc, inode);
12531 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12532 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12537 + /* need to cpup or reopen */
12538 + parent = dget_parent(cpg.dentry);
12539 + di_write_lock_parent(parent);
12540 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12542 + if (unlikely(err < 0))
12546 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12547 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12548 + if (unlikely(err))
12552 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12553 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12554 + if (unlikely(err))
12557 + dbstart = au_dbstart(cpg.dentry);
12558 + if (dbstart <= cpg.bdst)
12559 + cpg.bsrc = cpg.bdst;
12561 + if (dbstart <= cpg.bdst /* just reopen */
12562 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12564 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12565 + if (IS_ERR(h_file))
12566 + err = PTR_ERR(h_file);
12568 + di_downgrade_lock(parent, AuLock_IR);
12569 + if (dbstart > cpg.bdst)
12570 + err = au_sio_cpup_simple(&cpg);
12572 + err = au_reopen_nondir(file);
12573 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12575 + } else { /* copyup as wh and reopen */
12577 + * since writable hfsplus branch is not supported,
12578 + * h_open_pre/post() are unnecessary.
12580 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12581 + di_downgrade_lock(parent, AuLock_IR);
12585 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12586 + goto out_dput; /* success */
12592 + di_downgrade_lock(parent, AuLock_IR);
12594 + di_read_unlock(parent, AuLock_IR);
12601 +/* ---------------------------------------------------------------------- */
12603 +int au_do_flush(struct file *file, fl_owner_t id,
12604 + int (*flush)(struct file *file, fl_owner_t id))
12607 + struct super_block *sb;
12608 + struct inode *inode;
12610 + inode = file_inode(file);
12611 + sb = inode->i_sb;
12612 + si_noflush_read_lock(sb);
12613 + fi_read_lock(file);
12614 + ii_read_lock_child(inode);
12616 + err = flush(file, id);
12617 + au_cpup_attr_timesizes(inode);
12619 + ii_read_unlock(inode);
12620 + fi_read_unlock(file);
12621 + si_read_unlock(sb);
12625 +/* ---------------------------------------------------------------------- */
12627 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12630 + struct au_pin pin;
12631 + struct au_finfo *finfo;
12632 + struct dentry *parent, *hi_wh;
12633 + struct inode *inode;
12634 + struct super_block *sb;
12635 + struct au_cp_generic cpg = {
12636 + .dentry = file->f_path.dentry,
12641 + .flags = AuCpup_DTIME
12644 + FiMustWriteLock(file);
12647 + finfo = au_fi(file);
12648 + sb = cpg.dentry->d_sb;
12649 + inode = d_inode(cpg.dentry);
12650 + cpg.bdst = au_ibstart(inode);
12651 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12654 + parent = dget_parent(cpg.dentry);
12655 + if (au_test_ro(sb, cpg.bdst, inode)) {
12656 + di_read_lock_parent(parent, !AuLock_IR);
12657 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12659 + di_read_unlock(parent, !AuLock_IR);
12660 + if (unlikely(err < 0))
12665 + di_read_lock_parent(parent, AuLock_IR);
12666 + hi_wh = au_hi_wh(inode, cpg.bdst);
12667 + if (!S_ISDIR(inode->i_mode)
12668 + && au_opt_test(au_mntflags(sb), PLINK)
12669 + && au_plink_test(inode)
12670 + && !d_unhashed(cpg.dentry)
12671 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12672 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12673 + if (unlikely(err))
12676 + /* always superio. */
12677 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12678 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12680 + err = au_sio_cpup_simple(&cpg);
12683 + } else if (hi_wh) {
12684 + /* already copied-up after unlink */
12685 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12686 + *need_reopen = 0;
12690 + di_read_unlock(parent, AuLock_IR);
12697 +static void au_do_refresh_dir(struct file *file)
12699 + aufs_bindex_t bindex, bend, new_bindex, brid;
12700 + struct au_hfile *p, tmp, *q;
12701 + struct au_finfo *finfo;
12702 + struct super_block *sb;
12703 + struct au_fidir *fidir;
12705 + FiMustWriteLock(file);
12707 + sb = file->f_path.dentry->d_sb;
12708 + finfo = au_fi(file);
12709 + fidir = finfo->fi_hdir;
12710 + AuDebugOn(!fidir);
12711 + p = fidir->fd_hfile + finfo->fi_btop;
12712 + brid = p->hf_br->br_id;
12713 + bend = fidir->fd_bbot;
12714 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12718 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12719 + if (new_bindex == bindex)
12721 + if (new_bindex < 0) {
12722 + au_set_h_fptr(file, bindex, NULL);
12726 + /* swap two lower inode, and loop again */
12727 + q = fidir->fd_hfile + new_bindex;
12731 + if (tmp.hf_file) {
12737 + p = fidir->fd_hfile;
12738 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12739 + bend = au_sbend(sb);
12740 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12741 + finfo->fi_btop++, p++)
12742 + if (p->hf_file) {
12743 + if (file_inode(p->hf_file))
12745 + au_hfput(p, file);
12748 + bend = au_br_index(sb, brid);
12749 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12750 + finfo->fi_btop++, p++)
12752 + au_hfput(p, file);
12753 + bend = au_sbend(sb);
12756 + p = fidir->fd_hfile + bend;
12757 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12758 + fidir->fd_bbot--, p--)
12759 + if (p->hf_file) {
12760 + if (file_inode(p->hf_file))
12762 + au_hfput(p, file);
12764 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12768 + * after branch manipulating, refresh the file.
12770 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12772 + int err, need_reopen;
12773 + aufs_bindex_t bend, bindex;
12774 + struct dentry *dentry;
12775 + struct au_finfo *finfo;
12776 + struct au_hfile *hfile;
12778 + dentry = file->f_path.dentry;
12779 + finfo = au_fi(file);
12780 + if (!finfo->fi_hdir) {
12781 + hfile = &finfo->fi_htop;
12782 + AuDebugOn(!hfile->hf_file);
12783 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12784 + AuDebugOn(bindex < 0);
12785 + if (bindex != finfo->fi_btop)
12786 + au_set_fbstart(file, bindex);
12788 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12789 + if (unlikely(err))
12791 + au_do_refresh_dir(file);
12796 + if (!au_test_mmapped(file))
12797 + err = au_file_refresh_by_inode(file, &need_reopen);
12798 + if (!err && need_reopen && !d_unlinked(dentry))
12799 + err = reopen(file);
12801 + au_update_figen(file);
12802 + goto out; /* success */
12805 + /* error, close all lower files */
12806 + if (finfo->fi_hdir) {
12807 + bend = au_fbend_dir(file);
12808 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12809 + au_set_h_fptr(file, bindex, NULL);
12816 +/* common function to regular file and dir */
12817 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12821 + unsigned int sigen, figen;
12822 + aufs_bindex_t bstart;
12823 + unsigned char pseudo_link;
12824 + struct dentry *dentry;
12825 + struct inode *inode;
12828 + dentry = file->f_path.dentry;
12829 + inode = d_inode(dentry);
12830 + sigen = au_sigen(dentry->d_sb);
12831 + fi_write_lock(file);
12832 + figen = au_figen(file);
12833 + di_write_lock_child(dentry);
12834 + bstart = au_dbstart(dentry);
12835 + pseudo_link = (bstart != au_ibstart(inode));
12836 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12838 + di_downgrade_lock(dentry, AuLock_IR);
12839 + fi_downgrade_lock(file);
12841 + goto out; /* success */
12844 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12845 + if (au_digen_test(dentry, sigen)) {
12846 + err = au_reval_dpath(dentry, sigen);
12847 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12851 + err = refresh_file(file, reopen);
12854 + di_downgrade_lock(dentry, AuLock_IR);
12855 + fi_downgrade_lock(file);
12858 + di_write_unlock(dentry);
12859 + fi_write_unlock(file);
12866 +/* ---------------------------------------------------------------------- */
12868 +/* cf. aufs_nopage() */
12869 +/* for madvise(2) */
12870 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12872 + unlock_page(page);
12876 +/* it will never be called, but necessary to support O_DIRECT */
12877 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
12879 +{ BUG(); return 0; }
12881 +/* they will never be called. */
12882 +#ifdef CONFIG_AUFS_DEBUG
12883 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12884 + loff_t pos, unsigned len, unsigned flags,
12885 + struct page **pagep, void **fsdata)
12886 +{ AuUnsupport(); return 0; }
12887 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12888 + loff_t pos, unsigned len, unsigned copied,
12889 + struct page *page, void *fsdata)
12890 +{ AuUnsupport(); return 0; }
12891 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12892 +{ AuUnsupport(); return 0; }
12894 +static int aufs_set_page_dirty(struct page *page)
12895 +{ AuUnsupport(); return 0; }
12896 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12897 + unsigned int length)
12898 +{ AuUnsupport(); }
12899 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12900 +{ AuUnsupport(); return 0; }
12901 +#if 0 /* called by memory compaction regardless file */
12902 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12903 + struct page *page, enum migrate_mode mode)
12904 +{ AuUnsupport(); return 0; }
12906 +static int aufs_launder_page(struct page *page)
12907 +{ AuUnsupport(); return 0; }
12908 +static int aufs_is_partially_uptodate(struct page *page,
12909 + unsigned long from,
12910 + unsigned long count)
12911 +{ AuUnsupport(); return 0; }
12912 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12914 +{ AuUnsupport(); }
12915 +static int aufs_error_remove_page(struct address_space *mapping,
12916 + struct page *page)
12917 +{ AuUnsupport(); return 0; }
12918 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12920 +{ AuUnsupport(); return 0; }
12921 +static void aufs_swap_deactivate(struct file *file)
12922 +{ AuUnsupport(); }
12923 +#endif /* CONFIG_AUFS_DEBUG */
12925 +const struct address_space_operations aufs_aop = {
12926 + .readpage = aufs_readpage,
12927 + .direct_IO = aufs_direct_IO,
12928 +#ifdef CONFIG_AUFS_DEBUG
12929 + .writepage = aufs_writepage,
12930 + /* no writepages, because of writepage */
12931 + .set_page_dirty = aufs_set_page_dirty,
12932 + /* no readpages, because of readpage */
12933 + .write_begin = aufs_write_begin,
12934 + .write_end = aufs_write_end,
12935 + /* no bmap, no block device */
12936 + .invalidatepage = aufs_invalidatepage,
12937 + .releasepage = aufs_releasepage,
12938 + /* is fallback_migrate_page ok? */
12939 + /* .migratepage = aufs_migratepage, */
12940 + .launder_page = aufs_launder_page,
12941 + .is_partially_uptodate = aufs_is_partially_uptodate,
12942 + .is_dirty_writeback = aufs_is_dirty_writeback,
12943 + .error_remove_page = aufs_error_remove_page,
12944 + .swap_activate = aufs_swap_activate,
12945 + .swap_deactivate = aufs_swap_deactivate
12946 +#endif /* CONFIG_AUFS_DEBUG */
12948 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12949 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12950 +++ linux/fs/aufs/file.h 2016-04-24 18:32:51.393686895 +0200
12953 + * Copyright (C) 2005-2016 Junjiro R. Okajima
12955 + * This program, aufs is free software; you can redistribute it and/or modify
12956 + * it under the terms of the GNU General Public License as published by
12957 + * the Free Software Foundation; either version 2 of the License, or
12958 + * (at your option) any later version.
12960 + * This program is distributed in the hope that it will be useful,
12961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12963 + * GNU General Public License for more details.
12965 + * You should have received a copy of the GNU General Public License
12966 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12970 + * file operations
12973 +#ifndef __AUFS_FILE_H__
12974 +#define __AUFS_FILE_H__
12978 +#include <linux/file.h>
12979 +#include <linux/fs.h>
12980 +#include <linux/poll.h>
12981 +#include "rwsem.h"
12985 + struct file *hf_file;
12986 + struct au_branch *hf_br;
12991 + aufs_bindex_t fd_bbot;
12992 + aufs_bindex_t fd_nent;
12993 + struct au_vdir *fd_vdir_cache;
12994 + struct au_hfile fd_hfile[];
12997 +static inline int au_fidir_sz(int nent)
12999 + AuDebugOn(nent < 0);
13000 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13004 + atomic_t fi_generation;
13006 + struct au_rwsem fi_rwsem;
13007 + aufs_bindex_t fi_btop;
13009 + /* do not union them */
13010 + struct { /* for non-dir */
13011 + struct au_hfile fi_htop;
13012 + atomic_t fi_mmapped;
13014 + struct au_fidir *fi_hdir; /* for dir only */
13016 + struct hlist_node fi_hlist;
13017 + struct file *fi_file; /* very ugly */
13018 +} ____cacheline_aligned_in_smp;
13020 +/* ---------------------------------------------------------------------- */
13023 +extern const struct address_space_operations aufs_aop;
13024 +unsigned int au_file_roflags(unsigned int flags);
13025 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13026 + struct file *file, int force_wr);
13027 +struct au_do_open_args {
13029 + int (*open)(struct file *file, int flags,
13030 + struct file *h_file);
13031 + struct au_fidir *fidir;
13032 + struct file *h_file;
13034 +int au_do_open(struct file *file, struct au_do_open_args *args);
13035 +int au_reopen_nondir(struct file *file);
13037 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13038 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13040 +int au_do_flush(struct file *file, fl_owner_t id,
13041 + int (*flush)(struct file *file, fl_owner_t id));
13044 +#ifdef CONFIG_AUFS_POLL
13045 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13048 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13050 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13052 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13053 + struct file *h_file);
13055 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13056 + aufs_bindex_t bindex, int force_wr)
13057 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13058 + struct file *h_file);
13062 +extern const struct file_operations aufs_file_fop;
13063 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13064 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13065 +struct file *au_read_pre(struct file *file, int keep_fi);
13068 +void au_hfput(struct au_hfile *hf, struct file *file);
13069 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13070 + struct file *h_file);
13072 +void au_update_figen(struct file *file);
13073 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13074 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
13076 +void au_fi_init_once(void *_fi);
13077 +void au_finfo_fin(struct file *file);
13078 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13081 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13082 +#ifdef CONFIG_COMPAT
13083 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13084 + unsigned long arg);
13085 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13086 + unsigned long arg);
13089 +/* ---------------------------------------------------------------------- */
13091 +static inline struct au_finfo *au_fi(struct file *file)
13093 + return file->private_data;
13096 +/* ---------------------------------------------------------------------- */
13099 + * fi_read_lock, fi_write_lock,
13100 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13102 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13104 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13105 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13106 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13108 +/* ---------------------------------------------------------------------- */
13110 +/* todo: hard/soft set? */
13111 +static inline aufs_bindex_t au_fbstart(struct file *file)
13113 + FiMustAnyLock(file);
13114 + return au_fi(file)->fi_btop;
13117 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
13119 + FiMustAnyLock(file);
13120 + AuDebugOn(!au_fi(file)->fi_hdir);
13121 + return au_fi(file)->fi_hdir->fd_bbot;
13124 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13126 + FiMustAnyLock(file);
13127 + AuDebugOn(!au_fi(file)->fi_hdir);
13128 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13131 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
13133 + FiMustWriteLock(file);
13134 + au_fi(file)->fi_btop = bindex;
13137 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
13139 + FiMustWriteLock(file);
13140 + AuDebugOn(!au_fi(file)->fi_hdir);
13141 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13144 +static inline void au_set_fvdir_cache(struct file *file,
13145 + struct au_vdir *vdir_cache)
13147 + FiMustWriteLock(file);
13148 + AuDebugOn(!au_fi(file)->fi_hdir);
13149 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13152 +static inline struct file *au_hf_top(struct file *file)
13154 + FiMustAnyLock(file);
13155 + AuDebugOn(au_fi(file)->fi_hdir);
13156 + return au_fi(file)->fi_htop.hf_file;
13159 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13161 + FiMustAnyLock(file);
13162 + AuDebugOn(!au_fi(file)->fi_hdir);
13163 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13166 +/* todo: memory barrier? */
13167 +static inline unsigned int au_figen(struct file *f)
13169 + return atomic_read(&au_fi(f)->fi_generation);
13172 +static inline void au_set_mmapped(struct file *f)
13174 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13176 + pr_warn("fi_mmapped wrapped around\n");
13177 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13181 +static inline void au_unset_mmapped(struct file *f)
13183 + atomic_dec(&au_fi(f)->fi_mmapped);
13186 +static inline int au_test_mmapped(struct file *f)
13188 + return atomic_read(&au_fi(f)->fi_mmapped);
13191 +/* customize vma->vm_file */
13193 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13194 + struct file *file)
13198 + f = vma->vm_file;
13200 + vma->vm_file = file;
13205 +#define AuDbgVmRegion(file, vma) do {} while (0)
13207 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13208 + struct file *file)
13210 + au_do_vm_file_reset(vma, file);
13213 +#define AuDbgVmRegion(file, vma) \
13214 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13216 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13217 + struct file *file)
13221 + au_do_vm_file_reset(vma, file);
13222 + f = vma->vm_region->vm_file;
13224 + vma->vm_region->vm_file = file;
13227 +#endif /* CONFIG_MMU */
13229 +/* handle vma->vm_prfile */
13230 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13231 + struct file *file)
13234 + vma->vm_prfile = file;
13235 +#ifndef CONFIG_MMU
13237 + vma->vm_region->vm_prfile = file;
13241 +#endif /* __KERNEL__ */
13242 +#endif /* __AUFS_FILE_H__ */
13243 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13244 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13245 +++ linux/fs/aufs/finfo.c 2016-04-24 18:32:51.393686895 +0200
13248 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13250 + * This program, aufs is free software; you can redistribute it and/or modify
13251 + * it under the terms of the GNU General Public License as published by
13252 + * the Free Software Foundation; either version 2 of the License, or
13253 + * (at your option) any later version.
13255 + * This program is distributed in the hope that it will be useful,
13256 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13257 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13258 + * GNU General Public License for more details.
13260 + * You should have received a copy of the GNU General Public License
13261 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13265 + * file private data
13270 +void au_hfput(struct au_hfile *hf, struct file *file)
13272 + /* todo: direct access f_flags */
13273 + if (vfsub_file_flags(file) & __FMODE_EXEC)
13274 + allow_write_access(hf->hf_file);
13275 + fput(hf->hf_file);
13276 + hf->hf_file = NULL;
13277 + atomic_dec(&hf->hf_br->br_count);
13278 + hf->hf_br = NULL;
13281 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13283 + struct au_finfo *finfo = au_fi(file);
13284 + struct au_hfile *hf;
13285 + struct au_fidir *fidir;
13287 + fidir = finfo->fi_hdir;
13289 + AuDebugOn(finfo->fi_btop != bindex);
13290 + hf = &finfo->fi_htop;
13292 + hf = fidir->fd_hfile + bindex;
13294 + if (hf && hf->hf_file)
13295 + au_hfput(hf, file);
13297 + FiMustWriteLock(file);
13298 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13299 + hf->hf_file = val;
13300 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13304 +void au_update_figen(struct file *file)
13306 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13307 + /* smp_mb(); */ /* atomic_set */
13310 +/* ---------------------------------------------------------------------- */
13312 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13314 + struct au_fidir *fidir;
13317 + nbr = au_sbend(sb) + 1;
13319 + nbr = 2; /* initial allocate for 2 branches */
13320 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13322 + fidir->fd_bbot = -1;
13323 + fidir->fd_nent = nbr;
13329 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13332 + struct au_fidir *fidir, *p;
13334 + AuRwMustWriteLock(&finfo->fi_rwsem);
13335 + fidir = finfo->fi_hdir;
13336 + AuDebugOn(!fidir);
13339 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13342 + p->fd_nent = nbr;
13343 + finfo->fi_hdir = p;
13350 +/* ---------------------------------------------------------------------- */
13352 +void au_finfo_fin(struct file *file)
13354 + struct au_finfo *finfo;
13356 + au_nfiles_dec(file->f_path.dentry->d_sb);
13358 + finfo = au_fi(file);
13359 + AuDebugOn(finfo->fi_hdir);
13360 + AuRwDestroy(&finfo->fi_rwsem);
13361 + au_cache_free_finfo(finfo);
13364 +void au_fi_init_once(void *_finfo)
13366 + struct au_finfo *finfo = _finfo;
13367 + static struct lock_class_key aufs_fi;
13369 + au_rw_init(&finfo->fi_rwsem);
13370 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
13373 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13376 + struct au_finfo *finfo;
13377 + struct dentry *dentry;
13380 + dentry = file->f_path.dentry;
13381 + finfo = au_cache_alloc_finfo();
13382 + if (unlikely(!finfo))
13386 + au_nfiles_inc(dentry->d_sb);
13387 + /* verbose coding for lock class name */
13389 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
13391 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
13392 + au_rw_write_lock(&finfo->fi_rwsem);
13393 + finfo->fi_btop = -1;
13394 + finfo->fi_hdir = fidir;
13395 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13396 + /* smp_mb(); */ /* atomic_set */
13398 + file->private_data = finfo;
13403 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13404 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13405 +++ linux/fs/aufs/f_op.c 2016-04-24 18:32:51.393686895 +0200
13408 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13410 + * This program, aufs is free software; you can redistribute it and/or modify
13411 + * it under the terms of the GNU General Public License as published by
13412 + * the Free Software Foundation; either version 2 of the License, or
13413 + * (at your option) any later version.
13415 + * This program is distributed in the hope that it will be useful,
13416 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13417 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13418 + * GNU General Public License for more details.
13420 + * You should have received a copy of the GNU General Public License
13421 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13425 + * file and vm operations
13428 +#include <linux/aio.h>
13429 +#include <linux/fs_stack.h>
13430 +#include <linux/mman.h>
13431 +#include <linux/security.h>
13434 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13437 + aufs_bindex_t bindex;
13438 + struct dentry *dentry, *h_dentry;
13439 + struct au_finfo *finfo;
13440 + struct inode *h_inode;
13442 + FiMustWriteLock(file);
13445 + dentry = file->f_path.dentry;
13446 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13447 + finfo = au_fi(file);
13448 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13449 + atomic_set(&finfo->fi_mmapped, 0);
13450 + bindex = au_dbstart(dentry);
13452 + h_dentry = au_h_dptr(dentry, bindex);
13453 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13454 + if (unlikely(err))
13456 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13458 + h_dentry = h_file->f_path.dentry;
13459 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13460 + if (unlikely(err))
13462 + get_file(h_file);
13464 + if (IS_ERR(h_file))
13465 + err = PTR_ERR(h_file);
13467 + if ((flags & __O_TMPFILE)
13468 + && !(flags & O_EXCL)) {
13469 + h_inode = file_inode(h_file);
13470 + spin_lock(&h_inode->i_lock);
13471 + h_inode->i_state |= I_LINKABLE;
13472 + spin_unlock(&h_inode->i_lock);
13474 + au_set_fbstart(file, bindex);
13475 + au_set_h_fptr(file, bindex, h_file);
13476 + au_update_figen(file);
13477 + /* todo: necessary? */
13478 + /* file->f_ra = h_file->f_ra; */
13485 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13486 + struct file *file)
13489 + struct super_block *sb;
13490 + struct au_do_open_args args = {
13491 + .open = au_do_open_nondir
13494 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13495 + file, vfsub_file_flags(file), file->f_mode);
13497 + sb = file->f_path.dentry->d_sb;
13498 + si_read_lock(sb, AuLock_FLUSH);
13499 + err = au_do_open(file, &args);
13500 + si_read_unlock(sb);
13504 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13506 + struct au_finfo *finfo;
13507 + aufs_bindex_t bindex;
13509 + finfo = au_fi(file);
13510 + au_sphl_del(&finfo->fi_hlist,
13511 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13512 + bindex = finfo->fi_btop;
13514 + au_set_h_fptr(file, bindex, NULL);
13516 + au_finfo_fin(file);
13520 +/* ---------------------------------------------------------------------- */
13522 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13525 + struct file *h_file;
13528 + h_file = au_hf_top(file);
13530 + err = vfsub_flush(h_file, id);
13534 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13536 + return au_do_flush(file, id, au_do_flush_nondir);
13539 +/* ---------------------------------------------------------------------- */
13541 + * read and write functions acquire [fdi]_rwsem once, but release before
13542 + * mmap_sem. This is because to stop a race condition between mmap(2).
13543 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13544 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13545 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13548 +/* Callers should call au_read_post() or fput() in the end */
13549 +struct file *au_read_pre(struct file *file, int keep_fi)
13551 + struct file *h_file;
13554 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13556 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13557 + h_file = au_hf_top(file);
13558 + get_file(h_file);
13560 + fi_read_unlock(file);
13562 + h_file = ERR_PTR(err);
13567 +static void au_read_post(struct inode *inode, struct file *h_file)
13569 + /* update without lock, I don't think it a problem */
13570 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13574 +struct au_write_pre {
13576 + aufs_bindex_t bstart;
13580 + * return with iinfo is write-locked
13581 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13584 +static struct file *au_write_pre(struct file *file, int do_ready,
13585 + struct au_write_pre *wpre)
13587 + struct file *h_file;
13588 + struct dentry *dentry;
13590 + struct au_pin pin;
13592 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13593 + h_file = ERR_PTR(err);
13594 + if (unlikely(err))
13597 + dentry = file->f_path.dentry;
13599 + err = au_ready_to_write(file, -1, &pin);
13600 + if (unlikely(err)) {
13601 + h_file = ERR_PTR(err);
13602 + di_write_unlock(dentry);
13607 + di_downgrade_lock(dentry, /*flags*/0);
13609 + wpre->bstart = au_fbstart(file);
13610 + h_file = au_hf_top(file);
13611 + get_file(h_file);
13613 + wpre->blks = file_inode(h_file)->i_blocks;
13616 + di_read_unlock(dentry, /*flags*/0);
13619 + fi_write_unlock(file);
13624 +static void au_write_post(struct inode *inode, struct file *h_file,
13625 + struct au_write_pre *wpre, ssize_t written)
13627 + struct inode *h_inode;
13629 + au_cpup_attr_timesizes(inode);
13630 + AuDebugOn(au_ibstart(inode) != wpre->bstart);
13631 + h_inode = file_inode(h_file);
13632 + inode->i_mode = h_inode->i_mode;
13633 + ii_write_unlock(inode);
13636 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13638 + au_fhsm_wrote(inode->i_sb, wpre->bstart,
13639 + /*force*/h_inode->i_blocks > wpre->blks);
13642 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13646 + struct inode *inode;
13647 + struct file *h_file;
13648 + struct super_block *sb;
13650 + inode = file_inode(file);
13651 + sb = inode->i_sb;
13652 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13654 + h_file = au_read_pre(file, /*keep_fi*/0);
13655 + err = PTR_ERR(h_file);
13656 + if (IS_ERR(h_file))
13659 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13660 + err = vfsub_read_u(h_file, buf, count, ppos);
13661 + /* todo: necessary? */
13662 + /* file->f_ra = h_file->f_ra; */
13663 + au_read_post(inode, h_file);
13666 + si_read_unlock(sb);
13671 + * todo: very ugly
13672 + * it locks both of i_mutex and si_rwsem for read in safe.
13673 + * if the plink maintenance mode continues forever (that is the problem),
13674 + * may loop forever.
13676 +static void au_mtx_and_read_lock(struct inode *inode)
13679 + struct super_block *sb = inode->i_sb;
13682 + inode_lock(inode);
13683 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13686 + inode_unlock(inode);
13687 + si_read_lock(sb, AuLock_NOPLMW);
13688 + si_read_unlock(sb);
13692 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13693 + size_t count, loff_t *ppos)
13696 + struct au_write_pre wpre;
13697 + struct inode *inode;
13698 + struct file *h_file;
13699 + char __user *buf = (char __user *)ubuf;
13701 + inode = file_inode(file);
13702 + au_mtx_and_read_lock(inode);
13704 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13705 + err = PTR_ERR(h_file);
13706 + if (IS_ERR(h_file))
13709 + err = vfsub_write_u(h_file, buf, count, ppos);
13710 + au_write_post(inode, h_file, &wpre, err);
13713 + si_read_unlock(inode->i_sb);
13714 + inode_unlock(inode);
13718 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13719 + struct iov_iter *iov_iter)
13722 + struct file *file;
13723 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13725 + err = security_file_permission(h_file, rw);
13726 + if (unlikely(err))
13731 + if (rw == MAY_READ)
13732 + iter = h_file->f_op->read_iter;
13733 + else if (rw == MAY_WRITE)
13734 + iter = h_file->f_op->write_iter;
13736 + file = kio->ki_filp;
13737 + kio->ki_filp = h_file;
13740 + err = iter(kio, iov_iter);
13743 + /* currently there is no such fs */
13745 + kio->ki_filp = file;
13751 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13754 + struct file *file, *h_file;
13755 + struct inode *inode;
13756 + struct super_block *sb;
13758 + file = kio->ki_filp;
13759 + inode = file_inode(file);
13760 + sb = inode->i_sb;
13761 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13763 + h_file = au_read_pre(file, /*keep_fi*/0);
13764 + err = PTR_ERR(h_file);
13765 + if (IS_ERR(h_file))
13768 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13769 + /* todo: necessary? */
13770 + /* file->f_ra = h_file->f_ra; */
13771 + au_read_post(inode, h_file);
13774 + si_read_unlock(sb);
13778 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13781 + struct au_write_pre wpre;
13782 + struct inode *inode;
13783 + struct file *file, *h_file;
13785 + file = kio->ki_filp;
13786 + inode = file_inode(file);
13787 + au_mtx_and_read_lock(inode);
13789 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13790 + err = PTR_ERR(h_file);
13791 + if (IS_ERR(h_file))
13794 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13795 + au_write_post(inode, h_file, &wpre, err);
13798 + si_read_unlock(inode->i_sb);
13799 + inode_unlock(inode);
13803 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13804 + struct pipe_inode_info *pipe, size_t len,
13805 + unsigned int flags)
13808 + struct file *h_file;
13809 + struct inode *inode;
13810 + struct super_block *sb;
13812 + inode = file_inode(file);
13813 + sb = inode->i_sb;
13814 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13816 + h_file = au_read_pre(file, /*keep_fi*/1);
13817 + err = PTR_ERR(h_file);
13818 + if (IS_ERR(h_file))
13821 + if (au_test_loopback_kthread()) {
13822 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13823 + if (file->f_mapping != h_file->f_mapping) {
13824 + file->f_mapping = h_file->f_mapping;
13825 + smp_mb(); /* unnecessary? */
13828 + fi_read_unlock(file);
13830 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13831 + /* todo: necessasry? */
13832 + /* file->f_ra = h_file->f_ra; */
13833 + au_read_post(inode, h_file);
13836 + si_read_unlock(sb);
13841 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13842 + size_t len, unsigned int flags)
13845 + struct au_write_pre wpre;
13846 + struct inode *inode;
13847 + struct file *h_file;
13849 + inode = file_inode(file);
13850 + au_mtx_and_read_lock(inode);
13852 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13853 + err = PTR_ERR(h_file);
13854 + if (IS_ERR(h_file))
13857 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13858 + au_write_post(inode, h_file, &wpre, err);
13861 + si_read_unlock(inode->i_sb);
13862 + inode_unlock(inode);
13866 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13870 + struct au_write_pre wpre;
13871 + struct inode *inode;
13872 + struct file *h_file;
13874 + inode = file_inode(file);
13875 + au_mtx_and_read_lock(inode);
13877 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13878 + err = PTR_ERR(h_file);
13879 + if (IS_ERR(h_file))
13883 + err = vfs_fallocate(h_file, mode, offset, len);
13885 + au_write_post(inode, h_file, &wpre, /*written*/1);
13888 + si_read_unlock(inode->i_sb);
13889 + inode_unlock(inode);
13893 +/* ---------------------------------------------------------------------- */
13896 + * The locking order around current->mmap_sem.
13897 + * - in most and regular cases
13898 + * file I/O syscall -- aufs_read() or something
13899 + * -- si_rwsem for read -- mmap_sem
13900 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13902 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13903 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13904 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13905 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13906 + * It means that when aufs acquires si_rwsem for write, the process should never
13907 + * acquire mmap_sem.
13909 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13910 + * problem either since any directory is not able to be mmap-ed.
13911 + * The similar scenario is applied to aufs_readlink() too.
13914 +#if 0 /* stop calling security_file_mmap() */
13915 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13916 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13918 +static unsigned long au_arch_prot_conv(unsigned long flags)
13920 + /* currently ppc64 only */
13921 +#ifdef CONFIG_PPC64
13922 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13923 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13924 + return AuConv_VM_PROT(flags, SAO);
13926 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13931 +static unsigned long au_prot_conv(unsigned long flags)
13933 + return AuConv_VM_PROT(flags, READ)
13934 + | AuConv_VM_PROT(flags, WRITE)
13935 + | AuConv_VM_PROT(flags, EXEC)
13936 + | au_arch_prot_conv(flags);
13939 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13940 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13942 +static unsigned long au_flag_conv(unsigned long flags)
13944 + return AuConv_VM_MAP(flags, GROWSDOWN)
13945 + | AuConv_VM_MAP(flags, DENYWRITE)
13946 + | AuConv_VM_MAP(flags, LOCKED);
13950 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13953 + const unsigned char wlock
13954 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13955 + struct super_block *sb;
13956 + struct file *h_file;
13957 + struct inode *inode;
13959 + AuDbgVmRegion(file, vma);
13961 + inode = file_inode(file);
13962 + sb = inode->i_sb;
13964 + si_read_lock(sb, AuLock_NOPLMW);
13966 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
13968 + err = PTR_ERR(h_file);
13969 + if (IS_ERR(h_file))
13973 + au_set_mmapped(file);
13974 + au_vm_file_reset(vma, h_file);
13976 + * we cannot call security_mmap_file() here since it may acquire
13977 + * mmap_sem or i_mutex.
13979 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13980 + * au_flag_conv(vma->vm_flags));
13983 + err = h_file->f_op->mmap(h_file, vma);
13985 + au_vm_prfile_set(vma, file);
13986 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13987 + goto out_fput; /* success */
13989 + au_unset_mmapped(file);
13990 + au_vm_file_reset(vma, file);
13994 + ii_write_unlock(inode);
13999 + si_read_unlock(sb);
14005 +/* ---------------------------------------------------------------------- */
14007 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14011 + struct au_write_pre wpre;
14012 + struct inode *inode;
14013 + struct file *h_file;
14015 + err = 0; /* -EBADF; */ /* posix? */
14016 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14019 + inode = file_inode(file);
14020 + au_mtx_and_read_lock(inode);
14022 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14023 + err = PTR_ERR(h_file);
14024 + if (IS_ERR(h_file))
14027 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14028 + au_write_post(inode, h_file, &wpre, /*written*/0);
14031 + si_read_unlock(inode->i_sb);
14032 + inode_unlock(inode);
14037 +/* no one supports this operation, currently */
14039 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
14042 + struct au_write_pre wpre;
14043 + struct inode *inode, *h_inode;
14044 + struct file *file, *h_file;
14046 + err = 0; /* -EBADF; */ /* posix? */
14047 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14050 + file = kio->ki_filp;
14051 + inode = file_inode(file);
14052 + au_mtx_and_read_lock(inode);
14054 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14055 + err = PTR_ERR(h_file);
14056 + if (IS_ERR(h_file))
14060 + h_file = au_hf_top(file);
14061 + if (h_file->f_op->aio_fsync) {
14062 + h_inode = file_inode(h_file);
14063 + if (!is_sync_kiocb(kio)) {
14064 + get_file(h_file);
14067 + kio->ki_filp = h_file;
14068 + err = h_file->f_op->aio_fsync(kio, datasync);
14069 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
14071 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
14073 + inode_unlock(h_inode);
14075 + au_write_post(inode, h_file, &wpre, /*written*/0);
14078 + si_read_unlock(inode->sb);
14079 + inode_unlock(inode);
14085 +static int aufs_fasync(int fd, struct file *file, int flag)
14088 + struct file *h_file;
14089 + struct super_block *sb;
14091 + sb = file->f_path.dentry->d_sb;
14092 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14094 + h_file = au_read_pre(file, /*keep_fi*/0);
14095 + err = PTR_ERR(h_file);
14096 + if (IS_ERR(h_file))
14099 + if (h_file->f_op->fasync)
14100 + err = h_file->f_op->fasync(fd, h_file, flag);
14101 + fput(h_file); /* instead of au_read_post() */
14104 + si_read_unlock(sb);
14108 +static int aufs_setfl(struct file *file, unsigned long arg)
14111 + struct file *h_file;
14112 + struct super_block *sb;
14114 + sb = file->f_path.dentry->d_sb;
14115 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14117 + h_file = au_read_pre(file, /*keep_fi*/0);
14118 + err = PTR_ERR(h_file);
14119 + if (IS_ERR(h_file))
14122 + arg |= vfsub_file_flags(file) & FASYNC; /* stop calling h_file->fasync */
14123 + err = setfl(/*unused fd*/-1, h_file, arg);
14124 + fput(h_file); /* instead of au_read_post() */
14127 + si_read_unlock(sb);
14131 +/* ---------------------------------------------------------------------- */
14133 +/* no one supports this operation, currently */
14135 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14136 + size_t len, loff_t *pos, int more)
14141 +/* ---------------------------------------------------------------------- */
14143 +const struct file_operations aufs_file_fop = {
14144 + .owner = THIS_MODULE,
14146 + .llseek = default_llseek,
14148 + .read = aufs_read,
14149 + .write = aufs_write,
14150 + .read_iter = aufs_read_iter,
14151 + .write_iter = aufs_write_iter,
14153 +#ifdef CONFIG_AUFS_POLL
14154 + .poll = aufs_poll,
14156 + .unlocked_ioctl = aufs_ioctl_nondir,
14157 +#ifdef CONFIG_COMPAT
14158 + .compat_ioctl = aufs_compat_ioctl_nondir,
14160 + .mmap = aufs_mmap,
14161 + .open = aufs_open_nondir,
14162 + .flush = aufs_flush_nondir,
14163 + .release = aufs_release_nondir,
14164 + .fsync = aufs_fsync_nondir,
14165 + /* .aio_fsync = aufs_aio_fsync_nondir, */
14166 + .fasync = aufs_fasync,
14167 + /* .sendpage = aufs_sendpage, */
14168 + .setfl = aufs_setfl,
14169 + .splice_write = aufs_splice_write,
14170 + .splice_read = aufs_splice_read,
14172 + .aio_splice_write = aufs_aio_splice_write,
14173 + .aio_splice_read = aufs_aio_splice_read,
14175 + .fallocate = aufs_fallocate
14177 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14178 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14179 +++ linux/fs/aufs/fstype.h 2016-04-24 18:32:51.393686895 +0200
14182 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14184 + * This program, aufs is free software; you can redistribute it and/or modify
14185 + * it under the terms of the GNU General Public License as published by
14186 + * the Free Software Foundation; either version 2 of the License, or
14187 + * (at your option) any later version.
14189 + * This program is distributed in the hope that it will be useful,
14190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14192 + * GNU General Public License for more details.
14194 + * You should have received a copy of the GNU General Public License
14195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14199 + * judging filesystem type
14202 +#ifndef __AUFS_FSTYPE_H__
14203 +#define __AUFS_FSTYPE_H__
14207 +#include <linux/fs.h>
14208 +#include <linux/magic.h>
14209 +#include <linux/nfs_fs.h>
14210 +#include <linux/romfs_fs.h>
14212 +static inline int au_test_aufs(struct super_block *sb)
14214 + return sb->s_magic == AUFS_SUPER_MAGIC;
14217 +static inline const char *au_sbtype(struct super_block *sb)
14219 + return sb->s_type->name;
14222 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14224 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
14225 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14231 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14233 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
14234 + return sb->s_magic == ROMFS_MAGIC;
14240 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14242 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
14243 + return sb->s_magic == CRAMFS_MAGIC;
14248 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14250 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
14251 + return sb->s_magic == NFS_SUPER_MAGIC;
14257 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14259 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
14260 + return sb->s_magic == FUSE_SUPER_MAGIC;
14266 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14268 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
14269 + return sb->s_magic == XFS_SB_MAGIC;
14275 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14277 +#ifdef CONFIG_TMPFS
14278 + return sb->s_magic == TMPFS_MAGIC;
14284 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14286 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
14287 + return !strcmp(au_sbtype(sb), "ecryptfs");
14293 +static inline int au_test_ramfs(struct super_block *sb)
14295 + return sb->s_magic == RAMFS_MAGIC;
14298 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14300 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
14301 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14307 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14309 +#ifdef CONFIG_PROC_FS
14310 + return sb->s_magic == PROC_SUPER_MAGIC;
14316 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14318 +#ifdef CONFIG_SYSFS
14319 + return sb->s_magic == SYSFS_MAGIC;
14325 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14327 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
14328 + return sb->s_magic == CONFIGFS_MAGIC;
14334 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14336 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
14337 + return sb->s_magic == MINIX3_SUPER_MAGIC
14338 + || sb->s_magic == MINIX2_SUPER_MAGIC
14339 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14340 + || sb->s_magic == MINIX_SUPER_MAGIC
14341 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14347 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14349 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14350 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14356 +static inline int au_test_msdos(struct super_block *sb)
14358 + return au_test_fat(sb);
14361 +static inline int au_test_vfat(struct super_block *sb)
14363 + return au_test_fat(sb);
14366 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14368 +#ifdef CONFIG_SECURITYFS
14369 + return sb->s_magic == SECURITYFS_MAGIC;
14375 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14377 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14378 + return sb->s_magic == SQUASHFS_MAGIC;
14384 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14386 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14387 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14393 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14395 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14396 + return sb->s_magic == XENFS_SUPER_MAGIC;
14402 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14404 +#ifdef CONFIG_DEBUG_FS
14405 + return sb->s_magic == DEBUGFS_MAGIC;
14411 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14413 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14414 + return sb->s_magic == NILFS_SUPER_MAGIC;
14420 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14422 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14423 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14429 +/* ---------------------------------------------------------------------- */
14431 + * they can't be an aufs branch.
14433 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14436 +#ifndef CONFIG_AUFS_BR_RAMFS
14437 + au_test_ramfs(sb) ||
14439 + au_test_procfs(sb)
14440 + || au_test_sysfs(sb)
14441 + || au_test_configfs(sb)
14442 + || au_test_debugfs(sb)
14443 + || au_test_securityfs(sb)
14444 + || au_test_xenfs(sb)
14445 + || au_test_ecryptfs(sb)
14446 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14447 + || au_test_aufs(sb); /* will be supported in next version */
14450 +static inline int au_test_fs_remote(struct super_block *sb)
14452 + return !au_test_tmpfs(sb)
14453 +#ifdef CONFIG_AUFS_BR_RAMFS
14454 + && !au_test_ramfs(sb)
14456 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14459 +/* ---------------------------------------------------------------------- */
14462 + * Note: these functions (below) are created after reading ->getattr() in all
14463 + * filesystems under linux/fs. it means we have to do so in every update...
14467 + * some filesystems require getattr to refresh the inode attributes before
14469 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14470 + * and leave the work for d_revalidate()
14472 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14474 + return au_test_nfs(sb)
14475 + || au_test_fuse(sb)
14476 + /* || au_test_btrfs(sb) */ /* untested */
14481 + * filesystems which don't maintain i_size or i_blocks.
14483 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14485 + return au_test_xfs(sb)
14486 + || au_test_btrfs(sb)
14487 + || au_test_ubifs(sb)
14488 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14489 + /* || au_test_minix(sb) */ /* untested */
14494 + * filesystems which don't store the correct value in some of their inode
14497 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14499 + return au_test_fs_bad_iattr_size(sb)
14500 + || au_test_fat(sb)
14501 + || au_test_msdos(sb)
14502 + || au_test_vfat(sb);
14505 +/* they don't check i_nlink in link(2) */
14506 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14508 + return au_test_tmpfs(sb)
14509 +#ifdef CONFIG_AUFS_BR_RAMFS
14510 + || au_test_ramfs(sb)
14512 + || au_test_ubifs(sb)
14513 + || au_test_hfsplus(sb);
14517 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14519 +static inline int au_test_fs_notime(struct super_block *sb)
14521 + return au_test_nfs(sb)
14522 + || au_test_fuse(sb)
14523 + || au_test_ubifs(sb)
14527 +/* temporary support for i#1 in cramfs */
14528 +static inline int au_test_fs_unique_ino(struct inode *inode)
14530 + if (au_test_cramfs(inode->i_sb))
14531 + return inode->i_ino != 1;
14535 +/* ---------------------------------------------------------------------- */
14538 + * the filesystem where the xino files placed must support i/o after unlink and
14539 + * maintain i_size and i_blocks.
14541 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14543 + return au_test_fs_remote(sb)
14544 + || au_test_fs_bad_iattr_size(sb)
14545 + /* don't want unnecessary work for xino */
14546 + || au_test_aufs(sb)
14547 + || au_test_ecryptfs(sb)
14548 + || au_test_nilfs(sb);
14551 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14553 + return au_test_tmpfs(sb)
14554 + || au_test_ramfs(sb);
14558 + * test if the @sb is real-readonly.
14560 +static inline int au_test_fs_rr(struct super_block *sb)
14562 + return au_test_squashfs(sb)
14563 + || au_test_iso9660(sb)
14564 + || au_test_cramfs(sb)
14565 + || au_test_romfs(sb);
14569 + * test if the @inode is nfs with 'noacl' option
14570 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14572 +static inline int au_test_nfs_noacl(struct inode *inode)
14574 + return au_test_nfs(inode->i_sb)
14575 + /* && IS_POSIXACL(inode) */
14576 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14579 +#endif /* __KERNEL__ */
14580 +#endif /* __AUFS_FSTYPE_H__ */
14581 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14582 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14583 +++ linux/fs/aufs/hfsnotify.c 2016-04-24 18:32:51.393686895 +0200
14586 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14588 + * This program, aufs is free software; you can redistribute it and/or modify
14589 + * it under the terms of the GNU General Public License as published by
14590 + * the Free Software Foundation; either version 2 of the License, or
14591 + * (at your option) any later version.
14593 + * This program is distributed in the hope that it will be useful,
14594 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14595 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14596 + * GNU General Public License for more details.
14598 + * You should have received a copy of the GNU General Public License
14599 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14603 + * fsnotify for the lower directories
14608 +/* FS_IN_IGNORED is unnecessary */
14609 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14610 + | FS_CREATE | FS_EVENT_ON_CHILD);
14611 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14612 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14614 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14616 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14619 + au_cache_free_hnotify(hn);
14620 + smp_mb__before_atomic();
14621 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14622 + wake_up(&au_hfsn_wq);
14625 +static int au_hfsn_alloc(struct au_hinode *hinode)
14628 + struct au_hnotify *hn;
14629 + struct super_block *sb;
14630 + struct au_branch *br;
14631 + struct fsnotify_mark *mark;
14632 + aufs_bindex_t bindex;
14634 + hn = hinode->hi_notify;
14635 + sb = hn->hn_aufs_inode->i_sb;
14636 + bindex = au_br_index(sb, hinode->hi_id);
14637 + br = au_sbr(sb, bindex);
14638 + AuDebugOn(!br->br_hfsn);
14640 + mark = &hn->hn_mark;
14641 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14642 + mark->mask = AuHfsnMask;
14644 + * by udba rename or rmdir, aufs assign a new inode to the known
14645 + * h_inode, so specify 1 to allow dups.
14648 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14649 + /*mnt*/NULL, /*allow_dups*/1);
14650 + /* even if err */
14651 + fsnotify_put_mark(mark);
14657 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14659 + struct fsnotify_mark *mark;
14660 + unsigned long long ull;
14661 + struct fsnotify_group *group;
14663 + ull = atomic64_inc_return(&au_hfsn_ifree);
14666 + mark = &hn->hn_mark;
14667 + spin_lock(&mark->lock);
14668 + group = mark->group;
14669 + fsnotify_get_group(group);
14670 + spin_unlock(&mark->lock);
14672 + fsnotify_destroy_mark(mark, group);
14673 + fsnotify_put_group(group);
14676 + /* free hn by myself */
14680 +/* ---------------------------------------------------------------------- */
14682 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14684 + struct fsnotify_mark *mark;
14686 + mark = &hinode->hi_notify->hn_mark;
14687 + spin_lock(&mark->lock);
14689 + AuDebugOn(mark->mask & AuHfsnMask);
14690 + mark->mask |= AuHfsnMask;
14692 + AuDebugOn(!(mark->mask & AuHfsnMask));
14693 + mark->mask &= ~AuHfsnMask;
14695 + spin_unlock(&mark->lock);
14696 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14699 +/* ---------------------------------------------------------------------- */
14701 +/* #define AuDbgHnotify */
14702 +#ifdef AuDbgHnotify
14703 +static char *au_hfsn_name(u32 mask)
14705 +#ifdef CONFIG_AUFS_DEBUG
14706 +#define test_ret(flag) \
14708 + if (mask & flag) \
14711 + test_ret(FS_ACCESS);
14712 + test_ret(FS_MODIFY);
14713 + test_ret(FS_ATTRIB);
14714 + test_ret(FS_CLOSE_WRITE);
14715 + test_ret(FS_CLOSE_NOWRITE);
14716 + test_ret(FS_OPEN);
14717 + test_ret(FS_MOVED_FROM);
14718 + test_ret(FS_MOVED_TO);
14719 + test_ret(FS_CREATE);
14720 + test_ret(FS_DELETE);
14721 + test_ret(FS_DELETE_SELF);
14722 + test_ret(FS_MOVE_SELF);
14723 + test_ret(FS_UNMOUNT);
14724 + test_ret(FS_Q_OVERFLOW);
14725 + test_ret(FS_IN_IGNORED);
14726 + test_ret(FS_ISDIR);
14727 + test_ret(FS_IN_ONESHOT);
14728 + test_ret(FS_EVENT_ON_CHILD);
14737 +/* ---------------------------------------------------------------------- */
14739 +static void au_hfsn_free_group(struct fsnotify_group *group)
14741 + struct au_br_hfsnotify *hfsn = group->private;
14747 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14748 + struct inode *inode,
14749 + struct fsnotify_mark *inode_mark,
14750 + struct fsnotify_mark *vfsmount_mark,
14751 + u32 mask, void *data, int data_type,
14752 + const unsigned char *file_name, u32 cookie)
14755 + struct au_hnotify *hnotify;
14756 + struct inode *h_dir, *h_inode;
14757 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14759 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14762 + /* if FS_UNMOUNT happens, there must be another bug */
14763 + AuDebugOn(mask & FS_UNMOUNT);
14764 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14769 +#ifdef AuDbgHnotify
14771 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14772 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14773 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14774 + h_dir->i_ino, mask, au_hfsn_name(mask),
14775 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14776 + /* WARN_ON(1); */
14781 + AuDebugOn(!inode_mark);
14782 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14783 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14789 +static struct fsnotify_ops au_hfsn_ops = {
14790 + .handle_event = au_hfsn_handle_event,
14791 + .free_group_priv = au_hfsn_free_group
14794 +/* ---------------------------------------------------------------------- */
14796 +static void au_hfsn_fin_br(struct au_branch *br)
14798 + struct au_br_hfsnotify *hfsn;
14800 + hfsn = br->br_hfsn;
14803 + fsnotify_put_group(hfsn->hfsn_group);
14808 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14811 + struct fsnotify_group *group;
14812 + struct au_br_hfsnotify *hfsn;
14815 + br->br_hfsn = NULL;
14816 + if (!au_br_hnotifyable(perm))
14820 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14821 + if (unlikely(!hfsn))
14825 + group = fsnotify_alloc_group(&au_hfsn_ops);
14826 + if (IS_ERR(group)) {
14827 + err = PTR_ERR(group);
14828 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14832 + group->private = hfsn;
14833 + hfsn->hfsn_group = group;
14834 + br->br_hfsn = hfsn;
14835 + goto out; /* success */
14843 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14848 + if (!br->br_hfsn)
14849 + err = au_hfsn_init_br(br, perm);
14854 +/* ---------------------------------------------------------------------- */
14856 +static void au_hfsn_fin(void)
14858 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14859 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14862 +const struct au_hnotify_op au_hnotify_op = {
14863 + .ctl = au_hfsn_ctl,
14864 + .alloc = au_hfsn_alloc,
14865 + .free = au_hfsn_free,
14867 + .fin = au_hfsn_fin,
14869 + .reset_br = au_hfsn_reset_br,
14870 + .fin_br = au_hfsn_fin_br,
14871 + .init_br = au_hfsn_init_br
14873 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14874 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14875 +++ linux/fs/aufs/hfsplus.c 2016-04-24 18:32:51.393686895 +0200
14878 + * Copyright (C) 2010-2016 Junjiro R. Okajima
14880 + * This program, aufs is free software; you can redistribute it and/or modify
14881 + * it under the terms of the GNU General Public License as published by
14882 + * the Free Software Foundation; either version 2 of the License, or
14883 + * (at your option) any later version.
14885 + * This program is distributed in the hope that it will be useful,
14886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14888 + * GNU General Public License for more details.
14890 + * You should have received a copy of the GNU General Public License
14891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14895 + * special support for filesystems which aqucires an inode mutex
14896 + * at final closing a file, eg, hfsplus.
14898 + * This trick is very simple and stupid, just to open the file before really
14899 + * neceeary open to tell hfsplus that this is not the final closing.
14900 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14901 + * and au_h_open_post() after releasing it.
14906 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14909 + struct file *h_file;
14910 + struct dentry *h_dentry;
14912 + h_dentry = au_h_dptr(dentry, bindex);
14913 + AuDebugOn(!h_dentry);
14914 + AuDebugOn(d_is_negative(h_dentry));
14917 + if (au_test_hfsplus(h_dentry->d_sb)
14918 + && d_is_reg(h_dentry))
14919 + h_file = au_h_open(dentry, bindex,
14920 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14921 + /*file*/NULL, force_wr);
14925 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14926 + struct file *h_file)
14930 + au_sbr_put(dentry->d_sb, bindex);
14933 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14934 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14935 +++ linux/fs/aufs/hnotify.c 2016-04-24 18:32:51.393686895 +0200
14938 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14940 + * This program, aufs is free software; you can redistribute it and/or modify
14941 + * it under the terms of the GNU General Public License as published by
14942 + * the Free Software Foundation; either version 2 of the License, or
14943 + * (at your option) any later version.
14945 + * This program is distributed in the hope that it will be useful,
14946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14948 + * GNU General Public License for more details.
14950 + * You should have received a copy of the GNU General Public License
14951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14955 + * abstraction to notify the direct changes on lower directories
14960 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14963 + struct au_hnotify *hn;
14966 + hn = au_cache_alloc_hnotify();
14968 + hn->hn_aufs_inode = inode;
14969 + hinode->hi_notify = hn;
14970 + err = au_hnotify_op.alloc(hinode);
14972 + if (unlikely(err)) {
14973 + hinode->hi_notify = NULL;
14974 + au_cache_free_hnotify(hn);
14976 + * The upper dir was removed by udba, but the same named
14977 + * dir left. In this case, aufs assignes a new inode
14978 + * number and set the monitor again.
14979 + * For the lower dir, the old monitnor is still left.
14981 + if (err == -EEXIST)
14990 +void au_hn_free(struct au_hinode *hinode)
14992 + struct au_hnotify *hn;
14994 + hn = hinode->hi_notify;
14996 + hinode->hi_notify = NULL;
14997 + if (au_hnotify_op.free(hinode, hn))
14998 + au_cache_free_hnotify(hn);
15002 +/* ---------------------------------------------------------------------- */
15004 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15006 + if (hinode->hi_notify)
15007 + au_hnotify_op.ctl(hinode, do_set);
15010 +void au_hn_reset(struct inode *inode, unsigned int flags)
15012 + aufs_bindex_t bindex, bend;
15013 + struct inode *hi;
15014 + struct dentry *iwhdentry;
15016 + bend = au_ibend(inode);
15017 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
15018 + hi = au_h_iptr(inode, bindex);
15022 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15023 + iwhdentry = au_hi_wh(inode, bindex);
15027 + au_set_h_iptr(inode, bindex, NULL, 0);
15028 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15029 + flags & ~AuHi_XINO);
15032 + /* inode_unlock(hi); */
15036 +/* ---------------------------------------------------------------------- */
15038 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15041 + aufs_bindex_t bindex, bend, bfound, bstart;
15042 + struct inode *h_i;
15045 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15046 + pr_warn("branch root dir was changed\n");
15051 + bend = au_ibend(inode);
15052 + bstart = au_ibstart(inode);
15053 +#if 0 /* reserved for future use */
15054 + if (bindex == bend) {
15055 + /* keep this ino in rename case */
15059 + for (bindex = bstart; bindex <= bend; bindex++)
15060 + if (au_h_iptr(inode, bindex) == h_inode) {
15067 + for (bindex = bstart; bindex <= bend; bindex++) {
15068 + h_i = au_h_iptr(inode, bindex);
15072 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15073 + /* ignore this error */
15074 + /* bad action? */
15077 + /* children inode number will be broken */
15084 +static int hn_gen_tree(struct dentry *dentry)
15086 + int err, i, j, ndentry;
15087 + struct au_dcsub_pages dpages;
15088 + struct au_dpage *dpage;
15089 + struct dentry **dentries;
15091 + err = au_dpages_init(&dpages, GFP_NOFS);
15092 + if (unlikely(err))
15094 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15095 + if (unlikely(err))
15098 + for (i = 0; i < dpages.ndpage; i++) {
15099 + dpage = dpages.dpages + i;
15100 + dentries = dpage->dentries;
15101 + ndentry = dpage->ndentry;
15102 + for (j = 0; j < ndentry; j++) {
15103 + struct dentry *d;
15110 + if (d_really_is_positive(d))
15111 + /* todo: reset children xino?
15112 + cached children only? */
15113 + au_iigen_dec(d_inode(d));
15118 + au_dpages_free(&dpages);
15121 + /* discard children */
15122 + dentry_unhash(dentry);
15130 + * return 0 if processed.
15132 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15133 + const unsigned int isdir)
15136 + struct dentry *d;
15137 + struct qstr *dname;
15140 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15141 + pr_warn("branch root dir was changed\n");
15147 + AuDebugOn(!name);
15148 + au_iigen_dec(inode);
15149 + spin_lock(&inode->i_lock);
15150 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15151 + spin_lock(&d->d_lock);
15152 + dname = &d->d_name;
15153 + if (dname->len != nlen
15154 + && memcmp(dname->name, name, nlen)) {
15155 + spin_unlock(&d->d_lock);
15160 + spin_unlock(&d->d_lock);
15163 + spin_unlock(&inode->i_lock);
15165 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15166 + d = d_find_any_alias(inode);
15168 + au_iigen_dec(inode);
15172 + spin_lock(&d->d_lock);
15173 + dname = &d->d_name;
15174 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15175 + spin_unlock(&d->d_lock);
15176 + err = hn_gen_tree(d);
15177 + spin_lock(&d->d_lock);
15179 + spin_unlock(&d->d_lock);
15188 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15192 + if (IS_ROOT(dentry)) {
15193 + pr_warn("branch root dir was changed\n");
15199 + au_digen_dec(dentry);
15200 + if (d_really_is_positive(dentry))
15201 + au_iigen_dec(d_inode(dentry));
15203 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15204 + if (d_really_is_positive(dentry))
15205 + err = hn_gen_tree(dentry);
15212 +/* ---------------------------------------------------------------------- */
15214 +/* hnotify job flags */
15215 +#define AuHnJob_XINO0 1
15216 +#define AuHnJob_GEN (1 << 1)
15217 +#define AuHnJob_DIRENT (1 << 2)
15218 +#define AuHnJob_ISDIR (1 << 3)
15219 +#define AuHnJob_TRYXINO0 (1 << 4)
15220 +#define AuHnJob_MNTPNT (1 << 5)
15221 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15222 +#define au_fset_hnjob(flags, name) \
15223 + do { (flags) |= AuHnJob_##name; } while (0)
15224 +#define au_fclr_hnjob(flags, name) \
15225 + do { (flags) &= ~AuHnJob_##name; } while (0)
15233 +struct au_hnotify_args {
15234 + struct inode *h_dir, *dir, *h_child_inode;
15236 + unsigned int flags[AuHnLast];
15237 + unsigned int h_child_nlen;
15238 + char h_child_name[];
15241 +struct hn_job_args {
15242 + unsigned int flags;
15243 + struct inode *inode, *h_inode, *dir, *h_dir;
15244 + struct dentry *dentry;
15249 +static int hn_job(struct hn_job_args *a)
15251 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15255 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15256 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15258 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15261 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
15262 + if (!a->h_inode->i_nlink
15263 + && !(a->h_inode->i_state & I_LINKABLE))
15264 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15265 + inode_unlock(a->h_inode);
15268 + /* make the generation obsolete */
15269 + if (au_ftest_hnjob(a->flags, GEN)) {
15272 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15274 + if (e && a->dentry)
15275 + hn_gen_by_name(a->dentry, isdir);
15276 + /* ignore this error */
15279 + /* make dir entries obsolete */
15280 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15281 + struct au_vdir *vdir;
15283 + vdir = au_ivdir(a->inode);
15285 + vdir->vd_jiffy = 0;
15286 + /* IMustLock(a->inode); */
15287 + /* a->inode->i_version++; */
15290 + /* can do nothing but warn */
15291 + if (au_ftest_hnjob(a->flags, MNTPNT)
15293 + && d_mountpoint(a->dentry))
15294 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15299 +/* ---------------------------------------------------------------------- */
15301 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15302 + struct inode *dir)
15304 + struct dentry *dentry, *d, *parent;
15305 + struct qstr *dname;
15307 + parent = d_find_any_alias(dir);
15312 + spin_lock(&parent->d_lock);
15313 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15314 + /* AuDbg("%pd\n", d); */
15315 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15316 + dname = &d->d_name;
15317 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15318 + goto cont_unlock;
15322 + goto cont_unlock;
15323 + if (au_dcount(d) > 0) {
15324 + dentry = dget_dlock(d);
15325 + spin_unlock(&d->d_lock);
15330 + spin_unlock(&d->d_lock);
15332 + spin_unlock(&parent->d_lock);
15336 + di_write_lock_child(dentry);
15341 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15342 + aufs_bindex_t bindex, ino_t h_ino)
15344 + struct inode *inode;
15349 + err = au_xino_read(sb, bindex, h_ino, &ino);
15351 + inode = ilookup(sb, ino);
15355 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15356 + pr_warn("wrong root branch\n");
15362 + ii_write_lock_child(inode);
15368 +static void au_hn_bh(void *_args)
15370 + struct au_hnotify_args *a = _args;
15371 + struct super_block *sb;
15372 + aufs_bindex_t bindex, bend, bfound;
15373 + unsigned char xino, try_iput;
15375 + struct inode *inode;
15377 + struct hn_job_args args;
15378 + struct dentry *dentry;
15379 + struct au_sbinfo *sbinfo;
15381 + AuDebugOn(!_args);
15382 + AuDebugOn(!a->h_dir);
15383 + AuDebugOn(!a->dir);
15384 + AuDebugOn(!a->mask);
15385 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15386 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15387 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15392 + * do not lock a->dir->i_mutex here
15393 + * because of d_revalidate() may cause a deadlock.
15395 + sb = a->dir->i_sb;
15397 + sbinfo = au_sbi(sb);
15398 + AuDebugOn(!sbinfo);
15399 + si_write_lock(sb, AuLock_NOPLMW);
15401 + ii_read_lock_parent(a->dir);
15403 + bend = au_ibend(a->dir);
15404 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
15405 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15409 + ii_read_unlock(a->dir);
15410 + if (unlikely(bfound < 0))
15413 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15415 + if (a->h_child_inode)
15416 + h_ino = a->h_child_inode->i_ino;
15418 + if (a->h_child_nlen
15419 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15420 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15421 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15424 + if (dentry && d_really_is_positive(dentry))
15425 + inode = d_inode(dentry);
15426 + if (xino && !inode && h_ino
15427 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15428 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15429 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15430 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15434 + args.flags = a->flags[AuHn_CHILD];
15435 + args.dentry = dentry;
15436 + args.inode = inode;
15437 + args.h_inode = a->h_child_inode;
15438 + args.dir = a->dir;
15439 + args.h_dir = a->h_dir;
15440 + args.h_name = a->h_child_name;
15441 + args.h_nlen = a->h_child_nlen;
15442 + err = hn_job(&args);
15444 + if (au_di(dentry))
15445 + di_write_unlock(dentry);
15448 + if (inode && try_iput) {
15449 + ii_write_unlock(inode);
15453 + ii_write_lock_parent(a->dir);
15454 + args.flags = a->flags[AuHn_PARENT];
15455 + args.dentry = NULL;
15456 + args.inode = a->dir;
15457 + args.h_inode = a->h_dir;
15459 + args.h_dir = NULL;
15460 + args.h_name = NULL;
15462 + err = hn_job(&args);
15463 + ii_write_unlock(a->dir);
15466 + iput(a->h_child_inode);
15469 + si_write_unlock(sb);
15470 + au_nwt_done(&sbinfo->si_nowait);
15474 +/* ---------------------------------------------------------------------- */
15476 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15477 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15480 + unsigned int flags[AuHnLast], f;
15481 + unsigned char isdir, isroot, wh;
15482 + struct inode *dir;
15483 + struct au_hnotify_args *args;
15484 + char *p, *h_child_name;
15487 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15488 + dir = igrab(hnotify->hn_aufs_inode);
15492 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15494 + h_child_name = (void *)h_child_qstr->name;
15495 + len = h_child_qstr->len;
15496 + if (h_child_name) {
15497 + if (len > AUFS_WH_PFX_LEN
15498 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15499 + h_child_name += AUFS_WH_PFX_LEN;
15500 + len -= AUFS_WH_PFX_LEN;
15506 + if (h_child_inode)
15507 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15508 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15509 + flags[AuHn_CHILD] = 0;
15511 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15512 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15513 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15514 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15515 + case FS_MOVED_FROM:
15516 + case FS_MOVED_TO:
15517 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15518 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15521 + AuDebugOn(!h_child_name);
15526 + * aufs never be able to get this child inode.
15527 + * revalidation should be in d_revalidate()
15528 + * by checking i_nlink, i_generation or d_unhashed().
15530 + AuDebugOn(!h_child_name);
15531 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15532 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15540 + h_child_inode = NULL;
15543 + /* iput() and kfree() will be called in au_hnotify() */
15544 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15545 + if (unlikely(!args)) {
15546 + AuErr1("no memory\n");
15550 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15551 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15552 + args->mask = mask;
15554 + args->h_dir = igrab(h_dir);
15555 + if (h_child_inode)
15556 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15557 + args->h_child_inode = h_child_inode;
15558 + args->h_child_nlen = len;
15560 + p = (void *)args;
15561 + p += sizeof(*args);
15562 + memcpy(p, h_child_name, len);
15566 + /* NFS fires the event for silly-renamed one from kworker */
15568 + if (!dir->i_nlink
15569 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15571 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15572 + if (unlikely(err)) {
15573 + pr_err("wkq %d\n", err);
15574 + iput(args->h_child_inode);
15575 + iput(args->h_dir);
15584 +/* ---------------------------------------------------------------------- */
15586 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15590 + AuDebugOn(!(udba & AuOptMask_UDBA));
15593 + if (au_hnotify_op.reset_br)
15594 + err = au_hnotify_op.reset_br(udba, br, perm);
15599 +int au_hnotify_init_br(struct au_branch *br, int perm)
15604 + if (au_hnotify_op.init_br)
15605 + err = au_hnotify_op.init_br(br, perm);
15610 +void au_hnotify_fin_br(struct au_branch *br)
15612 + if (au_hnotify_op.fin_br)
15613 + au_hnotify_op.fin_br(br);
15616 +static void au_hn_destroy_cache(void)
15618 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15619 + au_cachep[AuCache_HNOTIFY] = NULL;
15622 +int __init au_hnotify_init(void)
15627 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15628 + if (au_cachep[AuCache_HNOTIFY]) {
15630 + if (au_hnotify_op.init)
15631 + err = au_hnotify_op.init();
15632 + if (unlikely(err))
15633 + au_hn_destroy_cache();
15639 +void au_hnotify_fin(void)
15641 + if (au_hnotify_op.fin)
15642 + au_hnotify_op.fin();
15643 + /* cf. au_cache_fin() */
15644 + if (au_cachep[AuCache_HNOTIFY])
15645 + au_hn_destroy_cache();
15647 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15648 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15649 +++ linux/fs/aufs/iinfo.c 2016-04-24 18:32:51.393686895 +0200
15652 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15654 + * This program, aufs is free software; you can redistribute it and/or modify
15655 + * it under the terms of the GNU General Public License as published by
15656 + * the Free Software Foundation; either version 2 of the License, or
15657 + * (at your option) any later version.
15659 + * This program is distributed in the hope that it will be useful,
15660 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15661 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15662 + * GNU General Public License for more details.
15664 + * You should have received a copy of the GNU General Public License
15665 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15669 + * inode private data
15674 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15676 + struct inode *h_inode;
15678 + IiMustAnyLock(inode);
15680 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15681 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15685 +/* todo: hard/soft set? */
15686 +void au_hiput(struct au_hinode *hinode)
15688 + au_hn_free(hinode);
15689 + dput(hinode->hi_whdentry);
15690 + iput(hinode->hi_inode);
15693 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15695 + unsigned int flags;
15696 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15699 + if (au_opt_test(mnt_flags, XINO))
15700 + au_fset_hi(flags, XINO);
15701 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15702 + au_fset_hi(flags, HNOTIFY);
15706 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15707 + struct inode *h_inode, unsigned int flags)
15709 + struct au_hinode *hinode;
15710 + struct inode *hi;
15711 + struct au_iinfo *iinfo = au_ii(inode);
15713 + IiMustWriteLock(inode);
15715 + hinode = iinfo->ii_hinode + bindex;
15716 + hi = hinode->hi_inode;
15717 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15720 + au_hiput(hinode);
15721 + hinode->hi_inode = h_inode;
15724 + struct super_block *sb = inode->i_sb;
15725 + struct au_branch *br;
15727 + AuDebugOn(inode->i_mode
15728 + && (h_inode->i_mode & S_IFMT)
15729 + != (inode->i_mode & S_IFMT));
15730 + if (bindex == iinfo->ii_bstart)
15731 + au_cpup_igen(inode, h_inode);
15732 + br = au_sbr(sb, bindex);
15733 + hinode->hi_id = br->br_id;
15734 + if (au_ftest_hi(flags, XINO)) {
15735 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15737 + if (unlikely(err))
15738 + AuIOErr1("failed au_xino_write() %d\n", err);
15741 + if (au_ftest_hi(flags, HNOTIFY)
15742 + && au_br_hnotifyable(br->br_perm)) {
15743 + err = au_hn_alloc(hinode, inode);
15744 + if (unlikely(err))
15745 + AuIOErr1("au_hn_alloc() %d\n", err);
15750 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15751 + struct dentry *h_wh)
15753 + struct au_hinode *hinode;
15755 + IiMustWriteLock(inode);
15757 + hinode = au_ii(inode)->ii_hinode + bindex;
15758 + AuDebugOn(hinode->hi_whdentry);
15759 + hinode->hi_whdentry = h_wh;
15762 +void au_update_iigen(struct inode *inode, int half)
15764 + struct au_iinfo *iinfo;
15765 + struct au_iigen *iigen;
15766 + unsigned int sigen;
15768 + sigen = au_sigen(inode->i_sb);
15769 + iinfo = au_ii(inode);
15770 + iigen = &iinfo->ii_generation;
15771 + spin_lock(&iigen->ig_spin);
15772 + iigen->ig_generation = sigen;
15774 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15776 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15777 + spin_unlock(&iigen->ig_spin);
15780 +/* it may be called at remount time, too */
15781 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15783 + struct au_iinfo *iinfo;
15784 + aufs_bindex_t bindex, bend;
15786 + iinfo = au_ii(inode);
15790 + IiMustWriteLock(inode);
15792 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15793 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15795 + struct inode *h_i;
15797 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15800 + && !(h_i->i_state & I_LINKABLE))
15801 + au_set_h_iptr(inode, bindex, NULL, 0);
15805 + iinfo->ii_bstart = -1;
15806 + iinfo->ii_bend = -1;
15807 + bend = au_sbend(inode->i_sb);
15808 + for (bindex = 0; bindex <= bend; bindex++)
15809 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15810 + iinfo->ii_bstart = bindex;
15813 + if (iinfo->ii_bstart >= 0)
15814 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15815 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15816 + iinfo->ii_bend = bindex;
15819 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15822 +/* ---------------------------------------------------------------------- */
15824 +void au_icntnr_init_once(void *_c)
15826 + struct au_icntnr *c = _c;
15827 + struct au_iinfo *iinfo = &c->iinfo;
15828 + static struct lock_class_key aufs_ii;
15830 + spin_lock_init(&iinfo->ii_generation.ig_spin);
15831 + au_rw_init(&iinfo->ii_rwsem);
15832 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15833 + inode_init_once(&c->vfs_inode);
15836 +int au_iinfo_init(struct inode *inode)
15838 + struct au_iinfo *iinfo;
15839 + struct super_block *sb;
15842 + sb = inode->i_sb;
15843 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15844 + nbr = au_sbend(sb) + 1;
15845 + if (unlikely(nbr <= 0))
15847 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15848 + if (iinfo->ii_hinode) {
15849 + au_ninodes_inc(sb);
15850 + for (i = 0; i < nbr; i++)
15851 + iinfo->ii_hinode[i].hi_id = -1;
15853 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15854 + iinfo->ii_bstart = -1;
15855 + iinfo->ii_bend = -1;
15856 + iinfo->ii_vdir = NULL;
15862 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15865 + struct au_hinode *hip;
15867 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15870 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15872 + sz = sizeof(*hip);
15873 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15875 + iinfo->ii_hinode = hip;
15882 +void au_iinfo_fin(struct inode *inode)
15884 + struct au_iinfo *iinfo;
15885 + struct au_hinode *hi;
15886 + struct super_block *sb;
15887 + aufs_bindex_t bindex, bend;
15888 + const unsigned char unlinked = !inode->i_nlink;
15890 + iinfo = au_ii(inode);
15891 + /* bad_inode case */
15895 + sb = inode->i_sb;
15896 + au_ninodes_dec(sb);
15897 + if (si_pid_test(sb))
15898 + au_xino_delete_inode(inode, unlinked);
15901 + * it is safe to hide the dependency between sbinfo and
15905 + si_noflush_read_lock(sb);
15906 + au_xino_delete_inode(inode, unlinked);
15907 + si_read_unlock(sb);
15911 + if (iinfo->ii_vdir)
15912 + au_vdir_free(iinfo->ii_vdir);
15914 + bindex = iinfo->ii_bstart;
15915 + if (bindex >= 0) {
15916 + hi = iinfo->ii_hinode + bindex;
15917 + bend = iinfo->ii_bend;
15918 + while (bindex++ <= bend) {
15919 + if (hi->hi_inode)
15924 + kfree(iinfo->ii_hinode);
15925 + iinfo->ii_hinode = NULL;
15926 + AuRwDestroy(&iinfo->ii_rwsem);
15928 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15929 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15930 +++ linux/fs/aufs/inode.c 2016-04-24 18:32:51.393686895 +0200
15933 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15935 + * This program, aufs is free software; you can redistribute it and/or modify
15936 + * it under the terms of the GNU General Public License as published by
15937 + * the Free Software Foundation; either version 2 of the License, or
15938 + * (at your option) any later version.
15940 + * This program is distributed in the hope that it will be useful,
15941 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15942 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15943 + * GNU General Public License for more details.
15945 + * You should have received a copy of the GNU General Public License
15946 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15950 + * inode functions
15955 +struct inode *au_igrab(struct inode *inode)
15958 + AuDebugOn(!atomic_read(&inode->i_count));
15964 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15966 + au_cpup_attr_all(inode, /*force*/0);
15967 + au_update_iigen(inode, /*half*/1);
15969 + inode->i_version++;
15972 +static int au_ii_refresh(struct inode *inode, int *update)
15976 + aufs_bindex_t bindex, new_bindex;
15977 + struct super_block *sb;
15978 + struct au_iinfo *iinfo;
15979 + struct au_hinode *p, *q, tmp;
15981 + IiMustWriteLock(inode);
15984 + sb = inode->i_sb;
15985 + type = inode->i_mode & S_IFMT;
15986 + iinfo = au_ii(inode);
15987 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15988 + if (unlikely(err))
15991 + AuDebugOn(iinfo->ii_bstart < 0);
15992 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15993 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15995 + if (!p->hi_inode)
15998 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15999 + new_bindex = au_br_index(sb, p->hi_id);
16000 + if (new_bindex == bindex)
16003 + if (new_bindex < 0) {
16006 + p->hi_inode = NULL;
16010 + if (new_bindex < iinfo->ii_bstart)
16011 + iinfo->ii_bstart = new_bindex;
16012 + if (iinfo->ii_bend < new_bindex)
16013 + iinfo->ii_bend = new_bindex;
16014 + /* swap two lower inode, and loop again */
16015 + q = iinfo->ii_hinode + new_bindex;
16019 + if (tmp.hi_inode) {
16024 + au_update_ibrange(inode, /*do_put_zero*/0);
16025 + e = au_dy_irefresh(inode);
16026 + if (unlikely(e && !err))
16034 +void au_refresh_iop(struct inode *inode, int force_getattr)
16037 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
16038 + const struct inode_operations *iop
16039 + = force_getattr ? aufs_iop : sbi->si_iop_array;
16041 + if (inode->i_op == iop)
16044 + switch (inode->i_mode & S_IFMT) {
16046 + type = AuIop_DIR;
16049 + type = AuIop_SYMLINK;
16052 + type = AuIop_OTHER;
16056 + inode->i_op = iop + type;
16057 + /* unnecessary smp_wmb() */
16060 +int au_refresh_hinode_self(struct inode *inode)
16064 + err = au_ii_refresh(inode, &update);
16066 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16072 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16074 + int err, e, update;
16075 + unsigned int flags;
16077 + aufs_bindex_t bindex, bend;
16078 + unsigned char isdir;
16079 + struct au_hinode *p;
16080 + struct au_iinfo *iinfo;
16082 + err = au_ii_refresh(inode, &update);
16083 + if (unlikely(err))
16087 + iinfo = au_ii(inode);
16088 + p = iinfo->ii_hinode + iinfo->ii_bstart;
16089 + mode = (inode->i_mode & S_IFMT);
16090 + isdir = S_ISDIR(mode);
16091 + flags = au_hi_flags(inode, isdir);
16092 + bend = au_dbend(dentry);
16093 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
16094 + struct inode *h_i, *h_inode;
16095 + struct dentry *h_d;
16097 + h_d = au_h_dptr(dentry, bindex);
16098 + if (!h_d || d_is_negative(h_d))
16101 + h_inode = d_inode(h_d);
16102 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16103 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
16104 + h_i = au_h_iptr(inode, bindex);
16106 + if (h_i == h_inode)
16112 + if (bindex < iinfo->ii_bstart)
16113 + iinfo->ii_bstart = bindex;
16114 + if (iinfo->ii_bend < bindex)
16115 + iinfo->ii_bend = bindex;
16116 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16119 + au_update_ibrange(inode, /*do_put_zero*/0);
16120 + e = au_dy_irefresh(inode);
16121 + if (unlikely(e && !err))
16124 + au_refresh_hinode_attr(inode, update && isdir);
16131 +static int set_inode(struct inode *inode, struct dentry *dentry)
16134 + unsigned int flags;
16136 + aufs_bindex_t bindex, bstart, btail;
16137 + unsigned char isdir;
16138 + struct dentry *h_dentry;
16139 + struct inode *h_inode;
16140 + struct au_iinfo *iinfo;
16141 + struct inode_operations *iop;
16143 + IiMustWriteLock(inode);
16147 + iop = au_sbi(inode->i_sb)->si_iop_array;
16148 + bstart = au_dbstart(dentry);
16149 + h_dentry = au_h_dptr(dentry, bstart);
16150 + h_inode = d_inode(h_dentry);
16151 + mode = h_inode->i_mode;
16152 + switch (mode & S_IFMT) {
16154 + btail = au_dbtail(dentry);
16155 + inode->i_op = iop + AuIop_OTHER;
16156 + inode->i_fop = &aufs_file_fop;
16157 + err = au_dy_iaop(inode, bstart, h_inode);
16158 + if (unlikely(err))
16163 + btail = au_dbtaildir(dentry);
16164 + inode->i_op = iop + AuIop_DIR;
16165 + inode->i_fop = &aufs_dir_fop;
16168 + btail = au_dbtail(dentry);
16169 + inode->i_op = iop + AuIop_SYMLINK;
16175 + btail = au_dbtail(dentry);
16176 + inode->i_op = iop + AuIop_OTHER;
16177 + init_special_inode(inode, mode, h_inode->i_rdev);
16180 + AuIOErr("Unknown file type 0%o\n", mode);
16185 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16186 + flags = au_hi_flags(inode, isdir);
16187 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16188 + && au_ftest_hi(flags, HNOTIFY)
16189 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16190 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16191 + au_fclr_hi(flags, HNOTIFY);
16192 + iinfo = au_ii(inode);
16193 + iinfo->ii_bstart = bstart;
16194 + iinfo->ii_bend = btail;
16195 + for (bindex = bstart; bindex <= btail; bindex++) {
16196 + h_dentry = au_h_dptr(dentry, bindex);
16198 + au_set_h_iptr(inode, bindex,
16199 + au_igrab(d_inode(h_dentry)), flags);
16201 + au_cpup_attr_all(inode, /*force*/1);
16203 + * to force calling aufs_get_acl() every time,
16204 + * do not call cache_no_acl() for aufs inode.
16212 + * successful returns with iinfo write_locked
16214 + * zero: success, matched
16215 + * plus: no error, but unmatched
16217 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16220 + unsigned int gen, igflags;
16221 + aufs_bindex_t bindex, bend;
16222 + struct inode *h_inode, *h_dinode;
16223 + struct dentry *h_dentry;
16226 + * before this function, if aufs got any iinfo lock, it must be only
16227 + * one, the parent dir.
16228 + * it can happen by UDBA and the obsoleted inode number.
16231 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16235 + ii_write_lock_new_child(inode);
16236 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
16237 + h_dinode = d_inode(h_dentry);
16238 + bend = au_ibend(inode);
16239 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
16240 + h_inode = au_h_iptr(inode, bindex);
16241 + if (!h_inode || h_inode != h_dinode)
16245 + gen = au_iigen(inode, &igflags);
16246 + if (gen == au_digen(dentry)
16247 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16250 + /* fully refresh inode using dentry */
16251 + err = au_refresh_hinode(inode, dentry);
16253 + au_update_iigen(inode, /*half*/0);
16257 + if (unlikely(err))
16258 + ii_write_unlock(inode);
16263 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16264 + unsigned int d_type, ino_t *ino)
16267 + struct mutex *mtx;
16269 + /* prevent hardlinked inode number from race condition */
16271 + if (d_type != DT_DIR) {
16272 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16275 + err = au_xino_read(sb, bindex, h_ino, ino);
16276 + if (unlikely(err))
16281 + *ino = au_xino_new_ino(sb);
16282 + if (unlikely(!*ino))
16284 + err = au_xino_write(sb, bindex, h_ino, *ino);
16285 + if (unlikely(err))
16291 + mutex_unlock(mtx);
16295 +/* successful returns with iinfo write_locked */
16296 +/* todo: return with unlocked? */
16297 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16299 + struct inode *inode, *h_inode;
16300 + struct dentry *h_dentry;
16301 + struct super_block *sb;
16302 + struct mutex *mtx;
16303 + ino_t h_ino, ino;
16305 + aufs_bindex_t bstart;
16307 + sb = dentry->d_sb;
16308 + bstart = au_dbstart(dentry);
16309 + h_dentry = au_h_dptr(dentry, bstart);
16310 + h_inode = d_inode(h_dentry);
16311 + h_ino = h_inode->i_ino;
16314 + * stop 'race'-ing between hardlinks under different
16318 + if (!d_is_dir(h_dentry))
16319 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
16324 + err = au_xino_read(sb, bstart, h_ino, &ino);
16325 + inode = ERR_PTR(err);
16326 + if (unlikely(err))
16330 + ino = au_xino_new_ino(sb);
16331 + if (unlikely(!ino)) {
16332 + inode = ERR_PTR(-EIO);
16337 + AuDbg("i%lu\n", (unsigned long)ino);
16338 + inode = au_iget_locked(sb, ino);
16339 + err = PTR_ERR(inode);
16340 + if (IS_ERR(inode))
16343 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16344 + if (inode->i_state & I_NEW) {
16345 + /* verbose coding for lock class name */
16346 + if (unlikely(d_is_symlink(h_dentry)))
16347 + au_rw_class(&au_ii(inode)->ii_rwsem,
16348 + au_lc_key + AuLcSymlink_IIINFO);
16349 + else if (unlikely(d_is_dir(h_dentry)))
16350 + au_rw_class(&au_ii(inode)->ii_rwsem,
16351 + au_lc_key + AuLcDir_IIINFO);
16352 + else /* likely */
16353 + au_rw_class(&au_ii(inode)->ii_rwsem,
16354 + au_lc_key + AuLcNonDir_IIINFO);
16356 + ii_write_lock_new_child(inode);
16357 + err = set_inode(inode, dentry);
16359 + unlock_new_inode(inode);
16360 + goto out; /* success */
16364 + * iget_failed() calls iput(), but we need to call
16365 + * ii_write_unlock() after iget_failed(). so dirty hack for
16368 + atomic_inc(&inode->i_count);
16369 + iget_failed(inode);
16370 + ii_write_unlock(inode);
16371 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
16372 + /* ignore this error */
16374 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16376 + * horrible race condition between lookup, readdir and copyup
16377 + * (or something).
16380 + mutex_unlock(mtx);
16381 + err = reval_inode(inode, dentry);
16382 + if (unlikely(err < 0)) {
16389 + goto out; /* success */
16394 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16395 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16396 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16397 + bstart, au_sbtype(h_dentry->d_sb), dentry,
16398 + (unsigned long)h_ino, (unsigned long)ino);
16400 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
16404 + mutex_unlock(mtx);
16410 + inode = ERR_PTR(err);
16413 + mutex_unlock(mtx);
16417 +/* ---------------------------------------------------------------------- */
16419 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16420 + struct inode *inode)
16423 + struct inode *hi;
16425 + err = au_br_rdonly(au_sbr(sb, bindex));
16427 + /* pseudo-link after flushed may happen out of bounds */
16430 + && au_ibstart(inode) <= bindex
16431 + && bindex <= au_ibend(inode)) {
16433 + * permission check is unnecessary since vfsub routine
16434 + * will be called later
16436 + hi = au_h_iptr(inode, bindex);
16438 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16444 +int au_test_h_perm(struct inode *h_inode, int mask)
16446 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16448 + return inode_permission(h_inode, mask);
16451 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16453 + if (au_test_nfs(h_inode->i_sb)
16454 + && (mask & MAY_WRITE)
16455 + && S_ISDIR(h_inode->i_mode))
16456 + mask |= MAY_READ; /* force permission check */
16457 + return au_test_h_perm(h_inode, mask);
16459 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16460 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16461 +++ linux/fs/aufs/inode.h 2016-04-24 18:32:51.393686895 +0200
16464 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16466 + * This program, aufs is free software; you can redistribute it and/or modify
16467 + * it under the terms of the GNU General Public License as published by
16468 + * the Free Software Foundation; either version 2 of the License, or
16469 + * (at your option) any later version.
16471 + * This program is distributed in the hope that it will be useful,
16472 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16473 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16474 + * GNU General Public License for more details.
16476 + * You should have received a copy of the GNU General Public License
16477 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16481 + * inode operations
16484 +#ifndef __AUFS_INODE_H__
16485 +#define __AUFS_INODE_H__
16489 +#include <linux/fsnotify.h>
16490 +#include "rwsem.h"
16494 +struct au_hnotify {
16495 +#ifdef CONFIG_AUFS_HNOTIFY
16496 +#ifdef CONFIG_AUFS_HFSNOTIFY
16497 + /* never use fsnotify_add_vfsmount_mark() */
16498 + struct fsnotify_mark hn_mark;
16500 + struct inode *hn_aufs_inode; /* no get/put */
16502 +} ____cacheline_aligned_in_smp;
16504 +struct au_hinode {
16505 + struct inode *hi_inode;
16506 + aufs_bindex_t hi_id;
16507 +#ifdef CONFIG_AUFS_HNOTIFY
16508 + struct au_hnotify *hi_notify;
16511 + /* reference to the copied-up whiteout with get/put */
16512 + struct dentry *hi_whdentry;
16516 +#define AuIG_HALF_REFRESHED 1
16517 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16518 +#define au_ig_fset(flags, name) \
16519 + do { (flags) |= AuIG_##name; } while (0)
16520 +#define au_ig_fclr(flags, name) \
16521 + do { (flags) &= ~AuIG_##name; } while (0)
16524 + spinlock_t ig_spin;
16525 + __u32 ig_generation, ig_flags;
16530 + struct au_iigen ii_generation;
16531 + struct super_block *ii_hsb1; /* no get/put */
16533 + struct au_rwsem ii_rwsem;
16534 + aufs_bindex_t ii_bstart, ii_bend;
16536 + struct au_hinode *ii_hinode;
16537 + struct au_vdir *ii_vdir;
16540 +struct au_icntnr {
16541 + struct au_iinfo iinfo;
16542 + struct inode vfs_inode;
16543 +} ____cacheline_aligned_in_smp;
16545 +/* au_pin flags */
16546 +#define AuPin_DI_LOCKED 1
16547 +#define AuPin_MNT_WRITE (1 << 1)
16548 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16549 +#define au_fset_pin(flags, name) \
16550 + do { (flags) |= AuPin_##name; } while (0)
16551 +#define au_fclr_pin(flags, name) \
16552 + do { (flags) &= ~AuPin_##name; } while (0)
16556 + struct dentry *dentry;
16557 + unsigned int udba;
16558 + unsigned char lsc_di, lsc_hi, flags;
16559 + aufs_bindex_t bindex;
16562 + struct dentry *parent;
16563 + struct au_hinode *hdir;
16564 + struct vfsmount *h_mnt;
16566 + /* temporary unlock/relock for copyup */
16567 + struct dentry *h_dentry, *h_parent;
16568 + struct au_branch *br;
16569 + struct task_struct *task;
16572 +void au_pin_hdir_unlock(struct au_pin *p);
16573 +int au_pin_hdir_lock(struct au_pin *p);
16574 +int au_pin_hdir_relock(struct au_pin *p);
16575 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16576 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16577 +void au_pin_hdir_release(struct au_pin *p);
16579 +/* ---------------------------------------------------------------------- */
16581 +static inline struct au_iinfo *au_ii(struct inode *inode)
16583 + struct au_iinfo *iinfo;
16585 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16586 + if (iinfo->ii_hinode)
16588 + return NULL; /* debugging bad_inode case */
16591 +/* ---------------------------------------------------------------------- */
16594 +struct inode *au_igrab(struct inode *inode);
16595 +void au_refresh_iop(struct inode *inode, int force_getattr);
16596 +int au_refresh_hinode_self(struct inode *inode);
16597 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16598 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16599 + unsigned int d_type, ino_t *ino);
16600 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16601 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16602 + struct inode *inode);
16603 +int au_test_h_perm(struct inode *h_inode, int mask);
16604 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16606 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16607 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16609 +#ifdef CONFIG_AUFS_SHWH
16610 + return au_ino(sb, bindex, h_ino, d_type, ino);
16623 +extern struct inode_operations aufs_iop[AuIop_Last],
16624 + aufs_iop_nogetattr[AuIop_Last];
16626 +/* au_wr_dir flags */
16627 +#define AuWrDir_ADD_ENTRY 1
16628 +#define AuWrDir_ISDIR (1 << 1)
16629 +#define AuWrDir_TMPFILE (1 << 2)
16630 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16631 +#define au_fset_wrdir(flags, name) \
16632 + do { (flags) |= AuWrDir_##name; } while (0)
16633 +#define au_fclr_wrdir(flags, name) \
16634 + do { (flags) &= ~AuWrDir_##name; } while (0)
16636 +struct au_wr_dir_args {
16637 + aufs_bindex_t force_btgt;
16638 + unsigned char flags;
16640 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16641 + struct au_wr_dir_args *args);
16643 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16644 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16645 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16646 + unsigned int udba, unsigned char flags);
16647 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16648 + unsigned int udba, unsigned char flags) __must_check;
16649 +int au_do_pin(struct au_pin *pin) __must_check;
16650 +void au_unpin(struct au_pin *pin);
16651 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16653 +#define AuIcpup_DID_CPUP 1
16654 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16655 +#define au_fset_icpup(flags, name) \
16656 + do { (flags) |= AuIcpup_##name; } while (0)
16657 +#define au_fclr_icpup(flags, name) \
16658 + do { (flags) &= ~AuIcpup_##name; } while (0)
16660 +struct au_icpup_args {
16661 + unsigned char flags;
16662 + unsigned char pin_flags;
16663 + aufs_bindex_t btgt;
16664 + unsigned int udba;
16665 + struct au_pin pin;
16666 + struct path h_path;
16667 + struct inode *h_inode;
16670 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16671 + struct au_icpup_args *a);
16673 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16676 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16677 + struct dentry *h_parent, int isdir);
16678 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16680 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16681 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16683 +struct vfsub_aopen_args;
16684 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16685 + struct vfsub_aopen_args *args);
16686 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16687 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16688 + struct dentry *dentry);
16689 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16692 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16693 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16694 + struct dentry *h_parent, int isdir);
16695 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16696 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16699 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16700 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16701 + struct inode *dir, struct dentry *dentry);
16704 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16705 +void au_hiput(struct au_hinode *hinode);
16706 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16707 + struct dentry *h_wh);
16708 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16710 +/* hinode flags */
16711 +#define AuHi_XINO 1
16712 +#define AuHi_HNOTIFY (1 << 1)
16713 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16714 +#define au_fset_hi(flags, name) \
16715 + do { (flags) |= AuHi_##name; } while (0)
16716 +#define au_fclr_hi(flags, name) \
16717 + do { (flags) &= ~AuHi_##name; } while (0)
16719 +#ifndef CONFIG_AUFS_HNOTIFY
16720 +#undef AuHi_HNOTIFY
16721 +#define AuHi_HNOTIFY 0
16724 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16725 + struct inode *h_inode, unsigned int flags);
16727 +void au_update_iigen(struct inode *inode, int half);
16728 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16730 +void au_icntnr_init_once(void *_c);
16731 +int au_iinfo_init(struct inode *inode);
16732 +void au_iinfo_fin(struct inode *inode);
16733 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16735 +#ifdef CONFIG_PROC_FS
16737 +int au_plink_maint(struct super_block *sb, int flags);
16739 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16740 +int au_plink_maint_enter(struct super_block *sb);
16741 +#ifdef CONFIG_AUFS_DEBUG
16742 +void au_plink_list(struct super_block *sb);
16744 +AuStubVoid(au_plink_list, struct super_block *sb)
16746 +int au_plink_test(struct inode *inode);
16747 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16748 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16749 + struct dentry *h_dentry);
16750 +void au_plink_put(struct super_block *sb, int verbose);
16751 +void au_plink_clean(struct super_block *sb, int verbose);
16752 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16754 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16755 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16756 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16757 +AuStubVoid(au_plink_list, struct super_block *sb);
16758 +AuStubInt0(au_plink_test, struct inode *inode);
16759 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16760 + struct inode *inode, aufs_bindex_t bindex);
16761 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16762 + struct dentry *h_dentry);
16763 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16764 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16765 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16766 +#endif /* CONFIG_PROC_FS */
16768 +#ifdef CONFIG_AUFS_XATTR
16770 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16771 + unsigned int verbose);
16772 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16773 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
16775 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
16776 + size_t size, int flags);
16777 +int aufs_removexattr(struct dentry *dentry, const char *name);
16779 +/* void au_xattr_init(struct super_block *sb); */
16781 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16782 + int ignore_flags, unsigned int verbose);
16783 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16786 +#ifdef CONFIG_FS_POSIX_ACL
16787 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16788 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16791 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16798 +struct au_srxattr {
16802 + const char *name;
16803 + const void *value;
16808 + const char *name;
16811 + struct posix_acl *acl;
16816 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
16819 +/* ---------------------------------------------------------------------- */
16821 +/* lock subclass for iinfo */
16823 + AuLsc_II_CHILD, /* child first */
16824 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16825 + AuLsc_II_CHILD3, /* copyup dirs */
16826 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16827 + AuLsc_II_PARENT2,
16828 + AuLsc_II_PARENT3, /* copyup dirs */
16829 + AuLsc_II_NEW_CHILD
16833 + * ii_read_lock_child, ii_write_lock_child,
16834 + * ii_read_lock_child2, ii_write_lock_child2,
16835 + * ii_read_lock_child3, ii_write_lock_child3,
16836 + * ii_read_lock_parent, ii_write_lock_parent,
16837 + * ii_read_lock_parent2, ii_write_lock_parent2,
16838 + * ii_read_lock_parent3, ii_write_lock_parent3,
16839 + * ii_read_lock_new_child, ii_write_lock_new_child,
16841 +#define AuReadLockFunc(name, lsc) \
16842 +static inline void ii_read_lock_##name(struct inode *i) \
16844 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16847 +#define AuWriteLockFunc(name, lsc) \
16848 +static inline void ii_write_lock_##name(struct inode *i) \
16850 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16853 +#define AuRWLockFuncs(name, lsc) \
16854 + AuReadLockFunc(name, lsc) \
16855 + AuWriteLockFunc(name, lsc)
16857 +AuRWLockFuncs(child, CHILD);
16858 +AuRWLockFuncs(child2, CHILD2);
16859 +AuRWLockFuncs(child3, CHILD3);
16860 +AuRWLockFuncs(parent, PARENT);
16861 +AuRWLockFuncs(parent2, PARENT2);
16862 +AuRWLockFuncs(parent3, PARENT3);
16863 +AuRWLockFuncs(new_child, NEW_CHILD);
16865 +#undef AuReadLockFunc
16866 +#undef AuWriteLockFunc
16867 +#undef AuRWLockFuncs
16870 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16872 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16874 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16875 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16876 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16878 +/* ---------------------------------------------------------------------- */
16880 +static inline void au_icntnr_init(struct au_icntnr *c)
16882 +#ifdef CONFIG_AUFS_DEBUG
16883 + c->vfs_inode.i_mode = 0;
16887 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
16889 + unsigned int gen;
16890 + struct au_iinfo *iinfo;
16891 + struct au_iigen *iigen;
16893 + iinfo = au_ii(inode);
16894 + iigen = &iinfo->ii_generation;
16895 + spin_lock(&iigen->ig_spin);
16897 + *igflags = iigen->ig_flags;
16898 + gen = iigen->ig_generation;
16899 + spin_unlock(&iigen->ig_spin);
16904 +/* tiny test for inode number */
16905 +/* tmpfs generation is too rough */
16906 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16908 + struct au_iinfo *iinfo;
16910 + iinfo = au_ii(inode);
16911 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16912 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16913 + && iinfo->ii_higen == h_inode->i_generation);
16916 +static inline void au_iigen_dec(struct inode *inode)
16918 + struct au_iinfo *iinfo;
16919 + struct au_iigen *iigen;
16921 + iinfo = au_ii(inode);
16922 + iigen = &iinfo->ii_generation;
16923 + spin_lock(&iigen->ig_spin);
16924 + iigen->ig_generation--;
16925 + spin_unlock(&iigen->ig_spin);
16928 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16933 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16939 +/* ---------------------------------------------------------------------- */
16941 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16942 + aufs_bindex_t bindex)
16944 + IiMustAnyLock(inode);
16945 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16948 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16950 + IiMustAnyLock(inode);
16951 + return au_ii(inode)->ii_bstart;
16954 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16956 + IiMustAnyLock(inode);
16957 + return au_ii(inode)->ii_bend;
16960 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16962 + IiMustAnyLock(inode);
16963 + return au_ii(inode)->ii_vdir;
16966 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16968 + IiMustAnyLock(inode);
16969 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16972 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16974 + IiMustWriteLock(inode);
16975 + au_ii(inode)->ii_bstart = bindex;
16978 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16980 + IiMustWriteLock(inode);
16981 + au_ii(inode)->ii_bend = bindex;
16984 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16986 + IiMustWriteLock(inode);
16987 + au_ii(inode)->ii_vdir = vdir;
16990 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16992 + IiMustAnyLock(inode);
16993 + return au_ii(inode)->ii_hinode + bindex;
16996 +/* ---------------------------------------------------------------------- */
16998 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17001 + return pin->parent;
17005 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17007 + if (pin && pin->hdir)
17008 + return pin->hdir->hi_inode;
17012 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17015 + return pin->hdir;
17019 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17022 + pin->dentry = dentry;
17025 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17026 + unsigned char lflag)
17030 + au_fset_pin(pin->flags, DI_LOCKED);
17032 + au_fclr_pin(pin->flags, DI_LOCKED);
17036 +#if 0 /* reserved */
17037 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17040 + dput(pin->parent);
17041 + pin->parent = dget(parent);
17046 +/* ---------------------------------------------------------------------- */
17049 +#ifdef CONFIG_AUFS_HNOTIFY
17050 +struct au_hnotify_op {
17051 + void (*ctl)(struct au_hinode *hinode, int do_set);
17052 + int (*alloc)(struct au_hinode *hinode);
17055 + * if it returns true, the the caller should free hinode->hi_notify,
17056 + * otherwise ->free() frees it.
17058 + int (*free)(struct au_hinode *hinode,
17059 + struct au_hnotify *hn) __must_check;
17061 + void (*fin)(void);
17062 + int (*init)(void);
17064 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17065 + void (*fin_br)(struct au_branch *br);
17066 + int (*init_br)(struct au_branch *br, int perm);
17070 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17071 +void au_hn_free(struct au_hinode *hinode);
17072 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17073 +void au_hn_reset(struct inode *inode, unsigned int flags);
17074 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17075 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17076 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17077 +int au_hnotify_init_br(struct au_branch *br, int perm);
17078 +void au_hnotify_fin_br(struct au_branch *br);
17079 +int __init au_hnotify_init(void);
17080 +void au_hnotify_fin(void);
17083 +extern const struct au_hnotify_op au_hnotify_op;
17086 +void au_hn_init(struct au_hinode *hinode)
17088 + hinode->hi_notify = NULL;
17091 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17093 + return hinode->hi_notify;
17097 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17098 + struct au_hinode *hinode __maybe_unused,
17099 + struct inode *inode __maybe_unused)
17100 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17101 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17102 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17103 + int do_set __maybe_unused)
17104 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17105 + unsigned int flags __maybe_unused)
17106 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17107 + struct au_branch *br __maybe_unused,
17108 + int perm __maybe_unused)
17109 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17110 + int perm __maybe_unused)
17111 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17112 +AuStubInt0(__init au_hnotify_init, void)
17113 +AuStubVoid(au_hnotify_fin, void)
17114 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17115 +#endif /* CONFIG_AUFS_HNOTIFY */
17117 +static inline void au_hn_suspend(struct au_hinode *hdir)
17119 + au_hn_ctl(hdir, /*do_set*/0);
17122 +static inline void au_hn_resume(struct au_hinode *hdir)
17124 + au_hn_ctl(hdir, /*do_set*/1);
17127 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
17129 + inode_lock(hdir->hi_inode);
17130 + au_hn_suspend(hdir);
17133 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
17134 + unsigned int sc __maybe_unused)
17136 + inode_lock_nested(hdir->hi_inode, sc);
17137 + au_hn_suspend(hdir);
17140 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
17142 + au_hn_resume(hdir);
17143 + inode_unlock(hdir->hi_inode);
17146 +#endif /* __KERNEL__ */
17147 +#endif /* __AUFS_INODE_H__ */
17148 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17149 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17150 +++ linux/fs/aufs/ioctl.c 2016-04-24 18:32:51.393686895 +0200
17153 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17155 + * This program, aufs is free software; you can redistribute it and/or modify
17156 + * it under the terms of the GNU General Public License as published by
17157 + * the Free Software Foundation; either version 2 of the License, or
17158 + * (at your option) any later version.
17160 + * This program is distributed in the hope that it will be useful,
17161 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17162 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17163 + * GNU General Public License for more details.
17165 + * You should have received a copy of the GNU General Public License
17166 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17171 + * plink-management and readdir in userspace.
17172 + * assist the pathconf(3) wrapper library.
17174 + * File-based Hierarchical Storage Management.
17177 +#include <linux/compat.h>
17178 +#include <linux/file.h>
17181 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17184 + aufs_bindex_t wbi, bindex, bend;
17185 + struct file *h_file;
17186 + struct super_block *sb;
17187 + struct dentry *root;
17188 + struct au_branch *br;
17189 + struct aufs_wbr_fd wbrfd = {
17190 + .oflags = au_dir_roflags,
17193 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17194 + | O_NOATIME | O_CLOEXEC;
17196 + AuDebugOn(wbrfd.oflags & ~valid);
17199 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17200 + if (unlikely(err)) {
17206 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17207 + wbrfd.oflags |= au_dir_roflags;
17208 + AuDbg("0%o\n", wbrfd.oflags);
17209 + if (unlikely(wbrfd.oflags & ~valid))
17213 + fd = get_unused_fd_flags(0);
17215 + if (unlikely(fd < 0))
17218 + h_file = ERR_PTR(-EINVAL);
17221 + sb = path->dentry->d_sb;
17222 + root = sb->s_root;
17223 + aufs_read_lock(root, AuLock_IR);
17224 + bend = au_sbend(sb);
17225 + if (wbrfd.brid >= 0) {
17226 + wbi = au_br_index(sb, wbrfd.brid);
17227 + if (unlikely(wbi < 0 || wbi > bend))
17231 + h_file = ERR_PTR(-ENOENT);
17232 + br = au_sbr(sb, wbi);
17233 + if (!au_br_writable(br->br_perm)) {
17237 + bindex = wbi + 1;
17239 + for (; bindex <= bend; bindex++) {
17240 + br = au_sbr(sb, bindex);
17241 + if (au_br_writable(br->br_perm)) {
17243 + br = au_sbr(sb, wbi);
17248 + AuDbg("wbi %d\n", wbi);
17250 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17254 + aufs_read_unlock(root, AuLock_IR);
17255 + err = PTR_ERR(h_file);
17256 + if (IS_ERR(h_file))
17259 + atomic_dec(&br->br_count); /* cf. au_h_open() */
17260 + fd_install(fd, h_file);
17262 + goto out; /* success */
17265 + put_unused_fd(fd);
17271 +/* ---------------------------------------------------------------------- */
17273 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17276 + struct dentry *dentry;
17279 + case AUFS_CTL_RDU:
17280 + case AUFS_CTL_RDU_INO:
17281 + err = au_rdu_ioctl(file, cmd, arg);
17284 + case AUFS_CTL_WBR_FD:
17285 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17288 + case AUFS_CTL_IBUSY:
17289 + err = au_ibusy_ioctl(file, arg);
17292 + case AUFS_CTL_BRINFO:
17293 + err = au_brinfo_ioctl(file, arg);
17296 + case AUFS_CTL_FHSM_FD:
17297 + dentry = file->f_path.dentry;
17298 + if (IS_ROOT(dentry))
17299 + err = au_fhsm_fd(dentry->d_sb, arg);
17305 + /* do not call the lower */
17306 + AuDbg("0x%x\n", cmd);
17314 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17319 + case AUFS_CTL_MVDOWN:
17320 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17323 + case AUFS_CTL_WBR_FD:
17324 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17328 + /* do not call the lower */
17329 + AuDbg("0x%x\n", cmd);
17337 +#ifdef CONFIG_COMPAT
17338 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17339 + unsigned long arg)
17344 + case AUFS_CTL_RDU:
17345 + case AUFS_CTL_RDU_INO:
17346 + err = au_rdu_compat_ioctl(file, cmd, arg);
17349 + case AUFS_CTL_IBUSY:
17350 + err = au_ibusy_compat_ioctl(file, arg);
17353 + case AUFS_CTL_BRINFO:
17354 + err = au_brinfo_compat_ioctl(file, arg);
17358 + err = aufs_ioctl_dir(file, cmd, arg);
17365 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17366 + unsigned long arg)
17368 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17371 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17372 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17373 +++ linux/fs/aufs/i_op_add.c 2016-04-24 18:32:51.393686895 +0200
17376 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17378 + * This program, aufs is free software; you can redistribute it and/or modify
17379 + * it under the terms of the GNU General Public License as published by
17380 + * the Free Software Foundation; either version 2 of the License, or
17381 + * (at your option) any later version.
17383 + * This program is distributed in the hope that it will be useful,
17384 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17385 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17386 + * GNU General Public License for more details.
17388 + * You should have received a copy of the GNU General Public License
17389 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17393 + * inode operations (add entry)
17399 + * final procedure of adding a new entry, except link(2).
17400 + * remove whiteout, instantiate, copyup the parent dir's times and size
17401 + * and update version.
17402 + * if it failed, re-create the removed whiteout.
17404 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17405 + struct dentry *wh_dentry, struct dentry *dentry)
17408 + aufs_bindex_t bwh;
17409 + struct path h_path;
17410 + struct super_block *sb;
17411 + struct inode *inode, *h_dir;
17412 + struct dentry *wh;
17417 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17418 + IMustLock(h_dir);
17419 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17420 + bwh = au_dbwh(dentry);
17421 + h_path.dentry = wh_dentry;
17422 + h_path.mnt = au_sbr_mnt(sb, bindex);
17423 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17425 + if (unlikely(err))
17429 + inode = au_new_inode(dentry, /*must_new*/1);
17430 + if (!IS_ERR(inode)) {
17431 + d_instantiate(dentry, inode);
17432 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17434 + au_dir_ts(dir, bindex);
17435 + dir->i_version++;
17436 + au_fhsm_wrote(sb, bindex, /*force*/0);
17437 + return 0; /* success */
17440 + err = PTR_ERR(inode);
17445 + /* dir inode is locked */
17446 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17447 + rerr = PTR_ERR(wh);
17448 + if (IS_ERR(wh)) {
17449 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17450 + dentry, err, rerr);
17459 +static int au_d_may_add(struct dentry *dentry)
17464 + if (unlikely(d_unhashed(dentry)))
17466 + if (unlikely(d_really_is_positive(dentry)))
17472 + * simple tests for the adding inode operations.
17473 + * following the checks in vfs, plus the parent-child relationship.
17475 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17476 + struct dentry *h_parent, int isdir)
17480 + struct dentry *h_dentry;
17481 + struct inode *h_inode;
17483 + err = -ENAMETOOLONG;
17484 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17487 + h_dentry = au_h_dptr(dentry, bindex);
17488 + if (d_really_is_negative(dentry)) {
17490 + if (unlikely(d_is_positive(h_dentry)))
17493 + /* rename(2) case */
17495 + if (unlikely(d_is_negative(h_dentry)))
17497 + h_inode = d_inode(h_dentry);
17498 + if (unlikely(!h_inode->i_nlink))
17501 + h_mode = h_inode->i_mode;
17504 + if (unlikely(S_ISDIR(h_mode)))
17506 + } else if (unlikely(!S_ISDIR(h_mode))) {
17513 + /* expected parent dir is locked */
17514 + if (unlikely(h_parent != h_dentry->d_parent))
17523 + * initial procedure of adding a new entry.
17524 + * prepare writable branch and the parent dir, lock it,
17525 + * and lookup whiteout for the new entry.
17527 +static struct dentry*
17528 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17529 + struct dentry *src_dentry, struct au_pin *pin,
17530 + struct au_wr_dir_args *wr_dir_args)
17532 + struct dentry *wh_dentry, *h_parent;
17533 + struct super_block *sb;
17534 + struct au_branch *br;
17536 + unsigned int udba;
17537 + aufs_bindex_t bcpup;
17539 + AuDbg("%pd\n", dentry);
17541 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17543 + wh_dentry = ERR_PTR(err);
17544 + if (unlikely(err < 0))
17547 + sb = dentry->d_sb;
17548 + udba = au_opt_udba(sb);
17549 + err = au_pin(pin, dentry, bcpup, udba,
17550 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17551 + wh_dentry = ERR_PTR(err);
17552 + if (unlikely(err))
17555 + h_parent = au_pinned_h_parent(pin);
17556 + if (udba != AuOpt_UDBA_NONE
17557 + && au_dbstart(dentry) == bcpup)
17558 + err = au_may_add(dentry, bcpup, h_parent,
17559 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17560 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17561 + err = -ENAMETOOLONG;
17562 + wh_dentry = ERR_PTR(err);
17563 + if (unlikely(err))
17566 + br = au_sbr(sb, bcpup);
17568 + struct path tmp = {
17569 + .dentry = h_parent,
17570 + .mnt = au_br_mnt(br)
17572 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17575 + wh_dentry = NULL;
17576 + if (bcpup != au_dbwh(dentry))
17577 + goto out; /* success */
17580 + * ENAMETOOLONG here means that if we allowed create such name, then it
17581 + * would not be able to removed in the future. So we don't allow such
17582 + * name here and we don't handle ENAMETOOLONG differently here.
17584 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17587 + if (IS_ERR(wh_dentry))
17590 + return wh_dentry;
17593 +/* ---------------------------------------------------------------------- */
17595 +enum { Mknod, Symlink, Creat };
17596 +struct simple_arg {
17603 + struct vfsub_aopen_args *aopen;
17606 + const char *symname;
17615 +static int add_simple(struct inode *dir, struct dentry *dentry,
17616 + struct simple_arg *arg)
17619 + aufs_bindex_t bstart;
17620 + unsigned char created;
17621 + const unsigned char try_aopen
17622 + = (arg->type == Creat && arg->u.c.try_aopen);
17623 + struct dentry *wh_dentry, *parent;
17624 + struct inode *h_dir;
17625 + struct super_block *sb;
17626 + struct au_branch *br;
17627 + /* to reuduce stack size */
17629 + struct au_dtime dt;
17630 + struct au_pin pin;
17631 + struct path h_path;
17632 + struct au_wr_dir_args wr_dir_args;
17635 + AuDbg("%pd\n", dentry);
17639 + a = kmalloc(sizeof(*a), GFP_NOFS);
17640 + if (unlikely(!a))
17642 + a->wr_dir_args.force_btgt = -1;
17643 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17645 + parent = dentry->d_parent; /* dir inode is locked */
17646 + if (!try_aopen) {
17647 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17648 + if (unlikely(err))
17651 + err = au_d_may_add(dentry);
17652 + if (unlikely(err))
17655 + di_write_lock_parent(parent);
17656 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17657 + &a->pin, &a->wr_dir_args);
17658 + err = PTR_ERR(wh_dentry);
17659 + if (IS_ERR(wh_dentry))
17662 + bstart = au_dbstart(dentry);
17663 + sb = dentry->d_sb;
17664 + br = au_sbr(sb, bstart);
17665 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17666 + a->h_path.mnt = au_br_mnt(br);
17667 + h_dir = au_pinned_h_dir(&a->pin);
17668 + switch (arg->type) {
17671 + if (!try_aopen || !h_dir->i_op->atomic_open)
17672 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17673 + arg->u.c.want_excl);
17675 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17676 + arg->u.c.aopen, br);
17679 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17682 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17690 + err = epilog(dir, bstart, wh_dentry, dentry);
17693 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
17694 + /* no delegation since it is just created */
17695 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17698 + AuIOErr("%pd revert failure(%d, %d)\n",
17699 + dentry, err, rerr);
17702 + au_dtime_revert(&a->dt);
17705 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17706 + *arg->u.c.aopen->opened |= FILE_CREATED;
17708 + au_unpin(&a->pin);
17713 + di_write_unlock(parent);
17715 + if (unlikely(err)) {
17716 + au_update_dbstart(dentry);
17720 + aufs_read_unlock(dentry, AuLock_DW);
17727 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17730 + struct simple_arg arg = {
17737 + return add_simple(dir, dentry, &arg);
17740 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17742 + struct simple_arg arg = {
17744 + .u.s.symname = symname
17746 + return add_simple(dir, dentry, &arg);
17749 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17752 + struct simple_arg arg = {
17756 + .want_excl = want_excl
17759 + return add_simple(dir, dentry, &arg);
17762 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17763 + struct vfsub_aopen_args *aopen_args)
17765 + struct simple_arg arg = {
17768 + .mode = aopen_args->create_mode,
17769 + .want_excl = aopen_args->open_flag & O_EXCL,
17770 + .try_aopen = true,
17771 + .aopen = aopen_args
17774 + return add_simple(dir, dentry, &arg);
17777 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17780 + aufs_bindex_t bindex;
17781 + struct super_block *sb;
17782 + struct dentry *parent, *h_parent, *h_dentry;
17783 + struct inode *h_dir, *inode;
17784 + struct vfsmount *h_mnt;
17785 + struct au_wr_dir_args wr_dir_args = {
17786 + .force_btgt = -1,
17787 + .flags = AuWrDir_TMPFILE
17790 + /* copy-up may happen */
17794 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17795 + if (unlikely(err))
17798 + err = au_di_init(dentry);
17799 + if (unlikely(err))
17803 + parent = d_find_any_alias(dir);
17804 + AuDebugOn(!parent);
17805 + di_write_lock_parent(parent);
17806 + if (unlikely(d_inode(parent) != dir))
17809 + err = au_digen_test(parent, au_sigen(sb));
17810 + if (unlikely(err))
17813 + bindex = au_dbstart(parent);
17814 + au_set_dbstart(dentry, bindex);
17815 + au_set_dbend(dentry, bindex);
17816 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17818 + if (unlikely(err < 0))
17821 + err = -EOPNOTSUPP;
17822 + h_dir = au_h_iptr(dir, bindex);
17823 + if (unlikely(!h_dir->i_op->tmpfile))
17826 + h_mnt = au_sbr_mnt(sb, bindex);
17827 + err = vfsub_mnt_want_write(h_mnt);
17828 + if (unlikely(err))
17831 + h_parent = au_h_dptr(parent, bindex);
17832 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
17833 + if (unlikely(err))
17837 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17838 + if (unlikely(!h_dentry))
17841 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17842 + if (unlikely(err))
17845 + au_set_dbstart(dentry, bindex);
17846 + au_set_dbend(dentry, bindex);
17847 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17848 + inode = au_new_inode(dentry, /*must_new*/1);
17849 + if (IS_ERR(inode)) {
17850 + err = PTR_ERR(inode);
17851 + au_set_h_dptr(dentry, bindex, NULL);
17852 + au_set_dbstart(dentry, -1);
17853 + au_set_dbend(dentry, -1);
17855 + if (!inode->i_nlink)
17856 + set_nlink(inode, 1);
17857 + d_tmpfile(dentry, inode);
17858 + au_di(dentry)->di_tmpfile = 1;
17860 + /* update without i_mutex */
17861 + if (au_ibstart(dir) == au_dbstart(dentry))
17862 + au_cpup_attr_timesizes(dir);
17868 + vfsub_mnt_drop_write(h_mnt);
17870 + di_write_unlock(parent);
17872 + di_write_unlock(dentry);
17875 + /* verbose coding for lock class name */
17876 + au_rw_class(&au_di(dentry)->di_rwsem,
17877 + au_lc_key + AuLcNonDir_DIINFO);
17882 + au_di_fin(dentry);
17883 + dentry->d_fsdata = NULL;
17886 + si_read_unlock(sb);
17888 + inode_unlock(dir);
17892 +/* ---------------------------------------------------------------------- */
17894 +struct au_link_args {
17895 + aufs_bindex_t bdst, bsrc;
17896 + struct au_pin pin;
17897 + struct path h_path;
17898 + struct dentry *src_parent, *parent;
17901 +static int au_cpup_before_link(struct dentry *src_dentry,
17902 + struct au_link_args *a)
17905 + struct dentry *h_src_dentry;
17906 + struct au_cp_generic cpg = {
17907 + .dentry = src_dentry,
17912 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17915 + di_read_lock_parent(a->src_parent, AuLock_IR);
17916 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17917 + if (unlikely(err))
17920 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17921 + err = au_pin(&a->pin, src_dentry, a->bdst,
17922 + au_opt_udba(src_dentry->d_sb),
17923 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17924 + if (unlikely(err))
17927 + err = au_sio_cpup_simple(&cpg);
17928 + au_unpin(&a->pin);
17931 + di_read_unlock(a->src_parent, AuLock_IR);
17935 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17936 + struct au_link_args *a)
17939 + unsigned char plink;
17940 + aufs_bindex_t bend;
17941 + struct dentry *h_src_dentry;
17942 + struct inode *h_inode, *inode, *delegated;
17943 + struct super_block *sb;
17944 + struct file *h_file;
17948 + sb = src_dentry->d_sb;
17949 + inode = d_inode(src_dentry);
17950 + if (au_ibstart(inode) <= a->bdst)
17951 + h_inode = au_h_iptr(inode, a->bdst);
17952 + if (!h_inode || !h_inode->i_nlink) {
17953 + /* copyup src_dentry as the name of dentry. */
17954 + bend = au_dbend(dentry);
17955 + if (bend < a->bsrc)
17956 + au_set_dbend(dentry, a->bsrc);
17957 + au_set_h_dptr(dentry, a->bsrc,
17958 + dget(au_h_dptr(src_dentry, a->bsrc)));
17959 + dget(a->h_path.dentry);
17960 + au_set_h_dptr(dentry, a->bdst, NULL);
17961 + AuDbg("temporary d_inode...\n");
17962 + spin_lock(&dentry->d_lock);
17963 + dentry->d_inode = d_inode(src_dentry); /* tmp */
17964 + spin_unlock(&dentry->d_lock);
17965 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17966 + if (IS_ERR(h_file))
17967 + err = PTR_ERR(h_file);
17969 + struct au_cp_generic cpg = {
17970 + .dentry = dentry,
17975 + .flags = AuCpup_KEEPLINO
17977 + err = au_sio_cpup_simple(&cpg);
17978 + au_h_open_post(dentry, a->bsrc, h_file);
17980 + dput(a->h_path.dentry);
17981 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17983 + au_set_h_dptr(dentry, a->bdst,
17984 + a->h_path.dentry);
17986 + spin_lock(&dentry->d_lock);
17987 + dentry->d_inode = NULL; /* restore */
17988 + spin_unlock(&dentry->d_lock);
17989 + AuDbg("temporary d_inode...done\n");
17990 + au_set_h_dptr(dentry, a->bsrc, NULL);
17991 + au_set_dbend(dentry, bend);
17993 + /* the inode of src_dentry already exists on a.bdst branch */
17994 + h_src_dentry = d_find_alias(h_inode);
17995 + if (!h_src_dentry && au_plink_test(inode)) {
17997 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17998 + err = PTR_ERR(h_src_dentry);
17999 + if (IS_ERR(h_src_dentry))
18002 + if (unlikely(d_is_negative(h_src_dentry))) {
18003 + dput(h_src_dentry);
18004 + h_src_dentry = NULL;
18008 + if (h_src_dentry) {
18009 + delegated = NULL;
18010 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18011 + &a->h_path, &delegated);
18012 + if (unlikely(err == -EWOULDBLOCK)) {
18013 + pr_warn("cannot retry for NFSv4 delegation"
18014 + " for an internal link\n");
18017 + dput(h_src_dentry);
18019 + AuIOErr("no dentry found for hi%lu on b%d\n",
18020 + h_inode->i_ino, a->bdst);
18025 + if (!err && !plink)
18026 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18033 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18034 + struct dentry *dentry)
18037 + struct au_dtime dt;
18038 + struct au_link_args *a;
18039 + struct dentry *wh_dentry, *h_src_dentry;
18040 + struct inode *inode, *delegated;
18041 + struct super_block *sb;
18042 + struct au_wr_dir_args wr_dir_args = {
18043 + /* .force_btgt = -1, */
18044 + .flags = AuWrDir_ADD_ENTRY
18048 + inode = d_inode(src_dentry);
18049 + IMustLock(inode);
18052 + a = kzalloc(sizeof(*a), GFP_NOFS);
18053 + if (unlikely(!a))
18056 + a->parent = dentry->d_parent; /* dir inode is locked */
18057 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18058 + AuLock_NOPLM | AuLock_GEN);
18059 + if (unlikely(err))
18061 + err = au_d_linkable(src_dentry);
18062 + if (unlikely(err))
18064 + err = au_d_may_add(dentry);
18065 + if (unlikely(err))
18068 + a->src_parent = dget_parent(src_dentry);
18069 + wr_dir_args.force_btgt = au_ibstart(inode);
18071 + di_write_lock_parent(a->parent);
18072 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18073 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18075 + err = PTR_ERR(wh_dentry);
18076 + if (IS_ERR(wh_dentry))
18080 + sb = dentry->d_sb;
18081 + a->bdst = au_dbstart(dentry);
18082 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18083 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18084 + a->bsrc = au_ibstart(inode);
18085 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18086 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18087 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18088 + if (!h_src_dentry) {
18089 + a->bsrc = au_dbstart(src_dentry);
18090 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18091 + AuDebugOn(!h_src_dentry);
18092 + } else if (IS_ERR(h_src_dentry)) {
18093 + err = PTR_ERR(h_src_dentry);
18097 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18098 + if (a->bdst < a->bsrc
18099 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18100 + err = au_cpup_or_link(src_dentry, dentry, a);
18102 + delegated = NULL;
18103 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18104 + &a->h_path, &delegated);
18105 + if (unlikely(err == -EWOULDBLOCK)) {
18106 + pr_warn("cannot retry for NFSv4 delegation"
18107 + " for an internal link\n");
18111 + dput(h_src_dentry);
18114 + * copyup src_dentry to the branch we process,
18115 + * and then link(2) to it.
18117 + dput(h_src_dentry);
18118 + if (a->bdst < a->bsrc
18119 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18120 + au_unpin(&a->pin);
18121 + di_write_unlock(a->parent);
18122 + err = au_cpup_before_link(src_dentry, a);
18123 + di_write_lock_parent(a->parent);
18125 + err = au_pin(&a->pin, dentry, a->bdst,
18127 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18128 + if (unlikely(err))
18132 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18134 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18135 + delegated = NULL;
18136 + err = vfsub_link(h_src_dentry,
18137 + au_pinned_h_dir(&a->pin),
18138 + &a->h_path, &delegated);
18139 + if (unlikely(err == -EWOULDBLOCK)) {
18140 + pr_warn("cannot retry"
18141 + " for NFSv4 delegation"
18142 + " for an internal link\n");
18148 + if (unlikely(err))
18152 + a->h_path.dentry = wh_dentry;
18153 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18155 + if (unlikely(err))
18159 + au_dir_ts(dir, a->bdst);
18160 + dir->i_version++;
18161 + inc_nlink(inode);
18162 + inode->i_ctime = dir->i_ctime;
18163 + d_instantiate(dentry, au_igrab(inode));
18164 + if (d_unhashed(a->h_path.dentry))
18165 + /* some filesystem calls d_drop() */
18167 + /* some filesystems consume an inode even hardlink */
18168 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18169 + goto out_unpin; /* success */
18172 + /* no delegation since it is just created */
18173 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18174 + /*delegated*/NULL, /*force*/0);
18175 + if (unlikely(rerr)) {
18176 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18179 + au_dtime_revert(&dt);
18181 + au_unpin(&a->pin);
18185 + di_write_unlock(a->parent);
18186 + dput(a->src_parent);
18188 + if (unlikely(err)) {
18189 + au_update_dbstart(dentry);
18192 + aufs_read_and_write_unlock2(dentry, src_dentry);
18200 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18203 + aufs_bindex_t bindex;
18204 + unsigned char diropq;
18205 + struct path h_path;
18206 + struct dentry *wh_dentry, *parent, *opq_dentry;
18207 + struct inode *h_inode;
18208 + struct super_block *sb;
18210 + struct au_pin pin;
18211 + struct au_dtime dt;
18212 + } *a; /* reduce the stack usage */
18213 + struct au_wr_dir_args wr_dir_args = {
18214 + .force_btgt = -1,
18215 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18221 + a = kmalloc(sizeof(*a), GFP_NOFS);
18222 + if (unlikely(!a))
18225 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18226 + if (unlikely(err))
18228 + err = au_d_may_add(dentry);
18229 + if (unlikely(err))
18232 + parent = dentry->d_parent; /* dir inode is locked */
18233 + di_write_lock_parent(parent);
18234 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18235 + &a->pin, &wr_dir_args);
18236 + err = PTR_ERR(wh_dentry);
18237 + if (IS_ERR(wh_dentry))
18240 + sb = dentry->d_sb;
18241 + bindex = au_dbstart(dentry);
18242 + h_path.dentry = au_h_dptr(dentry, bindex);
18243 + h_path.mnt = au_sbr_mnt(sb, bindex);
18244 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18245 + if (unlikely(err))
18248 + /* make the dir opaque */
18250 + h_inode = d_inode(h_path.dentry);
18252 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18253 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18254 + opq_dentry = au_diropq_create(dentry, bindex);
18255 + inode_unlock(h_inode);
18256 + err = PTR_ERR(opq_dentry);
18257 + if (IS_ERR(opq_dentry))
18259 + dput(opq_dentry);
18263 + err = epilog(dir, bindex, wh_dentry, dentry);
18266 + goto out_unpin; /* success */
18271 + AuLabel(revert opq);
18272 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18273 + rerr = au_diropq_remove(dentry, bindex);
18274 + inode_unlock(h_inode);
18276 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18277 + dentry, err, rerr);
18283 + AuLabel(revert dir);
18284 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18286 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18287 + dentry, err, rerr);
18290 + au_dtime_revert(&a->dt);
18292 + au_unpin(&a->pin);
18295 + di_write_unlock(parent);
18297 + if (unlikely(err)) {
18298 + au_update_dbstart(dentry);
18301 + aufs_read_unlock(dentry, AuLock_DW);
18307 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18308 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18309 +++ linux/fs/aufs/i_op.c 2016-04-24 18:32:51.393686895 +0200
18312 + * Copyright (C) 2005-2016 Junjiro R. Okajima
18314 + * This program, aufs is free software; you can redistribute it and/or modify
18315 + * it under the terms of the GNU General Public License as published by
18316 + * the Free Software Foundation; either version 2 of the License, or
18317 + * (at your option) any later version.
18319 + * This program is distributed in the hope that it will be useful,
18320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18322 + * GNU General Public License for more details.
18324 + * You should have received a copy of the GNU General Public License
18325 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18329 + * inode operations (except add/del/rename)
18332 +#include <linux/device_cgroup.h>
18333 +#include <linux/fs_stack.h>
18334 +#include <linux/namei.h>
18335 +#include <linux/security.h>
18338 +static int h_permission(struct inode *h_inode, int mask,
18339 + struct path *h_path, int brperm)
18342 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18345 + if ((write_mask && IS_IMMUTABLE(h_inode))
18346 + || ((mask & MAY_EXEC)
18347 + && S_ISREG(h_inode->i_mode)
18348 + && (path_noexec(h_path)
18349 + || !(h_inode->i_mode & S_IXUGO))))
18353 + * - skip the lower fs test in the case of write to ro branch.
18354 + * - nfs dir permission write check is optimized, but a policy for
18355 + * link/rename requires a real check.
18356 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18357 + * in this case, generic_permission() returns -EOPNOTSUPP.
18359 + if ((write_mask && !au_br_writable(brperm))
18360 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18361 + && write_mask && !(mask & MAY_READ))
18362 + || !h_inode->i_op->permission) {
18363 + /* AuLabel(generic_permission); */
18364 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18365 + err = generic_permission(h_inode, mask);
18366 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18367 + err = h_inode->i_op->permission(h_inode, mask);
18370 + /* AuLabel(h_inode->permission); */
18371 + err = h_inode->i_op->permission(h_inode, mask);
18376 + err = devcgroup_inode_permission(h_inode, mask);
18378 + err = security_inode_permission(h_inode, mask);
18382 + /* todo: do we need to call ima_path_check()? */
18383 + struct path h_path = {
18387 + err = ima_path_check(&h_path,
18388 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18389 + IMA_COUNT_LEAVE);
18397 +static int aufs_permission(struct inode *inode, int mask)
18400 + aufs_bindex_t bindex, bend;
18401 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18402 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18403 + struct inode *h_inode;
18404 + struct super_block *sb;
18405 + struct au_branch *br;
18407 + /* todo: support rcu-walk? */
18408 + if (mask & MAY_NOT_BLOCK)
18411 + sb = inode->i_sb;
18412 + si_read_lock(sb, AuLock_FLUSH);
18413 + ii_read_lock_child(inode);
18415 + err = au_iigen_test(inode, au_sigen(sb));
18416 + if (unlikely(err))
18422 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18423 + err = au_busy_or_stale();
18424 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18425 + if (unlikely(!h_inode
18426 + || (h_inode->i_mode & S_IFMT)
18427 + != (inode->i_mode & S_IFMT)))
18431 + bindex = au_ibstart(inode);
18432 + br = au_sbr(sb, bindex);
18433 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18436 + && !special_file(h_inode->i_mode)) {
18437 + /* test whether the upper writable branch exists */
18439 + for (; bindex >= 0; bindex--)
18440 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18448 + /* non-write to dir */
18450 + bend = au_ibend(inode);
18451 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
18452 + h_inode = au_h_iptr(inode, bindex);
18454 + err = au_busy_or_stale();
18455 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18458 + br = au_sbr(sb, bindex);
18459 + err = h_permission(h_inode, mask, &br->br_path,
18465 + ii_read_unlock(inode);
18466 + si_read_unlock(sb);
18470 +/* ---------------------------------------------------------------------- */
18472 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18473 + unsigned int flags)
18475 + struct dentry *ret, *parent;
18476 + struct inode *inode;
18477 + struct super_block *sb;
18478 + int err, npositive;
18482 + /* todo: support rcu-walk? */
18483 + ret = ERR_PTR(-ECHILD);
18484 + if (flags & LOOKUP_RCU)
18487 + ret = ERR_PTR(-ENAMETOOLONG);
18488 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18492 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18493 + ret = ERR_PTR(err);
18494 + if (unlikely(err))
18497 + err = au_di_init(dentry);
18498 + ret = ERR_PTR(err);
18499 + if (unlikely(err))
18503 + npositive = 0; /* suppress a warning */
18504 + parent = dentry->d_parent; /* dir inode is locked */
18505 + di_read_lock_parent(parent, AuLock_IR);
18506 + err = au_alive_dir(parent);
18508 + err = au_digen_test(parent, au_sigen(sb));
18510 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
18514 + di_read_unlock(parent, AuLock_IR);
18515 + ret = ERR_PTR(err);
18516 + if (unlikely(err < 0))
18520 + inode = au_new_inode(dentry, /*must_new*/0);
18521 + if (IS_ERR(inode)) {
18522 + ret = (void *)inode;
18529 + atomic_inc(&inode->i_count);
18530 + ret = d_splice_alias(inode, dentry);
18532 + if (unlikely(d_need_lookup(dentry))) {
18533 + spin_lock(&dentry->d_lock);
18534 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18535 + spin_unlock(&dentry->d_lock);
18539 + if (!IS_ERR(ret)) {
18541 + if (ret && ret != dentry)
18542 + ii_write_unlock(inode);
18544 + ii_write_unlock(inode);
18551 + di_write_unlock(dentry);
18553 + /* verbose coding for lock class name */
18554 + if (unlikely(S_ISLNK(inode->i_mode)))
18555 + au_rw_class(&au_di(dentry)->di_rwsem,
18556 + au_lc_key + AuLcSymlink_DIINFO);
18557 + else if (unlikely(S_ISDIR(inode->i_mode)))
18558 + au_rw_class(&au_di(dentry)->di_rwsem,
18559 + au_lc_key + AuLcDir_DIINFO);
18560 + else /* likely */
18561 + au_rw_class(&au_di(dentry)->di_rwsem,
18562 + au_lc_key + AuLcNonDir_DIINFO);
18565 + si_read_unlock(sb);
18570 +/* ---------------------------------------------------------------------- */
18572 +struct aopen_node {
18573 + struct hlist_node hlist;
18574 + struct file *file, *h_file;
18577 +static int au_do_aopen(struct inode *inode, struct file *file)
18579 + struct au_sphlhead *aopen;
18580 + struct aopen_node *node;
18581 + struct au_do_open_args args = {
18583 + .open = au_do_open_nondir
18586 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18587 + spin_lock(&aopen->spin);
18588 + hlist_for_each_entry(node, &aopen->head, hlist)
18589 + if (node->file == file) {
18590 + args.h_file = node->h_file;
18593 + spin_unlock(&aopen->spin);
18594 + /* AuDebugOn(!args.h_file); */
18596 + return au_do_open(file, &args);
18599 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18600 + struct file *file, unsigned int open_flag,
18601 + umode_t create_mode, int *opened)
18603 + int err, h_opened = *opened;
18604 + struct dentry *parent;
18605 + struct dentry *d;
18606 + struct au_sphlhead *aopen;
18607 + struct vfsub_aopen_args args = {
18608 + .open_flag = open_flag,
18609 + .create_mode = create_mode,
18610 + .opened = &h_opened
18612 + struct aopen_node aopen_node = {
18617 + AuDbg("open_flag 0x%x\n", open_flag);
18618 + AuDbgDentry(dentry);
18621 + if (!au_di(dentry)) {
18622 + d = aufs_lookup(dir, dentry, /*flags*/0);
18624 + err = PTR_ERR(d);
18628 + * obsoleted dentry found.
18629 + * another error will be returned later.
18635 + AuDbgDentry(dentry);
18638 + if (d_is_positive(dentry)
18639 + || d_unhashed(dentry)
18640 + || d_unlinked(dentry)
18641 + || !(open_flag & O_CREAT))
18642 + goto out_no_open;
18644 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18645 + if (unlikely(err))
18648 + parent = dentry->d_parent; /* dir is locked */
18649 + di_write_lock_parent(parent);
18650 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
18651 + if (unlikely(err))
18654 + AuDbgDentry(dentry);
18655 + if (d_is_positive(dentry))
18658 + args.file = get_empty_filp();
18659 + err = PTR_ERR(args.file);
18660 + if (IS_ERR(args.file))
18663 + args.file->f_flags = file->f_flags;
18664 + err = au_aopen_or_create(dir, dentry, &args);
18666 + AuDbgFile(args.file);
18667 + if (unlikely(err < 0)) {
18668 + if (h_opened & FILE_OPENED)
18671 + put_filp(args.file);
18675 + /* some filesystems don't set FILE_CREATED while succeeded? */
18676 + *opened |= FILE_CREATED;
18677 + if (h_opened & FILE_OPENED)
18678 + aopen_node.h_file = args.file;
18680 + put_filp(args.file);
18681 + args.file = NULL;
18683 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18684 + au_sphl_add(&aopen_node.hlist, aopen);
18685 + err = finish_open(file, dentry, au_do_aopen, opened);
18686 + au_sphl_del(&aopen_node.hlist, aopen);
18689 + if (aopen_node.h_file)
18690 + fput(aopen_node.h_file);
18693 + di_write_unlock(parent);
18694 + aufs_read_unlock(dentry, AuLock_DW);
18695 + AuDbgDentry(dentry);
18696 + if (unlikely(err))
18699 + if (!err && !(*opened & FILE_CREATED)) {
18700 + AuLabel(out_no_open);
18702 + err = finish_no_open(file, dentry);
18705 + AuDbg("%pd%s%s\n", dentry,
18706 + (*opened & FILE_CREATED) ? " created" : "",
18707 + (*opened & FILE_OPENED) ? " opened" : "");
18713 +/* ---------------------------------------------------------------------- */
18715 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18716 + const unsigned char add_entry, aufs_bindex_t bcpup,
18717 + aufs_bindex_t bstart)
18720 + struct dentry *h_parent;
18721 + struct inode *h_dir;
18724 + IMustLock(d_inode(parent));
18726 + di_write_lock_parent(parent);
18729 + if (!au_h_dptr(parent, bcpup)) {
18730 + if (bstart > bcpup)
18731 + err = au_cpup_dirs(dentry, bcpup);
18732 + else if (bstart < bcpup)
18733 + err = au_cpdown_dirs(dentry, bcpup);
18737 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18738 + h_parent = au_h_dptr(parent, bcpup);
18739 + h_dir = d_inode(h_parent);
18740 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
18741 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18742 + /* todo: no unlock here */
18743 + inode_unlock(h_dir);
18745 + AuDbg("bcpup %d\n", bcpup);
18747 + if (d_really_is_negative(dentry))
18748 + au_set_h_dptr(dentry, bstart, NULL);
18749 + au_update_dbrange(dentry, /*do_put_zero*/0);
18754 + di_write_unlock(parent);
18756 + err = bcpup; /* success */
18763 + * decide the branch and the parent dir where we will create a new entry.
18764 + * returns new bindex or an error.
18765 + * copyup the parent dir if needed.
18767 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18768 + struct au_wr_dir_args *args)
18771 + unsigned int flags;
18772 + aufs_bindex_t bcpup, bstart, src_bstart;
18773 + const unsigned char add_entry
18774 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18775 + | au_ftest_wrdir(args->flags, TMPFILE);
18776 + struct super_block *sb;
18777 + struct dentry *parent;
18778 + struct au_sbinfo *sbinfo;
18780 + sb = dentry->d_sb;
18781 + sbinfo = au_sbi(sb);
18782 + parent = dget_parent(dentry);
18783 + bstart = au_dbstart(dentry);
18785 + if (args->force_btgt < 0) {
18786 + if (src_dentry) {
18787 + src_bstart = au_dbstart(src_dentry);
18788 + if (src_bstart < bstart)
18789 + bcpup = src_bstart;
18790 + } else if (add_entry) {
18792 + if (au_ftest_wrdir(args->flags, ISDIR))
18793 + au_fset_wbr(flags, DIR);
18794 + err = AuWbrCreate(sbinfo, dentry, flags);
18798 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
18800 + err = AuWbrCopyup(sbinfo, dentry);
18802 + if (!IS_ROOT(dentry)) {
18803 + di_read_lock_parent(parent, !AuLock_IR);
18804 + err = AuWbrCopyup(sbinfo, dentry);
18805 + di_read_unlock(parent, !AuLock_IR);
18807 + err = AuWbrCopyup(sbinfo, dentry);
18810 + if (unlikely(err < 0))
18814 + bcpup = args->force_btgt;
18815 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
18818 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18820 + if (bcpup == bstart)
18821 + goto out; /* success */
18823 + /* copyup the new parent into the branch we process */
18824 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18826 + if (d_really_is_negative(dentry)) {
18827 + au_set_h_dptr(dentry, bstart, NULL);
18828 + au_set_dbstart(dentry, bcpup);
18829 + au_set_dbend(dentry, bcpup);
18831 + AuDebugOn(add_entry
18832 + && !au_ftest_wrdir(args->flags, TMPFILE)
18833 + && !au_h_dptr(dentry, bcpup));
18841 +/* ---------------------------------------------------------------------- */
18843 +void au_pin_hdir_unlock(struct au_pin *p)
18846 + au_hn_imtx_unlock(p->hdir);
18849 +int au_pin_hdir_lock(struct au_pin *p)
18857 + /* even if an error happens later, keep this lock */
18858 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18861 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
18866 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18867 + p->h_parent, p->br);
18873 +int au_pin_hdir_relock(struct au_pin *p)
18876 + struct inode *h_i;
18877 + struct dentry *h_d[] = {
18882 + err = au_pin_hdir_lock(p);
18883 + if (unlikely(err))
18886 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18889 + if (d_is_positive(h_d[i])) {
18890 + h_i = d_inode(h_d[i]);
18891 + err = !h_i->i_nlink;
18899 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18901 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18902 + p->hdir->hi_inode->i_mutex.owner = task;
18906 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18909 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18910 + p->lsc_hi, 0, NULL, _RET_IP_);
18911 + au_pin_hdir_set_owner(p, current);
18915 +void au_pin_hdir_release(struct au_pin *p)
18918 + au_pin_hdir_set_owner(p, p->task);
18919 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18923 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18925 + if (pin && pin->parent)
18926 + return au_h_dptr(pin->parent, pin->bindex);
18930 +void au_unpin(struct au_pin *p)
18933 + au_pin_hdir_unlock(p);
18934 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18935 + vfsub_mnt_drop_write(p->h_mnt);
18939 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18940 + di_read_unlock(p->parent, AuLock_IR);
18941 + iput(p->hdir->hi_inode);
18943 + p->parent = NULL;
18946 + /* do not clear p->task */
18949 +int au_do_pin(struct au_pin *p)
18952 + struct super_block *sb;
18953 + struct inode *h_dir;
18956 + sb = p->dentry->d_sb;
18957 + p->br = au_sbr(sb, p->bindex);
18958 + if (IS_ROOT(p->dentry)) {
18959 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18960 + p->h_mnt = au_br_mnt(p->br);
18961 + err = vfsub_mnt_want_write(p->h_mnt);
18962 + if (unlikely(err)) {
18963 + au_fclr_pin(p->flags, MNT_WRITE);
18970 + p->h_dentry = NULL;
18971 + if (p->bindex <= au_dbend(p->dentry))
18972 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18974 + p->parent = dget_parent(p->dentry);
18975 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18976 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18979 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18980 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
18982 + h_dir = p->hdir->hi_inode;
18986 + * if DI_LOCKED is not set, then p->parent may be different
18987 + * and h_parent can be NULL.
18989 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18991 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18992 + di_read_unlock(p->parent, AuLock_IR);
18994 + p->parent = NULL;
18998 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18999 + p->h_mnt = au_br_mnt(p->br);
19000 + err = vfsub_mnt_want_write(p->h_mnt);
19001 + if (unlikely(err)) {
19002 + au_fclr_pin(p->flags, MNT_WRITE);
19003 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19004 + di_read_unlock(p->parent, AuLock_IR);
19006 + p->parent = NULL;
19012 + err = au_pin_hdir_lock(p);
19014 + goto out; /* success */
19019 + pr_err("err %d\n", err);
19020 + err = au_busy_or_stale();
19025 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19026 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19027 + unsigned int udba, unsigned char flags)
19029 + p->dentry = dentry;
19031 + p->lsc_di = lsc_di;
19032 + p->lsc_hi = lsc_hi;
19033 + p->flags = flags;
19034 + p->bindex = bindex;
19036 + p->parent = NULL;
19040 + p->h_dentry = NULL;
19041 + p->h_parent = NULL;
19043 + p->task = current;
19046 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19047 + unsigned int udba, unsigned char flags)
19049 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19051 + return au_do_pin(pin);
19054 +/* ---------------------------------------------------------------------- */
19057 + * ->setattr() and ->getattr() are called in various cases.
19058 + * chmod, stat: dentry is revalidated.
19059 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19061 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19063 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19064 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19067 + struct dentry *parent;
19070 + if (au_digen_test(dentry, sigen)) {
19071 + parent = dget_parent(dentry);
19072 + di_read_lock_parent(parent, AuLock_IR);
19073 + err = au_refresh_dentry(dentry, parent);
19074 + di_read_unlock(parent, AuLock_IR);
19082 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19083 + struct au_icpup_args *a)
19087 + aufs_bindex_t bstart, ibstart;
19088 + struct dentry *hi_wh, *parent;
19089 + struct inode *inode;
19090 + struct au_wr_dir_args wr_dir_args = {
19091 + .force_btgt = -1,
19095 + if (d_is_dir(dentry))
19096 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19097 + /* plink or hi_wh() case */
19098 + bstart = au_dbstart(dentry);
19099 + inode = d_inode(dentry);
19100 + ibstart = au_ibstart(inode);
19101 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
19102 + wr_dir_args.force_btgt = ibstart;
19103 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19104 + if (unlikely(err < 0))
19107 + if (err != bstart)
19108 + au_fset_icpup(a->flags, DID_CPUP);
19111 + a->pin_flags = AuPin_MNT_WRITE;
19113 + if (!IS_ROOT(dentry)) {
19114 + au_fset_pin(a->pin_flags, DI_LOCKED);
19115 + parent = dget_parent(dentry);
19116 + di_write_lock_parent(parent);
19119 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19120 + if (unlikely(err))
19123 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19125 + a->h_inode = d_inode(a->h_path.dentry);
19126 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19127 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19128 + if (ia->ia_size < i_size_read(a->h_inode))
19129 + sz = ia->ia_size;
19130 + inode_unlock(a->h_inode);
19134 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19135 + hi_wh = au_hi_wh(inode, a->btgt);
19137 + struct au_cp_generic cpg = {
19138 + .dentry = dentry,
19144 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19145 + if (unlikely(err))
19147 + hi_wh = au_hi_wh(inode, a->btgt);
19148 + /* todo: revalidate hi_wh? */
19153 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19154 + di_downgrade_lock(parent, AuLock_IR);
19158 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19159 + goto out; /* success */
19161 + if (!d_unhashed(dentry)) {
19162 + struct au_cp_generic cpg = {
19163 + .dentry = dentry,
19168 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19170 + err = au_sio_cpup_simple(&cpg);
19172 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19173 + } else if (!hi_wh)
19174 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19176 + a->h_path.dentry = hi_wh; /* do not dget here */
19179 + a->h_inode = d_inode(a->h_path.dentry);
19181 + goto out; /* success */
19182 + au_unpin(&a->pin);
19185 + di_write_unlock(parent);
19190 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19194 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19197 + struct inode *inode, *delegated;
19198 + struct super_block *sb;
19199 + struct file *file;
19200 + struct au_icpup_args *a;
19202 + inode = d_inode(dentry);
19203 + IMustLock(inode);
19206 + a = kzalloc(sizeof(*a), GFP_NOFS);
19207 + if (unlikely(!a))
19210 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19211 + ia->ia_valid &= ~ATTR_MODE;
19214 + sb = dentry->d_sb;
19215 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19216 + if (unlikely(err))
19219 + if (ia->ia_valid & ATTR_FILE) {
19220 + /* currently ftruncate(2) only */
19221 + AuDebugOn(!d_is_reg(dentry));
19222 + file = ia->ia_file;
19223 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
19224 + if (unlikely(err))
19226 + ia->ia_file = au_hf_top(file);
19227 + a->udba = AuOpt_UDBA_NONE;
19229 + /* fchmod() doesn't pass ia_file */
19230 + a->udba = au_opt_udba(sb);
19231 + di_write_lock_child(dentry);
19232 + /* no d_unlinked(), to set UDBA_NONE for root */
19233 + if (d_unhashed(dentry))
19234 + a->udba = AuOpt_UDBA_NONE;
19235 + if (a->udba != AuOpt_UDBA_NONE) {
19236 + AuDebugOn(IS_ROOT(dentry));
19237 + err = au_reval_for_attr(dentry, au_sigen(sb));
19238 + if (unlikely(err))
19243 + err = au_pin_and_icpup(dentry, ia, a);
19244 + if (unlikely(err < 0))
19246 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19247 + ia->ia_file = NULL;
19248 + ia->ia_valid &= ~ATTR_FILE;
19251 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19252 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19253 + == (ATTR_MODE | ATTR_CTIME)) {
19254 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19255 + if (unlikely(err))
19257 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19258 + && (ia->ia_valid & ATTR_CTIME)) {
19259 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19260 + if (unlikely(err))
19264 + if (ia->ia_valid & ATTR_SIZE) {
19267 + if (ia->ia_size < i_size_read(inode))
19269 + truncate_setsize(inode, ia->ia_size);
19272 + if (ia->ia_valid & ATTR_FILE)
19274 + inode_unlock(a->h_inode);
19275 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19276 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19278 + delegated = NULL;
19280 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19282 + err = break_deleg_wait(&delegated);
19290 + * regardless aufs 'acl' option setting.
19291 + * why don't all acl-aware fs call this func from their ->setattr()?
19293 + if (!err && (ia->ia_valid & ATTR_MODE))
19294 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19296 + au_cpup_attr_changeable(inode);
19299 + inode_unlock(a->h_inode);
19300 + au_unpin(&a->pin);
19301 + if (unlikely(err))
19302 + au_update_dbstart(dentry);
19304 + di_write_unlock(dentry);
19306 + fi_write_unlock(file);
19307 + ia->ia_file = file;
19308 + ia->ia_valid |= ATTR_FILE;
19311 + si_read_unlock(sb);
19319 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19320 +static int au_h_path_to_set_attr(struct dentry *dentry,
19321 + struct au_icpup_args *a, struct path *h_path)
19324 + struct super_block *sb;
19326 + sb = dentry->d_sb;
19327 + a->udba = au_opt_udba(sb);
19328 + /* no d_unlinked(), to set UDBA_NONE for root */
19329 + if (d_unhashed(dentry))
19330 + a->udba = AuOpt_UDBA_NONE;
19331 + if (a->udba != AuOpt_UDBA_NONE) {
19332 + AuDebugOn(IS_ROOT(dentry));
19333 + err = au_reval_for_attr(dentry, au_sigen(sb));
19334 + if (unlikely(err))
19337 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19338 + if (unlikely(err < 0))
19341 + h_path->dentry = a->h_path.dentry;
19342 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19348 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
19351 + struct path h_path;
19352 + struct super_block *sb;
19353 + struct au_icpup_args *a;
19354 + struct inode *inode, *h_inode;
19356 + inode = d_inode(dentry);
19357 + IMustLock(inode);
19360 + a = kzalloc(sizeof(*a), GFP_NOFS);
19361 + if (unlikely(!a))
19364 + sb = dentry->d_sb;
19365 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19366 + if (unlikely(err))
19369 + h_path.dentry = NULL; /* silence gcc */
19370 + di_write_lock_child(dentry);
19371 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19372 + if (unlikely(err))
19375 + inode_unlock(a->h_inode);
19376 + switch (arg->type) {
19377 + case AU_XATTR_SET:
19378 + err = vfsub_setxattr(h_path.dentry,
19379 + arg->u.set.name, arg->u.set.value,
19380 + arg->u.set.size, arg->u.set.flags);
19382 + case AU_XATTR_REMOVE:
19383 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
19386 + err = -EOPNOTSUPP;
19387 + h_inode = d_inode(h_path.dentry);
19388 + if (h_inode->i_op->set_acl)
19389 + err = h_inode->i_op->set_acl(h_inode,
19390 + arg->u.acl_set.acl,
19391 + arg->u.acl_set.type);
19395 + au_cpup_attr_timesizes(inode);
19397 + au_unpin(&a->pin);
19398 + if (unlikely(err))
19399 + au_update_dbstart(dentry);
19402 + di_write_unlock(dentry);
19403 + si_read_unlock(sb);
19412 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19413 + unsigned int nlink)
19417 + inode->i_mode = st->mode;
19418 + /* don't i_[ug]id_write() here */
19419 + inode->i_uid = st->uid;
19420 + inode->i_gid = st->gid;
19421 + inode->i_atime = st->atime;
19422 + inode->i_mtime = st->mtime;
19423 + inode->i_ctime = st->ctime;
19425 + au_cpup_attr_nlink(inode, /*force*/0);
19426 + if (S_ISDIR(inode->i_mode)) {
19427 + n = inode->i_nlink;
19430 + smp_mb(); /* for i_nlink */
19431 + /* 0 can happen */
19432 + set_nlink(inode, n);
19435 + spin_lock(&inode->i_lock);
19436 + inode->i_blocks = st->blocks;
19437 + i_size_write(inode, st->size);
19438 + spin_unlock(&inode->i_lock);
19442 + * common routine for aufs_getattr() and aufs_getxattr().
19443 + * returns zero or negative (an error).
19444 + * @dentry will be read-locked in success.
19446 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19449 + unsigned int mnt_flags, sigen;
19450 + unsigned char udba_none;
19451 + aufs_bindex_t bindex;
19452 + struct super_block *sb, *h_sb;
19453 + struct inode *inode;
19455 + h_path->mnt = NULL;
19456 + h_path->dentry = NULL;
19459 + sb = dentry->d_sb;
19460 + mnt_flags = au_mntflags(sb);
19461 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19463 + /* support fstat(2) */
19464 + if (!d_unlinked(dentry) && !udba_none) {
19465 + sigen = au_sigen(sb);
19466 + err = au_digen_test(dentry, sigen);
19468 + di_read_lock_child(dentry, AuLock_IR);
19469 + err = au_dbrange_test(dentry);
19470 + if (unlikely(err)) {
19471 + di_read_unlock(dentry, AuLock_IR);
19475 + AuDebugOn(IS_ROOT(dentry));
19476 + di_write_lock_child(dentry);
19477 + err = au_dbrange_test(dentry);
19479 + err = au_reval_for_attr(dentry, sigen);
19481 + di_downgrade_lock(dentry, AuLock_IR);
19483 + di_write_unlock(dentry);
19488 + di_read_lock_child(dentry, AuLock_IR);
19490 + inode = d_inode(dentry);
19491 + bindex = au_ibstart(inode);
19492 + h_path->mnt = au_sbr_mnt(sb, bindex);
19493 + h_sb = h_path->mnt->mnt_sb;
19495 + && !au_test_fs_bad_iattr(h_sb)
19497 + goto out; /* success */
19499 + if (au_dbstart(dentry) == bindex)
19500 + h_path->dentry = au_h_dptr(dentry, bindex);
19501 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19502 + h_path->dentry = au_plink_lkup(inode, bindex);
19503 + if (IS_ERR(h_path->dentry))
19504 + /* pretending success */
19505 + h_path->dentry = NULL;
19507 + dput(h_path->dentry);
19514 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19515 + struct dentry *dentry, struct kstat *st)
19518 + unsigned char positive;
19519 + struct path h_path;
19520 + struct inode *inode;
19521 + struct super_block *sb;
19523 + inode = d_inode(dentry);
19524 + sb = dentry->d_sb;
19525 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19526 + if (unlikely(err))
19528 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19529 + if (unlikely(err))
19531 + if (unlikely(!h_path.dentry))
19532 + /* illegally overlapped or something */
19533 + goto out_fill; /* pretending success */
19535 + positive = d_is_positive(h_path.dentry);
19537 + err = vfs_getattr(&h_path, st);
19540 + au_refresh_iattr(inode, st,
19541 + d_inode(h_path.dentry)->i_nlink);
19542 + goto out_fill; /* success */
19548 + generic_fillattr(inode, st);
19550 + di_read_unlock(dentry, AuLock_IR);
19552 + si_read_unlock(sb);
19558 +/* ---------------------------------------------------------------------- */
19560 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19561 + struct delayed_call *done)
19564 + struct dentry *h_dentry;
19565 + struct inode *h_inode;
19567 + aufs_bindex_t bindex;
19569 + ret = NULL; /* suppress a warning */
19574 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19575 + if (unlikely(err))
19578 + err = au_d_hashed_positive(dentry);
19579 + if (unlikely(err))
19583 + inode = d_inode(dentry);
19584 + bindex = au_ibstart(inode);
19585 + h_inode = au_h_iptr(inode, bindex);
19586 + if (unlikely(!h_inode->i_op->get_link))
19591 + if (au_dbstart(dentry) <= bindex) {
19592 + h_dentry = au_h_dptr(dentry, bindex);
19597 + h_dentry = d_find_any_alias(h_inode);
19598 + if (IS_ERR(h_dentry)) {
19599 + err = PTR_ERR(h_dentry);
19603 + if (unlikely(!h_dentry))
19607 + AuDbg("%pf\n", h_inode->i_op->get_link);
19608 + AuDbgDentry(h_dentry);
19609 + ret = h_inode->i_op->get_link(h_dentry, h_inode, done);
19612 + err = PTR_ERR(ret);
19615 + aufs_read_unlock(dentry, AuLock_IR);
19617 + if (unlikely(err))
19618 + ret = ERR_PTR(err);
19619 + AuTraceErrPtr(ret);
19623 +/* ---------------------------------------------------------------------- */
19625 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19628 + struct super_block *sb;
19629 + struct inode *h_inode;
19631 + sb = inode->i_sb;
19632 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19634 + si_read_lock(sb, AuLock_FLUSH);
19635 + ii_write_lock_child(inode);
19637 + h_inode = au_h_iptr(inode, au_ibstart(inode));
19638 + err = vfsub_update_time(h_inode, ts, flags);
19641 + au_cpup_attr_timesizes(inode);
19642 + ii_write_unlock(inode);
19643 + si_read_unlock(sb);
19646 + if (!err && (flags & S_VERSION))
19647 + inode_inc_iversion(inode);
19652 +/* ---------------------------------------------------------------------- */
19654 +/* no getattr version will be set by module.c:aufs_init() */
19655 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
19657 + [AuIop_SYMLINK] = {
19658 + .permission = aufs_permission,
19659 +#ifdef CONFIG_FS_POSIX_ACL
19660 + .get_acl = aufs_get_acl,
19661 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19664 + .setattr = aufs_setattr,
19665 + .getattr = aufs_getattr,
19667 +#ifdef CONFIG_AUFS_XATTR
19668 + .setxattr = aufs_setxattr,
19669 + .getxattr = aufs_getxattr,
19670 + .listxattr = aufs_listxattr,
19671 + .removexattr = aufs_removexattr,
19674 + .readlink = generic_readlink,
19675 + .get_link = aufs_get_link,
19677 + /* .update_time = aufs_update_time */
19680 + .create = aufs_create,
19681 + .lookup = aufs_lookup,
19682 + .link = aufs_link,
19683 + .unlink = aufs_unlink,
19684 + .symlink = aufs_symlink,
19685 + .mkdir = aufs_mkdir,
19686 + .rmdir = aufs_rmdir,
19687 + .mknod = aufs_mknod,
19688 + .rename = aufs_rename,
19690 + .permission = aufs_permission,
19691 +#ifdef CONFIG_FS_POSIX_ACL
19692 + .get_acl = aufs_get_acl,
19693 + .set_acl = aufs_set_acl,
19696 + .setattr = aufs_setattr,
19697 + .getattr = aufs_getattr,
19699 +#ifdef CONFIG_AUFS_XATTR
19700 + .setxattr = aufs_setxattr,
19701 + .getxattr = aufs_getxattr,
19702 + .listxattr = aufs_listxattr,
19703 + .removexattr = aufs_removexattr,
19706 + .update_time = aufs_update_time,
19707 + .atomic_open = aufs_atomic_open,
19708 + .tmpfile = aufs_tmpfile
19710 + [AuIop_OTHER] = {
19711 + .permission = aufs_permission,
19712 +#ifdef CONFIG_FS_POSIX_ACL
19713 + .get_acl = aufs_get_acl,
19714 + .set_acl = aufs_set_acl,
19717 + .setattr = aufs_setattr,
19718 + .getattr = aufs_getattr,
19720 +#ifdef CONFIG_AUFS_XATTR
19721 + .setxattr = aufs_setxattr,
19722 + .getxattr = aufs_getxattr,
19723 + .listxattr = aufs_listxattr,
19724 + .removexattr = aufs_removexattr,
19727 + .update_time = aufs_update_time
19730 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19731 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19732 +++ linux/fs/aufs/i_op_del.c 2016-04-24 18:32:51.393686895 +0200
19735 + * Copyright (C) 2005-2016 Junjiro R. Okajima
19737 + * This program, aufs is free software; you can redistribute it and/or modify
19738 + * it under the terms of the GNU General Public License as published by
19739 + * the Free Software Foundation; either version 2 of the License, or
19740 + * (at your option) any later version.
19742 + * This program is distributed in the hope that it will be useful,
19743 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19745 + * GNU General Public License for more details.
19747 + * You should have received a copy of the GNU General Public License
19748 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19752 + * inode operations (del entry)
19758 + * decide if a new whiteout for @dentry is necessary or not.
19759 + * when it is necessary, prepare the parent dir for the upper branch whose
19760 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19761 + * be done by caller.
19763 + * 0: wh is unnecessary
19764 + * plus: wh is necessary
19767 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19769 + int need_wh, err;
19770 + aufs_bindex_t bstart;
19771 + struct super_block *sb;
19773 + sb = dentry->d_sb;
19774 + bstart = au_dbstart(dentry);
19775 + if (*bcpup < 0) {
19777 + if (au_test_ro(sb, bstart, d_inode(dentry))) {
19778 + err = AuWbrCopyup(au_sbi(sb), dentry);
19780 + if (unlikely(err < 0))
19784 + AuDebugOn(bstart < *bcpup
19785 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
19786 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19788 + if (*bcpup != bstart) {
19789 + err = au_cpup_dirs(dentry, *bcpup);
19790 + if (unlikely(err))
19794 + struct au_dinfo *dinfo, *tmp;
19796 + need_wh = -ENOMEM;
19797 + dinfo = au_di(dentry);
19798 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19800 + au_di_cp(tmp, dinfo);
19801 + au_di_swap(tmp, dinfo);
19802 + /* returns the number of positive dentries */
19803 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19804 + au_di_swap(tmp, dinfo);
19805 + au_rw_write_unlock(&tmp->di_rwsem);
19809 + AuDbg("need_wh %d\n", need_wh);
19817 + * simple tests for the del-entry operations.
19818 + * following the checks in vfs, plus the parent-child relationship.
19820 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19821 + struct dentry *h_parent, int isdir)
19825 + struct dentry *h_dentry, *h_latest;
19826 + struct inode *h_inode;
19828 + h_dentry = au_h_dptr(dentry, bindex);
19829 + if (d_really_is_positive(dentry)) {
19831 + if (unlikely(d_is_negative(h_dentry)))
19833 + h_inode = d_inode(h_dentry);
19834 + if (unlikely(!h_inode->i_nlink))
19837 + h_mode = h_inode->i_mode;
19840 + if (unlikely(S_ISDIR(h_mode)))
19842 + } else if (unlikely(!S_ISDIR(h_mode))) {
19847 + /* rename(2) case */
19849 + if (unlikely(d_is_positive(h_dentry)))
19854 + /* expected parent dir is locked */
19855 + if (unlikely(h_parent != h_dentry->d_parent))
19860 + * rmdir a dir may break the consistency on some filesystem.
19861 + * let's try heavy test.
19864 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19865 + && au_test_h_perm(d_inode(h_parent),
19866 + MAY_EXEC | MAY_WRITE)))
19869 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19871 + if (IS_ERR(h_latest))
19873 + if (h_latest == h_dentry)
19882 + * decide the branch where we operate for @dentry. the branch index will be set
19883 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19884 + * dir for reverting.
19885 + * when a new whiteout is necessary, create it.
19887 +static struct dentry*
19888 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19889 + struct au_dtime *dt, struct au_pin *pin)
19891 + struct dentry *wh_dentry;
19892 + struct super_block *sb;
19893 + struct path h_path;
19894 + int err, need_wh;
19895 + unsigned int udba;
19896 + aufs_bindex_t bcpup;
19898 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19899 + wh_dentry = ERR_PTR(need_wh);
19900 + if (unlikely(need_wh < 0))
19903 + sb = dentry->d_sb;
19904 + udba = au_opt_udba(sb);
19906 + err = au_pin(pin, dentry, bcpup, udba,
19907 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19908 + wh_dentry = ERR_PTR(err);
19909 + if (unlikely(err))
19912 + h_path.dentry = au_pinned_h_parent(pin);
19913 + if (udba != AuOpt_UDBA_NONE
19914 + && au_dbstart(dentry) == bcpup) {
19915 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19916 + wh_dentry = ERR_PTR(err);
19917 + if (unlikely(err))
19921 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19922 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19923 + wh_dentry = NULL;
19925 + goto out; /* success, no need to create whiteout */
19927 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19928 + if (IS_ERR(wh_dentry))
19931 + /* returns with the parent is locked and wh_dentry is dget-ed */
19932 + goto out; /* success */
19937 + return wh_dentry;
19941 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19942 + * in order to be revertible and save time for removing many child whiteouts
19944 + * returns 1 when there are too many child whiteout and caller should remove
19945 + * them asynchronously. returns 0 when the number of children is enough small to
19946 + * remove now or the branch fs is a remote fs.
19947 + * otherwise return an error.
19949 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19950 + struct au_nhash *whlist, struct inode *dir)
19952 + int rmdir_later, err, dirwh;
19953 + struct dentry *h_dentry;
19954 + struct super_block *sb;
19955 + struct inode *inode;
19957 + sb = dentry->d_sb;
19958 + SiMustAnyLock(sb);
19959 + h_dentry = au_h_dptr(dentry, bindex);
19960 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19961 + if (unlikely(err))
19964 + /* stop monitoring */
19965 + inode = d_inode(dentry);
19966 + au_hn_free(au_hi(inode, bindex));
19968 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19969 + dirwh = au_sbi(sb)->si_dirwh;
19970 + rmdir_later = (dirwh <= 1);
19971 + if (!rmdir_later)
19972 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19975 + return rmdir_later;
19978 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19979 + if (unlikely(err)) {
19980 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19981 + h_dentry, bindex, err);
19991 + * final procedure for deleting a entry.
19992 + * maintain dentry and iattr.
19994 +static void epilog(struct inode *dir, struct dentry *dentry,
19995 + aufs_bindex_t bindex)
19997 + struct inode *inode;
19999 + inode = d_inode(dentry);
20001 + inode->i_ctime = dir->i_ctime;
20003 + au_dir_ts(dir, bindex);
20004 + dir->i_version++;
20008 + * when an error happened, remove the created whiteout and revert everything.
20010 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20011 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20012 + struct dentry *dentry, struct au_dtime *dt)
20015 + struct path h_path = {
20016 + .dentry = wh_dentry,
20017 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20020 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20022 + au_set_dbwh(dentry, bwh);
20023 + au_dtime_revert(dt);
20027 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20031 +/* ---------------------------------------------------------------------- */
20033 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20036 + aufs_bindex_t bwh, bindex, bstart;
20037 + struct inode *inode, *h_dir, *delegated;
20038 + struct dentry *parent, *wh_dentry;
20039 + /* to reuduce stack size */
20041 + struct au_dtime dt;
20042 + struct au_pin pin;
20043 + struct path h_path;
20049 + a = kmalloc(sizeof(*a), GFP_NOFS);
20050 + if (unlikely(!a))
20053 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20054 + if (unlikely(err))
20056 + err = au_d_hashed_positive(dentry);
20057 + if (unlikely(err))
20059 + inode = d_inode(dentry);
20060 + IMustLock(inode);
20062 + if (unlikely(d_is_dir(dentry)))
20063 + goto out_unlock; /* possible? */
20065 + bstart = au_dbstart(dentry);
20066 + bwh = au_dbwh(dentry);
20068 + parent = dentry->d_parent; /* dir inode is locked */
20069 + di_write_lock_parent(parent);
20070 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20072 + err = PTR_ERR(wh_dentry);
20073 + if (IS_ERR(wh_dentry))
20076 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
20077 + a->h_path.dentry = au_h_dptr(dentry, bstart);
20078 + dget(a->h_path.dentry);
20079 + if (bindex == bstart) {
20080 + h_dir = au_pinned_h_dir(&a->pin);
20081 + delegated = NULL;
20082 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20083 + if (unlikely(err == -EWOULDBLOCK)) {
20084 + pr_warn("cannot retry for NFSv4 delegation"
20085 + " for an internal unlink\n");
20089 + /* dir inode is locked */
20090 + h_dir = d_inode(wh_dentry->d_parent);
20091 + IMustLock(h_dir);
20096 + vfsub_drop_nlink(inode);
20097 + epilog(dir, dentry, bindex);
20099 + /* update target timestamps */
20100 + if (bindex == bstart) {
20101 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20103 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20105 + /* todo: this timestamp may be reverted later */
20106 + inode->i_ctime = h_dir->i_ctime;
20107 + goto out_unpin; /* success */
20114 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20121 + au_unpin(&a->pin);
20123 + dput(a->h_path.dentry);
20125 + di_write_unlock(parent);
20127 + aufs_read_unlock(dentry, AuLock_DW);
20134 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20136 + int err, rmdir_later;
20137 + aufs_bindex_t bwh, bindex, bstart;
20138 + struct inode *inode;
20139 + struct dentry *parent, *wh_dentry, *h_dentry;
20140 + struct au_whtmp_rmdir *args;
20141 + /* to reuduce stack size */
20143 + struct au_dtime dt;
20144 + struct au_pin pin;
20150 + a = kmalloc(sizeof(*a), GFP_NOFS);
20151 + if (unlikely(!a))
20154 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20155 + if (unlikely(err))
20157 + err = au_alive_dir(dentry);
20158 + if (unlikely(err))
20160 + inode = d_inode(dentry);
20161 + IMustLock(inode);
20163 + if (unlikely(!d_is_dir(dentry)))
20164 + goto out_unlock; /* possible? */
20167 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20168 + if (unlikely(!args))
20171 + parent = dentry->d_parent; /* dir inode is locked */
20172 + di_write_lock_parent(parent);
20173 + err = au_test_empty(dentry, &args->whlist);
20174 + if (unlikely(err))
20177 + bstart = au_dbstart(dentry);
20178 + bwh = au_dbwh(dentry);
20180 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20182 + err = PTR_ERR(wh_dentry);
20183 + if (IS_ERR(wh_dentry))
20186 + h_dentry = au_h_dptr(dentry, bstart);
20189 + if (bindex == bstart) {
20190 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
20192 + rmdir_later = err;
20196 + /* stop monitoring */
20197 + au_hn_free(au_hi(inode, bstart));
20199 + /* dir inode is locked */
20200 + IMustLock(d_inode(wh_dentry->d_parent));
20205 + vfsub_dead_dir(inode);
20206 + au_set_dbdiropq(dentry, -1);
20207 + epilog(dir, dentry, bindex);
20209 + if (rmdir_later) {
20210 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
20214 + goto out_unpin; /* success */
20222 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20229 + au_unpin(&a->pin);
20233 + di_write_unlock(parent);
20235 + au_whtmp_rmdir_free(args);
20237 + aufs_read_unlock(dentry, AuLock_DW);
20244 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20245 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20246 +++ linux/fs/aufs/i_op_ren.c 2016-04-24 18:32:51.393686895 +0200
20249 + * Copyright (C) 2005-2016 Junjiro R. Okajima
20251 + * This program, aufs is free software; you can redistribute it and/or modify
20252 + * it under the terms of the GNU General Public License as published by
20253 + * the Free Software Foundation; either version 2 of the License, or
20254 + * (at your option) any later version.
20256 + * This program is distributed in the hope that it will be useful,
20257 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20258 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20259 + * GNU General Public License for more details.
20261 + * You should have received a copy of the GNU General Public License
20262 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20266 + * inode operation (rename entry)
20267 + * todo: this is crazy monster
20272 +enum { AuSRC, AuDST, AuSrcDst };
20273 +enum { AuPARENT, AuCHILD, AuParentChild };
20275 +#define AuRen_ISDIR 1
20276 +#define AuRen_ISSAMEDIR (1 << 1)
20277 +#define AuRen_WHSRC (1 << 2)
20278 +#define AuRen_WHDST (1 << 3)
20279 +#define AuRen_MNT_WRITE (1 << 4)
20280 +#define AuRen_DT_DSTDIR (1 << 5)
20281 +#define AuRen_DIROPQ (1 << 6)
20282 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20283 +#define au_fset_ren(flags, name) \
20284 + do { (flags) |= AuRen_##name; } while (0)
20285 +#define au_fclr_ren(flags, name) \
20286 + do { (flags) &= ~AuRen_##name; } while (0)
20288 +struct au_ren_args {
20290 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20292 + struct inode *dir, *inode;
20293 + struct au_hinode *hdir;
20294 + struct au_dtime dt[AuParentChild];
20295 + aufs_bindex_t bstart;
20298 +#define src_dentry sd[AuSRC].dentry
20299 +#define src_dir sd[AuSRC].dir
20300 +#define src_inode sd[AuSRC].inode
20301 +#define src_h_dentry sd[AuSRC].h_dentry
20302 +#define src_parent sd[AuSRC].parent
20303 +#define src_h_parent sd[AuSRC].h_parent
20304 +#define src_wh_dentry sd[AuSRC].wh_dentry
20305 +#define src_hdir sd[AuSRC].hdir
20306 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20307 +#define src_dt sd[AuSRC].dt
20308 +#define src_bstart sd[AuSRC].bstart
20310 +#define dst_dentry sd[AuDST].dentry
20311 +#define dst_dir sd[AuDST].dir
20312 +#define dst_inode sd[AuDST].inode
20313 +#define dst_h_dentry sd[AuDST].h_dentry
20314 +#define dst_parent sd[AuDST].parent
20315 +#define dst_h_parent sd[AuDST].h_parent
20316 +#define dst_wh_dentry sd[AuDST].wh_dentry
20317 +#define dst_hdir sd[AuDST].hdir
20318 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20319 +#define dst_dt sd[AuDST].dt
20320 +#define dst_bstart sd[AuDST].bstart
20322 + struct dentry *h_trap;
20323 + struct au_branch *br;
20324 + struct au_hinode *src_hinode;
20325 + struct path h_path;
20326 + struct au_nhash whlist;
20327 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
20329 + unsigned int flags;
20331 + struct au_whtmp_rmdir *thargs;
20332 + struct dentry *h_dst;
20335 +/* ---------------------------------------------------------------------- */
20338 + * functions for reverting.
20339 + * when an error happened in a single rename systemcall, we should revert
20340 + * everything as if nothing happened.
20341 + * we don't need to revert the copied-up/down the parent dir since they are
20345 +#define RevertFailure(fmt, ...) do { \
20346 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20347 + ##__VA_ARGS__, err, rerr); \
20351 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20355 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20356 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
20357 + au_hn_imtx_unlock(a->src_hinode);
20358 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
20360 + RevertFailure("remove diropq %pd", a->src_dentry);
20363 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20366 + struct inode *delegated;
20368 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20369 + a->src_h_parent);
20370 + rerr = PTR_ERR(a->h_path.dentry);
20371 + if (IS_ERR(a->h_path.dentry)) {
20372 + RevertFailure("lkup one %pd", a->src_dentry);
20376 + delegated = NULL;
20377 + rerr = vfsub_rename(a->dst_h_dir,
20378 + au_h_dptr(a->src_dentry, a->btgt),
20379 + a->src_h_dir, &a->h_path, &delegated);
20380 + if (unlikely(rerr == -EWOULDBLOCK)) {
20381 + pr_warn("cannot retry for NFSv4 delegation"
20382 + " for an internal rename\n");
20385 + d_drop(a->h_path.dentry);
20386 + dput(a->h_path.dentry);
20387 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20389 + RevertFailure("rename %pd", a->src_dentry);
20392 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20395 + struct inode *delegated;
20397 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20398 + a->dst_h_parent);
20399 + rerr = PTR_ERR(a->h_path.dentry);
20400 + if (IS_ERR(a->h_path.dentry)) {
20401 + RevertFailure("lkup one %pd", a->dst_dentry);
20404 + if (d_is_positive(a->h_path.dentry)) {
20405 + d_drop(a->h_path.dentry);
20406 + dput(a->h_path.dentry);
20410 + delegated = NULL;
20411 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20413 + if (unlikely(rerr == -EWOULDBLOCK)) {
20414 + pr_warn("cannot retry for NFSv4 delegation"
20415 + " for an internal rename\n");
20418 + d_drop(a->h_path.dentry);
20419 + dput(a->h_path.dentry);
20421 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20423 + RevertFailure("rename %pd", a->h_dst);
20426 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20430 + a->h_path.dentry = a->src_wh_dentry;
20431 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20432 + au_set_dbwh(a->src_dentry, a->src_bwh);
20434 + RevertFailure("unlink %pd", a->src_wh_dentry);
20436 +#undef RevertFailure
20438 +/* ---------------------------------------------------------------------- */
20441 + * when we have to copyup the renaming entry, do it with the rename-target name
20442 + * in order to minimize the cost (the later actual rename is unnecessary).
20443 + * otherwise rename it on the target branch.
20445 +static int au_ren_or_cpup(struct au_ren_args *a)
20448 + struct dentry *d;
20449 + struct inode *delegated;
20451 + d = a->src_dentry;
20452 + if (au_dbstart(d) == a->btgt) {
20453 + a->h_path.dentry = a->dst_h_dentry;
20454 + if (au_ftest_ren(a->flags, DIROPQ)
20455 + && au_dbdiropq(d) == a->btgt)
20456 + au_fclr_ren(a->flags, DIROPQ);
20457 + AuDebugOn(au_dbstart(d) != a->btgt);
20458 + delegated = NULL;
20459 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20460 + a->dst_h_dir, &a->h_path, &delegated);
20461 + if (unlikely(err == -EWOULDBLOCK)) {
20462 + pr_warn("cannot retry for NFSv4 delegation"
20463 + " for an internal rename\n");
20469 + if (!err && a->h_dst)
20470 + /* it will be set to dinfo later */
20476 +/* cf. aufs_rmdir() */
20477 +static int au_ren_del_whtmp(struct au_ren_args *a)
20480 + struct inode *dir;
20482 + dir = a->dst_dir;
20483 + SiMustAnyLock(dir->i_sb);
20484 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20485 + au_sbi(dir->i_sb)->si_dirwh)
20486 + || au_test_fs_remote(a->h_dst->d_sb)) {
20487 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20488 + if (unlikely(err))
20489 + pr_warn("failed removing whtmp dir %pd (%d), "
20490 + "ignored.\n", a->h_dst, err);
20492 + au_nhash_wh_free(&a->thargs->whlist);
20493 + a->thargs->whlist = a->whlist;
20494 + a->whlist.nh_num = 0;
20495 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20497 + a->thargs = NULL;
20503 +/* make it 'opaque' dir. */
20504 +static int au_ren_diropq(struct au_ren_args *a)
20507 + struct dentry *diropq;
20510 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20511 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20512 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20513 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20514 + au_hn_imtx_unlock(a->src_hinode);
20515 + if (IS_ERR(diropq))
20516 + err = PTR_ERR(diropq);
20523 +static int do_rename(struct au_ren_args *a)
20526 + struct dentry *d, *h_d;
20528 + /* prepare workqueue args for asynchronous rmdir */
20529 + h_d = a->dst_h_dentry;
20530 + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) {
20532 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20533 + if (unlikely(!a->thargs))
20535 + a->h_dst = dget(h_d);
20538 + /* create whiteout for src_dentry */
20539 + if (au_ftest_ren(a->flags, WHSRC)) {
20540 + a->src_bwh = au_dbwh(a->src_dentry);
20541 + AuDebugOn(a->src_bwh >= 0);
20543 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20544 + err = PTR_ERR(a->src_wh_dentry);
20545 + if (IS_ERR(a->src_wh_dentry))
20549 + /* lookup whiteout for dentry */
20550 + if (au_ftest_ren(a->flags, WHDST)) {
20551 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20553 + err = PTR_ERR(h_d);
20556 + if (d_is_negative(h_d))
20559 + a->dst_wh_dentry = h_d;
20562 + /* rename dentry to tmpwh */
20564 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20565 + if (unlikely(err))
20568 + d = a->dst_dentry;
20569 + au_set_h_dptr(d, a->btgt, NULL);
20570 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20571 + if (unlikely(err))
20573 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20576 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_bstart != a->btgt);
20578 + /* rename by vfs_rename or cpup */
20579 + d = a->dst_dentry;
20580 + if (au_ftest_ren(a->flags, ISDIR)
20581 + && (a->dst_wh_dentry
20582 + || au_dbdiropq(d) == a->btgt
20583 + /* hide the lower to keep xino */
20584 + || a->btgt < au_dbend(d)
20585 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20586 + au_fset_ren(a->flags, DIROPQ);
20587 + err = au_ren_or_cpup(a);
20588 + if (unlikely(err))
20589 + /* leave the copied-up one */
20592 + /* make dir opaque */
20593 + if (au_ftest_ren(a->flags, DIROPQ)) {
20594 + err = au_ren_diropq(a);
20595 + if (unlikely(err))
20599 + /* update target timestamps */
20600 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
20601 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20602 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20603 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20605 + /* remove whiteout for dentry */
20606 + if (a->dst_wh_dentry) {
20607 + a->h_path.dentry = a->dst_wh_dentry;
20608 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20610 + if (unlikely(err))
20614 + /* remove whtmp */
20616 + au_ren_del_whtmp(a); /* ignore this error */
20618 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20620 + goto out_success;
20623 + if (au_ftest_ren(a->flags, DIROPQ))
20624 + au_ren_rev_diropq(err, a);
20626 + au_ren_rev_rename(err, a);
20630 + au_ren_rev_whtmp(err, a);
20632 + dput(a->dst_wh_dentry);
20633 + a->dst_wh_dentry = NULL;
20635 + if (a->src_wh_dentry)
20636 + au_ren_rev_whsrc(err, a);
20638 + dput(a->src_wh_dentry);
20639 + dput(a->dst_wh_dentry);
20643 + au_whtmp_rmdir_free(a->thargs);
20644 + a->thargs = NULL;
20650 +/* ---------------------------------------------------------------------- */
20653 + * test if @dentry dir can be rename destination or not.
20654 + * success means, it is a logically empty dir.
20656 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20658 + return au_test_empty(dentry, whlist);
20662 + * test if @dentry dir can be rename source or not.
20663 + * if it can, return 0 and @children is filled.
20665 + * - it is a logically empty dir.
20666 + * - or, it exists on writable branch and has no children including whiteouts
20667 + * on the lower branch.
20669 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20672 + unsigned int rdhash;
20673 + aufs_bindex_t bstart;
20675 + bstart = au_dbstart(dentry);
20676 + if (bstart != btgt) {
20677 + struct au_nhash whlist;
20679 + SiMustAnyLock(dentry->d_sb);
20680 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20682 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20684 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20685 + if (unlikely(err))
20687 + err = au_test_empty(dentry, &whlist);
20688 + au_nhash_wh_free(&whlist);
20692 + if (bstart == au_dbtaildir(dentry))
20693 + return 0; /* success */
20695 + err = au_test_empty_lower(dentry);
20698 + if (err == -ENOTEMPTY) {
20699 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20700 + " is not supported\n");
20706 +/* side effect: sets whlist and h_dentry */
20707 +static int au_ren_may_dir(struct au_ren_args *a)
20710 + unsigned int rdhash;
20711 + struct dentry *d;
20713 + d = a->dst_dentry;
20714 + SiMustAnyLock(d->d_sb);
20717 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20718 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20720 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20721 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20722 + if (unlikely(err))
20725 + au_set_dbstart(d, a->dst_bstart);
20726 + err = may_rename_dstdir(d, &a->whlist);
20727 + au_set_dbstart(d, a->btgt);
20729 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
20730 + if (unlikely(err))
20733 + d = a->src_dentry;
20734 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
20735 + if (au_ftest_ren(a->flags, ISDIR)) {
20736 + err = may_rename_srcdir(d, a->btgt);
20737 + if (unlikely(err)) {
20738 + au_nhash_wh_free(&a->whlist);
20739 + a->whlist.nh_num = 0;
20746 +/* ---------------------------------------------------------------------- */
20749 + * simple tests for rename.
20750 + * following the checks in vfs, plus the parent-child relationship.
20752 +static int au_may_ren(struct au_ren_args *a)
20755 + struct inode *h_inode;
20757 + if (a->src_bstart == a->btgt) {
20758 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20759 + au_ftest_ren(a->flags, ISDIR));
20760 + if (unlikely(err))
20763 + if (unlikely(a->src_h_dentry == a->h_trap))
20768 + if (a->dst_bstart != a->btgt)
20771 + err = -ENOTEMPTY;
20772 + if (unlikely(a->dst_h_dentry == a->h_trap))
20776 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20777 + if (d_really_is_negative(a->dst_dentry)) {
20778 + if (d_is_negative(a->dst_h_dentry))
20779 + err = au_may_add(a->dst_dentry, a->btgt,
20780 + a->dst_h_parent, isdir);
20782 + if (unlikely(d_is_negative(a->dst_h_dentry)))
20784 + h_inode = d_inode(a->dst_h_dentry);
20785 + if (h_inode->i_nlink)
20786 + err = au_may_del(a->dst_dentry, a->btgt,
20787 + a->dst_h_parent, isdir);
20791 + if (unlikely(err == -ENOENT || err == -EEXIST))
20797 +/* ---------------------------------------------------------------------- */
20802 + * - src_dir and dir by lock_rename()
20803 + * - inode if exitsts
20806 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20808 + * + di_write_lock2_child()
20809 + * + di_write_lock_child()
20810 + * + ii_write_lock_child()
20811 + * + di_write_lock_child2()
20812 + * + ii_write_lock_child2()
20813 + * + src_parent and parent
20814 + * + di_write_lock_parent()
20815 + * + ii_write_lock_parent()
20816 + * + di_write_lock_parent2()
20817 + * + ii_write_lock_parent2()
20818 + * + lower src_dir and dir by vfsub_lock_rename()
20819 + * + verify the every relationships between child and parent. if any
20820 + * of them failed, unlock all and return -EBUSY.
20822 +static void au_ren_unlock(struct au_ren_args *a)
20824 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20825 + a->dst_h_parent, a->dst_hdir);
20826 + if (au_ftest_ren(a->flags, MNT_WRITE))
20827 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20830 +static int au_ren_lock(struct au_ren_args *a)
20833 + unsigned int udba;
20836 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20837 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20838 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20839 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20841 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20842 + if (unlikely(err))
20844 + au_fset_ren(a->flags, MNT_WRITE);
20845 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20846 + a->dst_h_parent, a->dst_hdir);
20847 + udba = au_opt_udba(a->src_dentry->d_sb);
20848 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
20849 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
20850 + err = au_busy_or_stale();
20851 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20852 + err = au_h_verify(a->src_h_dentry, udba,
20853 + d_inode(a->src_h_parent), a->src_h_parent,
20855 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20856 + err = au_h_verify(a->dst_h_dentry, udba,
20857 + d_inode(a->dst_h_parent), a->dst_h_parent,
20860 + goto out; /* success */
20862 + err = au_busy_or_stale();
20863 + au_ren_unlock(a);
20869 +/* ---------------------------------------------------------------------- */
20871 +static void au_ren_refresh_dir(struct au_ren_args *a)
20873 + struct inode *dir;
20875 + dir = a->dst_dir;
20876 + dir->i_version++;
20877 + if (au_ftest_ren(a->flags, ISDIR)) {
20878 + /* is this updating defined in POSIX? */
20879 + au_cpup_attr_timesizes(a->src_inode);
20880 + au_cpup_attr_nlink(dir, /*force*/1);
20883 + au_dir_ts(dir, a->btgt);
20885 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20888 + dir = a->src_dir;
20889 + dir->i_version++;
20890 + if (au_ftest_ren(a->flags, ISDIR))
20891 + au_cpup_attr_nlink(dir, /*force*/1);
20892 + au_dir_ts(dir, a->btgt);
20895 +static void au_ren_refresh(struct au_ren_args *a)
20897 + aufs_bindex_t bend, bindex;
20898 + struct dentry *d, *h_d;
20899 + struct inode *i, *h_i;
20900 + struct super_block *sb;
20902 + d = a->dst_dentry;
20905 + /* already dget-ed by au_ren_or_cpup() */
20906 + au_set_h_dptr(d, a->btgt, a->h_dst);
20908 + i = a->dst_inode;
20910 + if (!au_ftest_ren(a->flags, ISDIR))
20911 + vfsub_drop_nlink(i);
20913 + vfsub_dead_dir(i);
20914 + au_cpup_attr_timesizes(i);
20916 + au_update_dbrange(d, /*do_put_zero*/1);
20919 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20920 + au_set_h_dptr(d, bindex, NULL);
20921 + bend = au_dbend(d);
20922 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20923 + au_set_h_dptr(d, bindex, NULL);
20924 + au_update_dbrange(d, /*do_put_zero*/0);
20927 + d = a->src_dentry;
20928 + au_set_dbwh(d, -1);
20929 + bend = au_dbend(d);
20930 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20931 + h_d = au_h_dptr(d, bindex);
20933 + au_set_h_dptr(d, bindex, NULL);
20935 + au_set_dbend(d, a->btgt);
20938 + i = a->src_inode;
20939 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20940 + return; /* success */
20942 + bend = au_ibend(i);
20943 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20944 + h_i = au_h_iptr(i, bindex);
20946 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20947 + /* ignore this error */
20948 + au_set_h_iptr(i, bindex, NULL, 0);
20951 + au_set_ibend(i, a->btgt);
20954 +/* ---------------------------------------------------------------------- */
20956 +/* mainly for link(2) and rename(2) */
20957 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20959 + aufs_bindex_t bdiropq, bwh;
20960 + struct dentry *parent;
20961 + struct au_branch *br;
20963 + parent = dentry->d_parent;
20964 + IMustLock(d_inode(parent)); /* dir is locked */
20966 + bdiropq = au_dbdiropq(parent);
20967 + bwh = au_dbwh(dentry);
20968 + br = au_sbr(dentry->d_sb, btgt);
20969 + if (au_br_rdonly(br)
20970 + || (0 <= bdiropq && bdiropq < btgt)
20971 + || (0 <= bwh && bwh < btgt))
20974 + AuDbg("btgt %d\n", btgt);
20978 +/* sets src_bstart, dst_bstart and btgt */
20979 +static int au_ren_wbr(struct au_ren_args *a)
20982 + struct au_wr_dir_args wr_dir_args = {
20983 + /* .force_btgt = -1, */
20984 + .flags = AuWrDir_ADD_ENTRY
20987 + a->src_bstart = au_dbstart(a->src_dentry);
20988 + a->dst_bstart = au_dbstart(a->dst_dentry);
20989 + if (au_ftest_ren(a->flags, ISDIR))
20990 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20991 + wr_dir_args.force_btgt = a->src_bstart;
20992 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20993 + wr_dir_args.force_btgt = a->dst_bstart;
20994 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20995 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21001 +static void au_ren_dt(struct au_ren_args *a)
21003 + a->h_path.dentry = a->src_h_parent;
21004 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21005 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
21006 + a->h_path.dentry = a->dst_h_parent;
21007 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21010 + au_fclr_ren(a->flags, DT_DSTDIR);
21011 + if (!au_ftest_ren(a->flags, ISDIR))
21014 + a->h_path.dentry = a->src_h_dentry;
21015 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21016 + if (d_is_positive(a->dst_h_dentry)) {
21017 + au_fset_ren(a->flags, DT_DSTDIR);
21018 + a->h_path.dentry = a->dst_h_dentry;
21019 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21023 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21025 + struct dentry *h_d;
21026 + struct inode *h_inode;
21028 + au_dtime_revert(a->src_dt + AuPARENT);
21029 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
21030 + au_dtime_revert(a->dst_dt + AuPARENT);
21032 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
21033 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21034 + h_inode = d_inode(h_d);
21035 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21036 + au_dtime_revert(a->src_dt + AuCHILD);
21037 + inode_unlock(h_inode);
21039 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
21040 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21041 + h_inode = d_inode(h_d);
21042 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21043 + au_dtime_revert(a->dst_dt + AuCHILD);
21044 + inode_unlock(h_inode);
21049 +/* ---------------------------------------------------------------------- */
21051 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21052 + struct inode *_dst_dir, struct dentry *_dst_dentry)
21055 + /* reduce stack space */
21056 + struct au_ren_args *a;
21058 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
21059 + IMustLock(_src_dir);
21060 + IMustLock(_dst_dir);
21063 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21064 + a = kzalloc(sizeof(*a), GFP_NOFS);
21065 + if (unlikely(!a))
21068 + a->src_dir = _src_dir;
21069 + a->src_dentry = _src_dentry;
21070 + a->src_inode = NULL;
21071 + if (d_really_is_positive(a->src_dentry))
21072 + a->src_inode = d_inode(a->src_dentry);
21073 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21074 + a->dst_dir = _dst_dir;
21075 + a->dst_dentry = _dst_dentry;
21076 + a->dst_inode = NULL;
21077 + if (d_really_is_positive(a->dst_dentry))
21078 + a->dst_inode = d_inode(a->dst_dentry);
21079 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21080 + if (a->dst_inode) {
21081 + IMustLock(a->dst_inode);
21082 + au_igrab(a->dst_inode);
21086 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21087 + if (d_is_dir(a->src_dentry)) {
21088 + au_fset_ren(a->flags, ISDIR);
21089 + if (unlikely(d_really_is_positive(a->dst_dentry)
21090 + && !d_is_dir(a->dst_dentry)))
21092 + flags |= AuLock_DIRS;
21094 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, flags);
21095 + if (unlikely(err))
21098 + err = au_d_hashed_positive(a->src_dentry);
21099 + if (unlikely(err))
21102 + if (a->dst_inode) {
21104 + * If it is a dir, VFS unhash dst_dentry before this
21105 + * function. It means we cannot rely upon d_unhashed().
21107 + if (unlikely(!a->dst_inode->i_nlink))
21109 + if (!S_ISDIR(a->dst_inode->i_mode)) {
21110 + err = au_d_hashed_positive(a->dst_dentry);
21111 + if (unlikely(err))
21113 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21115 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21119 + * is it possible?
21120 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21121 + * there may exist a problem somewhere else.
21124 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21127 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
21128 + di_write_lock_parent(a->dst_parent);
21130 + /* which branch we process */
21131 + err = au_ren_wbr(a);
21132 + if (unlikely(err < 0))
21134 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21135 + a->h_path.mnt = au_br_mnt(a->br);
21137 + /* are they available to be renamed */
21138 + err = au_ren_may_dir(a);
21139 + if (unlikely(err))
21140 + goto out_children;
21142 + /* prepare the writable parent dir on the same branch */
21143 + if (a->dst_bstart == a->btgt) {
21144 + au_fset_ren(a->flags, WHDST);
21146 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21147 + if (unlikely(err))
21148 + goto out_children;
21151 + if (a->src_dir != a->dst_dir) {
21153 + * this temporary unlock is safe,
21154 + * because both dir->i_mutex are locked.
21156 + di_write_unlock(a->dst_parent);
21157 + di_write_lock_parent(a->src_parent);
21158 + err = au_wr_dir_need_wh(a->src_dentry,
21159 + au_ftest_ren(a->flags, ISDIR),
21161 + di_write_unlock(a->src_parent);
21162 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
21163 + au_fclr_ren(a->flags, ISSAMEDIR);
21165 + err = au_wr_dir_need_wh(a->src_dentry,
21166 + au_ftest_ren(a->flags, ISDIR),
21168 + if (unlikely(err < 0))
21169 + goto out_children;
21171 + au_fset_ren(a->flags, WHSRC);
21174 + if (a->src_bstart != a->btgt) {
21175 + struct au_pin pin;
21177 + err = au_pin(&pin, a->src_dentry, a->btgt,
21178 + au_opt_udba(a->src_dentry->d_sb),
21179 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21181 + struct au_cp_generic cpg = {
21182 + .dentry = a->src_dentry,
21184 + .bsrc = a->src_bstart,
21187 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21189 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
21190 + err = au_sio_cpup_simple(&cpg);
21193 + if (unlikely(err))
21194 + goto out_children;
21195 + a->src_bstart = a->btgt;
21196 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21197 + au_fset_ren(a->flags, WHSRC);
21200 + /* lock them all */
21201 + err = au_ren_lock(a);
21202 + if (unlikely(err))
21203 + /* leave the copied-up one */
21204 + goto out_children;
21206 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21207 + err = au_may_ren(a);
21208 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21209 + err = -ENAMETOOLONG;
21210 + if (unlikely(err))
21213 + /* store timestamps to be revertible */
21217 + err = do_rename(a);
21218 + if (unlikely(err))
21221 + /* update dir attributes */
21222 + au_ren_refresh_dir(a);
21224 + /* dput/iput all lower dentries */
21225 + au_ren_refresh(a);
21227 + goto out_hdir; /* success */
21230 + au_ren_rev_dt(err, a);
21232 + au_ren_unlock(a);
21234 + au_nhash_wh_free(&a->whlist);
21235 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
21236 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
21237 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21238 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
21242 + d_move(a->src_dentry, a->dst_dentry);
21244 + au_update_dbstart(a->dst_dentry);
21245 + if (!a->dst_inode)
21246 + d_drop(a->dst_dentry);
21248 + if (au_ftest_ren(a->flags, ISSAMEDIR))
21249 + di_write_unlock(a->dst_parent);
21251 + di_write_unlock2(a->src_parent, a->dst_parent);
21253 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21255 + iput(a->dst_inode);
21257 + au_whtmp_rmdir_free(a->thargs);
21263 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21264 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21265 +++ linux/fs/aufs/Kconfig 2016-04-24 18:32:51.390353525 +0200
21268 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21270 + Aufs is a stackable unification filesystem such as Unionfs,
21271 + which unifies several directories and provides a merged single
21273 + In the early days, aufs was entirely re-designed and
21274 + re-implemented Unionfs Version 1.x series. Introducing many
21275 + original ideas, approaches and improvements, it becomes totally
21276 + different from Unionfs while keeping the basic features.
21280 + prompt "Maximum number of branches"
21281 + default AUFS_BRANCH_MAX_127
21283 + Specifies the maximum number of branches (or member directories)
21284 + in a single aufs. The larger value consumes more system
21285 + resources and has a minor impact to performance.
21286 +config AUFS_BRANCH_MAX_127
21289 + Specifies the maximum number of branches (or member directories)
21290 + in a single aufs. The larger value consumes more system
21291 + resources and has a minor impact to performance.
21292 +config AUFS_BRANCH_MAX_511
21295 + Specifies the maximum number of branches (or member directories)
21296 + in a single aufs. The larger value consumes more system
21297 + resources and has a minor impact to performance.
21298 +config AUFS_BRANCH_MAX_1023
21301 + Specifies the maximum number of branches (or member directories)
21302 + in a single aufs. The larger value consumes more system
21303 + resources and has a minor impact to performance.
21304 +config AUFS_BRANCH_MAX_32767
21307 + Specifies the maximum number of branches (or member directories)
21308 + in a single aufs. The larger value consumes more system
21309 + resources and has a minor impact to performance.
21312 +config AUFS_SBILIST
21314 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21317 + Automatic configuration for internal use.
21318 + When aufs supports Magic SysRq or /proc, enabled automatically.
21320 +config AUFS_HNOTIFY
21321 + bool "Detect direct branch access (bypassing aufs)"
21323 + If you want to modify files on branches directly, eg. bypassing aufs,
21324 + and want aufs to detect the changes of them fully, then enable this
21325 + option and use 'udba=notify' mount option.
21326 + Currently there is only one available configuration, "fsnotify".
21327 + It will have a negative impact to the performance.
21328 + See detail in aufs.5.
21331 + prompt "method" if AUFS_HNOTIFY
21332 + default AUFS_HFSNOTIFY
21333 +config AUFS_HFSNOTIFY
21338 +config AUFS_EXPORT
21339 + bool "NFS-exportable aufs"
21340 + depends on EXPORTFS
21342 + If you want to export your mounted aufs via NFS, then enable this
21343 + option. There are several requirements for this configuration.
21344 + See detail in aufs.5.
21346 +config AUFS_INO_T_64
21348 + depends on AUFS_EXPORT
21349 + depends on 64BIT && !(ALPHA || S390)
21352 + Automatic configuration for internal use.
21353 + /* typedef unsigned long/int __kernel_ino_t */
21354 + /* alpha and s390x are int */
21357 + bool "support for XATTR/EA (including Security Labels)"
21359 + If your branch fs supports XATTR/EA and you want to make them
21360 + available in aufs too, then enable this opsion and specify the
21361 + branch attributes for EA.
21362 + See detail in aufs.5.
21365 + bool "File-based Hierarchical Storage Management"
21367 + Hierarchical Storage Management (or HSM) is a well-known feature
21368 + in the storage world. Aufs provides this feature as file-based.
21369 + with multiple branches.
21370 + These multiple branches are prioritized, ie. the topmost one
21371 + should be the fastest drive and be used heavily.
21374 + bool "Readdir in userspace"
21376 + Aufs has two methods to provide a merged view for a directory,
21377 + by a user-space library and by kernel-space natively. The latter
21378 + is always enabled but sometimes large and slow.
21379 + If you enable this option, install the library in aufs2-util
21380 + package, and set some environment variables for your readdir(3),
21381 + then the work will be handled in user-space which generally
21382 + shows better performance in most cases.
21383 + See detail in aufs.5.
21386 + bool "Show whiteouts"
21388 + If you want to make the whiteouts in aufs visible, then enable
21389 + this option and specify 'shwh' mount option. Although it may
21390 + sounds like philosophy or something, but in technically it
21391 + simply shows the name of whiteout with keeping its behaviour.
21393 +config AUFS_BR_RAMFS
21394 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21396 + If you want to use ramfs as an aufs branch fs, then enable this
21397 + option. Generally tmpfs is recommended.
21398 + Aufs prohibited them to be a branch fs by default, because
21399 + initramfs becomes unusable after switch_root or something
21400 + generally. If you sets initramfs as an aufs branch and boot your
21401 + system by switch_root, you will meet a problem easily since the
21402 + files in initramfs may be inaccessible.
21403 + Unless you are going to use ramfs as an aufs branch fs without
21404 + switch_root or something, leave it N.
21406 +config AUFS_BR_FUSE
21407 + bool "Fuse fs as an aufs branch"
21408 + depends on FUSE_FS
21411 + If you want to use fuse-based userspace filesystem as an aufs
21412 + branch fs, then enable this option.
21413 + It implements the internal poll(2) operation which is
21414 + implemented by fuse only (curretnly).
21419 + Automatic configuration for internal use.
21421 +config AUFS_BR_HFSPLUS
21422 + bool "Hfsplus as an aufs branch"
21423 + depends on HFSPLUS_FS
21426 + If you want to use hfsplus fs as an aufs branch fs, then enable
21427 + this option. This option introduces a small overhead at
21428 + copying-up a file on hfsplus.
21430 +config AUFS_BDEV_LOOP
21432 + depends on BLK_DEV_LOOP
21435 + Automatic configuration for internal use.
21436 + Convert =[ym] into =y.
21439 + bool "Debug aufs"
21441 + Enable this to compile aufs internal debug code.
21442 + It will have a negative impact to the performance.
21444 +config AUFS_MAGIC_SYSRQ
21446 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21449 + Automatic configuration for internal use.
21450 + When aufs supports Magic SysRq, enabled automatically.
21452 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21453 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21454 +++ linux/fs/aufs/loop.c 2016-04-24 18:32:51.393686895 +0200
21457 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21459 + * This program, aufs is free software; you can redistribute it and/or modify
21460 + * it under the terms of the GNU General Public License as published by
21461 + * the Free Software Foundation; either version 2 of the License, or
21462 + * (at your option) any later version.
21464 + * This program is distributed in the hope that it will be useful,
21465 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21466 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21467 + * GNU General Public License for more details.
21469 + * You should have received a copy of the GNU General Public License
21470 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21474 + * support for loopback block device as a branch
21479 +/* added into drivers/block/loop.c */
21480 +static struct file *(*backing_file_func)(struct super_block *sb);
21483 + * test if two lower dentries have overlapping branches.
21485 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21487 + struct super_block *h_sb;
21488 + struct file *backing_file;
21490 + if (unlikely(!backing_file_func)) {
21491 + /* don't load "loop" module here */
21492 + backing_file_func = symbol_get(loop_backing_file);
21493 + if (unlikely(!backing_file_func))
21494 + /* "loop" module is not loaded */
21498 + h_sb = h_adding->d_sb;
21499 + backing_file = backing_file_func(h_sb);
21500 + if (!backing_file)
21503 + h_adding = backing_file->f_path.dentry;
21505 + * h_adding can be local NFS.
21506 + * in this case aufs cannot detect the loop.
21508 + if (unlikely(h_adding->d_sb == sb))
21510 + return !!au_test_subdir(h_adding, sb->s_root);
21513 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21514 +int au_test_loopback_kthread(void)
21517 + struct task_struct *tsk = current;
21518 + char c, comm[sizeof(tsk->comm)];
21521 + if (tsk->flags & PF_KTHREAD) {
21522 + get_task_comm(comm, tsk);
21524 + ret = ('0' <= c && c <= '9'
21525 + && !strncmp(comm, "loop", 4));
21531 +/* ---------------------------------------------------------------------- */
21533 +#define au_warn_loopback_step 16
21534 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21535 +static unsigned long *au_warn_loopback_array;
21537 +void au_warn_loopback(struct super_block *h_sb)
21539 + int i, new_nelem;
21540 + unsigned long *a, magic;
21541 + static DEFINE_SPINLOCK(spin);
21543 + magic = h_sb->s_magic;
21544 + spin_lock(&spin);
21545 + a = au_warn_loopback_array;
21546 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21547 + if (a[i] == magic) {
21548 + spin_unlock(&spin);
21552 + /* h_sb is new to us, print it */
21553 + if (i < au_warn_loopback_nelem) {
21558 + /* expand the array */
21559 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21560 + a = au_kzrealloc(au_warn_loopback_array,
21561 + au_warn_loopback_nelem * sizeof(unsigned long),
21562 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
21564 + au_warn_loopback_nelem = new_nelem;
21565 + au_warn_loopback_array = a;
21570 + spin_unlock(&spin);
21571 + AuWarn1("realloc failed, ignored\n");
21575 + spin_unlock(&spin);
21576 + pr_warn("you may want to try another patch for loopback file "
21577 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21580 +int au_loopback_init(void)
21583 + struct super_block *sb __maybe_unused;
21585 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
21588 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21589 + sizeof(unsigned long), GFP_NOFS);
21590 + if (unlikely(!au_warn_loopback_array))
21596 +void au_loopback_fin(void)
21598 + if (backing_file_func)
21599 + symbol_put(loop_backing_file);
21600 + kfree(au_warn_loopback_array);
21602 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21603 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21604 +++ linux/fs/aufs/loop.h 2016-04-24 18:32:51.393686895 +0200
21607 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21609 + * This program, aufs is free software; you can redistribute it and/or modify
21610 + * it under the terms of the GNU General Public License as published by
21611 + * the Free Software Foundation; either version 2 of the License, or
21612 + * (at your option) any later version.
21614 + * This program is distributed in the hope that it will be useful,
21615 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21616 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21617 + * GNU General Public License for more details.
21619 + * You should have received a copy of the GNU General Public License
21620 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21624 + * support for loopback mount as a branch
21627 +#ifndef __AUFS_LOOP_H__
21628 +#define __AUFS_LOOP_H__
21633 +struct super_block;
21635 +#ifdef CONFIG_AUFS_BDEV_LOOP
21636 +/* drivers/block/loop.c */
21637 +struct file *loop_backing_file(struct super_block *sb);
21640 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21641 +int au_test_loopback_kthread(void);
21642 +void au_warn_loopback(struct super_block *h_sb);
21644 +int au_loopback_init(void);
21645 +void au_loopback_fin(void);
21647 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21648 + struct dentry *h_adding)
21649 +AuStubInt0(au_test_loopback_kthread, void)
21650 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21652 +AuStubInt0(au_loopback_init, void)
21653 +AuStubVoid(au_loopback_fin, void)
21654 +#endif /* BLK_DEV_LOOP */
21656 +#endif /* __KERNEL__ */
21657 +#endif /* __AUFS_LOOP_H__ */
21658 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21659 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21660 +++ linux/fs/aufs/magic.mk 2016-04-24 18:32:51.393686895 +0200
21663 +# defined in ${srctree}/fs/fuse/inode.c
21665 +ifdef CONFIG_FUSE_FS
21666 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21669 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21671 +ifdef CONFIG_XFS_FS
21672 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21675 +# defined in ${srctree}/fs/configfs/mount.c
21677 +ifdef CONFIG_CONFIGFS_FS
21678 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21681 +# defined in ${srctree}/fs/ubifs/ubifs.h
21683 +ifdef CONFIG_UBIFS_FS
21684 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21687 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21689 +ifdef CONFIG_HFSPLUS_FS
21690 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21692 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21693 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21694 +++ linux/fs/aufs/Makefile 2016-04-24 18:32:51.390353525 +0200
21697 +include ${src}/magic.mk
21698 +ifeq (${CONFIG_AUFS_FS},m)
21699 +include ${src}/conf.mk
21701 +-include ${src}/priv_def.mk
21703 +# cf. include/linux/kernel.h
21705 +ccflags-y += -DDEBUG
21706 +# sparse requires the full pathname
21708 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21710 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21713 +obj-$(CONFIG_AUFS_FS) += aufs.o
21714 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21715 + wkq.o vfsub.o dcsub.o \
21716 + cpup.o whout.o wbr_policy.o \
21717 + dinfo.o dentry.o \
21719 + finfo.o file.o f_op.o \
21721 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21725 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21726 +aufs-$(CONFIG_SYSFS) += sysfs.o
21727 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21728 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21729 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21730 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21731 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21732 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21733 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21734 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21735 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21736 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21737 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21738 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21739 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21740 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21741 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21742 +++ linux/fs/aufs/module.c 2016-04-24 18:32:51.393686895 +0200
21745 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21747 + * This program, aufs is free software; you can redistribute it and/or modify
21748 + * it under the terms of the GNU General Public License as published by
21749 + * the Free Software Foundation; either version 2 of the License, or
21750 + * (at your option) any later version.
21752 + * This program is distributed in the hope that it will be useful,
21753 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21754 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21755 + * GNU General Public License for more details.
21757 + * You should have received a copy of the GNU General Public License
21758 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21762 + * module global variables and operations
21765 +#include <linux/module.h>
21766 +#include <linux/seq_file.h>
21769 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21771 + if (new_sz <= nused)
21774 + p = krealloc(p, new_sz, gfp);
21776 + memset(p + nused, 0, new_sz - nused);
21780 +/* ---------------------------------------------------------------------- */
21785 +struct kmem_cache *au_cachep[AuCache_Last];
21786 +static int __init au_cache_init(void)
21788 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21789 + if (au_cachep[AuCache_DINFO])
21790 + /* SLAB_DESTROY_BY_RCU */
21791 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21792 + au_icntnr_init_once);
21793 + if (au_cachep[AuCache_ICNTNR])
21794 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21795 + au_fi_init_once);
21796 + if (au_cachep[AuCache_FINFO])
21797 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21798 + if (au_cachep[AuCache_VDIR])
21799 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21800 + if (au_cachep[AuCache_DEHSTR])
21806 +static void au_cache_fin(void)
21811 + * Make sure all delayed rcu free inodes are flushed before we
21816 + /* excluding AuCache_HNOTIFY */
21817 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21818 + for (i = 0; i < AuCache_HNOTIFY; i++) {
21819 + kmem_cache_destroy(au_cachep[i]);
21820 + au_cachep[i] = NULL;
21824 +/* ---------------------------------------------------------------------- */
21826 +int au_dir_roflags;
21828 +#ifdef CONFIG_AUFS_SBILIST
21830 + * iterate_supers_type() doesn't protect us from
21831 + * remounting (branch management)
21833 +struct au_splhead au_sbilist;
21836 +struct lock_class_key au_lc_key[AuLcKey_Last];
21839 + * functions for module interface.
21841 +MODULE_LICENSE("GPL");
21842 +/* MODULE_LICENSE("GPL v2"); */
21843 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21844 +MODULE_DESCRIPTION(AUFS_NAME
21845 + " -- Advanced multi layered unification filesystem");
21846 +MODULE_VERSION(AUFS_VERSION);
21847 +MODULE_ALIAS_FS(AUFS_NAME);
21849 +/* this module parameter has no meaning when SYSFS is disabled */
21850 +int sysaufs_brs = 1;
21851 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21852 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21854 +/* this module parameter has no meaning when USER_NS is disabled */
21856 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21857 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21859 +/* ---------------------------------------------------------------------- */
21861 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21863 +int au_seq_path(struct seq_file *seq, struct path *path)
21867 + err = seq_path(seq, path, au_esc_chars);
21870 + else if (err < 0)
21876 +/* ---------------------------------------------------------------------- */
21878 +static int __init aufs_init(void)
21883 + p = au_esc_chars;
21884 + for (i = 1; i <= ' '; i++)
21890 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21892 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
21893 + for (i = 0; i < AuIop_Last; i++)
21894 + aufs_iop_nogetattr[i].getattr = NULL;
21896 + au_sbilist_init();
21897 + sysaufs_brs_init();
21900 + err = sysaufs_init();
21901 + if (unlikely(err))
21903 + err = au_procfs_init();
21904 + if (unlikely(err))
21905 + goto out_sysaufs;
21906 + err = au_wkq_init();
21907 + if (unlikely(err))
21909 + err = au_loopback_init();
21910 + if (unlikely(err))
21912 + err = au_hnotify_init();
21913 + if (unlikely(err))
21914 + goto out_loopback;
21915 + err = au_sysrq_init();
21916 + if (unlikely(err))
21918 + err = au_cache_init();
21919 + if (unlikely(err))
21922 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21923 + err = register_filesystem(&aufs_fs_type);
21924 + if (unlikely(err))
21927 + /* since we define pr_fmt, call printk directly */
21928 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21929 + goto out; /* success */
21936 + au_hnotify_fin();
21938 + au_loopback_fin();
21950 +static void __exit aufs_exit(void)
21952 + unregister_filesystem(&aufs_fs_type);
21955 + au_hnotify_fin();
21956 + au_loopback_fin();
21963 +module_init(aufs_init);
21964 +module_exit(aufs_exit);
21965 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21966 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21967 +++ linux/fs/aufs/module.h 2016-04-24 18:32:51.393686895 +0200
21970 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21972 + * This program, aufs is free software; you can redistribute it and/or modify
21973 + * it under the terms of the GNU General Public License as published by
21974 + * the Free Software Foundation; either version 2 of the License, or
21975 + * (at your option) any later version.
21977 + * This program is distributed in the hope that it will be useful,
21978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21980 + * GNU General Public License for more details.
21982 + * You should have received a copy of the GNU General Public License
21983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21987 + * module initialization and module-global
21990 +#ifndef __AUFS_MODULE_H__
21991 +#define __AUFS_MODULE_H__
21995 +#include <linux/slab.h>
22000 +/* module parameters */
22001 +extern int sysaufs_brs;
22002 +extern bool au_userns;
22004 +/* ---------------------------------------------------------------------- */
22006 +extern int au_dir_roflags;
22009 + AuLcNonDir_FIINFO,
22010 + AuLcNonDir_DIINFO,
22011 + AuLcNonDir_IIINFO,
22017 + AuLcSymlink_DIINFO,
22018 + AuLcSymlink_IIINFO,
22022 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
22024 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
22025 +int au_seq_path(struct seq_file *seq, struct path *path);
22027 +#ifdef CONFIG_PROC_FS
22029 +int __init au_procfs_init(void);
22030 +void au_procfs_fin(void);
22032 +AuStubInt0(au_procfs_init, void);
22033 +AuStubVoid(au_procfs_fin, void);
22036 +/* ---------------------------------------------------------------------- */
22045 + AuCache_HNOTIFY, /* must be last */
22049 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22050 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22051 +#define AuCacheCtor(type, ctor) \
22052 + kmem_cache_create(#type, sizeof(struct type), \
22053 + __alignof__(struct type), AuCacheFlags, ctor)
22055 +extern struct kmem_cache *au_cachep[];
22057 +#define AuCacheFuncs(name, index) \
22058 +static inline struct au_##name *au_cache_alloc_##name(void) \
22059 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
22060 +static inline void au_cache_free_##name(struct au_##name *p) \
22061 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
22063 +AuCacheFuncs(dinfo, DINFO);
22064 +AuCacheFuncs(icntnr, ICNTNR);
22065 +AuCacheFuncs(finfo, FINFO);
22066 +AuCacheFuncs(vdir, VDIR);
22067 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22068 +#ifdef CONFIG_AUFS_HNOTIFY
22069 +AuCacheFuncs(hnotify, HNOTIFY);
22072 +#endif /* __KERNEL__ */
22073 +#endif /* __AUFS_MODULE_H__ */
22074 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22075 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22076 +++ linux/fs/aufs/mvdown.c 2016-04-24 18:32:51.393686895 +0200
22079 + * Copyright (C) 2011-2016 Junjiro R. Okajima
22081 + * This program, aufs is free software; you can redistribute it and/or modify
22082 + * it under the terms of the GNU General Public License as published by
22083 + * the Free Software Foundation; either version 2 of the License, or
22084 + * (at your option) any later version.
22086 + * This program is distributed in the hope that it will be useful,
22087 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22088 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22089 + * GNU General Public License for more details.
22091 + * You should have received a copy of the GNU General Public License
22092 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22096 + * move-down, opposite of copy-up
22101 +struct au_mvd_args {
22103 + struct super_block *h_sb;
22104 + struct dentry *h_parent;
22105 + struct au_hinode *hdir;
22106 + struct inode *h_dir, *h_inode;
22107 + struct au_pin pin;
22108 + } info[AUFS_MVDOWN_NARRAY];
22110 + struct aufs_mvdown mvdown;
22111 + struct dentry *dentry, *parent;
22112 + struct inode *inode, *dir;
22113 + struct super_block *sb;
22114 + aufs_bindex_t bopq, bwh, bfound;
22115 + unsigned char rename_lock;
22118 +#define mvd_errno mvdown.au_errno
22119 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22120 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22121 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22122 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22124 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22125 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22126 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22127 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22128 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22129 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22131 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22132 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22133 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22134 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22135 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22136 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22138 +#define AU_MVD_PR(flag, ...) do { \
22140 + pr_err(__VA_ARGS__); \
22143 +static int find_lower_writable(struct au_mvd_args *a)
22145 + struct super_block *sb;
22146 + aufs_bindex_t bindex, bend;
22147 + struct au_branch *br;
22150 + bindex = a->mvd_bsrc;
22151 + bend = au_sbend(sb);
22152 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22153 + for (bindex++; bindex <= bend; bindex++) {
22154 + br = au_sbr(sb, bindex);
22155 + if (au_br_fhsm(br->br_perm)
22156 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22159 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22160 + for (bindex++; bindex <= bend; bindex++) {
22161 + br = au_sbr(sb, bindex);
22162 + if (!au_br_rdonly(br))
22166 + for (bindex++; bindex <= bend; bindex++) {
22167 + br = au_sbr(sb, bindex);
22168 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22169 + if (au_br_rdonly(br))
22171 + |= AUFS_MVDOWN_ROLOWER_R;
22179 +/* make the parent dir on bdst */
22180 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22185 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22186 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22187 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22188 + a->mvd_h_dst_parent = NULL;
22189 + if (au_dbend(a->parent) >= a->mvd_bdst)
22190 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22191 + if (!a->mvd_h_dst_parent) {
22192 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22193 + if (unlikely(err)) {
22194 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22197 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22205 +/* lock them all */
22206 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22209 + struct dentry *h_trap;
22211 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22212 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22213 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22214 + au_opt_udba(a->sb),
22215 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22217 + if (unlikely(err)) {
22218 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22222 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22223 + a->rename_lock = 0;
22224 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22225 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22226 + au_opt_udba(a->sb),
22227 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22228 + err = au_do_pin(&a->mvd_pin_src);
22230 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22231 + if (unlikely(err)) {
22232 + AU_MVD_PR(dmsg, "pin_src failed\n");
22235 + goto out; /* success */
22238 + a->rename_lock = 1;
22239 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22240 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22241 + au_opt_udba(a->sb),
22242 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22244 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22245 + if (unlikely(err)) {
22246 + AU_MVD_PR(dmsg, "pin_src failed\n");
22247 + au_pin_hdir_lock(&a->mvd_pin_dst);
22250 + au_pin_hdir_unlock(&a->mvd_pin_src);
22251 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22252 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22254 + err = (h_trap != a->mvd_h_src_parent);
22256 + err = (h_trap != a->mvd_h_dst_parent);
22258 + BUG_ON(err); /* it should never happen */
22259 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22262 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22263 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22264 + au_pin_hdir_lock(&a->mvd_pin_src);
22265 + au_unpin(&a->mvd_pin_src);
22266 + au_pin_hdir_lock(&a->mvd_pin_dst);
22269 + goto out; /* success */
22272 + au_unpin(&a->mvd_pin_dst);
22278 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22280 + if (!a->rename_lock)
22281 + au_unpin(&a->mvd_pin_src);
22283 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22284 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22285 + au_pin_hdir_lock(&a->mvd_pin_src);
22286 + au_unpin(&a->mvd_pin_src);
22287 + au_pin_hdir_lock(&a->mvd_pin_dst);
22289 + au_unpin(&a->mvd_pin_dst);
22292 +/* copy-down the file */
22293 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22296 + struct au_cp_generic cpg = {
22297 + .dentry = a->dentry,
22298 + .bdst = a->mvd_bdst,
22299 + .bsrc = a->mvd_bsrc,
22301 + .pin = &a->mvd_pin_dst,
22302 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22305 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22306 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22307 + au_fset_cpup(cpg.flags, OVERWRITE);
22308 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22309 + au_fset_cpup(cpg.flags, RWDST);
22310 + err = au_sio_cpdown_simple(&cpg);
22311 + if (unlikely(err))
22312 + AU_MVD_PR(dmsg, "cpdown failed\n");
22319 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22322 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22325 + struct path h_path;
22326 + struct au_branch *br;
22327 + struct inode *delegated;
22329 + br = au_sbr(a->sb, a->mvd_bdst);
22330 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22331 + err = PTR_ERR(h_path.dentry);
22332 + if (IS_ERR(h_path.dentry)) {
22333 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22338 + if (d_is_positive(h_path.dentry)) {
22339 + h_path.mnt = au_br_mnt(br);
22340 + delegated = NULL;
22341 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22342 + &delegated, /*force*/0);
22343 + if (unlikely(err == -EWOULDBLOCK)) {
22344 + pr_warn("cannot retry for NFSv4 delegation"
22345 + " for an internal unlink\n");
22348 + if (unlikely(err))
22349 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22351 + dput(h_path.dentry);
22359 + * unlink the topmost h_dentry
22361 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22364 + struct path h_path;
22365 + struct inode *delegated;
22367 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22368 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22369 + delegated = NULL;
22370 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22371 + if (unlikely(err == -EWOULDBLOCK)) {
22372 + pr_warn("cannot retry for NFSv4 delegation"
22373 + " for an internal unlink\n");
22376 + if (unlikely(err))
22377 + AU_MVD_PR(dmsg, "unlink failed\n");
22383 +/* Since mvdown succeeded, we ignore an error of this function */
22384 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22387 + struct au_branch *br;
22389 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22390 + br = au_sbr(a->sb, a->mvd_bsrc);
22391 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22393 + br = au_sbr(a->sb, a->mvd_bdst);
22394 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22395 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22398 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22400 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22404 + * copy-down the file and unlink the bsrc file.
22405 + * - unlink the bdst whout if exist
22406 + * - copy-down the file (with whtmp name and rename)
22407 + * - unlink the bsrc file
22409 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22413 + err = au_do_mkdir(dmsg, a);
22415 + err = au_do_lock(dmsg, a);
22416 + if (unlikely(err))
22420 + * do not revert the activities we made on bdst since they should be
22421 + * harmless in aufs.
22424 + err = au_do_cpdown(dmsg, a);
22426 + err = au_do_unlink_wh(dmsg, a);
22427 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22428 + err = au_do_unlink(dmsg, a);
22429 + if (unlikely(err))
22432 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22433 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22434 + if (find_lower_writable(a) < 0)
22435 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22437 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22438 + au_do_stfs(dmsg, a);
22440 + /* maintain internal array */
22441 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22442 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22443 + au_set_dbstart(a->dentry, a->mvd_bdst);
22444 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22445 + au_set_ibstart(a->inode, a->mvd_bdst);
22447 + /* hide the lower */
22448 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22449 + au_set_dbend(a->dentry, a->mvd_bsrc);
22450 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
22451 + au_set_ibend(a->inode, a->mvd_bsrc);
22453 + if (au_dbend(a->dentry) < a->mvd_bdst)
22454 + au_set_dbend(a->dentry, a->mvd_bdst);
22455 + if (au_ibend(a->inode) < a->mvd_bdst)
22456 + au_set_ibend(a->inode, a->mvd_bdst);
22459 + au_do_unlock(dmsg, a);
22465 +/* ---------------------------------------------------------------------- */
22467 +/* make sure the file is idle */
22468 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22470 + int err, plinked;
22473 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22474 + if (au_dbstart(a->dentry) == a->mvd_bsrc
22475 + && au_dcount(a->dentry) == 1
22476 + && atomic_read(&a->inode->i_count) == 1
22477 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22478 + && (!plinked || !au_plink_test(a->inode))
22479 + && a->inode->i_nlink == 1)
22484 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22485 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
22486 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22487 + a->mvd_h_src_inode->i_nlink,
22488 + plinked, plinked ? au_plink_test(a->inode) : 0);
22495 +/* make sure the parent dir is fine */
22496 +static int au_mvd_args_parent(const unsigned char dmsg,
22497 + struct au_mvd_args *a)
22500 + aufs_bindex_t bindex;
22503 + if (unlikely(au_alive_dir(a->parent))) {
22505 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22509 + a->bopq = au_dbdiropq(a->parent);
22510 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22511 + AuDbg("b%d\n", bindex);
22512 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22513 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22515 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22516 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22517 + a->bopq, a->mvd_bdst);
22525 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22526 + struct au_mvd_args *a)
22529 + struct au_dinfo *dinfo, *tmp;
22531 + /* lookup the next lower positive entry */
22533 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22534 + if (unlikely(!tmp))
22539 + dinfo = au_di(a->dentry);
22540 + au_di_cp(tmp, dinfo);
22541 + au_di_swap(tmp, dinfo);
22543 + /* returns the number of positive dentries */
22544 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
22546 + a->bwh = au_dbwh(a->dentry);
22547 + else if (err > 0)
22548 + a->bfound = au_dbstart(a->dentry);
22550 + au_di_swap(tmp, dinfo);
22551 + au_rw_write_unlock(&tmp->di_rwsem);
22553 + if (unlikely(err < 0))
22554 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22557 + * here, we have these cases.
22559 + * no positive dentry under bsrc. there are more sub-cases.
22561 + * there no whiteout, we can safely move-down.
22564 + * bsrc < bwh && bwh < bdst
22565 + * there is a whiteout on RO branch. cannot proceed.
22567 + * there is a whiteout on the RW target branch. it should
22570 + * there is a whiteout somewhere unrelated branch.
22571 + * -1 < bfound && bfound <= bsrc
22574 + * found, but it is on RO branch between bsrc and bdst. cannot
22577 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22580 + * found, after we create the file on bdst, it will be hidden.
22583 + AuDebugOn(a->bfound == -1
22585 + && a->bwh <= a->mvd_bsrc);
22586 + AuDebugOn(-1 < a->bfound
22587 + && a->bfound <= a->mvd_bsrc);
22590 + if (a->bfound == -1
22591 + && a->mvd_bsrc < a->bwh
22593 + && a->bwh < a->mvd_bdst) {
22594 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22595 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22596 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22598 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22599 + a->mvd_errno = EAU_MVDOWN_UPPER;
22600 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22601 + a->mvd_bdst, a->bfound);
22605 + err = 0; /* success */
22612 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22617 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22618 + && a->bfound == a->mvd_bdst)
22624 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
22627 + struct au_branch *br;
22630 + if (unlikely(S_ISDIR(a->inode->i_mode)))
22634 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
22635 + a->mvd_bsrc = au_ibstart(a->inode);
22637 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
22638 + if (unlikely(a->mvd_bsrc < 0
22639 + || (a->mvd_bsrc < au_dbstart(a->dentry)
22640 + || au_dbend(a->dentry) < a->mvd_bsrc
22641 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
22642 + || (a->mvd_bsrc < au_ibstart(a->inode)
22643 + || au_ibend(a->inode) < a->mvd_bsrc
22644 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
22645 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
22646 + AU_MVD_PR(dmsg, "no upper\n");
22650 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
22651 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22652 + AU_MVD_PR(dmsg, "on the bottom\n");
22655 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
22656 + br = au_sbr(a->sb, a->mvd_bsrc);
22657 + err = au_br_rdonly(br);
22658 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
22659 + if (unlikely(err))
22661 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
22662 + || IS_APPEND(a->mvd_h_src_inode))) {
22664 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22670 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22671 + a->mvd_bdst = find_lower_writable(a);
22672 + if (unlikely(a->mvd_bdst < 0)) {
22673 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22674 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22678 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22679 + if (unlikely(a->mvd_bdst < 0
22680 + || au_sbend(a->sb) < a->mvd_bdst)) {
22681 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22682 + AU_MVD_PR(dmsg, "no lower brid\n");
22687 + err = au_mvd_args_busy(dmsg, a);
22689 + err = au_mvd_args_parent(dmsg, a);
22691 + err = au_mvd_args_intermediate(dmsg, a);
22693 + err = au_mvd_args_exist(dmsg, a);
22695 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22702 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22705 + unsigned char dmsg;
22706 + struct au_mvd_args *args;
22707 + struct inode *inode;
22709 + inode = d_inode(dentry);
22711 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22715 + args = kmalloc(sizeof(*args), GFP_NOFS);
22716 + if (unlikely(!args))
22719 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22721 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22722 + if (unlikely(err)) {
22727 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22728 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22729 + args->mvdown.au_errno = 0;
22730 + args->dentry = dentry;
22731 + args->inode = inode;
22732 + args->sb = dentry->d_sb;
22735 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22736 + args->parent = dget_parent(dentry);
22737 + args->dir = d_inode(args->parent);
22738 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
22739 + dput(args->parent);
22740 + if (unlikely(args->parent != dentry->d_parent)) {
22741 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22745 + inode_lock_nested(inode, I_MUTEX_CHILD);
22746 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
22747 + if (unlikely(err))
22750 + di_write_lock_parent(args->parent);
22751 + err = au_mvd_args(dmsg, args);
22752 + if (unlikely(err))
22755 + err = au_do_mvdown(dmsg, args);
22756 + if (unlikely(err))
22759 + au_cpup_attr_timesizes(args->dir);
22760 + au_cpup_attr_timesizes(inode);
22761 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
22762 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
22763 + /* au_digen_dec(dentry); */
22766 + di_write_unlock(args->parent);
22767 + aufs_read_unlock(dentry, AuLock_DW);
22769 + inode_unlock(inode);
22771 + inode_unlock(args->dir);
22773 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22781 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22782 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22783 +++ linux/fs/aufs/opts.c 2016-04-24 18:32:51.393686895 +0200
22786 + * Copyright (C) 2005-2016 Junjiro R. Okajima
22788 + * This program, aufs is free software; you can redistribute it and/or modify
22789 + * it under the terms of the GNU General Public License as published by
22790 + * the Free Software Foundation; either version 2 of the License, or
22791 + * (at your option) any later version.
22793 + * This program is distributed in the hope that it will be useful,
22794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22796 + * GNU General Public License for more details.
22798 + * You should have received a copy of the GNU General Public License
22799 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22803 + * mount options/flags
22806 +#include <linux/namei.h>
22807 +#include <linux/types.h> /* a distribution requires */
22808 +#include <linux/parser.h>
22811 +/* ---------------------------------------------------------------------- */
22815 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
22816 + Opt_idel, Opt_imod,
22817 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
22818 + Opt_rdblk_def, Opt_rdhash_def,
22819 + Opt_xino, Opt_noxino,
22820 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22821 + Opt_trunc_xino_path, Opt_itrunc_xino,
22822 + Opt_trunc_xib, Opt_notrunc_xib,
22823 + Opt_shwh, Opt_noshwh,
22824 + Opt_plink, Opt_noplink, Opt_list_plink,
22826 + Opt_dio, Opt_nodio,
22827 + Opt_diropq_a, Opt_diropq_w,
22828 + Opt_warn_perm, Opt_nowarn_perm,
22829 + Opt_wbr_copyup, Opt_wbr_create,
22831 + Opt_verbose, Opt_noverbose,
22832 + Opt_sum, Opt_nosum, Opt_wsum,
22833 + Opt_dirperm1, Opt_nodirperm1,
22834 + Opt_acl, Opt_noacl,
22835 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22838 +static match_table_t options = {
22839 + {Opt_br, "br=%s"},
22840 + {Opt_br, "br:%s"},
22842 + {Opt_add, "add=%d:%s"},
22843 + {Opt_add, "add:%d:%s"},
22844 + {Opt_add, "ins=%d:%s"},
22845 + {Opt_add, "ins:%d:%s"},
22846 + {Opt_append, "append=%s"},
22847 + {Opt_append, "append:%s"},
22848 + {Opt_prepend, "prepend=%s"},
22849 + {Opt_prepend, "prepend:%s"},
22851 + {Opt_del, "del=%s"},
22852 + {Opt_del, "del:%s"},
22853 + /* {Opt_idel, "idel:%d"}, */
22854 + {Opt_mod, "mod=%s"},
22855 + {Opt_mod, "mod:%s"},
22856 + /* {Opt_imod, "imod:%d:%s"}, */
22858 + {Opt_dirwh, "dirwh=%d"},
22860 + {Opt_xino, "xino=%s"},
22861 + {Opt_noxino, "noxino"},
22862 + {Opt_trunc_xino, "trunc_xino"},
22863 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22864 + {Opt_notrunc_xino, "notrunc_xino"},
22865 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22866 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22867 + /* {Opt_zxino, "zxino=%s"}, */
22868 + {Opt_trunc_xib, "trunc_xib"},
22869 + {Opt_notrunc_xib, "notrunc_xib"},
22871 +#ifdef CONFIG_PROC_FS
22872 + {Opt_plink, "plink"},
22874 + {Opt_ignore_silent, "plink"},
22877 + {Opt_noplink, "noplink"},
22879 +#ifdef CONFIG_AUFS_DEBUG
22880 + {Opt_list_plink, "list_plink"},
22883 + {Opt_udba, "udba=%s"},
22885 + {Opt_dio, "dio"},
22886 + {Opt_nodio, "nodio"},
22888 +#ifdef CONFIG_AUFS_FHSM
22889 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22891 + {Opt_ignore_silent, "fhsm_sec=%d"},
22894 + {Opt_diropq_a, "diropq=always"},
22895 + {Opt_diropq_a, "diropq=a"},
22896 + {Opt_diropq_w, "diropq=whiteouted"},
22897 + {Opt_diropq_w, "diropq=w"},
22899 + {Opt_warn_perm, "warn_perm"},
22900 + {Opt_nowarn_perm, "nowarn_perm"},
22902 + /* keep them temporary */
22903 + {Opt_ignore_silent, "nodlgt"},
22904 + {Opt_ignore_silent, "clean_plink"},
22906 +#ifdef CONFIG_AUFS_SHWH
22907 + {Opt_shwh, "shwh"},
22909 + {Opt_noshwh, "noshwh"},
22911 + {Opt_dirperm1, "dirperm1"},
22912 + {Opt_nodirperm1, "nodirperm1"},
22914 + {Opt_verbose, "verbose"},
22915 + {Opt_verbose, "v"},
22916 + {Opt_noverbose, "noverbose"},
22917 + {Opt_noverbose, "quiet"},
22918 + {Opt_noverbose, "q"},
22919 + {Opt_noverbose, "silent"},
22921 + {Opt_sum, "sum"},
22922 + {Opt_nosum, "nosum"},
22923 + {Opt_wsum, "wsum"},
22925 + {Opt_rdcache, "rdcache=%d"},
22926 + {Opt_rdblk, "rdblk=%d"},
22927 + {Opt_rdblk_def, "rdblk=def"},
22928 + {Opt_rdhash, "rdhash=%d"},
22929 + {Opt_rdhash_def, "rdhash=def"},
22931 + {Opt_wbr_create, "create=%s"},
22932 + {Opt_wbr_create, "create_policy=%s"},
22933 + {Opt_wbr_copyup, "cpup=%s"},
22934 + {Opt_wbr_copyup, "copyup=%s"},
22935 + {Opt_wbr_copyup, "copyup_policy=%s"},
22937 + /* generic VFS flag */
22938 +#ifdef CONFIG_FS_POSIX_ACL
22939 + {Opt_acl, "acl"},
22940 + {Opt_noacl, "noacl"},
22942 + {Opt_ignore_silent, "acl"},
22943 + {Opt_ignore_silent, "noacl"},
22946 + /* internal use for the scripts */
22947 + {Opt_ignore_silent, "si=%s"},
22949 + {Opt_br, "dirs=%s"},
22950 + {Opt_ignore, "debug=%d"},
22951 + {Opt_ignore, "delete=whiteout"},
22952 + {Opt_ignore, "delete=all"},
22953 + {Opt_ignore, "imap=%s"},
22955 + /* temporary workaround, due to old mount(8)? */
22956 + {Opt_ignore_silent, "relatime"},
22961 +/* ---------------------------------------------------------------------- */
22963 +static const char *au_parser_pattern(int val, match_table_t tbl)
22965 + struct match_token *p;
22968 + while (p->pattern) {
22969 + if (p->token == val)
22970 + return p->pattern;
22977 +static const char *au_optstr(int *val, match_table_t tbl)
22979 + struct match_token *p;
22986 + while (p->pattern) {
22988 + && (v & p->token) == p->token) {
22989 + *val &= ~p->token;
22990 + return p->pattern;
22999 +/* ---------------------------------------------------------------------- */
23001 +static match_table_t brperm = {
23002 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23003 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23004 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23008 +static match_table_t brattr = {
23010 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23011 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23012 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23013 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23014 +#ifdef CONFIG_AUFS_FHSM
23015 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23017 +#ifdef CONFIG_AUFS_XATTR
23018 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23019 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23020 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23021 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23022 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23023 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23026 + /* ro/rr branch */
23027 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23030 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23031 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23036 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23043 + p = strchr(str, '+');
23046 + v = match_token(str, table, args);
23048 + if (v & AuBrAttr_CMOO_Mask)
23049 + attr &= ~AuBrAttr_CMOO_Mask;
23054 + pr_warn("ignored branch attribute %s\n", str);
23064 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23072 + p = au_optstr(&perm, brattr);
23075 + memcpy(q, p, sz + 1);
23081 + p = au_optstr(&perm, brattr);
23085 + memcpy(q, p, sz + 1);
23091 + return q - str->a;
23094 +static int noinline_for_stack br_perm_val(char *perm)
23096 + int val, bad, sz;
23098 + substring_t args[MAX_OPT_ARGS];
23099 + au_br_perm_str_t attr;
23101 + p = strchr(perm, '+');
23104 + val = match_token(perm, brperm, args);
23108 + pr_warn("ignored branch permission %s\n", perm);
23109 + val = AuBrPerm_RO;
23115 + val |= br_attr_val(p + 1, brattr, args);
23118 + switch (val & AuBrPerm_Mask) {
23119 + case AuBrPerm_RO:
23120 + case AuBrPerm_RR:
23121 + bad = val & AuBrWAttr_Mask;
23122 + val &= ~AuBrWAttr_Mask;
23124 + case AuBrPerm_RW:
23125 + bad = val & AuBrRAttr_Mask;
23126 + val &= ~AuBrRAttr_Mask;
23131 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23132 + * does not treat it as an error, just warning.
23133 + * this is a tiny guard for the user operation.
23135 + if (val & AuBrAttr_UNPIN) {
23136 + bad |= AuBrAttr_UNPIN;
23137 + val &= ~AuBrAttr_UNPIN;
23140 + if (unlikely(bad)) {
23141 + sz = au_do_optstr_br_attr(&attr, bad);
23143 + pr_warn("ignored branch attribute %s\n", attr.a);
23150 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23152 + au_br_perm_str_t attr;
23158 + p = au_optstr(&perm, brperm);
23159 + AuDebugOn(!p || !*p);
23161 + memcpy(q, p, sz + 1);
23164 + sz = au_do_optstr_br_attr(&attr, perm);
23167 + memcpy(q, attr.a, sz + 1);
23170 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23173 +/* ---------------------------------------------------------------------- */
23175 +static match_table_t udbalevel = {
23176 + {AuOpt_UDBA_REVAL, "reval"},
23177 + {AuOpt_UDBA_NONE, "none"},
23178 +#ifdef CONFIG_AUFS_HNOTIFY
23179 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23180 +#ifdef CONFIG_AUFS_HFSNOTIFY
23181 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23187 +static int noinline_for_stack udba_val(char *str)
23189 + substring_t args[MAX_OPT_ARGS];
23191 + return match_token(str, udbalevel, args);
23194 +const char *au_optstr_udba(int udba)
23196 + return au_parser_pattern(udba, udbalevel);
23199 +/* ---------------------------------------------------------------------- */
23201 +static match_table_t au_wbr_create_policy = {
23202 + {AuWbrCreate_TDP, "tdp"},
23203 + {AuWbrCreate_TDP, "top-down-parent"},
23204 + {AuWbrCreate_RR, "rr"},
23205 + {AuWbrCreate_RR, "round-robin"},
23206 + {AuWbrCreate_MFS, "mfs"},
23207 + {AuWbrCreate_MFS, "most-free-space"},
23208 + {AuWbrCreate_MFSV, "mfs:%d"},
23209 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23211 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23212 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23213 + {AuWbrCreate_PMFS, "pmfs"},
23214 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23215 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23216 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23222 + * cf. linux/lib/parser.c and cmdline.c
23223 + * gave up calling memparse() since it uses simple_strtoull() instead of
23226 +static int noinline_for_stack
23227 +au_match_ull(substring_t *s, unsigned long long *result)
23230 + unsigned int len;
23234 + len = s->to - s->from;
23235 + if (len + 1 <= sizeof(a)) {
23236 + memcpy(a, s->from, len);
23238 + err = kstrtoull(a, 0, result);
23243 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23244 + struct au_opt_wbr_create *create)
23247 + unsigned long long ull;
23250 + if (!au_match_ull(arg, &ull))
23251 + create->mfsrr_watermark = ull;
23253 + pr_err("bad integer in %s\n", str);
23260 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23261 + struct au_opt_wbr_create *create)
23266 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23267 + create->mfs_second = n;
23269 + pr_err("bad integer in %s\n", str);
23276 +static int noinline_for_stack
23277 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23280 + substring_t args[MAX_OPT_ARGS];
23282 + err = match_token(str, au_wbr_create_policy, args);
23283 + create->wbr_create = err;
23285 + case AuWbrCreate_MFSRRV:
23286 + case AuWbrCreate_PMFSRRV:
23287 + e = au_wbr_mfs_wmark(&args[0], str, create);
23289 + e = au_wbr_mfs_sec(&args[1], str, create);
23293 + case AuWbrCreate_MFSRR:
23294 + case AuWbrCreate_PMFSRR:
23295 + e = au_wbr_mfs_wmark(&args[0], str, create);
23296 + if (unlikely(e)) {
23301 + case AuWbrCreate_MFS:
23302 + case AuWbrCreate_PMFS:
23303 + create->mfs_second = AUFS_MFS_DEF_SEC;
23305 + case AuWbrCreate_MFSV:
23306 + case AuWbrCreate_PMFSV:
23307 + e = au_wbr_mfs_sec(&args[0], str, create);
23316 +const char *au_optstr_wbr_create(int wbr_create)
23318 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23321 +static match_table_t au_wbr_copyup_policy = {
23322 + {AuWbrCopyup_TDP, "tdp"},
23323 + {AuWbrCopyup_TDP, "top-down-parent"},
23324 + {AuWbrCopyup_BUP, "bup"},
23325 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23326 + {AuWbrCopyup_BU, "bu"},
23327 + {AuWbrCopyup_BU, "bottom-up"},
23331 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23333 + substring_t args[MAX_OPT_ARGS];
23335 + return match_token(str, au_wbr_copyup_policy, args);
23338 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23340 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23343 +/* ---------------------------------------------------------------------- */
23345 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23347 +static void dump_opts(struct au_opts *opts)
23349 +#ifdef CONFIG_AUFS_DEBUG
23350 + /* reduce stack space */
23352 + struct au_opt_add *add;
23353 + struct au_opt_del *del;
23354 + struct au_opt_mod *mod;
23355 + struct au_opt_xino *xino;
23356 + struct au_opt_xino_itrunc *xino_itrunc;
23357 + struct au_opt_wbr_create *create;
23359 + struct au_opt *opt;
23362 + while (opt->type != Opt_tail) {
23363 + switch (opt->type) {
23365 + u.add = &opt->add;
23366 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23367 + u.add->bindex, u.add->pathname, u.add->perm,
23368 + u.add->path.dentry);
23372 + u.del = &opt->del;
23373 + AuDbg("del {%s, %p}\n",
23374 + u.del->pathname, u.del->h_path.dentry);
23378 + u.mod = &opt->mod;
23379 + AuDbg("mod {%s, 0x%x, %p}\n",
23380 + u.mod->path, u.mod->perm, u.mod->h_root);
23383 + u.add = &opt->add;
23384 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23385 + u.add->bindex, u.add->pathname, u.add->perm,
23386 + u.add->path.dentry);
23388 + case Opt_prepend:
23389 + u.add = &opt->add;
23390 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23391 + u.add->bindex, u.add->pathname, u.add->perm,
23392 + u.add->path.dentry);
23395 + AuDbg("dirwh %d\n", opt->dirwh);
23397 + case Opt_rdcache:
23398 + AuDbg("rdcache %d\n", opt->rdcache);
23401 + AuDbg("rdblk %u\n", opt->rdblk);
23403 + case Opt_rdblk_def:
23404 + AuDbg("rdblk_def\n");
23407 + AuDbg("rdhash %u\n", opt->rdhash);
23409 + case Opt_rdhash_def:
23410 + AuDbg("rdhash_def\n");
23413 + u.xino = &opt->xino;
23414 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23416 + case Opt_trunc_xino:
23417 + AuLabel(trunc_xino);
23419 + case Opt_notrunc_xino:
23420 + AuLabel(notrunc_xino);
23422 + case Opt_trunc_xino_path:
23423 + case Opt_itrunc_xino:
23424 + u.xino_itrunc = &opt->xino_itrunc;
23425 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23430 + case Opt_trunc_xib:
23431 + AuLabel(trunc_xib);
23433 + case Opt_notrunc_xib:
23434 + AuLabel(notrunc_xib);
23442 + case Opt_dirperm1:
23443 + AuLabel(dirperm1);
23445 + case Opt_nodirperm1:
23446 + AuLabel(nodirperm1);
23451 + case Opt_noplink:
23452 + AuLabel(noplink);
23454 + case Opt_list_plink:
23455 + AuLabel(list_plink);
23458 + AuDbg("udba %d, %s\n",
23459 + opt->udba, au_optstr_udba(opt->udba));
23467 + case Opt_diropq_a:
23468 + AuLabel(diropq_a);
23470 + case Opt_diropq_w:
23471 + AuLabel(diropq_w);
23473 + case Opt_warn_perm:
23474 + AuLabel(warn_perm);
23476 + case Opt_nowarn_perm:
23477 + AuLabel(nowarn_perm);
23479 + case Opt_verbose:
23480 + AuLabel(verbose);
23482 + case Opt_noverbose:
23483 + AuLabel(noverbose);
23494 + case Opt_wbr_create:
23495 + u.create = &opt->wbr_create;
23496 + AuDbg("create %d, %s\n", u.create->wbr_create,
23497 + au_optstr_wbr_create(u.create->wbr_create));
23498 + switch (u.create->wbr_create) {
23499 + case AuWbrCreate_MFSV:
23500 + case AuWbrCreate_PMFSV:
23501 + AuDbg("%d sec\n", u.create->mfs_second);
23503 + case AuWbrCreate_MFSRR:
23504 + AuDbg("%llu watermark\n",
23505 + u.create->mfsrr_watermark);
23507 + case AuWbrCreate_MFSRRV:
23508 + case AuWbrCreate_PMFSRRV:
23509 + AuDbg("%llu watermark, %d sec\n",
23510 + u.create->mfsrr_watermark,
23511 + u.create->mfs_second);
23515 + case Opt_wbr_copyup:
23516 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23517 + au_optstr_wbr_copyup(opt->wbr_copyup));
23519 + case Opt_fhsm_sec:
23520 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23536 +void au_opts_free(struct au_opts *opts)
23538 + struct au_opt *opt;
23541 + while (opt->type != Opt_tail) {
23542 + switch (opt->type) {
23545 + case Opt_prepend:
23546 + path_put(&opt->add.path);
23550 + path_put(&opt->del.h_path);
23554 + dput(opt->mod.h_root);
23557 + fput(opt->xino.file);
23564 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23565 + aufs_bindex_t bindex)
23568 + struct au_opt_add *add = &opt->add;
23571 + add->bindex = bindex;
23572 + add->perm = AuBrPerm_RO;
23573 + add->pathname = opt_str;
23574 + p = strchr(opt_str, '=');
23578 + add->perm = br_perm_val(p);
23581 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23584 + add->perm = AuBrPerm_RO;
23585 + if (au_test_fs_rr(add->path.dentry->d_sb))
23586 + add->perm = AuBrPerm_RR;
23587 + else if (!bindex && !(sb_flags & MS_RDONLY))
23588 + add->perm = AuBrPerm_RW;
23590 + opt->type = Opt_add;
23593 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23600 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23604 + del->pathname = args[0].from;
23605 + AuDbg("del path %s\n", del->pathname);
23607 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23608 + if (unlikely(err))
23609 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23614 +#if 0 /* reserved for future use */
23615 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23616 + struct au_opt_del *del, substring_t args[])
23619 + struct dentry *root;
23622 + root = sb->s_root;
23623 + aufs_read_lock(root, AuLock_FLUSH);
23624 + if (bindex < 0 || au_sbend(sb) < bindex) {
23625 + pr_err("out of bounds, %d\n", bindex);
23630 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
23631 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
23634 + aufs_read_unlock(root, !AuLock_IR);
23639 +static int noinline_for_stack
23640 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
23643 + struct path path;
23647 + mod->path = args[0].from;
23648 + p = strchr(mod->path, '=');
23649 + if (unlikely(!p)) {
23650 + pr_err("no permssion %s\n", args[0].from);
23655 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
23656 + if (unlikely(err)) {
23657 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23661 + mod->perm = br_perm_val(p);
23662 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23663 + mod->h_root = dget(path.dentry);
23670 +#if 0 /* reserved for future use */
23671 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23672 + struct au_opt_mod *mod, substring_t args[])
23675 + struct dentry *root;
23678 + root = sb->s_root;
23679 + aufs_read_lock(root, AuLock_FLUSH);
23680 + if (bindex < 0 || au_sbend(sb) < bindex) {
23681 + pr_err("out of bounds, %d\n", bindex);
23686 + mod->perm = br_perm_val(args[1].from);
23687 + AuDbg("mod path %s, perm 0x%x, %s\n",
23688 + mod->path, mod->perm, args[1].from);
23689 + mod->h_root = dget(au_h_dptr(root, bindex));
23692 + aufs_read_unlock(root, !AuLock_IR);
23697 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23698 + substring_t args[])
23701 + struct file *file;
23703 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23704 + err = PTR_ERR(file);
23705 + if (IS_ERR(file))
23709 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
23711 + pr_err("%s must be outside\n", args[0].from);
23716 + xino->file = file;
23717 + xino->path = args[0].from;
23723 +static int noinline_for_stack
23724 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23725 + struct au_opt_xino_itrunc *xino_itrunc,
23726 + substring_t args[])
23729 + aufs_bindex_t bend, bindex;
23730 + struct path path;
23731 + struct dentry *root;
23733 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23734 + if (unlikely(err)) {
23735 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23739 + xino_itrunc->bindex = -1;
23740 + root = sb->s_root;
23741 + aufs_read_lock(root, AuLock_FLUSH);
23742 + bend = au_sbend(sb);
23743 + for (bindex = 0; bindex <= bend; bindex++) {
23744 + if (au_h_dptr(root, bindex) == path.dentry) {
23745 + xino_itrunc->bindex = bindex;
23749 + aufs_read_unlock(root, !AuLock_IR);
23752 + if (unlikely(xino_itrunc->bindex < 0)) {
23753 + pr_err("no such branch %s\n", args[0].from);
23761 +/* called without aufs lock */
23762 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23764 + int err, n, token;
23765 + aufs_bindex_t bindex;
23766 + unsigned char skipped;
23767 + struct dentry *root;
23768 + struct au_opt *opt, *opt_tail;
23770 + /* reduce the stack space */
23772 + struct au_opt_xino_itrunc *xino_itrunc;
23773 + struct au_opt_wbr_create *create;
23776 + substring_t args[MAX_OPT_ARGS];
23780 + a = kmalloc(sizeof(*a), GFP_NOFS);
23781 + if (unlikely(!a))
23784 + root = sb->s_root;
23788 + opt_tail = opt + opts->max_opt - 1;
23789 + opt->type = Opt_tail;
23790 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23793 + token = match_token(opt_str, options, a->args);
23797 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23799 + err = opt_add(opt, opt_str, opts->sb_flags,
23801 + if (unlikely(!err && ++opt > opt_tail)) {
23805 + opt->type = Opt_tail;
23810 + if (unlikely(match_int(&a->args[0], &n))) {
23811 + pr_err("bad integer in %s\n", opt_str);
23815 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23818 + opt->type = token;
23821 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23822 + /*dummy bindex*/1);
23824 + opt->type = token;
23826 + case Opt_prepend:
23827 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23830 + opt->type = token;
23833 + err = au_opts_parse_del(&opt->del, a->args);
23835 + opt->type = token;
23837 +#if 0 /* reserved for future use */
23839 + del->pathname = "(indexed)";
23840 + if (unlikely(match_int(&args[0], &n))) {
23841 + pr_err("bad integer in %s\n", opt_str);
23844 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23846 + opt->type = token;
23850 + err = au_opts_parse_mod(&opt->mod, a->args);
23852 + opt->type = token;
23854 +#ifdef IMOD /* reserved for future use */
23856 + u.mod->path = "(indexed)";
23857 + if (unlikely(match_int(&a->args[0], &n))) {
23858 + pr_err("bad integer in %s\n", opt_str);
23861 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23863 + opt->type = token;
23867 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23869 + opt->type = token;
23872 + case Opt_trunc_xino_path:
23873 + err = au_opts_parse_xino_itrunc_path
23874 + (sb, &opt->xino_itrunc, a->args);
23876 + opt->type = token;
23879 + case Opt_itrunc_xino:
23880 + u.xino_itrunc = &opt->xino_itrunc;
23881 + if (unlikely(match_int(&a->args[0], &n))) {
23882 + pr_err("bad integer in %s\n", opt_str);
23885 + u.xino_itrunc->bindex = n;
23886 + aufs_read_lock(root, AuLock_FLUSH);
23887 + if (n < 0 || au_sbend(sb) < n) {
23888 + pr_err("out of bounds, %d\n", n);
23889 + aufs_read_unlock(root, !AuLock_IR);
23892 + aufs_read_unlock(root, !AuLock_IR);
23894 + opt->type = token;
23898 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23901 + opt->type = token;
23904 + case Opt_rdcache:
23905 + if (unlikely(match_int(&a->args[0], &n))) {
23906 + pr_err("bad integer in %s\n", opt_str);
23909 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23910 + pr_err("rdcache must be smaller than %d\n",
23911 + AUFS_RDCACHE_MAX);
23914 + opt->rdcache = n;
23916 + opt->type = token;
23919 + if (unlikely(match_int(&a->args[0], &n)
23921 + || n > KMALLOC_MAX_SIZE)) {
23922 + pr_err("bad integer in %s\n", opt_str);
23925 + if (unlikely(n && n < NAME_MAX)) {
23926 + pr_err("rdblk must be larger than %d\n",
23932 + opt->type = token;
23935 + if (unlikely(match_int(&a->args[0], &n)
23937 + || n * sizeof(struct hlist_head)
23938 + > KMALLOC_MAX_SIZE)) {
23939 + pr_err("bad integer in %s\n", opt_str);
23944 + opt->type = token;
23947 + case Opt_trunc_xino:
23948 + case Opt_notrunc_xino:
23950 + case Opt_trunc_xib:
23951 + case Opt_notrunc_xib:
23954 + case Opt_dirperm1:
23955 + case Opt_nodirperm1:
23957 + case Opt_noplink:
23958 + case Opt_list_plink:
23961 + case Opt_diropq_a:
23962 + case Opt_diropq_w:
23963 + case Opt_warn_perm:
23964 + case Opt_nowarn_perm:
23965 + case Opt_verbose:
23966 + case Opt_noverbose:
23970 + case Opt_rdblk_def:
23971 + case Opt_rdhash_def:
23975 + opt->type = token;
23979 + opt->udba = udba_val(a->args[0].from);
23980 + if (opt->udba >= 0) {
23982 + opt->type = token;
23984 + pr_err("wrong value, %s\n", opt_str);
23987 + case Opt_wbr_create:
23988 + u.create = &opt->wbr_create;
23989 + u.create->wbr_create
23990 + = au_wbr_create_val(a->args[0].from, u.create);
23991 + if (u.create->wbr_create >= 0) {
23993 + opt->type = token;
23995 + pr_err("wrong value, %s\n", opt_str);
23997 + case Opt_wbr_copyup:
23998 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23999 + if (opt->wbr_copyup >= 0) {
24001 + opt->type = token;
24003 + pr_err("wrong value, %s\n", opt_str);
24006 + case Opt_fhsm_sec:
24007 + if (unlikely(match_int(&a->args[0], &n)
24009 + pr_err("bad integer in %s\n", opt_str);
24012 + if (sysaufs_brs) {
24013 + opt->fhsm_second = n;
24014 + opt->type = token;
24016 + pr_warn("ignored %s\n", opt_str);
24021 + pr_warn("ignored %s\n", opt_str);
24023 + case Opt_ignore_silent:
24028 + pr_err("unknown option %s\n", opt_str);
24032 + if (!err && !skipped) {
24033 + if (unlikely(++opt > opt_tail)) {
24036 + opt->type = Opt_tail;
24039 + opt->type = Opt_tail;
24045 + if (unlikely(err))
24046 + au_opts_free(opts);
24052 +static int au_opt_wbr_create(struct super_block *sb,
24053 + struct au_opt_wbr_create *create)
24056 + struct au_sbinfo *sbinfo;
24058 + SiMustWriteLock(sb);
24060 + err = 1; /* handled */
24061 + sbinfo = au_sbi(sb);
24062 + if (sbinfo->si_wbr_create_ops->fin) {
24063 + err = sbinfo->si_wbr_create_ops->fin(sb);
24068 + sbinfo->si_wbr_create = create->wbr_create;
24069 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24070 + switch (create->wbr_create) {
24071 + case AuWbrCreate_MFSRRV:
24072 + case AuWbrCreate_MFSRR:
24073 + case AuWbrCreate_PMFSRR:
24074 + case AuWbrCreate_PMFSRRV:
24075 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24077 + case AuWbrCreate_MFS:
24078 + case AuWbrCreate_MFSV:
24079 + case AuWbrCreate_PMFS:
24080 + case AuWbrCreate_PMFSV:
24081 + sbinfo->si_wbr_mfs.mfs_expire
24082 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24086 + if (sbinfo->si_wbr_create_ops->init)
24087 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24094 + * plus: processed without an error
24095 + * zero: unprocessed
24097 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24098 + struct au_opts *opts)
24101 + struct au_sbinfo *sbinfo;
24103 + SiMustWriteLock(sb);
24105 + err = 1; /* handled */
24106 + sbinfo = au_sbi(sb);
24107 + switch (opt->type) {
24109 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24110 + sbinfo->si_mntflags |= opt->udba;
24111 + opts->given_udba |= opt->udba;
24115 + au_opt_set(sbinfo->si_mntflags, PLINK);
24117 + case Opt_noplink:
24118 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24119 + au_plink_put(sb, /*verbose*/1);
24120 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24122 + case Opt_list_plink:
24123 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24124 + au_plink_list(sb);
24128 + au_opt_set(sbinfo->si_mntflags, DIO);
24129 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24132 + au_opt_clr(sbinfo->si_mntflags, DIO);
24133 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24136 + case Opt_fhsm_sec:
24137 + au_fhsm_set(sbinfo, opt->fhsm_second);
24140 + case Opt_diropq_a:
24141 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24143 + case Opt_diropq_w:
24144 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24147 + case Opt_warn_perm:
24148 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24150 + case Opt_nowarn_perm:
24151 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24154 + case Opt_verbose:
24155 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24157 + case Opt_noverbose:
24158 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24162 + au_opt_set(sbinfo->si_mntflags, SUM);
24165 + au_opt_clr(sbinfo->si_mntflags, SUM);
24166 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24168 + au_opt_clr(sbinfo->si_mntflags, SUM);
24169 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24172 + case Opt_wbr_create:
24173 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24175 + case Opt_wbr_copyup:
24176 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24177 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24181 + sbinfo->si_dirwh = opt->dirwh;
24184 + case Opt_rdcache:
24185 + sbinfo->si_rdcache
24186 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24189 + sbinfo->si_rdblk = opt->rdblk;
24191 + case Opt_rdblk_def:
24192 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24195 + sbinfo->si_rdhash = opt->rdhash;
24197 + case Opt_rdhash_def:
24198 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24202 + au_opt_set(sbinfo->si_mntflags, SHWH);
24205 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24208 + case Opt_dirperm1:
24209 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24211 + case Opt_nodirperm1:
24212 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24215 + case Opt_trunc_xino:
24216 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24218 + case Opt_notrunc_xino:
24219 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24222 + case Opt_trunc_xino_path:
24223 + case Opt_itrunc_xino:
24224 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24229 + case Opt_trunc_xib:
24230 + au_fset_opts(opts->flags, TRUNC_XIB);
24232 + case Opt_notrunc_xib:
24233 + au_fclr_opts(opts->flags, TRUNC_XIB);
24237 + sb->s_flags |= MS_POSIXACL;
24240 + sb->s_flags &= ~MS_POSIXACL;
24252 + * returns tri-state.
24253 + * plus: processed without an error
24254 + * zero: unprocessed
24257 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24258 + struct au_opts *opts)
24260 + int err, do_refresh;
24263 + switch (opt->type) {
24265 + opt->add.bindex = au_sbend(sb) + 1;
24266 + if (opt->add.bindex < 0)
24267 + opt->add.bindex = 0;
24269 + case Opt_prepend:
24270 + opt->add.bindex = 0;
24271 + add: /* indented label */
24273 + err = au_br_add(sb, &opt->add,
24274 + au_ftest_opts(opts->flags, REMOUNT));
24277 + au_fset_opts(opts->flags, REFRESH);
24283 + err = au_br_del(sb, &opt->del,
24284 + au_ftest_opts(opts->flags, REMOUNT));
24287 + au_fset_opts(opts->flags, TRUNC_XIB);
24288 + au_fset_opts(opts->flags, REFRESH);
24294 + err = au_br_mod(sb, &opt->mod,
24295 + au_ftest_opts(opts->flags, REMOUNT),
24300 + au_fset_opts(opts->flags, REFRESH);
24308 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24309 + struct au_opt_xino **opt_xino,
24310 + struct au_opts *opts)
24313 + aufs_bindex_t bend, bindex;
24314 + struct dentry *root, *parent, *h_root;
24317 + switch (opt->type) {
24319 + err = au_xino_set(sb, &opt->xino,
24320 + !!au_ftest_opts(opts->flags, REMOUNT));
24321 + if (unlikely(err))
24324 + *opt_xino = &opt->xino;
24325 + au_xino_brid_set(sb, -1);
24327 + /* safe d_parent access */
24328 + parent = opt->xino.file->f_path.dentry->d_parent;
24329 + root = sb->s_root;
24330 + bend = au_sbend(sb);
24331 + for (bindex = 0; bindex <= bend; bindex++) {
24332 + h_root = au_h_dptr(root, bindex);
24333 + if (h_root == parent) {
24334 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24342 + au_xino_brid_set(sb, -1);
24343 + *opt_xino = (void *)-1;
24350 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24351 + unsigned int pending)
24354 + aufs_bindex_t bindex, bend;
24355 + unsigned char do_plink, skip, do_free, can_no_dreval;
24356 + struct au_branch *br;
24357 + struct au_wbr *wbr;
24358 + struct dentry *root, *dentry;
24359 + struct inode *dir, *h_dir;
24360 + struct au_sbinfo *sbinfo;
24361 + struct au_hinode *hdir;
24363 + SiMustAnyLock(sb);
24365 + sbinfo = au_sbi(sb);
24366 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24368 + if (!(sb_flags & MS_RDONLY)) {
24369 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24370 + pr_warn("first branch should be rw\n");
24371 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24372 + pr_warn_once("shwh should be used with ro\n");
24375 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24376 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24377 + pr_warn_once("udba=*notify requires xino\n");
24379 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24380 + pr_warn_once("dirperm1 breaks the protection"
24381 + " by the permission bits on the lower branch\n");
24385 + root = sb->s_root;
24386 + dir = d_inode(root);
24387 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24388 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24390 + bend = au_sbend(sb);
24391 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24393 + h_dir = au_h_iptr(dir, bindex);
24394 + br = au_sbr(sb, bindex);
24396 + if ((br->br_perm & AuBrAttr_ICEX)
24397 + && !h_dir->i_op->listxattr)
24398 + br->br_perm &= ~AuBrAttr_ICEX;
24400 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24401 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24402 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24406 + wbr = br->br_wbr;
24408 + wbr_wh_read_lock(wbr);
24410 + if (!au_br_writable(br->br_perm)) {
24413 + || (!wbr->wbr_whbase
24414 + && !wbr->wbr_plink
24415 + && !wbr->wbr_orph));
24416 + } else if (!au_br_wh_linkable(br->br_perm)) {
24417 + /* skip = (!br->br_whbase && !br->br_orph); */
24418 + skip = (!wbr || !wbr->wbr_whbase);
24419 + if (skip && wbr) {
24421 + skip = !!wbr->wbr_plink;
24423 + skip = !wbr->wbr_plink;
24426 + /* skip = (br->br_whbase && br->br_ohph); */
24427 + skip = (wbr && wbr->wbr_whbase);
24430 + skip = !!wbr->wbr_plink;
24432 + skip = !wbr->wbr_plink;
24436 + wbr_wh_read_unlock(wbr);
24438 + if (can_no_dreval) {
24439 + dentry = br->br_path.dentry;
24440 + spin_lock(&dentry->d_lock);
24441 + if (dentry->d_flags &
24442 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24443 + can_no_dreval = 0;
24444 + spin_unlock(&dentry->d_lock);
24447 + if (au_br_fhsm(br->br_perm)) {
24449 + AuDebugOn(!br->br_fhsm);
24455 + hdir = au_hi(dir, bindex);
24456 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
24458 + wbr_wh_write_lock(wbr);
24459 + err = au_wh_init(br, sb);
24461 + wbr_wh_write_unlock(wbr);
24462 + au_hn_imtx_unlock(hdir);
24464 + if (!err && do_free) {
24466 + br->br_wbr = NULL;
24470 + if (can_no_dreval)
24471 + au_fset_si(sbinfo, NO_DREVAL);
24473 + au_fclr_si(sbinfo, NO_DREVAL);
24476 + au_fset_si(sbinfo, FHSM);
24477 + for (bindex = bend; bindex >= 0; bindex--) {
24478 + br = au_sbr(sb, bindex);
24479 + if (au_br_fhsm(br->br_perm)) {
24480 + au_fhsm_set_bottom(sb, bindex);
24485 + au_fclr_si(sbinfo, FHSM);
24486 + au_fhsm_set_bottom(sb, -1);
24492 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24495 + unsigned int tmp;
24496 + aufs_bindex_t bindex, bend;
24497 + struct au_opt *opt;
24498 + struct au_opt_xino *opt_xino, xino;
24499 + struct au_sbinfo *sbinfo;
24500 + struct au_branch *br;
24501 + struct inode *dir;
24503 + SiMustWriteLock(sb);
24508 + while (err >= 0 && opt->type != Opt_tail)
24509 + err = au_opt_simple(sb, opt++, opts);
24512 + else if (unlikely(err < 0))
24515 + /* disable xino and udba temporary */
24516 + sbinfo = au_sbi(sb);
24517 + tmp = sbinfo->si_mntflags;
24518 + au_opt_clr(sbinfo->si_mntflags, XINO);
24519 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24522 + while (err >= 0 && opt->type != Opt_tail)
24523 + err = au_opt_br(sb, opt++, opts);
24526 + else if (unlikely(err < 0))
24529 + bend = au_sbend(sb);
24530 + if (unlikely(bend < 0)) {
24532 + pr_err("no branches\n");
24536 + if (au_opt_test(tmp, XINO))
24537 + au_opt_set(sbinfo->si_mntflags, XINO);
24539 + while (!err && opt->type != Opt_tail)
24540 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24541 + if (unlikely(err))
24544 + err = au_opts_verify(sb, sb->s_flags, tmp);
24545 + if (unlikely(err))
24548 + /* restore xino */
24549 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24550 + xino.file = au_xino_def(sb);
24551 + err = PTR_ERR(xino.file);
24552 + if (IS_ERR(xino.file))
24555 + err = au_xino_set(sb, &xino, /*remount*/0);
24557 + if (unlikely(err))
24561 + /* restore udba */
24562 + tmp &= AuOptMask_UDBA;
24563 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24564 + sbinfo->si_mntflags |= tmp;
24565 + bend = au_sbend(sb);
24566 + for (bindex = 0; bindex <= bend; bindex++) {
24567 + br = au_sbr(sb, bindex);
24568 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24569 + if (unlikely(err))
24570 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24572 + /* go on even if err */
24574 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24575 + dir = d_inode(sb->s_root);
24576 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24583 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24586 + unsigned char no_dreval;
24587 + struct inode *dir;
24588 + struct au_opt_xino *opt_xino;
24589 + struct au_opt *opt;
24590 + struct au_sbinfo *sbinfo;
24592 + SiMustWriteLock(sb);
24595 + dir = d_inode(sb->s_root);
24596 + sbinfo = au_sbi(sb);
24599 + while (err >= 0 && opt->type != Opt_tail) {
24600 + err = au_opt_simple(sb, opt, opts);
24602 + err = au_opt_br(sb, opt, opts);
24604 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24610 + /* go on even err */
24612 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
24613 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24614 + if (unlikely(rerr && !err))
24617 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
24618 + au_fset_opts(opts->flags, REFRESH_IDOP);
24620 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24621 + rerr = au_xib_trunc(sb);
24622 + if (unlikely(rerr && !err))
24626 + /* will be handled by the caller */
24627 + if (!au_ftest_opts(opts->flags, REFRESH)
24628 + && (opts->given_udba
24629 + || au_opt_test(sbinfo->si_mntflags, XINO)
24630 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
24632 + au_fset_opts(opts->flags, REFRESH);
24634 + AuDbg("status 0x%x\n", opts->flags);
24638 +/* ---------------------------------------------------------------------- */
24640 +unsigned int au_opt_udba(struct super_block *sb)
24642 + return au_mntflags(sb) & AuOptMask_UDBA;
24644 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
24645 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
24646 +++ linux/fs/aufs/opts.h 2016-04-24 18:32:51.393686895 +0200
24649 + * Copyright (C) 2005-2016 Junjiro R. Okajima
24651 + * This program, aufs is free software; you can redistribute it and/or modify
24652 + * it under the terms of the GNU General Public License as published by
24653 + * the Free Software Foundation; either version 2 of the License, or
24654 + * (at your option) any later version.
24656 + * This program is distributed in the hope that it will be useful,
24657 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24658 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24659 + * GNU General Public License for more details.
24661 + * You should have received a copy of the GNU General Public License
24662 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24666 + * mount options/flags
24669 +#ifndef __AUFS_OPTS_H__
24670 +#define __AUFS_OPTS_H__
24674 +#include <linux/path.h>
24677 +struct super_block;
24679 +/* ---------------------------------------------------------------------- */
24682 +#define AuOpt_XINO 1 /* external inode number bitmap
24683 + and translation table */
24684 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24685 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24686 +#define AuOpt_UDBA_REVAL (1 << 3)
24687 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24688 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24689 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24690 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24692 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24693 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24694 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24695 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24696 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24697 +#define AuOpt_DIO (1 << 14) /* direct io */
24699 +#ifndef CONFIG_AUFS_HNOTIFY
24700 +#undef AuOpt_UDBA_HNOTIFY
24701 +#define AuOpt_UDBA_HNOTIFY 0
24703 +#ifndef CONFIG_AUFS_SHWH
24705 +#define AuOpt_SHWH 0
24708 +#define AuOpt_Def (AuOpt_XINO \
24709 + | AuOpt_UDBA_REVAL \
24711 + /* | AuOpt_DIRPERM1 */ \
24712 + | AuOpt_WARN_PERM)
24713 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24714 + | AuOpt_UDBA_REVAL \
24715 + | AuOpt_UDBA_HNOTIFY)
24717 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24718 +#define au_opt_set(flags, name) do { \
24719 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24720 + ((flags) |= AuOpt_##name); \
24722 +#define au_opt_set_udba(flags, name) do { \
24723 + (flags) &= ~AuOptMask_UDBA; \
24724 + ((flags) |= AuOpt_##name); \
24726 +#define au_opt_clr(flags, name) do { \
24727 + ((flags) &= ~AuOpt_##name); \
24730 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24732 +#ifdef CONFIG_PROC_FS
24735 + return mntflags & ~AuOpt_PLINK;
24739 +/* ---------------------------------------------------------------------- */
24741 +/* policies to select one among multiple writable branches */
24743 + AuWbrCreate_TDP, /* top down parent */
24744 + AuWbrCreate_RR, /* round robin */
24745 + AuWbrCreate_MFS, /* most free space */
24746 + AuWbrCreate_MFSV, /* mfs with seconds */
24747 + AuWbrCreate_MFSRR, /* mfs then rr */
24748 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24749 + AuWbrCreate_PMFS, /* parent and mfs */
24750 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24751 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24752 + AuWbrCreate_PMFSRRV, /* plus seconds */
24754 + AuWbrCreate_Def = AuWbrCreate_TDP
24758 + AuWbrCopyup_TDP, /* top down parent */
24759 + AuWbrCopyup_BUP, /* bottom up parent */
24760 + AuWbrCopyup_BU, /* bottom up */
24762 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24765 +/* ---------------------------------------------------------------------- */
24767 +struct au_opt_add {
24768 + aufs_bindex_t bindex;
24771 + struct path path;
24774 +struct au_opt_del {
24776 + struct path h_path;
24779 +struct au_opt_mod {
24782 + struct dentry *h_root;
24785 +struct au_opt_xino {
24787 + struct file *file;
24790 +struct au_opt_xino_itrunc {
24791 + aufs_bindex_t bindex;
24794 +struct au_opt_wbr_create {
24797 + unsigned long long mfsrr_watermark;
24803 + struct au_opt_xino xino;
24804 + struct au_opt_xino_itrunc xino_itrunc;
24805 + struct au_opt_add add;
24806 + struct au_opt_del del;
24807 + struct au_opt_mod mod;
24810 + unsigned int rdblk;
24811 + unsigned int rdhash;
24813 + struct au_opt_wbr_create wbr_create;
24815 + unsigned int fhsm_second;
24820 +#define AuOpts_REMOUNT 1
24821 +#define AuOpts_REFRESH (1 << 1)
24822 +#define AuOpts_TRUNC_XIB (1 << 2)
24823 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24824 +#define AuOpts_REFRESH_IDOP (1 << 4)
24825 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24826 +#define au_fset_opts(flags, name) \
24827 + do { (flags) |= AuOpts_##name; } while (0)
24828 +#define au_fclr_opts(flags, name) \
24829 + do { (flags) &= ~AuOpts_##name; } while (0)
24832 + struct au_opt *opt;
24835 + unsigned int given_udba;
24836 + unsigned int flags;
24837 + unsigned long sb_flags;
24840 +/* ---------------------------------------------------------------------- */
24843 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24844 +const char *au_optstr_udba(int udba);
24845 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24846 +const char *au_optstr_wbr_create(int wbr_create);
24848 +void au_opts_free(struct au_opts *opts);
24849 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24850 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24851 + unsigned int pending);
24852 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24853 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24855 +unsigned int au_opt_udba(struct super_block *sb);
24857 +#endif /* __KERNEL__ */
24858 +#endif /* __AUFS_OPTS_H__ */
24859 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24860 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24861 +++ linux/fs/aufs/plink.c 2016-04-24 18:32:51.393686895 +0200
24864 + * Copyright (C) 2005-2016 Junjiro R. Okajima
24866 + * This program, aufs is free software; you can redistribute it and/or modify
24867 + * it under the terms of the GNU General Public License as published by
24868 + * the Free Software Foundation; either version 2 of the License, or
24869 + * (at your option) any later version.
24871 + * This program is distributed in the hope that it will be useful,
24872 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24873 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24874 + * GNU General Public License for more details.
24876 + * You should have received a copy of the GNU General Public License
24877 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24887 + * the pseudo-link maintenance mode.
24888 + * during a user process maintains the pseudo-links,
24889 + * prohibit adding a new plink and branch manipulation.
24893 + * For entry functions which will handle plink, and i_mutex is already held
24895 + * They cannot wait and should return an error at once.
24896 + * Callers has to check the error.
24898 + * For entry functions which will handle plink, but i_mutex is not held
24900 + * They can wait the plink maintenance mode to finish.
24902 + * They behave like F_SETLK and F_SETLKW.
24903 + * If the caller never handle plink, then both flags are unnecessary.
24906 +int au_plink_maint(struct super_block *sb, int flags)
24910 + struct au_sbinfo *sbi;
24912 + SiMustAnyLock(sb);
24915 + if (!au_opt_test(au_mntflags(sb), PLINK))
24918 + sbi = au_sbi(sb);
24919 + pid = sbi->si_plink_maint_pid;
24920 + if (!pid || pid == current->pid)
24923 + /* todo: it highly depends upon /sbin/mount.aufs */
24925 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24926 + rcu_read_unlock();
24930 + if (au_ftest_lock(flags, NOPLMW)) {
24931 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24932 + /* AuDebugOn(!lockdep_depth(current)); */
24933 + while (sbi->si_plink_maint_pid) {
24934 + si_read_unlock(sb);
24935 + /* gave up wake_up_bit() */
24936 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24938 + if (au_ftest_lock(flags, FLUSH))
24939 + au_nwt_flush(&sbi->si_nowait);
24940 + si_noflush_read_lock(sb);
24942 + } else if (au_ftest_lock(flags, NOPLM)) {
24943 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24951 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24953 + spin_lock(&sbinfo->si_plink_maint_lock);
24954 + sbinfo->si_plink_maint_pid = 0;
24955 + spin_unlock(&sbinfo->si_plink_maint_lock);
24956 + wake_up_all(&sbinfo->si_plink_wq);
24959 +int au_plink_maint_enter(struct super_block *sb)
24962 + struct au_sbinfo *sbinfo;
24965 + sbinfo = au_sbi(sb);
24966 + /* make sure i am the only one in this fs */
24967 + si_write_lock(sb, AuLock_FLUSH);
24968 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24969 + spin_lock(&sbinfo->si_plink_maint_lock);
24970 + if (!sbinfo->si_plink_maint_pid)
24971 + sbinfo->si_plink_maint_pid = current->pid;
24974 + spin_unlock(&sbinfo->si_plink_maint_lock);
24976 + si_write_unlock(sb);
24981 +/* ---------------------------------------------------------------------- */
24983 +#ifdef CONFIG_AUFS_DEBUG
24984 +void au_plink_list(struct super_block *sb)
24987 + struct au_sbinfo *sbinfo;
24988 + struct hlist_head *plink_hlist;
24989 + struct pseudo_link *plink;
24991 + SiMustAnyLock(sb);
24993 + sbinfo = au_sbi(sb);
24994 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24995 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24997 + for (i = 0; i < AuPlink_NHASH; i++) {
24998 + plink_hlist = &sbinfo->si_plink[i].head;
25000 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
25001 + AuDbg("%lu\n", plink->inode->i_ino);
25002 + rcu_read_unlock();
25007 +/* is the inode pseudo-linked? */
25008 +int au_plink_test(struct inode *inode)
25011 + struct au_sbinfo *sbinfo;
25012 + struct hlist_head *plink_hlist;
25013 + struct pseudo_link *plink;
25015 + sbinfo = au_sbi(inode->i_sb);
25016 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25017 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25018 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25021 + i = au_plink_hash(inode->i_ino);
25022 + plink_hlist = &sbinfo->si_plink[i].head;
25024 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
25025 + if (plink->inode == inode) {
25029 + rcu_read_unlock();
25033 +/* ---------------------------------------------------------------------- */
25036 + * generate a name for plink.
25037 + * the file will be stored under AUFS_WH_PLINKDIR.
25039 +/* 20 is max digits length of ulong 64 */
25040 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25042 +static int plink_name(char *name, int len, struct inode *inode,
25043 + aufs_bindex_t bindex)
25046 + struct inode *h_inode;
25048 + h_inode = au_h_iptr(inode, bindex);
25049 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25053 +struct au_do_plink_lkup_args {
25054 + struct dentry **errp;
25055 + struct qstr *tgtname;
25056 + struct dentry *h_parent;
25057 + struct au_branch *br;
25060 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25061 + struct dentry *h_parent,
25062 + struct au_branch *br)
25064 + struct dentry *h_dentry;
25065 + struct inode *h_inode;
25067 + h_inode = d_inode(h_parent);
25068 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
25069 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25070 + inode_unlock(h_inode);
25074 +static void au_call_do_plink_lkup(void *args)
25076 + struct au_do_plink_lkup_args *a = args;
25077 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25080 +/* lookup the plink-ed @inode under the branch at @bindex */
25081 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25083 + struct dentry *h_dentry, *h_parent;
25084 + struct au_branch *br;
25086 + char a[PLINK_NAME_LEN];
25087 + struct qstr tgtname = QSTR_INIT(a, 0);
25089 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25091 + br = au_sbr(inode->i_sb, bindex);
25092 + h_parent = br->br_wbr->wbr_plink;
25093 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25095 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25096 + struct au_do_plink_lkup_args args = {
25097 + .errp = &h_dentry,
25098 + .tgtname = &tgtname,
25099 + .h_parent = h_parent,
25103 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25104 + if (unlikely(wkq_err))
25105 + h_dentry = ERR_PTR(wkq_err);
25107 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25112 +/* create a pseudo-link */
25113 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25114 + struct dentry *h_dentry, struct au_branch *br)
25117 + struct path h_path = {
25118 + .mnt = au_br_mnt(br)
25120 + struct inode *h_dir, *delegated;
25122 + h_dir = d_inode(h_parent);
25123 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
25125 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25126 + err = PTR_ERR(h_path.dentry);
25127 + if (IS_ERR(h_path.dentry))
25131 + /* wh.plink dir is not monitored */
25132 + /* todo: is it really safe? */
25133 + if (d_is_positive(h_path.dentry)
25134 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25135 + delegated = NULL;
25136 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25137 + if (unlikely(err == -EWOULDBLOCK)) {
25138 + pr_warn("cannot retry for NFSv4 delegation"
25139 + " for an internal unlink\n");
25142 + dput(h_path.dentry);
25143 + h_path.dentry = NULL;
25147 + if (!err && d_is_negative(h_path.dentry)) {
25148 + delegated = NULL;
25149 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25150 + if (unlikely(err == -EWOULDBLOCK)) {
25151 + pr_warn("cannot retry for NFSv4 delegation"
25152 + " for an internal link\n");
25156 + dput(h_path.dentry);
25159 + inode_unlock(h_dir);
25163 +struct do_whplink_args {
25165 + struct qstr *tgt;
25166 + struct dentry *h_parent;
25167 + struct dentry *h_dentry;
25168 + struct au_branch *br;
25171 +static void call_do_whplink(void *args)
25173 + struct do_whplink_args *a = args;
25174 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25177 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25178 + aufs_bindex_t bindex, struct au_branch *br)
25180 + int err, wkq_err;
25181 + struct au_wbr *wbr;
25182 + struct dentry *h_parent;
25183 + char a[PLINK_NAME_LEN];
25184 + struct qstr tgtname = QSTR_INIT(a, 0);
25186 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25187 + h_parent = wbr->wbr_plink;
25188 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25190 + /* always superio. */
25191 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25192 + struct do_whplink_args args = {
25195 + .h_parent = h_parent,
25196 + .h_dentry = h_dentry,
25199 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25200 + if (unlikely(wkq_err))
25203 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25208 +/* free a single plink */
25209 +static void do_put_plink(struct pseudo_link *plink, int do_del)
25212 + hlist_del(&plink->hlist);
25213 + iput(plink->inode);
25217 +static void do_put_plink_rcu(struct rcu_head *rcu)
25219 + struct pseudo_link *plink;
25221 + plink = container_of(rcu, struct pseudo_link, rcu);
25222 + iput(plink->inode);
25227 + * create a new pseudo-link for @h_dentry on @bindex.
25228 + * the linked inode is held in aufs @inode.
25230 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25231 + struct dentry *h_dentry)
25233 + struct super_block *sb;
25234 + struct au_sbinfo *sbinfo;
25235 + struct hlist_head *plink_hlist;
25236 + struct pseudo_link *plink, *tmp;
25237 + struct au_sphlhead *sphl;
25238 + int found, err, cnt, i;
25240 + sb = inode->i_sb;
25241 + sbinfo = au_sbi(sb);
25242 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25243 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25245 + found = au_plink_test(inode);
25249 + i = au_plink_hash(inode->i_ino);
25250 + sphl = sbinfo->si_plink + i;
25251 + plink_hlist = &sphl->head;
25252 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
25254 + tmp->inode = au_igrab(inode);
25260 + spin_lock(&sphl->spin);
25261 + hlist_for_each_entry(plink, plink_hlist, hlist) {
25262 + if (plink->inode == inode) {
25268 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
25269 + spin_unlock(&sphl->spin);
25271 + cnt = au_sphl_count(sphl);
25272 +#define msg "unexpectedly unblanced or too many pseudo-links"
25273 + if (cnt > AUFS_PLINK_WARN)
25274 + AuWarn1(msg ", %d\n", cnt);
25276 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25278 + do_put_plink(tmp, 0);
25283 + if (unlikely(err)) {
25284 + pr_warn("err %d, damaged pseudo link.\n", err);
25286 + au_sphl_del_rcu(&tmp->hlist, sphl);
25287 + call_rcu(&tmp->rcu, do_put_plink_rcu);
25292 +/* free all plinks */
25293 +void au_plink_put(struct super_block *sb, int verbose)
25296 + struct au_sbinfo *sbinfo;
25297 + struct hlist_head *plink_hlist;
25298 + struct hlist_node *tmp;
25299 + struct pseudo_link *plink;
25301 + SiMustWriteLock(sb);
25303 + sbinfo = au_sbi(sb);
25304 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25305 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25307 + /* no spin_lock since sbinfo is write-locked */
25309 + for (i = 0; i < AuPlink_NHASH; i++) {
25310 + plink_hlist = &sbinfo->si_plink[i].head;
25311 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25312 + pr_warn("pseudo-link is not flushed");
25315 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
25316 + do_put_plink(plink, 0);
25317 + INIT_HLIST_HEAD(plink_hlist);
25321 +void au_plink_clean(struct super_block *sb, int verbose)
25323 + struct dentry *root;
25325 + root = sb->s_root;
25326 + aufs_write_lock(root);
25327 + if (au_opt_test(au_mntflags(sb), PLINK))
25328 + au_plink_put(sb, verbose);
25329 + aufs_write_unlock(root);
25332 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25335 + aufs_bindex_t bstart, bend, bindex;
25338 + bstart = au_ibstart(inode);
25339 + bend = au_ibend(inode);
25340 + if (bstart >= 0) {
25341 + for (bindex = bstart; bindex <= bend; bindex++) {
25342 + if (!au_h_iptr(inode, bindex)
25343 + || au_ii_br_id(inode, bindex) != br_id)
25345 + au_set_h_iptr(inode, bindex, NULL, 0);
25350 + for (bindex = bstart; bindex <= bend; bindex++)
25351 + if (au_h_iptr(inode, bindex)) {
25361 +/* free the plinks on a branch specified by @br_id */
25362 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25364 + struct au_sbinfo *sbinfo;
25365 + struct hlist_head *plink_hlist;
25366 + struct hlist_node *tmp;
25367 + struct pseudo_link *plink;
25368 + struct inode *inode;
25371 + SiMustWriteLock(sb);
25373 + sbinfo = au_sbi(sb);
25374 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25375 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25377 + /* no spin_lock since sbinfo is write-locked */
25378 + for (i = 0; i < AuPlink_NHASH; i++) {
25379 + plink_hlist = &sbinfo->si_plink[i].head;
25380 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
25381 + inode = au_igrab(plink->inode);
25382 + ii_write_lock_child(inode);
25383 + do_put = au_plink_do_half_refresh(inode, br_id);
25385 + do_put_plink(plink, 1);
25386 + ii_write_unlock(inode);
25391 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25392 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25393 +++ linux/fs/aufs/poll.c 2016-04-24 18:32:51.393686895 +0200
25396 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25398 + * This program, aufs is free software; you can redistribute it and/or modify
25399 + * it under the terms of the GNU General Public License as published by
25400 + * the Free Software Foundation; either version 2 of the License, or
25401 + * (at your option) any later version.
25403 + * This program is distributed in the hope that it will be useful,
25404 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25405 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25406 + * GNU General Public License for more details.
25408 + * You should have received a copy of the GNU General Public License
25409 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25414 + * There is only one filesystem which implements ->poll operation, currently.
25419 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25421 + unsigned int mask;
25423 + struct file *h_file;
25424 + struct super_block *sb;
25426 + /* We should pretend an error happened. */
25427 + mask = POLLERR /* | POLLIN | POLLOUT */;
25428 + sb = file->f_path.dentry->d_sb;
25429 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25431 + h_file = au_read_pre(file, /*keep_fi*/0);
25432 + err = PTR_ERR(h_file);
25433 + if (IS_ERR(h_file))
25436 + /* it is not an error if h_file has no operation */
25437 + mask = DEFAULT_POLLMASK;
25438 + if (h_file->f_op->poll)
25439 + mask = h_file->f_op->poll(h_file, wait);
25440 + fput(h_file); /* instead of au_read_post() */
25443 + si_read_unlock(sb);
25444 + AuTraceErr((int)mask);
25447 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25448 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25449 +++ linux/fs/aufs/posix_acl.c 2016-04-24 18:32:51.393686895 +0200
25452 + * Copyright (C) 2014-2016 Junjiro R. Okajima
25454 + * This program, aufs is free software; you can redistribute it and/or modify
25455 + * it under the terms of the GNU General Public License as published by
25456 + * the Free Software Foundation; either version 2 of the License, or
25457 + * (at your option) any later version.
25459 + * This program is distributed in the hope that it will be useful,
25460 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25461 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25462 + * GNU General Public License for more details.
25464 + * You should have received a copy of the GNU General Public License
25465 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25469 + * posix acl operations
25472 +#include <linux/fs.h>
25475 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25477 + struct posix_acl *acl;
25479 + aufs_bindex_t bindex;
25480 + struct inode *h_inode;
25481 + struct super_block *sb;
25484 + sb = inode->i_sb;
25485 + si_read_lock(sb, AuLock_FLUSH);
25486 + ii_read_lock_child(inode);
25487 + if (!(sb->s_flags & MS_POSIXACL))
25490 + bindex = au_ibstart(inode);
25491 + h_inode = au_h_iptr(inode, bindex);
25492 + if (unlikely(!h_inode
25493 + || ((h_inode->i_mode & S_IFMT)
25494 + != (inode->i_mode & S_IFMT)))) {
25495 + err = au_busy_or_stale();
25496 + acl = ERR_PTR(err);
25500 + /* always topmost only */
25501 + acl = get_acl(h_inode, type);
25504 + ii_read_unlock(inode);
25505 + si_read_unlock(sb);
25507 + AuTraceErrPtr(acl);
25511 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25515 + struct dentry *dentry;
25516 + struct au_srxattr arg = {
25517 + .type = AU_ACL_SET,
25524 + inode_lock(inode);
25525 + if (inode->i_ino == AUFS_ROOT_INO)
25526 + dentry = dget(inode->i_sb->s_root);
25528 + dentry = d_find_alias(inode);
25530 + dentry = d_find_any_alias(inode);
25532 + pr_warn("cannot handle this inode, "
25533 + "please report to aufs-users ML\n");
25539 + ssz = au_srxattr(dentry, &arg);
25546 + inode_unlock(inode);
25549 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25550 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25551 +++ linux/fs/aufs/procfs.c 2016-04-24 18:32:51.393686895 +0200
25554 + * Copyright (C) 2010-2016 Junjiro R. Okajima
25556 + * This program, aufs is free software; you can redistribute it and/or modify
25557 + * it under the terms of the GNU General Public License as published by
25558 + * the Free Software Foundation; either version 2 of the License, or
25559 + * (at your option) any later version.
25561 + * This program is distributed in the hope that it will be useful,
25562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25564 + * GNU General Public License for more details.
25566 + * You should have received a copy of the GNU General Public License
25567 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25571 + * procfs interfaces
25574 +#include <linux/proc_fs.h>
25577 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25579 + struct au_sbinfo *sbinfo;
25581 + sbinfo = file->private_data;
25583 + au_plink_maint_leave(sbinfo);
25584 + kobject_put(&sbinfo->si_kobj);
25590 +static void au_procfs_plm_write_clean(struct file *file)
25592 + struct au_sbinfo *sbinfo;
25594 + sbinfo = file->private_data;
25596 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25599 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25602 + struct super_block *sb;
25603 + struct au_sbinfo *sbinfo;
25606 + if (unlikely(file->private_data))
25610 + /* don't use au_sbilist_lock() here */
25611 + spin_lock(&au_sbilist.spin);
25612 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25613 + if (id == sysaufs_si_id(sbinfo)) {
25614 + kobject_get(&sbinfo->si_kobj);
25615 + sb = sbinfo->si_sb;
25618 + spin_unlock(&au_sbilist.spin);
25621 + if (unlikely(!sb))
25624 + err = au_plink_maint_enter(sb);
25626 + /* keep kobject_get() */
25627 + file->private_data = sbinfo;
25629 + kobject_put(&sbinfo->si_kobj);
25635 + * Accept a valid "si=xxxx" only.
25636 + * Once it is accepted successfully, accept "clean" too.
25638 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
25639 + size_t count, loff_t *ppos)
25642 + unsigned long id;
25643 + /* last newline is allowed */
25644 + char buf[3 + sizeof(unsigned long) * 2 + 1];
25647 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25651 + if (unlikely(count > sizeof(buf)))
25654 + err = copy_from_user(buf, ubuf, count);
25655 + if (unlikely(err)) {
25662 + if (!strcmp("clean", buf)) {
25663 + au_procfs_plm_write_clean(file);
25664 + goto out_success;
25665 + } else if (unlikely(strncmp("si=", buf, 3)))
25668 + err = kstrtoul(buf + 3, 16, &id);
25669 + if (unlikely(err))
25672 + err = au_procfs_plm_write_si(file, id);
25673 + if (unlikely(err))
25677 + err = count; /* success */
25682 +static const struct file_operations au_procfs_plm_fop = {
25683 + .write = au_procfs_plm_write,
25684 + .release = au_procfs_plm_release,
25685 + .owner = THIS_MODULE
25688 +/* ---------------------------------------------------------------------- */
25690 +static struct proc_dir_entry *au_procfs_dir;
25692 +void au_procfs_fin(void)
25694 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25695 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25698 +int __init au_procfs_init(void)
25701 + struct proc_dir_entry *entry;
25704 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25705 + if (unlikely(!au_procfs_dir))
25708 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25709 + au_procfs_dir, &au_procfs_plm_fop);
25710 + if (unlikely(!entry))
25714 + goto out; /* success */
25718 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25722 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25723 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25724 +++ linux/fs/aufs/rdu.c 2016-04-24 18:32:51.393686895 +0200
25727 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25729 + * This program, aufs is free software; you can redistribute it and/or modify
25730 + * it under the terms of the GNU General Public License as published by
25731 + * the Free Software Foundation; either version 2 of the License, or
25732 + * (at your option) any later version.
25734 + * This program is distributed in the hope that it will be useful,
25735 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25736 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25737 + * GNU General Public License for more details.
25739 + * You should have received a copy of the GNU General Public License
25740 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25744 + * readdir in userspace.
25747 +#include <linux/compat.h>
25748 +#include <linux/fs_stack.h>
25749 +#include <linux/security.h>
25752 +/* bits for struct aufs_rdu.flags */
25753 +#define AuRdu_CALLED 1
25754 +#define AuRdu_CONT (1 << 1)
25755 +#define AuRdu_FULL (1 << 2)
25756 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25757 +#define au_fset_rdu(flags, name) \
25758 + do { (flags) |= AuRdu_##name; } while (0)
25759 +#define au_fclr_rdu(flags, name) \
25760 + do { (flags) &= ~AuRdu_##name; } while (0)
25762 +struct au_rdu_arg {
25763 + struct dir_context ctx;
25764 + struct aufs_rdu *rdu;
25765 + union au_rdu_ent_ul ent;
25766 + unsigned long end;
25768 + struct super_block *sb;
25772 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25773 + loff_t offset, u64 h_ino, unsigned int d_type)
25776 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25777 + struct aufs_rdu *rdu = arg->rdu;
25778 + struct au_rdu_ent ent;
25782 + au_fset_rdu(rdu->cookie.flags, CALLED);
25783 + len = au_rdu_len(nlen);
25784 + if (arg->ent.ul + len < arg->end) {
25786 + ent.bindex = rdu->cookie.bindex;
25787 + ent.type = d_type;
25789 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25790 + ent.type = DT_UNKNOWN;
25792 + /* unnecessary to support mmap_sem since this is a dir */
25794 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25796 + if (copy_to_user(arg->ent.e->name, name, nlen))
25798 + /* the terminating NULL */
25799 + if (__put_user(0, arg->ent.e->name + nlen))
25802 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25803 + arg->ent.ul += len;
25807 + au_fset_rdu(rdu->cookie.flags, FULL);
25809 + rdu->tail = arg->ent;
25813 + /* AuTraceErr(err); */
25817 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25821 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25823 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25824 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25826 + if (unlikely(offset != cookie->h_pos))
25832 + au_fclr_rdu(cookie->flags, CALLED);
25834 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25838 + && au_ftest_rdu(cookie->flags, CALLED)
25839 + && !au_ftest_rdu(cookie->flags, FULL));
25840 + cookie->h_pos = h_file->f_pos;
25847 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25850 + aufs_bindex_t bend;
25851 + struct au_rdu_arg arg = {
25853 + .actor = au_rdu_fill
25856 + struct dentry *dentry;
25857 + struct inode *inode;
25858 + struct file *h_file;
25859 + struct au_rdu_cookie *cookie = &rdu->cookie;
25861 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25862 + if (unlikely(err)) {
25868 + rdu->tail = rdu->ent;
25871 + arg.ent = rdu->ent;
25872 + arg.end = arg.ent.ul;
25873 + arg.end += rdu->sz;
25876 + if (unlikely(!file->f_op->iterate))
25879 + err = security_file_permission(file, MAY_READ);
25881 + if (unlikely(err))
25884 + dentry = file->f_path.dentry;
25885 + inode = d_inode(dentry);
25887 + inode_lock(inode);
25889 + /* todo: create a new inline func inode_lock_killable() */
25890 + err = mutex_lock_killable(&inode->i_mutex);
25892 + if (unlikely(err))
25896 + arg.sb = inode->i_sb;
25897 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25898 + if (unlikely(err))
25900 + err = au_alive_dir(dentry);
25901 + if (unlikely(err))
25903 + /* todo: reval? */
25904 + fi_read_lock(file);
25907 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25908 + && cookie->generation != au_figen(file)))
25913 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25915 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25917 + bend = au_fbstart(file);
25918 + if (cookie->bindex < bend)
25919 + cookie->bindex = bend;
25920 + bend = au_fbend_dir(file);
25921 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25922 + for (; !err && cookie->bindex <= bend;
25923 + cookie->bindex++, cookie->h_pos = 0) {
25924 + h_file = au_hf_dir(file, cookie->bindex);
25928 + au_fclr_rdu(cookie->flags, FULL);
25929 + err = au_rdu_do(h_file, &arg);
25931 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25934 + AuDbg("rent %llu\n", rdu->rent);
25936 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25937 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25938 + au_fset_rdu(cookie->flags, CONT);
25939 + cookie->generation = au_figen(file);
25942 + ii_read_lock_child(inode);
25943 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25944 + ii_read_unlock(inode);
25947 + fi_read_unlock(file);
25949 + si_read_unlock(arg.sb);
25951 + inode_unlock(inode);
25957 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25961 + unsigned long long nent;
25962 + union au_rdu_ent_ul *u;
25963 + struct au_rdu_ent ent;
25964 + struct super_block *sb;
25967 + nent = rdu->nent;
25969 + sb = file->f_path.dentry->d_sb;
25970 + si_read_lock(sb, AuLock_FLUSH);
25971 + while (nent-- > 0) {
25972 + /* unnecessary to support mmap_sem since this is a dir */
25973 + err = copy_from_user(&ent, u->e, sizeof(ent));
25975 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25976 + if (unlikely(err)) {
25982 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25984 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25986 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25988 + if (unlikely(err)) {
25993 + err = __put_user(ino, &u->e->ino);
25994 + if (unlikely(err)) {
25999 + u->ul += au_rdu_len(ent.nlen);
26001 + si_read_unlock(sb);
26006 +/* ---------------------------------------------------------------------- */
26008 +static int au_rdu_verify(struct aufs_rdu *rdu)
26010 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26011 + "%llu, b%d, 0x%x, g%u}\n",
26012 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26014 + rdu->rent, rdu->shwh, rdu->full,
26015 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26016 + rdu->cookie.generation);
26018 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26022 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26026 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26029 + struct aufs_rdu rdu;
26030 + void __user *p = (void __user *)arg;
26032 + err = copy_from_user(&rdu, p, sizeof(rdu));
26033 + if (unlikely(err)) {
26038 + err = au_rdu_verify(&rdu);
26039 + if (unlikely(err))
26043 + case AUFS_CTL_RDU:
26044 + err = au_rdu(file, &rdu);
26045 + if (unlikely(err))
26048 + e = copy_to_user(p, &rdu, sizeof(rdu));
26049 + if (unlikely(e)) {
26054 + case AUFS_CTL_RDU_INO:
26055 + err = au_rdu_ino(file, &rdu);
26059 + /* err = -ENOTTY; */
26068 +#ifdef CONFIG_COMPAT
26069 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26072 + struct aufs_rdu rdu;
26073 + void __user *p = compat_ptr(arg);
26075 + /* todo: get_user()? */
26076 + err = copy_from_user(&rdu, p, sizeof(rdu));
26077 + if (unlikely(err)) {
26082 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26083 + err = au_rdu_verify(&rdu);
26084 + if (unlikely(err))
26088 + case AUFS_CTL_RDU:
26089 + err = au_rdu(file, &rdu);
26090 + if (unlikely(err))
26093 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26094 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26095 + e = copy_to_user(p, &rdu, sizeof(rdu));
26096 + if (unlikely(e)) {
26101 + case AUFS_CTL_RDU_INO:
26102 + err = au_rdu_ino(file, &rdu);
26106 + /* err = -ENOTTY; */
26115 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26116 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26117 +++ linux/fs/aufs/rwsem.h 2016-04-24 18:32:51.393686895 +0200
26120 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26122 + * This program, aufs is free software; you can redistribute it and/or modify
26123 + * it under the terms of the GNU General Public License as published by
26124 + * the Free Software Foundation; either version 2 of the License, or
26125 + * (at your option) any later version.
26127 + * This program is distributed in the hope that it will be useful,
26128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26130 + * GNU General Public License for more details.
26132 + * You should have received a copy of the GNU General Public License
26133 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26137 + * simple read-write semaphore wrappers
26140 +#ifndef __AUFS_RWSEM_H__
26141 +#define __AUFS_RWSEM_H__
26145 +#include "debug.h"
26148 + struct rw_semaphore rwsem;
26149 +#ifdef CONFIG_AUFS_DEBUG
26150 + /* just for debugging, not almighty counter */
26151 + atomic_t rcnt, wcnt;
26155 +#ifdef CONFIG_AUFS_DEBUG
26156 +#define AuDbgCntInit(rw) do { \
26157 + atomic_set(&(rw)->rcnt, 0); \
26158 + atomic_set(&(rw)->wcnt, 0); \
26159 + smp_mb(); /* atomic set */ \
26162 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
26163 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
26164 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
26165 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
26167 +#define AuDbgCntInit(rw) do {} while (0)
26168 +#define AuDbgRcntInc(rw) do {} while (0)
26169 +#define AuDbgRcntDec(rw) do {} while (0)
26170 +#define AuDbgWcntInc(rw) do {} while (0)
26171 +#define AuDbgWcntDec(rw) do {} while (0)
26172 +#endif /* CONFIG_AUFS_DEBUG */
26174 +/* to debug easier, do not make them inlined functions */
26175 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
26176 +/* rwsem_is_locked() is unusable */
26177 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
26178 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
26179 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
26180 + && atomic_read(&(rw)->wcnt) <= 0)
26181 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
26182 + || atomic_read(&(rw)->wcnt))
26184 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
26186 +static inline void au_rw_init(struct au_rwsem *rw)
26188 + AuDbgCntInit(rw);
26189 + init_rwsem(&rw->rwsem);
26192 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
26195 + down_write(&rw->rwsem);
26196 + AuDbgWcntInc(rw);
26199 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
26200 + unsigned int lsc)
26203 + down_write_nested(&rw->rwsem, lsc);
26204 + AuDbgWcntInc(rw);
26207 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26209 + down_read(&rw->rwsem);
26210 + AuDbgRcntInc(rw);
26213 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26215 + down_read_nested(&rw->rwsem, lsc);
26216 + AuDbgRcntInc(rw);
26219 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26221 + AuRwMustReadLock(rw);
26222 + AuDbgRcntDec(rw);
26223 + up_read(&rw->rwsem);
26226 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26228 + AuRwMustWriteLock(rw);
26229 + AuDbgRcntInc(rw);
26230 + AuDbgWcntDec(rw);
26231 + downgrade_write(&rw->rwsem);
26234 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26236 + down_write(&rw->rwsem);
26237 + AuDbgWcntInc(rw);
26240 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26241 + unsigned int lsc)
26243 + down_write_nested(&rw->rwsem, lsc);
26244 + AuDbgWcntInc(rw);
26247 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26249 + AuRwMustWriteLock(rw);
26250 + AuDbgWcntDec(rw);
26251 + up_write(&rw->rwsem);
26254 +/* why is not _nested version defined */
26255 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26259 + ret = down_read_trylock(&rw->rwsem);
26261 + AuDbgRcntInc(rw);
26265 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26269 + ret = down_write_trylock(&rw->rwsem);
26271 + AuDbgWcntInc(rw);
26275 +#undef AuDbgCntInit
26276 +#undef AuDbgRcntInc
26277 +#undef AuDbgRcntDec
26278 +#undef AuDbgWcntInc
26279 +#undef AuDbgWcntDec
26281 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26282 +static inline void prefix##_read_lock(param) \
26283 +{ au_rw_read_lock(rwsem); } \
26284 +static inline void prefix##_write_lock(param) \
26285 +{ au_rw_write_lock(rwsem); } \
26286 +static inline int prefix##_read_trylock(param) \
26287 +{ return au_rw_read_trylock(rwsem); } \
26288 +static inline int prefix##_write_trylock(param) \
26289 +{ return au_rw_write_trylock(rwsem); }
26290 +/* why is not _nested version defined */
26291 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26292 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26293 +static inline void prefix##_write_trylock_nestd(param, lsc)
26294 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26296 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26297 +static inline void prefix##_read_unlock(param) \
26298 +{ au_rw_read_unlock(rwsem); } \
26299 +static inline void prefix##_write_unlock(param) \
26300 +{ au_rw_write_unlock(rwsem); } \
26301 +static inline void prefix##_downgrade_lock(param) \
26302 +{ au_rw_dgrade_lock(rwsem); }
26304 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26305 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26306 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26308 +#endif /* __KERNEL__ */
26309 +#endif /* __AUFS_RWSEM_H__ */
26310 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26311 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26312 +++ linux/fs/aufs/sbinfo.c 2016-04-24 18:32:51.393686895 +0200
26315 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26317 + * This program, aufs is free software; you can redistribute it and/or modify
26318 + * it under the terms of the GNU General Public License as published by
26319 + * the Free Software Foundation; either version 2 of the License, or
26320 + * (at your option) any later version.
26322 + * This program is distributed in the hope that it will be useful,
26323 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26324 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26325 + * GNU General Public License for more details.
26327 + * You should have received a copy of the GNU General Public License
26328 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26332 + * superblock private data
26338 + * they are necessary regardless sysfs is disabled.
26340 +void au_si_free(struct kobject *kobj)
26343 + struct au_sbinfo *sbinfo;
26344 + char *locked __maybe_unused; /* debug only */
26346 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26347 + for (i = 0; i < AuPlink_NHASH; i++)
26348 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26349 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26351 + au_rw_write_lock(&sbinfo->si_rwsem);
26352 + au_br_free(sbinfo);
26353 + au_rw_write_unlock(&sbinfo->si_rwsem);
26355 + kfree(sbinfo->si_branch);
26356 + for (i = 0; i < AU_NPIDMAP; i++)
26357 + kfree(sbinfo->au_si_pid.pid_bitmap[i]);
26358 + mutex_destroy(&sbinfo->au_si_pid.pid_mtx);
26359 + mutex_destroy(&sbinfo->si_xib_mtx);
26360 + AuRwDestroy(&sbinfo->si_rwsem);
26365 +int au_si_alloc(struct super_block *sb)
26368 + struct au_sbinfo *sbinfo;
26369 + static struct lock_class_key aufs_si;
26372 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26373 + if (unlikely(!sbinfo))
26376 + /* will be reallocated separately */
26377 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26378 + if (unlikely(!sbinfo->si_branch))
26381 + err = sysaufs_si_init(sbinfo);
26382 + if (unlikely(err))
26385 + au_nwt_init(&sbinfo->si_nowait);
26386 + au_rw_init_wlock(&sbinfo->si_rwsem);
26387 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
26388 + mutex_init(&sbinfo->au_si_pid.pid_mtx);
26390 + atomic_long_set(&sbinfo->si_ninodes, 0);
26391 + atomic_long_set(&sbinfo->si_nfiles, 0);
26393 + sbinfo->si_bend = -1;
26394 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26396 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26397 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26398 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26399 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26401 + au_fhsm_init(sbinfo);
26403 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26405 + sbinfo->si_xino_jiffy = jiffies;
26406 + sbinfo->si_xino_expire
26407 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26408 + mutex_init(&sbinfo->si_xib_mtx);
26409 + sbinfo->si_xino_brid = -1;
26410 + /* leave si_xib_last_pindex and si_xib_next_bit */
26412 + au_sphl_init(&sbinfo->si_aopen);
26414 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26415 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26416 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26417 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26419 + for (i = 0; i < AuPlink_NHASH; i++)
26420 + au_sphl_init(sbinfo->si_plink + i);
26421 + init_waitqueue_head(&sbinfo->si_plink_wq);
26422 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26424 + au_sphl_init(&sbinfo->si_files);
26426 + /* with getattr by default */
26427 + sbinfo->si_iop_array = aufs_iop;
26429 + /* leave other members for sysaufs and si_mnt. */
26430 + sbinfo->si_sb = sb;
26431 + sb->s_fs_info = sbinfo;
26433 + return 0; /* success */
26436 + kfree(sbinfo->si_branch);
26443 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
26446 + struct au_branch **brp;
26448 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26451 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
26452 + if (unlikely(!sz))
26453 + sz = sizeof(*brp);
26454 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
26456 + sbinfo->si_branch = brp;
26463 +/* ---------------------------------------------------------------------- */
26465 +unsigned int au_sigen_inc(struct super_block *sb)
26467 + unsigned int gen;
26468 + struct inode *inode;
26470 + SiMustWriteLock(sb);
26472 + gen = ++au_sbi(sb)->si_generation;
26473 + au_update_digen(sb->s_root);
26474 + inode = d_inode(sb->s_root);
26475 + au_update_iigen(inode, /*half*/0);
26476 + inode->i_version++;
26480 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26482 + aufs_bindex_t br_id;
26484 + struct au_sbinfo *sbinfo;
26486 + SiMustWriteLock(sb);
26488 + sbinfo = au_sbi(sb);
26489 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26490 + br_id = ++sbinfo->si_last_br_id;
26491 + AuDebugOn(br_id < 0);
26492 + if (br_id && au_br_index(sb, br_id) < 0)
26499 +/* ---------------------------------------------------------------------- */
26501 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26502 +int si_read_lock(struct super_block *sb, int flags)
26507 + if (au_ftest_lock(flags, FLUSH))
26508 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26510 + si_noflush_read_lock(sb);
26511 + err = au_plink_maint(sb, flags);
26512 + if (unlikely(err))
26513 + si_read_unlock(sb);
26518 +int si_write_lock(struct super_block *sb, int flags)
26522 + if (au_ftest_lock(flags, FLUSH))
26523 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26525 + si_noflush_write_lock(sb);
26526 + err = au_plink_maint(sb, flags);
26527 + if (unlikely(err))
26528 + si_write_unlock(sb);
26533 +/* dentry and super_block lock. call at entry point */
26534 +int aufs_read_lock(struct dentry *dentry, int flags)
26537 + struct super_block *sb;
26539 + sb = dentry->d_sb;
26540 + err = si_read_lock(sb, flags);
26541 + if (unlikely(err))
26544 + if (au_ftest_lock(flags, DW))
26545 + di_write_lock_child(dentry);
26547 + di_read_lock_child(dentry, flags);
26549 + if (au_ftest_lock(flags, GEN)) {
26550 + err = au_digen_test(dentry, au_sigen(sb));
26551 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
26552 + AuDebugOn(!err && au_dbrange_test(dentry));
26554 + err = au_dbrange_test(dentry);
26555 + if (unlikely(err))
26556 + aufs_read_unlock(dentry, flags);
26563 +void aufs_read_unlock(struct dentry *dentry, int flags)
26565 + if (au_ftest_lock(flags, DW))
26566 + di_write_unlock(dentry);
26568 + di_read_unlock(dentry, flags);
26569 + si_read_unlock(dentry->d_sb);
26572 +void aufs_write_lock(struct dentry *dentry)
26574 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26575 + di_write_lock_child(dentry);
26578 +void aufs_write_unlock(struct dentry *dentry)
26580 + di_write_unlock(dentry);
26581 + si_write_unlock(dentry->d_sb);
26584 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26587 + unsigned int sigen;
26588 + struct super_block *sb;
26591 + err = si_read_lock(sb, flags);
26592 + if (unlikely(err))
26595 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
26597 + if (au_ftest_lock(flags, GEN)) {
26598 + sigen = au_sigen(sb);
26599 + err = au_digen_test(d1, sigen);
26600 + AuDebugOn(!err && au_dbrange_test(d1));
26602 + err = au_digen_test(d2, sigen);
26603 + AuDebugOn(!err && au_dbrange_test(d2));
26605 + if (unlikely(err))
26606 + aufs_read_and_write_unlock2(d1, d2);
26613 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26615 + di_write_unlock2(d1, d2);
26616 + si_read_unlock(d1->d_sb);
26619 +/* ---------------------------------------------------------------------- */
26621 +static void si_pid_alloc(struct au_si_pid *au_si_pid, int idx)
26623 + unsigned long *p;
26625 + BUILD_BUG_ON(sizeof(unsigned long) !=
26626 + sizeof(*au_si_pid->pid_bitmap));
26628 + mutex_lock(&au_si_pid->pid_mtx);
26629 + p = au_si_pid->pid_bitmap[idx];
26633 + * but keeping 'si_pid_set()' void is more important.
26635 + p = kcalloc(BITS_TO_LONGS(AU_PIDSTEP),
26636 + sizeof(*au_si_pid->pid_bitmap),
26642 + au_si_pid->pid_bitmap[idx] = p;
26643 + mutex_unlock(&au_si_pid->pid_mtx);
26646 +void si_pid_set(struct super_block *sb)
26650 + unsigned long *bitmap;
26651 + struct au_si_pid *au_si_pid;
26653 + si_pid_idx_bit(&idx, &bit);
26654 + au_si_pid = &au_sbi(sb)->au_si_pid;
26655 + bitmap = au_si_pid->pid_bitmap[idx];
26657 + si_pid_alloc(au_si_pid, idx);
26658 + bitmap = au_si_pid->pid_bitmap[idx];
26660 + AuDebugOn(test_bit(bit, bitmap));
26661 + set_bit(bit, bitmap);
26664 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26665 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26666 +++ linux/fs/aufs/spl.h 2016-04-24 18:32:51.393686895 +0200
26669 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26671 + * This program, aufs is free software; you can redistribute it and/or modify
26672 + * it under the terms of the GNU General Public License as published by
26673 + * the Free Software Foundation; either version 2 of the License, or
26674 + * (at your option) any later version.
26676 + * This program is distributed in the hope that it will be useful,
26677 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26678 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26679 + * GNU General Public License for more details.
26681 + * You should have received a copy of the GNU General Public License
26682 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26686 + * simple list protected by a spinlock
26689 +#ifndef __AUFS_SPL_H__
26690 +#define __AUFS_SPL_H__
26694 +struct au_splhead {
26696 + struct list_head head;
26699 +static inline void au_spl_init(struct au_splhead *spl)
26701 + spin_lock_init(&spl->spin);
26702 + INIT_LIST_HEAD(&spl->head);
26705 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26707 + spin_lock(&spl->spin);
26708 + list_add(list, &spl->head);
26709 + spin_unlock(&spl->spin);
26712 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26714 + spin_lock(&spl->spin);
26716 + spin_unlock(&spl->spin);
26719 +static inline void au_spl_del_rcu(struct list_head *list,
26720 + struct au_splhead *spl)
26722 + spin_lock(&spl->spin);
26723 + list_del_rcu(list);
26724 + spin_unlock(&spl->spin);
26727 +/* ---------------------------------------------------------------------- */
26729 +struct au_sphlhead {
26731 + struct hlist_head head;
26734 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26736 + spin_lock_init(&sphl->spin);
26737 + INIT_HLIST_HEAD(&sphl->head);
26740 +static inline void au_sphl_add(struct hlist_node *hlist,
26741 + struct au_sphlhead *sphl)
26743 + spin_lock(&sphl->spin);
26744 + hlist_add_head(hlist, &sphl->head);
26745 + spin_unlock(&sphl->spin);
26748 +static inline void au_sphl_del(struct hlist_node *hlist,
26749 + struct au_sphlhead *sphl)
26751 + spin_lock(&sphl->spin);
26752 + hlist_del(hlist);
26753 + spin_unlock(&sphl->spin);
26756 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26757 + struct au_sphlhead *sphl)
26759 + spin_lock(&sphl->spin);
26760 + hlist_del_rcu(hlist);
26761 + spin_unlock(&sphl->spin);
26764 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26766 + unsigned long cnt;
26767 + struct hlist_node *pos;
26770 + spin_lock(&sphl->spin);
26771 + hlist_for_each(pos, &sphl->head)
26773 + spin_unlock(&sphl->spin);
26777 +#endif /* __KERNEL__ */
26778 +#endif /* __AUFS_SPL_H__ */
26779 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26780 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26781 +++ linux/fs/aufs/super.c 2016-04-24 18:32:51.393686895 +0200
26784 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26786 + * This program, aufs is free software; you can redistribute it and/or modify
26787 + * it under the terms of the GNU General Public License as published by
26788 + * the Free Software Foundation; either version 2 of the License, or
26789 + * (at your option) any later version.
26791 + * This program is distributed in the hope that it will be useful,
26792 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26793 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26794 + * GNU General Public License for more details.
26796 + * You should have received a copy of the GNU General Public License
26797 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26801 + * mount and super_block operations
26804 +#include <linux/mm.h>
26805 +#include <linux/seq_file.h>
26806 +#include <linux/statfs.h>
26807 +#include <linux/vmalloc.h>
26811 + * super_operations
26813 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26815 + struct au_icntnr *c;
26817 + c = au_cache_alloc_icntnr();
26819 + au_icntnr_init(c);
26820 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26821 + c->iinfo.ii_hinode = NULL;
26822 + return &c->vfs_inode;
26827 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26829 + struct inode *inode = container_of(head, struct inode, i_rcu);
26831 + INIT_HLIST_HEAD(&inode->i_dentry);
26832 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26835 +static void aufs_destroy_inode(struct inode *inode)
26837 + au_iinfo_fin(inode);
26838 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26841 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26843 + struct inode *inode;
26846 + inode = iget_locked(sb, ino);
26847 + if (unlikely(!inode)) {
26848 + inode = ERR_PTR(-ENOMEM);
26851 + if (!(inode->i_state & I_NEW))
26854 + err = au_xigen_new(inode);
26856 + err = au_iinfo_init(inode);
26858 + inode->i_version++;
26860 + iget_failed(inode);
26861 + inode = ERR_PTR(err);
26865 + /* never return NULL */
26866 + AuDebugOn(!inode);
26867 + AuTraceErrPtr(inode);
26871 +/* lock free root dinfo */
26872 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26875 + aufs_bindex_t bindex, bend;
26876 + struct path path;
26877 + struct au_hdentry *hdp;
26878 + struct au_branch *br;
26879 + au_br_perm_str_t perm;
26882 + bend = au_sbend(sb);
26883 + hdp = au_di(sb->s_root)->di_hdentry;
26884 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26885 + br = au_sbr(sb, bindex);
26886 + path.mnt = au_br_mnt(br);
26887 + path.dentry = hdp[bindex].hd_dentry;
26888 + err = au_seq_path(seq, &path);
26890 + au_optstr_br_perm(&perm, br->br_perm);
26891 + seq_printf(seq, "=%s", perm.a);
26892 + if (bindex != bend)
26893 + seq_putc(seq, ':');
26896 + if (unlikely(err || seq_has_overflowed(seq)))
26902 +static void au_show_wbr_create(struct seq_file *m, int v,
26903 + struct au_sbinfo *sbinfo)
26907 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26909 + seq_puts(m, ",create=");
26910 + pat = au_optstr_wbr_create(v);
26912 + case AuWbrCreate_TDP:
26913 + case AuWbrCreate_RR:
26914 + case AuWbrCreate_MFS:
26915 + case AuWbrCreate_PMFS:
26916 + seq_puts(m, pat);
26918 + case AuWbrCreate_MFSV:
26919 + seq_printf(m, /*pat*/"mfs:%lu",
26920 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26923 + case AuWbrCreate_PMFSV:
26924 + seq_printf(m, /*pat*/"pmfs:%lu",
26925 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26928 + case AuWbrCreate_MFSRR:
26929 + seq_printf(m, /*pat*/"mfsrr:%llu",
26930 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26932 + case AuWbrCreate_MFSRRV:
26933 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26934 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26935 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26938 + case AuWbrCreate_PMFSRR:
26939 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26940 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26942 + case AuWbrCreate_PMFSRRV:
26943 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26944 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26945 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26951 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26953 +#ifdef CONFIG_SYSFS
26957 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26958 + aufs_bindex_t bindex, brid;
26959 + struct qstr *name;
26961 + struct dentry *d, *h_root;
26962 + struct au_hdentry *hdp;
26964 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26967 + f = au_sbi(sb)->si_xib;
26971 + /* stop printing the default xino path on the first writable branch */
26973 + brid = au_xino_brid(sb);
26975 + bindex = au_br_index(sb, brid);
26976 + hdp = au_di(sb->s_root)->di_hdentry;
26977 + h_root = hdp[0 + bindex].hd_dentry;
26979 + d = f->f_path.dentry;
26980 + name = &d->d_name;
26981 + /* safe ->d_parent because the file is unlinked */
26982 + if (d->d_parent == h_root
26983 + && name->len == len
26984 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26987 + seq_puts(seq, ",xino=");
26988 + err = au_xino_path(seq, f);
26995 +/* seq_file will re-call me in case of too long string */
26996 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26999 + unsigned int mnt_flags, v;
27000 + struct super_block *sb;
27001 + struct au_sbinfo *sbinfo;
27003 +#define AuBool(name, str) do { \
27004 + v = au_opt_test(mnt_flags, name); \
27005 + if (v != au_opt_test(AuOpt_Def, name)) \
27006 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27009 +#define AuStr(name, str) do { \
27010 + v = mnt_flags & AuOptMask_##name; \
27011 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27012 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27015 +#define AuUInt(name, str, val) do { \
27016 + if (val != AUFS_##name##_DEF) \
27017 + seq_printf(m, "," #str "=%u", val); \
27020 + sb = dentry->d_sb;
27021 + if (sb->s_flags & MS_POSIXACL)
27022 + seq_puts(m, ",acl");
27024 + /* lock free root dinfo */
27025 + si_noflush_read_lock(sb);
27026 + sbinfo = au_sbi(sb);
27027 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27029 + mnt_flags = au_mntflags(sb);
27030 + if (au_opt_test(mnt_flags, XINO)) {
27031 + err = au_show_xino(m, sb);
27032 + if (unlikely(err))
27035 + seq_puts(m, ",noxino");
27037 + AuBool(TRUNC_XINO, trunc_xino);
27038 + AuStr(UDBA, udba);
27039 + AuBool(SHWH, shwh);
27040 + AuBool(PLINK, plink);
27041 + AuBool(DIO, dio);
27042 + AuBool(DIRPERM1, dirperm1);
27044 + v = sbinfo->si_wbr_create;
27045 + if (v != AuWbrCreate_Def)
27046 + au_show_wbr_create(m, v, sbinfo);
27048 + v = sbinfo->si_wbr_copyup;
27049 + if (v != AuWbrCopyup_Def)
27050 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27052 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27053 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27054 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27056 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27058 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27059 + AuUInt(RDCACHE, rdcache, v);
27061 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27062 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27064 + au_fhsm_show(m, sbinfo);
27066 + AuBool(SUM, sum);
27067 + /* AuBool(SUM_W, wsum); */
27068 + AuBool(WARN_PERM, warn_perm);
27069 + AuBool(VERBOSE, verbose);
27072 + /* be sure to print "br:" last */
27073 + if (!sysaufs_brs) {
27074 + seq_puts(m, ",br:");
27075 + au_show_brs(m, sb);
27077 + si_read_unlock(sb);
27085 +/* ---------------------------------------------------------------------- */
27087 +/* sum mode which returns the summation for statfs(2) */
27089 +static u64 au_add_till_max(u64 a, u64 b)
27097 + return ULLONG_MAX;
27100 +static u64 au_mul_till_max(u64 a, long mul)
27108 + return ULLONG_MAX;
27111 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27114 + long bsize, factor;
27115 + u64 blocks, bfree, bavail, files, ffree;
27116 + aufs_bindex_t bend, bindex, i;
27117 + unsigned char shared;
27118 + struct path h_path;
27119 + struct super_block *h_sb;
27122 + bsize = LONG_MAX;
27128 + bend = au_sbend(sb);
27129 + for (bindex = 0; bindex <= bend; bindex++) {
27130 + h_path.mnt = au_sbr_mnt(sb, bindex);
27131 + h_sb = h_path.mnt->mnt_sb;
27133 + for (i = 0; !shared && i < bindex; i++)
27134 + shared = (au_sbr_sb(sb, i) == h_sb);
27138 + /* sb->s_root for NFS is unreliable */
27139 + h_path.dentry = h_path.mnt->mnt_root;
27140 + err = vfs_statfs(&h_path, buf);
27141 + if (unlikely(err))
27144 + if (bsize > buf->f_bsize) {
27146 + * we will reduce bsize, so we have to expand blocks
27147 + * etc. to match them again
27149 + factor = (bsize / buf->f_bsize);
27150 + blocks = au_mul_till_max(blocks, factor);
27151 + bfree = au_mul_till_max(bfree, factor);
27152 + bavail = au_mul_till_max(bavail, factor);
27153 + bsize = buf->f_bsize;
27156 + factor = (buf->f_bsize / bsize);
27157 + blocks = au_add_till_max(blocks,
27158 + au_mul_till_max(buf->f_blocks, factor));
27159 + bfree = au_add_till_max(bfree,
27160 + au_mul_till_max(buf->f_bfree, factor));
27161 + bavail = au_add_till_max(bavail,
27162 + au_mul_till_max(buf->f_bavail, factor));
27163 + files = au_add_till_max(files, buf->f_files);
27164 + ffree = au_add_till_max(ffree, buf->f_ffree);
27167 + buf->f_bsize = bsize;
27168 + buf->f_blocks = blocks;
27169 + buf->f_bfree = bfree;
27170 + buf->f_bavail = bavail;
27171 + buf->f_files = files;
27172 + buf->f_ffree = ffree;
27173 + buf->f_frsize = 0;
27179 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27182 + struct path h_path;
27183 + struct super_block *sb;
27185 + /* lock free root dinfo */
27186 + sb = dentry->d_sb;
27187 + si_noflush_read_lock(sb);
27188 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27189 + /* sb->s_root for NFS is unreliable */
27190 + h_path.mnt = au_sbr_mnt(sb, 0);
27191 + h_path.dentry = h_path.mnt->mnt_root;
27192 + err = vfs_statfs(&h_path, buf);
27194 + err = au_statfs_sum(sb, buf);
27195 + si_read_unlock(sb);
27198 + buf->f_type = AUFS_SUPER_MAGIC;
27199 + buf->f_namelen = AUFS_MAX_NAMELEN;
27200 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27202 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27207 +/* ---------------------------------------------------------------------- */
27209 +static int aufs_sync_fs(struct super_block *sb, int wait)
27212 + aufs_bindex_t bend, bindex;
27213 + struct au_branch *br;
27214 + struct super_block *h_sb;
27217 + si_noflush_read_lock(sb);
27218 + bend = au_sbend(sb);
27219 + for (bindex = 0; bindex <= bend; bindex++) {
27220 + br = au_sbr(sb, bindex);
27221 + if (!au_br_writable(br->br_perm))
27224 + h_sb = au_sbr_sb(sb, bindex);
27225 + if (h_sb->s_op->sync_fs) {
27226 + e = h_sb->s_op->sync_fs(h_sb, wait);
27227 + if (unlikely(e && !err))
27229 + /* go on even if an error happens */
27232 + si_read_unlock(sb);
27237 +/* ---------------------------------------------------------------------- */
27239 +/* final actions when unmounting a file system */
27240 +static void aufs_put_super(struct super_block *sb)
27242 + struct au_sbinfo *sbinfo;
27244 + sbinfo = au_sbi(sb);
27248 + dbgaufs_si_fin(sbinfo);
27249 + kobject_put(&sbinfo->si_kobj);
27252 +/* ---------------------------------------------------------------------- */
27254 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27255 + struct super_block *sb, void *arg)
27258 + unsigned long long n, sz;
27265 + if (*hint > ULLONG_MAX / sizeof(array)) {
27266 + array = ERR_PTR(-EMFILE);
27267 + pr_err("hint %llu\n", *hint);
27271 + sz = sizeof(array) * *hint;
27272 + array = kzalloc(sz, GFP_NOFS);
27273 + if (unlikely(!array))
27274 + array = vzalloc(sz);
27275 + if (unlikely(!array)) {
27276 + array = ERR_PTR(-ENOMEM);
27280 + n = cb(sb, array, *hint, arg);
27281 + AuDebugOn(n > *hint);
27288 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27289 + unsigned long long max __maybe_unused,
27292 + unsigned long long n;
27293 + struct inode **p, *inode;
27294 + struct list_head *head;
27299 + spin_lock(&sb->s_inode_list_lock);
27300 + list_for_each_entry(inode, head, i_sb_list) {
27301 + if (!is_bad_inode(inode)
27302 + && au_ii(inode)->ii_bstart >= 0) {
27303 + spin_lock(&inode->i_lock);
27304 + if (atomic_read(&inode->i_count)) {
27308 + AuDebugOn(n > max);
27310 + spin_unlock(&inode->i_lock);
27313 + spin_unlock(&sb->s_inode_list_lock);
27318 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27320 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
27321 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27324 +void au_iarray_free(struct inode **a, unsigned long long max)
27326 + unsigned long long ull;
27328 + for (ull = 0; ull < max; ull++)
27333 +/* ---------------------------------------------------------------------- */
27336 + * refresh dentry and inode at remount time.
27338 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27339 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27340 + struct dentry *parent)
27344 + di_write_lock_child(dentry);
27345 + di_read_lock_parent(parent, AuLock_IR);
27346 + err = au_refresh_dentry(dentry, parent);
27347 + if (!err && dir_flags)
27348 + au_hn_reset(d_inode(dentry), dir_flags);
27349 + di_read_unlock(parent, AuLock_IR);
27350 + di_write_unlock(dentry);
27355 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27356 + struct au_sbinfo *sbinfo,
27357 + const unsigned int dir_flags, unsigned int do_idop)
27360 + struct dentry *parent;
27363 + parent = dget_parent(dentry);
27364 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27365 + if (d_really_is_positive(dentry)) {
27366 + if (!d_is_dir(dentry))
27367 + err = au_do_refresh(dentry, /*dir_flags*/0,
27370 + err = au_do_refresh(dentry, dir_flags, parent);
27371 + if (unlikely(err))
27372 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27375 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27376 + AuDbgDentry(dentry);
27382 + au_refresh_dop(dentry, /*force_reval*/0);
27384 + au_refresh_dop(dentry, /*force_reval*/1);
27390 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
27392 + int err, i, j, ndentry, e;
27393 + unsigned int sigen;
27394 + struct au_dcsub_pages dpages;
27395 + struct au_dpage *dpage;
27396 + struct dentry **dentries, *d;
27397 + struct au_sbinfo *sbinfo;
27398 + struct dentry *root = sb->s_root;
27399 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27402 + au_refresh_dop(root, /*force_reval*/0);
27404 + err = au_dpages_init(&dpages, GFP_NOFS);
27405 + if (unlikely(err))
27407 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27408 + if (unlikely(err))
27411 + sigen = au_sigen(sb);
27412 + sbinfo = au_sbi(sb);
27413 + for (i = 0; i < dpages.ndpage; i++) {
27414 + dpage = dpages.dpages + i;
27415 + dentries = dpage->dentries;
27416 + ndentry = dpage->ndentry;
27417 + for (j = 0; j < ndentry; j++) {
27419 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
27421 + if (unlikely(e && !err))
27423 + /* go on even err */
27428 + au_dpages_free(&dpages);
27433 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
27436 + unsigned int sigen;
27437 + unsigned long long max, ull;
27438 + struct inode *inode, **array;
27440 + array = au_iarray_alloc(sb, &max);
27441 + err = PTR_ERR(array);
27442 + if (IS_ERR(array))
27446 + sigen = au_sigen(sb);
27447 + for (ull = 0; ull < max; ull++) {
27448 + inode = array[ull];
27449 + if (unlikely(!inode))
27453 + ii_write_lock_child(inode);
27454 + if (au_iigen(inode, NULL) != sigen) {
27455 + e = au_refresh_hinode_self(inode);
27456 + if (unlikely(e)) {
27457 + au_refresh_iop(inode, /*force_getattr*/1);
27458 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27461 + /* go on even if err */
27464 + if (!e && do_idop)
27465 + au_refresh_iop(inode, /*force_getattr*/0);
27466 + ii_write_unlock(inode);
27469 + au_iarray_free(array, max);
27475 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
27478 + unsigned int udba;
27479 + aufs_bindex_t bindex, bend;
27480 + struct dentry *root;
27481 + struct inode *inode;
27482 + struct au_branch *br;
27483 + struct au_sbinfo *sbi;
27485 + au_sigen_inc(sb);
27486 + sbi = au_sbi(sb);
27487 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
27489 + root = sb->s_root;
27490 + DiMustNoWaiters(root);
27491 + inode = d_inode(root);
27492 + IiMustNoWaiters(inode);
27494 + udba = au_opt_udba(sb);
27495 + bend = au_sbend(sb);
27496 + for (bindex = 0; bindex <= bend; bindex++) {
27497 + br = au_sbr(sb, bindex);
27498 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27499 + if (unlikely(err))
27500 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27502 + /* go on even if err */
27504 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27507 + if (au_ftest_si(sbi, NO_DREVAL)) {
27508 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
27509 + sb->s_d_op = &aufs_dop_noreval;
27510 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
27511 + sbi->si_iop_array = aufs_iop_nogetattr;
27513 + AuDebugOn(sb->s_d_op == &aufs_dop);
27514 + sb->s_d_op = &aufs_dop;
27515 + AuDebugOn(sbi->si_iop_array == aufs_iop);
27516 + sbi->si_iop_array = aufs_iop;
27518 + pr_info("reset to %pf and %pf\n",
27519 + sb->s_d_op, sbi->si_iop_array);
27522 + di_write_unlock(root);
27523 + err = au_refresh_d(sb, do_idop);
27524 + e = au_refresh_i(sb, do_idop);
27525 + if (unlikely(e && !err))
27527 + /* aufs_write_lock() calls ..._child() */
27528 + di_write_lock_child(root);
27530 + au_cpup_attr_all(inode, /*force*/1);
27532 + if (unlikely(err))
27533 + AuIOErr("refresh failed, ignored, %d\n", err);
27536 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27537 +static int cvt_err(int err)
27551 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27554 + unsigned int mntflags;
27555 + struct au_opts opts = {
27558 + struct dentry *root;
27559 + struct inode *inode;
27560 + struct au_sbinfo *sbinfo;
27563 + root = sb->s_root;
27564 + if (!data || !*data) {
27565 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27567 + di_write_lock_child(root);
27568 + err = au_opts_verify(sb, *flags, /*pending*/0);
27569 + aufs_write_unlock(root);
27575 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27576 + if (unlikely(!opts.opt))
27578 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27579 + opts.flags = AuOpts_REMOUNT;
27580 + opts.sb_flags = *flags;
27582 + /* parse it before aufs lock */
27583 + err = au_opts_parse(sb, data, &opts);
27584 + if (unlikely(err))
27587 + sbinfo = au_sbi(sb);
27588 + inode = d_inode(root);
27589 + inode_lock(inode);
27590 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27591 + if (unlikely(err))
27593 + di_write_lock_child(root);
27595 + /* au_opts_remount() may return an error */
27596 + err = au_opts_remount(sb, &opts);
27597 + au_opts_free(&opts);
27599 + if (au_ftest_opts(opts.flags, REFRESH))
27600 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
27602 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27603 + mntflags = au_mntflags(sb);
27604 + do_dx = !!au_opt_test(mntflags, DIO);
27605 + au_dy_arefresh(do_dx);
27608 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27609 + aufs_write_unlock(root);
27612 + inode_unlock(inode);
27614 + free_page((unsigned long)opts.opt);
27616 + err = cvt_err(err);
27621 +static const struct super_operations aufs_sop = {
27622 + .alloc_inode = aufs_alloc_inode,
27623 + .destroy_inode = aufs_destroy_inode,
27624 + /* always deleting, no clearing */
27625 + .drop_inode = generic_delete_inode,
27626 + .show_options = aufs_show_options,
27627 + .statfs = aufs_statfs,
27628 + .put_super = aufs_put_super,
27629 + .sync_fs = aufs_sync_fs,
27630 + .remount_fs = aufs_remount_fs
27633 +/* ---------------------------------------------------------------------- */
27635 +static int alloc_root(struct super_block *sb)
27638 + struct inode *inode;
27639 + struct dentry *root;
27642 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
27643 + err = PTR_ERR(inode);
27644 + if (IS_ERR(inode))
27647 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
27648 + inode->i_fop = &aufs_dir_fop;
27649 + inode->i_mode = S_IFDIR;
27650 + set_nlink(inode, 2);
27651 + unlock_new_inode(inode);
27653 + root = d_make_root(inode);
27654 + if (unlikely(!root))
27656 + err = PTR_ERR(root);
27657 + if (IS_ERR(root))
27660 + err = au_di_init(root);
27662 + sb->s_root = root;
27663 + return 0; /* success */
27671 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27672 + int silent __maybe_unused)
27675 + struct au_opts opts = {
27678 + struct au_sbinfo *sbinfo;
27679 + struct dentry *root;
27680 + struct inode *inode;
27681 + char *arg = raw_data;
27683 + if (unlikely(!arg || !*arg)) {
27685 + pr_err("no arg\n");
27690 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27691 + if (unlikely(!opts.opt))
27693 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27694 + opts.sb_flags = sb->s_flags;
27696 + err = au_si_alloc(sb);
27697 + if (unlikely(err))
27699 + sbinfo = au_sbi(sb);
27701 + /* all timestamps always follow the ones on the branch */
27702 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27703 + sb->s_op = &aufs_sop;
27704 + sb->s_d_op = &aufs_dop;
27705 + sb->s_magic = AUFS_SUPER_MAGIC;
27706 + sb->s_maxbytes = 0;
27707 + sb->s_stack_depth = 1;
27708 + au_export_init(sb);
27709 + /* au_xattr_init(sb); */
27711 + err = alloc_root(sb);
27712 + if (unlikely(err)) {
27713 + si_write_unlock(sb);
27716 + root = sb->s_root;
27717 + inode = d_inode(root);
27720 + * actually we can parse options regardless aufs lock here.
27721 + * but at remount time, parsing must be done before aufs lock.
27722 + * so we follow the same rule.
27724 + ii_write_lock_parent(inode);
27725 + aufs_write_unlock(root);
27726 + err = au_opts_parse(sb, arg, &opts);
27727 + if (unlikely(err))
27730 + /* lock vfs_inode first, then aufs. */
27731 + inode_lock(inode);
27732 + aufs_write_lock(root);
27733 + err = au_opts_mount(sb, &opts);
27734 + au_opts_free(&opts);
27735 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
27736 + sb->s_d_op = &aufs_dop_noreval;
27737 + pr_info("%pf\n", sb->s_d_op);
27738 + au_refresh_dop(root, /*force_reval*/0);
27739 + sbinfo->si_iop_array = aufs_iop_nogetattr;
27740 + au_refresh_iop(inode, /*force_getattr*/0);
27742 + aufs_write_unlock(root);
27743 + inode_unlock(inode);
27745 + goto out_opts; /* success */
27749 + sb->s_root = NULL;
27751 + dbgaufs_si_fin(sbinfo);
27752 + kobject_put(&sbinfo->si_kobj);
27753 + sb->s_fs_info = NULL;
27755 + free_page((unsigned long)opts.opt);
27758 + err = cvt_err(err);
27763 +/* ---------------------------------------------------------------------- */
27765 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27766 + const char *dev_name __maybe_unused,
27769 + struct dentry *root;
27770 + struct super_block *sb;
27772 + /* all timestamps always follow the ones on the branch */
27773 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27774 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27775 + if (IS_ERR(root))
27779 + si_write_lock(sb, !AuLock_FLUSH);
27780 + sysaufs_brs_add(sb, 0);
27781 + si_write_unlock(sb);
27782 + au_sbilist_add(sb);
27788 +static void aufs_kill_sb(struct super_block *sb)
27790 + struct au_sbinfo *sbinfo;
27792 + sbinfo = au_sbi(sb);
27794 + au_sbilist_del(sb);
27795 + aufs_write_lock(sb->s_root);
27797 + if (sbinfo->si_wbr_create_ops->fin)
27798 + sbinfo->si_wbr_create_ops->fin(sb);
27799 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27800 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27801 + au_remount_refresh(sb, /*do_idop*/0);
27803 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27804 + au_plink_put(sb, /*verbose*/1);
27806 + sbinfo->si_sb = NULL;
27807 + aufs_write_unlock(sb->s_root);
27808 + au_nwt_flush(&sbinfo->si_nowait);
27810 + kill_anon_super(sb);
27813 +struct file_system_type aufs_fs_type = {
27814 + .name = AUFS_FSTYPE,
27815 + /* a race between rename and others */
27816 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27817 + .mount = aufs_mount,
27818 + .kill_sb = aufs_kill_sb,
27819 + /* no need to __module_get() and module_put(). */
27820 + .owner = THIS_MODULE,
27822 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27823 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27824 +++ linux/fs/aufs/super.h 2016-04-24 18:32:51.393686895 +0200
27827 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27829 + * This program, aufs is free software; you can redistribute it and/or modify
27830 + * it under the terms of the GNU General Public License as published by
27831 + * the Free Software Foundation; either version 2 of the License, or
27832 + * (at your option) any later version.
27834 + * This program is distributed in the hope that it will be useful,
27835 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27836 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27837 + * GNU General Public License for more details.
27839 + * You should have received a copy of the GNU General Public License
27840 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27844 + * super_block operations
27847 +#ifndef __AUFS_SUPER_H__
27848 +#define __AUFS_SUPER_H__
27852 +#include <linux/fs.h>
27853 +#include <linux/kobject.h>
27854 +#include "rwsem.h"
27858 +/* policies to select one among multiple writable branches */
27859 +struct au_wbr_copyup_operations {
27860 + int (*copyup)(struct dentry *dentry);
27863 +#define AuWbr_DIR 1 /* target is a dir */
27864 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27866 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27867 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27868 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27870 +struct au_wbr_create_operations {
27871 + int (*create)(struct dentry *dentry, unsigned int flags);
27872 + int (*init)(struct super_block *sb);
27873 + int (*fin)(struct super_block *sb);
27876 +struct au_wbr_mfs {
27877 + struct mutex mfs_lock; /* protect this structure */
27878 + unsigned long mfs_jiffy;
27879 + unsigned long mfs_expire;
27880 + aufs_bindex_t mfs_bindex;
27882 + unsigned long long mfsrr_bytes;
27883 + unsigned long long mfsrr_watermark;
27886 +struct pseudo_link {
27888 + struct hlist_node hlist;
27889 + struct rcu_head rcu;
27891 + struct inode *inode;
27894 +#define AuPlink_NHASH 100
27895 +static inline int au_plink_hash(ino_t ino)
27897 + return ino % AuPlink_NHASH;
27900 +/* File-based Hierarchical Storage Management */
27902 +#ifdef CONFIG_AUFS_FHSM
27903 + /* allow only one process who can receive the notification */
27904 + spinlock_t fhsm_spin;
27906 + wait_queue_head_t fhsm_wqh;
27907 + atomic_t fhsm_readable;
27909 + /* these are protected by si_rwsem */
27910 + unsigned long fhsm_expire;
27911 + aufs_bindex_t fhsm_bottom;
27915 +#define AU_PIDSTEP (int)(BITS_TO_LONGS(PID_MAX_DEFAULT) * BITS_PER_LONG)
27916 +#define AU_NPIDMAP (int)DIV_ROUND_UP(PID_MAX_LIMIT, AU_PIDSTEP)
27917 +struct au_si_pid {
27918 + unsigned long *pid_bitmap[AU_NPIDMAP];
27919 + struct mutex pid_mtx;
27923 +struct au_sbinfo {
27924 + /* nowait tasks in the system-wide workqueue */
27925 + struct au_nowait_tasks si_nowait;
27928 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27929 + * rwsem for au_sbinfo is necessary.
27931 + struct au_rwsem si_rwsem;
27933 + /* prevent recursive locking in deleting inode */
27934 + struct au_si_pid au_si_pid;
27937 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27940 + atomic_long_t si_ninodes, si_nfiles;
27942 + /* branch management */
27943 + unsigned int si_generation;
27945 + /* see AuSi_ flags */
27946 + unsigned char au_si_status;
27948 + aufs_bindex_t si_bend;
27950 + /* dirty trick to keep br_id plus */
27951 + unsigned int si_last_br_id :
27952 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27953 + struct au_branch **si_branch;
27955 + /* policy to select a writable branch */
27956 + unsigned char si_wbr_copyup;
27957 + unsigned char si_wbr_create;
27958 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27959 + struct au_wbr_create_operations *si_wbr_create_ops;
27961 + /* round robin */
27962 + atomic_t si_wbr_rr_next;
27964 + /* most free space */
27965 + struct au_wbr_mfs si_wbr_mfs;
27967 + /* File-based Hierarchical Storage Management */
27968 + struct au_fhsm si_fhsm;
27970 + /* mount flags */
27971 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27972 + unsigned int si_mntflags;
27974 + /* external inode number (bitmap and translation table) */
27975 + vfs_readf_t si_xread;
27976 + vfs_writef_t si_xwrite;
27977 + struct file *si_xib;
27978 + struct mutex si_xib_mtx; /* protect xib members */
27979 + unsigned long *si_xib_buf;
27980 + unsigned long si_xib_last_pindex;
27981 + int si_xib_next_bit;
27982 + aufs_bindex_t si_xino_brid;
27983 + unsigned long si_xino_jiffy;
27984 + unsigned long si_xino_expire;
27985 + /* reserved for future use */
27986 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
27988 +#ifdef CONFIG_AUFS_EXPORT
27989 + /* i_generation */
27990 + struct file *si_xigen;
27991 + atomic_t si_xigen_next;
27994 + /* dirty trick to suppoer atomic_open */
27995 + struct au_sphlhead si_aopen;
27997 + /* vdir parameters */
27998 + unsigned long si_rdcache; /* max cache time in jiffies */
27999 + unsigned int si_rdblk; /* deblk size */
28000 + unsigned int si_rdhash; /* hash size */
28003 + * If the number of whiteouts are larger than si_dirwh, leave all of
28004 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28005 + * future fsck.aufs or kernel thread will remove them later.
28006 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28008 + unsigned int si_dirwh;
28010 + /* pseudo_link list */
28011 + struct au_sphlhead si_plink[AuPlink_NHASH];
28012 + wait_queue_head_t si_plink_wq;
28013 + spinlock_t si_plink_maint_lock;
28014 + pid_t si_plink_maint_pid;
28017 + struct au_sphlhead si_files;
28019 + /* with/without getattr, brother of sb->s_d_op */
28020 + struct inode_operations *si_iop_array;
28023 + * sysfs and lifetime management.
28024 + * this is not a small structure and it may be a waste of memory in case
28025 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28026 + * but using sysfs is majority.
28028 + struct kobject si_kobj;
28029 +#ifdef CONFIG_DEBUG_FS
28030 + struct dentry *si_dbgaufs;
28031 + struct dentry *si_dbgaufs_plink;
28032 + struct dentry *si_dbgaufs_xib;
28033 +#ifdef CONFIG_AUFS_EXPORT
28034 + struct dentry *si_dbgaufs_xigen;
28038 +#ifdef CONFIG_AUFS_SBILIST
28039 + struct list_head si_list;
28042 + /* dirty, necessary for unmounting, sysfs and sysrq */
28043 + struct super_block *si_sb;
28046 +/* sbinfo status flags */
28048 + * set true when refresh_dirs() failed at remount time.
28049 + * then try refreshing dirs at access time again.
28050 + * if it is false, refreshing dirs at access time is unnecesary
28052 +#define AuSi_FAILED_REFRESH_DIR 1
28053 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28054 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28056 +#ifndef CONFIG_AUFS_FHSM
28058 +#define AuSi_FHSM 0
28061 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28062 + unsigned int flag)
28064 + AuRwMustAnyLock(&sbi->si_rwsem);
28065 + return sbi->au_si_status & flag;
28067 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28068 +#define au_fset_si(sbinfo, name) do { \
28069 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28070 + (sbinfo)->au_si_status |= AuSi_##name; \
28072 +#define au_fclr_si(sbinfo, name) do { \
28073 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28074 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28077 +/* ---------------------------------------------------------------------- */
28079 +/* policy to select one among writable branches */
28080 +#define AuWbrCopyup(sbinfo, ...) \
28081 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28082 +#define AuWbrCreate(sbinfo, ...) \
28083 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28085 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28086 +#define AuLock_DW 1 /* write-lock dentry */
28087 +#define AuLock_IR (1 << 1) /* read-lock inode */
28088 +#define AuLock_IW (1 << 2) /* write-lock inode */
28089 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28090 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28091 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28092 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28093 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28094 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28095 +#define au_fset_lock(flags, name) \
28096 + do { (flags) |= AuLock_##name; } while (0)
28097 +#define au_fclr_lock(flags, name) \
28098 + do { (flags) &= ~AuLock_##name; } while (0)
28100 +/* ---------------------------------------------------------------------- */
28103 +extern struct file_system_type aufs_fs_type;
28104 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28105 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28106 + unsigned long long max, void *arg);
28107 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28108 + struct super_block *sb, void *arg);
28109 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28110 +void au_iarray_free(struct inode **a, unsigned long long max);
28113 +void au_si_free(struct kobject *kobj);
28114 +int au_si_alloc(struct super_block *sb);
28115 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
28117 +unsigned int au_sigen_inc(struct super_block *sb);
28118 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28120 +int si_read_lock(struct super_block *sb, int flags);
28121 +int si_write_lock(struct super_block *sb, int flags);
28122 +int aufs_read_lock(struct dentry *dentry, int flags);
28123 +void aufs_read_unlock(struct dentry *dentry, int flags);
28124 +void aufs_write_lock(struct dentry *dentry);
28125 +void aufs_write_unlock(struct dentry *dentry);
28126 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28127 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28129 +/* wbr_policy.c */
28130 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28131 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28132 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28133 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28134 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
28137 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28139 +#ifdef CONFIG_AUFS_FHSM
28142 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28146 + spin_lock(&fhsm->fhsm_spin);
28147 + pid = fhsm->fhsm_pid;
28148 + spin_unlock(&fhsm->fhsm_spin);
28153 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28154 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28155 +int au_fhsm_fd(struct super_block *sb, int oflags);
28156 +int au_fhsm_br_alloc(struct au_branch *br);
28157 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28158 +void au_fhsm_fin(struct super_block *sb);
28159 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28160 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28161 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28163 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28165 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28166 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28167 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28168 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28169 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28170 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28171 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28172 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28173 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28176 +/* ---------------------------------------------------------------------- */
28178 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28180 + return sb->s_fs_info;
28183 +/* ---------------------------------------------------------------------- */
28185 +#ifdef CONFIG_AUFS_EXPORT
28186 +int au_test_nfsd(void);
28187 +void au_export_init(struct super_block *sb);
28188 +void au_xigen_inc(struct inode *inode);
28189 +int au_xigen_new(struct inode *inode);
28190 +int au_xigen_set(struct super_block *sb, struct file *base);
28191 +void au_xigen_clr(struct super_block *sb);
28193 +static inline int au_busy_or_stale(void)
28195 + if (!au_test_nfsd())
28200 +AuStubInt0(au_test_nfsd, void)
28201 +AuStubVoid(au_export_init, struct super_block *sb)
28202 +AuStubVoid(au_xigen_inc, struct inode *inode)
28203 +AuStubInt0(au_xigen_new, struct inode *inode)
28204 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28205 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28206 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28207 +#endif /* CONFIG_AUFS_EXPORT */
28209 +/* ---------------------------------------------------------------------- */
28211 +#ifdef CONFIG_AUFS_SBILIST
28213 +extern struct au_splhead au_sbilist;
28215 +static inline void au_sbilist_init(void)
28217 + au_spl_init(&au_sbilist);
28220 +static inline void au_sbilist_add(struct super_block *sb)
28222 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
28225 +static inline void au_sbilist_del(struct super_block *sb)
28227 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
28230 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28231 +static inline void au_sbilist_lock(void)
28233 + spin_lock(&au_sbilist.spin);
28236 +static inline void au_sbilist_unlock(void)
28238 + spin_unlock(&au_sbilist.spin);
28240 +#define AuGFP_SBILIST GFP_ATOMIC
28242 +AuStubVoid(au_sbilist_lock, void)
28243 +AuStubVoid(au_sbilist_unlock, void)
28244 +#define AuGFP_SBILIST GFP_NOFS
28245 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28247 +AuStubVoid(au_sbilist_init, void)
28248 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28249 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28250 +AuStubVoid(au_sbilist_lock, void)
28251 +AuStubVoid(au_sbilist_unlock, void)
28252 +#define AuGFP_SBILIST GFP_NOFS
28255 +/* ---------------------------------------------------------------------- */
28257 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28260 + * This function is a dynamic '__init' function actually,
28261 + * so the tiny check for si_rwsem is unnecessary.
28263 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28264 +#ifdef CONFIG_DEBUG_FS
28265 + sbinfo->si_dbgaufs = NULL;
28266 + sbinfo->si_dbgaufs_plink = NULL;
28267 + sbinfo->si_dbgaufs_xib = NULL;
28268 +#ifdef CONFIG_AUFS_EXPORT
28269 + sbinfo->si_dbgaufs_xigen = NULL;
28274 +/* ---------------------------------------------------------------------- */
28276 +static inline void si_pid_idx_bit(int *idx, pid_t *bit)
28278 + /* the origin of pid is 1, but the bitmap's is 0 */
28279 + *bit = current->pid - 1;
28280 + *idx = *bit / AU_PIDSTEP;
28281 + *bit %= AU_PIDSTEP;
28284 +static inline int si_pid_test(struct super_block *sb)
28288 + unsigned long *bitmap;
28290 + si_pid_idx_bit(&idx, &bit);
28291 + bitmap = au_sbi(sb)->au_si_pid.pid_bitmap[idx];
28293 + return test_bit(bit, bitmap);
28297 +static inline void si_pid_clr(struct super_block *sb)
28301 + unsigned long *bitmap;
28303 + si_pid_idx_bit(&idx, &bit);
28304 + bitmap = au_sbi(sb)->au_si_pid.pid_bitmap[idx];
28306 + AuDebugOn(!test_bit(bit, bitmap));
28307 + clear_bit(bit, bitmap);
28311 +void si_pid_set(struct super_block *sb);
28313 +/* ---------------------------------------------------------------------- */
28315 +/* lock superblock. mainly for entry point functions */
28317 + * __si_read_lock, __si_write_lock,
28318 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28320 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28322 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28323 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28324 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28326 +static inline void si_noflush_read_lock(struct super_block *sb)
28328 + __si_read_lock(sb);
28332 +static inline int si_noflush_read_trylock(struct super_block *sb)
28336 + locked = __si_read_trylock(sb);
28342 +static inline void si_noflush_write_lock(struct super_block *sb)
28344 + __si_write_lock(sb);
28348 +static inline int si_noflush_write_trylock(struct super_block *sb)
28352 + locked = __si_write_trylock(sb);
28358 +#if 0 /* reserved */
28359 +static inline int si_read_trylock(struct super_block *sb, int flags)
28361 + if (au_ftest_lock(flags, FLUSH))
28362 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28363 + return si_noflush_read_trylock(sb);
28367 +static inline void si_read_unlock(struct super_block *sb)
28370 + __si_read_unlock(sb);
28373 +#if 0 /* reserved */
28374 +static inline int si_write_trylock(struct super_block *sb, int flags)
28376 + if (au_ftest_lock(flags, FLUSH))
28377 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28378 + return si_noflush_write_trylock(sb);
28382 +static inline void si_write_unlock(struct super_block *sb)
28385 + __si_write_unlock(sb);
28388 +#if 0 /* reserved */
28389 +static inline void si_downgrade_lock(struct super_block *sb)
28391 + __si_downgrade_lock(sb);
28395 +/* ---------------------------------------------------------------------- */
28397 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
28399 + SiMustAnyLock(sb);
28400 + return au_sbi(sb)->si_bend;
28403 +static inline unsigned int au_mntflags(struct super_block *sb)
28405 + SiMustAnyLock(sb);
28406 + return au_sbi(sb)->si_mntflags;
28409 +static inline unsigned int au_sigen(struct super_block *sb)
28411 + SiMustAnyLock(sb);
28412 + return au_sbi(sb)->si_generation;
28415 +static inline void au_ninodes_inc(struct super_block *sb)
28417 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
28420 +static inline void au_ninodes_dec(struct super_block *sb)
28422 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
28423 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
28426 +static inline void au_nfiles_inc(struct super_block *sb)
28428 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
28431 +static inline void au_nfiles_dec(struct super_block *sb)
28433 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
28434 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
28437 +static inline struct au_branch *au_sbr(struct super_block *sb,
28438 + aufs_bindex_t bindex)
28440 + SiMustAnyLock(sb);
28441 + return au_sbi(sb)->si_branch[0 + bindex];
28444 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28446 + SiMustWriteLock(sb);
28447 + au_sbi(sb)->si_xino_brid = brid;
28450 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28452 + SiMustAnyLock(sb);
28453 + return au_sbi(sb)->si_xino_brid;
28456 +#endif /* __KERNEL__ */
28457 +#endif /* __AUFS_SUPER_H__ */
28458 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28459 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28460 +++ linux/fs/aufs/sysaufs.c 2016-04-24 18:32:51.393686895 +0200
28463 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28465 + * This program, aufs is free software; you can redistribute it and/or modify
28466 + * it under the terms of the GNU General Public License as published by
28467 + * the Free Software Foundation; either version 2 of the License, or
28468 + * (at your option) any later version.
28470 + * This program is distributed in the hope that it will be useful,
28471 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28472 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28473 + * GNU General Public License for more details.
28475 + * You should have received a copy of the GNU General Public License
28476 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28480 + * sysfs interface and lifetime management
28481 + * they are necessary regardless sysfs is disabled.
28484 +#include <linux/random.h>
28487 +unsigned long sysaufs_si_mask;
28488 +struct kset *sysaufs_kset;
28490 +#define AuSiAttr(_name) { \
28491 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28492 + .show = sysaufs_si_##_name, \
28495 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28496 +struct attribute *sysaufs_si_attrs[] = {
28497 + &sysaufs_si_attr_xi_path.attr,
28501 +static const struct sysfs_ops au_sbi_ops = {
28502 + .show = sysaufs_si_show
28505 +static struct kobj_type au_sbi_ktype = {
28506 + .release = au_si_free,
28507 + .sysfs_ops = &au_sbi_ops,
28508 + .default_attrs = sysaufs_si_attrs
28511 +/* ---------------------------------------------------------------------- */
28513 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28517 + sbinfo->si_kobj.kset = sysaufs_kset;
28518 + /* cf. sysaufs_name() */
28519 + err = kobject_init_and_add
28520 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28521 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28523 + dbgaufs_si_null(sbinfo);
28525 + err = dbgaufs_si_init(sbinfo);
28526 + if (unlikely(err))
28527 + kobject_put(&sbinfo->si_kobj);
28532 +void sysaufs_fin(void)
28535 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28536 + kset_unregister(sysaufs_kset);
28539 +int __init sysaufs_init(void)
28544 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28545 + } while (!sysaufs_si_mask);
28548 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28549 + if (unlikely(!sysaufs_kset))
28551 + err = PTR_ERR(sysaufs_kset);
28552 + if (IS_ERR(sysaufs_kset))
28554 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28555 + if (unlikely(err)) {
28556 + kset_unregister(sysaufs_kset);
28560 + err = dbgaufs_init();
28561 + if (unlikely(err))
28566 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28567 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28568 +++ linux/fs/aufs/sysaufs.h 2016-04-24 18:32:51.393686895 +0200
28571 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28573 + * This program, aufs is free software; you can redistribute it and/or modify
28574 + * it under the terms of the GNU General Public License as published by
28575 + * the Free Software Foundation; either version 2 of the License, or
28576 + * (at your option) any later version.
28578 + * This program is distributed in the hope that it will be useful,
28579 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28580 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28581 + * GNU General Public License for more details.
28583 + * You should have received a copy of the GNU General Public License
28584 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28588 + * sysfs interface and mount lifetime management
28591 +#ifndef __SYSAUFS_H__
28592 +#define __SYSAUFS_H__
28596 +#include <linux/sysfs.h>
28597 +#include "module.h"
28599 +struct super_block;
28602 +struct sysaufs_si_attr {
28603 + struct attribute attr;
28604 + int (*show)(struct seq_file *seq, struct super_block *sb);
28607 +/* ---------------------------------------------------------------------- */
28610 +extern unsigned long sysaufs_si_mask;
28611 +extern struct kset *sysaufs_kset;
28612 +extern struct attribute *sysaufs_si_attrs[];
28613 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28614 +int __init sysaufs_init(void);
28615 +void sysaufs_fin(void);
28617 +/* ---------------------------------------------------------------------- */
28619 +/* some people doesn't like to show a pointer in kernel */
28620 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28622 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28625 +#define SysaufsSiNamePrefix "si_"
28626 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
28627 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
28629 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
28630 + sysaufs_si_id(sbinfo));
28634 +#ifdef CONFIG_SYSFS
28636 +extern struct attribute_group *sysaufs_attr_group;
28638 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
28639 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28641 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
28642 +#ifdef CONFIG_COMPAT
28643 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
28646 +void sysaufs_br_init(struct au_branch *br);
28647 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
28648 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
28650 +#define sysaufs_brs_init() do {} while (0)
28653 +#define sysaufs_attr_group NULL
28655 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
28656 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
28657 + struct attribute *attr, char *buf)
28658 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
28659 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
28660 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28662 +static inline void sysaufs_brs_init(void)
28667 +#endif /* CONFIG_SYSFS */
28669 +#endif /* __KERNEL__ */
28670 +#endif /* __SYSAUFS_H__ */
28671 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
28672 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28673 +++ linux/fs/aufs/sysfs.c 2016-04-24 18:32:51.393686895 +0200
28676 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28678 + * This program, aufs is free software; you can redistribute it and/or modify
28679 + * it under the terms of the GNU General Public License as published by
28680 + * the Free Software Foundation; either version 2 of the License, or
28681 + * (at your option) any later version.
28683 + * This program is distributed in the hope that it will be useful,
28684 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28685 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28686 + * GNU General Public License for more details.
28688 + * You should have received a copy of the GNU General Public License
28689 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28693 + * sysfs interface
28696 +#include <linux/compat.h>
28697 +#include <linux/seq_file.h>
28700 +#ifdef CONFIG_AUFS_FS_MODULE
28701 +/* this entry violates the "one line per file" policy of sysfs */
28702 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28706 + static char *conf =
28707 +/* this file is generated at compiling */
28708 +#include "conf.str"
28711 + err = snprintf(buf, PAGE_SIZE, conf);
28712 + if (unlikely(err >= PAGE_SIZE))
28717 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28720 +static struct attribute *au_attr[] = {
28721 +#ifdef CONFIG_AUFS_FS_MODULE
28722 + &au_config_attr.attr,
28724 + NULL, /* need to NULL terminate the list of attributes */
28727 +static struct attribute_group sysaufs_attr_group_body = {
28731 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28733 +/* ---------------------------------------------------------------------- */
28735 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28739 + SiMustAnyLock(sb);
28742 + if (au_opt_test(au_mntflags(sb), XINO)) {
28743 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28744 + seq_putc(seq, '\n');
28750 + * the lifetime of branch is independent from the entry under sysfs.
28751 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28754 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28755 + aufs_bindex_t bindex, int idx)
28758 + struct path path;
28759 + struct dentry *root;
28760 + struct au_branch *br;
28761 + au_br_perm_str_t perm;
28763 + AuDbg("b%d\n", bindex);
28766 + root = sb->s_root;
28767 + di_read_lock_parent(root, !AuLock_IR);
28768 + br = au_sbr(sb, bindex);
28771 + case AuBrSysfs_BR:
28772 + path.mnt = au_br_mnt(br);
28773 + path.dentry = au_h_dptr(root, bindex);
28774 + err = au_seq_path(seq, &path);
28776 + au_optstr_br_perm(&perm, br->br_perm);
28777 + seq_printf(seq, "=%s\n", perm.a);
28780 + case AuBrSysfs_BRID:
28781 + seq_printf(seq, "%d\n", br->br_id);
28784 + di_read_unlock(root, !AuLock_IR);
28785 + if (unlikely(err || seq_has_overflowed(seq)))
28791 +/* ---------------------------------------------------------------------- */
28793 +static struct seq_file *au_seq(char *p, ssize_t len)
28795 + struct seq_file *seq;
28797 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28799 + /* mutex_init(&seq.lock); */
28802 + return seq; /* success */
28805 + seq = ERR_PTR(-ENOMEM);
28809 +#define SysaufsBr_PREFIX "br"
28810 +#define SysaufsBrid_PREFIX "brid"
28812 +/* todo: file size may exceed PAGE_SIZE */
28813 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28819 + aufs_bindex_t bend;
28820 + struct au_sbinfo *sbinfo;
28821 + struct super_block *sb;
28822 + struct seq_file *seq;
28824 + struct attribute **cattr;
28826 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28827 + sb = sbinfo->si_sb;
28830 + * prevent a race condition between sysfs and aufs.
28831 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28832 + * prohibits maintaining the sysfs entries.
28833 + * hew we acquire read lock after sysfs_get_active_two().
28834 + * on the other hand, the remount process may maintain the sysfs/aufs
28835 + * entries after acquiring write lock.
28836 + * it can cause a deadlock.
28837 + * simply we gave up processing read here.
28840 + if (unlikely(!si_noflush_read_trylock(sb)))
28843 + seq = au_seq(buf, PAGE_SIZE);
28844 + err = PTR_ERR(seq);
28848 + name = (void *)attr->name;
28849 + cattr = sysaufs_si_attrs;
28851 + if (!strcmp(name, (*cattr)->name)) {
28852 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28859 + if (!strncmp(name, SysaufsBrid_PREFIX,
28860 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28861 + idx = AuBrSysfs_BRID;
28862 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28863 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28864 + sizeof(SysaufsBr_PREFIX) - 1)) {
28865 + idx = AuBrSysfs_BR;
28866 + name += sizeof(SysaufsBr_PREFIX) - 1;
28870 + err = kstrtol(name, 10, &l);
28872 + bend = au_sbend(sb);
28874 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28881 + err = seq->count;
28882 + /* sysfs limit */
28883 + if (unlikely(err == PAGE_SIZE))
28888 + si_read_unlock(sb);
28893 +/* ---------------------------------------------------------------------- */
28895 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28899 + aufs_bindex_t bindex, bend;
28902 + struct seq_file *seq;
28903 + struct au_branch *br;
28905 + si_read_lock(sb, AuLock_FLUSH);
28906 + bend = au_sbend(sb);
28912 + buf = (void *)__get_free_page(GFP_NOFS);
28913 + if (unlikely(!buf))
28916 + seq = au_seq(buf, PAGE_SIZE);
28917 + err = PTR_ERR(seq);
28921 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28922 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28923 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28924 + if (unlikely(err))
28927 + br = au_sbr(sb, bindex);
28928 + brid = br->br_id;
28929 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28930 + err = __put_user(brid, &arg->id);
28931 + if (unlikely(err))
28934 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28935 + err = __put_user(br->br_perm, &arg->perm);
28936 + if (unlikely(err))
28939 + err = au_seq_path(seq, &br->br_path);
28940 + if (unlikely(err))
28942 + seq_putc(seq, '\0');
28943 + if (!seq_has_overflowed(seq)) {
28944 + err = copy_to_user(arg->path, seq->buf, seq->count);
28946 + if (unlikely(err))
28953 + if (unlikely(err))
28959 + free_page((unsigned long)buf);
28961 + si_read_unlock(sb);
28965 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28967 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
28970 +#ifdef CONFIG_COMPAT
28971 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
28973 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
28977 +/* ---------------------------------------------------------------------- */
28979 +void sysaufs_br_init(struct au_branch *br)
28982 + struct au_brsysfs *br_sysfs;
28983 + struct attribute *attr;
28985 + br_sysfs = br->br_sysfs;
28986 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28987 + attr = &br_sysfs->attr;
28988 + sysfs_attr_init(attr);
28989 + attr->name = br_sysfs->name;
28990 + attr->mode = S_IRUGO;
28995 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28997 + struct au_branch *br;
28998 + struct kobject *kobj;
28999 + struct au_brsysfs *br_sysfs;
29001 + aufs_bindex_t bend;
29003 + dbgaufs_brs_del(sb, bindex);
29005 + if (!sysaufs_brs)
29008 + kobj = &au_sbi(sb)->si_kobj;
29009 + bend = au_sbend(sb);
29010 + for (; bindex <= bend; bindex++) {
29011 + br = au_sbr(sb, bindex);
29012 + br_sysfs = br->br_sysfs;
29013 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29014 + sysfs_remove_file(kobj, &br_sysfs->attr);
29020 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29023 + aufs_bindex_t bend;
29024 + struct kobject *kobj;
29025 + struct au_branch *br;
29026 + struct au_brsysfs *br_sysfs;
29028 + dbgaufs_brs_add(sb, bindex);
29030 + if (!sysaufs_brs)
29033 + kobj = &au_sbi(sb)->si_kobj;
29034 + bend = au_sbend(sb);
29035 + for (; bindex <= bend; bindex++) {
29036 + br = au_sbr(sb, bindex);
29037 + br_sysfs = br->br_sysfs;
29038 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29039 + SysaufsBr_PREFIX "%d", bindex);
29040 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29041 + SysaufsBrid_PREFIX "%d", bindex);
29042 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29043 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29044 + if (unlikely(err))
29045 + pr_warn("failed %s under sysfs(%d)\n",
29046 + br_sysfs->name, err);
29051 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29052 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29053 +++ linux/fs/aufs/sysrq.c 2016-04-24 18:32:51.397020264 +0200
29056 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29058 + * This program, aufs is free software; you can redistribute it and/or modify
29059 + * it under the terms of the GNU General Public License as published by
29060 + * the Free Software Foundation; either version 2 of the License, or
29061 + * (at your option) any later version.
29063 + * This program is distributed in the hope that it will be useful,
29064 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29065 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29066 + * GNU General Public License for more details.
29068 + * You should have received a copy of the GNU General Public License
29069 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29073 + * magic sysrq hanlder
29076 +/* #include <linux/sysrq.h> */
29077 +#include <linux/writeback.h>
29080 +/* ---------------------------------------------------------------------- */
29082 +static void sysrq_sb(struct super_block *sb)
29085 + struct au_sbinfo *sbinfo;
29086 + struct file *file;
29087 + struct au_sphlhead *files;
29088 + struct au_finfo *finfo;
29090 + plevel = au_plevel;
29091 + au_plevel = KERN_WARNING;
29093 + /* since we define pr_fmt, call printk directly */
29094 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29096 + sbinfo = au_sbi(sb);
29097 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29098 + pr("superblock\n");
29102 + pr("root dentry\n");
29103 + au_dpri_dentry(sb->s_root);
29104 + pr("root inode\n");
29105 + au_dpri_inode(d_inode(sb->s_root));
29110 + int err, i, j, ndentry;
29111 + struct au_dcsub_pages dpages;
29112 + struct au_dpage *dpage;
29114 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29115 + if (unlikely(err))
29117 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29119 + for (i = 0; i < dpages.ndpage; i++) {
29120 + dpage = dpages.dpages + i;
29121 + ndentry = dpage->ndentry;
29122 + for (j = 0; j < ndentry; j++)
29123 + au_dpri_dentry(dpage->dentries[j]);
29125 + au_dpages_free(&dpages);
29133 + pr("isolated inode\n");
29134 + spin_lock(&sb->s_inode_list_lock);
29135 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29136 + spin_lock(&i->i_lock);
29137 + if (1 || hlist_empty(&i->i_dentry))
29138 + au_dpri_inode(i);
29139 + spin_unlock(&i->i_lock);
29141 + spin_unlock(&sb->s_inode_list_lock);
29145 + files = &au_sbi(sb)->si_files;
29146 + spin_lock(&files->spin);
29147 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29150 + file = finfo->fi_file;
29151 + mode = file_inode(file)->i_mode;
29152 + if (!special_file(mode))
29153 + au_dpri_file(file);
29155 + spin_unlock(&files->spin);
29159 + au_plevel = plevel;
29162 +/* ---------------------------------------------------------------------- */
29164 +/* module parameter */
29165 +static char *aufs_sysrq_key = "a";
29166 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29167 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29169 +static void au_sysrq(int key __maybe_unused)
29171 + struct au_sbinfo *sbinfo;
29174 + au_sbilist_lock();
29175 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29176 + sysrq_sb(sbinfo->si_sb);
29177 + au_sbilist_unlock();
29181 +static struct sysrq_key_op au_sysrq_op = {
29182 + .handler = au_sysrq,
29183 + .help_msg = "Aufs",
29184 + .action_msg = "Aufs",
29185 + .enable_mask = SYSRQ_ENABLE_DUMP
29188 +/* ---------------------------------------------------------------------- */
29190 +int __init au_sysrq_init(void)
29196 + key = *aufs_sysrq_key;
29197 + if ('a' <= key && key <= 'z')
29198 + err = register_sysrq_key(key, &au_sysrq_op);
29199 + if (unlikely(err))
29200 + pr_err("err %d, sysrq=%c\n", err, key);
29204 +void au_sysrq_fin(void)
29208 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29209 + if (unlikely(err))
29210 + pr_err("err %d (ignored)\n", err);
29212 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29213 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29214 +++ linux/fs/aufs/vdir.c 2016-04-24 18:32:51.397020264 +0200
29217 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29219 + * This program, aufs is free software; you can redistribute it and/or modify
29220 + * it under the terms of the GNU General Public License as published by
29221 + * the Free Software Foundation; either version 2 of the License, or
29222 + * (at your option) any later version.
29224 + * This program is distributed in the hope that it will be useful,
29225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29227 + * GNU General Public License for more details.
29229 + * You should have received a copy of the GNU General Public License
29230 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29234 + * virtual or vertical directory
29239 +static unsigned int calc_size(int nlen)
29241 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29244 +static int set_deblk_end(union au_vdir_deblk_p *p,
29245 + union au_vdir_deblk_p *deblk_end)
29247 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29248 + p->de->de_str.len = 0;
29252 + return -1; /* error */
29255 +/* returns true or false */
29256 +static int is_deblk_end(union au_vdir_deblk_p *p,
29257 + union au_vdir_deblk_p *deblk_end)
29259 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29260 + return !p->de->de_str.len;
29264 +static unsigned char *last_deblk(struct au_vdir *vdir)
29266 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29269 +/* ---------------------------------------------------------------------- */
29271 +/* estimate the appropriate size for name hash table */
29272 +unsigned int au_rdhash_est(loff_t sz)
29280 + if (sz < AUFS_RDHASH_DEF)
29281 + n = AUFS_RDHASH_DEF;
29282 + /* pr_info("n %u\n", n); */
29287 + * the allocated memory has to be freed by
29288 + * au_nhash_wh_free() or au_nhash_de_free().
29290 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29292 + struct hlist_head *head;
29296 + sz = sizeof(*nhash->nh_head) * num_hash;
29297 + head = kmalloc(sz, gfp);
29299 + nhash->nh_num = num_hash;
29300 + nhash->nh_head = head;
29301 + for (u = 0; u < num_hash; u++)
29302 + INIT_HLIST_HEAD(head++);
29303 + return 0; /* success */
29309 +static void nhash_count(struct hlist_head *head)
29313 + struct hlist_node *pos;
29316 + hlist_for_each(pos, head)
29318 + pr_info("%lu\n", n);
29322 +static void au_nhash_wh_do_free(struct hlist_head *head)
29324 + struct au_vdir_wh *pos;
29325 + struct hlist_node *node;
29327 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29331 +static void au_nhash_de_do_free(struct hlist_head *head)
29333 + struct au_vdir_dehstr *pos;
29334 + struct hlist_node *node;
29336 + hlist_for_each_entry_safe(pos, node, head, hash)
29337 + au_cache_free_vdir_dehstr(pos);
29340 +static void au_nhash_do_free(struct au_nhash *nhash,
29341 + void (*free)(struct hlist_head *head))
29344 + struct hlist_head *head;
29346 + n = nhash->nh_num;
29350 + head = nhash->nh_head;
29351 + while (n-- > 0) {
29352 + nhash_count(head);
29355 + kfree(nhash->nh_head);
29358 +void au_nhash_wh_free(struct au_nhash *whlist)
29360 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29363 +static void au_nhash_de_free(struct au_nhash *delist)
29365 + au_nhash_do_free(delist, au_nhash_de_do_free);
29368 +/* ---------------------------------------------------------------------- */
29370 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29374 + unsigned int u, n;
29375 + struct hlist_head *head;
29376 + struct au_vdir_wh *pos;
29379 + n = whlist->nh_num;
29380 + head = whlist->nh_head;
29381 + for (u = 0; u < n; u++, head++)
29382 + hlist_for_each_entry(pos, head, wh_hash)
29383 + if (pos->wh_bindex == btgt && ++num > limit)
29388 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29389 + unsigned char *name,
29390 + unsigned int len)
29393 + /* const unsigned int magic_bit = 12; */
29395 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29400 + /* v = hash_long(v, magic_bit); */
29401 + v %= nhash->nh_num;
29402 + return nhash->nh_head + v;
29405 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29408 + return str->len == nlen && !memcmp(str->name, name, nlen);
29411 +/* returns found or not */
29412 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29414 + struct hlist_head *head;
29415 + struct au_vdir_wh *pos;
29416 + struct au_vdir_destr *str;
29418 + head = au_name_hash(whlist, name, nlen);
29419 + hlist_for_each_entry(pos, head, wh_hash) {
29420 + str = &pos->wh_str;
29421 + AuDbg("%.*s\n", str->len, str->name);
29422 + if (au_nhash_test_name(str, name, nlen))
29428 +/* returns found(true) or not */
29429 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29431 + struct hlist_head *head;
29432 + struct au_vdir_dehstr *pos;
29433 + struct au_vdir_destr *str;
29435 + head = au_name_hash(delist, name, nlen);
29436 + hlist_for_each_entry(pos, head, hash) {
29438 + AuDbg("%.*s\n", str->len, str->name);
29439 + if (au_nhash_test_name(str, name, nlen))
29445 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29446 + unsigned char d_type)
29448 +#ifdef CONFIG_AUFS_SHWH
29449 + wh->wh_ino = ino;
29450 + wh->wh_type = d_type;
29454 +/* ---------------------------------------------------------------------- */
29456 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29457 + unsigned int d_type, aufs_bindex_t bindex,
29458 + unsigned char shwh)
29461 + struct au_vdir_destr *str;
29462 + struct au_vdir_wh *wh;
29464 + AuDbg("%.*s\n", nlen, name);
29465 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29468 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29469 + if (unlikely(!wh))
29473 + wh->wh_bindex = bindex;
29475 + au_shwh_init_wh(wh, ino, d_type);
29476 + str = &wh->wh_str;
29478 + memcpy(str->name, name, nlen);
29479 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29486 +static int append_deblk(struct au_vdir *vdir)
29489 + unsigned long ul;
29490 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29491 + union au_vdir_deblk_p p, deblk_end;
29492 + unsigned char **o;
29495 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29497 + if (unlikely(!o))
29500 + vdir->vd_deblk = o;
29501 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29503 + ul = vdir->vd_nblk++;
29504 + vdir->vd_deblk[ul] = p.deblk;
29505 + vdir->vd_last.ul = ul;
29506 + vdir->vd_last.p.deblk = p.deblk;
29507 + deblk_end.deblk = p.deblk + deblk_sz;
29508 + err = set_deblk_end(&p, &deblk_end);
29515 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29516 + unsigned int d_type, struct au_nhash *delist)
29520 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29521 + union au_vdir_deblk_p p, *room, deblk_end;
29522 + struct au_vdir_dehstr *dehstr;
29524 + p.deblk = last_deblk(vdir);
29525 + deblk_end.deblk = p.deblk + deblk_sz;
29526 + room = &vdir->vd_last.p;
29527 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29528 + || !is_deblk_end(room, &deblk_end));
29530 + sz = calc_size(nlen);
29531 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29532 + err = append_deblk(vdir);
29533 + if (unlikely(err))
29536 + p.deblk = last_deblk(vdir);
29537 + deblk_end.deblk = p.deblk + deblk_sz;
29539 + AuDebugOn(room->deblk != p.deblk);
29543 + dehstr = au_cache_alloc_vdir_dehstr();
29544 + if (unlikely(!dehstr))
29547 + dehstr->str = &room->de->de_str;
29548 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29549 + room->de->de_ino = ino;
29550 + room->de->de_type = d_type;
29551 + room->de->de_str.len = nlen;
29552 + memcpy(room->de->de_str.name, name, nlen);
29555 + room->deblk += sz;
29556 + if (unlikely(set_deblk_end(room, &deblk_end)))
29557 + err = append_deblk(vdir);
29564 +/* ---------------------------------------------------------------------- */
29566 +void au_vdir_free(struct au_vdir *vdir)
29568 + unsigned char **deblk;
29570 + deblk = vdir->vd_deblk;
29571 + while (vdir->vd_nblk--)
29573 + kfree(vdir->vd_deblk);
29574 + au_cache_free_vdir(vdir);
29577 +static struct au_vdir *alloc_vdir(struct file *file)
29579 + struct au_vdir *vdir;
29580 + struct super_block *sb;
29583 + sb = file->f_path.dentry->d_sb;
29584 + SiMustAnyLock(sb);
29587 + vdir = au_cache_alloc_vdir();
29588 + if (unlikely(!vdir))
29591 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29592 + if (unlikely(!vdir->vd_deblk))
29595 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29596 + if (!vdir->vd_deblk_sz) {
29597 + /* estimate the appropriate size for deblk */
29598 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29599 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29601 + vdir->vd_nblk = 0;
29602 + vdir->vd_version = 0;
29603 + vdir->vd_jiffy = 0;
29604 + err = append_deblk(vdir);
29606 + return vdir; /* success */
29608 + kfree(vdir->vd_deblk);
29611 + au_cache_free_vdir(vdir);
29613 + vdir = ERR_PTR(err);
29617 +static int reinit_vdir(struct au_vdir *vdir)
29620 + union au_vdir_deblk_p p, deblk_end;
29622 + while (vdir->vd_nblk > 1) {
29623 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
29624 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
29627 + p.deblk = vdir->vd_deblk[0];
29628 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
29629 + err = set_deblk_end(&p, &deblk_end);
29630 + /* keep vd_dblk_sz */
29631 + vdir->vd_last.ul = 0;
29632 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29633 + vdir->vd_version = 0;
29634 + vdir->vd_jiffy = 0;
29639 +/* ---------------------------------------------------------------------- */
29641 +#define AuFillVdir_CALLED 1
29642 +#define AuFillVdir_WHABLE (1 << 1)
29643 +#define AuFillVdir_SHWH (1 << 2)
29644 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
29645 +#define au_fset_fillvdir(flags, name) \
29646 + do { (flags) |= AuFillVdir_##name; } while (0)
29647 +#define au_fclr_fillvdir(flags, name) \
29648 + do { (flags) &= ~AuFillVdir_##name; } while (0)
29650 +#ifndef CONFIG_AUFS_SHWH
29651 +#undef AuFillVdir_SHWH
29652 +#define AuFillVdir_SHWH 0
29655 +struct fillvdir_arg {
29656 + struct dir_context ctx;
29657 + struct file *file;
29658 + struct au_vdir *vdir;
29659 + struct au_nhash delist;
29660 + struct au_nhash whlist;
29661 + aufs_bindex_t bindex;
29662 + unsigned int flags;
29666 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29667 + loff_t offset __maybe_unused, u64 h_ino,
29668 + unsigned int d_type)
29670 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29671 + char *name = (void *)__name;
29672 + struct super_block *sb;
29674 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29677 + sb = arg->file->f_path.dentry->d_sb;
29678 + au_fset_fillvdir(arg->flags, CALLED);
29680 + if (nlen <= AUFS_WH_PFX_LEN
29681 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29682 + if (test_known(&arg->delist, name, nlen)
29683 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29684 + goto out; /* already exists or whiteouted */
29686 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29688 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29689 + d_type = DT_UNKNOWN;
29690 + arg->err = append_de(arg->vdir, name, nlen, ino,
29691 + d_type, &arg->delist);
29693 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29694 + name += AUFS_WH_PFX_LEN;
29695 + nlen -= AUFS_WH_PFX_LEN;
29696 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29697 + goto out; /* already whiteouted */
29700 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29703 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29704 + d_type = DT_UNKNOWN;
29705 + arg->err = au_nhash_append_wh
29706 + (&arg->whlist, name, nlen, ino, d_type,
29707 + arg->bindex, shwh);
29713 + arg->vdir->vd_jiffy = jiffies;
29715 + AuTraceErr(arg->err);
29719 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29720 + struct au_nhash *whlist, struct au_nhash *delist)
29722 +#ifdef CONFIG_AUFS_SHWH
29724 + unsigned int nh, u;
29725 + struct hlist_head *head;
29726 + struct au_vdir_wh *pos;
29727 + struct hlist_node *n;
29729 + struct au_vdir_destr *destr;
29731 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29734 + o = p = (void *)__get_free_page(GFP_NOFS);
29735 + if (unlikely(!p))
29739 + nh = whlist->nh_num;
29740 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29741 + p += AUFS_WH_PFX_LEN;
29742 + for (u = 0; u < nh; u++) {
29743 + head = whlist->nh_head + u;
29744 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29745 + destr = &pos->wh_str;
29746 + memcpy(p, destr->name, destr->len);
29747 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29748 + pos->wh_ino, pos->wh_type, delist);
29749 + if (unlikely(err))
29754 + free_page((unsigned long)o);
29764 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29767 + unsigned int rdhash;
29769 + aufs_bindex_t bend, bindex, bstart;
29770 + unsigned char shwh;
29771 + struct file *hf, *file;
29772 + struct super_block *sb;
29774 + file = arg->file;
29775 + sb = file->f_path.dentry->d_sb;
29776 + SiMustAnyLock(sb);
29778 + rdhash = au_sbi(sb)->si_rdhash;
29780 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29781 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29782 + if (unlikely(err))
29784 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29785 + if (unlikely(err))
29791 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29793 + au_fset_fillvdir(arg->flags, SHWH);
29795 + bstart = au_fbstart(file);
29796 + bend = au_fbend_dir(file);
29797 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29798 + hf = au_hf_dir(file, bindex);
29802 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29804 + if (unlikely(offset))
29807 + arg->bindex = bindex;
29808 + au_fclr_fillvdir(arg->flags, WHABLE);
29810 + || (bindex != bend
29811 + && au_br_whable(au_sbr_perm(sb, bindex))))
29812 + au_fset_fillvdir(arg->flags, WHABLE);
29815 + au_fclr_fillvdir(arg->flags, CALLED);
29817 + err = vfsub_iterate_dir(hf, &arg->ctx);
29820 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29823 + * dir_relax() may be good for concurrency, but aufs should not
29824 + * use it since it will cause a lockdep problem.
29828 + if (!err && shwh)
29829 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29831 + au_nhash_wh_free(&arg->whlist);
29834 + au_nhash_de_free(&arg->delist);
29839 +static int read_vdir(struct file *file, int may_read)
29842 + unsigned long expire;
29843 + unsigned char do_read;
29844 + struct fillvdir_arg arg = {
29846 + .actor = fillvdir
29849 + struct inode *inode;
29850 + struct au_vdir *vdir, *allocated;
29853 + inode = file_inode(file);
29854 + IMustLock(inode);
29855 + SiMustAnyLock(inode->i_sb);
29857 + allocated = NULL;
29859 + expire = au_sbi(inode->i_sb)->si_rdcache;
29860 + vdir = au_ivdir(inode);
29863 + vdir = alloc_vdir(file);
29864 + err = PTR_ERR(vdir);
29865 + if (IS_ERR(vdir))
29868 + allocated = vdir;
29869 + } else if (may_read
29870 + && (inode->i_version != vdir->vd_version
29871 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29873 + err = reinit_vdir(vdir);
29874 + if (unlikely(err))
29879 + return 0; /* success */
29883 + err = au_do_read_vdir(&arg);
29885 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29886 + vdir->vd_version = inode->i_version;
29887 + vdir->vd_last.ul = 0;
29888 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29890 + au_set_ivdir(inode, allocated);
29891 + } else if (allocated)
29892 + au_vdir_free(allocated);
29898 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29901 + unsigned long ul, n;
29902 + const unsigned int deblk_sz = src->vd_deblk_sz;
29904 + AuDebugOn(tgt->vd_nblk != 1);
29907 + if (tgt->vd_nblk < src->vd_nblk) {
29908 + unsigned char **p;
29910 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29912 + if (unlikely(!p))
29914 + tgt->vd_deblk = p;
29917 + if (tgt->vd_deblk_sz != deblk_sz) {
29918 + unsigned char *p;
29920 + tgt->vd_deblk_sz = deblk_sz;
29921 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29922 + if (unlikely(!p))
29924 + tgt->vd_deblk[0] = p;
29926 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29927 + tgt->vd_version = src->vd_version;
29928 + tgt->vd_jiffy = src->vd_jiffy;
29930 + n = src->vd_nblk;
29931 + for (ul = 1; ul < n; ul++) {
29932 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29934 + if (unlikely(!tgt->vd_deblk[ul]))
29938 + tgt->vd_nblk = n;
29939 + tgt->vd_last.ul = tgt->vd_last.ul;
29940 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29941 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29942 + - src->vd_deblk[src->vd_last.ul];
29944 + return 0; /* success */
29947 + rerr = reinit_vdir(tgt);
29952 +int au_vdir_init(struct file *file)
29955 + struct inode *inode;
29956 + struct au_vdir *vdir_cache, *allocated;
29958 + /* test file->f_pos here instead of ctx->pos */
29959 + err = read_vdir(file, !file->f_pos);
29960 + if (unlikely(err))
29963 + allocated = NULL;
29964 + vdir_cache = au_fvdir_cache(file);
29965 + if (!vdir_cache) {
29966 + vdir_cache = alloc_vdir(file);
29967 + err = PTR_ERR(vdir_cache);
29968 + if (IS_ERR(vdir_cache))
29970 + allocated = vdir_cache;
29971 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29972 + /* test file->f_pos here instead of ctx->pos */
29973 + err = reinit_vdir(vdir_cache);
29974 + if (unlikely(err))
29977 + return 0; /* success */
29979 + inode = file_inode(file);
29980 + err = copy_vdir(vdir_cache, au_ivdir(inode));
29982 + file->f_version = inode->i_version;
29984 + au_set_fvdir_cache(file, allocated);
29985 + } else if (allocated)
29986 + au_vdir_free(allocated);
29992 +static loff_t calc_offset(struct au_vdir *vdir)
29995 + union au_vdir_deblk_p p;
29997 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29998 + offset = vdir->vd_last.p.deblk - p.deblk;
29999 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30003 +/* returns true or false */
30004 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30007 + unsigned int deblk_sz;
30008 + unsigned long ul, n;
30010 + union au_vdir_deblk_p p, deblk_end;
30011 + struct au_vdir *vdir_cache;
30014 + vdir_cache = au_fvdir_cache(file);
30015 + offset = calc_offset(vdir_cache);
30016 + AuDbg("offset %lld\n", offset);
30017 + if (ctx->pos == offset)
30020 + vdir_cache->vd_last.ul = 0;
30021 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30026 + deblk_sz = vdir_cache->vd_deblk_sz;
30027 + ul = div64_u64(ctx->pos, deblk_sz);
30028 + AuDbg("ul %lu\n", ul);
30029 + if (ul >= vdir_cache->vd_nblk)
30032 + n = vdir_cache->vd_nblk;
30033 + for (; ul < n; ul++) {
30034 + p.deblk = vdir_cache->vd_deblk[ul];
30035 + deblk_end.deblk = p.deblk + deblk_sz;
30037 + offset *= deblk_sz;
30038 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30041 + l = calc_size(p.de->de_str.len);
30045 + if (!is_deblk_end(&p, &deblk_end)) {
30047 + vdir_cache->vd_last.ul = ul;
30048 + vdir_cache->vd_last.p = p;
30055 + AuTraceErr(!valid);
30059 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30061 + unsigned int l, deblk_sz;
30062 + union au_vdir_deblk_p deblk_end;
30063 + struct au_vdir *vdir_cache;
30064 + struct au_vdir_de *de;
30066 + vdir_cache = au_fvdir_cache(file);
30067 + if (!seek_vdir(file, ctx))
30070 + deblk_sz = vdir_cache->vd_deblk_sz;
30072 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30073 + deblk_end.deblk += deblk_sz;
30074 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30075 + de = vdir_cache->vd_last.p.de;
30076 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30077 + de->de_str.len, de->de_str.name, ctx->pos,
30078 + (unsigned long)de->de_ino, de->de_type);
30079 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30080 + de->de_str.len, de->de_ino,
30082 + /* todo: ignore the error caused by udba? */
30083 + /* return err; */
30087 + l = calc_size(de->de_str.len);
30088 + vdir_cache->vd_last.p.deblk += l;
30091 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30092 + vdir_cache->vd_last.ul++;
30093 + vdir_cache->vd_last.p.deblk
30094 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30095 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30104 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30105 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30106 +++ linux/fs/aufs/vfsub.c 2016-04-24 18:32:51.397020264 +0200
30109 + * Copyright (C) 2005-2016 Junjiro R. Okajima
30111 + * This program, aufs is free software; you can redistribute it and/or modify
30112 + * it under the terms of the GNU General Public License as published by
30113 + * the Free Software Foundation; either version 2 of the License, or
30114 + * (at your option) any later version.
30116 + * This program is distributed in the hope that it will be useful,
30117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30119 + * GNU General Public License for more details.
30121 + * You should have received a copy of the GNU General Public License
30122 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30126 + * sub-routines for VFS
30129 +#include <linux/namei.h>
30130 +#include <linux/nsproxy.h>
30131 +#include <linux/security.h>
30132 +#include <linux/splice.h>
30133 +#include "../fs/mount.h"
30136 +#ifdef CONFIG_AUFS_BR_FUSE
30137 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30139 + struct nsproxy *ns;
30141 + if (!au_test_fuse(h_sb) || !au_userns)
30144 + ns = current->nsproxy;
30145 + /* no {get,put}_nsproxy(ns) */
30146 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30150 +/* ---------------------------------------------------------------------- */
30152 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30156 + struct super_block *h_sb;
30158 + /* for remote fs, leave work for its getattr or d_revalidate */
30159 + /* for bad i_attr fs, handle them in aufs_getattr() */
30160 + /* still some fs may acquire i_mutex. we need to skip them */
30164 + h_sb = h_path->dentry->d_sb;
30165 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30167 + err = vfs_getattr(h_path, &st);
30172 +/* ---------------------------------------------------------------------- */
30174 +struct file *vfsub_dentry_open(struct path *path, int flags)
30176 + struct file *file;
30178 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30180 + if (!IS_ERR_OR_NULL(file)
30181 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30182 + i_readcount_inc(d_inode(path->dentry));
30187 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30189 + struct file *file;
30192 + file = filp_open(path,
30193 + oflags /* | __FMODE_NONOTIFY */,
30196 + if (IS_ERR(file))
30198 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30205 + * Ideally this function should call VFS:do_last() in order to keep all its
30206 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30207 + * structure such as nameidata. This is a second (or third) best approach.
30208 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30210 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30211 + struct vfsub_aopen_args *args, struct au_branch *br)
30214 + struct file *file = args->file;
30215 + /* copied from linux/fs/namei.c:atomic_open() */
30216 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30219 + AuDebugOn(!dir->i_op->atomic_open);
30221 + err = au_br_test_oflag(args->open_flag, br);
30222 + if (unlikely(err))
30225 + args->file->f_path.dentry = DENTRY_NOT_SET;
30226 + args->file->f_path.mnt = au_br_mnt(br);
30227 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30228 + args->create_mode, args->opened);
30230 + /* some filesystems don't set FILE_CREATED while succeeded? */
30231 + if (*args->opened & FILE_CREATED)
30232 + fsnotify_create(dir, dentry);
30238 + /* todo: call VFS:may_open() here */
30239 + err = open_check_o_direct(file);
30240 + /* todo: ima_file_check() too? */
30241 + if (!err && (args->open_flag & __FMODE_EXEC))
30242 + err = deny_write_access(file);
30243 + if (unlikely(err))
30244 + /* note that the file is created and still opened */
30248 + atomic_inc(&br->br_count);
30249 + fsnotify_open(file);
30255 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30259 + err = kern_path(name, flags, path);
30260 + if (!err && d_is_positive(path->dentry))
30261 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30265 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
30266 + struct dentry *parent, int len)
30268 + struct path path = {
30272 + path.dentry = lookup_one_len_unlocked(name, parent, len);
30273 + if (IS_ERR(path.dentry))
30275 + if (d_is_positive(path.dentry))
30276 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30279 + AuTraceErrPtr(path.dentry);
30280 + return path.dentry;
30283 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30286 + struct path path = {
30290 + /* VFS checks it too, but by WARN_ON_ONCE() */
30291 + IMustLock(d_inode(parent));
30293 + path.dentry = lookup_one_len(name, parent, len);
30294 + if (IS_ERR(path.dentry))
30296 + if (d_is_positive(path.dentry))
30297 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30300 + AuTraceErrPtr(path.dentry);
30301 + return path.dentry;
30304 +void vfsub_call_lkup_one(void *args)
30306 + struct vfsub_lkup_one_args *a = args;
30307 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30310 +/* ---------------------------------------------------------------------- */
30312 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30313 + struct dentry *d2, struct au_hinode *hdir2)
30315 + struct dentry *d;
30318 + d = lock_rename(d1, d2);
30320 + au_hn_suspend(hdir1);
30321 + if (hdir1 != hdir2)
30322 + au_hn_suspend(hdir2);
30327 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30328 + struct dentry *d2, struct au_hinode *hdir2)
30330 + au_hn_resume(hdir1);
30331 + if (hdir1 != hdir2)
30332 + au_hn_resume(hdir2);
30334 + unlock_rename(d1, d2);
30338 +/* ---------------------------------------------------------------------- */
30340 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30343 + struct dentry *d;
30347 + d = path->dentry;
30348 + path->dentry = d->d_parent;
30349 + err = security_path_mknod(path, d, mode, 0);
30350 + path->dentry = d;
30351 + if (unlikely(err))
30355 + err = vfs_create(dir, path->dentry, mode, want_excl);
30358 + struct path tmp = *path;
30361 + vfsub_update_h_iattr(&tmp, &did);
30363 + tmp.dentry = path->dentry->d_parent;
30364 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30373 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30376 + struct dentry *d;
30380 + d = path->dentry;
30381 + path->dentry = d->d_parent;
30382 + err = security_path_symlink(path, d, symname);
30383 + path->dentry = d;
30384 + if (unlikely(err))
30388 + err = vfs_symlink(dir, path->dentry, symname);
30391 + struct path tmp = *path;
30394 + vfsub_update_h_iattr(&tmp, &did);
30396 + tmp.dentry = path->dentry->d_parent;
30397 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30406 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30409 + struct dentry *d;
30413 + d = path->dentry;
30414 + path->dentry = d->d_parent;
30415 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30416 + path->dentry = d;
30417 + if (unlikely(err))
30421 + err = vfs_mknod(dir, path->dentry, mode, dev);
30424 + struct path tmp = *path;
30427 + vfsub_update_h_iattr(&tmp, &did);
30429 + tmp.dentry = path->dentry->d_parent;
30430 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30439 +static int au_test_nlink(struct inode *inode)
30441 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30443 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30444 + || inode->i_nlink < link_max)
30449 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30450 + struct inode **delegated_inode)
30453 + struct dentry *d;
30457 + err = au_test_nlink(d_inode(src_dentry));
30458 + if (unlikely(err))
30461 + /* we don't call may_linkat() */
30462 + d = path->dentry;
30463 + path->dentry = d->d_parent;
30464 + err = security_path_link(src_dentry, path, d);
30465 + path->dentry = d;
30466 + if (unlikely(err))
30470 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30473 + struct path tmp = *path;
30476 + /* fuse has different memory inode for the same inumber */
30477 + vfsub_update_h_iattr(&tmp, &did);
30479 + tmp.dentry = path->dentry->d_parent;
30480 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30481 + tmp.dentry = src_dentry;
30482 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30491 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30492 + struct inode *dir, struct path *path,
30493 + struct inode **delegated_inode)
30496 + struct path tmp = {
30499 + struct dentry *d;
30502 + IMustLock(src_dir);
30504 + d = path->dentry;
30505 + path->dentry = d->d_parent;
30506 + tmp.dentry = src_dentry->d_parent;
30507 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30508 + path->dentry = d;
30509 + if (unlikely(err))
30513 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30514 + delegated_inode, /*flags*/0);
30519 + tmp.dentry = d->d_parent;
30520 + vfsub_update_h_iattr(&tmp, &did);
30522 + tmp.dentry = src_dentry;
30523 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30524 + tmp.dentry = src_dentry->d_parent;
30525 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30534 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30537 + struct dentry *d;
30541 + d = path->dentry;
30542 + path->dentry = d->d_parent;
30543 + err = security_path_mkdir(path, d, mode);
30544 + path->dentry = d;
30545 + if (unlikely(err))
30549 + err = vfs_mkdir(dir, path->dentry, mode);
30552 + struct path tmp = *path;
30555 + vfsub_update_h_iattr(&tmp, &did);
30557 + tmp.dentry = path->dentry->d_parent;
30558 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30567 +int vfsub_rmdir(struct inode *dir, struct path *path)
30570 + struct dentry *d;
30574 + d = path->dentry;
30575 + path->dentry = d->d_parent;
30576 + err = security_path_rmdir(path, d);
30577 + path->dentry = d;
30578 + if (unlikely(err))
30582 + err = vfs_rmdir(dir, path->dentry);
30585 + struct path tmp = {
30586 + .dentry = path->dentry->d_parent,
30590 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30597 +/* ---------------------------------------------------------------------- */
30599 +/* todo: support mmap_sem? */
30600 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30606 + err = vfs_read(file, ubuf, count, ppos);
30609 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30613 +/* todo: kernel_read()? */
30614 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30618 + mm_segment_t oldfs;
30625 + oldfs = get_fs();
30626 + set_fs(KERNEL_DS);
30627 + err = vfsub_read_u(file, buf.u, count, ppos);
30632 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30638 + err = vfs_write(file, ubuf, count, ppos);
30641 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30645 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
30648 + mm_segment_t oldfs;
30651 + const char __user *u;
30655 + oldfs = get_fs();
30656 + set_fs(KERNEL_DS);
30657 + err = vfsub_write_u(file, buf.u, count, ppos);
30662 +int vfsub_flush(struct file *file, fl_owner_t id)
30667 + if (file->f_op->flush) {
30668 + if (!au_test_nfs(file->f_path.dentry->d_sb))
30669 + err = file->f_op->flush(file, id);
30672 + err = file->f_op->flush(file, id);
30676 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30682 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30686 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30689 + err = iterate_dir(file, ctx);
30692 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30696 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30697 + struct pipe_inode_info *pipe, size_t len,
30698 + unsigned int flags)
30703 + err = do_splice_to(in, ppos, pipe, len, flags);
30705 + file_accessed(in);
30707 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30711 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30712 + loff_t *ppos, size_t len, unsigned int flags)
30717 + err = do_splice_from(pipe, out, ppos, len, flags);
30720 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30724 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30728 + /* file can be NULL */
30730 + err = vfs_fsync(file, datasync);
30734 + AuDebugOn(!file);
30735 + path = &file->f_path;
30737 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30742 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30743 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30744 + struct file *h_file)
30747 + struct inode *h_inode;
30748 + struct super_block *h_sb;
30751 + err = vfsub_truncate(h_path, length);
30755 + h_inode = d_inode(h_path->dentry);
30756 + h_sb = h_inode->i_sb;
30758 + sb_start_write(h_sb);
30760 + err = locks_verify_truncate(h_inode, h_file, length);
30762 + err = security_path_truncate(h_path);
30765 + err = do_truncate(h_path->dentry, length, attr, h_file);
30769 + sb_end_write(h_sb);
30776 +/* ---------------------------------------------------------------------- */
30778 +struct au_vfsub_mkdir_args {
30780 + struct inode *dir;
30781 + struct path *path;
30785 +static void au_call_vfsub_mkdir(void *args)
30787 + struct au_vfsub_mkdir_args *a = args;
30788 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30791 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30793 + int err, do_sio, wkq_err;
30795 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30798 + err = vfsub_mkdir(dir, path, mode);
30801 + struct au_vfsub_mkdir_args args = {
30807 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30808 + if (unlikely(wkq_err))
30815 +struct au_vfsub_rmdir_args {
30817 + struct inode *dir;
30818 + struct path *path;
30821 +static void au_call_vfsub_rmdir(void *args)
30823 + struct au_vfsub_rmdir_args *a = args;
30824 + *a->errp = vfsub_rmdir(a->dir, a->path);
30827 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30829 + int err, do_sio, wkq_err;
30831 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30834 + err = vfsub_rmdir(dir, path);
30837 + struct au_vfsub_rmdir_args args = {
30842 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30843 + if (unlikely(wkq_err))
30850 +/* ---------------------------------------------------------------------- */
30852 +struct notify_change_args {
30854 + struct path *path;
30855 + struct iattr *ia;
30856 + struct inode **delegated_inode;
30859 +static void call_notify_change(void *args)
30861 + struct notify_change_args *a = args;
30862 + struct inode *h_inode;
30864 + h_inode = d_inode(a->path->dentry);
30865 + IMustLock(h_inode);
30867 + *a->errp = -EPERM;
30868 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30870 + *a->errp = notify_change(a->path->dentry, a->ia,
30871 + a->delegated_inode);
30874 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30876 + AuTraceErr(*a->errp);
30879 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30880 + struct inode **delegated_inode)
30883 + struct notify_change_args args = {
30887 + .delegated_inode = delegated_inode
30890 + call_notify_change(&args);
30895 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30896 + struct inode **delegated_inode)
30898 + int err, wkq_err;
30899 + struct notify_change_args args = {
30903 + .delegated_inode = delegated_inode
30906 + wkq_err = au_wkq_wait(call_notify_change, &args);
30907 + if (unlikely(wkq_err))
30913 +/* ---------------------------------------------------------------------- */
30915 +struct unlink_args {
30917 + struct inode *dir;
30918 + struct path *path;
30919 + struct inode **delegated_inode;
30922 +static void call_unlink(void *args)
30924 + struct unlink_args *a = args;
30925 + struct dentry *d = a->path->dentry;
30926 + struct inode *h_inode;
30927 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30928 + && au_dcount(d) == 1);
30930 + IMustLock(a->dir);
30932 + a->path->dentry = d->d_parent;
30933 + *a->errp = security_path_unlink(a->path, d);
30934 + a->path->dentry = d;
30935 + if (unlikely(*a->errp))
30938 + if (!stop_sillyrename)
30941 + if (d_is_positive(d)) {
30942 + h_inode = d_inode(d);
30947 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30950 + struct path tmp = {
30951 + .dentry = d->d_parent,
30952 + .mnt = a->path->mnt
30954 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30957 + if (!stop_sillyrename)
30962 + AuTraceErr(*a->errp);
30966 + * @dir: must be locked.
30967 + * @dentry: target dentry.
30969 +int vfsub_unlink(struct inode *dir, struct path *path,
30970 + struct inode **delegated_inode, int force)
30973 + struct unlink_args args = {
30977 + .delegated_inode = delegated_inode
30981 + call_unlink(&args);
30985 + wkq_err = au_wkq_wait(call_unlink, &args);
30986 + if (unlikely(wkq_err))
30992 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
30993 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
30994 +++ linux/fs/aufs/vfsub.h 2016-04-24 18:32:51.397020264 +0200
30997 + * Copyright (C) 2005-2016 Junjiro R. Okajima
30999 + * This program, aufs is free software; you can redistribute it and/or modify
31000 + * it under the terms of the GNU General Public License as published by
31001 + * the Free Software Foundation; either version 2 of the License, or
31002 + * (at your option) any later version.
31004 + * This program is distributed in the hope that it will be useful,
31005 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31006 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31007 + * GNU General Public License for more details.
31009 + * You should have received a copy of the GNU General Public License
31010 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31014 + * sub-routines for VFS
31017 +#ifndef __AUFS_VFSUB_H__
31018 +#define __AUFS_VFSUB_H__
31022 +#include <linux/fs.h>
31023 +#include <linux/mount.h>
31024 +#include <linux/posix_acl.h>
31025 +#include <linux/xattr.h>
31026 +#include "debug.h"
31028 +/* copied from linux/fs/internal.h */
31029 +/* todo: BAD approach!! */
31030 +extern void __mnt_drop_write(struct vfsmount *);
31031 +extern int open_check_o_direct(struct file *f);
31033 +/* ---------------------------------------------------------------------- */
31035 +/* lock subclass for lower inode */
31036 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31037 +/* reduce? gave up. */
31039 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31040 + AuLsc_I_PARENT, /* lower inode, parent first */
31041 + AuLsc_I_PARENT2, /* copyup dirs */
31042 + AuLsc_I_PARENT3, /* copyup wh */
31048 +/* to debug easier, do not make them inlined functions */
31049 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31050 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
31052 +/* ---------------------------------------------------------------------- */
31054 +static inline void vfsub_drop_nlink(struct inode *inode)
31056 + AuDebugOn(!inode->i_nlink);
31057 + drop_nlink(inode);
31060 +static inline void vfsub_dead_dir(struct inode *inode)
31062 + AuDebugOn(!S_ISDIR(inode->i_mode));
31063 + inode->i_flags |= S_DEAD;
31064 + clear_nlink(inode);
31067 +static inline int vfsub_native_ro(struct inode *inode)
31069 + return (inode->i_sb->s_flags & MS_RDONLY)
31070 + || IS_RDONLY(inode)
31071 + /* || IS_APPEND(inode) */
31072 + || IS_IMMUTABLE(inode);
31075 +#ifdef CONFIG_AUFS_BR_FUSE
31076 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31078 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31081 +/* ---------------------------------------------------------------------- */
31083 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31084 +struct file *vfsub_dentry_open(struct path *path, int flags);
31085 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31086 +struct vfsub_aopen_args {
31087 + struct file *file;
31088 + unsigned int open_flag;
31089 + umode_t create_mode;
31093 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31094 + struct vfsub_aopen_args *args, struct au_branch *br);
31095 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31097 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31098 + struct dentry *parent, int len);
31099 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31102 +struct vfsub_lkup_one_args {
31103 + struct dentry **errp;
31104 + struct qstr *name;
31105 + struct dentry *parent;
31108 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31109 + struct dentry *parent)
31111 + return vfsub_lookup_one_len(name->name, parent, name->len);
31114 +void vfsub_call_lkup_one(void *args);
31116 +/* ---------------------------------------------------------------------- */
31118 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31123 + err = mnt_want_write(mnt);
31128 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31131 + mnt_drop_write(mnt);
31135 +#if 0 /* reserved */
31136 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31139 + mnt_drop_write_file(file);
31144 +/* ---------------------------------------------------------------------- */
31147 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31148 + struct dentry *d2, struct au_hinode *hdir2);
31149 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31150 + struct dentry *d2, struct au_hinode *hdir2);
31152 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31154 +int vfsub_symlink(struct inode *dir, struct path *path,
31155 + const char *symname);
31156 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31157 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31158 + struct path *path, struct inode **delegated_inode);
31159 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31160 + struct inode *hdir, struct path *path,
31161 + struct inode **delegated_inode);
31162 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31163 +int vfsub_rmdir(struct inode *dir, struct path *path);
31165 +/* ---------------------------------------------------------------------- */
31167 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31169 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31171 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31173 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31175 +int vfsub_flush(struct file *file, fl_owner_t id);
31176 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31178 +static inline loff_t vfsub_f_size_read(struct file *file)
31180 + return i_size_read(file_inode(file));
31183 +static inline unsigned int vfsub_file_flags(struct file *file)
31185 + unsigned int flags;
31187 + spin_lock(&file->f_lock);
31188 + flags = file->f_flags;
31189 + spin_unlock(&file->f_lock);
31194 +#if 0 /* reserved */
31195 +static inline void vfsub_file_accessed(struct file *h_file)
31197 + file_accessed(h_file);
31198 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31202 +#if 0 /* reserved */
31203 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31204 + struct dentry *h_dentry)
31206 + struct path h_path = {
31207 + .dentry = h_dentry,
31210 + touch_atime(&h_path);
31211 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31215 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31218 + return generic_update_time(h_inode, ts, flags);
31219 + /* no vfsub_update_h_iattr() since we don't have struct path */
31222 +#ifdef CONFIG_FS_POSIX_ACL
31223 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31227 + err = posix_acl_chmod(h_inode, h_mode);
31228 + if (err == -EOPNOTSUPP)
31233 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31236 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31237 + struct pipe_inode_info *pipe, size_t len,
31238 + unsigned int flags);
31239 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31240 + loff_t *ppos, size_t len, unsigned int flags);
31242 +static inline long vfsub_truncate(struct path *path, loff_t length)
31247 + err = vfs_truncate(path, length);
31252 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31253 + struct file *h_file);
31254 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31256 +/* ---------------------------------------------------------------------- */
31258 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31263 + err = vfs_llseek(file, offset, origin);
31268 +/* ---------------------------------------------------------------------- */
31270 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31271 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31272 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31273 + struct inode **delegated_inode);
31274 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31275 + struct inode **delegated_inode);
31276 +int vfsub_unlink(struct inode *dir, struct path *path,
31277 + struct inode **delegated_inode, int force);
31279 +/* ---------------------------------------------------------------------- */
31281 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31282 + const void *value, size_t size, int flags)
31287 + err = vfs_setxattr(dentry, name, value, size, flags);
31293 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31298 + err = vfs_removexattr(dentry, name);
31304 +#endif /* __KERNEL__ */
31305 +#endif /* __AUFS_VFSUB_H__ */
31306 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31307 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31308 +++ linux/fs/aufs/wbr_policy.c 2016-04-24 18:32:51.397020264 +0200
31311 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31313 + * This program, aufs is free software; you can redistribute it and/or modify
31314 + * it under the terms of the GNU General Public License as published by
31315 + * the Free Software Foundation; either version 2 of the License, or
31316 + * (at your option) any later version.
31318 + * This program is distributed in the hope that it will be useful,
31319 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31320 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31321 + * GNU General Public License for more details.
31323 + * You should have received a copy of the GNU General Public License
31324 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31328 + * policies for selecting one among multiple writable branches
31331 +#include <linux/statfs.h>
31334 +/* subset of cpup_attr() */
31335 +static noinline_for_stack
31336 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31340 + struct inode *h_isrc;
31342 + h_isrc = d_inode(h_src);
31343 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31344 + ia.ia_mode = h_isrc->i_mode;
31345 + ia.ia_uid = h_isrc->i_uid;
31346 + ia.ia_gid = h_isrc->i_gid;
31347 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31348 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31349 + /* no delegation since it is just created */
31350 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31352 + /* is this nfs only? */
31353 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31354 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31355 + ia.ia_mode = h_isrc->i_mode;
31356 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31362 +#define AuCpdown_PARENT_OPQ 1
31363 +#define AuCpdown_WHED (1 << 1)
31364 +#define AuCpdown_MADE_DIR (1 << 2)
31365 +#define AuCpdown_DIROPQ (1 << 3)
31366 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31367 +#define au_fset_cpdown(flags, name) \
31368 + do { (flags) |= AuCpdown_##name; } while (0)
31369 +#define au_fclr_cpdown(flags, name) \
31370 + do { (flags) &= ~AuCpdown_##name; } while (0)
31372 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31373 + unsigned int *flags)
31376 + struct dentry *opq_dentry;
31378 + opq_dentry = au_diropq_create(dentry, bdst);
31379 + err = PTR_ERR(opq_dentry);
31380 + if (IS_ERR(opq_dentry))
31382 + dput(opq_dentry);
31383 + au_fset_cpdown(*flags, DIROPQ);
31389 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31390 + struct inode *dir, aufs_bindex_t bdst)
31393 + struct path h_path;
31394 + struct au_branch *br;
31396 + br = au_sbr(dentry->d_sb, bdst);
31397 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31398 + err = PTR_ERR(h_path.dentry);
31399 + if (IS_ERR(h_path.dentry))
31403 + if (d_is_positive(h_path.dentry)) {
31404 + h_path.mnt = au_br_mnt(br);
31405 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31408 + dput(h_path.dentry);
31414 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31415 + struct au_pin *pin,
31416 + struct dentry *h_parent, void *arg)
31419 + aufs_bindex_t bopq, bstart;
31420 + struct path h_path;
31421 + struct dentry *parent;
31422 + struct inode *h_dir, *h_inode, *inode, *dir;
31423 + unsigned int *flags = arg;
31425 + bstart = au_dbstart(dentry);
31426 + /* dentry is di-locked */
31427 + parent = dget_parent(dentry);
31428 + dir = d_inode(parent);
31429 + h_dir = d_inode(h_parent);
31430 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31431 + IMustLock(h_dir);
31433 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31434 + if (unlikely(err < 0))
31436 + h_path.dentry = au_h_dptr(dentry, bdst);
31437 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31438 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31439 + S_IRWXU | S_IRUGO | S_IXUGO);
31440 + if (unlikely(err))
31442 + au_fset_cpdown(*flags, MADE_DIR);
31444 + bopq = au_dbdiropq(dentry);
31445 + au_fclr_cpdown(*flags, WHED);
31446 + au_fclr_cpdown(*flags, DIROPQ);
31447 + if (au_dbwh(dentry) == bdst)
31448 + au_fset_cpdown(*flags, WHED);
31449 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31450 + au_fset_cpdown(*flags, PARENT_OPQ);
31451 + h_inode = d_inode(h_path.dentry);
31452 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31453 + if (au_ftest_cpdown(*flags, WHED)) {
31454 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31455 + if (unlikely(err)) {
31456 + inode_unlock(h_inode);
31461 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
31462 + inode_unlock(h_inode);
31463 + if (unlikely(err))
31466 + if (au_ftest_cpdown(*flags, WHED)) {
31467 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31468 + if (unlikely(err))
31472 + inode = d_inode(dentry);
31473 + if (au_ibend(inode) < bdst)
31474 + au_set_ibend(inode, bdst);
31475 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31476 + au_hi_flags(inode, /*isdir*/1));
31477 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31478 + goto out; /* success */
31482 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31483 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31484 + rerr = au_diropq_remove(dentry, bdst);
31485 + inode_unlock(h_inode);
31486 + if (unlikely(rerr)) {
31487 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31488 + dentry, bdst, rerr);
31494 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31495 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31496 + if (unlikely(rerr)) {
31497 + AuIOErr("failed removing %pd b%d (%d)\n",
31498 + dentry, bdst, rerr);
31503 + au_set_h_dptr(dentry, bdst, NULL);
31504 + if (au_dbend(dentry) == bdst)
31505 + au_update_dbend(dentry);
31511 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31514 + unsigned int flags;
31517 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31522 +/* ---------------------------------------------------------------------- */
31524 +/* policies for create */
31526 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31528 + int err, i, j, ndentry;
31529 + aufs_bindex_t bopq;
31530 + struct au_dcsub_pages dpages;
31531 + struct au_dpage *dpage;
31532 + struct dentry **dentries, *parent, *d;
31534 + err = au_dpages_init(&dpages, GFP_NOFS);
31535 + if (unlikely(err))
31537 + parent = dget_parent(dentry);
31538 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31539 + if (unlikely(err))
31543 + for (i = 0; i < dpages.ndpage; i++) {
31544 + dpage = dpages.dpages + i;
31545 + dentries = dpage->dentries;
31546 + ndentry = dpage->ndentry;
31547 + for (j = 0; j < ndentry; j++) {
31549 + di_read_lock_parent2(d, !AuLock_IR);
31550 + bopq = au_dbdiropq(d);
31551 + di_read_unlock(d, !AuLock_IR);
31552 + if (bopq >= 0 && bopq < err)
31559 + au_dpages_free(&dpages);
31564 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31566 + for (; bindex >= 0; bindex--)
31567 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31572 +/* top down parent */
31573 +static int au_wbr_create_tdp(struct dentry *dentry,
31574 + unsigned int flags __maybe_unused)
31577 + aufs_bindex_t bstart, bindex;
31578 + struct super_block *sb;
31579 + struct dentry *parent, *h_parent;
31581 + sb = dentry->d_sb;
31582 + bstart = au_dbstart(dentry);
31584 + if (!au_br_rdonly(au_sbr(sb, bstart)))
31588 + parent = dget_parent(dentry);
31589 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
31590 + h_parent = au_h_dptr(parent, bindex);
31591 + if (!h_parent || d_is_negative(h_parent))
31594 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31601 + /* bottom up here */
31602 + if (unlikely(err < 0)) {
31603 + err = au_wbr_bu(sb, bstart - 1);
31605 + err = au_wbr_nonopq(dentry, err);
31609 + AuDbg("b%d\n", err);
31613 +/* ---------------------------------------------------------------------- */
31615 +/* an exception for the policy other than tdp */
31616 +static int au_wbr_create_exp(struct dentry *dentry)
31619 + aufs_bindex_t bwh, bdiropq;
31620 + struct dentry *parent;
31623 + bwh = au_dbwh(dentry);
31624 + parent = dget_parent(dentry);
31625 + bdiropq = au_dbdiropq(parent);
31627 + if (bdiropq >= 0)
31628 + err = min(bdiropq, bwh);
31631 + AuDbg("%d\n", err);
31632 + } else if (bdiropq >= 0) {
31634 + AuDbg("%d\n", err);
31639 + err = au_wbr_nonopq(dentry, err);
31641 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
31644 + AuDbg("%d\n", err);
31648 +/* ---------------------------------------------------------------------- */
31651 +static int au_wbr_create_init_rr(struct super_block *sb)
31655 + err = au_wbr_bu(sb, au_sbend(sb));
31656 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
31659 + AuDbg("b%d\n", err);
31663 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
31667 + aufs_bindex_t bindex, bend;
31668 + struct super_block *sb;
31671 + err = au_wbr_create_exp(dentry);
31675 + sb = dentry->d_sb;
31676 + next = &au_sbi(sb)->si_wbr_rr_next;
31677 + bend = au_sbend(sb);
31679 + for (bindex = 0; bindex <= bend; bindex++) {
31680 + if (!au_ftest_wbr(flags, DIR)) {
31681 + err = atomic_dec_return(next) + 1;
31682 + /* modulo for 0 is meaningless */
31683 + if (unlikely(!err))
31684 + err = atomic_dec_return(next) + 1;
31686 + err = atomic_read(next);
31687 + AuDbg("%d\n", err);
31690 + AuDbg("%d\n", err);
31691 + if (!au_br_rdonly(au_sbr(sb, err)))
31697 + err = au_wbr_nonopq(dentry, err);
31700 + AuDbg("%d\n", err);
31704 +/* ---------------------------------------------------------------------- */
31706 +/* most free space */
31707 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31709 + struct super_block *sb;
31710 + struct au_branch *br;
31711 + struct au_wbr_mfs *mfs;
31712 + struct dentry *h_parent;
31713 + aufs_bindex_t bindex, bend;
31715 + unsigned long long b, bavail;
31716 + struct path h_path;
31717 + /* reduce the stack usage */
31718 + struct kstatfs *st;
31720 + st = kmalloc(sizeof(*st), GFP_NOFS);
31721 + if (unlikely(!st)) {
31722 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31727 + sb = dentry->d_sb;
31728 + mfs = &au_sbi(sb)->si_wbr_mfs;
31729 + MtxMustLock(&mfs->mfs_lock);
31730 + mfs->mfs_bindex = -EROFS;
31731 + mfs->mfsrr_bytes = 0;
31734 + bend = au_sbend(sb);
31736 + bindex = au_dbstart(parent);
31737 + bend = au_dbtaildir(parent);
31740 + for (; bindex <= bend; bindex++) {
31742 + h_parent = au_h_dptr(parent, bindex);
31743 + if (!h_parent || d_is_negative(h_parent))
31746 + br = au_sbr(sb, bindex);
31747 + if (au_br_rdonly(br))
31750 + /* sb->s_root for NFS is unreliable */
31751 + h_path.mnt = au_br_mnt(br);
31752 + h_path.dentry = h_path.mnt->mnt_root;
31753 + err = vfs_statfs(&h_path, st);
31754 + if (unlikely(err)) {
31755 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31759 + /* when the available size is equal, select the lower one */
31760 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31761 + || sizeof(b) < sizeof(st->f_bsize));
31762 + b = st->f_bavail * st->f_bsize;
31763 + br->br_wbr->wbr_bytes = b;
31764 + if (b >= bavail) {
31766 + mfs->mfs_bindex = bindex;
31767 + mfs->mfs_jiffy = jiffies;
31771 + mfs->mfsrr_bytes = bavail;
31772 + AuDbg("b%d\n", mfs->mfs_bindex);
31776 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31779 + struct dentry *parent;
31780 + struct super_block *sb;
31781 + struct au_wbr_mfs *mfs;
31783 + err = au_wbr_create_exp(dentry);
31787 + sb = dentry->d_sb;
31789 + if (au_ftest_wbr(flags, PARENT))
31790 + parent = dget_parent(dentry);
31791 + mfs = &au_sbi(sb)->si_wbr_mfs;
31792 + mutex_lock(&mfs->mfs_lock);
31793 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31794 + || mfs->mfs_bindex < 0
31795 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31796 + au_mfs(dentry, parent);
31797 + mutex_unlock(&mfs->mfs_lock);
31798 + err = mfs->mfs_bindex;
31802 + err = au_wbr_nonopq(dentry, err);
31805 + AuDbg("b%d\n", err);
31809 +static int au_wbr_create_init_mfs(struct super_block *sb)
31811 + struct au_wbr_mfs *mfs;
31813 + mfs = &au_sbi(sb)->si_wbr_mfs;
31814 + mutex_init(&mfs->mfs_lock);
31815 + mfs->mfs_jiffy = 0;
31816 + mfs->mfs_bindex = -EROFS;
31821 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31823 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31827 +/* ---------------------------------------------------------------------- */
31829 +/* most free space and then round robin */
31830 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31833 + struct au_wbr_mfs *mfs;
31835 + err = au_wbr_create_mfs(dentry, flags);
31837 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31838 + mutex_lock(&mfs->mfs_lock);
31839 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31840 + err = au_wbr_create_rr(dentry, flags);
31841 + mutex_unlock(&mfs->mfs_lock);
31844 + AuDbg("b%d\n", err);
31848 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31852 + au_wbr_create_init_mfs(sb); /* ignore */
31853 + err = au_wbr_create_init_rr(sb);
31858 +/* ---------------------------------------------------------------------- */
31860 +/* top down parent and most free space */
31861 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31864 + unsigned long long b;
31865 + aufs_bindex_t bindex, bstart, bend;
31866 + struct super_block *sb;
31867 + struct dentry *parent, *h_parent;
31868 + struct au_branch *br;
31870 + err = au_wbr_create_tdp(dentry, flags);
31871 + if (unlikely(err < 0))
31873 + parent = dget_parent(dentry);
31874 + bstart = au_dbstart(parent);
31875 + bend = au_dbtaildir(parent);
31876 + if (bstart == bend)
31877 + goto out_parent; /* success */
31879 + e2 = au_wbr_create_mfs(dentry, flags);
31881 + goto out_parent; /* success */
31883 + /* when the available size is equal, select upper one */
31884 + sb = dentry->d_sb;
31885 + br = au_sbr(sb, err);
31886 + b = br->br_wbr->wbr_bytes;
31887 + AuDbg("b%d, %llu\n", err, b);
31889 + for (bindex = bstart; bindex <= bend; bindex++) {
31890 + h_parent = au_h_dptr(parent, bindex);
31891 + if (!h_parent || d_is_negative(h_parent))
31894 + br = au_sbr(sb, bindex);
31895 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31896 + b = br->br_wbr->wbr_bytes;
31898 + AuDbg("b%d, %llu\n", err, b);
31903 + err = au_wbr_nonopq(dentry, err);
31908 + AuDbg("b%d\n", err);
31912 +/* ---------------------------------------------------------------------- */
31915 + * - top down parent
31916 + * - most free space with parent
31917 + * - most free space round-robin regardless parent
31919 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31922 + unsigned long long watermark;
31923 + struct super_block *sb;
31924 + struct au_branch *br;
31925 + struct au_wbr_mfs *mfs;
31927 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31928 + if (unlikely(err < 0))
31931 + sb = dentry->d_sb;
31932 + br = au_sbr(sb, err);
31933 + mfs = &au_sbi(sb)->si_wbr_mfs;
31934 + mutex_lock(&mfs->mfs_lock);
31935 + watermark = mfs->mfsrr_watermark;
31936 + mutex_unlock(&mfs->mfs_lock);
31937 + if (br->br_wbr->wbr_bytes < watermark)
31938 + /* regardless the parent dir */
31939 + err = au_wbr_create_mfsrr(dentry, flags);
31942 + AuDbg("b%d\n", err);
31946 +/* ---------------------------------------------------------------------- */
31948 +/* policies for copyup */
31950 +/* top down parent */
31951 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31953 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31956 +/* bottom up parent */
31957 +static int au_wbr_copyup_bup(struct dentry *dentry)
31960 + aufs_bindex_t bindex, bstart;
31961 + struct dentry *parent, *h_parent;
31962 + struct super_block *sb;
31965 + sb = dentry->d_sb;
31966 + parent = dget_parent(dentry);
31967 + bstart = au_dbstart(parent);
31968 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31969 + h_parent = au_h_dptr(parent, bindex);
31970 + if (!h_parent || d_is_negative(h_parent))
31973 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31980 + /* bottom up here */
31981 + if (unlikely(err < 0))
31982 + err = au_wbr_bu(sb, bstart - 1);
31984 + AuDbg("b%d\n", err);
31989 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
31993 + err = au_wbr_bu(dentry->d_sb, bstart);
31994 + AuDbg("b%d\n", err);
31995 + if (err > bstart)
31996 + err = au_wbr_nonopq(dentry, err);
31998 + AuDbg("b%d\n", err);
32002 +static int au_wbr_copyup_bu(struct dentry *dentry)
32005 + aufs_bindex_t bstart;
32007 + bstart = au_dbstart(dentry);
32008 + err = au_wbr_do_copyup_bu(dentry, bstart);
32012 +/* ---------------------------------------------------------------------- */
32014 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32015 + [AuWbrCopyup_TDP] = {
32016 + .copyup = au_wbr_copyup_tdp
32018 + [AuWbrCopyup_BUP] = {
32019 + .copyup = au_wbr_copyup_bup
32021 + [AuWbrCopyup_BU] = {
32022 + .copyup = au_wbr_copyup_bu
32026 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32027 + [AuWbrCreate_TDP] = {
32028 + .create = au_wbr_create_tdp
32030 + [AuWbrCreate_RR] = {
32031 + .create = au_wbr_create_rr,
32032 + .init = au_wbr_create_init_rr
32034 + [AuWbrCreate_MFS] = {
32035 + .create = au_wbr_create_mfs,
32036 + .init = au_wbr_create_init_mfs,
32037 + .fin = au_wbr_create_fin_mfs
32039 + [AuWbrCreate_MFSV] = {
32040 + .create = au_wbr_create_mfs,
32041 + .init = au_wbr_create_init_mfs,
32042 + .fin = au_wbr_create_fin_mfs
32044 + [AuWbrCreate_MFSRR] = {
32045 + .create = au_wbr_create_mfsrr,
32046 + .init = au_wbr_create_init_mfsrr,
32047 + .fin = au_wbr_create_fin_mfs
32049 + [AuWbrCreate_MFSRRV] = {
32050 + .create = au_wbr_create_mfsrr,
32051 + .init = au_wbr_create_init_mfsrr,
32052 + .fin = au_wbr_create_fin_mfs
32054 + [AuWbrCreate_PMFS] = {
32055 + .create = au_wbr_create_pmfs,
32056 + .init = au_wbr_create_init_mfs,
32057 + .fin = au_wbr_create_fin_mfs
32059 + [AuWbrCreate_PMFSV] = {
32060 + .create = au_wbr_create_pmfs,
32061 + .init = au_wbr_create_init_mfs,
32062 + .fin = au_wbr_create_fin_mfs
32064 + [AuWbrCreate_PMFSRR] = {
32065 + .create = au_wbr_create_pmfsrr,
32066 + .init = au_wbr_create_init_mfsrr,
32067 + .fin = au_wbr_create_fin_mfs
32069 + [AuWbrCreate_PMFSRRV] = {
32070 + .create = au_wbr_create_pmfsrr,
32071 + .init = au_wbr_create_init_mfsrr,
32072 + .fin = au_wbr_create_fin_mfs
32075 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32076 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32077 +++ linux/fs/aufs/whout.c 2016-04-24 18:32:51.397020264 +0200
32080 + * Copyright (C) 2005-2016 Junjiro R. Okajima
32082 + * This program, aufs is free software; you can redistribute it and/or modify
32083 + * it under the terms of the GNU General Public License as published by
32084 + * the Free Software Foundation; either version 2 of the License, or
32085 + * (at your option) any later version.
32087 + * This program is distributed in the hope that it will be useful,
32088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32090 + * GNU General Public License for more details.
32092 + * You should have received a copy of the GNU General Public License
32093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32097 + * whiteout for logical deletion and opaque directory
32102 +#define WH_MASK S_IRUGO
32105 + * If a directory contains this file, then it is opaque. We start with the
32106 + * .wh. flag so that it is blocked by lookup.
32108 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32109 + sizeof(AUFS_WH_DIROPQ) - 1);
32112 + * generate whiteout name, which is NOT terminated by NULL.
32113 + * @name: original d_name.name
32114 + * @len: original d_name.len
32115 + * @wh: whiteout qstr
32116 + * returns zero when succeeds, otherwise error.
32117 + * succeeded value as wh->name should be freed by kfree().
32119 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32123 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32124 + return -ENAMETOOLONG;
32126 + wh->len = name->len + AUFS_WH_PFX_LEN;
32127 + p = kmalloc(wh->len, GFP_NOFS);
32130 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32131 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32138 +/* ---------------------------------------------------------------------- */
32141 + * test if the @wh_name exists under @h_parent.
32142 + * @try_sio specifies the necessary of super-io.
32144 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32147 + struct dentry *wh_dentry;
32150 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32152 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32153 + err = PTR_ERR(wh_dentry);
32154 + if (IS_ERR(wh_dentry)) {
32155 + if (err == -ENAMETOOLONG)
32161 + if (d_is_negative(wh_dentry))
32162 + goto out_wh; /* success */
32165 + if (d_is_reg(wh_dentry))
32166 + goto out_wh; /* success */
32169 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32170 + wh_dentry, d_inode(wh_dentry)->i_mode);
32179 + * test if the @h_dentry sets opaque or not.
32181 +int au_diropq_test(struct dentry *h_dentry)
32184 + struct inode *h_dir;
32186 + h_dir = d_inode(h_dentry);
32187 + err = au_wh_test(h_dentry, &diropq_name,
32188 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32193 + * returns a negative dentry whose name is unique and temporary.
32195 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32196 + struct qstr *prefix)
32198 + struct dentry *dentry;
32200 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32202 + /* strict atomic_t is unnecessary here */
32203 + static unsigned short cnt;
32206 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32209 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32210 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32211 + dentry = ERR_PTR(-ENAMETOOLONG);
32212 + if (unlikely(qs.len > NAME_MAX))
32214 + dentry = ERR_PTR(-ENOMEM);
32215 + name = kmalloc(qs.len + 1, GFP_NOFS);
32216 + if (unlikely(!name))
32220 + /* doubly whiteout-ed */
32221 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32222 + p = name + AUFS_WH_PFX_LEN * 2;
32223 + memcpy(p, prefix->name, prefix->len);
32224 + p += prefix->len;
32226 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32229 + for (i = 0; i < 3; i++) {
32230 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32231 + dentry = au_sio_lkup_one(&qs, h_parent);
32232 + if (IS_ERR(dentry) || d_is_negative(dentry))
32236 + /* pr_warn("could not get random name\n"); */
32237 + dentry = ERR_PTR(-EEXIST);
32238 + AuDbg("%.*s\n", AuLNPair(&qs));
32242 + if (name != defname)
32245 + AuTraceErrPtr(dentry);
32250 + * rename the @h_dentry on @br to the whiteouted temporary name.
32252 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32255 + struct path h_path = {
32256 + .mnt = au_br_mnt(br)
32258 + struct inode *h_dir, *delegated;
32259 + struct dentry *h_parent;
32261 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32262 + h_dir = d_inode(h_parent);
32263 + IMustLock(h_dir);
32265 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32266 + err = PTR_ERR(h_path.dentry);
32267 + if (IS_ERR(h_path.dentry))
32270 + /* under the same dir, no need to lock_rename() */
32271 + delegated = NULL;
32272 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
32274 + if (unlikely(err == -EWOULDBLOCK)) {
32275 + pr_warn("cannot retry for NFSv4 delegation"
32276 + " for an internal rename\n");
32279 + dput(h_path.dentry);
32286 +/* ---------------------------------------------------------------------- */
32288 + * functions for removing a whiteout
32291 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32294 + struct inode *delegated;
32297 + * forces superio when the dir has a sticky bit.
32298 + * this may be a violation of unix fs semantics.
32300 + force = (h_dir->i_mode & S_ISVTX)
32301 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32302 + delegated = NULL;
32303 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32304 + if (unlikely(err == -EWOULDBLOCK)) {
32305 + pr_warn("cannot retry for NFSv4 delegation"
32306 + " for an internal unlink\n");
32312 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32313 + struct dentry *dentry)
32317 + err = do_unlink_wh(h_dir, h_path);
32318 + if (!err && dentry)
32319 + au_set_dbwh(dentry, -1);
32324 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32325 + struct au_branch *br)
32328 + struct path h_path = {
32329 + .mnt = au_br_mnt(br)
32333 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32334 + if (IS_ERR(h_path.dentry))
32335 + err = PTR_ERR(h_path.dentry);
32337 + if (d_is_reg(h_path.dentry))
32338 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32339 + dput(h_path.dentry);
32345 +/* ---------------------------------------------------------------------- */
32347 + * initialize/clean whiteout for a branch
32350 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32354 + struct inode *delegated;
32356 + if (d_is_negative(whpath->dentry))
32360 + err = vfsub_rmdir(h_dir, whpath);
32362 + delegated = NULL;
32363 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32364 + if (unlikely(err == -EWOULDBLOCK)) {
32365 + pr_warn("cannot retry for NFSv4 delegation"
32366 + " for an internal unlink\n");
32370 + if (unlikely(err))
32371 + pr_warn("failed removing %pd (%d), ignored.\n",
32372 + whpath->dentry, err);
32375 +static int test_linkable(struct dentry *h_root)
32377 + struct inode *h_dir = d_inode(h_root);
32379 + if (h_dir->i_op->link)
32382 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32383 + h_root, au_sbtype(h_root->d_sb));
32387 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32388 +static int au_whdir(struct inode *h_dir, struct path *path)
32393 + if (d_is_negative(path->dentry)) {
32394 + int mode = S_IRWXU;
32396 + if (au_test_nfs(path->dentry->d_sb))
32398 + err = vfsub_mkdir(h_dir, path, mode);
32399 + } else if (d_is_dir(path->dentry))
32402 + pr_err("unknown %pd exists\n", path->dentry);
32407 +struct au_wh_base {
32408 + const struct qstr *name;
32409 + struct dentry *dentry;
32412 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32413 + struct path *h_path)
32415 + h_path->dentry = base[AuBrWh_BASE].dentry;
32416 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32417 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32418 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32419 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32420 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32424 + * returns tri-state,
32425 + * minus: error, caller should print the message
32427 + * plus: error, caller should NOT print the message
32429 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
32430 + int do_plink, struct au_wh_base base[],
32431 + struct path *h_path)
32434 + struct inode *h_dir;
32436 + h_dir = d_inode(h_root);
32437 + h_path->dentry = base[AuBrWh_BASE].dentry;
32438 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32439 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32441 + err = test_linkable(h_root);
32442 + if (unlikely(err)) {
32447 + err = au_whdir(h_dir, h_path);
32448 + if (unlikely(err))
32450 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32452 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32453 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32454 + err = au_whdir(h_dir, h_path);
32455 + if (unlikely(err))
32457 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32464 + * for the moment, aufs supports the branch filesystem which does not support
32465 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
32466 + * copyup failed. finally, such filesystem will not be used as the writable
32469 + * returns tri-state, see above.
32471 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
32472 + int do_plink, struct au_wh_base base[],
32473 + struct path *h_path)
32476 + struct inode *h_dir;
32478 + WbrWhMustWriteLock(wbr);
32480 + err = test_linkable(h_root);
32481 + if (unlikely(err)) {
32487 + * todo: should this create be done in /sbin/mount.aufs helper?
32490 + h_dir = d_inode(h_root);
32491 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
32492 + h_path->dentry = base[AuBrWh_BASE].dentry;
32493 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32494 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
32497 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32498 + if (unlikely(err))
32501 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32503 + err = au_whdir(h_dir, h_path);
32504 + if (unlikely(err))
32506 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32508 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32509 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32511 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32512 + err = au_whdir(h_dir, h_path);
32513 + if (unlikely(err))
32515 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32522 + * initialize the whiteout base file/dir for @br.
32524 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32527 + const unsigned char do_plink
32528 + = !!au_opt_test(au_mntflags(sb), PLINK);
32529 + struct inode *h_dir;
32530 + struct path path = br->br_path;
32531 + struct dentry *h_root = path.dentry;
32532 + struct au_wbr *wbr = br->br_wbr;
32533 + static const struct qstr base_name[] = {
32534 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32535 + sizeof(AUFS_BASE_NAME) - 1),
32536 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32537 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32538 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32539 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32541 + struct au_wh_base base[] = {
32542 + [AuBrWh_BASE] = {
32543 + .name = base_name + AuBrWh_BASE,
32546 + [AuBrWh_PLINK] = {
32547 + .name = base_name + AuBrWh_PLINK,
32550 + [AuBrWh_ORPH] = {
32551 + .name = base_name + AuBrWh_ORPH,
32557 + WbrWhMustWriteLock(wbr);
32559 + for (i = 0; i < AuBrWh_Last; i++) {
32560 + /* doubly whiteouted */
32561 + struct dentry *d;
32563 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32564 + err = PTR_ERR(d);
32568 + base[i].dentry = d;
32570 + && wbr->wbr_wh[i]
32571 + && wbr->wbr_wh[i] != base[i].dentry);
32575 + for (i = 0; i < AuBrWh_Last; i++) {
32576 + dput(wbr->wbr_wh[i]);
32577 + wbr->wbr_wh[i] = NULL;
32581 + if (!au_br_writable(br->br_perm)) {
32582 + h_dir = d_inode(h_root);
32583 + au_wh_init_ro(h_dir, base, &path);
32584 + } else if (!au_br_wh_linkable(br->br_perm)) {
32585 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32591 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32597 + goto out; /* success */
32600 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32601 + err, h_root, au_sbtype(h_root->d_sb));
32603 + for (i = 0; i < AuBrWh_Last; i++)
32604 + dput(base[i].dentry);
32608 +/* ---------------------------------------------------------------------- */
32610 + * whiteouts are all hard-linked usually.
32611 + * when its link count reaches a ceiling, we create a new whiteout base
32612 + * asynchronously.
32615 +struct reinit_br_wh {
32616 + struct super_block *sb;
32617 + struct au_branch *br;
32620 +static void reinit_br_wh(void *arg)
32623 + aufs_bindex_t bindex;
32624 + struct path h_path;
32625 + struct reinit_br_wh *a = arg;
32626 + struct au_wbr *wbr;
32627 + struct inode *dir, *delegated;
32628 + struct dentry *h_root;
32629 + struct au_hinode *hdir;
32632 + wbr = a->br->br_wbr;
32633 + /* big aufs lock */
32634 + si_noflush_write_lock(a->sb);
32635 + if (!au_br_writable(a->br->br_perm))
32637 + bindex = au_br_index(a->sb, a->br->br_id);
32638 + if (unlikely(bindex < 0))
32641 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
32642 + dir = d_inode(a->sb->s_root);
32643 + hdir = au_hi(dir, bindex);
32644 + h_root = au_h_dptr(a->sb->s_root, bindex);
32645 + AuDebugOn(h_root != au_br_dentry(a->br));
32647 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32648 + wbr_wh_write_lock(wbr);
32649 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
32652 + h_path.dentry = wbr->wbr_whbase;
32653 + h_path.mnt = au_br_mnt(a->br);
32654 + delegated = NULL;
32655 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
32657 + if (unlikely(err == -EWOULDBLOCK)) {
32658 + pr_warn("cannot retry for NFSv4 delegation"
32659 + " for an internal unlink\n");
32663 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
32666 + dput(wbr->wbr_whbase);
32667 + wbr->wbr_whbase = NULL;
32669 + err = au_wh_init(a->br, a->sb);
32670 + wbr_wh_write_unlock(wbr);
32671 + au_hn_imtx_unlock(hdir);
32672 + di_read_unlock(a->sb->s_root, AuLock_IR);
32674 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
32678 + atomic_dec(&wbr->wbr_wh_running);
32679 + atomic_dec(&a->br->br_count);
32680 + si_write_unlock(a->sb);
32681 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32683 + if (unlikely(err))
32684 + AuIOErr("err %d\n", err);
32687 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32689 + int do_dec, wkq_err;
32690 + struct reinit_br_wh *arg;
32693 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32696 + /* ignore ENOMEM */
32697 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32700 + * dec(wh_running), kfree(arg) and dec(br_count)
32701 + * in reinit function
32705 + atomic_inc(&br->br_count);
32706 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32707 + if (unlikely(wkq_err)) {
32708 + atomic_dec(&br->br_wbr->wbr_wh_running);
32709 + atomic_dec(&br->br_count);
32717 + atomic_dec(&br->br_wbr->wbr_wh_running);
32720 +/* ---------------------------------------------------------------------- */
32723 + * create the whiteout @wh.
32725 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32726 + struct dentry *wh)
32729 + struct path h_path = {
32732 + struct au_branch *br;
32733 + struct au_wbr *wbr;
32734 + struct dentry *h_parent;
32735 + struct inode *h_dir, *delegated;
32737 + h_parent = wh->d_parent; /* dir inode is locked */
32738 + h_dir = d_inode(h_parent);
32739 + IMustLock(h_dir);
32741 + br = au_sbr(sb, bindex);
32742 + h_path.mnt = au_br_mnt(br);
32743 + wbr = br->br_wbr;
32744 + wbr_wh_read_lock(wbr);
32745 + if (wbr->wbr_whbase) {
32746 + delegated = NULL;
32747 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32748 + if (unlikely(err == -EWOULDBLOCK)) {
32749 + pr_warn("cannot retry for NFSv4 delegation"
32750 + " for an internal link\n");
32753 + if (!err || err != -EMLINK)
32756 + /* link count full. re-initialize br_whbase. */
32757 + kick_reinit_br_wh(sb, br);
32760 + /* return this error in this context */
32761 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32763 + au_fhsm_wrote(sb, bindex, /*force*/0);
32766 + wbr_wh_read_unlock(wbr);
32770 +/* ---------------------------------------------------------------------- */
32773 + * create or remove the diropq.
32775 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32776 + unsigned int flags)
32778 + struct dentry *opq_dentry, *h_dentry;
32779 + struct super_block *sb;
32780 + struct au_branch *br;
32783 + sb = dentry->d_sb;
32784 + br = au_sbr(sb, bindex);
32785 + h_dentry = au_h_dptr(dentry, bindex);
32786 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32787 + if (IS_ERR(opq_dentry))
32790 + if (au_ftest_diropq(flags, CREATE)) {
32791 + err = link_or_create_wh(sb, bindex, opq_dentry);
32793 + au_set_dbdiropq(dentry, bindex);
32794 + goto out; /* success */
32797 + struct path tmp = {
32798 + .dentry = opq_dentry,
32799 + .mnt = au_br_mnt(br)
32801 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
32803 + au_set_dbdiropq(dentry, -1);
32805 + dput(opq_dentry);
32806 + opq_dentry = ERR_PTR(err);
32809 + return opq_dentry;
32812 +struct do_diropq_args {
32813 + struct dentry **errp;
32814 + struct dentry *dentry;
32815 + aufs_bindex_t bindex;
32816 + unsigned int flags;
32819 +static void call_do_diropq(void *args)
32821 + struct do_diropq_args *a = args;
32822 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32825 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32826 + unsigned int flags)
32828 + struct dentry *diropq, *h_dentry;
32830 + h_dentry = au_h_dptr(dentry, bindex);
32831 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
32832 + diropq = do_diropq(dentry, bindex, flags);
32835 + struct do_diropq_args args = {
32837 + .dentry = dentry,
32838 + .bindex = bindex,
32842 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32843 + if (unlikely(wkq_err))
32844 + diropq = ERR_PTR(wkq_err);
32850 +/* ---------------------------------------------------------------------- */
32853 + * lookup whiteout dentry.
32854 + * @h_parent: lower parent dentry which must exist and be locked
32855 + * @base_name: name of dentry which will be whiteouted
32856 + * returns dentry for whiteout.
32858 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32859 + struct au_branch *br)
32862 + struct qstr wh_name;
32863 + struct dentry *wh_dentry;
32865 + err = au_wh_name_alloc(&wh_name, base_name);
32866 + wh_dentry = ERR_PTR(err);
32868 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32869 + kfree(wh_name.name);
32871 + return wh_dentry;
32875 + * link/create a whiteout for @dentry on @bindex.
32877 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32878 + struct dentry *h_parent)
32880 + struct dentry *wh_dentry;
32881 + struct super_block *sb;
32884 + sb = dentry->d_sb;
32885 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32886 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
32887 + err = link_or_create_wh(sb, bindex, wh_dentry);
32889 + au_set_dbwh(dentry, bindex);
32890 + au_fhsm_wrote(sb, bindex, /*force*/0);
32893 + wh_dentry = ERR_PTR(err);
32897 + return wh_dentry;
32900 +/* ---------------------------------------------------------------------- */
32902 +/* Delete all whiteouts in this directory on branch bindex. */
32903 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32904 + aufs_bindex_t bindex, struct au_branch *br)
32907 + unsigned long ul, n;
32908 + struct qstr wh_name;
32910 + struct hlist_head *head;
32911 + struct au_vdir_wh *pos;
32912 + struct au_vdir_destr *str;
32915 + p = (void *)__get_free_page(GFP_NOFS);
32916 + wh_name.name = p;
32917 + if (unlikely(!wh_name.name))
32921 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32922 + p += AUFS_WH_PFX_LEN;
32923 + n = whlist->nh_num;
32924 + head = whlist->nh_head;
32925 + for (ul = 0; !err && ul < n; ul++, head++) {
32926 + hlist_for_each_entry(pos, head, wh_hash) {
32927 + if (pos->wh_bindex != bindex)
32930 + str = &pos->wh_str;
32931 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32932 + memcpy(p, str->name, str->len);
32933 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32934 + err = unlink_wh_name(h_dentry, &wh_name, br);
32939 + AuIOErr("whiteout name too long %.*s\n",
32940 + str->len, str->name);
32945 + free_page((unsigned long)wh_name.name);
32951 +struct del_wh_children_args {
32953 + struct dentry *h_dentry;
32954 + struct au_nhash *whlist;
32955 + aufs_bindex_t bindex;
32956 + struct au_branch *br;
32959 +static void call_del_wh_children(void *args)
32961 + struct del_wh_children_args *a = args;
32962 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32965 +/* ---------------------------------------------------------------------- */
32967 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32969 + struct au_whtmp_rmdir *whtmp;
32971 + unsigned int rdhash;
32973 + SiMustAnyLock(sb);
32975 + whtmp = kzalloc(sizeof(*whtmp), gfp);
32976 + if (unlikely(!whtmp)) {
32977 + whtmp = ERR_PTR(-ENOMEM);
32981 + /* no estimation for dir size */
32982 + rdhash = au_sbi(sb)->si_rdhash;
32984 + rdhash = AUFS_RDHASH_DEF;
32985 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32986 + if (unlikely(err)) {
32988 + whtmp = ERR_PTR(err);
32995 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
32998 + atomic_dec(&whtmp->br->br_count);
32999 + dput(whtmp->wh_dentry);
33000 + iput(whtmp->dir);
33001 + au_nhash_wh_free(&whtmp->whlist);
33006 + * rmdir the whiteouted temporary named dir @h_dentry.
33007 + * @whlist: whiteouted children.
33009 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33010 + struct dentry *wh_dentry, struct au_nhash *whlist)
33013 + unsigned int h_nlink;
33014 + struct path h_tmp;
33015 + struct inode *wh_inode, *h_dir;
33016 + struct au_branch *br;
33018 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33019 + IMustLock(h_dir);
33021 + br = au_sbr(dir->i_sb, bindex);
33022 + wh_inode = d_inode(wh_dentry);
33023 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33026 + * someone else might change some whiteouts while we were sleeping.
33027 + * it means this whlist may have an obsoleted entry.
33029 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33030 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33033 + struct del_wh_children_args args = {
33035 + .h_dentry = wh_dentry,
33036 + .whlist = whlist,
33037 + .bindex = bindex,
33041 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33042 + if (unlikely(wkq_err))
33045 + inode_unlock(wh_inode);
33048 + h_tmp.dentry = wh_dentry;
33049 + h_tmp.mnt = au_br_mnt(br);
33050 + h_nlink = h_dir->i_nlink;
33051 + err = vfsub_rmdir(h_dir, &h_tmp);
33052 + /* some fs doesn't change the parent nlink in some cases */
33053 + h_nlink -= h_dir->i_nlink;
33057 + if (au_ibstart(dir) == bindex) {
33058 + /* todo: dir->i_mutex is necessary */
33059 + au_cpup_attr_timesizes(dir);
33061 + vfsub_drop_nlink(dir);
33063 + return 0; /* success */
33066 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33070 +static void call_rmdir_whtmp(void *args)
33073 + aufs_bindex_t bindex;
33074 + struct au_whtmp_rmdir *a = args;
33075 + struct super_block *sb;
33076 + struct dentry *h_parent;
33077 + struct inode *h_dir;
33078 + struct au_hinode *hdir;
33080 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33081 + /* inode_lock(a->dir); */
33083 + sb = a->dir->i_sb;
33084 + si_read_lock(sb, !AuLock_FLUSH);
33085 + if (!au_br_writable(a->br->br_perm))
33087 + bindex = au_br_index(sb, a->br->br_id);
33088 + if (unlikely(bindex < 0))
33092 + ii_write_lock_parent(a->dir);
33093 + h_parent = dget_parent(a->wh_dentry);
33094 + h_dir = d_inode(h_parent);
33095 + hdir = au_hi(a->dir, bindex);
33096 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33097 + if (unlikely(err))
33099 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
33100 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33103 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33104 + au_hn_imtx_unlock(hdir);
33105 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33109 + ii_write_unlock(a->dir);
33111 + /* inode_unlock(a->dir); */
33112 + au_whtmp_rmdir_free(a);
33113 + si_read_unlock(sb);
33114 + au_nwt_done(&au_sbi(sb)->si_nowait);
33115 + if (unlikely(err))
33116 + AuIOErr("err %d\n", err);
33119 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33120 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33123 + struct super_block *sb;
33127 + /* all post-process will be done in do_rmdir_whtmp(). */
33129 + args->dir = au_igrab(dir);
33130 + args->br = au_sbr(sb, bindex);
33131 + atomic_inc(&args->br->br_count);
33132 + args->wh_dentry = dget(wh_dentry);
33133 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33134 + if (unlikely(wkq_err)) {
33135 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33136 + au_whtmp_rmdir_free(args);
33139 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33140 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33141 +++ linux/fs/aufs/whout.h 2016-04-24 18:32:51.397020264 +0200
33144 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33146 + * This program, aufs is free software; you can redistribute it and/or modify
33147 + * it under the terms of the GNU General Public License as published by
33148 + * the Free Software Foundation; either version 2 of the License, or
33149 + * (at your option) any later version.
33151 + * This program is distributed in the hope that it will be useful,
33152 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33153 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33154 + * GNU General Public License for more details.
33156 + * You should have received a copy of the GNU General Public License
33157 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33161 + * whiteout for logical deletion and opaque directory
33164 +#ifndef __AUFS_WHOUT_H__
33165 +#define __AUFS_WHOUT_H__
33172 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33173 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33174 +int au_diropq_test(struct dentry *h_dentry);
33176 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33177 + struct qstr *prefix);
33178 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33179 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33180 + struct dentry *dentry);
33181 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33183 +/* diropq flags */
33184 +#define AuDiropq_CREATE 1
33185 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33186 +#define au_fset_diropq(flags, name) \
33187 + do { (flags) |= AuDiropq_##name; } while (0)
33188 +#define au_fclr_diropq(flags, name) \
33189 + do { (flags) &= ~AuDiropq_##name; } while (0)
33191 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33192 + unsigned int flags);
33193 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33194 + struct au_branch *br);
33195 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33196 + struct dentry *h_parent);
33198 +/* real rmdir for the whiteout-ed dir */
33199 +struct au_whtmp_rmdir {
33200 + struct inode *dir;
33201 + struct au_branch *br;
33202 + struct dentry *wh_dentry;
33203 + struct au_nhash whlist;
33206 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33207 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33208 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33209 + struct dentry *wh_dentry, struct au_nhash *whlist);
33210 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33211 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33213 +/* ---------------------------------------------------------------------- */
33215 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33216 + aufs_bindex_t bindex)
33218 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33221 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33223 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33226 +#endif /* __KERNEL__ */
33227 +#endif /* __AUFS_WHOUT_H__ */
33228 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33229 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33230 +++ linux/fs/aufs/wkq.c 2016-04-24 18:32:51.397020264 +0200
33233 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33235 + * This program, aufs is free software; you can redistribute it and/or modify
33236 + * it under the terms of the GNU General Public License as published by
33237 + * the Free Software Foundation; either version 2 of the License, or
33238 + * (at your option) any later version.
33240 + * This program is distributed in the hope that it will be useful,
33241 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33242 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33243 + * GNU General Public License for more details.
33245 + * You should have received a copy of the GNU General Public License
33246 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33250 + * workqueue for asynchronous/super-io operations
33251 + * todo: try new dredential scheme
33254 +#include <linux/module.h>
33257 +/* internal workqueue named AUFS_WKQ_NAME */
33259 +static struct workqueue_struct *au_wkq;
33261 +struct au_wkinfo {
33262 + struct work_struct wk;
33263 + struct kobject *kobj;
33265 + unsigned int flags; /* see wkq.h */
33267 + au_wkq_func_t func;
33270 + struct completion *comp;
33273 +/* ---------------------------------------------------------------------- */
33275 +static void wkq_func(struct work_struct *wk)
33277 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33279 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33280 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33282 + wkinfo->func(wkinfo->args);
33283 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33284 + complete(wkinfo->comp);
33286 + kobject_put(wkinfo->kobj);
33287 + module_put(THIS_MODULE); /* todo: ?? */
33293 + * Since struct completion is large, try allocating it dynamically.
33295 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33296 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33298 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33300 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33302 + init_completion(*comp);
33303 + wkinfo->comp = *comp;
33309 +static void au_wkq_comp_free(struct completion *comp)
33317 +#define AuWkqCompDeclare(name) \
33318 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33319 + struct completion *comp = &_ ## name
33321 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33323 + wkinfo->comp = *comp;
33327 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33331 +#endif /* 4KSTACKS */
33333 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33335 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33336 + if (au_wkq_test()) {
33337 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33338 + " due to a dead dir by UDBA?\n");
33339 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33342 + au_dbg_verify_kthread();
33344 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33345 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33346 + queue_work(au_wkq, &wkinfo->wk);
33348 + INIT_WORK(&wkinfo->wk, wkq_func);
33349 + schedule_work(&wkinfo->wk);
33354 + * Be careful. It is easy to make deadlock happen.
33355 + * processA: lock, wkq and wait
33356 + * processB: wkq and wait, lock in wkq
33359 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33362 + AuWkqCompDeclare(comp);
33363 + struct au_wkinfo wkinfo = {
33369 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33371 + au_wkq_run(&wkinfo);
33372 + /* no timeout, no interrupt */
33373 + wait_for_completion(wkinfo.comp);
33374 + au_wkq_comp_free(comp);
33375 + destroy_work_on_stack(&wkinfo.wk);
33383 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33384 + * problem in a concurrent umounting.
33386 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33387 + unsigned int flags)
33390 + struct au_wkinfo *wkinfo;
33392 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33395 + * wkq_func() must free this wkinfo.
33396 + * it highly depends upon the implementation of workqueue.
33399 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33401 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33402 + wkinfo->flags = flags & ~AuWkq_WAIT;
33403 + wkinfo->func = func;
33404 + wkinfo->args = args;
33405 + wkinfo->comp = NULL;
33406 + kobject_get(wkinfo->kobj);
33407 + __module_get(THIS_MODULE); /* todo: ?? */
33409 + au_wkq_run(wkinfo);
33412 + au_nwt_done(&au_sbi(sb)->si_nowait);
33418 +/* ---------------------------------------------------------------------- */
33420 +void au_nwt_init(struct au_nowait_tasks *nwt)
33422 + atomic_set(&nwt->nw_len, 0);
33423 + /* smp_mb(); */ /* atomic_set */
33424 + init_waitqueue_head(&nwt->nw_wq);
33427 +void au_wkq_fin(void)
33429 + destroy_workqueue(au_wkq);
33432 +int __init au_wkq_init(void)
33437 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
33438 + if (IS_ERR(au_wkq))
33439 + err = PTR_ERR(au_wkq);
33440 + else if (!au_wkq)
33445 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
33446 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
33447 +++ linux/fs/aufs/wkq.h 2016-04-24 18:32:51.397020264 +0200
33450 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33452 + * This program, aufs is free software; you can redistribute it and/or modify
33453 + * it under the terms of the GNU General Public License as published by
33454 + * the Free Software Foundation; either version 2 of the License, or
33455 + * (at your option) any later version.
33457 + * This program is distributed in the hope that it will be useful,
33458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33460 + * GNU General Public License for more details.
33462 + * You should have received a copy of the GNU General Public License
33463 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33467 + * workqueue for asynchronous/super-io operations
33468 + * todo: try new credentials management scheme
33471 +#ifndef __AUFS_WKQ_H__
33472 +#define __AUFS_WKQ_H__
33476 +struct super_block;
33478 +/* ---------------------------------------------------------------------- */
33481 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
33483 +struct au_nowait_tasks {
33485 + wait_queue_head_t nw_wq;
33488 +/* ---------------------------------------------------------------------- */
33490 +typedef void (*au_wkq_func_t)(void *args);
33493 +#define AuWkq_WAIT 1
33494 +#define AuWkq_NEST (1 << 1)
33495 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33496 +#define au_fset_wkq(flags, name) \
33497 + do { (flags) |= AuWkq_##name; } while (0)
33498 +#define au_fclr_wkq(flags, name) \
33499 + do { (flags) &= ~AuWkq_##name; } while (0)
33501 +#ifndef CONFIG_AUFS_HNOTIFY
33503 +#define AuWkq_NEST 0
33507 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33508 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33509 + unsigned int flags);
33510 +void au_nwt_init(struct au_nowait_tasks *nwt);
33511 +int __init au_wkq_init(void);
33512 +void au_wkq_fin(void);
33514 +/* ---------------------------------------------------------------------- */
33516 +static inline int au_wkq_test(void)
33518 + return current->flags & PF_WQ_WORKER;
33521 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33523 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33526 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33528 + if (atomic_dec_and_test(&nwt->nw_len))
33529 + wake_up_all(&nwt->nw_wq);
33532 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33534 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
33538 +#endif /* __KERNEL__ */
33539 +#endif /* __AUFS_WKQ_H__ */
33540 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33541 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33542 +++ linux/fs/aufs/xattr.c 2016-04-24 18:32:51.397020264 +0200
33545 + * Copyright (C) 2014-2016 Junjiro R. Okajima
33547 + * This program, aufs is free software; you can redistribute it and/or modify
33548 + * it under the terms of the GNU General Public License as published by
33549 + * the Free Software Foundation; either version 2 of the License, or
33550 + * (at your option) any later version.
33552 + * This program is distributed in the hope that it will be useful,
33553 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33554 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33555 + * GNU General Public License for more details.
33557 + * You should have received a copy of the GNU General Public License
33558 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33562 + * handling xattr functions
33565 +#include <linux/xattr.h>
33568 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33570 + if (!ignore_flags)
33578 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33583 +#define cmp(brattr, prefix) do { \
33584 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33585 + XATTR_##prefix##_PREFIX_LEN)) { \
33586 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33592 + cmp(SEC, SECURITY);
33593 + cmp(SYS, SYSTEM);
33594 + cmp(TR, TRUSTED);
33598 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33605 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
33607 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
33608 + char *name, char **buf, unsigned int ignore_flags,
33609 + unsigned int verbose)
33613 + struct inode *h_idst;
33615 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
33617 + if (unlikely(err <= 0)) {
33618 + if (err == -ENODATA
33619 + || (err == -EOPNOTSUPP
33620 + && ((ignore_flags & au_xattr_out_of_list)
33621 + || (au_test_nfs_noacl(d_inode(h_src))
33622 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
33624 + XATTR_NAME_POSIX_ACL_DEFAULT))))
33627 + if (err && (verbose || au_debug_test()))
33628 + pr_err("%s, err %d\n", name, err);
33632 + /* unlock it temporary */
33633 + h_idst = d_inode(h_dst);
33634 + inode_unlock(h_idst);
33635 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
33636 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
33637 + if (unlikely(err)) {
33638 + if (verbose || au_debug_test())
33639 + pr_err("%s, err %d\n", name, err);
33640 + err = au_xattr_ignore(err, name, ignore_flags);
33647 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
33648 + unsigned int verbose)
33650 + int err, unlocked, acl_access, acl_default;
33652 + struct inode *h_isrc, *h_idst;
33653 + char *value, *p, *o, *e;
33655 + /* try stopping to update the source inode while we are referencing */
33656 + /* there should not be the parent-child relationship between them */
33657 + h_isrc = d_inode(h_src);
33658 + h_idst = d_inode(h_dst);
33659 + inode_unlock(h_idst);
33660 + inode_lock_nested(h_isrc, AuLsc_I_CHILD);
33661 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
33664 + /* some filesystems don't list POSIX ACL, for example tmpfs */
33665 + ssz = vfs_listxattr(h_src, NULL, 0);
33667 + if (unlikely(err < 0)) {
33669 + if (err == -ENODATA
33670 + || err == -EOPNOTSUPP)
33671 + err = 0; /* ignore */
33680 + p = kmalloc(ssz, GFP_NOFS);
33682 + if (unlikely(!p))
33684 + err = vfs_listxattr(h_src, p, ssz);
33686 + inode_unlock(h_isrc);
33688 + AuDbg("err %d, ssz %zd\n", err, ssz);
33689 + if (unlikely(err < 0))
33697 + while (!err && p < e) {
33698 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33699 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33700 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33701 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33703 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
33705 + p += strlen(p) + 1;
33708 + ignore_flags |= au_xattr_out_of_list;
33709 + if (!err && !acl_access) {
33710 + err = au_do_cpup_xattr(h_dst, h_src,
33711 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33712 + ignore_flags, verbose);
33715 + if (!err && !acl_default) {
33716 + err = au_do_cpup_xattr(h_dst, h_src,
33717 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33718 + ignore_flags, verbose);
33728 + inode_unlock(h_isrc);
33733 +/* ---------------------------------------------------------------------- */
33740 +struct au_lgxattr {
33748 + const char *name;
33755 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33758 + struct path h_path;
33759 + struct super_block *sb;
33761 + sb = dentry->d_sb;
33762 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33763 + if (unlikely(err))
33765 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33766 + if (unlikely(err))
33768 + if (unlikely(!h_path.dentry))
33769 + /* illegally overlapped or something */
33770 + goto out_di; /* pretending success */
33772 + /* always topmost entry only */
33773 + switch (arg->type) {
33774 + case AU_XATTR_LIST:
33775 + err = vfs_listxattr(h_path.dentry,
33776 + arg->u.list.list, arg->u.list.size);
33778 + case AU_XATTR_GET:
33779 + err = vfs_getxattr(h_path.dentry,
33780 + arg->u.get.name, arg->u.get.value,
33781 + arg->u.get.size);
33786 + di_read_unlock(dentry, AuLock_IR);
33788 + si_read_unlock(sb);
33794 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33796 + struct au_lgxattr arg = {
33797 + .type = AU_XATTR_LIST,
33804 + return au_lgxattr(dentry, &arg);
33807 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
33810 + struct au_lgxattr arg = {
33811 + .type = AU_XATTR_GET,
33819 + return au_lgxattr(dentry, &arg);
33822 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33823 + size_t size, int flags)
33825 + struct au_srxattr arg = {
33826 + .type = AU_XATTR_SET,
33835 + return au_srxattr(dentry, &arg);
33838 +int aufs_removexattr(struct dentry *dentry, const char *name)
33840 + struct au_srxattr arg = {
33841 + .type = AU_XATTR_REMOVE,
33847 + return au_srxattr(dentry, &arg);
33850 +/* ---------------------------------------------------------------------- */
33853 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33854 + const char *name, size_t name_len, int type)
33856 + return aufs_listxattr(dentry, list, list_size);
33859 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33860 + size_t size, int type)
33862 + return aufs_getxattr(dentry, name, buffer, size);
33865 +static int au_xattr_set(struct dentry *dentry, const char *name,
33866 + const void *value, size_t size, int flags, int type)
33868 + return aufs_setxattr(dentry, name, value, size, flags);
33871 +static const struct xattr_handler au_xattr_handler = {
33872 + /* no prefix, no flags */
33873 + .list = au_xattr_list,
33874 + .get = au_xattr_get,
33875 + .set = au_xattr_set
33876 + /* why no remove? */
33879 +static const struct xattr_handler *au_xattr_handlers[] = {
33880 + &au_xattr_handler
33883 +void au_xattr_init(struct super_block *sb)
33885 + /* sb->s_xattr = au_xattr_handlers; */
33888 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33889 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33890 +++ linux/fs/aufs/xino.c 2016-04-24 18:32:51.397020264 +0200
33893 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33895 + * This program, aufs is free software; you can redistribute it and/or modify
33896 + * it under the terms of the GNU General Public License as published by
33897 + * the Free Software Foundation; either version 2 of the License, or
33898 + * (at your option) any later version.
33900 + * This program is distributed in the hope that it will be useful,
33901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33903 + * GNU General Public License for more details.
33905 + * You should have received a copy of the GNU General Public License
33906 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33910 + * external inode number translation table and bitmap
33913 +#include <linux/seq_file.h>
33914 +#include <linux/statfs.h>
33917 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33918 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
33922 + mm_segment_t oldfs;
33929 + oldfs = get_fs();
33930 + set_fs(KERNEL_DS);
33932 + /* todo: signal_pending? */
33933 + err = func(file, buf.u, size, pos);
33934 + } while (err == -EAGAIN || err == -EINTR);
33937 +#if 0 /* reserved for future use */
33939 + fsnotify_access(file->f_path.dentry);
33945 +/* ---------------------------------------------------------------------- */
33947 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
33948 + size_t size, loff_t *pos);
33950 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
33951 + size_t size, loff_t *pos)
33954 + mm_segment_t oldfs;
33957 + const char __user *u;
33960 + const int prevent_endless = 10;
33964 + oldfs = get_fs();
33965 + set_fs(KERNEL_DS);
33967 + err = func(file, buf.u, size, pos);
33968 + if (err == -EINTR
33969 + && !au_wkq_test()
33970 + && fatal_signal_pending(current)) {
33972 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
33973 + BUG_ON(err == -EINTR);
33974 + oldfs = get_fs();
33975 + set_fs(KERNEL_DS);
33977 + } while (i++ < prevent_endless
33978 + && (err == -EAGAIN || err == -EINTR));
33981 +#if 0 /* reserved for future use */
33983 + fsnotify_modify(file->f_path.dentry);
33989 +struct do_xino_fwrite_args {
33991 + vfs_writef_t func;
33992 + struct file *file;
33998 +static void call_do_xino_fwrite(void *args)
34000 + struct do_xino_fwrite_args *a = args;
34001 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34004 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34005 + size_t size, loff_t *pos)
34009 + struct do_xino_fwrite_args args = {
34019 + * it breaks RLIMIT_FSIZE and normal user's limit,
34020 + * users should care about quota and real 'filesystem full.'
34022 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34023 + if (unlikely(wkq_err))
34029 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34030 + size_t size, loff_t *pos)
34034 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34036 + err = do_xino_fwrite(func, file, buf, size, pos);
34039 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34044 +/* ---------------------------------------------------------------------- */
34047 + * create a new xinofile at the same place/path as @base_file.
34049 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34051 + struct file *file;
34052 + struct dentry *base, *parent;
34053 + struct inode *dir, *delegated;
34054 + struct qstr *name;
34055 + struct path path;
34058 + base = base_file->f_path.dentry;
34059 + parent = base->d_parent; /* dir inode is locked */
34060 + dir = d_inode(parent);
34063 + file = ERR_PTR(-EINVAL);
34064 + name = &base->d_name;
34065 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34066 + if (IS_ERR(path.dentry)) {
34067 + file = (void *)path.dentry;
34068 + pr_err("%pd lookup err %ld\n",
34069 + base, PTR_ERR(path.dentry));
34073 + /* no need to mnt_want_write() since we call dentry_open() later */
34074 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34075 + if (unlikely(err)) {
34076 + file = ERR_PTR(err);
34077 + pr_err("%pd create err %d\n", base, err);
34081 + path.mnt = base_file->f_path.mnt;
34082 + file = vfsub_dentry_open(&path,
34083 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34084 + /* | __FMODE_NONOTIFY */);
34085 + if (IS_ERR(file)) {
34086 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34090 + delegated = NULL;
34091 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34092 + if (unlikely(err == -EWOULDBLOCK)) {
34093 + pr_warn("cannot retry for NFSv4 delegation"
34094 + " for an internal unlink\n");
34097 + if (unlikely(err)) {
34098 + pr_err("%pd unlink err %d\n", base, err);
34103 + /* no one can touch copy_src xino */
34104 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34105 + if (unlikely(err)) {
34106 + pr_err("%pd copy err %d\n", base, err);
34110 + goto out_dput; /* success */
34114 + file = ERR_PTR(err);
34116 + dput(path.dentry);
34121 +struct au_xino_lock_dir {
34122 + struct au_hinode *hdir;
34123 + struct dentry *parent;
34124 + struct inode *dir;
34127 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34128 + struct au_xino_lock_dir *ldir)
34130 + aufs_bindex_t brid, bindex;
34132 + ldir->hdir = NULL;
34134 + brid = au_xino_brid(sb);
34136 + bindex = au_br_index(sb, brid);
34137 + if (bindex >= 0) {
34138 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34139 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34141 + ldir->parent = dget_parent(xino->f_path.dentry);
34142 + ldir->dir = d_inode(ldir->parent);
34143 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34147 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34150 + au_hn_imtx_unlock(ldir->hdir);
34152 + inode_unlock(ldir->dir);
34153 + dput(ldir->parent);
34157 +/* ---------------------------------------------------------------------- */
34159 +/* trucate xino files asynchronously */
34161 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34164 + unsigned long jiffy;
34166 + aufs_bindex_t bi, bend;
34167 + struct kstatfs *st;
34168 + struct au_branch *br;
34169 + struct file *new_xino, *file;
34170 + struct super_block *h_sb;
34171 + struct au_xino_lock_dir ldir;
34174 + st = kmalloc(sizeof(*st), GFP_NOFS);
34175 + if (unlikely(!st))
34179 + bend = au_sbend(sb);
34180 + if (unlikely(bindex < 0 || bend < bindex))
34182 + br = au_sbr(sb, bindex);
34183 + file = br->br_xino.xi_file;
34187 + err = vfs_statfs(&file->f_path, st);
34188 + if (unlikely(err))
34189 + AuErr1("statfs err %d, ignored\n", err);
34191 + blocks = file_inode(file)->i_blocks;
34192 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34193 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34195 + au_xino_lock_dir(sb, file, &ldir);
34196 + /* mnt_want_write() is unnecessary here */
34197 + new_xino = au_xino_create2(file, file);
34198 + au_xino_unlock_dir(&ldir);
34199 + err = PTR_ERR(new_xino);
34200 + if (IS_ERR(new_xino)) {
34201 + pr_err("err %d, ignored\n", err);
34206 + br->br_xino.xi_file = new_xino;
34208 + h_sb = au_br_sb(br);
34209 + for (bi = 0; bi <= bend; bi++) {
34210 + if (unlikely(bi == bindex))
34212 + br = au_sbr(sb, bi);
34213 + if (au_br_sb(br) != h_sb)
34216 + fput(br->br_xino.xi_file);
34217 + br->br_xino.xi_file = new_xino;
34218 + get_file(new_xino);
34221 + err = vfs_statfs(&new_xino->f_path, st);
34223 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34224 + bindex, (u64)file_inode(new_xino)->i_blocks,
34225 + st->f_bfree, st->f_blocks);
34226 + if (file_inode(new_xino)->i_blocks < blocks)
34227 + au_sbi(sb)->si_xino_jiffy = jiffy;
34229 + AuErr1("statfs err %d, ignored\n", err);
34237 +struct xino_do_trunc_args {
34238 + struct super_block *sb;
34239 + struct au_branch *br;
34242 +static void xino_do_trunc(void *_args)
34244 + struct xino_do_trunc_args *args = _args;
34245 + struct super_block *sb;
34246 + struct au_branch *br;
34247 + struct inode *dir;
34249 + aufs_bindex_t bindex;
34253 + dir = d_inode(sb->s_root);
34256 + si_noflush_write_lock(sb);
34257 + ii_read_lock_parent(dir);
34258 + bindex = au_br_index(sb, br->br_id);
34259 + err = au_xino_trunc(sb, bindex);
34260 + ii_read_unlock(dir);
34261 + if (unlikely(err))
34262 + pr_warn("err b%d, (%d)\n", bindex, err);
34263 + atomic_dec(&br->br_xino_running);
34264 + atomic_dec(&br->br_count);
34265 + si_write_unlock(sb);
34266 + au_nwt_done(&au_sbi(sb)->si_nowait);
34270 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34273 + struct kstatfs st;
34274 + struct au_sbinfo *sbinfo;
34276 + /* todo: si_xino_expire and the ratio should be customizable */
34277 + sbinfo = au_sbi(sb);
34278 + if (time_before(jiffies,
34279 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34282 + /* truncation border */
34283 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34284 + if (unlikely(err)) {
34285 + AuErr1("statfs err %d, ignored\n", err);
34288 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34294 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34296 + struct xino_do_trunc_args *args;
34299 + if (!xino_trunc_test(sb, br))
34302 + if (atomic_inc_return(&br->br_xino_running) > 1)
34305 + /* lock and kfree() will be called in trunc_xino() */
34306 + args = kmalloc(sizeof(*args), GFP_NOFS);
34307 + if (unlikely(!args)) {
34308 + AuErr1("no memory\n");
34312 + atomic_inc(&br->br_count);
34315 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34317 + return; /* success */
34319 + pr_err("wkq %d\n", wkq_err);
34320 + atomic_dec(&br->br_count);
34325 + atomic_dec(&br->br_xino_running);
34328 +/* ---------------------------------------------------------------------- */
34330 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34331 + ino_t h_ino, ino_t ino)
34337 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34338 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34341 + pos *= sizeof(ino);
34342 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34343 + if (sz == sizeof(ino))
34344 + return 0; /* success */
34346 + AuIOErr("write failed (%zd)\n", sz);
34351 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34352 + * at the position of @h_ino.
34353 + * even if @ino is zero, it is written to the xinofile and means no entry.
34354 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34355 + * try truncating it.
34357 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34361 + unsigned int mnt_flags;
34362 + struct au_branch *br;
34364 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34365 + || ((loff_t)-1) > 0);
34366 + SiMustAnyLock(sb);
34368 + mnt_flags = au_mntflags(sb);
34369 + if (!au_opt_test(mnt_flags, XINO))
34372 + br = au_sbr(sb, bindex);
34373 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34376 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34377 + && au_test_fs_trunc_xino(au_br_sb(br)))
34378 + xino_try_trunc(sb, br);
34379 + return 0; /* success */
34382 + AuIOErr("write failed (%d)\n", err);
34386 +/* ---------------------------------------------------------------------- */
34388 +/* aufs inode number bitmap */
34390 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34391 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34395 + AuDebugOn(bit < 0 || page_bits <= bit);
34396 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34400 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34402 + AuDebugOn(ino < AUFS_FIRST_INO);
34403 + ino -= AUFS_FIRST_INO;
34404 + *pindex = ino / page_bits;
34405 + *bit = ino % page_bits;
34408 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34413 + struct au_sbinfo *sbinfo;
34414 + struct file *xib;
34415 + unsigned long *p;
34417 + sbinfo = au_sbi(sb);
34418 + MtxMustLock(&sbinfo->si_xib_mtx);
34419 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34420 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34422 + if (pindex == sbinfo->si_xib_last_pindex)
34425 + xib = sbinfo->si_xib;
34426 + p = sbinfo->si_xib_buf;
34427 + pos = sbinfo->si_xib_last_pindex;
34428 + pos *= PAGE_SIZE;
34429 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34430 + if (unlikely(sz != PAGE_SIZE))
34434 + pos *= PAGE_SIZE;
34435 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
34436 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
34438 + memset(p, 0, PAGE_SIZE);
34439 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34441 + if (sz == PAGE_SIZE) {
34442 + sbinfo->si_xib_last_pindex = pindex;
34443 + return 0; /* success */
34447 + AuIOErr1("write failed (%zd)\n", sz);
34454 +/* ---------------------------------------------------------------------- */
34456 +static void au_xib_clear_bit(struct inode *inode)
34459 + unsigned long pindex;
34460 + struct super_block *sb;
34461 + struct au_sbinfo *sbinfo;
34463 + AuDebugOn(inode->i_nlink);
34465 + sb = inode->i_sb;
34466 + xib_calc_bit(inode->i_ino, &pindex, &bit);
34467 + AuDebugOn(page_bits <= bit);
34468 + sbinfo = au_sbi(sb);
34469 + mutex_lock(&sbinfo->si_xib_mtx);
34470 + err = xib_pindex(sb, pindex);
34472 + clear_bit(bit, sbinfo->si_xib_buf);
34473 + sbinfo->si_xib_next_bit = bit;
34475 + mutex_unlock(&sbinfo->si_xib_mtx);
34478 +/* for s_op->delete_inode() */
34479 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
34482 + unsigned int mnt_flags;
34483 + aufs_bindex_t bindex, bend, bi;
34484 + unsigned char try_trunc;
34485 + struct au_iinfo *iinfo;
34486 + struct super_block *sb;
34487 + struct au_hinode *hi;
34488 + struct inode *h_inode;
34489 + struct au_branch *br;
34490 + vfs_writef_t xwrite;
34492 + sb = inode->i_sb;
34493 + mnt_flags = au_mntflags(sb);
34494 + if (!au_opt_test(mnt_flags, XINO)
34495 + || inode->i_ino == AUFS_ROOT_INO)
34499 + au_xigen_inc(inode);
34500 + au_xib_clear_bit(inode);
34503 + iinfo = au_ii(inode);
34507 + bindex = iinfo->ii_bstart;
34511 + xwrite = au_sbi(sb)->si_xwrite;
34512 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
34513 + hi = iinfo->ii_hinode + bindex;
34514 + bend = iinfo->ii_bend;
34515 + for (; bindex <= bend; bindex++, hi++) {
34516 + h_inode = hi->hi_inode;
34518 + || (!unlinked && h_inode->i_nlink))
34521 + /* inode may not be revalidated */
34522 + bi = au_br_index(sb, hi->hi_id);
34526 + br = au_sbr(sb, bi);
34527 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34528 + h_inode->i_ino, /*ino*/0);
34529 + if (!err && try_trunc
34530 + && au_test_fs_trunc_xino(au_br_sb(br)))
34531 + xino_try_trunc(sb, br);
34535 +/* get an unused inode number from bitmap */
34536 +ino_t au_xino_new_ino(struct super_block *sb)
34539 + unsigned long *p, pindex, ul, pend;
34540 + struct au_sbinfo *sbinfo;
34541 + struct file *file;
34542 + int free_bit, err;
34544 + if (!au_opt_test(au_mntflags(sb), XINO))
34545 + return iunique(sb, AUFS_FIRST_INO);
34547 + sbinfo = au_sbi(sb);
34548 + mutex_lock(&sbinfo->si_xib_mtx);
34549 + p = sbinfo->si_xib_buf;
34550 + free_bit = sbinfo->si_xib_next_bit;
34551 + if (free_bit < page_bits && !test_bit(free_bit, p))
34552 + goto out; /* success */
34553 + free_bit = find_first_zero_bit(p, page_bits);
34554 + if (free_bit < page_bits)
34555 + goto out; /* success */
34557 + pindex = sbinfo->si_xib_last_pindex;
34558 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34559 + err = xib_pindex(sb, ul);
34560 + if (unlikely(err))
34562 + free_bit = find_first_zero_bit(p, page_bits);
34563 + if (free_bit < page_bits)
34564 + goto out; /* success */
34567 + file = sbinfo->si_xib;
34568 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34569 + for (ul = pindex + 1; ul <= pend; ul++) {
34570 + err = xib_pindex(sb, ul);
34571 + if (unlikely(err))
34573 + free_bit = find_first_zero_bit(p, page_bits);
34574 + if (free_bit < page_bits)
34575 + goto out; /* success */
34580 + set_bit(free_bit, p);
34581 + sbinfo->si_xib_next_bit = free_bit + 1;
34582 + pindex = sbinfo->si_xib_last_pindex;
34583 + mutex_unlock(&sbinfo->si_xib_mtx);
34584 + ino = xib_calc_ino(pindex, free_bit);
34585 + AuDbg("i%lu\n", (unsigned long)ino);
34588 + mutex_unlock(&sbinfo->si_xib_mtx);
34594 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34595 + * at the position of @h_ino.
34596 + * if @ino does not exist and @do_new is true, get new one.
34598 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34604 + struct file *file;
34605 + struct au_sbinfo *sbinfo;
34608 + if (!au_opt_test(au_mntflags(sb), XINO))
34609 + return 0; /* no xino */
34612 + sbinfo = au_sbi(sb);
34614 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
34615 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34618 + pos *= sizeof(*ino);
34620 + file = au_sbr(sb, bindex)->br_xino.xi_file;
34621 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
34622 + return 0; /* no ino */
34624 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
34625 + if (sz == sizeof(*ino))
34626 + return 0; /* success */
34629 + if (unlikely(sz >= 0)) {
34631 + AuIOErr("xino read error (%zd)\n", sz);
34637 +/* ---------------------------------------------------------------------- */
34639 +/* create and set a new xino file */
34641 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
34643 + struct file *file;
34644 + struct dentry *h_parent, *d;
34645 + struct inode *h_dir, *inode;
34649 + * at mount-time, and the xino file is the default path,
34650 + * hnotify is disabled so we have no notify events to ignore.
34651 + * when a user specified the xino, we cannot get au_hdir to be ignored.
34653 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34654 + /* | __FMODE_NONOTIFY */,
34655 + S_IRUGO | S_IWUGO);
34656 + if (IS_ERR(file)) {
34658 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
34662 + /* keep file count */
34664 + inode = file_inode(file);
34665 + h_parent = dget_parent(file->f_path.dentry);
34666 + h_dir = d_inode(h_parent);
34667 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
34668 + /* mnt_want_write() is unnecessary here */
34669 + /* no delegation since it is just created */
34670 + if (inode->i_nlink)
34671 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
34673 + inode_unlock(h_dir);
34675 + if (unlikely(err)) {
34677 + pr_err("unlink %s(%d)\n", fname, err);
34682 + d = file->f_path.dentry;
34683 + if (unlikely(sb == d->d_sb)) {
34685 + pr_err("%s must be outside\n", fname);
34688 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34690 + pr_err("xino doesn't support %s(%s)\n",
34691 + fname, au_sbtype(d->d_sb));
34694 + return file; /* success */
34698 + file = ERR_PTR(err);
34703 + * find another branch who is on the same filesystem of the specified
34704 + * branch{@btgt}. search until @bend.
34706 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34707 + aufs_bindex_t bend)
34709 + aufs_bindex_t bindex;
34710 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34712 + for (bindex = 0; bindex < btgt; bindex++)
34713 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34715 + for (bindex++; bindex <= bend; bindex++)
34716 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34721 +/* ---------------------------------------------------------------------- */
34724 + * initialize the xinofile for the specified branch @br
34725 + * at the place/path where @base_file indicates.
34726 + * test whether another branch is on the same filesystem or not,
34727 + * if @do_test is true.
34729 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34730 + struct file *base_file, int do_test)
34734 + aufs_bindex_t bend, bindex;
34735 + struct au_branch *shared_br, *b;
34736 + struct file *file;
34737 + struct super_block *tgt_sb;
34739 + shared_br = NULL;
34740 + bend = au_sbend(sb);
34742 + tgt_sb = au_br_sb(br);
34743 + for (bindex = 0; bindex <= bend; bindex++) {
34744 + b = au_sbr(sb, bindex);
34745 + if (tgt_sb == au_br_sb(b)) {
34752 + if (!shared_br || !shared_br->br_xino.xi_file) {
34753 + struct au_xino_lock_dir ldir;
34755 + au_xino_lock_dir(sb, base_file, &ldir);
34756 + /* mnt_want_write() is unnecessary here */
34757 + file = au_xino_create2(base_file, NULL);
34758 + au_xino_unlock_dir(&ldir);
34759 + err = PTR_ERR(file);
34760 + if (IS_ERR(file))
34762 + br->br_xino.xi_file = file;
34764 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34765 + get_file(br->br_xino.xi_file);
34768 + ino = AUFS_ROOT_INO;
34769 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34771 + if (unlikely(err)) {
34772 + fput(br->br_xino.xi_file);
34773 + br->br_xino.xi_file = NULL;
34780 +/* ---------------------------------------------------------------------- */
34782 +/* trucate a xino bitmap file */
34785 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34789 + unsigned long pindex;
34790 + loff_t pos, pend;
34791 + struct au_sbinfo *sbinfo;
34792 + vfs_readf_t func;
34794 + unsigned long *p;
34797 + sbinfo = au_sbi(sb);
34798 + MtxMustLock(&sbinfo->si_xib_mtx);
34799 + p = sbinfo->si_xib_buf;
34800 + func = sbinfo->si_xread;
34801 + pend = vfsub_f_size_read(file);
34803 + while (pos < pend) {
34804 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34806 + if (unlikely(sz <= 0))
34810 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34811 + if (unlikely(*ino < AUFS_FIRST_INO))
34814 + xib_calc_bit(*ino, &pindex, &bit);
34815 + AuDebugOn(page_bits <= bit);
34816 + err = xib_pindex(sb, pindex);
34828 +static int xib_restore(struct super_block *sb)
34831 + aufs_bindex_t bindex, bend;
34835 + page = (void *)__get_free_page(GFP_NOFS);
34836 + if (unlikely(!page))
34840 + bend = au_sbend(sb);
34841 + for (bindex = 0; !err && bindex <= bend; bindex++)
34842 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34843 + err = do_xib_restore
34844 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34846 + AuDbg("b%d\n", bindex);
34847 + free_page((unsigned long)page);
34853 +int au_xib_trunc(struct super_block *sb)
34858 + struct au_xino_lock_dir ldir;
34859 + struct au_sbinfo *sbinfo;
34860 + unsigned long *p;
34861 + struct file *file;
34863 + SiMustWriteLock(sb);
34866 + sbinfo = au_sbi(sb);
34867 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34870 + file = sbinfo->si_xib;
34871 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34874 + au_xino_lock_dir(sb, file, &ldir);
34875 + /* mnt_want_write() is unnecessary here */
34876 + file = au_xino_create2(sbinfo->si_xib, NULL);
34877 + au_xino_unlock_dir(&ldir);
34878 + err = PTR_ERR(file);
34879 + if (IS_ERR(file))
34881 + fput(sbinfo->si_xib);
34882 + sbinfo->si_xib = file;
34884 + p = sbinfo->si_xib_buf;
34885 + memset(p, 0, PAGE_SIZE);
34887 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34888 + if (unlikely(sz != PAGE_SIZE)) {
34890 + AuIOErr("err %d\n", err);
34896 + mutex_lock(&sbinfo->si_xib_mtx);
34897 + /* mnt_want_write() is unnecessary here */
34898 + err = xib_restore(sb);
34899 + mutex_unlock(&sbinfo->si_xib_mtx);
34905 +/* ---------------------------------------------------------------------- */
34908 + * xino mount option handlers
34912 +static void xino_clear_xib(struct super_block *sb)
34914 + struct au_sbinfo *sbinfo;
34916 + SiMustWriteLock(sb);
34918 + sbinfo = au_sbi(sb);
34919 + sbinfo->si_xread = NULL;
34920 + sbinfo->si_xwrite = NULL;
34921 + if (sbinfo->si_xib)
34922 + fput(sbinfo->si_xib);
34923 + sbinfo->si_xib = NULL;
34924 + free_page((unsigned long)sbinfo->si_xib_buf);
34925 + sbinfo->si_xib_buf = NULL;
34928 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34932 + struct au_sbinfo *sbinfo;
34933 + struct file *file;
34935 + SiMustWriteLock(sb);
34937 + sbinfo = au_sbi(sb);
34938 + file = au_xino_create2(base, sbinfo->si_xib);
34939 + err = PTR_ERR(file);
34940 + if (IS_ERR(file))
34942 + if (sbinfo->si_xib)
34943 + fput(sbinfo->si_xib);
34944 + sbinfo->si_xib = file;
34945 + sbinfo->si_xread = vfs_readf(file);
34946 + sbinfo->si_xwrite = vfs_writef(file);
34949 + if (!sbinfo->si_xib_buf)
34950 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34951 + if (unlikely(!sbinfo->si_xib_buf))
34954 + sbinfo->si_xib_last_pindex = 0;
34955 + sbinfo->si_xib_next_bit = 0;
34956 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34958 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34959 + PAGE_SIZE, &pos);
34960 + if (unlikely(err != PAGE_SIZE))
34964 + goto out; /* success */
34967 + free_page((unsigned long)sbinfo->si_xib_buf);
34968 + sbinfo->si_xib_buf = NULL;
34972 + fput(sbinfo->si_xib);
34973 + sbinfo->si_xib = NULL;
34974 + sbinfo->si_xread = NULL;
34975 + sbinfo->si_xwrite = NULL;
34980 +/* xino for each branch */
34981 +static void xino_clear_br(struct super_block *sb)
34983 + aufs_bindex_t bindex, bend;
34984 + struct au_branch *br;
34986 + bend = au_sbend(sb);
34987 + for (bindex = 0; bindex <= bend; bindex++) {
34988 + br = au_sbr(sb, bindex);
34989 + if (!br || !br->br_xino.xi_file)
34992 + fput(br->br_xino.xi_file);
34993 + br->br_xino.xi_file = NULL;
34997 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35001 + aufs_bindex_t bindex, bend, bshared;
35003 + struct file *old, *new;
35005 + struct au_branch *br;
35006 + struct inode *inode;
35007 + vfs_writef_t writef;
35009 + SiMustWriteLock(sb);
35012 + bend = au_sbend(sb);
35013 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
35014 + if (unlikely(!fpair))
35017 + inode = d_inode(sb->s_root);
35018 + ino = AUFS_ROOT_INO;
35019 + writef = au_sbi(sb)->si_xwrite;
35020 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
35021 + br = au_sbr(sb, bindex);
35022 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35023 + if (bshared >= 0) {
35024 + /* shared xino */
35025 + *p = fpair[bshared];
35026 + get_file(p->new);
35031 + p->old = br->br_xino.xi_file;
35032 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35033 + err = PTR_ERR(p->new);
35034 + if (IS_ERR(p->new)) {
35040 + err = au_xino_do_write(writef, p->new,
35041 + au_h_iptr(inode, bindex)->i_ino, ino);
35042 + if (unlikely(err))
35046 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
35047 + br = au_sbr(sb, bindex);
35048 + if (br->br_xino.xi_file)
35049 + fput(br->br_xino.xi_file);
35050 + get_file(p->new);
35051 + br->br_xino.xi_file = p->new;
35055 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
35065 +void au_xino_clr(struct super_block *sb)
35067 + struct au_sbinfo *sbinfo;
35069 + au_xigen_clr(sb);
35070 + xino_clear_xib(sb);
35071 + xino_clear_br(sb);
35072 + sbinfo = au_sbi(sb);
35073 + /* lvalue, do not call au_mntflags() */
35074 + au_opt_clr(sbinfo->si_mntflags, XINO);
35077 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35080 + struct dentry *parent, *cur_parent;
35081 + struct qstr *dname, *cur_name;
35082 + struct file *cur_xino;
35083 + struct inode *dir;
35084 + struct au_sbinfo *sbinfo;
35086 + SiMustWriteLock(sb);
35089 + sbinfo = au_sbi(sb);
35090 + parent = dget_parent(xino->file->f_path.dentry);
35093 + dname = &xino->file->f_path.dentry->d_name;
35094 + cur_xino = sbinfo->si_xib;
35096 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35097 + cur_name = &cur_xino->f_path.dentry->d_name;
35098 + skip = (cur_parent == parent
35099 + && au_qstreq(dname, cur_name));
35100 + dput(cur_parent);
35106 + au_opt_set(sbinfo->si_mntflags, XINO);
35107 + dir = d_inode(parent);
35108 + inode_lock_nested(dir, AuLsc_I_PARENT);
35109 + /* mnt_want_write() is unnecessary here */
35110 + err = au_xino_set_xib(sb, xino->file);
35112 + err = au_xigen_set(sb, xino->file);
35114 + err = au_xino_set_br(sb, xino->file);
35115 + inode_unlock(dir);
35117 + goto out; /* success */
35120 + AuIOErr("failed creating xino(%d).\n", err);
35121 + au_xigen_clr(sb);
35122 + xino_clear_xib(sb);
35129 +/* ---------------------------------------------------------------------- */
35132 + * create a xinofile at the default place/path.
35134 +struct file *au_xino_def(struct super_block *sb)
35136 + struct file *file;
35138 + struct au_branch *br;
35139 + struct super_block *h_sb;
35140 + struct path path;
35141 + aufs_bindex_t bend, bindex, bwr;
35144 + bend = au_sbend(sb);
35146 + for (bindex = 0; bindex <= bend; bindex++) {
35147 + br = au_sbr(sb, bindex);
35148 + if (au_br_writable(br->br_perm)
35149 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35156 + file = ERR_PTR(-ENOMEM);
35157 + page = (void *)__get_free_page(GFP_NOFS);
35158 + if (unlikely(!page))
35160 + path.mnt = au_br_mnt(br);
35161 + path.dentry = au_h_dptr(sb->s_root, bwr);
35162 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35163 + file = (void *)p;
35164 + if (!IS_ERR(p)) {
35165 + strcat(p, "/" AUFS_XINO_FNAME);
35166 + AuDbg("%s\n", p);
35167 + file = au_xino_create(sb, p, /*silent*/0);
35168 + if (!IS_ERR(file))
35169 + au_xino_brid_set(sb, br->br_id);
35171 + free_page((unsigned long)page);
35173 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35174 + if (IS_ERR(file))
35176 + h_sb = file->f_path.dentry->d_sb;
35177 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35178 + pr_err("xino doesn't support %s(%s)\n",
35179 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35181 + file = ERR_PTR(-EINVAL);
35183 + if (!IS_ERR(file))
35184 + au_xino_brid_set(sb, -1);
35191 +/* ---------------------------------------------------------------------- */
35193 +int au_xino_path(struct seq_file *seq, struct file *file)
35197 + err = au_seq_path(seq, &file->f_path);
35198 + if (unlikely(err))
35201 +#define Deleted "\\040(deleted)"
35202 + seq->count -= sizeof(Deleted) - 1;
35203 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35204 + sizeof(Deleted) - 1));
35210 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35211 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35212 +++ linux/include/uapi/linux/aufs_type.h 2016-04-24 18:32:51.397020264 +0200
35215 + * Copyright (C) 2005-2016 Junjiro R. Okajima
35217 + * This program, aufs is free software; you can redistribute it and/or modify
35218 + * it under the terms of the GNU General Public License as published by
35219 + * the Free Software Foundation; either version 2 of the License, or
35220 + * (at your option) any later version.
35222 + * This program is distributed in the hope that it will be useful,
35223 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35224 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35225 + * GNU General Public License for more details.
35227 + * You should have received a copy of the GNU General Public License
35228 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35231 +#ifndef __AUFS_TYPE_H__
35232 +#define __AUFS_TYPE_H__
35234 +#define AUFS_NAME "aufs"
35238 + * define it before including all other headers.
35239 + * sched.h may use pr_* macros before defining "current", so define the
35240 + * no-current version first, and re-define later.
35242 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35243 +#include <linux/sched.h>
35245 +#define pr_fmt(fmt) \
35246 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35247 + (int)sizeof(current->comm), current->comm, current->pid
35249 +#include <stdint.h>
35250 +#include <sys/types.h>
35251 +#endif /* __KERNEL__ */
35253 +#include <linux/limits.h>
35255 +#define AUFS_VERSION "4.5-20160328"
35257 +/* todo? move this to linux-2.6.19/include/magic.h */
35258 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35260 +/* ---------------------------------------------------------------------- */
35262 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35263 +typedef int8_t aufs_bindex_t;
35264 +#define AUFS_BRANCH_MAX 127
35266 +typedef int16_t aufs_bindex_t;
35267 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35268 +#define AUFS_BRANCH_MAX 511
35269 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35270 +#define AUFS_BRANCH_MAX 1023
35271 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35272 +#define AUFS_BRANCH_MAX 32767
35277 +#ifndef AUFS_BRANCH_MAX
35278 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35280 +#endif /* __KERNEL__ */
35282 +/* ---------------------------------------------------------------------- */
35284 +#define AUFS_FSTYPE AUFS_NAME
35286 +#define AUFS_ROOT_INO 2
35287 +#define AUFS_FIRST_INO 11
35289 +#define AUFS_WH_PFX ".wh."
35290 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
35291 +#define AUFS_WH_TMP_LEN 4
35292 +/* a limit for rmdir/rename a dir and copyup */
35293 +#define AUFS_MAX_NAMELEN (NAME_MAX \
35294 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
35296 + - AUFS_WH_TMP_LEN) /* hex */
35297 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
35298 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
35299 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
35300 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
35301 +#define AUFS_DIRWH_DEF 3
35302 +#define AUFS_RDCACHE_DEF 10 /* seconds */
35303 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
35304 +#define AUFS_RDBLK_DEF 512 /* bytes */
35305 +#define AUFS_RDHASH_DEF 32
35306 +#define AUFS_WKQ_NAME AUFS_NAME "d"
35307 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
35308 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
35309 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
35310 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35312 +/* pseudo-link maintenace under /proc */
35313 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35314 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35315 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35317 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35318 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35320 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35321 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35322 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35324 +/* doubly whiteouted */
35325 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35326 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35327 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35329 +/* branch permissions and attributes */
35330 +#define AUFS_BRPERM_RW "rw"
35331 +#define AUFS_BRPERM_RO "ro"
35332 +#define AUFS_BRPERM_RR "rr"
35333 +#define AUFS_BRATTR_COO_REG "coo_reg"
35334 +#define AUFS_BRATTR_COO_ALL "coo_all"
35335 +#define AUFS_BRATTR_FHSM "fhsm"
35336 +#define AUFS_BRATTR_UNPIN "unpin"
35337 +#define AUFS_BRATTR_ICEX "icex"
35338 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35339 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35340 +#define AUFS_BRATTR_ICEX_TR "icextr"
35341 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35342 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35343 +#define AUFS_BRRATTR_WH "wh"
35344 +#define AUFS_BRWATTR_NLWH "nolwh"
35345 +#define AUFS_BRWATTR_MOO "moo"
35347 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35348 +#define AuBrPerm_RO (1 << 1) /* readonly */
35349 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35350 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35352 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35353 +#define AuBrAttr_COO_ALL (1 << 4)
35354 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35356 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35357 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35358 + branch. meaningless since
35359 + linux-3.18-rc1 */
35361 +/* ignore error in copying XATTR */
35362 +#define AuBrAttr_ICEX_SEC (1 << 7)
35363 +#define AuBrAttr_ICEX_SYS (1 << 8)
35364 +#define AuBrAttr_ICEX_TR (1 << 9)
35365 +#define AuBrAttr_ICEX_USR (1 << 10)
35366 +#define AuBrAttr_ICEX_OTH (1 << 11)
35367 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35368 + | AuBrAttr_ICEX_SYS \
35369 + | AuBrAttr_ICEX_TR \
35370 + | AuBrAttr_ICEX_USR \
35371 + | AuBrAttr_ICEX_OTH)
35373 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35374 +#define AuBrRAttr_Mask AuBrRAttr_WH
35376 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35377 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35378 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35380 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35382 +/* #warning test userspace */
35384 +#ifndef CONFIG_AUFS_FHSM
35385 +#undef AuBrAttr_FHSM
35386 +#define AuBrAttr_FHSM 0
35388 +#ifndef CONFIG_AUFS_XATTR
35389 +#undef AuBrAttr_ICEX
35390 +#define AuBrAttr_ICEX 0
35391 +#undef AuBrAttr_ICEX_SEC
35392 +#define AuBrAttr_ICEX_SEC 0
35393 +#undef AuBrAttr_ICEX_SYS
35394 +#define AuBrAttr_ICEX_SYS 0
35395 +#undef AuBrAttr_ICEX_TR
35396 +#define AuBrAttr_ICEX_TR 0
35397 +#undef AuBrAttr_ICEX_USR
35398 +#define AuBrAttr_ICEX_USR 0
35399 +#undef AuBrAttr_ICEX_OTH
35400 +#define AuBrAttr_ICEX_OTH 0
35404 +/* the longest combination */
35405 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35406 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35407 + "+" AUFS_BRATTR_COO_REG \
35408 + "+" AUFS_BRATTR_FHSM \
35409 + "+" AUFS_BRATTR_UNPIN \
35410 + "+" AUFS_BRATTR_ICEX_SEC \
35411 + "+" AUFS_BRATTR_ICEX_SYS \
35412 + "+" AUFS_BRATTR_ICEX_USR \
35413 + "+" AUFS_BRATTR_ICEX_OTH \
35414 + "+" AUFS_BRWATTR_NLWH)
35417 + char a[AuBrPermStrSz];
35418 +} au_br_perm_str_t;
35420 +static inline int au_br_writable(int brperm)
35422 + return brperm & AuBrPerm_RW;
35425 +static inline int au_br_whable(int brperm)
35427 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35430 +static inline int au_br_wh_linkable(int brperm)
35432 + return !(brperm & AuBrWAttr_NoLinkWH);
35435 +static inline int au_br_cmoo(int brperm)
35437 + return brperm & AuBrAttr_CMOO_Mask;
35440 +static inline int au_br_fhsm(int brperm)
35442 + return brperm & AuBrAttr_FHSM;
35445 +/* ---------------------------------------------------------------------- */
35449 + /* readdir in userspace */
35453 + AuCtl_WBR_FD, /* pathconf wrapper */
35454 + AuCtl_IBUSY, /* busy inode */
35455 + AuCtl_MVDOWN, /* move-down */
35456 + AuCtl_BR, /* info about branches */
35457 + AuCtl_FHSM_FD /* connection for fhsm */
35460 +/* borrowed from linux/include/linux/kernel.h */
35462 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
35463 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
35466 +/* borrowed from linux/include/linux/compiler-gcc3.h */
35468 +#define __aligned(x) __attribute__((aligned(x)))
35473 +#define __packed __attribute__((packed))
35477 +struct au_rdu_cookie {
35482 + uint32_t generation;
35485 +struct au_rdu_ent {
35494 +static inline int au_rdu_len(int nlen)
35496 + /* include the terminating NULL */
35497 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35498 + sizeof(uint64_t));
35501 +union au_rdu_ent_ul {
35502 + struct au_rdu_ent __user *e;
35514 + uint64_t sz; /* AuCtl_RDU */
35515 + uint64_t nent; /* AuCtl_RDU_INO */
35517 + union au_rdu_ent_ul ent;
35518 + uint16_t verify[AufsCtlRduV_End];
35520 + /* input/output */
35524 + union au_rdu_ent_ul tail;
35525 + /* number of entries which were added in a single call */
35530 + struct au_rdu_cookie cookie;
35533 +/* ---------------------------------------------------------------------- */
35535 +struct aufs_wbr_fd {
35540 +/* ---------------------------------------------------------------------- */
35542 +struct aufs_ibusy {
35543 + uint64_t ino, h_ino;
35547 +/* ---------------------------------------------------------------------- */
35549 +/* error code for move-down */
35550 +/* the actual message strings are implemented in aufs-util.git */
35552 + EAU_MVDOWN_OPAQUE = 1,
35553 + EAU_MVDOWN_WHITEOUT,
35554 + EAU_MVDOWN_UPPER,
35555 + EAU_MVDOWN_BOTTOM,
35556 + EAU_MVDOWN_NOUPPER,
35557 + EAU_MVDOWN_NOLOWERBR,
35561 +/* flags for move-down */
35562 +#define AUFS_MVDOWN_DMSG 1
35563 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35564 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35565 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35566 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35567 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35568 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35569 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35570 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35571 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35572 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35573 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35574 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35576 +/* index for move-down */
35578 + AUFS_MVDOWN_UPPER,
35579 + AUFS_MVDOWN_LOWER,
35580 + AUFS_MVDOWN_NARRAY
35584 + * additional info of move-down
35585 + * number of free blocks and inodes.
35586 + * subset of struct kstatfs, but smaller and always 64bit.
35588 +struct aufs_stfs {
35589 + uint64_t f_blocks;
35590 + uint64_t f_bavail;
35591 + uint64_t f_files;
35592 + uint64_t f_ffree;
35595 +struct aufs_stbr {
35596 + int16_t brid; /* optional input */
35597 + int16_t bindex; /* output */
35598 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35601 +struct aufs_mvdown {
35602 + uint32_t flags; /* input/output */
35603 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35604 + int8_t au_errno; /* output */
35607 +/* ---------------------------------------------------------------------- */
35609 +union aufs_brinfo {
35610 + /* PATH_MAX may differ between kernel-space and user-space */
35611 + char _spacer[4096];
35619 +/* ---------------------------------------------------------------------- */
35621 +#define AuCtlType 'A'
35622 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35623 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35624 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35625 + struct aufs_wbr_fd)
35626 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35627 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35628 + struct aufs_mvdown)
35629 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35630 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35632 +#endif /* __AUFS_TYPE_H__ */
35633 aufs4.5 loopback patch
35635 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
35636 index 0b816b2..86dd454 100644
35637 --- a/drivers/block/loop.c
35638 +++ b/drivers/block/loop.c
35639 @@ -556,7 +556,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
35642 struct switch_request {
35643 - struct file *file;
35644 + struct file *file, *virt_file;
35645 struct completion wait;
35648 @@ -582,6 +582,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35649 mapping = file->f_mapping;
35650 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
35651 lo->lo_backing_file = file;
35652 + lo->lo_backing_virt_file = p->virt_file;
35653 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
35654 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
35655 lo->old_gfp_mask = mapping_gfp_mask(mapping);
35656 @@ -594,11 +595,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35657 * First it needs to flush existing IO, it does this by sending a magic
35658 * BIO down the pipe. The completion of this BIO does the actual switch.
35660 -static int loop_switch(struct loop_device *lo, struct file *file)
35661 +static int loop_switch(struct loop_device *lo, struct file *file,
35662 + struct file *virt_file)
35664 struct switch_request w;
35667 + w.virt_file = virt_file;
35669 /* freeze queue and wait for completion of scheduled requests */
35670 blk_mq_freeze_queue(lo->lo_queue);
35671 @@ -617,7 +620,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
35673 static int loop_flush(struct loop_device *lo)
35675 - return loop_switch(lo, NULL);
35676 + return loop_switch(lo, NULL, NULL);
35679 +static struct file *loop_real_file(struct file *file)
35681 + struct file *f = NULL;
35683 + if (file->f_path.dentry->d_sb->s_op->real_loop)
35684 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
35688 static void loop_reread_partitions(struct loop_device *lo,
35689 @@ -654,6 +666,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35692 struct file *file, *old_file;
35693 + struct file *f, *virt_file = NULL, *old_virt_file;
35694 struct inode *inode;
35697 @@ -670,9 +683,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35701 + f = loop_real_file(file);
35703 + virt_file = file;
35708 inode = file->f_mapping->host;
35709 old_file = lo->lo_backing_file;
35710 + old_virt_file = lo->lo_backing_virt_file;
35714 @@ -684,17 +704,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35717 /* and ... switch */
35718 - error = loop_switch(lo, file);
35719 + error = loop_switch(lo, file, virt_file);
35724 + if (old_virt_file)
35725 + fput(old_virt_file);
35726 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
35727 loop_reread_partitions(lo, bdev);
35737 @@ -881,7 +905,7 @@ static int loop_prepare_queue(struct loop_device *lo)
35738 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35739 struct block_device *bdev, unsigned int arg)
35741 - struct file *file, *f;
35742 + struct file *file, *f, *virt_file = NULL;
35743 struct inode *inode;
35744 struct address_space *mapping;
35745 unsigned lo_blocksize;
35746 @@ -896,6 +920,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35750 + f = loop_real_file(file);
35752 + virt_file = file;
35758 if (lo->lo_state != Lo_unbound)
35759 @@ -948,6 +978,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35760 lo->lo_device = bdev;
35761 lo->lo_flags = lo_flags;
35762 lo->lo_backing_file = file;
35763 + lo->lo_backing_virt_file = virt_file;
35764 lo->transfer = NULL;
35766 lo->lo_sizelimit = 0;
35767 @@ -980,6 +1011,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35774 /* This is safe: open() is still holding a reference. */
35775 module_put(THIS_MODULE);
35776 @@ -1026,6 +1059,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
35777 static int loop_clr_fd(struct loop_device *lo)
35779 struct file *filp = lo->lo_backing_file;
35780 + struct file *virt_filp = lo->lo_backing_virt_file;
35781 gfp_t gfp = lo->old_gfp_mask;
35782 struct block_device *bdev = lo->lo_device;
35784 @@ -1057,6 +1091,7 @@ static int loop_clr_fd(struct loop_device *lo)
35785 spin_lock_irq(&lo->lo_lock);
35786 lo->lo_state = Lo_rundown;
35787 lo->lo_backing_file = NULL;
35788 + lo->lo_backing_virt_file = NULL;
35789 spin_unlock_irq(&lo->lo_lock);
35791 loop_release_xfer(lo);
35792 @@ -1101,6 +1136,8 @@ static int loop_clr_fd(struct loop_device *lo)
35793 * bd_mutex which is usually taken before lo_ctl_mutex.
35801 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
35802 index fb2237c..c3888c5 100644
35803 --- a/drivers/block/loop.h
35804 +++ b/drivers/block/loop.h
35805 @@ -46,7 +46,7 @@ struct loop_device {
35806 int (*ioctl)(struct loop_device *, int cmd,
35807 unsigned long arg);
35809 - struct file * lo_backing_file;
35810 + struct file * lo_backing_file, *lo_backing_virt_file;
35811 struct block_device *lo_device;
35812 unsigned lo_blocksize;
35814 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
35815 index ac1304a..0cefd8a 100644
35816 --- a/fs/aufs/f_op.c
35817 +++ b/fs/aufs/f_op.c
35818 @@ -399,7 +399,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
35819 if (IS_ERR(h_file))
35822 - if (au_test_loopback_kthread()) {
35823 + if (0 && au_test_loopback_kthread()) {
35824 au_warn_loopback(h_file->f_path.dentry->d_sb);
35825 if (file->f_mapping != h_file->f_mapping) {
35826 file->f_mapping = h_file->f_mapping;
35827 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
35828 index 5711e7a..9df5d16 100644
35829 --- a/fs/aufs/loop.c
35830 +++ b/fs/aufs/loop.c
35831 @@ -131,3 +131,19 @@ void au_loopback_fin(void)
35832 symbol_put(loop_backing_file);
35833 kfree(au_warn_loopback_array);
35836 +/* ---------------------------------------------------------------------- */
35838 +/* support the loopback block device insude aufs */
35840 +struct file *aufs_real_loop(struct file *file)
35844 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
35845 + fi_read_lock(file);
35846 + f = au_hf_top(file);
35847 + fi_read_unlock(file);
35851 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
35852 index 48bf070..66afec7 100644
35853 --- a/fs/aufs/loop.h
35854 +++ b/fs/aufs/loop.h
35855 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
35857 int au_loopback_init(void);
35858 void au_loopback_fin(void);
35860 +struct file *aufs_real_loop(struct file *file);
35862 +AuStub(struct file *, loop_backing_file, return NULL)
35864 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
35865 struct dentry *h_adding)
35866 AuStubInt0(au_test_loopback_kthread, void)
35867 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
35869 AuStubInt0(au_loopback_init, void)
35870 AuStubVoid(au_loopback_fin, void)
35872 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
35873 #endif /* BLK_DEV_LOOP */
35875 #endif /* __KERNEL__ */
35876 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
35877 index 7928a50..9466cc9 100644
35878 --- a/fs/aufs/super.c
35879 +++ b/fs/aufs/super.c
35880 @@ -832,7 +832,10 @@ static const struct super_operations aufs_sop = {
35881 .statfs = aufs_statfs,
35882 .put_super = aufs_put_super,
35883 .sync_fs = aufs_sync_fs,
35884 - .remount_fs = aufs_remount_fs
35885 + .remount_fs = aufs_remount_fs,
35886 +#ifdef CONFIG_AUFS_BDEV_LOOP
35887 + .real_loop = aufs_real_loop
35891 /* ---------------------------------------------------------------------- */
35892 diff --git a/include/linux/fs.h b/include/linux/fs.h
35893 index 99fc2bd..842a2e0 100644
35894 --- a/include/linux/fs.h
35895 +++ b/include/linux/fs.h
35896 @@ -1759,6 +1759,10 @@ struct super_operations {
35897 struct shrink_control *);
35898 long (*free_cached_objects)(struct super_block *,
35899 struct shrink_control *);
35900 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
35902 + struct file *(*real_loop)(struct file *);