1 aufs3.18.1+ kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 664991a..1481093 100644
7 @@ -210,6 +210,7 @@ source "fs/ufs/Kconfig"
8 source "fs/exofs/Kconfig"
9 source "fs/f2fs/Kconfig"
10 source "fs/efivarfs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index da0bbb4..c8bc724 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 8523f9b..11f8f74 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -56,6 +56,7 @@ header-y += atmppp.h
30 header-y += atm_zatm.h
32 +header-y += aufs_type.h
33 header-y += auto_fs4.h
36 aufs3.18.1+ base patch
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index c721042..83801d0 100644
42 @@ -1795,6 +1795,20 @@ 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://git.code.sf.net/p/aufs/aufs3-linux
52 +T: git://github.com/sfjro/aufs3-linux.git
54 +F: Documentation/filesystems/aufs/
55 +F: Documentation/ABI/testing/debugfs-aufs
56 +F: Documentation/ABI/testing/sysfs-aufs
58 +F: include/uapi/linux/aufs_type.h
60 AUXILIARY DISPLAY DRIVERS
61 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
62 W: http://miguelojeda.es/auxdisplay.htm
63 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
64 index 6cb1beb..30efd68 100644
65 --- a/drivers/block/loop.c
66 +++ b/drivers/block/loop.c
67 @@ -692,6 +692,24 @@ static inline int is_loop_device(struct file *file)
68 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
73 + * no get/put for file.
75 +struct file *loop_backing_file(struct super_block *sb)
78 + struct loop_device *l;
81 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
82 + l = sb->s_bdev->bd_disk->private_data;
83 + ret = l->lo_backing_file;
87 +EXPORT_SYMBOL(loop_backing_file);
89 /* loop sysfs attributes */
91 static ssize_t loop_attr_show(struct device *dev, char *page,
92 diff --git a/fs/dcache.c b/fs/dcache.c
93 index 71acf8d..da7342e 100644
96 @@ -1019,7 +1019,7 @@ enum d_walk_ret {
98 * The @enter() and @finish() callbacks are called with d_lock held.
100 -static void d_walk(struct dentry *parent, void *data,
101 +void d_walk(struct dentry *parent, void *data,
102 enum d_walk_ret (*enter)(void *, struct dentry *),
103 void (*finish)(void *))
105 diff --git a/fs/inode.c b/fs/inode.c
106 index 26753ba..df21e66 100644
109 @@ -1497,7 +1497,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
110 * This does the actual work of updating an inodes time or version. Must have
111 * had called mnt_want_write() before calling this.
113 -static int update_time(struct inode *inode, struct timespec *time, int flags)
114 +int update_time(struct inode *inode, struct timespec *time, int flags)
116 if (inode->i_op->update_time)
117 return inode->i_op->update_time(inode, time, flags);
118 diff --git a/fs/splice.c b/fs/splice.c
119 index 75c6058..619359a 100644
122 @@ -1114,8 +1114,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
124 * Attempt to initiate a splice from pipe to file.
126 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
127 - loff_t *ppos, size_t len, unsigned int flags)
128 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
129 + loff_t *ppos, size_t len, unsigned int flags)
131 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
132 loff_t *, size_t, unsigned int);
133 @@ -1131,9 +1131,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
135 * Attempt to initiate a splice from a file to a pipe.
137 -static long do_splice_to(struct file *in, loff_t *ppos,
138 - struct pipe_inode_info *pipe, size_t len,
139 - unsigned int flags)
140 +long do_splice_to(struct file *in, loff_t *ppos,
141 + struct pipe_inode_info *pipe, size_t len,
142 + unsigned int flags)
144 ssize_t (*splice_read)(struct file *, loff_t *,
145 struct pipe_inode_info *, size_t, unsigned int);
146 diff --git a/include/linux/fs.h b/include/linux/fs.h
147 index 9ab779e..aabcbba 100644
148 --- a/include/linux/fs.h
149 +++ b/include/linux/fs.h
150 @@ -2664,6 +2664,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
151 extern int inode_newsize_ok(const struct inode *, loff_t offset);
152 extern void setattr_copy(struct inode *inode, const struct iattr *attr);
154 +extern int update_time(struct inode *, struct timespec *, int);
155 extern int file_update_time(struct file *file);
157 extern int generic_show_options(struct seq_file *m, struct dentry *root);
158 diff --git a/include/linux/splice.h b/include/linux/splice.h
159 index da2751d..2e0fca6 100644
160 --- a/include/linux/splice.h
161 +++ b/include/linux/splice.h
162 @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
163 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
165 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
167 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
168 + loff_t *ppos, size_t len, unsigned int flags);
169 +extern long do_splice_to(struct file *in, loff_t *ppos,
170 + struct pipe_inode_info *pipe, size_t len,
171 + unsigned int flags);
173 aufs3.18.1+ mmap patch
175 diff --git a/fs/buffer.c b/fs/buffer.c
176 index 20805db..363569f 100644
179 @@ -2450,7 +2450,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
180 * Update file times before taking page lock. We may end up failing the
181 * fault so this update may be superfluous but who really cares...
183 - file_update_time(vma->vm_file);
184 + vma_file_update_time(vma);
186 ret = __block_page_mkwrite(vma, vmf, get_block);
187 sb_end_pagefault(sb);
188 diff --git a/fs/proc/base.c b/fs/proc/base.c
189 index 772efa4..2c944de 100644
192 @@ -1735,7 +1735,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
193 down_read(&mm->mmap_sem);
194 vma = find_exact_vma(mm, vm_start, vm_end);
195 if (vma && vma->vm_file) {
196 - *path = vma->vm_file->f_path;
197 + *path = vma_pr_or_file(vma)->f_path;
201 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
202 index d4a3574..1397181 100644
203 --- a/fs/proc/nommu.c
204 +++ b/fs/proc/nommu.c
205 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
206 file = region->vm_file;
209 - struct inode *inode = file_inode(region->vm_file);
210 + struct inode *inode;
212 + file = vmr_pr_or_file(region);
213 + inode = file_inode(file);
214 dev = inode->i_sb->s_dev;
217 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
218 index 4e0388c..fc429e7 100644
219 --- a/fs/proc/task_mmu.c
220 +++ b/fs/proc/task_mmu.c
221 @@ -276,7 +276,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
222 const char *name = NULL;
225 - struct inode *inode = file_inode(vma->vm_file);
226 + struct inode *inode;
228 + file = vma_pr_or_file(vma);
229 + inode = file_inode(file);
230 dev = inode->i_sb->s_dev;
232 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
233 @@ -1440,7 +1443,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
234 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
235 struct vm_area_struct *vma = v;
236 struct numa_maps *md = &numa_priv->md;
237 - struct file *file = vma->vm_file;
238 + struct file *file = vma_pr_or_file(vma);
239 struct mm_struct *mm = vma->vm_mm;
240 struct mm_walk walk = {};
241 struct mempolicy *pol;
242 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
243 index 599ec2e..de6cd6e 100644
244 --- a/fs/proc/task_nommu.c
245 +++ b/fs/proc/task_nommu.c
246 @@ -160,7 +160,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
250 - struct inode *inode = file_inode(vma->vm_file);
251 + struct inode *inode;
253 + file = vma_pr_or_file(file);
254 + inode = file_inode(file);
255 dev = inode->i_sb->s_dev;
257 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
258 diff --git a/include/linux/mm.h b/include/linux/mm.h
259 index b464611..8027d51 100644
260 --- a/include/linux/mm.h
261 +++ b/include/linux/mm.h
262 @@ -1206,6 +1206,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
267 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
268 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
270 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
271 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
273 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
275 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
277 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
278 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
280 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
281 +extern void vmr_do_fput(struct vm_region *, const char[], int);
283 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
285 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
286 +#endif /* CONFIG_MMU */
288 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
289 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
290 void *buf, int len, int write);
291 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
292 index 6e0b286..8f374ed 100644
293 --- a/include/linux/mm_types.h
294 +++ b/include/linux/mm_types.h
295 @@ -232,6 +232,7 @@ struct vm_region {
296 unsigned long vm_top; /* region allocated to here */
297 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
298 struct file *vm_file; /* the backing file or NULL */
299 + struct file *vm_prfile; /* the virtual backing file or NULL */
301 int vm_usage; /* region usage count (access under nommu_region_sem) */
302 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
303 @@ -300,6 +301,7 @@ struct vm_area_struct {
304 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
305 units, *not* PAGE_CACHE_SIZE */
306 struct file * vm_file; /* File we map to (can be NULL). */
307 + struct file *vm_prfile; /* shadow of vm_file */
308 void * vm_private_data; /* was vm_pte (shared mem) */
311 diff --git a/kernel/fork.c b/kernel/fork.c
312 index 9b7d746..9a3b8fe 100644
315 @@ -430,7 +430,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
316 struct inode *inode = file_inode(file);
317 struct address_space *mapping = file->f_mapping;
321 if (tmp->vm_flags & VM_DENYWRITE)
322 atomic_dec(&inode->i_writecount);
323 mutex_lock(&mapping->i_mmap_mutex);
324 diff --git a/mm/Makefile b/mm/Makefile
325 index 8405eb0..e0bda2d 100644
328 @@ -18,7 +18,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
329 mm_init.o mmu_context.o percpu.o slab_common.o \
330 compaction.o vmacache.o \
331 interval_tree.o list_lru.o workingset.o \
332 - iov_iter.o debug.o $(mmu-y)
333 + iov_iter.o prfile.o debug.o $(mmu-y)
337 diff --git a/mm/filemap.c b/mm/filemap.c
338 index 14b4642..99bc835 100644
341 @@ -2067,7 +2067,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
342 int ret = VM_FAULT_LOCKED;
344 sb_start_pagefault(inode->i_sb);
345 - file_update_time(vma->vm_file);
346 + vma_file_update_time(vma);
348 if (page->mapping != inode->i_mapping) {
350 diff --git a/mm/fremap.c b/mm/fremap.c
351 index 72b8fa3..a00bbf0 100644
354 @@ -224,16 +224,28 @@ get_write_lock:
356 if (mapping_cap_account_dirty(mapping)) {
358 - struct file *file = get_file(vma->vm_file);
359 + struct file *file = vma->vm_file,
360 + *prfile = vma->vm_prfile;
362 /* mmap_region may free vma; grab the info now */
363 vm_flags = vma->vm_flags;
366 addr = mmap_region(file, start, size, vm_flags, pgoff);
369 if (IS_ERR_VALUE(addr)) {
372 BUG_ON(addr != start);
374 + struct vm_area_struct *new_vma;
376 + new_vma = find_vma(mm, addr);
377 + if (!new_vma->vm_prfile)
378 + new_vma->vm_prfile = prfile;
379 + if (new_vma != vma)
385 diff --git a/mm/madvise.c b/mm/madvise.c
386 index 0938b30..0b66856 100644
389 @@ -324,12 +324,12 @@ static long madvise_remove(struct vm_area_struct *vma,
390 * vma's reference to the file) can go away as soon as we drop
395 up_read(¤t->mm->mmap_sem);
396 error = vfs_fallocate(f,
397 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
398 offset, end - start);
401 down_read(¤t->mm->mmap_sem);
404 diff --git a/mm/memory.c b/mm/memory.c
405 index d5f2ae9..0830a96 100644
408 @@ -2163,7 +2163,7 @@ reuse:
409 set_page_dirty_balance(dirty_page);
410 /* file_update_time outside page_lock */
412 - file_update_time(vma->vm_file);
413 + vma_file_update_time(vma);
415 put_page(dirty_page);
417 diff --git a/mm/mmap.c b/mm/mmap.c
418 index ae91989..e3bee5c 100644
421 @@ -277,7 +277,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
422 if (vma->vm_ops && vma->vm_ops->close)
423 vma->vm_ops->close(vma);
425 - fput(vma->vm_file);
427 mpol_put(vma_policy(vma));
428 kmem_cache_free(vm_area_cachep, vma);
430 @@ -895,7 +895,7 @@ again: remove_next = 1 + (end > next->vm_end);
433 uprobe_munmap(next, next->vm_start, next->vm_end);
438 anon_vma_merge(vma, next);
439 @@ -1680,8 +1680,8 @@ out:
447 /* Undo any partial mapping done by a device driver. */
448 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
449 @@ -2477,7 +2477,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
453 - get_file(new->vm_file);
456 if (new->vm_ops && new->vm_ops->open)
457 new->vm_ops->open(new);
458 @@ -2496,7 +2496,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
459 if (new->vm_ops && new->vm_ops->close)
460 new->vm_ops->close(new);
462 - fput(new->vm_file);
464 unlink_anon_vmas(new);
466 mpol_put(vma_policy(new));
467 @@ -2886,7 +2886,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
468 if (anon_vma_clone(new_vma, vma))
469 goto out_free_mempol;
470 if (new_vma->vm_file)
471 - get_file(new_vma->vm_file);
472 + vma_get_file(new_vma);
473 if (new_vma->vm_ops && new_vma->vm_ops->open)
474 new_vma->vm_ops->open(new_vma);
475 vma_link(mm, new_vma, prev, rb_link, rb_parent);
476 diff --git a/mm/msync.c b/mm/msync.c
477 index 992a167..ce1915b 100644
480 @@ -84,13 +84,13 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
482 if ((flags & MS_SYNC) && file &&
483 (vma->vm_flags & VM_SHARED)) {
486 up_read(&mm->mmap_sem);
487 if (vma->vm_flags & VM_NONLINEAR)
488 error = vfs_fsync(file, 1);
490 error = vfs_fsync_range(file, fstart, fend, 1);
493 if (error || start >= end)
495 down_read(&mm->mmap_sem);
496 diff --git a/mm/nommu.c b/mm/nommu.c
497 index bd1808e..c9ea035 100644
500 @@ -658,7 +658,7 @@ static void __put_nommu_region(struct vm_region *region)
501 up_write(&nommu_region_sem);
504 - fput(region->vm_file);
507 /* IO memory and memory shared directly out of the pagecache
508 * from ramfs/tmpfs mustn't be released here */
509 @@ -823,7 +823,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
510 if (vma->vm_ops && vma->vm_ops->close)
511 vma->vm_ops->close(vma);
513 - fput(vma->vm_file);
515 put_nommu_region(vma->vm_region);
516 kmem_cache_free(vm_area_cachep, vma);
518 @@ -1385,7 +1385,7 @@ unsigned long do_mmap_pgoff(struct file *file,
519 goto error_just_free;
522 - fput(region->vm_file);
524 kmem_cache_free(vm_region_jar, region);
527 @@ -1461,10 +1461,10 @@ error_just_free:
528 up_write(&nommu_region_sem);
531 - fput(region->vm_file);
533 kmem_cache_free(vm_region_jar, region);
535 - fput(vma->vm_file);
537 kmem_cache_free(vm_area_cachep, vma);
538 kleave(" = %d", ret);
540 diff --git a/mm/prfile.c b/mm/prfile.c
542 index 0000000..fc708d2
547 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
548 + * in /proc/PID/maps.
549 + * Call these functions via macros defined in linux/mm.h.
551 + * See Documentation/filesystems/aufs/design/06mmap.txt
553 + * Copyright (c) 2014 Junjro R. Okajima
554 + * Copyright (c) 2014 Ian Campbell
557 +#include <linux/mm.h>
558 +#include <linux/file.h>
559 +#include <linux/fs.h>
561 +/* #define PRFILE_TRACE */
562 +static inline void prfile_trace(struct file *f, struct file *pr,
563 + const char func[], int line, const char func2[])
567 + pr_info("%s:%d: %s, %p\n", func, line, func2,
568 + f ? (char *)f->f_dentry->d_name.name : "(null)");
573 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
576 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
578 + prfile_trace(f, pr, func, line, __func__);
579 + file_update_time(f);
581 + file_update_time(pr);
584 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
587 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
589 + prfile_trace(f, pr, func, line, __func__);
590 + return (f && pr) ? pr : f;
593 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
595 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
597 + prfile_trace(f, pr, func, line, __func__);
603 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
605 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
607 + prfile_trace(f, pr, func, line, __func__);
613 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
616 + struct file *f = region->vm_file, *pr = region->vm_prfile;
618 + prfile_trace(f, pr, func, line, __func__);
619 + return (f && pr) ? pr : f;
622 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
624 + struct file *f = region->vm_file, *pr = region->vm_prfile;
626 + prfile_trace(f, pr, func, line, __func__);
631 +#endif /* CONFIG_MMU */
632 aufs3.18.1+ standalone patch
634 diff --git a/fs/dcache.c b/fs/dcache.c
635 index da7342e..b147b6c 100644
638 @@ -1124,6 +1124,7 @@ rename_retry:
642 +EXPORT_SYMBOL(d_walk);
645 * Search for at least 1 mount point in the dentry's subdirs.
646 diff --git a/fs/inode.c b/fs/inode.c
647 index df21e66..c8df03d 100644
650 @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
651 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
653 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
654 +EXPORT_SYMBOL(inode_sb_list_lock);
657 * Empty aops. Can be used for the cases where the user does not
658 @@ -1513,6 +1514,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
659 mark_inode_dirty_sync(inode);
662 +EXPORT_SYMBOL(update_time);
665 * touch_atime - update the access time
666 diff --git a/fs/namespace.c b/fs/namespace.c
667 index 5b66b2b..68ff4e4 100644
670 @@ -454,6 +454,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
671 mnt_dec_writers(real_mount(mnt));
674 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
677 * mnt_drop_write - give up write access to a mount
678 @@ -1727,6 +1728,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
682 +EXPORT_SYMBOL(iterate_mounts);
684 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
686 diff --git a/fs/notify/group.c b/fs/notify/group.c
687 index d16b62c..06ca6bc 100644
688 --- a/fs/notify/group.c
689 +++ b/fs/notify/group.c
691 #include <linux/srcu.h>
692 #include <linux/rculist.h>
693 #include <linux/wait.h>
694 +#include <linux/module.h>
696 #include <linux/fsnotify_backend.h>
697 #include "fsnotify.h"
698 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
700 atomic_inc(&group->refcnt);
702 +EXPORT_SYMBOL(fsnotify_get_group);
705 * Drop a reference to a group. Free it if it's through.
706 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
707 if (atomic_dec_and_test(&group->refcnt))
708 fsnotify_final_destroy_group(group);
710 +EXPORT_SYMBOL(fsnotify_put_group);
713 * Create a new fsnotify_group and hold a reference for the group returned.
714 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
718 +EXPORT_SYMBOL(fsnotify_alloc_group);
720 int fsnotify_fasync(int fd, struct file *file, int on)
722 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
723 index 34c38fa..d40cf58 100644
724 --- a/fs/notify/mark.c
725 +++ b/fs/notify/mark.c
726 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
727 mark->free_mark(mark);
730 +EXPORT_SYMBOL(fsnotify_put_mark);
733 * Any time a mark is getting freed we end up here.
734 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
735 fsnotify_destroy_mark_locked(mark, group);
736 mutex_unlock(&group->mark_mutex);
738 +EXPORT_SYMBOL(fsnotify_destroy_mark);
740 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
742 @@ -311,6 +313,7 @@ err:
746 +EXPORT_SYMBOL(fsnotify_add_mark);
748 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
749 struct inode *inode, struct vfsmount *mnt, int allow_dups)
750 @@ -372,6 +375,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
751 atomic_set(&mark->refcnt, 1);
752 mark->free_mark = free_mark;
754 +EXPORT_SYMBOL(fsnotify_init_mark);
756 static int fsnotify_mark_destroy(void *ignored)
758 diff --git a/fs/open.c b/fs/open.c
759 index de92c13..65d8ab0 100644
762 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
763 mutex_unlock(&dentry->d_inode->i_mutex);
766 +EXPORT_SYMBOL(do_truncate);
768 long vfs_truncate(struct path *path, loff_t length)
770 diff --git a/fs/splice.c b/fs/splice.c
771 index 619359a..c14f60e 100644
774 @@ -1127,6 +1127,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
776 return splice_write(pipe, out, ppos, len, flags);
778 +EXPORT_SYMBOL(do_splice_from);
781 * Attempt to initiate a splice from a file to a pipe.
782 @@ -1153,6 +1154,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
784 return splice_read(in, ppos, pipe, len, flags);
786 +EXPORT_SYMBOL(do_splice_to);
789 * splice_direct_to_actor - splices data directly between two non-pipes
790 diff --git a/fs/xattr.c b/fs/xattr.c
791 index 64e83ef..bd71e53 100644
794 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
795 *xattr_value = value;
798 +EXPORT_SYMBOL(vfs_getxattr_alloc);
800 /* Compare an extended attribute value with the given value */
801 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
802 diff --git a/security/commoncap.c b/security/commoncap.c
803 index bab0611..3fa2f82 100644
804 --- a/security/commoncap.c
805 +++ b/security/commoncap.c
806 @@ -979,9 +979,11 @@ int cap_mmap_addr(unsigned long addr)
810 +EXPORT_SYMBOL(cap_mmap_addr);
812 int cap_mmap_file(struct file *file, unsigned long reqprot,
813 unsigned long prot, unsigned long flags)
817 +EXPORT_SYMBOL(cap_mmap_file);
818 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
819 index 188c1d2..426d9af 100644
820 --- a/security/device_cgroup.c
821 +++ b/security/device_cgroup.c
823 #include <linux/device_cgroup.h>
824 #include <linux/cgroup.h>
825 #include <linux/ctype.h>
826 +#include <linux/export.h>
827 #include <linux/list.h>
828 #include <linux/uaccess.h>
829 #include <linux/seq_file.h>
830 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
831 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
834 +EXPORT_SYMBOL(__devcgroup_inode_permission);
836 int devcgroup_inode_mknod(int mode, dev_t dev)
838 diff --git a/security/security.c b/security/security.c
839 index 18b35c6..12c67af 100644
840 --- a/security/security.c
841 +++ b/security/security.c
842 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
844 return security_ops->path_rmdir(dir, dentry);
846 +EXPORT_SYMBOL(security_path_rmdir);
848 int security_path_unlink(struct path *dir, struct dentry *dentry)
850 @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
852 return security_ops->path_symlink(dir, dentry, old_name);
854 +EXPORT_SYMBOL(security_path_symlink);
856 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
857 struct dentry *new_dentry)
858 @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
860 return security_ops->path_link(old_dentry, new_dir, new_dentry);
862 +EXPORT_SYMBOL(security_path_link);
864 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
865 struct path *new_dir, struct dentry *new_dentry,
866 @@ -458,6 +461,7 @@ int security_path_truncate(struct path *path)
868 return security_ops->path_truncate(path);
870 +EXPORT_SYMBOL(security_path_truncate);
872 int security_path_chmod(struct path *path, umode_t mode)
874 @@ -465,6 +469,7 @@ int security_path_chmod(struct path *path, umode_t mode)
876 return security_ops->path_chmod(path, mode);
878 +EXPORT_SYMBOL(security_path_chmod);
880 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
882 @@ -472,6 +477,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
884 return security_ops->path_chown(path, uid, gid);
886 +EXPORT_SYMBOL(security_path_chown);
888 int security_path_chroot(struct path *path)
890 @@ -557,6 +563,7 @@ int security_inode_readlink(struct dentry *dentry)
892 return security_ops->inode_readlink(dentry);
894 +EXPORT_SYMBOL(security_inode_readlink);
896 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
898 @@ -571,6 +578,7 @@ int security_inode_permission(struct inode *inode, int mask)
900 return security_ops->inode_permission(inode, mask);
902 +EXPORT_SYMBOL(security_inode_permission);
904 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
906 @@ -693,6 +701,7 @@ int security_file_permission(struct file *file, int mask)
908 return fsnotify_perm(file, mask);
910 +EXPORT_SYMBOL(security_file_permission);
912 int security_file_alloc(struct file *file)
914 @@ -753,6 +762,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
916 return ima_file_mmap(file, prot);
918 +EXPORT_SYMBOL(security_mmap_file);
920 int security_mmap_addr(unsigned long addr)
922 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
923 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
924 +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-01-25 13:00:38.627713742 +0100
926 +What: /debug/aufs/si_<id>/
928 +Contact: J. R. Okajima <hooanon05g@gmail.com>
930 + Under /debug/aufs, a directory named si_<id> is created
931 + per aufs mount, where <id> is a unique id generated
934 +What: /debug/aufs/si_<id>/plink
936 +Contact: J. R. Okajima <hooanon05g@gmail.com>
938 + It has three lines and shows the information about the
939 + pseudo-link. The first line is a single number
940 + representing a number of buckets. The second line is a
941 + number of pseudo-links per buckets (separated by a
942 + blank). The last line is a single number representing a
943 + total number of psedo-links.
944 + When the aufs mount option 'noplink' is specified, it
945 + will show "1\n0\n0\n".
947 +What: /debug/aufs/si_<id>/xib
949 +Contact: J. R. Okajima <hooanon05g@gmail.com>
951 + It shows the consumed blocks by xib (External Inode Number
952 + Bitmap), its block size and file size.
953 + When the aufs mount option 'noxino' is specified, it
954 + will be empty. About XINO files, see the aufs manual.
956 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
958 +Contact: J. R. Okajima <hooanon05g@gmail.com>
960 + It shows the consumed blocks by xino (External Inode Number
961 + Translation Table), its link count, block size and file
963 + When the aufs mount option 'noxino' is specified, it
964 + will be empty. About XINO files, see the aufs manual.
966 +What: /debug/aufs/si_<id>/xigen
968 +Contact: J. R. Okajima <hooanon05g@gmail.com>
970 + It shows the consumed blocks by xigen (External Inode
971 + Generation Table), its block size and file size.
972 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
974 + When the aufs mount option 'noxino' is specified, it
975 + will be empty. About XINO files, see the aufs manual.
976 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
977 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
978 +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-01-25 13:00:38.627713742 +0100
980 +What: /sys/fs/aufs/si_<id>/
982 +Contact: J. R. Okajima <hooanon05g@gmail.com>
984 + Under /sys/fs/aufs, a directory named si_<id> is created
985 + per aufs mount, where <id> is a unique id generated
988 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
990 +Contact: J. R. Okajima <hooanon05g@gmail.com>
992 + It shows the abolute path of a member directory (which
993 + is called branch) in aufs, and its permission.
995 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
997 +Contact: J. R. Okajima <hooanon05g@gmail.com>
999 + It shows the id of a member directory (which is called
1002 +What: /sys/fs/aufs/si_<id>/xi_path
1004 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1006 + It shows the abolute path of XINO (External Inode Number
1007 + Bitmap, Translation Table and Generation Table) file
1008 + even if it is the default path.
1009 + When the aufs mount option 'noxino' is specified, it
1010 + will be empty. About XINO files, see the aufs manual.
1011 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1012 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1013 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-01-25 13:00:38.627713742 +0100
1016 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1018 +# This program is free software; you can redistribute it and/or modify
1019 +# it under the terms of the GNU General Public License as published by
1020 +# the Free Software Foundation; either version 2 of the License, or
1021 +# (at your option) any later version.
1023 +# This program is distributed in the hope that it will be useful,
1024 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1025 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1026 +# GNU General Public License for more details.
1028 +# You should have received a copy of the GNU General Public License
1029 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1032 +----------------------------------------
1034 +aufs [ei ju: ef es] | [a u f s]
1035 +1. abbrev. for "advanced multi-layered unification filesystem".
1036 +2. abbrev. for "another unionfs".
1037 +3. abbrev. for "auf das" in German which means "on the" in English.
1038 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1039 + But "Filesystem aufs Filesystem" is hard to understand.
1041 +AUFS is a filesystem with features:
1042 +- multi layered stackable unification filesystem, the member directory
1043 + is called as a branch.
1044 +- branch permission and attribute, 'readonly', 'real-readonly',
1045 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
1047 +- internal "file copy-on-write".
1048 +- logical deletion, whiteout.
1049 +- dynamic branch manipulation, adding, deleting and changing permission.
1050 +- allow bypassing aufs, user's direct branch access.
1051 +- external inode number translation table and bitmap which maintains the
1052 + persistent aufs inode number.
1053 +- seekable directory, including NFS readdir.
1054 +- file mapping, mmap and sharing pages.
1055 +- pseudo-link, hardlink over branches.
1056 +- loopback mounted filesystem as a branch.
1057 +- several policies to select one among multiple writable branches.
1058 +- revert a single systemcall when an error occurs in aufs.
1062 +Multi Layered Stackable Unification Filesystem
1063 +----------------------------------------------------------------------
1064 +Most people already knows what it is.
1065 +It is a filesystem which unifies several directories and provides a
1066 +merged single directory. When users access a file, the access will be
1067 +passed/re-directed/converted (sorry, I am not sure which English word is
1068 +correct) to the real file on the member filesystem. The member
1069 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1070 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1071 +readonly branch is handled by creating 'whiteout' on the upper writable
1074 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1075 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1076 +different approaches to implement the merged-view.
1077 +The former tries putting it into VFS, and the latter implements as a
1078 +separate filesystem.
1079 +(If I misunderstand about these implementations, please let me know and
1080 +I shall correct it. Because it is a long time ago when I read their
1081 +source files last time).
1083 +UnionMount's approach will be able to small, but may be hard to share
1084 +branches between several UnionMount since the whiteout in it is
1085 +implemented in the inode on branch filesystem and always
1086 +shared. According to Bharata's post, readdir does not seems to be
1088 +There are several missing features known in this implementations such as
1089 +- for users, the inode number may change silently. eg. copy-up.
1090 +- link(2) may break by copy-up.
1091 +- read(2) may get an obsoleted filedata (fstat(2) too).
1092 +- fcntl(F_SETLK) may be broken by copy-up.
1093 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1096 +Unionfs has a longer history. When I started implementing a stacking filesystem
1097 +(Aug 2005), it already existed. It has virtual super_block, inode,
1098 +dentry and file objects and they have an array pointing lower same kind
1099 +objects. After contributing many patches for Unionfs, I re-started my
1100 +project AUFS (Jun 2006).
1102 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1103 +implemented my own ideas, approaches and enhancements and it became
1104 +totally different one.
1106 +Comparing DM snapshot and fs based implementation
1107 +- the number of bytes to be copied between devices is much smaller.
1108 +- the type of filesystem must be one and only.
1109 +- the fs must be writable, no readonly fs, even for the lower original
1110 + device. so the compression fs will not be usable. but if we use
1111 + loopback mount, we may address this issue.
1113 + mount /cdrom/squashfs.img /sq
1114 + losetup /sq/ext2.img
1115 + losetup /somewhere/cow
1116 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1117 +- it will be difficult (or needs more operations) to extract the
1118 + difference between the original device and COW.
1119 +- DM snapshot-merge may help a lot when users try merging. in the
1120 + fs-layer union, users will use rsync(1).
1123 +Several characters/aspects of aufs
1124 +----------------------------------------------------------------------
1126 +Aufs has several characters or aspects.
1127 +1. a filesystem, callee of VFS helper
1128 +2. sub-VFS, caller of VFS helper for branches
1129 +3. a virtual filesystem which maintains persistent inode number
1130 +4. reader/writer of files on branches such like an application
1132 +1. Callee of VFS Helper
1133 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1134 +unlink(2) from an application reaches sys_unlink() kernel function and
1135 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1136 +calls filesystem specific unlink operation. Actually aufs implements the
1137 +unlink operation but it behaves like a redirector.
1139 +2. Caller of VFS Helper for Branches
1140 +aufs_unlink() passes the unlink request to the branch filesystem as if
1141 +it were called from VFS. So the called unlink operation of the branch
1142 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1143 +every necessary pre/post operation for the branch filesystem.
1144 +- acquire the lock for the parent dir on a branch
1145 +- lookup in a branch
1146 +- revalidate dentry on a branch
1147 +- mnt_want_write() for a branch
1148 +- vfs_unlink() for a branch
1149 +- mnt_drop_write() for a branch
1150 +- release the lock on a branch
1152 +3. Persistent Inode Number
1153 +One of the most important issue for a filesystem is to maintain inode
1154 +numbers. This is particularly important to support exporting a
1155 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1156 +backend block device for its own. But some storage is necessary to
1157 +maintain inode number. It may be a large space and may not suit to keep
1158 +in memory. Aufs rents some space from its first writable branch
1159 +filesystem (by default) and creates file(s) on it. These files are
1160 +created by aufs internally and removed soon (currently) keeping opened.
1161 +Note: Because these files are removed, they are totally gone after
1162 + unmounting aufs. It means the inode numbers are not persistent
1163 + across unmount or reboot. I have a plan to make them really
1164 + persistent which will be important for aufs on NFS server.
1166 +4. Read/Write Files Internally (copy-on-write)
1167 +Because a branch can be readonly, when you write a file on it, aufs will
1168 +"copy-up" it to the upper writable branch internally. And then write the
1169 +originally requested thing to the file. Generally kernel doesn't
1170 +open/read/write file actively. In aufs, even a single write may cause a
1171 +internal "file copy". This behaviour is very similar to cp(1) command.
1173 +Some people may think it is better to pass such work to user space
1174 +helper, instead of doing in kernel space. Actually I am still thinking
1175 +about it. But currently I have implemented it in kernel space.
1176 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1177 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1178 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-01-25 13:00:38.627713742 +0100
1181 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1183 +# This program is free software; you can redistribute it and/or modify
1184 +# it under the terms of the GNU General Public License as published by
1185 +# the Free Software Foundation; either version 2 of the License, or
1186 +# (at your option) any later version.
1188 +# This program is distributed in the hope that it will be useful,
1189 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1190 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1191 +# GNU General Public License for more details.
1193 +# You should have received a copy of the GNU General Public License
1194 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1196 +Basic Aufs Internal Structure
1198 +Superblock/Inode/Dentry/File Objects
1199 +----------------------------------------------------------------------
1200 +As like an ordinary filesystem, aufs has its own
1201 +superblock/inode/dentry/file objects. All these objects have a
1202 +dynamically allocated array and store the same kind of pointers to the
1203 +lower filesystem, branch.
1204 +For example, when you build a union with one readwrite branch and one
1205 +readonly, mounted /au, /rw and /ro respectively.
1207 +- /ro/fileA exists but /rw/fileA
1209 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1210 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1214 +This style of an array is essentially same to the aufs
1215 +superblock/inode/dentry/file objects.
1217 +Because aufs supports manipulating branches, ie. add/delete/change
1218 +dynamically, these objects has its own generation. When branches are
1219 +changed, the generation in aufs superblock is incremented. And a
1220 +generation in other object are compared when it is accessed.
1221 +When a generation in other objects are obsoleted, aufs refreshes the
1226 +----------------------------------------------------------------------
1227 +Additionally aufs superblock has some data for policies to select one
1228 +among multiple writable branches, XIB files, pseudo-links and kobject.
1229 +See below in detail.
1230 +About the policies which supports copy-down a directory, see policy.txt
1234 +Branch and XINO(External Inode Number Translation Table)
1235 +----------------------------------------------------------------------
1236 +Every branch has its own xino (external inode number translation table)
1237 +file. The xino file is created and unlinked by aufs internally. When two
1238 +members of a union exist on the same filesystem, they share the single
1240 +The struct of a xino file is simple, just a sequence of aufs inode
1241 +numbers which is indexed by the lower inode number.
1242 +In the above sample, assume the inode number of /ro/fileA is i111 and
1243 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1244 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1246 +When the inode numbers are not contiguous, the xino file will be sparse
1247 +which has a hole in it and doesn't consume as much disk space as it
1248 +might appear. If your branch filesystem consumes disk space for such
1249 +holes, then you should specify 'xino=' option at mounting aufs.
1251 +Also a writable branch has three kinds of "whiteout bases". All these
1252 +are existed when the branch is joined to aufs and the names are
1253 +whiteout-ed doubly, so that users will never see their names in aufs
1255 +1. a regular file which will be linked to all whiteouts.
1256 +2. a directory to store a pseudo-link.
1257 +3. a directory to store an "orphan-ed" file temporary.
1260 + When you remove a file on a readonly branch, aufs handles it as a
1261 + logical deletion and creates a whiteout on the upper writable branch
1262 + as a hardlink of this file in order not to consume inode on the
1265 + See below, Pseudo-link.
1267 + When "fileC" exists on the lower readonly branch only and it is
1268 + opened and removed with its parent dir, and then user writes
1269 + something into it, then aufs copies-up fileC to this
1270 + directory. Because there is no other dir to store fileC. After
1271 + creating a file under this dir, the file is unlinked.
1273 +Because aufs supports manipulating branches, ie. add/delete/change
1274 +dynamically, a branch has its own id. When the branch order changes, aufs
1275 +finds the new index by searching the branch id.
1279 +----------------------------------------------------------------------
1280 +Assume "fileA" exists on the lower readonly branch only and it is
1281 +hardlinked to "fileB" on the branch. When you write something to fileA,
1282 +aufs copies-up it to the upper writable branch. Additionally aufs
1283 +creates a hardlink under the Pseudo-link Directory of the writable
1284 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1285 +simple list. If fileB is read after unlinking fileA, aufs returns
1286 +filedata from the pseudo-link instead of the lower readonly
1287 +branch. Because the pseudo-link is based upon the inode, to keep the
1288 +inode number by xino (see above) is important.
1290 +All the hardlinks under the Pseudo-link Directory of the writable branch
1291 +should be restored in a proper location later. Aufs provides a utility
1292 +to do this. The userspace helpers executed at remounting and unmounting
1294 +During this utility is running, it puts aufs into the pseudo-link
1295 +maintenance mode. In this mode, only the process which began the
1296 +maintenance mode (and its child processes) is allowed to operate in
1297 +aufs. Some other processes which are not related to the pseudo-link will
1298 +be allowed to run too, but the rest have to return an error or wait
1299 +until the maintenance mode ends. If a process already acquires an inode
1300 +mutex (in VFS), it has to return an error.
1303 +XIB(external inode number bitmap)
1304 +----------------------------------------------------------------------
1305 +Addition to the xino file per a branch, aufs has an external inode number
1306 +bitmap in a superblock object. It is also a file such like a xino file.
1307 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1309 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1311 +Aufs implements a feature to truncate/refresh both of xino and xib to
1312 +reduce the number of consumed disk blocks for these files.
1315 +Virtual or Vertical Dir, and Readdir in Userspace
1316 +----------------------------------------------------------------------
1317 +In order to support multiple layers (branches), aufs readdir operation
1318 +constructs a virtual dir block on memory. For readdir, aufs calls
1319 +vfs_readdir() internally for each dir on branches, merges their entries
1320 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1321 +object. So the file object has its entry list until it is closed. The
1322 +entry list will be updated when the file position is zero and becomes
1323 +old. This decision is made in aufs automatically.
1325 +The dynamically allocated memory block for the name of entries has a
1326 +unit of 512 bytes (by default) and stores the names contiguously (no
1327 +padding). Another block for each entry is handled by kmem_cache too.
1328 +During building dir blocks, aufs creates hash list and judging whether
1329 +the entry is whiteouted by its upper branch or already listed.
1330 +The merged result is cached in the corresponding inode object and
1331 +maintained by a customizable life-time option.
1333 +Some people may call it can be a security hole or invite DoS attack
1334 +since the opened and once readdir-ed dir (file object) holds its entry
1335 +list and becomes a pressure for system memory. But I'd say it is similar
1336 +to files under /proc or /sys. The virtual files in them also holds a
1337 +memory page (generally) while they are opened. When an idea to reduce
1338 +memory for them is introduced, it will be applied to aufs too.
1339 +For those who really hate this situation, I've developed readdir(3)
1340 +library which operates this merging in userspace. You just need to set
1341 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1342 +kernel space for readdir(3).
1346 +----------------------------------------------------------------------
1347 +Aufs sometimes requires privilege access to a branch. For instance,
1348 +in copy-up/down operation. When a user process is going to make changes
1349 +to a file which exists in the lower readonly branch only, and the mode
1350 +of one of ancestor directories may not be writable by a user
1351 +process. Here aufs copy-up the file with its ancestors and they may
1352 +require privilege to set its owner/group/mode/etc.
1353 +This is a typical case of a application character of aufs (see
1356 +Aufs uses workqueue synchronously for this case. It creates its own
1357 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1358 +passes the request to call mkdir or write (for example), and wait for
1359 +its completion. This approach solves a problem of a signal handler
1361 +If aufs didn't adopt the workqueue and changed the privilege of the
1362 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
1363 +then the user process might gain a privilege or the generated core file
1364 +was owned by a superuser.
1366 +Also aufs uses the system global workqueue ("events" kernel thread) too
1367 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1368 +whiteout base and etc. This is unrelated to a privilege.
1369 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1370 +superblock at the beginning, at the same time waits for the completion
1371 +of all queued asynchronous tasks.
1375 +----------------------------------------------------------------------
1376 +The whiteout in aufs is very similar to Unionfs's. That is represented
1377 +by its filename. UnionMount takes an approach of a file mode, but I am
1378 +afraid several utilities (find(1) or something) will have to support it.
1380 +Basically the whiteout represents "logical deletion" which stops aufs to
1381 +lookup further, but also it represents "dir is opaque" which also stop
1384 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1385 +In order to make several functions in a single systemcall to be
1386 +revertible, aufs adopts an approach to rename a directory to a temporary
1387 +unique whiteouted name.
1388 +For example, in rename(2) dir where the target dir already existed, aufs
1389 +renames the target dir to a temporary unique whiteouted name before the
1390 +actual rename on a branch and then handles other actions (make it opaque,
1391 +update the attributes, etc). If an error happens in these actions, aufs
1392 +simply renames the whiteouted name back and returns an error. If all are
1393 +succeeded, aufs registers a function to remove the whiteouted unique
1394 +temporary name completely and asynchronously to the system global
1399 +----------------------------------------------------------------------
1400 +It is a well-known feature or concept.
1401 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1402 +internally and makes change to the new file on the upper writable branch.
1403 +When the trigger systemcall does not update the timestamps of the parent
1404 +dir, aufs reverts it after copy-up.
1407 +Move-down (aufs3.9 and later)
1408 +----------------------------------------------------------------------
1409 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1410 +the lower readonly branch to the upper writable branch when a user
1411 +changes something about the file.
1412 +"Move-down" is an opposite action of copy-up. Basically this action is
1413 +ran manually instead of automatically and internally.
1414 +For desgin and implementation, aufs has to consider these issues.
1415 +- whiteout for the file may exist on the lower branch.
1416 +- ancestor directories may not exist on the lower branch.
1417 +- diropq for the ancestor directories may exist on the upper branch.
1418 +- free space on the lower branch will reduce.
1419 +- another access to the file may happen during moving-down, including
1421 +- the file should not be hard-linked nor pseudo-linked. they should be
1422 + handled by auplink utility later.
1424 +Sometimes users want to move-down a file from the upper writable branch
1425 +to the lower readonly or writable branch. For instance,
1426 +- the free space of the upper writable branch is going to run out.
1427 +- create a new intermediate branch between the upper and lower branch.
1430 +For this purpose, use "aumvdown" command in aufs-util.git.
1431 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1432 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1433 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-01-25 13:00:38.627713742 +0100
1436 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1438 +# This program is free software; you can redistribute it and/or modify
1439 +# it under the terms of the GNU General Public License as published by
1440 +# the Free Software Foundation; either version 2 of the License, or
1441 +# (at your option) any later version.
1443 +# This program is distributed in the hope that it will be useful,
1444 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1445 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1446 +# GNU General Public License for more details.
1448 +# You should have received a copy of the GNU General Public License
1449 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1452 +----------------------------------------------------------------------
1453 +Since aufs has a character of sub-VFS (see Introduction), it operates
1454 +lookup for branches as VFS does. It may be a heavy work. Generally
1455 +speaking struct nameidata is a bigger structure and includes many
1456 +information. But almost all lookup operation in aufs is the simplest
1457 +case, ie. lookup only an entry directly connected to its parent. Digging
1458 +down the directory hierarchy is unnecessary.
1460 +VFS has a function lookup_one_len() for that use, but it is not usable
1461 +for a branch filesystem which requires struct nameidata. So aufs
1462 +implements a simple lookup wrapper function. When a branch filesystem
1463 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
1464 +a simplest nameidata and calls lookup_hash().
1465 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
1466 +NFS-export, then it has to support NULL as a nameidata parameter for
1467 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
1468 +aufs tests if ->s_export_op in the branch is NULL or not.
1470 +When a branch is a remote filesystem, aufs basically trusts its
1471 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1473 +For d_revalidate, aufs implements three levels of revalidate tests. See
1474 +"Revalidate Dentry and UDBA" in detail.
1477 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1478 +----------------------------------------------------------------------
1479 +Let's try case study.
1480 +- aufs has two branches, upper readwrite and lower readonly.
1482 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1483 +- user invoked "chmod a+rx /au/dirA"
1484 +- the internal copy-up is activated and "/rw/dirA" is created and its
1485 + permission bits are set to world readble.
1486 +- then "/au/dirA" becomes world readable?
1488 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1489 +or it may be a natively readonly filesystem. If aufs respects the lower
1490 +branch, it should not respond readdir request from other users. But user
1491 +allowed it by chmod. Should really aufs rejects showing the entries
1494 +To be honest, I don't have a best solution for this case. So aufs
1495 +implements 'dirperm1' and 'nodirperm1' and leave it to users.
1496 +When dirperm1 is specified, aufs checks only the highest one for the
1497 +directory permission, and shows the entries. Otherwise, as usual, checks
1498 +every dir existing on all branches and rejects the request.
1500 +As a side effect, dirperm1 option improves the performance of aufs
1501 +because the number of permission check is reduced when the number of
1506 +----------------------------------------------------------------------
1507 +Basically aufs supports any type of filesystem and block device for a
1508 +branch (actually there are some exceptions). But it is prohibited to add
1509 +a loopback mounted one whose backend file exists in a filesystem which is
1510 +already added to aufs. The reason is to protect aufs from a recursive
1511 +lookup. If it was allowed, the aufs lookup operation might re-enter a
1512 +lookup for the loopback mounted branch in the same context, and will
1516 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1517 +----------------------------------------------------------------------
1518 +Generally VFS helpers re-validate a dentry as a part of lookup.
1519 +0. digging down the directory hierarchy.
1520 +1. lock the parent dir by its i_mutex.
1521 +2. lookup the final (child) entry.
1523 +4. call the actual operation (create, unlink, etc.)
1524 +5. unlock the parent dir
1526 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1527 +called. Actually aufs implements it and checks the dentry on a branch is
1529 +But it is not enough. Because aufs has to release the lock for the
1530 +parent dir on a branch at the end of ->lookup() (step 2) and
1531 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1533 +If the file on a branch is changed directly, eg. bypassing aufs, after
1534 +aufs released the lock, then the subsequent operation may cause
1535 +something unpleasant result.
1537 +This situation is a result of VFS architecture, ->lookup() and
1538 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1539 +design from VFS's point of view. It is just not suitable for sub-VFS
1542 +Aufs supports such case by three level of revalidation which is
1543 +selectable by user.
1544 +1. Simple Revalidate
1545 + Addition to the native flow in VFS's, confirm the child-parent
1546 + relationship on the branch just after locking the parent dir on the
1547 + branch in the "actual operation" (step 4). When this validation
1548 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1549 + checks the validation of the dentry on branches.
1550 +2. Monitor Changes Internally by Inotify/Fsnotify
1551 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1552 + the dentry on the branch, and returns EBUSY if it finds different
1554 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1555 + during it is in cache. When the event is notified, aufs registers a
1556 + function to kernel 'events' thread by schedule_work(). And the
1557 + function sets some special status to the cached aufs dentry and inode
1558 + private data. If they are not cached, then aufs has nothing to
1559 + do. When the same file is accessed through aufs (step 0-3) later,
1560 + aufs will detect the status and refresh all necessary data.
1561 + In this mode, aufs has to ignore the event which is fired by aufs
1563 +3. No Extra Validation
1564 + This is the simplest test and doesn't add any additional revalidation
1565 + test, and skip therevalidatin in step 4. It is useful and improves
1566 + aufs performance when system surely hide the aufs branches from user,
1567 + by over-mounting something (or another method).
1568 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1569 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1570 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-01-25 13:00:38.627713742 +0100
1573 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1575 +# This program is free software; you can redistribute it and/or modify
1576 +# it under the terms of the GNU General Public License as published by
1577 +# the Free Software Foundation; either version 2 of the License, or
1578 +# (at your option) any later version.
1580 +# This program is distributed in the hope that it will be useful,
1581 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1582 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1583 +# GNU General Public License for more details.
1585 +# You should have received a copy of the GNU General Public License
1586 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1588 +Branch Manipulation
1590 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1591 +and changing its permission/attribute, there are a lot of works to do.
1595 +----------------------------------------------------------------------
1596 +o Confirm the adding dir exists outside of aufs, including loopback
1598 +- and other various attributes...
1599 +o Initialize the xino file and whiteout bases if necessary.
1602 +o Check the owner/group/mode of the directory
1603 + When the owner/group/mode of the adding directory differs from the
1604 + existing branch, aufs issues a warning because it may impose a
1606 + For example, when a upper writable branch has a world writable empty
1607 + top directory, a malicious user can create any files on the writable
1608 + branch directly, like copy-up and modify manually. If something like
1609 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1610 + writable branch, and the writable branch is world-writable, then a
1611 + malicious guy may create /etc/passwd on the writable branch directly
1612 + and the infected file will be valid in aufs.
1613 + I am afraid it can be a security issue, but nothing to do except
1614 + producing a warning.
1618 +----------------------------------------------------------------------
1619 +o Confirm the deleting branch is not busy
1620 + To be general, there is one merit to adopt "remount" interface to
1621 + manipulate branches. It is to discard caches. At deleting a branch,
1622 + aufs checks the still cached (and connected) dentries and inodes. If
1623 + there are any, then they are all in-use. An inode without its
1624 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1626 + For the cached one, aufs checks whether the same named entry exists on
1628 + If the cached one is a directory, because aufs provides a merged view
1629 + to users, as long as one dir is left on any branch aufs can show the
1630 + dir to users. In this case, the branch can be removed from aufs.
1631 + Otherwise aufs rejects deleting the branch.
1633 + If any file on the deleting branch is opened by aufs, then aufs
1637 +Modify the Permission of a Branch
1638 +----------------------------------------------------------------------
1639 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1642 +o rw --> ro: Confirm the modifying branch is not busy
1643 + Aufs rejects the request if any of these conditions are true.
1644 + - a file on the branch is mmap-ed.
1645 + - a regular file on the branch is opened for write and there is no
1646 + same named entry on the upper branch.
1647 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1648 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1649 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-01-25 13:00:38.627713742 +0100
1652 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1654 +# This program is free software; you can redistribute it and/or modify
1655 +# it under the terms of the GNU General Public License as published by
1656 +# the Free Software Foundation; either version 2 of the License, or
1657 +# (at your option) any later version.
1659 +# This program is distributed in the hope that it will be useful,
1660 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1661 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1662 +# GNU General Public License for more details.
1664 +# You should have received a copy of the GNU General Public License
1665 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1667 +Policies to Select One among Multiple Writable Branches
1668 +----------------------------------------------------------------------
1669 +When the number of writable branch is more than one, aufs has to decide
1670 +the target branch for file creation or copy-up. By default, the highest
1671 +writable branch which has the parent (or ancestor) dir of the target
1672 +file is chosen (top-down-parent policy).
1673 +By user's request, aufs implements some other policies to select the
1674 +writable branch, for file creation two policies, round-robin and
1675 +most-free-space policies. For copy-up three policies, top-down-parent,
1676 +bottom-up-parent and bottom-up policies.
1678 +As expected, the round-robin policy selects the branch in circular. When
1679 +you have two writable branches and creates 10 new files, 5 files will be
1680 +created for each branch. mkdir(2) systemcall is an exception. When you
1681 +create 10 new directories, all will be created on the same branch.
1682 +And the most-free-space policy selects the one which has most free
1683 +space among the writable branches. The amount of free space will be
1684 +checked by aufs internally, and users can specify its time interval.
1686 +The policies for copy-up is more simple,
1687 +top-down-parent is equivalent to the same named on in create policy,
1688 +bottom-up-parent selects the writable branch where the parent dir
1689 +exists and the nearest upper one from the copyup-source,
1690 +bottom-up selects the nearest upper writable branch from the
1691 +copyup-source, regardless the existence of the parent dir.
1693 +There are some rules or exceptions to apply these policies.
1694 +- If there is a readonly branch above the policy-selected branch and
1695 + the parent dir is marked as opaque (a variation of whiteout), or the
1696 + target (creating) file is whiteout-ed on the upper readonly branch,
1697 + then the result of the policy is ignored and the target file will be
1698 + created on the nearest upper writable branch than the readonly branch.
1699 +- If there is a writable branch above the policy-selected branch and
1700 + the parent dir is marked as opaque or the target file is whiteouted
1701 + on the branch, then the result of the policy is ignored and the target
1702 + file will be created on the highest one among the upper writable
1703 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1705 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1706 + They try selecting the branch where the source exists as possible
1707 + since copyup a large file will take long time. If it can't be,
1708 + ie. the branch where the source exists is readonly, then they will
1709 + follow the copyup policy.
1710 +- There is an exception for rename(2) when the target exists.
1711 + If the rename target exists, aufs compares the index of the branches
1712 + where the source and the target exists and selects the higher
1713 + one. If the selected branch is readonly, then aufs follows the
1715 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1716 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1717 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-01-25 13:00:38.627713742 +0100
1720 +# Copyright (C) 2011-2014 Junjiro R. Okajima
1722 +# This program is free software; you can redistribute it and/or modify
1723 +# it under the terms of the GNU General Public License as published by
1724 +# the Free Software Foundation; either version 2 of the License, or
1725 +# (at your option) any later version.
1727 +# This program is distributed in the hope that it will be useful,
1728 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1729 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1730 +# GNU General Public License for more details.
1732 +# You should have received a copy of the GNU General Public License
1733 +# along with this program; if not, write to the Free Software
1734 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1737 +File-based Hierarchical Storage Management (FHSM)
1738 +----------------------------------------------------------------------
1739 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1740 +storage world. Aufs provides this feature as file-based with multiple
1741 +writable branches, based upon the principle of "Colder-Lower".
1742 +Here the word "colder" means that the less used files, and "lower" means
1743 +that the position in the order of the stacked branches.
1744 +These multiple writable branches are prioritized, ie. the topmost one
1745 +should be the fastest drive and be used heavily.
1747 +o Characters in aufs FHSM story
1748 +- aufs itself and a new branch attribute.
1749 +- a new ioctl interface to move-down and to establish a connection with
1750 + the daemon ("move-down" is a converse of "copy-up").
1751 +- userspace tool and daemon.
1753 +The userspace daemon establishes a connection with aufs and waits for
1754 +the notification. The notified information is very similar to struct
1755 +statfs containing the number of consumed blocks and inodes.
1756 +When the consumed blocks/inodes of a branch exceeds the user-specified
1757 +upper watermark, the daemon activates its move-down process until the
1758 +consumed blocks/inodes reaches the user-specified lower watermark.
1760 +The actual move-down is done by aufs based upon the request from
1761 +user-space since we need to maintain the inode number and the internal
1762 +pointer arrays in aufs.
1764 +Currently aufs FHSM handles the regular files only. Additionally they
1765 +must not be hard-linked nor pseudo-linked.
1768 +o Cowork of aufs and the user-space daemon
1769 + During the userspace daemon established the connection, aufs sends a
1770 + small notification to it whenever aufs writes something into the
1771 + writable branch. But it may cost high since aufs issues statfs(2)
1772 + internally. So user can specify a new option to cache the
1773 + info. Actually the notification is controlled by these factors.
1774 + + the specified cache time.
1775 + + classified as "force" by aufs internally.
1776 + Until the specified time expires, aufs doesn't send the info
1777 + except the forced cases. When aufs decide forcing, the info is always
1778 + notified to userspace.
1779 + For example, the number of free inodes is generally large enough and
1780 + the shortage of it happens rarely. So aufs doesn't force the
1781 + notification when creating a new file, directory and others. This is
1782 + the typical case which aufs doesn't force.
1783 + When aufs writes the actual filedata and the files consumes any of new
1784 + blocks, the aufs forces notifying.
1787 +o Interfaces in aufs
1788 +- New branch attribute.
1790 + Specifies that the branch is managed by FHSM feature. In other word,
1791 + participant in the FHSM.
1792 + When nofhsm is set to the branch, it will not be the source/target
1793 + branch of the move-down operation. This attribute is set
1794 + independently from coo and moo attributes, and if you want full
1795 + FHSM, you should specify them as well.
1796 +- New mount option.
1798 + Specifies a second to suppress many less important info to be
1801 + + AUFS_CTL_FHSM_FD
1802 + create a new file descriptor which userspace can read the notification
1803 + (a subset of struct statfs) from aufs.
1804 +- Module parameter 'brs'
1805 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1807 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1808 + When there are two or more branches with fhsm attributes,
1809 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1810 + terminates it. As a result of remounting and branch-manipulation, the
1811 + number of branches with fhsm attribute can be one. In this case,
1812 + /sbin/mount.aufs will terminate the user-space daemon.
1815 +Finally the operation is done as these steps in kernel-space.
1817 + + no one else is using the file.
1818 + + the file is not hard-linked.
1819 + + the file is not pseudo-linked.
1820 + + the file is a regular file.
1821 + + the parent dir is not opaqued.
1822 +- find the target writable branch.
1823 +- make sure the file is not whiteout-ed by the upper (than the target)
1825 +- make the parent dir on the target branch.
1826 +- mutex lock the inode on the branch.
1827 +- unlink the whiteout on the target branch (if exists).
1828 +- lookup and create the whiteout-ed temporary name on the target branch.
1829 +- copy the file as the whiteout-ed temporary name on the target branch.
1830 +- rename the whiteout-ed temporary name to the original name.
1831 +- unlink the file on the source branch.
1832 +- maintain the internal pointer array and the external inode number
1834 +- maintain the timestamps and other attributes of the parent dir and the
1837 +And of course, in every step, an error may happen. So the operation
1838 +should restore the original file state after an error happens.
1839 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1840 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1841 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-01-25 13:00:38.627713742 +0100
1844 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1846 +# This program is free software; you can redistribute it and/or modify
1847 +# it under the terms of the GNU General Public License as published by
1848 +# the Free Software Foundation; either version 2 of the License, or
1849 +# (at your option) any later version.
1851 +# This program is distributed in the hope that it will be useful,
1852 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1853 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1854 +# GNU General Public License for more details.
1856 +# You should have received a copy of the GNU General Public License
1857 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1859 +mmap(2) -- File Memory Mapping
1860 +----------------------------------------------------------------------
1861 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1862 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1864 +This approach is simple and good, but there is one problem.
1865 +Under /proc, several entries show the mmap-ped files by its path (with
1866 +device and inode number), and the printed path will be the path on the
1867 +branch fs's instead of virtual aufs's.
1868 +This is not a problem in most cases, but some utilities lsof(1) (and its
1869 +user) may expect the path on aufs.
1871 +To address this issue, aufs adds a new member called vm_prfile in struct
1872 +vm_area_struct (and struct vm_region). The original vm_file points to
1873 +the file on the branch fs in order to handle everything correctly as
1874 +usual. The new vm_prfile points to a virtual file in aufs, and the
1875 +show-functions in procfs refers to vm_prfile if it is set.
1876 +Also we need to maintain several other places where touching vm_file
1878 +- fork()/clone() copies vma and the reference count of vm_file is
1880 +- merging vma maintains the ref count too.
1882 +This is not a good approach. It just faking the printed path. But it
1883 +leaves all behaviour around f_mapping unchanged. This is surely an
1885 +Actually aufs had adopted another complicated approach which calls
1886 +generic_file_mmap() and handles struct vm_operations_struct. In this
1887 +approach, aufs met a hard problem and I could not solve it without
1888 +switching the approach.
1889 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
1890 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
1891 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-01-25 13:00:38.627713742 +0100
1894 +# Copyright (C) 2014 Junjiro R. Okajima
1896 +# This program is free software; you can redistribute it and/or modify
1897 +# it under the terms of the GNU General Public License as published by
1898 +# the Free Software Foundation; either version 2 of the License, or
1899 +# (at your option) any later version.
1901 +# This program is distributed in the hope that it will be useful,
1902 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1903 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1904 +# GNU General Public License for more details.
1906 +# You should have received a copy of the GNU General Public License
1907 +# along with this program; if not, write to the Free Software
1908 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1911 +Listing XATTR/EA and getting the value
1912 +----------------------------------------------------------------------
1913 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
1914 +shows the values from the topmost existing file. This behaviour is good
1915 +for the non-dir entreis since the bahaviour exactly matches the shown
1916 +information. But for the directories, aufs considers all the same named
1917 +entries on the lower branches. Which means, if one of the lower entry
1918 +rejects readdir call, then aufs returns an error even if the topmost
1919 +entry allows it. This behaviour is necessary to respect the branch fs's
1920 +security, but can make users confused since the user-visible standard
1921 +attributes don't match the behaviour.
1922 +To address this issue, aufs has a mount option called dirperm1 which
1923 +checks the permission for the topmost entry only, and ignores the lower
1924 +entry's permission.
1926 +A similar issue can happen around XATTR.
1927 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
1928 +always set. Otherwise these very unpleasant situation can happen.
1929 +- listxattr(2) may return the duplicated entires.
1930 +- users may not be able to remove or reset the XATTR forever,
1933 +XATTR/EA support in the internal (copy,move)-(up,down)
1934 +----------------------------------------------------------------------
1935 +Generally the extended attributes of inode are categorazied as these.
1936 +- "security" for LSM and capability.
1937 +- "system" for posix ACL, 'acl' mount option is required for the branch
1939 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
1940 +- "user" for userspace, 'user_xattr' mount option is required for the
1941 + branch fs generally.
1943 +Moreover there are some other categories. Aufs handles these rather
1944 +unpopular categories as the ordinary ones, ie. there is no special
1945 +condition nor exception.
1947 +In copy-up, the support for XATTR on the dst branch may differ from the
1948 +src branch. In this case, the copy-up operation will get an error and
1949 +the original user operation which triggered the copy-up fails. It can
1950 +happen that even all copy-up will fail.
1951 +When both of src and dst branches support XATTR and if an error occurs
1952 +during copying XATTR, then the copy-up should fail obviously. That is a
1953 +good reason and aufs should return an error to userspace. But when only
1954 +the src branch support XATTR, aufs should not return an error.
1955 +For example, the src branch supports ACL but the dst branch doesn't
1956 +because the dst branch may natively un-support it or temporary
1957 +un-support it due to "noacl" mount option. Of course, the dst branch fs
1958 +may NOT return an error even if the XATTR is not supported. It is
1959 +totally up to the branch fs.
1961 +Anyway when the aufs internal copy-up gets an error from the dst branch
1962 +fs, then aufs tries removing the just copied entry and returns the error
1963 +to the userspace. The worst case of this situation will be all copy-up
1966 +For the copy-up operation, there two basic approaches.
1967 +- copy the specified XATTR only (by category above), and return the
1968 + error if it happens inconditionally.
1969 +- copy all XATTR, and ignore the error on the specified category only.
1971 +In order to support XATTR and to implement the correct behaviour, aufs
1972 +chooses the latter approach and introduces some attributes for its
1973 +branch, "icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
1974 +They correspond to the XATTR namespaces (see above). Additionally, to be
1975 +convenient, "icex" is also provided which means all "ix*" attributes are
1978 +The meaning of these attributes is to ignore the error from setting
1979 +XATTR on that branch.
1980 +Note that aufs tries copying all XATTR unconditionally, and ignores the
1981 +error from the dst branch according to the specified attributes.
1983 +Some XATTR may have its default value. The default value may come from
1984 +the parent dir or the environment. If the default value is set at the
1985 +file creating-time, it will be overwritten by copy-up.
1986 +Some contradiction may happen I am afraid.
1987 +Do we need another attribute to stop copying XATTR? I am unsure. For
1988 +now, aufs implements the branch attributes to ignore the error.
1989 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1990 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1991 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-01-25 13:00:38.627713742 +0100
1994 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1996 +# This program is free software; you can redistribute it and/or modify
1997 +# it under the terms of the GNU General Public License as published by
1998 +# the Free Software Foundation; either version 2 of the License, or
1999 +# (at your option) any later version.
2001 +# This program is distributed in the hope that it will be useful,
2002 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2003 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2004 +# GNU General Public License for more details.
2006 +# You should have received a copy of the GNU General Public License
2007 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2009 +Export Aufs via NFS
2010 +----------------------------------------------------------------------
2011 +Here is an approach.
2012 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2014 +- iget_locked(): initialize aufs inode generation for a new inode, and
2015 + store it in xigen file.
2016 +- destroy_inode(): increment aufs inode generation and store it in xigen
2017 + file. it is necessary even if it is not unlinked, because any data of
2018 + inode may be changed by UDBA.
2019 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2020 + build file handle by
2021 + + branch id (4 bytes)
2022 + + superblock generation (4 bytes)
2023 + + inode number (4 or 8 bytes)
2024 + + parent dir inode number (4 or 8 bytes)
2025 + + inode generation (4 bytes))
2026 + + return value of exportfs_encode_fh() for the parent on a branch (4
2028 + + file handle for a branch (by exportfs_encode_fh())
2030 + + find the index of a branch from its id in handle, and check it is
2031 + still exist in aufs.
2032 + + 1st level: get the inode number from handle and search it in cache.
2033 + + 2nd level: if not found, get the parent inode number from handle and
2034 + search it in cache. and then open the parent dir, find the matching
2035 + inode number by vfs_readdir() and get its name, and call
2036 + lookup_one_len() for the target dentry.
2037 + + 3rd level: if the parent dir is not cached, call
2038 + exportfs_decode_fh() for a branch and get the parent on a branch,
2039 + build a pathname of it, convert it a pathname in aufs, call
2040 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2042 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2043 + for every branch, but not itself. to get this, (currently) aufs
2044 + searches in current->nsproxy->mnt_ns list. it may not be a good
2045 + idea, but I didn't get other approach.
2046 + + test the generation of the gotten inode.
2047 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2048 + convert it into ESTALE for NFSD.
2049 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2050 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2051 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2052 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2053 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-01-25 13:00:38.627713742 +0100
2056 +# Copyright (C) 2005-2014 Junjiro R. Okajima
2058 +# This program is free software; you can redistribute it and/or modify
2059 +# it under the terms of the GNU General Public License as published by
2060 +# the Free Software Foundation; either version 2 of the License, or
2061 +# (at your option) any later version.
2063 +# This program is distributed in the hope that it will be useful,
2064 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2065 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2066 +# GNU General Public License for more details.
2068 +# You should have received a copy of the GNU General Public License
2069 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2071 +Show Whiteout Mode (shwh)
2072 +----------------------------------------------------------------------
2073 +Generally aufs hides the name of whiteouts. But in some cases, to show
2074 +them is very useful for users. For instance, creating a new middle layer
2075 +(branch) by merging existing layers.
2077 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2078 +When you have three branches,
2079 +- Bottom: 'system', squashfs (underlying base system), read-only
2080 +- Middle: 'mods', squashfs, read-only
2081 +- Top: 'overlay', ram (tmpfs), read-write
2083 +The top layer is loaded at boot time and saved at shutdown, to preserve
2084 +the changes made to the system during the session.
2085 +When larger changes have been made, or smaller changes have accumulated,
2086 +the size of the saved top layer data grows. At this point, it would be
2087 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2088 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2089 +restoring save and load speed.
2091 +This merging is simplified by the use of another aufs mount, of just the
2092 +two overlay branches using the 'shwh' option.
2093 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2094 + aufs /livesys/merge_union
2096 +A merged view of these two branches is then available at
2097 +/livesys/merge_union, and the new feature is that the whiteouts are
2099 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2100 +writing to all branches. Also the default mode for all branches is 'ro'.
2101 +It is now possible to save the combined contents of the two overlay
2102 +branches to a new squashfs, e.g.:
2103 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2105 +This new squashfs archive can be stored on the boot device and the
2106 +initramfs will use it to replace the old one at the next boot.
2107 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2108 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2109 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-01-25 13:00:38.627713742 +0100
2112 +# Copyright (C) 2010-2014 Junjiro R. Okajima
2114 +# This program is free software; you can redistribute it and/or modify
2115 +# it under the terms of the GNU General Public License as published by
2116 +# the Free Software Foundation; either version 2 of the License, or
2117 +# (at your option) any later version.
2119 +# This program is distributed in the hope that it will be useful,
2120 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2121 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2122 +# GNU General Public License for more details.
2124 +# You should have received a copy of the GNU General Public License
2125 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2127 +Dynamically customizable FS operations
2128 +----------------------------------------------------------------------
2129 +Generally FS operations (struct inode_operations, struct
2130 +address_space_operations, struct file_operations, etc.) are defined as
2131 +"static const", but it never means that FS have only one set of
2132 +operation. Some FS have multiple sets of them. For instance, ext2 has
2133 +three sets, one for XIP, for NOBH, and for normal.
2134 +Since aufs overrides and redirects these operations, sometimes aufs has
2135 +to change its behaviour according to the branch FS type. More imporantly
2136 +VFS acts differently if a function (member in the struct) is set or
2137 +not. It means aufs should have several sets of operations and select one
2138 +among them according to the branch FS definition.
2140 +In order to solve this problem and not to affect the behavour of VFS,
2141 +aufs defines these operations dynamically. For instance, aufs defines
2142 +aio_read function for struct file_operations, but it may not be set to
2143 +the file_operations. When the branch FS doesn't have it, aufs doesn't
2144 +set it to its file_operations while the function definition itself is
2145 +still alive. So the behaviour of io_submit(2) will not change, and it
2146 +will return an error when aio_read is not defined.
2148 +The lifetime of these dynamically generated operation object is
2149 +maintained by aufs branch object. When the branch is removed from aufs,
2150 +the reference counter of the object is decremented. When it reaches
2151 +zero, the dynamically generated operation object will be freed.
2153 +This approach is designed to support AIO (io_submit), Direcit I/O and
2155 +Currently this approach is applied to file_operations and
2156 +vm_operations_struct for regular files only.
2157 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
2158 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
2159 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2015-01-25 13:00:38.627713742 +0100
2162 +# Copyright (C) 2005-2014 Junjiro R. Okajima
2164 +# This program is free software; you can redistribute it and/or modify
2165 +# it under the terms of the GNU General Public License as published by
2166 +# the Free Software Foundation; either version 2 of the License, or
2167 +# (at your option) any later version.
2169 +# This program is distributed in the hope that it will be useful,
2170 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2171 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2172 +# GNU General Public License for more details.
2174 +# You should have received a copy of the GNU General Public License
2175 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2179 +Restoring some features which was implemented in aufs1.
2180 +They were dropped in aufs2 in order to make source files simpler and
2181 +easier to be reviewed.
2184 +Being Another Aufs's Readonly Branch (robr)
2185 +----------------------------------------------------------------------
2186 +Aufs1 allows aufs to be another aufs's readonly branch.
2187 +This feature was developed by a user's request. But it may not be used
2191 +Refresh the Opened File (refrof)
2192 +----------------------------------------------------------------------
2193 +This option is implemented in aufs1 but incomplete.
2195 +When user reads from a file, he expects to get its latest filedata
2196 +generally. If the file is removed and a new same named file is created,
2197 +the content he gets is unchanged, ie. the unlinked filedata.
2199 +Let's try case study again.
2200 +- aufs has two branches.
2202 +- "fileA" exists under /ro, but /rw.
2203 +- user opened "/au/fileA".
2204 +- he or someone else inserts a branch (/new) between /rw and /ro.
2205 + /au = /rw + /new + /ro
2206 +- the new branch has "fileA".
2207 +- user reads from the opened "fileA"
2208 +- which filedata should aufs return, from /ro or /new?
2210 +Some people says it has to be "from /ro" and it is a semantics of Unix.
2211 +The others say it should be "from /new" because the file is not removed
2212 +and it is equivalent to the case of someone else modifies the file.
2214 +Here again I don't have a best and final answer. I got an idea to
2215 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
2216 +Opened File) is specified (by default), aufs returns the filedata from
2218 +Otherwise from /new.
2219 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2220 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2221 +++ linux/Documentation/filesystems/aufs/README 2015-01-25 13:00:38.627713742 +0100
2224 +Aufs3 -- advanced multi layered unification filesystem version 3.x
2230 +----------------------------------------
2231 +In the early days, aufs was entirely re-designed and re-implemented
2232 +Unionfs Version 1.x series. After many original ideas, approaches,
2233 +improvements and implementations, it becomes totally different from
2234 +Unionfs while keeping the basic features.
2235 +Recently, Unionfs Version 2.x series begin taking some of the same
2236 +approaches to aufs1's.
2237 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2238 +University and his team.
2240 +Aufs3 supports linux-3.0 and later.
2241 +If you want older kernel version support, try aufs2-2.6.git or
2242 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2244 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2245 + According to Christoph Hellwig, linux rejects all union-type
2246 + filesystems but UnionMount.
2247 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2249 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2250 + UnionMount, and he pointed out an issue around a directory mutex
2251 + lock and aufs addressed it. But it is still unsure whether aufs will
2252 + be merged (or any other union solution).
2253 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2257 +----------------------------------------
2258 +- unite several directories into a single virtual filesystem. The member
2259 + directory is called as a branch.
2260 +- you can specify the permission flags to the branch, which are 'readonly',
2261 + 'readwrite' and 'whiteout-able.'
2262 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2263 + readonly branch are modifiable logically.
2264 +- dynamic branch manipulation, add, del.
2267 +Also there are many enhancements in aufs1, such as:
2268 +- readdir(3) in userspace.
2269 +- keep inode number by external inode number table
2270 +- keep the timestamps of file/dir in internal copyup operation
2271 +- seekable directory, supporting NFS readdir.
2272 +- whiteout is hardlinked in order to reduce the consumption of inodes
2274 +- do not copyup, nor create a whiteout when it is unnecessary
2275 +- revert a single systemcall when an error occurs in aufs
2276 +- remount interface instead of ioctl
2277 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2278 +- loopback mounted filesystem as a branch
2279 +- kernel thread for removing the dir who has a plenty of whiteouts
2280 +- support copyup sparse file (a file which has a 'hole' in it)
2281 +- default permission flags for branches
2282 +- selectable permission flags for ro branch, whether whiteout can
2285 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2286 +- support multiple writable branches, some policies to select one
2287 + among multiple writable branches.
2288 +- a new semantics for link(2) and rename(2) to support multiple
2289 + writable branches.
2290 +- no glibc changes are required.
2291 +- pseudo hardlink (hardlink over branches)
2292 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2293 + including NFS or remote filesystem branch.
2294 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2297 +Currently these features are dropped temporary from aufs3.
2298 +See design/08plan.txt in detail.
2299 +- test only the highest one for the directory permission (dirperm1)
2300 +- copyup on open (coo=)
2301 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2303 +- statistics of aufs thread (/sys/fs/aufs/stat)
2304 +- delegation mode (dlgt)
2305 + a delegation of the internal branch access to support task I/O
2306 + accounting, which also supports Linux Security Modules (LSM) mainly
2307 + for Suse AppArmor.
2308 +- intent.open/create (file open in a single lookup)
2310 +Features or just an idea in the future (see also design/*.txt),
2311 +- reorder the branch index without del/re-add.
2312 +- permanent xino files for NFSD
2313 +- an option for refreshing the opened files after add/del branches
2314 +- 'move' policy for copy-up between two writable branches, after
2315 + checking free space.
2316 +- light version, without branch manipulation. (unnecessary?)
2317 +- copyup in userspace
2318 +- inotify in userspace
2324 +----------------------------------------
2325 +There were three GIT trees for aufs3, aufs3-linux.git,
2326 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
2328 +While the aufs-util is always necessary, you need either of aufs3-linux
2329 +or aufs3-standalone.
2331 +The aufs3-linux tree includes the whole linux mainline GIT tree,
2332 +git://git.kernel.org/.../torvalds/linux.git.
2333 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2334 +build aufs3 as an external kernel module.
2336 +On the other hand, the aufs3-standalone tree has only aufs source files
2337 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2339 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
2340 +represents the linux kernel version, "linux-3.x". For instance,
2341 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
2342 +"aufs3.x-rcN" branch.
2345 +$ git clone --reference /your/linux/git/tree \
2346 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
2348 +- if you don't have linux GIT tree, then remove "--reference ..."
2349 +$ cd aufs3-linux.git
2350 +$ git checkout origin/aufs3.0
2352 +o aufs3-standalone tree
2353 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
2354 + aufs3-standalone.git
2355 +$ cd aufs3-standalone.git
2356 +$ git checkout origin/aufs3.0
2359 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
2362 +$ git checkout origin/aufs3.0
2364 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
2365 +The minor version number, 'x' in '3.x', of aufs may not always
2366 +follow the minor version number of the kernel.
2367 +Because changes in the kernel that cause the use of a new
2368 +minor version number do not always require changes to aufs-util.
2370 +Since aufs-util has its own minor version number, you may not be
2371 +able to find a GIT branch in aufs-util for your kernel's
2372 +exact minor version number.
2373 +In this case, you should git-checkout the branch for the
2374 +nearest lower number.
2376 +For (an unreleased) example:
2377 +If you are using "linux-3.10" and the "aufs3.10" branch
2378 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
2379 +or something numerically smaller is the branch for your kernel.
2381 +Also you can view all branches by
2385 +3. Configuration and Compilation
2386 +----------------------------------------
2387 +Make sure you have git-checkout'ed the correct branch.
2389 +For aufs3-linux tree,
2390 +- enable CONFIG_AUFS_FS.
2391 +- set other aufs configurations if necessary.
2393 +For aufs3-standalone tree,
2394 +There are several ways to build.
2397 +- apply ./aufs3-kbuild.patch to your kernel source files.
2398 +- apply ./aufs3-base.patch too.
2399 +- apply ./aufs3-mmap.patch too.
2400 +- apply ./aufs3-standalone.patch too, if you have a plan to set
2401 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
2402 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2403 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2404 +- enable CONFIG_AUFS_FS, you can select either
2406 +- and build your kernel as usual.
2407 +- install the built kernel.
2408 + Note: Since linux-3.9, every filesystem module requires an alias
2409 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2410 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2411 +- install the header files too by "make headers_install" to the
2412 + directory where you specify. By default, it is $PWD/usr.
2413 + "make help" shows a brief note for headers_install.
2414 +- and reboot your system.
2417 +- module only (CONFIG_AUFS_FS=m).
2418 +- apply ./aufs3-base.patch to your kernel source files.
2419 +- apply ./aufs3-mmap.patch too.
2420 +- apply ./aufs3-standalone.patch too.
2421 +- build your kernel, don't forget "make headers_install", and reboot.
2422 +- edit ./config.mk and set other aufs configurations if necessary.
2423 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2424 + every aufs configurations.
2425 +- build the module by simple "make".
2426 + Note: Since linux-3.9, every filesystem module requires an alias
2427 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2428 + modules.aliases file.
2429 +- you can specify ${KDIR} make variable which points to your kernel
2431 +- install the files
2432 + + run "make install" to install the aufs module, or copy the built
2433 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2434 + + run "make install_headers" (instead of headers_install) to install
2435 + the modified aufs header file (you can specify DESTDIR which is
2436 + available in aufs standalone version's Makefile only), or copy
2437 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2438 + you like manually. By default, the target directory is $PWD/usr.
2439 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
2440 + kernel source tree.
2442 +Note: The header file aufs_type.h is necessary to build aufs-util
2443 + as well as "make headers_install" in the kernel source tree.
2444 + headers_install is subject to be forgotten, but it is essentially
2445 + necessary, not only for building aufs-util.
2446 + You may not meet problems without headers_install in some older
2450 +- read README in aufs-util, build and install it
2451 +- note that your distribution may contain an obsoleted version of
2452 + aufs_type.h in /usr/include/linux or something. When you build aufs
2453 + utilities, make sure that your compiler refers the correct aufs header
2454 + file which is built by "make headers_install."
2455 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2456 + then run "make install_ulib" too. And refer to the aufs manual in
2459 +There several other patches in aufs3-standalone.git. They are all
2460 +optional. When you meet some problems, they will help you.
2461 +- aufs3-loopback.patch
2462 + Supports a nested loopback mount in a branch-fs. This patch is
2463 + unnecessary until aufs produces a message like "you may want to try
2464 + another patch for loopback file".
2466 + Modifies a system global kernel internal function get_next_ino() in
2467 + order to stop assigning 0 for an inode-number. Not directly related to
2468 + aufs, but recommended generally.
2470 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2471 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2472 + duplication of inode number, which is important for backup tools and
2473 + other utilities. When you find aufs XINO files for tmpfs branch
2474 + growing too much, try this patch.
2478 +----------------------------------------
2479 +At first, make sure aufs-util are installed, and please read the aufs
2480 +manual, aufs.5 in aufs-util.git tree.
2484 +$ mkdir /tmp/rw /tmp/aufs
2485 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2487 +Here is another example. The result is equivalent.
2488 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2490 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2491 +# mount -o remount,append:${HOME} /tmp/aufs
2493 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2494 +you modify a file under /tmp/aufs, the one on your home directory is
2495 +not affected, instead the same named file will be newly created under
2496 +/tmp/rw. And all of your modification to a file will be applied to
2497 +the one under /tmp/rw. This is called the file based Copy on Write
2499 +Aufs mount options are described in aufs.5.
2500 +If you run chroot or something and make your aufs as a root directory,
2501 +then you need to customize the shutdown script. See the aufs manual in
2504 +Additionally, there are some sample usages of aufs which are a
2505 +diskless system with network booting, and LiveCD over NFS.
2506 +See sample dir in CVS tree on SourceForge.
2510 +----------------------------------------
2511 +When you have any problems or strange behaviour in aufs, please let me
2513 +- /proc/mounts (instead of the output of mount(8))
2514 +- /sys/module/aufs/*
2515 +- /sys/fs/aufs/* (if you have them)
2516 +- /debug/aufs/* (if you have them)
2517 +- linux kernel version
2518 + if your kernel is not plain, for example modified by distributor,
2519 + the url where i can download its source is necessary too.
2520 +- aufs version which was printed at loading the module or booting the
2521 + system, instead of the date you downloaded.
2522 +- configuration (define/undefine CONFIG_AUFS_xxx)
2523 +- kernel configuration or /proc/config.gz (if you have it)
2524 +- behaviour which you think to be incorrect
2525 +- actual operation, reproducible one is better
2526 +- mailto: aufs-users at lists.sourceforge.net
2528 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2529 +and Feature Requests) on SourceForge. Please join and write to
2533 +6. Acknowledgements
2534 +----------------------------------------
2535 +Thanks to everyone who have tried and are using aufs, whoever
2536 +have reported a bug or any feedback.
2538 +Especially donators:
2539 +Tomas Matejicek(slax.org) made a donation (much more than once).
2540 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2541 + scripts) is making "doubling" donations.
2542 + Unfortunately I cannot list all of the donators, but I really
2544 + It ends Aug 2010, but the ordinary donation URL is still available.
2545 + <http://sourceforge.net/donate/index.php?group_id=167503>
2546 +Dai Itasaka made a donation (2007/8).
2547 +Chuck Smith made a donation (2008/4, 10 and 12).
2548 +Henk Schoneveld made a donation (2008/9).
2549 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2550 +Francois Dupoux made a donation (2008/11).
2551 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2552 + aufs2 GIT tree (2009/2).
2553 +William Grant made a donation (2009/3).
2554 +Patrick Lane made a donation (2009/4).
2555 +The Mail Archive (mail-archive.com) made donations (2009/5).
2556 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2557 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2558 +Pavel Pronskiy made a donation (2011/2).
2559 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2560 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2561 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2563 +Sam Liddicott made a donation (2011/9).
2564 +Era Scarecrow made a donation (2013/4).
2565 +Bor Ratajc made a donation (2013/4).
2566 +Alessandro Gorreta made a donation (2013/4).
2567 +POIRETTE Marc made a donation (2013/4).
2568 +Alessandro Gorreta made a donation (2013/4).
2569 +lauri kasvandik made a donation (2013/5).
2570 +"pemasu from Finland" made a donation (2013/7).
2571 +The Parted Magic Project made a donation (2013/9 and 11).
2572 +Pavel Barta made a donation (2013/10).
2573 +Nikolay Pertsev made a donation (2014/5).
2574 +James B made a donation (2014/7).
2575 +Stefano Di Biase made a donation (2014/8).
2577 +Thank you very much.
2578 +Donations are always, including future donations, very important and
2579 +helpful for me to keep on developing aufs.
2583 +----------------------------------------
2584 +If you are an experienced user, no explanation is needed. Aufs is
2585 +just a linux filesystem.
2590 +# Local variables: ;
2593 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2594 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2595 +++ linux/fs/aufs/aufs.h 2015-01-25 13:00:38.627713742 +0100
2598 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2600 + * This program, aufs is free software; you can redistribute it and/or modify
2601 + * it under the terms of the GNU General Public License as published by
2602 + * the Free Software Foundation; either version 2 of the License, or
2603 + * (at your option) any later version.
2605 + * This program is distributed in the hope that it will be useful,
2606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2608 + * GNU General Public License for more details.
2610 + * You should have received a copy of the GNU General Public License
2611 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2615 + * all header files
2623 +#define AuStub(type, name, body, ...) \
2624 + static inline type name(__VA_ARGS__) { body; }
2626 +#define AuStubVoid(name, ...) \
2627 + AuStub(void, name, , __VA_ARGS__)
2628 +#define AuStubInt0(name, ...) \
2629 + AuStub(int, name, return 0, __VA_ARGS__)
2633 +#include "branch.h"
2636 +#include "dbgaufs.h"
2637 +#include "dentry.h"
2641 +#include "fstype.h"
2644 +#include "module.h"
2649 +#include "sysaufs.h"
2654 +#endif /* __KERNEL__ */
2655 +#endif /* __AUFS_H__ */
2656 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2657 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2658 +++ linux/fs/aufs/branch.c 2015-01-25 13:00:38.627713742 +0100
2661 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2663 + * This program, aufs is free software; you can redistribute it and/or modify
2664 + * it under the terms of the GNU General Public License as published by
2665 + * the Free Software Foundation; either version 2 of the License, or
2666 + * (at your option) any later version.
2668 + * This program is distributed in the hope that it will be useful,
2669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2671 + * GNU General Public License for more details.
2673 + * You should have received a copy of the GNU General Public License
2674 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2678 + * branch management
2681 +#include <linux/compat.h>
2682 +#include <linux/statfs.h>
2686 + * free a single branch
2688 +static void au_br_do_free(struct au_branch *br)
2691 + struct au_wbr *wbr;
2692 + struct au_dykey **key;
2694 + au_hnotify_fin_br(br);
2696 + if (br->br_xino.xi_file)
2697 + fput(br->br_xino.xi_file);
2698 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2700 + AuDebugOn(atomic_read(&br->br_count));
2704 + for (i = 0; i < AuBrWh_Last; i++)
2705 + dput(wbr->wbr_wh[i]);
2706 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2707 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2710 + if (br->br_fhsm) {
2711 + au_br_fhsm_fin(br->br_fhsm);
2712 + kfree(br->br_fhsm);
2715 + key = br->br_dykey;
2716 + for (i = 0; i < AuBrDynOp; i++, key++)
2722 + /* recursive lock, s_umount of branch's */
2724 + path_put(&br->br_path);
2731 + * frees all branches
2733 +void au_br_free(struct au_sbinfo *sbinfo)
2735 + aufs_bindex_t bmax;
2736 + struct au_branch **br;
2738 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2740 + bmax = sbinfo->si_bend + 1;
2741 + br = sbinfo->si_branch;
2743 + au_br_do_free(*br++);
2747 + * find the index of a branch which is specified by @br_id.
2749 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2751 + aufs_bindex_t bindex, bend;
2753 + bend = au_sbend(sb);
2754 + for (bindex = 0; bindex <= bend; bindex++)
2755 + if (au_sbr_id(sb, bindex) == br_id)
2760 +/* ---------------------------------------------------------------------- */
2766 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2767 + struct dentry *h_root)
2769 + if (unlikely(h_adding == h_root
2770 + || au_test_loopback_overlap(sb, h_adding)))
2772 + if (h_adding->d_sb != h_root->d_sb)
2774 + return au_test_subdir(h_adding, h_root)
2775 + || au_test_subdir(h_root, h_adding);
2779 + * returns a newly allocated branch. @new_nbranch is a number of branches
2780 + * after adding a branch.
2782 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2785 + struct au_branch *add_branch;
2786 + struct dentry *root;
2790 + root = sb->s_root;
2791 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2792 + if (unlikely(!add_branch))
2795 + err = au_hnotify_init_br(add_branch, perm);
2796 + if (unlikely(err))
2799 + add_branch->br_wbr = NULL;
2800 + if (au_br_writable(perm)) {
2801 + /* may be freed separately at changing the branch permission */
2802 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2804 + if (unlikely(!add_branch->br_wbr))
2808 + add_branch->br_fhsm = NULL;
2809 + if (au_br_fhsm(perm)) {
2810 + err = au_fhsm_br_alloc(add_branch);
2811 + if (unlikely(err))
2815 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2817 + err = au_di_realloc(au_di(root), new_nbranch);
2819 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2821 + return add_branch; /* success */
2824 + kfree(add_branch->br_wbr);
2826 + au_hnotify_fin_br(add_branch);
2828 + kfree(add_branch);
2830 + return ERR_PTR(err);
2834 + * test if the branch permission is legal or not.
2836 +static int test_br(struct inode *inode, int brperm, char *path)
2840 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2845 + pr_err("write permission for readonly mount or inode, %s\n", path);
2853 + * 0: success, the caller will add it
2854 + * plus: success, it is already unified, the caller should ignore it
2857 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2860 + aufs_bindex_t bend, bindex;
2861 + struct dentry *root;
2862 + struct inode *inode, *h_inode;
2864 + root = sb->s_root;
2865 + bend = au_sbend(sb);
2866 + if (unlikely(bend >= 0
2867 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2871 + pr_err("%s duplicated\n", add->pathname);
2876 + err = -ENOSPC; /* -E2BIG; */
2877 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2878 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2879 + pr_err("number of branches exceeded %s\n", add->pathname);
2884 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2885 + pr_err("bad index %d\n", add->bindex);
2889 + inode = add->path.dentry->d_inode;
2891 + if (unlikely(!inode->i_nlink)) {
2892 + pr_err("no existence %s\n", add->pathname);
2897 + if (unlikely(inode->i_sb == sb)) {
2898 + pr_err("%s must be outside\n", add->pathname);
2902 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2903 + pr_err("unsupported filesystem, %s (%s)\n",
2904 + add->pathname, au_sbtype(inode->i_sb));
2908 + if (unlikely(inode->i_sb->s_stack_depth)) {
2909 + pr_err("already stacked, %s (%s)\n",
2910 + add->pathname, au_sbtype(inode->i_sb));
2914 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2915 + if (unlikely(err))
2919 + return 0; /* success */
2922 + for (bindex = 0; bindex <= bend; bindex++)
2923 + if (unlikely(test_overlap(sb, add->path.dentry,
2924 + au_h_dptr(root, bindex)))) {
2925 + pr_err("%s is overlapped\n", add->pathname);
2930 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2931 + h_inode = au_h_dptr(root, 0)->d_inode;
2932 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2933 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2934 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2935 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2937 + i_uid_read(inode), i_gid_read(inode),
2938 + (inode->i_mode & S_IALLUGO),
2939 + i_uid_read(h_inode), i_gid_read(h_inode),
2940 + (h_inode->i_mode & S_IALLUGO));
2948 + * initialize or clean the whiteouts for an adding branch
2950 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2953 + int err, old_perm;
2954 + aufs_bindex_t bindex;
2955 + struct mutex *h_mtx;
2956 + struct au_wbr *wbr;
2957 + struct au_hinode *hdir;
2959 + err = vfsub_mnt_want_write(au_br_mnt(br));
2960 + if (unlikely(err))
2964 + old_perm = br->br_perm;
2965 + br->br_perm = new_perm;
2968 + bindex = au_br_index(sb, br->br_id);
2969 + if (0 <= bindex) {
2970 + hdir = au_hi(sb->s_root->d_inode, bindex);
2971 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2973 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2974 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2977 + err = au_wh_init(br, sb);
2979 + wbr_wh_write_lock(wbr);
2980 + err = au_wh_init(br, sb);
2981 + wbr_wh_write_unlock(wbr);
2984 + au_hn_imtx_unlock(hdir);
2986 + mutex_unlock(h_mtx);
2987 + vfsub_mnt_drop_write(au_br_mnt(br));
2988 + br->br_perm = old_perm;
2990 + if (!err && wbr && !au_br_writable(new_perm)) {
2992 + br->br_wbr = NULL;
2999 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3003 + struct kstatfs kst;
3004 + struct au_wbr *wbr;
3007 + au_rw_init(&wbr->wbr_wh_rwsem);
3008 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
3009 + atomic_set(&wbr->wbr_wh_running, 0);
3010 + wbr->wbr_bytes = 0;
3013 + * a limit for rmdir/rename a dir
3014 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3016 + err = vfs_statfs(&br->br_path, &kst);
3017 + if (unlikely(err))
3020 + if (kst.f_namelen >= NAME_MAX)
3021 + err = au_br_init_wh(sb, br, perm);
3023 + pr_err("%pd(%s), unsupported namelen %ld\n",
3025 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3031 +/* initialize a new branch */
3032 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3033 + struct au_opt_add *add)
3038 + memset(&br->br_xino, 0, sizeof(br->br_xino));
3039 + mutex_init(&br->br_xino.xi_nondir_mtx);
3040 + br->br_perm = add->perm;
3041 + br->br_path = add->path; /* set first, path_get() later */
3042 + spin_lock_init(&br->br_dykey_lock);
3043 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
3044 + atomic_set(&br->br_count, 0);
3045 + atomic_set(&br->br_xino_running, 0);
3046 + br->br_id = au_new_br_id(sb);
3047 + AuDebugOn(br->br_id < 0);
3049 + if (au_br_writable(add->perm)) {
3050 + err = au_wbr_init(br, sb, add->perm);
3051 + if (unlikely(err))
3055 + if (au_opt_test(au_mntflags(sb), XINO)) {
3056 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
3057 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3058 + if (unlikely(err)) {
3059 + AuDebugOn(br->br_xino.xi_file);
3064 + sysaufs_br_init(br);
3065 + path_get(&br->br_path);
3066 + goto out; /* success */
3069 + memset(&br->br_path, 0, sizeof(br->br_path));
3074 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3075 + struct au_branch *br, aufs_bindex_t bend,
3076 + aufs_bindex_t amount)
3078 + struct au_branch **brp;
3080 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3082 + brp = sbinfo->si_branch + bindex;
3083 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3085 + sbinfo->si_bend++;
3086 + if (unlikely(bend < 0))
3087 + sbinfo->si_bend = 0;
3090 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3091 + aufs_bindex_t bend, aufs_bindex_t amount)
3093 + struct au_hdentry *hdp;
3095 + AuRwMustWriteLock(&dinfo->di_rwsem);
3097 + hdp = dinfo->di_hdentry + bindex;
3098 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3099 + au_h_dentry_init(hdp);
3101 + if (unlikely(bend < 0))
3102 + dinfo->di_bstart = 0;
3105 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3106 + aufs_bindex_t bend, aufs_bindex_t amount)
3108 + struct au_hinode *hip;
3110 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3112 + hip = iinfo->ii_hinode + bindex;
3113 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3114 + hip->hi_inode = NULL;
3117 + if (unlikely(bend < 0))
3118 + iinfo->ii_bstart = 0;
3121 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3122 + aufs_bindex_t bindex)
3124 + struct dentry *root, *h_dentry;
3125 + struct inode *root_inode;
3126 + aufs_bindex_t bend, amount;
3128 + root = sb->s_root;
3129 + root_inode = root->d_inode;
3130 + bend = au_sbend(sb);
3131 + amount = bend + 1 - bindex;
3132 + h_dentry = au_br_dentry(br);
3133 + au_sbilist_lock();
3134 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3135 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3136 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3137 + au_set_h_dptr(root, bindex, dget(h_dentry));
3138 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
3140 + au_sbilist_unlock();
3143 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3146 + aufs_bindex_t bend, add_bindex;
3147 + struct dentry *root, *h_dentry;
3148 + struct inode *root_inode;
3149 + struct au_branch *add_branch;
3151 + root = sb->s_root;
3152 + root_inode = root->d_inode;
3153 + IMustLock(root_inode);
3154 + err = test_add(sb, add, remount);
3155 + if (unlikely(err < 0))
3159 + goto out; /* success */
3162 + bend = au_sbend(sb);
3163 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3164 + err = PTR_ERR(add_branch);
3165 + if (IS_ERR(add_branch))
3168 + err = au_br_init(add_branch, sb, add);
3169 + if (unlikely(err)) {
3170 + au_br_do_free(add_branch);
3174 + add_bindex = add->bindex;
3176 + au_br_do_add(sb, add_branch, add_bindex);
3178 + sysaufs_brs_del(sb, add_bindex);
3179 + au_br_do_add(sb, add_branch, add_bindex);
3180 + sysaufs_brs_add(sb, add_bindex);
3183 + h_dentry = add->path.dentry;
3184 + if (!add_bindex) {
3185 + au_cpup_attr_all(root_inode, /*force*/1);
3186 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3188 + au_add_nlink(root_inode, h_dentry->d_inode);
3191 + * this test/set prevents aufs from handling unnecesary notify events
3192 + * of xino files, in case of re-adding a writable branch which was
3193 + * once detached from aufs.
3195 + if (au_xino_brid(sb) < 0
3196 + && au_br_writable(add_branch->br_perm)
3197 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3198 + && add_branch->br_xino.xi_file
3199 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
3200 + au_xino_brid_set(sb, add_branch->br_id);
3206 +/* ---------------------------------------------------------------------- */
3208 +static unsigned long long au_farray_cb(void *a,
3209 + unsigned long long max __maybe_unused,
3212 + unsigned long long n;
3213 + struct file **p, *f;
3214 + struct au_sphlhead *files;
3215 + struct au_finfo *finfo;
3216 + struct super_block *sb = arg;
3220 + files = &au_sbi(sb)->si_files;
3221 + spin_lock(&files->spin);
3222 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3223 + f = finfo->fi_file;
3225 + && !special_file(file_inode(f)->i_mode)) {
3229 + AuDebugOn(n > max);
3232 + spin_unlock(&files->spin);
3237 +static struct file **au_farray_alloc(struct super_block *sb,
3238 + unsigned long long *max)
3240 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3241 + return au_array_alloc(max, au_farray_cb, sb);
3244 +static void au_farray_free(struct file **a, unsigned long long max)
3246 + unsigned long long ull;
3248 + for (ull = 0; ull < max; ull++)
3254 +/* ---------------------------------------------------------------------- */
3260 +/* to show the line number, do not make it inlined function */
3261 +#define AuVerbose(do_info, fmt, ...) do { \
3263 + pr_info(fmt, ##__VA_ARGS__); \
3266 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3267 + aufs_bindex_t bend)
3269 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3272 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3273 + aufs_bindex_t bend)
3275 + return au_test_ibusy(dentry->d_inode, bstart, bend);
3279 + * test if the branch is deletable or not.
3281 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3282 + unsigned int sigen, const unsigned int verbose)
3284 + int err, i, j, ndentry;
3285 + aufs_bindex_t bstart, bend;
3286 + struct au_dcsub_pages dpages;
3287 + struct au_dpage *dpage;
3290 + err = au_dpages_init(&dpages, GFP_NOFS);
3291 + if (unlikely(err))
3293 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3294 + if (unlikely(err))
3297 + for (i = 0; !err && i < dpages.ndpage; i++) {
3298 + dpage = dpages.dpages + i;
3299 + ndentry = dpage->ndentry;
3300 + for (j = 0; !err && j < ndentry; j++) {
3301 + d = dpage->dentries[j];
3302 + AuDebugOn(au_dcount(d) <= 0);
3303 + if (!au_digen_test(d, sigen)) {
3304 + di_read_lock_child(d, AuLock_IR);
3305 + if (unlikely(au_dbrange_test(d))) {
3306 + di_read_unlock(d, AuLock_IR);
3310 + di_write_lock_child(d);
3311 + if (unlikely(au_dbrange_test(d))) {
3312 + di_write_unlock(d);
3315 + err = au_reval_dpath(d, sigen);
3317 + di_downgrade_lock(d, AuLock_IR);
3319 + di_write_unlock(d);
3324 + /* AuDbgDentry(d); */
3325 + bstart = au_dbstart(d);
3326 + bend = au_dbend(d);
3327 + if (bstart <= bindex
3329 + && au_h_dptr(d, bindex)
3330 + && au_test_dbusy(d, bstart, bend)) {
3332 + AuVerbose(verbose, "busy %pd\n", d);
3335 + di_read_unlock(d, AuLock_IR);
3340 + au_dpages_free(&dpages);
3345 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3346 + unsigned int sigen, const unsigned int verbose)
3349 + unsigned long long max, ull;
3350 + struct inode *i, **array;
3351 + aufs_bindex_t bstart, bend;
3353 + array = au_iarray_alloc(sb, &max);
3354 + err = PTR_ERR(array);
3355 + if (IS_ERR(array))
3359 + AuDbg("b%d\n", bindex);
3360 + for (ull = 0; !err && ull < max; ull++) {
3364 + if (i->i_ino == AUFS_ROOT_INO)
3367 + /* AuDbgInode(i); */
3368 + if (au_iigen(i, NULL) == sigen)
3369 + ii_read_lock_child(i);
3371 + ii_write_lock_child(i);
3372 + err = au_refresh_hinode_self(i);
3375 + ii_downgrade_lock(i);
3377 + ii_write_unlock(i);
3382 + bstart = au_ibstart(i);
3383 + bend = au_ibend(i);
3384 + if (bstart <= bindex
3386 + && au_h_iptr(i, bindex)
3387 + && au_test_ibusy(i, bstart, bend)) {
3389 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3392 + ii_read_unlock(i);
3394 + au_iarray_free(array, max);
3400 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3401 + const unsigned int verbose)
3404 + unsigned int sigen;
3406 + sigen = au_sigen(root->d_sb);
3407 + DiMustNoWaiters(root);
3408 + IiMustNoWaiters(root->d_inode);
3409 + di_write_unlock(root);
3410 + err = test_dentry_busy(root, bindex, sigen, verbose);
3412 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3413 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3418 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3419 + struct file **to_free, int *idx)
3422 + unsigned char matched, root;
3423 + aufs_bindex_t bindex, bend;
3424 + struct au_fidir *fidir;
3425 + struct au_hfile *hfile;
3428 + root = IS_ROOT(file->f_dentry);
3431 + to_free[*idx] = file;
3437 + fidir = au_fi(file)->fi_hdir;
3438 + AuDebugOn(!fidir);
3439 + bend = au_fbend_dir(file);
3440 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3441 + hfile = fidir->fd_hfile + bindex;
3442 + if (!hfile->hf_file)
3445 + if (hfile->hf_br->br_id == br_id) {
3457 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3458 + struct file **to_free, int opened)
3461 + unsigned long long ull, max;
3462 + aufs_bindex_t bstart;
3463 + struct file *file, **array;
3464 + struct inode *inode;
3465 + struct dentry *root;
3466 + struct au_hfile *hfile;
3468 + array = au_farray_alloc(sb, &max);
3469 + err = PTR_ERR(array);
3470 + if (IS_ERR(array))
3475 + root = sb->s_root;
3476 + di_write_unlock(root);
3477 + for (ull = 0; ull < max; ull++) {
3478 + file = array[ull];
3479 + if (unlikely(!file))
3482 + /* AuDbg("%pD\n", file); */
3483 + fi_read_lock(file);
3484 + bstart = au_fbstart(file);
3485 + inode = file_inode(file);
3486 + if (!S_ISDIR(inode->i_mode)) {
3487 + hfile = &au_fi(file)->fi_htop;
3488 + if (hfile->hf_br->br_id == br_id)
3491 + err = test_dir_busy(file, br_id, to_free, &idx);
3492 + fi_read_unlock(file);
3493 + if (unlikely(err))
3496 + di_write_lock_child(root);
3497 + au_farray_free(array, max);
3498 + AuDebugOn(idx > opened);
3504 +static void br_del_file(struct file **to_free, unsigned long long opened,
3505 + aufs_bindex_t br_id)
3507 + unsigned long long ull;
3508 + aufs_bindex_t bindex, bstart, bend, bfound;
3509 + struct file *file;
3510 + struct au_fidir *fidir;
3511 + struct au_hfile *hfile;
3513 + for (ull = 0; ull < opened; ull++) {
3514 + file = to_free[ull];
3515 + if (unlikely(!file))
3518 + /* AuDbg("%pD\n", file); */
3519 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
3521 + fidir = au_fi(file)->fi_hdir;
3522 + AuDebugOn(!fidir);
3523 + fi_write_lock(file);
3524 + bstart = au_fbstart(file);
3525 + bend = au_fbend_dir(file);
3526 + for (bindex = bstart; bindex <= bend; bindex++) {
3527 + hfile = fidir->fd_hfile + bindex;
3528 + if (!hfile->hf_file)
3531 + if (hfile->hf_br->br_id == br_id) {
3536 + AuDebugOn(bfound < 0);
3537 + au_set_h_fptr(file, bfound, NULL);
3538 + if (bfound == bstart) {
3539 + for (bstart++; bstart <= bend; bstart++)
3540 + if (au_hf_dir(file, bstart)) {
3541 + au_set_fbstart(file, bstart);
3545 + fi_write_unlock(file);
3549 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3550 + const aufs_bindex_t bindex,
3551 + const aufs_bindex_t bend)
3553 + struct au_branch **brp, **p;
3555 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3557 + brp = sbinfo->si_branch + bindex;
3558 + if (bindex < bend)
3559 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3560 + sbinfo->si_branch[0 + bend] = NULL;
3561 + sbinfo->si_bend--;
3563 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3565 + sbinfo->si_branch = p;
3566 + /* harmless error */
3569 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3570 + const aufs_bindex_t bend)
3572 + struct au_hdentry *hdp, *p;
3574 + AuRwMustWriteLock(&dinfo->di_rwsem);
3576 + hdp = dinfo->di_hdentry;
3577 + if (bindex < bend)
3578 + memmove(hdp + bindex, hdp + bindex + 1,
3579 + sizeof(*hdp) * (bend - bindex));
3580 + hdp[0 + bend].hd_dentry = NULL;
3583 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3585 + dinfo->di_hdentry = p;
3586 + /* harmless error */
3589 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3590 + const aufs_bindex_t bend)
3592 + struct au_hinode *hip, *p;
3594 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3596 + hip = iinfo->ii_hinode + bindex;
3597 + if (bindex < bend)
3598 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3599 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3600 + au_hn_init(iinfo->ii_hinode + bend);
3603 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3605 + iinfo->ii_hinode = p;
3606 + /* harmless error */
3609 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3610 + struct au_branch *br)
3612 + aufs_bindex_t bend;
3613 + struct au_sbinfo *sbinfo;
3614 + struct dentry *root, *h_root;
3615 + struct inode *inode, *h_inode;
3616 + struct au_hinode *hinode;
3618 + SiMustWriteLock(sb);
3620 + root = sb->s_root;
3621 + inode = root->d_inode;
3622 + sbinfo = au_sbi(sb);
3623 + bend = sbinfo->si_bend;
3625 + h_root = au_h_dptr(root, bindex);
3626 + hinode = au_hi(inode, bindex);
3627 + h_inode = au_igrab(hinode->hi_inode);
3630 + au_sbilist_lock();
3631 + au_br_do_del_brp(sbinfo, bindex, bend);
3632 + au_br_do_del_hdp(au_di(root), bindex, bend);
3633 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3634 + au_sbilist_unlock();
3638 + au_br_do_free(br);
3641 +static unsigned long long empty_cb(void *array, unsigned long long max,
3647 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3650 + unsigned long long opened;
3651 + unsigned int mnt_flags;
3652 + aufs_bindex_t bindex, bend, br_id;
3653 + unsigned char do_wh, verbose;
3654 + struct au_branch *br;
3655 + struct au_wbr *wbr;
3656 + struct dentry *root;
3657 + struct file **to_free;
3662 + root = sb->s_root;
3663 + bindex = au_find_dbindex(root, del->h_path.dentry);
3666 + goto out; /* success */
3668 + pr_err("%s no such branch\n", del->pathname);
3671 + AuDbg("bindex b%d\n", bindex);
3674 + mnt_flags = au_mntflags(sb);
3675 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3676 + bend = au_sbend(sb);
3677 + if (unlikely(!bend)) {
3678 + AuVerbose(verbose, "no more branches left\n");
3681 + br = au_sbr(sb, bindex);
3682 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3684 + br_id = br->br_id;
3685 + opened = atomic_read(&br->br_count);
3686 + if (unlikely(opened)) {
3687 + to_free = au_array_alloc(&opened, empty_cb, NULL);
3688 + err = PTR_ERR(to_free);
3689 + if (IS_ERR(to_free))
3692 + err = test_file_busy(sb, br_id, to_free, opened);
3693 + if (unlikely(err)) {
3694 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3700 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3702 + /* instead of WbrWhMustWriteLock(wbr) */
3703 + SiMustWriteLock(sb);
3704 + for (i = 0; i < AuBrWh_Last; i++) {
3705 + dput(wbr->wbr_wh[i]);
3706 + wbr->wbr_wh[i] = NULL;
3710 + err = test_children_busy(root, bindex, verbose);
3711 + if (unlikely(err)) {
3720 + * now we confirmed the branch is deletable.
3721 + * let's free the remaining opened dirs on the branch.
3723 + di_write_unlock(root);
3724 + br_del_file(to_free, opened, br_id);
3725 + di_write_lock_child(root);
3729 + au_br_do_del(sb, bindex, br);
3731 + sysaufs_brs_del(sb, bindex);
3732 + au_br_do_del(sb, bindex, br);
3733 + sysaufs_brs_add(sb, bindex);
3737 + au_cpup_attr_all(root->d_inode, /*force*/1);
3738 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3740 + au_sub_nlink(root->d_inode, del->h_path.dentry->d_inode);
3741 + if (au_opt_test(mnt_flags, PLINK))
3742 + au_plink_half_refresh(sb, br_id);
3744 + if (au_xino_brid(sb) == br_id)
3745 + au_xino_brid_set(sb, -1);
3746 + goto out; /* success */
3750 + rerr = au_br_init_wh(sb, br, br->br_perm);
3752 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3753 + del->pathname, rerr);
3756 + au_farray_free(to_free, opened);
3760 +/* ---------------------------------------------------------------------- */
3762 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3765 + aufs_bindex_t bstart, bend;
3766 + struct aufs_ibusy ibusy;
3767 + struct inode *inode, *h_inode;
3770 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3773 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3775 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3776 + if (unlikely(err)) {
3783 + si_read_lock(sb, AuLock_FLUSH);
3784 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3788 + ibusy.h_ino = 0; /* invalid */
3789 + inode = ilookup(sb, ibusy.ino);
3791 + || inode->i_ino == AUFS_ROOT_INO
3792 + || is_bad_inode(inode))
3795 + ii_read_lock_child(inode);
3796 + bstart = au_ibstart(inode);
3797 + bend = au_ibend(inode);
3798 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3799 + h_inode = au_h_iptr(inode, ibusy.bindex);
3800 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3801 + ibusy.h_ino = h_inode->i_ino;
3803 + ii_read_unlock(inode);
3807 + si_read_unlock(sb);
3809 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3810 + if (unlikely(err)) {
3819 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3821 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
3824 +#ifdef CONFIG_COMPAT
3825 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3827 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
3831 +/* ---------------------------------------------------------------------- */
3834 + * change a branch permission
3837 +static void au_warn_ima(void)
3840 + /* since it doesn't support mark_files_ro() */
3841 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3845 +static int do_need_sigen_inc(int a, int b)
3847 + return au_br_whable(a) && !au_br_whable(b);
3850 +static int need_sigen_inc(int old, int new)
3852 + return do_need_sigen_inc(old, new)
3853 + || do_need_sigen_inc(new, old);
3856 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3859 + unsigned int mnt_flags;
3860 + unsigned long long ull, max;
3861 + aufs_bindex_t br_id;
3862 + unsigned char verbose, writer;
3863 + struct file *file, *hf, **array;
3864 + struct inode *inode;
3865 + struct au_hfile *hfile;
3867 + mnt_flags = au_mntflags(sb);
3868 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3870 + array = au_farray_alloc(sb, &max);
3871 + err = PTR_ERR(array);
3872 + if (IS_ERR(array))
3876 + br_id = au_sbr_id(sb, bindex);
3877 + for (ull = 0; ull < max; ull++) {
3878 + file = array[ull];
3879 + if (unlikely(!file))
3882 + /* AuDbg("%pD\n", file); */
3883 + fi_read_lock(file);
3884 + if (unlikely(au_test_mmapped(file))) {
3886 + AuVerbose(verbose, "mmapped %pD\n", file);
3888 + FiMustNoWaiters(file);
3889 + fi_read_unlock(file);
3893 + inode = file_inode(file);
3894 + hfile = &au_fi(file)->fi_htop;
3895 + hf = hfile->hf_file;
3896 + if (!S_ISREG(inode->i_mode)
3897 + || !(file->f_mode & FMODE_WRITE)
3898 + || hfile->hf_br->br_id != br_id
3899 + || !(hf->f_mode & FMODE_WRITE))
3900 + array[ull] = NULL;
3906 + FiMustNoWaiters(file);
3907 + fi_read_unlock(file);
3915 + for (ull = 0; ull < max; ull++) {
3916 + file = array[ull];
3920 + /* todo: already flushed? */
3922 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
3923 + * approach which resets f_mode and calls mnt_drop_write() and
3924 + * file_release_write() for each file, because the branch
3925 + * attribute in aufs world is totally different from the native
3928 + /* fi_read_lock(file); */
3929 + hfile = &au_fi(file)->fi_htop;
3930 + hf = hfile->hf_file;
3931 + /* fi_read_unlock(file); */
3932 + spin_lock(&hf->f_lock);
3933 + writer = !!(hf->f_mode & FMODE_WRITER);
3934 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
3935 + spin_unlock(&hf->f_lock);
3937 + put_write_access(file_inode(hf));
3938 + __mnt_drop_write(hf->f_path.mnt);
3943 + au_farray_free(array, max);
3949 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3953 + aufs_bindex_t bindex;
3954 + struct dentry *root;
3955 + struct au_branch *br;
3956 + struct au_br_fhsm *bf;
3958 + root = sb->s_root;
3959 + bindex = au_find_dbindex(root, mod->h_root);
3962 + return 0; /* success */
3964 + pr_err("%s no such branch\n", mod->path);
3967 + AuDbg("bindex b%d\n", bindex);
3969 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3970 + if (unlikely(err))
3973 + br = au_sbr(sb, bindex);
3974 + AuDebugOn(mod->h_root != au_br_dentry(br));
3975 + if (br->br_perm == mod->perm)
3976 + return 0; /* success */
3978 + /* pre-allocate for non-fhsm --> fhsm */
3980 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
3981 + err = au_fhsm_br_alloc(br);
3982 + if (unlikely(err))
3985 + br->br_fhsm = NULL;
3988 + if (au_br_writable(br->br_perm)) {
3989 + /* remove whiteout base */
3990 + err = au_br_init_wh(sb, br, mod->perm);
3991 + if (unlikely(err))
3994 + if (!au_br_writable(mod->perm)) {
3995 + /* rw --> ro, file might be mmapped */
3996 + DiMustNoWaiters(root);
3997 + IiMustNoWaiters(root->d_inode);
3998 + di_write_unlock(root);
3999 + err = au_br_mod_files_ro(sb, bindex);
4000 + /* aufs_write_lock() calls ..._child() */
4001 + di_write_lock_child(root);
4003 + if (unlikely(err)) {
4005 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
4008 + rerr = au_wbr_init(br, sb, br->br_perm);
4009 + if (unlikely(rerr)) {
4010 + AuIOErr("nested error %d (%d)\n",
4012 + br->br_perm = mod->perm;
4016 + } else if (au_br_writable(mod->perm)) {
4019 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
4021 + err = au_wbr_init(br, sb, mod->perm);
4022 + if (unlikely(err)) {
4023 + kfree(br->br_wbr);
4024 + br->br_wbr = NULL;
4028 + if (unlikely(err))
4031 + if (au_br_fhsm(br->br_perm)) {
4032 + if (!au_br_fhsm(mod->perm)) {
4033 + /* fhsm --> non-fhsm */
4034 + au_br_fhsm_fin(br->br_fhsm);
4035 + kfree(br->br_fhsm);
4036 + br->br_fhsm = NULL;
4038 + } else if (au_br_fhsm(mod->perm))
4039 + /* non-fhsm --> fhsm */
4042 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4043 + br->br_perm = mod->perm;
4044 + goto out; /* success */
4053 +/* ---------------------------------------------------------------------- */
4055 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4058 + struct kstatfs kstfs;
4060 + err = vfs_statfs(&br->br_path, &kstfs);
4062 + stfs->f_blocks = kstfs.f_blocks;
4063 + stfs->f_bavail = kstfs.f_bavail;
4064 + stfs->f_files = kstfs.f_files;
4065 + stfs->f_ffree = kstfs.f_ffree;
4070 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4071 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4072 +++ linux/fs/aufs/branch.h 2015-01-25 13:00:38.627713742 +0100
4075 + * Copyright (C) 2005-2014 Junjiro R. Okajima
4077 + * This program, aufs is free software; you can redistribute it and/or modify
4078 + * it under the terms of the GNU General Public License as published by
4079 + * the Free Software Foundation; either version 2 of the License, or
4080 + * (at your option) any later version.
4082 + * This program is distributed in the hope that it will be useful,
4083 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4084 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4085 + * GNU General Public License for more details.
4087 + * You should have received a copy of the GNU General Public License
4088 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4092 + * branch filesystems and xino for them
4095 +#ifndef __AUFS_BRANCH_H__
4096 +#define __AUFS_BRANCH_H__
4100 +#include <linux/mount.h>
4105 +/* ---------------------------------------------------------------------- */
4108 +struct au_xino_file {
4109 + struct file *xi_file;
4110 + struct mutex xi_nondir_mtx;
4112 + /* todo: make xino files an array to support huge inode number */
4114 +#ifdef CONFIG_DEBUG_FS
4115 + struct dentry *xi_dbgaufs;
4119 +/* File-based Hierarchical Storage Management */
4120 +struct au_br_fhsm {
4121 +#ifdef CONFIG_AUFS_FHSM
4122 + struct mutex bf_lock;
4123 + unsigned long bf_jiffy;
4124 + struct aufs_stfs bf_stfs;
4129 +/* members for writable branch only */
4130 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4132 + struct au_rwsem wbr_wh_rwsem;
4133 + struct dentry *wbr_wh[AuBrWh_Last];
4134 + atomic_t wbr_wh_running;
4135 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4136 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4137 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4140 + unsigned long long wbr_bytes;
4143 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4144 +#define AuBrDynOp (AuDyLast * 4)
4146 +#ifdef CONFIG_AUFS_HFSNOTIFY
4147 +/* support for asynchronous destruction */
4148 +struct au_br_hfsnotify {
4149 + struct fsnotify_group *hfsn_group;
4153 +/* sysfs entries */
4154 +struct au_brsysfs {
4156 + struct attribute attr;
4165 +/* protected by superblock rwsem */
4167 + struct au_xino_file br_xino;
4169 + aufs_bindex_t br_id;
4172 + struct path br_path;
4173 + spinlock_t br_dykey_lock;
4174 + struct au_dykey *br_dykey[AuBrDynOp];
4175 + atomic_t br_count;
4177 + struct au_wbr *br_wbr;
4178 + struct au_br_fhsm *br_fhsm;
4180 + /* xino truncation */
4181 + atomic_t br_xino_running;
4183 +#ifdef CONFIG_AUFS_HFSNOTIFY
4184 + struct au_br_hfsnotify *br_hfsn;
4187 +#ifdef CONFIG_SYSFS
4188 + /* entries under sysfs per mount-point */
4189 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4193 +/* ---------------------------------------------------------------------- */
4195 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4197 + return br->br_path.mnt;
4200 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4202 + return br->br_path.dentry;
4205 +static inline struct super_block *au_br_sb(struct au_branch *br)
4207 + return au_br_mnt(br)->mnt_sb;
4210 +static inline int au_br_rdonly(struct au_branch *br)
4212 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4213 + || !au_br_writable(br->br_perm))
4217 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4219 +#ifdef CONFIG_AUFS_HNOTIFY
4220 + return !(brperm & AuBrPerm_RR);
4226 +/* ---------------------------------------------------------------------- */
4230 +void au_br_free(struct au_sbinfo *sinfo);
4231 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4233 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4235 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4236 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4237 +#ifdef CONFIG_COMPAT
4238 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4241 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4244 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4247 +static const loff_t au_loff_max = LLONG_MAX;
4249 +int au_xib_trunc(struct super_block *sb);
4250 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
4252 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
4254 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4255 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4256 +ino_t au_xino_new_ino(struct super_block *sb);
4257 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4258 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4260 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4262 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4263 + struct file *base_file, int do_test);
4264 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4266 +struct au_opt_xino;
4267 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4268 +void au_xino_clr(struct super_block *sb);
4269 +struct file *au_xino_def(struct super_block *sb);
4270 +int au_xino_path(struct seq_file *seq, struct file *file);
4272 +/* ---------------------------------------------------------------------- */
4274 +/* Superblock to branch */
4276 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4278 + return au_sbr(sb, bindex)->br_id;
4282 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4284 + return au_br_mnt(au_sbr(sb, bindex));
4288 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4290 + return au_br_sb(au_sbr(sb, bindex));
4293 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4295 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4298 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4300 + return au_sbr(sb, bindex)->br_perm;
4303 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4305 + return au_br_whable(au_sbr_perm(sb, bindex));
4308 +/* ---------------------------------------------------------------------- */
4311 + * wbr_wh_read_lock, wbr_wh_write_lock
4312 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4314 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4316 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4317 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4318 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4320 +/* ---------------------------------------------------------------------- */
4322 +#ifdef CONFIG_AUFS_FHSM
4323 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4325 + mutex_init(&brfhsm->bf_lock);
4326 + brfhsm->bf_jiffy = 0;
4327 + brfhsm->bf_readable = 0;
4330 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4332 + mutex_destroy(&brfhsm->bf_lock);
4335 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4336 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4339 +#endif /* __KERNEL__ */
4340 +#endif /* __AUFS_BRANCH_H__ */
4341 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4342 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4343 +++ linux/fs/aufs/conf.mk 2015-01-25 13:00:38.631047076 +0100
4346 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4350 +AuConfStr += ${1}=${${1}}
4354 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4356 + HNOTIFY HFSNOTIFY \
4367 +$(foreach i, ${AuConfAll}, \
4368 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4370 +AuConfName = ${obj}/conf.str
4371 +${AuConfName}.tmp: FORCE
4372 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4373 +${AuConfName}: ${AuConfName}.tmp
4374 + @diff -q $< $@ > /dev/null 2>&1 || { \
4375 + echo ' GEN ' $@; \
4379 +clean-files += ${AuConfName} ${AuConfName}.tmp
4380 +${obj}/sysfs.o: ${AuConfName}
4382 +-include ${srctree}/${src}/conf_priv.mk
4383 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4384 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4385 +++ linux/fs/aufs/cpup.c 2015-01-25 13:00:38.631047076 +0100
4388 + * Copyright (C) 2005-2014 Junjiro R. Okajima
4390 + * This program, aufs is free software; you can redistribute it and/or modify
4391 + * it under the terms of the GNU General Public License as published by
4392 + * the Free Software Foundation; either version 2 of the License, or
4393 + * (at your option) any later version.
4395 + * This program is distributed in the hope that it will be useful,
4396 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4397 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4398 + * GNU General Public License for more details.
4400 + * You should have received a copy of the GNU General Public License
4401 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4405 + * copy-up functions, see wbr_policy.c for copy-down
4408 +#include <linux/fs_stack.h>
4409 +#include <linux/mm.h>
4412 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4414 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4415 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4417 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4419 + dst->i_flags |= iflags & ~mask;
4420 + if (au_test_fs_notime(dst->i_sb))
4421 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4424 +void au_cpup_attr_timesizes(struct inode *inode)
4426 + struct inode *h_inode;
4428 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4429 + fsstack_copy_attr_times(inode, h_inode);
4430 + fsstack_copy_inode_size(inode, h_inode);
4433 +void au_cpup_attr_nlink(struct inode *inode, int force)
4435 + struct inode *h_inode;
4436 + struct super_block *sb;
4437 + aufs_bindex_t bindex, bend;
4440 + bindex = au_ibstart(inode);
4441 + h_inode = au_h_iptr(inode, bindex);
4443 + && !S_ISDIR(h_inode->i_mode)
4444 + && au_opt_test(au_mntflags(sb), PLINK)
4445 + && au_plink_test(inode))
4449 + * 0 can happen in revalidating.
4450 + * h_inode->i_mutex may not be held here, but it is harmless since once
4451 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4453 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4454 + * the incorrect link count.
4456 + set_nlink(inode, h_inode->i_nlink);
4459 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4460 + * it may includes whplink directory.
4462 + if (S_ISDIR(h_inode->i_mode)) {
4463 + bend = au_ibend(inode);
4464 + for (bindex++; bindex <= bend; bindex++) {
4465 + h_inode = au_h_iptr(inode, bindex);
4467 + au_add_nlink(inode, h_inode);
4472 +void au_cpup_attr_changeable(struct inode *inode)
4474 + struct inode *h_inode;
4476 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4477 + inode->i_mode = h_inode->i_mode;
4478 + inode->i_uid = h_inode->i_uid;
4479 + inode->i_gid = h_inode->i_gid;
4480 + au_cpup_attr_timesizes(inode);
4481 + au_cpup_attr_flags(inode, h_inode->i_flags);
4484 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4486 + struct au_iinfo *iinfo = au_ii(inode);
4488 + IiMustWriteLock(inode);
4490 + iinfo->ii_higen = h_inode->i_generation;
4491 + iinfo->ii_hsb1 = h_inode->i_sb;
4494 +void au_cpup_attr_all(struct inode *inode, int force)
4496 + struct inode *h_inode;
4498 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4499 + au_cpup_attr_changeable(inode);
4500 + if (inode->i_nlink > 0)
4501 + au_cpup_attr_nlink(inode, force);
4502 + inode->i_rdev = h_inode->i_rdev;
4503 + inode->i_blkbits = h_inode->i_blkbits;
4504 + au_cpup_igen(inode, h_inode);
4507 +/* ---------------------------------------------------------------------- */
4509 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4511 +/* keep the timestamps of the parent dir when cpup */
4512 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4513 + struct path *h_path)
4515 + struct inode *h_inode;
4517 + dt->dt_dentry = dentry;
4518 + dt->dt_h_path = *h_path;
4519 + h_inode = h_path->dentry->d_inode;
4520 + dt->dt_atime = h_inode->i_atime;
4521 + dt->dt_mtime = h_inode->i_mtime;
4525 +void au_dtime_revert(struct au_dtime *dt)
4527 + struct iattr attr;
4530 + attr.ia_atime = dt->dt_atime;
4531 + attr.ia_mtime = dt->dt_mtime;
4532 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4533 + | ATTR_ATIME | ATTR_ATIME_SET;
4535 + /* no delegation since this is a directory */
4536 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4537 + if (unlikely(err))
4538 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4541 +/* ---------------------------------------------------------------------- */
4543 +/* internal use only */
4544 +struct au_cpup_reg_attr {
4547 + unsigned int iflags; /* inode->i_flags */
4550 +static noinline_for_stack
4551 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4552 + struct au_cpup_reg_attr *h_src_attr)
4554 + int err, sbits, icex;
4556 + struct path h_path;
4557 + struct inode *h_isrc, *h_idst;
4558 + struct kstat *h_st;
4559 + struct au_branch *br;
4561 + h_path.dentry = au_h_dptr(dst, bindex);
4562 + h_idst = h_path.dentry->d_inode;
4563 + br = au_sbr(dst->d_sb, bindex);
4564 + h_path.mnt = au_br_mnt(br);
4565 + h_isrc = h_src->d_inode;
4566 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4567 + | ATTR_ATIME | ATTR_MTIME
4568 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4569 + if (h_src_attr && h_src_attr->valid) {
4570 + h_st = &h_src_attr->st;
4571 + ia.ia_uid = h_st->uid;
4572 + ia.ia_gid = h_st->gid;
4573 + ia.ia_atime = h_st->atime;
4574 + ia.ia_mtime = h_st->mtime;
4575 + if (h_idst->i_mode != h_st->mode
4576 + && !S_ISLNK(h_idst->i_mode)) {
4577 + ia.ia_valid |= ATTR_MODE;
4578 + ia.ia_mode = h_st->mode;
4580 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4581 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4583 + ia.ia_uid = h_isrc->i_uid;
4584 + ia.ia_gid = h_isrc->i_gid;
4585 + ia.ia_atime = h_isrc->i_atime;
4586 + ia.ia_mtime = h_isrc->i_mtime;
4587 + if (h_idst->i_mode != h_isrc->i_mode
4588 + && !S_ISLNK(h_idst->i_mode)) {
4589 + ia.ia_valid |= ATTR_MODE;
4590 + ia.ia_mode = h_isrc->i_mode;
4592 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4593 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4595 + /* no delegation since it is just created */
4596 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4598 + /* is this nfs only? */
4599 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4600 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4601 + ia.ia_mode = h_isrc->i_mode;
4602 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4605 + icex = br->br_perm & AuBrAttr_ICEX;
4607 + err = au_cpup_xattr(h_path.dentry, h_src, icex);
4612 +/* ---------------------------------------------------------------------- */
4614 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4615 + char *buf, unsigned long blksize)
4618 + size_t sz, rbytes, wbytes;
4619 + unsigned char all_zero;
4621 + struct mutex *h_mtx;
4622 + /* reduce stack usage */
4625 + zp = page_address(ZERO_PAGE(0));
4626 + if (unlikely(!zp))
4627 + return -ENOMEM; /* possible? */
4632 + AuDbg("len %lld\n", len);
4634 + if (len < blksize)
4638 + /* todo: signal_pending? */
4639 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4640 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4643 + if (unlikely(err < 0))
4647 + if (len >= rbytes && rbytes == blksize)
4648 + all_zero = !memcmp(buf, zp, rbytes);
4655 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4657 + /* todo: signal_pending? */
4658 + if (unlikely(err == -EAGAIN || err == -EINTR))
4660 + if (unlikely(err < 0))
4665 + if (unlikely(err < 0))
4671 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4673 + if (unlikely(res < 0))
4680 + /* the last block may be a hole */
4681 + if (!err && all_zero) {
4682 + AuLabel(last hole);
4685 + if (au_test_nfs(dst->f_dentry->d_sb)) {
4686 + /* nfs requires this step to make last hole */
4687 + /* is this only nfs? */
4689 + /* todo: signal_pending? */
4690 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4691 + } while (err == -EAGAIN || err == -EINTR);
4698 + ia->ia_size = dst->f_pos;
4699 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4700 + ia->ia_file = dst;
4701 + h_mtx = &file_inode(dst)->i_mutex;
4702 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4703 + /* no delegation since it is just created */
4704 + err = vfsub_notify_change(&dst->f_path, ia,
4705 + /*delegated*/NULL);
4706 + mutex_unlock(h_mtx);
4713 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4716 + unsigned long blksize;
4717 + unsigned char do_kfree;
4721 + blksize = dst->f_dentry->d_sb->s_blocksize;
4722 + if (!blksize || PAGE_SIZE < blksize)
4723 + blksize = PAGE_SIZE;
4724 + AuDbg("blksize %lu\n", blksize);
4725 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4727 + buf = kmalloc(blksize, GFP_NOFS);
4729 + buf = (void *)__get_free_page(GFP_NOFS);
4730 + if (unlikely(!buf))
4733 + if (len > (1 << 22))
4734 + AuDbg("copying a large file %lld\n", (long long)len);
4738 + err = au_do_copy_file(dst, src, len, buf, blksize);
4742 + free_page((unsigned long)buf);
4749 + * to support a sparse file which is opened with O_APPEND,
4750 + * we need to close the file.
4752 +static int au_cp_regular(struct au_cp_generic *cpg)
4755 + enum { SRC, DST };
4757 + aufs_bindex_t bindex;
4758 + unsigned int flags;
4759 + struct dentry *dentry;
4761 + struct file *file;
4765 + .bindex = cpg->bsrc,
4766 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4770 + .bindex = cpg->bdst,
4771 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4772 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4773 + .label = &&out_src
4776 + struct super_block *sb;
4778 + /* bsrc branch can be ro/rw. */
4779 + sb = cpg->dentry->d_sb;
4781 + for (i = 0; i < 2; i++, f++) {
4782 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4783 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4784 + /*file*/NULL, f->force_wr);
4785 + err = PTR_ERR(f->file);
4786 + if (IS_ERR(f->file))
4790 + /* try stopping to update while we copyup */
4791 + IMustLock(file[SRC].dentry->d_inode);
4792 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4794 + fput(file[DST].file);
4795 + au_sbr_put(sb, file[DST].bindex);
4798 + fput(file[SRC].file);
4799 + au_sbr_put(sb, file[SRC].bindex);
4804 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4805 + struct au_cpup_reg_attr *h_src_attr)
4809 + struct path h_path;
4810 + struct inode *h_src_inode, *h_dst_inode;
4813 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
4814 + l = i_size_read(h_src_inode);
4815 + if (cpg->len == -1 || l < cpg->len)
4818 + /* try stopping to update while we are referencing */
4819 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4820 + au_pin_hdir_unlock(cpg->pin);
4822 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4823 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4824 + h_src_attr->iflags = h_src_inode->i_flags;
4825 + err = vfs_getattr(&h_path, &h_src_attr->st);
4826 + if (unlikely(err)) {
4827 + mutex_unlock(&h_src_inode->i_mutex);
4830 + h_src_attr->valid = 1;
4831 + err = au_cp_regular(cpg);
4832 + mutex_unlock(&h_src_inode->i_mutex);
4833 + rerr = au_pin_hdir_relock(cpg->pin);
4837 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4838 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4839 + h_dst_inode = h_path.dentry->d_inode;
4840 + spin_lock(&h_dst_inode->i_lock);
4841 + h_dst_inode->i_state |= I_LINKABLE;
4842 + spin_unlock(&h_dst_inode->i_lock);
4849 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4850 + struct inode *h_dir)
4853 + mm_segment_t old_fs;
4860 + if (unlikely(!h_src->d_inode->i_op->readlink))
4864 + sym.k = (void *)__get_free_page(GFP_NOFS);
4865 + if (unlikely(!sym.k))
4868 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4869 + old_fs = get_fs();
4870 + set_fs(KERNEL_DS);
4871 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
4876 + sym.k[symlen] = 0;
4877 + err = vfsub_symlink(h_dir, h_path, sym.k);
4879 + free_page((unsigned long)sym.k);
4885 +static noinline_for_stack
4886 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
4887 + struct au_cpup_reg_attr *h_src_attr)
4891 + unsigned int mnt_flags;
4892 + unsigned char isdir, isreg, force;
4893 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
4894 + struct au_dtime dt;
4895 + struct path h_path;
4896 + struct dentry *h_src, *h_dst, *h_parent;
4897 + struct inode *h_inode, *h_dir;
4898 + struct super_block *sb;
4900 + /* bsrc branch can be ro/rw. */
4901 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4902 + h_inode = h_src->d_inode;
4903 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
4905 + /* try stopping to be referenced while we are creating */
4906 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4907 + if (au_ftest_cpup(cpg->flags, RENAME))
4908 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
4909 + AUFS_WH_PFX_LEN));
4910 + h_parent = h_dst->d_parent; /* dir inode is locked */
4911 + h_dir = h_parent->d_inode;
4913 + AuDebugOn(h_parent != h_dst->d_parent);
4915 + sb = cpg->dentry->d_sb;
4916 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4918 + h_path.dentry = h_parent;
4919 + au_dtime_store(&dt, dst_parent, &h_path);
4921 + h_path.dentry = h_dst;
4925 + mode = h_inode->i_mode;
4926 + switch (mode & S_IFMT) {
4929 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
4930 + /*want_excl*/true);
4932 + err = au_do_cpup_regular(cpg, h_src_attr);
4936 + err = vfsub_mkdir(h_dir, &h_path, mode);
4939 + * strange behaviour from the users view,
4940 + * particularry setattr case
4942 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
4943 + au_cpup_attr_nlink(dst_parent->d_inode,
4945 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
4949 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4953 + AuDebugOn(!capable(CAP_MKNOD));
4957 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4960 + AuIOErr("Unknown inode type 0%o\n", mode);
4964 + mnt_flags = au_mntflags(sb);
4965 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4967 + && au_opt_test(mnt_flags, XINO)
4968 + && (h_inode->i_nlink == 1
4969 + || (h_inode->i_state & I_LINKABLE))
4970 + /* todo: unnecessary? */
4971 + /* && cpg->dentry->d_inode->i_nlink == 1 */
4972 + && cpg->bdst < cpg->bsrc
4973 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4974 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4975 + /* ignore this error */
4980 + force = !!cpg->len;
4981 + if (cpg->len == -1)
4982 + force = !!i_size_read(h_inode);
4984 + au_fhsm_wrote(sb, cpg->bdst, force);
4988 + au_dtime_revert(&dt);
4992 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4995 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4996 + struct inode *h_dir;
4997 + aufs_bindex_t bdst;
4999 + dentry = cpg->dentry;
5001 + h_dentry = au_h_dptr(dentry, bdst);
5002 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5004 + au_set_h_dptr(dentry, bdst, NULL);
5005 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5007 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5008 + au_set_h_dptr(dentry, bdst, h_dentry);
5011 + parent = dget_parent(dentry);
5012 + h_parent = au_h_dptr(parent, bdst);
5014 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5015 + if (IS_ERR(h_path->dentry))
5016 + err = PTR_ERR(h_path->dentry);
5018 + if (unlikely(err))
5021 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5022 + h_dir = h_parent->d_inode;
5024 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5025 + /* no delegation since it is just created */
5026 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5027 + dput(h_path->dentry);
5034 + * copyup the @dentry from @bsrc to @bdst.
5035 + * the caller must set the both of lower dentries.
5036 + * @len is for truncating when it is -1 copyup the entire file.
5037 + * in link/rename cases, @dst_parent may be different from the real one.
5038 + * basic->bsrc can be larger than basic->bdst.
5040 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5043 + aufs_bindex_t old_ibstart;
5044 + unsigned char isdir, plink;
5045 + struct dentry *h_src, *h_dst, *h_parent;
5046 + struct inode *dst_inode, *h_dir, *inode, *delegated;
5047 + struct super_block *sb;
5048 + struct au_branch *br;
5049 + /* to reuduce stack size */
5051 + struct au_dtime dt;
5052 + struct path h_path;
5053 + struct au_cpup_reg_attr h_src_attr;
5057 + a = kmalloc(sizeof(*a), GFP_NOFS);
5060 + a->h_src_attr.valid = 0;
5062 + sb = cpg->dentry->d_sb;
5063 + br = au_sbr(sb, cpg->bdst);
5064 + a->h_path.mnt = au_br_mnt(br);
5065 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5066 + h_parent = h_dst->d_parent; /* dir inode is locked */
5067 + h_dir = h_parent->d_inode;
5070 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5071 + inode = cpg->dentry->d_inode;
5074 + dst_parent = dget_parent(cpg->dentry);
5078 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5079 + dst_inode = au_h_iptr(inode, cpg->bdst);
5081 + if (unlikely(!plink)) {
5083 + AuIOErr("hi%lu(i%lu) exists on b%d "
5084 + "but plink is disabled\n",
5085 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5089 + if (dst_inode->i_nlink) {
5090 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5092 + h_src = au_plink_lkup(inode, cpg->bdst);
5093 + err = PTR_ERR(h_src);
5094 + if (IS_ERR(h_src))
5096 + if (unlikely(!h_src->d_inode)) {
5098 + AuIOErr("i%lu exists on a upper branch "
5099 + "but not pseudo-linked\n",
5106 + a->h_path.dentry = h_parent;
5107 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5110 + a->h_path.dentry = h_dst;
5112 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5113 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5114 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5116 + au_dtime_revert(&a->dt);
5117 + if (unlikely(err == -EWOULDBLOCK)) {
5118 + pr_warn("cannot retry for NFSv4 delegation"
5119 + " for an internal link\n");
5125 + /* todo: cpup_wh_file? */
5127 + au_update_ibrange(inode, /*do_put_zero*/1);
5130 + isdir = S_ISDIR(inode->i_mode);
5131 + old_ibstart = au_ibstart(inode);
5132 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5133 + if (unlikely(err))
5135 + dst_inode = h_dst->d_inode;
5136 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
5137 + /* todo: necessary? */
5138 + /* au_pin_hdir_unlock(cpg->pin); */
5140 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5141 + if (unlikely(err)) {
5142 + /* todo: necessary? */
5143 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5144 + mutex_unlock(&dst_inode->i_mutex);
5148 + if (cpg->bdst < old_ibstart) {
5149 + if (S_ISREG(inode->i_mode)) {
5150 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5151 + if (unlikely(err)) {
5152 + /* ignore an error */
5153 + /* au_pin_hdir_relock(cpg->pin); */
5154 + mutex_unlock(&dst_inode->i_mutex);
5158 + au_set_ibstart(inode, cpg->bdst);
5160 + au_set_ibend(inode, cpg->bdst);
5161 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5162 + au_hi_flags(inode, isdir));
5164 + /* todo: necessary? */
5165 + /* err = au_pin_hdir_relock(cpg->pin); */
5166 + mutex_unlock(&dst_inode->i_mutex);
5167 + if (unlikely(err))
5171 + && (h_src->d_inode->i_nlink > 1
5172 + || h_src->d_inode->i_state & I_LINKABLE)
5174 + au_plink_append(inode, cpg->bdst, h_dst);
5176 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5177 + a->h_path.dentry = h_dst;
5178 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5181 + goto out_parent; /* success */
5185 + a->h_path.dentry = h_parent;
5186 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5187 + a->h_path.dentry = h_dst;
5189 + if (h_dst->d_inode) {
5191 + /* no delegation since it is just created */
5192 + rerr = vfsub_unlink(h_dir, &a->h_path,
5193 + /*delegated*/NULL, /*force*/0);
5195 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5197 + au_dtime_revert(&a->dt);
5199 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5210 +struct au_cpup_single_args {
5212 + struct au_cp_generic *cpg;
5213 + struct dentry *dst_parent;
5216 +static void au_call_cpup_single(void *args)
5218 + struct au_cpup_single_args *a = args;
5220 + au_pin_hdir_acquire_nest(a->cpg->pin);
5221 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5222 + au_pin_hdir_release(a->cpg->pin);
5227 + * prevent SIGXFSZ in copy-up.
5228 + * testing CAP_MKNOD is for generic fs,
5229 + * but CAP_FSETID is for xfs only, currently.
5231 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5234 + struct super_block *sb;
5235 + struct inode *h_dir;
5238 + sb = au_pinned_parent(pin)->d_sb;
5239 + if (!au_wkq_test()
5240 + && (!au_sbi(sb)->si_plink_maint_pid
5241 + || au_plink_maint(sb, AuLock_NOPLM))) {
5242 + switch (mode & S_IFMT) {
5244 + /* no condition about RLIMIT_FSIZE and the file size */
5249 + do_sio = !capable(CAP_MKNOD);
5253 + do_sio = ((mode & (S_ISUID | S_ISGID))
5254 + && !capable(CAP_FSETID));
5255 + /* this workaround may be removed in the future */
5257 + h_dir = au_pinned_h_dir(pin);
5258 + do_sio = h_dir->i_mode & S_ISVTX;
5266 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5269 + struct dentry *h_dentry;
5271 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5272 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
5273 + err = au_cpup_single(cpg, dst_parent);
5275 + struct au_cpup_single_args args = {
5278 + .dst_parent = dst_parent
5280 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5281 + if (unlikely(wkq_err))
5290 + * copyup the @dentry from the first active lower branch to @bdst,
5291 + * using au_cpup_single().
5293 +static int au_cpup_simple(struct au_cp_generic *cpg)
5296 + unsigned int flags_orig;
5297 + struct dentry *dentry;
5299 + AuDebugOn(cpg->bsrc < 0);
5301 + dentry = cpg->dentry;
5302 + DiMustWriteLock(dentry);
5304 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5306 + flags_orig = cpg->flags;
5307 + au_fset_cpup(cpg->flags, RENAME);
5308 + err = au_cpup_single(cpg, NULL);
5309 + cpg->flags = flags_orig;
5311 + return 0; /* success */
5314 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5315 + au_set_dbstart(dentry, cpg->bsrc);
5321 +struct au_cpup_simple_args {
5323 + struct au_cp_generic *cpg;
5326 +static void au_call_cpup_simple(void *args)
5328 + struct au_cpup_simple_args *a = args;
5330 + au_pin_hdir_acquire_nest(a->cpg->pin);
5331 + *a->errp = au_cpup_simple(a->cpg);
5332 + au_pin_hdir_release(a->cpg->pin);
5335 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5338 + struct dentry *dentry, *parent;
5339 + struct file *h_file;
5340 + struct inode *h_dir;
5342 + dentry = cpg->dentry;
5344 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5345 + AuDebugOn(cpg->bsrc < 0);
5346 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5347 + err = PTR_ERR(h_file);
5348 + if (IS_ERR(h_file))
5352 + parent = dget_parent(dentry);
5353 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
5354 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5355 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5356 + err = au_cpup_simple(cpg);
5358 + struct au_cpup_simple_args args = {
5362 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5363 + if (unlikely(wkq_err))
5369 + au_h_open_post(dentry, cpg->bsrc, h_file);
5375 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5377 + aufs_bindex_t bsrc, bend;
5378 + struct dentry *dentry, *h_dentry;
5380 + if (cpg->bsrc < 0) {
5381 + dentry = cpg->dentry;
5382 + bend = au_dbend(dentry);
5383 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5384 + h_dentry = au_h_dptr(dentry, bsrc);
5386 + AuDebugOn(!h_dentry->d_inode);
5390 + AuDebugOn(bsrc > bend);
5393 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5394 + return au_do_sio_cpup_simple(cpg);
5397 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5399 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5400 + return au_do_sio_cpup_simple(cpg);
5403 +/* ---------------------------------------------------------------------- */
5406 + * copyup the deleted file for writing.
5408 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5409 + struct file *file)
5412 + unsigned int flags_orig;
5413 + aufs_bindex_t bsrc_orig;
5414 + struct dentry *h_d_dst, *h_d_start;
5415 + struct au_dinfo *dinfo;
5416 + struct au_hdentry *hdp;
5418 + dinfo = au_di(cpg->dentry);
5419 + AuRwMustWriteLock(&dinfo->di_rwsem);
5421 + bsrc_orig = cpg->bsrc;
5422 + cpg->bsrc = dinfo->di_bstart;
5423 + hdp = dinfo->di_hdentry;
5424 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5425 + dinfo->di_bstart = cpg->bdst;
5426 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5429 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5430 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
5432 + flags_orig = cpg->flags;
5433 + cpg->flags = !AuCpup_DTIME;
5434 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5435 + cpg->flags = flags_orig;
5438 + err = au_reopen_nondir(file);
5439 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5441 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5442 + dinfo->di_bstart = cpg->bsrc;
5443 + cpg->bsrc = bsrc_orig;
5448 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5451 + aufs_bindex_t bdst;
5452 + struct au_dtime dt;
5453 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5454 + struct au_branch *br;
5455 + struct path h_path;
5457 + dentry = cpg->dentry;
5459 + br = au_sbr(dentry->d_sb, bdst);
5460 + parent = dget_parent(dentry);
5461 + h_parent = au_h_dptr(parent, bdst);
5462 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5463 + err = PTR_ERR(wh_dentry);
5464 + if (IS_ERR(wh_dentry))
5467 + h_path.dentry = h_parent;
5468 + h_path.mnt = au_br_mnt(br);
5469 + au_dtime_store(&dt, parent, &h_path);
5470 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5471 + if (unlikely(err))
5475 + h_path.dentry = wh_dentry;
5476 + if (!S_ISDIR(wh_dentry->d_inode->i_mode)) {
5477 + /* no delegation since it is just created */
5478 + err = vfsub_unlink(h_parent->d_inode, &h_path,
5479 + /*delegated*/NULL, /*force*/0);
5481 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
5482 + if (unlikely(err)) {
5483 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5487 + au_dtime_revert(&dt);
5488 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
5497 +struct au_cpup_wh_args {
5499 + struct au_cp_generic *cpg;
5500 + struct file *file;
5503 +static void au_call_cpup_wh(void *args)
5505 + struct au_cpup_wh_args *a = args;
5507 + au_pin_hdir_acquire_nest(a->cpg->pin);
5508 + *a->errp = au_cpup_wh(a->cpg, a->file);
5509 + au_pin_hdir_release(a->cpg->pin);
5512 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5515 + aufs_bindex_t bdst;
5516 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5517 + struct inode *dir, *h_dir, *h_tmpdir;
5518 + struct au_wbr *wbr;
5519 + struct au_pin wh_pin, *pin_orig;
5521 + dentry = cpg->dentry;
5523 + parent = dget_parent(dentry);
5524 + dir = parent->d_inode;
5527 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5530 + if (!h_dir->i_nlink) {
5531 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5532 + h_orph = wbr->wbr_orph;
5534 + h_parent = dget(au_h_dptr(parent, bdst));
5535 + au_set_h_dptr(parent, bdst, dget(h_orph));
5536 + h_tmpdir = h_orph->d_inode;
5537 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5539 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5540 + /* todo: au_h_open_pre()? */
5542 + pin_orig = cpg->pin;
5543 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5544 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5545 + cpg->pin = &wh_pin;
5548 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5549 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5550 + err = au_cpup_wh(cpg, file);
5552 + struct au_cpup_wh_args args = {
5557 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5558 + if (unlikely(wkq_err))
5563 + mutex_unlock(&h_tmpdir->i_mutex);
5564 + /* todo: au_h_open_post()? */
5565 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5566 + au_set_h_dptr(parent, bdst, h_parent);
5567 + AuDebugOn(!pin_orig);
5568 + cpg->pin = pin_orig;
5576 +/* ---------------------------------------------------------------------- */
5579 + * generic routine for both of copy-up and copy-down.
5581 +/* cf. revalidate function in file.c */
5582 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5583 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5584 + struct au_pin *pin,
5585 + struct dentry *h_parent, void *arg),
5589 + struct au_pin pin;
5590 + struct dentry *d, *parent, *h_parent, *real_parent;
5593 + parent = dget_parent(dentry);
5594 + if (IS_ROOT(parent))
5597 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5598 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5600 + /* do not use au_dpage */
5601 + real_parent = parent;
5604 + parent = dget_parent(dentry);
5605 + h_parent = au_h_dptr(parent, bdst);
5607 + goto out; /* success */
5609 + /* find top dir which is necessary to cpup */
5613 + parent = dget_parent(d);
5614 + di_read_lock_parent3(parent, !AuLock_IR);
5615 + h_parent = au_h_dptr(parent, bdst);
5616 + di_read_unlock(parent, !AuLock_IR);
5617 + } while (!h_parent);
5619 + if (d != real_parent)
5620 + di_write_lock_child3(d);
5622 + /* somebody else might create while we were sleeping */
5623 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
5624 + if (au_h_dptr(d, bdst))
5625 + au_update_dbstart(d);
5627 + au_pin_set_dentry(&pin, d);
5628 + err = au_do_pin(&pin);
5630 + err = cp(d, bdst, &pin, h_parent, arg);
5635 + if (d != real_parent)
5636 + di_write_unlock(d);
5637 + if (unlikely(err))
5646 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5647 + struct au_pin *pin,
5648 + struct dentry *h_parent __maybe_unused ,
5649 + void *arg __maybe_unused)
5651 + struct au_cp_generic cpg = {
5657 + .flags = AuCpup_DTIME
5659 + return au_sio_cpup_simple(&cpg);
5662 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5664 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5667 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5670 + struct dentry *parent;
5671 + struct inode *dir;
5673 + parent = dget_parent(dentry);
5674 + dir = parent->d_inode;
5676 + if (au_h_iptr(dir, bdst))
5679 + di_read_unlock(parent, AuLock_IR);
5680 + di_write_lock_parent(parent);
5681 + /* someone else might change our inode while we were sleeping */
5682 + if (!au_h_iptr(dir, bdst))
5683 + err = au_cpup_dirs(dentry, bdst);
5684 + di_downgrade_lock(parent, AuLock_IR);
5690 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5691 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5692 +++ linux/fs/aufs/cpup.h 2015-01-25 13:00:38.631047076 +0100
5695 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5697 + * This program, aufs is free software; you can redistribute it and/or modify
5698 + * it under the terms of the GNU General Public License as published by
5699 + * the Free Software Foundation; either version 2 of the License, or
5700 + * (at your option) any later version.
5702 + * This program is distributed in the hope that it will be useful,
5703 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5704 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5705 + * GNU General Public License for more details.
5707 + * You should have received a copy of the GNU General Public License
5708 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5712 + * copy-up/down functions
5715 +#ifndef __AUFS_CPUP_H__
5716 +#define __AUFS_CPUP_H__
5720 +#include <linux/path.h>
5726 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5727 +void au_cpup_attr_timesizes(struct inode *inode);
5728 +void au_cpup_attr_nlink(struct inode *inode, int force);
5729 +void au_cpup_attr_changeable(struct inode *inode);
5730 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5731 +void au_cpup_attr_all(struct inode *inode, int force);
5733 +/* ---------------------------------------------------------------------- */
5735 +struct au_cp_generic {
5736 + struct dentry *dentry;
5737 + aufs_bindex_t bdst, bsrc;
5739 + struct au_pin *pin;
5740 + unsigned int flags;
5744 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5745 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5747 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5748 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5750 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5752 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5753 + the branch is marked as RO */
5755 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5756 +#define au_fset_cpup(flags, name) \
5757 + do { (flags) |= AuCpup_##name; } while (0)
5758 +#define au_fclr_cpup(flags, name) \
5759 + do { (flags) &= ~AuCpup_##name; } while (0)
5761 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5762 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5763 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5764 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5766 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5767 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5768 + struct au_pin *pin,
5769 + struct dentry *h_parent, void *arg),
5771 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5772 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5774 +/* ---------------------------------------------------------------------- */
5776 +/* keep timestamps when copyup */
5778 + struct dentry *dt_dentry;
5779 + struct path dt_h_path;
5780 + struct timespec dt_atime, dt_mtime;
5782 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5783 + struct path *h_path);
5784 +void au_dtime_revert(struct au_dtime *dt);
5786 +#endif /* __KERNEL__ */
5787 +#endif /* __AUFS_CPUP_H__ */
5788 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5789 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5790 +++ linux/fs/aufs/dbgaufs.c 2015-01-25 13:00:38.631047076 +0100
5793 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5795 + * This program, aufs is free software; you can redistribute it and/or modify
5796 + * it under the terms of the GNU General Public License as published by
5797 + * the Free Software Foundation; either version 2 of the License, or
5798 + * (at your option) any later version.
5800 + * This program is distributed in the hope that it will be useful,
5801 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5802 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5803 + * GNU General Public License for more details.
5805 + * You should have received a copy of the GNU General Public License
5806 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5810 + * debugfs interface
5813 +#include <linux/debugfs.h>
5816 +#ifndef CONFIG_SYSFS
5817 +#error DEBUG_FS depends upon SYSFS
5820 +static struct dentry *dbgaufs;
5821 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5823 +/* 20 is max digits length of ulong 64 */
5824 +struct dbgaufs_arg {
5830 + * common function for all XINO files
5832 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5833 + struct file *file)
5835 + kfree(file->private_data);
5839 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5843 + struct dbgaufs_arg *p;
5846 + p = kmalloc(sizeof(*p), GFP_NOFS);
5852 + file->private_data = p;
5856 + err = vfs_getattr(&xf->f_path, &st);
5860 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5861 + (long)file_count(xf), st.blocks, st.blksize,
5862 + (long long)st.size);
5864 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5865 + st.blocks, st.blksize,
5866 + (long long)st.size);
5867 + AuDebugOn(p->n >= sizeof(p->a));
5869 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5878 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5879 + size_t count, loff_t *ppos)
5881 + struct dbgaufs_arg *p;
5883 + p = file->private_data;
5884 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5887 +/* ---------------------------------------------------------------------- */
5889 +struct dbgaufs_plink_arg {
5894 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
5895 + struct file *file)
5897 + free_page((unsigned long)file->private_data);
5901 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
5903 + int err, i, limit;
5904 + unsigned long n, sum;
5905 + struct dbgaufs_plink_arg *p;
5906 + struct au_sbinfo *sbinfo;
5907 + struct super_block *sb;
5908 + struct au_sphlhead *sphl;
5911 + p = (void *)get_zeroed_page(GFP_NOFS);
5916 + sbinfo = inode->i_private;
5917 + sb = sbinfo->si_sb;
5918 + si_noflush_read_lock(sb);
5919 + if (au_opt_test(au_mntflags(sb), PLINK)) {
5920 + limit = PAGE_SIZE - sizeof(p->n);
5922 + /* the number of buckets */
5923 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
5928 + for (i = 0, sphl = sbinfo->si_plink;
5929 + i < AuPlink_NHASH;
5931 + n = au_sphl_count(sphl);
5934 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5937 + if (unlikely(limit <= 0))
5940 + p->a[p->n - 1] = '\n';
5942 + /* the sum of plinks */
5943 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5946 + if (unlikely(limit <= 0))
5949 +#define str "1\n0\n0\n"
5950 + p->n = sizeof(str) - 1;
5951 + strcpy(p->a, str);
5954 + si_read_unlock(sb);
5957 + file->private_data = p;
5958 + goto out; /* success */
5961 + free_page((unsigned long)p);
5966 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5967 + size_t count, loff_t *ppos)
5969 + struct dbgaufs_plink_arg *p;
5971 + p = file->private_data;
5972 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5975 +static const struct file_operations dbgaufs_plink_fop = {
5976 + .owner = THIS_MODULE,
5977 + .open = dbgaufs_plink_open,
5978 + .release = dbgaufs_plink_release,
5979 + .read = dbgaufs_plink_read
5982 +/* ---------------------------------------------------------------------- */
5984 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5987 + struct au_sbinfo *sbinfo;
5988 + struct super_block *sb;
5990 + sbinfo = inode->i_private;
5991 + sb = sbinfo->si_sb;
5992 + si_noflush_read_lock(sb);
5993 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5994 + si_read_unlock(sb);
5998 +static const struct file_operations dbgaufs_xib_fop = {
5999 + .owner = THIS_MODULE,
6000 + .open = dbgaufs_xib_open,
6001 + .release = dbgaufs_xi_release,
6002 + .read = dbgaufs_xi_read
6005 +/* ---------------------------------------------------------------------- */
6007 +#define DbgaufsXi_PREFIX "xi"
6009 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6013 + struct au_sbinfo *sbinfo;
6014 + struct super_block *sb;
6016 + struct qstr *name;
6020 + name = &file->f_dentry->d_name;
6021 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6022 + || memcmp(name->name, DbgaufsXi_PREFIX,
6023 + sizeof(DbgaufsXi_PREFIX) - 1)))
6025 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6026 + if (unlikely(err))
6029 + sbinfo = inode->i_private;
6030 + sb = sbinfo->si_sb;
6031 + si_noflush_read_lock(sb);
6032 + if (l <= au_sbend(sb)) {
6033 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6034 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6037 + si_read_unlock(sb);
6043 +static const struct file_operations dbgaufs_xino_fop = {
6044 + .owner = THIS_MODULE,
6045 + .open = dbgaufs_xino_open,
6046 + .release = dbgaufs_xi_release,
6047 + .read = dbgaufs_xi_read
6050 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6052 + aufs_bindex_t bend;
6053 + struct au_branch *br;
6054 + struct au_xino_file *xi;
6056 + if (!au_sbi(sb)->si_dbgaufs)
6059 + bend = au_sbend(sb);
6060 + for (; bindex <= bend; bindex++) {
6061 + br = au_sbr(sb, bindex);
6062 + xi = &br->br_xino;
6063 + debugfs_remove(xi->xi_dbgaufs);
6064 + xi->xi_dbgaufs = NULL;
6068 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6070 + struct au_sbinfo *sbinfo;
6071 + struct dentry *parent;
6072 + struct au_branch *br;
6073 + struct au_xino_file *xi;
6074 + aufs_bindex_t bend;
6075 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6077 + sbinfo = au_sbi(sb);
6078 + parent = sbinfo->si_dbgaufs;
6082 + bend = au_sbend(sb);
6083 + for (; bindex <= bend; bindex++) {
6084 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6085 + br = au_sbr(sb, bindex);
6086 + xi = &br->br_xino;
6087 + AuDebugOn(xi->xi_dbgaufs);
6088 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6089 + sbinfo, &dbgaufs_xino_fop);
6090 + /* ignore an error */
6091 + if (unlikely(!xi->xi_dbgaufs))
6092 + AuWarn1("failed %s under debugfs\n", name);
6096 +/* ---------------------------------------------------------------------- */
6098 +#ifdef CONFIG_AUFS_EXPORT
6099 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6102 + struct au_sbinfo *sbinfo;
6103 + struct super_block *sb;
6105 + sbinfo = inode->i_private;
6106 + sb = sbinfo->si_sb;
6107 + si_noflush_read_lock(sb);
6108 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6109 + si_read_unlock(sb);
6113 +static const struct file_operations dbgaufs_xigen_fop = {
6114 + .owner = THIS_MODULE,
6115 + .open = dbgaufs_xigen_open,
6116 + .release = dbgaufs_xi_release,
6117 + .read = dbgaufs_xi_read
6120 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6125 + * This function is a dynamic '__init' function actually,
6126 + * so the tiny check for si_rwsem is unnecessary.
6128 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6131 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6132 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6133 + &dbgaufs_xigen_fop);
6134 + if (sbinfo->si_dbgaufs_xigen)
6140 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6144 +#endif /* CONFIG_AUFS_EXPORT */
6146 +/* ---------------------------------------------------------------------- */
6148 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6151 + * This function is a dynamic '__init' function actually,
6152 + * so the tiny check for si_rwsem is unnecessary.
6154 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6156 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6157 + sbinfo->si_dbgaufs = NULL;
6158 + kobject_put(&sbinfo->si_kobj);
6161 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6164 + char name[SysaufsSiNameLen];
6167 + * This function is a dynamic '__init' function actually,
6168 + * so the tiny check for si_rwsem is unnecessary.
6170 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6174 + AuErr1("/debug/aufs is uninitialized\n");
6179 + sysaufs_name(sbinfo, name);
6180 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6181 + if (unlikely(!sbinfo->si_dbgaufs))
6183 + kobject_get(&sbinfo->si_kobj);
6185 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6186 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6187 + &dbgaufs_xib_fop);
6188 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6191 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6192 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6193 + &dbgaufs_plink_fop);
6194 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6197 + err = dbgaufs_xigen_init(sbinfo);
6199 + goto out; /* success */
6202 + dbgaufs_si_fin(sbinfo);
6207 +/* ---------------------------------------------------------------------- */
6209 +void dbgaufs_fin(void)
6211 + debugfs_remove(dbgaufs);
6214 +int __init dbgaufs_init(void)
6219 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6224 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6225 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6226 +++ linux/fs/aufs/dbgaufs.h 2015-01-25 13:00:38.631047076 +0100
6229 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6231 + * This program, aufs is free software; you can redistribute it and/or modify
6232 + * it under the terms of the GNU General Public License as published by
6233 + * the Free Software Foundation; either version 2 of the License, or
6234 + * (at your option) any later version.
6236 + * This program is distributed in the hope that it will be useful,
6237 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6238 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6239 + * GNU General Public License for more details.
6241 + * You should have received a copy of the GNU General Public License
6242 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6246 + * debugfs interface
6249 +#ifndef __DBGAUFS_H__
6250 +#define __DBGAUFS_H__
6254 +struct super_block;
6257 +#ifdef CONFIG_DEBUG_FS
6259 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6260 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6261 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6262 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6263 +void dbgaufs_fin(void);
6264 +int __init dbgaufs_init(void);
6266 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6267 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6268 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6269 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6270 +AuStubVoid(dbgaufs_fin, void)
6271 +AuStubInt0(__init dbgaufs_init, void)
6272 +#endif /* CONFIG_DEBUG_FS */
6274 +#endif /* __KERNEL__ */
6275 +#endif /* __DBGAUFS_H__ */
6276 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6277 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6278 +++ linux/fs/aufs/dcsub.c 2015-01-25 13:00:38.631047076 +0100
6281 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6283 + * This program, aufs is free software; you can redistribute it and/or modify
6284 + * it under the terms of the GNU General Public License as published by
6285 + * the Free Software Foundation; either version 2 of the License, or
6286 + * (at your option) any later version.
6288 + * This program is distributed in the hope that it will be useful,
6289 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6290 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6291 + * GNU General Public License for more details.
6293 + * You should have received a copy of the GNU General Public License
6294 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6298 + * sub-routines for dentry cache
6303 +static void au_dpage_free(struct au_dpage *dpage)
6306 + struct dentry **p;
6308 + p = dpage->dentries;
6309 + for (i = 0; i < dpage->ndentry; i++)
6311 + free_page((unsigned long)dpage->dentries);
6314 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6320 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6321 + if (unlikely(!dpages->dpages))
6324 + p = (void *)__get_free_page(gfp);
6328 + dpages->dpages[0].ndentry = 0;
6329 + dpages->dpages[0].dentries = p;
6330 + dpages->ndpage = 1;
6331 + return 0; /* success */
6334 + kfree(dpages->dpages);
6339 +void au_dpages_free(struct au_dcsub_pages *dpages)
6342 + struct au_dpage *p;
6344 + p = dpages->dpages;
6345 + for (i = 0; i < dpages->ndpage; i++)
6346 + au_dpage_free(p++);
6347 + kfree(dpages->dpages);
6350 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6351 + struct dentry *dentry, gfp_t gfp)
6354 + struct au_dpage *dpage;
6357 + dpage = dpages->dpages + dpages->ndpage - 1;
6358 + sz = PAGE_SIZE / sizeof(dentry);
6359 + if (unlikely(dpage->ndentry >= sz)) {
6360 + AuLabel(new dpage);
6362 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6363 + p = au_kzrealloc(dpages->dpages, sz,
6364 + sz + sizeof(*dpages->dpages), gfp);
6368 + dpages->dpages = p;
6369 + dpage = dpages->dpages + dpages->ndpage;
6370 + p = (void *)__get_free_page(gfp);
6374 + dpage->ndentry = 0;
6375 + dpage->dentries = p;
6379 + AuDebugOn(au_dcount(dentry) <= 0);
6380 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6381 + return 0; /* success */
6387 +/* todo: BAD approach */
6388 +/* copied from linux/fs/dcache.c */
6396 +extern void d_walk(struct dentry *parent, void *data,
6397 + enum d_walk_ret (*enter)(void *, struct dentry *),
6398 + void (*finish)(void *));
6400 +struct ac_dpages_arg {
6402 + struct au_dcsub_pages *dpages;
6403 + struct super_block *sb;
6404 + au_dpages_test test;
6408 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6410 + enum d_walk_ret ret;
6411 + struct ac_dpages_arg *arg = _arg;
6413 + ret = D_WALK_CONTINUE;
6414 + if (dentry->d_sb == arg->sb
6415 + && !IS_ROOT(dentry)
6416 + && au_dcount(dentry) > 0
6418 + && (!arg->test || arg->test(dentry, arg->arg))) {
6419 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6420 + if (unlikely(arg->err))
6421 + ret = D_WALK_QUIT;
6427 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6428 + au_dpages_test test, void *arg)
6430 + struct ac_dpages_arg args = {
6438 + d_walk(root, &args, au_call_dpages_append, NULL);
6443 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6444 + int do_include, au_dpages_test test, void *arg)
6449 + write_seqlock(&rename_lock);
6450 + spin_lock(&dentry->d_lock);
6452 + && au_dcount(dentry) > 0
6453 + && (!test || test(dentry, arg)))
6454 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6455 + spin_unlock(&dentry->d_lock);
6456 + if (unlikely(err))
6460 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6463 + while (!IS_ROOT(dentry)) {
6464 + dentry = dentry->d_parent; /* rename_lock is locked */
6465 + spin_lock(&dentry->d_lock);
6466 + if (au_dcount(dentry) > 0
6467 + && (!test || test(dentry, arg)))
6468 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6469 + spin_unlock(&dentry->d_lock);
6470 + if (unlikely(err))
6475 + write_sequnlock(&rename_lock);
6479 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6481 + return au_di(dentry) && dentry->d_sb == arg;
6484 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6485 + struct dentry *dentry, int do_include)
6487 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6488 + au_dcsub_dpages_aufs, dentry->d_sb);
6491 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6493 + struct path path[2] = {
6502 + return path_is_under(path + 0, path + 1);
6504 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6505 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6506 +++ linux/fs/aufs/dcsub.h 2015-01-25 13:00:38.631047076 +0100
6509 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6511 + * This program, aufs is free software; you can redistribute it and/or modify
6512 + * it under the terms of the GNU General Public License as published by
6513 + * the Free Software Foundation; either version 2 of the License, or
6514 + * (at your option) any later version.
6516 + * This program is distributed in the hope that it will be useful,
6517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6519 + * GNU General Public License for more details.
6521 + * You should have received a copy of the GNU General Public License
6522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6526 + * sub-routines for dentry cache
6529 +#ifndef __AUFS_DCSUB_H__
6530 +#define __AUFS_DCSUB_H__
6534 +#include <linux/dcache.h>
6535 +#include <linux/fs.h>
6541 + struct dentry **dentries;
6544 +struct au_dcsub_pages {
6546 + struct au_dpage *dpages;
6549 +/* ---------------------------------------------------------------------- */
6552 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6553 +void au_dpages_free(struct au_dcsub_pages *dpages);
6554 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6555 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6556 + au_dpages_test test, void *arg);
6557 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6558 + int do_include, au_dpages_test test, void *arg);
6559 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6560 + struct dentry *dentry, int do_include);
6561 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6563 +/* ---------------------------------------------------------------------- */
6566 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6567 + * include/linux/dcache.h. Try them (in the future).
6570 +static inline int au_d_hashed_positive(struct dentry *d)
6573 + struct inode *inode = d->d_inode;
6576 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
6581 +static inline int au_d_linkable(struct dentry *d)
6584 + struct inode *inode = d->d_inode;
6586 + err = au_d_hashed_positive(d);
6589 + && (inode->i_state & I_LINKABLE))
6594 +static inline int au_d_alive(struct dentry *d)
6597 + struct inode *inode;
6601 + err = au_d_hashed_positive(d);
6603 + inode = d->d_inode;
6604 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
6610 +static inline int au_alive_dir(struct dentry *d)
6614 + err = au_d_alive(d);
6615 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
6620 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6622 + return a->len == b->len
6623 + && !memcmp(a->name, b->name, a->len);
6626 +static inline int au_dcount(struct dentry *d)
6628 + return (int)d_count(d);
6631 +#endif /* __KERNEL__ */
6632 +#endif /* __AUFS_DCSUB_H__ */
6633 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6634 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6635 +++ linux/fs/aufs/debug.c 2015-01-25 13:00:38.631047076 +0100
6638 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6640 + * This program, aufs is free software; you can redistribute it and/or modify
6641 + * it under the terms of the GNU General Public License as published by
6642 + * the Free Software Foundation; either version 2 of the License, or
6643 + * (at your option) any later version.
6645 + * This program is distributed in the hope that it will be useful,
6646 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6647 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6648 + * GNU General Public License for more details.
6650 + * You should have received a copy of the GNU General Public License
6651 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6655 + * debug print functions
6658 +#include <linux/vt_kern.h>
6661 +/* Returns 0, or -errno. arg is in kp->arg. */
6662 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6666 + err = kstrtoint(val, 0, &n);
6676 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6677 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6682 + return sprintf(buffer, "%d", atomic_read(a));
6685 +static struct kernel_param_ops param_ops_atomic_t = {
6686 + .set = param_atomic_t_set,
6687 + .get = param_atomic_t_get
6688 + /* void (*free)(void *arg) */
6691 +atomic_t aufs_debug = ATOMIC_INIT(0);
6692 +MODULE_PARM_DESC(debug, "debug print");
6693 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6695 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6696 +char *au_plevel = KERN_DEBUG;
6697 +#define dpri(fmt, ...) do { \
6699 + && strcmp(au_plevel, KERN_DEBUG)) \
6700 + || au_debug_test()) \
6701 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6704 +/* ---------------------------------------------------------------------- */
6706 +void au_dpri_whlist(struct au_nhash *whlist)
6708 + unsigned long ul, n;
6709 + struct hlist_head *head;
6710 + struct au_vdir_wh *pos;
6712 + n = whlist->nh_num;
6713 + head = whlist->nh_head;
6714 + for (ul = 0; ul < n; ul++) {
6715 + hlist_for_each_entry(pos, head, wh_hash)
6716 + dpri("b%d, %.*s, %d\n",
6718 + pos->wh_str.len, pos->wh_str.name,
6724 +void au_dpri_vdir(struct au_vdir *vdir)
6727 + union au_vdir_deblk_p p;
6730 + if (!vdir || IS_ERR(vdir)) {
6731 + dpri("err %ld\n", PTR_ERR(vdir));
6735 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6736 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6737 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6738 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6739 + p.deblk = vdir->vd_deblk[ul];
6741 + dpri("[%lu]: %p\n", ul, o);
6745 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6746 + struct dentry *wh)
6751 + if (!inode || IS_ERR(inode)) {
6752 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6756 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6757 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6758 + && sizeof(inode->i_blocks) != sizeof(u64));
6760 + n = (void *)wh->d_name.name;
6761 + l = wh->d_name.len;
6764 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6765 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6767 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6768 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6769 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6770 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6771 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6772 + inode->i_state, inode->i_flags, inode->i_version,
6773 + inode->i_generation,
6774 + l ? ", wh " : "", l, n);
6778 +void au_dpri_inode(struct inode *inode)
6780 + struct au_iinfo *iinfo;
6781 + aufs_bindex_t bindex;
6784 + err = do_pri_inode(-1, inode, -1, NULL);
6785 + if (err || !au_test_aufs(inode->i_sb))
6788 + iinfo = au_ii(inode);
6791 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6792 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6793 + if (iinfo->ii_bstart < 0)
6796 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6797 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6798 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6799 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6803 +void au_dpri_dalias(struct inode *inode)
6807 + spin_lock(&inode->i_lock);
6808 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
6809 + au_dpri_dentry(d);
6810 + spin_unlock(&inode->i_lock);
6813 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6815 + struct dentry *wh = NULL;
6817 + struct au_iinfo *iinfo;
6819 + if (!dentry || IS_ERR(dentry)) {
6820 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6823 + /* do not call dget_parent() here */
6824 + /* note: access d_xxx without d_lock */
6825 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6826 + bindex, dentry, dentry,
6827 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6828 + au_dcount(dentry), dentry->d_flags,
6829 + d_unhashed(dentry) ? "un" : "");
6831 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
6832 + iinfo = au_ii(dentry->d_inode);
6834 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6835 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6838 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
6842 +void au_dpri_dentry(struct dentry *dentry)
6844 + struct au_dinfo *dinfo;
6845 + aufs_bindex_t bindex;
6847 + struct au_hdentry *hdp;
6849 + err = do_pri_dentry(-1, dentry);
6850 + if (err || !au_test_aufs(dentry->d_sb))
6853 + dinfo = au_di(dentry);
6856 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
6857 + dinfo->di_bstart, dinfo->di_bend,
6858 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
6859 + dinfo->di_tmpfile);
6860 + if (dinfo->di_bstart < 0)
6862 + hdp = dinfo->di_hdentry;
6863 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6864 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6867 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
6871 + if (!file || IS_ERR(file)) {
6872 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
6878 + && au_test_aufs(file->f_dentry->d_sb)
6880 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
6881 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
6882 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
6883 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
6884 + file->f_version, file->f_pos, a);
6885 + if (file->f_dentry)
6886 + do_pri_dentry(bindex, file->f_dentry);
6890 +void au_dpri_file(struct file *file)
6892 + struct au_finfo *finfo;
6893 + struct au_fidir *fidir;
6894 + struct au_hfile *hfile;
6895 + aufs_bindex_t bindex;
6898 + err = do_pri_file(-1, file);
6899 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
6902 + finfo = au_fi(file);
6905 + if (finfo->fi_btop < 0)
6907 + fidir = finfo->fi_hdir;
6909 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
6911 + for (bindex = finfo->fi_btop;
6912 + bindex >= 0 && bindex <= fidir->fd_bbot;
6914 + hfile = fidir->fd_hfile + bindex;
6915 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
6919 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
6921 + struct vfsmount *mnt;
6922 + struct super_block *sb;
6924 + if (!br || IS_ERR(br))
6926 + mnt = au_br_mnt(br);
6927 + if (!mnt || IS_ERR(mnt))
6930 + if (!sb || IS_ERR(sb))
6933 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
6934 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
6936 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
6937 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
6938 + sb->s_flags, sb->s_count,
6939 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
6943 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6947 +void au_dpri_sb(struct super_block *sb)
6949 + struct au_sbinfo *sbinfo;
6950 + aufs_bindex_t bindex;
6952 + /* to reuduce stack size */
6954 + struct vfsmount mnt;
6955 + struct au_branch fake;
6958 + /* this function can be called from magic sysrq */
6959 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6960 + if (unlikely(!a)) {
6961 + dpri("no memory\n");
6965 + a->mnt.mnt_sb = sb;
6966 + a->fake.br_perm = 0;
6967 + a->fake.br_path.mnt = &a->mnt;
6968 + a->fake.br_xino.xi_file = NULL;
6969 + atomic_set(&a->fake.br_count, 0);
6970 + smp_mb(); /* atomic_set */
6971 + err = do_pri_br(-1, &a->fake);
6973 + dpri("dev 0x%x\n", sb->s_dev);
6974 + if (err || !au_test_aufs(sb))
6977 + sbinfo = au_sbi(sb);
6980 + dpri("nw %d, gen %u, kobj %d\n",
6981 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6982 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6983 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6984 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6987 +/* ---------------------------------------------------------------------- */
6989 +void au_dbg_sleep_jiffy(int jiffy)
6992 + jiffy = schedule_timeout_uninterruptible(jiffy);
6995 +void au_dbg_iattr(struct iattr *ia)
6997 +#define AuBit(name) \
6999 + if (ia->ia_valid & ATTR_ ## name) \
7000 + dpri(#name "\n"); \
7020 + dpri("ia_file %p\n", ia->ia_file);
7023 +/* ---------------------------------------------------------------------- */
7025 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7027 + struct inode *h_inode, *inode = dentry->d_inode;
7028 + struct dentry *h_dentry;
7029 + aufs_bindex_t bindex, bend, bi;
7031 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7034 + bend = au_dbend(dentry);
7035 + bi = au_ibend(inode);
7038 + bindex = au_dbstart(dentry);
7039 + bi = au_ibstart(inode);
7043 + for (; bindex <= bend; bindex++) {
7044 + h_dentry = au_h_dptr(dentry, bindex);
7047 + h_inode = au_h_iptr(inode, bindex);
7048 + if (unlikely(h_inode != h_dentry->d_inode)) {
7050 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7051 + AuDbgDentry(dentry);
7052 + AuDbgInode(inode);
7059 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
7061 + struct dentry *parent;
7063 + parent = dget_parent(dentry);
7064 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
7065 + AuDebugOn(IS_ROOT(dentry));
7066 + AuDebugOn(au_digen_test(parent, sigen));
7070 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
7072 + struct dentry *parent;
7073 + struct inode *inode;
7075 + parent = dget_parent(dentry);
7076 + inode = dentry->d_inode;
7077 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
7078 + AuDebugOn(au_digen_test(parent, sigen));
7082 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7085 + struct au_dcsub_pages dpages;
7086 + struct au_dpage *dpage;
7087 + struct dentry **dentries;
7089 + err = au_dpages_init(&dpages, GFP_NOFS);
7091 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7093 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7094 + dpage = dpages.dpages + i;
7095 + dentries = dpage->dentries;
7096 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7097 + AuDebugOn(au_digen_test(dentries[j], sigen));
7099 + au_dpages_free(&dpages);
7102 +void au_dbg_verify_kthread(void)
7104 + if (au_wkq_test()) {
7107 + * It may be recursive, but udba=notify between two aufs mounts,
7108 + * where a single ro branch is shared, is not a problem.
7114 +/* ---------------------------------------------------------------------- */
7116 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
7118 +#ifdef AuForceNoPlink
7119 + au_opt_clr(sbinfo->si_mntflags, PLINK);
7121 +#ifdef AuForceNoXino
7122 + au_opt_clr(sbinfo->si_mntflags, XINO);
7124 +#ifdef AuForceNoRefrof
7125 + au_opt_clr(sbinfo->si_mntflags, REFROF);
7127 +#ifdef AuForceHnotify
7128 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
7131 + sbinfo->si_rdblk = 0;
7132 + sbinfo->si_rdhash = 0;
7136 +int __init au_debug_init(void)
7138 + aufs_bindex_t bindex;
7139 + struct au_vdir_destr destr;
7142 + AuDebugOn(bindex >= 0);
7145 + AuDebugOn(destr.len < NAME_MAX);
7147 +#ifdef CONFIG_4KSTACKS
7148 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7151 +#ifdef AuForceNoBrs
7157 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7158 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7159 +++ linux/fs/aufs/debug.h 2015-01-25 13:00:38.631047076 +0100
7162 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7164 + * This program, aufs is free software; you can redistribute it and/or modify
7165 + * it under the terms of the GNU General Public License as published by
7166 + * the Free Software Foundation; either version 2 of the License, or
7167 + * (at your option) any later version.
7169 + * This program is distributed in the hope that it will be useful,
7170 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7171 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7172 + * GNU General Public License for more details.
7174 + * You should have received a copy of the GNU General Public License
7175 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7179 + * debug print functions
7182 +#ifndef __AUFS_DEBUG_H__
7183 +#define __AUFS_DEBUG_H__
7187 +#include <linux/atomic.h>
7188 +#include <linux/module.h>
7189 +#include <linux/kallsyms.h>
7190 +#include <linux/sysrq.h>
7192 +#ifdef CONFIG_AUFS_DEBUG
7193 +#define AuDebugOn(a) BUG_ON(a)
7195 +/* module parameter */
7196 +extern atomic_t aufs_debug;
7197 +static inline void au_debug_on(void)
7199 + atomic_inc(&aufs_debug);
7201 +static inline void au_debug_off(void)
7203 + atomic_dec_if_positive(&aufs_debug);
7206 +static inline int au_debug_test(void)
7208 + return atomic_read(&aufs_debug) > 0;
7211 +#define AuDebugOn(a) do {} while (0)
7212 +AuStubVoid(au_debug_on, void)
7213 +AuStubVoid(au_debug_off, void)
7214 +AuStubInt0(au_debug_test, void)
7215 +#endif /* CONFIG_AUFS_DEBUG */
7217 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7219 +/* ---------------------------------------------------------------------- */
7223 +#define AuDbg(fmt, ...) do { \
7224 + if (au_debug_test()) \
7225 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7227 +#define AuLabel(l) AuDbg(#l "\n")
7228 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7229 +#define AuWarn1(fmt, ...) do { \
7230 + static unsigned char _c; \
7232 + pr_warn(fmt, ##__VA_ARGS__); \
7235 +#define AuErr1(fmt, ...) do { \
7236 + static unsigned char _c; \
7238 + pr_err(fmt, ##__VA_ARGS__); \
7241 +#define AuIOErr1(fmt, ...) do { \
7242 + static unsigned char _c; \
7244 + AuIOErr(fmt, ##__VA_ARGS__); \
7247 +#define AuUnsupportMsg "This operation is not supported." \
7248 + " Please report this application to aufs-users ML."
7249 +#define AuUnsupport(fmt, ...) do { \
7250 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7254 +#define AuTraceErr(e) do { \
7255 + if (unlikely((e) < 0)) \
7256 + AuDbg("err %d\n", (int)(e)); \
7259 +#define AuTraceErrPtr(p) do { \
7261 + AuDbg("err %ld\n", PTR_ERR(p)); \
7264 +/* dirty macros for debug print, use with "%.*s" and caution */
7265 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7267 +/* ---------------------------------------------------------------------- */
7272 +#ifdef CONFIG_AUFS_DEBUG
7273 +extern struct mutex au_dbg_mtx;
7274 +extern char *au_plevel;
7276 +void au_dpri_whlist(struct au_nhash *whlist);
7278 +void au_dpri_vdir(struct au_vdir *vdir);
7280 +void au_dpri_inode(struct inode *inode);
7281 +void au_dpri_dalias(struct inode *inode);
7282 +void au_dpri_dentry(struct dentry *dentry);
7284 +void au_dpri_file(struct file *filp);
7285 +struct super_block;
7286 +void au_dpri_sb(struct super_block *sb);
7288 +void au_dbg_sleep_jiffy(int jiffy);
7290 +void au_dbg_iattr(struct iattr *ia);
7292 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7293 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7294 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
7295 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
7296 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7297 +void au_dbg_verify_kthread(void);
7299 +int __init au_debug_init(void);
7300 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
7301 +#define AuDbgWhlist(w) do { \
7302 + mutex_lock(&au_dbg_mtx); \
7304 + au_dpri_whlist(w); \
7305 + mutex_unlock(&au_dbg_mtx); \
7308 +#define AuDbgVdir(v) do { \
7309 + mutex_lock(&au_dbg_mtx); \
7311 + au_dpri_vdir(v); \
7312 + mutex_unlock(&au_dbg_mtx); \
7315 +#define AuDbgInode(i) do { \
7316 + mutex_lock(&au_dbg_mtx); \
7318 + au_dpri_inode(i); \
7319 + mutex_unlock(&au_dbg_mtx); \
7322 +#define AuDbgDAlias(i) do { \
7323 + mutex_lock(&au_dbg_mtx); \
7325 + au_dpri_dalias(i); \
7326 + mutex_unlock(&au_dbg_mtx); \
7329 +#define AuDbgDentry(d) do { \
7330 + mutex_lock(&au_dbg_mtx); \
7332 + au_dpri_dentry(d); \
7333 + mutex_unlock(&au_dbg_mtx); \
7336 +#define AuDbgFile(f) do { \
7337 + mutex_lock(&au_dbg_mtx); \
7339 + au_dpri_file(f); \
7340 + mutex_unlock(&au_dbg_mtx); \
7343 +#define AuDbgSb(sb) do { \
7344 + mutex_lock(&au_dbg_mtx); \
7345 + AuDbg(#sb "\n"); \
7347 + mutex_unlock(&au_dbg_mtx); \
7350 +#define AuDbgSleep(sec) do { \
7351 + AuDbg("sleep %d sec\n", sec); \
7355 +#define AuDbgSleepJiffy(jiffy) do { \
7356 + AuDbg("sleep %d jiffies\n", jiffy); \
7357 + au_dbg_sleep_jiffy(jiffy); \
7360 +#define AuDbgIAttr(ia) do { \
7361 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
7362 + au_dbg_iattr(ia); \
7365 +#define AuDbgSym(addr) do { \
7366 + char sym[KSYM_SYMBOL_LEN]; \
7367 + sprint_symbol(sym, (unsigned long)addr); \
7368 + AuDbg("%s\n", sym); \
7371 +#define AuInfoSym(addr) do { \
7372 + char sym[KSYM_SYMBOL_LEN]; \
7373 + sprint_symbol(sym, (unsigned long)addr); \
7374 + AuInfo("%s\n", sym); \
7377 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7378 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
7379 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
7380 + unsigned int sigen)
7381 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7382 +AuStubVoid(au_dbg_verify_kthread, void)
7383 +AuStubInt0(__init au_debug_init, void)
7384 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
7386 +#define AuDbgWhlist(w) do {} while (0)
7387 +#define AuDbgVdir(v) do {} while (0)
7388 +#define AuDbgInode(i) do {} while (0)
7389 +#define AuDbgDAlias(i) do {} while (0)
7390 +#define AuDbgDentry(d) do {} while (0)
7391 +#define AuDbgFile(f) do {} while (0)
7392 +#define AuDbgSb(sb) do {} while (0)
7393 +#define AuDbgSleep(sec) do {} while (0)
7394 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
7395 +#define AuDbgIAttr(ia) do {} while (0)
7396 +#define AuDbgSym(addr) do {} while (0)
7397 +#define AuInfoSym(addr) do {} while (0)
7398 +#endif /* CONFIG_AUFS_DEBUG */
7400 +/* ---------------------------------------------------------------------- */
7402 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7403 +int __init au_sysrq_init(void);
7404 +void au_sysrq_fin(void);
7406 +#ifdef CONFIG_HW_CONSOLE
7407 +#define au_dbg_blocked() do { \
7409 + handle_sysrq('w'); \
7412 +AuStubVoid(au_dbg_blocked, void)
7416 +AuStubInt0(__init au_sysrq_init, void)
7417 +AuStubVoid(au_sysrq_fin, void)
7418 +AuStubVoid(au_dbg_blocked, void)
7419 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7421 +#endif /* __KERNEL__ */
7422 +#endif /* __AUFS_DEBUG_H__ */
7423 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7424 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7425 +++ linux/fs/aufs/dentry.c 2015-01-25 13:00:38.631047076 +0100
7428 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7430 + * This program, aufs is free software; you can redistribute it and/or modify
7431 + * it under the terms of the GNU General Public License as published by
7432 + * the Free Software Foundation; either version 2 of the License, or
7433 + * (at your option) any later version.
7435 + * This program is distributed in the hope that it will be useful,
7436 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7437 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7438 + * GNU General Public License for more details.
7440 + * You should have received a copy of the GNU General Public License
7441 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7445 + * lookup and dentry operations
7448 +#include <linux/namei.h>
7451 +#define AuLkup_ALLOW_NEG 1
7452 +#define AuLkup_IGNORE_PERM (1 << 1)
7453 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7454 +#define au_fset_lkup(flags, name) \
7455 + do { (flags) |= AuLkup_##name; } while (0)
7456 +#define au_fclr_lkup(flags, name) \
7457 + do { (flags) &= ~AuLkup_##name; } while (0)
7459 +struct au_do_lookup_args {
7460 + unsigned int flags;
7465 + * returns positive/negative dentry, NULL or an error.
7466 + * NULL means whiteout-ed or not-found.
7468 +static struct dentry*
7469 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7470 + aufs_bindex_t bindex, struct qstr *wh_name,
7471 + struct au_do_lookup_args *args)
7473 + struct dentry *h_dentry;
7474 + struct inode *h_inode, *inode;
7475 + struct au_branch *br;
7476 + int wh_found, opq;
7477 + unsigned char wh_able;
7478 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7479 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7483 + br = au_sbr(dentry->d_sb, bindex);
7484 + wh_able = !!au_br_whable(br->br_perm);
7486 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7487 + h_dentry = ERR_PTR(wh_found);
7490 + if (unlikely(wh_found < 0))
7493 + /* We found a whiteout */
7494 + /* au_set_dbend(dentry, bindex); */
7495 + au_set_dbwh(dentry, bindex);
7497 + return NULL; /* success */
7501 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7503 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7504 + if (IS_ERR(h_dentry))
7507 + h_inode = h_dentry->d_inode;
7511 + } else if (wh_found
7512 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7515 + if (au_dbend(dentry) <= bindex)
7516 + au_set_dbend(dentry, bindex);
7517 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7518 + au_set_dbstart(dentry, bindex);
7519 + au_set_h_dptr(dentry, bindex, h_dentry);
7521 + inode = dentry->d_inode;
7522 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
7523 + || (inode && !S_ISDIR(inode->i_mode)))
7524 + goto out; /* success */
7526 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7527 + opq = au_diropq_test(h_dentry);
7528 + mutex_unlock(&h_inode->i_mutex);
7530 + au_set_dbdiropq(dentry, bindex);
7531 + else if (unlikely(opq < 0)) {
7532 + au_set_h_dptr(dentry, bindex, NULL);
7533 + h_dentry = ERR_PTR(opq);
7544 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7546 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7547 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7553 + * returns the number of lower positive dentries,
7554 + * otherwise an error.
7555 + * can be called at unlinking with @type is zero.
7557 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7559 + int npositive, err;
7560 + aufs_bindex_t bindex, btail, bdiropq;
7561 + unsigned char isdir, dirperm1;
7562 + struct qstr whname;
7563 + struct au_do_lookup_args args = {
7567 + const struct qstr *name = &dentry->d_name;
7568 + struct dentry *parent;
7569 + struct inode *inode;
7570 + struct super_block *sb;
7572 + sb = dentry->d_sb;
7573 + err = au_test_shwh(sb, name);
7574 + if (unlikely(err))
7577 + err = au_wh_name_alloc(&whname, name);
7578 + if (unlikely(err))
7581 + inode = dentry->d_inode;
7582 + isdir = !!(inode && S_ISDIR(inode->i_mode));
7584 + au_fset_lkup(args.flags, ALLOW_NEG);
7585 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7588 + parent = dget_parent(dentry);
7589 + btail = au_dbtaildir(parent);
7590 + for (bindex = bstart; bindex <= btail; bindex++) {
7591 + struct dentry *h_parent, *h_dentry;
7592 + struct inode *h_inode, *h_dir;
7594 + h_dentry = au_h_dptr(dentry, bindex);
7596 + if (h_dentry->d_inode)
7598 + if (type != S_IFDIR)
7602 + h_parent = au_h_dptr(parent, bindex);
7605 + h_dir = h_parent->d_inode;
7606 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
7609 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7610 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7612 + mutex_unlock(&h_dir->i_mutex);
7613 + err = PTR_ERR(h_dentry);
7614 + if (IS_ERR(h_dentry))
7616 + au_fclr_lkup(args.flags, ALLOW_NEG);
7618 + au_fset_lkup(args.flags, IGNORE_PERM);
7620 + if (au_dbwh(dentry) >= 0)
7624 + h_inode = h_dentry->d_inode;
7629 + args.type = h_inode->i_mode & S_IFMT;
7630 + if (args.type != S_IFDIR)
7633 + /* the type of lower may be different */
7634 + bdiropq = au_dbdiropq(dentry);
7635 + if (bdiropq >= 0 && bdiropq <= bindex)
7641 + AuLabel(positive);
7642 + au_update_dbstart(dentry);
7645 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7646 + && au_dbstart(dentry) < 0)) {
7648 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7654 + kfree(whname.name);
7659 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7661 + struct dentry *dentry;
7664 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
7665 + dentry = vfsub_lkup_one(name, parent);
7667 + struct vfsub_lkup_one_args args = {
7673 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7674 + if (unlikely(wkq_err))
7675 + dentry = ERR_PTR(wkq_err);
7682 + * lookup @dentry on @bindex which should be negative.
7684 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7687 + struct dentry *parent, *h_parent, *h_dentry;
7688 + struct au_branch *br;
7690 + parent = dget_parent(dentry);
7691 + h_parent = au_h_dptr(parent, bindex);
7692 + br = au_sbr(dentry->d_sb, bindex);
7694 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7696 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7697 + err = PTR_ERR(h_dentry);
7698 + if (IS_ERR(h_dentry))
7700 + if (unlikely(h_dentry->d_inode)) {
7702 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7708 + if (bindex < au_dbstart(dentry))
7709 + au_set_dbstart(dentry, bindex);
7710 + if (au_dbend(dentry) < bindex)
7711 + au_set_dbend(dentry, bindex);
7712 + au_set_h_dptr(dentry, bindex, h_dentry);
7719 +/* ---------------------------------------------------------------------- */
7721 +/* subset of struct inode */
7723 + unsigned long i_ino;
7724 + /* unsigned int i_nlink; */
7730 + blkcnt_t i_blocks;
7735 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7737 + ia->i_ino = h_inode->i_ino;
7738 + /* ia->i_nlink = h_inode->i_nlink; */
7739 + ia->i_uid = h_inode->i_uid;
7740 + ia->i_gid = h_inode->i_gid;
7741 + ia->i_version = h_inode->i_version;
7743 + ia->i_size = h_inode->i_size;
7744 + ia->i_blocks = h_inode->i_blocks;
7746 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7749 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7751 + return ia->i_ino != h_inode->i_ino
7752 + /* || ia->i_nlink != h_inode->i_nlink */
7753 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7754 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7755 + || ia->i_version != h_inode->i_version
7757 + || ia->i_size != h_inode->i_size
7758 + || ia->i_blocks != h_inode->i_blocks
7760 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7763 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7764 + struct au_branch *br)
7767 + struct au_iattr ia;
7768 + struct inode *h_inode;
7769 + struct dentry *h_d;
7770 + struct super_block *h_sb;
7773 + memset(&ia, -1, sizeof(ia));
7774 + h_sb = h_dentry->d_sb;
7775 + h_inode = h_dentry->d_inode;
7777 + au_iattr_save(&ia, h_inode);
7778 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7779 + /* nfs d_revalidate may return 0 for negative dentry */
7780 + /* fuse d_revalidate always return 0 for negative dentry */
7783 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7784 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7785 + err = PTR_ERR(h_d);
7790 + if (unlikely(h_d != h_dentry
7791 + || h_d->d_inode != h_inode
7792 + || (h_inode && au_iattr_test(&ia, h_inode))))
7793 + err = au_busy_or_stale();
7801 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7802 + struct dentry *h_parent, struct au_branch *br)
7807 + if (udba == AuOpt_UDBA_REVAL
7808 + && !au_test_fs_remote(h_dentry->d_sb)) {
7810 + err = (h_dentry->d_parent->d_inode != h_dir);
7811 + } else if (udba != AuOpt_UDBA_NONE)
7812 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7817 +/* ---------------------------------------------------------------------- */
7819 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7822 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7823 + struct au_hdentry tmp, *p, *q;
7824 + struct au_dinfo *dinfo;
7825 + struct super_block *sb;
7827 + DiMustWriteLock(dentry);
7829 + sb = dentry->d_sb;
7830 + dinfo = au_di(dentry);
7831 + bend = dinfo->di_bend;
7832 + bwh = dinfo->di_bwh;
7833 + bdiropq = dinfo->di_bdiropq;
7834 + p = dinfo->di_hdentry + dinfo->di_bstart;
7835 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7836 + if (!p->hd_dentry)
7839 + new_bindex = au_br_index(sb, p->hd_id);
7840 + if (new_bindex == bindex)
7843 + if (dinfo->di_bwh == bindex)
7845 + if (dinfo->di_bdiropq == bindex)
7846 + bdiropq = new_bindex;
7847 + if (new_bindex < 0) {
7849 + p->hd_dentry = NULL;
7853 + /* swap two lower dentries, and loop again */
7854 + q = dinfo->di_hdentry + new_bindex;
7858 + if (tmp.hd_dentry) {
7864 + dinfo->di_bwh = -1;
7865 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7866 + dinfo->di_bwh = bwh;
7868 + dinfo->di_bdiropq = -1;
7870 + && bdiropq <= au_sbend(sb)
7871 + && au_sbr_whable(sb, bdiropq))
7872 + dinfo->di_bdiropq = bdiropq;
7875 + dinfo->di_bstart = -1;
7876 + dinfo->di_bend = -1;
7877 + bend = au_dbend(parent);
7878 + p = dinfo->di_hdentry;
7879 + for (bindex = 0; bindex <= bend; bindex++, p++)
7880 + if (p->hd_dentry) {
7881 + dinfo->di_bstart = bindex;
7885 + if (dinfo->di_bstart >= 0) {
7886 + p = dinfo->di_hdentry + bend;
7887 + for (bindex = bend; bindex >= 0; bindex--, p--)
7888 + if (p->hd_dentry) {
7889 + dinfo->di_bend = bindex;
7898 +static void au_do_hide(struct dentry *dentry)
7900 + struct inode *inode;
7902 + inode = dentry->d_inode;
7904 + if (!S_ISDIR(inode->i_mode)) {
7905 + if (inode->i_nlink && !d_unhashed(dentry))
7906 + drop_nlink(inode);
7908 + clear_nlink(inode);
7909 + /* stop next lookup */
7910 + inode->i_flags |= S_DEAD;
7912 + smp_mb(); /* necessary? */
7917 +static int au_hide_children(struct dentry *parent)
7919 + int err, i, j, ndentry;
7920 + struct au_dcsub_pages dpages;
7921 + struct au_dpage *dpage;
7922 + struct dentry *dentry;
7924 + err = au_dpages_init(&dpages, GFP_NOFS);
7925 + if (unlikely(err))
7927 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7928 + if (unlikely(err))
7931 + /* in reverse order */
7932 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7933 + dpage = dpages.dpages + i;
7934 + ndentry = dpage->ndentry;
7935 + for (j = ndentry - 1; j >= 0; j--) {
7936 + dentry = dpage->dentries[j];
7937 + if (dentry != parent)
7938 + au_do_hide(dentry);
7943 + au_dpages_free(&dpages);
7948 +static void au_hide(struct dentry *dentry)
7951 + struct inode *inode;
7953 + AuDbgDentry(dentry);
7954 + inode = dentry->d_inode;
7955 + if (inode && S_ISDIR(inode->i_mode)) {
7956 + /* shrink_dcache_parent(dentry); */
7957 + err = au_hide_children(dentry);
7958 + if (unlikely(err))
7959 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7962 + au_do_hide(dentry);
7966 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7968 + * a dirty branch is added
7969 + * - on the top of layers
7970 + * - in the middle of layers
7971 + * - to the bottom of layers
7973 + * on the added branch there exists
7976 + * - a same named entry
7978 + * * negative --> positive
7979 + * * positive --> positive
7980 + * - type is unchanged
7981 + * - type is changed
7983 + * * negative --> negative
7984 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7987 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7988 + struct au_dinfo *tmp)
7991 + aufs_bindex_t bindex, bend;
7993 + struct dentry *dentry;
7994 + struct inode *inode;
7997 + struct au_hdentry *hd;
7998 + struct inode *inode, *h_inode;
7999 + struct dentry *h_dentry;
8002 + AuDebugOn(dinfo->di_bstart < 0);
8003 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
8004 + orig_h.inode = orig_h.dentry->d_inode;
8007 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8008 + memset(&tmp_h, 0, sizeof(tmp_h));
8009 + if (tmp->di_bstart >= 0) {
8010 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
8011 + tmp_h.inode = tmp_h.dentry->d_inode;
8013 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8016 + inode = dentry->d_inode;
8017 + if (!orig_h.inode) {
8018 + AuDbg("nagative originally\n");
8024 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8025 + AuDebugOn(dinfo->di_bdiropq != -1);
8027 + if (!tmp_h.inode) {
8028 + AuDbg("negative --> negative\n");
8029 + /* should have only one negative lower */
8030 + if (tmp->di_bstart >= 0
8031 + && tmp->di_bstart < dinfo->di_bstart) {
8032 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
8033 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8034 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
8035 + au_di_cp(dinfo, tmp);
8036 + hd = tmp->di_hdentry + tmp->di_bstart;
8037 + au_set_h_dptr(dentry, tmp->di_bstart,
8038 + dget(hd->hd_dentry));
8040 + au_dbg_verify_dinode(dentry);
8042 + AuDbg("negative --> positive\n");
8044 + * similar to the behaviour of creating with bypassing
8046 + * unhash it in order to force an error in the
8047 + * succeeding create operation.
8048 + * we should not set S_DEAD here.
8051 + /* au_di_swap(tmp, dinfo); */
8052 + au_dbg_verify_dinode(dentry);
8055 + AuDbg("positive originally\n");
8056 + /* inode may be NULL */
8057 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8058 + if (!tmp_h.inode) {
8059 + AuDbg("positive --> negative\n");
8060 + /* or bypassing aufs */
8062 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
8063 + dinfo->di_bwh = tmp->di_bwh;
8065 + err = au_refresh_hinode_self(inode);
8066 + au_dbg_verify_dinode(dentry);
8067 + } else if (orig_h.mode == tmp_h.mode) {
8068 + AuDbg("positive --> positive, same type\n");
8069 + if (!S_ISDIR(orig_h.mode)
8070 + && dinfo->di_bstart > tmp->di_bstart) {
8072 + * similar to the behaviour of removing and
8077 + err = au_refresh_hinode_self(inode);
8078 + au_dbg_verify_dinode(dentry);
8080 + /* fill empty slots */
8081 + if (dinfo->di_bstart > tmp->di_bstart)
8082 + dinfo->di_bstart = tmp->di_bstart;
8083 + if (dinfo->di_bend < tmp->di_bend)
8084 + dinfo->di_bend = tmp->di_bend;
8085 + dinfo->di_bwh = tmp->di_bwh;
8086 + dinfo->di_bdiropq = tmp->di_bdiropq;
8087 + hd = tmp->di_hdentry;
8088 + bend = dinfo->di_bend;
8089 + for (bindex = tmp->di_bstart; bindex <= bend;
8091 + if (au_h_dptr(dentry, bindex))
8093 + h_dentry = hd[bindex].hd_dentry;
8096 + h_inode = h_dentry->d_inode;
8097 + AuDebugOn(!h_inode);
8098 + AuDebugOn(orig_h.mode
8099 + != (h_inode->i_mode
8101 + au_set_h_dptr(dentry, bindex,
8104 + err = au_refresh_hinode(inode, dentry);
8105 + au_dbg_verify_dinode(dentry);
8108 + AuDbg("positive --> positive, different type\n");
8109 + /* similar to the behaviour of removing and creating */
8112 + err = au_refresh_hinode_self(inode);
8113 + au_dbg_verify_dinode(dentry);
8121 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8124 + unsigned int sigen;
8125 + struct au_dinfo *dinfo, *tmp;
8126 + struct super_block *sb;
8127 + struct inode *inode;
8129 + DiMustWriteLock(dentry);
8130 + AuDebugOn(IS_ROOT(dentry));
8131 + AuDebugOn(!parent->d_inode);
8133 + sb = dentry->d_sb;
8134 + inode = dentry->d_inode;
8135 + sigen = au_sigen(sb);
8136 + err = au_digen_test(parent, sigen);
8137 + if (unlikely(err))
8140 + dinfo = au_di(dentry);
8141 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
8142 + if (unlikely(err))
8144 + ebrange = au_dbrange_test(dentry);
8146 + ebrange = au_do_refresh_hdentry(dentry, parent);
8148 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8149 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8151 + err = au_refresh_hinode_self(inode);
8152 + au_dbg_verify_dinode(dentry);
8154 + goto out_dgen; /* success */
8158 + /* temporary dinfo */
8159 + AuDbgDentry(dentry);
8161 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8162 + if (unlikely(!tmp))
8164 + au_di_swap(tmp, dinfo);
8165 + /* returns the number of positive dentries */
8167 + * if current working dir is removed, it returns an error.
8168 + * but the dentry is legal.
8170 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8171 + AuDbgDentry(dentry);
8172 + au_di_swap(tmp, dinfo);
8173 + if (err == -ENOENT)
8176 + /* compare/refresh by dinfo */
8177 + AuDbgDentry(dentry);
8178 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8179 + au_dbg_verify_dinode(dentry);
8182 + au_rw_write_unlock(&tmp->di_rwsem);
8184 + if (unlikely(err))
8188 + au_update_digen(dentry);
8190 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8191 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8192 + AuDbgDentry(dentry);
8198 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8199 + struct dentry *dentry, aufs_bindex_t bindex)
8204 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8207 + AuDbg("b%d\n", bindex);
8209 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8210 + * due to whiteout and branch permission.
8212 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8213 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8214 + /* it may return tri-state */
8215 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8217 + if (unlikely(valid < 0))
8227 +/* todo: remove this */
8228 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8229 + unsigned int flags, int do_udba)
8232 + umode_t mode, h_mode;
8233 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8234 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8235 + struct inode *h_inode, *h_cached_inode;
8236 + struct dentry *h_dentry;
8237 + struct qstr *name, *h_name;
8244 + unhashed = !!d_unhashed(dentry);
8245 + is_root = !!IS_ROOT(dentry);
8246 + name = &dentry->d_name;
8247 + tmpfile = au_di(dentry)->di_tmpfile;
8250 + * Theoretically, REVAL test should be unnecessary in case of
8252 + * But {fs,i}notify doesn't fire some necessary events,
8253 + * IN_ATTRIB for atime/nlink/pageio
8254 + * Let's do REVAL test too.
8256 + if (do_udba && inode) {
8257 + mode = (inode->i_mode & S_IFMT);
8258 + plus = (inode->i_nlink > 0);
8259 + ibs = au_ibstart(inode);
8260 + ibe = au_ibend(inode);
8263 + bstart = au_dbstart(dentry);
8265 + if (inode && S_ISDIR(inode->i_mode))
8266 + btail = au_dbtaildir(dentry);
8267 + for (bindex = bstart; bindex <= btail; bindex++) {
8268 + h_dentry = au_h_dptr(dentry, bindex);
8272 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8273 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8274 + spin_lock(&h_dentry->d_lock);
8275 + h_name = &h_dentry->d_name;
8276 + if (unlikely(do_udba
8279 + && (unhashed != !!d_unhashed(h_dentry)
8281 + && !au_qstreq(name, h_name))
8284 + && !(flags & LOOKUP_OPEN)
8285 + && (h_dentry->d_flags
8286 + & DCACHE_NFSFS_RENAMED)))
8290 + h_unhashed = d_unhashed(h_dentry);
8291 + spin_unlock(&h_dentry->d_lock);
8292 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8293 + unhashed, h_unhashed, dentry, h_dentry);
8296 + spin_unlock(&h_dentry->d_lock);
8298 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8299 + if (unlikely(err))
8300 + /* do not goto err, to keep the errno */
8303 + /* todo: plink too? */
8308 + h_inode = h_dentry->d_inode;
8309 + if (unlikely(!!inode != !!h_inode))
8314 + h_cached_inode = h_inode;
8316 + h_mode = (h_inode->i_mode & S_IFMT);
8317 + h_plus = (h_inode->i_nlink > 0);
8319 + if (inode && ibs <= bindex && bindex <= ibe)
8320 + h_cached_inode = au_h_iptr(inode, bindex);
8323 + if (unlikely(plus != h_plus && !tmpfile))
8326 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8328 + && !IS_ROOT(h_dentry)
8329 + && unhashed != d_unhashed(h_dentry)))
8332 + if (unlikely(mode != h_mode
8333 + || h_cached_inode != h_inode))
8346 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8347 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8350 + struct dentry *parent;
8352 + if (!au_digen_test(dentry, sigen))
8355 + parent = dget_parent(dentry);
8356 + di_read_lock_parent(parent, AuLock_IR);
8357 + AuDebugOn(au_digen_test(parent, sigen));
8358 + au_dbg_verify_gen(parent, sigen);
8359 + err = au_refresh_dentry(dentry, parent);
8360 + di_read_unlock(parent, AuLock_IR);
8366 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8369 + struct dentry *d, *parent;
8370 + struct inode *inode;
8372 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8373 + return simple_reval_dpath(dentry, sigen);
8375 + /* slow loop, keep it simple and stupid */
8376 + /* cf: au_cpup_dirs() */
8379 + while (au_digen_test(dentry, sigen)) {
8383 + parent = dget_parent(d);
8384 + if (!au_digen_test(parent, sigen))
8389 + inode = d->d_inode;
8391 + di_write_lock_child2(d);
8393 + /* someone might update our dentry while we were sleeping */
8394 + if (au_digen_test(d, sigen)) {
8396 + * todo: consolidate with simple_reval_dpath(),
8397 + * do_refresh() and au_reval_for_attr().
8399 + di_read_lock_parent(parent, AuLock_IR);
8400 + err = au_refresh_dentry(d, parent);
8401 + di_read_unlock(parent, AuLock_IR);
8405 + di_write_unlock(d);
8407 + if (unlikely(err))
8415 + * if valid returns 1, otherwise 0.
8417 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8420 + unsigned int sigen;
8421 + unsigned char do_udba;
8422 + struct super_block *sb;
8423 + struct inode *inode;
8425 + /* todo: support rcu-walk? */
8426 + if (flags & LOOKUP_RCU)
8430 + if (unlikely(!au_di(dentry)))
8434 + sb = dentry->d_sb;
8437 + * i_mutex of parent dir may be held,
8438 + * but we should not return 'invalid' due to busy.
8440 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8441 + if (unlikely(err)) {
8446 + inode = dentry->d_inode;
8447 + if (unlikely(inode && is_bad_inode(inode))) {
8452 + if (unlikely(au_dbrange_test(dentry))) {
8458 + sigen = au_sigen(sb);
8459 + if (au_digen_test(dentry, sigen)) {
8460 + AuDebugOn(IS_ROOT(dentry));
8461 + err = au_reval_dpath(dentry, sigen);
8462 + if (unlikely(err)) {
8467 + di_downgrade_lock(dentry, AuLock_IR);
8470 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8472 + && !(inode->i_state && I_LINKABLE)
8473 + && (IS_DEADDIR(inode) || !inode->i_nlink))
8476 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8477 + if (do_udba && inode) {
8478 + aufs_bindex_t bstart = au_ibstart(inode);
8479 + struct inode *h_inode;
8481 + if (bstart >= 0) {
8482 + h_inode = au_h_iptr(inode, bstart);
8483 + if (h_inode && au_test_higen(inode, h_inode))
8488 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8489 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8491 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8497 + di_downgrade_lock(dentry, AuLock_IR);
8499 + aufs_read_unlock(dentry, AuLock_IR);
8504 + AuDbg("%pd invalid, %d\n", dentry, valid);
8510 +static void aufs_d_release(struct dentry *dentry)
8512 + if (au_di(dentry)) {
8513 + au_di_fin(dentry);
8514 + au_hn_di_reinit(dentry);
8518 +const struct dentry_operations aufs_dop = {
8519 + .d_revalidate = aufs_d_revalidate,
8520 + .d_weak_revalidate = aufs_d_revalidate,
8521 + .d_release = aufs_d_release
8523 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8524 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8525 +++ linux/fs/aufs/dentry.h 2015-01-25 13:00:38.631047076 +0100
8528 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8530 + * This program, aufs is free software; you can redistribute it and/or modify
8531 + * it under the terms of the GNU General Public License as published by
8532 + * the Free Software Foundation; either version 2 of the License, or
8533 + * (at your option) any later version.
8535 + * This program is distributed in the hope that it will be useful,
8536 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8537 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8538 + * GNU General Public License for more details.
8540 + * You should have received a copy of the GNU General Public License
8541 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8545 + * lookup and dentry operations
8548 +#ifndef __AUFS_DENTRY_H__
8549 +#define __AUFS_DENTRY_H__
8553 +#include <linux/dcache.h>
8556 +struct au_hdentry {
8557 + struct dentry *hd_dentry;
8558 + aufs_bindex_t hd_id;
8562 + atomic_t di_generation;
8564 + struct au_rwsem di_rwsem;
8565 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8566 + unsigned char di_tmpfile; /* to allow the different name */
8567 + struct au_hdentry *di_hdentry;
8568 +} ____cacheline_aligned_in_smp;
8570 +/* ---------------------------------------------------------------------- */
8573 +extern const struct dentry_operations aufs_dop;
8575 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8576 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8577 + struct dentry *h_parent, struct au_branch *br);
8579 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8580 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8581 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8582 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8585 +void au_di_init_once(void *_di);
8586 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8587 +void au_di_free(struct au_dinfo *dinfo);
8588 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8589 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8590 +int au_di_init(struct dentry *dentry);
8591 +void au_di_fin(struct dentry *dentry);
8592 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8594 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8595 +void di_read_unlock(struct dentry *d, int flags);
8596 +void di_downgrade_lock(struct dentry *d, int flags);
8597 +void di_write_lock(struct dentry *d, unsigned int lsc);
8598 +void di_write_unlock(struct dentry *d);
8599 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8600 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8601 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8603 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8604 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8605 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8606 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8608 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8609 + struct dentry *h_dentry);
8610 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8611 +int au_dbrange_test(struct dentry *dentry);
8612 +void au_update_digen(struct dentry *dentry);
8613 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8614 +void au_update_dbstart(struct dentry *dentry);
8615 +void au_update_dbend(struct dentry *dentry);
8616 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8618 +/* ---------------------------------------------------------------------- */
8620 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8622 + return dentry->d_fsdata;
8625 +/* ---------------------------------------------------------------------- */
8627 +/* lock subclass for dinfo */
8629 + AuLsc_DI_CHILD, /* child first */
8630 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8631 + AuLsc_DI_CHILD3, /* copyup dirs */
8635 + AuLsc_DI_TMP /* temp for replacing dinfo */
8639 + * di_read_lock_child, di_write_lock_child,
8640 + * di_read_lock_child2, di_write_lock_child2,
8641 + * di_read_lock_child3, di_write_lock_child3,
8642 + * di_read_lock_parent, di_write_lock_parent,
8643 + * di_read_lock_parent2, di_write_lock_parent2,
8644 + * di_read_lock_parent3, di_write_lock_parent3,
8646 +#define AuReadLockFunc(name, lsc) \
8647 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8648 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8650 +#define AuWriteLockFunc(name, lsc) \
8651 +static inline void di_write_lock_##name(struct dentry *d) \
8652 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8654 +#define AuRWLockFuncs(name, lsc) \
8655 + AuReadLockFunc(name, lsc) \
8656 + AuWriteLockFunc(name, lsc)
8658 +AuRWLockFuncs(child, CHILD);
8659 +AuRWLockFuncs(child2, CHILD2);
8660 +AuRWLockFuncs(child3, CHILD3);
8661 +AuRWLockFuncs(parent, PARENT);
8662 +AuRWLockFuncs(parent2, PARENT2);
8663 +AuRWLockFuncs(parent3, PARENT3);
8665 +#undef AuReadLockFunc
8666 +#undef AuWriteLockFunc
8667 +#undef AuRWLockFuncs
8669 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8670 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8671 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8673 +/* ---------------------------------------------------------------------- */
8675 +/* todo: memory barrier? */
8676 +static inline unsigned int au_digen(struct dentry *d)
8678 + return atomic_read(&au_di(d)->di_generation);
8681 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8683 + hdentry->hd_dentry = NULL;
8686 +static inline void au_hdput(struct au_hdentry *hd)
8689 + dput(hd->hd_dentry);
8692 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8694 + DiMustAnyLock(dentry);
8695 + return au_di(dentry)->di_bstart;
8698 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8700 + DiMustAnyLock(dentry);
8701 + return au_di(dentry)->di_bend;
8704 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8706 + DiMustAnyLock(dentry);
8707 + return au_di(dentry)->di_bwh;
8710 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8712 + DiMustAnyLock(dentry);
8713 + return au_di(dentry)->di_bdiropq;
8716 +/* todo: hard/soft set? */
8717 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8719 + DiMustWriteLock(dentry);
8720 + au_di(dentry)->di_bstart = bindex;
8723 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8725 + DiMustWriteLock(dentry);
8726 + au_di(dentry)->di_bend = bindex;
8729 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8731 + DiMustWriteLock(dentry);
8732 + /* dbwh can be outside of bstart - bend range */
8733 + au_di(dentry)->di_bwh = bindex;
8736 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8738 + DiMustWriteLock(dentry);
8739 + au_di(dentry)->di_bdiropq = bindex;
8742 +/* ---------------------------------------------------------------------- */
8744 +#ifdef CONFIG_AUFS_HNOTIFY
8745 +static inline void au_digen_dec(struct dentry *d)
8747 + atomic_dec(&au_di(d)->di_generation);
8750 +static inline void au_hn_di_reinit(struct dentry *dentry)
8752 + dentry->d_fsdata = NULL;
8755 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8756 +#endif /* CONFIG_AUFS_HNOTIFY */
8758 +#endif /* __KERNEL__ */
8759 +#endif /* __AUFS_DENTRY_H__ */
8760 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8761 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8762 +++ linux/fs/aufs/dinfo.c 2015-01-25 13:00:38.631047076 +0100
8765 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8767 + * This program, aufs is free software; you can redistribute it and/or modify
8768 + * it under the terms of the GNU General Public License as published by
8769 + * the Free Software Foundation; either version 2 of the License, or
8770 + * (at your option) any later version.
8772 + * This program is distributed in the hope that it will be useful,
8773 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8774 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8775 + * GNU General Public License for more details.
8777 + * You should have received a copy of the GNU General Public License
8778 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8782 + * dentry private data
8787 +void au_di_init_once(void *_dinfo)
8789 + struct au_dinfo *dinfo = _dinfo;
8790 + static struct lock_class_key aufs_di;
8792 + au_rw_init(&dinfo->di_rwsem);
8793 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8796 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8798 + struct au_dinfo *dinfo;
8801 + dinfo = au_cache_alloc_dinfo();
8802 + if (unlikely(!dinfo))
8805 + nbr = au_sbend(sb) + 1;
8808 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8809 + if (dinfo->di_hdentry) {
8810 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8811 + dinfo->di_bstart = -1;
8812 + dinfo->di_bend = -1;
8813 + dinfo->di_bwh = -1;
8814 + dinfo->di_bdiropq = -1;
8815 + dinfo->di_tmpfile = 0;
8816 + for (i = 0; i < nbr; i++)
8817 + dinfo->di_hdentry[i].hd_id = -1;
8821 + au_cache_free_dinfo(dinfo);
8828 +void au_di_free(struct au_dinfo *dinfo)
8830 + struct au_hdentry *p;
8831 + aufs_bindex_t bend, bindex;
8833 + /* dentry may not be revalidated */
8834 + bindex = dinfo->di_bstart;
8835 + if (bindex >= 0) {
8836 + bend = dinfo->di_bend;
8837 + p = dinfo->di_hdentry + bindex;
8838 + while (bindex++ <= bend)
8841 + kfree(dinfo->di_hdentry);
8842 + au_cache_free_dinfo(dinfo);
8845 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8847 + struct au_hdentry *p;
8850 + AuRwMustWriteLock(&a->di_rwsem);
8851 + AuRwMustWriteLock(&b->di_rwsem);
8853 +#define DiSwap(v, name) \
8855 + v = a->di_##name; \
8856 + a->di_##name = b->di_##name; \
8857 + b->di_##name = v; \
8860 + DiSwap(p, hdentry);
8861 + DiSwap(bi, bstart);
8864 + DiSwap(bi, bdiropq);
8870 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8872 + AuRwMustWriteLock(&dst->di_rwsem);
8873 + AuRwMustWriteLock(&src->di_rwsem);
8875 + dst->di_bstart = src->di_bstart;
8876 + dst->di_bend = src->di_bend;
8877 + dst->di_bwh = src->di_bwh;
8878 + dst->di_bdiropq = src->di_bdiropq;
8882 +int au_di_init(struct dentry *dentry)
8885 + struct super_block *sb;
8886 + struct au_dinfo *dinfo;
8889 + sb = dentry->d_sb;
8890 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8892 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8893 + /* smp_mb(); */ /* atomic_set */
8894 + dentry->d_fsdata = dinfo;
8901 +void au_di_fin(struct dentry *dentry)
8903 + struct au_dinfo *dinfo;
8905 + dinfo = au_di(dentry);
8906 + AuRwDestroy(&dinfo->di_rwsem);
8907 + au_di_free(dinfo);
8910 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8913 + struct au_hdentry *hdp;
8915 + AuRwMustWriteLock(&dinfo->di_rwsem);
8918 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8920 + sz = sizeof(*hdp);
8921 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8923 + dinfo->di_hdentry = hdp;
8930 +/* ---------------------------------------------------------------------- */
8932 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8935 + case AuLsc_DI_CHILD:
8936 + ii_write_lock_child(inode);
8938 + case AuLsc_DI_CHILD2:
8939 + ii_write_lock_child2(inode);
8941 + case AuLsc_DI_CHILD3:
8942 + ii_write_lock_child3(inode);
8944 + case AuLsc_DI_PARENT:
8945 + ii_write_lock_parent(inode);
8947 + case AuLsc_DI_PARENT2:
8948 + ii_write_lock_parent2(inode);
8950 + case AuLsc_DI_PARENT3:
8951 + ii_write_lock_parent3(inode);
8958 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8961 + case AuLsc_DI_CHILD:
8962 + ii_read_lock_child(inode);
8964 + case AuLsc_DI_CHILD2:
8965 + ii_read_lock_child2(inode);
8967 + case AuLsc_DI_CHILD3:
8968 + ii_read_lock_child3(inode);
8970 + case AuLsc_DI_PARENT:
8971 + ii_read_lock_parent(inode);
8973 + case AuLsc_DI_PARENT2:
8974 + ii_read_lock_parent2(inode);
8976 + case AuLsc_DI_PARENT3:
8977 + ii_read_lock_parent3(inode);
8984 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
8986 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8988 + if (au_ftest_lock(flags, IW))
8989 + do_ii_write_lock(d->d_inode, lsc);
8990 + else if (au_ftest_lock(flags, IR))
8991 + do_ii_read_lock(d->d_inode, lsc);
8995 +void di_read_unlock(struct dentry *d, int flags)
8998 + if (au_ftest_lock(flags, IW)) {
8999 + au_dbg_verify_dinode(d);
9000 + ii_write_unlock(d->d_inode);
9001 + } else if (au_ftest_lock(flags, IR)) {
9002 + au_dbg_verify_dinode(d);
9003 + ii_read_unlock(d->d_inode);
9006 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9009 +void di_downgrade_lock(struct dentry *d, int flags)
9011 + if (d->d_inode && au_ftest_lock(flags, IR))
9012 + ii_downgrade_lock(d->d_inode);
9013 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9016 +void di_write_lock(struct dentry *d, unsigned int lsc)
9018 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9020 + do_ii_write_lock(d->d_inode, lsc);
9023 +void di_write_unlock(struct dentry *d)
9025 + au_dbg_verify_dinode(d);
9027 + ii_write_unlock(d->d_inode);
9028 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9031 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9033 + AuDebugOn(d1 == d2
9034 + || d1->d_inode == d2->d_inode
9035 + || d1->d_sb != d2->d_sb);
9037 + if (isdir && au_test_subdir(d1, d2)) {
9038 + di_write_lock_child(d1);
9039 + di_write_lock_child2(d2);
9041 + /* there should be no races */
9042 + di_write_lock_child(d2);
9043 + di_write_lock_child2(d1);
9047 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9049 + AuDebugOn(d1 == d2
9050 + || d1->d_inode == d2->d_inode
9051 + || d1->d_sb != d2->d_sb);
9053 + if (isdir && au_test_subdir(d1, d2)) {
9054 + di_write_lock_parent(d1);
9055 + di_write_lock_parent2(d2);
9057 + /* there should be no races */
9058 + di_write_lock_parent(d2);
9059 + di_write_lock_parent2(d1);
9063 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9065 + di_write_unlock(d1);
9066 + if (d1->d_inode == d2->d_inode)
9067 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9069 + di_write_unlock(d2);
9072 +/* ---------------------------------------------------------------------- */
9074 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9078 + DiMustAnyLock(dentry);
9080 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
9082 + AuDebugOn(bindex < 0);
9083 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
9084 + AuDebugOn(d && au_dcount(d) <= 0);
9089 + * extended version of au_h_dptr().
9090 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9093 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9095 + struct dentry *h_dentry;
9096 + struct inode *inode, *h_inode;
9098 + inode = dentry->d_inode;
9099 + AuDebugOn(!inode);
9102 + if (au_dbstart(dentry) <= bindex
9103 + && bindex <= au_dbend(dentry))
9104 + h_dentry = au_h_dptr(dentry, bindex);
9105 + if (h_dentry && !au_d_linkable(h_dentry)) {
9107 + goto out; /* success */
9110 + AuDebugOn(bindex < au_ibstart(inode));
9111 + AuDebugOn(au_ibend(inode) < bindex);
9112 + h_inode = au_h_iptr(inode, bindex);
9113 + h_dentry = d_find_alias(h_inode);
9115 + if (!IS_ERR(h_dentry)) {
9116 + if (!au_d_linkable(h_dentry))
9117 + goto out; /* success */
9123 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9124 + h_dentry = au_plink_lkup(inode, bindex);
9125 + AuDebugOn(!h_dentry);
9126 + if (!IS_ERR(h_dentry)) {
9127 + if (!au_d_hashed_positive(h_dentry))
9128 + goto out; /* success */
9135 + AuDbgDentry(h_dentry);
9139 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9141 + aufs_bindex_t bend, bwh;
9143 + bend = au_dbend(dentry);
9145 + bwh = au_dbwh(dentry);
9148 + if (0 < bwh && bwh < bend)
9154 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9156 + aufs_bindex_t bend, bopq;
9158 + bend = au_dbtail(dentry);
9160 + bopq = au_dbdiropq(dentry);
9161 + if (0 <= bopq && bopq < bend)
9167 +/* ---------------------------------------------------------------------- */
9169 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9170 + struct dentry *h_dentry)
9172 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9173 + struct au_branch *br;
9175 + DiMustWriteLock(dentry);
9178 + hd->hd_dentry = h_dentry;
9180 + br = au_sbr(dentry->d_sb, bindex);
9181 + hd->hd_id = br->br_id;
9185 +int au_dbrange_test(struct dentry *dentry)
9188 + aufs_bindex_t bstart, bend;
9191 + bstart = au_dbstart(dentry);
9192 + bend = au_dbend(dentry);
9194 + AuDebugOn(bend < 0 && bstart > bend);
9197 + AuDebugOn(bend >= 0);
9203 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9208 + if (unlikely(au_digen(dentry) != sigen
9209 + || au_iigen_test(dentry->d_inode, sigen)))
9215 +void au_update_digen(struct dentry *dentry)
9217 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9218 + /* smp_mb(); */ /* atomic_set */
9221 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9223 + struct au_dinfo *dinfo;
9224 + struct dentry *h_d;
9225 + struct au_hdentry *hdp;
9227 + DiMustWriteLock(dentry);
9229 + dinfo = au_di(dentry);
9230 + if (!dinfo || dinfo->di_bstart < 0)
9233 + hdp = dinfo->di_hdentry;
9234 + if (do_put_zero) {
9235 + aufs_bindex_t bindex, bend;
9237 + bend = dinfo->di_bend;
9238 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9239 + h_d = hdp[0 + bindex].hd_dentry;
9240 + if (h_d && !h_d->d_inode)
9241 + au_set_h_dptr(dentry, bindex, NULL);
9245 + dinfo->di_bstart = -1;
9246 + while (++dinfo->di_bstart <= dinfo->di_bend)
9247 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9249 + if (dinfo->di_bstart > dinfo->di_bend) {
9250 + dinfo->di_bstart = -1;
9251 + dinfo->di_bend = -1;
9256 + while (0 <= --dinfo->di_bend)
9257 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9259 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9262 +void au_update_dbstart(struct dentry *dentry)
9264 + aufs_bindex_t bindex, bend;
9265 + struct dentry *h_dentry;
9267 + bend = au_dbend(dentry);
9268 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9269 + h_dentry = au_h_dptr(dentry, bindex);
9272 + if (h_dentry->d_inode) {
9273 + au_set_dbstart(dentry, bindex);
9276 + au_set_h_dptr(dentry, bindex, NULL);
9280 +void au_update_dbend(struct dentry *dentry)
9282 + aufs_bindex_t bindex, bstart;
9283 + struct dentry *h_dentry;
9285 + bstart = au_dbstart(dentry);
9286 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9287 + h_dentry = au_h_dptr(dentry, bindex);
9290 + if (h_dentry->d_inode) {
9291 + au_set_dbend(dentry, bindex);
9294 + au_set_h_dptr(dentry, bindex, NULL);
9298 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9300 + aufs_bindex_t bindex, bend;
9302 + bend = au_dbend(dentry);
9303 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9304 + if (au_h_dptr(dentry, bindex) == h_dentry)
9308 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9309 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9310 +++ linux/fs/aufs/dir.c 2015-01-25 13:00:38.631047076 +0100
9313 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9315 + * This program, aufs is free software; you can redistribute it and/or modify
9316 + * it under the terms of the GNU General Public License as published by
9317 + * the Free Software Foundation; either version 2 of the License, or
9318 + * (at your option) any later version.
9320 + * This program is distributed in the hope that it will be useful,
9321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9323 + * GNU General Public License for more details.
9325 + * You should have received a copy of the GNU General Public License
9326 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9330 + * directory operations
9333 +#include <linux/fs_stack.h>
9336 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9338 + unsigned int nlink;
9340 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9342 + nlink = dir->i_nlink;
9343 + nlink += h_dir->i_nlink - 2;
9344 + if (h_dir->i_nlink < 2)
9346 + smp_mb(); /* for i_nlink */
9347 + /* 0 can happen in revaliding */
9348 + set_nlink(dir, nlink);
9351 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9353 + unsigned int nlink;
9355 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9357 + nlink = dir->i_nlink;
9358 + nlink -= h_dir->i_nlink - 2;
9359 + if (h_dir->i_nlink < 2)
9361 + smp_mb(); /* for i_nlink */
9362 + /* nlink == 0 means the branch-fs is broken */
9363 + set_nlink(dir, nlink);
9366 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9369 + aufs_bindex_t bindex, bend;
9370 + struct file *h_file;
9371 + struct dentry *h_dentry;
9375 + AuDebugOn(!file_inode(file));
9376 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
9378 + bend = au_fbend_dir(file);
9379 + for (bindex = au_fbstart(file);
9380 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9382 + h_file = au_hf_dir(file, bindex);
9383 + if (h_file && file_inode(h_file))
9384 + sz += vfsub_f_size_read(h_file);
9387 + AuDebugOn(!dentry);
9388 + AuDebugOn(!dentry->d_inode);
9389 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
9391 + bend = au_dbtaildir(dentry);
9392 + for (bindex = au_dbstart(dentry);
9393 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9395 + h_dentry = au_h_dptr(dentry, bindex);
9396 + if (h_dentry && h_dentry->d_inode)
9397 + sz += i_size_read(h_dentry->d_inode);
9400 + if (sz < KMALLOC_MAX_SIZE)
9401 + sz = roundup_pow_of_two(sz);
9402 + if (sz > KMALLOC_MAX_SIZE)
9403 + sz = KMALLOC_MAX_SIZE;
9404 + else if (sz < NAME_MAX) {
9405 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9406 + sz = AUFS_RDBLK_DEF;
9411 +/* ---------------------------------------------------------------------- */
9413 +static int reopen_dir(struct file *file)
9416 + unsigned int flags;
9417 + aufs_bindex_t bindex, btail, bstart;
9418 + struct dentry *dentry, *h_dentry;
9419 + struct file *h_file;
9421 + /* open all lower dirs */
9422 + dentry = file->f_dentry;
9423 + bstart = au_dbstart(dentry);
9424 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9425 + au_set_h_fptr(file, bindex, NULL);
9426 + au_set_fbstart(file, bstart);
9428 + btail = au_dbtaildir(dentry);
9429 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9430 + au_set_h_fptr(file, bindex, NULL);
9431 + au_set_fbend_dir(file, btail);
9433 + flags = vfsub_file_flags(file);
9434 + for (bindex = bstart; bindex <= btail; bindex++) {
9435 + h_dentry = au_h_dptr(dentry, bindex);
9438 + h_file = au_hf_dir(file, bindex);
9442 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9443 + err = PTR_ERR(h_file);
9444 + if (IS_ERR(h_file))
9445 + goto out; /* close all? */
9446 + au_set_h_fptr(file, bindex, h_file);
9448 + au_update_figen(file);
9449 + /* todo: necessary? */
9450 + /* file->f_ra = h_file->f_ra; */
9457 +static int do_open_dir(struct file *file, int flags)
9460 + aufs_bindex_t bindex, btail;
9461 + struct dentry *dentry, *h_dentry;
9462 + struct file *h_file;
9464 + FiMustWriteLock(file);
9467 + dentry = file->f_dentry;
9468 + file->f_version = dentry->d_inode->i_version;
9469 + bindex = au_dbstart(dentry);
9470 + au_set_fbstart(file, bindex);
9471 + btail = au_dbtaildir(dentry);
9472 + au_set_fbend_dir(file, btail);
9473 + for (; !err && bindex <= btail; bindex++) {
9474 + h_dentry = au_h_dptr(dentry, bindex);
9478 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9479 + if (IS_ERR(h_file)) {
9480 + err = PTR_ERR(h_file);
9483 + au_set_h_fptr(file, bindex, h_file);
9485 + au_update_figen(file);
9486 + /* todo: necessary? */
9487 + /* file->f_ra = h_file->f_ra; */
9489 + return 0; /* success */
9492 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9493 + au_set_h_fptr(file, bindex, NULL);
9494 + au_set_fbstart(file, -1);
9495 + au_set_fbend_dir(file, -1);
9500 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9501 + struct file *file)
9504 + struct super_block *sb;
9505 + struct au_fidir *fidir;
9508 + sb = file->f_dentry->d_sb;
9509 + si_read_lock(sb, AuLock_FLUSH);
9510 + fidir = au_fidir_alloc(sb);
9512 + err = au_do_open(file, do_open_dir, fidir);
9513 + if (unlikely(err))
9516 + si_read_unlock(sb);
9520 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9521 + struct file *file)
9523 + struct au_vdir *vdir_cache;
9524 + struct au_finfo *finfo;
9525 + struct au_fidir *fidir;
9526 + aufs_bindex_t bindex, bend;
9528 + finfo = au_fi(file);
9529 + fidir = finfo->fi_hdir;
9531 + au_sphl_del(&finfo->fi_hlist,
9532 + &au_sbi(file->f_dentry->d_sb)->si_files);
9533 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9535 + au_vdir_free(vdir_cache);
9537 + bindex = finfo->fi_btop;
9538 + if (bindex >= 0) {
9540 + * calls fput() instead of filp_close(),
9541 + * since no dnotify or lock for the lower file.
9543 + bend = fidir->fd_bbot;
9544 + for (; bindex <= bend; bindex++)
9545 + au_set_h_fptr(file, bindex, NULL);
9548 + finfo->fi_hdir = NULL;
9550 + au_finfo_fin(file);
9554 +/* ---------------------------------------------------------------------- */
9556 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9559 + aufs_bindex_t bindex, bend;
9560 + struct file *h_file;
9563 + bend = au_fbend_dir(file);
9564 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9565 + h_file = au_hf_dir(file, bindex);
9567 + err = vfsub_flush(h_file, id);
9572 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9574 + return au_do_flush(file, id, au_do_flush_dir);
9577 +/* ---------------------------------------------------------------------- */
9579 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9582 + aufs_bindex_t bend, bindex;
9583 + struct inode *inode;
9584 + struct super_block *sb;
9587 + sb = dentry->d_sb;
9588 + inode = dentry->d_inode;
9590 + bend = au_dbend(dentry);
9591 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9592 + struct path h_path;
9594 + if (au_test_ro(sb, bindex, inode))
9596 + h_path.dentry = au_h_dptr(dentry, bindex);
9597 + if (!h_path.dentry)
9600 + h_path.mnt = au_sbr_mnt(sb, bindex);
9601 + err = vfsub_fsync(NULL, &h_path, datasync);
9607 +static int au_do_fsync_dir(struct file *file, int datasync)
9610 + aufs_bindex_t bend, bindex;
9611 + struct file *h_file;
9612 + struct super_block *sb;
9613 + struct inode *inode;
9615 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9616 + if (unlikely(err))
9619 + sb = file->f_dentry->d_sb;
9620 + inode = file_inode(file);
9621 + bend = au_fbend_dir(file);
9622 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9623 + h_file = au_hf_dir(file, bindex);
9624 + if (!h_file || au_test_ro(sb, bindex, inode))
9627 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9635 + * @file may be NULL
9637 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9641 + struct dentry *dentry;
9642 + struct super_block *sb;
9643 + struct mutex *mtx;
9646 + dentry = file->f_dentry;
9647 + mtx = &dentry->d_inode->i_mutex;
9649 + sb = dentry->d_sb;
9650 + si_noflush_read_lock(sb);
9652 + err = au_do_fsync_dir(file, datasync);
9654 + di_write_lock_child(dentry);
9655 + err = au_do_fsync_dir_no_file(dentry, datasync);
9657 + au_cpup_attr_timesizes(dentry->d_inode);
9658 + di_write_unlock(dentry);
9660 + fi_write_unlock(file);
9662 + si_read_unlock(sb);
9663 + mutex_unlock(mtx);
9667 +/* ---------------------------------------------------------------------- */
9669 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9672 + struct dentry *dentry;
9673 + struct inode *inode, *h_inode;
9674 + struct super_block *sb;
9676 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9678 + dentry = file->f_dentry;
9679 + inode = dentry->d_inode;
9682 + sb = dentry->d_sb;
9683 + si_read_lock(sb, AuLock_FLUSH);
9684 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9685 + if (unlikely(err))
9687 + err = au_alive_dir(dentry);
9689 + err = au_vdir_init(file);
9690 + di_downgrade_lock(dentry, AuLock_IR);
9691 + if (unlikely(err))
9694 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9695 + if (!au_test_nfsd()) {
9696 + err = au_vdir_fill_de(file, ctx);
9697 + fsstack_copy_attr_atime(inode, h_inode);
9700 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9701 + * encode_fh() and others.
9703 + atomic_inc(&h_inode->i_count);
9704 + di_read_unlock(dentry, AuLock_IR);
9705 + si_read_unlock(sb);
9706 + err = au_vdir_fill_de(file, ctx);
9707 + fsstack_copy_attr_atime(inode, h_inode);
9708 + fi_write_unlock(file);
9716 + di_read_unlock(dentry, AuLock_IR);
9717 + fi_write_unlock(file);
9719 + si_read_unlock(sb);
9723 +/* ---------------------------------------------------------------------- */
9725 +#define AuTestEmpty_WHONLY 1
9726 +#define AuTestEmpty_CALLED (1 << 1)
9727 +#define AuTestEmpty_SHWH (1 << 2)
9728 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9729 +#define au_fset_testempty(flags, name) \
9730 + do { (flags) |= AuTestEmpty_##name; } while (0)
9731 +#define au_fclr_testempty(flags, name) \
9732 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9734 +#ifndef CONFIG_AUFS_SHWH
9735 +#undef AuTestEmpty_SHWH
9736 +#define AuTestEmpty_SHWH 0
9739 +struct test_empty_arg {
9740 + struct dir_context ctx;
9741 + struct au_nhash *whlist;
9742 + unsigned int flags;
9744 + aufs_bindex_t bindex;
9747 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9748 + int namelen, loff_t offset __maybe_unused, u64 ino,
9749 + unsigned int d_type)
9751 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9753 + char *name = (void *)__name;
9756 + au_fset_testempty(arg->flags, CALLED);
9758 + if (name[0] == '.'
9759 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9760 + goto out; /* success */
9762 + if (namelen <= AUFS_WH_PFX_LEN
9763 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9764 + if (au_ftest_testempty(arg->flags, WHONLY)
9765 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9766 + arg->err = -ENOTEMPTY;
9770 + name += AUFS_WH_PFX_LEN;
9771 + namelen -= AUFS_WH_PFX_LEN;
9772 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9773 + arg->err = au_nhash_append_wh
9774 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9775 + au_ftest_testempty(arg->flags, SHWH));
9779 + AuTraceErr(arg->err);
9783 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9786 + struct file *h_file;
9788 + h_file = au_h_open(dentry, arg->bindex,
9789 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9790 + /*file*/NULL, /*force_wr*/0);
9791 + err = PTR_ERR(h_file);
9792 + if (IS_ERR(h_file))
9796 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9797 + && !file_inode(h_file)->i_nlink)
9802 + au_fclr_testempty(arg->flags, CALLED);
9804 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9807 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9811 + au_sbr_put(dentry->d_sb, arg->bindex);
9816 +struct do_test_empty_args {
9818 + struct dentry *dentry;
9819 + struct test_empty_arg *arg;
9822 +static void call_do_test_empty(void *args)
9824 + struct do_test_empty_args *a = args;
9825 + *a->errp = do_test_empty(a->dentry, a->arg);
9828 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9831 + struct dentry *h_dentry;
9832 + struct inode *h_inode;
9834 + h_dentry = au_h_dptr(dentry, arg->bindex);
9835 + h_inode = h_dentry->d_inode;
9836 + /* todo: i_mode changes anytime? */
9837 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9838 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9839 + mutex_unlock(&h_inode->i_mutex);
9841 + err = do_test_empty(dentry, arg);
9843 + struct do_test_empty_args args = {
9848 + unsigned int flags = arg->flags;
9850 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9851 + if (unlikely(wkq_err))
9853 + arg->flags = flags;
9859 +int au_test_empty_lower(struct dentry *dentry)
9862 + unsigned int rdhash;
9863 + aufs_bindex_t bindex, bstart, btail;
9864 + struct au_nhash whlist;
9865 + struct test_empty_arg arg = {
9867 + .actor = au_diractor(test_empty_cb)
9870 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
9872 + SiMustAnyLock(dentry->d_sb);
9874 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
9876 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
9877 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
9878 + if (unlikely(err))
9882 + arg.whlist = &whlist;
9883 + bstart = au_dbstart(dentry);
9884 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9885 + au_fset_testempty(arg.flags, SHWH);
9886 + test_empty = do_test_empty;
9887 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
9888 + test_empty = sio_test_empty;
9889 + arg.bindex = bstart;
9890 + err = test_empty(dentry, &arg);
9891 + if (unlikely(err))
9894 + au_fset_testempty(arg.flags, WHONLY);
9895 + btail = au_dbtaildir(dentry);
9896 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
9897 + struct dentry *h_dentry;
9899 + h_dentry = au_h_dptr(dentry, bindex);
9900 + if (h_dentry && h_dentry->d_inode) {
9901 + arg.bindex = bindex;
9902 + err = test_empty(dentry, &arg);
9907 + au_nhash_wh_free(&whlist);
9912 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
9915 + struct test_empty_arg arg = {
9917 + .actor = au_diractor(test_empty_cb)
9920 + aufs_bindex_t bindex, btail;
9923 + arg.whlist = whlist;
9924 + arg.flags = AuTestEmpty_WHONLY;
9925 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9926 + au_fset_testempty(arg.flags, SHWH);
9927 + btail = au_dbtaildir(dentry);
9928 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
9929 + struct dentry *h_dentry;
9931 + h_dentry = au_h_dptr(dentry, bindex);
9932 + if (h_dentry && h_dentry->d_inode) {
9933 + arg.bindex = bindex;
9934 + err = sio_test_empty(dentry, &arg);
9941 +/* ---------------------------------------------------------------------- */
9943 +const struct file_operations aufs_dir_fop = {
9944 + .owner = THIS_MODULE,
9945 + .llseek = default_llseek,
9946 + .read = generic_read_dir,
9947 + .iterate = aufs_iterate,
9948 + .unlocked_ioctl = aufs_ioctl_dir,
9949 +#ifdef CONFIG_COMPAT
9950 + .compat_ioctl = aufs_compat_ioctl_dir,
9952 + .open = aufs_open_dir,
9953 + .release = aufs_release_dir,
9954 + .flush = aufs_flush_dir,
9955 + .fsync = aufs_fsync_dir
9957 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
9958 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
9959 +++ linux/fs/aufs/dir.h 2015-01-25 13:00:38.631047076 +0100
9962 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9964 + * This program, aufs is free software; you can redistribute it and/or modify
9965 + * it under the terms of the GNU General Public License as published by
9966 + * the Free Software Foundation; either version 2 of the License, or
9967 + * (at your option) any later version.
9969 + * This program is distributed in the hope that it will be useful,
9970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9972 + * GNU General Public License for more details.
9974 + * You should have received a copy of the GNU General Public License
9975 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9979 + * directory operations
9982 +#ifndef __AUFS_DIR_H__
9983 +#define __AUFS_DIR_H__
9987 +#include <linux/fs.h>
9989 +/* ---------------------------------------------------------------------- */
9991 +/* need to be faster and smaller */
9994 + unsigned int nh_num;
9995 + struct hlist_head *nh_head;
9998 +struct au_vdir_destr {
9999 + unsigned char len;
10000 + unsigned char name[0];
10003 +struct au_vdir_dehstr {
10004 + struct hlist_node hash;
10005 + struct au_vdir_destr *str;
10006 +} ____cacheline_aligned_in_smp;
10008 +struct au_vdir_de {
10010 + unsigned char de_type;
10011 + /* caution: packed */
10012 + struct au_vdir_destr de_str;
10015 +struct au_vdir_wh {
10016 + struct hlist_node wh_hash;
10017 +#ifdef CONFIG_AUFS_SHWH
10019 + aufs_bindex_t wh_bindex;
10020 + unsigned char wh_type;
10022 + aufs_bindex_t wh_bindex;
10024 + /* caution: packed */
10025 + struct au_vdir_destr wh_str;
10028 +union au_vdir_deblk_p {
10029 + unsigned char *deblk;
10030 + struct au_vdir_de *de;
10034 + unsigned char **vd_deblk;
10035 + unsigned long vd_nblk;
10037 + unsigned long ul;
10038 + union au_vdir_deblk_p p;
10041 + unsigned long vd_version;
10042 + unsigned int vd_deblk_sz;
10043 + unsigned long vd_jiffy;
10044 +} ____cacheline_aligned_in_smp;
10046 +/* ---------------------------------------------------------------------- */
10049 +extern const struct file_operations aufs_dir_fop;
10050 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10051 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10052 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10053 +int au_test_empty_lower(struct dentry *dentry);
10054 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10057 +unsigned int au_rdhash_est(loff_t sz);
10058 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10059 +void au_nhash_wh_free(struct au_nhash *whlist);
10060 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10062 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10063 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10064 + unsigned int d_type, aufs_bindex_t bindex,
10065 + unsigned char shwh);
10066 +void au_vdir_free(struct au_vdir *vdir);
10067 +int au_vdir_init(struct file *file);
10068 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10071 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10073 +#ifdef CONFIG_AUFS_RDU
10075 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10076 +#ifdef CONFIG_COMPAT
10077 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10078 + unsigned long arg);
10081 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10082 + unsigned int cmd, unsigned long arg)
10083 +#ifdef CONFIG_COMPAT
10084 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10085 + unsigned int cmd, unsigned long arg)
10089 +#endif /* __KERNEL__ */
10090 +#endif /* __AUFS_DIR_H__ */
10091 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10092 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10093 +++ linux/fs/aufs/dynop.c 2015-01-25 13:00:38.631047076 +0100
10096 + * Copyright (C) 2010-2014 Junjiro R. Okajima
10098 + * This program, aufs is free software; you can redistribute it and/or modify
10099 + * it under the terms of the GNU General Public License as published by
10100 + * the Free Software Foundation; either version 2 of the License, or
10101 + * (at your option) any later version.
10103 + * This program is distributed in the hope that it will be useful,
10104 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10105 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10106 + * GNU General Public License for more details.
10108 + * You should have received a copy of the GNU General Public License
10109 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10113 + * dynamically customizable operations for regular files
10118 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10121 + * How large will these lists be?
10122 + * Usually just a few elements, 20-30 at most for each, I guess.
10124 +static struct au_splhead dynop[AuDyLast];
10126 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
10128 + struct au_dykey *key, *tmp;
10129 + struct list_head *head;
10132 + head = &spl->head;
10134 + list_for_each_entry_rcu(tmp, head, dk_list)
10135 + if (tmp->dk_op.dy_hop == h_op) {
10137 + kref_get(&key->dk_kref);
10140 + rcu_read_unlock();
10145 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10147 + struct au_dykey **k, *found;
10148 + const void *h_op = key->dk_op.dy_hop;
10152 + k = br->br_dykey;
10153 + for (i = 0; i < AuBrDynOp; i++)
10155 + if (k[i]->dk_op.dy_hop == h_op) {
10162 + spin_lock(&br->br_dykey_lock);
10163 + for (; i < AuBrDynOp; i++)
10165 + if (k[i]->dk_op.dy_hop == h_op) {
10173 + spin_unlock(&br->br_dykey_lock);
10174 + BUG_ON(i == AuBrDynOp); /* expand the array */
10180 +/* kref_get() if @key is already added */
10181 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10183 + struct au_dykey *tmp, *found;
10184 + struct list_head *head;
10185 + const void *h_op = key->dk_op.dy_hop;
10188 + head = &spl->head;
10189 + spin_lock(&spl->spin);
10190 + list_for_each_entry(tmp, head, dk_list)
10191 + if (tmp->dk_op.dy_hop == h_op) {
10192 + kref_get(&tmp->dk_kref);
10197 + list_add_rcu(&key->dk_list, head);
10198 + spin_unlock(&spl->spin);
10205 +static void dy_free_rcu(struct rcu_head *rcu)
10207 + struct au_dykey *key;
10209 + key = container_of(rcu, struct au_dykey, dk_rcu);
10214 +static void dy_free(struct kref *kref)
10216 + struct au_dykey *key;
10217 + struct au_splhead *spl;
10219 + key = container_of(kref, struct au_dykey, dk_kref);
10220 + spl = dynop + key->dk_op.dy_type;
10221 + au_spl_del_rcu(&key->dk_list, spl);
10222 + call_rcu(&key->dk_rcu, dy_free_rcu);
10225 +void au_dy_put(struct au_dykey *key)
10227 + kref_put(&key->dk_kref, dy_free);
10230 +/* ---------------------------------------------------------------------- */
10232 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10234 +#ifdef CONFIG_AUFS_DEBUG
10235 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10236 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10238 +#define DyDbgDeclare(cnt) do {} while (0)
10239 +#define DyDbgInc(cnt) do {} while (0)
10242 +#define DySet(func, dst, src, h_op, h_sb) do { \
10244 + if (h_op->func) { \
10246 + dst.func = src.func; \
10248 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10252 +#define DySetForce(func, dst, src) do { \
10253 + AuDebugOn(!src.func); \
10255 + dst.func = src.func; \
10258 +#define DySetAop(func) \
10259 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10260 +#define DySetAopForce(func) \
10261 + DySetForce(func, dyaop->da_op, aufs_aop)
10263 +static void dy_aop(struct au_dykey *key, const void *h_op,
10264 + struct super_block *h_sb __maybe_unused)
10266 + struct au_dyaop *dyaop = (void *)key;
10267 + const struct address_space_operations *h_aop = h_op;
10268 + DyDbgDeclare(cnt);
10270 + AuDbg("%s\n", au_sbtype(h_sb));
10272 + DySetAop(writepage);
10273 + DySetAopForce(readpage); /* force */
10274 + DySetAop(writepages);
10275 + DySetAop(set_page_dirty);
10276 + DySetAop(readpages);
10277 + DySetAop(write_begin);
10278 + DySetAop(write_end);
10280 + DySetAop(invalidatepage);
10281 + DySetAop(releasepage);
10282 + DySetAop(freepage);
10283 + /* these two will be changed according to an aufs mount option */
10284 + DySetAop(direct_IO);
10285 + DySetAop(get_xip_mem);
10286 + DySetAop(migratepage);
10287 + DySetAop(launder_page);
10288 + DySetAop(is_partially_uptodate);
10289 + DySetAop(is_dirty_writeback);
10290 + DySetAop(error_remove_page);
10291 + DySetAop(swap_activate);
10292 + DySetAop(swap_deactivate);
10294 + DyDbgSize(cnt, *h_aop);
10295 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
10298 +/* ---------------------------------------------------------------------- */
10300 +static void dy_bug(struct kref *kref)
10305 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10307 + struct au_dykey *key, *old;
10308 + struct au_splhead *spl;
10311 + void (*set)(struct au_dykey *key, const void *h_op,
10312 + struct super_block *h_sb __maybe_unused);
10314 + static const struct op a[] = {
10316 + .sz = sizeof(struct au_dyaop),
10320 + const struct op *p;
10322 + spl = dynop + op->dy_type;
10323 + key = dy_gfind_get(spl, op->dy_hop);
10325 + goto out_add; /* success */
10327 + p = a + op->dy_type;
10328 + key = kzalloc(p->sz, GFP_NOFS);
10329 + if (unlikely(!key)) {
10330 + key = ERR_PTR(-ENOMEM);
10334 + key->dk_op.dy_hop = op->dy_hop;
10335 + kref_init(&key->dk_kref);
10336 + p->set(key, op->dy_hop, au_br_sb(br));
10337 + old = dy_gadd(spl, key);
10344 + old = dy_bradd(br, key);
10346 + /* its ref-count should never be zero here */
10347 + kref_put(&key->dk_kref, dy_bug);
10352 +/* ---------------------------------------------------------------------- */
10354 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10355 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10356 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10357 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10358 + * See the aufs manual in detail.
10360 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
10361 + * performance of fadvise() and madvise() may be affected.
10363 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10366 + dyaop->da_op.direct_IO = NULL;
10367 + dyaop->da_op.get_xip_mem = NULL;
10369 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10370 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
10371 + if (!dyaop->da_get_xip_mem)
10372 + dyaop->da_op.get_xip_mem = NULL;
10376 +static struct au_dyaop *dy_aget(struct au_branch *br,
10377 + const struct address_space_operations *h_aop,
10380 + struct au_dyaop *dyaop;
10381 + struct au_dynop op;
10383 + op.dy_type = AuDy_AOP;
10384 + op.dy_haop = h_aop;
10385 + dyaop = (void *)dy_get(&op, br);
10386 + if (IS_ERR(dyaop))
10388 + dy_adx(dyaop, do_dx);
10394 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10395 + struct inode *h_inode)
10398 + struct super_block *sb;
10399 + struct au_branch *br;
10400 + struct au_dyaop *dyaop;
10402 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10403 + IiMustWriteLock(inode);
10405 + sb = inode->i_sb;
10406 + br = au_sbr(sb, bindex);
10407 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10408 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10409 + err = PTR_ERR(dyaop);
10410 + if (IS_ERR(dyaop))
10411 + /* unnecessary to call dy_fput() */
10415 + inode->i_mapping->a_ops = &dyaop->da_op;
10422 + * Is it safe to replace a_ops during the inode/file is in operation?
10423 + * Yes, I hope so.
10425 +int au_dy_irefresh(struct inode *inode)
10428 + aufs_bindex_t bstart;
10429 + struct inode *h_inode;
10432 + if (S_ISREG(inode->i_mode)) {
10433 + bstart = au_ibstart(inode);
10434 + h_inode = au_h_iptr(inode, bstart);
10435 + err = au_dy_iaop(inode, bstart, h_inode);
10440 +void au_dy_arefresh(int do_dx)
10442 + struct au_splhead *spl;
10443 + struct list_head *head;
10444 + struct au_dykey *key;
10446 + spl = dynop + AuDy_AOP;
10447 + head = &spl->head;
10448 + spin_lock(&spl->spin);
10449 + list_for_each_entry(key, head, dk_list)
10450 + dy_adx((void *)key, do_dx);
10451 + spin_unlock(&spl->spin);
10454 +/* ---------------------------------------------------------------------- */
10456 +void __init au_dy_init(void)
10460 + /* make sure that 'struct au_dykey *' can be any type */
10461 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10463 + for (i = 0; i < AuDyLast; i++)
10464 + au_spl_init(dynop + i);
10467 +void au_dy_fin(void)
10471 + for (i = 0; i < AuDyLast; i++)
10472 + WARN_ON(!list_empty(&dynop[i].head));
10474 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10475 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10476 +++ linux/fs/aufs/dynop.h 2015-01-25 13:00:38.631047076 +0100
10479 + * Copyright (C) 2010-2014 Junjiro R. Okajima
10481 + * This program, aufs is free software; you can redistribute it and/or modify
10482 + * it under the terms of the GNU General Public License as published by
10483 + * the Free Software Foundation; either version 2 of the License, or
10484 + * (at your option) any later version.
10486 + * This program is distributed in the hope that it will be useful,
10487 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10488 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10489 + * GNU General Public License for more details.
10491 + * You should have received a copy of the GNU General Public License
10492 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10496 + * dynamically customizable operations (for regular files only)
10499 +#ifndef __AUFS_DYNOP_H__
10500 +#define __AUFS_DYNOP_H__
10504 +#include "inode.h"
10506 +enum {AuDy_AOP, AuDyLast};
10511 + const void *dy_hop;
10512 + const struct address_space_operations *dy_haop;
10518 + struct list_head dk_list;
10519 + struct rcu_head dk_rcu;
10521 + struct au_dynop dk_op;
10524 + * during I am in the branch local array, kref is gotten. when the
10525 + * branch is removed, kref is put.
10527 + struct kref dk_kref;
10530 +/* stop unioning since their sizes are very different from each other */
10532 + struct au_dykey da_key;
10533 + struct address_space_operations da_op; /* not const */
10534 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
10535 + void **, unsigned long *);
10538 +/* ---------------------------------------------------------------------- */
10542 +void au_dy_put(struct au_dykey *key);
10543 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10544 + struct inode *h_inode);
10545 +int au_dy_irefresh(struct inode *inode);
10546 +void au_dy_arefresh(int do_dio);
10548 +void __init au_dy_init(void);
10549 +void au_dy_fin(void);
10551 +#endif /* __KERNEL__ */
10552 +#endif /* __AUFS_DYNOP_H__ */
10553 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10554 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10555 +++ linux/fs/aufs/export.c 2015-01-25 13:00:38.631047076 +0100
10558 + * Copyright (C) 2005-2014 Junjiro R. Okajima
10560 + * This program, aufs is free software; you can redistribute it and/or modify
10561 + * it under the terms of the GNU General Public License as published by
10562 + * the Free Software Foundation; either version 2 of the License, or
10563 + * (at your option) any later version.
10565 + * This program is distributed in the hope that it will be useful,
10566 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10567 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10568 + * GNU General Public License for more details.
10570 + * You should have received a copy of the GNU General Public License
10571 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10578 +#include <linux/exportfs.h>
10579 +#include <linux/fs_struct.h>
10580 +#include <linux/namei.h>
10581 +#include <linux/nsproxy.h>
10582 +#include <linux/random.h>
10583 +#include <linux/writeback.h>
10584 +#include "../fs/mount.h"
10588 +#ifdef CONFIG_AUFS_INO_T_64
10596 +static ino_t decode_ino(__u32 *a)
10600 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10602 +#ifdef CONFIG_AUFS_INO_T_64
10608 +static void encode_ino(__u32 *a, ino_t ino)
10614 +#ifdef CONFIG_AUFS_INO_T_64
10619 +/* NFS file handle */
10623 +#ifdef CONFIG_AUFS_INO_T_64
10624 + /* support 64bit inode number */
10637 + Fh_ino = Fh_ino1,
10638 + Fh_dir_ino = Fh_dir_ino1
10641 +static int au_test_anon(struct dentry *dentry)
10643 + /* note: read d_flags without d_lock */
10644 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10647 +int au_test_nfsd(void)
10650 + struct task_struct *tsk = current;
10651 + char comm[sizeof(tsk->comm)];
10654 + if (tsk->flags & PF_KTHREAD) {
10655 + get_task_comm(comm, tsk);
10656 + ret = !strcmp(comm, "nfsd");
10662 +/* ---------------------------------------------------------------------- */
10663 +/* inode generation external table */
10665 +void au_xigen_inc(struct inode *inode)
10670 + struct super_block *sb;
10671 + struct au_sbinfo *sbinfo;
10673 + sb = inode->i_sb;
10674 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10676 + sbinfo = au_sbi(sb);
10677 + pos = inode->i_ino;
10678 + pos *= sizeof(igen);
10679 + igen = inode->i_generation + 1;
10680 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10681 + sizeof(igen), &pos);
10682 + if (sz == sizeof(igen))
10683 + return; /* success */
10685 + if (unlikely(sz >= 0))
10686 + AuIOErr("xigen error (%zd)\n", sz);
10689 +int au_xigen_new(struct inode *inode)
10694 + struct super_block *sb;
10695 + struct au_sbinfo *sbinfo;
10696 + struct file *file;
10699 + /* todo: dirty, at mount time */
10700 + if (inode->i_ino == AUFS_ROOT_INO)
10702 + sb = inode->i_sb;
10703 + SiMustAnyLock(sb);
10704 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10708 + pos = inode->i_ino;
10709 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10710 + AuIOErr1("too large i%lld\n", pos);
10713 + pos *= sizeof(inode->i_generation);
10716 + sbinfo = au_sbi(sb);
10717 + file = sbinfo->si_xigen;
10720 + if (vfsub_f_size_read(file)
10721 + < pos + sizeof(inode->i_generation)) {
10722 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10723 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10724 + sizeof(inode->i_generation), &pos);
10726 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10727 + sizeof(inode->i_generation), &pos);
10728 + if (sz == sizeof(inode->i_generation))
10729 + goto out; /* success */
10732 + if (unlikely(sz >= 0)) {
10734 + AuIOErr("xigen error (%zd)\n", sz);
10741 +int au_xigen_set(struct super_block *sb, struct file *base)
10744 + struct au_sbinfo *sbinfo;
10745 + struct file *file;
10747 + SiMustWriteLock(sb);
10749 + sbinfo = au_sbi(sb);
10750 + file = au_xino_create2(base, sbinfo->si_xigen);
10751 + err = PTR_ERR(file);
10752 + if (IS_ERR(file))
10755 + if (sbinfo->si_xigen)
10756 + fput(sbinfo->si_xigen);
10757 + sbinfo->si_xigen = file;
10763 +void au_xigen_clr(struct super_block *sb)
10765 + struct au_sbinfo *sbinfo;
10767 + SiMustWriteLock(sb);
10769 + sbinfo = au_sbi(sb);
10770 + if (sbinfo->si_xigen) {
10771 + fput(sbinfo->si_xigen);
10772 + sbinfo->si_xigen = NULL;
10776 +/* ---------------------------------------------------------------------- */
10778 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10781 + struct dentry *dentry, *d;
10782 + struct inode *inode;
10783 + unsigned int sigen;
10786 + inode = ilookup(sb, ino);
10790 + dentry = ERR_PTR(-ESTALE);
10791 + sigen = au_sigen(sb);
10792 + if (unlikely(is_bad_inode(inode)
10793 + || IS_DEADDIR(inode)
10794 + || sigen != au_iigen(inode, NULL)))
10798 + if (!dir_ino || S_ISDIR(inode->i_mode))
10799 + dentry = d_find_alias(inode);
10801 + spin_lock(&inode->i_lock);
10802 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
10803 + spin_lock(&d->d_lock);
10804 + if (!au_test_anon(d)
10805 + && d->d_parent->d_inode->i_ino == dir_ino) {
10806 + dentry = dget_dlock(d);
10807 + spin_unlock(&d->d_lock);
10810 + spin_unlock(&d->d_lock);
10812 + spin_unlock(&inode->i_lock);
10814 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10815 + /* need to refresh */
10823 + AuTraceErrPtr(dentry);
10827 +/* ---------------------------------------------------------------------- */
10829 +/* todo: dirty? */
10830 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10832 +struct au_compare_mnt_args {
10834 + struct super_block *sb;
10837 + struct vfsmount *mnt;
10840 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10842 + struct au_compare_mnt_args *a = arg;
10844 + if (mnt->mnt_sb != a->sb)
10846 + a->mnt = mntget(mnt);
10850 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10853 + struct path root;
10854 + struct au_compare_mnt_args args = {
10858 + get_fs_root(current->fs, &root);
10860 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10861 + rcu_read_unlock();
10864 + AuDebugOn(!args.mnt);
10868 +struct au_nfsd_si_lock {
10869 + unsigned int sigen;
10870 + aufs_bindex_t bindex, br_id;
10871 + unsigned char force_lock;
10874 +static int si_nfsd_read_lock(struct super_block *sb,
10875 + struct au_nfsd_si_lock *nsi_lock)
10878 + aufs_bindex_t bindex;
10880 + si_read_lock(sb, AuLock_FLUSH);
10882 + /* branch id may be wrapped around */
10884 + bindex = au_br_index(sb, nsi_lock->br_id);
10885 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
10886 + goto out; /* success */
10890 + if (!nsi_lock->force_lock)
10891 + si_read_unlock(sb);
10894 + nsi_lock->bindex = bindex;
10898 +struct find_name_by_ino {
10899 + struct dir_context ctx;
10900 + int called, found;
10907 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
10908 + loff_t offset, u64 ino, unsigned int d_type)
10910 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
10914 + if (a->ino != ino)
10917 + memcpy(a->name, name, namelen);
10918 + a->namelen = namelen;
10923 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
10924 + struct au_nfsd_si_lock *nsi_lock)
10926 + struct dentry *dentry, *parent;
10927 + struct file *file;
10928 + struct inode *dir;
10929 + struct find_name_by_ino arg = {
10931 + .actor = au_diractor(find_name_by_ino)
10936 + parent = path->dentry;
10938 + si_read_unlock(parent->d_sb);
10939 + file = vfsub_dentry_open(path, au_dir_roflags);
10940 + dentry = (void *)file;
10941 + if (IS_ERR(file))
10944 + dentry = ERR_PTR(-ENOMEM);
10945 + arg.name = (void *)__get_free_page(GFP_NOFS);
10946 + if (unlikely(!arg.name))
10953 + err = vfsub_iterate_dir(file, &arg.ctx);
10954 + } while (!err && !arg.found && arg.called);
10955 + dentry = ERR_PTR(err);
10956 + if (unlikely(err))
10958 + /* instead of ENOENT */
10959 + dentry = ERR_PTR(-ESTALE);
10963 + /* do not call vfsub_lkup_one() */
10964 + dir = parent->d_inode;
10965 + mutex_lock(&dir->i_mutex);
10966 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
10967 + mutex_unlock(&dir->i_mutex);
10968 + AuTraceErrPtr(dentry);
10969 + if (IS_ERR(dentry))
10971 + AuDebugOn(au_test_anon(dentry));
10972 + if (unlikely(!dentry->d_inode)) {
10974 + dentry = ERR_PTR(-ENOENT);
10978 + free_page((unsigned long)arg.name);
10982 + if (unlikely(nsi_lock
10983 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10984 + if (!IS_ERR(dentry)) {
10986 + dentry = ERR_PTR(-ESTALE);
10988 + AuTraceErrPtr(dentry);
10992 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
10994 + struct au_nfsd_si_lock *nsi_lock)
10996 + struct dentry *dentry;
10997 + struct path path;
10999 + if (dir_ino != AUFS_ROOT_INO) {
11000 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11001 + dentry = path.dentry;
11002 + if (!path.dentry || IS_ERR(path.dentry))
11004 + AuDebugOn(au_test_anon(path.dentry));
11006 + path.dentry = dget(sb->s_root);
11008 + path.mnt = au_mnt_get(sb);
11009 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11013 + AuTraceErrPtr(dentry);
11017 +/* ---------------------------------------------------------------------- */
11019 +static int h_acceptable(void *expv, struct dentry *dentry)
11024 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11025 + char *buf, int len, struct super_block *sb)
11029 + struct path path;
11031 + p = d_path(h_rootpath, buf, len);
11036 + path.mnt = h_rootpath->mnt;
11037 + path.dentry = h_parent;
11038 + p = d_path(&path, buf, len);
11044 + path.mnt = au_mnt_get(sb);
11045 + path.dentry = sb->s_root;
11046 + p = d_path(&path, buf, len - strlen(p));
11047 + mntput(path.mnt);
11051 + p[strlen(p)] = '/';
11054 + AuTraceErrPtr(p);
11059 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11060 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11062 + struct dentry *dentry, *h_parent, *root;
11063 + struct super_block *h_sb;
11064 + char *pathname, *p;
11065 + struct vfsmount *h_mnt;
11066 + struct au_branch *br;
11068 + struct path path;
11070 + br = au_sbr(sb, nsi_lock->bindex);
11071 + h_mnt = au_br_mnt(br);
11072 + h_sb = h_mnt->mnt_sb;
11073 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11074 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11075 + fh_len - Fh_tail, fh[Fh_h_type],
11076 + h_acceptable, /*context*/NULL);
11077 + dentry = h_parent;
11078 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11079 + AuWarn1("%s decode_fh failed, %ld\n",
11080 + au_sbtype(h_sb), PTR_ERR(h_parent));
11084 + if (unlikely(au_test_anon(h_parent))) {
11085 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11086 + au_sbtype(h_sb));
11087 + goto out_h_parent;
11090 + dentry = ERR_PTR(-ENOMEM);
11091 + pathname = (void *)__get_free_page(GFP_NOFS);
11092 + if (unlikely(!pathname))
11093 + goto out_h_parent;
11095 + root = sb->s_root;
11096 + path.mnt = h_mnt;
11097 + di_read_lock_parent(root, !AuLock_IR);
11098 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11099 + di_read_unlock(root, !AuLock_IR);
11100 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11101 + dentry = (void *)p;
11103 + goto out_pathname;
11105 + si_read_unlock(sb);
11106 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11107 + dentry = ERR_PTR(err);
11108 + if (unlikely(err))
11111 + dentry = ERR_PTR(-ENOENT);
11112 + AuDebugOn(au_test_anon(path.dentry));
11113 + if (unlikely(!path.dentry->d_inode))
11116 + if (ino != path.dentry->d_inode->i_ino)
11117 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11119 + dentry = dget(path.dentry);
11124 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11125 + if (!IS_ERR(dentry)) {
11127 + dentry = ERR_PTR(-ESTALE);
11130 + free_page((unsigned long)pathname);
11134 + AuTraceErrPtr(dentry);
11138 +/* ---------------------------------------------------------------------- */
11140 +static struct dentry *
11141 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11144 + struct dentry *dentry;
11145 + __u32 *fh = fid->raw;
11146 + struct au_branch *br;
11147 + ino_t ino, dir_ino;
11148 + struct au_nfsd_si_lock nsi_lock = {
11152 + dentry = ERR_PTR(-ESTALE);
11153 + /* it should never happen, but the file handle is unreliable */
11154 + if (unlikely(fh_len < Fh_tail))
11156 + nsi_lock.sigen = fh[Fh_sigen];
11157 + nsi_lock.br_id = fh[Fh_br_id];
11159 + /* branch id may be wrapped around */
11161 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11163 + nsi_lock.force_lock = 1;
11165 + /* is this inode still cached? */
11166 + ino = decode_ino(fh + Fh_ino);
11167 + /* it should never happen */
11168 + if (unlikely(ino == AUFS_ROOT_INO))
11171 + dir_ino = decode_ino(fh + Fh_dir_ino);
11172 + dentry = decode_by_ino(sb, ino, dir_ino);
11173 + if (IS_ERR(dentry))
11178 + /* is the parent dir cached? */
11179 + br = au_sbr(sb, nsi_lock.bindex);
11180 + atomic_inc(&br->br_count);
11181 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11182 + if (IS_ERR(dentry))
11187 + /* lookup path */
11188 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11189 + if (IS_ERR(dentry))
11191 + if (unlikely(!dentry))
11192 + /* todo?: make it ESTALE */
11196 + if (!au_digen_test(dentry, au_sigen(sb))
11197 + && dentry->d_inode->i_generation == fh[Fh_igen])
11198 + goto out_unlock; /* success */
11201 + dentry = ERR_PTR(-ESTALE);
11204 + atomic_dec(&br->br_count);
11205 + si_read_unlock(sb);
11207 + AuTraceErrPtr(dentry);
11211 +#if 0 /* reserved for future use */
11212 +/* support subtreecheck option */
11213 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11214 + int fh_len, int fh_type)
11216 + struct dentry *parent;
11217 + __u32 *fh = fid->raw;
11220 + dir_ino = decode_ino(fh + Fh_dir_ino);
11221 + parent = decode_by_ino(sb, dir_ino, 0);
11222 + if (IS_ERR(parent))
11225 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11226 + dir_ino, fh, fh_len);
11229 + AuTraceErrPtr(parent);
11234 +/* ---------------------------------------------------------------------- */
11236 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11237 + struct inode *dir)
11240 + aufs_bindex_t bindex;
11241 + struct super_block *sb, *h_sb;
11242 + struct dentry *dentry, *parent, *h_parent;
11243 + struct inode *h_dir;
11244 + struct au_branch *br;
11247 + if (unlikely(*max_len <= Fh_tail)) {
11248 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11252 + err = FILEID_ROOT;
11253 + if (inode->i_ino == AUFS_ROOT_INO) {
11254 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11259 + sb = inode->i_sb;
11260 + err = si_read_lock(sb, AuLock_FLUSH);
11261 + if (unlikely(err))
11264 +#ifdef CONFIG_AUFS_DEBUG
11265 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11266 + AuWarn1("NFS-exporting requires xino\n");
11270 + ii_read_lock_child(inode);
11271 + bindex = au_ibstart(inode);
11273 + dentry = d_find_any_alias(inode);
11274 + if (unlikely(!dentry))
11276 + AuDebugOn(au_test_anon(dentry));
11277 + parent = dget_parent(dentry);
11279 + if (unlikely(!parent))
11281 + dir = parent->d_inode;
11284 + ii_read_lock_parent(dir);
11285 + h_dir = au_h_iptr(dir, bindex);
11286 + ii_read_unlock(dir);
11287 + if (unlikely(!h_dir))
11289 + h_parent = d_find_any_alias(h_dir);
11290 + if (unlikely(!h_parent))
11291 + goto out_hparent;
11294 + br = au_sbr(sb, bindex);
11295 + h_sb = au_br_sb(br);
11296 + if (unlikely(!h_sb->s_export_op)) {
11297 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11298 + goto out_hparent;
11301 + fh[Fh_br_id] = br->br_id;
11302 + fh[Fh_sigen] = au_sigen(sb);
11303 + encode_ino(fh + Fh_ino, inode->i_ino);
11304 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11305 + fh[Fh_igen] = inode->i_generation;
11307 + *max_len -= Fh_tail;
11308 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11310 + /*connectable or subtreecheck*/0);
11311 + err = fh[Fh_h_type];
11312 + *max_len += Fh_tail;
11313 + /* todo: macros? */
11314 + if (err != FILEID_INVALID)
11317 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11324 + ii_read_unlock(inode);
11325 + si_read_unlock(sb);
11327 + if (unlikely(err < 0))
11328 + err = FILEID_INVALID;
11332 +/* ---------------------------------------------------------------------- */
11334 +static int aufs_commit_metadata(struct inode *inode)
11337 + aufs_bindex_t bindex;
11338 + struct super_block *sb;
11339 + struct inode *h_inode;
11340 + int (*f)(struct inode *inode);
11342 + sb = inode->i_sb;
11343 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11344 + ii_write_lock_child(inode);
11345 + bindex = au_ibstart(inode);
11346 + AuDebugOn(bindex < 0);
11347 + h_inode = au_h_iptr(inode, bindex);
11349 + f = h_inode->i_sb->s_export_op->commit_metadata;
11351 + err = f(h_inode);
11353 + struct writeback_control wbc = {
11354 + .sync_mode = WB_SYNC_ALL,
11355 + .nr_to_write = 0 /* metadata only */
11358 + err = sync_inode(h_inode, &wbc);
11361 + au_cpup_attr_timesizes(inode);
11362 + ii_write_unlock(inode);
11363 + si_read_unlock(sb);
11367 +/* ---------------------------------------------------------------------- */
11369 +static struct export_operations aufs_export_op = {
11370 + .fh_to_dentry = aufs_fh_to_dentry,
11371 + /* .fh_to_parent = aufs_fh_to_parent, */
11372 + .encode_fh = aufs_encode_fh,
11373 + .commit_metadata = aufs_commit_metadata
11376 +void au_export_init(struct super_block *sb)
11378 + struct au_sbinfo *sbinfo;
11381 + sb->s_export_op = &aufs_export_op;
11382 + sbinfo = au_sbi(sb);
11383 + sbinfo->si_xigen = NULL;
11384 + get_random_bytes(&u, sizeof(u));
11385 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11386 + atomic_set(&sbinfo->si_xigen_next, u);
11388 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11389 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11390 +++ linux/fs/aufs/fhsm.c 2015-01-25 13:00:38.631047076 +0100
11393 + * Copyright (C) 2011-2014 Junjiro R. Okajima
11395 + * This program, aufs is free software; you can redistribute it and/or modify
11396 + * it under the terms of the GNU General Public License as published by
11397 + * the Free Software Foundation; either version 2 of the License, or
11398 + * (at your option) any later version.
11400 + * This program is distributed in the hope that it will be useful,
11401 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11402 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11403 + * GNU General Public License for more details.
11405 + * You should have received a copy of the GNU General Public License
11406 + * along with this program; if not, write to the Free Software
11407 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11411 + * File-based Hierarchy Storage Management
11414 +#include <linux/anon_inodes.h>
11415 +#include <linux/poll.h>
11416 +#include <linux/seq_file.h>
11417 +#include <linux/statfs.h>
11420 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11422 + struct au_sbinfo *sbinfo;
11423 + struct au_fhsm *fhsm;
11425 + SiMustAnyLock(sb);
11427 + sbinfo = au_sbi(sb);
11428 + fhsm = &sbinfo->si_fhsm;
11429 + AuDebugOn(!fhsm);
11430 + return fhsm->fhsm_bottom;
11433 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11435 + struct au_sbinfo *sbinfo;
11436 + struct au_fhsm *fhsm;
11438 + SiMustWriteLock(sb);
11440 + sbinfo = au_sbi(sb);
11441 + fhsm = &sbinfo->si_fhsm;
11442 + AuDebugOn(!fhsm);
11443 + fhsm->fhsm_bottom = bindex;
11446 +/* ---------------------------------------------------------------------- */
11448 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11450 + struct au_br_fhsm *bf;
11452 + bf = br->br_fhsm;
11453 + MtxMustLock(&bf->bf_lock);
11455 + return !bf->bf_readable
11456 + || time_after(jiffies,
11457 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11460 +/* ---------------------------------------------------------------------- */
11462 +static void au_fhsm_notify(struct super_block *sb, int val)
11464 + struct au_sbinfo *sbinfo;
11465 + struct au_fhsm *fhsm;
11467 + SiMustAnyLock(sb);
11469 + sbinfo = au_sbi(sb);
11470 + fhsm = &sbinfo->si_fhsm;
11471 + if (au_fhsm_pid(fhsm)
11472 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11473 + atomic_set(&fhsm->fhsm_readable, val);
11475 + wake_up(&fhsm->fhsm_wqh);
11479 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11480 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11483 + struct au_branch *br;
11484 + struct au_br_fhsm *bf;
11486 + br = au_sbr(sb, bindex);
11487 + AuDebugOn(au_br_rdonly(br));
11488 + bf = br->br_fhsm;
11492 + mutex_lock(&bf->bf_lock);
11494 + MtxMustLock(&bf->bf_lock);
11496 + /* sb->s_root for NFS is unreliable */
11497 + err = au_br_stfs(br, &bf->bf_stfs);
11498 + if (unlikely(err)) {
11499 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11503 + bf->bf_jiffy = jiffies;
11504 + bf->bf_readable = 1;
11506 + au_fhsm_notify(sb, /*val*/1);
11508 + *rstfs = bf->bf_stfs;
11512 + mutex_unlock(&bf->bf_lock);
11513 + au_fhsm_notify(sb, /*val*/1);
11518 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11521 + struct au_sbinfo *sbinfo;
11522 + struct au_fhsm *fhsm;
11523 + struct au_branch *br;
11524 + struct au_br_fhsm *bf;
11526 + AuDbg("b%d, force %d\n", bindex, force);
11527 + SiMustAnyLock(sb);
11529 + sbinfo = au_sbi(sb);
11530 + fhsm = &sbinfo->si_fhsm;
11531 + if (!au_ftest_si(sbinfo, FHSM)
11532 + || fhsm->fhsm_bottom == bindex)
11535 + br = au_sbr(sb, bindex);
11536 + bf = br->br_fhsm;
11538 + mutex_lock(&bf->bf_lock);
11540 + || au_fhsm_pid(fhsm)
11541 + || au_fhsm_test_jiffy(sbinfo, br))
11542 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11544 + mutex_unlock(&bf->bf_lock);
11547 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11549 + aufs_bindex_t bindex, bend;
11550 + struct au_branch *br;
11552 + /* exclude the bottom */
11553 + bend = au_fhsm_bottom(sb);
11554 + for (bindex = 0; bindex < bend; bindex++) {
11555 + br = au_sbr(sb, bindex);
11556 + if (au_br_fhsm(br->br_perm))
11557 + au_fhsm_wrote(sb, bindex, force);
11561 +/* ---------------------------------------------------------------------- */
11563 +static unsigned int au_fhsm_poll(struct file *file,
11564 + struct poll_table_struct *wait)
11566 + unsigned int mask;
11567 + struct au_sbinfo *sbinfo;
11568 + struct au_fhsm *fhsm;
11571 + sbinfo = file->private_data;
11572 + fhsm = &sbinfo->si_fhsm;
11573 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11574 + if (atomic_read(&fhsm->fhsm_readable))
11575 + mask = POLLIN /* | POLLRDNORM */;
11577 + AuTraceErr((int)mask);
11581 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11582 + struct aufs_stfs *stfs, __s16 brid)
11586 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11588 + err = __put_user(brid, &stbr->brid);
11589 + if (unlikely(err))
11595 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11596 + struct aufs_stbr __user *stbr, size_t count)
11600 + aufs_bindex_t bindex, bend;
11601 + struct au_branch *br;
11602 + struct au_br_fhsm *bf;
11604 + /* except the bottom branch */
11607 + bend = au_fhsm_bottom(sb);
11608 + for (bindex = 0; !err && bindex < bend; bindex++) {
11609 + br = au_sbr(sb, bindex);
11610 + if (!au_br_fhsm(br->br_perm))
11613 + bf = br->br_fhsm;
11614 + mutex_lock(&bf->bf_lock);
11615 + if (bf->bf_readable) {
11617 + if (count >= sizeof(*stbr))
11618 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11621 + bf->bf_readable = 0;
11622 + count -= sizeof(*stbr);
11626 + mutex_unlock(&bf->bf_lock);
11629 + err = sizeof(*stbr) * nstbr;
11634 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11639 + aufs_bindex_t nfhsm, bindex, bend;
11640 + struct au_sbinfo *sbinfo;
11641 + struct au_fhsm *fhsm;
11642 + struct au_branch *br;
11643 + struct super_block *sb;
11646 + sbinfo = file->private_data;
11647 + fhsm = &sbinfo->si_fhsm;
11649 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11650 + if (!atomic_read(&fhsm->fhsm_readable)) {
11651 + if (vfsub_file_flags(file) & O_NONBLOCK)
11654 + err = wait_event_interruptible_locked_irq
11656 + atomic_read(&fhsm->fhsm_readable));
11658 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11659 + if (unlikely(err))
11662 + /* sb may already be dead */
11663 + au_rw_read_lock(&sbinfo->si_rwsem);
11664 + readable = atomic_read(&fhsm->fhsm_readable);
11665 + if (readable > 0) {
11666 + sb = sbinfo->si_sb;
11668 + /* exclude the bottom branch */
11670 + bend = au_fhsm_bottom(sb);
11671 + for (bindex = 0; bindex < bend; bindex++) {
11672 + br = au_sbr(sb, bindex);
11673 + if (au_br_fhsm(br->br_perm))
11677 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11678 + atomic_set(&fhsm->fhsm_readable, 0);
11679 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11683 + au_rw_read_unlock(&sbinfo->si_rwsem);
11691 +static int au_fhsm_release(struct inode *inode, struct file *file)
11693 + struct au_sbinfo *sbinfo;
11694 + struct au_fhsm *fhsm;
11696 + /* sb may already be dead */
11697 + sbinfo = file->private_data;
11698 + fhsm = &sbinfo->si_fhsm;
11699 + spin_lock(&fhsm->fhsm_spin);
11700 + fhsm->fhsm_pid = 0;
11701 + spin_unlock(&fhsm->fhsm_spin);
11702 + kobject_put(&sbinfo->si_kobj);
11707 +static const struct file_operations au_fhsm_fops = {
11708 + .owner = THIS_MODULE,
11709 + .llseek = noop_llseek,
11710 + .read = au_fhsm_read,
11711 + .poll = au_fhsm_poll,
11712 + .release = au_fhsm_release
11715 +int au_fhsm_fd(struct super_block *sb, int oflags)
11718 + struct au_sbinfo *sbinfo;
11719 + struct au_fhsm *fhsm;
11722 + if (unlikely(!capable(CAP_SYS_ADMIN)))
11726 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
11730 + sbinfo = au_sbi(sb);
11731 + fhsm = &sbinfo->si_fhsm;
11732 + spin_lock(&fhsm->fhsm_spin);
11733 + if (!fhsm->fhsm_pid)
11734 + fhsm->fhsm_pid = current->pid;
11737 + spin_unlock(&fhsm->fhsm_spin);
11738 + if (unlikely(err))
11741 + oflags |= O_RDONLY;
11742 + /* oflags |= FMODE_NONOTIFY; */
11743 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
11745 + if (unlikely(fd < 0))
11748 + /* succeed reglardless 'fhsm' status */
11749 + kobject_get(&sbinfo->si_kobj);
11750 + si_noflush_read_lock(sb);
11751 + if (au_ftest_si(sbinfo, FHSM))
11752 + au_fhsm_wrote_all(sb, /*force*/0);
11753 + si_read_unlock(sb);
11754 + goto out; /* success */
11757 + spin_lock(&fhsm->fhsm_spin);
11758 + fhsm->fhsm_pid = 0;
11759 + spin_unlock(&fhsm->fhsm_spin);
11765 +/* ---------------------------------------------------------------------- */
11767 +int au_fhsm_br_alloc(struct au_branch *br)
11772 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
11774 + au_br_fhsm_init(br->br_fhsm);
11781 +/* ---------------------------------------------------------------------- */
11783 +void au_fhsm_fin(struct super_block *sb)
11785 + au_fhsm_notify(sb, /*val*/-1);
11788 +void au_fhsm_init(struct au_sbinfo *sbinfo)
11790 + struct au_fhsm *fhsm;
11792 + fhsm = &sbinfo->si_fhsm;
11793 + spin_lock_init(&fhsm->fhsm_spin);
11794 + init_waitqueue_head(&fhsm->fhsm_wqh);
11795 + atomic_set(&fhsm->fhsm_readable, 0);
11796 + fhsm->fhsm_expire
11797 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
11798 + fhsm->fhsm_bottom = -1;
11801 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
11803 + sbinfo->si_fhsm.fhsm_expire
11804 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
11807 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
11811 + if (!au_ftest_si(sbinfo, FHSM))
11814 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
11815 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
11816 + seq_printf(seq, ",fhsm_sec=%u", u);
11818 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
11819 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
11820 +++ linux/fs/aufs/file.c 2015-01-25 13:00:38.631047076 +0100
11823 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11825 + * This program, aufs is free software; you can redistribute it and/or modify
11826 + * it under the terms of the GNU General Public License as published by
11827 + * the Free Software Foundation; either version 2 of the License, or
11828 + * (at your option) any later version.
11830 + * This program is distributed in the hope that it will be useful,
11831 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11832 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11833 + * GNU General Public License for more details.
11835 + * You should have received a copy of the GNU General Public License
11836 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11840 + * handling file/dir, and address_space operation
11843 +#ifdef CONFIG_AUFS_DEBUG
11844 +#include <linux/migrate.h>
11846 +#include <linux/pagemap.h>
11849 +/* drop flags for writing */
11850 +unsigned int au_file_roflags(unsigned int flags)
11852 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
11853 + flags |= O_RDONLY | O_NOATIME;
11857 +/* common functions to regular file and dir */
11858 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11859 + struct file *file, int force_wr)
11861 + struct file *h_file;
11862 + struct dentry *h_dentry;
11863 + struct inode *h_inode;
11864 + struct super_block *sb;
11865 + struct au_branch *br;
11866 + struct path h_path;
11867 + int err, exec_flag;
11869 + /* a race condition can happen between open and unlink/rmdir */
11870 + h_file = ERR_PTR(-ENOENT);
11871 + h_dentry = au_h_dptr(dentry, bindex);
11872 + if (au_test_nfsd() && !h_dentry)
11874 + h_inode = h_dentry->d_inode;
11875 + if (au_test_nfsd() && !h_inode)
11877 + spin_lock(&h_dentry->d_lock);
11878 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
11880 + /* || !dentry->d_inode->i_nlink */
11882 + spin_unlock(&h_dentry->d_lock);
11883 + if (unlikely(err))
11886 + sb = dentry->d_sb;
11887 + br = au_sbr(sb, bindex);
11888 + h_file = ERR_PTR(-EACCES);
11889 + exec_flag = flags & __FMODE_EXEC;
11890 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
11893 + /* drop flags for writing */
11894 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
11895 + if (force_wr && !(flags & O_WRONLY))
11897 + flags = au_file_roflags(flags);
11899 + h_file = ERR_PTR(-EROFS);
11900 + flags = au_file_roflags(flags);
11901 + if (unlikely(vfsub_native_ro(h_inode)
11902 + || IS_APPEND(h_inode)))
11904 + flags &= ~O_ACCMODE;
11905 + flags |= O_WRONLY;
11908 + flags &= ~O_CREAT;
11909 + atomic_inc(&br->br_count);
11910 + h_path.dentry = h_dentry;
11911 + h_path.mnt = au_br_mnt(br);
11912 + h_file = vfsub_dentry_open(&h_path, flags);
11913 + if (IS_ERR(h_file))
11917 + err = deny_write_access(h_file);
11918 + if (unlikely(err)) {
11920 + h_file = ERR_PTR(err);
11924 + fsnotify_open(h_file);
11925 + goto out; /* success */
11928 + atomic_dec(&br->br_count);
11933 +static int au_cmoo(struct dentry *dentry)
11936 + unsigned int udba;
11937 + struct path h_path;
11938 + struct au_pin pin;
11939 + struct au_cp_generic cpg = {
11940 + .dentry = dentry,
11945 + .flags = AuCpup_DTIME | AuCpup_HOPEN
11947 + struct inode *inode, *delegated;
11948 + struct super_block *sb;
11949 + struct au_sbinfo *sbinfo;
11950 + struct au_fhsm *fhsm;
11952 + struct au_branch *br;
11953 + struct dentry *parent;
11954 + struct au_hinode *hdir;
11956 + DiMustWriteLock(dentry);
11957 + inode = dentry->d_inode;
11958 + IiMustWriteLock(inode);
11961 + if (IS_ROOT(dentry))
11963 + cpg.bsrc = au_dbstart(dentry);
11967 + sb = dentry->d_sb;
11968 + sbinfo = au_sbi(sb);
11969 + fhsm = &sbinfo->si_fhsm;
11970 + pid = au_fhsm_pid(fhsm);
11972 + && (current->pid == pid
11973 + || current->real_parent->pid == pid))
11976 + br = au_sbr(sb, cpg.bsrc);
11977 + cmoo = au_br_cmoo(br->br_perm);
11980 + if (!S_ISREG(inode->i_mode))
11981 + cmoo &= AuBrAttr_COO_ALL;
11985 + parent = dget_parent(dentry);
11986 + di_write_lock_parent(parent);
11987 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
11989 + if (unlikely(err < 0)) {
11990 + err = 0; /* there is no upper writable branch */
11993 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
11995 + /* do not respect the coo attrib for the target branch */
11996 + err = au_cpup_dirs(dentry, cpg.bdst);
11997 + if (unlikely(err))
12000 + di_downgrade_lock(parent, AuLock_IR);
12001 + udba = au_opt_udba(sb);
12002 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12003 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12004 + if (unlikely(err))
12007 + err = au_sio_cpup_simple(&cpg);
12009 + if (unlikely(err))
12011 + if (!(cmoo & AuBrWAttr_MOO))
12012 + goto out_parent; /* success */
12014 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12015 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12016 + if (unlikely(err))
12019 + h_path.mnt = au_br_mnt(br);
12020 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12021 + hdir = au_hi(parent->d_inode, cpg.bsrc);
12022 + delegated = NULL;
12023 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12025 + /* todo: keep h_dentry or not? */
12026 + if (unlikely(err == -EWOULDBLOCK)) {
12027 + pr_warn("cannot retry for NFSv4 delegation"
12028 + " for an internal unlink\n");
12031 + if (unlikely(err)) {
12032 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12036 + goto out_parent; /* success */
12039 + di_downgrade_lock(parent, AuLock_IR);
12041 + di_read_unlock(parent, AuLock_IR);
12048 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
12049 + struct au_fidir *fidir)
12052 + struct dentry *dentry;
12053 + struct au_finfo *finfo;
12055 + err = au_finfo_init(file, fidir);
12056 + if (unlikely(err))
12059 + dentry = file->f_dentry;
12060 + di_write_lock_child(dentry);
12061 + err = au_cmoo(dentry);
12062 + di_downgrade_lock(dentry, AuLock_IR);
12064 + err = open(file, vfsub_file_flags(file));
12065 + di_read_unlock(dentry, AuLock_IR);
12067 + finfo = au_fi(file);
12069 + finfo->fi_file = file;
12070 + au_sphl_add(&finfo->fi_hlist,
12071 + &au_sbi(file->f_dentry->d_sb)->si_files);
12073 + fi_write_unlock(file);
12074 + if (unlikely(err)) {
12075 + finfo->fi_hdir = NULL;
12076 + au_finfo_fin(file);
12083 +int au_reopen_nondir(struct file *file)
12086 + aufs_bindex_t bstart;
12087 + struct dentry *dentry;
12088 + struct file *h_file, *h_file_tmp;
12090 + dentry = file->f_dentry;
12091 + bstart = au_dbstart(dentry);
12092 + h_file_tmp = NULL;
12093 + if (au_fbstart(file) == bstart) {
12094 + h_file = au_hf_top(file);
12095 + if (file->f_mode == h_file->f_mode)
12096 + return 0; /* success */
12097 + h_file_tmp = h_file;
12098 + get_file(h_file_tmp);
12099 + au_set_h_fptr(file, bstart, NULL);
12101 + AuDebugOn(au_fi(file)->fi_hdir);
12104 + * file exists on both of rw and ro
12105 + * open --> dbstart and fbstart are both 0
12106 + * prepend a branch as rw, "rw" become ro
12108 + * delete the top branch, "rw" becomes rw again
12109 + * --> dbstart is 1, fbstart is still 0
12110 + * write --> fbstart is 0 but dbstart is 1
12112 + /* AuDebugOn(au_fbstart(file) < bstart); */
12114 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
12115 + file, /*force_wr*/0);
12116 + err = PTR_ERR(h_file);
12117 + if (IS_ERR(h_file)) {
12118 + if (h_file_tmp) {
12119 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
12120 + au_set_h_fptr(file, bstart, h_file_tmp);
12121 + h_file_tmp = NULL;
12123 + goto out; /* todo: close all? */
12127 + au_set_fbstart(file, bstart);
12128 + au_set_h_fptr(file, bstart, h_file);
12129 + au_update_figen(file);
12130 + /* todo: necessary? */
12131 + /* file->f_ra = h_file->f_ra; */
12135 + fput(h_file_tmp);
12139 +/* ---------------------------------------------------------------------- */
12141 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12142 + struct dentry *hi_wh)
12145 + aufs_bindex_t bstart;
12146 + struct au_dinfo *dinfo;
12147 + struct dentry *h_dentry;
12148 + struct au_hdentry *hdp;
12150 + dinfo = au_di(file->f_dentry);
12151 + AuRwMustWriteLock(&dinfo->di_rwsem);
12153 + bstart = dinfo->di_bstart;
12154 + dinfo->di_bstart = btgt;
12155 + hdp = dinfo->di_hdentry;
12156 + h_dentry = hdp[0 + btgt].hd_dentry;
12157 + hdp[0 + btgt].hd_dentry = hi_wh;
12158 + err = au_reopen_nondir(file);
12159 + hdp[0 + btgt].hd_dentry = h_dentry;
12160 + dinfo->di_bstart = bstart;
12165 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12166 + aufs_bindex_t bcpup, struct au_pin *pin)
12169 + struct inode *inode, *h_inode;
12170 + struct dentry *h_dentry, *hi_wh;
12171 + struct au_cp_generic cpg = {
12172 + .dentry = file->f_dentry,
12179 + au_update_dbstart(cpg.dentry);
12180 + inode = cpg.dentry->d_inode;
12182 + if (au_dbstart(cpg.dentry) <= bcpup
12183 + && au_dbend(cpg.dentry) >= bcpup) {
12184 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12186 + h_inode = h_dentry->d_inode;
12188 + hi_wh = au_hi_wh(inode, bcpup);
12189 + if (!hi_wh && !h_inode)
12190 + err = au_sio_cpup_wh(&cpg, file);
12192 + /* already copied-up after unlink */
12193 + err = au_reopen_wh(file, bcpup, hi_wh);
12196 + && (inode->i_nlink > 1
12197 + || (inode->i_state & I_LINKABLE))
12198 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12199 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12205 + * prepare the @file for writing.
12207 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12210 + aufs_bindex_t dbstart;
12211 + struct dentry *parent;
12212 + struct inode *inode;
12213 + struct super_block *sb;
12214 + struct file *h_file;
12215 + struct au_cp_generic cpg = {
12216 + .dentry = file->f_dentry,
12221 + .flags = AuCpup_DTIME
12224 + sb = cpg.dentry->d_sb;
12225 + inode = cpg.dentry->d_inode;
12226 + cpg.bsrc = au_fbstart(file);
12227 + err = au_test_ro(sb, cpg.bsrc, inode);
12228 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12229 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12234 + /* need to cpup or reopen */
12235 + parent = dget_parent(cpg.dentry);
12236 + di_write_lock_parent(parent);
12237 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12239 + if (unlikely(err < 0))
12243 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12244 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12245 + if (unlikely(err))
12249 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12250 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12251 + if (unlikely(err))
12254 + dbstart = au_dbstart(cpg.dentry);
12255 + if (dbstart <= cpg.bdst)
12256 + cpg.bsrc = cpg.bdst;
12258 + if (dbstart <= cpg.bdst /* just reopen */
12259 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12261 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12262 + if (IS_ERR(h_file))
12263 + err = PTR_ERR(h_file);
12265 + di_downgrade_lock(parent, AuLock_IR);
12266 + if (dbstart > cpg.bdst)
12267 + err = au_sio_cpup_simple(&cpg);
12269 + err = au_reopen_nondir(file);
12270 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12272 + } else { /* copyup as wh and reopen */
12274 + * since writable hfsplus branch is not supported,
12275 + * h_open_pre/post() are unnecessary.
12277 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12278 + di_downgrade_lock(parent, AuLock_IR);
12282 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12283 + goto out_dput; /* success */
12289 + di_downgrade_lock(parent, AuLock_IR);
12291 + di_read_unlock(parent, AuLock_IR);
12298 +/* ---------------------------------------------------------------------- */
12300 +int au_do_flush(struct file *file, fl_owner_t id,
12301 + int (*flush)(struct file *file, fl_owner_t id))
12304 + struct super_block *sb;
12305 + struct inode *inode;
12307 + inode = file_inode(file);
12308 + sb = inode->i_sb;
12309 + si_noflush_read_lock(sb);
12310 + fi_read_lock(file);
12311 + ii_read_lock_child(inode);
12313 + err = flush(file, id);
12314 + au_cpup_attr_timesizes(inode);
12316 + ii_read_unlock(inode);
12317 + fi_read_unlock(file);
12318 + si_read_unlock(sb);
12322 +/* ---------------------------------------------------------------------- */
12324 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12327 + struct au_pin pin;
12328 + struct au_finfo *finfo;
12329 + struct dentry *parent, *hi_wh;
12330 + struct inode *inode;
12331 + struct super_block *sb;
12332 + struct au_cp_generic cpg = {
12333 + .dentry = file->f_dentry,
12338 + .flags = AuCpup_DTIME
12341 + FiMustWriteLock(file);
12344 + finfo = au_fi(file);
12345 + sb = cpg.dentry->d_sb;
12346 + inode = cpg.dentry->d_inode;
12347 + cpg.bdst = au_ibstart(inode);
12348 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12351 + parent = dget_parent(cpg.dentry);
12352 + if (au_test_ro(sb, cpg.bdst, inode)) {
12353 + di_read_lock_parent(parent, !AuLock_IR);
12354 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12356 + di_read_unlock(parent, !AuLock_IR);
12357 + if (unlikely(err < 0))
12362 + di_read_lock_parent(parent, AuLock_IR);
12363 + hi_wh = au_hi_wh(inode, cpg.bdst);
12364 + if (!S_ISDIR(inode->i_mode)
12365 + && au_opt_test(au_mntflags(sb), PLINK)
12366 + && au_plink_test(inode)
12367 + && !d_unhashed(cpg.dentry)
12368 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12369 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12370 + if (unlikely(err))
12373 + /* always superio. */
12374 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12375 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12377 + err = au_sio_cpup_simple(&cpg);
12380 + } else if (hi_wh) {
12381 + /* already copied-up after unlink */
12382 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12383 + *need_reopen = 0;
12387 + di_read_unlock(parent, AuLock_IR);
12394 +static void au_do_refresh_dir(struct file *file)
12396 + aufs_bindex_t bindex, bend, new_bindex, brid;
12397 + struct au_hfile *p, tmp, *q;
12398 + struct au_finfo *finfo;
12399 + struct super_block *sb;
12400 + struct au_fidir *fidir;
12402 + FiMustWriteLock(file);
12404 + sb = file->f_dentry->d_sb;
12405 + finfo = au_fi(file);
12406 + fidir = finfo->fi_hdir;
12407 + AuDebugOn(!fidir);
12408 + p = fidir->fd_hfile + finfo->fi_btop;
12409 + brid = p->hf_br->br_id;
12410 + bend = fidir->fd_bbot;
12411 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12415 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12416 + if (new_bindex == bindex)
12418 + if (new_bindex < 0) {
12419 + au_set_h_fptr(file, bindex, NULL);
12423 + /* swap two lower inode, and loop again */
12424 + q = fidir->fd_hfile + new_bindex;
12428 + if (tmp.hf_file) {
12434 + p = fidir->fd_hfile;
12435 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
12436 + bend = au_sbend(sb);
12437 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12438 + finfo->fi_btop++, p++)
12439 + if (p->hf_file) {
12440 + if (file_inode(p->hf_file))
12442 + au_hfput(p, file);
12445 + bend = au_br_index(sb, brid);
12446 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12447 + finfo->fi_btop++, p++)
12449 + au_hfput(p, file);
12450 + bend = au_sbend(sb);
12453 + p = fidir->fd_hfile + bend;
12454 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12455 + fidir->fd_bbot--, p--)
12456 + if (p->hf_file) {
12457 + if (file_inode(p->hf_file))
12459 + au_hfput(p, file);
12461 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12465 + * after branch manipulating, refresh the file.
12467 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12469 + int err, need_reopen;
12470 + aufs_bindex_t bend, bindex;
12471 + struct dentry *dentry;
12472 + struct au_finfo *finfo;
12473 + struct au_hfile *hfile;
12475 + dentry = file->f_dentry;
12476 + finfo = au_fi(file);
12477 + if (!finfo->fi_hdir) {
12478 + hfile = &finfo->fi_htop;
12479 + AuDebugOn(!hfile->hf_file);
12480 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12481 + AuDebugOn(bindex < 0);
12482 + if (bindex != finfo->fi_btop)
12483 + au_set_fbstart(file, bindex);
12485 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12486 + if (unlikely(err))
12488 + au_do_refresh_dir(file);
12493 + if (!au_test_mmapped(file))
12494 + err = au_file_refresh_by_inode(file, &need_reopen);
12495 + if (!err && need_reopen && !d_unlinked(dentry))
12496 + err = reopen(file);
12498 + au_update_figen(file);
12499 + goto out; /* success */
12502 + /* error, close all lower files */
12503 + if (finfo->fi_hdir) {
12504 + bend = au_fbend_dir(file);
12505 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12506 + au_set_h_fptr(file, bindex, NULL);
12513 +/* common function to regular file and dir */
12514 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12518 + unsigned int sigen, figen;
12519 + aufs_bindex_t bstart;
12520 + unsigned char pseudo_link;
12521 + struct dentry *dentry;
12522 + struct inode *inode;
12525 + dentry = file->f_dentry;
12526 + inode = dentry->d_inode;
12527 + sigen = au_sigen(dentry->d_sb);
12528 + fi_write_lock(file);
12529 + figen = au_figen(file);
12530 + di_write_lock_child(dentry);
12531 + bstart = au_dbstart(dentry);
12532 + pseudo_link = (bstart != au_ibstart(inode));
12533 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12535 + di_downgrade_lock(dentry, AuLock_IR);
12536 + fi_downgrade_lock(file);
12538 + goto out; /* success */
12541 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12542 + if (au_digen_test(dentry, sigen)) {
12543 + err = au_reval_dpath(dentry, sigen);
12544 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12548 + err = refresh_file(file, reopen);
12551 + di_downgrade_lock(dentry, AuLock_IR);
12552 + fi_downgrade_lock(file);
12555 + di_write_unlock(dentry);
12556 + fi_write_unlock(file);
12563 +/* ---------------------------------------------------------------------- */
12565 +/* cf. aufs_nopage() */
12566 +/* for madvise(2) */
12567 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12569 + unlock_page(page);
12573 +/* it will never be called, but necessary to support O_DIRECT */
12574 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
12575 + struct iov_iter *iter, loff_t offset)
12576 +{ BUG(); return 0; }
12579 + * it will never be called, but madvise and fadvise behaves differently
12580 + * when get_xip_mem is defined
12582 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
12583 + int create, void **kmem, unsigned long *pfn)
12584 +{ BUG(); return 0; }
12586 +/* they will never be called. */
12587 +#ifdef CONFIG_AUFS_DEBUG
12588 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12589 + loff_t pos, unsigned len, unsigned flags,
12590 + struct page **pagep, void **fsdata)
12591 +{ AuUnsupport(); return 0; }
12592 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12593 + loff_t pos, unsigned len, unsigned copied,
12594 + struct page *page, void *fsdata)
12595 +{ AuUnsupport(); return 0; }
12596 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12597 +{ AuUnsupport(); return 0; }
12599 +static int aufs_set_page_dirty(struct page *page)
12600 +{ AuUnsupport(); return 0; }
12601 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12602 + unsigned int length)
12603 +{ AuUnsupport(); }
12604 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12605 +{ AuUnsupport(); return 0; }
12606 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12607 + struct page *page, enum migrate_mode mode)
12608 +{ AuUnsupport(); return 0; }
12609 +static int aufs_launder_page(struct page *page)
12610 +{ AuUnsupport(); return 0; }
12611 +static int aufs_is_partially_uptodate(struct page *page,
12612 + unsigned long from,
12613 + unsigned long count)
12614 +{ AuUnsupport(); return 0; }
12615 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12617 +{ AuUnsupport(); }
12618 +static int aufs_error_remove_page(struct address_space *mapping,
12619 + struct page *page)
12620 +{ AuUnsupport(); return 0; }
12621 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12623 +{ AuUnsupport(); return 0; }
12624 +static void aufs_swap_deactivate(struct file *file)
12625 +{ AuUnsupport(); }
12626 +#endif /* CONFIG_AUFS_DEBUG */
12628 +const struct address_space_operations aufs_aop = {
12629 + .readpage = aufs_readpage,
12630 + .direct_IO = aufs_direct_IO,
12631 + .get_xip_mem = aufs_get_xip_mem,
12632 +#ifdef CONFIG_AUFS_DEBUG
12633 + .writepage = aufs_writepage,
12634 + /* no writepages, because of writepage */
12635 + .set_page_dirty = aufs_set_page_dirty,
12636 + /* no readpages, because of readpage */
12637 + .write_begin = aufs_write_begin,
12638 + .write_end = aufs_write_end,
12639 + /* no bmap, no block device */
12640 + .invalidatepage = aufs_invalidatepage,
12641 + .releasepage = aufs_releasepage,
12642 + .migratepage = aufs_migratepage,
12643 + .launder_page = aufs_launder_page,
12644 + .is_partially_uptodate = aufs_is_partially_uptodate,
12645 + .is_dirty_writeback = aufs_is_dirty_writeback,
12646 + .error_remove_page = aufs_error_remove_page,
12647 + .swap_activate = aufs_swap_activate,
12648 + .swap_deactivate = aufs_swap_deactivate
12649 +#endif /* CONFIG_AUFS_DEBUG */
12651 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12652 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12653 +++ linux/fs/aufs/file.h 2015-01-25 13:00:38.631047076 +0100
12656 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12658 + * This program, aufs is free software; you can redistribute it and/or modify
12659 + * it under the terms of the GNU General Public License as published by
12660 + * the Free Software Foundation; either version 2 of the License, or
12661 + * (at your option) any later version.
12663 + * This program is distributed in the hope that it will be useful,
12664 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12665 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12666 + * GNU General Public License for more details.
12668 + * You should have received a copy of the GNU General Public License
12669 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12673 + * file operations
12676 +#ifndef __AUFS_FILE_H__
12677 +#define __AUFS_FILE_H__
12681 +#include <linux/file.h>
12682 +#include <linux/fs.h>
12683 +#include <linux/poll.h>
12684 +#include "rwsem.h"
12688 + struct file *hf_file;
12689 + struct au_branch *hf_br;
12694 + aufs_bindex_t fd_bbot;
12695 + aufs_bindex_t fd_nent;
12696 + struct au_vdir *fd_vdir_cache;
12697 + struct au_hfile fd_hfile[];
12700 +static inline int au_fidir_sz(int nent)
12702 + AuDebugOn(nent < 0);
12703 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
12707 + atomic_t fi_generation;
12709 + struct au_rwsem fi_rwsem;
12710 + aufs_bindex_t fi_btop;
12712 + /* do not union them */
12713 + struct { /* for non-dir */
12714 + struct au_hfile fi_htop;
12715 + atomic_t fi_mmapped;
12717 + struct au_fidir *fi_hdir; /* for dir only */
12719 + struct hlist_node fi_hlist;
12720 + struct file *fi_file; /* very ugly */
12721 +} ____cacheline_aligned_in_smp;
12723 +/* ---------------------------------------------------------------------- */
12726 +extern const struct address_space_operations aufs_aop;
12727 +unsigned int au_file_roflags(unsigned int flags);
12728 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12729 + struct file *file, int force_wr);
12730 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
12731 + struct au_fidir *fidir);
12732 +int au_reopen_nondir(struct file *file);
12734 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
12735 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12737 +int au_do_flush(struct file *file, fl_owner_t id,
12738 + int (*flush)(struct file *file, fl_owner_t id));
12741 +#ifdef CONFIG_AUFS_POLL
12742 +unsigned int aufs_poll(struct file *file, poll_table *wait);
12745 +#ifdef CONFIG_AUFS_BR_HFSPLUS
12747 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
12749 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12750 + struct file *h_file);
12752 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
12753 + aufs_bindex_t bindex, int force_wr)
12754 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
12755 + struct file *h_file);
12759 +extern const struct file_operations aufs_file_fop;
12760 +int au_do_open_nondir(struct file *file, int flags);
12761 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
12764 +void au_hfput(struct au_hfile *hf, struct file *file);
12765 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
12766 + struct file *h_file);
12768 +void au_update_figen(struct file *file);
12769 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
12770 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
12772 +void au_fi_init_once(void *_fi);
12773 +void au_finfo_fin(struct file *file);
12774 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
12777 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
12778 +#ifdef CONFIG_COMPAT
12779 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
12780 + unsigned long arg);
12781 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
12782 + unsigned long arg);
12785 +/* ---------------------------------------------------------------------- */
12787 +static inline struct au_finfo *au_fi(struct file *file)
12789 + return file->private_data;
12792 +/* ---------------------------------------------------------------------- */
12795 + * fi_read_lock, fi_write_lock,
12796 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
12798 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
12800 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
12801 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
12802 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
12804 +/* ---------------------------------------------------------------------- */
12806 +/* todo: hard/soft set? */
12807 +static inline aufs_bindex_t au_fbstart(struct file *file)
12809 + FiMustAnyLock(file);
12810 + return au_fi(file)->fi_btop;
12813 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
12815 + FiMustAnyLock(file);
12816 + AuDebugOn(!au_fi(file)->fi_hdir);
12817 + return au_fi(file)->fi_hdir->fd_bbot;
12820 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
12822 + FiMustAnyLock(file);
12823 + AuDebugOn(!au_fi(file)->fi_hdir);
12824 + return au_fi(file)->fi_hdir->fd_vdir_cache;
12827 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
12829 + FiMustWriteLock(file);
12830 + au_fi(file)->fi_btop = bindex;
12833 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
12835 + FiMustWriteLock(file);
12836 + AuDebugOn(!au_fi(file)->fi_hdir);
12837 + au_fi(file)->fi_hdir->fd_bbot = bindex;
12840 +static inline void au_set_fvdir_cache(struct file *file,
12841 + struct au_vdir *vdir_cache)
12843 + FiMustWriteLock(file);
12844 + AuDebugOn(!au_fi(file)->fi_hdir);
12845 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
12848 +static inline struct file *au_hf_top(struct file *file)
12850 + FiMustAnyLock(file);
12851 + AuDebugOn(au_fi(file)->fi_hdir);
12852 + return au_fi(file)->fi_htop.hf_file;
12855 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
12857 + FiMustAnyLock(file);
12858 + AuDebugOn(!au_fi(file)->fi_hdir);
12859 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
12862 +/* todo: memory barrier? */
12863 +static inline unsigned int au_figen(struct file *f)
12865 + return atomic_read(&au_fi(f)->fi_generation);
12868 +static inline void au_set_mmapped(struct file *f)
12870 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
12872 + pr_warn("fi_mmapped wrapped around\n");
12873 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
12877 +static inline void au_unset_mmapped(struct file *f)
12879 + atomic_dec(&au_fi(f)->fi_mmapped);
12882 +static inline int au_test_mmapped(struct file *f)
12884 + return atomic_read(&au_fi(f)->fi_mmapped);
12887 +/* customize vma->vm_file */
12889 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
12890 + struct file *file)
12894 + f = vma->vm_file;
12896 + vma->vm_file = file;
12901 +#define AuDbgVmRegion(file, vma) do {} while (0)
12903 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12904 + struct file *file)
12906 + au_do_vm_file_reset(vma, file);
12909 +#define AuDbgVmRegion(file, vma) \
12910 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
12912 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12913 + struct file *file)
12917 + au_do_vm_file_reset(vma, file);
12918 + f = vma->vm_region->vm_file;
12920 + vma->vm_region->vm_file = file;
12923 +#endif /* CONFIG_MMU */
12925 +/* handle vma->vm_prfile */
12926 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
12927 + struct file *file)
12930 + vma->vm_prfile = file;
12931 +#ifndef CONFIG_MMU
12933 + vma->vm_region->vm_prfile = file;
12937 +#endif /* __KERNEL__ */
12938 +#endif /* __AUFS_FILE_H__ */
12939 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
12940 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
12941 +++ linux/fs/aufs/finfo.c 2015-01-25 13:00:38.631047076 +0100
12944 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12946 + * This program, aufs is free software; you can redistribute it and/or modify
12947 + * it under the terms of the GNU General Public License as published by
12948 + * the Free Software Foundation; either version 2 of the License, or
12949 + * (at your option) any later version.
12951 + * This program is distributed in the hope that it will be useful,
12952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12954 + * GNU General Public License for more details.
12956 + * You should have received a copy of the GNU General Public License
12957 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12961 + * file private data
12966 +void au_hfput(struct au_hfile *hf, struct file *file)
12968 + /* todo: direct access f_flags */
12969 + if (vfsub_file_flags(file) & __FMODE_EXEC)
12970 + allow_write_access(hf->hf_file);
12971 + fput(hf->hf_file);
12972 + hf->hf_file = NULL;
12973 + atomic_dec(&hf->hf_br->br_count);
12974 + hf->hf_br = NULL;
12977 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
12979 + struct au_finfo *finfo = au_fi(file);
12980 + struct au_hfile *hf;
12981 + struct au_fidir *fidir;
12983 + fidir = finfo->fi_hdir;
12985 + AuDebugOn(finfo->fi_btop != bindex);
12986 + hf = &finfo->fi_htop;
12988 + hf = fidir->fd_hfile + bindex;
12990 + if (hf && hf->hf_file)
12991 + au_hfput(hf, file);
12993 + FiMustWriteLock(file);
12994 + hf->hf_file = val;
12995 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
12999 +void au_update_figen(struct file *file)
13001 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
13002 + /* smp_mb(); */ /* atomic_set */
13005 +/* ---------------------------------------------------------------------- */
13007 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13009 + struct au_fidir *fidir;
13012 + nbr = au_sbend(sb) + 1;
13014 + nbr = 2; /* initial allocate for 2 branches */
13015 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13017 + fidir->fd_bbot = -1;
13018 + fidir->fd_nent = nbr;
13019 + fidir->fd_vdir_cache = NULL;
13025 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13028 + struct au_fidir *fidir, *p;
13030 + AuRwMustWriteLock(&finfo->fi_rwsem);
13031 + fidir = finfo->fi_hdir;
13032 + AuDebugOn(!fidir);
13035 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13038 + p->fd_nent = nbr;
13039 + finfo->fi_hdir = p;
13046 +/* ---------------------------------------------------------------------- */
13048 +void au_finfo_fin(struct file *file)
13050 + struct au_finfo *finfo;
13052 + au_nfiles_dec(file->f_dentry->d_sb);
13054 + finfo = au_fi(file);
13055 + AuDebugOn(finfo->fi_hdir);
13056 + AuRwDestroy(&finfo->fi_rwsem);
13057 + au_cache_free_finfo(finfo);
13060 +void au_fi_init_once(void *_finfo)
13062 + struct au_finfo *finfo = _finfo;
13063 + static struct lock_class_key aufs_fi;
13065 + au_rw_init(&finfo->fi_rwsem);
13066 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
13069 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13072 + struct au_finfo *finfo;
13073 + struct dentry *dentry;
13076 + dentry = file->f_dentry;
13077 + finfo = au_cache_alloc_finfo();
13078 + if (unlikely(!finfo))
13082 + au_nfiles_inc(dentry->d_sb);
13083 + /* verbose coding for lock class name */
13085 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
13087 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
13088 + au_rw_write_lock(&finfo->fi_rwsem);
13089 + finfo->fi_btop = -1;
13090 + finfo->fi_hdir = fidir;
13091 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13092 + /* smp_mb(); */ /* atomic_set */
13094 + file->private_data = finfo;
13099 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13100 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13101 +++ linux/fs/aufs/f_op.c 2015-01-25 13:00:38.631047076 +0100
13104 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13106 + * This program, aufs is free software; you can redistribute it and/or modify
13107 + * it under the terms of the GNU General Public License as published by
13108 + * the Free Software Foundation; either version 2 of the License, or
13109 + * (at your option) any later version.
13111 + * This program is distributed in the hope that it will be useful,
13112 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13113 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13114 + * GNU General Public License for more details.
13116 + * You should have received a copy of the GNU General Public License
13117 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13121 + * file and vm operations
13124 +#include <linux/aio.h>
13125 +#include <linux/fs_stack.h>
13126 +#include <linux/mman.h>
13127 +#include <linux/security.h>
13130 +int au_do_open_nondir(struct file *file, int flags)
13133 + aufs_bindex_t bindex;
13134 + struct file *h_file;
13135 + struct dentry *dentry;
13136 + struct au_finfo *finfo;
13137 + struct inode *h_inode;
13139 + FiMustWriteLock(file);
13142 + dentry = file->f_dentry;
13143 + finfo = au_fi(file);
13144 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13145 + atomic_set(&finfo->fi_mmapped, 0);
13146 + bindex = au_dbstart(dentry);
13147 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13148 + if (IS_ERR(h_file))
13149 + err = PTR_ERR(h_file);
13151 + if ((flags & __O_TMPFILE)
13152 + && !(flags & O_EXCL)) {
13153 + h_inode = file_inode(h_file);
13154 + spin_lock(&h_inode->i_lock);
13155 + h_inode->i_state |= I_LINKABLE;
13156 + spin_unlock(&h_inode->i_lock);
13158 + au_set_fbstart(file, bindex);
13159 + au_set_h_fptr(file, bindex, h_file);
13160 + au_update_figen(file);
13161 + /* todo: necessary? */
13162 + /* file->f_ra = h_file->f_ra; */
13168 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13169 + struct file *file)
13172 + struct super_block *sb;
13174 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13175 + file, vfsub_file_flags(file), file->f_mode);
13177 + sb = file->f_dentry->d_sb;
13178 + si_read_lock(sb, AuLock_FLUSH);
13179 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
13180 + si_read_unlock(sb);
13184 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13186 + struct au_finfo *finfo;
13187 + aufs_bindex_t bindex;
13189 + finfo = au_fi(file);
13190 + au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files);
13191 + bindex = finfo->fi_btop;
13193 + au_set_h_fptr(file, bindex, NULL);
13195 + au_finfo_fin(file);
13199 +/* ---------------------------------------------------------------------- */
13201 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13204 + struct file *h_file;
13207 + h_file = au_hf_top(file);
13209 + err = vfsub_flush(h_file, id);
13213 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13215 + return au_do_flush(file, id, au_do_flush_nondir);
13218 +/* ---------------------------------------------------------------------- */
13220 + * read and write functions acquire [fdi]_rwsem once, but release before
13221 + * mmap_sem. This is because to stop a race condition between mmap(2).
13222 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13223 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13224 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13227 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13231 + struct dentry *dentry;
13232 + struct file *h_file;
13233 + struct super_block *sb;
13235 + dentry = file->f_dentry;
13236 + sb = dentry->d_sb;
13237 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13238 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13239 + if (unlikely(err))
13242 + h_file = au_hf_top(file);
13243 + get_file(h_file);
13244 + di_read_unlock(dentry, AuLock_IR);
13245 + fi_read_unlock(file);
13247 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13248 + err = vfsub_read_u(h_file, buf, count, ppos);
13249 + /* todo: necessary? */
13250 + /* file->f_ra = h_file->f_ra; */
13251 + /* update without lock, I don't think it a problem */
13252 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13256 + si_read_unlock(sb);
13261 + * todo: very ugly
13262 + * it locks both of i_mutex and si_rwsem for read in safe.
13263 + * if the plink maintenance mode continues forever (that is the problem),
13264 + * may loop forever.
13266 +static void au_mtx_and_read_lock(struct inode *inode)
13269 + struct super_block *sb = inode->i_sb;
13272 + mutex_lock(&inode->i_mutex);
13273 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13276 + mutex_unlock(&inode->i_mutex);
13277 + si_read_lock(sb, AuLock_NOPLMW);
13278 + si_read_unlock(sb);
13282 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13283 + size_t count, loff_t *ppos)
13287 + aufs_bindex_t bstart;
13288 + struct au_pin pin;
13289 + struct dentry *dentry;
13290 + struct inode *inode, *h_inode;
13291 + struct super_block *sb;
13292 + struct file *h_file;
13293 + char __user *buf = (char __user *)ubuf;
13295 + dentry = file->f_dentry;
13296 + sb = dentry->d_sb;
13297 + inode = dentry->d_inode;
13298 + au_mtx_and_read_lock(inode);
13300 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13301 + if (unlikely(err))
13304 + err = au_ready_to_write(file, -1, &pin);
13305 + di_downgrade_lock(dentry, AuLock_IR);
13306 + if (unlikely(err)) {
13307 + di_read_unlock(dentry, AuLock_IR);
13308 + fi_write_unlock(file);
13312 + bstart = au_fbstart(file);
13313 + h_file = au_hf_top(file);
13314 + get_file(h_file);
13315 + h_inode = file_inode(h_file);
13316 + blks = h_inode->i_blocks;
13318 + di_read_unlock(dentry, AuLock_IR);
13319 + fi_write_unlock(file);
13321 + err = vfsub_write_u(h_file, buf, count, ppos);
13322 + ii_write_lock_child(inode);
13323 + au_cpup_attr_timesizes(inode);
13324 + inode->i_mode = file_inode(h_file)->i_mode;
13325 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13327 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13328 + ii_write_unlock(inode);
13332 + si_read_unlock(sb);
13333 + mutex_unlock(&inode->i_mutex);
13337 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13338 + struct iov_iter *iov_iter)
13341 + struct file *file;
13342 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13343 + ssize_t (*aio)(struct kiocb *, const struct iovec *, unsigned long,
13346 + err = security_file_permission(h_file, rw);
13347 + if (unlikely(err))
13353 + if (rw == MAY_READ) {
13354 + iter = h_file->f_op->read_iter;
13355 + aio = h_file->f_op->aio_read;
13356 + } else if (rw == MAY_WRITE) {
13357 + iter = h_file->f_op->write_iter;
13358 + aio = h_file->f_op->aio_write;
13361 + file = kio->ki_filp;
13362 + kio->ki_filp = h_file;
13365 + err = iter(kio, iov_iter);
13367 + } else if (aio) {
13369 + err = aio(kio, iov_iter->iov, iov_iter->nr_segs, kio->ki_pos);
13372 + /* currently there is no such fs */
13374 + kio->ki_filp = file;
13380 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13383 + struct file *file, *h_file;
13384 + struct dentry *dentry;
13385 + struct super_block *sb;
13387 + file = kio->ki_filp;
13388 + dentry = file->f_dentry;
13389 + sb = dentry->d_sb;
13390 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13391 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13392 + if (unlikely(err))
13395 + h_file = au_hf_top(file);
13396 + get_file(h_file);
13397 + di_read_unlock(dentry, AuLock_IR);
13398 + fi_read_unlock(file);
13400 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13401 + /* todo: necessary? */
13402 + /* file->f_ra = h_file->f_ra; */
13403 + /* update without lock, I don't think it a problem */
13404 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13408 + si_read_unlock(sb);
13412 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13416 + aufs_bindex_t bstart;
13417 + struct au_pin pin;
13418 + struct dentry *dentry;
13419 + struct inode *inode, *h_inode;
13420 + struct file *file, *h_file;
13421 + struct super_block *sb;
13423 + file = kio->ki_filp;
13424 + dentry = file->f_dentry;
13425 + sb = dentry->d_sb;
13426 + inode = dentry->d_inode;
13427 + au_mtx_and_read_lock(inode);
13429 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13430 + if (unlikely(err))
13433 + err = au_ready_to_write(file, -1, &pin);
13434 + di_downgrade_lock(dentry, AuLock_IR);
13435 + if (unlikely(err)) {
13436 + di_read_unlock(dentry, AuLock_IR);
13437 + fi_write_unlock(file);
13441 + bstart = au_fbstart(file);
13442 + h_file = au_hf_top(file);
13443 + get_file(h_file);
13444 + h_inode = file_inode(h_file);
13445 + blks = h_inode->i_blocks;
13447 + di_read_unlock(dentry, AuLock_IR);
13448 + fi_write_unlock(file);
13450 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13451 + ii_write_lock_child(inode);
13452 + au_cpup_attr_timesizes(inode);
13453 + inode->i_mode = file_inode(h_file)->i_mode;
13454 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13456 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13457 + ii_write_unlock(inode);
13461 + si_read_unlock(sb);
13462 + mutex_unlock(&inode->i_mutex);
13466 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13467 + struct pipe_inode_info *pipe, size_t len,
13468 + unsigned int flags)
13471 + struct file *h_file;
13472 + struct dentry *dentry;
13473 + struct super_block *sb;
13475 + dentry = file->f_dentry;
13476 + sb = dentry->d_sb;
13477 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13478 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13479 + if (unlikely(err))
13483 + h_file = au_hf_top(file);
13484 + get_file(h_file);
13485 + if (au_test_loopback_kthread()) {
13486 + au_warn_loopback(h_file->f_dentry->d_sb);
13487 + if (file->f_mapping != h_file->f_mapping) {
13488 + file->f_mapping = h_file->f_mapping;
13489 + smp_mb(); /* unnecessary? */
13492 + di_read_unlock(dentry, AuLock_IR);
13493 + fi_read_unlock(file);
13495 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13496 + /* todo: necessasry? */
13497 + /* file->f_ra = h_file->f_ra; */
13498 + /* update without lock, I don't think it a problem */
13499 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13503 + si_read_unlock(sb);
13508 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13509 + size_t len, unsigned int flags)
13513 + aufs_bindex_t bstart;
13514 + struct au_pin pin;
13515 + struct dentry *dentry;
13516 + struct inode *inode, *h_inode;
13517 + struct super_block *sb;
13518 + struct file *h_file;
13520 + dentry = file->f_dentry;
13521 + sb = dentry->d_sb;
13522 + inode = dentry->d_inode;
13523 + au_mtx_and_read_lock(inode);
13525 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13526 + if (unlikely(err))
13529 + err = au_ready_to_write(file, -1, &pin);
13530 + di_downgrade_lock(dentry, AuLock_IR);
13531 + if (unlikely(err)) {
13532 + di_read_unlock(dentry, AuLock_IR);
13533 + fi_write_unlock(file);
13537 + bstart = au_fbstart(file);
13538 + h_file = au_hf_top(file);
13539 + get_file(h_file);
13540 + h_inode = file_inode(h_file);
13541 + blks = h_inode->i_blocks;
13543 + di_read_unlock(dentry, AuLock_IR);
13544 + fi_write_unlock(file);
13546 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13547 + ii_write_lock_child(inode);
13548 + au_cpup_attr_timesizes(inode);
13549 + inode->i_mode = file_inode(h_file)->i_mode;
13550 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13552 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13553 + ii_write_unlock(inode);
13557 + si_read_unlock(sb);
13558 + mutex_unlock(&inode->i_mutex);
13562 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13566 + struct au_pin pin;
13567 + struct dentry *dentry;
13568 + struct super_block *sb;
13569 + struct inode *inode;
13570 + struct file *h_file;
13572 + dentry = file->f_dentry;
13573 + sb = dentry->d_sb;
13574 + inode = dentry->d_inode;
13575 + au_mtx_and_read_lock(inode);
13577 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13578 + if (unlikely(err))
13581 + err = au_ready_to_write(file, -1, &pin);
13582 + di_downgrade_lock(dentry, AuLock_IR);
13583 + if (unlikely(err)) {
13584 + di_read_unlock(dentry, AuLock_IR);
13585 + fi_write_unlock(file);
13589 + h_file = au_hf_top(file);
13590 + get_file(h_file);
13592 + di_read_unlock(dentry, AuLock_IR);
13593 + fi_write_unlock(file);
13596 + err = vfs_fallocate(h_file, mode, offset, len);
13598 + ii_write_lock_child(inode);
13599 + au_cpup_attr_timesizes(inode);
13600 + inode->i_mode = file_inode(h_file)->i_mode;
13601 + ii_write_unlock(inode);
13605 + si_read_unlock(sb);
13606 + mutex_unlock(&inode->i_mutex);
13610 +/* ---------------------------------------------------------------------- */
13613 + * The locking order around current->mmap_sem.
13614 + * - in most and regular cases
13615 + * file I/O syscall -- aufs_read() or something
13616 + * -- si_rwsem for read -- mmap_sem
13617 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13619 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13620 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13621 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13622 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13623 + * It means that when aufs acquires si_rwsem for write, the process should never
13624 + * acquire mmap_sem.
13626 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13627 + * problem either since any directory is not able to be mmap-ed.
13628 + * The similar scenario is applied to aufs_readlink() too.
13631 +#if 0 /* stop calling security_file_mmap() */
13632 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13633 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13635 +static unsigned long au_arch_prot_conv(unsigned long flags)
13637 + /* currently ppc64 only */
13638 +#ifdef CONFIG_PPC64
13639 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13640 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13641 + return AuConv_VM_PROT(flags, SAO);
13643 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13648 +static unsigned long au_prot_conv(unsigned long flags)
13650 + return AuConv_VM_PROT(flags, READ)
13651 + | AuConv_VM_PROT(flags, WRITE)
13652 + | AuConv_VM_PROT(flags, EXEC)
13653 + | au_arch_prot_conv(flags);
13656 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13657 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13659 +static unsigned long au_flag_conv(unsigned long flags)
13661 + return AuConv_VM_MAP(flags, GROWSDOWN)
13662 + | AuConv_VM_MAP(flags, DENYWRITE)
13663 + | AuConv_VM_MAP(flags, LOCKED);
13667 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13670 + aufs_bindex_t bstart;
13671 + const unsigned char wlock
13672 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13673 + struct dentry *dentry;
13674 + struct super_block *sb;
13675 + struct file *h_file;
13676 + struct au_branch *br;
13677 + struct au_pin pin;
13679 + AuDbgVmRegion(file, vma);
13681 + dentry = file->f_dentry;
13682 + sb = dentry->d_sb;
13684 + si_read_lock(sb, AuLock_NOPLMW);
13685 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13686 + if (unlikely(err))
13690 + err = au_ready_to_write(file, -1, &pin);
13691 + di_write_unlock(dentry);
13692 + if (unlikely(err)) {
13693 + fi_write_unlock(file);
13698 + di_write_unlock(dentry);
13700 + bstart = au_fbstart(file);
13701 + br = au_sbr(sb, bstart);
13702 + h_file = au_hf_top(file);
13703 + get_file(h_file);
13704 + au_set_mmapped(file);
13705 + fi_write_unlock(file);
13708 + au_vm_file_reset(vma, h_file);
13710 + * we cannot call security_mmap_file() here since it may acquire
13711 + * mmap_sem or i_mutex.
13713 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13714 + * au_flag_conv(vma->vm_flags));
13717 + err = h_file->f_op->mmap(h_file, vma);
13718 + if (unlikely(err))
13721 + au_vm_prfile_set(vma, file);
13722 + /* update without lock, I don't think it a problem */
13723 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
13724 + goto out_fput; /* success */
13727 + au_unset_mmapped(file);
13728 + au_vm_file_reset(vma, file);
13733 + si_read_unlock(sb);
13739 +/* ---------------------------------------------------------------------- */
13741 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
13745 + struct au_pin pin;
13746 + struct dentry *dentry;
13747 + struct inode *inode;
13748 + struct file *h_file;
13749 + struct super_block *sb;
13751 + dentry = file->f_dentry;
13752 + inode = dentry->d_inode;
13753 + sb = dentry->d_sb;
13754 + mutex_lock(&inode->i_mutex);
13755 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13756 + if (unlikely(err))
13759 + err = 0; /* -EBADF; */ /* posix? */
13760 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13762 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13763 + if (unlikely(err))
13766 + err = au_ready_to_write(file, -1, &pin);
13767 + di_downgrade_lock(dentry, AuLock_IR);
13768 + if (unlikely(err))
13773 + h_file = au_hf_top(file);
13774 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
13775 + au_cpup_attr_timesizes(inode);
13778 + di_read_unlock(dentry, AuLock_IR);
13779 + fi_write_unlock(file);
13781 + si_read_unlock(sb);
13783 + mutex_unlock(&inode->i_mutex);
13787 +/* no one supports this operation, currently */
13789 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
13792 + struct au_pin pin;
13793 + struct dentry *dentry;
13794 + struct inode *inode;
13795 + struct file *file, *h_file;
13797 + file = kio->ki_filp;
13798 + dentry = file->f_dentry;
13799 + inode = dentry->d_inode;
13800 + au_mtx_and_read_lock(inode);
13802 + err = 0; /* -EBADF; */ /* posix? */
13803 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13805 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13806 + if (unlikely(err))
13809 + err = au_ready_to_write(file, -1, &pin);
13810 + di_downgrade_lock(dentry, AuLock_IR);
13811 + if (unlikely(err))
13816 + h_file = au_hf_top(file);
13817 + if (h_file->f_op->aio_fsync) {
13818 + struct mutex *h_mtx;
13820 + h_mtx = &file_inode(h_file)->i_mutex;
13821 + if (!is_sync_kiocb(kio)) {
13822 + get_file(h_file);
13825 + kio->ki_filp = h_file;
13826 + err = h_file->f_op->aio_fsync(kio, datasync);
13827 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13829 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
13831 + au_cpup_attr_timesizes(inode);
13832 + mutex_unlock(h_mtx);
13836 + di_read_unlock(dentry, AuLock_IR);
13837 + fi_write_unlock(file);
13839 + si_read_unlock(inode->sb);
13840 + mutex_unlock(&inode->i_mutex);
13845 +static int aufs_fasync(int fd, struct file *file, int flag)
13848 + struct file *h_file;
13849 + struct dentry *dentry;
13850 + struct super_block *sb;
13852 + dentry = file->f_dentry;
13853 + sb = dentry->d_sb;
13854 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13855 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13856 + if (unlikely(err))
13859 + h_file = au_hf_top(file);
13860 + if (h_file->f_op->fasync)
13861 + err = h_file->f_op->fasync(fd, h_file, flag);
13863 + di_read_unlock(dentry, AuLock_IR);
13864 + fi_read_unlock(file);
13867 + si_read_unlock(sb);
13871 +/* ---------------------------------------------------------------------- */
13873 +/* no one supports this operation, currently */
13875 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
13876 + size_t len, loff_t *pos , int more)
13881 +/* ---------------------------------------------------------------------- */
13883 +const struct file_operations aufs_file_fop = {
13884 + .owner = THIS_MODULE,
13886 + .llseek = default_llseek,
13888 + .read = aufs_read,
13889 + .write = aufs_write,
13890 + .read_iter = aufs_read_iter,
13891 + .write_iter = aufs_write_iter,
13893 +#ifdef CONFIG_AUFS_POLL
13894 + .poll = aufs_poll,
13896 + .unlocked_ioctl = aufs_ioctl_nondir,
13897 +#ifdef CONFIG_COMPAT
13898 + .compat_ioctl = aufs_compat_ioctl_nondir,
13900 + .mmap = aufs_mmap,
13901 + .open = aufs_open_nondir,
13902 + .flush = aufs_flush_nondir,
13903 + .release = aufs_release_nondir,
13904 + .fsync = aufs_fsync_nondir,
13905 + /* .aio_fsync = aufs_aio_fsync_nondir, */
13906 + .fasync = aufs_fasync,
13907 + /* .sendpage = aufs_sendpage, */
13908 + .splice_write = aufs_splice_write,
13909 + .splice_read = aufs_splice_read,
13911 + .aio_splice_write = aufs_aio_splice_write,
13912 + .aio_splice_read = aufs_aio_splice_read,
13914 + .fallocate = aufs_fallocate
13916 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
13917 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13918 +++ linux/fs/aufs/fstype.h 2015-01-25 13:00:38.631047076 +0100
13921 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13923 + * This program, aufs is free software; you can redistribute it and/or modify
13924 + * it under the terms of the GNU General Public License as published by
13925 + * the Free Software Foundation; either version 2 of the License, or
13926 + * (at your option) any later version.
13928 + * This program is distributed in the hope that it will be useful,
13929 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13930 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13931 + * GNU General Public License for more details.
13933 + * You should have received a copy of the GNU General Public License
13934 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13938 + * judging filesystem type
13941 +#ifndef __AUFS_FSTYPE_H__
13942 +#define __AUFS_FSTYPE_H__
13946 +#include <linux/fs.h>
13947 +#include <linux/magic.h>
13948 +#include <linux/romfs_fs.h>
13950 +static inline int au_test_aufs(struct super_block *sb)
13952 + return sb->s_magic == AUFS_SUPER_MAGIC;
13955 +static inline const char *au_sbtype(struct super_block *sb)
13957 + return sb->s_type->name;
13960 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
13962 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
13963 + return sb->s_magic == ROMFS_MAGIC;
13969 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
13971 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
13972 + return sb->s_magic == ISOFS_SUPER_MAGIC;
13978 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
13980 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
13981 + return sb->s_magic == CRAMFS_MAGIC;
13986 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
13988 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
13989 + return sb->s_magic == NFS_SUPER_MAGIC;
13995 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
13997 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
13998 + return sb->s_magic == FUSE_SUPER_MAGIC;
14004 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14006 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
14007 + return sb->s_magic == XFS_SB_MAGIC;
14013 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14015 +#ifdef CONFIG_TMPFS
14016 + return sb->s_magic == TMPFS_MAGIC;
14022 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14024 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
14025 + return !strcmp(au_sbtype(sb), "ecryptfs");
14031 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
14033 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
14034 + return sb->s_magic == OCFS2_SUPER_MAGIC;
14040 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
14042 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
14043 + return sb->s_magic == DLMFS_MAGIC;
14049 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
14051 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
14052 + return sb->s_magic == CODA_SUPER_MAGIC;
14058 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
14060 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
14061 + return sb->s_magic == V9FS_MAGIC;
14067 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
14069 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
14070 + return sb->s_magic == EXT4_SUPER_MAGIC;
14076 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
14078 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
14079 + return !strcmp(au_sbtype(sb), "sysv");
14085 +static inline int au_test_ramfs(struct super_block *sb)
14087 + return sb->s_magic == RAMFS_MAGIC;
14090 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14092 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
14093 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14099 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14101 +#ifdef CONFIG_PROC_FS
14102 + return sb->s_magic == PROC_SUPER_MAGIC;
14108 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14110 +#ifdef CONFIG_SYSFS
14111 + return sb->s_magic == SYSFS_MAGIC;
14117 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14119 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
14120 + return sb->s_magic == CONFIGFS_MAGIC;
14126 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14128 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
14129 + return sb->s_magic == MINIX3_SUPER_MAGIC
14130 + || sb->s_magic == MINIX2_SUPER_MAGIC
14131 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14132 + || sb->s_magic == MINIX_SUPER_MAGIC
14133 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14139 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
14141 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
14142 + return sb->s_magic == CIFS_MAGIC_NUMBER;
14148 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14150 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14151 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14157 +static inline int au_test_msdos(struct super_block *sb)
14159 + return au_test_fat(sb);
14162 +static inline int au_test_vfat(struct super_block *sb)
14164 + return au_test_fat(sb);
14167 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14169 +#ifdef CONFIG_SECURITYFS
14170 + return sb->s_magic == SECURITYFS_MAGIC;
14176 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14178 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14179 + return sb->s_magic == SQUASHFS_MAGIC;
14185 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14187 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14188 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14194 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14196 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14197 + return sb->s_magic == XENFS_SUPER_MAGIC;
14203 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14205 +#ifdef CONFIG_DEBUG_FS
14206 + return sb->s_magic == DEBUGFS_MAGIC;
14212 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14214 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14215 + return sb->s_magic == NILFS_SUPER_MAGIC;
14221 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14223 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14224 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14230 +/* ---------------------------------------------------------------------- */
14232 + * they can't be an aufs branch.
14234 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14237 +#ifndef CONFIG_AUFS_BR_RAMFS
14238 + au_test_ramfs(sb) ||
14240 + au_test_procfs(sb)
14241 + || au_test_sysfs(sb)
14242 + || au_test_configfs(sb)
14243 + || au_test_debugfs(sb)
14244 + || au_test_securityfs(sb)
14245 + || au_test_xenfs(sb)
14246 + || au_test_ecryptfs(sb)
14247 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14248 + || au_test_aufs(sb); /* will be supported in next version */
14251 +static inline int au_test_fs_remote(struct super_block *sb)
14253 + return !au_test_tmpfs(sb)
14254 +#ifdef CONFIG_AUFS_BR_RAMFS
14255 + && !au_test_ramfs(sb)
14257 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14260 +/* ---------------------------------------------------------------------- */
14263 + * Note: these functions (below) are created after reading ->getattr() in all
14264 + * filesystems under linux/fs. it means we have to do so in every update...
14268 + * some filesystems require getattr to refresh the inode attributes before
14270 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14271 + * and leave the work for d_revalidate()
14273 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14275 + return au_test_nfs(sb)
14276 + || au_test_fuse(sb)
14277 + /* || au_test_ocfs2(sb) */ /* untested */
14278 + /* || au_test_btrfs(sb) */ /* untested */
14279 + /* || au_test_coda(sb) */ /* untested */
14280 + /* || au_test_v9fs(sb) */ /* untested */
14285 + * filesystems which don't maintain i_size or i_blocks.
14287 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14289 + return au_test_xfs(sb)
14290 + || au_test_btrfs(sb)
14291 + || au_test_ubifs(sb)
14292 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14293 + /* || au_test_ext4(sb) */ /* untested */
14294 + /* || au_test_ocfs2(sb) */ /* untested */
14295 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
14296 + /* || au_test_sysv(sb) */ /* untested */
14297 + /* || au_test_minix(sb) */ /* untested */
14302 + * filesystems which don't store the correct value in some of their inode
14305 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14307 + return au_test_fs_bad_iattr_size(sb)
14308 + /* || au_test_cifs(sb) */ /* untested */
14309 + || au_test_fat(sb)
14310 + || au_test_msdos(sb)
14311 + || au_test_vfat(sb);
14314 +/* they don't check i_nlink in link(2) */
14315 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14317 + return au_test_tmpfs(sb)
14318 +#ifdef CONFIG_AUFS_BR_RAMFS
14319 + || au_test_ramfs(sb)
14321 + || au_test_ubifs(sb)
14322 + || au_test_hfsplus(sb);
14326 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14328 +static inline int au_test_fs_notime(struct super_block *sb)
14330 + return au_test_nfs(sb)
14331 + || au_test_fuse(sb)
14332 + || au_test_ubifs(sb)
14333 + /* || au_test_cifs(sb) */ /* untested */
14338 + * filesystems which requires replacing i_mapping.
14340 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
14342 + return au_test_fuse(sb)
14343 + || au_test_ubifs(sb);
14346 +/* temporary support for i#1 in cramfs */
14347 +static inline int au_test_fs_unique_ino(struct inode *inode)
14349 + if (au_test_cramfs(inode->i_sb))
14350 + return inode->i_ino != 1;
14354 +/* ---------------------------------------------------------------------- */
14357 + * the filesystem where the xino files placed must support i/o after unlink and
14358 + * maintain i_size and i_blocks.
14360 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14362 + return au_test_fs_remote(sb)
14363 + || au_test_fs_bad_iattr_size(sb)
14364 + /* don't want unnecessary work for xino */
14365 + || au_test_aufs(sb)
14366 + || au_test_ecryptfs(sb)
14367 + || au_test_nilfs(sb);
14370 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14372 + return au_test_tmpfs(sb)
14373 + || au_test_ramfs(sb);
14377 + * test if the @sb is real-readonly.
14379 +static inline int au_test_fs_rr(struct super_block *sb)
14381 + return au_test_squashfs(sb)
14382 + || au_test_iso9660(sb)
14383 + || au_test_cramfs(sb)
14384 + || au_test_romfs(sb);
14387 +#endif /* __KERNEL__ */
14388 +#endif /* __AUFS_FSTYPE_H__ */
14389 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14390 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14391 +++ linux/fs/aufs/hfsnotify.c 2015-01-25 13:00:38.631047076 +0100
14394 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14396 + * This program, aufs is free software; you can redistribute it and/or modify
14397 + * it under the terms of the GNU General Public License as published by
14398 + * the Free Software Foundation; either version 2 of the License, or
14399 + * (at your option) any later version.
14401 + * This program is distributed in the hope that it will be useful,
14402 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14403 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14404 + * GNU General Public License for more details.
14406 + * You should have received a copy of the GNU General Public License
14407 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14411 + * fsnotify for the lower directories
14416 +/* FS_IN_IGNORED is unnecessary */
14417 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14418 + | FS_CREATE | FS_EVENT_ON_CHILD);
14419 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14420 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14422 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14424 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14427 + au_cache_free_hnotify(hn);
14428 + smp_mb__before_atomic();
14429 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14430 + wake_up(&au_hfsn_wq);
14433 +static int au_hfsn_alloc(struct au_hinode *hinode)
14436 + struct au_hnotify *hn;
14437 + struct super_block *sb;
14438 + struct au_branch *br;
14439 + struct fsnotify_mark *mark;
14440 + aufs_bindex_t bindex;
14442 + hn = hinode->hi_notify;
14443 + sb = hn->hn_aufs_inode->i_sb;
14444 + bindex = au_br_index(sb, hinode->hi_id);
14445 + br = au_sbr(sb, bindex);
14446 + AuDebugOn(!br->br_hfsn);
14448 + mark = &hn->hn_mark;
14449 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14450 + mark->mask = AuHfsnMask;
14452 + * by udba rename or rmdir, aufs assign a new inode to the known
14453 + * h_inode, so specify 1 to allow dups.
14456 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14457 + /*mnt*/NULL, /*allow_dups*/1);
14458 + /* even if err */
14459 + fsnotify_put_mark(mark);
14465 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14467 + struct fsnotify_mark *mark;
14468 + unsigned long long ull;
14469 + struct fsnotify_group *group;
14471 + ull = atomic64_inc_return(&au_hfsn_ifree);
14474 + mark = &hn->hn_mark;
14475 + spin_lock(&mark->lock);
14476 + group = mark->group;
14477 + fsnotify_get_group(group);
14478 + spin_unlock(&mark->lock);
14480 + fsnotify_destroy_mark(mark, group);
14481 + fsnotify_put_group(group);
14484 + /* free hn by myself */
14488 +/* ---------------------------------------------------------------------- */
14490 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14492 + struct fsnotify_mark *mark;
14494 + mark = &hinode->hi_notify->hn_mark;
14495 + spin_lock(&mark->lock);
14497 + AuDebugOn(mark->mask & AuHfsnMask);
14498 + mark->mask |= AuHfsnMask;
14500 + AuDebugOn(!(mark->mask & AuHfsnMask));
14501 + mark->mask &= ~AuHfsnMask;
14503 + spin_unlock(&mark->lock);
14504 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14507 +/* ---------------------------------------------------------------------- */
14509 +/* #define AuDbgHnotify */
14510 +#ifdef AuDbgHnotify
14511 +static char *au_hfsn_name(u32 mask)
14513 +#ifdef CONFIG_AUFS_DEBUG
14514 +#define test_ret(flag) \
14516 + if (mask & flag) \
14519 + test_ret(FS_ACCESS);
14520 + test_ret(FS_MODIFY);
14521 + test_ret(FS_ATTRIB);
14522 + test_ret(FS_CLOSE_WRITE);
14523 + test_ret(FS_CLOSE_NOWRITE);
14524 + test_ret(FS_OPEN);
14525 + test_ret(FS_MOVED_FROM);
14526 + test_ret(FS_MOVED_TO);
14527 + test_ret(FS_CREATE);
14528 + test_ret(FS_DELETE);
14529 + test_ret(FS_DELETE_SELF);
14530 + test_ret(FS_MOVE_SELF);
14531 + test_ret(FS_UNMOUNT);
14532 + test_ret(FS_Q_OVERFLOW);
14533 + test_ret(FS_IN_IGNORED);
14534 + test_ret(FS_IN_ISDIR);
14535 + test_ret(FS_IN_ONESHOT);
14536 + test_ret(FS_EVENT_ON_CHILD);
14545 +/* ---------------------------------------------------------------------- */
14547 +static void au_hfsn_free_group(struct fsnotify_group *group)
14549 + struct au_br_hfsnotify *hfsn = group->private;
14555 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14556 + struct inode *inode,
14557 + struct fsnotify_mark *inode_mark,
14558 + struct fsnotify_mark *vfsmount_mark,
14559 + u32 mask, void *data, int data_type,
14560 + const unsigned char *file_name, u32 cookie)
14563 + struct au_hnotify *hnotify;
14564 + struct inode *h_dir, *h_inode;
14565 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14567 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14570 + /* if FS_UNMOUNT happens, there must be another bug */
14571 + AuDebugOn(mask & FS_UNMOUNT);
14572 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14577 +#ifdef AuDbgHnotify
14579 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14580 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14581 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14582 + h_dir->i_ino, mask, au_hfsn_name(mask),
14583 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14584 + /* WARN_ON(1); */
14589 + AuDebugOn(!inode_mark);
14590 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14591 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14597 +static struct fsnotify_ops au_hfsn_ops = {
14598 + .handle_event = au_hfsn_handle_event,
14599 + .free_group_priv = au_hfsn_free_group
14602 +/* ---------------------------------------------------------------------- */
14604 +static void au_hfsn_fin_br(struct au_branch *br)
14606 + struct au_br_hfsnotify *hfsn;
14608 + hfsn = br->br_hfsn;
14611 + fsnotify_put_group(hfsn->hfsn_group);
14616 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14619 + struct fsnotify_group *group;
14620 + struct au_br_hfsnotify *hfsn;
14623 + br->br_hfsn = NULL;
14624 + if (!au_br_hnotifyable(perm))
14628 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14629 + if (unlikely(!hfsn))
14633 + group = fsnotify_alloc_group(&au_hfsn_ops);
14634 + if (IS_ERR(group)) {
14635 + err = PTR_ERR(group);
14636 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14640 + group->private = hfsn;
14641 + hfsn->hfsn_group = group;
14642 + br->br_hfsn = hfsn;
14643 + goto out; /* success */
14651 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14656 + if (!br->br_hfsn)
14657 + err = au_hfsn_init_br(br, perm);
14662 +/* ---------------------------------------------------------------------- */
14664 +static void au_hfsn_fin(void)
14666 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14667 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14670 +const struct au_hnotify_op au_hnotify_op = {
14671 + .ctl = au_hfsn_ctl,
14672 + .alloc = au_hfsn_alloc,
14673 + .free = au_hfsn_free,
14675 + .fin = au_hfsn_fin,
14677 + .reset_br = au_hfsn_reset_br,
14678 + .fin_br = au_hfsn_fin_br,
14679 + .init_br = au_hfsn_init_br
14681 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14682 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14683 +++ linux/fs/aufs/hfsplus.c 2015-01-25 13:00:38.631047076 +0100
14686 + * Copyright (C) 2010-2014 Junjiro R. Okajima
14688 + * This program, aufs is free software; you can redistribute it and/or modify
14689 + * it under the terms of the GNU General Public License as published by
14690 + * the Free Software Foundation; either version 2 of the License, or
14691 + * (at your option) any later version.
14693 + * This program is distributed in the hope that it will be useful,
14694 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14695 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14696 + * GNU General Public License for more details.
14698 + * You should have received a copy of the GNU General Public License
14699 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14703 + * special support for filesystems which aqucires an inode mutex
14704 + * at final closing a file, eg, hfsplus.
14706 + * This trick is very simple and stupid, just to open the file before really
14707 + * neceeary open to tell hfsplus that this is not the final closing.
14708 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14709 + * and au_h_open_post() after releasing it.
14714 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14717 + struct file *h_file;
14718 + struct dentry *h_dentry;
14720 + h_dentry = au_h_dptr(dentry, bindex);
14721 + AuDebugOn(!h_dentry);
14722 + AuDebugOn(!h_dentry->d_inode);
14725 + if (au_test_hfsplus(h_dentry->d_sb)
14726 + && S_ISREG(h_dentry->d_inode->i_mode))
14727 + h_file = au_h_open(dentry, bindex,
14728 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14729 + /*file*/NULL, force_wr);
14733 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14734 + struct file *h_file)
14738 + au_sbr_put(dentry->d_sb, bindex);
14741 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14742 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14743 +++ linux/fs/aufs/hnotify.c 2015-01-25 13:00:38.631047076 +0100
14746 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14748 + * This program, aufs is free software; you can redistribute it and/or modify
14749 + * it under the terms of the GNU General Public License as published by
14750 + * the Free Software Foundation; either version 2 of the License, or
14751 + * (at your option) any later version.
14753 + * This program is distributed in the hope that it will be useful,
14754 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14755 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14756 + * GNU General Public License for more details.
14758 + * You should have received a copy of the GNU General Public License
14759 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14763 + * abstraction to notify the direct changes on lower directories
14768 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14771 + struct au_hnotify *hn;
14774 + hn = au_cache_alloc_hnotify();
14776 + hn->hn_aufs_inode = inode;
14777 + hinode->hi_notify = hn;
14778 + err = au_hnotify_op.alloc(hinode);
14780 + if (unlikely(err)) {
14781 + hinode->hi_notify = NULL;
14782 + au_cache_free_hnotify(hn);
14784 + * The upper dir was removed by udba, but the same named
14785 + * dir left. In this case, aufs assignes a new inode
14786 + * number and set the monitor again.
14787 + * For the lower dir, the old monitnor is still left.
14789 + if (err == -EEXIST)
14798 +void au_hn_free(struct au_hinode *hinode)
14800 + struct au_hnotify *hn;
14802 + hn = hinode->hi_notify;
14804 + hinode->hi_notify = NULL;
14805 + if (au_hnotify_op.free(hinode, hn))
14806 + au_cache_free_hnotify(hn);
14810 +/* ---------------------------------------------------------------------- */
14812 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14814 + if (hinode->hi_notify)
14815 + au_hnotify_op.ctl(hinode, do_set);
14818 +void au_hn_reset(struct inode *inode, unsigned int flags)
14820 + aufs_bindex_t bindex, bend;
14821 + struct inode *hi;
14822 + struct dentry *iwhdentry;
14824 + bend = au_ibend(inode);
14825 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14826 + hi = au_h_iptr(inode, bindex);
14830 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14831 + iwhdentry = au_hi_wh(inode, bindex);
14835 + au_set_h_iptr(inode, bindex, NULL, 0);
14836 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14837 + flags & ~AuHi_XINO);
14840 + /* mutex_unlock(&hi->i_mutex); */
14844 +/* ---------------------------------------------------------------------- */
14846 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14849 + aufs_bindex_t bindex, bend, bfound, bstart;
14850 + struct inode *h_i;
14853 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14854 + pr_warn("branch root dir was changed\n");
14859 + bend = au_ibend(inode);
14860 + bstart = au_ibstart(inode);
14861 +#if 0 /* reserved for future use */
14862 + if (bindex == bend) {
14863 + /* keep this ino in rename case */
14867 + for (bindex = bstart; bindex <= bend; bindex++)
14868 + if (au_h_iptr(inode, bindex) == h_inode) {
14875 + for (bindex = bstart; bindex <= bend; bindex++) {
14876 + h_i = au_h_iptr(inode, bindex);
14880 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14881 + /* ignore this error */
14882 + /* bad action? */
14885 + /* children inode number will be broken */
14892 +static int hn_gen_tree(struct dentry *dentry)
14894 + int err, i, j, ndentry;
14895 + struct au_dcsub_pages dpages;
14896 + struct au_dpage *dpage;
14897 + struct dentry **dentries;
14899 + err = au_dpages_init(&dpages, GFP_NOFS);
14900 + if (unlikely(err))
14902 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14903 + if (unlikely(err))
14906 + for (i = 0; i < dpages.ndpage; i++) {
14907 + dpage = dpages.dpages + i;
14908 + dentries = dpage->dentries;
14909 + ndentry = dpage->ndentry;
14910 + for (j = 0; j < ndentry; j++) {
14911 + struct dentry *d;
14919 + /* todo: reset children xino?
14920 + cached children only? */
14921 + au_iigen_dec(d->d_inode);
14926 + au_dpages_free(&dpages);
14929 + /* discard children */
14930 + dentry_unhash(dentry);
14938 + * return 0 if processed.
14940 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14941 + const unsigned int isdir)
14944 + struct dentry *d;
14945 + struct qstr *dname;
14948 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14949 + pr_warn("branch root dir was changed\n");
14955 + AuDebugOn(!name);
14956 + au_iigen_dec(inode);
14957 + spin_lock(&inode->i_lock);
14958 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
14959 + spin_lock(&d->d_lock);
14960 + dname = &d->d_name;
14961 + if (dname->len != nlen
14962 + && memcmp(dname->name, name, nlen)) {
14963 + spin_unlock(&d->d_lock);
14968 + spin_unlock(&d->d_lock);
14971 + spin_unlock(&inode->i_lock);
14973 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14974 + d = d_find_any_alias(inode);
14976 + au_iigen_dec(inode);
14980 + spin_lock(&d->d_lock);
14981 + dname = &d->d_name;
14982 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14983 + spin_unlock(&d->d_lock);
14984 + err = hn_gen_tree(d);
14985 + spin_lock(&d->d_lock);
14987 + spin_unlock(&d->d_lock);
14996 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
14999 + struct inode *inode;
15001 + inode = dentry->d_inode;
15002 + if (IS_ROOT(dentry)
15003 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
15005 + pr_warn("branch root dir was changed\n");
15011 + au_digen_dec(dentry);
15013 + au_iigen_dec(inode);
15015 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15017 + err = hn_gen_tree(dentry);
15024 +/* ---------------------------------------------------------------------- */
15026 +/* hnotify job flags */
15027 +#define AuHnJob_XINO0 1
15028 +#define AuHnJob_GEN (1 << 1)
15029 +#define AuHnJob_DIRENT (1 << 2)
15030 +#define AuHnJob_ISDIR (1 << 3)
15031 +#define AuHnJob_TRYXINO0 (1 << 4)
15032 +#define AuHnJob_MNTPNT (1 << 5)
15033 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15034 +#define au_fset_hnjob(flags, name) \
15035 + do { (flags) |= AuHnJob_##name; } while (0)
15036 +#define au_fclr_hnjob(flags, name) \
15037 + do { (flags) &= ~AuHnJob_##name; } while (0)
15045 +struct au_hnotify_args {
15046 + struct inode *h_dir, *dir, *h_child_inode;
15048 + unsigned int flags[AuHnLast];
15049 + unsigned int h_child_nlen;
15050 + char h_child_name[];
15053 +struct hn_job_args {
15054 + unsigned int flags;
15055 + struct inode *inode, *h_inode, *dir, *h_dir;
15056 + struct dentry *dentry;
15061 +static int hn_job(struct hn_job_args *a)
15063 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15067 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15068 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15070 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15073 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
15074 + if (!a->h_inode->i_nlink
15075 + && !(a->h_inode->i_state & I_LINKABLE))
15076 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15077 + mutex_unlock(&a->h_inode->i_mutex);
15080 + /* make the generation obsolete */
15081 + if (au_ftest_hnjob(a->flags, GEN)) {
15084 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15086 + if (e && a->dentry)
15087 + hn_gen_by_name(a->dentry, isdir);
15088 + /* ignore this error */
15091 + /* make dir entries obsolete */
15092 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15093 + struct au_vdir *vdir;
15095 + vdir = au_ivdir(a->inode);
15097 + vdir->vd_jiffy = 0;
15098 + /* IMustLock(a->inode); */
15099 + /* a->inode->i_version++; */
15102 + /* can do nothing but warn */
15103 + if (au_ftest_hnjob(a->flags, MNTPNT)
15105 + && d_mountpoint(a->dentry))
15106 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15111 +/* ---------------------------------------------------------------------- */
15113 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15114 + struct inode *dir)
15116 + struct dentry *dentry, *d, *parent;
15117 + struct qstr *dname;
15119 + parent = d_find_any_alias(dir);
15124 + spin_lock(&parent->d_lock);
15125 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15126 + /* AuDbg("%pd\n", d); */
15127 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15128 + dname = &d->d_name;
15129 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15130 + goto cont_unlock;
15134 + goto cont_unlock;
15135 + if (au_dcount(d) > 0) {
15136 + dentry = dget_dlock(d);
15137 + spin_unlock(&d->d_lock);
15142 + spin_unlock(&d->d_lock);
15144 + spin_unlock(&parent->d_lock);
15148 + di_write_lock_child(dentry);
15153 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15154 + aufs_bindex_t bindex, ino_t h_ino)
15156 + struct inode *inode;
15161 + err = au_xino_read(sb, bindex, h_ino, &ino);
15163 + inode = ilookup(sb, ino);
15167 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15168 + pr_warn("wrong root branch\n");
15174 + ii_write_lock_child(inode);
15180 +static void au_hn_bh(void *_args)
15182 + struct au_hnotify_args *a = _args;
15183 + struct super_block *sb;
15184 + aufs_bindex_t bindex, bend, bfound;
15185 + unsigned char xino, try_iput;
15187 + struct inode *inode;
15189 + struct hn_job_args args;
15190 + struct dentry *dentry;
15191 + struct au_sbinfo *sbinfo;
15193 + AuDebugOn(!_args);
15194 + AuDebugOn(!a->h_dir);
15195 + AuDebugOn(!a->dir);
15196 + AuDebugOn(!a->mask);
15197 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15198 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15199 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15204 + * do not lock a->dir->i_mutex here
15205 + * because of d_revalidate() may cause a deadlock.
15207 + sb = a->dir->i_sb;
15209 + sbinfo = au_sbi(sb);
15210 + AuDebugOn(!sbinfo);
15211 + si_write_lock(sb, AuLock_NOPLMW);
15213 + ii_read_lock_parent(a->dir);
15215 + bend = au_ibend(a->dir);
15216 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
15217 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15221 + ii_read_unlock(a->dir);
15222 + if (unlikely(bfound < 0))
15225 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15227 + if (a->h_child_inode)
15228 + h_ino = a->h_child_inode->i_ino;
15230 + if (a->h_child_nlen
15231 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15232 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15233 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15237 + inode = dentry->d_inode;
15238 + if (xino && !inode && h_ino
15239 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15240 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15241 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15242 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15246 + args.flags = a->flags[AuHn_CHILD];
15247 + args.dentry = dentry;
15248 + args.inode = inode;
15249 + args.h_inode = a->h_child_inode;
15250 + args.dir = a->dir;
15251 + args.h_dir = a->h_dir;
15252 + args.h_name = a->h_child_name;
15253 + args.h_nlen = a->h_child_nlen;
15254 + err = hn_job(&args);
15256 + if (au_di(dentry))
15257 + di_write_unlock(dentry);
15260 + if (inode && try_iput) {
15261 + ii_write_unlock(inode);
15265 + ii_write_lock_parent(a->dir);
15266 + args.flags = a->flags[AuHn_PARENT];
15267 + args.dentry = NULL;
15268 + args.inode = a->dir;
15269 + args.h_inode = a->h_dir;
15271 + args.h_dir = NULL;
15272 + args.h_name = NULL;
15274 + err = hn_job(&args);
15275 + ii_write_unlock(a->dir);
15278 + iput(a->h_child_inode);
15281 + si_write_unlock(sb);
15282 + au_nwt_done(&sbinfo->si_nowait);
15286 +/* ---------------------------------------------------------------------- */
15288 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15289 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15292 + unsigned int flags[AuHnLast], f;
15293 + unsigned char isdir, isroot, wh;
15294 + struct inode *dir;
15295 + struct au_hnotify_args *args;
15296 + char *p, *h_child_name;
15299 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15300 + dir = igrab(hnotify->hn_aufs_inode);
15304 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15306 + h_child_name = (void *)h_child_qstr->name;
15307 + len = h_child_qstr->len;
15308 + if (h_child_name) {
15309 + if (len > AUFS_WH_PFX_LEN
15310 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15311 + h_child_name += AUFS_WH_PFX_LEN;
15312 + len -= AUFS_WH_PFX_LEN;
15318 + if (h_child_inode)
15319 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15320 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15321 + flags[AuHn_CHILD] = 0;
15323 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15324 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15325 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15326 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15327 + case FS_MOVED_FROM:
15328 + case FS_MOVED_TO:
15329 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15330 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15333 + AuDebugOn(!h_child_name);
15338 + * aufs never be able to get this child inode.
15339 + * revalidation should be in d_revalidate()
15340 + * by checking i_nlink, i_generation or d_unhashed().
15342 + AuDebugOn(!h_child_name);
15343 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15344 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15352 + h_child_inode = NULL;
15355 + /* iput() and kfree() will be called in au_hnotify() */
15356 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15357 + if (unlikely(!args)) {
15358 + AuErr1("no memory\n");
15362 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15363 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15364 + args->mask = mask;
15366 + args->h_dir = igrab(h_dir);
15367 + if (h_child_inode)
15368 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15369 + args->h_child_inode = h_child_inode;
15370 + args->h_child_nlen = len;
15372 + p = (void *)args;
15373 + p += sizeof(*args);
15374 + memcpy(p, h_child_name, len);
15378 + /* NFS fires the event for silly-renamed one from kworker */
15380 + if (!dir->i_nlink
15381 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15383 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15384 + if (unlikely(err)) {
15385 + pr_err("wkq %d\n", err);
15386 + iput(args->h_child_inode);
15387 + iput(args->h_dir);
15396 +/* ---------------------------------------------------------------------- */
15398 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15402 + AuDebugOn(!(udba & AuOptMask_UDBA));
15405 + if (au_hnotify_op.reset_br)
15406 + err = au_hnotify_op.reset_br(udba, br, perm);
15411 +int au_hnotify_init_br(struct au_branch *br, int perm)
15416 + if (au_hnotify_op.init_br)
15417 + err = au_hnotify_op.init_br(br, perm);
15422 +void au_hnotify_fin_br(struct au_branch *br)
15424 + if (au_hnotify_op.fin_br)
15425 + au_hnotify_op.fin_br(br);
15428 +static void au_hn_destroy_cache(void)
15430 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15431 + au_cachep[AuCache_HNOTIFY] = NULL;
15434 +int __init au_hnotify_init(void)
15439 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15440 + if (au_cachep[AuCache_HNOTIFY]) {
15442 + if (au_hnotify_op.init)
15443 + err = au_hnotify_op.init();
15444 + if (unlikely(err))
15445 + au_hn_destroy_cache();
15451 +void au_hnotify_fin(void)
15453 + if (au_hnotify_op.fin)
15454 + au_hnotify_op.fin();
15455 + /* cf. au_cache_fin() */
15456 + if (au_cachep[AuCache_HNOTIFY])
15457 + au_hn_destroy_cache();
15459 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15460 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15461 +++ linux/fs/aufs/iinfo.c 2015-01-25 13:00:38.631047076 +0100
15464 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15466 + * This program, aufs is free software; you can redistribute it and/or modify
15467 + * it under the terms of the GNU General Public License as published by
15468 + * the Free Software Foundation; either version 2 of the License, or
15469 + * (at your option) any later version.
15471 + * This program is distributed in the hope that it will be useful,
15472 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15473 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15474 + * GNU General Public License for more details.
15476 + * You should have received a copy of the GNU General Public License
15477 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15481 + * inode private data
15486 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15488 + struct inode *h_inode;
15490 + IiMustAnyLock(inode);
15492 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15493 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15497 +/* todo: hard/soft set? */
15498 +void au_hiput(struct au_hinode *hinode)
15500 + au_hn_free(hinode);
15501 + dput(hinode->hi_whdentry);
15502 + iput(hinode->hi_inode);
15505 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15507 + unsigned int flags;
15508 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15511 + if (au_opt_test(mnt_flags, XINO))
15512 + au_fset_hi(flags, XINO);
15513 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15514 + au_fset_hi(flags, HNOTIFY);
15518 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15519 + struct inode *h_inode, unsigned int flags)
15521 + struct au_hinode *hinode;
15522 + struct inode *hi;
15523 + struct au_iinfo *iinfo = au_ii(inode);
15525 + IiMustWriteLock(inode);
15527 + hinode = iinfo->ii_hinode + bindex;
15528 + hi = hinode->hi_inode;
15529 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15532 + au_hiput(hinode);
15533 + hinode->hi_inode = h_inode;
15536 + struct super_block *sb = inode->i_sb;
15537 + struct au_branch *br;
15539 + AuDebugOn(inode->i_mode
15540 + && (h_inode->i_mode & S_IFMT)
15541 + != (inode->i_mode & S_IFMT));
15542 + if (bindex == iinfo->ii_bstart)
15543 + au_cpup_igen(inode, h_inode);
15544 + br = au_sbr(sb, bindex);
15545 + hinode->hi_id = br->br_id;
15546 + if (au_ftest_hi(flags, XINO)) {
15547 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15549 + if (unlikely(err))
15550 + AuIOErr1("failed au_xino_write() %d\n", err);
15553 + if (au_ftest_hi(flags, HNOTIFY)
15554 + && au_br_hnotifyable(br->br_perm)) {
15555 + err = au_hn_alloc(hinode, inode);
15556 + if (unlikely(err))
15557 + AuIOErr1("au_hn_alloc() %d\n", err);
15562 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15563 + struct dentry *h_wh)
15565 + struct au_hinode *hinode;
15567 + IiMustWriteLock(inode);
15569 + hinode = au_ii(inode)->ii_hinode + bindex;
15570 + AuDebugOn(hinode->hi_whdentry);
15571 + hinode->hi_whdentry = h_wh;
15574 +void au_update_iigen(struct inode *inode, int half)
15576 + struct au_iinfo *iinfo;
15577 + struct au_iigen *iigen;
15578 + unsigned int sigen;
15580 + sigen = au_sigen(inode->i_sb);
15581 + iinfo = au_ii(inode);
15582 + iigen = &iinfo->ii_generation;
15583 + spin_lock(&iinfo->ii_genspin);
15584 + iigen->ig_generation = sigen;
15586 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15588 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15589 + spin_unlock(&iinfo->ii_genspin);
15592 +/* it may be called at remount time, too */
15593 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15595 + struct au_iinfo *iinfo;
15596 + aufs_bindex_t bindex, bend;
15598 + iinfo = au_ii(inode);
15602 + IiMustWriteLock(inode);
15604 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15605 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15607 + struct inode *h_i;
15609 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15612 + && !(h_i->i_state & I_LINKABLE))
15613 + au_set_h_iptr(inode, bindex, NULL, 0);
15617 + iinfo->ii_bstart = -1;
15618 + iinfo->ii_bend = -1;
15619 + bend = au_sbend(inode->i_sb);
15620 + for (bindex = 0; bindex <= bend; bindex++)
15621 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15622 + iinfo->ii_bstart = bindex;
15625 + if (iinfo->ii_bstart >= 0)
15626 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15627 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15628 + iinfo->ii_bend = bindex;
15631 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15634 +/* ---------------------------------------------------------------------- */
15636 +void au_icntnr_init_once(void *_c)
15638 + struct au_icntnr *c = _c;
15639 + struct au_iinfo *iinfo = &c->iinfo;
15640 + static struct lock_class_key aufs_ii;
15642 + spin_lock_init(&iinfo->ii_genspin);
15643 + au_rw_init(&iinfo->ii_rwsem);
15644 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15645 + inode_init_once(&c->vfs_inode);
15648 +int au_iinfo_init(struct inode *inode)
15650 + struct au_iinfo *iinfo;
15651 + struct super_block *sb;
15654 + sb = inode->i_sb;
15655 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15656 + nbr = au_sbend(sb) + 1;
15657 + if (unlikely(nbr <= 0))
15659 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15660 + if (iinfo->ii_hinode) {
15661 + au_ninodes_inc(sb);
15662 + for (i = 0; i < nbr; i++)
15663 + iinfo->ii_hinode[i].hi_id = -1;
15665 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15666 + iinfo->ii_bstart = -1;
15667 + iinfo->ii_bend = -1;
15668 + iinfo->ii_vdir = NULL;
15674 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15677 + struct au_hinode *hip;
15679 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15682 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15684 + sz = sizeof(*hip);
15685 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15687 + iinfo->ii_hinode = hip;
15694 +void au_iinfo_fin(struct inode *inode)
15696 + struct au_iinfo *iinfo;
15697 + struct au_hinode *hi;
15698 + struct super_block *sb;
15699 + aufs_bindex_t bindex, bend;
15700 + const unsigned char unlinked = !inode->i_nlink;
15702 + iinfo = au_ii(inode);
15703 + /* bad_inode case */
15707 + sb = inode->i_sb;
15708 + au_ninodes_dec(sb);
15709 + if (si_pid_test(sb))
15710 + au_xino_delete_inode(inode, unlinked);
15713 + * it is safe to hide the dependency between sbinfo and
15717 + si_noflush_read_lock(sb);
15718 + au_xino_delete_inode(inode, unlinked);
15719 + si_read_unlock(sb);
15723 + if (iinfo->ii_vdir)
15724 + au_vdir_free(iinfo->ii_vdir);
15726 + bindex = iinfo->ii_bstart;
15727 + if (bindex >= 0) {
15728 + hi = iinfo->ii_hinode + bindex;
15729 + bend = iinfo->ii_bend;
15730 + while (bindex++ <= bend) {
15731 + if (hi->hi_inode)
15736 + kfree(iinfo->ii_hinode);
15737 + iinfo->ii_hinode = NULL;
15738 + AuRwDestroy(&iinfo->ii_rwsem);
15740 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15741 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15742 +++ linux/fs/aufs/inode.c 2015-01-25 13:00:38.631047076 +0100
15745 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15747 + * This program, aufs is free software; you can redistribute it and/or modify
15748 + * it under the terms of the GNU General Public License as published by
15749 + * the Free Software Foundation; either version 2 of the License, or
15750 + * (at your option) any later version.
15752 + * This program is distributed in the hope that it will be useful,
15753 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15754 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15755 + * GNU General Public License for more details.
15757 + * You should have received a copy of the GNU General Public License
15758 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15762 + * inode functions
15767 +struct inode *au_igrab(struct inode *inode)
15770 + AuDebugOn(!atomic_read(&inode->i_count));
15776 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15778 + au_cpup_attr_all(inode, /*force*/0);
15779 + au_update_iigen(inode, /*half*/1);
15781 + inode->i_version++;
15784 +static int au_ii_refresh(struct inode *inode, int *update)
15788 + aufs_bindex_t bindex, new_bindex;
15789 + struct super_block *sb;
15790 + struct au_iinfo *iinfo;
15791 + struct au_hinode *p, *q, tmp;
15793 + IiMustWriteLock(inode);
15796 + sb = inode->i_sb;
15797 + type = inode->i_mode & S_IFMT;
15798 + iinfo = au_ii(inode);
15799 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15800 + if (unlikely(err))
15803 + AuDebugOn(iinfo->ii_bstart < 0);
15804 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15805 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15807 + if (!p->hi_inode)
15810 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15811 + new_bindex = au_br_index(sb, p->hi_id);
15812 + if (new_bindex == bindex)
15815 + if (new_bindex < 0) {
15818 + p->hi_inode = NULL;
15822 + if (new_bindex < iinfo->ii_bstart)
15823 + iinfo->ii_bstart = new_bindex;
15824 + if (iinfo->ii_bend < new_bindex)
15825 + iinfo->ii_bend = new_bindex;
15826 + /* swap two lower inode, and loop again */
15827 + q = iinfo->ii_hinode + new_bindex;
15831 + if (tmp.hi_inode) {
15836 + au_update_ibrange(inode, /*do_put_zero*/0);
15837 + e = au_dy_irefresh(inode);
15838 + if (unlikely(e && !err))
15846 +int au_refresh_hinode_self(struct inode *inode)
15850 + err = au_ii_refresh(inode, &update);
15852 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
15858 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
15860 + int err, e, update;
15861 + unsigned int flags;
15863 + aufs_bindex_t bindex, bend;
15864 + unsigned char isdir;
15865 + struct au_hinode *p;
15866 + struct au_iinfo *iinfo;
15868 + err = au_ii_refresh(inode, &update);
15869 + if (unlikely(err))
15873 + iinfo = au_ii(inode);
15874 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15875 + mode = (inode->i_mode & S_IFMT);
15876 + isdir = S_ISDIR(mode);
15877 + flags = au_hi_flags(inode, isdir);
15878 + bend = au_dbend(dentry);
15879 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15880 + struct inode *h_i;
15881 + struct dentry *h_d;
15883 + h_d = au_h_dptr(dentry, bindex);
15884 + if (!h_d || !h_d->d_inode)
15887 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
15888 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15889 + h_i = au_h_iptr(inode, bindex);
15891 + if (h_i == h_d->d_inode)
15897 + if (bindex < iinfo->ii_bstart)
15898 + iinfo->ii_bstart = bindex;
15899 + if (iinfo->ii_bend < bindex)
15900 + iinfo->ii_bend = bindex;
15901 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
15904 + au_update_ibrange(inode, /*do_put_zero*/0);
15905 + e = au_dy_irefresh(inode);
15906 + if (unlikely(e && !err))
15909 + au_refresh_hinode_attr(inode, update && isdir);
15916 +static int set_inode(struct inode *inode, struct dentry *dentry)
15919 + unsigned int flags;
15921 + aufs_bindex_t bindex, bstart, btail;
15922 + unsigned char isdir;
15923 + struct dentry *h_dentry;
15924 + struct inode *h_inode;
15925 + struct au_iinfo *iinfo;
15927 + IiMustWriteLock(inode);
15931 + bstart = au_dbstart(dentry);
15932 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
15933 + mode = h_inode->i_mode;
15934 + switch (mode & S_IFMT) {
15936 + btail = au_dbtail(dentry);
15937 + inode->i_op = &aufs_iop;
15938 + inode->i_fop = &aufs_file_fop;
15939 + err = au_dy_iaop(inode, bstart, h_inode);
15940 + if (unlikely(err))
15945 + btail = au_dbtaildir(dentry);
15946 + inode->i_op = &aufs_dir_iop;
15947 + inode->i_fop = &aufs_dir_fop;
15950 + btail = au_dbtail(dentry);
15951 + inode->i_op = &aufs_symlink_iop;
15957 + btail = au_dbtail(dentry);
15958 + inode->i_op = &aufs_iop;
15959 + init_special_inode(inode, mode, h_inode->i_rdev);
15962 + AuIOErr("Unknown file type 0%o\n", mode);
15967 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
15968 + flags = au_hi_flags(inode, isdir);
15969 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
15970 + && au_ftest_hi(flags, HNOTIFY)
15971 + && dentry->d_name.len > AUFS_WH_PFX_LEN
15972 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
15973 + au_fclr_hi(flags, HNOTIFY);
15974 + iinfo = au_ii(inode);
15975 + iinfo->ii_bstart = bstart;
15976 + iinfo->ii_bend = btail;
15977 + for (bindex = bstart; bindex <= btail; bindex++) {
15978 + h_dentry = au_h_dptr(dentry, bindex);
15980 + au_set_h_iptr(inode, bindex,
15981 + au_igrab(h_dentry->d_inode), flags);
15983 + au_cpup_attr_all(inode, /*force*/1);
15985 + * to force calling aufs_get_acl() every time,
15986 + * do not call cache_no_acl() for aufs inode.
15994 + * successful returns with iinfo write_locked
15996 + * zero: success, matched
15997 + * plus: no error, but unmatched
15999 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16002 + unsigned int gen;
16003 + struct au_iigen iigen;
16004 + aufs_bindex_t bindex, bend;
16005 + struct inode *h_inode, *h_dinode;
16008 + * before this function, if aufs got any iinfo lock, it must be only
16009 + * one, the parent dir.
16010 + * it can happen by UDBA and the obsoleted inode number.
16013 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16017 + ii_write_lock_new_child(inode);
16018 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
16019 + bend = au_ibend(inode);
16020 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
16021 + h_inode = au_h_iptr(inode, bindex);
16022 + if (!h_inode || h_inode != h_dinode)
16026 + gen = au_iigen(inode, &iigen);
16027 + if (gen == au_digen(dentry)
16028 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
16031 + /* fully refresh inode using dentry */
16032 + err = au_refresh_hinode(inode, dentry);
16034 + au_update_iigen(inode, /*half*/0);
16038 + if (unlikely(err))
16039 + ii_write_unlock(inode);
16044 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16045 + unsigned int d_type, ino_t *ino)
16048 + struct mutex *mtx;
16050 + /* prevent hardlinked inode number from race condition */
16052 + if (d_type != DT_DIR) {
16053 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16056 + err = au_xino_read(sb, bindex, h_ino, ino);
16057 + if (unlikely(err))
16062 + *ino = au_xino_new_ino(sb);
16063 + if (unlikely(!*ino))
16065 + err = au_xino_write(sb, bindex, h_ino, *ino);
16066 + if (unlikely(err))
16072 + mutex_unlock(mtx);
16076 +/* successful returns with iinfo write_locked */
16077 +/* todo: return with unlocked? */
16078 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16080 + struct inode *inode, *h_inode;
16081 + struct dentry *h_dentry;
16082 + struct super_block *sb;
16083 + struct mutex *mtx;
16084 + ino_t h_ino, ino;
16086 + aufs_bindex_t bstart;
16088 + sb = dentry->d_sb;
16089 + bstart = au_dbstart(dentry);
16090 + h_dentry = au_h_dptr(dentry, bstart);
16091 + h_inode = h_dentry->d_inode;
16092 + h_ino = h_inode->i_ino;
16095 + * stop 'race'-ing between hardlinks under different
16099 + if (!S_ISDIR(h_inode->i_mode))
16100 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
16105 + err = au_xino_read(sb, bstart, h_ino, &ino);
16106 + inode = ERR_PTR(err);
16107 + if (unlikely(err))
16111 + ino = au_xino_new_ino(sb);
16112 + if (unlikely(!ino)) {
16113 + inode = ERR_PTR(-EIO);
16118 + AuDbg("i%lu\n", (unsigned long)ino);
16119 + inode = au_iget_locked(sb, ino);
16120 + err = PTR_ERR(inode);
16121 + if (IS_ERR(inode))
16124 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16125 + if (inode->i_state & I_NEW) {
16126 + /* verbose coding for lock class name */
16127 + if (unlikely(S_ISLNK(h_inode->i_mode)))
16128 + au_rw_class(&au_ii(inode)->ii_rwsem,
16129 + au_lc_key + AuLcSymlink_IIINFO);
16130 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
16131 + au_rw_class(&au_ii(inode)->ii_rwsem,
16132 + au_lc_key + AuLcDir_IIINFO);
16133 + else /* likely */
16134 + au_rw_class(&au_ii(inode)->ii_rwsem,
16135 + au_lc_key + AuLcNonDir_IIINFO);
16137 + ii_write_lock_new_child(inode);
16138 + err = set_inode(inode, dentry);
16140 + unlock_new_inode(inode);
16141 + goto out; /* success */
16145 + * iget_failed() calls iput(), but we need to call
16146 + * ii_write_unlock() after iget_failed(). so dirty hack for
16149 + atomic_inc(&inode->i_count);
16150 + iget_failed(inode);
16151 + ii_write_unlock(inode);
16152 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
16153 + /* ignore this error */
16155 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16157 + * horrible race condition between lookup, readdir and copyup
16158 + * (or something).
16161 + mutex_unlock(mtx);
16162 + err = reval_inode(inode, dentry);
16163 + if (unlikely(err < 0)) {
16170 + goto out; /* success */
16175 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
16176 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16177 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16178 + bstart, au_sbtype(h_dentry->d_sb), dentry,
16179 + (unsigned long)h_ino, (unsigned long)ino);
16181 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
16185 + mutex_unlock(mtx);
16191 + inode = ERR_PTR(err);
16194 + mutex_unlock(mtx);
16198 +/* ---------------------------------------------------------------------- */
16200 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16201 + struct inode *inode)
16204 + struct inode *hi;
16206 + err = au_br_rdonly(au_sbr(sb, bindex));
16208 + /* pseudo-link after flushed may happen out of bounds */
16211 + && au_ibstart(inode) <= bindex
16212 + && bindex <= au_ibend(inode)) {
16214 + * permission check is unnecessary since vfsub routine
16215 + * will be called later
16217 + hi = au_h_iptr(inode, bindex);
16219 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16225 +int au_test_h_perm(struct inode *h_inode, int mask)
16227 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16229 + return inode_permission(h_inode, mask);
16232 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16234 + if (au_test_nfs(h_inode->i_sb)
16235 + && (mask & MAY_WRITE)
16236 + && S_ISDIR(h_inode->i_mode))
16237 + mask |= MAY_READ; /* force permission check */
16238 + return au_test_h_perm(h_inode, mask);
16240 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16241 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16242 +++ linux/fs/aufs/inode.h 2015-01-25 13:00:38.631047076 +0100
16245 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16247 + * This program, aufs is free software; you can redistribute it and/or modify
16248 + * it under the terms of the GNU General Public License as published by
16249 + * the Free Software Foundation; either version 2 of the License, or
16250 + * (at your option) any later version.
16252 + * This program is distributed in the hope that it will be useful,
16253 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16254 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16255 + * GNU General Public License for more details.
16257 + * You should have received a copy of the GNU General Public License
16258 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16262 + * inode operations
16265 +#ifndef __AUFS_INODE_H__
16266 +#define __AUFS_INODE_H__
16270 +#include <linux/fsnotify.h>
16271 +#include "rwsem.h"
16275 +struct au_hnotify {
16276 +#ifdef CONFIG_AUFS_HNOTIFY
16277 +#ifdef CONFIG_AUFS_HFSNOTIFY
16278 + /* never use fsnotify_add_vfsmount_mark() */
16279 + struct fsnotify_mark hn_mark;
16281 + struct inode *hn_aufs_inode; /* no get/put */
16283 +} ____cacheline_aligned_in_smp;
16285 +struct au_hinode {
16286 + struct inode *hi_inode;
16287 + aufs_bindex_t hi_id;
16288 +#ifdef CONFIG_AUFS_HNOTIFY
16289 + struct au_hnotify *hi_notify;
16292 + /* reference to the copied-up whiteout with get/put */
16293 + struct dentry *hi_whdentry;
16297 +#define AuIG_HALF_REFRESHED 1
16298 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16299 +#define au_ig_fset(flags, name) \
16300 + do { (flags) |= AuIG_##name; } while (0)
16301 +#define au_ig_fclr(flags, name) \
16302 + do { (flags) &= ~AuIG_##name; } while (0)
16305 + __u32 ig_generation, ig_flags;
16310 + spinlock_t ii_genspin;
16311 + struct au_iigen ii_generation;
16312 + struct super_block *ii_hsb1; /* no get/put */
16314 + struct au_rwsem ii_rwsem;
16315 + aufs_bindex_t ii_bstart, ii_bend;
16317 + struct au_hinode *ii_hinode;
16318 + struct au_vdir *ii_vdir;
16321 +struct au_icntnr {
16322 + struct au_iinfo iinfo;
16323 + struct inode vfs_inode;
16324 +} ____cacheline_aligned_in_smp;
16326 +/* au_pin flags */
16327 +#define AuPin_DI_LOCKED 1
16328 +#define AuPin_MNT_WRITE (1 << 1)
16329 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16330 +#define au_fset_pin(flags, name) \
16331 + do { (flags) |= AuPin_##name; } while (0)
16332 +#define au_fclr_pin(flags, name) \
16333 + do { (flags) &= ~AuPin_##name; } while (0)
16337 + struct dentry *dentry;
16338 + unsigned int udba;
16339 + unsigned char lsc_di, lsc_hi, flags;
16340 + aufs_bindex_t bindex;
16343 + struct dentry *parent;
16344 + struct au_hinode *hdir;
16345 + struct vfsmount *h_mnt;
16347 + /* temporary unlock/relock for copyup */
16348 + struct dentry *h_dentry, *h_parent;
16349 + struct au_branch *br;
16350 + struct task_struct *task;
16353 +void au_pin_hdir_unlock(struct au_pin *p);
16354 +int au_pin_hdir_lock(struct au_pin *p);
16355 +int au_pin_hdir_relock(struct au_pin *p);
16356 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16357 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16358 +void au_pin_hdir_release(struct au_pin *p);
16360 +/* ---------------------------------------------------------------------- */
16362 +static inline struct au_iinfo *au_ii(struct inode *inode)
16364 + struct au_iinfo *iinfo;
16366 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16367 + if (iinfo->ii_hinode)
16369 + return NULL; /* debugging bad_inode case */
16372 +/* ---------------------------------------------------------------------- */
16375 +struct inode *au_igrab(struct inode *inode);
16376 +int au_refresh_hinode_self(struct inode *inode);
16377 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16378 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16379 + unsigned int d_type, ino_t *ino);
16380 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16381 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16382 + struct inode *inode);
16383 +int au_test_h_perm(struct inode *h_inode, int mask);
16384 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16386 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16387 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16389 +#ifdef CONFIG_AUFS_SHWH
16390 + return au_ino(sb, bindex, h_ino, d_type, ino);
16397 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
16399 +/* au_wr_dir flags */
16400 +#define AuWrDir_ADD_ENTRY 1
16401 +#define AuWrDir_TMP_WHENTRY (1 << 1)
16402 +#define AuWrDir_ISDIR (1 << 2)
16403 +#define AuWrDir_TMPFILE (1 << 3)
16404 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16405 +#define au_fset_wrdir(flags, name) \
16406 + do { (flags) |= AuWrDir_##name; } while (0)
16407 +#define au_fclr_wrdir(flags, name) \
16408 + do { (flags) &= ~AuWrDir_##name; } while (0)
16410 +struct au_wr_dir_args {
16411 + aufs_bindex_t force_btgt;
16412 + unsigned char flags;
16414 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16415 + struct au_wr_dir_args *args);
16417 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16418 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16419 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16420 + unsigned int udba, unsigned char flags);
16421 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16422 + unsigned int udba, unsigned char flags) __must_check;
16423 +int au_do_pin(struct au_pin *pin) __must_check;
16424 +void au_unpin(struct au_pin *pin);
16425 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16427 +#define AuIcpup_DID_CPUP 1
16428 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16429 +#define au_fset_icpup(flags, name) \
16430 + do { (flags) |= AuIcpup_##name; } while (0)
16431 +#define au_fclr_icpup(flags, name) \
16432 + do { (flags) &= ~AuIcpup_##name; } while (0)
16434 +struct au_icpup_args {
16435 + unsigned char flags;
16436 + unsigned char pin_flags;
16437 + aufs_bindex_t btgt;
16438 + unsigned int udba;
16439 + struct au_pin pin;
16440 + struct path h_path;
16441 + struct inode *h_inode;
16444 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16445 + struct au_icpup_args *a);
16447 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16450 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16451 + struct dentry *h_parent, int isdir);
16452 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16454 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16455 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16457 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16458 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16459 + struct dentry *dentry);
16460 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16463 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16464 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16465 + struct dentry *h_parent, int isdir);
16466 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16467 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16470 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16471 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16472 + struct inode *dir, struct dentry *dentry);
16475 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16476 +void au_hiput(struct au_hinode *hinode);
16477 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16478 + struct dentry *h_wh);
16479 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16481 +/* hinode flags */
16482 +#define AuHi_XINO 1
16483 +#define AuHi_HNOTIFY (1 << 1)
16484 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16485 +#define au_fset_hi(flags, name) \
16486 + do { (flags) |= AuHi_##name; } while (0)
16487 +#define au_fclr_hi(flags, name) \
16488 + do { (flags) &= ~AuHi_##name; } while (0)
16490 +#ifndef CONFIG_AUFS_HNOTIFY
16491 +#undef AuHi_HNOTIFY
16492 +#define AuHi_HNOTIFY 0
16495 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16496 + struct inode *h_inode, unsigned int flags);
16498 +void au_update_iigen(struct inode *inode, int half);
16499 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16501 +void au_icntnr_init_once(void *_c);
16502 +int au_iinfo_init(struct inode *inode);
16503 +void au_iinfo_fin(struct inode *inode);
16504 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16506 +#ifdef CONFIG_PROC_FS
16508 +int au_plink_maint(struct super_block *sb, int flags);
16509 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16510 +int au_plink_maint_enter(struct super_block *sb);
16511 +#ifdef CONFIG_AUFS_DEBUG
16512 +void au_plink_list(struct super_block *sb);
16514 +AuStubVoid(au_plink_list, struct super_block *sb)
16516 +int au_plink_test(struct inode *inode);
16517 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16518 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16519 + struct dentry *h_dentry);
16520 +void au_plink_put(struct super_block *sb, int verbose);
16521 +void au_plink_clean(struct super_block *sb, int verbose);
16522 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16524 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16525 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16526 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16527 +AuStubVoid(au_plink_list, struct super_block *sb);
16528 +AuStubInt0(au_plink_test, struct inode *inode);
16529 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16530 + struct inode *inode, aufs_bindex_t bindex);
16531 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16532 + struct dentry *h_dentry);
16533 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16534 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16535 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16536 +#endif /* CONFIG_PROC_FS */
16538 +#ifdef CONFIG_AUFS_XATTR
16540 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags);
16541 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16542 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
16544 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
16545 + size_t size, int flags);
16546 +int aufs_removexattr(struct dentry *dentry, const char *name);
16548 +/* void au_xattr_init(struct super_block *sb); */
16550 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16551 + int ignore_flags);
16552 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16555 +#ifdef CONFIG_FS_POSIX_ACL
16556 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16557 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16560 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16567 +struct au_srxattr {
16571 + const char *name;
16572 + const void *value;
16577 + const char *name;
16580 + struct posix_acl *acl;
16585 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
16588 +/* ---------------------------------------------------------------------- */
16590 +/* lock subclass for iinfo */
16592 + AuLsc_II_CHILD, /* child first */
16593 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16594 + AuLsc_II_CHILD3, /* copyup dirs */
16595 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16596 + AuLsc_II_PARENT2,
16597 + AuLsc_II_PARENT3, /* copyup dirs */
16598 + AuLsc_II_NEW_CHILD
16602 + * ii_read_lock_child, ii_write_lock_child,
16603 + * ii_read_lock_child2, ii_write_lock_child2,
16604 + * ii_read_lock_child3, ii_write_lock_child3,
16605 + * ii_read_lock_parent, ii_write_lock_parent,
16606 + * ii_read_lock_parent2, ii_write_lock_parent2,
16607 + * ii_read_lock_parent3, ii_write_lock_parent3,
16608 + * ii_read_lock_new_child, ii_write_lock_new_child,
16610 +#define AuReadLockFunc(name, lsc) \
16611 +static inline void ii_read_lock_##name(struct inode *i) \
16613 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16616 +#define AuWriteLockFunc(name, lsc) \
16617 +static inline void ii_write_lock_##name(struct inode *i) \
16619 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16622 +#define AuRWLockFuncs(name, lsc) \
16623 + AuReadLockFunc(name, lsc) \
16624 + AuWriteLockFunc(name, lsc)
16626 +AuRWLockFuncs(child, CHILD);
16627 +AuRWLockFuncs(child2, CHILD2);
16628 +AuRWLockFuncs(child3, CHILD3);
16629 +AuRWLockFuncs(parent, PARENT);
16630 +AuRWLockFuncs(parent2, PARENT2);
16631 +AuRWLockFuncs(parent3, PARENT3);
16632 +AuRWLockFuncs(new_child, NEW_CHILD);
16634 +#undef AuReadLockFunc
16635 +#undef AuWriteLockFunc
16636 +#undef AuRWLockFuncs
16639 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16641 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16643 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16644 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16645 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16647 +/* ---------------------------------------------------------------------- */
16649 +static inline void au_icntnr_init(struct au_icntnr *c)
16651 +#ifdef CONFIG_AUFS_DEBUG
16652 + c->vfs_inode.i_mode = 0;
16656 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
16658 + unsigned int gen;
16659 + struct au_iinfo *iinfo;
16661 + iinfo = au_ii(inode);
16662 + spin_lock(&iinfo->ii_genspin);
16664 + *iigen = iinfo->ii_generation;
16665 + gen = iinfo->ii_generation.ig_generation;
16666 + spin_unlock(&iinfo->ii_genspin);
16671 +/* tiny test for inode number */
16672 +/* tmpfs generation is too rough */
16673 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16675 + struct au_iinfo *iinfo;
16677 + iinfo = au_ii(inode);
16678 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16679 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16680 + && iinfo->ii_higen == h_inode->i_generation);
16683 +static inline void au_iigen_dec(struct inode *inode)
16685 + struct au_iinfo *iinfo;
16687 + iinfo = au_ii(inode);
16688 + spin_lock(&iinfo->ii_genspin);
16689 + iinfo->ii_generation.ig_generation--;
16690 + spin_unlock(&iinfo->ii_genspin);
16693 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16698 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16704 +/* ---------------------------------------------------------------------- */
16706 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16707 + aufs_bindex_t bindex)
16709 + IiMustAnyLock(inode);
16710 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16713 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16715 + IiMustAnyLock(inode);
16716 + return au_ii(inode)->ii_bstart;
16719 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16721 + IiMustAnyLock(inode);
16722 + return au_ii(inode)->ii_bend;
16725 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16727 + IiMustAnyLock(inode);
16728 + return au_ii(inode)->ii_vdir;
16731 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16733 + IiMustAnyLock(inode);
16734 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16737 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16739 + IiMustWriteLock(inode);
16740 + au_ii(inode)->ii_bstart = bindex;
16743 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16745 + IiMustWriteLock(inode);
16746 + au_ii(inode)->ii_bend = bindex;
16749 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16751 + IiMustWriteLock(inode);
16752 + au_ii(inode)->ii_vdir = vdir;
16755 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16757 + IiMustAnyLock(inode);
16758 + return au_ii(inode)->ii_hinode + bindex;
16761 +/* ---------------------------------------------------------------------- */
16763 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16766 + return pin->parent;
16770 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16772 + if (pin && pin->hdir)
16773 + return pin->hdir->hi_inode;
16777 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16780 + return pin->hdir;
16784 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16787 + pin->dentry = dentry;
16790 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16791 + unsigned char lflag)
16795 + au_fset_pin(pin->flags, DI_LOCKED);
16797 + au_fclr_pin(pin->flags, DI_LOCKED);
16801 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16804 + dput(pin->parent);
16805 + pin->parent = dget(parent);
16809 +/* ---------------------------------------------------------------------- */
16812 +#ifdef CONFIG_AUFS_HNOTIFY
16813 +struct au_hnotify_op {
16814 + void (*ctl)(struct au_hinode *hinode, int do_set);
16815 + int (*alloc)(struct au_hinode *hinode);
16818 + * if it returns true, the the caller should free hinode->hi_notify,
16819 + * otherwise ->free() frees it.
16821 + int (*free)(struct au_hinode *hinode,
16822 + struct au_hnotify *hn) __must_check;
16824 + void (*fin)(void);
16825 + int (*init)(void);
16827 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16828 + void (*fin_br)(struct au_branch *br);
16829 + int (*init_br)(struct au_branch *br, int perm);
16833 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
16834 +void au_hn_free(struct au_hinode *hinode);
16835 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
16836 +void au_hn_reset(struct inode *inode, unsigned int flags);
16837 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
16838 + struct qstr *h_child_qstr, struct inode *h_child_inode);
16839 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
16840 +int au_hnotify_init_br(struct au_branch *br, int perm);
16841 +void au_hnotify_fin_br(struct au_branch *br);
16842 +int __init au_hnotify_init(void);
16843 +void au_hnotify_fin(void);
16846 +extern const struct au_hnotify_op au_hnotify_op;
16849 +void au_hn_init(struct au_hinode *hinode)
16851 + hinode->hi_notify = NULL;
16854 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16856 + return hinode->hi_notify;
16860 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
16861 + struct au_hinode *hinode __maybe_unused,
16862 + struct inode *inode __maybe_unused)
16863 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
16864 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
16865 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
16866 + int do_set __maybe_unused)
16867 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
16868 + unsigned int flags __maybe_unused)
16869 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
16870 + struct au_branch *br __maybe_unused,
16871 + int perm __maybe_unused)
16872 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
16873 + int perm __maybe_unused)
16874 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
16875 +AuStubInt0(__init au_hnotify_init, void)
16876 +AuStubVoid(au_hnotify_fin, void)
16877 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
16878 +#endif /* CONFIG_AUFS_HNOTIFY */
16880 +static inline void au_hn_suspend(struct au_hinode *hdir)
16882 + au_hn_ctl(hdir, /*do_set*/0);
16885 +static inline void au_hn_resume(struct au_hinode *hdir)
16887 + au_hn_ctl(hdir, /*do_set*/1);
16890 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
16892 + mutex_lock(&hdir->hi_inode->i_mutex);
16893 + au_hn_suspend(hdir);
16896 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
16897 + unsigned int sc __maybe_unused)
16899 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
16900 + au_hn_suspend(hdir);
16903 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
16905 + au_hn_resume(hdir);
16906 + mutex_unlock(&hdir->hi_inode->i_mutex);
16909 +#endif /* __KERNEL__ */
16910 +#endif /* __AUFS_INODE_H__ */
16911 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
16912 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
16913 +++ linux/fs/aufs/ioctl.c 2015-01-25 13:00:38.631047076 +0100
16916 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16918 + * This program, aufs is free software; you can redistribute it and/or modify
16919 + * it under the terms of the GNU General Public License as published by
16920 + * the Free Software Foundation; either version 2 of the License, or
16921 + * (at your option) any later version.
16923 + * This program is distributed in the hope that it will be useful,
16924 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16925 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16926 + * GNU General Public License for more details.
16928 + * You should have received a copy of the GNU General Public License
16929 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16934 + * plink-management and readdir in userspace.
16935 + * assist the pathconf(3) wrapper library.
16937 + * File-based Hierarchical Storage Management.
16940 +#include <linux/compat.h>
16941 +#include <linux/file.h>
16944 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16947 + aufs_bindex_t wbi, bindex, bend;
16948 + struct file *h_file;
16949 + struct super_block *sb;
16950 + struct dentry *root;
16951 + struct au_branch *br;
16952 + struct aufs_wbr_fd wbrfd = {
16953 + .oflags = au_dir_roflags,
16956 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
16957 + | O_NOATIME | O_CLOEXEC;
16959 + AuDebugOn(wbrfd.oflags & ~valid);
16962 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
16963 + if (unlikely(err)) {
16969 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
16970 + wbrfd.oflags |= au_dir_roflags;
16971 + AuDbg("0%o\n", wbrfd.oflags);
16972 + if (unlikely(wbrfd.oflags & ~valid))
16976 + fd = get_unused_fd();
16978 + if (unlikely(fd < 0))
16981 + h_file = ERR_PTR(-EINVAL);
16984 + sb = path->dentry->d_sb;
16985 + root = sb->s_root;
16986 + aufs_read_lock(root, AuLock_IR);
16987 + bend = au_sbend(sb);
16988 + if (wbrfd.brid >= 0) {
16989 + wbi = au_br_index(sb, wbrfd.brid);
16990 + if (unlikely(wbi < 0 || wbi > bend))
16994 + h_file = ERR_PTR(-ENOENT);
16995 + br = au_sbr(sb, wbi);
16996 + if (!au_br_writable(br->br_perm)) {
17000 + bindex = wbi + 1;
17002 + for (; bindex <= bend; bindex++) {
17003 + br = au_sbr(sb, bindex);
17004 + if (au_br_writable(br->br_perm)) {
17006 + br = au_sbr(sb, wbi);
17011 + AuDbg("wbi %d\n", wbi);
17013 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17017 + aufs_read_unlock(root, AuLock_IR);
17018 + err = PTR_ERR(h_file);
17019 + if (IS_ERR(h_file))
17022 + atomic_dec(&br->br_count); /* cf. au_h_open() */
17023 + fd_install(fd, h_file);
17025 + goto out; /* success */
17028 + put_unused_fd(fd);
17034 +/* ---------------------------------------------------------------------- */
17036 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17039 + struct dentry *dentry;
17042 + case AUFS_CTL_RDU:
17043 + case AUFS_CTL_RDU_INO:
17044 + err = au_rdu_ioctl(file, cmd, arg);
17047 + case AUFS_CTL_WBR_FD:
17048 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17051 + case AUFS_CTL_IBUSY:
17052 + err = au_ibusy_ioctl(file, arg);
17055 + case AUFS_CTL_BRINFO:
17056 + err = au_brinfo_ioctl(file, arg);
17059 + case AUFS_CTL_FHSM_FD:
17060 + dentry = file->f_dentry;
17061 + if (IS_ROOT(dentry))
17062 + err = au_fhsm_fd(dentry->d_sb, arg);
17068 + /* do not call the lower */
17069 + AuDbg("0x%x\n", cmd);
17077 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17082 + case AUFS_CTL_MVDOWN:
17083 + err = au_mvdown(file->f_dentry, (void __user *)arg);
17086 + case AUFS_CTL_WBR_FD:
17087 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17091 + /* do not call the lower */
17092 + AuDbg("0x%x\n", cmd);
17100 +#ifdef CONFIG_COMPAT
17101 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17102 + unsigned long arg)
17107 + case AUFS_CTL_RDU:
17108 + case AUFS_CTL_RDU_INO:
17109 + err = au_rdu_compat_ioctl(file, cmd, arg);
17112 + case AUFS_CTL_IBUSY:
17113 + err = au_ibusy_compat_ioctl(file, arg);
17116 + case AUFS_CTL_BRINFO:
17117 + err = au_brinfo_compat_ioctl(file, arg);
17121 + err = aufs_ioctl_dir(file, cmd, arg);
17128 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17129 + unsigned long arg)
17131 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17134 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17135 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17136 +++ linux/fs/aufs/i_op_add.c 2015-01-25 13:00:38.631047076 +0100
17139 + * Copyright (C) 2005-2014 Junjiro R. Okajima
17141 + * This program, aufs is free software; you can redistribute it and/or modify
17142 + * it under the terms of the GNU General Public License as published by
17143 + * the Free Software Foundation; either version 2 of the License, or
17144 + * (at your option) any later version.
17146 + * This program is distributed in the hope that it will be useful,
17147 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17148 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17149 + * GNU General Public License for more details.
17151 + * You should have received a copy of the GNU General Public License
17152 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17156 + * inode operations (add entry)
17162 + * final procedure of adding a new entry, except link(2).
17163 + * remove whiteout, instantiate, copyup the parent dir's times and size
17164 + * and update version.
17165 + * if it failed, re-create the removed whiteout.
17167 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17168 + struct dentry *wh_dentry, struct dentry *dentry)
17171 + aufs_bindex_t bwh;
17172 + struct path h_path;
17173 + struct super_block *sb;
17174 + struct inode *inode, *h_dir;
17175 + struct dentry *wh;
17180 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
17181 + IMustLock(h_dir);
17182 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17183 + bwh = au_dbwh(dentry);
17184 + h_path.dentry = wh_dentry;
17185 + h_path.mnt = au_sbr_mnt(sb, bindex);
17186 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17188 + if (unlikely(err))
17192 + inode = au_new_inode(dentry, /*must_new*/1);
17193 + if (!IS_ERR(inode)) {
17194 + d_instantiate(dentry, inode);
17195 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
17197 + if (au_ibstart(dir) == au_dbstart(dentry))
17198 + au_cpup_attr_timesizes(dir);
17199 + dir->i_version++;
17200 + au_fhsm_wrote(sb, bindex, /*force*/0);
17201 + return 0; /* success */
17204 + err = PTR_ERR(inode);
17209 + /* dir inode is locked */
17210 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17211 + rerr = PTR_ERR(wh);
17212 + if (IS_ERR(wh)) {
17213 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17214 + dentry, err, rerr);
17223 +static int au_d_may_add(struct dentry *dentry)
17228 + if (unlikely(d_unhashed(dentry)))
17230 + if (unlikely(dentry->d_inode))
17236 + * simple tests for the adding inode operations.
17237 + * following the checks in vfs, plus the parent-child relationship.
17239 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17240 + struct dentry *h_parent, int isdir)
17244 + struct dentry *h_dentry;
17245 + struct inode *h_inode;
17247 + err = -ENAMETOOLONG;
17248 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17251 + h_dentry = au_h_dptr(dentry, bindex);
17252 + h_inode = h_dentry->d_inode;
17253 + if (!dentry->d_inode) {
17255 + if (unlikely(h_inode))
17258 + /* rename(2) case */
17260 + if (unlikely(!h_inode || !h_inode->i_nlink))
17263 + h_mode = h_inode->i_mode;
17266 + if (unlikely(S_ISDIR(h_mode)))
17268 + } else if (unlikely(!S_ISDIR(h_mode))) {
17275 + /* expected parent dir is locked */
17276 + if (unlikely(h_parent != h_dentry->d_parent))
17285 + * initial procedure of adding a new entry.
17286 + * prepare writable branch and the parent dir, lock it,
17287 + * and lookup whiteout for the new entry.
17289 +static struct dentry*
17290 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17291 + struct dentry *src_dentry, struct au_pin *pin,
17292 + struct au_wr_dir_args *wr_dir_args)
17294 + struct dentry *wh_dentry, *h_parent;
17295 + struct super_block *sb;
17296 + struct au_branch *br;
17298 + unsigned int udba;
17299 + aufs_bindex_t bcpup;
17301 + AuDbg("%pd\n", dentry);
17303 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17305 + wh_dentry = ERR_PTR(err);
17306 + if (unlikely(err < 0))
17309 + sb = dentry->d_sb;
17310 + udba = au_opt_udba(sb);
17311 + err = au_pin(pin, dentry, bcpup, udba,
17312 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17313 + wh_dentry = ERR_PTR(err);
17314 + if (unlikely(err))
17317 + h_parent = au_pinned_h_parent(pin);
17318 + if (udba != AuOpt_UDBA_NONE
17319 + && au_dbstart(dentry) == bcpup)
17320 + err = au_may_add(dentry, bcpup, h_parent,
17321 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17322 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17323 + err = -ENAMETOOLONG;
17324 + wh_dentry = ERR_PTR(err);
17325 + if (unlikely(err))
17328 + br = au_sbr(sb, bcpup);
17330 + struct path tmp = {
17331 + .dentry = h_parent,
17332 + .mnt = au_br_mnt(br)
17334 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17337 + wh_dentry = NULL;
17338 + if (bcpup != au_dbwh(dentry))
17339 + goto out; /* success */
17341 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17344 + if (IS_ERR(wh_dentry))
17347 + return wh_dentry;
17350 +/* ---------------------------------------------------------------------- */
17352 +enum { Mknod, Symlink, Creat };
17353 +struct simple_arg {
17361 + const char *symname;
17370 +static int add_simple(struct inode *dir, struct dentry *dentry,
17371 + struct simple_arg *arg)
17374 + aufs_bindex_t bstart;
17375 + unsigned char created;
17376 + struct dentry *wh_dentry, *parent;
17377 + struct inode *h_dir;
17378 + /* to reuduce stack size */
17380 + struct au_dtime dt;
17381 + struct au_pin pin;
17382 + struct path h_path;
17383 + struct au_wr_dir_args wr_dir_args;
17386 + AuDbg("%pd\n", dentry);
17390 + a = kmalloc(sizeof(*a), GFP_NOFS);
17391 + if (unlikely(!a))
17393 + a->wr_dir_args.force_btgt = -1;
17394 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17396 + parent = dentry->d_parent; /* dir inode is locked */
17397 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17398 + if (unlikely(err))
17400 + err = au_d_may_add(dentry);
17401 + if (unlikely(err))
17403 + di_write_lock_parent(parent);
17404 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17405 + &a->pin, &a->wr_dir_args);
17406 + err = PTR_ERR(wh_dentry);
17407 + if (IS_ERR(wh_dentry))
17410 + bstart = au_dbstart(dentry);
17411 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17412 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17413 + h_dir = au_pinned_h_dir(&a->pin);
17414 + switch (arg->type) {
17416 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17417 + arg->u.c.want_excl);
17420 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17423 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17431 + err = epilog(dir, bstart, wh_dentry, dentry);
17434 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
17435 + /* no delegation since it is just created */
17436 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17439 + AuIOErr("%pd revert failure(%d, %d)\n",
17440 + dentry, err, rerr);
17443 + au_dtime_revert(&a->dt);
17446 + au_unpin(&a->pin);
17450 + di_write_unlock(parent);
17452 + if (unlikely(err)) {
17453 + au_update_dbstart(dentry);
17456 + aufs_read_unlock(dentry, AuLock_DW);
17463 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17466 + struct simple_arg arg = {
17473 + return add_simple(dir, dentry, &arg);
17476 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17478 + struct simple_arg arg = {
17480 + .u.s.symname = symname
17482 + return add_simple(dir, dentry, &arg);
17485 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17488 + struct simple_arg arg = {
17492 + .want_excl = want_excl
17495 + return add_simple(dir, dentry, &arg);
17498 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17501 + aufs_bindex_t bindex;
17502 + struct super_block *sb;
17503 + struct dentry *parent, *h_parent, *h_dentry;
17504 + struct inode *h_dir, *inode;
17505 + struct vfsmount *h_mnt;
17506 + struct au_wr_dir_args wr_dir_args = {
17507 + .force_btgt = -1,
17508 + .flags = AuWrDir_TMPFILE
17511 + /* copy-up may happen */
17512 + mutex_lock(&dir->i_mutex);
17515 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17516 + if (unlikely(err))
17519 + err = au_di_init(dentry);
17520 + if (unlikely(err))
17524 + parent = d_find_any_alias(dir);
17525 + AuDebugOn(!parent);
17526 + di_write_lock_parent(parent);
17527 + if (unlikely(parent->d_inode != dir))
17530 + err = au_digen_test(parent, au_sigen(sb));
17531 + if (unlikely(err))
17534 + bindex = au_dbstart(parent);
17535 + au_set_dbstart(dentry, bindex);
17536 + au_set_dbend(dentry, bindex);
17537 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17539 + if (unlikely(err < 0))
17542 + err = -EOPNOTSUPP;
17543 + h_dir = au_h_iptr(dir, bindex);
17544 + if (unlikely(!h_dir->i_op->tmpfile))
17547 + h_mnt = au_sbr_mnt(sb, bindex);
17548 + err = vfsub_mnt_want_write(h_mnt);
17549 + if (unlikely(err))
17552 + h_parent = au_h_dptr(parent, bindex);
17553 + err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC);
17554 + if (unlikely(err))
17558 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17559 + if (unlikely(!h_dentry))
17562 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17563 + if (unlikely(err))
17566 + au_set_dbstart(dentry, bindex);
17567 + au_set_dbend(dentry, bindex);
17568 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17569 + inode = au_new_inode(dentry, /*must_new*/1);
17570 + if (IS_ERR(inode)) {
17571 + err = PTR_ERR(inode);
17572 + au_set_h_dptr(dentry, bindex, NULL);
17573 + au_set_dbstart(dentry, -1);
17574 + au_set_dbend(dentry, -1);
17576 + if (!inode->i_nlink)
17577 + set_nlink(inode, 1);
17578 + d_tmpfile(dentry, inode);
17579 + au_di(dentry)->di_tmpfile = 1;
17581 + /* update without i_mutex */
17582 + if (au_ibstart(dir) == au_dbstart(dentry))
17583 + au_cpup_attr_timesizes(dir);
17589 + vfsub_mnt_drop_write(h_mnt);
17591 + di_write_unlock(parent);
17593 + di_write_unlock(dentry);
17596 + /* verbose coding for lock class name */
17597 + au_rw_class(&au_di(dentry)->di_rwsem,
17598 + au_lc_key + AuLcNonDir_DIINFO);
17603 + au_di_fin(dentry);
17604 + dentry->d_fsdata = NULL;
17607 + si_read_unlock(sb);
17609 + mutex_unlock(&dir->i_mutex);
17613 +/* ---------------------------------------------------------------------- */
17615 +struct au_link_args {
17616 + aufs_bindex_t bdst, bsrc;
17617 + struct au_pin pin;
17618 + struct path h_path;
17619 + struct dentry *src_parent, *parent;
17622 +static int au_cpup_before_link(struct dentry *src_dentry,
17623 + struct au_link_args *a)
17626 + struct dentry *h_src_dentry;
17627 + struct au_cp_generic cpg = {
17628 + .dentry = src_dentry,
17633 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17636 + di_read_lock_parent(a->src_parent, AuLock_IR);
17637 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17638 + if (unlikely(err))
17641 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17642 + err = au_pin(&a->pin, src_dentry, a->bdst,
17643 + au_opt_udba(src_dentry->d_sb),
17644 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17645 + if (unlikely(err))
17648 + err = au_sio_cpup_simple(&cpg);
17649 + au_unpin(&a->pin);
17652 + di_read_unlock(a->src_parent, AuLock_IR);
17656 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17657 + struct au_link_args *a)
17660 + unsigned char plink;
17661 + aufs_bindex_t bend;
17662 + struct dentry *h_src_dentry;
17663 + struct inode *h_inode, *inode, *delegated;
17664 + struct super_block *sb;
17665 + struct file *h_file;
17669 + sb = src_dentry->d_sb;
17670 + inode = src_dentry->d_inode;
17671 + if (au_ibstart(inode) <= a->bdst)
17672 + h_inode = au_h_iptr(inode, a->bdst);
17673 + if (!h_inode || !h_inode->i_nlink) {
17674 + /* copyup src_dentry as the name of dentry. */
17675 + bend = au_dbend(dentry);
17676 + if (bend < a->bsrc)
17677 + au_set_dbend(dentry, a->bsrc);
17678 + au_set_h_dptr(dentry, a->bsrc,
17679 + dget(au_h_dptr(src_dentry, a->bsrc)));
17680 + dget(a->h_path.dentry);
17681 + au_set_h_dptr(dentry, a->bdst, NULL);
17682 + AuDbg("temporary d_inode...\n");
17683 + spin_lock(&dentry->d_lock);
17684 + dentry->d_inode = src_dentry->d_inode; /* tmp */
17685 + spin_unlock(&dentry->d_lock);
17686 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17687 + if (IS_ERR(h_file))
17688 + err = PTR_ERR(h_file);
17690 + struct au_cp_generic cpg = {
17691 + .dentry = dentry,
17696 + .flags = AuCpup_KEEPLINO
17698 + err = au_sio_cpup_simple(&cpg);
17699 + au_h_open_post(dentry, a->bsrc, h_file);
17701 + dput(a->h_path.dentry);
17702 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17704 + au_set_h_dptr(dentry, a->bdst,
17705 + a->h_path.dentry);
17707 + spin_lock(&dentry->d_lock);
17708 + dentry->d_inode = NULL; /* restore */
17709 + spin_unlock(&dentry->d_lock);
17710 + AuDbg("temporary d_inode...done\n");
17711 + au_set_h_dptr(dentry, a->bsrc, NULL);
17712 + au_set_dbend(dentry, bend);
17714 + /* the inode of src_dentry already exists on a.bdst branch */
17715 + h_src_dentry = d_find_alias(h_inode);
17716 + if (!h_src_dentry && au_plink_test(inode)) {
17718 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17719 + err = PTR_ERR(h_src_dentry);
17720 + if (IS_ERR(h_src_dentry))
17723 + if (unlikely(!h_src_dentry->d_inode)) {
17724 + dput(h_src_dentry);
17725 + h_src_dentry = NULL;
17729 + if (h_src_dentry) {
17730 + delegated = NULL;
17731 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17732 + &a->h_path, &delegated);
17733 + if (unlikely(err == -EWOULDBLOCK)) {
17734 + pr_warn("cannot retry for NFSv4 delegation"
17735 + " for an internal link\n");
17738 + dput(h_src_dentry);
17740 + AuIOErr("no dentry found for hi%lu on b%d\n",
17741 + h_inode->i_ino, a->bdst);
17746 + if (!err && !plink)
17747 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17754 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17755 + struct dentry *dentry)
17758 + struct au_dtime dt;
17759 + struct au_link_args *a;
17760 + struct dentry *wh_dentry, *h_src_dentry;
17761 + struct inode *inode, *delegated;
17762 + struct super_block *sb;
17763 + struct au_wr_dir_args wr_dir_args = {
17764 + /* .force_btgt = -1, */
17765 + .flags = AuWrDir_ADD_ENTRY
17769 + inode = src_dentry->d_inode;
17770 + IMustLock(inode);
17773 + a = kzalloc(sizeof(*a), GFP_NOFS);
17774 + if (unlikely(!a))
17777 + a->parent = dentry->d_parent; /* dir inode is locked */
17778 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17779 + AuLock_NOPLM | AuLock_GEN);
17780 + if (unlikely(err))
17782 + err = au_d_linkable(src_dentry);
17783 + if (unlikely(err))
17785 + err = au_d_may_add(dentry);
17786 + if (unlikely(err))
17789 + a->src_parent = dget_parent(src_dentry);
17790 + wr_dir_args.force_btgt = au_ibstart(inode);
17792 + di_write_lock_parent(a->parent);
17793 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
17794 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
17796 + err = PTR_ERR(wh_dentry);
17797 + if (IS_ERR(wh_dentry))
17801 + sb = dentry->d_sb;
17802 + a->bdst = au_dbstart(dentry);
17803 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17804 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17805 + a->bsrc = au_ibstart(inode);
17806 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17807 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
17808 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
17809 + if (!h_src_dentry) {
17810 + a->bsrc = au_dbstart(src_dentry);
17811 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17812 + AuDebugOn(!h_src_dentry);
17813 + } else if (IS_ERR(h_src_dentry)) {
17814 + err = PTR_ERR(h_src_dentry);
17818 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17819 + if (a->bdst < a->bsrc
17820 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17821 + err = au_cpup_or_link(src_dentry, dentry, a);
17823 + delegated = NULL;
17824 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17825 + &a->h_path, &delegated);
17826 + if (unlikely(err == -EWOULDBLOCK)) {
17827 + pr_warn("cannot retry for NFSv4 delegation"
17828 + " for an internal link\n");
17832 + dput(h_src_dentry);
17835 + * copyup src_dentry to the branch we process,
17836 + * and then link(2) to it.
17838 + dput(h_src_dentry);
17839 + if (a->bdst < a->bsrc
17840 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17841 + au_unpin(&a->pin);
17842 + di_write_unlock(a->parent);
17843 + err = au_cpup_before_link(src_dentry, a);
17844 + di_write_lock_parent(a->parent);
17846 + err = au_pin(&a->pin, dentry, a->bdst,
17848 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17849 + if (unlikely(err))
17853 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17855 + if (h_src_dentry && h_src_dentry->d_inode) {
17856 + delegated = NULL;
17857 + err = vfsub_link(h_src_dentry,
17858 + au_pinned_h_dir(&a->pin),
17859 + &a->h_path, &delegated);
17860 + if (unlikely(err == -EWOULDBLOCK)) {
17861 + pr_warn("cannot retry"
17862 + " for NFSv4 delegation"
17863 + " for an internal link\n");
17869 + if (unlikely(err))
17873 + a->h_path.dentry = wh_dentry;
17874 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17876 + if (unlikely(err))
17880 + dir->i_version++;
17881 + if (au_ibstart(dir) == au_dbstart(dentry))
17882 + au_cpup_attr_timesizes(dir);
17883 + inc_nlink(inode);
17884 + inode->i_ctime = dir->i_ctime;
17885 + d_instantiate(dentry, au_igrab(inode));
17886 + if (d_unhashed(a->h_path.dentry))
17887 + /* some filesystem calls d_drop() */
17889 + /* some filesystems consume an inode even hardlink */
17890 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
17891 + goto out_unpin; /* success */
17894 + /* no delegation since it is just created */
17895 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17896 + /*delegated*/NULL, /*force*/0);
17897 + if (unlikely(rerr)) {
17898 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17901 + au_dtime_revert(&dt);
17903 + au_unpin(&a->pin);
17907 + di_write_unlock(a->parent);
17908 + dput(a->src_parent);
17910 + if (unlikely(err)) {
17911 + au_update_dbstart(dentry);
17914 + aufs_read_and_write_unlock2(dentry, src_dentry);
17922 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
17925 + aufs_bindex_t bindex;
17926 + unsigned char diropq;
17927 + struct path h_path;
17928 + struct dentry *wh_dentry, *parent, *opq_dentry;
17929 + struct mutex *h_mtx;
17930 + struct super_block *sb;
17932 + struct au_pin pin;
17933 + struct au_dtime dt;
17934 + } *a; /* reduce the stack usage */
17935 + struct au_wr_dir_args wr_dir_args = {
17936 + .force_btgt = -1,
17937 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
17943 + a = kmalloc(sizeof(*a), GFP_NOFS);
17944 + if (unlikely(!a))
17947 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17948 + if (unlikely(err))
17950 + err = au_d_may_add(dentry);
17951 + if (unlikely(err))
17954 + parent = dentry->d_parent; /* dir inode is locked */
17955 + di_write_lock_parent(parent);
17956 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17957 + &a->pin, &wr_dir_args);
17958 + err = PTR_ERR(wh_dentry);
17959 + if (IS_ERR(wh_dentry))
17962 + sb = dentry->d_sb;
17963 + bindex = au_dbstart(dentry);
17964 + h_path.dentry = au_h_dptr(dentry, bindex);
17965 + h_path.mnt = au_sbr_mnt(sb, bindex);
17966 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
17967 + if (unlikely(err))
17970 + /* make the dir opaque */
17972 + h_mtx = &h_path.dentry->d_inode->i_mutex;
17974 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
17975 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17976 + opq_dentry = au_diropq_create(dentry, bindex);
17977 + mutex_unlock(h_mtx);
17978 + err = PTR_ERR(opq_dentry);
17979 + if (IS_ERR(opq_dentry))
17981 + dput(opq_dentry);
17985 + err = epilog(dir, bindex, wh_dentry, dentry);
17988 + goto out_unpin; /* success */
17993 + AuLabel(revert opq);
17994 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17995 + rerr = au_diropq_remove(dentry, bindex);
17996 + mutex_unlock(h_mtx);
17998 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
17999 + dentry, err, rerr);
18005 + AuLabel(revert dir);
18006 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18008 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18009 + dentry, err, rerr);
18012 + au_dtime_revert(&a->dt);
18014 + au_unpin(&a->pin);
18017 + di_write_unlock(parent);
18019 + if (unlikely(err)) {
18020 + au_update_dbstart(dentry);
18023 + aufs_read_unlock(dentry, AuLock_DW);
18029 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18030 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18031 +++ linux/fs/aufs/i_op.c 2015-01-25 13:00:38.631047076 +0100
18034 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18036 + * This program, aufs is free software; you can redistribute it and/or modify
18037 + * it under the terms of the GNU General Public License as published by
18038 + * the Free Software Foundation; either version 2 of the License, or
18039 + * (at your option) any later version.
18041 + * This program is distributed in the hope that it will be useful,
18042 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18043 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18044 + * GNU General Public License for more details.
18046 + * You should have received a copy of the GNU General Public License
18047 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18051 + * inode operations (except add/del/rename)
18054 +#include <linux/device_cgroup.h>
18055 +#include <linux/fs_stack.h>
18056 +#include <linux/mm.h>
18057 +#include <linux/namei.h>
18058 +#include <linux/security.h>
18061 +static int h_permission(struct inode *h_inode, int mask,
18062 + struct vfsmount *h_mnt, int brperm)
18065 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18068 + if ((write_mask && IS_IMMUTABLE(h_inode))
18069 + || ((mask & MAY_EXEC)
18070 + && S_ISREG(h_inode->i_mode)
18071 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
18072 + || !(h_inode->i_mode & S_IXUGO))))
18076 + * - skip the lower fs test in the case of write to ro branch.
18077 + * - nfs dir permission write check is optimized, but a policy for
18078 + * link/rename requires a real check.
18080 + if ((write_mask && !au_br_writable(brperm))
18081 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18082 + && write_mask && !(mask & MAY_READ))
18083 + || !h_inode->i_op->permission) {
18084 + /* AuLabel(generic_permission); */
18085 + err = generic_permission(h_inode, mask);
18087 + /* AuLabel(h_inode->permission); */
18088 + err = h_inode->i_op->permission(h_inode, mask);
18093 + err = devcgroup_inode_permission(h_inode, mask);
18095 + err = security_inode_permission(h_inode, mask);
18099 + /* todo: do we need to call ima_path_check()? */
18100 + struct path h_path = {
18104 + err = ima_path_check(&h_path,
18105 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18106 + IMA_COUNT_LEAVE);
18114 +static int aufs_permission(struct inode *inode, int mask)
18117 + aufs_bindex_t bindex, bend;
18118 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18119 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18120 + struct inode *h_inode;
18121 + struct super_block *sb;
18122 + struct au_branch *br;
18124 + /* todo: support rcu-walk? */
18125 + if (mask & MAY_NOT_BLOCK)
18128 + sb = inode->i_sb;
18129 + si_read_lock(sb, AuLock_FLUSH);
18130 + ii_read_lock_child(inode);
18132 + err = au_iigen_test(inode, au_sigen(sb));
18133 + if (unlikely(err))
18139 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18140 + err = au_busy_or_stale();
18141 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18142 + if (unlikely(!h_inode
18143 + || (h_inode->i_mode & S_IFMT)
18144 + != (inode->i_mode & S_IFMT)))
18148 + bindex = au_ibstart(inode);
18149 + br = au_sbr(sb, bindex);
18150 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
18153 + && !special_file(h_inode->i_mode)) {
18154 + /* test whether the upper writable branch exists */
18156 + for (; bindex >= 0; bindex--)
18157 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18165 + /* non-write to dir */
18167 + bend = au_ibend(inode);
18168 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
18169 + h_inode = au_h_iptr(inode, bindex);
18171 + err = au_busy_or_stale();
18172 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18175 + br = au_sbr(sb, bindex);
18176 + err = h_permission(h_inode, mask, au_br_mnt(br),
18182 + ii_read_unlock(inode);
18183 + si_read_unlock(sb);
18187 +/* ---------------------------------------------------------------------- */
18189 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18190 + unsigned int flags)
18192 + struct dentry *ret, *parent;
18193 + struct inode *inode;
18194 + struct super_block *sb;
18195 + int err, npositive;
18199 + /* todo: support rcu-walk? */
18200 + ret = ERR_PTR(-ECHILD);
18201 + if (flags & LOOKUP_RCU)
18204 + ret = ERR_PTR(-ENAMETOOLONG);
18205 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18209 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18210 + ret = ERR_PTR(err);
18211 + if (unlikely(err))
18214 + err = au_di_init(dentry);
18215 + ret = ERR_PTR(err);
18216 + if (unlikely(err))
18220 + npositive = 0; /* suppress a warning */
18221 + parent = dentry->d_parent; /* dir inode is locked */
18222 + di_read_lock_parent(parent, AuLock_IR);
18223 + err = au_alive_dir(parent);
18225 + err = au_digen_test(parent, au_sigen(sb));
18227 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
18231 + di_read_unlock(parent, AuLock_IR);
18232 + ret = ERR_PTR(err);
18233 + if (unlikely(err < 0))
18237 + inode = au_new_inode(dentry, /*must_new*/0);
18238 + if (IS_ERR(inode)) {
18239 + ret = (void *)inode;
18246 + atomic_inc(&inode->i_count);
18247 + ret = d_splice_alias(inode, dentry);
18249 + && PTR_ERR(ret) == -EIO
18251 + && S_ISDIR(inode->i_mode)) {
18252 + atomic_inc(&inode->i_count);
18253 + ret = d_materialise_unique(dentry, inode);
18254 + if (!IS_ERR(ret))
18255 + ii_write_unlock(inode);
18258 + if (unlikely(d_need_lookup(dentry))) {
18259 + spin_lock(&dentry->d_lock);
18260 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18261 + spin_unlock(&dentry->d_lock);
18265 + if (!IS_ERR(ret))
18268 + ii_write_unlock(inode);
18275 + di_write_unlock(dentry);
18277 + /* verbose coding for lock class name */
18278 + if (unlikely(S_ISLNK(inode->i_mode)))
18279 + au_rw_class(&au_di(dentry)->di_rwsem,
18280 + au_lc_key + AuLcSymlink_DIINFO);
18281 + else if (unlikely(S_ISDIR(inode->i_mode)))
18282 + au_rw_class(&au_di(dentry)->di_rwsem,
18283 + au_lc_key + AuLcDir_DIINFO);
18284 + else /* likely */
18285 + au_rw_class(&au_di(dentry)->di_rwsem,
18286 + au_lc_key + AuLcNonDir_DIINFO);
18289 + si_read_unlock(sb);
18294 +/* ---------------------------------------------------------------------- */
18296 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18297 + const unsigned char add_entry, aufs_bindex_t bcpup,
18298 + aufs_bindex_t bstart)
18301 + struct dentry *h_parent;
18302 + struct inode *h_dir;
18305 + IMustLock(parent->d_inode);
18307 + di_write_lock_parent(parent);
18310 + if (!au_h_dptr(parent, bcpup)) {
18311 + if (bstart > bcpup)
18312 + err = au_cpup_dirs(dentry, bcpup);
18313 + else if (bstart < bcpup)
18314 + err = au_cpdown_dirs(dentry, bcpup);
18318 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18319 + h_parent = au_h_dptr(parent, bcpup);
18320 + h_dir = h_parent->d_inode;
18321 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
18322 + err = au_lkup_neg(dentry, bcpup,
18323 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
18324 + /* todo: no unlock here */
18325 + mutex_unlock(&h_dir->i_mutex);
18327 + AuDbg("bcpup %d\n", bcpup);
18329 + if (!dentry->d_inode)
18330 + au_set_h_dptr(dentry, bstart, NULL);
18331 + au_update_dbrange(dentry, /*do_put_zero*/0);
18336 + di_write_unlock(parent);
18338 + err = bcpup; /* success */
18345 + * decide the branch and the parent dir where we will create a new entry.
18346 + * returns new bindex or an error.
18347 + * copyup the parent dir if needed.
18349 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18350 + struct au_wr_dir_args *args)
18353 + unsigned int flags;
18354 + aufs_bindex_t bcpup, bstart, src_bstart;
18355 + const unsigned char add_entry
18356 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18357 + | au_ftest_wrdir(args->flags, TMP_WHENTRY)
18358 + | au_ftest_wrdir(args->flags, TMPFILE);
18359 + struct super_block *sb;
18360 + struct dentry *parent;
18361 + struct au_sbinfo *sbinfo;
18363 + sb = dentry->d_sb;
18364 + sbinfo = au_sbi(sb);
18365 + parent = dget_parent(dentry);
18366 + bstart = au_dbstart(dentry);
18368 + if (args->force_btgt < 0) {
18369 + if (src_dentry) {
18370 + src_bstart = au_dbstart(src_dentry);
18371 + if (src_bstart < bstart)
18372 + bcpup = src_bstart;
18373 + } else if (add_entry) {
18375 + if (au_ftest_wrdir(args->flags, ISDIR))
18376 + au_fset_wbr(flags, DIR);
18377 + err = AuWbrCreate(sbinfo, dentry, flags);
18381 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
18383 + err = AuWbrCopyup(sbinfo, dentry);
18385 + if (!IS_ROOT(dentry)) {
18386 + di_read_lock_parent(parent, !AuLock_IR);
18387 + err = AuWbrCopyup(sbinfo, dentry);
18388 + di_read_unlock(parent, !AuLock_IR);
18390 + err = AuWbrCopyup(sbinfo, dentry);
18393 + if (unlikely(err < 0))
18397 + bcpup = args->force_btgt;
18398 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
18401 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18403 + if (bcpup == bstart)
18404 + goto out; /* success */
18406 + /* copyup the new parent into the branch we process */
18407 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18409 + if (!dentry->d_inode) {
18410 + au_set_h_dptr(dentry, bstart, NULL);
18411 + au_set_dbstart(dentry, bcpup);
18412 + au_set_dbend(dentry, bcpup);
18414 + AuDebugOn(add_entry
18415 + && !au_ftest_wrdir(args->flags, TMPFILE)
18416 + && !au_h_dptr(dentry, bcpup));
18424 +/* ---------------------------------------------------------------------- */
18426 +void au_pin_hdir_unlock(struct au_pin *p)
18429 + au_hn_imtx_unlock(p->hdir);
18432 +int au_pin_hdir_lock(struct au_pin *p)
18440 + /* even if an error happens later, keep this lock */
18441 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18444 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
18449 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18450 + p->h_parent, p->br);
18456 +int au_pin_hdir_relock(struct au_pin *p)
18459 + struct inode *h_i;
18460 + struct dentry *h_d[] = {
18465 + err = au_pin_hdir_lock(p);
18466 + if (unlikely(err))
18469 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18472 + h_i = h_d[i]->d_inode;
18474 + err = !h_i->i_nlink;
18481 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18483 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18484 + p->hdir->hi_inode->i_mutex.owner = task;
18488 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18491 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18492 + p->lsc_hi, 0, NULL, _RET_IP_);
18493 + au_pin_hdir_set_owner(p, current);
18497 +void au_pin_hdir_release(struct au_pin *p)
18500 + au_pin_hdir_set_owner(p, p->task);
18501 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18505 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18507 + if (pin && pin->parent)
18508 + return au_h_dptr(pin->parent, pin->bindex);
18512 +void au_unpin(struct au_pin *p)
18515 + au_pin_hdir_unlock(p);
18516 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18517 + vfsub_mnt_drop_write(p->h_mnt);
18521 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18522 + di_read_unlock(p->parent, AuLock_IR);
18523 + iput(p->hdir->hi_inode);
18525 + p->parent = NULL;
18528 + /* do not clear p->task */
18531 +int au_do_pin(struct au_pin *p)
18534 + struct super_block *sb;
18535 + struct inode *h_dir;
18538 + sb = p->dentry->d_sb;
18539 + p->br = au_sbr(sb, p->bindex);
18540 + if (IS_ROOT(p->dentry)) {
18541 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18542 + p->h_mnt = au_br_mnt(p->br);
18543 + err = vfsub_mnt_want_write(p->h_mnt);
18544 + if (unlikely(err)) {
18545 + au_fclr_pin(p->flags, MNT_WRITE);
18552 + p->h_dentry = NULL;
18553 + if (p->bindex <= au_dbend(p->dentry))
18554 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18556 + p->parent = dget_parent(p->dentry);
18557 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18558 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18561 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18562 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
18564 + h_dir = p->hdir->hi_inode;
18568 + * if DI_LOCKED is not set, then p->parent may be different
18569 + * and h_parent can be NULL.
18571 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18573 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18574 + di_read_unlock(p->parent, AuLock_IR);
18576 + p->parent = NULL;
18580 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18581 + p->h_mnt = au_br_mnt(p->br);
18582 + err = vfsub_mnt_want_write(p->h_mnt);
18583 + if (unlikely(err)) {
18584 + au_fclr_pin(p->flags, MNT_WRITE);
18585 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18586 + di_read_unlock(p->parent, AuLock_IR);
18588 + p->parent = NULL;
18594 + err = au_pin_hdir_lock(p);
18596 + goto out; /* success */
18601 + pr_err("err %d\n", err);
18602 + err = au_busy_or_stale();
18607 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
18608 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18609 + unsigned int udba, unsigned char flags)
18611 + p->dentry = dentry;
18613 + p->lsc_di = lsc_di;
18614 + p->lsc_hi = lsc_hi;
18615 + p->flags = flags;
18616 + p->bindex = bindex;
18618 + p->parent = NULL;
18622 + p->h_dentry = NULL;
18623 + p->h_parent = NULL;
18625 + p->task = current;
18628 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18629 + unsigned int udba, unsigned char flags)
18631 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
18633 + return au_do_pin(pin);
18636 +/* ---------------------------------------------------------------------- */
18639 + * ->setattr() and ->getattr() are called in various cases.
18640 + * chmod, stat: dentry is revalidated.
18641 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
18643 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
18645 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
18646 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
18649 + struct inode *inode;
18650 + struct dentry *parent;
18653 + inode = dentry->d_inode;
18654 + if (au_digen_test(dentry, sigen)) {
18655 + parent = dget_parent(dentry);
18656 + di_read_lock_parent(parent, AuLock_IR);
18657 + err = au_refresh_dentry(dentry, parent);
18658 + di_read_unlock(parent, AuLock_IR);
18666 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18667 + struct au_icpup_args *a)
18671 + aufs_bindex_t bstart, ibstart;
18672 + struct dentry *hi_wh, *parent;
18673 + struct inode *inode;
18674 + struct au_wr_dir_args wr_dir_args = {
18675 + .force_btgt = -1,
18679 + bstart = au_dbstart(dentry);
18680 + inode = dentry->d_inode;
18681 + if (S_ISDIR(inode->i_mode))
18682 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18683 + /* plink or hi_wh() case */
18684 + ibstart = au_ibstart(inode);
18685 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
18686 + wr_dir_args.force_btgt = ibstart;
18687 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18688 + if (unlikely(err < 0))
18691 + if (err != bstart)
18692 + au_fset_icpup(a->flags, DID_CPUP);
18695 + a->pin_flags = AuPin_MNT_WRITE;
18697 + if (!IS_ROOT(dentry)) {
18698 + au_fset_pin(a->pin_flags, DI_LOCKED);
18699 + parent = dget_parent(dentry);
18700 + di_write_lock_parent(parent);
18703 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
18704 + if (unlikely(err))
18707 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18708 + a->h_inode = a->h_path.dentry->d_inode;
18710 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
18711 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18712 + if (ia->ia_size < i_size_read(a->h_inode))
18713 + sz = ia->ia_size;
18714 + mutex_unlock(&a->h_inode->i_mutex);
18718 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
18719 + hi_wh = au_hi_wh(inode, a->btgt);
18721 + struct au_cp_generic cpg = {
18722 + .dentry = dentry,
18728 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
18729 + if (unlikely(err))
18731 + hi_wh = au_hi_wh(inode, a->btgt);
18732 + /* todo: revalidate hi_wh? */
18737 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
18738 + di_downgrade_lock(parent, AuLock_IR);
18742 + if (!au_ftest_icpup(a->flags, DID_CPUP))
18743 + goto out; /* success */
18745 + if (!d_unhashed(dentry)) {
18746 + struct au_cp_generic cpg = {
18747 + .dentry = dentry,
18752 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18754 + err = au_sio_cpup_simple(&cpg);
18756 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18757 + } else if (!hi_wh)
18758 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18760 + a->h_path.dentry = hi_wh; /* do not dget here */
18763 + a->h_inode = a->h_path.dentry->d_inode;
18765 + goto out; /* success */
18766 + au_unpin(&a->pin);
18769 + di_write_unlock(parent);
18774 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18778 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
18781 + struct inode *inode, *delegated;
18782 + struct super_block *sb;
18783 + struct file *file;
18784 + struct au_icpup_args *a;
18786 + inode = dentry->d_inode;
18787 + IMustLock(inode);
18790 + a = kzalloc(sizeof(*a), GFP_NOFS);
18791 + if (unlikely(!a))
18794 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
18795 + ia->ia_valid &= ~ATTR_MODE;
18798 + sb = dentry->d_sb;
18799 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18800 + if (unlikely(err))
18803 + if (ia->ia_valid & ATTR_FILE) {
18804 + /* currently ftruncate(2) only */
18805 + AuDebugOn(!S_ISREG(inode->i_mode));
18806 + file = ia->ia_file;
18807 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
18808 + if (unlikely(err))
18810 + ia->ia_file = au_hf_top(file);
18811 + a->udba = AuOpt_UDBA_NONE;
18813 + /* fchmod() doesn't pass ia_file */
18814 + a->udba = au_opt_udba(sb);
18815 + di_write_lock_child(dentry);
18816 + /* no d_unlinked(), to set UDBA_NONE for root */
18817 + if (d_unhashed(dentry))
18818 + a->udba = AuOpt_UDBA_NONE;
18819 + if (a->udba != AuOpt_UDBA_NONE) {
18820 + AuDebugOn(IS_ROOT(dentry));
18821 + err = au_reval_for_attr(dentry, au_sigen(sb));
18822 + if (unlikely(err))
18827 + err = au_pin_and_icpup(dentry, ia, a);
18828 + if (unlikely(err < 0))
18830 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
18831 + ia->ia_file = NULL;
18832 + ia->ia_valid &= ~ATTR_FILE;
18835 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
18836 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
18837 + == (ATTR_MODE | ATTR_CTIME)) {
18838 + err = security_path_chmod(&a->h_path, ia->ia_mode);
18839 + if (unlikely(err))
18841 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
18842 + && (ia->ia_valid & ATTR_CTIME)) {
18843 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
18844 + if (unlikely(err))
18848 + if (ia->ia_valid & ATTR_SIZE) {
18851 + if (ia->ia_size < i_size_read(inode))
18853 + truncate_setsize(inode, ia->ia_size);
18856 + if (ia->ia_valid & ATTR_FILE)
18858 + mutex_unlock(&a->h_inode->i_mutex);
18859 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
18860 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18862 + delegated = NULL;
18864 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
18866 + err = break_deleg_wait(&delegated);
18874 + au_cpup_attr_changeable(inode);
18877 + mutex_unlock(&a->h_inode->i_mutex);
18878 + au_unpin(&a->pin);
18879 + if (unlikely(err))
18880 + au_update_dbstart(dentry);
18882 + di_write_unlock(dentry);
18884 + fi_write_unlock(file);
18885 + ia->ia_file = file;
18886 + ia->ia_valid |= ATTR_FILE;
18889 + si_read_unlock(sb);
18897 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18898 +static int au_h_path_to_set_attr(struct dentry *dentry,
18899 + struct au_icpup_args *a, struct path *h_path)
18902 + struct super_block *sb;
18904 + sb = dentry->d_sb;
18905 + a->udba = au_opt_udba(sb);
18906 + /* no d_unlinked(), to set UDBA_NONE for root */
18907 + if (d_unhashed(dentry))
18908 + a->udba = AuOpt_UDBA_NONE;
18909 + if (a->udba != AuOpt_UDBA_NONE) {
18910 + AuDebugOn(IS_ROOT(dentry));
18911 + err = au_reval_for_attr(dentry, au_sigen(sb));
18912 + if (unlikely(err))
18915 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
18916 + if (unlikely(err < 0))
18919 + h_path->dentry = a->h_path.dentry;
18920 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
18926 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
18929 + struct path h_path;
18930 + struct super_block *sb;
18931 + struct au_icpup_args *a;
18932 + struct inode *inode, *h_inode;
18934 + inode = dentry->d_inode;
18935 + IMustLock(inode);
18938 + a = kzalloc(sizeof(*a), GFP_NOFS);
18939 + if (unlikely(!a))
18942 + sb = dentry->d_sb;
18943 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18944 + if (unlikely(err))
18947 + h_path.dentry = NULL; /* silence gcc */
18948 + di_write_lock_child(dentry);
18949 + err = au_h_path_to_set_attr(dentry, a, &h_path);
18950 + if (unlikely(err))
18953 + mutex_unlock(&a->h_inode->i_mutex);
18954 + switch (arg->type) {
18955 + case AU_XATTR_SET:
18956 + err = vfsub_setxattr(h_path.dentry,
18957 + arg->u.set.name, arg->u.set.value,
18958 + arg->u.set.size, arg->u.set.flags);
18960 + case AU_XATTR_REMOVE:
18961 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
18964 + err = -EOPNOTSUPP;
18965 + h_inode = h_path.dentry->d_inode;
18966 + if (h_inode->i_op->set_acl)
18967 + err = h_inode->i_op->set_acl(h_inode,
18968 + arg->u.acl_set.acl,
18969 + arg->u.acl_set.type);
18973 + au_cpup_attr_timesizes(inode);
18975 + au_unpin(&a->pin);
18976 + if (unlikely(err))
18977 + au_update_dbstart(dentry);
18980 + di_write_unlock(dentry);
18981 + si_read_unlock(sb);
18990 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
18991 + unsigned int nlink)
18995 + inode->i_mode = st->mode;
18996 + /* don't i_[ug]id_write() here */
18997 + inode->i_uid = st->uid;
18998 + inode->i_gid = st->gid;
18999 + inode->i_atime = st->atime;
19000 + inode->i_mtime = st->mtime;
19001 + inode->i_ctime = st->ctime;
19003 + au_cpup_attr_nlink(inode, /*force*/0);
19004 + if (S_ISDIR(inode->i_mode)) {
19005 + n = inode->i_nlink;
19008 + smp_mb(); /* for i_nlink */
19009 + /* 0 can happen */
19010 + set_nlink(inode, n);
19013 + spin_lock(&inode->i_lock);
19014 + inode->i_blocks = st->blocks;
19015 + i_size_write(inode, st->size);
19016 + spin_unlock(&inode->i_lock);
19020 + * common routine for aufs_getattr() and aufs_getxattr().
19021 + * returns zero or negative (an error).
19022 + * @dentry will be read-locked in success.
19024 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19027 + unsigned int mnt_flags, sigen;
19028 + unsigned char udba_none;
19029 + aufs_bindex_t bindex;
19030 + struct super_block *sb, *h_sb;
19031 + struct inode *inode;
19033 + h_path->mnt = NULL;
19034 + h_path->dentry = NULL;
19037 + sb = dentry->d_sb;
19038 + mnt_flags = au_mntflags(sb);
19039 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19041 + /* support fstat(2) */
19042 + if (!d_unlinked(dentry) && !udba_none) {
19043 + sigen = au_sigen(sb);
19044 + err = au_digen_test(dentry, sigen);
19046 + di_read_lock_child(dentry, AuLock_IR);
19047 + err = au_dbrange_test(dentry);
19048 + if (unlikely(err)) {
19049 + di_read_unlock(dentry, AuLock_IR);
19053 + AuDebugOn(IS_ROOT(dentry));
19054 + di_write_lock_child(dentry);
19055 + err = au_dbrange_test(dentry);
19057 + err = au_reval_for_attr(dentry, sigen);
19059 + di_downgrade_lock(dentry, AuLock_IR);
19061 + di_write_unlock(dentry);
19066 + di_read_lock_child(dentry, AuLock_IR);
19068 + inode = dentry->d_inode;
19069 + bindex = au_ibstart(inode);
19070 + h_path->mnt = au_sbr_mnt(sb, bindex);
19071 + h_sb = h_path->mnt->mnt_sb;
19073 + && !au_test_fs_bad_iattr(h_sb)
19075 + goto out; /* success */
19077 + if (au_dbstart(dentry) == bindex)
19078 + h_path->dentry = au_h_dptr(dentry, bindex);
19079 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19080 + h_path->dentry = au_plink_lkup(inode, bindex);
19081 + if (IS_ERR(h_path->dentry))
19082 + /* pretending success */
19083 + h_path->dentry = NULL;
19085 + dput(h_path->dentry);
19092 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19093 + struct dentry *dentry, struct kstat *st)
19096 + unsigned char positive;
19097 + struct path h_path;
19098 + struct inode *inode;
19099 + struct super_block *sb;
19101 + inode = dentry->d_inode;
19102 + sb = dentry->d_sb;
19103 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19104 + if (unlikely(err))
19106 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19107 + if (unlikely(err))
19109 + if (unlikely(!h_path.dentry))
19110 + /* illegally overlapped or something */
19111 + goto out_fill; /* pretending success */
19113 + positive = !!h_path.dentry->d_inode;
19115 + err = vfs_getattr(&h_path, st);
19118 + au_refresh_iattr(inode, st,
19119 + h_path.dentry->d_inode->i_nlink);
19120 + goto out_fill; /* success */
19126 + generic_fillattr(inode, st);
19128 + di_read_unlock(dentry, AuLock_IR);
19130 + si_read_unlock(sb);
19136 +/* ---------------------------------------------------------------------- */
19138 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
19142 + struct super_block *sb;
19143 + struct dentry *h_dentry;
19146 + h_dentry = au_h_dptr(dentry, bindex);
19147 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
19150 + err = security_inode_readlink(h_dentry);
19151 + if (unlikely(err))
19154 + sb = dentry->d_sb;
19155 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
19156 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
19157 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
19159 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
19165 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
19169 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19170 + if (unlikely(err))
19172 + err = au_d_hashed_positive(dentry);
19174 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
19175 + aufs_read_unlock(dentry, AuLock_IR);
19181 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
19184 + mm_segment_t old_fs;
19191 + buf.k = (void *)__get_free_page(GFP_NOFS);
19192 + if (unlikely(!buf.k))
19195 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19196 + if (unlikely(err))
19199 + err = au_d_hashed_positive(dentry);
19201 + old_fs = get_fs();
19202 + set_fs(KERNEL_DS);
19203 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
19206 + aufs_read_unlock(dentry, AuLock_IR);
19210 + /* will be freed by put_link */
19211 + nd_set_link(nd, buf.k);
19212 + return NULL; /* success */
19216 + free_page((unsigned long)buf.k);
19219 + return ERR_PTR(err);
19222 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
19223 + struct nameidata *nd, void *cookie __maybe_unused)
19227 + p = nd_get_link(nd);
19228 + if (!IS_ERR_OR_NULL(p))
19229 + free_page((unsigned long)p);
19232 +/* ---------------------------------------------------------------------- */
19234 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19237 + struct super_block *sb;
19238 + struct inode *h_inode;
19240 + sb = inode->i_sb;
19241 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19243 + si_read_lock(sb, AuLock_FLUSH);
19244 + ii_write_lock_child(inode);
19246 + h_inode = au_h_iptr(inode, au_ibstart(inode));
19247 + err = vfsub_update_time(h_inode, ts, flags);
19250 + au_cpup_attr_timesizes(inode);
19251 + ii_write_unlock(inode);
19252 + si_read_unlock(sb);
19255 + if (!err && (flags & S_VERSION))
19256 + inode_inc_iversion(inode);
19261 +/* ---------------------------------------------------------------------- */
19263 +struct inode_operations aufs_symlink_iop = {
19264 + .permission = aufs_permission,
19265 +#ifdef CONFIG_FS_POSIX_ACL
19266 + .get_acl = aufs_get_acl,
19267 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19270 + .setattr = aufs_setattr,
19271 + .getattr = aufs_getattr,
19273 +#ifdef CONFIG_AUFS_XATTR
19274 + .setxattr = aufs_setxattr,
19275 + .getxattr = aufs_getxattr,
19276 + .listxattr = aufs_listxattr,
19277 + .removexattr = aufs_removexattr,
19280 + .readlink = aufs_readlink,
19281 + .follow_link = aufs_follow_link,
19282 + .put_link = aufs_put_link,
19284 + /* .update_time = aufs_update_time */
19287 +struct inode_operations aufs_dir_iop = {
19288 + .create = aufs_create,
19289 + .lookup = aufs_lookup,
19290 + .link = aufs_link,
19291 + .unlink = aufs_unlink,
19292 + .symlink = aufs_symlink,
19293 + .mkdir = aufs_mkdir,
19294 + .rmdir = aufs_rmdir,
19295 + .mknod = aufs_mknod,
19296 + .rename = aufs_rename,
19298 + .permission = aufs_permission,
19299 +#ifdef CONFIG_FS_POSIX_ACL
19300 + .get_acl = aufs_get_acl,
19301 + .set_acl = aufs_set_acl,
19304 + .setattr = aufs_setattr,
19305 + .getattr = aufs_getattr,
19307 +#ifdef CONFIG_AUFS_XATTR
19308 + .setxattr = aufs_setxattr,
19309 + .getxattr = aufs_getxattr,
19310 + .listxattr = aufs_listxattr,
19311 + .removexattr = aufs_removexattr,
19314 + .update_time = aufs_update_time,
19315 + /* no support for atomic_open() */
19317 + .tmpfile = aufs_tmpfile
19320 +struct inode_operations aufs_iop = {
19321 + .permission = aufs_permission,
19322 +#ifdef CONFIG_FS_POSIX_ACL
19323 + .get_acl = aufs_get_acl,
19324 + .set_acl = aufs_set_acl,
19327 + .setattr = aufs_setattr,
19328 + .getattr = aufs_getattr,
19330 +#ifdef CONFIG_AUFS_XATTR
19331 + .setxattr = aufs_setxattr,
19332 + .getxattr = aufs_getxattr,
19333 + .listxattr = aufs_listxattr,
19334 + .removexattr = aufs_removexattr,
19337 + .update_time = aufs_update_time
19339 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19340 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19341 +++ linux/fs/aufs/i_op_del.c 2015-01-25 13:00:38.631047076 +0100
19344 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19346 + * This program, aufs is free software; you can redistribute it and/or modify
19347 + * it under the terms of the GNU General Public License as published by
19348 + * the Free Software Foundation; either version 2 of the License, or
19349 + * (at your option) any later version.
19351 + * This program is distributed in the hope that it will be useful,
19352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19354 + * GNU General Public License for more details.
19356 + * You should have received a copy of the GNU General Public License
19357 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19361 + * inode operations (del entry)
19367 + * decide if a new whiteout for @dentry is necessary or not.
19368 + * when it is necessary, prepare the parent dir for the upper branch whose
19369 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19370 + * be done by caller.
19372 + * 0: wh is unnecessary
19373 + * plus: wh is necessary
19376 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19378 + int need_wh, err;
19379 + aufs_bindex_t bstart;
19380 + struct super_block *sb;
19382 + sb = dentry->d_sb;
19383 + bstart = au_dbstart(dentry);
19384 + if (*bcpup < 0) {
19386 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
19387 + err = AuWbrCopyup(au_sbi(sb), dentry);
19389 + if (unlikely(err < 0))
19393 + AuDebugOn(bstart < *bcpup
19394 + || au_test_ro(sb, *bcpup, dentry->d_inode));
19395 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19397 + if (*bcpup != bstart) {
19398 + err = au_cpup_dirs(dentry, *bcpup);
19399 + if (unlikely(err))
19403 + struct au_dinfo *dinfo, *tmp;
19405 + need_wh = -ENOMEM;
19406 + dinfo = au_di(dentry);
19407 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19409 + au_di_cp(tmp, dinfo);
19410 + au_di_swap(tmp, dinfo);
19411 + /* returns the number of positive dentries */
19412 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19413 + au_di_swap(tmp, dinfo);
19414 + au_rw_write_unlock(&tmp->di_rwsem);
19418 + AuDbg("need_wh %d\n", need_wh);
19426 + * simple tests for the del-entry operations.
19427 + * following the checks in vfs, plus the parent-child relationship.
19429 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19430 + struct dentry *h_parent, int isdir)
19434 + struct dentry *h_dentry, *h_latest;
19435 + struct inode *h_inode;
19437 + h_dentry = au_h_dptr(dentry, bindex);
19438 + h_inode = h_dentry->d_inode;
19439 + if (dentry->d_inode) {
19441 + if (unlikely(!h_inode || !h_inode->i_nlink))
19444 + h_mode = h_inode->i_mode;
19447 + if (unlikely(S_ISDIR(h_mode)))
19449 + } else if (unlikely(!S_ISDIR(h_mode))) {
19454 + /* rename(2) case */
19456 + if (unlikely(h_inode))
19461 + /* expected parent dir is locked */
19462 + if (unlikely(h_parent != h_dentry->d_parent))
19467 + * rmdir a dir may break the consistency on some filesystem.
19468 + * let's try heavy test.
19471 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19472 + && au_test_h_perm(h_parent->d_inode,
19473 + MAY_EXEC | MAY_WRITE)))
19476 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19478 + if (IS_ERR(h_latest))
19480 + if (h_latest == h_dentry)
19489 + * decide the branch where we operate for @dentry. the branch index will be set
19490 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19491 + * dir for reverting.
19492 + * when a new whiteout is necessary, create it.
19494 +static struct dentry*
19495 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19496 + struct au_dtime *dt, struct au_pin *pin)
19498 + struct dentry *wh_dentry;
19499 + struct super_block *sb;
19500 + struct path h_path;
19501 + int err, need_wh;
19502 + unsigned int udba;
19503 + aufs_bindex_t bcpup;
19505 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19506 + wh_dentry = ERR_PTR(need_wh);
19507 + if (unlikely(need_wh < 0))
19510 + sb = dentry->d_sb;
19511 + udba = au_opt_udba(sb);
19513 + err = au_pin(pin, dentry, bcpup, udba,
19514 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19515 + wh_dentry = ERR_PTR(err);
19516 + if (unlikely(err))
19519 + h_path.dentry = au_pinned_h_parent(pin);
19520 + if (udba != AuOpt_UDBA_NONE
19521 + && au_dbstart(dentry) == bcpup) {
19522 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19523 + wh_dentry = ERR_PTR(err);
19524 + if (unlikely(err))
19528 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19529 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19530 + wh_dentry = NULL;
19532 + goto out; /* success, no need to create whiteout */
19534 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19535 + if (IS_ERR(wh_dentry))
19538 + /* returns with the parent is locked and wh_dentry is dget-ed */
19539 + goto out; /* success */
19544 + return wh_dentry;
19548 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19549 + * in order to be revertible and save time for removing many child whiteouts
19551 + * returns 1 when there are too many child whiteout and caller should remove
19552 + * them asynchronously. returns 0 when the number of children is enough small to
19553 + * remove now or the branch fs is a remote fs.
19554 + * otherwise return an error.
19556 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19557 + struct au_nhash *whlist, struct inode *dir)
19559 + int rmdir_later, err, dirwh;
19560 + struct dentry *h_dentry;
19561 + struct super_block *sb;
19563 + sb = dentry->d_sb;
19564 + SiMustAnyLock(sb);
19565 + h_dentry = au_h_dptr(dentry, bindex);
19566 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19567 + if (unlikely(err))
19570 + /* stop monitoring */
19571 + au_hn_free(au_hi(dentry->d_inode, bindex));
19573 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19574 + dirwh = au_sbi(sb)->si_dirwh;
19575 + rmdir_later = (dirwh <= 1);
19576 + if (!rmdir_later)
19577 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19580 + return rmdir_later;
19583 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19584 + if (unlikely(err)) {
19585 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19586 + h_dentry, bindex, err);
19596 + * final procedure for deleting a entry.
19597 + * maintain dentry and iattr.
19599 +static void epilog(struct inode *dir, struct dentry *dentry,
19600 + aufs_bindex_t bindex)
19602 + struct inode *inode;
19604 + inode = dentry->d_inode;
19606 + inode->i_ctime = dir->i_ctime;
19608 + if (au_ibstart(dir) == bindex)
19609 + au_cpup_attr_timesizes(dir);
19610 + dir->i_version++;
19614 + * when an error happened, remove the created whiteout and revert everything.
19616 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
19617 + aufs_bindex_t bwh, struct dentry *wh_dentry,
19618 + struct dentry *dentry, struct au_dtime *dt)
19621 + struct path h_path = {
19622 + .dentry = wh_dentry,
19623 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
19626 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
19628 + au_set_dbwh(dentry, bwh);
19629 + au_dtime_revert(dt);
19633 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
19637 +/* ---------------------------------------------------------------------- */
19639 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
19642 + aufs_bindex_t bwh, bindex, bstart;
19643 + struct inode *inode, *h_dir, *delegated;
19644 + struct dentry *parent, *wh_dentry;
19645 + /* to reuduce stack size */
19647 + struct au_dtime dt;
19648 + struct au_pin pin;
19649 + struct path h_path;
19655 + a = kmalloc(sizeof(*a), GFP_NOFS);
19656 + if (unlikely(!a))
19659 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19660 + if (unlikely(err))
19662 + err = au_d_hashed_positive(dentry);
19663 + if (unlikely(err))
19665 + inode = dentry->d_inode;
19666 + IMustLock(inode);
19668 + if (unlikely(S_ISDIR(inode->i_mode)))
19669 + goto out_unlock; /* possible? */
19671 + bstart = au_dbstart(dentry);
19672 + bwh = au_dbwh(dentry);
19674 + parent = dentry->d_parent; /* dir inode is locked */
19675 + di_write_lock_parent(parent);
19676 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
19678 + err = PTR_ERR(wh_dentry);
19679 + if (IS_ERR(wh_dentry))
19682 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
19683 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19684 + dget(a->h_path.dentry);
19685 + if (bindex == bstart) {
19686 + h_dir = au_pinned_h_dir(&a->pin);
19687 + delegated = NULL;
19688 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
19689 + if (unlikely(err == -EWOULDBLOCK)) {
19690 + pr_warn("cannot retry for NFSv4 delegation"
19691 + " for an internal unlink\n");
19695 + /* dir inode is locked */
19696 + h_dir = wh_dentry->d_parent->d_inode;
19697 + IMustLock(h_dir);
19702 + vfsub_drop_nlink(inode);
19703 + epilog(dir, dentry, bindex);
19705 + /* update target timestamps */
19706 + if (bindex == bstart) {
19707 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
19709 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
19711 + /* todo: this timestamp may be reverted later */
19712 + inode->i_ctime = h_dir->i_ctime;
19713 + goto out_unpin; /* success */
19720 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19727 + au_unpin(&a->pin);
19729 + dput(a->h_path.dentry);
19731 + di_write_unlock(parent);
19733 + aufs_read_unlock(dentry, AuLock_DW);
19740 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
19742 + int err, rmdir_later;
19743 + aufs_bindex_t bwh, bindex, bstart;
19744 + struct inode *inode;
19745 + struct dentry *parent, *wh_dentry, *h_dentry;
19746 + struct au_whtmp_rmdir *args;
19747 + /* to reuduce stack size */
19749 + struct au_dtime dt;
19750 + struct au_pin pin;
19756 + a = kmalloc(sizeof(*a), GFP_NOFS);
19757 + if (unlikely(!a))
19760 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
19761 + if (unlikely(err))
19763 + err = au_alive_dir(dentry);
19764 + if (unlikely(err))
19766 + inode = dentry->d_inode;
19767 + IMustLock(inode);
19769 + if (unlikely(!S_ISDIR(inode->i_mode)))
19770 + goto out_unlock; /* possible? */
19773 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
19774 + if (unlikely(!args))
19777 + parent = dentry->d_parent; /* dir inode is locked */
19778 + di_write_lock_parent(parent);
19779 + err = au_test_empty(dentry, &args->whlist);
19780 + if (unlikely(err))
19783 + bstart = au_dbstart(dentry);
19784 + bwh = au_dbwh(dentry);
19786 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
19788 + err = PTR_ERR(wh_dentry);
19789 + if (IS_ERR(wh_dentry))
19792 + h_dentry = au_h_dptr(dentry, bstart);
19795 + if (bindex == bstart) {
19796 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
19798 + rmdir_later = err;
19802 + /* stop monitoring */
19803 + au_hn_free(au_hi(inode, bstart));
19805 + /* dir inode is locked */
19806 + IMustLock(wh_dentry->d_parent->d_inode);
19811 + vfsub_dead_dir(inode);
19812 + au_set_dbdiropq(dentry, -1);
19813 + epilog(dir, dentry, bindex);
19815 + if (rmdir_later) {
19816 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
19820 + goto out_unpin; /* success */
19828 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19835 + au_unpin(&a->pin);
19839 + di_write_unlock(parent);
19841 + au_whtmp_rmdir_free(args);
19843 + aufs_read_unlock(dentry, AuLock_DW);
19850 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
19851 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
19852 +++ linux/fs/aufs/i_op_ren.c 2015-01-25 13:00:38.631047076 +0100
19855 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19857 + * This program, aufs is free software; you can redistribute it and/or modify
19858 + * it under the terms of the GNU General Public License as published by
19859 + * the Free Software Foundation; either version 2 of the License, or
19860 + * (at your option) any later version.
19862 + * This program is distributed in the hope that it will be useful,
19863 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19864 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19865 + * GNU General Public License for more details.
19867 + * You should have received a copy of the GNU General Public License
19868 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19872 + * inode operation (rename entry)
19873 + * todo: this is crazy monster
19878 +enum { AuSRC, AuDST, AuSrcDst };
19879 +enum { AuPARENT, AuCHILD, AuParentChild };
19881 +#define AuRen_ISDIR 1
19882 +#define AuRen_ISSAMEDIR (1 << 1)
19883 +#define AuRen_WHSRC (1 << 2)
19884 +#define AuRen_WHDST (1 << 3)
19885 +#define AuRen_MNT_WRITE (1 << 4)
19886 +#define AuRen_DT_DSTDIR (1 << 5)
19887 +#define AuRen_DIROPQ (1 << 6)
19888 +#define AuRen_CPUP (1 << 7)
19889 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
19890 +#define au_fset_ren(flags, name) \
19891 + do { (flags) |= AuRen_##name; } while (0)
19892 +#define au_fclr_ren(flags, name) \
19893 + do { (flags) &= ~AuRen_##name; } while (0)
19895 +struct au_ren_args {
19897 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
19899 + struct inode *dir, *inode;
19900 + struct au_hinode *hdir;
19901 + struct au_dtime dt[AuParentChild];
19902 + aufs_bindex_t bstart;
19905 +#define src_dentry sd[AuSRC].dentry
19906 +#define src_dir sd[AuSRC].dir
19907 +#define src_inode sd[AuSRC].inode
19908 +#define src_h_dentry sd[AuSRC].h_dentry
19909 +#define src_parent sd[AuSRC].parent
19910 +#define src_h_parent sd[AuSRC].h_parent
19911 +#define src_wh_dentry sd[AuSRC].wh_dentry
19912 +#define src_hdir sd[AuSRC].hdir
19913 +#define src_h_dir sd[AuSRC].hdir->hi_inode
19914 +#define src_dt sd[AuSRC].dt
19915 +#define src_bstart sd[AuSRC].bstart
19917 +#define dst_dentry sd[AuDST].dentry
19918 +#define dst_dir sd[AuDST].dir
19919 +#define dst_inode sd[AuDST].inode
19920 +#define dst_h_dentry sd[AuDST].h_dentry
19921 +#define dst_parent sd[AuDST].parent
19922 +#define dst_h_parent sd[AuDST].h_parent
19923 +#define dst_wh_dentry sd[AuDST].wh_dentry
19924 +#define dst_hdir sd[AuDST].hdir
19925 +#define dst_h_dir sd[AuDST].hdir->hi_inode
19926 +#define dst_dt sd[AuDST].dt
19927 +#define dst_bstart sd[AuDST].bstart
19929 + struct dentry *h_trap;
19930 + struct au_branch *br;
19931 + struct au_hinode *src_hinode;
19932 + struct path h_path;
19933 + struct au_nhash whlist;
19934 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
19936 + unsigned int flags;
19938 + struct au_whtmp_rmdir *thargs;
19939 + struct dentry *h_dst;
19942 +/* ---------------------------------------------------------------------- */
19945 + * functions for reverting.
19946 + * when an error happened in a single rename systemcall, we should revert
19947 + * everything as if nothing happend.
19948 + * we don't need to revert the copied-up/down the parent dir since they are
19952 +#define RevertFailure(fmt, ...) do { \
19953 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
19954 + ##__VA_ARGS__, err, rerr); \
19958 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
19962 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
19963 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
19964 + au_hn_imtx_unlock(a->src_hinode);
19965 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
19967 + RevertFailure("remove diropq %pd", a->src_dentry);
19970 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
19973 + struct inode *delegated;
19975 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
19976 + a->src_h_parent);
19977 + rerr = PTR_ERR(a->h_path.dentry);
19978 + if (IS_ERR(a->h_path.dentry)) {
19979 + RevertFailure("lkup one %pd", a->src_dentry);
19983 + delegated = NULL;
19984 + rerr = vfsub_rename(a->dst_h_dir,
19985 + au_h_dptr(a->src_dentry, a->btgt),
19986 + a->src_h_dir, &a->h_path, &delegated);
19987 + if (unlikely(rerr == -EWOULDBLOCK)) {
19988 + pr_warn("cannot retry for NFSv4 delegation"
19989 + " for an internal rename\n");
19992 + d_drop(a->h_path.dentry);
19993 + dput(a->h_path.dentry);
19994 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
19996 + RevertFailure("rename %pd", a->src_dentry);
19999 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
20003 + a->h_path.dentry = a->dst_h_dentry;
20004 + /* no delegation since it is just created */
20005 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL,
20007 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
20008 + au_set_dbstart(a->src_dentry, a->src_bstart);
20010 + RevertFailure("unlink %pd", a->dst_h_dentry);
20013 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20016 + struct inode *delegated;
20018 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20019 + a->dst_h_parent);
20020 + rerr = PTR_ERR(a->h_path.dentry);
20021 + if (IS_ERR(a->h_path.dentry)) {
20022 + RevertFailure("lkup one %pd", a->dst_dentry);
20025 + if (a->h_path.dentry->d_inode) {
20026 + d_drop(a->h_path.dentry);
20027 + dput(a->h_path.dentry);
20031 + delegated = NULL;
20032 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20034 + if (unlikely(rerr == -EWOULDBLOCK)) {
20035 + pr_warn("cannot retry for NFSv4 delegation"
20036 + " for an internal rename\n");
20039 + d_drop(a->h_path.dentry);
20040 + dput(a->h_path.dentry);
20042 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20044 + RevertFailure("rename %pd", a->h_dst);
20047 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20051 + a->h_path.dentry = a->src_wh_dentry;
20052 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20053 + au_set_dbwh(a->src_dentry, a->src_bwh);
20055 + RevertFailure("unlink %pd", a->src_wh_dentry);
20057 +#undef RevertFailure
20059 +/* ---------------------------------------------------------------------- */
20062 + * when we have to copyup the renaming entry, do it with the rename-target name
20063 + * in order to minimize the cost (the later actual rename is unnecessary).
20064 + * otherwise rename it on the target branch.
20066 +static int au_ren_or_cpup(struct au_ren_args *a)
20069 + struct dentry *d;
20070 + struct inode *delegated;
20072 + d = a->src_dentry;
20073 + if (au_dbstart(d) == a->btgt) {
20074 + a->h_path.dentry = a->dst_h_dentry;
20075 + if (au_ftest_ren(a->flags, DIROPQ)
20076 + && au_dbdiropq(d) == a->btgt)
20077 + au_fclr_ren(a->flags, DIROPQ);
20078 + AuDebugOn(au_dbstart(d) != a->btgt);
20079 + delegated = NULL;
20080 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20081 + a->dst_h_dir, &a->h_path, &delegated);
20082 + if (unlikely(err == -EWOULDBLOCK)) {
20083 + pr_warn("cannot retry for NFSv4 delegation"
20084 + " for an internal rename\n");
20090 + if (!err && a->h_dst)
20091 + /* it will be set to dinfo later */
20097 +/* cf. aufs_rmdir() */
20098 +static int au_ren_del_whtmp(struct au_ren_args *a)
20101 + struct inode *dir;
20103 + dir = a->dst_dir;
20104 + SiMustAnyLock(dir->i_sb);
20105 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20106 + au_sbi(dir->i_sb)->si_dirwh)
20107 + || au_test_fs_remote(a->h_dst->d_sb)) {
20108 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20109 + if (unlikely(err))
20110 + pr_warn("failed removing whtmp dir %pd (%d), "
20111 + "ignored.\n", a->h_dst, err);
20113 + au_nhash_wh_free(&a->thargs->whlist);
20114 + a->thargs->whlist = a->whlist;
20115 + a->whlist.nh_num = 0;
20116 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20118 + a->thargs = NULL;
20124 +/* make it 'opaque' dir. */
20125 +static int au_ren_diropq(struct au_ren_args *a)
20128 + struct dentry *diropq;
20131 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20132 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20133 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20134 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20135 + au_hn_imtx_unlock(a->src_hinode);
20136 + if (IS_ERR(diropq))
20137 + err = PTR_ERR(diropq);
20144 +static int do_rename(struct au_ren_args *a)
20147 + struct dentry *d, *h_d;
20149 + /* prepare workqueue args for asynchronous rmdir */
20150 + h_d = a->dst_h_dentry;
20151 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
20153 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20154 + if (unlikely(!a->thargs))
20156 + a->h_dst = dget(h_d);
20159 + /* create whiteout for src_dentry */
20160 + if (au_ftest_ren(a->flags, WHSRC)) {
20161 + a->src_bwh = au_dbwh(a->src_dentry);
20162 + AuDebugOn(a->src_bwh >= 0);
20164 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20165 + err = PTR_ERR(a->src_wh_dentry);
20166 + if (IS_ERR(a->src_wh_dentry))
20170 + /* lookup whiteout for dentry */
20171 + if (au_ftest_ren(a->flags, WHDST)) {
20172 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20174 + err = PTR_ERR(h_d);
20177 + if (!h_d->d_inode)
20180 + a->dst_wh_dentry = h_d;
20183 + /* rename dentry to tmpwh */
20185 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20186 + if (unlikely(err))
20189 + d = a->dst_dentry;
20190 + au_set_h_dptr(d, a->btgt, NULL);
20191 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20192 + if (unlikely(err))
20194 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20197 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
20199 + /* rename by vfs_rename or cpup */
20200 + d = a->dst_dentry;
20201 + if (au_ftest_ren(a->flags, ISDIR)
20202 + && (a->dst_wh_dentry
20203 + || au_dbdiropq(d) == a->btgt
20204 + /* hide the lower to keep xino */
20205 + || a->btgt < au_dbend(d)
20206 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20207 + au_fset_ren(a->flags, DIROPQ);
20208 + err = au_ren_or_cpup(a);
20209 + if (unlikely(err))
20210 + /* leave the copied-up one */
20213 + /* make dir opaque */
20214 + if (au_ftest_ren(a->flags, DIROPQ)) {
20215 + err = au_ren_diropq(a);
20216 + if (unlikely(err))
20220 + /* update target timestamps */
20221 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
20222 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20223 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20224 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
20226 + /* remove whiteout for dentry */
20227 + if (a->dst_wh_dentry) {
20228 + a->h_path.dentry = a->dst_wh_dentry;
20229 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20231 + if (unlikely(err))
20235 + /* remove whtmp */
20237 + au_ren_del_whtmp(a); /* ignore this error */
20239 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20241 + goto out_success;
20244 + if (au_ftest_ren(a->flags, DIROPQ))
20245 + au_ren_rev_diropq(err, a);
20247 + if (!au_ftest_ren(a->flags, CPUP))
20248 + au_ren_rev_rename(err, a);
20250 + au_ren_rev_cpup(err, a);
20254 + au_ren_rev_whtmp(err, a);
20256 + dput(a->dst_wh_dentry);
20257 + a->dst_wh_dentry = NULL;
20259 + if (a->src_wh_dentry)
20260 + au_ren_rev_whsrc(err, a);
20262 + dput(a->src_wh_dentry);
20263 + dput(a->dst_wh_dentry);
20267 + au_whtmp_rmdir_free(a->thargs);
20268 + a->thargs = NULL;
20274 +/* ---------------------------------------------------------------------- */
20277 + * test if @dentry dir can be rename destination or not.
20278 + * success means, it is a logically empty dir.
20280 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20282 + return au_test_empty(dentry, whlist);
20286 + * test if @dentry dir can be rename source or not.
20287 + * if it can, return 0 and @children is filled.
20289 + * - it is a logically empty dir.
20290 + * - or, it exists on writable branch and has no children including whiteouts
20291 + * on the lower branch.
20293 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20296 + unsigned int rdhash;
20297 + aufs_bindex_t bstart;
20299 + bstart = au_dbstart(dentry);
20300 + if (bstart != btgt) {
20301 + struct au_nhash whlist;
20303 + SiMustAnyLock(dentry->d_sb);
20304 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20306 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20308 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20309 + if (unlikely(err))
20311 + err = au_test_empty(dentry, &whlist);
20312 + au_nhash_wh_free(&whlist);
20316 + if (bstart == au_dbtaildir(dentry))
20317 + return 0; /* success */
20319 + err = au_test_empty_lower(dentry);
20322 + if (err == -ENOTEMPTY) {
20323 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20324 + " is not supported\n");
20330 +/* side effect: sets whlist and h_dentry */
20331 +static int au_ren_may_dir(struct au_ren_args *a)
20334 + unsigned int rdhash;
20335 + struct dentry *d;
20337 + d = a->dst_dentry;
20338 + SiMustAnyLock(d->d_sb);
20341 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20342 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20344 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20345 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20346 + if (unlikely(err))
20349 + au_set_dbstart(d, a->dst_bstart);
20350 + err = may_rename_dstdir(d, &a->whlist);
20351 + au_set_dbstart(d, a->btgt);
20353 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
20354 + if (unlikely(err))
20357 + d = a->src_dentry;
20358 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
20359 + if (au_ftest_ren(a->flags, ISDIR)) {
20360 + err = may_rename_srcdir(d, a->btgt);
20361 + if (unlikely(err)) {
20362 + au_nhash_wh_free(&a->whlist);
20363 + a->whlist.nh_num = 0;
20370 +/* ---------------------------------------------------------------------- */
20373 + * simple tests for rename.
20374 + * following the checks in vfs, plus the parent-child relationship.
20376 +static int au_may_ren(struct au_ren_args *a)
20379 + struct inode *h_inode;
20381 + if (a->src_bstart == a->btgt) {
20382 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20383 + au_ftest_ren(a->flags, ISDIR));
20384 + if (unlikely(err))
20387 + if (unlikely(a->src_h_dentry == a->h_trap))
20392 + if (a->dst_bstart != a->btgt)
20395 + err = -ENOTEMPTY;
20396 + if (unlikely(a->dst_h_dentry == a->h_trap))
20400 + h_inode = a->dst_h_dentry->d_inode;
20401 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20402 + if (!a->dst_dentry->d_inode) {
20403 + if (unlikely(h_inode))
20405 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
20408 + if (unlikely(!h_inode || !h_inode->i_nlink))
20410 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
20412 + if (unlikely(err))
20417 + if (unlikely(err == -ENOENT || err == -EEXIST))
20423 +/* ---------------------------------------------------------------------- */
20428 + * - src_dir and dir by lock_rename()
20429 + * - inode if exitsts
20432 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20434 + * + di_write_lock2_child()
20435 + * + di_write_lock_child()
20436 + * + ii_write_lock_child()
20437 + * + di_write_lock_child2()
20438 + * + ii_write_lock_child2()
20439 + * + src_parent and parent
20440 + * + di_write_lock_parent()
20441 + * + ii_write_lock_parent()
20442 + * + di_write_lock_parent2()
20443 + * + ii_write_lock_parent2()
20444 + * + lower src_dir and dir by vfsub_lock_rename()
20445 + * + verify the every relationships between child and parent. if any
20446 + * of them failed, unlock all and return -EBUSY.
20448 +static void au_ren_unlock(struct au_ren_args *a)
20450 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20451 + a->dst_h_parent, a->dst_hdir);
20452 + if (au_ftest_ren(a->flags, MNT_WRITE))
20453 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20456 +static int au_ren_lock(struct au_ren_args *a)
20459 + unsigned int udba;
20462 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20463 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20464 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20465 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20467 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20468 + if (unlikely(err))
20470 + au_fset_ren(a->flags, MNT_WRITE);
20471 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20472 + a->dst_h_parent, a->dst_hdir);
20473 + udba = au_opt_udba(a->src_dentry->d_sb);
20474 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
20475 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
20476 + err = au_busy_or_stale();
20477 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20478 + err = au_h_verify(a->src_h_dentry, udba,
20479 + a->src_h_parent->d_inode, a->src_h_parent,
20481 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20482 + err = au_h_verify(a->dst_h_dentry, udba,
20483 + a->dst_h_parent->d_inode, a->dst_h_parent,
20486 + goto out; /* success */
20488 + err = au_busy_or_stale();
20489 + au_ren_unlock(a);
20495 +/* ---------------------------------------------------------------------- */
20497 +static void au_ren_refresh_dir(struct au_ren_args *a)
20499 + struct inode *dir;
20501 + dir = a->dst_dir;
20502 + dir->i_version++;
20503 + if (au_ftest_ren(a->flags, ISDIR)) {
20504 + /* is this updating defined in POSIX? */
20505 + au_cpup_attr_timesizes(a->src_inode);
20506 + au_cpup_attr_nlink(dir, /*force*/1);
20509 + if (au_ibstart(dir) == a->btgt)
20510 + au_cpup_attr_timesizes(dir);
20512 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20515 + dir = a->src_dir;
20516 + dir->i_version++;
20517 + if (au_ftest_ren(a->flags, ISDIR))
20518 + au_cpup_attr_nlink(dir, /*force*/1);
20519 + if (au_ibstart(dir) == a->btgt)
20520 + au_cpup_attr_timesizes(dir);
20523 +static void au_ren_refresh(struct au_ren_args *a)
20525 + aufs_bindex_t bend, bindex;
20526 + struct dentry *d, *h_d;
20527 + struct inode *i, *h_i;
20528 + struct super_block *sb;
20530 + d = a->dst_dentry;
20533 + /* already dget-ed by au_ren_or_cpup() */
20534 + au_set_h_dptr(d, a->btgt, a->h_dst);
20536 + i = a->dst_inode;
20538 + if (!au_ftest_ren(a->flags, ISDIR))
20539 + vfsub_drop_nlink(i);
20541 + vfsub_dead_dir(i);
20542 + au_cpup_attr_timesizes(i);
20544 + au_update_dbrange(d, /*do_put_zero*/1);
20547 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20548 + au_set_h_dptr(d, bindex, NULL);
20549 + bend = au_dbend(d);
20550 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20551 + au_set_h_dptr(d, bindex, NULL);
20552 + au_update_dbrange(d, /*do_put_zero*/0);
20555 + d = a->src_dentry;
20556 + au_set_dbwh(d, -1);
20557 + bend = au_dbend(d);
20558 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20559 + h_d = au_h_dptr(d, bindex);
20561 + au_set_h_dptr(d, bindex, NULL);
20563 + au_set_dbend(d, a->btgt);
20566 + i = a->src_inode;
20567 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20568 + return; /* success */
20570 + bend = au_ibend(i);
20571 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20572 + h_i = au_h_iptr(i, bindex);
20574 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20575 + /* ignore this error */
20576 + au_set_h_iptr(i, bindex, NULL, 0);
20579 + au_set_ibend(i, a->btgt);
20582 +/* ---------------------------------------------------------------------- */
20584 +/* mainly for link(2) and rename(2) */
20585 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20587 + aufs_bindex_t bdiropq, bwh;
20588 + struct dentry *parent;
20589 + struct au_branch *br;
20591 + parent = dentry->d_parent;
20592 + IMustLock(parent->d_inode); /* dir is locked */
20594 + bdiropq = au_dbdiropq(parent);
20595 + bwh = au_dbwh(dentry);
20596 + br = au_sbr(dentry->d_sb, btgt);
20597 + if (au_br_rdonly(br)
20598 + || (0 <= bdiropq && bdiropq < btgt)
20599 + || (0 <= bwh && bwh < btgt))
20602 + AuDbg("btgt %d\n", btgt);
20606 +/* sets src_bstart, dst_bstart and btgt */
20607 +static int au_ren_wbr(struct au_ren_args *a)
20610 + struct au_wr_dir_args wr_dir_args = {
20611 + /* .force_btgt = -1, */
20612 + .flags = AuWrDir_ADD_ENTRY
20615 + a->src_bstart = au_dbstart(a->src_dentry);
20616 + a->dst_bstart = au_dbstart(a->dst_dentry);
20617 + if (au_ftest_ren(a->flags, ISDIR))
20618 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20619 + wr_dir_args.force_btgt = a->src_bstart;
20620 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20621 + wr_dir_args.force_btgt = a->dst_bstart;
20622 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20623 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
20629 +static void au_ren_dt(struct au_ren_args *a)
20631 + a->h_path.dentry = a->src_h_parent;
20632 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
20633 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
20634 + a->h_path.dentry = a->dst_h_parent;
20635 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
20638 + au_fclr_ren(a->flags, DT_DSTDIR);
20639 + if (!au_ftest_ren(a->flags, ISDIR))
20642 + a->h_path.dentry = a->src_h_dentry;
20643 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
20644 + if (a->dst_h_dentry->d_inode) {
20645 + au_fset_ren(a->flags, DT_DSTDIR);
20646 + a->h_path.dentry = a->dst_h_dentry;
20647 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
20651 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
20653 + struct dentry *h_d;
20654 + struct mutex *h_mtx;
20656 + au_dtime_revert(a->src_dt + AuPARENT);
20657 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
20658 + au_dtime_revert(a->dst_dt + AuPARENT);
20660 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
20661 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
20662 + h_mtx = &h_d->d_inode->i_mutex;
20663 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20664 + au_dtime_revert(a->src_dt + AuCHILD);
20665 + mutex_unlock(h_mtx);
20667 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
20668 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
20669 + h_mtx = &h_d->d_inode->i_mutex;
20670 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20671 + au_dtime_revert(a->dst_dt + AuCHILD);
20672 + mutex_unlock(h_mtx);
20677 +/* ---------------------------------------------------------------------- */
20679 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
20680 + struct inode *_dst_dir, struct dentry *_dst_dentry)
20683 + /* reduce stack space */
20684 + struct au_ren_args *a;
20686 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
20687 + IMustLock(_src_dir);
20688 + IMustLock(_dst_dir);
20691 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
20692 + a = kzalloc(sizeof(*a), GFP_NOFS);
20693 + if (unlikely(!a))
20696 + a->src_dir = _src_dir;
20697 + a->src_dentry = _src_dentry;
20698 + a->src_inode = a->src_dentry->d_inode;
20699 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
20700 + a->dst_dir = _dst_dir;
20701 + a->dst_dentry = _dst_dentry;
20702 + a->dst_inode = a->dst_dentry->d_inode;
20703 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
20704 + if (a->dst_inode) {
20705 + IMustLock(a->dst_inode);
20706 + au_igrab(a->dst_inode);
20710 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
20711 + if (S_ISDIR(a->src_inode->i_mode)) {
20712 + au_fset_ren(a->flags, ISDIR);
20713 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
20715 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20716 + AuLock_DIR | flags);
20718 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20720 + if (unlikely(err))
20723 + err = au_d_hashed_positive(a->src_dentry);
20724 + if (unlikely(err))
20727 + if (a->dst_inode) {
20729 + * If it is a dir, VFS unhash dst_dentry before this
20730 + * function. It means we cannot rely upon d_unhashed().
20732 + if (unlikely(!a->dst_inode->i_nlink))
20734 + if (!S_ISDIR(a->dst_inode->i_mode)) {
20735 + err = au_d_hashed_positive(a->dst_dentry);
20736 + if (unlikely(err))
20738 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
20740 + } else if (unlikely(d_unhashed(a->dst_dentry)))
20744 + * is it possible?
20745 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
20746 + * there may exist a problem somewhere else.
20749 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
20752 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
20753 + di_write_lock_parent(a->dst_parent);
20755 + /* which branch we process */
20756 + err = au_ren_wbr(a);
20757 + if (unlikely(err < 0))
20759 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
20760 + a->h_path.mnt = au_br_mnt(a->br);
20762 + /* are they available to be renamed */
20763 + err = au_ren_may_dir(a);
20764 + if (unlikely(err))
20765 + goto out_children;
20767 + /* prepare the writable parent dir on the same branch */
20768 + if (a->dst_bstart == a->btgt) {
20769 + au_fset_ren(a->flags, WHDST);
20771 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
20772 + if (unlikely(err))
20773 + goto out_children;
20776 + if (a->src_dir != a->dst_dir) {
20778 + * this temporary unlock is safe,
20779 + * because both dir->i_mutex are locked.
20781 + di_write_unlock(a->dst_parent);
20782 + di_write_lock_parent(a->src_parent);
20783 + err = au_wr_dir_need_wh(a->src_dentry,
20784 + au_ftest_ren(a->flags, ISDIR),
20786 + di_write_unlock(a->src_parent);
20787 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
20788 + au_fclr_ren(a->flags, ISSAMEDIR);
20790 + err = au_wr_dir_need_wh(a->src_dentry,
20791 + au_ftest_ren(a->flags, ISDIR),
20793 + if (unlikely(err < 0))
20794 + goto out_children;
20796 + au_fset_ren(a->flags, WHSRC);
20799 + if (a->src_bstart != a->btgt) {
20800 + struct au_pin pin;
20802 + err = au_pin(&pin, a->src_dentry, a->btgt,
20803 + au_opt_udba(a->src_dentry->d_sb),
20804 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20806 + struct au_cp_generic cpg = {
20807 + .dentry = a->src_dentry,
20809 + .bsrc = a->src_bstart,
20812 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20814 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
20815 + err = au_sio_cpup_simple(&cpg);
20818 + if (unlikely(err))
20819 + goto out_children;
20820 + a->src_bstart = a->btgt;
20821 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
20822 + au_fset_ren(a->flags, WHSRC);
20825 + /* lock them all */
20826 + err = au_ren_lock(a);
20827 + if (unlikely(err))
20828 + /* leave the copied-up one */
20829 + goto out_children;
20831 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
20832 + err = au_may_ren(a);
20833 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
20834 + err = -ENAMETOOLONG;
20835 + if (unlikely(err))
20838 + /* store timestamps to be revertible */
20842 + err = do_rename(a);
20843 + if (unlikely(err))
20846 + /* update dir attributes */
20847 + au_ren_refresh_dir(a);
20849 + /* dput/iput all lower dentries */
20850 + au_ren_refresh(a);
20852 + goto out_hdir; /* success */
20855 + au_ren_rev_dt(err, a);
20857 + au_ren_unlock(a);
20859 + au_nhash_wh_free(&a->whlist);
20860 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
20861 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
20862 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
20863 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
20867 + d_move(a->src_dentry, a->dst_dentry);
20869 + au_update_dbstart(a->dst_dentry);
20870 + if (!a->dst_inode)
20871 + d_drop(a->dst_dentry);
20873 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20874 + di_write_unlock(a->dst_parent);
20876 + di_write_unlock2(a->src_parent, a->dst_parent);
20878 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
20880 + iput(a->dst_inode);
20882 + au_whtmp_rmdir_free(a->thargs);
20888 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
20889 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
20890 +++ linux/fs/aufs/Kconfig 2015-01-25 13:00:38.627713742 +0100
20893 + tristate "Aufs (Advanced multi layered unification filesystem) support"
20895 + Aufs is a stackable unification filesystem such as Unionfs,
20896 + which unifies several directories and provides a merged single
20898 + In the early days, aufs was entirely re-designed and
20899 + re-implemented Unionfs Version 1.x series. Introducing many
20900 + original ideas, approaches and improvements, it becomes totally
20901 + different from Unionfs while keeping the basic features.
20905 + prompt "Maximum number of branches"
20906 + default AUFS_BRANCH_MAX_127
20908 + Specifies the maximum number of branches (or member directories)
20909 + in a single aufs. The larger value consumes more system
20910 + resources and has a minor impact to performance.
20911 +config AUFS_BRANCH_MAX_127
20914 + Specifies the maximum number of branches (or member directories)
20915 + in a single aufs. The larger value consumes more system
20916 + resources and has a minor impact to performance.
20917 +config AUFS_BRANCH_MAX_511
20920 + Specifies the maximum number of branches (or member directories)
20921 + in a single aufs. The larger value consumes more system
20922 + resources and has a minor impact to performance.
20923 +config AUFS_BRANCH_MAX_1023
20926 + Specifies the maximum number of branches (or member directories)
20927 + in a single aufs. The larger value consumes more system
20928 + resources and has a minor impact to performance.
20929 +config AUFS_BRANCH_MAX_32767
20932 + Specifies the maximum number of branches (or member directories)
20933 + in a single aufs. The larger value consumes more system
20934 + resources and has a minor impact to performance.
20937 +config AUFS_SBILIST
20939 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
20942 + Automatic configuration for internal use.
20943 + When aufs supports Magic SysRq or /proc, enabled automatically.
20945 +config AUFS_HNOTIFY
20946 + bool "Detect direct branch access (bypassing aufs)"
20948 + If you want to modify files on branches directly, eg. bypassing aufs,
20949 + and want aufs to detect the changes of them fully, then enable this
20950 + option and use 'udba=notify' mount option.
20951 + Currently there is only one available configuration, "fsnotify".
20952 + It will have a negative impact to the performance.
20953 + See detail in aufs.5.
20956 + prompt "method" if AUFS_HNOTIFY
20957 + default AUFS_HFSNOTIFY
20958 +config AUFS_HFSNOTIFY
20963 +config AUFS_EXPORT
20964 + bool "NFS-exportable aufs"
20965 + depends on EXPORTFS
20967 + If you want to export your mounted aufs via NFS, then enable this
20968 + option. There are several requirements for this configuration.
20969 + See detail in aufs.5.
20971 +config AUFS_INO_T_64
20973 + depends on AUFS_EXPORT
20974 + depends on 64BIT && !(ALPHA || S390)
20977 + Automatic configuration for internal use.
20978 + /* typedef unsigned long/int __kernel_ino_t */
20979 + /* alpha and s390x are int */
20982 + bool "support for XATTR/EA (including Security Labels)"
20984 + If your branch fs supports XATTR/EA and you want to make them
20985 + available in aufs too, then enable this opsion and specify the
20986 + branch attributes for EA.
20987 + See detail in aufs.5.
20990 + bool "File-based Hierarchical Storage Management"
20992 + Hierarchical Storage Management (or HSM) is a well-known feature
20993 + in the storage world. Aufs provides this feature as file-based.
20994 + with multiple branches.
20995 + These multiple branches are prioritized, ie. the topmost one
20996 + should be the fastest drive and be used heavily.
20999 + bool "Readdir in userspace"
21001 + Aufs has two methods to provide a merged view for a directory,
21002 + by a user-space library and by kernel-space natively. The latter
21003 + is always enabled but sometimes large and slow.
21004 + If you enable this option, install the library in aufs2-util
21005 + package, and set some environment variables for your readdir(3),
21006 + then the work will be handled in user-space which generally
21007 + shows better performance in most cases.
21008 + See detail in aufs.5.
21011 + bool "Show whiteouts"
21013 + If you want to make the whiteouts in aufs visible, then enable
21014 + this option and specify 'shwh' mount option. Although it may
21015 + sounds like philosophy or something, but in technically it
21016 + simply shows the name of whiteout with keeping its behaviour.
21018 +config AUFS_BR_RAMFS
21019 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21021 + If you want to use ramfs as an aufs branch fs, then enable this
21022 + option. Generally tmpfs is recommended.
21023 + Aufs prohibited them to be a branch fs by default, because
21024 + initramfs becomes unusable after switch_root or something
21025 + generally. If you sets initramfs as an aufs branch and boot your
21026 + system by switch_root, you will meet a problem easily since the
21027 + files in initramfs may be inaccessible.
21028 + Unless you are going to use ramfs as an aufs branch fs without
21029 + switch_root or something, leave it N.
21031 +config AUFS_BR_FUSE
21032 + bool "Fuse fs as an aufs branch"
21033 + depends on FUSE_FS
21036 + If you want to use fuse-based userspace filesystem as an aufs
21037 + branch fs, then enable this option.
21038 + It implements the internal poll(2) operation which is
21039 + implemented by fuse only (curretnly).
21044 + Automatic configuration for internal use.
21046 +config AUFS_BR_HFSPLUS
21047 + bool "Hfsplus as an aufs branch"
21048 + depends on HFSPLUS_FS
21051 + If you want to use hfsplus fs as an aufs branch fs, then enable
21052 + this option. This option introduces a small overhead at
21053 + copying-up a file on hfsplus.
21055 +config AUFS_BDEV_LOOP
21057 + depends on BLK_DEV_LOOP
21060 + Automatic configuration for internal use.
21061 + Convert =[ym] into =y.
21064 + bool "Debug aufs"
21066 + Enable this to compile aufs internal debug code.
21067 + It will have a negative impact to the performance.
21069 +config AUFS_MAGIC_SYSRQ
21071 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21074 + Automatic configuration for internal use.
21075 + When aufs supports Magic SysRq, enabled automatically.
21077 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21078 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21079 +++ linux/fs/aufs/loop.c 2015-01-25 13:00:38.631047076 +0100
21082 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21084 + * This program, aufs is free software; you can redistribute it and/or modify
21085 + * it under the terms of the GNU General Public License as published by
21086 + * the Free Software Foundation; either version 2 of the License, or
21087 + * (at your option) any later version.
21089 + * This program is distributed in the hope that it will be useful,
21090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21092 + * GNU General Public License for more details.
21094 + * You should have received a copy of the GNU General Public License
21095 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21099 + * support for loopback block device as a branch
21104 +/* added into drivers/block/loop.c */
21105 +static struct file *(*backing_file_func)(struct super_block *sb);
21108 + * test if two lower dentries have overlapping branches.
21110 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21112 + struct super_block *h_sb;
21113 + struct file *backing_file;
21115 + if (unlikely(!backing_file_func)) {
21116 + /* don't load "loop" module here */
21117 + backing_file_func = symbol_get(loop_backing_file);
21118 + if (unlikely(!backing_file_func))
21119 + /* "loop" module is not loaded */
21123 + h_sb = h_adding->d_sb;
21124 + backing_file = backing_file_func(h_sb);
21125 + if (!backing_file)
21128 + h_adding = backing_file->f_dentry;
21130 + * h_adding can be local NFS.
21131 + * in this case aufs cannot detect the loop.
21133 + if (unlikely(h_adding->d_sb == sb))
21135 + return !!au_test_subdir(h_adding, sb->s_root);
21138 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21139 +int au_test_loopback_kthread(void)
21142 + struct task_struct *tsk = current;
21143 + char c, comm[sizeof(tsk->comm)];
21146 + if (tsk->flags & PF_KTHREAD) {
21147 + get_task_comm(comm, tsk);
21149 + ret = ('0' <= c && c <= '9'
21150 + && !strncmp(comm, "loop", 4));
21156 +/* ---------------------------------------------------------------------- */
21158 +#define au_warn_loopback_step 16
21159 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21160 +static unsigned long *au_warn_loopback_array;
21162 +void au_warn_loopback(struct super_block *h_sb)
21164 + int i, new_nelem;
21165 + unsigned long *a, magic;
21166 + static DEFINE_SPINLOCK(spin);
21168 + magic = h_sb->s_magic;
21169 + spin_lock(&spin);
21170 + a = au_warn_loopback_array;
21171 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21172 + if (a[i] == magic) {
21173 + spin_unlock(&spin);
21177 + /* h_sb is new to us, print it */
21178 + if (i < au_warn_loopback_nelem) {
21183 + /* expand the array */
21184 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21185 + a = au_kzrealloc(au_warn_loopback_array,
21186 + au_warn_loopback_nelem * sizeof(unsigned long),
21187 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
21189 + au_warn_loopback_nelem = new_nelem;
21190 + au_warn_loopback_array = a;
21195 + spin_unlock(&spin);
21196 + AuWarn1("realloc failed, ignored\n");
21200 + spin_unlock(&spin);
21201 + pr_warn("you may want to try another patch for loopback file "
21202 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21205 +int au_loopback_init(void)
21208 + struct super_block *sb __maybe_unused;
21210 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
21213 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21214 + sizeof(unsigned long), GFP_NOFS);
21215 + if (unlikely(!au_warn_loopback_array))
21221 +void au_loopback_fin(void)
21223 + symbol_put(loop_backing_file);
21224 + kfree(au_warn_loopback_array);
21226 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21227 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21228 +++ linux/fs/aufs/loop.h 2015-01-25 13:00:38.631047076 +0100
21231 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21233 + * This program, aufs is free software; you can redistribute it and/or modify
21234 + * it under the terms of the GNU General Public License as published by
21235 + * the Free Software Foundation; either version 2 of the License, or
21236 + * (at your option) any later version.
21238 + * This program is distributed in the hope that it will be useful,
21239 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21240 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21241 + * GNU General Public License for more details.
21243 + * You should have received a copy of the GNU General Public License
21244 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21248 + * support for loopback mount as a branch
21251 +#ifndef __AUFS_LOOP_H__
21252 +#define __AUFS_LOOP_H__
21257 +struct super_block;
21259 +#ifdef CONFIG_AUFS_BDEV_LOOP
21260 +/* drivers/block/loop.c */
21261 +struct file *loop_backing_file(struct super_block *sb);
21264 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21265 +int au_test_loopback_kthread(void);
21266 +void au_warn_loopback(struct super_block *h_sb);
21268 +int au_loopback_init(void);
21269 +void au_loopback_fin(void);
21271 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21272 + struct dentry *h_adding)
21273 +AuStubInt0(au_test_loopback_kthread, void)
21274 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21276 +AuStubInt0(au_loopback_init, void)
21277 +AuStubVoid(au_loopback_fin, void)
21278 +#endif /* BLK_DEV_LOOP */
21280 +#endif /* __KERNEL__ */
21281 +#endif /* __AUFS_LOOP_H__ */
21282 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21283 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21284 +++ linux/fs/aufs/magic.mk 2015-01-25 13:00:38.631047076 +0100
21287 +# defined in ${srctree}/fs/fuse/inode.c
21289 +ifdef CONFIG_FUSE_FS
21290 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21293 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
21295 +ifdef CONFIG_OCFS2_FS
21296 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
21299 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
21301 +ifdef CONFIG_OCFS2_FS_O2CB
21302 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
21305 +# defined in ${srctree}/fs/cifs/cifsfs.c
21307 +ifdef CONFIG_CIFS_FS
21308 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
21311 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21313 +ifdef CONFIG_XFS_FS
21314 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21317 +# defined in ${srctree}/fs/configfs/mount.c
21319 +ifdef CONFIG_CONFIGFS_FS
21320 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21323 +# defined in ${srctree}/fs/9p/v9fs.h
21325 +ifdef CONFIG_9P_FS
21326 +ccflags-y += -DV9FS_MAGIC=0x01021997
21329 +# defined in ${srctree}/fs/ubifs/ubifs.h
21331 +ifdef CONFIG_UBIFS_FS
21332 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21335 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21337 +ifdef CONFIG_HFSPLUS_FS
21338 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21340 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21341 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21342 +++ linux/fs/aufs/Makefile 2015-01-25 13:00:38.627713742 +0100
21345 +include ${src}/magic.mk
21346 +ifeq (${CONFIG_AUFS_FS},m)
21347 +include ${src}/conf.mk
21349 +-include ${src}/priv_def.mk
21351 +# cf. include/linux/kernel.h
21353 +ccflags-y += -DDEBUG
21354 +# sparse requires the full pathname
21356 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21358 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21361 +obj-$(CONFIG_AUFS_FS) += aufs.o
21362 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21363 + wkq.o vfsub.o dcsub.o \
21364 + cpup.o whout.o wbr_policy.o \
21365 + dinfo.o dentry.o \
21367 + finfo.o file.o f_op.o \
21369 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21373 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21374 +aufs-$(CONFIG_SYSFS) += sysfs.o
21375 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21376 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21377 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21378 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21379 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21380 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21381 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21382 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21383 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21384 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21385 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21386 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21387 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21388 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21389 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21390 +++ linux/fs/aufs/module.c 2015-01-25 13:00:38.634380408 +0100
21393 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21395 + * This program, aufs is free software; you can redistribute it and/or modify
21396 + * it under the terms of the GNU General Public License as published by
21397 + * the Free Software Foundation; either version 2 of the License, or
21398 + * (at your option) any later version.
21400 + * This program is distributed in the hope that it will be useful,
21401 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21402 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21403 + * GNU General Public License for more details.
21405 + * You should have received a copy of the GNU General Public License
21406 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21410 + * module global variables and operations
21413 +#include <linux/module.h>
21414 +#include <linux/seq_file.h>
21417 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21419 + if (new_sz <= nused)
21422 + p = krealloc(p, new_sz, gfp);
21424 + memset(p + nused, 0, new_sz - nused);
21428 +/* ---------------------------------------------------------------------- */
21433 +struct kmem_cache *au_cachep[AuCache_Last];
21434 +static int __init au_cache_init(void)
21436 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21437 + if (au_cachep[AuCache_DINFO])
21438 + /* SLAB_DESTROY_BY_RCU */
21439 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21440 + au_icntnr_init_once);
21441 + if (au_cachep[AuCache_ICNTNR])
21442 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21443 + au_fi_init_once);
21444 + if (au_cachep[AuCache_FINFO])
21445 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21446 + if (au_cachep[AuCache_VDIR])
21447 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21448 + if (au_cachep[AuCache_DEHSTR])
21454 +static void au_cache_fin(void)
21459 + * Make sure all delayed rcu free inodes are flushed before we
21464 + /* excluding AuCache_HNOTIFY */
21465 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21466 + for (i = 0; i < AuCache_HNOTIFY; i++)
21467 + if (au_cachep[i]) {
21468 + kmem_cache_destroy(au_cachep[i]);
21469 + au_cachep[i] = NULL;
21473 +/* ---------------------------------------------------------------------- */
21475 +int au_dir_roflags;
21477 +#ifdef CONFIG_AUFS_SBILIST
21479 + * iterate_supers_type() doesn't protect us from
21480 + * remounting (branch management)
21482 +struct au_splhead au_sbilist;
21485 +struct lock_class_key au_lc_key[AuLcKey_Last];
21488 + * functions for module interface.
21490 +MODULE_LICENSE("GPL");
21491 +/* MODULE_LICENSE("GPL v2"); */
21492 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21493 +MODULE_DESCRIPTION(AUFS_NAME
21494 + " -- Advanced multi layered unification filesystem");
21495 +MODULE_VERSION(AUFS_VERSION);
21496 +MODULE_ALIAS_FS(AUFS_NAME);
21498 +/* this module parameter has no meaning when SYSFS is disabled */
21499 +int sysaufs_brs = 1;
21500 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21501 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21503 +/* this module parameter has no meaning when USER_NS is disabled */
21504 +static bool au_userns;
21505 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21506 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21508 +/* ---------------------------------------------------------------------- */
21510 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21512 +int au_seq_path(struct seq_file *seq, struct path *path)
21514 + return seq_path(seq, path, au_esc_chars);
21517 +/* ---------------------------------------------------------------------- */
21519 +static int __init aufs_init(void)
21524 + p = au_esc_chars;
21525 + for (i = 1; i <= ' '; i++)
21531 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21533 + au_sbilist_init();
21534 + sysaufs_brs_init();
21537 + err = sysaufs_init();
21538 + if (unlikely(err))
21540 + err = au_procfs_init();
21541 + if (unlikely(err))
21542 + goto out_sysaufs;
21543 + err = au_wkq_init();
21544 + if (unlikely(err))
21546 + err = au_loopback_init();
21547 + if (unlikely(err))
21549 + err = au_hnotify_init();
21550 + if (unlikely(err))
21551 + goto out_loopback;
21552 + err = au_sysrq_init();
21553 + if (unlikely(err))
21555 + err = au_cache_init();
21556 + if (unlikely(err))
21559 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21560 + err = register_filesystem(&aufs_fs_type);
21561 + if (unlikely(err))
21564 + /* since we define pr_fmt, call printk directly */
21565 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21566 + goto out; /* success */
21573 + au_hnotify_fin();
21575 + au_loopback_fin();
21587 +static void __exit aufs_exit(void)
21589 + unregister_filesystem(&aufs_fs_type);
21592 + au_hnotify_fin();
21593 + au_loopback_fin();
21600 +module_init(aufs_init);
21601 +module_exit(aufs_exit);
21602 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21603 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21604 +++ linux/fs/aufs/module.h 2015-01-25 13:00:38.634380408 +0100
21607 + * Copyright (C) 2005-2014 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 + * module initialization and module-global
21627 +#ifndef __AUFS_MODULE_H__
21628 +#define __AUFS_MODULE_H__
21632 +#include <linux/slab.h>
21637 +/* module parameters */
21638 +extern int sysaufs_brs;
21640 +/* ---------------------------------------------------------------------- */
21642 +extern int au_dir_roflags;
21645 + AuLcNonDir_FIINFO,
21646 + AuLcNonDir_DIINFO,
21647 + AuLcNonDir_IIINFO,
21653 + AuLcSymlink_DIINFO,
21654 + AuLcSymlink_IIINFO,
21658 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
21660 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
21661 +int au_seq_path(struct seq_file *seq, struct path *path);
21663 +#ifdef CONFIG_PROC_FS
21665 +int __init au_procfs_init(void);
21666 +void au_procfs_fin(void);
21668 +AuStubInt0(au_procfs_init, void);
21669 +AuStubVoid(au_procfs_fin, void);
21672 +/* ---------------------------------------------------------------------- */
21681 + AuCache_HNOTIFY, /* must be last */
21685 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
21686 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
21687 +#define AuCacheCtor(type, ctor) \
21688 + kmem_cache_create(#type, sizeof(struct type), \
21689 + __alignof__(struct type), AuCacheFlags, ctor)
21691 +extern struct kmem_cache *au_cachep[];
21693 +#define AuCacheFuncs(name, index) \
21694 +static inline struct au_##name *au_cache_alloc_##name(void) \
21695 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
21696 +static inline void au_cache_free_##name(struct au_##name *p) \
21697 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
21699 +AuCacheFuncs(dinfo, DINFO);
21700 +AuCacheFuncs(icntnr, ICNTNR);
21701 +AuCacheFuncs(finfo, FINFO);
21702 +AuCacheFuncs(vdir, VDIR);
21703 +AuCacheFuncs(vdir_dehstr, DEHSTR);
21704 +#ifdef CONFIG_AUFS_HNOTIFY
21705 +AuCacheFuncs(hnotify, HNOTIFY);
21708 +#endif /* __KERNEL__ */
21709 +#endif /* __AUFS_MODULE_H__ */
21710 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
21711 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
21712 +++ linux/fs/aufs/mvdown.c 2015-01-25 13:00:38.634380408 +0100
21715 + * Copyright (C) 2011-2014 Junjiro R. Okajima
21717 + * This program, aufs is free software; you can redistribute it and/or modify
21718 + * it under the terms of the GNU General Public License as published by
21719 + * the Free Software Foundation; either version 2 of the License, or
21720 + * (at your option) any later version.
21722 + * This program is distributed in the hope that it will be useful,
21723 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21724 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21725 + * GNU General Public License for more details.
21727 + * You should have received a copy of the GNU General Public License
21728 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21732 + * move-down, opposite of copy-up
21737 +struct au_mvd_args {
21739 + struct super_block *h_sb;
21740 + struct dentry *h_parent;
21741 + struct au_hinode *hdir;
21742 + struct inode *h_dir, *h_inode;
21743 + struct au_pin pin;
21744 + } info[AUFS_MVDOWN_NARRAY];
21746 + struct aufs_mvdown mvdown;
21747 + struct dentry *dentry, *parent;
21748 + struct inode *inode, *dir;
21749 + struct super_block *sb;
21750 + aufs_bindex_t bopq, bwh, bfound;
21751 + unsigned char rename_lock;
21754 +#define mvd_errno mvdown.au_errno
21755 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
21756 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
21757 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
21758 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
21760 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
21761 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
21762 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
21763 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
21764 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
21765 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
21767 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
21768 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
21769 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
21770 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
21771 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
21772 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
21774 +#define AU_MVD_PR(flag, ...) do { \
21776 + pr_err(__VA_ARGS__); \
21779 +static int find_lower_writable(struct au_mvd_args *a)
21781 + struct super_block *sb;
21782 + aufs_bindex_t bindex, bend;
21783 + struct au_branch *br;
21786 + bindex = a->mvd_bsrc;
21787 + bend = au_sbend(sb);
21788 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
21789 + for (bindex++; bindex <= bend; bindex++) {
21790 + br = au_sbr(sb, bindex);
21791 + if (au_br_fhsm(br->br_perm)
21792 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
21795 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
21796 + for (bindex++; bindex <= bend; bindex++) {
21797 + br = au_sbr(sb, bindex);
21798 + if (!au_br_rdonly(br))
21802 + for (bindex++; bindex <= bend; bindex++) {
21803 + br = au_sbr(sb, bindex);
21804 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21805 + if (au_br_rdonly(br))
21807 + |= AUFS_MVDOWN_ROLOWER_R;
21815 +/* make the parent dir on bdst */
21816 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
21821 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
21822 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
21823 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
21824 + a->mvd_h_dst_parent = NULL;
21825 + if (au_dbend(a->parent) >= a->mvd_bdst)
21826 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21827 + if (!a->mvd_h_dst_parent) {
21828 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
21829 + if (unlikely(err)) {
21830 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
21833 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21841 +/* lock them all */
21842 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
21845 + struct dentry *h_trap;
21847 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
21848 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
21849 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
21850 + au_opt_udba(a->sb),
21851 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21853 + if (unlikely(err)) {
21854 + AU_MVD_PR(dmsg, "pin_dst failed\n");
21858 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
21859 + a->rename_lock = 0;
21860 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
21861 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
21862 + au_opt_udba(a->sb),
21863 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21864 + err = au_do_pin(&a->mvd_pin_src);
21866 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
21867 + if (unlikely(err)) {
21868 + AU_MVD_PR(dmsg, "pin_src failed\n");
21871 + goto out; /* success */
21874 + a->rename_lock = 1;
21875 + au_pin_hdir_unlock(&a->mvd_pin_dst);
21876 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
21877 + au_opt_udba(a->sb),
21878 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21880 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
21881 + if (unlikely(err)) {
21882 + AU_MVD_PR(dmsg, "pin_src failed\n");
21883 + au_pin_hdir_lock(&a->mvd_pin_dst);
21886 + au_pin_hdir_unlock(&a->mvd_pin_src);
21887 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21888 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21890 + err = (h_trap != a->mvd_h_src_parent);
21892 + err = (h_trap != a->mvd_h_dst_parent);
21894 + BUG_ON(err); /* it should never happen */
21895 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
21898 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21899 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21900 + au_pin_hdir_lock(&a->mvd_pin_src);
21901 + au_unpin(&a->mvd_pin_src);
21902 + au_pin_hdir_lock(&a->mvd_pin_dst);
21905 + goto out; /* success */
21908 + au_unpin(&a->mvd_pin_dst);
21914 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
21916 + if (!a->rename_lock)
21917 + au_unpin(&a->mvd_pin_src);
21919 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21920 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21921 + au_pin_hdir_lock(&a->mvd_pin_src);
21922 + au_unpin(&a->mvd_pin_src);
21923 + au_pin_hdir_lock(&a->mvd_pin_dst);
21925 + au_unpin(&a->mvd_pin_dst);
21928 +/* copy-down the file */
21929 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
21932 + struct au_cp_generic cpg = {
21933 + .dentry = a->dentry,
21934 + .bdst = a->mvd_bdst,
21935 + .bsrc = a->mvd_bsrc,
21937 + .pin = &a->mvd_pin_dst,
21938 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21941 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
21942 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21943 + au_fset_cpup(cpg.flags, OVERWRITE);
21944 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
21945 + au_fset_cpup(cpg.flags, RWDST);
21946 + err = au_sio_cpdown_simple(&cpg);
21947 + if (unlikely(err))
21948 + AU_MVD_PR(dmsg, "cpdown failed\n");
21955 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
21958 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
21961 + struct path h_path;
21962 + struct au_branch *br;
21963 + struct inode *delegated;
21965 + br = au_sbr(a->sb, a->mvd_bdst);
21966 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
21967 + err = PTR_ERR(h_path.dentry);
21968 + if (IS_ERR(h_path.dentry)) {
21969 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
21974 + if (h_path.dentry->d_inode) {
21975 + h_path.mnt = au_br_mnt(br);
21976 + delegated = NULL;
21977 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
21978 + &delegated, /*force*/0);
21979 + if (unlikely(err == -EWOULDBLOCK)) {
21980 + pr_warn("cannot retry for NFSv4 delegation"
21981 + " for an internal unlink\n");
21984 + if (unlikely(err))
21985 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
21987 + dput(h_path.dentry);
21995 + * unlink the topmost h_dentry
21997 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22000 + struct path h_path;
22001 + struct inode *delegated;
22003 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22004 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22005 + delegated = NULL;
22006 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22007 + if (unlikely(err == -EWOULDBLOCK)) {
22008 + pr_warn("cannot retry for NFSv4 delegation"
22009 + " for an internal unlink\n");
22012 + if (unlikely(err))
22013 + AU_MVD_PR(dmsg, "unlink failed\n");
22019 +/* Since mvdown succeeded, we ignore an error of this function */
22020 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22023 + struct au_branch *br;
22025 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22026 + br = au_sbr(a->sb, a->mvd_bsrc);
22027 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22029 + br = au_sbr(a->sb, a->mvd_bdst);
22030 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22031 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22034 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22036 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22040 + * copy-down the file and unlink the bsrc file.
22041 + * - unlink the bdst whout if exist
22042 + * - copy-down the file (with whtmp name and rename)
22043 + * - unlink the bsrc file
22045 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22049 + err = au_do_mkdir(dmsg, a);
22051 + err = au_do_lock(dmsg, a);
22052 + if (unlikely(err))
22056 + * do not revert the activities we made on bdst since they should be
22057 + * harmless in aufs.
22060 + err = au_do_cpdown(dmsg, a);
22062 + err = au_do_unlink_wh(dmsg, a);
22063 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22064 + err = au_do_unlink(dmsg, a);
22065 + if (unlikely(err))
22068 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22069 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22070 + if (find_lower_writable(a) < 0)
22071 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22073 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22074 + au_do_stfs(dmsg, a);
22076 + /* maintain internal array */
22077 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22078 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22079 + au_set_dbstart(a->dentry, a->mvd_bdst);
22080 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22081 + au_set_ibstart(a->inode, a->mvd_bdst);
22083 + if (au_dbend(a->dentry) < a->mvd_bdst)
22084 + au_set_dbend(a->dentry, a->mvd_bdst);
22085 + if (au_ibend(a->inode) < a->mvd_bdst)
22086 + au_set_ibend(a->inode, a->mvd_bdst);
22089 + au_do_unlock(dmsg, a);
22095 +/* ---------------------------------------------------------------------- */
22097 +/* make sure the file is idle */
22098 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22100 + int err, plinked;
22103 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22104 + if (au_dbstart(a->dentry) == a->mvd_bsrc
22105 + && au_dcount(a->dentry) == 1
22106 + && atomic_read(&a->inode->i_count) == 1
22107 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22108 + && (!plinked || !au_plink_test(a->inode))
22109 + && a->inode->i_nlink == 1)
22114 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22115 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
22116 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22117 + a->mvd_h_src_inode->i_nlink,
22118 + plinked, plinked ? au_plink_test(a->inode) : 0);
22125 +/* make sure the parent dir is fine */
22126 +static int au_mvd_args_parent(const unsigned char dmsg,
22127 + struct au_mvd_args *a)
22130 + aufs_bindex_t bindex;
22133 + if (unlikely(au_alive_dir(a->parent))) {
22135 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22139 + a->bopq = au_dbdiropq(a->parent);
22140 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22141 + AuDbg("b%d\n", bindex);
22142 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22143 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22145 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22146 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22147 + a->bopq, a->mvd_bdst);
22155 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22156 + struct au_mvd_args *a)
22159 + struct au_dinfo *dinfo, *tmp;
22161 + /* lookup the next lower positive entry */
22163 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22164 + if (unlikely(!tmp))
22169 + dinfo = au_di(a->dentry);
22170 + au_di_cp(tmp, dinfo);
22171 + au_di_swap(tmp, dinfo);
22173 + /* returns the number of positive dentries */
22174 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
22176 + a->bwh = au_dbwh(a->dentry);
22177 + else if (err > 0)
22178 + a->bfound = au_dbstart(a->dentry);
22180 + au_di_swap(tmp, dinfo);
22181 + au_rw_write_unlock(&tmp->di_rwsem);
22183 + if (unlikely(err < 0))
22184 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22187 + * here, we have these cases.
22189 + * no positive dentry under bsrc. there are more sub-cases.
22191 + * there no whiteout, we can safely move-down.
22194 + * bsrc < bwh && bwh < bdst
22195 + * there is a whiteout on RO branch. cannot proceed.
22197 + * there is a whiteout on the RW target branch. it should
22200 + * there is a whiteout somewhere unrelated branch.
22201 + * -1 < bfound && bfound <= bsrc
22204 + * found, but it is on RO branch between bsrc and bdst. cannot
22207 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22210 + * found, after we create the file on bdst, it will be hidden.
22213 + AuDebugOn(a->bfound == -1
22215 + && a->bwh <= a->mvd_bsrc);
22216 + AuDebugOn(-1 < a->bfound
22217 + && a->bfound <= a->mvd_bsrc);
22220 + if (a->bfound == -1
22221 + && a->mvd_bsrc < a->bwh
22223 + && a->bwh < a->mvd_bdst) {
22224 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22225 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22226 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22228 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22229 + a->mvd_errno = EAU_MVDOWN_UPPER;
22230 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22231 + a->mvd_bdst, a->bfound);
22235 + err = 0; /* success */
22242 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22247 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22248 + && a->bfound == a->mvd_bdst)
22254 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
22257 + struct au_branch *br;
22260 + if (unlikely(S_ISDIR(a->inode->i_mode)))
22264 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
22265 + a->mvd_bsrc = au_ibstart(a->inode);
22267 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
22268 + if (unlikely(a->mvd_bsrc < 0
22269 + || (a->mvd_bsrc < au_dbstart(a->dentry)
22270 + || au_dbend(a->dentry) < a->mvd_bsrc
22271 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
22272 + || (a->mvd_bsrc < au_ibstart(a->inode)
22273 + || au_ibend(a->inode) < a->mvd_bsrc
22274 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
22275 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
22276 + AU_MVD_PR(dmsg, "no upper\n");
22280 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
22281 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22282 + AU_MVD_PR(dmsg, "on the bottom\n");
22285 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
22286 + br = au_sbr(a->sb, a->mvd_bsrc);
22287 + err = au_br_rdonly(br);
22288 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
22289 + if (unlikely(err))
22291 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
22292 + || IS_APPEND(a->mvd_h_src_inode))) {
22294 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22300 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22301 + a->mvd_bdst = find_lower_writable(a);
22302 + if (unlikely(a->mvd_bdst < 0)) {
22303 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22304 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22308 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22309 + if (unlikely(a->mvd_bdst < 0
22310 + || au_sbend(a->sb) < a->mvd_bdst)) {
22311 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22312 + AU_MVD_PR(dmsg, "no lower brid\n");
22317 + err = au_mvd_args_busy(dmsg, a);
22319 + err = au_mvd_args_parent(dmsg, a);
22321 + err = au_mvd_args_intermediate(dmsg, a);
22323 + err = au_mvd_args_exist(dmsg, a);
22325 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22332 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22335 + unsigned char dmsg;
22336 + struct au_mvd_args *args;
22339 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22343 + args = kmalloc(sizeof(*args), GFP_NOFS);
22344 + if (unlikely(!args))
22347 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22349 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22350 + if (unlikely(err)) {
22355 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22356 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22357 + args->mvdown.au_errno = 0;
22358 + args->dentry = dentry;
22359 + args->inode = dentry->d_inode;
22360 + args->sb = dentry->d_sb;
22363 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22364 + args->parent = dget_parent(dentry);
22365 + args->dir = args->parent->d_inode;
22366 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
22367 + dput(args->parent);
22368 + if (unlikely(args->parent != dentry->d_parent)) {
22369 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22373 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
22374 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
22375 + if (unlikely(err))
22378 + di_write_lock_parent(args->parent);
22379 + err = au_mvd_args(dmsg, args);
22380 + if (unlikely(err))
22383 + err = au_do_mvdown(dmsg, args);
22384 + if (unlikely(err))
22387 + au_cpup_attr_timesizes(args->dir);
22388 + au_cpup_attr_timesizes(args->inode);
22389 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
22390 + /* au_digen_dec(dentry); */
22393 + di_write_unlock(args->parent);
22394 + aufs_read_unlock(dentry, AuLock_DW);
22396 + mutex_unlock(&args->inode->i_mutex);
22398 + mutex_unlock(&args->dir->i_mutex);
22400 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22408 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22409 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22410 +++ linux/fs/aufs/opts.c 2015-01-25 13:00:38.634380408 +0100
22413 + * Copyright (C) 2005-2014 Junjiro R. Okajima
22415 + * This program, aufs is free software; you can redistribute it and/or modify
22416 + * it under the terms of the GNU General Public License as published by
22417 + * the Free Software Foundation; either version 2 of the License, or
22418 + * (at your option) any later version.
22420 + * This program is distributed in the hope that it will be useful,
22421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22423 + * GNU General Public License for more details.
22425 + * You should have received a copy of the GNU General Public License
22426 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22430 + * mount options/flags
22433 +#include <linux/namei.h>
22434 +#include <linux/types.h> /* a distribution requires */
22435 +#include <linux/parser.h>
22438 +/* ---------------------------------------------------------------------- */
22442 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
22443 + Opt_idel, Opt_imod, Opt_ireorder,
22444 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
22445 + Opt_rdblk_def, Opt_rdhash_def,
22446 + Opt_xino, Opt_zxino, Opt_noxino,
22447 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22448 + Opt_trunc_xino_path, Opt_itrunc_xino,
22449 + Opt_trunc_xib, Opt_notrunc_xib,
22450 + Opt_shwh, Opt_noshwh,
22451 + Opt_plink, Opt_noplink, Opt_list_plink,
22453 + Opt_dio, Opt_nodio,
22454 + /* Opt_lock, Opt_unlock, */
22455 + Opt_cmd, Opt_cmd_args,
22456 + Opt_diropq_a, Opt_diropq_w,
22457 + Opt_warn_perm, Opt_nowarn_perm,
22458 + Opt_wbr_copyup, Opt_wbr_create,
22460 + Opt_refrof, Opt_norefrof,
22461 + Opt_verbose, Opt_noverbose,
22462 + Opt_sum, Opt_nosum, Opt_wsum,
22463 + Opt_dirperm1, Opt_nodirperm1,
22464 + Opt_acl, Opt_noacl,
22465 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22468 +static match_table_t options = {
22469 + {Opt_br, "br=%s"},
22470 + {Opt_br, "br:%s"},
22472 + {Opt_add, "add=%d:%s"},
22473 + {Opt_add, "add:%d:%s"},
22474 + {Opt_add, "ins=%d:%s"},
22475 + {Opt_add, "ins:%d:%s"},
22476 + {Opt_append, "append=%s"},
22477 + {Opt_append, "append:%s"},
22478 + {Opt_prepend, "prepend=%s"},
22479 + {Opt_prepend, "prepend:%s"},
22481 + {Opt_del, "del=%s"},
22482 + {Opt_del, "del:%s"},
22483 + /* {Opt_idel, "idel:%d"}, */
22484 + {Opt_mod, "mod=%s"},
22485 + {Opt_mod, "mod:%s"},
22486 + /* {Opt_imod, "imod:%d:%s"}, */
22488 + {Opt_dirwh, "dirwh=%d"},
22490 + {Opt_xino, "xino=%s"},
22491 + {Opt_noxino, "noxino"},
22492 + {Opt_trunc_xino, "trunc_xino"},
22493 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22494 + {Opt_notrunc_xino, "notrunc_xino"},
22495 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22496 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22497 + /* {Opt_zxino, "zxino=%s"}, */
22498 + {Opt_trunc_xib, "trunc_xib"},
22499 + {Opt_notrunc_xib, "notrunc_xib"},
22501 +#ifdef CONFIG_PROC_FS
22502 + {Opt_plink, "plink"},
22504 + {Opt_ignore_silent, "plink"},
22507 + {Opt_noplink, "noplink"},
22509 +#ifdef CONFIG_AUFS_DEBUG
22510 + {Opt_list_plink, "list_plink"},
22513 + {Opt_udba, "udba=%s"},
22515 + {Opt_dio, "dio"},
22516 + {Opt_nodio, "nodio"},
22518 +#ifdef CONFIG_AUFS_FHSM
22519 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22521 + {Opt_ignore_silent, "fhsm_sec=%d"},
22524 + {Opt_diropq_a, "diropq=always"},
22525 + {Opt_diropq_a, "diropq=a"},
22526 + {Opt_diropq_w, "diropq=whiteouted"},
22527 + {Opt_diropq_w, "diropq=w"},
22529 + {Opt_warn_perm, "warn_perm"},
22530 + {Opt_nowarn_perm, "nowarn_perm"},
22532 + /* keep them temporary */
22533 + {Opt_ignore_silent, "nodlgt"},
22534 + {Opt_ignore_silent, "clean_plink"},
22536 +#ifdef CONFIG_AUFS_SHWH
22537 + {Opt_shwh, "shwh"},
22539 + {Opt_noshwh, "noshwh"},
22541 + {Opt_dirperm1, "dirperm1"},
22542 + {Opt_nodirperm1, "nodirperm1"},
22544 + {Opt_rendir, "rendir=%d"},
22546 + {Opt_refrof, "refrof"},
22547 + {Opt_norefrof, "norefrof"},
22549 + {Opt_verbose, "verbose"},
22550 + {Opt_verbose, "v"},
22551 + {Opt_noverbose, "noverbose"},
22552 + {Opt_noverbose, "quiet"},
22553 + {Opt_noverbose, "q"},
22554 + {Opt_noverbose, "silent"},
22556 + {Opt_sum, "sum"},
22557 + {Opt_nosum, "nosum"},
22558 + {Opt_wsum, "wsum"},
22560 + {Opt_rdcache, "rdcache=%d"},
22561 + {Opt_rdblk, "rdblk=%d"},
22562 + {Opt_rdblk_def, "rdblk=def"},
22563 + {Opt_rdhash, "rdhash=%d"},
22564 + {Opt_rdhash_def, "rdhash=def"},
22566 + {Opt_wbr_create, "create=%s"},
22567 + {Opt_wbr_create, "create_policy=%s"},
22568 + {Opt_wbr_copyup, "cpup=%s"},
22569 + {Opt_wbr_copyup, "copyup=%s"},
22570 + {Opt_wbr_copyup, "copyup_policy=%s"},
22572 + /* generic VFS flag */
22573 +#ifdef CONFIG_FS_POSIX_ACL
22574 + {Opt_acl, "acl"},
22575 + {Opt_noacl, "noacl"},
22577 + {Opt_ignore_silent, "acl"},
22578 + {Opt_ignore_silent, "noacl"},
22581 + /* internal use for the scripts */
22582 + {Opt_ignore_silent, "si=%s"},
22584 + {Opt_br, "dirs=%s"},
22585 + {Opt_ignore, "debug=%d"},
22586 + {Opt_ignore, "delete=whiteout"},
22587 + {Opt_ignore, "delete=all"},
22588 + {Opt_ignore, "imap=%s"},
22590 + /* temporary workaround, due to old mount(8)? */
22591 + {Opt_ignore_silent, "relatime"},
22596 +/* ---------------------------------------------------------------------- */
22598 +static const char *au_parser_pattern(int val, match_table_t tbl)
22600 + struct match_token *p;
22603 + while (p->pattern) {
22604 + if (p->token == val)
22605 + return p->pattern;
22612 +static const char *au_optstr(int *val, match_table_t tbl)
22614 + struct match_token *p;
22619 + while (p->token) {
22620 + if ((v & p->token) == p->token) {
22621 + *val &= ~p->token;
22622 + return p->pattern;
22629 +/* ---------------------------------------------------------------------- */
22631 +static match_table_t brperm = {
22632 + {AuBrPerm_RO, AUFS_BRPERM_RO},
22633 + {AuBrPerm_RR, AUFS_BRPERM_RR},
22634 + {AuBrPerm_RW, AUFS_BRPERM_RW},
22638 +static match_table_t brattr = {
22640 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
22641 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
22642 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
22643 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
22644 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
22645 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
22646 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
22647 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
22648 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
22649 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
22650 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
22652 + /* ro/rr branch */
22653 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
22656 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
22657 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
22662 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
22669 + p = strchr(str, '+');
22672 + v = match_token(str, table, args);
22674 + if (v & AuBrAttr_CMOO_Mask)
22675 + attr &= ~AuBrAttr_CMOO_Mask;
22680 + pr_warn("ignored branch attribute %s\n", str);
22690 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
22698 + p = au_optstr(&perm, brattr);
22701 + memcpy(q, p, sz + 1);
22707 + p = au_optstr(&perm, brattr);
22711 + memcpy(q, p, sz + 1);
22717 + return q - str->a;
22720 +static int noinline_for_stack br_perm_val(char *perm)
22722 + int val, bad, sz;
22724 + substring_t args[MAX_OPT_ARGS];
22725 + au_br_perm_str_t attr;
22727 + p = strchr(perm, '+');
22730 + val = match_token(perm, brperm, args);
22734 + pr_warn("ignored branch permission %s\n", perm);
22735 + val = AuBrPerm_RO;
22741 + val |= br_attr_val(p + 1, brattr, args);
22744 + switch (val & AuBrPerm_Mask) {
22745 + case AuBrPerm_RO:
22746 + case AuBrPerm_RR:
22747 + bad = val & AuBrWAttr_Mask;
22748 + val &= ~AuBrWAttr_Mask;
22750 + case AuBrPerm_RW:
22751 + bad = val & AuBrRAttr_Mask;
22752 + val &= ~AuBrRAttr_Mask;
22757 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
22758 + * does not treat it as an error, just warning.
22759 + * this is a tiny guard for the user operation.
22761 + if (val & AuBrAttr_UNPIN) {
22762 + bad |= AuBrAttr_UNPIN;
22763 + val &= ~AuBrAttr_UNPIN;
22766 + if (unlikely(bad)) {
22767 + sz = au_do_optstr_br_attr(&attr, bad);
22769 + pr_warn("ignored branch attribute %s\n", attr.a);
22776 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
22778 + au_br_perm_str_t attr;
22784 + p = au_optstr(&perm, brperm);
22785 + AuDebugOn(!p || !*p);
22787 + memcpy(q, p, sz + 1);
22790 + sz = au_do_optstr_br_attr(&attr, perm);
22793 + memcpy(q, attr.a, sz + 1);
22796 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
22799 +/* ---------------------------------------------------------------------- */
22801 +static match_table_t udbalevel = {
22802 + {AuOpt_UDBA_REVAL, "reval"},
22803 + {AuOpt_UDBA_NONE, "none"},
22804 +#ifdef CONFIG_AUFS_HNOTIFY
22805 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
22806 +#ifdef CONFIG_AUFS_HFSNOTIFY
22807 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
22813 +static int noinline_for_stack udba_val(char *str)
22815 + substring_t args[MAX_OPT_ARGS];
22817 + return match_token(str, udbalevel, args);
22820 +const char *au_optstr_udba(int udba)
22822 + return au_parser_pattern(udba, udbalevel);
22825 +/* ---------------------------------------------------------------------- */
22827 +static match_table_t au_wbr_create_policy = {
22828 + {AuWbrCreate_TDP, "tdp"},
22829 + {AuWbrCreate_TDP, "top-down-parent"},
22830 + {AuWbrCreate_RR, "rr"},
22831 + {AuWbrCreate_RR, "round-robin"},
22832 + {AuWbrCreate_MFS, "mfs"},
22833 + {AuWbrCreate_MFS, "most-free-space"},
22834 + {AuWbrCreate_MFSV, "mfs:%d"},
22835 + {AuWbrCreate_MFSV, "most-free-space:%d"},
22837 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
22838 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
22839 + {AuWbrCreate_PMFS, "pmfs"},
22840 + {AuWbrCreate_PMFSV, "pmfs:%d"},
22841 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
22842 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
22848 + * cf. linux/lib/parser.c and cmdline.c
22849 + * gave up calling memparse() since it uses simple_strtoull() instead of
22852 +static int noinline_for_stack
22853 +au_match_ull(substring_t *s, unsigned long long *result)
22856 + unsigned int len;
22860 + len = s->to - s->from;
22861 + if (len + 1 <= sizeof(a)) {
22862 + memcpy(a, s->from, len);
22864 + err = kstrtoull(a, 0, result);
22869 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
22870 + struct au_opt_wbr_create *create)
22873 + unsigned long long ull;
22876 + if (!au_match_ull(arg, &ull))
22877 + create->mfsrr_watermark = ull;
22879 + pr_err("bad integer in %s\n", str);
22886 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
22887 + struct au_opt_wbr_create *create)
22892 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
22893 + create->mfs_second = n;
22895 + pr_err("bad integer in %s\n", str);
22902 +static int noinline_for_stack
22903 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
22906 + substring_t args[MAX_OPT_ARGS];
22908 + err = match_token(str, au_wbr_create_policy, args);
22909 + create->wbr_create = err;
22911 + case AuWbrCreate_MFSRRV:
22912 + case AuWbrCreate_PMFSRRV:
22913 + e = au_wbr_mfs_wmark(&args[0], str, create);
22915 + e = au_wbr_mfs_sec(&args[1], str, create);
22919 + case AuWbrCreate_MFSRR:
22920 + case AuWbrCreate_PMFSRR:
22921 + e = au_wbr_mfs_wmark(&args[0], str, create);
22922 + if (unlikely(e)) {
22927 + case AuWbrCreate_MFS:
22928 + case AuWbrCreate_PMFS:
22929 + create->mfs_second = AUFS_MFS_DEF_SEC;
22931 + case AuWbrCreate_MFSV:
22932 + case AuWbrCreate_PMFSV:
22933 + e = au_wbr_mfs_sec(&args[0], str, create);
22942 +const char *au_optstr_wbr_create(int wbr_create)
22944 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
22947 +static match_table_t au_wbr_copyup_policy = {
22948 + {AuWbrCopyup_TDP, "tdp"},
22949 + {AuWbrCopyup_TDP, "top-down-parent"},
22950 + {AuWbrCopyup_BUP, "bup"},
22951 + {AuWbrCopyup_BUP, "bottom-up-parent"},
22952 + {AuWbrCopyup_BU, "bu"},
22953 + {AuWbrCopyup_BU, "bottom-up"},
22957 +static int noinline_for_stack au_wbr_copyup_val(char *str)
22959 + substring_t args[MAX_OPT_ARGS];
22961 + return match_token(str, au_wbr_copyup_policy, args);
22964 +const char *au_optstr_wbr_copyup(int wbr_copyup)
22966 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
22969 +/* ---------------------------------------------------------------------- */
22971 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
22973 +static void dump_opts(struct au_opts *opts)
22975 +#ifdef CONFIG_AUFS_DEBUG
22976 + /* reduce stack space */
22978 + struct au_opt_add *add;
22979 + struct au_opt_del *del;
22980 + struct au_opt_mod *mod;
22981 + struct au_opt_xino *xino;
22982 + struct au_opt_xino_itrunc *xino_itrunc;
22983 + struct au_opt_wbr_create *create;
22985 + struct au_opt *opt;
22988 + while (opt->type != Opt_tail) {
22989 + switch (opt->type) {
22991 + u.add = &opt->add;
22992 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
22993 + u.add->bindex, u.add->pathname, u.add->perm,
22994 + u.add->path.dentry);
22998 + u.del = &opt->del;
22999 + AuDbg("del {%s, %p}\n",
23000 + u.del->pathname, u.del->h_path.dentry);
23004 + u.mod = &opt->mod;
23005 + AuDbg("mod {%s, 0x%x, %p}\n",
23006 + u.mod->path, u.mod->perm, u.mod->h_root);
23009 + u.add = &opt->add;
23010 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23011 + u.add->bindex, u.add->pathname, u.add->perm,
23012 + u.add->path.dentry);
23014 + case Opt_prepend:
23015 + u.add = &opt->add;
23016 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23017 + u.add->bindex, u.add->pathname, u.add->perm,
23018 + u.add->path.dentry);
23021 + AuDbg("dirwh %d\n", opt->dirwh);
23023 + case Opt_rdcache:
23024 + AuDbg("rdcache %d\n", opt->rdcache);
23027 + AuDbg("rdblk %u\n", opt->rdblk);
23029 + case Opt_rdblk_def:
23030 + AuDbg("rdblk_def\n");
23033 + AuDbg("rdhash %u\n", opt->rdhash);
23035 + case Opt_rdhash_def:
23036 + AuDbg("rdhash_def\n");
23039 + u.xino = &opt->xino;
23040 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23042 + case Opt_trunc_xino:
23043 + AuLabel(trunc_xino);
23045 + case Opt_notrunc_xino:
23046 + AuLabel(notrunc_xino);
23048 + case Opt_trunc_xino_path:
23049 + case Opt_itrunc_xino:
23050 + u.xino_itrunc = &opt->xino_itrunc;
23051 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23057 + case Opt_trunc_xib:
23058 + AuLabel(trunc_xib);
23060 + case Opt_notrunc_xib:
23061 + AuLabel(notrunc_xib);
23069 + case Opt_dirperm1:
23070 + AuLabel(dirperm1);
23072 + case Opt_nodirperm1:
23073 + AuLabel(nodirperm1);
23078 + case Opt_noplink:
23079 + AuLabel(noplink);
23081 + case Opt_list_plink:
23082 + AuLabel(list_plink);
23085 + AuDbg("udba %d, %s\n",
23086 + opt->udba, au_optstr_udba(opt->udba));
23094 + case Opt_diropq_a:
23095 + AuLabel(diropq_a);
23097 + case Opt_diropq_w:
23098 + AuLabel(diropq_w);
23100 + case Opt_warn_perm:
23101 + AuLabel(warn_perm);
23103 + case Opt_nowarn_perm:
23104 + AuLabel(nowarn_perm);
23109 + case Opt_norefrof:
23110 + AuLabel(norefrof);
23112 + case Opt_verbose:
23113 + AuLabel(verbose);
23115 + case Opt_noverbose:
23116 + AuLabel(noverbose);
23127 + case Opt_wbr_create:
23128 + u.create = &opt->wbr_create;
23129 + AuDbg("create %d, %s\n", u.create->wbr_create,
23130 + au_optstr_wbr_create(u.create->wbr_create));
23131 + switch (u.create->wbr_create) {
23132 + case AuWbrCreate_MFSV:
23133 + case AuWbrCreate_PMFSV:
23134 + AuDbg("%d sec\n", u.create->mfs_second);
23136 + case AuWbrCreate_MFSRR:
23137 + AuDbg("%llu watermark\n",
23138 + u.create->mfsrr_watermark);
23140 + case AuWbrCreate_MFSRRV:
23141 + case AuWbrCreate_PMFSRRV:
23142 + AuDbg("%llu watermark, %d sec\n",
23143 + u.create->mfsrr_watermark,
23144 + u.create->mfs_second);
23148 + case Opt_wbr_copyup:
23149 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23150 + au_optstr_wbr_copyup(opt->wbr_copyup));
23152 + case Opt_fhsm_sec:
23153 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23169 +void au_opts_free(struct au_opts *opts)
23171 + struct au_opt *opt;
23174 + while (opt->type != Opt_tail) {
23175 + switch (opt->type) {
23178 + case Opt_prepend:
23179 + path_put(&opt->add.path);
23183 + path_put(&opt->del.h_path);
23187 + dput(opt->mod.h_root);
23190 + fput(opt->xino.file);
23197 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23198 + aufs_bindex_t bindex)
23201 + struct au_opt_add *add = &opt->add;
23204 + add->bindex = bindex;
23205 + add->perm = AuBrPerm_RO;
23206 + add->pathname = opt_str;
23207 + p = strchr(opt_str, '=');
23211 + add->perm = br_perm_val(p);
23214 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23217 + add->perm = AuBrPerm_RO;
23218 + if (au_test_fs_rr(add->path.dentry->d_sb))
23219 + add->perm = AuBrPerm_RR;
23220 + else if (!bindex && !(sb_flags & MS_RDONLY))
23221 + add->perm = AuBrPerm_RW;
23223 + opt->type = Opt_add;
23226 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23233 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23237 + del->pathname = args[0].from;
23238 + AuDbg("del path %s\n", del->pathname);
23240 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23241 + if (unlikely(err))
23242 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23247 +#if 0 /* reserved for future use */
23248 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23249 + struct au_opt_del *del, substring_t args[])
23252 + struct dentry *root;
23255 + root = sb->s_root;
23256 + aufs_read_lock(root, AuLock_FLUSH);
23257 + if (bindex < 0 || au_sbend(sb) < bindex) {
23258 + pr_err("out of bounds, %d\n", bindex);
23263 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
23264 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
23267 + aufs_read_unlock(root, !AuLock_IR);
23272 +static int noinline_for_stack
23273 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
23276 + struct path path;
23280 + mod->path = args[0].from;
23281 + p = strchr(mod->path, '=');
23282 + if (unlikely(!p)) {
23283 + pr_err("no permssion %s\n", args[0].from);
23288 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
23289 + if (unlikely(err)) {
23290 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23294 + mod->perm = br_perm_val(p);
23295 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23296 + mod->h_root = dget(path.dentry);
23303 +#if 0 /* reserved for future use */
23304 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23305 + struct au_opt_mod *mod, substring_t args[])
23308 + struct dentry *root;
23311 + root = sb->s_root;
23312 + aufs_read_lock(root, AuLock_FLUSH);
23313 + if (bindex < 0 || au_sbend(sb) < bindex) {
23314 + pr_err("out of bounds, %d\n", bindex);
23319 + mod->perm = br_perm_val(args[1].from);
23320 + AuDbg("mod path %s, perm 0x%x, %s\n",
23321 + mod->path, mod->perm, args[1].from);
23322 + mod->h_root = dget(au_h_dptr(root, bindex));
23325 + aufs_read_unlock(root, !AuLock_IR);
23330 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23331 + substring_t args[])
23334 + struct file *file;
23336 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23337 + err = PTR_ERR(file);
23338 + if (IS_ERR(file))
23342 + if (unlikely(file->f_dentry->d_sb == sb)) {
23344 + pr_err("%s must be outside\n", args[0].from);
23349 + xino->file = file;
23350 + xino->path = args[0].from;
23356 +static int noinline_for_stack
23357 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23358 + struct au_opt_xino_itrunc *xino_itrunc,
23359 + substring_t args[])
23362 + aufs_bindex_t bend, bindex;
23363 + struct path path;
23364 + struct dentry *root;
23366 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23367 + if (unlikely(err)) {
23368 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23372 + xino_itrunc->bindex = -1;
23373 + root = sb->s_root;
23374 + aufs_read_lock(root, AuLock_FLUSH);
23375 + bend = au_sbend(sb);
23376 + for (bindex = 0; bindex <= bend; bindex++) {
23377 + if (au_h_dptr(root, bindex) == path.dentry) {
23378 + xino_itrunc->bindex = bindex;
23382 + aufs_read_unlock(root, !AuLock_IR);
23385 + if (unlikely(xino_itrunc->bindex < 0)) {
23386 + pr_err("no such branch %s\n", args[0].from);
23394 +/* called without aufs lock */
23395 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23397 + int err, n, token;
23398 + aufs_bindex_t bindex;
23399 + unsigned char skipped;
23400 + struct dentry *root;
23401 + struct au_opt *opt, *opt_tail;
23403 + /* reduce the stack space */
23405 + struct au_opt_xino_itrunc *xino_itrunc;
23406 + struct au_opt_wbr_create *create;
23409 + substring_t args[MAX_OPT_ARGS];
23413 + a = kmalloc(sizeof(*a), GFP_NOFS);
23414 + if (unlikely(!a))
23417 + root = sb->s_root;
23421 + opt_tail = opt + opts->max_opt - 1;
23422 + opt->type = Opt_tail;
23423 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23426 + token = match_token(opt_str, options, a->args);
23430 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23432 + err = opt_add(opt, opt_str, opts->sb_flags,
23434 + if (unlikely(!err && ++opt > opt_tail)) {
23438 + opt->type = Opt_tail;
23443 + if (unlikely(match_int(&a->args[0], &n))) {
23444 + pr_err("bad integer in %s\n", opt_str);
23448 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23451 + opt->type = token;
23454 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23455 + /*dummy bindex*/1);
23457 + opt->type = token;
23459 + case Opt_prepend:
23460 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23463 + opt->type = token;
23466 + err = au_opts_parse_del(&opt->del, a->args);
23468 + opt->type = token;
23470 +#if 0 /* reserved for future use */
23472 + del->pathname = "(indexed)";
23473 + if (unlikely(match_int(&args[0], &n))) {
23474 + pr_err("bad integer in %s\n", opt_str);
23477 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23479 + opt->type = token;
23483 + err = au_opts_parse_mod(&opt->mod, a->args);
23485 + opt->type = token;
23487 +#ifdef IMOD /* reserved for future use */
23489 + u.mod->path = "(indexed)";
23490 + if (unlikely(match_int(&a->args[0], &n))) {
23491 + pr_err("bad integer in %s\n", opt_str);
23494 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23496 + opt->type = token;
23500 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23502 + opt->type = token;
23505 + case Opt_trunc_xino_path:
23506 + err = au_opts_parse_xino_itrunc_path
23507 + (sb, &opt->xino_itrunc, a->args);
23509 + opt->type = token;
23512 + case Opt_itrunc_xino:
23513 + u.xino_itrunc = &opt->xino_itrunc;
23514 + if (unlikely(match_int(&a->args[0], &n))) {
23515 + pr_err("bad integer in %s\n", opt_str);
23518 + u.xino_itrunc->bindex = n;
23519 + aufs_read_lock(root, AuLock_FLUSH);
23520 + if (n < 0 || au_sbend(sb) < n) {
23521 + pr_err("out of bounds, %d\n", n);
23522 + aufs_read_unlock(root, !AuLock_IR);
23525 + aufs_read_unlock(root, !AuLock_IR);
23527 + opt->type = token;
23531 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23534 + opt->type = token;
23537 + case Opt_rdcache:
23538 + if (unlikely(match_int(&a->args[0], &n))) {
23539 + pr_err("bad integer in %s\n", opt_str);
23542 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23543 + pr_err("rdcache must be smaller than %d\n",
23544 + AUFS_RDCACHE_MAX);
23547 + opt->rdcache = n;
23549 + opt->type = token;
23552 + if (unlikely(match_int(&a->args[0], &n)
23554 + || n > KMALLOC_MAX_SIZE)) {
23555 + pr_err("bad integer in %s\n", opt_str);
23558 + if (unlikely(n && n < NAME_MAX)) {
23559 + pr_err("rdblk must be larger than %d\n",
23565 + opt->type = token;
23568 + if (unlikely(match_int(&a->args[0], &n)
23570 + || n * sizeof(struct hlist_head)
23571 + > KMALLOC_MAX_SIZE)) {
23572 + pr_err("bad integer in %s\n", opt_str);
23577 + opt->type = token;
23580 + case Opt_trunc_xino:
23581 + case Opt_notrunc_xino:
23583 + case Opt_trunc_xib:
23584 + case Opt_notrunc_xib:
23587 + case Opt_dirperm1:
23588 + case Opt_nodirperm1:
23590 + case Opt_noplink:
23591 + case Opt_list_plink:
23594 + case Opt_diropq_a:
23595 + case Opt_diropq_w:
23596 + case Opt_warn_perm:
23597 + case Opt_nowarn_perm:
23599 + case Opt_norefrof:
23600 + case Opt_verbose:
23601 + case Opt_noverbose:
23605 + case Opt_rdblk_def:
23606 + case Opt_rdhash_def:
23610 + opt->type = token;
23614 + opt->udba = udba_val(a->args[0].from);
23615 + if (opt->udba >= 0) {
23617 + opt->type = token;
23619 + pr_err("wrong value, %s\n", opt_str);
23622 + case Opt_wbr_create:
23623 + u.create = &opt->wbr_create;
23624 + u.create->wbr_create
23625 + = au_wbr_create_val(a->args[0].from, u.create);
23626 + if (u.create->wbr_create >= 0) {
23628 + opt->type = token;
23630 + pr_err("wrong value, %s\n", opt_str);
23632 + case Opt_wbr_copyup:
23633 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23634 + if (opt->wbr_copyup >= 0) {
23636 + opt->type = token;
23638 + pr_err("wrong value, %s\n", opt_str);
23641 + case Opt_fhsm_sec:
23642 + if (unlikely(match_int(&a->args[0], &n)
23644 + pr_err("bad integer in %s\n", opt_str);
23647 + if (sysaufs_brs) {
23648 + opt->fhsm_second = n;
23649 + opt->type = token;
23651 + pr_warn("ignored %s\n", opt_str);
23656 + pr_warn("ignored %s\n", opt_str);
23658 + case Opt_ignore_silent:
23663 + pr_err("unknown option %s\n", opt_str);
23667 + if (!err && !skipped) {
23668 + if (unlikely(++opt > opt_tail)) {
23671 + opt->type = Opt_tail;
23674 + opt->type = Opt_tail;
23680 + if (unlikely(err))
23681 + au_opts_free(opts);
23687 +static int au_opt_wbr_create(struct super_block *sb,
23688 + struct au_opt_wbr_create *create)
23691 + struct au_sbinfo *sbinfo;
23693 + SiMustWriteLock(sb);
23695 + err = 1; /* handled */
23696 + sbinfo = au_sbi(sb);
23697 + if (sbinfo->si_wbr_create_ops->fin) {
23698 + err = sbinfo->si_wbr_create_ops->fin(sb);
23703 + sbinfo->si_wbr_create = create->wbr_create;
23704 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
23705 + switch (create->wbr_create) {
23706 + case AuWbrCreate_MFSRRV:
23707 + case AuWbrCreate_MFSRR:
23708 + case AuWbrCreate_PMFSRR:
23709 + case AuWbrCreate_PMFSRRV:
23710 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
23712 + case AuWbrCreate_MFS:
23713 + case AuWbrCreate_MFSV:
23714 + case AuWbrCreate_PMFS:
23715 + case AuWbrCreate_PMFSV:
23716 + sbinfo->si_wbr_mfs.mfs_expire
23717 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
23721 + if (sbinfo->si_wbr_create_ops->init)
23722 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
23729 + * plus: processed without an error
23730 + * zero: unprocessed
23732 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
23733 + struct au_opts *opts)
23736 + struct au_sbinfo *sbinfo;
23738 + SiMustWriteLock(sb);
23740 + err = 1; /* handled */
23741 + sbinfo = au_sbi(sb);
23742 + switch (opt->type) {
23744 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23745 + sbinfo->si_mntflags |= opt->udba;
23746 + opts->given_udba |= opt->udba;
23750 + au_opt_set(sbinfo->si_mntflags, PLINK);
23752 + case Opt_noplink:
23753 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23754 + au_plink_put(sb, /*verbose*/1);
23755 + au_opt_clr(sbinfo->si_mntflags, PLINK);
23757 + case Opt_list_plink:
23758 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23759 + au_plink_list(sb);
23763 + au_opt_set(sbinfo->si_mntflags, DIO);
23764 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23767 + au_opt_clr(sbinfo->si_mntflags, DIO);
23768 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23771 + case Opt_fhsm_sec:
23772 + au_fhsm_set(sbinfo, opt->fhsm_second);
23775 + case Opt_diropq_a:
23776 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23778 + case Opt_diropq_w:
23779 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23782 + case Opt_warn_perm:
23783 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
23785 + case Opt_nowarn_perm:
23786 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
23790 + au_opt_set(sbinfo->si_mntflags, REFROF);
23792 + case Opt_norefrof:
23793 + au_opt_clr(sbinfo->si_mntflags, REFROF);
23796 + case Opt_verbose:
23797 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
23799 + case Opt_noverbose:
23800 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
23804 + au_opt_set(sbinfo->si_mntflags, SUM);
23807 + au_opt_clr(sbinfo->si_mntflags, SUM);
23808 + au_opt_set(sbinfo->si_mntflags, SUM_W);
23810 + au_opt_clr(sbinfo->si_mntflags, SUM);
23811 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
23814 + case Opt_wbr_create:
23815 + err = au_opt_wbr_create(sb, &opt->wbr_create);
23817 + case Opt_wbr_copyup:
23818 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
23819 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
23823 + sbinfo->si_dirwh = opt->dirwh;
23826 + case Opt_rdcache:
23827 + sbinfo->si_rdcache
23828 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
23831 + sbinfo->si_rdblk = opt->rdblk;
23833 + case Opt_rdblk_def:
23834 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
23837 + sbinfo->si_rdhash = opt->rdhash;
23839 + case Opt_rdhash_def:
23840 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
23844 + au_opt_set(sbinfo->si_mntflags, SHWH);
23847 + au_opt_clr(sbinfo->si_mntflags, SHWH);
23850 + case Opt_dirperm1:
23851 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
23853 + case Opt_nodirperm1:
23854 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
23857 + case Opt_trunc_xino:
23858 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
23860 + case Opt_notrunc_xino:
23861 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
23864 + case Opt_trunc_xino_path:
23865 + case Opt_itrunc_xino:
23866 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
23871 + case Opt_trunc_xib:
23872 + au_fset_opts(opts->flags, TRUNC_XIB);
23874 + case Opt_notrunc_xib:
23875 + au_fclr_opts(opts->flags, TRUNC_XIB);
23879 + sb->s_flags |= MS_POSIXACL;
23882 + sb->s_flags &= ~MS_POSIXACL;
23894 + * returns tri-state.
23895 + * plus: processed without an error
23896 + * zero: unprocessed
23899 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
23900 + struct au_opts *opts)
23902 + int err, do_refresh;
23905 + switch (opt->type) {
23907 + opt->add.bindex = au_sbend(sb) + 1;
23908 + if (opt->add.bindex < 0)
23909 + opt->add.bindex = 0;
23911 + case Opt_prepend:
23912 + opt->add.bindex = 0;
23913 + add: /* indented label */
23915 + err = au_br_add(sb, &opt->add,
23916 + au_ftest_opts(opts->flags, REMOUNT));
23919 + au_fset_opts(opts->flags, REFRESH);
23925 + err = au_br_del(sb, &opt->del,
23926 + au_ftest_opts(opts->flags, REMOUNT));
23929 + au_fset_opts(opts->flags, TRUNC_XIB);
23930 + au_fset_opts(opts->flags, REFRESH);
23936 + err = au_br_mod(sb, &opt->mod,
23937 + au_ftest_opts(opts->flags, REMOUNT),
23942 + au_fset_opts(opts->flags, REFRESH);
23950 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
23951 + struct au_opt_xino **opt_xino,
23952 + struct au_opts *opts)
23955 + aufs_bindex_t bend, bindex;
23956 + struct dentry *root, *parent, *h_root;
23959 + switch (opt->type) {
23961 + err = au_xino_set(sb, &opt->xino,
23962 + !!au_ftest_opts(opts->flags, REMOUNT));
23963 + if (unlikely(err))
23966 + *opt_xino = &opt->xino;
23967 + au_xino_brid_set(sb, -1);
23969 + /* safe d_parent access */
23970 + parent = opt->xino.file->f_dentry->d_parent;
23971 + root = sb->s_root;
23972 + bend = au_sbend(sb);
23973 + for (bindex = 0; bindex <= bend; bindex++) {
23974 + h_root = au_h_dptr(root, bindex);
23975 + if (h_root == parent) {
23976 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
23984 + au_xino_brid_set(sb, -1);
23985 + *opt_xino = (void *)-1;
23992 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
23993 + unsigned int pending)
23996 + aufs_bindex_t bindex, bend;
23997 + unsigned char do_plink, skip, do_free;
23998 + struct au_branch *br;
23999 + struct au_wbr *wbr;
24000 + struct dentry *root;
24001 + struct inode *dir, *h_dir;
24002 + struct au_sbinfo *sbinfo;
24003 + struct au_hinode *hdir;
24005 + SiMustAnyLock(sb);
24007 + sbinfo = au_sbi(sb);
24008 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24010 + if (!(sb_flags & MS_RDONLY)) {
24011 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24012 + pr_warn("first branch should be rw\n");
24013 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24014 + pr_warn("shwh should be used with ro\n");
24017 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24018 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24019 + pr_warn("udba=*notify requires xino\n");
24021 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24022 + pr_warn("dirperm1 breaks the protection"
24023 + " by the permission bits on the lower branch\n");
24027 + root = sb->s_root;
24028 + dir = root->d_inode;
24029 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24030 + bend = au_sbend(sb);
24031 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24033 + h_dir = au_h_iptr(dir, bindex);
24034 + br = au_sbr(sb, bindex);
24036 + if ((br->br_perm & AuBrAttr_ICEX)
24037 + && !h_dir->i_op->listxattr)
24038 + br->br_perm &= ~AuBrAttr_ICEX;
24040 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24041 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24042 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24046 + wbr = br->br_wbr;
24048 + wbr_wh_read_lock(wbr);
24050 + if (!au_br_writable(br->br_perm)) {
24053 + || (!wbr->wbr_whbase
24054 + && !wbr->wbr_plink
24055 + && !wbr->wbr_orph));
24056 + } else if (!au_br_wh_linkable(br->br_perm)) {
24057 + /* skip = (!br->br_whbase && !br->br_orph); */
24058 + skip = (!wbr || !wbr->wbr_whbase);
24059 + if (skip && wbr) {
24061 + skip = !!wbr->wbr_plink;
24063 + skip = !wbr->wbr_plink;
24066 + /* skip = (br->br_whbase && br->br_ohph); */
24067 + skip = (wbr && wbr->wbr_whbase);
24070 + skip = !!wbr->wbr_plink;
24072 + skip = !wbr->wbr_plink;
24076 + wbr_wh_read_unlock(wbr);
24078 + if (au_br_fhsm(br->br_perm)) {
24080 + AuDebugOn(!br->br_fhsm);
24086 + hdir = au_hi(dir, bindex);
24087 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
24089 + wbr_wh_write_lock(wbr);
24090 + err = au_wh_init(br, sb);
24092 + wbr_wh_write_unlock(wbr);
24093 + au_hn_imtx_unlock(hdir);
24095 + if (!err && do_free) {
24097 + br->br_wbr = NULL;
24102 + au_fset_si(sbinfo, FHSM);
24103 + for (bindex = bend; bindex >= 0; bindex--) {
24104 + br = au_sbr(sb, bindex);
24105 + if (au_br_fhsm(br->br_perm)) {
24106 + au_fhsm_set_bottom(sb, bindex);
24111 + au_fclr_si(sbinfo, FHSM);
24112 + au_fhsm_set_bottom(sb, -1);
24118 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24121 + unsigned int tmp;
24122 + aufs_bindex_t bindex, bend;
24123 + struct au_opt *opt;
24124 + struct au_opt_xino *opt_xino, xino;
24125 + struct au_sbinfo *sbinfo;
24126 + struct au_branch *br;
24127 + struct inode *dir;
24129 + SiMustWriteLock(sb);
24134 + while (err >= 0 && opt->type != Opt_tail)
24135 + err = au_opt_simple(sb, opt++, opts);
24138 + else if (unlikely(err < 0))
24141 + /* disable xino and udba temporary */
24142 + sbinfo = au_sbi(sb);
24143 + tmp = sbinfo->si_mntflags;
24144 + au_opt_clr(sbinfo->si_mntflags, XINO);
24145 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24148 + while (err >= 0 && opt->type != Opt_tail)
24149 + err = au_opt_br(sb, opt++, opts);
24152 + else if (unlikely(err < 0))
24155 + bend = au_sbend(sb);
24156 + if (unlikely(bend < 0)) {
24158 + pr_err("no branches\n");
24162 + if (au_opt_test(tmp, XINO))
24163 + au_opt_set(sbinfo->si_mntflags, XINO);
24165 + while (!err && opt->type != Opt_tail)
24166 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24167 + if (unlikely(err))
24170 + err = au_opts_verify(sb, sb->s_flags, tmp);
24171 + if (unlikely(err))
24174 + /* restore xino */
24175 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24176 + xino.file = au_xino_def(sb);
24177 + err = PTR_ERR(xino.file);
24178 + if (IS_ERR(xino.file))
24181 + err = au_xino_set(sb, &xino, /*remount*/0);
24183 + if (unlikely(err))
24187 + /* restore udba */
24188 + tmp &= AuOptMask_UDBA;
24189 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24190 + sbinfo->si_mntflags |= tmp;
24191 + bend = au_sbend(sb);
24192 + for (bindex = 0; bindex <= bend; bindex++) {
24193 + br = au_sbr(sb, bindex);
24194 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24195 + if (unlikely(err))
24196 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24198 + /* go on even if err */
24200 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24201 + dir = sb->s_root->d_inode;
24202 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24209 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24212 + struct inode *dir;
24213 + struct au_opt_xino *opt_xino;
24214 + struct au_opt *opt;
24215 + struct au_sbinfo *sbinfo;
24217 + SiMustWriteLock(sb);
24219 + dir = sb->s_root->d_inode;
24220 + sbinfo = au_sbi(sb);
24224 + while (err >= 0 && opt->type != Opt_tail) {
24225 + err = au_opt_simple(sb, opt, opts);
24227 + err = au_opt_br(sb, opt, opts);
24229 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24235 + /* go on even err */
24237 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24238 + if (unlikely(rerr && !err))
24241 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24242 + rerr = au_xib_trunc(sb);
24243 + if (unlikely(rerr && !err))
24247 + /* will be handled by the caller */
24248 + if (!au_ftest_opts(opts->flags, REFRESH)
24249 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
24250 + au_fset_opts(opts->flags, REFRESH);
24252 + AuDbg("status 0x%x\n", opts->flags);
24256 +/* ---------------------------------------------------------------------- */
24258 +unsigned int au_opt_udba(struct super_block *sb)
24260 + return au_mntflags(sb) & AuOptMask_UDBA;
24262 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
24263 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
24264 +++ linux/fs/aufs/opts.h 2015-01-25 13:00:38.634380408 +0100
24267 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24269 + * This program, aufs is free software; you can redistribute it and/or modify
24270 + * it under the terms of the GNU General Public License as published by
24271 + * the Free Software Foundation; either version 2 of the License, or
24272 + * (at your option) any later version.
24274 + * This program is distributed in the hope that it will be useful,
24275 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24276 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24277 + * GNU General Public License for more details.
24279 + * You should have received a copy of the GNU General Public License
24280 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24284 + * mount options/flags
24287 +#ifndef __AUFS_OPTS_H__
24288 +#define __AUFS_OPTS_H__
24292 +#include <linux/path.h>
24293 +#include "branch.h"
24296 +struct super_block;
24298 +/* ---------------------------------------------------------------------- */
24301 +#define AuOpt_XINO 1 /* external inode number bitmap
24302 + and translation table */
24303 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24304 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24305 +#define AuOpt_UDBA_REVAL (1 << 3)
24306 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24307 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24308 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24309 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24311 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
24312 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24313 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24314 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24315 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24316 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24317 +#define AuOpt_DIO (1 << 14) /* direct io */
24319 +#ifndef CONFIG_AUFS_HNOTIFY
24320 +#undef AuOpt_UDBA_HNOTIFY
24321 +#define AuOpt_UDBA_HNOTIFY 0
24323 +#ifndef CONFIG_AUFS_SHWH
24325 +#define AuOpt_SHWH 0
24328 +#define AuOpt_Def (AuOpt_XINO \
24329 + | AuOpt_UDBA_REVAL \
24331 + /* | AuOpt_DIRPERM1 */ \
24332 + | AuOpt_WARN_PERM)
24333 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24334 + | AuOpt_UDBA_REVAL \
24335 + | AuOpt_UDBA_HNOTIFY)
24337 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24338 +#define au_opt_set(flags, name) do { \
24339 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24340 + ((flags) |= AuOpt_##name); \
24342 +#define au_opt_set_udba(flags, name) do { \
24343 + (flags) &= ~AuOptMask_UDBA; \
24344 + ((flags) |= AuOpt_##name); \
24346 +#define au_opt_clr(flags, name) do { \
24347 + ((flags) &= ~AuOpt_##name); \
24350 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24352 +#ifdef CONFIG_PROC_FS
24355 + return mntflags & ~AuOpt_PLINK;
24359 +/* ---------------------------------------------------------------------- */
24361 +/* policies to select one among multiple writable branches */
24363 + AuWbrCreate_TDP, /* top down parent */
24364 + AuWbrCreate_RR, /* round robin */
24365 + AuWbrCreate_MFS, /* most free space */
24366 + AuWbrCreate_MFSV, /* mfs with seconds */
24367 + AuWbrCreate_MFSRR, /* mfs then rr */
24368 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24369 + AuWbrCreate_PMFS, /* parent and mfs */
24370 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24371 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24372 + AuWbrCreate_PMFSRRV, /* plus seconds */
24374 + AuWbrCreate_Def = AuWbrCreate_TDP
24378 + AuWbrCopyup_TDP, /* top down parent */
24379 + AuWbrCopyup_BUP, /* bottom up parent */
24380 + AuWbrCopyup_BU, /* bottom up */
24382 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24385 +/* ---------------------------------------------------------------------- */
24387 +struct au_opt_add {
24388 + aufs_bindex_t bindex;
24391 + struct path path;
24394 +struct au_opt_del {
24396 + struct path h_path;
24399 +struct au_opt_mod {
24402 + struct dentry *h_root;
24405 +struct au_opt_xino {
24407 + struct file *file;
24410 +struct au_opt_xino_itrunc {
24411 + aufs_bindex_t bindex;
24414 +struct au_opt_wbr_create {
24417 + unsigned long long mfsrr_watermark;
24423 + struct au_opt_xino xino;
24424 + struct au_opt_xino_itrunc xino_itrunc;
24425 + struct au_opt_add add;
24426 + struct au_opt_del del;
24427 + struct au_opt_mod mod;
24430 + unsigned int rdblk;
24431 + unsigned int rdhash;
24433 + struct au_opt_wbr_create wbr_create;
24435 + unsigned int fhsm_second;
24440 +#define AuOpts_REMOUNT 1
24441 +#define AuOpts_REFRESH (1 << 1)
24442 +#define AuOpts_TRUNC_XIB (1 << 2)
24443 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24444 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24445 +#define au_fset_opts(flags, name) \
24446 + do { (flags) |= AuOpts_##name; } while (0)
24447 +#define au_fclr_opts(flags, name) \
24448 + do { (flags) &= ~AuOpts_##name; } while (0)
24451 + struct au_opt *opt;
24454 + unsigned int given_udba;
24455 + unsigned int flags;
24456 + unsigned long sb_flags;
24459 +/* ---------------------------------------------------------------------- */
24461 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24462 +const char *au_optstr_udba(int udba);
24463 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24464 +const char *au_optstr_wbr_create(int wbr_create);
24466 +void au_opts_free(struct au_opts *opts);
24467 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24468 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24469 + unsigned int pending);
24470 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24471 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24473 +unsigned int au_opt_udba(struct super_block *sb);
24475 +/* ---------------------------------------------------------------------- */
24477 +#endif /* __KERNEL__ */
24478 +#endif /* __AUFS_OPTS_H__ */
24479 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24480 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24481 +++ linux/fs/aufs/plink.c 2015-01-25 13:00:38.634380408 +0100
24484 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24486 + * This program, aufs is free software; you can redistribute it and/or modify
24487 + * it under the terms of the GNU General Public License as published by
24488 + * the Free Software Foundation; either version 2 of the License, or
24489 + * (at your option) any later version.
24491 + * This program is distributed in the hope that it will be useful,
24492 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24493 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24494 + * GNU General Public License for more details.
24496 + * You should have received a copy of the GNU General Public License
24497 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24507 + * the pseudo-link maintenance mode.
24508 + * during a user process maintains the pseudo-links,
24509 + * prohibit adding a new plink and branch manipulation.
24513 + * For entry functions which will handle plink, and i_mutex is already held
24515 + * They cannot wait and should return an error at once.
24516 + * Callers has to check the error.
24518 + * For entry functions which will handle plink, but i_mutex is not held
24520 + * They can wait the plink maintenance mode to finish.
24522 + * They behave like F_SETLK and F_SETLKW.
24523 + * If the caller never handle plink, then both flags are unnecessary.
24526 +int au_plink_maint(struct super_block *sb, int flags)
24530 + struct au_sbinfo *sbi;
24532 + SiMustAnyLock(sb);
24535 + if (!au_opt_test(au_mntflags(sb), PLINK))
24538 + sbi = au_sbi(sb);
24539 + pid = sbi->si_plink_maint_pid;
24540 + if (!pid || pid == current->pid)
24543 + /* todo: it highly depends upon /sbin/mount.aufs */
24545 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24546 + rcu_read_unlock();
24550 + if (au_ftest_lock(flags, NOPLMW)) {
24551 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24552 + /* AuDebugOn(!lockdep_depth(current)); */
24553 + while (sbi->si_plink_maint_pid) {
24554 + si_read_unlock(sb);
24555 + /* gave up wake_up_bit() */
24556 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24558 + if (au_ftest_lock(flags, FLUSH))
24559 + au_nwt_flush(&sbi->si_nowait);
24560 + si_noflush_read_lock(sb);
24562 + } else if (au_ftest_lock(flags, NOPLM)) {
24563 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24571 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24573 + spin_lock(&sbinfo->si_plink_maint_lock);
24574 + sbinfo->si_plink_maint_pid = 0;
24575 + spin_unlock(&sbinfo->si_plink_maint_lock);
24576 + wake_up_all(&sbinfo->si_plink_wq);
24579 +int au_plink_maint_enter(struct super_block *sb)
24582 + struct au_sbinfo *sbinfo;
24585 + sbinfo = au_sbi(sb);
24586 + /* make sure i am the only one in this fs */
24587 + si_write_lock(sb, AuLock_FLUSH);
24588 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24589 + spin_lock(&sbinfo->si_plink_maint_lock);
24590 + if (!sbinfo->si_plink_maint_pid)
24591 + sbinfo->si_plink_maint_pid = current->pid;
24594 + spin_unlock(&sbinfo->si_plink_maint_lock);
24596 + si_write_unlock(sb);
24601 +/* ---------------------------------------------------------------------- */
24603 +#ifdef CONFIG_AUFS_DEBUG
24604 +void au_plink_list(struct super_block *sb)
24607 + struct au_sbinfo *sbinfo;
24608 + struct hlist_head *plink_hlist;
24609 + struct pseudo_link *plink;
24611 + SiMustAnyLock(sb);
24613 + sbinfo = au_sbi(sb);
24614 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24615 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24617 + for (i = 0; i < AuPlink_NHASH; i++) {
24618 + plink_hlist = &sbinfo->si_plink[i].head;
24620 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24621 + AuDbg("%lu\n", plink->inode->i_ino);
24622 + rcu_read_unlock();
24627 +/* is the inode pseudo-linked? */
24628 +int au_plink_test(struct inode *inode)
24631 + struct au_sbinfo *sbinfo;
24632 + struct hlist_head *plink_hlist;
24633 + struct pseudo_link *plink;
24635 + sbinfo = au_sbi(inode->i_sb);
24636 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24637 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
24638 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24641 + i = au_plink_hash(inode->i_ino);
24642 + plink_hlist = &sbinfo->si_plink[i].head;
24644 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24645 + if (plink->inode == inode) {
24649 + rcu_read_unlock();
24653 +/* ---------------------------------------------------------------------- */
24656 + * generate a name for plink.
24657 + * the file will be stored under AUFS_WH_PLINKDIR.
24659 +/* 20 is max digits length of ulong 64 */
24660 +#define PLINK_NAME_LEN ((20 + 1) * 2)
24662 +static int plink_name(char *name, int len, struct inode *inode,
24663 + aufs_bindex_t bindex)
24666 + struct inode *h_inode;
24668 + h_inode = au_h_iptr(inode, bindex);
24669 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
24673 +struct au_do_plink_lkup_args {
24674 + struct dentry **errp;
24675 + struct qstr *tgtname;
24676 + struct dentry *h_parent;
24677 + struct au_branch *br;
24680 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
24681 + struct dentry *h_parent,
24682 + struct au_branch *br)
24684 + struct dentry *h_dentry;
24685 + struct mutex *h_mtx;
24687 + h_mtx = &h_parent->d_inode->i_mutex;
24688 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
24689 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
24690 + mutex_unlock(h_mtx);
24694 +static void au_call_do_plink_lkup(void *args)
24696 + struct au_do_plink_lkup_args *a = args;
24697 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
24700 +/* lookup the plink-ed @inode under the branch at @bindex */
24701 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
24703 + struct dentry *h_dentry, *h_parent;
24704 + struct au_branch *br;
24705 + struct inode *h_dir;
24707 + char a[PLINK_NAME_LEN];
24708 + struct qstr tgtname = QSTR_INIT(a, 0);
24710 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24712 + br = au_sbr(inode->i_sb, bindex);
24713 + h_parent = br->br_wbr->wbr_plink;
24714 + h_dir = h_parent->d_inode;
24715 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24717 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24718 + struct au_do_plink_lkup_args args = {
24719 + .errp = &h_dentry,
24720 + .tgtname = &tgtname,
24721 + .h_parent = h_parent,
24725 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
24726 + if (unlikely(wkq_err))
24727 + h_dentry = ERR_PTR(wkq_err);
24729 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
24734 +/* create a pseudo-link */
24735 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
24736 + struct dentry *h_dentry, struct au_branch *br)
24739 + struct path h_path = {
24740 + .mnt = au_br_mnt(br)
24742 + struct inode *h_dir, *delegated;
24744 + h_dir = h_parent->d_inode;
24745 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
24747 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
24748 + err = PTR_ERR(h_path.dentry);
24749 + if (IS_ERR(h_path.dentry))
24753 + /* wh.plink dir is not monitored */
24754 + /* todo: is it really safe? */
24755 + if (h_path.dentry->d_inode
24756 + && h_path.dentry->d_inode != h_dentry->d_inode) {
24757 + delegated = NULL;
24758 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
24759 + if (unlikely(err == -EWOULDBLOCK)) {
24760 + pr_warn("cannot retry for NFSv4 delegation"
24761 + " for an internal unlink\n");
24764 + dput(h_path.dentry);
24765 + h_path.dentry = NULL;
24769 + if (!err && !h_path.dentry->d_inode) {
24770 + delegated = NULL;
24771 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
24772 + if (unlikely(err == -EWOULDBLOCK)) {
24773 + pr_warn("cannot retry for NFSv4 delegation"
24774 + " for an internal link\n");
24778 + dput(h_path.dentry);
24781 + mutex_unlock(&h_dir->i_mutex);
24785 +struct do_whplink_args {
24787 + struct qstr *tgt;
24788 + struct dentry *h_parent;
24789 + struct dentry *h_dentry;
24790 + struct au_branch *br;
24793 +static void call_do_whplink(void *args)
24795 + struct do_whplink_args *a = args;
24796 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
24799 +static int whplink(struct dentry *h_dentry, struct inode *inode,
24800 + aufs_bindex_t bindex, struct au_branch *br)
24802 + int err, wkq_err;
24803 + struct au_wbr *wbr;
24804 + struct dentry *h_parent;
24805 + struct inode *h_dir;
24806 + char a[PLINK_NAME_LEN];
24807 + struct qstr tgtname = QSTR_INIT(a, 0);
24809 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
24810 + h_parent = wbr->wbr_plink;
24811 + h_dir = h_parent->d_inode;
24812 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24814 + /* always superio. */
24815 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24816 + struct do_whplink_args args = {
24819 + .h_parent = h_parent,
24820 + .h_dentry = h_dentry,
24823 + wkq_err = au_wkq_wait(call_do_whplink, &args);
24824 + if (unlikely(wkq_err))
24827 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
24832 +/* free a single plink */
24833 +static void do_put_plink(struct pseudo_link *plink, int do_del)
24836 + hlist_del(&plink->hlist);
24837 + iput(plink->inode);
24841 +static void do_put_plink_rcu(struct rcu_head *rcu)
24843 + struct pseudo_link *plink;
24845 + plink = container_of(rcu, struct pseudo_link, rcu);
24846 + iput(plink->inode);
24851 + * create a new pseudo-link for @h_dentry on @bindex.
24852 + * the linked inode is held in aufs @inode.
24854 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
24855 + struct dentry *h_dentry)
24857 + struct super_block *sb;
24858 + struct au_sbinfo *sbinfo;
24859 + struct hlist_head *plink_hlist;
24860 + struct pseudo_link *plink, *tmp;
24861 + struct au_sphlhead *sphl;
24862 + int found, err, cnt, i;
24864 + sb = inode->i_sb;
24865 + sbinfo = au_sbi(sb);
24866 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24867 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24869 + found = au_plink_test(inode);
24873 + i = au_plink_hash(inode->i_ino);
24874 + sphl = sbinfo->si_plink + i;
24875 + plink_hlist = &sphl->head;
24876 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
24878 + tmp->inode = au_igrab(inode);
24884 + spin_lock(&sphl->spin);
24885 + hlist_for_each_entry(plink, plink_hlist, hlist) {
24886 + if (plink->inode == inode) {
24892 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
24893 + spin_unlock(&sphl->spin);
24895 + cnt = au_sphl_count(sphl);
24896 +#define msg "unexpectedly unblanced or too many pseudo-links"
24897 + if (cnt > AUFS_PLINK_WARN)
24898 + AuWarn1(msg ", %d\n", cnt);
24900 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
24902 + do_put_plink(tmp, 0);
24907 + if (unlikely(err)) {
24908 + pr_warn("err %d, damaged pseudo link.\n", err);
24910 + au_sphl_del_rcu(&tmp->hlist, sphl);
24911 + call_rcu(&tmp->rcu, do_put_plink_rcu);
24916 +/* free all plinks */
24917 +void au_plink_put(struct super_block *sb, int verbose)
24920 + struct au_sbinfo *sbinfo;
24921 + struct hlist_head *plink_hlist;
24922 + struct hlist_node *tmp;
24923 + struct pseudo_link *plink;
24925 + SiMustWriteLock(sb);
24927 + sbinfo = au_sbi(sb);
24928 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24929 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24931 + /* no spin_lock since sbinfo is write-locked */
24933 + for (i = 0; i < AuPlink_NHASH; i++) {
24934 + plink_hlist = &sbinfo->si_plink[i].head;
24935 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
24936 + pr_warn("pseudo-link is not flushed");
24939 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
24940 + do_put_plink(plink, 0);
24941 + INIT_HLIST_HEAD(plink_hlist);
24945 +void au_plink_clean(struct super_block *sb, int verbose)
24947 + struct dentry *root;
24949 + root = sb->s_root;
24950 + aufs_write_lock(root);
24951 + if (au_opt_test(au_mntflags(sb), PLINK))
24952 + au_plink_put(sb, verbose);
24953 + aufs_write_unlock(root);
24956 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
24959 + aufs_bindex_t bstart, bend, bindex;
24962 + bstart = au_ibstart(inode);
24963 + bend = au_ibend(inode);
24964 + if (bstart >= 0) {
24965 + for (bindex = bstart; bindex <= bend; bindex++) {
24966 + if (!au_h_iptr(inode, bindex)
24967 + || au_ii_br_id(inode, bindex) != br_id)
24969 + au_set_h_iptr(inode, bindex, NULL, 0);
24974 + for (bindex = bstart; bindex <= bend; bindex++)
24975 + if (au_h_iptr(inode, bindex)) {
24985 +/* free the plinks on a branch specified by @br_id */
24986 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
24988 + struct au_sbinfo *sbinfo;
24989 + struct hlist_head *plink_hlist;
24990 + struct hlist_node *tmp;
24991 + struct pseudo_link *plink;
24992 + struct inode *inode;
24995 + SiMustWriteLock(sb);
24997 + sbinfo = au_sbi(sb);
24998 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24999 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25001 + /* no spin_lock since sbinfo is write-locked */
25002 + for (i = 0; i < AuPlink_NHASH; i++) {
25003 + plink_hlist = &sbinfo->si_plink[i].head;
25004 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
25005 + inode = au_igrab(plink->inode);
25006 + ii_write_lock_child(inode);
25007 + do_put = au_plink_do_half_refresh(inode, br_id);
25009 + do_put_plink(plink, 1);
25010 + ii_write_unlock(inode);
25015 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25016 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25017 +++ linux/fs/aufs/poll.c 2015-01-25 13:00:38.634380408 +0100
25020 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25022 + * This program, aufs is free software; you can redistribute it and/or modify
25023 + * it under the terms of the GNU General Public License as published by
25024 + * the Free Software Foundation; either version 2 of the License, or
25025 + * (at your option) any later version.
25027 + * This program is distributed in the hope that it will be useful,
25028 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25029 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25030 + * GNU General Public License for more details.
25032 + * You should have received a copy of the GNU General Public License
25033 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25038 + * There is only one filesystem which implements ->poll operation, currently.
25043 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25045 + unsigned int mask;
25047 + struct file *h_file;
25048 + struct dentry *dentry;
25049 + struct super_block *sb;
25051 + /* We should pretend an error happened. */
25052 + mask = POLLERR /* | POLLIN | POLLOUT */;
25053 + dentry = file->f_dentry;
25054 + sb = dentry->d_sb;
25055 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25056 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
25057 + if (unlikely(err))
25060 + /* it is not an error if h_file has no operation */
25061 + mask = DEFAULT_POLLMASK;
25062 + h_file = au_hf_top(file);
25063 + if (h_file->f_op->poll)
25064 + mask = h_file->f_op->poll(h_file, wait);
25066 + di_read_unlock(dentry, AuLock_IR);
25067 + fi_read_unlock(file);
25070 + si_read_unlock(sb);
25071 + AuTraceErr((int)mask);
25074 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25075 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25076 +++ linux/fs/aufs/posix_acl.c 2015-01-25 13:00:38.634380408 +0100
25079 + * Copyright (C) 2014 Junjiro R. Okajima
25081 + * This program, aufs is free software; you can redistribute it and/or modify
25082 + * it under the terms of the GNU General Public License as published by
25083 + * the Free Software Foundation; either version 2 of the License, or
25084 + * (at your option) any later version.
25086 + * This program is distributed in the hope that it will be useful,
25087 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25088 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25089 + * GNU General Public License for more details.
25091 + * You should have received a copy of the GNU General Public License
25092 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25096 + * posix acl operations
25099 +#include <linux/fs.h>
25100 +#include <linux/posix_acl.h>
25103 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25105 + struct posix_acl *acl;
25107 + aufs_bindex_t bindex;
25108 + struct inode *h_inode;
25109 + struct super_block *sb;
25112 + sb = inode->i_sb;
25113 + si_read_lock(sb, AuLock_FLUSH);
25114 + ii_read_lock_child(inode);
25115 + if (!(sb->s_flags & MS_POSIXACL))
25118 + bindex = au_ibstart(inode);
25119 + h_inode = au_h_iptr(inode, bindex);
25120 + if (unlikely(!h_inode
25121 + || ((h_inode->i_mode & S_IFMT)
25122 + != (inode->i_mode & S_IFMT)))) {
25123 + err = au_busy_or_stale();
25124 + acl = ERR_PTR(err);
25128 + /* always topmost only */
25129 + acl = get_acl(h_inode, type);
25132 + ii_read_unlock(inode);
25133 + si_read_unlock(sb);
25135 + AuTraceErrPtr(acl);
25139 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25143 + struct dentry *dentry;
25144 + struct au_srxattr arg = {
25145 + .type = AU_ACL_SET,
25152 + mutex_lock(&inode->i_mutex);
25153 + if (inode->i_ino == AUFS_ROOT_INO)
25154 + dentry = dget(inode->i_sb->s_root);
25156 + dentry = d_find_alias(inode);
25158 + dentry = d_find_any_alias(inode);
25160 + pr_warn("cannot handle this inode, "
25161 + "please report to aufs-users ML\n");
25167 + ssz = au_srxattr(dentry, &arg);
25174 + mutex_unlock(&inode->i_mutex);
25177 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25178 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25179 +++ linux/fs/aufs/procfs.c 2015-01-25 13:00:38.634380408 +0100
25182 + * Copyright (C) 2010-2014 Junjiro R. Okajima
25184 + * This program, aufs is free software; you can redistribute it and/or modify
25185 + * it under the terms of the GNU General Public License as published by
25186 + * the Free Software Foundation; either version 2 of the License, or
25187 + * (at your option) any later version.
25189 + * This program is distributed in the hope that it will be useful,
25190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25192 + * GNU General Public License for more details.
25194 + * You should have received a copy of the GNU General Public License
25195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25199 + * procfs interfaces
25202 +#include <linux/proc_fs.h>
25205 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25207 + struct au_sbinfo *sbinfo;
25209 + sbinfo = file->private_data;
25211 + au_plink_maint_leave(sbinfo);
25212 + kobject_put(&sbinfo->si_kobj);
25218 +static void au_procfs_plm_write_clean(struct file *file)
25220 + struct au_sbinfo *sbinfo;
25222 + sbinfo = file->private_data;
25224 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25227 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25230 + struct super_block *sb;
25231 + struct au_sbinfo *sbinfo;
25234 + if (unlikely(file->private_data))
25238 + /* don't use au_sbilist_lock() here */
25239 + spin_lock(&au_sbilist.spin);
25240 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25241 + if (id == sysaufs_si_id(sbinfo)) {
25242 + kobject_get(&sbinfo->si_kobj);
25243 + sb = sbinfo->si_sb;
25246 + spin_unlock(&au_sbilist.spin);
25249 + if (unlikely(!sb))
25252 + err = au_plink_maint_enter(sb);
25254 + /* keep kobject_get() */
25255 + file->private_data = sbinfo;
25257 + kobject_put(&sbinfo->si_kobj);
25263 + * Accept a valid "si=xxxx" only.
25264 + * Once it is accepted successfully, accept "clean" too.
25266 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
25267 + size_t count, loff_t *ppos)
25270 + unsigned long id;
25271 + /* last newline is allowed */
25272 + char buf[3 + sizeof(unsigned long) * 2 + 1];
25275 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25279 + if (unlikely(count > sizeof(buf)))
25282 + err = copy_from_user(buf, ubuf, count);
25283 + if (unlikely(err)) {
25290 + if (!strcmp("clean", buf)) {
25291 + au_procfs_plm_write_clean(file);
25292 + goto out_success;
25293 + } else if (unlikely(strncmp("si=", buf, 3)))
25296 + err = kstrtoul(buf + 3, 16, &id);
25297 + if (unlikely(err))
25300 + err = au_procfs_plm_write_si(file, id);
25301 + if (unlikely(err))
25305 + err = count; /* success */
25310 +static const struct file_operations au_procfs_plm_fop = {
25311 + .write = au_procfs_plm_write,
25312 + .release = au_procfs_plm_release,
25313 + .owner = THIS_MODULE
25316 +/* ---------------------------------------------------------------------- */
25318 +static struct proc_dir_entry *au_procfs_dir;
25320 +void au_procfs_fin(void)
25322 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25323 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25326 +int __init au_procfs_init(void)
25329 + struct proc_dir_entry *entry;
25332 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25333 + if (unlikely(!au_procfs_dir))
25336 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25337 + au_procfs_dir, &au_procfs_plm_fop);
25338 + if (unlikely(!entry))
25342 + goto out; /* success */
25346 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25350 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25351 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25352 +++ linux/fs/aufs/rdu.c 2015-01-25 13:00:38.634380408 +0100
25355 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25357 + * This program, aufs is free software; you can redistribute it and/or modify
25358 + * it under the terms of the GNU General Public License as published by
25359 + * the Free Software Foundation; either version 2 of the License, or
25360 + * (at your option) any later version.
25362 + * This program is distributed in the hope that it will be useful,
25363 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25364 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25365 + * GNU General Public License for more details.
25367 + * You should have received a copy of the GNU General Public License
25368 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25372 + * readdir in userspace.
25375 +#include <linux/compat.h>
25376 +#include <linux/fs_stack.h>
25377 +#include <linux/security.h>
25380 +/* bits for struct aufs_rdu.flags */
25381 +#define AuRdu_CALLED 1
25382 +#define AuRdu_CONT (1 << 1)
25383 +#define AuRdu_FULL (1 << 2)
25384 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25385 +#define au_fset_rdu(flags, name) \
25386 + do { (flags) |= AuRdu_##name; } while (0)
25387 +#define au_fclr_rdu(flags, name) \
25388 + do { (flags) &= ~AuRdu_##name; } while (0)
25390 +struct au_rdu_arg {
25391 + struct dir_context ctx;
25392 + struct aufs_rdu *rdu;
25393 + union au_rdu_ent_ul ent;
25394 + unsigned long end;
25396 + struct super_block *sb;
25400 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25401 + loff_t offset, u64 h_ino, unsigned int d_type)
25404 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25405 + struct aufs_rdu *rdu = arg->rdu;
25406 + struct au_rdu_ent ent;
25410 + au_fset_rdu(rdu->cookie.flags, CALLED);
25411 + len = au_rdu_len(nlen);
25412 + if (arg->ent.ul + len < arg->end) {
25414 + ent.bindex = rdu->cookie.bindex;
25415 + ent.type = d_type;
25417 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25418 + ent.type = DT_UNKNOWN;
25420 + /* unnecessary to support mmap_sem since this is a dir */
25422 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25424 + if (copy_to_user(arg->ent.e->name, name, nlen))
25426 + /* the terminating NULL */
25427 + if (__put_user(0, arg->ent.e->name + nlen))
25430 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25431 + arg->ent.ul += len;
25435 + au_fset_rdu(rdu->cookie.flags, FULL);
25437 + rdu->tail = arg->ent;
25441 + /* AuTraceErr(err); */
25445 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25449 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25451 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25452 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25454 + if (unlikely(offset != cookie->h_pos))
25460 + au_fclr_rdu(cookie->flags, CALLED);
25462 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25466 + && au_ftest_rdu(cookie->flags, CALLED)
25467 + && !au_ftest_rdu(cookie->flags, FULL));
25468 + cookie->h_pos = h_file->f_pos;
25475 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25478 + aufs_bindex_t bend;
25479 + struct au_rdu_arg arg = {
25481 + .actor = au_diractor(au_rdu_fill)
25484 + struct dentry *dentry;
25485 + struct inode *inode;
25486 + struct file *h_file;
25487 + struct au_rdu_cookie *cookie = &rdu->cookie;
25489 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25490 + if (unlikely(err)) {
25496 + rdu->tail = rdu->ent;
25499 + arg.ent = rdu->ent;
25500 + arg.end = arg.ent.ul;
25501 + arg.end += rdu->sz;
25504 + if (unlikely(!file->f_op->iterate))
25507 + err = security_file_permission(file, MAY_READ);
25509 + if (unlikely(err))
25512 + dentry = file->f_dentry;
25513 + inode = dentry->d_inode;
25515 + mutex_lock(&inode->i_mutex);
25517 + err = mutex_lock_killable(&inode->i_mutex);
25519 + if (unlikely(err))
25523 + arg.sb = inode->i_sb;
25524 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25525 + if (unlikely(err))
25527 + err = au_alive_dir(dentry);
25528 + if (unlikely(err))
25530 + /* todo: reval? */
25531 + fi_read_lock(file);
25534 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25535 + && cookie->generation != au_figen(file)))
25540 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25542 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25544 + bend = au_fbstart(file);
25545 + if (cookie->bindex < bend)
25546 + cookie->bindex = bend;
25547 + bend = au_fbend_dir(file);
25548 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25549 + for (; !err && cookie->bindex <= bend;
25550 + cookie->bindex++, cookie->h_pos = 0) {
25551 + h_file = au_hf_dir(file, cookie->bindex);
25555 + au_fclr_rdu(cookie->flags, FULL);
25556 + err = au_rdu_do(h_file, &arg);
25558 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25561 + AuDbg("rent %llu\n", rdu->rent);
25563 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25564 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25565 + au_fset_rdu(cookie->flags, CONT);
25566 + cookie->generation = au_figen(file);
25569 + ii_read_lock_child(inode);
25570 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25571 + ii_read_unlock(inode);
25574 + fi_read_unlock(file);
25576 + si_read_unlock(arg.sb);
25578 + mutex_unlock(&inode->i_mutex);
25584 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25588 + unsigned long long nent;
25589 + union au_rdu_ent_ul *u;
25590 + struct au_rdu_ent ent;
25591 + struct super_block *sb;
25594 + nent = rdu->nent;
25596 + sb = file->f_dentry->d_sb;
25597 + si_read_lock(sb, AuLock_FLUSH);
25598 + while (nent-- > 0) {
25599 + /* unnecessary to support mmap_sem since this is a dir */
25600 + err = copy_from_user(&ent, u->e, sizeof(ent));
25602 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25603 + if (unlikely(err)) {
25609 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25611 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25613 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25615 + if (unlikely(err)) {
25620 + err = __put_user(ino, &u->e->ino);
25621 + if (unlikely(err)) {
25626 + u->ul += au_rdu_len(ent.nlen);
25628 + si_read_unlock(sb);
25633 +/* ---------------------------------------------------------------------- */
25635 +static int au_rdu_verify(struct aufs_rdu *rdu)
25637 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
25638 + "%llu, b%d, 0x%x, g%u}\n",
25639 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
25641 + rdu->rent, rdu->shwh, rdu->full,
25642 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
25643 + rdu->cookie.generation);
25645 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
25649 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
25653 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25656 + struct aufs_rdu rdu;
25657 + void __user *p = (void __user *)arg;
25659 + err = copy_from_user(&rdu, p, sizeof(rdu));
25660 + if (unlikely(err)) {
25665 + err = au_rdu_verify(&rdu);
25666 + if (unlikely(err))
25670 + case AUFS_CTL_RDU:
25671 + err = au_rdu(file, &rdu);
25672 + if (unlikely(err))
25675 + e = copy_to_user(p, &rdu, sizeof(rdu));
25676 + if (unlikely(e)) {
25681 + case AUFS_CTL_RDU_INO:
25682 + err = au_rdu_ino(file, &rdu);
25686 + /* err = -ENOTTY; */
25695 +#ifdef CONFIG_COMPAT
25696 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25699 + struct aufs_rdu rdu;
25700 + void __user *p = compat_ptr(arg);
25702 + /* todo: get_user()? */
25703 + err = copy_from_user(&rdu, p, sizeof(rdu));
25704 + if (unlikely(err)) {
25709 + rdu.ent.e = compat_ptr(rdu.ent.ul);
25710 + err = au_rdu_verify(&rdu);
25711 + if (unlikely(err))
25715 + case AUFS_CTL_RDU:
25716 + err = au_rdu(file, &rdu);
25717 + if (unlikely(err))
25720 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
25721 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
25722 + e = copy_to_user(p, &rdu, sizeof(rdu));
25723 + if (unlikely(e)) {
25728 + case AUFS_CTL_RDU_INO:
25729 + err = au_rdu_ino(file, &rdu);
25733 + /* err = -ENOTTY; */
25742 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
25743 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
25744 +++ linux/fs/aufs/rwsem.h 2015-01-25 13:00:38.634380408 +0100
25747 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25749 + * This program, aufs is free software; you can redistribute it and/or modify
25750 + * it under the terms of the GNU General Public License as published by
25751 + * the Free Software Foundation; either version 2 of the License, or
25752 + * (at your option) any later version.
25754 + * This program is distributed in the hope that it will be useful,
25755 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25756 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25757 + * GNU General Public License for more details.
25759 + * You should have received a copy of the GNU General Public License
25760 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25764 + * simple read-write semaphore wrappers
25767 +#ifndef __AUFS_RWSEM_H__
25768 +#define __AUFS_RWSEM_H__
25772 +#include "debug.h"
25775 + struct rw_semaphore rwsem;
25776 +#ifdef CONFIG_AUFS_DEBUG
25777 + /* just for debugging, not almighty counter */
25778 + atomic_t rcnt, wcnt;
25782 +#ifdef CONFIG_AUFS_DEBUG
25783 +#define AuDbgCntInit(rw) do { \
25784 + atomic_set(&(rw)->rcnt, 0); \
25785 + atomic_set(&(rw)->wcnt, 0); \
25786 + smp_mb(); /* atomic set */ \
25789 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
25790 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
25791 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
25792 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
25794 +#define AuDbgCntInit(rw) do {} while (0)
25795 +#define AuDbgRcntInc(rw) do {} while (0)
25796 +#define AuDbgRcntDec(rw) do {} while (0)
25797 +#define AuDbgWcntInc(rw) do {} while (0)
25798 +#define AuDbgWcntDec(rw) do {} while (0)
25799 +#endif /* CONFIG_AUFS_DEBUG */
25801 +/* to debug easier, do not make them inlined functions */
25802 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
25803 +/* rwsem_is_locked() is unusable */
25804 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
25805 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
25806 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
25807 + && atomic_read(&(rw)->wcnt) <= 0)
25808 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
25809 + || atomic_read(&(rw)->wcnt))
25811 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
25813 +static inline void au_rw_init(struct au_rwsem *rw)
25815 + AuDbgCntInit(rw);
25816 + init_rwsem(&rw->rwsem);
25819 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
25822 + down_write(&rw->rwsem);
25823 + AuDbgWcntInc(rw);
25826 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
25827 + unsigned int lsc)
25830 + down_write_nested(&rw->rwsem, lsc);
25831 + AuDbgWcntInc(rw);
25834 +static inline void au_rw_read_lock(struct au_rwsem *rw)
25836 + down_read(&rw->rwsem);
25837 + AuDbgRcntInc(rw);
25840 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
25842 + down_read_nested(&rw->rwsem, lsc);
25843 + AuDbgRcntInc(rw);
25846 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
25848 + AuRwMustReadLock(rw);
25849 + AuDbgRcntDec(rw);
25850 + up_read(&rw->rwsem);
25853 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
25855 + AuRwMustWriteLock(rw);
25856 + AuDbgRcntInc(rw);
25857 + AuDbgWcntDec(rw);
25858 + downgrade_write(&rw->rwsem);
25861 +static inline void au_rw_write_lock(struct au_rwsem *rw)
25863 + down_write(&rw->rwsem);
25864 + AuDbgWcntInc(rw);
25867 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
25868 + unsigned int lsc)
25870 + down_write_nested(&rw->rwsem, lsc);
25871 + AuDbgWcntInc(rw);
25874 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
25876 + AuRwMustWriteLock(rw);
25877 + AuDbgWcntDec(rw);
25878 + up_write(&rw->rwsem);
25881 +/* why is not _nested version defined */
25882 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
25886 + ret = down_read_trylock(&rw->rwsem);
25888 + AuDbgRcntInc(rw);
25892 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
25896 + ret = down_write_trylock(&rw->rwsem);
25898 + AuDbgWcntInc(rw);
25902 +#undef AuDbgCntInit
25903 +#undef AuDbgRcntInc
25904 +#undef AuDbgRcntDec
25905 +#undef AuDbgWcntInc
25906 +#undef AuDbgWcntDec
25908 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25909 +static inline void prefix##_read_lock(param) \
25910 +{ au_rw_read_lock(rwsem); } \
25911 +static inline void prefix##_write_lock(param) \
25912 +{ au_rw_write_lock(rwsem); } \
25913 +static inline int prefix##_read_trylock(param) \
25914 +{ return au_rw_read_trylock(rwsem); } \
25915 +static inline int prefix##_write_trylock(param) \
25916 +{ return au_rw_write_trylock(rwsem); }
25917 +/* why is not _nested version defined */
25918 +/* static inline void prefix##_read_trylock_nested(param, lsc)
25919 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
25920 +static inline void prefix##_write_trylock_nestd(param, lsc)
25921 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
25923 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
25924 +static inline void prefix##_read_unlock(param) \
25925 +{ au_rw_read_unlock(rwsem); } \
25926 +static inline void prefix##_write_unlock(param) \
25927 +{ au_rw_write_unlock(rwsem); } \
25928 +static inline void prefix##_downgrade_lock(param) \
25929 +{ au_rw_dgrade_lock(rwsem); }
25931 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
25932 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25933 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
25935 +#endif /* __KERNEL__ */
25936 +#endif /* __AUFS_RWSEM_H__ */
25937 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
25938 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
25939 +++ linux/fs/aufs/sbinfo.c 2015-01-25 13:00:38.634380408 +0100
25942 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25944 + * This program, aufs is free software; you can redistribute it and/or modify
25945 + * it under the terms of the GNU General Public License as published by
25946 + * the Free Software Foundation; either version 2 of the License, or
25947 + * (at your option) any later version.
25949 + * This program is distributed in the hope that it will be useful,
25950 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25951 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25952 + * GNU General Public License for more details.
25954 + * You should have received a copy of the GNU General Public License
25955 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25959 + * superblock private data
25965 + * they are necessary regardless sysfs is disabled.
25967 +void au_si_free(struct kobject *kobj)
25970 + struct au_sbinfo *sbinfo;
25971 + char *locked __maybe_unused; /* debug only */
25973 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
25974 + for (i = 0; i < AuPlink_NHASH; i++)
25975 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
25976 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
25978 + au_rw_write_lock(&sbinfo->si_rwsem);
25979 + au_br_free(sbinfo);
25980 + au_rw_write_unlock(&sbinfo->si_rwsem);
25982 + AuDebugOn(radix_tree_gang_lookup
25983 + (&sbinfo->au_si_pid.tree, (void **)&locked,
25984 + /*first_index*/PID_MAX_DEFAULT - 1,
25985 + /*max_items*/sizeof(locked)/sizeof(*locked)));
25987 + kfree(sbinfo->si_branch);
25988 + kfree(sbinfo->au_si_pid.bitmap);
25989 + mutex_destroy(&sbinfo->si_xib_mtx);
25990 + AuRwDestroy(&sbinfo->si_rwsem);
25995 +int au_si_alloc(struct super_block *sb)
25998 + struct au_sbinfo *sbinfo;
25999 + static struct lock_class_key aufs_si;
26002 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26003 + if (unlikely(!sbinfo))
26006 + BUILD_BUG_ON(sizeof(unsigned long) !=
26007 + sizeof(*sbinfo->au_si_pid.bitmap));
26008 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
26009 + sizeof(*sbinfo->au_si_pid.bitmap),
26011 + if (unlikely(!sbinfo->au_si_pid.bitmap))
26014 + /* will be reallocated separately */
26015 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26016 + if (unlikely(!sbinfo->si_branch))
26019 + err = sysaufs_si_init(sbinfo);
26020 + if (unlikely(err))
26023 + au_nwt_init(&sbinfo->si_nowait);
26024 + au_rw_init_wlock(&sbinfo->si_rwsem);
26025 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
26026 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
26027 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
26029 + atomic_long_set(&sbinfo->si_ninodes, 0);
26030 + atomic_long_set(&sbinfo->si_nfiles, 0);
26032 + sbinfo->si_bend = -1;
26033 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26035 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26036 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26037 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26038 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26040 + au_fhsm_init(sbinfo);
26042 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26044 + sbinfo->si_xino_jiffy = jiffies;
26045 + sbinfo->si_xino_expire
26046 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26047 + mutex_init(&sbinfo->si_xib_mtx);
26048 + sbinfo->si_xino_brid = -1;
26049 + /* leave si_xib_last_pindex and si_xib_next_bit */
26051 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26052 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26053 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26054 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26056 + for (i = 0; i < AuPlink_NHASH; i++)
26057 + au_sphl_init(sbinfo->si_plink + i);
26058 + init_waitqueue_head(&sbinfo->si_plink_wq);
26059 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26061 + au_sphl_init(&sbinfo->si_files);
26063 + /* leave other members for sysaufs and si_mnt. */
26064 + sbinfo->si_sb = sb;
26065 + sb->s_fs_info = sbinfo;
26067 + au_debug_sbinfo_init(sbinfo);
26068 + return 0; /* success */
26071 + kfree(sbinfo->si_branch);
26073 + kfree(sbinfo->au_si_pid.bitmap);
26080 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
26083 + struct au_branch **brp;
26085 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26088 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
26089 + if (unlikely(!sz))
26090 + sz = sizeof(*brp);
26091 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
26093 + sbinfo->si_branch = brp;
26100 +/* ---------------------------------------------------------------------- */
26102 +unsigned int au_sigen_inc(struct super_block *sb)
26104 + unsigned int gen;
26106 + SiMustWriteLock(sb);
26108 + gen = ++au_sbi(sb)->si_generation;
26109 + au_update_digen(sb->s_root);
26110 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
26111 + sb->s_root->d_inode->i_version++;
26115 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26117 + aufs_bindex_t br_id;
26119 + struct au_sbinfo *sbinfo;
26121 + SiMustWriteLock(sb);
26123 + sbinfo = au_sbi(sb);
26124 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26125 + br_id = ++sbinfo->si_last_br_id;
26126 + AuDebugOn(br_id < 0);
26127 + if (br_id && au_br_index(sb, br_id) < 0)
26134 +/* ---------------------------------------------------------------------- */
26136 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26137 +int si_read_lock(struct super_block *sb, int flags)
26142 + if (au_ftest_lock(flags, FLUSH))
26143 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26145 + si_noflush_read_lock(sb);
26146 + err = au_plink_maint(sb, flags);
26147 + if (unlikely(err))
26148 + si_read_unlock(sb);
26153 +int si_write_lock(struct super_block *sb, int flags)
26157 + if (au_ftest_lock(flags, FLUSH))
26158 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26160 + si_noflush_write_lock(sb);
26161 + err = au_plink_maint(sb, flags);
26162 + if (unlikely(err))
26163 + si_write_unlock(sb);
26168 +/* dentry and super_block lock. call at entry point */
26169 +int aufs_read_lock(struct dentry *dentry, int flags)
26172 + struct super_block *sb;
26174 + sb = dentry->d_sb;
26175 + err = si_read_lock(sb, flags);
26176 + if (unlikely(err))
26179 + if (au_ftest_lock(flags, DW))
26180 + di_write_lock_child(dentry);
26182 + di_read_lock_child(dentry, flags);
26184 + if (au_ftest_lock(flags, GEN)) {
26185 + err = au_digen_test(dentry, au_sigen(sb));
26186 + AuDebugOn(!err && au_dbrange_test(dentry));
26187 + if (unlikely(err))
26188 + aufs_read_unlock(dentry, flags);
26195 +void aufs_read_unlock(struct dentry *dentry, int flags)
26197 + if (au_ftest_lock(flags, DW))
26198 + di_write_unlock(dentry);
26200 + di_read_unlock(dentry, flags);
26201 + si_read_unlock(dentry->d_sb);
26204 +void aufs_write_lock(struct dentry *dentry)
26206 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26207 + di_write_lock_child(dentry);
26210 +void aufs_write_unlock(struct dentry *dentry)
26212 + di_write_unlock(dentry);
26213 + si_write_unlock(dentry->d_sb);
26216 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26219 + unsigned int sigen;
26220 + struct super_block *sb;
26223 + err = si_read_lock(sb, flags);
26224 + if (unlikely(err))
26227 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
26229 + if (au_ftest_lock(flags, GEN)) {
26230 + sigen = au_sigen(sb);
26231 + err = au_digen_test(d1, sigen);
26232 + AuDebugOn(!err && au_dbrange_test(d1));
26234 + err = au_digen_test(d2, sigen);
26235 + AuDebugOn(!err && au_dbrange_test(d2));
26237 + if (unlikely(err))
26238 + aufs_read_and_write_unlock2(d1, d2);
26245 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26247 + di_write_unlock2(d1, d2);
26248 + si_read_unlock(d1->d_sb);
26251 +/* ---------------------------------------------------------------------- */
26253 +int si_pid_test_slow(struct super_block *sb)
26258 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
26259 + rcu_read_unlock();
26261 + return (long)!!p;
26264 +void si_pid_set_slow(struct super_block *sb)
26267 + struct au_sbinfo *sbinfo;
26269 + AuDebugOn(si_pid_test_slow(sb));
26271 + sbinfo = au_sbi(sb);
26272 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
26274 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26275 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
26276 + /*any valid ptr*/sb);
26277 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26279 + radix_tree_preload_end();
26282 +void si_pid_clr_slow(struct super_block *sb)
26285 + struct au_sbinfo *sbinfo;
26287 + AuDebugOn(!si_pid_test_slow(sb));
26289 + sbinfo = au_sbi(sb);
26290 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26291 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
26292 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26294 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26295 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26296 +++ linux/fs/aufs/spl.h 2015-01-25 13:00:38.634380408 +0100
26299 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26301 + * This program, aufs is free software; you can redistribute it and/or modify
26302 + * it under the terms of the GNU General Public License as published by
26303 + * the Free Software Foundation; either version 2 of the License, or
26304 + * (at your option) any later version.
26306 + * This program is distributed in the hope that it will be useful,
26307 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26308 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26309 + * GNU General Public License for more details.
26311 + * You should have received a copy of the GNU General Public License
26312 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26316 + * simple list protected by a spinlock
26319 +#ifndef __AUFS_SPL_H__
26320 +#define __AUFS_SPL_H__
26324 +struct au_splhead {
26326 + struct list_head head;
26329 +static inline void au_spl_init(struct au_splhead *spl)
26331 + spin_lock_init(&spl->spin);
26332 + INIT_LIST_HEAD(&spl->head);
26335 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26337 + spin_lock(&spl->spin);
26338 + list_add(list, &spl->head);
26339 + spin_unlock(&spl->spin);
26342 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26344 + spin_lock(&spl->spin);
26346 + spin_unlock(&spl->spin);
26349 +static inline void au_spl_del_rcu(struct list_head *list,
26350 + struct au_splhead *spl)
26352 + spin_lock(&spl->spin);
26353 + list_del_rcu(list);
26354 + spin_unlock(&spl->spin);
26357 +/* ---------------------------------------------------------------------- */
26359 +struct au_sphlhead {
26361 + struct hlist_head head;
26364 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26366 + spin_lock_init(&sphl->spin);
26367 + INIT_HLIST_HEAD(&sphl->head);
26370 +static inline void au_sphl_add(struct hlist_node *hlist,
26371 + struct au_sphlhead *sphl)
26373 + spin_lock(&sphl->spin);
26374 + hlist_add_head(hlist, &sphl->head);
26375 + spin_unlock(&sphl->spin);
26378 +static inline void au_sphl_del(struct hlist_node *hlist,
26379 + struct au_sphlhead *sphl)
26381 + spin_lock(&sphl->spin);
26382 + hlist_del(hlist);
26383 + spin_unlock(&sphl->spin);
26386 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26387 + struct au_sphlhead *sphl)
26389 + spin_lock(&sphl->spin);
26390 + hlist_del_rcu(hlist);
26391 + spin_unlock(&sphl->spin);
26394 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26396 + unsigned long cnt;
26397 + struct hlist_node *pos;
26400 + spin_lock(&sphl->spin);
26401 + hlist_for_each(pos, &sphl->head)
26403 + spin_unlock(&sphl->spin);
26407 +#endif /* __KERNEL__ */
26408 +#endif /* __AUFS_SPL_H__ */
26409 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26410 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26411 +++ linux/fs/aufs/super.c 2015-01-25 13:00:38.634380408 +0100
26414 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26416 + * This program, aufs is free software; you can redistribute it and/or modify
26417 + * it under the terms of the GNU General Public License as published by
26418 + * the Free Software Foundation; either version 2 of the License, or
26419 + * (at your option) any later version.
26421 + * This program is distributed in the hope that it will be useful,
26422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26424 + * GNU General Public License for more details.
26426 + * You should have received a copy of the GNU General Public License
26427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26431 + * mount and super_block operations
26434 +#include <linux/mm.h>
26435 +#include <linux/module.h>
26436 +#include <linux/seq_file.h>
26437 +#include <linux/statfs.h>
26438 +#include <linux/vmalloc.h>
26439 +#include <linux/writeback.h>
26443 + * super_operations
26445 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26447 + struct au_icntnr *c;
26449 + c = au_cache_alloc_icntnr();
26451 + au_icntnr_init(c);
26452 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26453 + c->iinfo.ii_hinode = NULL;
26454 + return &c->vfs_inode;
26459 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26461 + struct inode *inode = container_of(head, struct inode, i_rcu);
26463 + INIT_HLIST_HEAD(&inode->i_dentry);
26464 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26467 +static void aufs_destroy_inode(struct inode *inode)
26469 + au_iinfo_fin(inode);
26470 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26473 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26475 + struct inode *inode;
26478 + inode = iget_locked(sb, ino);
26479 + if (unlikely(!inode)) {
26480 + inode = ERR_PTR(-ENOMEM);
26483 + if (!(inode->i_state & I_NEW))
26486 + err = au_xigen_new(inode);
26488 + err = au_iinfo_init(inode);
26490 + inode->i_version++;
26492 + iget_failed(inode);
26493 + inode = ERR_PTR(err);
26497 + /* never return NULL */
26498 + AuDebugOn(!inode);
26499 + AuTraceErrPtr(inode);
26503 +/* lock free root dinfo */
26504 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26507 + aufs_bindex_t bindex, bend;
26508 + struct path path;
26509 + struct au_hdentry *hdp;
26510 + struct au_branch *br;
26511 + au_br_perm_str_t perm;
26514 + bend = au_sbend(sb);
26515 + hdp = au_di(sb->s_root)->di_hdentry;
26516 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26517 + br = au_sbr(sb, bindex);
26518 + path.mnt = au_br_mnt(br);
26519 + path.dentry = hdp[bindex].hd_dentry;
26520 + err = au_seq_path(seq, &path);
26522 + au_optstr_br_perm(&perm, br->br_perm);
26523 + err = seq_printf(seq, "=%s", perm.a);
26527 + if (!err && bindex != bend)
26528 + err = seq_putc(seq, ':');
26534 +static void au_show_wbr_create(struct seq_file *m, int v,
26535 + struct au_sbinfo *sbinfo)
26539 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26541 + seq_puts(m, ",create=");
26542 + pat = au_optstr_wbr_create(v);
26544 + case AuWbrCreate_TDP:
26545 + case AuWbrCreate_RR:
26546 + case AuWbrCreate_MFS:
26547 + case AuWbrCreate_PMFS:
26548 + seq_puts(m, pat);
26550 + case AuWbrCreate_MFSV:
26551 + seq_printf(m, /*pat*/"mfs:%lu",
26552 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26555 + case AuWbrCreate_PMFSV:
26556 + seq_printf(m, /*pat*/"pmfs:%lu",
26557 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26560 + case AuWbrCreate_MFSRR:
26561 + seq_printf(m, /*pat*/"mfsrr:%llu",
26562 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26564 + case AuWbrCreate_MFSRRV:
26565 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26566 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26567 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26570 + case AuWbrCreate_PMFSRR:
26571 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26572 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26574 + case AuWbrCreate_PMFSRRV:
26575 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26576 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26577 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26583 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26585 +#ifdef CONFIG_SYSFS
26589 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26590 + aufs_bindex_t bindex, brid;
26591 + struct qstr *name;
26593 + struct dentry *d, *h_root;
26594 + struct au_hdentry *hdp;
26596 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26599 + f = au_sbi(sb)->si_xib;
26603 + /* stop printing the default xino path on the first writable branch */
26605 + brid = au_xino_brid(sb);
26607 + bindex = au_br_index(sb, brid);
26608 + hdp = au_di(sb->s_root)->di_hdentry;
26609 + h_root = hdp[0 + bindex].hd_dentry;
26612 + name = &d->d_name;
26613 + /* safe ->d_parent because the file is unlinked */
26614 + if (d->d_parent == h_root
26615 + && name->len == len
26616 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26619 + seq_puts(seq, ",xino=");
26620 + err = au_xino_path(seq, f);
26627 +/* seq_file will re-call me in case of too long string */
26628 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26631 + unsigned int mnt_flags, v;
26632 + struct super_block *sb;
26633 + struct au_sbinfo *sbinfo;
26635 +#define AuBool(name, str) do { \
26636 + v = au_opt_test(mnt_flags, name); \
26637 + if (v != au_opt_test(AuOpt_Def, name)) \
26638 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
26641 +#define AuStr(name, str) do { \
26642 + v = mnt_flags & AuOptMask_##name; \
26643 + if (v != (AuOpt_Def & AuOptMask_##name)) \
26644 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
26647 +#define AuUInt(name, str, val) do { \
26648 + if (val != AUFS_##name##_DEF) \
26649 + seq_printf(m, "," #str "=%u", val); \
26652 + sb = dentry->d_sb;
26653 + if (sb->s_flags & MS_POSIXACL)
26654 + seq_puts(m, ",acl");
26656 + /* lock free root dinfo */
26657 + si_noflush_read_lock(sb);
26658 + sbinfo = au_sbi(sb);
26659 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
26661 + mnt_flags = au_mntflags(sb);
26662 + if (au_opt_test(mnt_flags, XINO)) {
26663 + err = au_show_xino(m, sb);
26664 + if (unlikely(err))
26667 + seq_puts(m, ",noxino");
26669 + AuBool(TRUNC_XINO, trunc_xino);
26670 + AuStr(UDBA, udba);
26671 + AuBool(SHWH, shwh);
26672 + AuBool(PLINK, plink);
26673 + AuBool(DIO, dio);
26674 + AuBool(DIRPERM1, dirperm1);
26675 + /* AuBool(REFROF, refrof); */
26677 + v = sbinfo->si_wbr_create;
26678 + if (v != AuWbrCreate_Def)
26679 + au_show_wbr_create(m, v, sbinfo);
26681 + v = sbinfo->si_wbr_copyup;
26682 + if (v != AuWbrCopyup_Def)
26683 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
26685 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
26686 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
26687 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
26689 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
26691 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
26692 + AuUInt(RDCACHE, rdcache, v);
26694 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
26695 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
26697 + au_fhsm_show(m, sbinfo);
26699 + AuBool(SUM, sum);
26700 + /* AuBool(SUM_W, wsum); */
26701 + AuBool(WARN_PERM, warn_perm);
26702 + AuBool(VERBOSE, verbose);
26705 + /* be sure to print "br:" last */
26706 + if (!sysaufs_brs) {
26707 + seq_puts(m, ",br:");
26708 + au_show_brs(m, sb);
26710 + si_read_unlock(sb);
26718 +/* ---------------------------------------------------------------------- */
26720 +/* sum mode which returns the summation for statfs(2) */
26722 +static u64 au_add_till_max(u64 a, u64 b)
26730 + return ULLONG_MAX;
26733 +static u64 au_mul_till_max(u64 a, long mul)
26741 + return ULLONG_MAX;
26744 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
26747 + long bsize, factor;
26748 + u64 blocks, bfree, bavail, files, ffree;
26749 + aufs_bindex_t bend, bindex, i;
26750 + unsigned char shared;
26751 + struct path h_path;
26752 + struct super_block *h_sb;
26755 + bsize = LONG_MAX;
26761 + bend = au_sbend(sb);
26762 + for (bindex = 0; bindex <= bend; bindex++) {
26763 + h_path.mnt = au_sbr_mnt(sb, bindex);
26764 + h_sb = h_path.mnt->mnt_sb;
26766 + for (i = 0; !shared && i < bindex; i++)
26767 + shared = (au_sbr_sb(sb, i) == h_sb);
26771 + /* sb->s_root for NFS is unreliable */
26772 + h_path.dentry = h_path.mnt->mnt_root;
26773 + err = vfs_statfs(&h_path, buf);
26774 + if (unlikely(err))
26777 + if (bsize > buf->f_bsize) {
26779 + * we will reduce bsize, so we have to expand blocks
26780 + * etc. to match them again
26782 + factor = (bsize / buf->f_bsize);
26783 + blocks = au_mul_till_max(blocks, factor);
26784 + bfree = au_mul_till_max(bfree, factor);
26785 + bavail = au_mul_till_max(bavail, factor);
26786 + bsize = buf->f_bsize;
26789 + factor = (buf->f_bsize / bsize);
26790 + blocks = au_add_till_max(blocks,
26791 + au_mul_till_max(buf->f_blocks, factor));
26792 + bfree = au_add_till_max(bfree,
26793 + au_mul_till_max(buf->f_bfree, factor));
26794 + bavail = au_add_till_max(bavail,
26795 + au_mul_till_max(buf->f_bavail, factor));
26796 + files = au_add_till_max(files, buf->f_files);
26797 + ffree = au_add_till_max(ffree, buf->f_ffree);
26800 + buf->f_bsize = bsize;
26801 + buf->f_blocks = blocks;
26802 + buf->f_bfree = bfree;
26803 + buf->f_bavail = bavail;
26804 + buf->f_files = files;
26805 + buf->f_ffree = ffree;
26806 + buf->f_frsize = 0;
26812 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
26815 + struct path h_path;
26816 + struct super_block *sb;
26818 + /* lock free root dinfo */
26819 + sb = dentry->d_sb;
26820 + si_noflush_read_lock(sb);
26821 + if (!au_opt_test(au_mntflags(sb), SUM)) {
26822 + /* sb->s_root for NFS is unreliable */
26823 + h_path.mnt = au_sbr_mnt(sb, 0);
26824 + h_path.dentry = h_path.mnt->mnt_root;
26825 + err = vfs_statfs(&h_path, buf);
26827 + err = au_statfs_sum(sb, buf);
26828 + si_read_unlock(sb);
26831 + buf->f_type = AUFS_SUPER_MAGIC;
26832 + buf->f_namelen = AUFS_MAX_NAMELEN;
26833 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
26835 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
26840 +/* ---------------------------------------------------------------------- */
26842 +static int aufs_sync_fs(struct super_block *sb, int wait)
26845 + aufs_bindex_t bend, bindex;
26846 + struct au_branch *br;
26847 + struct super_block *h_sb;
26850 + si_noflush_read_lock(sb);
26851 + bend = au_sbend(sb);
26852 + for (bindex = 0; bindex <= bend; bindex++) {
26853 + br = au_sbr(sb, bindex);
26854 + if (!au_br_writable(br->br_perm))
26857 + h_sb = au_sbr_sb(sb, bindex);
26858 + if (h_sb->s_op->sync_fs) {
26859 + e = h_sb->s_op->sync_fs(h_sb, wait);
26860 + if (unlikely(e && !err))
26862 + /* go on even if an error happens */
26865 + si_read_unlock(sb);
26870 +/* ---------------------------------------------------------------------- */
26872 +/* final actions when unmounting a file system */
26873 +static void aufs_put_super(struct super_block *sb)
26875 + struct au_sbinfo *sbinfo;
26877 + sbinfo = au_sbi(sb);
26881 + dbgaufs_si_fin(sbinfo);
26882 + kobject_put(&sbinfo->si_kobj);
26885 +/* ---------------------------------------------------------------------- */
26887 +void au_array_free(void *array)
26890 + if (!is_vmalloc_addr(array))
26897 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
26900 + unsigned long long n, sz;
26907 + if (*hint > ULLONG_MAX / sizeof(array)) {
26908 + array = ERR_PTR(-EMFILE);
26909 + pr_err("hint %llu\n", *hint);
26913 + sz = sizeof(array) * *hint;
26914 + array = kzalloc(sz, GFP_NOFS);
26915 + if (unlikely(!array))
26916 + array = vzalloc(sz);
26917 + if (unlikely(!array)) {
26918 + array = ERR_PTR(-ENOMEM);
26922 + n = cb(array, *hint, arg);
26923 + AuDebugOn(n > *hint);
26930 +static unsigned long long au_iarray_cb(void *a,
26931 + unsigned long long max __maybe_unused,
26934 + unsigned long long n;
26935 + struct inode **p, *inode;
26936 + struct list_head *head;
26941 + spin_lock(&inode_sb_list_lock);
26942 + list_for_each_entry(inode, head, i_sb_list) {
26943 + if (!is_bad_inode(inode)
26944 + && au_ii(inode)->ii_bstart >= 0) {
26945 + spin_lock(&inode->i_lock);
26946 + if (atomic_read(&inode->i_count)) {
26950 + AuDebugOn(n > max);
26952 + spin_unlock(&inode->i_lock);
26955 + spin_unlock(&inode_sb_list_lock);
26960 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
26962 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
26963 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
26966 +void au_iarray_free(struct inode **a, unsigned long long max)
26968 + unsigned long long ull;
26970 + for (ull = 0; ull < max; ull++)
26972 + au_array_free(a);
26975 +/* ---------------------------------------------------------------------- */
26978 + * refresh dentry and inode at remount time.
26980 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
26981 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
26982 + struct dentry *parent)
26986 + di_write_lock_child(dentry);
26987 + di_read_lock_parent(parent, AuLock_IR);
26988 + err = au_refresh_dentry(dentry, parent);
26989 + if (!err && dir_flags)
26990 + au_hn_reset(dentry->d_inode, dir_flags);
26991 + di_read_unlock(parent, AuLock_IR);
26992 + di_write_unlock(dentry);
26997 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
26998 + struct au_sbinfo *sbinfo,
26999 + const unsigned int dir_flags)
27002 + struct dentry *parent;
27003 + struct inode *inode;
27006 + parent = dget_parent(dentry);
27007 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27008 + inode = dentry->d_inode;
27010 + if (!S_ISDIR(inode->i_mode))
27011 + err = au_do_refresh(dentry, /*dir_flags*/0,
27014 + err = au_do_refresh(dentry, dir_flags, parent);
27015 + if (unlikely(err))
27016 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27019 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27020 + AuDbgDentry(dentry);
27028 +static int au_refresh_d(struct super_block *sb)
27030 + int err, i, j, ndentry, e;
27031 + unsigned int sigen;
27032 + struct au_dcsub_pages dpages;
27033 + struct au_dpage *dpage;
27034 + struct dentry **dentries, *d;
27035 + struct au_sbinfo *sbinfo;
27036 + struct dentry *root = sb->s_root;
27037 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
27039 + err = au_dpages_init(&dpages, GFP_NOFS);
27040 + if (unlikely(err))
27042 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27043 + if (unlikely(err))
27046 + sigen = au_sigen(sb);
27047 + sbinfo = au_sbi(sb);
27048 + for (i = 0; i < dpages.ndpage; i++) {
27049 + dpage = dpages.dpages + i;
27050 + dentries = dpage->dentries;
27051 + ndentry = dpage->ndentry;
27052 + for (j = 0; j < ndentry; j++) {
27054 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
27055 + if (unlikely(e && !err))
27057 + /* go on even err */
27062 + au_dpages_free(&dpages);
27067 +static int au_refresh_i(struct super_block *sb)
27070 + unsigned int sigen;
27071 + unsigned long long max, ull;
27072 + struct inode *inode, **array;
27074 + array = au_iarray_alloc(sb, &max);
27075 + err = PTR_ERR(array);
27076 + if (IS_ERR(array))
27080 + sigen = au_sigen(sb);
27081 + for (ull = 0; ull < max; ull++) {
27082 + inode = array[ull];
27083 + if (unlikely(!inode))
27085 + if (au_iigen(inode, NULL) != sigen) {
27086 + ii_write_lock_child(inode);
27087 + e = au_refresh_hinode_self(inode);
27088 + ii_write_unlock(inode);
27089 + if (unlikely(e)) {
27090 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27093 + /* go on even if err */
27098 + au_iarray_free(array, max);
27104 +static void au_remount_refresh(struct super_block *sb)
27107 + unsigned int udba;
27108 + aufs_bindex_t bindex, bend;
27109 + struct dentry *root;
27110 + struct inode *inode;
27111 + struct au_branch *br;
27113 + au_sigen_inc(sb);
27114 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
27116 + root = sb->s_root;
27117 + DiMustNoWaiters(root);
27118 + inode = root->d_inode;
27119 + IiMustNoWaiters(inode);
27121 + udba = au_opt_udba(sb);
27122 + bend = au_sbend(sb);
27123 + for (bindex = 0; bindex <= bend; bindex++) {
27124 + br = au_sbr(sb, bindex);
27125 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27126 + if (unlikely(err))
27127 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27129 + /* go on even if err */
27131 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27133 + di_write_unlock(root);
27134 + err = au_refresh_d(sb);
27135 + e = au_refresh_i(sb);
27136 + if (unlikely(e && !err))
27138 + /* aufs_write_lock() calls ..._child() */
27139 + di_write_lock_child(root);
27141 + au_cpup_attr_all(inode, /*force*/1);
27143 + if (unlikely(err))
27144 + AuIOErr("refresh failed, ignored, %d\n", err);
27147 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27148 +static int cvt_err(int err)
27162 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27165 + unsigned int mntflags;
27166 + struct au_opts opts;
27167 + struct dentry *root;
27168 + struct inode *inode;
27169 + struct au_sbinfo *sbinfo;
27172 + root = sb->s_root;
27173 + if (!data || !*data) {
27174 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27176 + di_write_lock_child(root);
27177 + err = au_opts_verify(sb, *flags, /*pending*/0);
27178 + aufs_write_unlock(root);
27184 + memset(&opts, 0, sizeof(opts));
27185 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27186 + if (unlikely(!opts.opt))
27188 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27189 + opts.flags = AuOpts_REMOUNT;
27190 + opts.sb_flags = *flags;
27192 + /* parse it before aufs lock */
27193 + err = au_opts_parse(sb, data, &opts);
27194 + if (unlikely(err))
27197 + sbinfo = au_sbi(sb);
27198 + inode = root->d_inode;
27199 + mutex_lock(&inode->i_mutex);
27200 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27201 + if (unlikely(err))
27203 + di_write_lock_child(root);
27205 + /* au_opts_remount() may return an error */
27206 + err = au_opts_remount(sb, &opts);
27207 + au_opts_free(&opts);
27209 + if (au_ftest_opts(opts.flags, REFRESH))
27210 + au_remount_refresh(sb);
27212 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27213 + mntflags = au_mntflags(sb);
27214 + do_dx = !!au_opt_test(mntflags, DIO);
27215 + au_dy_arefresh(do_dx);
27218 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27219 + aufs_write_unlock(root);
27222 + mutex_unlock(&inode->i_mutex);
27224 + free_page((unsigned long)opts.opt);
27226 + err = cvt_err(err);
27231 +static const struct super_operations aufs_sop = {
27232 + .alloc_inode = aufs_alloc_inode,
27233 + .destroy_inode = aufs_destroy_inode,
27234 + /* always deleting, no clearing */
27235 + .drop_inode = generic_delete_inode,
27236 + .show_options = aufs_show_options,
27237 + .statfs = aufs_statfs,
27238 + .put_super = aufs_put_super,
27239 + .sync_fs = aufs_sync_fs,
27240 + .remount_fs = aufs_remount_fs
27243 +/* ---------------------------------------------------------------------- */
27245 +static int alloc_root(struct super_block *sb)
27248 + struct inode *inode;
27249 + struct dentry *root;
27252 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
27253 + err = PTR_ERR(inode);
27254 + if (IS_ERR(inode))
27257 + inode->i_op = &aufs_dir_iop;
27258 + inode->i_fop = &aufs_dir_fop;
27259 + inode->i_mode = S_IFDIR;
27260 + set_nlink(inode, 2);
27261 + unlock_new_inode(inode);
27263 + root = d_make_root(inode);
27264 + if (unlikely(!root))
27266 + err = PTR_ERR(root);
27267 + if (IS_ERR(root))
27270 + err = au_di_init(root);
27272 + sb->s_root = root;
27273 + return 0; /* success */
27281 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27282 + int silent __maybe_unused)
27285 + struct au_opts opts;
27286 + struct dentry *root;
27287 + struct inode *inode;
27288 + char *arg = raw_data;
27290 + if (unlikely(!arg || !*arg)) {
27292 + pr_err("no arg\n");
27297 + memset(&opts, 0, sizeof(opts));
27298 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27299 + if (unlikely(!opts.opt))
27301 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27302 + opts.sb_flags = sb->s_flags;
27304 + err = au_si_alloc(sb);
27305 + if (unlikely(err))
27308 + /* all timestamps always follow the ones on the branch */
27309 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27310 + sb->s_op = &aufs_sop;
27311 + sb->s_d_op = &aufs_dop;
27312 + sb->s_magic = AUFS_SUPER_MAGIC;
27313 + sb->s_maxbytes = 0;
27314 + sb->s_stack_depth = 1;
27315 + au_export_init(sb);
27316 + /* au_xattr_init(sb); */
27318 + err = alloc_root(sb);
27319 + if (unlikely(err)) {
27320 + si_write_unlock(sb);
27323 + root = sb->s_root;
27324 + inode = root->d_inode;
27327 + * actually we can parse options regardless aufs lock here.
27328 + * but at remount time, parsing must be done before aufs lock.
27329 + * so we follow the same rule.
27331 + ii_write_lock_parent(inode);
27332 + aufs_write_unlock(root);
27333 + err = au_opts_parse(sb, arg, &opts);
27334 + if (unlikely(err))
27337 + /* lock vfs_inode first, then aufs. */
27338 + mutex_lock(&inode->i_mutex);
27339 + aufs_write_lock(root);
27340 + err = au_opts_mount(sb, &opts);
27341 + au_opts_free(&opts);
27342 + aufs_write_unlock(root);
27343 + mutex_unlock(&inode->i_mutex);
27345 + goto out_opts; /* success */
27349 + sb->s_root = NULL;
27351 + dbgaufs_si_fin(au_sbi(sb));
27352 + kobject_put(&au_sbi(sb)->si_kobj);
27353 + sb->s_fs_info = NULL;
27355 + free_page((unsigned long)opts.opt);
27358 + err = cvt_err(err);
27363 +/* ---------------------------------------------------------------------- */
27365 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27366 + const char *dev_name __maybe_unused,
27369 + struct dentry *root;
27370 + struct super_block *sb;
27372 + /* all timestamps always follow the ones on the branch */
27373 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27374 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27375 + if (IS_ERR(root))
27379 + si_write_lock(sb, !AuLock_FLUSH);
27380 + sysaufs_brs_add(sb, 0);
27381 + si_write_unlock(sb);
27382 + au_sbilist_add(sb);
27388 +static void aufs_kill_sb(struct super_block *sb)
27390 + struct au_sbinfo *sbinfo;
27392 + sbinfo = au_sbi(sb);
27394 + au_sbilist_del(sb);
27395 + aufs_write_lock(sb->s_root);
27397 + if (sbinfo->si_wbr_create_ops->fin)
27398 + sbinfo->si_wbr_create_ops->fin(sb);
27399 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27400 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27401 + au_remount_refresh(sb);
27403 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27404 + au_plink_put(sb, /*verbose*/1);
27406 + sbinfo->si_sb = NULL;
27407 + aufs_write_unlock(sb->s_root);
27408 + au_nwt_flush(&sbinfo->si_nowait);
27410 + kill_anon_super(sb);
27413 +struct file_system_type aufs_fs_type = {
27414 + .name = AUFS_FSTYPE,
27415 + /* a race between rename and others */
27416 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27417 + .mount = aufs_mount,
27418 + .kill_sb = aufs_kill_sb,
27419 + /* no need to __module_get() and module_put(). */
27420 + .owner = THIS_MODULE,
27422 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27423 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27424 +++ linux/fs/aufs/super.h 2015-01-25 13:00:38.634380408 +0100
27427 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27429 + * This program, aufs is free software; you can redistribute it and/or modify
27430 + * it under the terms of the GNU General Public License as published by
27431 + * the Free Software Foundation; either version 2 of the License, or
27432 + * (at your option) any later version.
27434 + * This program is distributed in the hope that it will be useful,
27435 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27436 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27437 + * GNU General Public License for more details.
27439 + * You should have received a copy of the GNU General Public License
27440 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27444 + * super_block operations
27447 +#ifndef __AUFS_SUPER_H__
27448 +#define __AUFS_SUPER_H__
27452 +#include <linux/fs.h>
27453 +#include "rwsem.h"
27457 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
27458 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
27461 +/* policies to select one among multiple writable branches */
27462 +struct au_wbr_copyup_operations {
27463 + int (*copyup)(struct dentry *dentry);
27466 +#define AuWbr_DIR 1 /* target is a dir */
27467 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27469 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27470 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27471 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27473 +struct au_wbr_create_operations {
27474 + int (*create)(struct dentry *dentry, unsigned int flags);
27475 + int (*init)(struct super_block *sb);
27476 + int (*fin)(struct super_block *sb);
27479 +struct au_wbr_mfs {
27480 + struct mutex mfs_lock; /* protect this structure */
27481 + unsigned long mfs_jiffy;
27482 + unsigned long mfs_expire;
27483 + aufs_bindex_t mfs_bindex;
27485 + unsigned long long mfsrr_bytes;
27486 + unsigned long long mfsrr_watermark;
27489 +struct pseudo_link {
27491 + struct hlist_node hlist;
27492 + struct rcu_head rcu;
27494 + struct inode *inode;
27497 +#define AuPlink_NHASH 100
27498 +static inline int au_plink_hash(ino_t ino)
27500 + return ino % AuPlink_NHASH;
27503 +/* File-based Hierarchical Storage Management */
27505 +#ifdef CONFIG_AUFS_FHSM
27506 + /* allow only one process who can receive the notification */
27507 + spinlock_t fhsm_spin;
27509 + wait_queue_head_t fhsm_wqh;
27510 + atomic_t fhsm_readable;
27512 + /* these are protected by si_rwsem */
27513 + unsigned long fhsm_expire;
27514 + aufs_bindex_t fhsm_bottom;
27519 +struct au_sbinfo {
27520 + /* nowait tasks in the system-wide workqueue */
27521 + struct au_nowait_tasks si_nowait;
27524 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27525 + * rwsem for au_sbinfo is necessary.
27527 + struct au_rwsem si_rwsem;
27529 + /* prevent recursive locking in deleting inode */
27531 + unsigned long *bitmap;
27532 + spinlock_t tree_lock;
27533 + struct radix_tree_root tree;
27537 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27540 + atomic_long_t si_ninodes, si_nfiles;
27542 + /* branch management */
27543 + unsigned int si_generation;
27545 + /* see above flags */
27546 + unsigned char au_si_status;
27548 + aufs_bindex_t si_bend;
27550 + /* dirty trick to keep br_id plus */
27551 + unsigned int si_last_br_id :
27552 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27553 + struct au_branch **si_branch;
27555 + /* policy to select a writable branch */
27556 + unsigned char si_wbr_copyup;
27557 + unsigned char si_wbr_create;
27558 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27559 + struct au_wbr_create_operations *si_wbr_create_ops;
27561 + /* round robin */
27562 + atomic_t si_wbr_rr_next;
27564 + /* most free space */
27565 + struct au_wbr_mfs si_wbr_mfs;
27567 + /* File-based Hierarchical Storage Management */
27568 + struct au_fhsm si_fhsm;
27570 + /* mount flags */
27571 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27572 + unsigned int si_mntflags;
27574 + /* external inode number (bitmap and translation table) */
27575 + au_readf_t si_xread;
27576 + au_writef_t si_xwrite;
27577 + struct file *si_xib;
27578 + struct mutex si_xib_mtx; /* protect xib members */
27579 + unsigned long *si_xib_buf;
27580 + unsigned long si_xib_last_pindex;
27581 + int si_xib_next_bit;
27582 + aufs_bindex_t si_xino_brid;
27583 + unsigned long si_xino_jiffy;
27584 + unsigned long si_xino_expire;
27585 + /* reserved for future use */
27586 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
27588 +#ifdef CONFIG_AUFS_EXPORT
27589 + /* i_generation */
27590 + struct file *si_xigen;
27591 + atomic_t si_xigen_next;
27594 + /* vdir parameters */
27595 + unsigned long si_rdcache; /* max cache time in jiffies */
27596 + unsigned int si_rdblk; /* deblk size */
27597 + unsigned int si_rdhash; /* hash size */
27600 + * If the number of whiteouts are larger than si_dirwh, leave all of
27601 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
27602 + * future fsck.aufs or kernel thread will remove them later.
27603 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
27605 + unsigned int si_dirwh;
27608 + * rename(2) a directory with all children.
27610 + /* reserved for future use */
27611 + /* int si_rendir; */
27613 + /* pseudo_link list */
27614 + struct au_sphlhead si_plink[AuPlink_NHASH];
27615 + wait_queue_head_t si_plink_wq;
27616 + spinlock_t si_plink_maint_lock;
27617 + pid_t si_plink_maint_pid;
27620 + struct au_sphlhead si_files;
27623 + * sysfs and lifetime management.
27624 + * this is not a small structure and it may be a waste of memory in case
27625 + * of sysfs is disabled, particulary when many aufs-es are mounted.
27626 + * but using sysfs is majority.
27628 + struct kobject si_kobj;
27629 +#ifdef CONFIG_DEBUG_FS
27630 + struct dentry *si_dbgaufs;
27631 + struct dentry *si_dbgaufs_plink;
27632 + struct dentry *si_dbgaufs_xib;
27633 +#ifdef CONFIG_AUFS_EXPORT
27634 + struct dentry *si_dbgaufs_xigen;
27638 +#ifdef CONFIG_AUFS_SBILIST
27639 + struct list_head si_list;
27642 + /* dirty, necessary for unmounting, sysfs and sysrq */
27643 + struct super_block *si_sb;
27646 +/* sbinfo status flags */
27648 + * set true when refresh_dirs() failed at remount time.
27649 + * then try refreshing dirs at access time again.
27650 + * if it is false, refreshing dirs at access time is unnecesary
27652 +#define AuSi_FAILED_REFRESH_DIR 1
27654 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
27656 +#ifndef CONFIG_AUFS_FHSM
27658 +#define AuSi_FHSM 0
27661 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
27662 + unsigned int flag)
27664 + AuRwMustAnyLock(&sbi->si_rwsem);
27665 + return sbi->au_si_status & flag;
27667 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
27668 +#define au_fset_si(sbinfo, name) do { \
27669 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27670 + (sbinfo)->au_si_status |= AuSi_##name; \
27672 +#define au_fclr_si(sbinfo, name) do { \
27673 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27674 + (sbinfo)->au_si_status &= ~AuSi_##name; \
27677 +/* ---------------------------------------------------------------------- */
27679 +/* policy to select one among writable branches */
27680 +#define AuWbrCopyup(sbinfo, ...) \
27681 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
27682 +#define AuWbrCreate(sbinfo, ...) \
27683 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
27685 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
27686 +#define AuLock_DW 1 /* write-lock dentry */
27687 +#define AuLock_IR (1 << 1) /* read-lock inode */
27688 +#define AuLock_IW (1 << 2) /* write-lock inode */
27689 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
27690 +#define AuLock_DIR (1 << 4) /* target is a dir */
27691 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
27692 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
27693 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
27694 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
27695 +#define au_fset_lock(flags, name) \
27696 + do { (flags) |= AuLock_##name; } while (0)
27697 +#define au_fclr_lock(flags, name) \
27698 + do { (flags) &= ~AuLock_##name; } while (0)
27700 +/* ---------------------------------------------------------------------- */
27703 +extern struct file_system_type aufs_fs_type;
27704 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
27705 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
27707 +void au_array_free(void *array);
27708 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
27709 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
27710 +void au_iarray_free(struct inode **a, unsigned long long max);
27713 +void au_si_free(struct kobject *kobj);
27714 +int au_si_alloc(struct super_block *sb);
27715 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
27717 +unsigned int au_sigen_inc(struct super_block *sb);
27718 +aufs_bindex_t au_new_br_id(struct super_block *sb);
27720 +int si_read_lock(struct super_block *sb, int flags);
27721 +int si_write_lock(struct super_block *sb, int flags);
27722 +int aufs_read_lock(struct dentry *dentry, int flags);
27723 +void aufs_read_unlock(struct dentry *dentry, int flags);
27724 +void aufs_write_lock(struct dentry *dentry);
27725 +void aufs_write_unlock(struct dentry *dentry);
27726 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
27727 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
27729 +int si_pid_test_slow(struct super_block *sb);
27730 +void si_pid_set_slow(struct super_block *sb);
27731 +void si_pid_clr_slow(struct super_block *sb);
27733 +/* wbr_policy.c */
27734 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
27735 +extern struct au_wbr_create_operations au_wbr_create_ops[];
27736 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
27737 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
27738 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
27741 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
27743 +#ifdef CONFIG_AUFS_FHSM
27746 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
27750 + spin_lock(&fhsm->fhsm_spin);
27751 + pid = fhsm->fhsm_pid;
27752 + spin_unlock(&fhsm->fhsm_spin);
27757 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
27758 +void au_fhsm_wrote_all(struct super_block *sb, int force);
27759 +int au_fhsm_fd(struct super_block *sb, int oflags);
27760 +int au_fhsm_br_alloc(struct au_branch *br);
27761 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
27762 +void au_fhsm_fin(struct super_block *sb);
27763 +void au_fhsm_init(struct au_sbinfo *sbinfo);
27764 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
27765 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
27767 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
27769 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
27770 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
27771 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
27772 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
27773 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
27774 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
27775 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
27776 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
27777 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
27780 +/* ---------------------------------------------------------------------- */
27782 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
27784 + return sb->s_fs_info;
27787 +/* ---------------------------------------------------------------------- */
27789 +#ifdef CONFIG_AUFS_EXPORT
27790 +int au_test_nfsd(void);
27791 +void au_export_init(struct super_block *sb);
27792 +void au_xigen_inc(struct inode *inode);
27793 +int au_xigen_new(struct inode *inode);
27794 +int au_xigen_set(struct super_block *sb, struct file *base);
27795 +void au_xigen_clr(struct super_block *sb);
27797 +static inline int au_busy_or_stale(void)
27799 + if (!au_test_nfsd())
27804 +AuStubInt0(au_test_nfsd, void)
27805 +AuStubVoid(au_export_init, struct super_block *sb)
27806 +AuStubVoid(au_xigen_inc, struct inode *inode)
27807 +AuStubInt0(au_xigen_new, struct inode *inode)
27808 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
27809 +AuStubVoid(au_xigen_clr, struct super_block *sb)
27810 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
27811 +#endif /* CONFIG_AUFS_EXPORT */
27813 +/* ---------------------------------------------------------------------- */
27815 +#ifdef CONFIG_AUFS_SBILIST
27817 +extern struct au_splhead au_sbilist;
27819 +static inline void au_sbilist_init(void)
27821 + au_spl_init(&au_sbilist);
27824 +static inline void au_sbilist_add(struct super_block *sb)
27826 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
27829 +static inline void au_sbilist_del(struct super_block *sb)
27831 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
27834 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
27835 +static inline void au_sbilist_lock(void)
27837 + spin_lock(&au_sbilist.spin);
27840 +static inline void au_sbilist_unlock(void)
27842 + spin_unlock(&au_sbilist.spin);
27844 +#define AuGFP_SBILIST GFP_ATOMIC
27846 +AuStubVoid(au_sbilist_lock, void)
27847 +AuStubVoid(au_sbilist_unlock, void)
27848 +#define AuGFP_SBILIST GFP_NOFS
27849 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
27851 +AuStubVoid(au_sbilist_init, void)
27852 +AuStubVoid(au_sbilist_add, struct super_block *sb)
27853 +AuStubVoid(au_sbilist_del, struct super_block *sb)
27854 +AuStubVoid(au_sbilist_lock, void)
27855 +AuStubVoid(au_sbilist_unlock, void)
27856 +#define AuGFP_SBILIST GFP_NOFS
27859 +/* ---------------------------------------------------------------------- */
27861 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
27864 + * This function is a dynamic '__init' function actually,
27865 + * so the tiny check for si_rwsem is unnecessary.
27867 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
27868 +#ifdef CONFIG_DEBUG_FS
27869 + sbinfo->si_dbgaufs = NULL;
27870 + sbinfo->si_dbgaufs_plink = NULL;
27871 + sbinfo->si_dbgaufs_xib = NULL;
27872 +#ifdef CONFIG_AUFS_EXPORT
27873 + sbinfo->si_dbgaufs_xigen = NULL;
27878 +/* ---------------------------------------------------------------------- */
27880 +static inline pid_t si_pid_bit(void)
27882 + /* the origin of pid is 1, but the bitmap's is 0 */
27883 + return current->pid - 1;
27886 +static inline int si_pid_test(struct super_block *sb)
27890 + bit = si_pid_bit();
27891 + if (bit < PID_MAX_DEFAULT)
27892 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27893 + return si_pid_test_slow(sb);
27896 +static inline void si_pid_set(struct super_block *sb)
27900 + bit = si_pid_bit();
27901 + if (bit < PID_MAX_DEFAULT) {
27902 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27903 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27906 + si_pid_set_slow(sb);
27909 +static inline void si_pid_clr(struct super_block *sb)
27913 + bit = si_pid_bit();
27914 + if (bit < PID_MAX_DEFAULT) {
27915 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27916 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27919 + si_pid_clr_slow(sb);
27922 +/* ---------------------------------------------------------------------- */
27924 +/* lock superblock. mainly for entry point functions */
27926 + * __si_read_lock, __si_write_lock,
27927 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
27929 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
27931 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
27932 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
27933 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
27935 +static inline void si_noflush_read_lock(struct super_block *sb)
27937 + __si_read_lock(sb);
27941 +static inline int si_noflush_read_trylock(struct super_block *sb)
27945 + locked = __si_read_trylock(sb);
27951 +static inline void si_noflush_write_lock(struct super_block *sb)
27953 + __si_write_lock(sb);
27957 +static inline int si_noflush_write_trylock(struct super_block *sb)
27961 + locked = __si_write_trylock(sb);
27967 +#if 0 /* unused */
27968 +static inline int si_read_trylock(struct super_block *sb, int flags)
27970 + if (au_ftest_lock(flags, FLUSH))
27971 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27972 + return si_noflush_read_trylock(sb);
27976 +static inline void si_read_unlock(struct super_block *sb)
27979 + __si_read_unlock(sb);
27982 +#if 0 /* unused */
27983 +static inline int si_write_trylock(struct super_block *sb, int flags)
27985 + if (au_ftest_lock(flags, FLUSH))
27986 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27987 + return si_noflush_write_trylock(sb);
27991 +static inline void si_write_unlock(struct super_block *sb)
27994 + __si_write_unlock(sb);
27997 +#if 0 /* unused */
27998 +static inline void si_downgrade_lock(struct super_block *sb)
28000 + __si_downgrade_lock(sb);
28004 +/* ---------------------------------------------------------------------- */
28006 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
28008 + SiMustAnyLock(sb);
28009 + return au_sbi(sb)->si_bend;
28012 +static inline unsigned int au_mntflags(struct super_block *sb)
28014 + SiMustAnyLock(sb);
28015 + return au_sbi(sb)->si_mntflags;
28018 +static inline unsigned int au_sigen(struct super_block *sb)
28020 + SiMustAnyLock(sb);
28021 + return au_sbi(sb)->si_generation;
28024 +static inline void au_ninodes_inc(struct super_block *sb)
28026 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
28029 +static inline void au_ninodes_dec(struct super_block *sb)
28031 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
28032 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
28035 +static inline void au_nfiles_inc(struct super_block *sb)
28037 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
28040 +static inline void au_nfiles_dec(struct super_block *sb)
28042 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
28043 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
28046 +static inline struct au_branch *au_sbr(struct super_block *sb,
28047 + aufs_bindex_t bindex)
28049 + SiMustAnyLock(sb);
28050 + return au_sbi(sb)->si_branch[0 + bindex];
28053 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28055 + SiMustWriteLock(sb);
28056 + au_sbi(sb)->si_xino_brid = brid;
28059 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28061 + SiMustAnyLock(sb);
28062 + return au_sbi(sb)->si_xino_brid;
28065 +#endif /* __KERNEL__ */
28066 +#endif /* __AUFS_SUPER_H__ */
28067 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28068 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28069 +++ linux/fs/aufs/sysaufs.c 2015-01-25 13:00:38.634380408 +0100
28072 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28074 + * This program, aufs is free software; you can redistribute it and/or modify
28075 + * it under the terms of the GNU General Public License as published by
28076 + * the Free Software Foundation; either version 2 of the License, or
28077 + * (at your option) any later version.
28079 + * This program is distributed in the hope that it will be useful,
28080 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28081 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28082 + * GNU General Public License for more details.
28084 + * You should have received a copy of the GNU General Public License
28085 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28089 + * sysfs interface and lifetime management
28090 + * they are necessary regardless sysfs is disabled.
28093 +#include <linux/random.h>
28096 +unsigned long sysaufs_si_mask;
28097 +struct kset *sysaufs_kset;
28099 +#define AuSiAttr(_name) { \
28100 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28101 + .show = sysaufs_si_##_name, \
28104 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28105 +struct attribute *sysaufs_si_attrs[] = {
28106 + &sysaufs_si_attr_xi_path.attr,
28110 +static const struct sysfs_ops au_sbi_ops = {
28111 + .show = sysaufs_si_show
28114 +static struct kobj_type au_sbi_ktype = {
28115 + .release = au_si_free,
28116 + .sysfs_ops = &au_sbi_ops,
28117 + .default_attrs = sysaufs_si_attrs
28120 +/* ---------------------------------------------------------------------- */
28122 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28126 + sbinfo->si_kobj.kset = sysaufs_kset;
28127 + /* cf. sysaufs_name() */
28128 + err = kobject_init_and_add
28129 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28130 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28132 + dbgaufs_si_null(sbinfo);
28134 + err = dbgaufs_si_init(sbinfo);
28135 + if (unlikely(err))
28136 + kobject_put(&sbinfo->si_kobj);
28141 +void sysaufs_fin(void)
28144 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28145 + kset_unregister(sysaufs_kset);
28148 +int __init sysaufs_init(void)
28153 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28154 + } while (!sysaufs_si_mask);
28157 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28158 + if (unlikely(!sysaufs_kset))
28160 + err = PTR_ERR(sysaufs_kset);
28161 + if (IS_ERR(sysaufs_kset))
28163 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28164 + if (unlikely(err)) {
28165 + kset_unregister(sysaufs_kset);
28169 + err = dbgaufs_init();
28170 + if (unlikely(err))
28175 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28176 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28177 +++ linux/fs/aufs/sysaufs.h 2015-01-25 13:00:38.634380408 +0100
28180 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28182 + * This program, aufs is free software; you can redistribute it and/or modify
28183 + * it under the terms of the GNU General Public License as published by
28184 + * the Free Software Foundation; either version 2 of the License, or
28185 + * (at your option) any later version.
28187 + * This program is distributed in the hope that it will be useful,
28188 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28189 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28190 + * GNU General Public License for more details.
28192 + * You should have received a copy of the GNU General Public License
28193 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28197 + * sysfs interface and mount lifetime management
28200 +#ifndef __SYSAUFS_H__
28201 +#define __SYSAUFS_H__
28205 +#include <linux/sysfs.h>
28206 +#include "module.h"
28208 +struct super_block;
28211 +struct sysaufs_si_attr {
28212 + struct attribute attr;
28213 + int (*show)(struct seq_file *seq, struct super_block *sb);
28216 +/* ---------------------------------------------------------------------- */
28219 +extern unsigned long sysaufs_si_mask;
28220 +extern struct kset *sysaufs_kset;
28221 +extern struct attribute *sysaufs_si_attrs[];
28222 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28223 +int __init sysaufs_init(void);
28224 +void sysaufs_fin(void);
28226 +/* ---------------------------------------------------------------------- */
28228 +/* some people doesn't like to show a pointer in kernel */
28229 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28231 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28234 +#define SysaufsSiNamePrefix "si_"
28235 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
28236 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
28238 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
28239 + sysaufs_si_id(sbinfo));
28243 +#ifdef CONFIG_SYSFS
28245 +extern struct attribute_group *sysaufs_attr_group;
28247 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
28248 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28250 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
28251 +#ifdef CONFIG_COMPAT
28252 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
28255 +void sysaufs_br_init(struct au_branch *br);
28256 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
28257 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
28259 +#define sysaufs_brs_init() do {} while (0)
28262 +#define sysaufs_attr_group NULL
28264 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
28265 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
28266 + struct attribute *attr, char *buf)
28267 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
28268 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
28269 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28271 +static inline void sysaufs_brs_init(void)
28276 +#endif /* CONFIG_SYSFS */
28278 +#endif /* __KERNEL__ */
28279 +#endif /* __SYSAUFS_H__ */
28280 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
28281 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28282 +++ linux/fs/aufs/sysfs.c 2015-01-25 13:00:38.634380408 +0100
28285 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28287 + * This program, aufs is free software; you can redistribute it and/or modify
28288 + * it under the terms of the GNU General Public License as published by
28289 + * the Free Software Foundation; either version 2 of the License, or
28290 + * (at your option) any later version.
28292 + * This program is distributed in the hope that it will be useful,
28293 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28294 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28295 + * GNU General Public License for more details.
28297 + * You should have received a copy of the GNU General Public License
28298 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28302 + * sysfs interface
28305 +#include <linux/compat.h>
28306 +#include <linux/seq_file.h>
28309 +#ifdef CONFIG_AUFS_FS_MODULE
28310 +/* this entry violates the "one line per file" policy of sysfs */
28311 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28315 + static char *conf =
28316 +/* this file is generated at compiling */
28317 +#include "conf.str"
28320 + err = snprintf(buf, PAGE_SIZE, conf);
28321 + if (unlikely(err >= PAGE_SIZE))
28326 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28329 +static struct attribute *au_attr[] = {
28330 +#ifdef CONFIG_AUFS_FS_MODULE
28331 + &au_config_attr.attr,
28333 + NULL, /* need to NULL terminate the list of attributes */
28336 +static struct attribute_group sysaufs_attr_group_body = {
28340 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28342 +/* ---------------------------------------------------------------------- */
28344 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28348 + SiMustAnyLock(sb);
28351 + if (au_opt_test(au_mntflags(sb), XINO)) {
28352 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28353 + seq_putc(seq, '\n');
28359 + * the lifetime of branch is independent from the entry under sysfs.
28360 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28363 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28364 + aufs_bindex_t bindex, int idx)
28367 + struct path path;
28368 + struct dentry *root;
28369 + struct au_branch *br;
28370 + au_br_perm_str_t perm;
28372 + AuDbg("b%d\n", bindex);
28375 + root = sb->s_root;
28376 + di_read_lock_parent(root, !AuLock_IR);
28377 + br = au_sbr(sb, bindex);
28380 + case AuBrSysfs_BR:
28381 + path.mnt = au_br_mnt(br);
28382 + path.dentry = au_h_dptr(root, bindex);
28383 + au_seq_path(seq, &path);
28384 + au_optstr_br_perm(&perm, br->br_perm);
28385 + err = seq_printf(seq, "=%s\n", perm.a);
28387 + case AuBrSysfs_BRID:
28388 + err = seq_printf(seq, "%d\n", br->br_id);
28391 + di_read_unlock(root, !AuLock_IR);
28398 +/* ---------------------------------------------------------------------- */
28400 +static struct seq_file *au_seq(char *p, ssize_t len)
28402 + struct seq_file *seq;
28404 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28406 + /* mutex_init(&seq.lock); */
28409 + return seq; /* success */
28412 + seq = ERR_PTR(-ENOMEM);
28416 +#define SysaufsBr_PREFIX "br"
28417 +#define SysaufsBrid_PREFIX "brid"
28419 +/* todo: file size may exceed PAGE_SIZE */
28420 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28426 + aufs_bindex_t bend;
28427 + struct au_sbinfo *sbinfo;
28428 + struct super_block *sb;
28429 + struct seq_file *seq;
28431 + struct attribute **cattr;
28433 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28434 + sb = sbinfo->si_sb;
28437 + * prevent a race condition between sysfs and aufs.
28438 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28439 + * prohibits maintaining the sysfs entries.
28440 + * hew we acquire read lock after sysfs_get_active_two().
28441 + * on the other hand, the remount process may maintain the sysfs/aufs
28442 + * entries after acquiring write lock.
28443 + * it can cause a deadlock.
28444 + * simply we gave up processing read here.
28447 + if (unlikely(!si_noflush_read_trylock(sb)))
28450 + seq = au_seq(buf, PAGE_SIZE);
28451 + err = PTR_ERR(seq);
28455 + name = (void *)attr->name;
28456 + cattr = sysaufs_si_attrs;
28458 + if (!strcmp(name, (*cattr)->name)) {
28459 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28466 + if (!strncmp(name, SysaufsBrid_PREFIX,
28467 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28468 + idx = AuBrSysfs_BRID;
28469 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28470 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28471 + sizeof(SysaufsBr_PREFIX) - 1)) {
28472 + idx = AuBrSysfs_BR;
28473 + name += sizeof(SysaufsBr_PREFIX) - 1;
28477 + err = kstrtol(name, 10, &l);
28479 + bend = au_sbend(sb);
28481 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28488 + err = seq->count;
28489 + /* sysfs limit */
28490 + if (unlikely(err == PAGE_SIZE))
28495 + si_read_unlock(sb);
28500 +/* ---------------------------------------------------------------------- */
28502 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28506 + aufs_bindex_t bindex, bend;
28509 + struct seq_file *seq;
28510 + struct au_branch *br;
28512 + si_read_lock(sb, AuLock_FLUSH);
28513 + bend = au_sbend(sb);
28519 + buf = (void *)__get_free_page(GFP_NOFS);
28520 + if (unlikely(!buf))
28523 + seq = au_seq(buf, PAGE_SIZE);
28524 + err = PTR_ERR(seq);
28528 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28529 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28530 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28531 + if (unlikely(err))
28534 + br = au_sbr(sb, bindex);
28535 + brid = br->br_id;
28536 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28537 + err = __put_user(brid, &arg->id);
28538 + if (unlikely(err))
28541 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28542 + err = __put_user(br->br_perm, &arg->perm);
28543 + if (unlikely(err))
28546 + au_seq_path(seq, &br->br_path);
28547 + err = seq_putc(seq, '\0');
28548 + if (!err && seq->count <= sz) {
28549 + err = copy_to_user(arg->path, seq->buf, seq->count);
28551 + if (unlikely(err))
28558 + if (unlikely(err))
28564 + free_page((unsigned long)buf);
28566 + si_read_unlock(sb);
28570 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28572 + return au_brinfo(file->f_dentry->d_sb, (void __user *)arg);
28575 +#ifdef CONFIG_COMPAT
28576 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
28578 + return au_brinfo(file->f_dentry->d_sb, compat_ptr(arg));
28582 +/* ---------------------------------------------------------------------- */
28584 +void sysaufs_br_init(struct au_branch *br)
28587 + struct au_brsysfs *br_sysfs;
28588 + struct attribute *attr;
28590 + br_sysfs = br->br_sysfs;
28591 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28592 + attr = &br_sysfs->attr;
28593 + sysfs_attr_init(attr);
28594 + attr->name = br_sysfs->name;
28595 + attr->mode = S_IRUGO;
28600 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28602 + struct au_branch *br;
28603 + struct kobject *kobj;
28604 + struct au_brsysfs *br_sysfs;
28606 + aufs_bindex_t bend;
28608 + dbgaufs_brs_del(sb, bindex);
28610 + if (!sysaufs_brs)
28613 + kobj = &au_sbi(sb)->si_kobj;
28614 + bend = au_sbend(sb);
28615 + for (; bindex <= bend; bindex++) {
28616 + br = au_sbr(sb, bindex);
28617 + br_sysfs = br->br_sysfs;
28618 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28619 + sysfs_remove_file(kobj, &br_sysfs->attr);
28625 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
28628 + aufs_bindex_t bend;
28629 + struct kobject *kobj;
28630 + struct au_branch *br;
28631 + struct au_brsysfs *br_sysfs;
28633 + dbgaufs_brs_add(sb, bindex);
28635 + if (!sysaufs_brs)
28638 + kobj = &au_sbi(sb)->si_kobj;
28639 + bend = au_sbend(sb);
28640 + for (; bindex <= bend; bindex++) {
28641 + br = au_sbr(sb, bindex);
28642 + br_sysfs = br->br_sysfs;
28643 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
28644 + SysaufsBr_PREFIX "%d", bindex);
28645 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
28646 + SysaufsBrid_PREFIX "%d", bindex);
28647 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28648 + err = sysfs_create_file(kobj, &br_sysfs->attr);
28649 + if (unlikely(err))
28650 + pr_warn("failed %s under sysfs(%d)\n",
28651 + br_sysfs->name, err);
28656 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
28657 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
28658 +++ linux/fs/aufs/sysrq.c 2015-01-25 13:00:38.634380408 +0100
28661 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28663 + * This program, aufs is free software; you can redistribute it and/or modify
28664 + * it under the terms of the GNU General Public License as published by
28665 + * the Free Software Foundation; either version 2 of the License, or
28666 + * (at your option) any later version.
28668 + * This program is distributed in the hope that it will be useful,
28669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28671 + * GNU General Public License for more details.
28673 + * You should have received a copy of the GNU General Public License
28674 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28678 + * magic sysrq hanlder
28681 +/* #include <linux/sysrq.h> */
28682 +#include <linux/writeback.h>
28685 +/* ---------------------------------------------------------------------- */
28687 +static void sysrq_sb(struct super_block *sb)
28690 + struct au_sbinfo *sbinfo;
28691 + struct file *file;
28692 + struct au_sphlhead *files;
28693 + struct au_finfo *finfo;
28695 + plevel = au_plevel;
28696 + au_plevel = KERN_WARNING;
28698 + /* since we define pr_fmt, call printk directly */
28699 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
28701 + sbinfo = au_sbi(sb);
28702 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
28703 + pr("superblock\n");
28707 + pr("root dentry\n");
28708 + au_dpri_dentry(sb->s_root);
28709 + pr("root inode\n");
28710 + au_dpri_inode(sb->s_root->d_inode);
28715 + int err, i, j, ndentry;
28716 + struct au_dcsub_pages dpages;
28717 + struct au_dpage *dpage;
28719 + err = au_dpages_init(&dpages, GFP_ATOMIC);
28720 + if (unlikely(err))
28722 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
28724 + for (i = 0; i < dpages.ndpage; i++) {
28725 + dpage = dpages.dpages + i;
28726 + ndentry = dpage->ndentry;
28727 + for (j = 0; j < ndentry; j++)
28728 + au_dpri_dentry(dpage->dentries[j]);
28730 + au_dpages_free(&dpages);
28738 + pr("isolated inode\n");
28739 + spin_lock(&inode_sb_list_lock);
28740 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
28741 + spin_lock(&i->i_lock);
28742 + if (1 || hlist_empty(&i->i_dentry))
28743 + au_dpri_inode(i);
28744 + spin_unlock(&i->i_lock);
28746 + spin_unlock(&inode_sb_list_lock);
28750 + files = &au_sbi(sb)->si_files;
28751 + spin_lock(&files->spin);
28752 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
28755 + file = finfo->fi_file;
28756 + mode = file_inode(file)->i_mode;
28757 + if (!special_file(mode))
28758 + au_dpri_file(file);
28760 + spin_unlock(&files->spin);
28764 + au_plevel = plevel;
28767 +/* ---------------------------------------------------------------------- */
28769 +/* module parameter */
28770 +static char *aufs_sysrq_key = "a";
28771 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
28772 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
28774 +static void au_sysrq(int key __maybe_unused)
28776 + struct au_sbinfo *sbinfo;
28779 + au_sbilist_lock();
28780 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
28781 + sysrq_sb(sbinfo->si_sb);
28782 + au_sbilist_unlock();
28786 +static struct sysrq_key_op au_sysrq_op = {
28787 + .handler = au_sysrq,
28788 + .help_msg = "Aufs",
28789 + .action_msg = "Aufs",
28790 + .enable_mask = SYSRQ_ENABLE_DUMP
28793 +/* ---------------------------------------------------------------------- */
28795 +int __init au_sysrq_init(void)
28801 + key = *aufs_sysrq_key;
28802 + if ('a' <= key && key <= 'z')
28803 + err = register_sysrq_key(key, &au_sysrq_op);
28804 + if (unlikely(err))
28805 + pr_err("err %d, sysrq=%c\n", err, key);
28809 +void au_sysrq_fin(void)
28813 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
28814 + if (unlikely(err))
28815 + pr_err("err %d (ignored)\n", err);
28817 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
28818 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
28819 +++ linux/fs/aufs/vdir.c 2015-01-25 13:00:38.634380408 +0100
28822 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28824 + * This program, aufs is free software; you can redistribute it and/or modify
28825 + * it under the terms of the GNU General Public License as published by
28826 + * the Free Software Foundation; either version 2 of the License, or
28827 + * (at your option) any later version.
28829 + * This program is distributed in the hope that it will be useful,
28830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28832 + * GNU General Public License for more details.
28834 + * You should have received a copy of the GNU General Public License
28835 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28839 + * virtual or vertical directory
28844 +static unsigned int calc_size(int nlen)
28846 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
28849 +static int set_deblk_end(union au_vdir_deblk_p *p,
28850 + union au_vdir_deblk_p *deblk_end)
28852 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
28853 + p->de->de_str.len = 0;
28857 + return -1; /* error */
28860 +/* returns true or false */
28861 +static int is_deblk_end(union au_vdir_deblk_p *p,
28862 + union au_vdir_deblk_p *deblk_end)
28864 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
28865 + return !p->de->de_str.len;
28869 +static unsigned char *last_deblk(struct au_vdir *vdir)
28871 + return vdir->vd_deblk[vdir->vd_nblk - 1];
28874 +/* ---------------------------------------------------------------------- */
28876 +/* estimate the apropriate size for name hash table */
28877 +unsigned int au_rdhash_est(loff_t sz)
28885 + if (sz < AUFS_RDHASH_DEF)
28886 + n = AUFS_RDHASH_DEF;
28887 + /* pr_info("n %u\n", n); */
28892 + * the allocated memory has to be freed by
28893 + * au_nhash_wh_free() or au_nhash_de_free().
28895 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
28897 + struct hlist_head *head;
28901 + sz = sizeof(*nhash->nh_head) * num_hash;
28902 + head = kmalloc(sz, gfp);
28904 + nhash->nh_num = num_hash;
28905 + nhash->nh_head = head;
28906 + for (u = 0; u < num_hash; u++)
28907 + INIT_HLIST_HEAD(head++);
28908 + return 0; /* success */
28914 +static void nhash_count(struct hlist_head *head)
28918 + struct hlist_node *pos;
28921 + hlist_for_each(pos, head)
28923 + pr_info("%lu\n", n);
28927 +static void au_nhash_wh_do_free(struct hlist_head *head)
28929 + struct au_vdir_wh *pos;
28930 + struct hlist_node *node;
28932 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
28936 +static void au_nhash_de_do_free(struct hlist_head *head)
28938 + struct au_vdir_dehstr *pos;
28939 + struct hlist_node *node;
28941 + hlist_for_each_entry_safe(pos, node, head, hash)
28942 + au_cache_free_vdir_dehstr(pos);
28945 +static void au_nhash_do_free(struct au_nhash *nhash,
28946 + void (*free)(struct hlist_head *head))
28949 + struct hlist_head *head;
28951 + n = nhash->nh_num;
28955 + head = nhash->nh_head;
28956 + while (n-- > 0) {
28957 + nhash_count(head);
28960 + kfree(nhash->nh_head);
28963 +void au_nhash_wh_free(struct au_nhash *whlist)
28965 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
28968 +static void au_nhash_de_free(struct au_nhash *delist)
28970 + au_nhash_do_free(delist, au_nhash_de_do_free);
28973 +/* ---------------------------------------------------------------------- */
28975 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
28979 + unsigned int u, n;
28980 + struct hlist_head *head;
28981 + struct au_vdir_wh *pos;
28984 + n = whlist->nh_num;
28985 + head = whlist->nh_head;
28986 + for (u = 0; u < n; u++, head++)
28987 + hlist_for_each_entry(pos, head, wh_hash)
28988 + if (pos->wh_bindex == btgt && ++num > limit)
28993 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
28994 + unsigned char *name,
28995 + unsigned int len)
28998 + /* const unsigned int magic_bit = 12; */
29000 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29005 + /* v = hash_long(v, magic_bit); */
29006 + v %= nhash->nh_num;
29007 + return nhash->nh_head + v;
29010 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29013 + return str->len == nlen && !memcmp(str->name, name, nlen);
29016 +/* returns found or not */
29017 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29019 + struct hlist_head *head;
29020 + struct au_vdir_wh *pos;
29021 + struct au_vdir_destr *str;
29023 + head = au_name_hash(whlist, name, nlen);
29024 + hlist_for_each_entry(pos, head, wh_hash) {
29025 + str = &pos->wh_str;
29026 + AuDbg("%.*s\n", str->len, str->name);
29027 + if (au_nhash_test_name(str, name, nlen))
29033 +/* returns found(true) or not */
29034 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29036 + struct hlist_head *head;
29037 + struct au_vdir_dehstr *pos;
29038 + struct au_vdir_destr *str;
29040 + head = au_name_hash(delist, name, nlen);
29041 + hlist_for_each_entry(pos, head, hash) {
29043 + AuDbg("%.*s\n", str->len, str->name);
29044 + if (au_nhash_test_name(str, name, nlen))
29050 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29051 + unsigned char d_type)
29053 +#ifdef CONFIG_AUFS_SHWH
29054 + wh->wh_ino = ino;
29055 + wh->wh_type = d_type;
29059 +/* ---------------------------------------------------------------------- */
29061 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29062 + unsigned int d_type, aufs_bindex_t bindex,
29063 + unsigned char shwh)
29066 + struct au_vdir_destr *str;
29067 + struct au_vdir_wh *wh;
29069 + AuDbg("%.*s\n", nlen, name);
29070 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29073 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29074 + if (unlikely(!wh))
29078 + wh->wh_bindex = bindex;
29080 + au_shwh_init_wh(wh, ino, d_type);
29081 + str = &wh->wh_str;
29083 + memcpy(str->name, name, nlen);
29084 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29091 +static int append_deblk(struct au_vdir *vdir)
29094 + unsigned long ul;
29095 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29096 + union au_vdir_deblk_p p, deblk_end;
29097 + unsigned char **o;
29100 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29102 + if (unlikely(!o))
29105 + vdir->vd_deblk = o;
29106 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29108 + ul = vdir->vd_nblk++;
29109 + vdir->vd_deblk[ul] = p.deblk;
29110 + vdir->vd_last.ul = ul;
29111 + vdir->vd_last.p.deblk = p.deblk;
29112 + deblk_end.deblk = p.deblk + deblk_sz;
29113 + err = set_deblk_end(&p, &deblk_end);
29120 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29121 + unsigned int d_type, struct au_nhash *delist)
29125 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29126 + union au_vdir_deblk_p p, *room, deblk_end;
29127 + struct au_vdir_dehstr *dehstr;
29129 + p.deblk = last_deblk(vdir);
29130 + deblk_end.deblk = p.deblk + deblk_sz;
29131 + room = &vdir->vd_last.p;
29132 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29133 + || !is_deblk_end(room, &deblk_end));
29135 + sz = calc_size(nlen);
29136 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29137 + err = append_deblk(vdir);
29138 + if (unlikely(err))
29141 + p.deblk = last_deblk(vdir);
29142 + deblk_end.deblk = p.deblk + deblk_sz;
29144 + AuDebugOn(room->deblk != p.deblk);
29148 + dehstr = au_cache_alloc_vdir_dehstr();
29149 + if (unlikely(!dehstr))
29152 + dehstr->str = &room->de->de_str;
29153 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29154 + room->de->de_ino = ino;
29155 + room->de->de_type = d_type;
29156 + room->de->de_str.len = nlen;
29157 + memcpy(room->de->de_str.name, name, nlen);
29160 + room->deblk += sz;
29161 + if (unlikely(set_deblk_end(room, &deblk_end)))
29162 + err = append_deblk(vdir);
29169 +/* ---------------------------------------------------------------------- */
29171 +void au_vdir_free(struct au_vdir *vdir)
29173 + unsigned char **deblk;
29175 + deblk = vdir->vd_deblk;
29176 + while (vdir->vd_nblk--)
29178 + kfree(vdir->vd_deblk);
29179 + au_cache_free_vdir(vdir);
29182 +static struct au_vdir *alloc_vdir(struct file *file)
29184 + struct au_vdir *vdir;
29185 + struct super_block *sb;
29188 + sb = file->f_dentry->d_sb;
29189 + SiMustAnyLock(sb);
29192 + vdir = au_cache_alloc_vdir();
29193 + if (unlikely(!vdir))
29196 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29197 + if (unlikely(!vdir->vd_deblk))
29200 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29201 + if (!vdir->vd_deblk_sz) {
29202 + /* estimate the apropriate size for deblk */
29203 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29204 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29206 + vdir->vd_nblk = 0;
29207 + vdir->vd_version = 0;
29208 + vdir->vd_jiffy = 0;
29209 + err = append_deblk(vdir);
29211 + return vdir; /* success */
29213 + kfree(vdir->vd_deblk);
29216 + au_cache_free_vdir(vdir);
29218 + vdir = ERR_PTR(err);
29222 +static int reinit_vdir(struct au_vdir *vdir)
29225 + union au_vdir_deblk_p p, deblk_end;
29227 + while (vdir->vd_nblk > 1) {
29228 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
29229 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
29232 + p.deblk = vdir->vd_deblk[0];
29233 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
29234 + err = set_deblk_end(&p, &deblk_end);
29235 + /* keep vd_dblk_sz */
29236 + vdir->vd_last.ul = 0;
29237 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29238 + vdir->vd_version = 0;
29239 + vdir->vd_jiffy = 0;
29244 +/* ---------------------------------------------------------------------- */
29246 +#define AuFillVdir_CALLED 1
29247 +#define AuFillVdir_WHABLE (1 << 1)
29248 +#define AuFillVdir_SHWH (1 << 2)
29249 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
29250 +#define au_fset_fillvdir(flags, name) \
29251 + do { (flags) |= AuFillVdir_##name; } while (0)
29252 +#define au_fclr_fillvdir(flags, name) \
29253 + do { (flags) &= ~AuFillVdir_##name; } while (0)
29255 +#ifndef CONFIG_AUFS_SHWH
29256 +#undef AuFillVdir_SHWH
29257 +#define AuFillVdir_SHWH 0
29260 +struct fillvdir_arg {
29261 + struct dir_context ctx;
29262 + struct file *file;
29263 + struct au_vdir *vdir;
29264 + struct au_nhash delist;
29265 + struct au_nhash whlist;
29266 + aufs_bindex_t bindex;
29267 + unsigned int flags;
29271 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29272 + loff_t offset __maybe_unused, u64 h_ino,
29273 + unsigned int d_type)
29275 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29276 + char *name = (void *)__name;
29277 + struct super_block *sb;
29279 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29282 + sb = arg->file->f_dentry->d_sb;
29283 + au_fset_fillvdir(arg->flags, CALLED);
29285 + if (nlen <= AUFS_WH_PFX_LEN
29286 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29287 + if (test_known(&arg->delist, name, nlen)
29288 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29289 + goto out; /* already exists or whiteouted */
29291 + sb = arg->file->f_dentry->d_sb;
29292 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29294 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29295 + d_type = DT_UNKNOWN;
29296 + arg->err = append_de(arg->vdir, name, nlen, ino,
29297 + d_type, &arg->delist);
29299 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29300 + name += AUFS_WH_PFX_LEN;
29301 + nlen -= AUFS_WH_PFX_LEN;
29302 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29303 + goto out; /* already whiteouted */
29306 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29309 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29310 + d_type = DT_UNKNOWN;
29311 + arg->err = au_nhash_append_wh
29312 + (&arg->whlist, name, nlen, ino, d_type,
29313 + arg->bindex, shwh);
29319 + arg->vdir->vd_jiffy = jiffies;
29321 + AuTraceErr(arg->err);
29325 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29326 + struct au_nhash *whlist, struct au_nhash *delist)
29328 +#ifdef CONFIG_AUFS_SHWH
29330 + unsigned int nh, u;
29331 + struct hlist_head *head;
29332 + struct au_vdir_wh *pos;
29333 + struct hlist_node *n;
29335 + struct au_vdir_destr *destr;
29337 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29340 + o = p = (void *)__get_free_page(GFP_NOFS);
29341 + if (unlikely(!p))
29345 + nh = whlist->nh_num;
29346 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29347 + p += AUFS_WH_PFX_LEN;
29348 + for (u = 0; u < nh; u++) {
29349 + head = whlist->nh_head + u;
29350 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29351 + destr = &pos->wh_str;
29352 + memcpy(p, destr->name, destr->len);
29353 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29354 + pos->wh_ino, pos->wh_type, delist);
29355 + if (unlikely(err))
29360 + free_page((unsigned long)o);
29370 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29373 + unsigned int rdhash;
29375 + aufs_bindex_t bend, bindex, bstart;
29376 + unsigned char shwh;
29377 + struct file *hf, *file;
29378 + struct super_block *sb;
29380 + file = arg->file;
29381 + sb = file->f_dentry->d_sb;
29382 + SiMustAnyLock(sb);
29384 + rdhash = au_sbi(sb)->si_rdhash;
29386 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29387 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29388 + if (unlikely(err))
29390 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29391 + if (unlikely(err))
29397 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29399 + au_fset_fillvdir(arg->flags, SHWH);
29401 + bstart = au_fbstart(file);
29402 + bend = au_fbend_dir(file);
29403 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29404 + hf = au_hf_dir(file, bindex);
29408 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29410 + if (unlikely(offset))
29413 + arg->bindex = bindex;
29414 + au_fclr_fillvdir(arg->flags, WHABLE);
29416 + || (bindex != bend
29417 + && au_br_whable(au_sbr_perm(sb, bindex))))
29418 + au_fset_fillvdir(arg->flags, WHABLE);
29421 + au_fclr_fillvdir(arg->flags, CALLED);
29423 + err = vfsub_iterate_dir(hf, &arg->ctx);
29426 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29429 + * dir_relax() may be good for concurrency, but aufs should not
29430 + * use it since it will cause a lockdep problem.
29434 + if (!err && shwh)
29435 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29437 + au_nhash_wh_free(&arg->whlist);
29440 + au_nhash_de_free(&arg->delist);
29445 +static int read_vdir(struct file *file, int may_read)
29448 + unsigned long expire;
29449 + unsigned char do_read;
29450 + struct fillvdir_arg arg = {
29452 + .actor = au_diractor(fillvdir)
29455 + struct inode *inode;
29456 + struct au_vdir *vdir, *allocated;
29459 + inode = file_inode(file);
29460 + IMustLock(inode);
29461 + SiMustAnyLock(inode->i_sb);
29463 + allocated = NULL;
29465 + expire = au_sbi(inode->i_sb)->si_rdcache;
29466 + vdir = au_ivdir(inode);
29469 + vdir = alloc_vdir(file);
29470 + err = PTR_ERR(vdir);
29471 + if (IS_ERR(vdir))
29474 + allocated = vdir;
29475 + } else if (may_read
29476 + && (inode->i_version != vdir->vd_version
29477 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29479 + err = reinit_vdir(vdir);
29480 + if (unlikely(err))
29485 + return 0; /* success */
29489 + err = au_do_read_vdir(&arg);
29491 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29492 + vdir->vd_version = inode->i_version;
29493 + vdir->vd_last.ul = 0;
29494 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29496 + au_set_ivdir(inode, allocated);
29497 + } else if (allocated)
29498 + au_vdir_free(allocated);
29504 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29507 + unsigned long ul, n;
29508 + const unsigned int deblk_sz = src->vd_deblk_sz;
29510 + AuDebugOn(tgt->vd_nblk != 1);
29513 + if (tgt->vd_nblk < src->vd_nblk) {
29514 + unsigned char **p;
29516 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29518 + if (unlikely(!p))
29520 + tgt->vd_deblk = p;
29523 + if (tgt->vd_deblk_sz != deblk_sz) {
29524 + unsigned char *p;
29526 + tgt->vd_deblk_sz = deblk_sz;
29527 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29528 + if (unlikely(!p))
29530 + tgt->vd_deblk[0] = p;
29532 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29533 + tgt->vd_version = src->vd_version;
29534 + tgt->vd_jiffy = src->vd_jiffy;
29536 + n = src->vd_nblk;
29537 + for (ul = 1; ul < n; ul++) {
29538 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29540 + if (unlikely(!tgt->vd_deblk[ul]))
29544 + tgt->vd_nblk = n;
29545 + tgt->vd_last.ul = tgt->vd_last.ul;
29546 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29547 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29548 + - src->vd_deblk[src->vd_last.ul];
29550 + return 0; /* success */
29553 + rerr = reinit_vdir(tgt);
29558 +int au_vdir_init(struct file *file)
29561 + struct inode *inode;
29562 + struct au_vdir *vdir_cache, *allocated;
29564 + /* test file->f_pos here instead of ctx->pos */
29565 + err = read_vdir(file, !file->f_pos);
29566 + if (unlikely(err))
29569 + allocated = NULL;
29570 + vdir_cache = au_fvdir_cache(file);
29571 + if (!vdir_cache) {
29572 + vdir_cache = alloc_vdir(file);
29573 + err = PTR_ERR(vdir_cache);
29574 + if (IS_ERR(vdir_cache))
29576 + allocated = vdir_cache;
29577 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29578 + /* test file->f_pos here instead of ctx->pos */
29579 + err = reinit_vdir(vdir_cache);
29580 + if (unlikely(err))
29583 + return 0; /* success */
29585 + inode = file_inode(file);
29586 + err = copy_vdir(vdir_cache, au_ivdir(inode));
29588 + file->f_version = inode->i_version;
29590 + au_set_fvdir_cache(file, allocated);
29591 + } else if (allocated)
29592 + au_vdir_free(allocated);
29598 +static loff_t calc_offset(struct au_vdir *vdir)
29601 + union au_vdir_deblk_p p;
29603 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29604 + offset = vdir->vd_last.p.deblk - p.deblk;
29605 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
29609 +/* returns true or false */
29610 +static int seek_vdir(struct file *file, struct dir_context *ctx)
29613 + unsigned int deblk_sz;
29614 + unsigned long ul, n;
29616 + union au_vdir_deblk_p p, deblk_end;
29617 + struct au_vdir *vdir_cache;
29620 + vdir_cache = au_fvdir_cache(file);
29621 + offset = calc_offset(vdir_cache);
29622 + AuDbg("offset %lld\n", offset);
29623 + if (ctx->pos == offset)
29626 + vdir_cache->vd_last.ul = 0;
29627 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
29632 + deblk_sz = vdir_cache->vd_deblk_sz;
29633 + ul = div64_u64(ctx->pos, deblk_sz);
29634 + AuDbg("ul %lu\n", ul);
29635 + if (ul >= vdir_cache->vd_nblk)
29638 + n = vdir_cache->vd_nblk;
29639 + for (; ul < n; ul++) {
29640 + p.deblk = vdir_cache->vd_deblk[ul];
29641 + deblk_end.deblk = p.deblk + deblk_sz;
29643 + offset *= deblk_sz;
29644 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
29647 + l = calc_size(p.de->de_str.len);
29651 + if (!is_deblk_end(&p, &deblk_end)) {
29653 + vdir_cache->vd_last.ul = ul;
29654 + vdir_cache->vd_last.p = p;
29661 + AuTraceErr(!valid);
29665 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
29667 + unsigned int l, deblk_sz;
29668 + union au_vdir_deblk_p deblk_end;
29669 + struct au_vdir *vdir_cache;
29670 + struct au_vdir_de *de;
29672 + vdir_cache = au_fvdir_cache(file);
29673 + if (!seek_vdir(file, ctx))
29676 + deblk_sz = vdir_cache->vd_deblk_sz;
29678 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29679 + deblk_end.deblk += deblk_sz;
29680 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
29681 + de = vdir_cache->vd_last.p.de;
29682 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
29683 + de->de_str.len, de->de_str.name, ctx->pos,
29684 + (unsigned long)de->de_ino, de->de_type);
29685 + if (unlikely(!dir_emit(ctx, de->de_str.name,
29686 + de->de_str.len, de->de_ino,
29688 + /* todo: ignore the error caused by udba? */
29689 + /* return err; */
29693 + l = calc_size(de->de_str.len);
29694 + vdir_cache->vd_last.p.deblk += l;
29697 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
29698 + vdir_cache->vd_last.ul++;
29699 + vdir_cache->vd_last.p.deblk
29700 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29701 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
29710 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
29711 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
29712 +++ linux/fs/aufs/vfsub.c 2015-01-25 13:00:38.634380408 +0100
29715 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29717 + * This program, aufs is free software; you can redistribute it and/or modify
29718 + * it under the terms of the GNU General Public License as published by
29719 + * the Free Software Foundation; either version 2 of the License, or
29720 + * (at your option) any later version.
29722 + * This program is distributed in the hope that it will be useful,
29723 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29724 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29725 + * GNU General Public License for more details.
29727 + * You should have received a copy of the GNU General Public License
29728 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29732 + * sub-routines for VFS
29735 +#include <linux/ima.h>
29736 +#include <linux/namei.h>
29737 +#include <linux/security.h>
29738 +#include <linux/splice.h>
29741 +int vfsub_update_h_iattr(struct path *h_path, int *did)
29745 + struct super_block *h_sb;
29747 + /* for remote fs, leave work for its getattr or d_revalidate */
29748 + /* for bad i_attr fs, handle them in aufs_getattr() */
29749 + /* still some fs may acquire i_mutex. we need to skip them */
29753 + h_sb = h_path->dentry->d_sb;
29754 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
29756 + err = vfs_getattr(h_path, &st);
29761 +/* ---------------------------------------------------------------------- */
29763 +struct file *vfsub_dentry_open(struct path *path, int flags)
29765 + struct file *file;
29767 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
29769 + if (!IS_ERR_OR_NULL(file)
29770 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
29771 + i_readcount_inc(path->dentry->d_inode);
29776 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
29778 + struct file *file;
29781 + file = filp_open(path,
29782 + oflags /* | __FMODE_NONOTIFY */,
29785 + if (IS_ERR(file))
29787 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29793 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
29797 + err = kern_path(name, flags, path);
29798 + if (!err && path->dentry->d_inode)
29799 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
29803 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
29806 + struct path path = {
29810 + /* VFS checks it too, but by WARN_ON_ONCE() */
29811 + IMustLock(parent->d_inode);
29813 + path.dentry = lookup_one_len(name, parent, len);
29814 + if (IS_ERR(path.dentry))
29816 + if (path.dentry->d_inode)
29817 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
29820 + AuTraceErrPtr(path.dentry);
29821 + return path.dentry;
29824 +void vfsub_call_lkup_one(void *args)
29826 + struct vfsub_lkup_one_args *a = args;
29827 + *a->errp = vfsub_lkup_one(a->name, a->parent);
29830 +/* ---------------------------------------------------------------------- */
29832 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
29833 + struct dentry *d2, struct au_hinode *hdir2)
29835 + struct dentry *d;
29838 + d = lock_rename(d1, d2);
29840 + au_hn_suspend(hdir1);
29841 + if (hdir1 != hdir2)
29842 + au_hn_suspend(hdir2);
29847 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
29848 + struct dentry *d2, struct au_hinode *hdir2)
29850 + au_hn_resume(hdir1);
29851 + if (hdir1 != hdir2)
29852 + au_hn_resume(hdir2);
29854 + unlock_rename(d1, d2);
29858 +/* ---------------------------------------------------------------------- */
29860 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
29863 + struct dentry *d;
29867 + d = path->dentry;
29868 + path->dentry = d->d_parent;
29869 + err = security_path_mknod(path, d, mode, 0);
29870 + path->dentry = d;
29871 + if (unlikely(err))
29875 + err = vfs_create(dir, path->dentry, mode, want_excl);
29878 + struct path tmp = *path;
29881 + vfsub_update_h_iattr(&tmp, &did);
29883 + tmp.dentry = path->dentry->d_parent;
29884 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29893 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
29896 + struct dentry *d;
29900 + d = path->dentry;
29901 + path->dentry = d->d_parent;
29902 + err = security_path_symlink(path, d, symname);
29903 + path->dentry = d;
29904 + if (unlikely(err))
29908 + err = vfs_symlink(dir, path->dentry, symname);
29911 + struct path tmp = *path;
29914 + vfsub_update_h_iattr(&tmp, &did);
29916 + tmp.dentry = path->dentry->d_parent;
29917 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29926 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
29929 + struct dentry *d;
29933 + d = path->dentry;
29934 + path->dentry = d->d_parent;
29935 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
29936 + path->dentry = d;
29937 + if (unlikely(err))
29941 + err = vfs_mknod(dir, path->dentry, mode, dev);
29944 + struct path tmp = *path;
29947 + vfsub_update_h_iattr(&tmp, &did);
29949 + tmp.dentry = path->dentry->d_parent;
29950 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29959 +static int au_test_nlink(struct inode *inode)
29961 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
29963 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
29964 + || inode->i_nlink < link_max)
29969 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
29970 + struct inode **delegated_inode)
29973 + struct dentry *d;
29977 + err = au_test_nlink(src_dentry->d_inode);
29978 + if (unlikely(err))
29981 + /* we don't call may_linkat() */
29982 + d = path->dentry;
29983 + path->dentry = d->d_parent;
29984 + err = security_path_link(src_dentry, path, d);
29985 + path->dentry = d;
29986 + if (unlikely(err))
29990 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
29993 + struct path tmp = *path;
29996 + /* fuse has different memory inode for the same inumber */
29997 + vfsub_update_h_iattr(&tmp, &did);
29999 + tmp.dentry = path->dentry->d_parent;
30000 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30001 + tmp.dentry = src_dentry;
30002 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30011 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30012 + struct inode *dir, struct path *path,
30013 + struct inode **delegated_inode)
30016 + struct path tmp = {
30019 + struct dentry *d;
30022 + IMustLock(src_dir);
30024 + d = path->dentry;
30025 + path->dentry = d->d_parent;
30026 + tmp.dentry = src_dentry->d_parent;
30027 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30028 + path->dentry = d;
30029 + if (unlikely(err))
30033 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30034 + delegated_inode, /*flags*/0);
30039 + tmp.dentry = d->d_parent;
30040 + vfsub_update_h_iattr(&tmp, &did);
30042 + tmp.dentry = src_dentry;
30043 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30044 + tmp.dentry = src_dentry->d_parent;
30045 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30054 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30057 + struct dentry *d;
30061 + d = path->dentry;
30062 + path->dentry = d->d_parent;
30063 + err = security_path_mkdir(path, d, mode);
30064 + path->dentry = d;
30065 + if (unlikely(err))
30069 + err = vfs_mkdir(dir, path->dentry, mode);
30072 + struct path tmp = *path;
30075 + vfsub_update_h_iattr(&tmp, &did);
30077 + tmp.dentry = path->dentry->d_parent;
30078 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30087 +int vfsub_rmdir(struct inode *dir, struct path *path)
30090 + struct dentry *d;
30094 + d = path->dentry;
30095 + path->dentry = d->d_parent;
30096 + err = security_path_rmdir(path, d);
30097 + path->dentry = d;
30098 + if (unlikely(err))
30102 + err = vfs_rmdir(dir, path->dentry);
30105 + struct path tmp = {
30106 + .dentry = path->dentry->d_parent,
30110 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30117 +/* ---------------------------------------------------------------------- */
30119 +/* todo: support mmap_sem? */
30120 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30126 + err = vfs_read(file, ubuf, count, ppos);
30129 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30133 +/* todo: kernel_read()? */
30134 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30138 + mm_segment_t oldfs;
30145 + oldfs = get_fs();
30146 + set_fs(KERNEL_DS);
30147 + err = vfsub_read_u(file, buf.u, count, ppos);
30152 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30158 + err = vfs_write(file, ubuf, count, ppos);
30161 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30165 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
30168 + mm_segment_t oldfs;
30171 + const char __user *u;
30175 + oldfs = get_fs();
30176 + set_fs(KERNEL_DS);
30177 + err = vfsub_write_u(file, buf.u, count, ppos);
30182 +int vfsub_flush(struct file *file, fl_owner_t id)
30187 + if (file->f_op->flush) {
30188 + if (!au_test_nfs(file->f_dentry->d_sb))
30189 + err = file->f_op->flush(file, id);
30192 + err = file->f_op->flush(file, id);
30196 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30202 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30206 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30209 + err = iterate_dir(file, ctx);
30212 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30216 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30217 + struct pipe_inode_info *pipe, size_t len,
30218 + unsigned int flags)
30223 + err = do_splice_to(in, ppos, pipe, len, flags);
30225 + file_accessed(in);
30227 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30231 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30232 + loff_t *ppos, size_t len, unsigned int flags)
30237 + err = do_splice_from(pipe, out, ppos, len, flags);
30240 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30244 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30248 + /* file can be NULL */
30250 + err = vfs_fsync(file, datasync);
30254 + AuDebugOn(!file);
30255 + path = &file->f_path;
30257 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30262 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30263 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30264 + struct file *h_file)
30267 + struct inode *h_inode;
30268 + struct super_block *h_sb;
30271 + err = vfsub_truncate(h_path, length);
30275 + h_inode = h_path->dentry->d_inode;
30276 + h_sb = h_inode->i_sb;
30278 + sb_start_write(h_sb);
30280 + err = locks_verify_truncate(h_inode, h_file, length);
30282 + err = security_path_truncate(h_path);
30285 + err = do_truncate(h_path->dentry, length, attr, h_file);
30289 + sb_end_write(h_sb);
30296 +/* ---------------------------------------------------------------------- */
30298 +struct au_vfsub_mkdir_args {
30300 + struct inode *dir;
30301 + struct path *path;
30305 +static void au_call_vfsub_mkdir(void *args)
30307 + struct au_vfsub_mkdir_args *a = args;
30308 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30311 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30313 + int err, do_sio, wkq_err;
30315 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30318 + err = vfsub_mkdir(dir, path, mode);
30321 + struct au_vfsub_mkdir_args args = {
30327 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30328 + if (unlikely(wkq_err))
30335 +struct au_vfsub_rmdir_args {
30337 + struct inode *dir;
30338 + struct path *path;
30341 +static void au_call_vfsub_rmdir(void *args)
30343 + struct au_vfsub_rmdir_args *a = args;
30344 + *a->errp = vfsub_rmdir(a->dir, a->path);
30347 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30349 + int err, do_sio, wkq_err;
30351 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30354 + err = vfsub_rmdir(dir, path);
30357 + struct au_vfsub_rmdir_args args = {
30362 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30363 + if (unlikely(wkq_err))
30370 +/* ---------------------------------------------------------------------- */
30372 +struct notify_change_args {
30374 + struct path *path;
30375 + struct iattr *ia;
30376 + struct inode **delegated_inode;
30379 +static void call_notify_change(void *args)
30381 + struct notify_change_args *a = args;
30382 + struct inode *h_inode;
30384 + h_inode = a->path->dentry->d_inode;
30385 + IMustLock(h_inode);
30387 + *a->errp = -EPERM;
30388 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30390 + *a->errp = notify_change(a->path->dentry, a->ia,
30391 + a->delegated_inode);
30394 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30396 + AuTraceErr(*a->errp);
30399 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30400 + struct inode **delegated_inode)
30403 + struct notify_change_args args = {
30407 + .delegated_inode = delegated_inode
30410 + call_notify_change(&args);
30415 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30416 + struct inode **delegated_inode)
30418 + int err, wkq_err;
30419 + struct notify_change_args args = {
30423 + .delegated_inode = delegated_inode
30426 + wkq_err = au_wkq_wait(call_notify_change, &args);
30427 + if (unlikely(wkq_err))
30433 +/* ---------------------------------------------------------------------- */
30435 +struct unlink_args {
30437 + struct inode *dir;
30438 + struct path *path;
30439 + struct inode **delegated_inode;
30442 +static void call_unlink(void *args)
30444 + struct unlink_args *a = args;
30445 + struct dentry *d = a->path->dentry;
30446 + struct inode *h_inode;
30447 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30448 + && au_dcount(d) == 1);
30450 + IMustLock(a->dir);
30452 + a->path->dentry = d->d_parent;
30453 + *a->errp = security_path_unlink(a->path, d);
30454 + a->path->dentry = d;
30455 + if (unlikely(*a->errp))
30458 + if (!stop_sillyrename)
30460 + h_inode = d->d_inode;
30465 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30468 + struct path tmp = {
30469 + .dentry = d->d_parent,
30470 + .mnt = a->path->mnt
30472 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30475 + if (!stop_sillyrename)
30480 + AuTraceErr(*a->errp);
30484 + * @dir: must be locked.
30485 + * @dentry: target dentry.
30487 +int vfsub_unlink(struct inode *dir, struct path *path,
30488 + struct inode **delegated_inode, int force)
30491 + struct unlink_args args = {
30495 + .delegated_inode = delegated_inode
30499 + call_unlink(&args);
30503 + wkq_err = au_wkq_wait(call_unlink, &args);
30504 + if (unlikely(wkq_err))
30510 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
30511 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
30512 +++ linux/fs/aufs/vfsub.h 2015-01-25 13:00:38.634380408 +0100
30515 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30517 + * This program, aufs is free software; you can redistribute it and/or modify
30518 + * it under the terms of the GNU General Public License as published by
30519 + * the Free Software Foundation; either version 2 of the License, or
30520 + * (at your option) any later version.
30522 + * This program is distributed in the hope that it will be useful,
30523 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30524 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30525 + * GNU General Public License for more details.
30527 + * You should have received a copy of the GNU General Public License
30528 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30532 + * sub-routines for VFS
30535 +#ifndef __AUFS_VFSUB_H__
30536 +#define __AUFS_VFSUB_H__
30540 +#include <linux/fs.h>
30541 +#include <linux/lglock.h>
30542 +#include <linux/mount.h>
30543 +#include <linux/xattr.h>
30544 +#include "debug.h"
30546 +/* copied from linux/fs/internal.h */
30547 +/* todo: BAD approach!! */
30548 +extern void __mnt_drop_write(struct vfsmount *);
30549 +extern spinlock_t inode_sb_list_lock;
30551 +/* ---------------------------------------------------------------------- */
30553 +/* lock subclass for lower inode */
30554 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
30555 +/* reduce? gave up. */
30557 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
30558 + AuLsc_I_PARENT, /* lower inode, parent first */
30559 + AuLsc_I_PARENT2, /* copyup dirs */
30560 + AuLsc_I_PARENT3, /* copyup wh */
30566 +/* to debug easier, do not make them inlined functions */
30567 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
30568 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
30570 +/* ---------------------------------------------------------------------- */
30572 +static inline void vfsub_drop_nlink(struct inode *inode)
30574 + AuDebugOn(!inode->i_nlink);
30575 + drop_nlink(inode);
30578 +static inline void vfsub_dead_dir(struct inode *inode)
30580 + AuDebugOn(!S_ISDIR(inode->i_mode));
30581 + inode->i_flags |= S_DEAD;
30582 + clear_nlink(inode);
30585 +static inline int vfsub_native_ro(struct inode *inode)
30587 + return (inode->i_sb->s_flags & MS_RDONLY)
30588 + || IS_RDONLY(inode)
30589 + /* || IS_APPEND(inode) */
30590 + || IS_IMMUTABLE(inode);
30593 +/* ---------------------------------------------------------------------- */
30595 +int vfsub_update_h_iattr(struct path *h_path, int *did);
30596 +struct file *vfsub_dentry_open(struct path *path, int flags);
30597 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
30598 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
30600 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30603 +struct vfsub_lkup_one_args {
30604 + struct dentry **errp;
30605 + struct qstr *name;
30606 + struct dentry *parent;
30609 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
30610 + struct dentry *parent)
30612 + return vfsub_lookup_one_len(name->name, parent, name->len);
30615 +void vfsub_call_lkup_one(void *args);
30617 +/* ---------------------------------------------------------------------- */
30619 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
30624 + err = mnt_want_write(mnt);
30629 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
30632 + mnt_drop_write(mnt);
30636 +static inline void vfsub_mnt_drop_write_file(struct file *file)
30639 + mnt_drop_write_file(file);
30643 +/* ---------------------------------------------------------------------- */
30646 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30647 + struct dentry *d2, struct au_hinode *hdir2);
30648 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30649 + struct dentry *d2, struct au_hinode *hdir2);
30651 +int vfsub_create(struct inode *dir, struct path *path, int mode,
30653 +int vfsub_symlink(struct inode *dir, struct path *path,
30654 + const char *symname);
30655 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
30656 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
30657 + struct path *path, struct inode **delegated_inode);
30658 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
30659 + struct inode *hdir, struct path *path,
30660 + struct inode **delegated_inode);
30661 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
30662 +int vfsub_rmdir(struct inode *dir, struct path *path);
30664 +/* ---------------------------------------------------------------------- */
30666 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30668 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30670 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30672 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
30674 +int vfsub_flush(struct file *file, fl_owner_t id);
30675 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
30677 +/* just for type-check */
30678 +static inline filldir_t au_diractor(int (*func)(struct dir_context *,
30679 + const char *, int, loff_t, u64,
30682 + return (filldir_t)func;
30686 +static inline loff_t vfsub_f_size_read(struct file *file)
30688 + return i_size_read(file_inode(file));
30691 +static inline unsigned int vfsub_file_flags(struct file *file)
30693 + unsigned int flags;
30695 + spin_lock(&file->f_lock);
30696 + flags = file->f_flags;
30697 + spin_unlock(&file->f_lock);
30702 +static inline void vfsub_file_accessed(struct file *h_file)
30704 + file_accessed(h_file);
30705 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
30708 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
30709 + struct dentry *h_dentry)
30711 + struct path h_path = {
30712 + .dentry = h_dentry,
30715 + touch_atime(&h_path);
30716 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
30719 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
30722 + return update_time(h_inode, ts, flags);
30723 + /* no vfsub_update_h_iattr() since we don't have struct path */
30726 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30727 + struct pipe_inode_info *pipe, size_t len,
30728 + unsigned int flags);
30729 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30730 + loff_t *ppos, size_t len, unsigned int flags);
30732 +static inline long vfsub_truncate(struct path *path, loff_t length)
30737 + err = vfs_truncate(path, length);
30742 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30743 + struct file *h_file);
30744 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
30746 +/* ---------------------------------------------------------------------- */
30748 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
30753 + err = vfs_llseek(file, offset, origin);
30758 +/* ---------------------------------------------------------------------- */
30760 +/* dirty workaround for strict type of fmode_t */
30766 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
30768 + union vfsub_fmu u = {
30772 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
30777 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
30779 + union vfsub_fmu u = {
30786 +/* ---------------------------------------------------------------------- */
30788 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
30789 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
30790 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30791 + struct inode **delegated_inode);
30792 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30793 + struct inode **delegated_inode);
30794 +int vfsub_unlink(struct inode *dir, struct path *path,
30795 + struct inode **delegated_inode, int force);
30797 +/* ---------------------------------------------------------------------- */
30799 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
30800 + const void *value, size_t size, int flags)
30805 + err = vfs_setxattr(dentry, name, value, size, flags);
30811 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
30816 + err = vfs_removexattr(dentry, name);
30822 +#endif /* __KERNEL__ */
30823 +#endif /* __AUFS_VFSUB_H__ */
30824 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
30825 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
30826 +++ linux/fs/aufs/wbr_policy.c 2015-01-25 13:00:38.634380408 +0100
30829 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30831 + * This program, aufs is free software; you can redistribute it and/or modify
30832 + * it under the terms of the GNU General Public License as published by
30833 + * the Free Software Foundation; either version 2 of the License, or
30834 + * (at your option) any later version.
30836 + * This program is distributed in the hope that it will be useful,
30837 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30838 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30839 + * GNU General Public License for more details.
30841 + * You should have received a copy of the GNU General Public License
30842 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30846 + * policies for selecting one among multiple writable branches
30849 +#include <linux/statfs.h>
30852 +/* subset of cpup_attr() */
30853 +static noinline_for_stack
30854 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
30858 + struct inode *h_isrc;
30860 + h_isrc = h_src->d_inode;
30861 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
30862 + ia.ia_mode = h_isrc->i_mode;
30863 + ia.ia_uid = h_isrc->i_uid;
30864 + ia.ia_gid = h_isrc->i_gid;
30865 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
30866 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
30867 + /* no delegation since it is just created */
30868 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30870 + /* is this nfs only? */
30871 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
30872 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
30873 + ia.ia_mode = h_isrc->i_mode;
30874 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30880 +#define AuCpdown_PARENT_OPQ 1
30881 +#define AuCpdown_WHED (1 << 1)
30882 +#define AuCpdown_MADE_DIR (1 << 2)
30883 +#define AuCpdown_DIROPQ (1 << 3)
30884 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
30885 +#define au_fset_cpdown(flags, name) \
30886 + do { (flags) |= AuCpdown_##name; } while (0)
30887 +#define au_fclr_cpdown(flags, name) \
30888 + do { (flags) &= ~AuCpdown_##name; } while (0)
30890 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
30891 + unsigned int *flags)
30894 + struct dentry *opq_dentry;
30896 + opq_dentry = au_diropq_create(dentry, bdst);
30897 + err = PTR_ERR(opq_dentry);
30898 + if (IS_ERR(opq_dentry))
30900 + dput(opq_dentry);
30901 + au_fset_cpdown(*flags, DIROPQ);
30907 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
30908 + struct inode *dir, aufs_bindex_t bdst)
30911 + struct path h_path;
30912 + struct au_branch *br;
30914 + br = au_sbr(dentry->d_sb, bdst);
30915 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
30916 + err = PTR_ERR(h_path.dentry);
30917 + if (IS_ERR(h_path.dentry))
30921 + if (h_path.dentry->d_inode) {
30922 + h_path.mnt = au_br_mnt(br);
30923 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
30926 + dput(h_path.dentry);
30932 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
30933 + struct au_pin *pin,
30934 + struct dentry *h_parent, void *arg)
30937 + aufs_bindex_t bopq, bstart;
30938 + struct path h_path;
30939 + struct dentry *parent;
30940 + struct inode *h_dir, *h_inode, *inode, *dir;
30941 + unsigned int *flags = arg;
30943 + bstart = au_dbstart(dentry);
30944 + /* dentry is di-locked */
30945 + parent = dget_parent(dentry);
30946 + dir = parent->d_inode;
30947 + h_dir = h_parent->d_inode;
30948 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
30949 + IMustLock(h_dir);
30951 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
30952 + if (unlikely(err < 0))
30954 + h_path.dentry = au_h_dptr(dentry, bdst);
30955 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
30956 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
30957 + S_IRWXU | S_IRUGO | S_IXUGO);
30958 + if (unlikely(err))
30960 + au_fset_cpdown(*flags, MADE_DIR);
30962 + bopq = au_dbdiropq(dentry);
30963 + au_fclr_cpdown(*flags, WHED);
30964 + au_fclr_cpdown(*flags, DIROPQ);
30965 + if (au_dbwh(dentry) == bdst)
30966 + au_fset_cpdown(*flags, WHED);
30967 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
30968 + au_fset_cpdown(*flags, PARENT_OPQ);
30969 + h_inode = h_path.dentry->d_inode;
30970 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
30971 + if (au_ftest_cpdown(*flags, WHED)) {
30972 + err = au_cpdown_dir_opq(dentry, bdst, flags);
30973 + if (unlikely(err)) {
30974 + mutex_unlock(&h_inode->i_mutex);
30979 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
30980 + mutex_unlock(&h_inode->i_mutex);
30981 + if (unlikely(err))
30984 + if (au_ftest_cpdown(*flags, WHED)) {
30985 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
30986 + if (unlikely(err))
30990 + inode = dentry->d_inode;
30991 + if (au_ibend(inode) < bdst)
30992 + au_set_ibend(inode, bdst);
30993 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
30994 + au_hi_flags(inode, /*isdir*/1));
30995 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
30996 + goto out; /* success */
31000 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31001 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31002 + rerr = au_diropq_remove(dentry, bdst);
31003 + mutex_unlock(&h_inode->i_mutex);
31004 + if (unlikely(rerr)) {
31005 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31006 + dentry, bdst, rerr);
31012 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31013 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31014 + if (unlikely(rerr)) {
31015 + AuIOErr("failed removing %pd b%d (%d)\n",
31016 + dentry, bdst, rerr);
31021 + au_set_h_dptr(dentry, bdst, NULL);
31022 + if (au_dbend(dentry) == bdst)
31023 + au_update_dbend(dentry);
31029 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31032 + unsigned int flags;
31035 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31040 +/* ---------------------------------------------------------------------- */
31042 +/* policies for create */
31044 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31046 + int err, i, j, ndentry;
31047 + aufs_bindex_t bopq;
31048 + struct au_dcsub_pages dpages;
31049 + struct au_dpage *dpage;
31050 + struct dentry **dentries, *parent, *d;
31052 + err = au_dpages_init(&dpages, GFP_NOFS);
31053 + if (unlikely(err))
31055 + parent = dget_parent(dentry);
31056 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31057 + if (unlikely(err))
31061 + for (i = 0; i < dpages.ndpage; i++) {
31062 + dpage = dpages.dpages + i;
31063 + dentries = dpage->dentries;
31064 + ndentry = dpage->ndentry;
31065 + for (j = 0; j < ndentry; j++) {
31067 + di_read_lock_parent2(d, !AuLock_IR);
31068 + bopq = au_dbdiropq(d);
31069 + di_read_unlock(d, !AuLock_IR);
31070 + if (bopq >= 0 && bopq < err)
31077 + au_dpages_free(&dpages);
31082 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31084 + for (; bindex >= 0; bindex--)
31085 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31090 +/* top down parent */
31091 +static int au_wbr_create_tdp(struct dentry *dentry,
31092 + unsigned int flags __maybe_unused)
31095 + aufs_bindex_t bstart, bindex;
31096 + struct super_block *sb;
31097 + struct dentry *parent, *h_parent;
31099 + sb = dentry->d_sb;
31100 + bstart = au_dbstart(dentry);
31102 + if (!au_br_rdonly(au_sbr(sb, bstart)))
31106 + parent = dget_parent(dentry);
31107 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
31108 + h_parent = au_h_dptr(parent, bindex);
31109 + if (!h_parent || !h_parent->d_inode)
31112 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31119 + /* bottom up here */
31120 + if (unlikely(err < 0)) {
31121 + err = au_wbr_bu(sb, bstart - 1);
31123 + err = au_wbr_nonopq(dentry, err);
31127 + AuDbg("b%d\n", err);
31131 +/* ---------------------------------------------------------------------- */
31133 +/* an exception for the policy other than tdp */
31134 +static int au_wbr_create_exp(struct dentry *dentry)
31137 + aufs_bindex_t bwh, bdiropq;
31138 + struct dentry *parent;
31141 + bwh = au_dbwh(dentry);
31142 + parent = dget_parent(dentry);
31143 + bdiropq = au_dbdiropq(parent);
31145 + if (bdiropq >= 0)
31146 + err = min(bdiropq, bwh);
31149 + AuDbg("%d\n", err);
31150 + } else if (bdiropq >= 0) {
31152 + AuDbg("%d\n", err);
31157 + err = au_wbr_nonopq(dentry, err);
31159 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
31162 + AuDbg("%d\n", err);
31166 +/* ---------------------------------------------------------------------- */
31169 +static int au_wbr_create_init_rr(struct super_block *sb)
31173 + err = au_wbr_bu(sb, au_sbend(sb));
31174 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
31177 + AuDbg("b%d\n", err);
31181 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
31185 + aufs_bindex_t bindex, bend;
31186 + struct super_block *sb;
31189 + err = au_wbr_create_exp(dentry);
31193 + sb = dentry->d_sb;
31194 + next = &au_sbi(sb)->si_wbr_rr_next;
31195 + bend = au_sbend(sb);
31197 + for (bindex = 0; bindex <= bend; bindex++) {
31198 + if (!au_ftest_wbr(flags, DIR)) {
31199 + err = atomic_dec_return(next) + 1;
31200 + /* modulo for 0 is meaningless */
31201 + if (unlikely(!err))
31202 + err = atomic_dec_return(next) + 1;
31204 + err = atomic_read(next);
31205 + AuDbg("%d\n", err);
31208 + AuDbg("%d\n", err);
31209 + if (!au_br_rdonly(au_sbr(sb, err)))
31215 + err = au_wbr_nonopq(dentry, err);
31218 + AuDbg("%d\n", err);
31222 +/* ---------------------------------------------------------------------- */
31224 +/* most free space */
31225 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31227 + struct super_block *sb;
31228 + struct au_branch *br;
31229 + struct au_wbr_mfs *mfs;
31230 + struct dentry *h_parent;
31231 + aufs_bindex_t bindex, bend;
31233 + unsigned long long b, bavail;
31234 + struct path h_path;
31235 + /* reduce the stack usage */
31236 + struct kstatfs *st;
31238 + st = kmalloc(sizeof(*st), GFP_NOFS);
31239 + if (unlikely(!st)) {
31240 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31245 + sb = dentry->d_sb;
31246 + mfs = &au_sbi(sb)->si_wbr_mfs;
31247 + MtxMustLock(&mfs->mfs_lock);
31248 + mfs->mfs_bindex = -EROFS;
31249 + mfs->mfsrr_bytes = 0;
31252 + bend = au_sbend(sb);
31254 + bindex = au_dbstart(parent);
31255 + bend = au_dbtaildir(parent);
31258 + for (; bindex <= bend; bindex++) {
31260 + h_parent = au_h_dptr(parent, bindex);
31261 + if (!h_parent || !h_parent->d_inode)
31264 + br = au_sbr(sb, bindex);
31265 + if (au_br_rdonly(br))
31268 + /* sb->s_root for NFS is unreliable */
31269 + h_path.mnt = au_br_mnt(br);
31270 + h_path.dentry = h_path.mnt->mnt_root;
31271 + err = vfs_statfs(&h_path, st);
31272 + if (unlikely(err)) {
31273 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31277 + /* when the available size is equal, select the lower one */
31278 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31279 + || sizeof(b) < sizeof(st->f_bsize));
31280 + b = st->f_bavail * st->f_bsize;
31281 + br->br_wbr->wbr_bytes = b;
31282 + if (b >= bavail) {
31284 + mfs->mfs_bindex = bindex;
31285 + mfs->mfs_jiffy = jiffies;
31289 + mfs->mfsrr_bytes = bavail;
31290 + AuDbg("b%d\n", mfs->mfs_bindex);
31294 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31297 + struct dentry *parent;
31298 + struct super_block *sb;
31299 + struct au_wbr_mfs *mfs;
31301 + err = au_wbr_create_exp(dentry);
31305 + sb = dentry->d_sb;
31307 + if (au_ftest_wbr(flags, PARENT))
31308 + parent = dget_parent(dentry);
31309 + mfs = &au_sbi(sb)->si_wbr_mfs;
31310 + mutex_lock(&mfs->mfs_lock);
31311 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31312 + || mfs->mfs_bindex < 0
31313 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31314 + au_mfs(dentry, parent);
31315 + mutex_unlock(&mfs->mfs_lock);
31316 + err = mfs->mfs_bindex;
31320 + err = au_wbr_nonopq(dentry, err);
31323 + AuDbg("b%d\n", err);
31327 +static int au_wbr_create_init_mfs(struct super_block *sb)
31329 + struct au_wbr_mfs *mfs;
31331 + mfs = &au_sbi(sb)->si_wbr_mfs;
31332 + mutex_init(&mfs->mfs_lock);
31333 + mfs->mfs_jiffy = 0;
31334 + mfs->mfs_bindex = -EROFS;
31339 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31341 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31345 +/* ---------------------------------------------------------------------- */
31347 +/* most free space and then round robin */
31348 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31351 + struct au_wbr_mfs *mfs;
31353 + err = au_wbr_create_mfs(dentry, flags);
31355 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31356 + mutex_lock(&mfs->mfs_lock);
31357 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31358 + err = au_wbr_create_rr(dentry, flags);
31359 + mutex_unlock(&mfs->mfs_lock);
31362 + AuDbg("b%d\n", err);
31366 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31370 + au_wbr_create_init_mfs(sb); /* ignore */
31371 + err = au_wbr_create_init_rr(sb);
31376 +/* ---------------------------------------------------------------------- */
31378 +/* top down parent and most free space */
31379 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31382 + unsigned long long b;
31383 + aufs_bindex_t bindex, bstart, bend;
31384 + struct super_block *sb;
31385 + struct dentry *parent, *h_parent;
31386 + struct au_branch *br;
31388 + err = au_wbr_create_tdp(dentry, flags);
31389 + if (unlikely(err < 0))
31391 + parent = dget_parent(dentry);
31392 + bstart = au_dbstart(parent);
31393 + bend = au_dbtaildir(parent);
31394 + if (bstart == bend)
31395 + goto out_parent; /* success */
31397 + e2 = au_wbr_create_mfs(dentry, flags);
31399 + goto out_parent; /* success */
31401 + /* when the available size is equal, select upper one */
31402 + sb = dentry->d_sb;
31403 + br = au_sbr(sb, err);
31404 + b = br->br_wbr->wbr_bytes;
31405 + AuDbg("b%d, %llu\n", err, b);
31407 + for (bindex = bstart; bindex <= bend; bindex++) {
31408 + h_parent = au_h_dptr(parent, bindex);
31409 + if (!h_parent || !h_parent->d_inode)
31412 + br = au_sbr(sb, bindex);
31413 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31414 + b = br->br_wbr->wbr_bytes;
31416 + AuDbg("b%d, %llu\n", err, b);
31421 + err = au_wbr_nonopq(dentry, err);
31426 + AuDbg("b%d\n", err);
31430 +/* ---------------------------------------------------------------------- */
31433 + * - top down parent
31434 + * - most free space with parent
31435 + * - most free space round-robin regardless parent
31437 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31440 + unsigned long long watermark;
31441 + struct super_block *sb;
31442 + struct au_branch *br;
31443 + struct au_wbr_mfs *mfs;
31445 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31446 + if (unlikely(err < 0))
31449 + sb = dentry->d_sb;
31450 + br = au_sbr(sb, err);
31451 + mfs = &au_sbi(sb)->si_wbr_mfs;
31452 + mutex_lock(&mfs->mfs_lock);
31453 + watermark = mfs->mfsrr_watermark;
31454 + mutex_unlock(&mfs->mfs_lock);
31455 + if (br->br_wbr->wbr_bytes < watermark)
31456 + /* regardless the parent dir */
31457 + err = au_wbr_create_mfsrr(dentry, flags);
31460 + AuDbg("b%d\n", err);
31464 +/* ---------------------------------------------------------------------- */
31466 +/* policies for copyup */
31468 +/* top down parent */
31469 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31471 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31474 +/* bottom up parent */
31475 +static int au_wbr_copyup_bup(struct dentry *dentry)
31478 + aufs_bindex_t bindex, bstart;
31479 + struct dentry *parent, *h_parent;
31480 + struct super_block *sb;
31483 + sb = dentry->d_sb;
31484 + parent = dget_parent(dentry);
31485 + bstart = au_dbstart(parent);
31486 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31487 + h_parent = au_h_dptr(parent, bindex);
31488 + if (!h_parent || !h_parent->d_inode)
31491 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31498 + /* bottom up here */
31499 + if (unlikely(err < 0))
31500 + err = au_wbr_bu(sb, bstart - 1);
31502 + AuDbg("b%d\n", err);
31507 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
31511 + err = au_wbr_bu(dentry->d_sb, bstart);
31512 + AuDbg("b%d\n", err);
31513 + if (err > bstart)
31514 + err = au_wbr_nonopq(dentry, err);
31516 + AuDbg("b%d\n", err);
31520 +static int au_wbr_copyup_bu(struct dentry *dentry)
31523 + aufs_bindex_t bstart;
31525 + bstart = au_dbstart(dentry);
31526 + err = au_wbr_do_copyup_bu(dentry, bstart);
31530 +/* ---------------------------------------------------------------------- */
31532 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
31533 + [AuWbrCopyup_TDP] = {
31534 + .copyup = au_wbr_copyup_tdp
31536 + [AuWbrCopyup_BUP] = {
31537 + .copyup = au_wbr_copyup_bup
31539 + [AuWbrCopyup_BU] = {
31540 + .copyup = au_wbr_copyup_bu
31544 +struct au_wbr_create_operations au_wbr_create_ops[] = {
31545 + [AuWbrCreate_TDP] = {
31546 + .create = au_wbr_create_tdp
31548 + [AuWbrCreate_RR] = {
31549 + .create = au_wbr_create_rr,
31550 + .init = au_wbr_create_init_rr
31552 + [AuWbrCreate_MFS] = {
31553 + .create = au_wbr_create_mfs,
31554 + .init = au_wbr_create_init_mfs,
31555 + .fin = au_wbr_create_fin_mfs
31557 + [AuWbrCreate_MFSV] = {
31558 + .create = au_wbr_create_mfs,
31559 + .init = au_wbr_create_init_mfs,
31560 + .fin = au_wbr_create_fin_mfs
31562 + [AuWbrCreate_MFSRR] = {
31563 + .create = au_wbr_create_mfsrr,
31564 + .init = au_wbr_create_init_mfsrr,
31565 + .fin = au_wbr_create_fin_mfs
31567 + [AuWbrCreate_MFSRRV] = {
31568 + .create = au_wbr_create_mfsrr,
31569 + .init = au_wbr_create_init_mfsrr,
31570 + .fin = au_wbr_create_fin_mfs
31572 + [AuWbrCreate_PMFS] = {
31573 + .create = au_wbr_create_pmfs,
31574 + .init = au_wbr_create_init_mfs,
31575 + .fin = au_wbr_create_fin_mfs
31577 + [AuWbrCreate_PMFSV] = {
31578 + .create = au_wbr_create_pmfs,
31579 + .init = au_wbr_create_init_mfs,
31580 + .fin = au_wbr_create_fin_mfs
31582 + [AuWbrCreate_PMFSRR] = {
31583 + .create = au_wbr_create_pmfsrr,
31584 + .init = au_wbr_create_init_mfsrr,
31585 + .fin = au_wbr_create_fin_mfs
31587 + [AuWbrCreate_PMFSRRV] = {
31588 + .create = au_wbr_create_pmfsrr,
31589 + .init = au_wbr_create_init_mfsrr,
31590 + .fin = au_wbr_create_fin_mfs
31593 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
31594 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
31595 +++ linux/fs/aufs/whout.c 2015-01-25 13:00:38.634380408 +0100
31598 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31600 + * This program, aufs is free software; you can redistribute it and/or modify
31601 + * it under the terms of the GNU General Public License as published by
31602 + * the Free Software Foundation; either version 2 of the License, or
31603 + * (at your option) any later version.
31605 + * This program is distributed in the hope that it will be useful,
31606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31608 + * GNU General Public License for more details.
31610 + * You should have received a copy of the GNU General Public License
31611 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31615 + * whiteout for logical deletion and opaque directory
31620 +#define WH_MASK S_IRUGO
31623 + * If a directory contains this file, then it is opaque. We start with the
31624 + * .wh. flag so that it is blocked by lookup.
31626 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
31627 + sizeof(AUFS_WH_DIROPQ) - 1);
31630 + * generate whiteout name, which is NOT terminated by NULL.
31631 + * @name: original d_name.name
31632 + * @len: original d_name.len
31633 + * @wh: whiteout qstr
31634 + * returns zero when succeeds, otherwise error.
31635 + * succeeded value as wh->name should be freed by kfree().
31637 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
31641 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
31642 + return -ENAMETOOLONG;
31644 + wh->len = name->len + AUFS_WH_PFX_LEN;
31645 + p = kmalloc(wh->len, GFP_NOFS);
31648 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31649 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
31656 +/* ---------------------------------------------------------------------- */
31659 + * test if the @wh_name exists under @h_parent.
31660 + * @try_sio specifies the necessary of super-io.
31662 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
31665 + struct dentry *wh_dentry;
31668 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
31670 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
31671 + err = PTR_ERR(wh_dentry);
31672 + if (IS_ERR(wh_dentry))
31676 + if (!wh_dentry->d_inode)
31677 + goto out_wh; /* success */
31680 + if (S_ISREG(wh_dentry->d_inode->i_mode))
31681 + goto out_wh; /* success */
31684 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
31685 + wh_dentry, wh_dentry->d_inode->i_mode);
31694 + * test if the @h_dentry sets opaque or not.
31696 +int au_diropq_test(struct dentry *h_dentry)
31699 + struct inode *h_dir;
31701 + h_dir = h_dentry->d_inode;
31702 + err = au_wh_test(h_dentry, &diropq_name,
31703 + au_test_h_perm_sio(h_dir, MAY_EXEC));
31708 + * returns a negative dentry whose name is unique and temporary.
31710 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31711 + struct qstr *prefix)
31713 + struct dentry *dentry;
31715 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
31717 + /* strict atomic_t is unnecessary here */
31718 + static unsigned short cnt;
31721 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
31724 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
31725 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
31726 + dentry = ERR_PTR(-ENAMETOOLONG);
31727 + if (unlikely(qs.len > NAME_MAX))
31729 + dentry = ERR_PTR(-ENOMEM);
31730 + name = kmalloc(qs.len + 1, GFP_NOFS);
31731 + if (unlikely(!name))
31735 + /* doubly whiteout-ed */
31736 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
31737 + p = name + AUFS_WH_PFX_LEN * 2;
31738 + memcpy(p, prefix->name, prefix->len);
31739 + p += prefix->len;
31741 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
31744 + for (i = 0; i < 3; i++) {
31745 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
31746 + dentry = au_sio_lkup_one(&qs, h_parent);
31747 + if (IS_ERR(dentry) || !dentry->d_inode)
31751 + /* pr_warn("could not get random name\n"); */
31752 + dentry = ERR_PTR(-EEXIST);
31753 + AuDbg("%.*s\n", AuLNPair(&qs));
31757 + if (name != defname)
31760 + AuTraceErrPtr(dentry);
31765 + * rename the @h_dentry on @br to the whiteouted temporary name.
31767 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
31770 + struct path h_path = {
31771 + .mnt = au_br_mnt(br)
31773 + struct inode *h_dir, *delegated;
31774 + struct dentry *h_parent;
31776 + h_parent = h_dentry->d_parent; /* dir inode is locked */
31777 + h_dir = h_parent->d_inode;
31778 + IMustLock(h_dir);
31780 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
31781 + err = PTR_ERR(h_path.dentry);
31782 + if (IS_ERR(h_path.dentry))
31785 + /* under the same dir, no need to lock_rename() */
31786 + delegated = NULL;
31787 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
31789 + if (unlikely(err == -EWOULDBLOCK)) {
31790 + pr_warn("cannot retry for NFSv4 delegation"
31791 + " for an internal rename\n");
31794 + dput(h_path.dentry);
31801 +/* ---------------------------------------------------------------------- */
31803 + * functions for removing a whiteout
31806 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
31809 + struct inode *delegated;
31812 + * forces superio when the dir has a sticky bit.
31813 + * this may be a violation of unix fs semantics.
31815 + force = (h_dir->i_mode & S_ISVTX)
31816 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
31817 + delegated = NULL;
31818 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
31819 + if (unlikely(err == -EWOULDBLOCK)) {
31820 + pr_warn("cannot retry for NFSv4 delegation"
31821 + " for an internal unlink\n");
31827 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
31828 + struct dentry *dentry)
31832 + err = do_unlink_wh(h_dir, h_path);
31833 + if (!err && dentry)
31834 + au_set_dbwh(dentry, -1);
31839 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
31840 + struct au_branch *br)
31843 + struct path h_path = {
31844 + .mnt = au_br_mnt(br)
31848 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
31849 + if (IS_ERR(h_path.dentry))
31850 + err = PTR_ERR(h_path.dentry);
31852 + if (h_path.dentry->d_inode
31853 + && S_ISREG(h_path.dentry->d_inode->i_mode))
31854 + err = do_unlink_wh(h_parent->d_inode, &h_path);
31855 + dput(h_path.dentry);
31861 +/* ---------------------------------------------------------------------- */
31863 + * initialize/clean whiteout for a branch
31866 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
31870 + struct inode *delegated;
31872 + if (!whpath->dentry->d_inode)
31876 + err = vfsub_rmdir(h_dir, whpath);
31878 + delegated = NULL;
31879 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
31880 + if (unlikely(err == -EWOULDBLOCK)) {
31881 + pr_warn("cannot retry for NFSv4 delegation"
31882 + " for an internal unlink\n");
31886 + if (unlikely(err))
31887 + pr_warn("failed removing %pd (%d), ignored.\n",
31888 + whpath->dentry, err);
31891 +static int test_linkable(struct dentry *h_root)
31893 + struct inode *h_dir = h_root->d_inode;
31895 + if (h_dir->i_op->link)
31898 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
31899 + h_root, au_sbtype(h_root->d_sb));
31903 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
31904 +static int au_whdir(struct inode *h_dir, struct path *path)
31909 + if (!path->dentry->d_inode) {
31910 + int mode = S_IRWXU;
31912 + if (au_test_nfs(path->dentry->d_sb))
31914 + err = vfsub_mkdir(h_dir, path, mode);
31915 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
31918 + pr_err("unknown %pd exists\n", path->dentry);
31923 +struct au_wh_base {
31924 + const struct qstr *name;
31925 + struct dentry *dentry;
31928 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
31929 + struct path *h_path)
31931 + h_path->dentry = base[AuBrWh_BASE].dentry;
31932 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31933 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31934 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31935 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31936 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31940 + * returns tri-state,
31941 + * minus: error, caller should print the message
31943 + * plus: error, caller should NOT print the message
31945 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
31946 + int do_plink, struct au_wh_base base[],
31947 + struct path *h_path)
31950 + struct inode *h_dir;
31952 + h_dir = h_root->d_inode;
31953 + h_path->dentry = base[AuBrWh_BASE].dentry;
31954 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31955 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31957 + err = test_linkable(h_root);
31958 + if (unlikely(err)) {
31963 + err = au_whdir(h_dir, h_path);
31964 + if (unlikely(err))
31966 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
31968 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31969 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31970 + err = au_whdir(h_dir, h_path);
31971 + if (unlikely(err))
31973 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
31980 + * for the moment, aufs supports the branch filesystem which does not support
31981 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
31982 + * copyup failed. finally, such filesystem will not be used as the writable
31985 + * returns tri-state, see above.
31987 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
31988 + int do_plink, struct au_wh_base base[],
31989 + struct path *h_path)
31992 + struct inode *h_dir;
31994 + WbrWhMustWriteLock(wbr);
31996 + err = test_linkable(h_root);
31997 + if (unlikely(err)) {
32003 + * todo: should this create be done in /sbin/mount.aufs helper?
32006 + h_dir = h_root->d_inode;
32007 + if (!base[AuBrWh_BASE].dentry->d_inode) {
32008 + h_path->dentry = base[AuBrWh_BASE].dentry;
32009 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32010 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
32013 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32014 + if (unlikely(err))
32017 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32019 + err = au_whdir(h_dir, h_path);
32020 + if (unlikely(err))
32022 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32024 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32025 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32027 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32028 + err = au_whdir(h_dir, h_path);
32029 + if (unlikely(err))
32031 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32038 + * initialize the whiteout base file/dir for @br.
32040 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32043 + const unsigned char do_plink
32044 + = !!au_opt_test(au_mntflags(sb), PLINK);
32045 + struct inode *h_dir;
32046 + struct path path = br->br_path;
32047 + struct dentry *h_root = path.dentry;
32048 + struct au_wbr *wbr = br->br_wbr;
32049 + static const struct qstr base_name[] = {
32050 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32051 + sizeof(AUFS_BASE_NAME) - 1),
32052 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32053 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32054 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32055 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32057 + struct au_wh_base base[] = {
32058 + [AuBrWh_BASE] = {
32059 + .name = base_name + AuBrWh_BASE,
32062 + [AuBrWh_PLINK] = {
32063 + .name = base_name + AuBrWh_PLINK,
32066 + [AuBrWh_ORPH] = {
32067 + .name = base_name + AuBrWh_ORPH,
32073 + WbrWhMustWriteLock(wbr);
32075 + for (i = 0; i < AuBrWh_Last; i++) {
32076 + /* doubly whiteouted */
32077 + struct dentry *d;
32079 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32080 + err = PTR_ERR(d);
32084 + base[i].dentry = d;
32086 + && wbr->wbr_wh[i]
32087 + && wbr->wbr_wh[i] != base[i].dentry);
32091 + for (i = 0; i < AuBrWh_Last; i++) {
32092 + dput(wbr->wbr_wh[i]);
32093 + wbr->wbr_wh[i] = NULL;
32097 + if (!au_br_writable(br->br_perm)) {
32098 + h_dir = h_root->d_inode;
32099 + au_wh_init_ro(h_dir, base, &path);
32100 + } else if (!au_br_wh_linkable(br->br_perm)) {
32101 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32107 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32113 + goto out; /* success */
32116 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32117 + err, h_root, au_sbtype(h_root->d_sb));
32119 + for (i = 0; i < AuBrWh_Last; i++)
32120 + dput(base[i].dentry);
32124 +/* ---------------------------------------------------------------------- */
32126 + * whiteouts are all hard-linked usually.
32127 + * when its link count reaches a ceiling, we create a new whiteout base
32128 + * asynchronously.
32131 +struct reinit_br_wh {
32132 + struct super_block *sb;
32133 + struct au_branch *br;
32136 +static void reinit_br_wh(void *arg)
32139 + aufs_bindex_t bindex;
32140 + struct path h_path;
32141 + struct reinit_br_wh *a = arg;
32142 + struct au_wbr *wbr;
32143 + struct inode *dir, *delegated;
32144 + struct dentry *h_root;
32145 + struct au_hinode *hdir;
32148 + wbr = a->br->br_wbr;
32149 + /* big aufs lock */
32150 + si_noflush_write_lock(a->sb);
32151 + if (!au_br_writable(a->br->br_perm))
32153 + bindex = au_br_index(a->sb, a->br->br_id);
32154 + if (unlikely(bindex < 0))
32157 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
32158 + dir = a->sb->s_root->d_inode;
32159 + hdir = au_hi(dir, bindex);
32160 + h_root = au_h_dptr(a->sb->s_root, bindex);
32161 + AuDebugOn(h_root != au_br_dentry(a->br));
32163 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32164 + wbr_wh_write_lock(wbr);
32165 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
32168 + h_path.dentry = wbr->wbr_whbase;
32169 + h_path.mnt = au_br_mnt(a->br);
32170 + delegated = NULL;
32171 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
32173 + if (unlikely(err == -EWOULDBLOCK)) {
32174 + pr_warn("cannot retry for NFSv4 delegation"
32175 + " for an internal unlink\n");
32179 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
32182 + dput(wbr->wbr_whbase);
32183 + wbr->wbr_whbase = NULL;
32185 + err = au_wh_init(a->br, a->sb);
32186 + wbr_wh_write_unlock(wbr);
32187 + au_hn_imtx_unlock(hdir);
32188 + di_read_unlock(a->sb->s_root, AuLock_IR);
32190 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
32194 + atomic_dec(&wbr->wbr_wh_running);
32195 + atomic_dec(&a->br->br_count);
32196 + si_write_unlock(a->sb);
32197 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32199 + if (unlikely(err))
32200 + AuIOErr("err %d\n", err);
32203 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32205 + int do_dec, wkq_err;
32206 + struct reinit_br_wh *arg;
32209 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32212 + /* ignore ENOMEM */
32213 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32216 + * dec(wh_running), kfree(arg) and dec(br_count)
32217 + * in reinit function
32221 + atomic_inc(&br->br_count);
32222 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32223 + if (unlikely(wkq_err)) {
32224 + atomic_dec(&br->br_wbr->wbr_wh_running);
32225 + atomic_dec(&br->br_count);
32233 + atomic_dec(&br->br_wbr->wbr_wh_running);
32236 +/* ---------------------------------------------------------------------- */
32239 + * create the whiteout @wh.
32241 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32242 + struct dentry *wh)
32245 + struct path h_path = {
32248 + struct au_branch *br;
32249 + struct au_wbr *wbr;
32250 + struct dentry *h_parent;
32251 + struct inode *h_dir, *delegated;
32253 + h_parent = wh->d_parent; /* dir inode is locked */
32254 + h_dir = h_parent->d_inode;
32255 + IMustLock(h_dir);
32257 + br = au_sbr(sb, bindex);
32258 + h_path.mnt = au_br_mnt(br);
32259 + wbr = br->br_wbr;
32260 + wbr_wh_read_lock(wbr);
32261 + if (wbr->wbr_whbase) {
32262 + delegated = NULL;
32263 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32264 + if (unlikely(err == -EWOULDBLOCK)) {
32265 + pr_warn("cannot retry for NFSv4 delegation"
32266 + " for an internal link\n");
32269 + if (!err || err != -EMLINK)
32272 + /* link count full. re-initialize br_whbase. */
32273 + kick_reinit_br_wh(sb, br);
32276 + /* return this error in this context */
32277 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32279 + au_fhsm_wrote(sb, bindex, /*force*/0);
32282 + wbr_wh_read_unlock(wbr);
32286 +/* ---------------------------------------------------------------------- */
32289 + * create or remove the diropq.
32291 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32292 + unsigned int flags)
32294 + struct dentry *opq_dentry, *h_dentry;
32295 + struct super_block *sb;
32296 + struct au_branch *br;
32299 + sb = dentry->d_sb;
32300 + br = au_sbr(sb, bindex);
32301 + h_dentry = au_h_dptr(dentry, bindex);
32302 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32303 + if (IS_ERR(opq_dentry))
32306 + if (au_ftest_diropq(flags, CREATE)) {
32307 + err = link_or_create_wh(sb, bindex, opq_dentry);
32309 + au_set_dbdiropq(dentry, bindex);
32310 + goto out; /* success */
32313 + struct path tmp = {
32314 + .dentry = opq_dentry,
32315 + .mnt = au_br_mnt(br)
32317 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
32319 + au_set_dbdiropq(dentry, -1);
32321 + dput(opq_dentry);
32322 + opq_dentry = ERR_PTR(err);
32325 + return opq_dentry;
32328 +struct do_diropq_args {
32329 + struct dentry **errp;
32330 + struct dentry *dentry;
32331 + aufs_bindex_t bindex;
32332 + unsigned int flags;
32335 +static void call_do_diropq(void *args)
32337 + struct do_diropq_args *a = args;
32338 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32341 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32342 + unsigned int flags)
32344 + struct dentry *diropq, *h_dentry;
32346 + h_dentry = au_h_dptr(dentry, bindex);
32347 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
32348 + diropq = do_diropq(dentry, bindex, flags);
32351 + struct do_diropq_args args = {
32353 + .dentry = dentry,
32354 + .bindex = bindex,
32358 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32359 + if (unlikely(wkq_err))
32360 + diropq = ERR_PTR(wkq_err);
32366 +/* ---------------------------------------------------------------------- */
32369 + * lookup whiteout dentry.
32370 + * @h_parent: lower parent dentry which must exist and be locked
32371 + * @base_name: name of dentry which will be whiteouted
32372 + * returns dentry for whiteout.
32374 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32375 + struct au_branch *br)
32378 + struct qstr wh_name;
32379 + struct dentry *wh_dentry;
32381 + err = au_wh_name_alloc(&wh_name, base_name);
32382 + wh_dentry = ERR_PTR(err);
32384 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32385 + kfree(wh_name.name);
32387 + return wh_dentry;
32391 + * link/create a whiteout for @dentry on @bindex.
32393 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32394 + struct dentry *h_parent)
32396 + struct dentry *wh_dentry;
32397 + struct super_block *sb;
32400 + sb = dentry->d_sb;
32401 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32402 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
32403 + err = link_or_create_wh(sb, bindex, wh_dentry);
32405 + au_set_dbwh(dentry, bindex);
32406 + au_fhsm_wrote(sb, bindex, /*force*/0);
32409 + wh_dentry = ERR_PTR(err);
32413 + return wh_dentry;
32416 +/* ---------------------------------------------------------------------- */
32418 +/* Delete all whiteouts in this directory on branch bindex. */
32419 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32420 + aufs_bindex_t bindex, struct au_branch *br)
32423 + unsigned long ul, n;
32424 + struct qstr wh_name;
32426 + struct hlist_head *head;
32427 + struct au_vdir_wh *pos;
32428 + struct au_vdir_destr *str;
32431 + p = (void *)__get_free_page(GFP_NOFS);
32432 + wh_name.name = p;
32433 + if (unlikely(!wh_name.name))
32437 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32438 + p += AUFS_WH_PFX_LEN;
32439 + n = whlist->nh_num;
32440 + head = whlist->nh_head;
32441 + for (ul = 0; !err && ul < n; ul++, head++) {
32442 + hlist_for_each_entry(pos, head, wh_hash) {
32443 + if (pos->wh_bindex != bindex)
32446 + str = &pos->wh_str;
32447 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32448 + memcpy(p, str->name, str->len);
32449 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32450 + err = unlink_wh_name(h_dentry, &wh_name, br);
32455 + AuIOErr("whiteout name too long %.*s\n",
32456 + str->len, str->name);
32461 + free_page((unsigned long)wh_name.name);
32467 +struct del_wh_children_args {
32469 + struct dentry *h_dentry;
32470 + struct au_nhash *whlist;
32471 + aufs_bindex_t bindex;
32472 + struct au_branch *br;
32475 +static void call_del_wh_children(void *args)
32477 + struct del_wh_children_args *a = args;
32478 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32481 +/* ---------------------------------------------------------------------- */
32483 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32485 + struct au_whtmp_rmdir *whtmp;
32487 + unsigned int rdhash;
32489 + SiMustAnyLock(sb);
32491 + whtmp = kmalloc(sizeof(*whtmp), gfp);
32492 + if (unlikely(!whtmp)) {
32493 + whtmp = ERR_PTR(-ENOMEM);
32497 + whtmp->dir = NULL;
32498 + whtmp->br = NULL;
32499 + whtmp->wh_dentry = NULL;
32500 + /* no estimation for dir size */
32501 + rdhash = au_sbi(sb)->si_rdhash;
32503 + rdhash = AUFS_RDHASH_DEF;
32504 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32505 + if (unlikely(err)) {
32507 + whtmp = ERR_PTR(err);
32514 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
32517 + atomic_dec(&whtmp->br->br_count);
32518 + dput(whtmp->wh_dentry);
32519 + iput(whtmp->dir);
32520 + au_nhash_wh_free(&whtmp->whlist);
32525 + * rmdir the whiteouted temporary named dir @h_dentry.
32526 + * @whlist: whiteouted children.
32528 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32529 + struct dentry *wh_dentry, struct au_nhash *whlist)
32532 + struct path h_tmp;
32533 + struct inode *wh_inode, *h_dir;
32534 + struct au_branch *br;
32536 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
32537 + IMustLock(h_dir);
32539 + br = au_sbr(dir->i_sb, bindex);
32540 + wh_inode = wh_dentry->d_inode;
32541 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
32544 + * someone else might change some whiteouts while we were sleeping.
32545 + * it means this whlist may have an obsoleted entry.
32547 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
32548 + err = del_wh_children(wh_dentry, whlist, bindex, br);
32551 + struct del_wh_children_args args = {
32553 + .h_dentry = wh_dentry,
32554 + .whlist = whlist,
32555 + .bindex = bindex,
32559 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
32560 + if (unlikely(wkq_err))
32563 + mutex_unlock(&wh_inode->i_mutex);
32566 + h_tmp.dentry = wh_dentry;
32567 + h_tmp.mnt = au_br_mnt(br);
32568 + err = vfsub_rmdir(h_dir, &h_tmp);
32572 + if (au_ibstart(dir) == bindex) {
32573 + /* todo: dir->i_mutex is necessary */
32574 + au_cpup_attr_timesizes(dir);
32575 + vfsub_drop_nlink(dir);
32577 + return 0; /* success */
32580 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
32584 +static void call_rmdir_whtmp(void *args)
32587 + aufs_bindex_t bindex;
32588 + struct au_whtmp_rmdir *a = args;
32589 + struct super_block *sb;
32590 + struct dentry *h_parent;
32591 + struct inode *h_dir;
32592 + struct au_hinode *hdir;
32594 + /* rmdir by nfsd may cause deadlock with this i_mutex */
32595 + /* mutex_lock(&a->dir->i_mutex); */
32597 + sb = a->dir->i_sb;
32598 + si_read_lock(sb, !AuLock_FLUSH);
32599 + if (!au_br_writable(a->br->br_perm))
32601 + bindex = au_br_index(sb, a->br->br_id);
32602 + if (unlikely(bindex < 0))
32606 + ii_write_lock_parent(a->dir);
32607 + h_parent = dget_parent(a->wh_dentry);
32608 + h_dir = h_parent->d_inode;
32609 + hdir = au_hi(a->dir, bindex);
32610 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
32611 + if (unlikely(err))
32613 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32614 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
32617 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
32618 + au_hn_imtx_unlock(hdir);
32619 + vfsub_mnt_drop_write(au_br_mnt(a->br));
32623 + ii_write_unlock(a->dir);
32625 + /* mutex_unlock(&a->dir->i_mutex); */
32626 + au_whtmp_rmdir_free(a);
32627 + si_read_unlock(sb);
32628 + au_nwt_done(&au_sbi(sb)->si_nowait);
32629 + if (unlikely(err))
32630 + AuIOErr("err %d\n", err);
32633 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32634 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
32637 + struct super_block *sb;
32641 + /* all post-process will be done in do_rmdir_whtmp(). */
32643 + args->dir = au_igrab(dir);
32644 + args->br = au_sbr(sb, bindex);
32645 + atomic_inc(&args->br->br_count);
32646 + args->wh_dentry = dget(wh_dentry);
32647 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
32648 + if (unlikely(wkq_err)) {
32649 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
32650 + au_whtmp_rmdir_free(args);
32653 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
32654 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
32655 +++ linux/fs/aufs/whout.h 2015-01-25 13:00:38.634380408 +0100
32658 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32660 + * This program, aufs is free software; you can redistribute it and/or modify
32661 + * it under the terms of the GNU General Public License as published by
32662 + * the Free Software Foundation; either version 2 of the License, or
32663 + * (at your option) any later version.
32665 + * This program is distributed in the hope that it will be useful,
32666 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32667 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32668 + * GNU General Public License for more details.
32670 + * You should have received a copy of the GNU General Public License
32671 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32675 + * whiteout for logical deletion and opaque directory
32678 +#ifndef __AUFS_WHOUT_H__
32679 +#define __AUFS_WHOUT_H__
32686 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
32688 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
32689 +int au_diropq_test(struct dentry *h_dentry);
32690 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32691 + struct qstr *prefix);
32692 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
32693 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32694 + struct dentry *dentry);
32695 +int au_wh_init(struct au_branch *br, struct super_block *sb);
32697 +/* diropq flags */
32698 +#define AuDiropq_CREATE 1
32699 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
32700 +#define au_fset_diropq(flags, name) \
32701 + do { (flags) |= AuDiropq_##name; } while (0)
32702 +#define au_fclr_diropq(flags, name) \
32703 + do { (flags) &= ~AuDiropq_##name; } while (0)
32705 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32706 + unsigned int flags);
32707 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32708 + struct au_branch *br);
32709 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32710 + struct dentry *h_parent);
32712 +/* real rmdir for the whiteout-ed dir */
32713 +struct au_whtmp_rmdir {
32714 + struct inode *dir;
32715 + struct au_branch *br;
32716 + struct dentry *wh_dentry;
32717 + struct au_nhash whlist;
32720 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
32721 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
32722 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32723 + struct dentry *wh_dentry, struct au_nhash *whlist);
32724 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32725 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
32727 +/* ---------------------------------------------------------------------- */
32729 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
32730 + aufs_bindex_t bindex)
32732 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
32735 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
32737 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
32740 +#endif /* __KERNEL__ */
32741 +#endif /* __AUFS_WHOUT_H__ */
32742 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
32743 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
32744 +++ linux/fs/aufs/wkq.c 2015-01-25 13:00:38.634380408 +0100
32747 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32749 + * This program, aufs is free software; you can redistribute it and/or modify
32750 + * it under the terms of the GNU General Public License as published by
32751 + * the Free Software Foundation; either version 2 of the License, or
32752 + * (at your option) any later version.
32754 + * This program is distributed in the hope that it will be useful,
32755 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32756 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32757 + * GNU General Public License for more details.
32759 + * You should have received a copy of the GNU General Public License
32760 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32764 + * workqueue for asynchronous/super-io operations
32765 + * todo: try new dredential scheme
32768 +#include <linux/module.h>
32771 +/* internal workqueue named AUFS_WKQ_NAME */
32773 +static struct workqueue_struct *au_wkq;
32775 +struct au_wkinfo {
32776 + struct work_struct wk;
32777 + struct kobject *kobj;
32779 + unsigned int flags; /* see wkq.h */
32781 + au_wkq_func_t func;
32784 + struct completion *comp;
32787 +/* ---------------------------------------------------------------------- */
32789 +static void wkq_func(struct work_struct *wk)
32791 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
32793 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
32794 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
32796 + wkinfo->func(wkinfo->args);
32797 + if (au_ftest_wkq(wkinfo->flags, WAIT))
32798 + complete(wkinfo->comp);
32800 + kobject_put(wkinfo->kobj);
32801 + module_put(THIS_MODULE); /* todo: ?? */
32807 + * Since struct completion is large, try allocating it dynamically.
32809 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
32810 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
32812 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32814 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
32816 + init_completion(*comp);
32817 + wkinfo->comp = *comp;
32823 +static void au_wkq_comp_free(struct completion *comp)
32831 +#define AuWkqCompDeclare(name) \
32832 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
32833 + struct completion *comp = &_ ## name
32835 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32837 + wkinfo->comp = *comp;
32841 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
32845 +#endif /* 4KSTACKS */
32847 +static void au_wkq_run(struct au_wkinfo *wkinfo)
32849 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
32850 + if (au_wkq_test()) {
32851 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
32852 + " due to a dead dir by UDBA?\n");
32853 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
32856 + au_dbg_verify_kthread();
32858 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
32859 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
32860 + queue_work(au_wkq, &wkinfo->wk);
32862 + INIT_WORK(&wkinfo->wk, wkq_func);
32863 + schedule_work(&wkinfo->wk);
32868 + * Be careful. It is easy to make deadlock happen.
32869 + * processA: lock, wkq and wait
32870 + * processB: wkq and wait, lock in wkq
32873 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
32876 + AuWkqCompDeclare(comp);
32877 + struct au_wkinfo wkinfo = {
32883 + err = au_wkq_comp_alloc(&wkinfo, &comp);
32885 + au_wkq_run(&wkinfo);
32886 + /* no timeout, no interrupt */
32887 + wait_for_completion(wkinfo.comp);
32888 + au_wkq_comp_free(comp);
32889 + destroy_work_on_stack(&wkinfo.wk);
32897 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
32898 + * problem in a concurrent umounting.
32900 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
32901 + unsigned int flags)
32904 + struct au_wkinfo *wkinfo;
32906 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
32909 + * wkq_func() must free this wkinfo.
32910 + * it highly depends upon the implementation of workqueue.
32913 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
32915 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
32916 + wkinfo->flags = flags & ~AuWkq_WAIT;
32917 + wkinfo->func = func;
32918 + wkinfo->args = args;
32919 + wkinfo->comp = NULL;
32920 + kobject_get(wkinfo->kobj);
32921 + __module_get(THIS_MODULE); /* todo: ?? */
32923 + au_wkq_run(wkinfo);
32926 + au_nwt_done(&au_sbi(sb)->si_nowait);
32932 +/* ---------------------------------------------------------------------- */
32934 +void au_nwt_init(struct au_nowait_tasks *nwt)
32936 + atomic_set(&nwt->nw_len, 0);
32937 + /* smp_mb(); */ /* atomic_set */
32938 + init_waitqueue_head(&nwt->nw_wq);
32941 +void au_wkq_fin(void)
32943 + destroy_workqueue(au_wkq);
32946 +int __init au_wkq_init(void)
32951 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
32952 + if (IS_ERR(au_wkq))
32953 + err = PTR_ERR(au_wkq);
32954 + else if (!au_wkq)
32959 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
32960 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
32961 +++ linux/fs/aufs/wkq.h 2015-01-25 13:00:38.634380408 +0100
32964 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32966 + * This program, aufs is free software; you can redistribute it and/or modify
32967 + * it under the terms of the GNU General Public License as published by
32968 + * the Free Software Foundation; either version 2 of the License, or
32969 + * (at your option) any later version.
32971 + * This program is distributed in the hope that it will be useful,
32972 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32973 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32974 + * GNU General Public License for more details.
32976 + * You should have received a copy of the GNU General Public License
32977 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32981 + * workqueue for asynchronous/super-io operations
32982 + * todo: try new credentials management scheme
32985 +#ifndef __AUFS_WKQ_H__
32986 +#define __AUFS_WKQ_H__
32990 +struct super_block;
32992 +/* ---------------------------------------------------------------------- */
32995 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
32997 +struct au_nowait_tasks {
32999 + wait_queue_head_t nw_wq;
33002 +/* ---------------------------------------------------------------------- */
33004 +typedef void (*au_wkq_func_t)(void *args);
33007 +#define AuWkq_WAIT 1
33008 +#define AuWkq_NEST (1 << 1)
33009 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33010 +#define au_fset_wkq(flags, name) \
33011 + do { (flags) |= AuWkq_##name; } while (0)
33012 +#define au_fclr_wkq(flags, name) \
33013 + do { (flags) &= ~AuWkq_##name; } while (0)
33015 +#ifndef CONFIG_AUFS_HNOTIFY
33017 +#define AuWkq_NEST 0
33021 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33022 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33023 + unsigned int flags);
33024 +void au_nwt_init(struct au_nowait_tasks *nwt);
33025 +int __init au_wkq_init(void);
33026 +void au_wkq_fin(void);
33028 +/* ---------------------------------------------------------------------- */
33030 +static inline int au_wkq_test(void)
33032 + return current->flags & PF_WQ_WORKER;
33035 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33037 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33040 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33042 + if (atomic_dec_and_test(&nwt->nw_len))
33043 + wake_up_all(&nwt->nw_wq);
33046 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33048 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
33052 +#endif /* __KERNEL__ */
33053 +#endif /* __AUFS_WKQ_H__ */
33054 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33055 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33056 +++ linux/fs/aufs/xattr.c 2015-01-25 13:00:38.634380408 +0100
33059 + * Copyright (C) 2014 Junjiro R. Okajima
33061 + * This program, aufs is free software; you can redistribute it and/or modify
33062 + * it under the terms of the GNU General Public License as published by
33063 + * the Free Software Foundation; either version 2 of the License, or
33064 + * (at your option) any later version.
33066 + * This program is distributed in the hope that it will be useful,
33067 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33068 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33069 + * GNU General Public License for more details.
33071 + * You should have received a copy of the GNU General Public License
33072 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33076 + * handling xattr functions
33079 +#include <linux/xattr.h>
33082 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33084 + if (!ignore_flags)
33092 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33097 +#define cmp(brattr, prefix) do { \
33098 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33099 + XATTR_##prefix##_PREFIX_LEN)) { \
33100 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33106 + cmp(SEC, SECURITY);
33107 + cmp(SYS, SYSTEM);
33108 + cmp(TR, TRUSTED);
33112 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33119 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
33121 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
33122 + char *name, char **buf, unsigned int ignore_flags)
33126 + struct inode *h_idst;
33128 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
33130 + if (unlikely(err <= 0)) {
33132 + if (err == -ENODATA
33133 + || (err == -EOPNOTSUPP
33134 + && (ignore_flags & au_xattr_out_of_list)))
33139 + /* unlock it temporary */
33140 + h_idst = h_dst->d_inode;
33141 + mutex_unlock(&h_idst->i_mutex);
33142 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
33143 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33144 + if (unlikely(err)) {
33145 + AuDbg("%s, err %d\n", name, err);
33146 + err = au_xattr_ignore(err, name, ignore_flags);
33153 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags)
33155 + int err, unlocked, acl_access, acl_default;
33157 + struct inode *h_isrc, *h_idst;
33158 + char *value, *p, *o, *e;
33160 + /* try stopping to update the source inode while we are referencing */
33161 + /* there should not be the parent-child relation ship between them */
33162 + h_isrc = h_src->d_inode;
33163 + h_idst = h_dst->d_inode;
33164 + mutex_unlock(&h_idst->i_mutex);
33165 + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
33166 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33169 + /* some filesystems don't list POSIX ACL, for example tmpfs */
33170 + ssz = vfs_listxattr(h_src, NULL, 0);
33172 + if (unlikely(err < 0)) {
33174 + if (err == -ENODATA
33175 + || err == -EOPNOTSUPP)
33176 + err = 0; /* ignore */
33185 + p = kmalloc(ssz, GFP_NOFS);
33187 + if (unlikely(!p))
33189 + err = vfs_listxattr(h_src, p, ssz);
33191 + mutex_unlock(&h_isrc->i_mutex);
33193 + AuDbg("err %d, ssz %zd\n", err, ssz);
33194 + if (unlikely(err < 0))
33202 + while (!err && p < e) {
33203 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33204 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33205 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33206 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33208 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags);
33209 + p += strlen(p) + 1;
33212 + ignore_flags |= au_xattr_out_of_list;
33213 + if (!err && !acl_access) {
33214 + err = au_do_cpup_xattr(h_dst, h_src,
33215 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33219 + if (!err && !acl_default) {
33220 + err = au_do_cpup_xattr(h_dst, h_src,
33221 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33232 + mutex_unlock(&h_isrc->i_mutex);
33237 +/* ---------------------------------------------------------------------- */
33244 +struct au_lgxattr {
33252 + const char *name;
33259 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33262 + struct path h_path;
33263 + struct super_block *sb;
33265 + sb = dentry->d_sb;
33266 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33267 + if (unlikely(err))
33269 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33270 + if (unlikely(err))
33272 + if (unlikely(!h_path.dentry))
33273 + /* illegally overlapped or something */
33274 + goto out_di; /* pretending success */
33276 + /* always topmost entry only */
33277 + switch (arg->type) {
33278 + case AU_XATTR_LIST:
33279 + err = vfs_listxattr(h_path.dentry,
33280 + arg->u.list.list, arg->u.list.size);
33282 + case AU_XATTR_GET:
33283 + err = vfs_getxattr(h_path.dentry,
33284 + arg->u.get.name, arg->u.get.value,
33285 + arg->u.get.size);
33290 + di_read_unlock(dentry, AuLock_IR);
33292 + si_read_unlock(sb);
33298 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33300 + struct au_lgxattr arg = {
33301 + .type = AU_XATTR_LIST,
33308 + return au_lgxattr(dentry, &arg);
33311 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
33314 + struct au_lgxattr arg = {
33315 + .type = AU_XATTR_GET,
33323 + return au_lgxattr(dentry, &arg);
33326 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33327 + size_t size, int flags)
33329 + struct au_srxattr arg = {
33330 + .type = AU_XATTR_SET,
33339 + return au_srxattr(dentry, &arg);
33342 +int aufs_removexattr(struct dentry *dentry, const char *name)
33344 + struct au_srxattr arg = {
33345 + .type = AU_XATTR_REMOVE,
33351 + return au_srxattr(dentry, &arg);
33354 +/* ---------------------------------------------------------------------- */
33357 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33358 + const char *name, size_t name_len, int type)
33360 + return aufs_listxattr(dentry, list, list_size);
33363 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33364 + size_t size, int type)
33366 + return aufs_getxattr(dentry, name, buffer, size);
33369 +static int au_xattr_set(struct dentry *dentry, const char *name,
33370 + const void *value, size_t size, int flags, int type)
33372 + return aufs_setxattr(dentry, name, value, size, flags);
33375 +static const struct xattr_handler au_xattr_handler = {
33376 + /* no prefix, no flags */
33377 + .list = au_xattr_list,
33378 + .get = au_xattr_get,
33379 + .set = au_xattr_set
33380 + /* why no remove? */
33383 +static const struct xattr_handler *au_xattr_handlers[] = {
33384 + &au_xattr_handler
33387 +void au_xattr_init(struct super_block *sb)
33389 + /* sb->s_xattr = au_xattr_handlers; */
33392 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33393 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33394 +++ linux/fs/aufs/xino.c 2015-01-25 13:00:38.634380408 +0100
33397 + * Copyright (C) 2005-2014 Junjiro R. Okajima
33399 + * This program, aufs is free software; you can redistribute it and/or modify
33400 + * it under the terms of the GNU General Public License as published by
33401 + * the Free Software Foundation; either version 2 of the License, or
33402 + * (at your option) any later version.
33404 + * This program is distributed in the hope that it will be useful,
33405 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33406 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33407 + * GNU General Public License for more details.
33409 + * You should have received a copy of the GNU General Public License
33410 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33414 + * external inode number translation table and bitmap
33417 +#include <linux/seq_file.h>
33418 +#include <linux/statfs.h>
33421 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33422 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
33426 + mm_segment_t oldfs;
33433 + oldfs = get_fs();
33434 + set_fs(KERNEL_DS);
33436 + /* todo: signal_pending? */
33437 + err = func(file, buf.u, size, pos);
33438 + } while (err == -EAGAIN || err == -EINTR);
33441 +#if 0 /* reserved for future use */
33443 + fsnotify_access(file->f_dentry);
33449 +/* ---------------------------------------------------------------------- */
33451 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
33452 + size_t size, loff_t *pos)
33455 + mm_segment_t oldfs;
33458 + const char __user *u;
33462 + oldfs = get_fs();
33463 + set_fs(KERNEL_DS);
33465 + /* todo: signal_pending? */
33466 + err = func(file, buf.u, size, pos);
33467 + } while (err == -EAGAIN || err == -EINTR);
33470 +#if 0 /* reserved for future use */
33472 + fsnotify_modify(file->f_dentry);
33478 +struct do_xino_fwrite_args {
33480 + au_writef_t func;
33481 + struct file *file;
33487 +static void call_do_xino_fwrite(void *args)
33489 + struct do_xino_fwrite_args *a = args;
33490 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
33493 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
33498 + /* todo: signal block and no wkq? */
33499 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
33501 + err = do_xino_fwrite(func, file, buf, size, pos);
33505 + * it breaks RLIMIT_FSIZE and normal user's limit,
33506 + * users should care about quota and real 'filesystem full.'
33509 + struct do_xino_fwrite_args args = {
33518 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
33519 + if (unlikely(wkq_err))
33526 +/* ---------------------------------------------------------------------- */
33529 + * create a new xinofile at the same place/path as @base_file.
33531 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
33533 + struct file *file;
33534 + struct dentry *base, *parent;
33535 + struct inode *dir, *delegated;
33536 + struct qstr *name;
33537 + struct path path;
33540 + base = base_file->f_dentry;
33541 + parent = base->d_parent; /* dir inode is locked */
33542 + dir = parent->d_inode;
33545 + file = ERR_PTR(-EINVAL);
33546 + name = &base->d_name;
33547 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
33548 + if (IS_ERR(path.dentry)) {
33549 + file = (void *)path.dentry;
33550 + pr_err("%pd lookup err %ld\n",
33551 + base, PTR_ERR(path.dentry));
33555 + /* no need to mnt_want_write() since we call dentry_open() later */
33556 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
33557 + if (unlikely(err)) {
33558 + file = ERR_PTR(err);
33559 + pr_err("%pd create err %d\n", base, err);
33563 + path.mnt = base_file->f_path.mnt;
33564 + file = vfsub_dentry_open(&path,
33565 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33566 + /* | __FMODE_NONOTIFY */);
33567 + if (IS_ERR(file)) {
33568 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
33572 + delegated = NULL;
33573 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
33574 + if (unlikely(err == -EWOULDBLOCK)) {
33575 + pr_warn("cannot retry for NFSv4 delegation"
33576 + " for an internal unlink\n");
33579 + if (unlikely(err)) {
33580 + pr_err("%pd unlink err %d\n", base, err);
33585 + /* no one can touch copy_src xino */
33586 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
33587 + if (unlikely(err)) {
33588 + pr_err("%pd copy err %d\n", base, err);
33592 + goto out_dput; /* success */
33596 + file = ERR_PTR(err);
33598 + dput(path.dentry);
33603 +struct au_xino_lock_dir {
33604 + struct au_hinode *hdir;
33605 + struct dentry *parent;
33606 + struct mutex *mtx;
33609 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
33610 + struct au_xino_lock_dir *ldir)
33612 + aufs_bindex_t brid, bindex;
33614 + ldir->hdir = NULL;
33616 + brid = au_xino_brid(sb);
33618 + bindex = au_br_index(sb, brid);
33619 + if (bindex >= 0) {
33620 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
33621 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
33623 + ldir->parent = dget_parent(xino->f_dentry);
33624 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
33625 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
33629 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
33632 + au_hn_imtx_unlock(ldir->hdir);
33634 + mutex_unlock(ldir->mtx);
33635 + dput(ldir->parent);
33639 +/* ---------------------------------------------------------------------- */
33641 +/* trucate xino files asynchronously */
33643 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
33646 + unsigned long jiffy;
33648 + aufs_bindex_t bi, bend;
33649 + struct kstatfs *st;
33650 + struct au_branch *br;
33651 + struct file *new_xino, *file;
33652 + struct super_block *h_sb;
33653 + struct au_xino_lock_dir ldir;
33656 + st = kzalloc(sizeof(*st), GFP_NOFS);
33657 + if (unlikely(!st))
33661 + bend = au_sbend(sb);
33662 + if (unlikely(bindex < 0 || bend < bindex))
33664 + br = au_sbr(sb, bindex);
33665 + file = br->br_xino.xi_file;
33669 + err = vfs_statfs(&file->f_path, st);
33670 + if (unlikely(err))
33671 + AuErr1("statfs err %d, ignored\n", err);
33673 + blocks = file_inode(file)->i_blocks;
33674 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33675 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
33677 + au_xino_lock_dir(sb, file, &ldir);
33678 + /* mnt_want_write() is unnecessary here */
33679 + new_xino = au_xino_create2(file, file);
33680 + au_xino_unlock_dir(&ldir);
33681 + err = PTR_ERR(new_xino);
33682 + if (IS_ERR(new_xino)) {
33683 + pr_err("err %d, ignored\n", err);
33688 + br->br_xino.xi_file = new_xino;
33690 + h_sb = au_br_sb(br);
33691 + for (bi = 0; bi <= bend; bi++) {
33692 + if (unlikely(bi == bindex))
33694 + br = au_sbr(sb, bi);
33695 + if (au_br_sb(br) != h_sb)
33698 + fput(br->br_xino.xi_file);
33699 + br->br_xino.xi_file = new_xino;
33700 + get_file(new_xino);
33703 + err = vfs_statfs(&new_xino->f_path, st);
33705 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33706 + bindex, (u64)file_inode(new_xino)->i_blocks,
33707 + st->f_bfree, st->f_blocks);
33708 + if (file_inode(new_xino)->i_blocks < blocks)
33709 + au_sbi(sb)->si_xino_jiffy = jiffy;
33711 + AuErr1("statfs err %d, ignored\n", err);
33719 +struct xino_do_trunc_args {
33720 + struct super_block *sb;
33721 + struct au_branch *br;
33724 +static void xino_do_trunc(void *_args)
33726 + struct xino_do_trunc_args *args = _args;
33727 + struct super_block *sb;
33728 + struct au_branch *br;
33729 + struct inode *dir;
33731 + aufs_bindex_t bindex;
33735 + dir = sb->s_root->d_inode;
33738 + si_noflush_write_lock(sb);
33739 + ii_read_lock_parent(dir);
33740 + bindex = au_br_index(sb, br->br_id);
33741 + err = au_xino_trunc(sb, bindex);
33742 + ii_read_unlock(dir);
33743 + if (unlikely(err))
33744 + pr_warn("err b%d, (%d)\n", bindex, err);
33745 + atomic_dec(&br->br_xino_running);
33746 + atomic_dec(&br->br_count);
33747 + si_write_unlock(sb);
33748 + au_nwt_done(&au_sbi(sb)->si_nowait);
33752 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
33755 + struct kstatfs st;
33756 + struct au_sbinfo *sbinfo;
33758 + /* todo: si_xino_expire and the ratio should be customizable */
33759 + sbinfo = au_sbi(sb);
33760 + if (time_before(jiffies,
33761 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
33764 + /* truncation border */
33765 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
33766 + if (unlikely(err)) {
33767 + AuErr1("statfs err %d, ignored\n", err);
33770 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
33776 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
33778 + struct xino_do_trunc_args *args;
33781 + if (!xino_trunc_test(sb, br))
33784 + if (atomic_inc_return(&br->br_xino_running) > 1)
33787 + /* lock and kfree() will be called in trunc_xino() */
33788 + args = kmalloc(sizeof(*args), GFP_NOFS);
33789 + if (unlikely(!args)) {
33790 + AuErr1("no memory\n");
33794 + atomic_inc(&br->br_count);
33797 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
33799 + return; /* success */
33801 + pr_err("wkq %d\n", wkq_err);
33802 + atomic_dec(&br->br_count);
33807 + atomic_dec(&br->br_xino_running);
33810 +/* ---------------------------------------------------------------------- */
33812 +static int au_xino_do_write(au_writef_t write, struct file *file,
33813 + ino_t h_ino, ino_t ino)
33819 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
33820 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
33823 + pos *= sizeof(ino);
33824 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
33825 + if (sz == sizeof(ino))
33826 + return 0; /* success */
33828 + AuIOErr("write failed (%zd)\n", sz);
33833 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
33834 + * at the position of @h_ino.
33835 + * even if @ino is zero, it is written to the xinofile and means no entry.
33836 + * if the size of the xino file on a specific filesystem exceeds the watermark,
33837 + * try truncating it.
33839 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
33843 + unsigned int mnt_flags;
33844 + struct au_branch *br;
33846 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
33847 + || ((loff_t)-1) > 0);
33848 + SiMustAnyLock(sb);
33850 + mnt_flags = au_mntflags(sb);
33851 + if (!au_opt_test(mnt_flags, XINO))
33854 + br = au_sbr(sb, bindex);
33855 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
33858 + if (au_opt_test(mnt_flags, TRUNC_XINO)
33859 + && au_test_fs_trunc_xino(au_br_sb(br)))
33860 + xino_try_trunc(sb, br);
33861 + return 0; /* success */
33864 + AuIOErr("write failed (%d)\n", err);
33868 +/* ---------------------------------------------------------------------- */
33870 +/* aufs inode number bitmap */
33872 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
33873 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
33877 + AuDebugOn(bit < 0 || page_bits <= bit);
33878 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
33882 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
33884 + AuDebugOn(ino < AUFS_FIRST_INO);
33885 + ino -= AUFS_FIRST_INO;
33886 + *pindex = ino / page_bits;
33887 + *bit = ino % page_bits;
33890 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
33895 + struct au_sbinfo *sbinfo;
33896 + struct file *xib;
33897 + unsigned long *p;
33899 + sbinfo = au_sbi(sb);
33900 + MtxMustLock(&sbinfo->si_xib_mtx);
33901 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
33902 + || !au_opt_test(sbinfo->si_mntflags, XINO));
33904 + if (pindex == sbinfo->si_xib_last_pindex)
33907 + xib = sbinfo->si_xib;
33908 + p = sbinfo->si_xib_buf;
33909 + pos = sbinfo->si_xib_last_pindex;
33910 + pos *= PAGE_SIZE;
33911 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
33912 + if (unlikely(sz != PAGE_SIZE))
33916 + pos *= PAGE_SIZE;
33917 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
33918 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
33920 + memset(p, 0, PAGE_SIZE);
33921 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
33923 + if (sz == PAGE_SIZE) {
33924 + sbinfo->si_xib_last_pindex = pindex;
33925 + return 0; /* success */
33929 + AuIOErr1("write failed (%zd)\n", sz);
33936 +/* ---------------------------------------------------------------------- */
33938 +static void au_xib_clear_bit(struct inode *inode)
33941 + unsigned long pindex;
33942 + struct super_block *sb;
33943 + struct au_sbinfo *sbinfo;
33945 + AuDebugOn(inode->i_nlink);
33947 + sb = inode->i_sb;
33948 + xib_calc_bit(inode->i_ino, &pindex, &bit);
33949 + AuDebugOn(page_bits <= bit);
33950 + sbinfo = au_sbi(sb);
33951 + mutex_lock(&sbinfo->si_xib_mtx);
33952 + err = xib_pindex(sb, pindex);
33954 + clear_bit(bit, sbinfo->si_xib_buf);
33955 + sbinfo->si_xib_next_bit = bit;
33957 + mutex_unlock(&sbinfo->si_xib_mtx);
33960 +/* for s_op->delete_inode() */
33961 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
33964 + unsigned int mnt_flags;
33965 + aufs_bindex_t bindex, bend, bi;
33966 + unsigned char try_trunc;
33967 + struct au_iinfo *iinfo;
33968 + struct super_block *sb;
33969 + struct au_hinode *hi;
33970 + struct inode *h_inode;
33971 + struct au_branch *br;
33972 + au_writef_t xwrite;
33974 + sb = inode->i_sb;
33975 + mnt_flags = au_mntflags(sb);
33976 + if (!au_opt_test(mnt_flags, XINO)
33977 + || inode->i_ino == AUFS_ROOT_INO)
33981 + au_xigen_inc(inode);
33982 + au_xib_clear_bit(inode);
33985 + iinfo = au_ii(inode);
33989 + bindex = iinfo->ii_bstart;
33993 + xwrite = au_sbi(sb)->si_xwrite;
33994 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
33995 + hi = iinfo->ii_hinode + bindex;
33996 + bend = iinfo->ii_bend;
33997 + for (; bindex <= bend; bindex++, hi++) {
33998 + h_inode = hi->hi_inode;
34000 + || (!unlinked && h_inode->i_nlink))
34003 + /* inode may not be revalidated */
34004 + bi = au_br_index(sb, hi->hi_id);
34008 + br = au_sbr(sb, bi);
34009 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34010 + h_inode->i_ino, /*ino*/0);
34011 + if (!err && try_trunc
34012 + && au_test_fs_trunc_xino(au_br_sb(br)))
34013 + xino_try_trunc(sb, br);
34017 +/* get an unused inode number from bitmap */
34018 +ino_t au_xino_new_ino(struct super_block *sb)
34021 + unsigned long *p, pindex, ul, pend;
34022 + struct au_sbinfo *sbinfo;
34023 + struct file *file;
34024 + int free_bit, err;
34026 + if (!au_opt_test(au_mntflags(sb), XINO))
34027 + return iunique(sb, AUFS_FIRST_INO);
34029 + sbinfo = au_sbi(sb);
34030 + mutex_lock(&sbinfo->si_xib_mtx);
34031 + p = sbinfo->si_xib_buf;
34032 + free_bit = sbinfo->si_xib_next_bit;
34033 + if (free_bit < page_bits && !test_bit(free_bit, p))
34034 + goto out; /* success */
34035 + free_bit = find_first_zero_bit(p, page_bits);
34036 + if (free_bit < page_bits)
34037 + goto out; /* success */
34039 + pindex = sbinfo->si_xib_last_pindex;
34040 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34041 + err = xib_pindex(sb, ul);
34042 + if (unlikely(err))
34044 + free_bit = find_first_zero_bit(p, page_bits);
34045 + if (free_bit < page_bits)
34046 + goto out; /* success */
34049 + file = sbinfo->si_xib;
34050 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34051 + for (ul = pindex + 1; ul <= pend; ul++) {
34052 + err = xib_pindex(sb, ul);
34053 + if (unlikely(err))
34055 + free_bit = find_first_zero_bit(p, page_bits);
34056 + if (free_bit < page_bits)
34057 + goto out; /* success */
34062 + set_bit(free_bit, p);
34063 + sbinfo->si_xib_next_bit = free_bit + 1;
34064 + pindex = sbinfo->si_xib_last_pindex;
34065 + mutex_unlock(&sbinfo->si_xib_mtx);
34066 + ino = xib_calc_ino(pindex, free_bit);
34067 + AuDbg("i%lu\n", (unsigned long)ino);
34070 + mutex_unlock(&sbinfo->si_xib_mtx);
34076 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34077 + * at the position of @h_ino.
34078 + * if @ino does not exist and @do_new is true, get new one.
34080 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34086 + struct file *file;
34087 + struct au_sbinfo *sbinfo;
34090 + if (!au_opt_test(au_mntflags(sb), XINO))
34091 + return 0; /* no xino */
34094 + sbinfo = au_sbi(sb);
34096 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
34097 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34100 + pos *= sizeof(*ino);
34102 + file = au_sbr(sb, bindex)->br_xino.xi_file;
34103 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
34104 + return 0; /* no ino */
34106 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
34107 + if (sz == sizeof(*ino))
34108 + return 0; /* success */
34111 + if (unlikely(sz >= 0)) {
34113 + AuIOErr("xino read error (%zd)\n", sz);
34119 +/* ---------------------------------------------------------------------- */
34121 +/* create and set a new xino file */
34123 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
34125 + struct file *file;
34126 + struct dentry *h_parent, *d;
34127 + struct inode *h_dir;
34131 + * at mount-time, and the xino file is the default path,
34132 + * hnotify is disabled so we have no notify events to ignore.
34133 + * when a user specified the xino, we cannot get au_hdir to be ignored.
34135 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34136 + /* | __FMODE_NONOTIFY */,
34137 + S_IRUGO | S_IWUGO);
34138 + if (IS_ERR(file)) {
34140 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
34144 + /* keep file count */
34145 + h_parent = dget_parent(file->f_dentry);
34146 + h_dir = h_parent->d_inode;
34147 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
34148 + /* mnt_want_write() is unnecessary here */
34149 + /* no delegation since it is just created */
34150 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
34151 + mutex_unlock(&h_dir->i_mutex);
34153 + if (unlikely(err)) {
34155 + pr_err("unlink %s(%d)\n", fname, err);
34160 + d = file->f_dentry;
34161 + if (unlikely(sb == d->d_sb)) {
34163 + pr_err("%s must be outside\n", fname);
34166 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34168 + pr_err("xino doesn't support %s(%s)\n",
34169 + fname, au_sbtype(d->d_sb));
34172 + return file; /* success */
34176 + file = ERR_PTR(err);
34181 + * find another branch who is on the same filesystem of the specified
34182 + * branch{@btgt}. search until @bend.
34184 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34185 + aufs_bindex_t bend)
34187 + aufs_bindex_t bindex;
34188 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34190 + for (bindex = 0; bindex < btgt; bindex++)
34191 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34193 + for (bindex++; bindex <= bend; bindex++)
34194 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34199 +/* ---------------------------------------------------------------------- */
34202 + * initialize the xinofile for the specified branch @br
34203 + * at the place/path where @base_file indicates.
34204 + * test whether another branch is on the same filesystem or not,
34205 + * if @do_test is true.
34207 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34208 + struct file *base_file, int do_test)
34212 + aufs_bindex_t bend, bindex;
34213 + struct au_branch *shared_br, *b;
34214 + struct file *file;
34215 + struct super_block *tgt_sb;
34217 + shared_br = NULL;
34218 + bend = au_sbend(sb);
34220 + tgt_sb = au_br_sb(br);
34221 + for (bindex = 0; bindex <= bend; bindex++) {
34222 + b = au_sbr(sb, bindex);
34223 + if (tgt_sb == au_br_sb(b)) {
34230 + if (!shared_br || !shared_br->br_xino.xi_file) {
34231 + struct au_xino_lock_dir ldir;
34233 + au_xino_lock_dir(sb, base_file, &ldir);
34234 + /* mnt_want_write() is unnecessary here */
34235 + file = au_xino_create2(base_file, NULL);
34236 + au_xino_unlock_dir(&ldir);
34237 + err = PTR_ERR(file);
34238 + if (IS_ERR(file))
34240 + br->br_xino.xi_file = file;
34242 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34243 + get_file(br->br_xino.xi_file);
34246 + ino = AUFS_ROOT_INO;
34247 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34249 + if (unlikely(err)) {
34250 + fput(br->br_xino.xi_file);
34251 + br->br_xino.xi_file = NULL;
34258 +/* ---------------------------------------------------------------------- */
34260 +/* trucate a xino bitmap file */
34263 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34267 + unsigned long pindex;
34268 + loff_t pos, pend;
34269 + struct au_sbinfo *sbinfo;
34272 + unsigned long *p;
34275 + sbinfo = au_sbi(sb);
34276 + MtxMustLock(&sbinfo->si_xib_mtx);
34277 + p = sbinfo->si_xib_buf;
34278 + func = sbinfo->si_xread;
34279 + pend = vfsub_f_size_read(file);
34281 + while (pos < pend) {
34282 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34284 + if (unlikely(sz <= 0))
34288 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34289 + if (unlikely(*ino < AUFS_FIRST_INO))
34292 + xib_calc_bit(*ino, &pindex, &bit);
34293 + AuDebugOn(page_bits <= bit);
34294 + err = xib_pindex(sb, pindex);
34306 +static int xib_restore(struct super_block *sb)
34309 + aufs_bindex_t bindex, bend;
34313 + page = (void *)__get_free_page(GFP_NOFS);
34314 + if (unlikely(!page))
34318 + bend = au_sbend(sb);
34319 + for (bindex = 0; !err && bindex <= bend; bindex++)
34320 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34321 + err = do_xib_restore
34322 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34324 + AuDbg("b%d\n", bindex);
34325 + free_page((unsigned long)page);
34331 +int au_xib_trunc(struct super_block *sb)
34336 + struct au_xino_lock_dir ldir;
34337 + struct au_sbinfo *sbinfo;
34338 + unsigned long *p;
34339 + struct file *file;
34341 + SiMustWriteLock(sb);
34344 + sbinfo = au_sbi(sb);
34345 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34348 + file = sbinfo->si_xib;
34349 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34352 + au_xino_lock_dir(sb, file, &ldir);
34353 + /* mnt_want_write() is unnecessary here */
34354 + file = au_xino_create2(sbinfo->si_xib, NULL);
34355 + au_xino_unlock_dir(&ldir);
34356 + err = PTR_ERR(file);
34357 + if (IS_ERR(file))
34359 + fput(sbinfo->si_xib);
34360 + sbinfo->si_xib = file;
34362 + p = sbinfo->si_xib_buf;
34363 + memset(p, 0, PAGE_SIZE);
34365 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34366 + if (unlikely(sz != PAGE_SIZE)) {
34368 + AuIOErr("err %d\n", err);
34374 + mutex_lock(&sbinfo->si_xib_mtx);
34375 + /* mnt_want_write() is unnecessary here */
34376 + err = xib_restore(sb);
34377 + mutex_unlock(&sbinfo->si_xib_mtx);
34383 +/* ---------------------------------------------------------------------- */
34386 + * xino mount option handlers
34388 +static au_readf_t find_readf(struct file *h_file)
34390 + const struct file_operations *fop = h_file->f_op;
34393 + return fop->read;
34394 + if (fop->aio_read)
34395 + return do_sync_read;
34396 + if (fop->read_iter)
34397 + return new_sync_read;
34398 + return ERR_PTR(-ENOSYS);
34401 +static au_writef_t find_writef(struct file *h_file)
34403 + const struct file_operations *fop = h_file->f_op;
34406 + return fop->write;
34407 + if (fop->aio_write)
34408 + return do_sync_write;
34409 + if (fop->write_iter)
34410 + return new_sync_write;
34411 + return ERR_PTR(-ENOSYS);
34415 +static void xino_clear_xib(struct super_block *sb)
34417 + struct au_sbinfo *sbinfo;
34419 + SiMustWriteLock(sb);
34421 + sbinfo = au_sbi(sb);
34422 + sbinfo->si_xread = NULL;
34423 + sbinfo->si_xwrite = NULL;
34424 + if (sbinfo->si_xib)
34425 + fput(sbinfo->si_xib);
34426 + sbinfo->si_xib = NULL;
34427 + free_page((unsigned long)sbinfo->si_xib_buf);
34428 + sbinfo->si_xib_buf = NULL;
34431 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34435 + struct au_sbinfo *sbinfo;
34436 + struct file *file;
34438 + SiMustWriteLock(sb);
34440 + sbinfo = au_sbi(sb);
34441 + file = au_xino_create2(base, sbinfo->si_xib);
34442 + err = PTR_ERR(file);
34443 + if (IS_ERR(file))
34445 + if (sbinfo->si_xib)
34446 + fput(sbinfo->si_xib);
34447 + sbinfo->si_xib = file;
34448 + sbinfo->si_xread = find_readf(file);
34449 + sbinfo->si_xwrite = find_writef(file);
34452 + if (!sbinfo->si_xib_buf)
34453 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34454 + if (unlikely(!sbinfo->si_xib_buf))
34457 + sbinfo->si_xib_last_pindex = 0;
34458 + sbinfo->si_xib_next_bit = 0;
34459 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34461 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34462 + PAGE_SIZE, &pos);
34463 + if (unlikely(err != PAGE_SIZE))
34467 + goto out; /* success */
34470 + free_page((unsigned long)sbinfo->si_xib_buf);
34471 + sbinfo->si_xib_buf = NULL;
34475 + fput(sbinfo->si_xib);
34476 + sbinfo->si_xib = NULL;
34477 + sbinfo->si_xread = NULL;
34478 + sbinfo->si_xwrite = NULL;
34483 +/* xino for each branch */
34484 +static void xino_clear_br(struct super_block *sb)
34486 + aufs_bindex_t bindex, bend;
34487 + struct au_branch *br;
34489 + bend = au_sbend(sb);
34490 + for (bindex = 0; bindex <= bend; bindex++) {
34491 + br = au_sbr(sb, bindex);
34492 + if (!br || !br->br_xino.xi_file)
34495 + fput(br->br_xino.xi_file);
34496 + br->br_xino.xi_file = NULL;
34500 +static int au_xino_set_br(struct super_block *sb, struct file *base)
34504 + aufs_bindex_t bindex, bend, bshared;
34506 + struct file *old, *new;
34508 + struct au_branch *br;
34509 + struct inode *inode;
34510 + au_writef_t writef;
34512 + SiMustWriteLock(sb);
34515 + bend = au_sbend(sb);
34516 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
34517 + if (unlikely(!fpair))
34520 + inode = sb->s_root->d_inode;
34521 + ino = AUFS_ROOT_INO;
34522 + writef = au_sbi(sb)->si_xwrite;
34523 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34524 + br = au_sbr(sb, bindex);
34525 + bshared = is_sb_shared(sb, bindex, bindex - 1);
34526 + if (bshared >= 0) {
34527 + /* shared xino */
34528 + *p = fpair[bshared];
34529 + get_file(p->new);
34534 + p->old = br->br_xino.xi_file;
34535 + p->new = au_xino_create2(base, br->br_xino.xi_file);
34536 + err = PTR_ERR(p->new);
34537 + if (IS_ERR(p->new)) {
34543 + err = au_xino_do_write(writef, p->new,
34544 + au_h_iptr(inode, bindex)->i_ino, ino);
34545 + if (unlikely(err))
34549 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34550 + br = au_sbr(sb, bindex);
34551 + if (br->br_xino.xi_file)
34552 + fput(br->br_xino.xi_file);
34553 + get_file(p->new);
34554 + br->br_xino.xi_file = p->new;
34558 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
34568 +void au_xino_clr(struct super_block *sb)
34570 + struct au_sbinfo *sbinfo;
34572 + au_xigen_clr(sb);
34573 + xino_clear_xib(sb);
34574 + xino_clear_br(sb);
34575 + sbinfo = au_sbi(sb);
34576 + /* lvalue, do not call au_mntflags() */
34577 + au_opt_clr(sbinfo->si_mntflags, XINO);
34580 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
34583 + struct dentry *parent, *cur_parent;
34584 + struct qstr *dname, *cur_name;
34585 + struct file *cur_xino;
34586 + struct inode *dir;
34587 + struct au_sbinfo *sbinfo;
34589 + SiMustWriteLock(sb);
34592 + sbinfo = au_sbi(sb);
34593 + parent = dget_parent(xino->file->f_dentry);
34596 + dname = &xino->file->f_dentry->d_name;
34597 + cur_xino = sbinfo->si_xib;
34599 + cur_parent = dget_parent(cur_xino->f_dentry);
34600 + cur_name = &cur_xino->f_dentry->d_name;
34601 + skip = (cur_parent == parent
34602 + && au_qstreq(dname, cur_name));
34603 + dput(cur_parent);
34609 + au_opt_set(sbinfo->si_mntflags, XINO);
34610 + dir = parent->d_inode;
34611 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
34612 + /* mnt_want_write() is unnecessary here */
34613 + err = au_xino_set_xib(sb, xino->file);
34615 + err = au_xigen_set(sb, xino->file);
34617 + err = au_xino_set_br(sb, xino->file);
34618 + mutex_unlock(&dir->i_mutex);
34620 + goto out; /* success */
34623 + AuIOErr("failed creating xino(%d).\n", err);
34624 + au_xigen_clr(sb);
34625 + xino_clear_xib(sb);
34632 +/* ---------------------------------------------------------------------- */
34635 + * create a xinofile at the default place/path.
34637 +struct file *au_xino_def(struct super_block *sb)
34639 + struct file *file;
34641 + struct au_branch *br;
34642 + struct super_block *h_sb;
34643 + struct path path;
34644 + aufs_bindex_t bend, bindex, bwr;
34647 + bend = au_sbend(sb);
34649 + for (bindex = 0; bindex <= bend; bindex++) {
34650 + br = au_sbr(sb, bindex);
34651 + if (au_br_writable(br->br_perm)
34652 + && !au_test_fs_bad_xino(au_br_sb(br))) {
34659 + file = ERR_PTR(-ENOMEM);
34660 + page = (void *)__get_free_page(GFP_NOFS);
34661 + if (unlikely(!page))
34663 + path.mnt = au_br_mnt(br);
34664 + path.dentry = au_h_dptr(sb->s_root, bwr);
34665 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
34666 + file = (void *)p;
34667 + if (!IS_ERR(p)) {
34668 + strcat(p, "/" AUFS_XINO_FNAME);
34669 + AuDbg("%s\n", p);
34670 + file = au_xino_create(sb, p, /*silent*/0);
34671 + if (!IS_ERR(file))
34672 + au_xino_brid_set(sb, br->br_id);
34674 + free_page((unsigned long)page);
34676 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
34677 + if (IS_ERR(file))
34679 + h_sb = file->f_dentry->d_sb;
34680 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
34681 + pr_err("xino doesn't support %s(%s)\n",
34682 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
34684 + file = ERR_PTR(-EINVAL);
34686 + if (!IS_ERR(file))
34687 + au_xino_brid_set(sb, -1);
34694 +/* ---------------------------------------------------------------------- */
34696 +int au_xino_path(struct seq_file *seq, struct file *file)
34700 + err = au_seq_path(seq, &file->f_path);
34701 + if (unlikely(err < 0))
34705 +#define Deleted "\\040(deleted)"
34706 + seq->count -= sizeof(Deleted) - 1;
34707 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
34708 + sizeof(Deleted) - 1));
34714 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
34715 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
34716 +++ linux/include/uapi/linux/aufs_type.h 2015-01-25 13:00:38.637713742 +0100
34719 + * Copyright (C) 2005-2014 Junjiro R. Okajima
34721 + * This program, aufs is free software; you can redistribute it and/or modify
34722 + * it under the terms of the GNU General Public License as published by
34723 + * the Free Software Foundation; either version 2 of the License, or
34724 + * (at your option) any later version.
34726 + * This program is distributed in the hope that it will be useful,
34727 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34728 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34729 + * GNU General Public License for more details.
34731 + * You should have received a copy of the GNU General Public License
34732 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34735 +#ifndef __AUFS_TYPE_H__
34736 +#define __AUFS_TYPE_H__
34738 +#define AUFS_NAME "aufs"
34742 + * define it before including all other headers.
34743 + * sched.h may use pr_* macros before defining "current", so define the
34744 + * no-current version first, and re-define later.
34746 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
34747 +#include <linux/sched.h>
34749 +#define pr_fmt(fmt) \
34750 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
34751 + (int)sizeof(current->comm), current->comm, current->pid
34753 +#include <stdint.h>
34754 +#include <sys/types.h>
34755 +#endif /* __KERNEL__ */
34757 +#include <linux/limits.h>
34759 +#define AUFS_VERSION "3.18.1+-20150119"
34761 +/* todo? move this to linux-2.6.19/include/magic.h */
34762 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
34764 +/* ---------------------------------------------------------------------- */
34766 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
34767 +typedef int8_t aufs_bindex_t;
34768 +#define AUFS_BRANCH_MAX 127
34770 +typedef int16_t aufs_bindex_t;
34771 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
34772 +#define AUFS_BRANCH_MAX 511
34773 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
34774 +#define AUFS_BRANCH_MAX 1023
34775 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
34776 +#define AUFS_BRANCH_MAX 32767
34781 +#ifndef AUFS_BRANCH_MAX
34782 +#error unknown CONFIG_AUFS_BRANCH_MAX value
34784 +#endif /* __KERNEL__ */
34786 +/* ---------------------------------------------------------------------- */
34788 +#define AUFS_FSTYPE AUFS_NAME
34790 +#define AUFS_ROOT_INO 2
34791 +#define AUFS_FIRST_INO 11
34793 +#define AUFS_WH_PFX ".wh."
34794 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
34795 +#define AUFS_WH_TMP_LEN 4
34796 +/* a limit for rmdir/rename a dir and copyup */
34797 +#define AUFS_MAX_NAMELEN (NAME_MAX \
34798 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
34800 + - AUFS_WH_TMP_LEN) /* hex */
34801 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
34802 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
34803 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
34804 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
34805 +#define AUFS_DIRWH_DEF 3
34806 +#define AUFS_RDCACHE_DEF 10 /* seconds */
34807 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
34808 +#define AUFS_RDBLK_DEF 512 /* bytes */
34809 +#define AUFS_RDHASH_DEF 32
34810 +#define AUFS_WKQ_NAME AUFS_NAME "d"
34811 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
34812 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
34813 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
34814 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
34816 +/* pseudo-link maintenace under /proc */
34817 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
34818 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
34819 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
34821 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
34822 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
34824 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
34825 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
34826 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
34828 +/* doubly whiteouted */
34829 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
34830 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
34831 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
34833 +/* branch permissions and attributes */
34834 +#define AUFS_BRPERM_RW "rw"
34835 +#define AUFS_BRPERM_RO "ro"
34836 +#define AUFS_BRPERM_RR "rr"
34837 +#define AUFS_BRATTR_COO_REG "coo_reg"
34838 +#define AUFS_BRATTR_COO_ALL "coo_all"
34839 +#define AUFS_BRATTR_FHSM "fhsm"
34840 +#define AUFS_BRATTR_UNPIN "unpin"
34841 +#define AUFS_BRATTR_ICEX "icex"
34842 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
34843 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
34844 +#define AUFS_BRATTR_ICEX_TR "icextr"
34845 +#define AUFS_BRATTR_ICEX_USR "icexusr"
34846 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
34847 +#define AUFS_BRRATTR_WH "wh"
34848 +#define AUFS_BRWATTR_NLWH "nolwh"
34849 +#define AUFS_BRWATTR_MOO "moo"
34851 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
34852 +#define AuBrPerm_RO (1 << 1) /* readonly */
34853 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
34854 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
34856 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
34857 +#define AuBrAttr_COO_ALL (1 << 4)
34858 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
34860 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
34861 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
34862 + branch. meaningless since
34863 + linux-3.18-rc1 */
34865 +/* ignore error in copying XATTR */
34866 +#define AuBrAttr_ICEX_SEC (1 << 7)
34867 +#define AuBrAttr_ICEX_SYS (1 << 8)
34868 +#define AuBrAttr_ICEX_TR (1 << 9)
34869 +#define AuBrAttr_ICEX_USR (1 << 10)
34870 +#define AuBrAttr_ICEX_OTH (1 << 11)
34871 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
34872 + | AuBrAttr_ICEX_SYS \
34873 + | AuBrAttr_ICEX_TR \
34874 + | AuBrAttr_ICEX_USR \
34875 + | AuBrAttr_ICEX_OTH)
34877 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
34878 +#define AuBrRAttr_Mask AuBrRAttr_WH
34880 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
34881 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
34882 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
34884 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
34886 +/* #warning test userspace */
34888 +#ifndef CONFIG_AUFS_FHSM
34889 +#undef AuBrAttr_FHSM
34890 +#define AuBrAttr_FHSM 0
34892 +#ifndef CONFIG_AUFS_XATTR
34893 +#undef AuBrAttr_ICEX
34894 +#define AuBrAttr_ICEX 0
34895 +#undef AuBrAttr_ICEX_SEC
34896 +#define AuBrAttr_ICEX_SEC 0
34897 +#undef AuBrAttr_ICEX_SYS
34898 +#define AuBrAttr_ICEX_SYS 0
34899 +#undef AuBrAttr_ICEX_TR
34900 +#define AuBrAttr_ICEX_TR 0
34901 +#undef AuBrAttr_ICEX_USR
34902 +#define AuBrAttr_ICEX_USR 0
34903 +#undef AuBrAttr_ICEX_OTH
34904 +#define AuBrAttr_ICEX_OTH 0
34908 +/* the longest combination */
34909 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
34910 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
34911 + "+" AUFS_BRATTR_COO_REG \
34912 + "+" AUFS_BRATTR_FHSM \
34913 + "+" AUFS_BRATTR_UNPIN \
34914 + "+" AUFS_BRATTR_ICEX_SEC \
34915 + "+" AUFS_BRATTR_ICEX_SYS \
34916 + "+" AUFS_BRATTR_ICEX_USR \
34917 + "+" AUFS_BRATTR_ICEX_OTH \
34918 + "+" AUFS_BRWATTR_NLWH)
34921 + char a[AuBrPermStrSz];
34922 +} au_br_perm_str_t;
34924 +static inline int au_br_writable(int brperm)
34926 + return brperm & AuBrPerm_RW;
34929 +static inline int au_br_whable(int brperm)
34931 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
34934 +static inline int au_br_wh_linkable(int brperm)
34936 + return !(brperm & AuBrWAttr_NoLinkWH);
34939 +static inline int au_br_cmoo(int brperm)
34941 + return brperm & AuBrAttr_CMOO_Mask;
34944 +static inline int au_br_fhsm(int brperm)
34946 + return brperm & AuBrAttr_FHSM;
34949 +/* ---------------------------------------------------------------------- */
34953 + /* readdir in userspace */
34957 + AuCtl_WBR_FD, /* pathconf wrapper */
34958 + AuCtl_IBUSY, /* busy inode */
34959 + AuCtl_MVDOWN, /* move-down */
34960 + AuCtl_BR, /* info about branches */
34961 + AuCtl_FHSM_FD /* connection for fhsm */
34964 +/* borrowed from linux/include/linux/kernel.h */
34966 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
34967 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
34970 +/* borrowed from linux/include/linux/compiler-gcc3.h */
34972 +#define __aligned(x) __attribute__((aligned(x)))
34977 +#define __packed __attribute__((packed))
34981 +struct au_rdu_cookie {
34986 + uint32_t generation;
34989 +struct au_rdu_ent {
34998 +static inline int au_rdu_len(int nlen)
35000 + /* include the terminating NULL */
35001 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35002 + sizeof(uint64_t));
35005 +union au_rdu_ent_ul {
35006 + struct au_rdu_ent __user *e;
35018 + uint64_t sz; /* AuCtl_RDU */
35019 + uint64_t nent; /* AuCtl_RDU_INO */
35021 + union au_rdu_ent_ul ent;
35022 + uint16_t verify[AufsCtlRduV_End];
35024 + /* input/output */
35028 + union au_rdu_ent_ul tail;
35029 + /* number of entries which were added in a single call */
35034 + struct au_rdu_cookie cookie;
35037 +/* ---------------------------------------------------------------------- */
35039 +struct aufs_wbr_fd {
35044 +/* ---------------------------------------------------------------------- */
35046 +struct aufs_ibusy {
35047 + uint64_t ino, h_ino;
35051 +/* ---------------------------------------------------------------------- */
35053 +/* error code for move-down */
35054 +/* the actual message strings are implemented in aufs-util.git */
35056 + EAU_MVDOWN_OPAQUE = 1,
35057 + EAU_MVDOWN_WHITEOUT,
35058 + EAU_MVDOWN_UPPER,
35059 + EAU_MVDOWN_BOTTOM,
35060 + EAU_MVDOWN_NOUPPER,
35061 + EAU_MVDOWN_NOLOWERBR,
35065 +/* flags for move-down */
35066 +#define AUFS_MVDOWN_DMSG 1
35067 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35068 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35069 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35070 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35071 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35072 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35073 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35074 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35075 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35076 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35077 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35078 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35080 +/* index for move-down */
35082 + AUFS_MVDOWN_UPPER,
35083 + AUFS_MVDOWN_LOWER,
35084 + AUFS_MVDOWN_NARRAY
35088 + * additional info of move-down
35089 + * number of free blocks and inodes.
35090 + * subset of struct kstatfs, but smaller and always 64bit.
35092 +struct aufs_stfs {
35093 + uint64_t f_blocks;
35094 + uint64_t f_bavail;
35095 + uint64_t f_files;
35096 + uint64_t f_ffree;
35099 +struct aufs_stbr {
35100 + int16_t brid; /* optional input */
35101 + int16_t bindex; /* output */
35102 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35105 +struct aufs_mvdown {
35106 + uint32_t flags; /* input/output */
35107 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35108 + int8_t au_errno; /* output */
35111 +/* ---------------------------------------------------------------------- */
35113 +union aufs_brinfo {
35114 + /* PATH_MAX may differ between kernel-space and user-space */
35115 + char _spacer[4096];
35123 +/* ---------------------------------------------------------------------- */
35125 +#define AuCtlType 'A'
35126 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35127 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35128 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35129 + struct aufs_wbr_fd)
35130 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35131 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35132 + struct aufs_mvdown)
35133 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35134 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35136 +#endif /* __AUFS_TYPE_H__ */
35137 aufs3.18.1+ loopback patch
35139 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
35140 index 30efd68..77b31b4 100644
35141 --- a/drivers/block/loop.c
35142 +++ b/drivers/block/loop.c
35143 @@ -514,7 +514,7 @@ out:
35146 struct switch_request {
35147 - struct file *file;
35148 + struct file *file, *virt_file;
35149 struct completion wait;
35152 @@ -576,7 +576,8 @@ static int loop_thread(void *data)
35153 * First it needs to flush existing IO, it does this by sending a magic
35154 * BIO down the pipe. The completion of this BIO does the actual switch.
35156 -static int loop_switch(struct loop_device *lo, struct file *file)
35157 +static int loop_switch(struct loop_device *lo, struct file *file,
35158 + struct file *virt_file)
35160 struct switch_request w;
35161 struct bio *bio = bio_alloc(GFP_KERNEL, 0);
35162 @@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file)
35164 init_completion(&w.wait);
35166 + w.virt_file = virt_file;
35167 bio->bi_private = &w;
35168 bio->bi_bdev = NULL;
35169 loop_make_request(lo->lo_queue, bio);
35170 @@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo)
35171 if (!lo->lo_thread)
35174 - return loop_switch(lo, NULL);
35175 + return loop_switch(lo, NULL, NULL);
35179 @@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35180 mapping = file->f_mapping;
35181 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
35182 lo->lo_backing_file = file;
35183 + lo->lo_backing_virt_file = p->virt_file;
35184 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
35185 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
35186 lo->old_gfp_mask = mapping_gfp_mask(mapping);
35187 @@ -627,6 +630,13 @@ out:
35188 complete(&p->wait);
35191 +static struct file *loop_real_file(struct file *file)
35193 + struct file *f = NULL;
35194 + if (file->f_dentry->d_sb->s_op->real_loop)
35195 + f = file->f_dentry->d_sb->s_op->real_loop(file);
35200 * loop_change_fd switched the backing store of a loopback device to
35201 @@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35204 struct file *file, *old_file;
35205 + struct file *f, *virt_file = NULL, *old_virt_file;
35206 struct inode *inode;
35209 @@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35213 + f = loop_real_file(file);
35215 + virt_file = file;
35220 inode = file->f_mapping->host;
35221 old_file = lo->lo_backing_file;
35222 + old_virt_file = lo->lo_backing_virt_file;
35226 @@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35229 /* and ... switch */
35230 - error = loop_switch(lo, file);
35231 + error = loop_switch(lo, file, virt_file);
35236 + if (old_virt_file)
35237 + fput(old_virt_file);
35238 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
35239 ioctl_by_bdev(bdev, BLKRRPART, 0);
35249 @@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo)
35250 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35251 struct block_device *bdev, unsigned int arg)
35253 - struct file *file, *f;
35254 + struct file *file, *f, *virt_file = NULL;
35255 struct inode *inode;
35256 struct address_space *mapping;
35257 unsigned lo_blocksize;
35258 @@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35262 + f = loop_real_file(file);
35264 + virt_file = file;
35270 if (lo->lo_state != Lo_unbound)
35271 @@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35272 lo->lo_device = bdev;
35273 lo->lo_flags = lo_flags;
35274 lo->lo_backing_file = file;
35275 + lo->lo_backing_virt_file = virt_file;
35276 lo->transfer = transfer_none;
35278 lo->lo_sizelimit = 0;
35279 @@ -948,6 +977,7 @@ out_clr:
35280 lo->lo_thread = NULL;
35281 lo->lo_device = NULL;
35282 lo->lo_backing_file = NULL;
35283 + lo->lo_backing_virt_file = NULL;
35285 set_capacity(lo->lo_disk, 0);
35286 invalidate_bdev(bdev);
35287 @@ -957,6 +987,8 @@ out_clr:
35288 lo->lo_state = Lo_unbound;
35294 /* This is safe: open() is still holding a reference. */
35295 module_put(THIS_MODULE);
35296 @@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
35297 static int loop_clr_fd(struct loop_device *lo)
35299 struct file *filp = lo->lo_backing_file;
35300 + struct file *virt_filp = lo->lo_backing_virt_file;
35301 gfp_t gfp = lo->old_gfp_mask;
35302 struct block_device *bdev = lo->lo_device;
35304 @@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo)
35306 spin_lock_irq(&lo->lo_lock);
35307 lo->lo_backing_file = NULL;
35308 + lo->lo_backing_virt_file = NULL;
35309 spin_unlock_irq(&lo->lo_lock);
35311 loop_release_xfer(lo);
35312 @@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo)
35313 * bd_mutex which is usually taken before lo_ctl_mutex.
35321 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
35322 index 90df5d6..cb91822 100644
35323 --- a/drivers/block/loop.h
35324 +++ b/drivers/block/loop.h
35325 @@ -44,7 +44,7 @@ struct loop_device {
35326 int (*ioctl)(struct loop_device *, int cmd,
35327 unsigned long arg);
35329 - struct file * lo_backing_file;
35330 + struct file * lo_backing_file, *lo_backing_virt_file;
35331 struct block_device *lo_device;
35332 unsigned lo_blocksize;
35334 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
35335 index 3dd9138..63a424c 100644
35336 --- a/fs/aufs/f_op.c
35337 +++ b/fs/aufs/f_op.c
35338 @@ -367,7 +367,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
35340 h_file = au_hf_top(file);
35342 - if (au_test_loopback_kthread()) {
35343 + if (0 && au_test_loopback_kthread()) {
35344 au_warn_loopback(h_file->f_dentry->d_sb);
35345 if (file->f_mapping != h_file->f_mapping) {
35346 file->f_mapping = h_file->f_mapping;
35347 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
35348 index 3b03b52..4ab749d 100644
35349 --- a/fs/aufs/loop.c
35350 +++ b/fs/aufs/loop.c
35351 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
35352 symbol_put(loop_backing_file);
35353 kfree(au_warn_loopback_array);
35356 +/* ---------------------------------------------------------------------- */
35358 +/* support the loopback block device insude aufs */
35360 +struct file *aufs_real_loop(struct file *file)
35364 + BUG_ON(!au_test_aufs(file->f_dentry->d_sb));
35365 + fi_read_lock(file);
35366 + f = au_hf_top(file);
35367 + fi_read_unlock(file);
35371 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
35372 index da8b756..28cb7ea 100644
35373 --- a/fs/aufs/loop.h
35374 +++ b/fs/aufs/loop.h
35375 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
35377 int au_loopback_init(void);
35378 void au_loopback_fin(void);
35380 +struct file *aufs_real_loop(struct file *file);
35382 +AuStub(struct file *, loop_backing_file, return NULL)
35384 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
35385 struct dentry *h_adding)
35386 AuStubInt0(au_test_loopback_kthread, void)
35387 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
35389 AuStubInt0(au_loopback_init, void)
35390 AuStubVoid(au_loopback_fin, void)
35392 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
35393 #endif /* BLK_DEV_LOOP */
35395 #endif /* __KERNEL__ */
35396 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
35397 index 2ec0b4f..65a6781 100644
35398 --- a/fs/aufs/super.c
35399 +++ b/fs/aufs/super.c
35400 @@ -812,7 +812,10 @@ static const struct super_operations aufs_sop = {
35401 .statfs = aufs_statfs,
35402 .put_super = aufs_put_super,
35403 .sync_fs = aufs_sync_fs,
35404 - .remount_fs = aufs_remount_fs
35405 + .remount_fs = aufs_remount_fs,
35406 +#ifdef CONFIG_AUFS_BDEV_LOOP
35407 + .real_loop = aufs_real_loop
35411 /* ---------------------------------------------------------------------- */
35412 diff --git a/include/linux/fs.h b/include/linux/fs.h
35413 index aabcbba..1a634f5 100644
35414 --- a/include/linux/fs.h
35415 +++ b/include/linux/fs.h
35416 @@ -1594,6 +1594,10 @@ struct super_operations {
35417 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
35418 long (*nr_cached_objects)(struct super_block *, int);
35419 long (*free_cached_objects)(struct super_block *, long, int);
35420 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
35422 + struct file *(*real_loop)(struct file *);
35427 diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
35428 index 50777b5..f9c6b3d 100644
35429 --- a/include/linux/shmem_fs.h
35430 +++ b/include/linux/shmem_fs.h
35431 @@ -26,10 +26,13 @@ struct shmem_inode_info {
35434 struct shmem_sb_info {
35435 + struct mutex idr_lock;
35437 + struct idr idr; /* manages inode-number */
35438 unsigned long max_blocks; /* How many blocks are allowed */
35439 struct percpu_counter used_blocks; /* How many are allocated */
35440 - unsigned long max_inodes; /* How many inodes are allowed */
35441 - unsigned long free_inodes; /* How many are left for allocation */
35442 + int max_inodes; /* How many inodes are allowed */
35443 + int free_inodes; /* How many are left for allocation */
35444 spinlock_t stat_lock; /* Serialize shmem_sb_info changes */
35445 kuid_t uid; /* Mount uid for root directory */
35446 kgid_t gid; /* Mount gid for root directory */
35447 diff --git a/mm/shmem.c b/mm/shmem.c
35448 index 185836b..ac7f9fb 100644
35451 @@ -110,9 +110,13 @@ static unsigned long shmem_default_max_blocks(void)
35452 return totalram_pages / 2;
35455 -static unsigned long shmem_default_max_inodes(void)
35456 +static int shmem_default_max_inodes(void)
35458 - return min(totalram_pages - totalhigh_pages, totalram_pages / 2);
35459 + unsigned long ul;
35462 + ul = min3(ul, totalram_pages - totalhigh_pages, totalram_pages / 2);
35467 @@ -592,6 +596,7 @@ static int shmem_setattr(struct dentry *dentry, struct iattr *attr)
35468 static void shmem_evict_inode(struct inode *inode)
35470 struct shmem_inode_info *info = SHMEM_I(inode);
35471 + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
35473 if (inode->i_mapping->a_ops == &shmem_aops) {
35474 shmem_unacct_size(info->flags, inode->i_size);
35475 @@ -607,6 +612,11 @@ static void shmem_evict_inode(struct inode *inode)
35477 simple_xattrs_free(&info->xattrs);
35478 WARN_ON(inode->i_blocks);
35479 + if (!sbinfo->idr_nouse && inode->i_ino) {
35480 + mutex_lock(&sbinfo->idr_lock);
35481 + idr_remove(&sbinfo->idr, inode->i_ino);
35482 + mutex_unlock(&sbinfo->idr_lock);
35484 shmem_free_inode(inode->i_sb);
35485 clear_inode(inode);
35487 @@ -1406,13 +1416,13 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
35488 struct inode *inode;
35489 struct shmem_inode_info *info;
35490 struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
35493 if (shmem_reserve_inode(sb))
35496 inode = new_inode(sb);
35498 - inode->i_ino = get_next_ino();
35499 inode_init_owner(inode, dir, mode);
35500 inode->i_blocks = 0;
35501 inode->i_mapping->backing_dev_info = &shmem_backing_dev_info;
35502 @@ -1454,6 +1464,25 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
35503 mpol_shared_policy_init(&info->policy, NULL);
35507 + if (!sbinfo->idr_nouse) {
35508 + /* inum 0 and 1 are unused */
35509 + mutex_lock(&sbinfo->idr_lock);
35510 + ino = idr_alloc(&sbinfo->idr, inode, 2, INT_MAX,
35513 + inode->i_ino = ino;
35514 + mutex_unlock(&sbinfo->idr_lock);
35515 + __insert_inode_hash(inode, inode->i_ino);
35517 + inode->i_ino = 0;
35518 + mutex_unlock(&sbinfo->idr_lock);
35520 + /* shmem_free_inode() will be called */
35524 + inode->i_ino = get_next_ino();
35526 shmem_free_inode(sb);
35528 @@ -2674,8 +2703,7 @@ static struct dentry *shmem_get_parent(struct dentry *child)
35529 static int shmem_match(struct inode *ino, void *vfh)
35532 - __u64 inum = fh[2];
35533 - inum = (inum << 32) | fh[1];
35534 + __u64 inum = fh[1];
35535 return ino->i_ino == inum && fh[0] == ino->i_generation;
35538 @@ -2686,14 +2714,11 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb,
35539 struct dentry *dentry = NULL;
35546 - inum = fid->raw[2];
35547 - inum = (inum << 32) | fid->raw[1];
35549 - inode = ilookup5(sb, (unsigned long)(inum + fid->raw[0]),
35550 - shmem_match, fid->raw);
35551 + inum = fid->raw[1];
35552 + inode = ilookup5(sb, inum, shmem_match, fid->raw);
35554 dentry = d_find_alias(inode);
35556 @@ -2705,30 +2730,15 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb,
35557 static int shmem_encode_fh(struct inode *inode, __u32 *fh, int *len,
35558 struct inode *parent)
35564 return FILEID_INVALID;
35567 - if (inode_unhashed(inode)) {
35568 - /* Unfortunately insert_inode_hash is not idempotent,
35569 - * so as we hash inodes here rather than at creation
35570 - * time, we need a lock to ensure we only try
35573 - static DEFINE_SPINLOCK(lock);
35574 - spin_lock(&lock);
35575 - if (inode_unhashed(inode))
35576 - __insert_inode_hash(inode,
35577 - inode->i_ino + inode->i_generation);
35578 - spin_unlock(&lock);
35581 fh[0] = inode->i_generation;
35582 fh[1] = inode->i_ino;
35583 - fh[2] = ((__u64)inode->i_ino) >> 32;
35590 @@ -2793,7 +2803,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
35592 } else if (!strcmp(this_char,"nr_inodes")) {
35593 sbinfo->max_inodes = memparse(value, &rest);
35595 + if (*rest || sbinfo->max_inodes < 2)
35597 } else if (!strcmp(this_char,"mode")) {
35599 @@ -2846,7 +2856,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
35601 struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
35602 struct shmem_sb_info config = *sbinfo;
35603 - unsigned long inodes;
35605 int error = -EINVAL;
35607 config.mpol = NULL;
35608 @@ -2894,7 +2904,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root)
35609 seq_printf(seq, ",size=%luk",
35610 sbinfo->max_blocks << (PAGE_CACHE_SHIFT - 10));
35611 if (sbinfo->max_inodes != shmem_default_max_inodes())
35612 - seq_printf(seq, ",nr_inodes=%lu", sbinfo->max_inodes);
35613 + seq_printf(seq, ",nr_inodes=%d", sbinfo->max_inodes);
35614 if (sbinfo->mode != (S_IRWXUGO | S_ISVTX))
35615 seq_printf(seq, ",mode=%03ho", sbinfo->mode);
35616 if (!uid_eq(sbinfo->uid, GLOBAL_ROOT_UID))
35617 @@ -2983,6 +2993,8 @@ static void shmem_put_super(struct super_block *sb)
35619 struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
35621 + if (!sbinfo->idr_nouse)
35622 + idr_destroy(&sbinfo->idr);
35623 percpu_counter_destroy(&sbinfo->used_blocks);
35624 mpol_put(sbinfo->mpol);
35626 @@ -3001,6 +3013,8 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
35630 + mutex_init(&sbinfo->idr_lock);
35631 + idr_init(&sbinfo->idr);
35632 sbinfo->mode = S_IRWXUGO | S_ISVTX;
35633 sbinfo->uid = current_fsuid();
35634 sbinfo->gid = current_fsgid();
35635 @@ -3104,6 +3118,15 @@ static void shmem_destroy_inodecache(void)
35636 kmem_cache_destroy(shmem_inode_cachep);
35639 +static __init void shmem_no_idr(struct super_block *sb)
35641 + struct shmem_sb_info *sbinfo;
35643 + sbinfo = SHMEM_SB(sb);
35644 + sbinfo->idr_nouse = true;
35645 + idr_destroy(&sbinfo->idr);
35648 static const struct address_space_operations shmem_aops = {
35649 .writepage = shmem_writepage,
35650 .set_page_dirty = __set_page_dirty_no_writeback,
35651 @@ -3246,6 +3269,7 @@ int __init shmem_init(void)
35652 printk(KERN_ERR "Could not kern_mount tmpfs\n");
35655 + shmem_no_idr(shm_mnt->mnt_sb);
35659 diff --git a/fs/inode.c b/fs/inode.c
35660 index 26753ba..61e0af2 100644
35663 @@ -840,6 +840,8 @@ unsigned int get_next_ino(void)
35664 unsigned int *p = &get_cpu_var(last_ino);
35665 unsigned int res = *p;
35670 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
35671 static atomic_t shared_last_ino;
35672 @@ -849,7 +851,9 @@ unsigned int get_next_ino(void)
35677 + if (unlikely(!++res))
35678 + goto start; /* never zero */
35680 put_cpu_var(last_ino);