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
32 +header-y += aufs_type.h
34 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 = do_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 @@ -298,6 +299,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
771 sb_end_write(inode->i_sb);
774 +EXPORT_SYMBOL(do_fallocate);
776 SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
778 diff --git a/fs/splice.c b/fs/splice.c
779 index 619359a..c14f60e 100644
782 @@ -1127,6 +1127,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
784 return splice_write(pipe, out, ppos, len, flags);
786 +EXPORT_SYMBOL(do_splice_from);
789 * Attempt to initiate a splice from a file to a pipe.
790 @@ -1153,6 +1154,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
792 return splice_read(in, ppos, pipe, len, flags);
794 +EXPORT_SYMBOL(do_splice_to);
797 * splice_direct_to_actor - splices data directly between two non-pipes
798 diff --git a/fs/xattr.c b/fs/xattr.c
799 index 64e83ef..bd71e53 100644
802 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
803 *xattr_value = value;
806 +EXPORT_SYMBOL(vfs_getxattr_alloc);
808 /* Compare an extended attribute value with the given value */
809 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
810 diff --git a/security/commoncap.c b/security/commoncap.c
811 index bab0611..3fa2f82 100644
812 --- a/security/commoncap.c
813 +++ b/security/commoncap.c
814 @@ -979,9 +979,11 @@ int cap_mmap_addr(unsigned long addr)
818 +EXPORT_SYMBOL(cap_mmap_addr);
820 int cap_mmap_file(struct file *file, unsigned long reqprot,
821 unsigned long prot, unsigned long flags)
825 +EXPORT_SYMBOL(cap_mmap_file);
826 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
827 index 188c1d2..426d9af 100644
828 --- a/security/device_cgroup.c
829 +++ b/security/device_cgroup.c
831 #include <linux/device_cgroup.h>
832 #include <linux/cgroup.h>
833 #include <linux/ctype.h>
834 +#include <linux/export.h>
835 #include <linux/list.h>
836 #include <linux/uaccess.h>
837 #include <linux/seq_file.h>
838 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
839 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
842 +EXPORT_SYMBOL(__devcgroup_inode_permission);
844 int devcgroup_inode_mknod(int mode, dev_t dev)
846 diff --git a/security/security.c b/security/security.c
847 index 18b35c6..12c67af 100644
848 --- a/security/security.c
849 +++ b/security/security.c
850 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
852 return security_ops->path_rmdir(dir, dentry);
854 +EXPORT_SYMBOL(security_path_rmdir);
856 int security_path_unlink(struct path *dir, struct dentry *dentry)
858 @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
860 return security_ops->path_symlink(dir, dentry, old_name);
862 +EXPORT_SYMBOL(security_path_symlink);
864 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
865 struct dentry *new_dentry)
866 @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
868 return security_ops->path_link(old_dentry, new_dir, new_dentry);
870 +EXPORT_SYMBOL(security_path_link);
872 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
873 struct path *new_dir, struct dentry *new_dentry,
874 @@ -458,6 +461,7 @@ int security_path_truncate(struct path *path)
876 return security_ops->path_truncate(path);
878 +EXPORT_SYMBOL(security_path_truncate);
880 int security_path_chmod(struct path *path, umode_t mode)
882 @@ -465,6 +469,7 @@ int security_path_chmod(struct path *path, umode_t mode)
884 return security_ops->path_chmod(path, mode);
886 +EXPORT_SYMBOL(security_path_chmod);
888 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
890 @@ -472,6 +477,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
892 return security_ops->path_chown(path, uid, gid);
894 +EXPORT_SYMBOL(security_path_chown);
896 int security_path_chroot(struct path *path)
898 @@ -557,6 +563,7 @@ int security_inode_readlink(struct dentry *dentry)
900 return security_ops->inode_readlink(dentry);
902 +EXPORT_SYMBOL(security_inode_readlink);
904 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
906 @@ -571,6 +578,7 @@ int security_inode_permission(struct inode *inode, int mask)
908 return security_ops->inode_permission(inode, mask);
910 +EXPORT_SYMBOL(security_inode_permission);
912 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
914 @@ -693,6 +701,7 @@ int security_file_permission(struct file *file, int mask)
916 return fsnotify_perm(file, mask);
918 +EXPORT_SYMBOL(security_file_permission);
920 int security_file_alloc(struct file *file)
922 @@ -753,6 +762,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
924 return ima_file_mmap(file, prot);
926 +EXPORT_SYMBOL(security_mmap_file);
928 int security_mmap_addr(unsigned long addr)
930 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
931 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
932 +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-01-25 13:00:38.627713742 +0100
934 +What: /debug/aufs/si_<id>/
936 +Contact: J. R. Okajima <hooanon05g@gmail.com>
938 + Under /debug/aufs, a directory named si_<id> is created
939 + per aufs mount, where <id> is a unique id generated
942 +What: /debug/aufs/si_<id>/plink
944 +Contact: J. R. Okajima <hooanon05g@gmail.com>
946 + It has three lines and shows the information about the
947 + pseudo-link. The first line is a single number
948 + representing a number of buckets. The second line is a
949 + number of pseudo-links per buckets (separated by a
950 + blank). The last line is a single number representing a
951 + total number of psedo-links.
952 + When the aufs mount option 'noplink' is specified, it
953 + will show "1\n0\n0\n".
955 +What: /debug/aufs/si_<id>/xib
957 +Contact: J. R. Okajima <hooanon05g@gmail.com>
959 + It shows the consumed blocks by xib (External Inode Number
960 + Bitmap), its block size and file size.
961 + When the aufs mount option 'noxino' is specified, it
962 + will be empty. About XINO files, see the aufs manual.
964 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
966 +Contact: J. R. Okajima <hooanon05g@gmail.com>
968 + It shows the consumed blocks by xino (External Inode Number
969 + Translation Table), its link count, block size and file
971 + When the aufs mount option 'noxino' is specified, it
972 + will be empty. About XINO files, see the aufs manual.
974 +What: /debug/aufs/si_<id>/xigen
976 +Contact: J. R. Okajima <hooanon05g@gmail.com>
978 + It shows the consumed blocks by xigen (External Inode
979 + Generation Table), its block size and file size.
980 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
982 + When the aufs mount option 'noxino' is specified, it
983 + will be empty. About XINO files, see the aufs manual.
984 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
985 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
986 +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-01-25 13:00:38.627713742 +0100
988 +What: /sys/fs/aufs/si_<id>/
990 +Contact: J. R. Okajima <hooanon05g@gmail.com>
992 + Under /sys/fs/aufs, a directory named si_<id> is created
993 + per aufs mount, where <id> is a unique id generated
996 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
998 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1000 + It shows the abolute path of a member directory (which
1001 + is called branch) in aufs, and its permission.
1003 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1005 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1007 + It shows the id of a member directory (which is called
1010 +What: /sys/fs/aufs/si_<id>/xi_path
1012 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1014 + It shows the abolute path of XINO (External Inode Number
1015 + Bitmap, Translation Table and Generation Table) file
1016 + even if it is the default path.
1017 + When the aufs mount option 'noxino' is specified, it
1018 + will be empty. About XINO files, see the aufs manual.
1019 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1020 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1021 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-01-25 13:00:38.627713742 +0100
1024 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1026 +# This program is free software; you can redistribute it and/or modify
1027 +# it under the terms of the GNU General Public License as published by
1028 +# the Free Software Foundation; either version 2 of the License, or
1029 +# (at your option) any later version.
1031 +# This program is distributed in the hope that it will be useful,
1032 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1033 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1034 +# GNU General Public License for more details.
1036 +# You should have received a copy of the GNU General Public License
1037 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1040 +----------------------------------------
1042 +aufs [ei ju: ef es] | [a u f s]
1043 +1. abbrev. for "advanced multi-layered unification filesystem".
1044 +2. abbrev. for "another unionfs".
1045 +3. abbrev. for "auf das" in German which means "on the" in English.
1046 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1047 + But "Filesystem aufs Filesystem" is hard to understand.
1049 +AUFS is a filesystem with features:
1050 +- multi layered stackable unification filesystem, the member directory
1051 + is called as a branch.
1052 +- branch permission and attribute, 'readonly', 'real-readonly',
1053 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
1055 +- internal "file copy-on-write".
1056 +- logical deletion, whiteout.
1057 +- dynamic branch manipulation, adding, deleting and changing permission.
1058 +- allow bypassing aufs, user's direct branch access.
1059 +- external inode number translation table and bitmap which maintains the
1060 + persistent aufs inode number.
1061 +- seekable directory, including NFS readdir.
1062 +- file mapping, mmap and sharing pages.
1063 +- pseudo-link, hardlink over branches.
1064 +- loopback mounted filesystem as a branch.
1065 +- several policies to select one among multiple writable branches.
1066 +- revert a single systemcall when an error occurs in aufs.
1070 +Multi Layered Stackable Unification Filesystem
1071 +----------------------------------------------------------------------
1072 +Most people already knows what it is.
1073 +It is a filesystem which unifies several directories and provides a
1074 +merged single directory. When users access a file, the access will be
1075 +passed/re-directed/converted (sorry, I am not sure which English word is
1076 +correct) to the real file on the member filesystem. The member
1077 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1078 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1079 +readonly branch is handled by creating 'whiteout' on the upper writable
1082 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1083 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1084 +different approaches to implement the merged-view.
1085 +The former tries putting it into VFS, and the latter implements as a
1086 +separate filesystem.
1087 +(If I misunderstand about these implementations, please let me know and
1088 +I shall correct it. Because it is a long time ago when I read their
1089 +source files last time).
1091 +UnionMount's approach will be able to small, but may be hard to share
1092 +branches between several UnionMount since the whiteout in it is
1093 +implemented in the inode on branch filesystem and always
1094 +shared. According to Bharata's post, readdir does not seems to be
1096 +There are several missing features known in this implementations such as
1097 +- for users, the inode number may change silently. eg. copy-up.
1098 +- link(2) may break by copy-up.
1099 +- read(2) may get an obsoleted filedata (fstat(2) too).
1100 +- fcntl(F_SETLK) may be broken by copy-up.
1101 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1104 +Unionfs has a longer history. When I started implementing a stacking filesystem
1105 +(Aug 2005), it already existed. It has virtual super_block, inode,
1106 +dentry and file objects and they have an array pointing lower same kind
1107 +objects. After contributing many patches for Unionfs, I re-started my
1108 +project AUFS (Jun 2006).
1110 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1111 +implemented my own ideas, approaches and enhancements and it became
1112 +totally different one.
1114 +Comparing DM snapshot and fs based implementation
1115 +- the number of bytes to be copied between devices is much smaller.
1116 +- the type of filesystem must be one and only.
1117 +- the fs must be writable, no readonly fs, even for the lower original
1118 + device. so the compression fs will not be usable. but if we use
1119 + loopback mount, we may address this issue.
1121 + mount /cdrom/squashfs.img /sq
1122 + losetup /sq/ext2.img
1123 + losetup /somewhere/cow
1124 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1125 +- it will be difficult (or needs more operations) to extract the
1126 + difference between the original device and COW.
1127 +- DM snapshot-merge may help a lot when users try merging. in the
1128 + fs-layer union, users will use rsync(1).
1131 +Several characters/aspects of aufs
1132 +----------------------------------------------------------------------
1134 +Aufs has several characters or aspects.
1135 +1. a filesystem, callee of VFS helper
1136 +2. sub-VFS, caller of VFS helper for branches
1137 +3. a virtual filesystem which maintains persistent inode number
1138 +4. reader/writer of files on branches such like an application
1140 +1. Callee of VFS Helper
1141 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1142 +unlink(2) from an application reaches sys_unlink() kernel function and
1143 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1144 +calls filesystem specific unlink operation. Actually aufs implements the
1145 +unlink operation but it behaves like a redirector.
1147 +2. Caller of VFS Helper for Branches
1148 +aufs_unlink() passes the unlink request to the branch filesystem as if
1149 +it were called from VFS. So the called unlink operation of the branch
1150 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1151 +every necessary pre/post operation for the branch filesystem.
1152 +- acquire the lock for the parent dir on a branch
1153 +- lookup in a branch
1154 +- revalidate dentry on a branch
1155 +- mnt_want_write() for a branch
1156 +- vfs_unlink() for a branch
1157 +- mnt_drop_write() for a branch
1158 +- release the lock on a branch
1160 +3. Persistent Inode Number
1161 +One of the most important issue for a filesystem is to maintain inode
1162 +numbers. This is particularly important to support exporting a
1163 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1164 +backend block device for its own. But some storage is necessary to
1165 +maintain inode number. It may be a large space and may not suit to keep
1166 +in memory. Aufs rents some space from its first writable branch
1167 +filesystem (by default) and creates file(s) on it. These files are
1168 +created by aufs internally and removed soon (currently) keeping opened.
1169 +Note: Because these files are removed, they are totally gone after
1170 + unmounting aufs. It means the inode numbers are not persistent
1171 + across unmount or reboot. I have a plan to make them really
1172 + persistent which will be important for aufs on NFS server.
1174 +4. Read/Write Files Internally (copy-on-write)
1175 +Because a branch can be readonly, when you write a file on it, aufs will
1176 +"copy-up" it to the upper writable branch internally. And then write the
1177 +originally requested thing to the file. Generally kernel doesn't
1178 +open/read/write file actively. In aufs, even a single write may cause a
1179 +internal "file copy". This behaviour is very similar to cp(1) command.
1181 +Some people may think it is better to pass such work to user space
1182 +helper, instead of doing in kernel space. Actually I am still thinking
1183 +about it. But currently I have implemented it in kernel space.
1184 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1185 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1186 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-01-25 13:00:38.627713742 +0100
1189 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1191 +# This program is free software; you can redistribute it and/or modify
1192 +# it under the terms of the GNU General Public License as published by
1193 +# the Free Software Foundation; either version 2 of the License, or
1194 +# (at your option) any later version.
1196 +# This program is distributed in the hope that it will be useful,
1197 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1198 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1199 +# GNU General Public License for more details.
1201 +# You should have received a copy of the GNU General Public License
1202 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1204 +Basic Aufs Internal Structure
1206 +Superblock/Inode/Dentry/File Objects
1207 +----------------------------------------------------------------------
1208 +As like an ordinary filesystem, aufs has its own
1209 +superblock/inode/dentry/file objects. All these objects have a
1210 +dynamically allocated array and store the same kind of pointers to the
1211 +lower filesystem, branch.
1212 +For example, when you build a union with one readwrite branch and one
1213 +readonly, mounted /au, /rw and /ro respectively.
1215 +- /ro/fileA exists but /rw/fileA
1217 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1218 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1222 +This style of an array is essentially same to the aufs
1223 +superblock/inode/dentry/file objects.
1225 +Because aufs supports manipulating branches, ie. add/delete/change
1226 +dynamically, these objects has its own generation. When branches are
1227 +changed, the generation in aufs superblock is incremented. And a
1228 +generation in other object are compared when it is accessed.
1229 +When a generation in other objects are obsoleted, aufs refreshes the
1234 +----------------------------------------------------------------------
1235 +Additionally aufs superblock has some data for policies to select one
1236 +among multiple writable branches, XIB files, pseudo-links and kobject.
1237 +See below in detail.
1238 +About the policies which supports copy-down a directory, see policy.txt
1242 +Branch and XINO(External Inode Number Translation Table)
1243 +----------------------------------------------------------------------
1244 +Every branch has its own xino (external inode number translation table)
1245 +file. The xino file is created and unlinked by aufs internally. When two
1246 +members of a union exist on the same filesystem, they share the single
1248 +The struct of a xino file is simple, just a sequence of aufs inode
1249 +numbers which is indexed by the lower inode number.
1250 +In the above sample, assume the inode number of /ro/fileA is i111 and
1251 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1252 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1254 +When the inode numbers are not contiguous, the xino file will be sparse
1255 +which has a hole in it and doesn't consume as much disk space as it
1256 +might appear. If your branch filesystem consumes disk space for such
1257 +holes, then you should specify 'xino=' option at mounting aufs.
1259 +Also a writable branch has three kinds of "whiteout bases". All these
1260 +are existed when the branch is joined to aufs and the names are
1261 +whiteout-ed doubly, so that users will never see their names in aufs
1263 +1. a regular file which will be linked to all whiteouts.
1264 +2. a directory to store a pseudo-link.
1265 +3. a directory to store an "orphan-ed" file temporary.
1268 + When you remove a file on a readonly branch, aufs handles it as a
1269 + logical deletion and creates a whiteout on the upper writable branch
1270 + as a hardlink of this file in order not to consume inode on the
1273 + See below, Pseudo-link.
1275 + When "fileC" exists on the lower readonly branch only and it is
1276 + opened and removed with its parent dir, and then user writes
1277 + something into it, then aufs copies-up fileC to this
1278 + directory. Because there is no other dir to store fileC. After
1279 + creating a file under this dir, the file is unlinked.
1281 +Because aufs supports manipulating branches, ie. add/delete/change
1282 +dynamically, a branch has its own id. When the branch order changes, aufs
1283 +finds the new index by searching the branch id.
1287 +----------------------------------------------------------------------
1288 +Assume "fileA" exists on the lower readonly branch only and it is
1289 +hardlinked to "fileB" on the branch. When you write something to fileA,
1290 +aufs copies-up it to the upper writable branch. Additionally aufs
1291 +creates a hardlink under the Pseudo-link Directory of the writable
1292 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1293 +simple list. If fileB is read after unlinking fileA, aufs returns
1294 +filedata from the pseudo-link instead of the lower readonly
1295 +branch. Because the pseudo-link is based upon the inode, to keep the
1296 +inode number by xino (see above) is important.
1298 +All the hardlinks under the Pseudo-link Directory of the writable branch
1299 +should be restored in a proper location later. Aufs provides a utility
1300 +to do this. The userspace helpers executed at remounting and unmounting
1302 +During this utility is running, it puts aufs into the pseudo-link
1303 +maintenance mode. In this mode, only the process which began the
1304 +maintenance mode (and its child processes) is allowed to operate in
1305 +aufs. Some other processes which are not related to the pseudo-link will
1306 +be allowed to run too, but the rest have to return an error or wait
1307 +until the maintenance mode ends. If a process already acquires an inode
1308 +mutex (in VFS), it has to return an error.
1311 +XIB(external inode number bitmap)
1312 +----------------------------------------------------------------------
1313 +Addition to the xino file per a branch, aufs has an external inode number
1314 +bitmap in a superblock object. It is also a file such like a xino file.
1315 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1317 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1319 +Aufs implements a feature to truncate/refresh both of xino and xib to
1320 +reduce the number of consumed disk blocks for these files.
1323 +Virtual or Vertical Dir, and Readdir in Userspace
1324 +----------------------------------------------------------------------
1325 +In order to support multiple layers (branches), aufs readdir operation
1326 +constructs a virtual dir block on memory. For readdir, aufs calls
1327 +vfs_readdir() internally for each dir on branches, merges their entries
1328 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1329 +object. So the file object has its entry list until it is closed. The
1330 +entry list will be updated when the file position is zero and becomes
1331 +old. This decision is made in aufs automatically.
1333 +The dynamically allocated memory block for the name of entries has a
1334 +unit of 512 bytes (by default) and stores the names contiguously (no
1335 +padding). Another block for each entry is handled by kmem_cache too.
1336 +During building dir blocks, aufs creates hash list and judging whether
1337 +the entry is whiteouted by its upper branch or already listed.
1338 +The merged result is cached in the corresponding inode object and
1339 +maintained by a customizable life-time option.
1341 +Some people may call it can be a security hole or invite DoS attack
1342 +since the opened and once readdir-ed dir (file object) holds its entry
1343 +list and becomes a pressure for system memory. But I'd say it is similar
1344 +to files under /proc or /sys. The virtual files in them also holds a
1345 +memory page (generally) while they are opened. When an idea to reduce
1346 +memory for them is introduced, it will be applied to aufs too.
1347 +For those who really hate this situation, I've developed readdir(3)
1348 +library which operates this merging in userspace. You just need to set
1349 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1350 +kernel space for readdir(3).
1354 +----------------------------------------------------------------------
1355 +Aufs sometimes requires privilege access to a branch. For instance,
1356 +in copy-up/down operation. When a user process is going to make changes
1357 +to a file which exists in the lower readonly branch only, and the mode
1358 +of one of ancestor directories may not be writable by a user
1359 +process. Here aufs copy-up the file with its ancestors and they may
1360 +require privilege to set its owner/group/mode/etc.
1361 +This is a typical case of a application character of aufs (see
1364 +Aufs uses workqueue synchronously for this case. It creates its own
1365 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1366 +passes the request to call mkdir or write (for example), and wait for
1367 +its completion. This approach solves a problem of a signal handler
1369 +If aufs didn't adopt the workqueue and changed the privilege of the
1370 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
1371 +then the user process might gain a privilege or the generated core file
1372 +was owned by a superuser.
1374 +Also aufs uses the system global workqueue ("events" kernel thread) too
1375 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1376 +whiteout base and etc. This is unrelated to a privilege.
1377 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1378 +superblock at the beginning, at the same time waits for the completion
1379 +of all queued asynchronous tasks.
1383 +----------------------------------------------------------------------
1384 +The whiteout in aufs is very similar to Unionfs's. That is represented
1385 +by its filename. UnionMount takes an approach of a file mode, but I am
1386 +afraid several utilities (find(1) or something) will have to support it.
1388 +Basically the whiteout represents "logical deletion" which stops aufs to
1389 +lookup further, but also it represents "dir is opaque" which also stop
1392 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1393 +In order to make several functions in a single systemcall to be
1394 +revertible, aufs adopts an approach to rename a directory to a temporary
1395 +unique whiteouted name.
1396 +For example, in rename(2) dir where the target dir already existed, aufs
1397 +renames the target dir to a temporary unique whiteouted name before the
1398 +actual rename on a branch and then handles other actions (make it opaque,
1399 +update the attributes, etc). If an error happens in these actions, aufs
1400 +simply renames the whiteouted name back and returns an error. If all are
1401 +succeeded, aufs registers a function to remove the whiteouted unique
1402 +temporary name completely and asynchronously to the system global
1407 +----------------------------------------------------------------------
1408 +It is a well-known feature or concept.
1409 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1410 +internally and makes change to the new file on the upper writable branch.
1411 +When the trigger systemcall does not update the timestamps of the parent
1412 +dir, aufs reverts it after copy-up.
1415 +Move-down (aufs3.9 and later)
1416 +----------------------------------------------------------------------
1417 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1418 +the lower readonly branch to the upper writable branch when a user
1419 +changes something about the file.
1420 +"Move-down" is an opposite action of copy-up. Basically this action is
1421 +ran manually instead of automatically and internally.
1422 +For desgin and implementation, aufs has to consider these issues.
1423 +- whiteout for the file may exist on the lower branch.
1424 +- ancestor directories may not exist on the lower branch.
1425 +- diropq for the ancestor directories may exist on the upper branch.
1426 +- free space on the lower branch will reduce.
1427 +- another access to the file may happen during moving-down, including
1429 +- the file should not be hard-linked nor pseudo-linked. they should be
1430 + handled by auplink utility later.
1432 +Sometimes users want to move-down a file from the upper writable branch
1433 +to the lower readonly or writable branch. For instance,
1434 +- the free space of the upper writable branch is going to run out.
1435 +- create a new intermediate branch between the upper and lower branch.
1438 +For this purpose, use "aumvdown" command in aufs-util.git.
1439 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1440 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1441 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-01-25 13:00:38.627713742 +0100
1444 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1446 +# This program is free software; you can redistribute it and/or modify
1447 +# it under the terms of the GNU General Public License as published by
1448 +# the Free Software Foundation; either version 2 of the License, or
1449 +# (at your option) any later version.
1451 +# This program is distributed in the hope that it will be useful,
1452 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1453 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1454 +# GNU General Public License for more details.
1456 +# You should have received a copy of the GNU General Public License
1457 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1460 +----------------------------------------------------------------------
1461 +Since aufs has a character of sub-VFS (see Introduction), it operates
1462 +lookup for branches as VFS does. It may be a heavy work. Generally
1463 +speaking struct nameidata is a bigger structure and includes many
1464 +information. But almost all lookup operation in aufs is the simplest
1465 +case, ie. lookup only an entry directly connected to its parent. Digging
1466 +down the directory hierarchy is unnecessary.
1468 +VFS has a function lookup_one_len() for that use, but it is not usable
1469 +for a branch filesystem which requires struct nameidata. So aufs
1470 +implements a simple lookup wrapper function. When a branch filesystem
1471 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
1472 +a simplest nameidata and calls lookup_hash().
1473 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
1474 +NFS-export, then it has to support NULL as a nameidata parameter for
1475 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
1476 +aufs tests if ->s_export_op in the branch is NULL or not.
1478 +When a branch is a remote filesystem, aufs basically trusts its
1479 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1481 +For d_revalidate, aufs implements three levels of revalidate tests. See
1482 +"Revalidate Dentry and UDBA" in detail.
1485 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1486 +----------------------------------------------------------------------
1487 +Let's try case study.
1488 +- aufs has two branches, upper readwrite and lower readonly.
1490 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1491 +- user invoked "chmod a+rx /au/dirA"
1492 +- the internal copy-up is activated and "/rw/dirA" is created and its
1493 + permission bits are set to world readble.
1494 +- then "/au/dirA" becomes world readable?
1496 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1497 +or it may be a natively readonly filesystem. If aufs respects the lower
1498 +branch, it should not respond readdir request from other users. But user
1499 +allowed it by chmod. Should really aufs rejects showing the entries
1502 +To be honest, I don't have a best solution for this case. So aufs
1503 +implements 'dirperm1' and 'nodirperm1' and leave it to users.
1504 +When dirperm1 is specified, aufs checks only the highest one for the
1505 +directory permission, and shows the entries. Otherwise, as usual, checks
1506 +every dir existing on all branches and rejects the request.
1508 +As a side effect, dirperm1 option improves the performance of aufs
1509 +because the number of permission check is reduced when the number of
1514 +----------------------------------------------------------------------
1515 +Basically aufs supports any type of filesystem and block device for a
1516 +branch (actually there are some exceptions). But it is prohibited to add
1517 +a loopback mounted one whose backend file exists in a filesystem which is
1518 +already added to aufs. The reason is to protect aufs from a recursive
1519 +lookup. If it was allowed, the aufs lookup operation might re-enter a
1520 +lookup for the loopback mounted branch in the same context, and will
1524 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1525 +----------------------------------------------------------------------
1526 +Generally VFS helpers re-validate a dentry as a part of lookup.
1527 +0. digging down the directory hierarchy.
1528 +1. lock the parent dir by its i_mutex.
1529 +2. lookup the final (child) entry.
1531 +4. call the actual operation (create, unlink, etc.)
1532 +5. unlock the parent dir
1534 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1535 +called. Actually aufs implements it and checks the dentry on a branch is
1537 +But it is not enough. Because aufs has to release the lock for the
1538 +parent dir on a branch at the end of ->lookup() (step 2) and
1539 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1541 +If the file on a branch is changed directly, eg. bypassing aufs, after
1542 +aufs released the lock, then the subsequent operation may cause
1543 +something unpleasant result.
1545 +This situation is a result of VFS architecture, ->lookup() and
1546 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1547 +design from VFS's point of view. It is just not suitable for sub-VFS
1550 +Aufs supports such case by three level of revalidation which is
1551 +selectable by user.
1552 +1. Simple Revalidate
1553 + Addition to the native flow in VFS's, confirm the child-parent
1554 + relationship on the branch just after locking the parent dir on the
1555 + branch in the "actual operation" (step 4). When this validation
1556 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1557 + checks the validation of the dentry on branches.
1558 +2. Monitor Changes Internally by Inotify/Fsnotify
1559 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1560 + the dentry on the branch, and returns EBUSY if it finds different
1562 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1563 + during it is in cache. When the event is notified, aufs registers a
1564 + function to kernel 'events' thread by schedule_work(). And the
1565 + function sets some special status to the cached aufs dentry and inode
1566 + private data. If they are not cached, then aufs has nothing to
1567 + do. When the same file is accessed through aufs (step 0-3) later,
1568 + aufs will detect the status and refresh all necessary data.
1569 + In this mode, aufs has to ignore the event which is fired by aufs
1571 +3. No Extra Validation
1572 + This is the simplest test and doesn't add any additional revalidation
1573 + test, and skip therevalidatin in step 4. It is useful and improves
1574 + aufs performance when system surely hide the aufs branches from user,
1575 + by over-mounting something (or another method).
1576 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1577 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1578 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-01-25 13:00:38.627713742 +0100
1581 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1583 +# This program is free software; you can redistribute it and/or modify
1584 +# it under the terms of the GNU General Public License as published by
1585 +# the Free Software Foundation; either version 2 of the License, or
1586 +# (at your option) any later version.
1588 +# This program is distributed in the hope that it will be useful,
1589 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1590 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1591 +# GNU General Public License for more details.
1593 +# You should have received a copy of the GNU General Public License
1594 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1596 +Branch Manipulation
1598 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1599 +and changing its permission/attribute, there are a lot of works to do.
1603 +----------------------------------------------------------------------
1604 +o Confirm the adding dir exists outside of aufs, including loopback
1606 +- and other various attributes...
1607 +o Initialize the xino file and whiteout bases if necessary.
1610 +o Check the owner/group/mode of the directory
1611 + When the owner/group/mode of the adding directory differs from the
1612 + existing branch, aufs issues a warning because it may impose a
1614 + For example, when a upper writable branch has a world writable empty
1615 + top directory, a malicious user can create any files on the writable
1616 + branch directly, like copy-up and modify manually. If something like
1617 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1618 + writable branch, and the writable branch is world-writable, then a
1619 + malicious guy may create /etc/passwd on the writable branch directly
1620 + and the infected file will be valid in aufs.
1621 + I am afraid it can be a security issue, but nothing to do except
1622 + producing a warning.
1626 +----------------------------------------------------------------------
1627 +o Confirm the deleting branch is not busy
1628 + To be general, there is one merit to adopt "remount" interface to
1629 + manipulate branches. It is to discard caches. At deleting a branch,
1630 + aufs checks the still cached (and connected) dentries and inodes. If
1631 + there are any, then they are all in-use. An inode without its
1632 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1634 + For the cached one, aufs checks whether the same named entry exists on
1636 + If the cached one is a directory, because aufs provides a merged view
1637 + to users, as long as one dir is left on any branch aufs can show the
1638 + dir to users. In this case, the branch can be removed from aufs.
1639 + Otherwise aufs rejects deleting the branch.
1641 + If any file on the deleting branch is opened by aufs, then aufs
1645 +Modify the Permission of a Branch
1646 +----------------------------------------------------------------------
1647 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1650 +o rw --> ro: Confirm the modifying branch is not busy
1651 + Aufs rejects the request if any of these conditions are true.
1652 + - a file on the branch is mmap-ed.
1653 + - a regular file on the branch is opened for write and there is no
1654 + same named entry on the upper branch.
1655 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1656 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1657 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-01-25 13:00:38.627713742 +0100
1660 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1662 +# This program is free software; you can redistribute it and/or modify
1663 +# it under the terms of the GNU General Public License as published by
1664 +# the Free Software Foundation; either version 2 of the License, or
1665 +# (at your option) any later version.
1667 +# This program is distributed in the hope that it will be useful,
1668 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1669 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1670 +# GNU General Public License for more details.
1672 +# You should have received a copy of the GNU General Public License
1673 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1675 +Policies to Select One among Multiple Writable Branches
1676 +----------------------------------------------------------------------
1677 +When the number of writable branch is more than one, aufs has to decide
1678 +the target branch for file creation or copy-up. By default, the highest
1679 +writable branch which has the parent (or ancestor) dir of the target
1680 +file is chosen (top-down-parent policy).
1681 +By user's request, aufs implements some other policies to select the
1682 +writable branch, for file creation two policies, round-robin and
1683 +most-free-space policies. For copy-up three policies, top-down-parent,
1684 +bottom-up-parent and bottom-up policies.
1686 +As expected, the round-robin policy selects the branch in circular. When
1687 +you have two writable branches and creates 10 new files, 5 files will be
1688 +created for each branch. mkdir(2) systemcall is an exception. When you
1689 +create 10 new directories, all will be created on the same branch.
1690 +And the most-free-space policy selects the one which has most free
1691 +space among the writable branches. The amount of free space will be
1692 +checked by aufs internally, and users can specify its time interval.
1694 +The policies for copy-up is more simple,
1695 +top-down-parent is equivalent to the same named on in create policy,
1696 +bottom-up-parent selects the writable branch where the parent dir
1697 +exists and the nearest upper one from the copyup-source,
1698 +bottom-up selects the nearest upper writable branch from the
1699 +copyup-source, regardless the existence of the parent dir.
1701 +There are some rules or exceptions to apply these policies.
1702 +- If there is a readonly branch above the policy-selected branch and
1703 + the parent dir is marked as opaque (a variation of whiteout), or the
1704 + target (creating) file is whiteout-ed on the upper readonly branch,
1705 + then the result of the policy is ignored and the target file will be
1706 + created on the nearest upper writable branch than the readonly branch.
1707 +- If there is a writable branch above the policy-selected branch and
1708 + the parent dir is marked as opaque or the target file is whiteouted
1709 + on the branch, then the result of the policy is ignored and the target
1710 + file will be created on the highest one among the upper writable
1711 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1713 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1714 + They try selecting the branch where the source exists as possible
1715 + since copyup a large file will take long time. If it can't be,
1716 + ie. the branch where the source exists is readonly, then they will
1717 + follow the copyup policy.
1718 +- There is an exception for rename(2) when the target exists.
1719 + If the rename target exists, aufs compares the index of the branches
1720 + where the source and the target exists and selects the higher
1721 + one. If the selected branch is readonly, then aufs follows the
1723 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1724 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1725 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-01-25 13:00:38.627713742 +0100
1728 +# Copyright (C) 2011-2014 Junjiro R. Okajima
1730 +# This program is free software; you can redistribute it and/or modify
1731 +# it under the terms of the GNU General Public License as published by
1732 +# the Free Software Foundation; either version 2 of the License, or
1733 +# (at your option) any later version.
1735 +# This program is distributed in the hope that it will be useful,
1736 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1737 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1738 +# GNU General Public License for more details.
1740 +# You should have received a copy of the GNU General Public License
1741 +# along with this program; if not, write to the Free Software
1742 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1745 +File-based Hierarchical Storage Management (FHSM)
1746 +----------------------------------------------------------------------
1747 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1748 +storage world. Aufs provides this feature as file-based with multiple
1749 +writable branches, based upon the principle of "Colder-Lower".
1750 +Here the word "colder" means that the less used files, and "lower" means
1751 +that the position in the order of the stacked branches.
1752 +These multiple writable branches are prioritized, ie. the topmost one
1753 +should be the fastest drive and be used heavily.
1755 +o Characters in aufs FHSM story
1756 +- aufs itself and a new branch attribute.
1757 +- a new ioctl interface to move-down and to establish a connection with
1758 + the daemon ("move-down" is a converse of "copy-up").
1759 +- userspace tool and daemon.
1761 +The userspace daemon establishes a connection with aufs and waits for
1762 +the notification. The notified information is very similar to struct
1763 +statfs containing the number of consumed blocks and inodes.
1764 +When the consumed blocks/inodes of a branch exceeds the user-specified
1765 +upper watermark, the daemon activates its move-down process until the
1766 +consumed blocks/inodes reaches the user-specified lower watermark.
1768 +The actual move-down is done by aufs based upon the request from
1769 +user-space since we need to maintain the inode number and the internal
1770 +pointer arrays in aufs.
1772 +Currently aufs FHSM handles the regular files only. Additionally they
1773 +must not be hard-linked nor pseudo-linked.
1776 +o Cowork of aufs and the user-space daemon
1777 + During the userspace daemon established the connection, aufs sends a
1778 + small notification to it whenever aufs writes something into the
1779 + writable branch. But it may cost high since aufs issues statfs(2)
1780 + internally. So user can specify a new option to cache the
1781 + info. Actually the notification is controlled by these factors.
1782 + + the specified cache time.
1783 + + classified as "force" by aufs internally.
1784 + Until the specified time expires, aufs doesn't send the info
1785 + except the forced cases. When aufs decide forcing, the info is always
1786 + notified to userspace.
1787 + For example, the number of free inodes is generally large enough and
1788 + the shortage of it happens rarely. So aufs doesn't force the
1789 + notification when creating a new file, directory and others. This is
1790 + the typical case which aufs doesn't force.
1791 + When aufs writes the actual filedata and the files consumes any of new
1792 + blocks, the aufs forces notifying.
1795 +o Interfaces in aufs
1796 +- New branch attribute.
1798 + Specifies that the branch is managed by FHSM feature. In other word,
1799 + participant in the FHSM.
1800 + When nofhsm is set to the branch, it will not be the source/target
1801 + branch of the move-down operation. This attribute is set
1802 + independently from coo and moo attributes, and if you want full
1803 + FHSM, you should specify them as well.
1804 +- New mount option.
1806 + Specifies a second to suppress many less important info to be
1809 + + AUFS_CTL_FHSM_FD
1810 + create a new file descriptor which userspace can read the notification
1811 + (a subset of struct statfs) from aufs.
1812 +- Module parameter 'brs'
1813 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1815 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1816 + When there are two or more branches with fhsm attributes,
1817 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1818 + terminates it. As a result of remounting and branch-manipulation, the
1819 + number of branches with fhsm attribute can be one. In this case,
1820 + /sbin/mount.aufs will terminate the user-space daemon.
1823 +Finally the operation is done as these steps in kernel-space.
1825 + + no one else is using the file.
1826 + + the file is not hard-linked.
1827 + + the file is not pseudo-linked.
1828 + + the file is a regular file.
1829 + + the parent dir is not opaqued.
1830 +- find the target writable branch.
1831 +- make sure the file is not whiteout-ed by the upper (than the target)
1833 +- make the parent dir on the target branch.
1834 +- mutex lock the inode on the branch.
1835 +- unlink the whiteout on the target branch (if exists).
1836 +- lookup and create the whiteout-ed temporary name on the target branch.
1837 +- copy the file as the whiteout-ed temporary name on the target branch.
1838 +- rename the whiteout-ed temporary name to the original name.
1839 +- unlink the file on the source branch.
1840 +- maintain the internal pointer array and the external inode number
1842 +- maintain the timestamps and other attributes of the parent dir and the
1845 +And of course, in every step, an error may happen. So the operation
1846 +should restore the original file state after an error happens.
1847 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1848 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1849 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-01-25 13:00:38.627713742 +0100
1852 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1854 +# This program is free software; you can redistribute it and/or modify
1855 +# it under the terms of the GNU General Public License as published by
1856 +# the Free Software Foundation; either version 2 of the License, or
1857 +# (at your option) any later version.
1859 +# This program is distributed in the hope that it will be useful,
1860 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1861 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1862 +# GNU General Public License for more details.
1864 +# You should have received a copy of the GNU General Public License
1865 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1867 +mmap(2) -- File Memory Mapping
1868 +----------------------------------------------------------------------
1869 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1870 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1872 +This approach is simple and good, but there is one problem.
1873 +Under /proc, several entries show the mmap-ped files by its path (with
1874 +device and inode number), and the printed path will be the path on the
1875 +branch fs's instead of virtual aufs's.
1876 +This is not a problem in most cases, but some utilities lsof(1) (and its
1877 +user) may expect the path on aufs.
1879 +To address this issue, aufs adds a new member called vm_prfile in struct
1880 +vm_area_struct (and struct vm_region). The original vm_file points to
1881 +the file on the branch fs in order to handle everything correctly as
1882 +usual. The new vm_prfile points to a virtual file in aufs, and the
1883 +show-functions in procfs refers to vm_prfile if it is set.
1884 +Also we need to maintain several other places where touching vm_file
1886 +- fork()/clone() copies vma and the reference count of vm_file is
1888 +- merging vma maintains the ref count too.
1890 +This is not a good approach. It just faking the printed path. But it
1891 +leaves all behaviour around f_mapping unchanged. This is surely an
1893 +Actually aufs had adopted another complicated approach which calls
1894 +generic_file_mmap() and handles struct vm_operations_struct. In this
1895 +approach, aufs met a hard problem and I could not solve it without
1896 +switching the approach.
1897 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
1898 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
1899 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-01-25 13:00:38.627713742 +0100
1902 +# Copyright (C) 2014 Junjiro R. Okajima
1904 +# This program is free software; you can redistribute it and/or modify
1905 +# it under the terms of the GNU General Public License as published by
1906 +# the Free Software Foundation; either version 2 of the License, or
1907 +# (at your option) any later version.
1909 +# This program is distributed in the hope that it will be useful,
1910 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1911 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1912 +# GNU General Public License for more details.
1914 +# You should have received a copy of the GNU General Public License
1915 +# along with this program; if not, write to the Free Software
1916 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919 +Listing XATTR/EA and getting the value
1920 +----------------------------------------------------------------------
1921 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
1922 +shows the values from the topmost existing file. This behaviour is good
1923 +for the non-dir entreis since the bahaviour exactly matches the shown
1924 +information. But for the directories, aufs considers all the same named
1925 +entries on the lower branches. Which means, if one of the lower entry
1926 +rejects readdir call, then aufs returns an error even if the topmost
1927 +entry allows it. This behaviour is necessary to respect the branch fs's
1928 +security, but can make users confused since the user-visible standard
1929 +attributes don't match the behaviour.
1930 +To address this issue, aufs has a mount option called dirperm1 which
1931 +checks the permission for the topmost entry only, and ignores the lower
1932 +entry's permission.
1934 +A similar issue can happen around XATTR.
1935 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
1936 +always set. Otherwise these very unpleasant situation can happen.
1937 +- listxattr(2) may return the duplicated entires.
1938 +- users may not be able to remove or reset the XATTR forever,
1941 +XATTR/EA support in the internal (copy,move)-(up,down)
1942 +----------------------------------------------------------------------
1943 +Generally the extended attributes of inode are categorazied as these.
1944 +- "security" for LSM and capability.
1945 +- "system" for posix ACL, 'acl' mount option is required for the branch
1947 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
1948 +- "user" for userspace, 'user_xattr' mount option is required for the
1949 + branch fs generally.
1951 +Moreover there are some other categories. Aufs handles these rather
1952 +unpopular categories as the ordinary ones, ie. there is no special
1953 +condition nor exception.
1955 +In copy-up, the support for XATTR on the dst branch may differ from the
1956 +src branch. In this case, the copy-up operation will get an error and
1957 +the original user operation which triggered the copy-up fails. It can
1958 +happen that even all copy-up will fail.
1959 +When both of src and dst branches support XATTR and if an error occurs
1960 +during copying XATTR, then the copy-up should fail obviously. That is a
1961 +good reason and aufs should return an error to userspace. But when only
1962 +the src branch support XATTR, aufs should not return an error.
1963 +For example, the src branch supports ACL but the dst branch doesn't
1964 +because the dst branch may natively un-support it or temporary
1965 +un-support it due to "noacl" mount option. Of course, the dst branch fs
1966 +may NOT return an error even if the XATTR is not supported. It is
1967 +totally up to the branch fs.
1969 +Anyway when the aufs internal copy-up gets an error from the dst branch
1970 +fs, then aufs tries removing the just copied entry and returns the error
1971 +to the userspace. The worst case of this situation will be all copy-up
1974 +For the copy-up operation, there two basic approaches.
1975 +- copy the specified XATTR only (by category above), and return the
1976 + error if it happens inconditionally.
1977 +- copy all XATTR, and ignore the error on the specified category only.
1979 +In order to support XATTR and to implement the correct behaviour, aufs
1980 +chooses the latter approach and introduces some attributes for its
1981 +branch, "icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
1982 +They correspond to the XATTR namespaces (see above). Additionally, to be
1983 +convenient, "icex" is also provided which means all "ix*" attributes are
1986 +The meaning of these attributes is to ignore the error from setting
1987 +XATTR on that branch.
1988 +Note that aufs tries copying all XATTR unconditionally, and ignores the
1989 +error from the dst branch according to the specified attributes.
1991 +Some XATTR may have its default value. The default value may come from
1992 +the parent dir or the environment. If the default value is set at the
1993 +file creating-time, it will be overwritten by copy-up.
1994 +Some contradiction may happen I am afraid.
1995 +Do we need another attribute to stop copying XATTR? I am unsure. For
1996 +now, aufs implements the branch attributes to ignore the error.
1997 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1998 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1999 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-01-25 13:00:38.627713742 +0100
2002 +# Copyright (C) 2005-2014 Junjiro R. Okajima
2004 +# This program is free software; you can redistribute it and/or modify
2005 +# it under the terms of the GNU General Public License as published by
2006 +# the Free Software Foundation; either version 2 of the License, or
2007 +# (at your option) any later version.
2009 +# This program is distributed in the hope that it will be useful,
2010 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2011 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2012 +# GNU General Public License for more details.
2014 +# You should have received a copy of the GNU General Public License
2015 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2017 +Export Aufs via NFS
2018 +----------------------------------------------------------------------
2019 +Here is an approach.
2020 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2022 +- iget_locked(): initialize aufs inode generation for a new inode, and
2023 + store it in xigen file.
2024 +- destroy_inode(): increment aufs inode generation and store it in xigen
2025 + file. it is necessary even if it is not unlinked, because any data of
2026 + inode may be changed by UDBA.
2027 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2028 + build file handle by
2029 + + branch id (4 bytes)
2030 + + superblock generation (4 bytes)
2031 + + inode number (4 or 8 bytes)
2032 + + parent dir inode number (4 or 8 bytes)
2033 + + inode generation (4 bytes))
2034 + + return value of exportfs_encode_fh() for the parent on a branch (4
2036 + + file handle for a branch (by exportfs_encode_fh())
2038 + + find the index of a branch from its id in handle, and check it is
2039 + still exist in aufs.
2040 + + 1st level: get the inode number from handle and search it in cache.
2041 + + 2nd level: if not found, get the parent inode number from handle and
2042 + search it in cache. and then open the parent dir, find the matching
2043 + inode number by vfs_readdir() and get its name, and call
2044 + lookup_one_len() for the target dentry.
2045 + + 3rd level: if the parent dir is not cached, call
2046 + exportfs_decode_fh() for a branch and get the parent on a branch,
2047 + build a pathname of it, convert it a pathname in aufs, call
2048 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2050 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2051 + for every branch, but not itself. to get this, (currently) aufs
2052 + searches in current->nsproxy->mnt_ns list. it may not be a good
2053 + idea, but I didn't get other approach.
2054 + + test the generation of the gotten inode.
2055 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2056 + convert it into ESTALE for NFSD.
2057 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2058 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2059 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2060 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2061 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-01-25 13:00:38.627713742 +0100
2064 +# Copyright (C) 2005-2014 Junjiro R. Okajima
2066 +# This program is free software; you can redistribute it and/or modify
2067 +# it under the terms of the GNU General Public License as published by
2068 +# the Free Software Foundation; either version 2 of the License, or
2069 +# (at your option) any later version.
2071 +# This program is distributed in the hope that it will be useful,
2072 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2073 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2074 +# GNU General Public License for more details.
2076 +# You should have received a copy of the GNU General Public License
2077 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2079 +Show Whiteout Mode (shwh)
2080 +----------------------------------------------------------------------
2081 +Generally aufs hides the name of whiteouts. But in some cases, to show
2082 +them is very useful for users. For instance, creating a new middle layer
2083 +(branch) by merging existing layers.
2085 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2086 +When you have three branches,
2087 +- Bottom: 'system', squashfs (underlying base system), read-only
2088 +- Middle: 'mods', squashfs, read-only
2089 +- Top: 'overlay', ram (tmpfs), read-write
2091 +The top layer is loaded at boot time and saved at shutdown, to preserve
2092 +the changes made to the system during the session.
2093 +When larger changes have been made, or smaller changes have accumulated,
2094 +the size of the saved top layer data grows. At this point, it would be
2095 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2096 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2097 +restoring save and load speed.
2099 +This merging is simplified by the use of another aufs mount, of just the
2100 +two overlay branches using the 'shwh' option.
2101 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2102 + aufs /livesys/merge_union
2104 +A merged view of these two branches is then available at
2105 +/livesys/merge_union, and the new feature is that the whiteouts are
2107 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2108 +writing to all branches. Also the default mode for all branches is 'ro'.
2109 +It is now possible to save the combined contents of the two overlay
2110 +branches to a new squashfs, e.g.:
2111 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2113 +This new squashfs archive can be stored on the boot device and the
2114 +initramfs will use it to replace the old one at the next boot.
2115 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2116 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2117 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-01-25 13:00:38.627713742 +0100
2120 +# Copyright (C) 2010-2014 Junjiro R. Okajima
2122 +# This program is free software; you can redistribute it and/or modify
2123 +# it under the terms of the GNU General Public License as published by
2124 +# the Free Software Foundation; either version 2 of the License, or
2125 +# (at your option) any later version.
2127 +# This program is distributed in the hope that it will be useful,
2128 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2129 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2130 +# GNU General Public License for more details.
2132 +# You should have received a copy of the GNU General Public License
2133 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2135 +Dynamically customizable FS operations
2136 +----------------------------------------------------------------------
2137 +Generally FS operations (struct inode_operations, struct
2138 +address_space_operations, struct file_operations, etc.) are defined as
2139 +"static const", but it never means that FS have only one set of
2140 +operation. Some FS have multiple sets of them. For instance, ext2 has
2141 +three sets, one for XIP, for NOBH, and for normal.
2142 +Since aufs overrides and redirects these operations, sometimes aufs has
2143 +to change its behaviour according to the branch FS type. More imporantly
2144 +VFS acts differently if a function (member in the struct) is set or
2145 +not. It means aufs should have several sets of operations and select one
2146 +among them according to the branch FS definition.
2148 +In order to solve this problem and not to affect the behavour of VFS,
2149 +aufs defines these operations dynamically. For instance, aufs defines
2150 +aio_read function for struct file_operations, but it may not be set to
2151 +the file_operations. When the branch FS doesn't have it, aufs doesn't
2152 +set it to its file_operations while the function definition itself is
2153 +still alive. So the behaviour of io_submit(2) will not change, and it
2154 +will return an error when aio_read is not defined.
2156 +The lifetime of these dynamically generated operation object is
2157 +maintained by aufs branch object. When the branch is removed from aufs,
2158 +the reference counter of the object is decremented. When it reaches
2159 +zero, the dynamically generated operation object will be freed.
2161 +This approach is designed to support AIO (io_submit), Direcit I/O and
2163 +Currently this approach is applied to file_operations and
2164 +vm_operations_struct for regular files only.
2165 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
2166 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
2167 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2015-01-25 13:00:38.627713742 +0100
2170 +# Copyright (C) 2005-2014 Junjiro R. Okajima
2172 +# This program is free software; you can redistribute it and/or modify
2173 +# it under the terms of the GNU General Public License as published by
2174 +# the Free Software Foundation; either version 2 of the License, or
2175 +# (at your option) any later version.
2177 +# This program is distributed in the hope that it will be useful,
2178 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2179 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2180 +# GNU General Public License for more details.
2182 +# You should have received a copy of the GNU General Public License
2183 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2187 +Restoring some features which was implemented in aufs1.
2188 +They were dropped in aufs2 in order to make source files simpler and
2189 +easier to be reviewed.
2192 +Being Another Aufs's Readonly Branch (robr)
2193 +----------------------------------------------------------------------
2194 +Aufs1 allows aufs to be another aufs's readonly branch.
2195 +This feature was developed by a user's request. But it may not be used
2199 +Refresh the Opened File (refrof)
2200 +----------------------------------------------------------------------
2201 +This option is implemented in aufs1 but incomplete.
2203 +When user reads from a file, he expects to get its latest filedata
2204 +generally. If the file is removed and a new same named file is created,
2205 +the content he gets is unchanged, ie. the unlinked filedata.
2207 +Let's try case study again.
2208 +- aufs has two branches.
2210 +- "fileA" exists under /ro, but /rw.
2211 +- user opened "/au/fileA".
2212 +- he or someone else inserts a branch (/new) between /rw and /ro.
2213 + /au = /rw + /new + /ro
2214 +- the new branch has "fileA".
2215 +- user reads from the opened "fileA"
2216 +- which filedata should aufs return, from /ro or /new?
2218 +Some people says it has to be "from /ro" and it is a semantics of Unix.
2219 +The others say it should be "from /new" because the file is not removed
2220 +and it is equivalent to the case of someone else modifies the file.
2222 +Here again I don't have a best and final answer. I got an idea to
2223 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
2224 +Opened File) is specified (by default), aufs returns the filedata from
2226 +Otherwise from /new.
2227 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2228 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2229 +++ linux/Documentation/filesystems/aufs/README 2015-01-25 13:00:38.627713742 +0100
2232 +Aufs3 -- advanced multi layered unification filesystem version 3.x
2238 +----------------------------------------
2239 +In the early days, aufs was entirely re-designed and re-implemented
2240 +Unionfs Version 1.x series. After many original ideas, approaches,
2241 +improvements and implementations, it becomes totally different from
2242 +Unionfs while keeping the basic features.
2243 +Recently, Unionfs Version 2.x series begin taking some of the same
2244 +approaches to aufs1's.
2245 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2246 +University and his team.
2248 +Aufs3 supports linux-3.0 and later.
2249 +If you want older kernel version support, try aufs2-2.6.git or
2250 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2252 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2253 + According to Christoph Hellwig, linux rejects all union-type
2254 + filesystems but UnionMount.
2255 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2257 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2258 + UnionMount, and he pointed out an issue around a directory mutex
2259 + lock and aufs addressed it. But it is still unsure whether aufs will
2260 + be merged (or any other union solution).
2261 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2265 +----------------------------------------
2266 +- unite several directories into a single virtual filesystem. The member
2267 + directory is called as a branch.
2268 +- you can specify the permission flags to the branch, which are 'readonly',
2269 + 'readwrite' and 'whiteout-able.'
2270 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2271 + readonly branch are modifiable logically.
2272 +- dynamic branch manipulation, add, del.
2275 +Also there are many enhancements in aufs1, such as:
2276 +- readdir(3) in userspace.
2277 +- keep inode number by external inode number table
2278 +- keep the timestamps of file/dir in internal copyup operation
2279 +- seekable directory, supporting NFS readdir.
2280 +- whiteout is hardlinked in order to reduce the consumption of inodes
2282 +- do not copyup, nor create a whiteout when it is unnecessary
2283 +- revert a single systemcall when an error occurs in aufs
2284 +- remount interface instead of ioctl
2285 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2286 +- loopback mounted filesystem as a branch
2287 +- kernel thread for removing the dir who has a plenty of whiteouts
2288 +- support copyup sparse file (a file which has a 'hole' in it)
2289 +- default permission flags for branches
2290 +- selectable permission flags for ro branch, whether whiteout can
2293 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2294 +- support multiple writable branches, some policies to select one
2295 + among multiple writable branches.
2296 +- a new semantics for link(2) and rename(2) to support multiple
2297 + writable branches.
2298 +- no glibc changes are required.
2299 +- pseudo hardlink (hardlink over branches)
2300 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2301 + including NFS or remote filesystem branch.
2302 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2305 +Currently these features are dropped temporary from aufs3.
2306 +See design/08plan.txt in detail.
2307 +- test only the highest one for the directory permission (dirperm1)
2308 +- copyup on open (coo=)
2309 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2311 +- statistics of aufs thread (/sys/fs/aufs/stat)
2312 +- delegation mode (dlgt)
2313 + a delegation of the internal branch access to support task I/O
2314 + accounting, which also supports Linux Security Modules (LSM) mainly
2315 + for Suse AppArmor.
2316 +- intent.open/create (file open in a single lookup)
2318 +Features or just an idea in the future (see also design/*.txt),
2319 +- reorder the branch index without del/re-add.
2320 +- permanent xino files for NFSD
2321 +- an option for refreshing the opened files after add/del branches
2322 +- 'move' policy for copy-up between two writable branches, after
2323 + checking free space.
2324 +- light version, without branch manipulation. (unnecessary?)
2325 +- copyup in userspace
2326 +- inotify in userspace
2332 +----------------------------------------
2333 +There were three GIT trees for aufs3, aufs3-linux.git,
2334 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
2336 +While the aufs-util is always necessary, you need either of aufs3-linux
2337 +or aufs3-standalone.
2339 +The aufs3-linux tree includes the whole linux mainline GIT tree,
2340 +git://git.kernel.org/.../torvalds/linux.git.
2341 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2342 +build aufs3 as an external kernel module.
2344 +On the other hand, the aufs3-standalone tree has only aufs source files
2345 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2347 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
2348 +represents the linux kernel version, "linux-3.x". For instance,
2349 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
2350 +"aufs3.x-rcN" branch.
2353 +$ git clone --reference /your/linux/git/tree \
2354 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
2356 +- if you don't have linux GIT tree, then remove "--reference ..."
2357 +$ cd aufs3-linux.git
2358 +$ git checkout origin/aufs3.0
2360 +o aufs3-standalone tree
2361 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
2362 + aufs3-standalone.git
2363 +$ cd aufs3-standalone.git
2364 +$ git checkout origin/aufs3.0
2367 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
2370 +$ git checkout origin/aufs3.0
2372 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
2373 +The minor version number, 'x' in '3.x', of aufs may not always
2374 +follow the minor version number of the kernel.
2375 +Because changes in the kernel that cause the use of a new
2376 +minor version number do not always require changes to aufs-util.
2378 +Since aufs-util has its own minor version number, you may not be
2379 +able to find a GIT branch in aufs-util for your kernel's
2380 +exact minor version number.
2381 +In this case, you should git-checkout the branch for the
2382 +nearest lower number.
2384 +For (an unreleased) example:
2385 +If you are using "linux-3.10" and the "aufs3.10" branch
2386 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
2387 +or something numerically smaller is the branch for your kernel.
2389 +Also you can view all branches by
2393 +3. Configuration and Compilation
2394 +----------------------------------------
2395 +Make sure you have git-checkout'ed the correct branch.
2397 +For aufs3-linux tree,
2398 +- enable CONFIG_AUFS_FS.
2399 +- set other aufs configurations if necessary.
2401 +For aufs3-standalone tree,
2402 +There are several ways to build.
2405 +- apply ./aufs3-kbuild.patch to your kernel source files.
2406 +- apply ./aufs3-base.patch too.
2407 +- apply ./aufs3-mmap.patch too.
2408 +- apply ./aufs3-standalone.patch too, if you have a plan to set
2409 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
2410 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2411 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2412 +- enable CONFIG_AUFS_FS, you can select either
2414 +- and build your kernel as usual.
2415 +- install the built kernel.
2416 + Note: Since linux-3.9, every filesystem module requires an alias
2417 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2418 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2419 +- install the header files too by "make headers_install" to the
2420 + directory where you specify. By default, it is $PWD/usr.
2421 + "make help" shows a brief note for headers_install.
2422 +- and reboot your system.
2425 +- module only (CONFIG_AUFS_FS=m).
2426 +- apply ./aufs3-base.patch to your kernel source files.
2427 +- apply ./aufs3-mmap.patch too.
2428 +- apply ./aufs3-standalone.patch too.
2429 +- build your kernel, don't forget "make headers_install", and reboot.
2430 +- edit ./config.mk and set other aufs configurations if necessary.
2431 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2432 + every aufs configurations.
2433 +- build the module by simple "make".
2434 + Note: Since linux-3.9, every filesystem module requires an alias
2435 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2436 + modules.aliases file.
2437 +- you can specify ${KDIR} make variable which points to your kernel
2439 +- install the files
2440 + + run "make install" to install the aufs module, or copy the built
2441 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2442 + + run "make install_headers" (instead of headers_install) to install
2443 + the modified aufs header file (you can specify DESTDIR which is
2444 + available in aufs standalone version's Makefile only), or copy
2445 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2446 + you like manually. By default, the target directory is $PWD/usr.
2447 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
2448 + kernel source tree.
2450 +Note: The header file aufs_type.h is necessary to build aufs-util
2451 + as well as "make headers_install" in the kernel source tree.
2452 + headers_install is subject to be forgotten, but it is essentially
2453 + necessary, not only for building aufs-util.
2454 + You may not meet problems without headers_install in some older
2458 +- read README in aufs-util, build and install it
2459 +- note that your distribution may contain an obsoleted version of
2460 + aufs_type.h in /usr/include/linux or something. When you build aufs
2461 + utilities, make sure that your compiler refers the correct aufs header
2462 + file which is built by "make headers_install."
2463 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2464 + then run "make install_ulib" too. And refer to the aufs manual in
2467 +There several other patches in aufs3-standalone.git. They are all
2468 +optional. When you meet some problems, they will help you.
2469 +- aufs3-loopback.patch
2470 + Supports a nested loopback mount in a branch-fs. This patch is
2471 + unnecessary until aufs produces a message like "you may want to try
2472 + another patch for loopback file".
2474 + Modifies a system global kernel internal function get_next_ino() in
2475 + order to stop assigning 0 for an inode-number. Not directly related to
2476 + aufs, but recommended generally.
2478 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2479 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2480 + duplication of inode number, which is important for backup tools and
2481 + other utilities. When you find aufs XINO files for tmpfs branch
2482 + growing too much, try this patch.
2486 +----------------------------------------
2487 +At first, make sure aufs-util are installed, and please read the aufs
2488 +manual, aufs.5 in aufs-util.git tree.
2492 +$ mkdir /tmp/rw /tmp/aufs
2493 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2495 +Here is another example. The result is equivalent.
2496 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2498 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2499 +# mount -o remount,append:${HOME} /tmp/aufs
2501 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2502 +you modify a file under /tmp/aufs, the one on your home directory is
2503 +not affected, instead the same named file will be newly created under
2504 +/tmp/rw. And all of your modification to a file will be applied to
2505 +the one under /tmp/rw. This is called the file based Copy on Write
2507 +Aufs mount options are described in aufs.5.
2508 +If you run chroot or something and make your aufs as a root directory,
2509 +then you need to customize the shutdown script. See the aufs manual in
2512 +Additionally, there are some sample usages of aufs which are a
2513 +diskless system with network booting, and LiveCD over NFS.
2514 +See sample dir in CVS tree on SourceForge.
2518 +----------------------------------------
2519 +When you have any problems or strange behaviour in aufs, please let me
2521 +- /proc/mounts (instead of the output of mount(8))
2522 +- /sys/module/aufs/*
2523 +- /sys/fs/aufs/* (if you have them)
2524 +- /debug/aufs/* (if you have them)
2525 +- linux kernel version
2526 + if your kernel is not plain, for example modified by distributor,
2527 + the url where i can download its source is necessary too.
2528 +- aufs version which was printed at loading the module or booting the
2529 + system, instead of the date you downloaded.
2530 +- configuration (define/undefine CONFIG_AUFS_xxx)
2531 +- kernel configuration or /proc/config.gz (if you have it)
2532 +- behaviour which you think to be incorrect
2533 +- actual operation, reproducible one is better
2534 +- mailto: aufs-users at lists.sourceforge.net
2536 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2537 +and Feature Requests) on SourceForge. Please join and write to
2541 +6. Acknowledgements
2542 +----------------------------------------
2543 +Thanks to everyone who have tried and are using aufs, whoever
2544 +have reported a bug or any feedback.
2546 +Especially donators:
2547 +Tomas Matejicek(slax.org) made a donation (much more than once).
2548 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2549 + scripts) is making "doubling" donations.
2550 + Unfortunately I cannot list all of the donators, but I really
2552 + It ends Aug 2010, but the ordinary donation URL is still available.
2553 + <http://sourceforge.net/donate/index.php?group_id=167503>
2554 +Dai Itasaka made a donation (2007/8).
2555 +Chuck Smith made a donation (2008/4, 10 and 12).
2556 +Henk Schoneveld made a donation (2008/9).
2557 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2558 +Francois Dupoux made a donation (2008/11).
2559 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2560 + aufs2 GIT tree (2009/2).
2561 +William Grant made a donation (2009/3).
2562 +Patrick Lane made a donation (2009/4).
2563 +The Mail Archive (mail-archive.com) made donations (2009/5).
2564 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2565 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2566 +Pavel Pronskiy made a donation (2011/2).
2567 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2568 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2569 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2571 +Sam Liddicott made a donation (2011/9).
2572 +Era Scarecrow made a donation (2013/4).
2573 +Bor Ratajc made a donation (2013/4).
2574 +Alessandro Gorreta made a donation (2013/4).
2575 +POIRETTE Marc made a donation (2013/4).
2576 +Alessandro Gorreta made a donation (2013/4).
2577 +lauri kasvandik made a donation (2013/5).
2578 +"pemasu from Finland" made a donation (2013/7).
2579 +The Parted Magic Project made a donation (2013/9 and 11).
2580 +Pavel Barta made a donation (2013/10).
2581 +Nikolay Pertsev made a donation (2014/5).
2582 +James B made a donation (2014/7).
2583 +Stefano Di Biase made a donation (2014/8).
2585 +Thank you very much.
2586 +Donations are always, including future donations, very important and
2587 +helpful for me to keep on developing aufs.
2591 +----------------------------------------
2592 +If you are an experienced user, no explanation is needed. Aufs is
2593 +just a linux filesystem.
2598 +# Local variables: ;
2601 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2602 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2603 +++ linux/fs/aufs/aufs.h 2015-01-25 13:00:38.627713742 +0100
2606 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2608 + * This program, aufs is free software; you can redistribute it and/or modify
2609 + * it under the terms of the GNU General Public License as published by
2610 + * the Free Software Foundation; either version 2 of the License, or
2611 + * (at your option) any later version.
2613 + * This program is distributed in the hope that it will be useful,
2614 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2615 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2616 + * GNU General Public License for more details.
2618 + * You should have received a copy of the GNU General Public License
2619 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2623 + * all header files
2631 +#define AuStub(type, name, body, ...) \
2632 + static inline type name(__VA_ARGS__) { body; }
2634 +#define AuStubVoid(name, ...) \
2635 + AuStub(void, name, , __VA_ARGS__)
2636 +#define AuStubInt0(name, ...) \
2637 + AuStub(int, name, return 0, __VA_ARGS__)
2641 +#include "branch.h"
2644 +#include "dbgaufs.h"
2645 +#include "dentry.h"
2649 +#include "fstype.h"
2652 +#include "module.h"
2657 +#include "sysaufs.h"
2662 +#endif /* __KERNEL__ */
2663 +#endif /* __AUFS_H__ */
2664 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2665 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2666 +++ linux/fs/aufs/branch.c 2015-01-25 13:00:38.627713742 +0100
2669 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2671 + * This program, aufs is free software; you can redistribute it and/or modify
2672 + * it under the terms of the GNU General Public License as published by
2673 + * the Free Software Foundation; either version 2 of the License, or
2674 + * (at your option) any later version.
2676 + * This program is distributed in the hope that it will be useful,
2677 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2678 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2679 + * GNU General Public License for more details.
2681 + * You should have received a copy of the GNU General Public License
2682 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2686 + * branch management
2689 +#include <linux/compat.h>
2690 +#include <linux/statfs.h>
2694 + * free a single branch
2696 +static void au_br_do_free(struct au_branch *br)
2699 + struct au_wbr *wbr;
2700 + struct au_dykey **key;
2702 + au_hnotify_fin_br(br);
2704 + if (br->br_xino.xi_file)
2705 + fput(br->br_xino.xi_file);
2706 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2708 + AuDebugOn(atomic_read(&br->br_count));
2712 + for (i = 0; i < AuBrWh_Last; i++)
2713 + dput(wbr->wbr_wh[i]);
2714 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2715 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2718 + if (br->br_fhsm) {
2719 + au_br_fhsm_fin(br->br_fhsm);
2720 + kfree(br->br_fhsm);
2723 + key = br->br_dykey;
2724 + for (i = 0; i < AuBrDynOp; i++, key++)
2730 + /* recursive lock, s_umount of branch's */
2732 + path_put(&br->br_path);
2739 + * frees all branches
2741 +void au_br_free(struct au_sbinfo *sbinfo)
2743 + aufs_bindex_t bmax;
2744 + struct au_branch **br;
2746 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2748 + bmax = sbinfo->si_bend + 1;
2749 + br = sbinfo->si_branch;
2751 + au_br_do_free(*br++);
2755 + * find the index of a branch which is specified by @br_id.
2757 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2759 + aufs_bindex_t bindex, bend;
2761 + bend = au_sbend(sb);
2762 + for (bindex = 0; bindex <= bend; bindex++)
2763 + if (au_sbr_id(sb, bindex) == br_id)
2768 +/* ---------------------------------------------------------------------- */
2774 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2775 + struct dentry *h_root)
2777 + if (unlikely(h_adding == h_root
2778 + || au_test_loopback_overlap(sb, h_adding)))
2780 + if (h_adding->d_sb != h_root->d_sb)
2782 + return au_test_subdir(h_adding, h_root)
2783 + || au_test_subdir(h_root, h_adding);
2787 + * returns a newly allocated branch. @new_nbranch is a number of branches
2788 + * after adding a branch.
2790 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2793 + struct au_branch *add_branch;
2794 + struct dentry *root;
2798 + root = sb->s_root;
2799 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2800 + if (unlikely(!add_branch))
2803 + err = au_hnotify_init_br(add_branch, perm);
2804 + if (unlikely(err))
2807 + add_branch->br_wbr = NULL;
2808 + if (au_br_writable(perm)) {
2809 + /* may be freed separately at changing the branch permission */
2810 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2812 + if (unlikely(!add_branch->br_wbr))
2816 + add_branch->br_fhsm = NULL;
2817 + if (au_br_fhsm(perm)) {
2818 + err = au_fhsm_br_alloc(add_branch);
2819 + if (unlikely(err))
2823 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2825 + err = au_di_realloc(au_di(root), new_nbranch);
2827 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2829 + return add_branch; /* success */
2832 + kfree(add_branch->br_wbr);
2834 + au_hnotify_fin_br(add_branch);
2836 + kfree(add_branch);
2838 + return ERR_PTR(err);
2842 + * test if the branch permission is legal or not.
2844 +static int test_br(struct inode *inode, int brperm, char *path)
2848 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2853 + pr_err("write permission for readonly mount or inode, %s\n", path);
2861 + * 0: success, the caller will add it
2862 + * plus: success, it is already unified, the caller should ignore it
2865 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2868 + aufs_bindex_t bend, bindex;
2869 + struct dentry *root;
2870 + struct inode *inode, *h_inode;
2872 + root = sb->s_root;
2873 + bend = au_sbend(sb);
2874 + if (unlikely(bend >= 0
2875 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2879 + pr_err("%s duplicated\n", add->pathname);
2884 + err = -ENOSPC; /* -E2BIG; */
2885 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2886 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2887 + pr_err("number of branches exceeded %s\n", add->pathname);
2892 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2893 + pr_err("bad index %d\n", add->bindex);
2897 + inode = add->path.dentry->d_inode;
2899 + if (unlikely(!inode->i_nlink)) {
2900 + pr_err("no existence %s\n", add->pathname);
2905 + if (unlikely(inode->i_sb == sb)) {
2906 + pr_err("%s must be outside\n", add->pathname);
2910 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2911 + pr_err("unsupported filesystem, %s (%s)\n",
2912 + add->pathname, au_sbtype(inode->i_sb));
2916 + if (unlikely(inode->i_sb->s_stack_depth)) {
2917 + pr_err("already stacked, %s (%s)\n",
2918 + add->pathname, au_sbtype(inode->i_sb));
2922 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2923 + if (unlikely(err))
2927 + return 0; /* success */
2930 + for (bindex = 0; bindex <= bend; bindex++)
2931 + if (unlikely(test_overlap(sb, add->path.dentry,
2932 + au_h_dptr(root, bindex)))) {
2933 + pr_err("%s is overlapped\n", add->pathname);
2938 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2939 + h_inode = au_h_dptr(root, 0)->d_inode;
2940 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2941 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2942 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2943 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2945 + i_uid_read(inode), i_gid_read(inode),
2946 + (inode->i_mode & S_IALLUGO),
2947 + i_uid_read(h_inode), i_gid_read(h_inode),
2948 + (h_inode->i_mode & S_IALLUGO));
2956 + * initialize or clean the whiteouts for an adding branch
2958 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2961 + int err, old_perm;
2962 + aufs_bindex_t bindex;
2963 + struct mutex *h_mtx;
2964 + struct au_wbr *wbr;
2965 + struct au_hinode *hdir;
2967 + err = vfsub_mnt_want_write(au_br_mnt(br));
2968 + if (unlikely(err))
2972 + old_perm = br->br_perm;
2973 + br->br_perm = new_perm;
2976 + bindex = au_br_index(sb, br->br_id);
2977 + if (0 <= bindex) {
2978 + hdir = au_hi(sb->s_root->d_inode, bindex);
2979 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2981 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2982 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2985 + err = au_wh_init(br, sb);
2987 + wbr_wh_write_lock(wbr);
2988 + err = au_wh_init(br, sb);
2989 + wbr_wh_write_unlock(wbr);
2992 + au_hn_imtx_unlock(hdir);
2994 + mutex_unlock(h_mtx);
2995 + vfsub_mnt_drop_write(au_br_mnt(br));
2996 + br->br_perm = old_perm;
2998 + if (!err && wbr && !au_br_writable(new_perm)) {
3000 + br->br_wbr = NULL;
3007 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3011 + struct kstatfs kst;
3012 + struct au_wbr *wbr;
3015 + au_rw_init(&wbr->wbr_wh_rwsem);
3016 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
3017 + atomic_set(&wbr->wbr_wh_running, 0);
3018 + wbr->wbr_bytes = 0;
3021 + * a limit for rmdir/rename a dir
3022 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3024 + err = vfs_statfs(&br->br_path, &kst);
3025 + if (unlikely(err))
3028 + if (kst.f_namelen >= NAME_MAX)
3029 + err = au_br_init_wh(sb, br, perm);
3031 + pr_err("%pd(%s), unsupported namelen %ld\n",
3033 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3039 +/* initialize a new branch */
3040 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3041 + struct au_opt_add *add)
3046 + memset(&br->br_xino, 0, sizeof(br->br_xino));
3047 + mutex_init(&br->br_xino.xi_nondir_mtx);
3048 + br->br_perm = add->perm;
3049 + br->br_path = add->path; /* set first, path_get() later */
3050 + spin_lock_init(&br->br_dykey_lock);
3051 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
3052 + atomic_set(&br->br_count, 0);
3053 + atomic_set(&br->br_xino_running, 0);
3054 + br->br_id = au_new_br_id(sb);
3055 + AuDebugOn(br->br_id < 0);
3057 + if (au_br_writable(add->perm)) {
3058 + err = au_wbr_init(br, sb, add->perm);
3059 + if (unlikely(err))
3063 + if (au_opt_test(au_mntflags(sb), XINO)) {
3064 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
3065 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3066 + if (unlikely(err)) {
3067 + AuDebugOn(br->br_xino.xi_file);
3072 + sysaufs_br_init(br);
3073 + path_get(&br->br_path);
3074 + goto out; /* success */
3077 + memset(&br->br_path, 0, sizeof(br->br_path));
3082 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3083 + struct au_branch *br, aufs_bindex_t bend,
3084 + aufs_bindex_t amount)
3086 + struct au_branch **brp;
3088 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3090 + brp = sbinfo->si_branch + bindex;
3091 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3093 + sbinfo->si_bend++;
3094 + if (unlikely(bend < 0))
3095 + sbinfo->si_bend = 0;
3098 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3099 + aufs_bindex_t bend, aufs_bindex_t amount)
3101 + struct au_hdentry *hdp;
3103 + AuRwMustWriteLock(&dinfo->di_rwsem);
3105 + hdp = dinfo->di_hdentry + bindex;
3106 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3107 + au_h_dentry_init(hdp);
3109 + if (unlikely(bend < 0))
3110 + dinfo->di_bstart = 0;
3113 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3114 + aufs_bindex_t bend, aufs_bindex_t amount)
3116 + struct au_hinode *hip;
3118 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3120 + hip = iinfo->ii_hinode + bindex;
3121 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3122 + hip->hi_inode = NULL;
3125 + if (unlikely(bend < 0))
3126 + iinfo->ii_bstart = 0;
3129 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3130 + aufs_bindex_t bindex)
3132 + struct dentry *root, *h_dentry;
3133 + struct inode *root_inode;
3134 + aufs_bindex_t bend, amount;
3136 + root = sb->s_root;
3137 + root_inode = root->d_inode;
3138 + bend = au_sbend(sb);
3139 + amount = bend + 1 - bindex;
3140 + h_dentry = au_br_dentry(br);
3141 + au_sbilist_lock();
3142 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3143 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3144 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3145 + au_set_h_dptr(root, bindex, dget(h_dentry));
3146 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
3148 + au_sbilist_unlock();
3151 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3154 + aufs_bindex_t bend, add_bindex;
3155 + struct dentry *root, *h_dentry;
3156 + struct inode *root_inode;
3157 + struct au_branch *add_branch;
3159 + root = sb->s_root;
3160 + root_inode = root->d_inode;
3161 + IMustLock(root_inode);
3162 + err = test_add(sb, add, remount);
3163 + if (unlikely(err < 0))
3167 + goto out; /* success */
3170 + bend = au_sbend(sb);
3171 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3172 + err = PTR_ERR(add_branch);
3173 + if (IS_ERR(add_branch))
3176 + err = au_br_init(add_branch, sb, add);
3177 + if (unlikely(err)) {
3178 + au_br_do_free(add_branch);
3182 + add_bindex = add->bindex;
3184 + au_br_do_add(sb, add_branch, add_bindex);
3186 + sysaufs_brs_del(sb, add_bindex);
3187 + au_br_do_add(sb, add_branch, add_bindex);
3188 + sysaufs_brs_add(sb, add_bindex);
3191 + h_dentry = add->path.dentry;
3192 + if (!add_bindex) {
3193 + au_cpup_attr_all(root_inode, /*force*/1);
3194 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3196 + au_add_nlink(root_inode, h_dentry->d_inode);
3199 + * this test/set prevents aufs from handling unnecesary notify events
3200 + * of xino files, in case of re-adding a writable branch which was
3201 + * once detached from aufs.
3203 + if (au_xino_brid(sb) < 0
3204 + && au_br_writable(add_branch->br_perm)
3205 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3206 + && add_branch->br_xino.xi_file
3207 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
3208 + au_xino_brid_set(sb, add_branch->br_id);
3214 +/* ---------------------------------------------------------------------- */
3216 +static unsigned long long au_farray_cb(void *a,
3217 + unsigned long long max __maybe_unused,
3220 + unsigned long long n;
3221 + struct file **p, *f;
3222 + struct au_sphlhead *files;
3223 + struct au_finfo *finfo;
3224 + struct super_block *sb = arg;
3228 + files = &au_sbi(sb)->si_files;
3229 + spin_lock(&files->spin);
3230 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3231 + f = finfo->fi_file;
3233 + && !special_file(file_inode(f)->i_mode)) {
3237 + AuDebugOn(n > max);
3240 + spin_unlock(&files->spin);
3245 +static struct file **au_farray_alloc(struct super_block *sb,
3246 + unsigned long long *max)
3248 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3249 + return au_array_alloc(max, au_farray_cb, sb);
3252 +static void au_farray_free(struct file **a, unsigned long long max)
3254 + unsigned long long ull;
3256 + for (ull = 0; ull < max; ull++)
3262 +/* ---------------------------------------------------------------------- */
3268 +/* to show the line number, do not make it inlined function */
3269 +#define AuVerbose(do_info, fmt, ...) do { \
3271 + pr_info(fmt, ##__VA_ARGS__); \
3274 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3275 + aufs_bindex_t bend)
3277 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3280 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3281 + aufs_bindex_t bend)
3283 + return au_test_ibusy(dentry->d_inode, bstart, bend);
3287 + * test if the branch is deletable or not.
3289 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3290 + unsigned int sigen, const unsigned int verbose)
3292 + int err, i, j, ndentry;
3293 + aufs_bindex_t bstart, bend;
3294 + struct au_dcsub_pages dpages;
3295 + struct au_dpage *dpage;
3298 + err = au_dpages_init(&dpages, GFP_NOFS);
3299 + if (unlikely(err))
3301 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3302 + if (unlikely(err))
3305 + for (i = 0; !err && i < dpages.ndpage; i++) {
3306 + dpage = dpages.dpages + i;
3307 + ndentry = dpage->ndentry;
3308 + for (j = 0; !err && j < ndentry; j++) {
3309 + d = dpage->dentries[j];
3310 + AuDebugOn(au_dcount(d) <= 0);
3311 + if (!au_digen_test(d, sigen)) {
3312 + di_read_lock_child(d, AuLock_IR);
3313 + if (unlikely(au_dbrange_test(d))) {
3314 + di_read_unlock(d, AuLock_IR);
3318 + di_write_lock_child(d);
3319 + if (unlikely(au_dbrange_test(d))) {
3320 + di_write_unlock(d);
3323 + err = au_reval_dpath(d, sigen);
3325 + di_downgrade_lock(d, AuLock_IR);
3327 + di_write_unlock(d);
3332 + /* AuDbgDentry(d); */
3333 + bstart = au_dbstart(d);
3334 + bend = au_dbend(d);
3335 + if (bstart <= bindex
3337 + && au_h_dptr(d, bindex)
3338 + && au_test_dbusy(d, bstart, bend)) {
3340 + AuVerbose(verbose, "busy %pd\n", d);
3343 + di_read_unlock(d, AuLock_IR);
3348 + au_dpages_free(&dpages);
3353 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3354 + unsigned int sigen, const unsigned int verbose)
3357 + unsigned long long max, ull;
3358 + struct inode *i, **array;
3359 + aufs_bindex_t bstart, bend;
3361 + array = au_iarray_alloc(sb, &max);
3362 + err = PTR_ERR(array);
3363 + if (IS_ERR(array))
3367 + AuDbg("b%d\n", bindex);
3368 + for (ull = 0; !err && ull < max; ull++) {
3372 + if (i->i_ino == AUFS_ROOT_INO)
3375 + /* AuDbgInode(i); */
3376 + if (au_iigen(i, NULL) == sigen)
3377 + ii_read_lock_child(i);
3379 + ii_write_lock_child(i);
3380 + err = au_refresh_hinode_self(i);
3383 + ii_downgrade_lock(i);
3385 + ii_write_unlock(i);
3390 + bstart = au_ibstart(i);
3391 + bend = au_ibend(i);
3392 + if (bstart <= bindex
3394 + && au_h_iptr(i, bindex)
3395 + && au_test_ibusy(i, bstart, bend)) {
3397 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3400 + ii_read_unlock(i);
3402 + au_iarray_free(array, max);
3408 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3409 + const unsigned int verbose)
3412 + unsigned int sigen;
3414 + sigen = au_sigen(root->d_sb);
3415 + DiMustNoWaiters(root);
3416 + IiMustNoWaiters(root->d_inode);
3417 + di_write_unlock(root);
3418 + err = test_dentry_busy(root, bindex, sigen, verbose);
3420 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3421 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3426 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3427 + struct file **to_free, int *idx)
3430 + unsigned char matched, root;
3431 + aufs_bindex_t bindex, bend;
3432 + struct au_fidir *fidir;
3433 + struct au_hfile *hfile;
3436 + root = IS_ROOT(file->f_dentry);
3439 + to_free[*idx] = file;
3445 + fidir = au_fi(file)->fi_hdir;
3446 + AuDebugOn(!fidir);
3447 + bend = au_fbend_dir(file);
3448 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3449 + hfile = fidir->fd_hfile + bindex;
3450 + if (!hfile->hf_file)
3453 + if (hfile->hf_br->br_id == br_id) {
3465 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3466 + struct file **to_free, int opened)
3469 + unsigned long long ull, max;
3470 + aufs_bindex_t bstart;
3471 + struct file *file, **array;
3472 + struct inode *inode;
3473 + struct dentry *root;
3474 + struct au_hfile *hfile;
3476 + array = au_farray_alloc(sb, &max);
3477 + err = PTR_ERR(array);
3478 + if (IS_ERR(array))
3483 + root = sb->s_root;
3484 + di_write_unlock(root);
3485 + for (ull = 0; ull < max; ull++) {
3486 + file = array[ull];
3487 + if (unlikely(!file))
3490 + /* AuDbg("%pD\n", file); */
3491 + fi_read_lock(file);
3492 + bstart = au_fbstart(file);
3493 + inode = file_inode(file);
3494 + if (!S_ISDIR(inode->i_mode)) {
3495 + hfile = &au_fi(file)->fi_htop;
3496 + if (hfile->hf_br->br_id == br_id)
3499 + err = test_dir_busy(file, br_id, to_free, &idx);
3500 + fi_read_unlock(file);
3501 + if (unlikely(err))
3504 + di_write_lock_child(root);
3505 + au_farray_free(array, max);
3506 + AuDebugOn(idx > opened);
3512 +static void br_del_file(struct file **to_free, unsigned long long opened,
3513 + aufs_bindex_t br_id)
3515 + unsigned long long ull;
3516 + aufs_bindex_t bindex, bstart, bend, bfound;
3517 + struct file *file;
3518 + struct au_fidir *fidir;
3519 + struct au_hfile *hfile;
3521 + for (ull = 0; ull < opened; ull++) {
3522 + file = to_free[ull];
3523 + if (unlikely(!file))
3526 + /* AuDbg("%pD\n", file); */
3527 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
3529 + fidir = au_fi(file)->fi_hdir;
3530 + AuDebugOn(!fidir);
3531 + fi_write_lock(file);
3532 + bstart = au_fbstart(file);
3533 + bend = au_fbend_dir(file);
3534 + for (bindex = bstart; bindex <= bend; bindex++) {
3535 + hfile = fidir->fd_hfile + bindex;
3536 + if (!hfile->hf_file)
3539 + if (hfile->hf_br->br_id == br_id) {
3544 + AuDebugOn(bfound < 0);
3545 + au_set_h_fptr(file, bfound, NULL);
3546 + if (bfound == bstart) {
3547 + for (bstart++; bstart <= bend; bstart++)
3548 + if (au_hf_dir(file, bstart)) {
3549 + au_set_fbstart(file, bstart);
3553 + fi_write_unlock(file);
3557 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3558 + const aufs_bindex_t bindex,
3559 + const aufs_bindex_t bend)
3561 + struct au_branch **brp, **p;
3563 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3565 + brp = sbinfo->si_branch + bindex;
3566 + if (bindex < bend)
3567 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3568 + sbinfo->si_branch[0 + bend] = NULL;
3569 + sbinfo->si_bend--;
3571 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3573 + sbinfo->si_branch = p;
3574 + /* harmless error */
3577 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3578 + const aufs_bindex_t bend)
3580 + struct au_hdentry *hdp, *p;
3582 + AuRwMustWriteLock(&dinfo->di_rwsem);
3584 + hdp = dinfo->di_hdentry;
3585 + if (bindex < bend)
3586 + memmove(hdp + bindex, hdp + bindex + 1,
3587 + sizeof(*hdp) * (bend - bindex));
3588 + hdp[0 + bend].hd_dentry = NULL;
3591 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3593 + dinfo->di_hdentry = p;
3594 + /* harmless error */
3597 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3598 + const aufs_bindex_t bend)
3600 + struct au_hinode *hip, *p;
3602 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3604 + hip = iinfo->ii_hinode + bindex;
3605 + if (bindex < bend)
3606 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3607 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3608 + au_hn_init(iinfo->ii_hinode + bend);
3611 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3613 + iinfo->ii_hinode = p;
3614 + /* harmless error */
3617 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3618 + struct au_branch *br)
3620 + aufs_bindex_t bend;
3621 + struct au_sbinfo *sbinfo;
3622 + struct dentry *root, *h_root;
3623 + struct inode *inode, *h_inode;
3624 + struct au_hinode *hinode;
3626 + SiMustWriteLock(sb);
3628 + root = sb->s_root;
3629 + inode = root->d_inode;
3630 + sbinfo = au_sbi(sb);
3631 + bend = sbinfo->si_bend;
3633 + h_root = au_h_dptr(root, bindex);
3634 + hinode = au_hi(inode, bindex);
3635 + h_inode = au_igrab(hinode->hi_inode);
3638 + au_sbilist_lock();
3639 + au_br_do_del_brp(sbinfo, bindex, bend);
3640 + au_br_do_del_hdp(au_di(root), bindex, bend);
3641 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3642 + au_sbilist_unlock();
3646 + au_br_do_free(br);
3649 +static unsigned long long empty_cb(void *array, unsigned long long max,
3655 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3658 + unsigned long long opened;
3659 + unsigned int mnt_flags;
3660 + aufs_bindex_t bindex, bend, br_id;
3661 + unsigned char do_wh, verbose;
3662 + struct au_branch *br;
3663 + struct au_wbr *wbr;
3664 + struct dentry *root;
3665 + struct file **to_free;
3670 + root = sb->s_root;
3671 + bindex = au_find_dbindex(root, del->h_path.dentry);
3674 + goto out; /* success */
3676 + pr_err("%s no such branch\n", del->pathname);
3679 + AuDbg("bindex b%d\n", bindex);
3682 + mnt_flags = au_mntflags(sb);
3683 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3684 + bend = au_sbend(sb);
3685 + if (unlikely(!bend)) {
3686 + AuVerbose(verbose, "no more branches left\n");
3689 + br = au_sbr(sb, bindex);
3690 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3692 + br_id = br->br_id;
3693 + opened = atomic_read(&br->br_count);
3694 + if (unlikely(opened)) {
3695 + to_free = au_array_alloc(&opened, empty_cb, NULL);
3696 + err = PTR_ERR(to_free);
3697 + if (IS_ERR(to_free))
3700 + err = test_file_busy(sb, br_id, to_free, opened);
3701 + if (unlikely(err)) {
3702 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3708 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3710 + /* instead of WbrWhMustWriteLock(wbr) */
3711 + SiMustWriteLock(sb);
3712 + for (i = 0; i < AuBrWh_Last; i++) {
3713 + dput(wbr->wbr_wh[i]);
3714 + wbr->wbr_wh[i] = NULL;
3718 + err = test_children_busy(root, bindex, verbose);
3719 + if (unlikely(err)) {
3728 + * now we confirmed the branch is deletable.
3729 + * let's free the remaining opened dirs on the branch.
3731 + di_write_unlock(root);
3732 + br_del_file(to_free, opened, br_id);
3733 + di_write_lock_child(root);
3737 + au_br_do_del(sb, bindex, br);
3739 + sysaufs_brs_del(sb, bindex);
3740 + au_br_do_del(sb, bindex, br);
3741 + sysaufs_brs_add(sb, bindex);
3745 + au_cpup_attr_all(root->d_inode, /*force*/1);
3746 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3748 + au_sub_nlink(root->d_inode, del->h_path.dentry->d_inode);
3749 + if (au_opt_test(mnt_flags, PLINK))
3750 + au_plink_half_refresh(sb, br_id);
3752 + if (au_xino_brid(sb) == br_id)
3753 + au_xino_brid_set(sb, -1);
3754 + goto out; /* success */
3758 + rerr = au_br_init_wh(sb, br, br->br_perm);
3760 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3761 + del->pathname, rerr);
3764 + au_farray_free(to_free, opened);
3768 +/* ---------------------------------------------------------------------- */
3770 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3773 + aufs_bindex_t bstart, bend;
3774 + struct aufs_ibusy ibusy;
3775 + struct inode *inode, *h_inode;
3778 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3781 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3783 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3784 + if (unlikely(err)) {
3791 + si_read_lock(sb, AuLock_FLUSH);
3792 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3796 + ibusy.h_ino = 0; /* invalid */
3797 + inode = ilookup(sb, ibusy.ino);
3799 + || inode->i_ino == AUFS_ROOT_INO
3800 + || is_bad_inode(inode))
3803 + ii_read_lock_child(inode);
3804 + bstart = au_ibstart(inode);
3805 + bend = au_ibend(inode);
3806 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3807 + h_inode = au_h_iptr(inode, ibusy.bindex);
3808 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3809 + ibusy.h_ino = h_inode->i_ino;
3811 + ii_read_unlock(inode);
3815 + si_read_unlock(sb);
3817 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3818 + if (unlikely(err)) {
3827 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3829 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
3832 +#ifdef CONFIG_COMPAT
3833 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3835 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
3839 +/* ---------------------------------------------------------------------- */
3842 + * change a branch permission
3845 +static void au_warn_ima(void)
3848 + /* since it doesn't support mark_files_ro() */
3849 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3853 +static int do_need_sigen_inc(int a, int b)
3855 + return au_br_whable(a) && !au_br_whable(b);
3858 +static int need_sigen_inc(int old, int new)
3860 + return do_need_sigen_inc(old, new)
3861 + || do_need_sigen_inc(new, old);
3864 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3867 + unsigned int mnt_flags;
3868 + unsigned long long ull, max;
3869 + aufs_bindex_t br_id;
3870 + unsigned char verbose, writer;
3871 + struct file *file, *hf, **array;
3872 + struct inode *inode;
3873 + struct au_hfile *hfile;
3875 + mnt_flags = au_mntflags(sb);
3876 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3878 + array = au_farray_alloc(sb, &max);
3879 + err = PTR_ERR(array);
3880 + if (IS_ERR(array))
3884 + br_id = au_sbr_id(sb, bindex);
3885 + for (ull = 0; ull < max; ull++) {
3886 + file = array[ull];
3887 + if (unlikely(!file))
3890 + /* AuDbg("%pD\n", file); */
3891 + fi_read_lock(file);
3892 + if (unlikely(au_test_mmapped(file))) {
3894 + AuVerbose(verbose, "mmapped %pD\n", file);
3896 + FiMustNoWaiters(file);
3897 + fi_read_unlock(file);
3901 + inode = file_inode(file);
3902 + hfile = &au_fi(file)->fi_htop;
3903 + hf = hfile->hf_file;
3904 + if (!S_ISREG(inode->i_mode)
3905 + || !(file->f_mode & FMODE_WRITE)
3906 + || hfile->hf_br->br_id != br_id
3907 + || !(hf->f_mode & FMODE_WRITE))
3908 + array[ull] = NULL;
3914 + FiMustNoWaiters(file);
3915 + fi_read_unlock(file);
3923 + for (ull = 0; ull < max; ull++) {
3924 + file = array[ull];
3928 + /* todo: already flushed? */
3930 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
3931 + * approach which resets f_mode and calls mnt_drop_write() and
3932 + * file_release_write() for each file, because the branch
3933 + * attribute in aufs world is totally different from the native
3936 + /* fi_read_lock(file); */
3937 + hfile = &au_fi(file)->fi_htop;
3938 + hf = hfile->hf_file;
3939 + /* fi_read_unlock(file); */
3940 + spin_lock(&hf->f_lock);
3941 + writer = !!(hf->f_mode & FMODE_WRITER);
3942 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
3943 + spin_unlock(&hf->f_lock);
3945 + put_write_access(file_inode(hf));
3946 + __mnt_drop_write(hf->f_path.mnt);
3951 + au_farray_free(array, max);
3957 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3961 + aufs_bindex_t bindex;
3962 + struct dentry *root;
3963 + struct au_branch *br;
3964 + struct au_br_fhsm *bf;
3966 + root = sb->s_root;
3967 + bindex = au_find_dbindex(root, mod->h_root);
3970 + return 0; /* success */
3972 + pr_err("%s no such branch\n", mod->path);
3975 + AuDbg("bindex b%d\n", bindex);
3977 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3978 + if (unlikely(err))
3981 + br = au_sbr(sb, bindex);
3982 + AuDebugOn(mod->h_root != au_br_dentry(br));
3983 + if (br->br_perm == mod->perm)
3984 + return 0; /* success */
3986 + /* pre-allocate for non-fhsm --> fhsm */
3988 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
3989 + err = au_fhsm_br_alloc(br);
3990 + if (unlikely(err))
3993 + br->br_fhsm = NULL;
3996 + if (au_br_writable(br->br_perm)) {
3997 + /* remove whiteout base */
3998 + err = au_br_init_wh(sb, br, mod->perm);
3999 + if (unlikely(err))
4002 + if (!au_br_writable(mod->perm)) {
4003 + /* rw --> ro, file might be mmapped */
4004 + DiMustNoWaiters(root);
4005 + IiMustNoWaiters(root->d_inode);
4006 + di_write_unlock(root);
4007 + err = au_br_mod_files_ro(sb, bindex);
4008 + /* aufs_write_lock() calls ..._child() */
4009 + di_write_lock_child(root);
4011 + if (unlikely(err)) {
4013 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
4016 + rerr = au_wbr_init(br, sb, br->br_perm);
4017 + if (unlikely(rerr)) {
4018 + AuIOErr("nested error %d (%d)\n",
4020 + br->br_perm = mod->perm;
4024 + } else if (au_br_writable(mod->perm)) {
4027 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
4029 + err = au_wbr_init(br, sb, mod->perm);
4030 + if (unlikely(err)) {
4031 + kfree(br->br_wbr);
4032 + br->br_wbr = NULL;
4036 + if (unlikely(err))
4039 + if (au_br_fhsm(br->br_perm)) {
4040 + if (!au_br_fhsm(mod->perm)) {
4041 + /* fhsm --> non-fhsm */
4042 + au_br_fhsm_fin(br->br_fhsm);
4043 + kfree(br->br_fhsm);
4044 + br->br_fhsm = NULL;
4046 + } else if (au_br_fhsm(mod->perm))
4047 + /* non-fhsm --> fhsm */
4050 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4051 + br->br_perm = mod->perm;
4052 + goto out; /* success */
4061 +/* ---------------------------------------------------------------------- */
4063 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4066 + struct kstatfs kstfs;
4068 + err = vfs_statfs(&br->br_path, &kstfs);
4070 + stfs->f_blocks = kstfs.f_blocks;
4071 + stfs->f_bavail = kstfs.f_bavail;
4072 + stfs->f_files = kstfs.f_files;
4073 + stfs->f_ffree = kstfs.f_ffree;
4078 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4079 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4080 +++ linux/fs/aufs/branch.h 2015-01-25 13:00:38.627713742 +0100
4083 + * Copyright (C) 2005-2014 Junjiro R. Okajima
4085 + * This program, aufs is free software; you can redistribute it and/or modify
4086 + * it under the terms of the GNU General Public License as published by
4087 + * the Free Software Foundation; either version 2 of the License, or
4088 + * (at your option) any later version.
4090 + * This program is distributed in the hope that it will be useful,
4091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4093 + * GNU General Public License for more details.
4095 + * You should have received a copy of the GNU General Public License
4096 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4100 + * branch filesystems and xino for them
4103 +#ifndef __AUFS_BRANCH_H__
4104 +#define __AUFS_BRANCH_H__
4108 +#include <linux/mount.h>
4113 +/* ---------------------------------------------------------------------- */
4116 +struct au_xino_file {
4117 + struct file *xi_file;
4118 + struct mutex xi_nondir_mtx;
4120 + /* todo: make xino files an array to support huge inode number */
4122 +#ifdef CONFIG_DEBUG_FS
4123 + struct dentry *xi_dbgaufs;
4127 +/* File-based Hierarchical Storage Management */
4128 +struct au_br_fhsm {
4129 +#ifdef CONFIG_AUFS_FHSM
4130 + struct mutex bf_lock;
4131 + unsigned long bf_jiffy;
4132 + struct aufs_stfs bf_stfs;
4137 +/* members for writable branch only */
4138 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4140 + struct au_rwsem wbr_wh_rwsem;
4141 + struct dentry *wbr_wh[AuBrWh_Last];
4142 + atomic_t wbr_wh_running;
4143 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4144 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4145 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4148 + unsigned long long wbr_bytes;
4151 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4152 +#define AuBrDynOp (AuDyLast * 4)
4154 +#ifdef CONFIG_AUFS_HFSNOTIFY
4155 +/* support for asynchronous destruction */
4156 +struct au_br_hfsnotify {
4157 + struct fsnotify_group *hfsn_group;
4161 +/* sysfs entries */
4162 +struct au_brsysfs {
4164 + struct attribute attr;
4173 +/* protected by superblock rwsem */
4175 + struct au_xino_file br_xino;
4177 + aufs_bindex_t br_id;
4180 + struct path br_path;
4181 + spinlock_t br_dykey_lock;
4182 + struct au_dykey *br_dykey[AuBrDynOp];
4183 + atomic_t br_count;
4185 + struct au_wbr *br_wbr;
4186 + struct au_br_fhsm *br_fhsm;
4188 + /* xino truncation */
4189 + atomic_t br_xino_running;
4191 +#ifdef CONFIG_AUFS_HFSNOTIFY
4192 + struct au_br_hfsnotify *br_hfsn;
4195 +#ifdef CONFIG_SYSFS
4196 + /* entries under sysfs per mount-point */
4197 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4201 +/* ---------------------------------------------------------------------- */
4203 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4205 + return br->br_path.mnt;
4208 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4210 + return br->br_path.dentry;
4213 +static inline struct super_block *au_br_sb(struct au_branch *br)
4215 + return au_br_mnt(br)->mnt_sb;
4218 +static inline int au_br_rdonly(struct au_branch *br)
4220 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4221 + || !au_br_writable(br->br_perm))
4225 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4227 +#ifdef CONFIG_AUFS_HNOTIFY
4228 + return !(brperm & AuBrPerm_RR);
4234 +/* ---------------------------------------------------------------------- */
4238 +void au_br_free(struct au_sbinfo *sinfo);
4239 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4241 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4243 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4244 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4245 +#ifdef CONFIG_COMPAT
4246 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4249 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4252 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4255 +static const loff_t au_loff_max = LLONG_MAX;
4257 +int au_xib_trunc(struct super_block *sb);
4258 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
4260 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
4262 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4263 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4264 +ino_t au_xino_new_ino(struct super_block *sb);
4265 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4266 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4268 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4270 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4271 + struct file *base_file, int do_test);
4272 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4274 +struct au_opt_xino;
4275 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4276 +void au_xino_clr(struct super_block *sb);
4277 +struct file *au_xino_def(struct super_block *sb);
4278 +int au_xino_path(struct seq_file *seq, struct file *file);
4280 +/* ---------------------------------------------------------------------- */
4282 +/* Superblock to branch */
4284 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4286 + return au_sbr(sb, bindex)->br_id;
4290 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4292 + return au_br_mnt(au_sbr(sb, bindex));
4296 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4298 + return au_br_sb(au_sbr(sb, bindex));
4301 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4303 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4306 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4308 + return au_sbr(sb, bindex)->br_perm;
4311 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4313 + return au_br_whable(au_sbr_perm(sb, bindex));
4316 +/* ---------------------------------------------------------------------- */
4319 + * wbr_wh_read_lock, wbr_wh_write_lock
4320 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4322 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4324 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4325 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4326 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4328 +/* ---------------------------------------------------------------------- */
4330 +#ifdef CONFIG_AUFS_FHSM
4331 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4333 + mutex_init(&brfhsm->bf_lock);
4334 + brfhsm->bf_jiffy = 0;
4335 + brfhsm->bf_readable = 0;
4338 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4340 + mutex_destroy(&brfhsm->bf_lock);
4343 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4344 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4347 +#endif /* __KERNEL__ */
4348 +#endif /* __AUFS_BRANCH_H__ */
4349 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4350 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4351 +++ linux/fs/aufs/conf.mk 2015-01-25 13:00:38.631047076 +0100
4354 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4358 +AuConfStr += ${1}=${${1}}
4362 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4364 + HNOTIFY HFSNOTIFY \
4375 +$(foreach i, ${AuConfAll}, \
4376 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4378 +AuConfName = ${obj}/conf.str
4379 +${AuConfName}.tmp: FORCE
4380 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4381 +${AuConfName}: ${AuConfName}.tmp
4382 + @diff -q $< $@ > /dev/null 2>&1 || { \
4383 + echo ' GEN ' $@; \
4387 +clean-files += ${AuConfName} ${AuConfName}.tmp
4388 +${obj}/sysfs.o: ${AuConfName}
4390 +-include ${srctree}/${src}/conf_priv.mk
4391 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4392 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4393 +++ linux/fs/aufs/cpup.c 2015-01-25 13:00:38.631047076 +0100
4396 + * Copyright (C) 2005-2014 Junjiro R. Okajima
4398 + * This program, aufs is free software; you can redistribute it and/or modify
4399 + * it under the terms of the GNU General Public License as published by
4400 + * the Free Software Foundation; either version 2 of the License, or
4401 + * (at your option) any later version.
4403 + * This program is distributed in the hope that it will be useful,
4404 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4405 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4406 + * GNU General Public License for more details.
4408 + * You should have received a copy of the GNU General Public License
4409 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4413 + * copy-up functions, see wbr_policy.c for copy-down
4416 +#include <linux/fs_stack.h>
4417 +#include <linux/mm.h>
4420 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4422 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4423 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4425 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4427 + dst->i_flags |= iflags & ~mask;
4428 + if (au_test_fs_notime(dst->i_sb))
4429 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4432 +void au_cpup_attr_timesizes(struct inode *inode)
4434 + struct inode *h_inode;
4436 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4437 + fsstack_copy_attr_times(inode, h_inode);
4438 + fsstack_copy_inode_size(inode, h_inode);
4441 +void au_cpup_attr_nlink(struct inode *inode, int force)
4443 + struct inode *h_inode;
4444 + struct super_block *sb;
4445 + aufs_bindex_t bindex, bend;
4448 + bindex = au_ibstart(inode);
4449 + h_inode = au_h_iptr(inode, bindex);
4451 + && !S_ISDIR(h_inode->i_mode)
4452 + && au_opt_test(au_mntflags(sb), PLINK)
4453 + && au_plink_test(inode))
4457 + * 0 can happen in revalidating.
4458 + * h_inode->i_mutex may not be held here, but it is harmless since once
4459 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4461 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4462 + * the incorrect link count.
4464 + set_nlink(inode, h_inode->i_nlink);
4467 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4468 + * it may includes whplink directory.
4470 + if (S_ISDIR(h_inode->i_mode)) {
4471 + bend = au_ibend(inode);
4472 + for (bindex++; bindex <= bend; bindex++) {
4473 + h_inode = au_h_iptr(inode, bindex);
4475 + au_add_nlink(inode, h_inode);
4480 +void au_cpup_attr_changeable(struct inode *inode)
4482 + struct inode *h_inode;
4484 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4485 + inode->i_mode = h_inode->i_mode;
4486 + inode->i_uid = h_inode->i_uid;
4487 + inode->i_gid = h_inode->i_gid;
4488 + au_cpup_attr_timesizes(inode);
4489 + au_cpup_attr_flags(inode, h_inode->i_flags);
4492 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4494 + struct au_iinfo *iinfo = au_ii(inode);
4496 + IiMustWriteLock(inode);
4498 + iinfo->ii_higen = h_inode->i_generation;
4499 + iinfo->ii_hsb1 = h_inode->i_sb;
4502 +void au_cpup_attr_all(struct inode *inode, int force)
4504 + struct inode *h_inode;
4506 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4507 + au_cpup_attr_changeable(inode);
4508 + if (inode->i_nlink > 0)
4509 + au_cpup_attr_nlink(inode, force);
4510 + inode->i_rdev = h_inode->i_rdev;
4511 + inode->i_blkbits = h_inode->i_blkbits;
4512 + au_cpup_igen(inode, h_inode);
4515 +/* ---------------------------------------------------------------------- */
4517 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4519 +/* keep the timestamps of the parent dir when cpup */
4520 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4521 + struct path *h_path)
4523 + struct inode *h_inode;
4525 + dt->dt_dentry = dentry;
4526 + dt->dt_h_path = *h_path;
4527 + h_inode = h_path->dentry->d_inode;
4528 + dt->dt_atime = h_inode->i_atime;
4529 + dt->dt_mtime = h_inode->i_mtime;
4533 +void au_dtime_revert(struct au_dtime *dt)
4535 + struct iattr attr;
4538 + attr.ia_atime = dt->dt_atime;
4539 + attr.ia_mtime = dt->dt_mtime;
4540 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4541 + | ATTR_ATIME | ATTR_ATIME_SET;
4543 + /* no delegation since this is a directory */
4544 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4545 + if (unlikely(err))
4546 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4549 +/* ---------------------------------------------------------------------- */
4551 +/* internal use only */
4552 +struct au_cpup_reg_attr {
4555 + unsigned int iflags; /* inode->i_flags */
4558 +static noinline_for_stack
4559 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4560 + struct au_cpup_reg_attr *h_src_attr)
4562 + int err, sbits, icex;
4564 + struct path h_path;
4565 + struct inode *h_isrc, *h_idst;
4566 + struct kstat *h_st;
4567 + struct au_branch *br;
4569 + h_path.dentry = au_h_dptr(dst, bindex);
4570 + h_idst = h_path.dentry->d_inode;
4571 + br = au_sbr(dst->d_sb, bindex);
4572 + h_path.mnt = au_br_mnt(br);
4573 + h_isrc = h_src->d_inode;
4574 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4575 + | ATTR_ATIME | ATTR_MTIME
4576 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4577 + if (h_src_attr && h_src_attr->valid) {
4578 + h_st = &h_src_attr->st;
4579 + ia.ia_uid = h_st->uid;
4580 + ia.ia_gid = h_st->gid;
4581 + ia.ia_atime = h_st->atime;
4582 + ia.ia_mtime = h_st->mtime;
4583 + if (h_idst->i_mode != h_st->mode
4584 + && !S_ISLNK(h_idst->i_mode)) {
4585 + ia.ia_valid |= ATTR_MODE;
4586 + ia.ia_mode = h_st->mode;
4588 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4589 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4591 + ia.ia_uid = h_isrc->i_uid;
4592 + ia.ia_gid = h_isrc->i_gid;
4593 + ia.ia_atime = h_isrc->i_atime;
4594 + ia.ia_mtime = h_isrc->i_mtime;
4595 + if (h_idst->i_mode != h_isrc->i_mode
4596 + && !S_ISLNK(h_idst->i_mode)) {
4597 + ia.ia_valid |= ATTR_MODE;
4598 + ia.ia_mode = h_isrc->i_mode;
4600 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4601 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4603 + /* no delegation since it is just created */
4604 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4606 + /* is this nfs only? */
4607 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4608 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4609 + ia.ia_mode = h_isrc->i_mode;
4610 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4613 + icex = br->br_perm & AuBrAttr_ICEX;
4615 + err = au_cpup_xattr(h_path.dentry, h_src, icex);
4620 +/* ---------------------------------------------------------------------- */
4622 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4623 + char *buf, unsigned long blksize)
4626 + size_t sz, rbytes, wbytes;
4627 + unsigned char all_zero;
4629 + struct mutex *h_mtx;
4630 + /* reduce stack usage */
4633 + zp = page_address(ZERO_PAGE(0));
4634 + if (unlikely(!zp))
4635 + return -ENOMEM; /* possible? */
4640 + AuDbg("len %lld\n", len);
4642 + if (len < blksize)
4646 + /* todo: signal_pending? */
4647 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4648 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4651 + if (unlikely(err < 0))
4655 + if (len >= rbytes && rbytes == blksize)
4656 + all_zero = !memcmp(buf, zp, rbytes);
4663 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4665 + /* todo: signal_pending? */
4666 + if (unlikely(err == -EAGAIN || err == -EINTR))
4668 + if (unlikely(err < 0))
4673 + if (unlikely(err < 0))
4679 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4681 + if (unlikely(res < 0))
4688 + /* the last block may be a hole */
4689 + if (!err && all_zero) {
4690 + AuLabel(last hole);
4693 + if (au_test_nfs(dst->f_dentry->d_sb)) {
4694 + /* nfs requires this step to make last hole */
4695 + /* is this only nfs? */
4697 + /* todo: signal_pending? */
4698 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4699 + } while (err == -EAGAIN || err == -EINTR);
4706 + ia->ia_size = dst->f_pos;
4707 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4708 + ia->ia_file = dst;
4709 + h_mtx = &file_inode(dst)->i_mutex;
4710 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4711 + /* no delegation since it is just created */
4712 + err = vfsub_notify_change(&dst->f_path, ia,
4713 + /*delegated*/NULL);
4714 + mutex_unlock(h_mtx);
4721 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4724 + unsigned long blksize;
4725 + unsigned char do_kfree;
4729 + blksize = dst->f_dentry->d_sb->s_blocksize;
4730 + if (!blksize || PAGE_SIZE < blksize)
4731 + blksize = PAGE_SIZE;
4732 + AuDbg("blksize %lu\n", blksize);
4733 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4735 + buf = kmalloc(blksize, GFP_NOFS);
4737 + buf = (void *)__get_free_page(GFP_NOFS);
4738 + if (unlikely(!buf))
4741 + if (len > (1 << 22))
4742 + AuDbg("copying a large file %lld\n", (long long)len);
4746 + err = au_do_copy_file(dst, src, len, buf, blksize);
4750 + free_page((unsigned long)buf);
4757 + * to support a sparse file which is opened with O_APPEND,
4758 + * we need to close the file.
4760 +static int au_cp_regular(struct au_cp_generic *cpg)
4763 + enum { SRC, DST };
4765 + aufs_bindex_t bindex;
4766 + unsigned int flags;
4767 + struct dentry *dentry;
4769 + struct file *file;
4773 + .bindex = cpg->bsrc,
4774 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4778 + .bindex = cpg->bdst,
4779 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4780 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4781 + .label = &&out_src
4784 + struct super_block *sb;
4786 + /* bsrc branch can be ro/rw. */
4787 + sb = cpg->dentry->d_sb;
4789 + for (i = 0; i < 2; i++, f++) {
4790 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4791 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4792 + /*file*/NULL, f->force_wr);
4793 + err = PTR_ERR(f->file);
4794 + if (IS_ERR(f->file))
4798 + /* try stopping to update while we copyup */
4799 + IMustLock(file[SRC].dentry->d_inode);
4800 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4802 + fput(file[DST].file);
4803 + au_sbr_put(sb, file[DST].bindex);
4806 + fput(file[SRC].file);
4807 + au_sbr_put(sb, file[SRC].bindex);
4812 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4813 + struct au_cpup_reg_attr *h_src_attr)
4817 + struct path h_path;
4818 + struct inode *h_src_inode, *h_dst_inode;
4821 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
4822 + l = i_size_read(h_src_inode);
4823 + if (cpg->len == -1 || l < cpg->len)
4826 + /* try stopping to update while we are referencing */
4827 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4828 + au_pin_hdir_unlock(cpg->pin);
4830 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4831 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4832 + h_src_attr->iflags = h_src_inode->i_flags;
4833 + err = vfs_getattr(&h_path, &h_src_attr->st);
4834 + if (unlikely(err)) {
4835 + mutex_unlock(&h_src_inode->i_mutex);
4838 + h_src_attr->valid = 1;
4839 + err = au_cp_regular(cpg);
4840 + mutex_unlock(&h_src_inode->i_mutex);
4841 + rerr = au_pin_hdir_relock(cpg->pin);
4845 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4846 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4847 + h_dst_inode = h_path.dentry->d_inode;
4848 + spin_lock(&h_dst_inode->i_lock);
4849 + h_dst_inode->i_state |= I_LINKABLE;
4850 + spin_unlock(&h_dst_inode->i_lock);
4857 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4858 + struct inode *h_dir)
4861 + mm_segment_t old_fs;
4868 + if (unlikely(!h_src->d_inode->i_op->readlink))
4872 + sym.k = (void *)__get_free_page(GFP_NOFS);
4873 + if (unlikely(!sym.k))
4876 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4877 + old_fs = get_fs();
4878 + set_fs(KERNEL_DS);
4879 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
4884 + sym.k[symlen] = 0;
4885 + err = vfsub_symlink(h_dir, h_path, sym.k);
4887 + free_page((unsigned long)sym.k);
4893 +static noinline_for_stack
4894 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
4895 + struct au_cpup_reg_attr *h_src_attr)
4899 + unsigned int mnt_flags;
4900 + unsigned char isdir, isreg, force;
4901 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
4902 + struct au_dtime dt;
4903 + struct path h_path;
4904 + struct dentry *h_src, *h_dst, *h_parent;
4905 + struct inode *h_inode, *h_dir;
4906 + struct super_block *sb;
4908 + /* bsrc branch can be ro/rw. */
4909 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4910 + h_inode = h_src->d_inode;
4911 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
4913 + /* try stopping to be referenced while we are creating */
4914 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4915 + if (au_ftest_cpup(cpg->flags, RENAME))
4916 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
4917 + AUFS_WH_PFX_LEN));
4918 + h_parent = h_dst->d_parent; /* dir inode is locked */
4919 + h_dir = h_parent->d_inode;
4921 + AuDebugOn(h_parent != h_dst->d_parent);
4923 + sb = cpg->dentry->d_sb;
4924 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4926 + h_path.dentry = h_parent;
4927 + au_dtime_store(&dt, dst_parent, &h_path);
4929 + h_path.dentry = h_dst;
4933 + mode = h_inode->i_mode;
4934 + switch (mode & S_IFMT) {
4937 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
4938 + /*want_excl*/true);
4940 + err = au_do_cpup_regular(cpg, h_src_attr);
4944 + err = vfsub_mkdir(h_dir, &h_path, mode);
4947 + * strange behaviour from the users view,
4948 + * particularry setattr case
4950 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
4951 + au_cpup_attr_nlink(dst_parent->d_inode,
4953 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
4957 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4961 + AuDebugOn(!capable(CAP_MKNOD));
4965 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4968 + AuIOErr("Unknown inode type 0%o\n", mode);
4972 + mnt_flags = au_mntflags(sb);
4973 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4975 + && au_opt_test(mnt_flags, XINO)
4976 + && (h_inode->i_nlink == 1
4977 + || (h_inode->i_state & I_LINKABLE))
4978 + /* todo: unnecessary? */
4979 + /* && cpg->dentry->d_inode->i_nlink == 1 */
4980 + && cpg->bdst < cpg->bsrc
4981 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4982 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4983 + /* ignore this error */
4988 + force = !!cpg->len;
4989 + if (cpg->len == -1)
4990 + force = !!i_size_read(h_inode);
4992 + au_fhsm_wrote(sb, cpg->bdst, force);
4996 + au_dtime_revert(&dt);
5000 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5003 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5004 + struct inode *h_dir;
5005 + aufs_bindex_t bdst;
5007 + dentry = cpg->dentry;
5009 + h_dentry = au_h_dptr(dentry, bdst);
5010 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5012 + au_set_h_dptr(dentry, bdst, NULL);
5013 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5015 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5016 + au_set_h_dptr(dentry, bdst, h_dentry);
5019 + parent = dget_parent(dentry);
5020 + h_parent = au_h_dptr(parent, bdst);
5022 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5023 + if (IS_ERR(h_path->dentry))
5024 + err = PTR_ERR(h_path->dentry);
5026 + if (unlikely(err))
5029 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5030 + h_dir = h_parent->d_inode;
5032 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5033 + /* no delegation since it is just created */
5034 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5035 + dput(h_path->dentry);
5042 + * copyup the @dentry from @bsrc to @bdst.
5043 + * the caller must set the both of lower dentries.
5044 + * @len is for truncating when it is -1 copyup the entire file.
5045 + * in link/rename cases, @dst_parent may be different from the real one.
5046 + * basic->bsrc can be larger than basic->bdst.
5048 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5051 + aufs_bindex_t old_ibstart;
5052 + unsigned char isdir, plink;
5053 + struct dentry *h_src, *h_dst, *h_parent;
5054 + struct inode *dst_inode, *h_dir, *inode, *delegated;
5055 + struct super_block *sb;
5056 + struct au_branch *br;
5057 + /* to reuduce stack size */
5059 + struct au_dtime dt;
5060 + struct path h_path;
5061 + struct au_cpup_reg_attr h_src_attr;
5065 + a = kmalloc(sizeof(*a), GFP_NOFS);
5068 + a->h_src_attr.valid = 0;
5070 + sb = cpg->dentry->d_sb;
5071 + br = au_sbr(sb, cpg->bdst);
5072 + a->h_path.mnt = au_br_mnt(br);
5073 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5074 + h_parent = h_dst->d_parent; /* dir inode is locked */
5075 + h_dir = h_parent->d_inode;
5078 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5079 + inode = cpg->dentry->d_inode;
5082 + dst_parent = dget_parent(cpg->dentry);
5086 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5087 + dst_inode = au_h_iptr(inode, cpg->bdst);
5089 + if (unlikely(!plink)) {
5091 + AuIOErr("hi%lu(i%lu) exists on b%d "
5092 + "but plink is disabled\n",
5093 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5097 + if (dst_inode->i_nlink) {
5098 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5100 + h_src = au_plink_lkup(inode, cpg->bdst);
5101 + err = PTR_ERR(h_src);
5102 + if (IS_ERR(h_src))
5104 + if (unlikely(!h_src->d_inode)) {
5106 + AuIOErr("i%lu exists on a upper branch "
5107 + "but not pseudo-linked\n",
5114 + a->h_path.dentry = h_parent;
5115 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5118 + a->h_path.dentry = h_dst;
5120 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5121 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5122 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5124 + au_dtime_revert(&a->dt);
5125 + if (unlikely(err == -EWOULDBLOCK)) {
5126 + pr_warn("cannot retry for NFSv4 delegation"
5127 + " for an internal link\n");
5133 + /* todo: cpup_wh_file? */
5135 + au_update_ibrange(inode, /*do_put_zero*/1);
5138 + isdir = S_ISDIR(inode->i_mode);
5139 + old_ibstart = au_ibstart(inode);
5140 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5141 + if (unlikely(err))
5143 + dst_inode = h_dst->d_inode;
5144 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
5145 + /* todo: necessary? */
5146 + /* au_pin_hdir_unlock(cpg->pin); */
5148 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5149 + if (unlikely(err)) {
5150 + /* todo: necessary? */
5151 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5152 + mutex_unlock(&dst_inode->i_mutex);
5156 + if (cpg->bdst < old_ibstart) {
5157 + if (S_ISREG(inode->i_mode)) {
5158 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5159 + if (unlikely(err)) {
5160 + /* ignore an error */
5161 + /* au_pin_hdir_relock(cpg->pin); */
5162 + mutex_unlock(&dst_inode->i_mutex);
5166 + au_set_ibstart(inode, cpg->bdst);
5168 + au_set_ibend(inode, cpg->bdst);
5169 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5170 + au_hi_flags(inode, isdir));
5172 + /* todo: necessary? */
5173 + /* err = au_pin_hdir_relock(cpg->pin); */
5174 + mutex_unlock(&dst_inode->i_mutex);
5175 + if (unlikely(err))
5179 + && (h_src->d_inode->i_nlink > 1
5180 + || h_src->d_inode->i_state & I_LINKABLE)
5182 + au_plink_append(inode, cpg->bdst, h_dst);
5184 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5185 + a->h_path.dentry = h_dst;
5186 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5189 + goto out_parent; /* success */
5193 + a->h_path.dentry = h_parent;
5194 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5195 + a->h_path.dentry = h_dst;
5197 + if (h_dst->d_inode) {
5199 + /* no delegation since it is just created */
5200 + rerr = vfsub_unlink(h_dir, &a->h_path,
5201 + /*delegated*/NULL, /*force*/0);
5203 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5205 + au_dtime_revert(&a->dt);
5207 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5218 +struct au_cpup_single_args {
5220 + struct au_cp_generic *cpg;
5221 + struct dentry *dst_parent;
5224 +static void au_call_cpup_single(void *args)
5226 + struct au_cpup_single_args *a = args;
5228 + au_pin_hdir_acquire_nest(a->cpg->pin);
5229 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5230 + au_pin_hdir_release(a->cpg->pin);
5235 + * prevent SIGXFSZ in copy-up.
5236 + * testing CAP_MKNOD is for generic fs,
5237 + * but CAP_FSETID is for xfs only, currently.
5239 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5242 + struct super_block *sb;
5243 + struct inode *h_dir;
5246 + sb = au_pinned_parent(pin)->d_sb;
5247 + if (!au_wkq_test()
5248 + && (!au_sbi(sb)->si_plink_maint_pid
5249 + || au_plink_maint(sb, AuLock_NOPLM))) {
5250 + switch (mode & S_IFMT) {
5252 + /* no condition about RLIMIT_FSIZE and the file size */
5257 + do_sio = !capable(CAP_MKNOD);
5261 + do_sio = ((mode & (S_ISUID | S_ISGID))
5262 + && !capable(CAP_FSETID));
5263 + /* this workaround may be removed in the future */
5265 + h_dir = au_pinned_h_dir(pin);
5266 + do_sio = h_dir->i_mode & S_ISVTX;
5274 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5277 + struct dentry *h_dentry;
5279 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5280 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
5281 + err = au_cpup_single(cpg, dst_parent);
5283 + struct au_cpup_single_args args = {
5286 + .dst_parent = dst_parent
5288 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5289 + if (unlikely(wkq_err))
5298 + * copyup the @dentry from the first active lower branch to @bdst,
5299 + * using au_cpup_single().
5301 +static int au_cpup_simple(struct au_cp_generic *cpg)
5304 + unsigned int flags_orig;
5305 + struct dentry *dentry;
5307 + AuDebugOn(cpg->bsrc < 0);
5309 + dentry = cpg->dentry;
5310 + DiMustWriteLock(dentry);
5312 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5314 + flags_orig = cpg->flags;
5315 + au_fset_cpup(cpg->flags, RENAME);
5316 + err = au_cpup_single(cpg, NULL);
5317 + cpg->flags = flags_orig;
5319 + return 0; /* success */
5322 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5323 + au_set_dbstart(dentry, cpg->bsrc);
5329 +struct au_cpup_simple_args {
5331 + struct au_cp_generic *cpg;
5334 +static void au_call_cpup_simple(void *args)
5336 + struct au_cpup_simple_args *a = args;
5338 + au_pin_hdir_acquire_nest(a->cpg->pin);
5339 + *a->errp = au_cpup_simple(a->cpg);
5340 + au_pin_hdir_release(a->cpg->pin);
5343 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5346 + struct dentry *dentry, *parent;
5347 + struct file *h_file;
5348 + struct inode *h_dir;
5350 + dentry = cpg->dentry;
5352 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5353 + AuDebugOn(cpg->bsrc < 0);
5354 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5355 + err = PTR_ERR(h_file);
5356 + if (IS_ERR(h_file))
5360 + parent = dget_parent(dentry);
5361 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
5362 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5363 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5364 + err = au_cpup_simple(cpg);
5366 + struct au_cpup_simple_args args = {
5370 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5371 + if (unlikely(wkq_err))
5377 + au_h_open_post(dentry, cpg->bsrc, h_file);
5383 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5385 + aufs_bindex_t bsrc, bend;
5386 + struct dentry *dentry, *h_dentry;
5388 + if (cpg->bsrc < 0) {
5389 + dentry = cpg->dentry;
5390 + bend = au_dbend(dentry);
5391 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5392 + h_dentry = au_h_dptr(dentry, bsrc);
5394 + AuDebugOn(!h_dentry->d_inode);
5398 + AuDebugOn(bsrc > bend);
5401 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5402 + return au_do_sio_cpup_simple(cpg);
5405 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5407 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5408 + return au_do_sio_cpup_simple(cpg);
5411 +/* ---------------------------------------------------------------------- */
5414 + * copyup the deleted file for writing.
5416 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5417 + struct file *file)
5420 + unsigned int flags_orig;
5421 + aufs_bindex_t bsrc_orig;
5422 + struct dentry *h_d_dst, *h_d_start;
5423 + struct au_dinfo *dinfo;
5424 + struct au_hdentry *hdp;
5426 + dinfo = au_di(cpg->dentry);
5427 + AuRwMustWriteLock(&dinfo->di_rwsem);
5429 + bsrc_orig = cpg->bsrc;
5430 + cpg->bsrc = dinfo->di_bstart;
5431 + hdp = dinfo->di_hdentry;
5432 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5433 + dinfo->di_bstart = cpg->bdst;
5434 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5437 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5438 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
5440 + flags_orig = cpg->flags;
5441 + cpg->flags = !AuCpup_DTIME;
5442 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5443 + cpg->flags = flags_orig;
5446 + err = au_reopen_nondir(file);
5447 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5449 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5450 + dinfo->di_bstart = cpg->bsrc;
5451 + cpg->bsrc = bsrc_orig;
5456 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5459 + aufs_bindex_t bdst;
5460 + struct au_dtime dt;
5461 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5462 + struct au_branch *br;
5463 + struct path h_path;
5465 + dentry = cpg->dentry;
5467 + br = au_sbr(dentry->d_sb, bdst);
5468 + parent = dget_parent(dentry);
5469 + h_parent = au_h_dptr(parent, bdst);
5470 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5471 + err = PTR_ERR(wh_dentry);
5472 + if (IS_ERR(wh_dentry))
5475 + h_path.dentry = h_parent;
5476 + h_path.mnt = au_br_mnt(br);
5477 + au_dtime_store(&dt, parent, &h_path);
5478 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5479 + if (unlikely(err))
5483 + h_path.dentry = wh_dentry;
5484 + if (!S_ISDIR(wh_dentry->d_inode->i_mode)) {
5485 + /* no delegation since it is just created */
5486 + err = vfsub_unlink(h_parent->d_inode, &h_path,
5487 + /*delegated*/NULL, /*force*/0);
5489 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
5490 + if (unlikely(err)) {
5491 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5495 + au_dtime_revert(&dt);
5496 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
5505 +struct au_cpup_wh_args {
5507 + struct au_cp_generic *cpg;
5508 + struct file *file;
5511 +static void au_call_cpup_wh(void *args)
5513 + struct au_cpup_wh_args *a = args;
5515 + au_pin_hdir_acquire_nest(a->cpg->pin);
5516 + *a->errp = au_cpup_wh(a->cpg, a->file);
5517 + au_pin_hdir_release(a->cpg->pin);
5520 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5523 + aufs_bindex_t bdst;
5524 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5525 + struct inode *dir, *h_dir, *h_tmpdir;
5526 + struct au_wbr *wbr;
5527 + struct au_pin wh_pin, *pin_orig;
5529 + dentry = cpg->dentry;
5531 + parent = dget_parent(dentry);
5532 + dir = parent->d_inode;
5535 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5538 + if (!h_dir->i_nlink) {
5539 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5540 + h_orph = wbr->wbr_orph;
5542 + h_parent = dget(au_h_dptr(parent, bdst));
5543 + au_set_h_dptr(parent, bdst, dget(h_orph));
5544 + h_tmpdir = h_orph->d_inode;
5545 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5547 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5548 + /* todo: au_h_open_pre()? */
5550 + pin_orig = cpg->pin;
5551 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5552 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5553 + cpg->pin = &wh_pin;
5556 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5557 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5558 + err = au_cpup_wh(cpg, file);
5560 + struct au_cpup_wh_args args = {
5565 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5566 + if (unlikely(wkq_err))
5571 + mutex_unlock(&h_tmpdir->i_mutex);
5572 + /* todo: au_h_open_post()? */
5573 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5574 + au_set_h_dptr(parent, bdst, h_parent);
5575 + AuDebugOn(!pin_orig);
5576 + cpg->pin = pin_orig;
5584 +/* ---------------------------------------------------------------------- */
5587 + * generic routine for both of copy-up and copy-down.
5589 +/* cf. revalidate function in file.c */
5590 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5591 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5592 + struct au_pin *pin,
5593 + struct dentry *h_parent, void *arg),
5597 + struct au_pin pin;
5598 + struct dentry *d, *parent, *h_parent, *real_parent;
5601 + parent = dget_parent(dentry);
5602 + if (IS_ROOT(parent))
5605 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5606 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5608 + /* do not use au_dpage */
5609 + real_parent = parent;
5612 + parent = dget_parent(dentry);
5613 + h_parent = au_h_dptr(parent, bdst);
5615 + goto out; /* success */
5617 + /* find top dir which is necessary to cpup */
5621 + parent = dget_parent(d);
5622 + di_read_lock_parent3(parent, !AuLock_IR);
5623 + h_parent = au_h_dptr(parent, bdst);
5624 + di_read_unlock(parent, !AuLock_IR);
5625 + } while (!h_parent);
5627 + if (d != real_parent)
5628 + di_write_lock_child3(d);
5630 + /* somebody else might create while we were sleeping */
5631 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
5632 + if (au_h_dptr(d, bdst))
5633 + au_update_dbstart(d);
5635 + au_pin_set_dentry(&pin, d);
5636 + err = au_do_pin(&pin);
5638 + err = cp(d, bdst, &pin, h_parent, arg);
5643 + if (d != real_parent)
5644 + di_write_unlock(d);
5645 + if (unlikely(err))
5654 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5655 + struct au_pin *pin,
5656 + struct dentry *h_parent __maybe_unused ,
5657 + void *arg __maybe_unused)
5659 + struct au_cp_generic cpg = {
5665 + .flags = AuCpup_DTIME
5667 + return au_sio_cpup_simple(&cpg);
5670 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5672 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5675 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5678 + struct dentry *parent;
5679 + struct inode *dir;
5681 + parent = dget_parent(dentry);
5682 + dir = parent->d_inode;
5684 + if (au_h_iptr(dir, bdst))
5687 + di_read_unlock(parent, AuLock_IR);
5688 + di_write_lock_parent(parent);
5689 + /* someone else might change our inode while we were sleeping */
5690 + if (!au_h_iptr(dir, bdst))
5691 + err = au_cpup_dirs(dentry, bdst);
5692 + di_downgrade_lock(parent, AuLock_IR);
5698 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5699 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5700 +++ linux/fs/aufs/cpup.h 2015-01-25 13:00:38.631047076 +0100
5703 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5705 + * This program, aufs is free software; you can redistribute it and/or modify
5706 + * it under the terms of the GNU General Public License as published by
5707 + * the Free Software Foundation; either version 2 of the License, or
5708 + * (at your option) any later version.
5710 + * This program is distributed in the hope that it will be useful,
5711 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5713 + * GNU General Public License for more details.
5715 + * You should have received a copy of the GNU General Public License
5716 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5720 + * copy-up/down functions
5723 +#ifndef __AUFS_CPUP_H__
5724 +#define __AUFS_CPUP_H__
5728 +#include <linux/path.h>
5734 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5735 +void au_cpup_attr_timesizes(struct inode *inode);
5736 +void au_cpup_attr_nlink(struct inode *inode, int force);
5737 +void au_cpup_attr_changeable(struct inode *inode);
5738 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5739 +void au_cpup_attr_all(struct inode *inode, int force);
5741 +/* ---------------------------------------------------------------------- */
5743 +struct au_cp_generic {
5744 + struct dentry *dentry;
5745 + aufs_bindex_t bdst, bsrc;
5747 + struct au_pin *pin;
5748 + unsigned int flags;
5752 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5753 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5755 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5756 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5758 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5760 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5761 + the branch is marked as RO */
5763 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5764 +#define au_fset_cpup(flags, name) \
5765 + do { (flags) |= AuCpup_##name; } while (0)
5766 +#define au_fclr_cpup(flags, name) \
5767 + do { (flags) &= ~AuCpup_##name; } while (0)
5769 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5770 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5771 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5772 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5774 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5775 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5776 + struct au_pin *pin,
5777 + struct dentry *h_parent, void *arg),
5779 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5780 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5782 +/* ---------------------------------------------------------------------- */
5784 +/* keep timestamps when copyup */
5786 + struct dentry *dt_dentry;
5787 + struct path dt_h_path;
5788 + struct timespec dt_atime, dt_mtime;
5790 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5791 + struct path *h_path);
5792 +void au_dtime_revert(struct au_dtime *dt);
5794 +#endif /* __KERNEL__ */
5795 +#endif /* __AUFS_CPUP_H__ */
5796 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5797 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5798 +++ linux/fs/aufs/dbgaufs.c 2015-01-25 13:00:38.631047076 +0100
5801 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5803 + * This program, aufs is free software; you can redistribute it and/or modify
5804 + * it under the terms of the GNU General Public License as published by
5805 + * the Free Software Foundation; either version 2 of the License, or
5806 + * (at your option) any later version.
5808 + * This program is distributed in the hope that it will be useful,
5809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5811 + * GNU General Public License for more details.
5813 + * You should have received a copy of the GNU General Public License
5814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5818 + * debugfs interface
5821 +#include <linux/debugfs.h>
5824 +#ifndef CONFIG_SYSFS
5825 +#error DEBUG_FS depends upon SYSFS
5828 +static struct dentry *dbgaufs;
5829 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5831 +/* 20 is max digits length of ulong 64 */
5832 +struct dbgaufs_arg {
5838 + * common function for all XINO files
5840 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5841 + struct file *file)
5843 + kfree(file->private_data);
5847 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5851 + struct dbgaufs_arg *p;
5854 + p = kmalloc(sizeof(*p), GFP_NOFS);
5860 + file->private_data = p;
5864 + err = vfs_getattr(&xf->f_path, &st);
5868 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5869 + (long)file_count(xf), st.blocks, st.blksize,
5870 + (long long)st.size);
5872 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5873 + st.blocks, st.blksize,
5874 + (long long)st.size);
5875 + AuDebugOn(p->n >= sizeof(p->a));
5877 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5886 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5887 + size_t count, loff_t *ppos)
5889 + struct dbgaufs_arg *p;
5891 + p = file->private_data;
5892 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5895 +/* ---------------------------------------------------------------------- */
5897 +struct dbgaufs_plink_arg {
5902 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
5903 + struct file *file)
5905 + free_page((unsigned long)file->private_data);
5909 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
5911 + int err, i, limit;
5912 + unsigned long n, sum;
5913 + struct dbgaufs_plink_arg *p;
5914 + struct au_sbinfo *sbinfo;
5915 + struct super_block *sb;
5916 + struct au_sphlhead *sphl;
5919 + p = (void *)get_zeroed_page(GFP_NOFS);
5924 + sbinfo = inode->i_private;
5925 + sb = sbinfo->si_sb;
5926 + si_noflush_read_lock(sb);
5927 + if (au_opt_test(au_mntflags(sb), PLINK)) {
5928 + limit = PAGE_SIZE - sizeof(p->n);
5930 + /* the number of buckets */
5931 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
5936 + for (i = 0, sphl = sbinfo->si_plink;
5937 + i < AuPlink_NHASH;
5939 + n = au_sphl_count(sphl);
5942 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5945 + if (unlikely(limit <= 0))
5948 + p->a[p->n - 1] = '\n';
5950 + /* the sum of plinks */
5951 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5954 + if (unlikely(limit <= 0))
5957 +#define str "1\n0\n0\n"
5958 + p->n = sizeof(str) - 1;
5959 + strcpy(p->a, str);
5962 + si_read_unlock(sb);
5965 + file->private_data = p;
5966 + goto out; /* success */
5969 + free_page((unsigned long)p);
5974 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5975 + size_t count, loff_t *ppos)
5977 + struct dbgaufs_plink_arg *p;
5979 + p = file->private_data;
5980 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5983 +static const struct file_operations dbgaufs_plink_fop = {
5984 + .owner = THIS_MODULE,
5985 + .open = dbgaufs_plink_open,
5986 + .release = dbgaufs_plink_release,
5987 + .read = dbgaufs_plink_read
5990 +/* ---------------------------------------------------------------------- */
5992 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5995 + struct au_sbinfo *sbinfo;
5996 + struct super_block *sb;
5998 + sbinfo = inode->i_private;
5999 + sb = sbinfo->si_sb;
6000 + si_noflush_read_lock(sb);
6001 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6002 + si_read_unlock(sb);
6006 +static const struct file_operations dbgaufs_xib_fop = {
6007 + .owner = THIS_MODULE,
6008 + .open = dbgaufs_xib_open,
6009 + .release = dbgaufs_xi_release,
6010 + .read = dbgaufs_xi_read
6013 +/* ---------------------------------------------------------------------- */
6015 +#define DbgaufsXi_PREFIX "xi"
6017 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6021 + struct au_sbinfo *sbinfo;
6022 + struct super_block *sb;
6024 + struct qstr *name;
6028 + name = &file->f_dentry->d_name;
6029 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6030 + || memcmp(name->name, DbgaufsXi_PREFIX,
6031 + sizeof(DbgaufsXi_PREFIX) - 1)))
6033 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6034 + if (unlikely(err))
6037 + sbinfo = inode->i_private;
6038 + sb = sbinfo->si_sb;
6039 + si_noflush_read_lock(sb);
6040 + if (l <= au_sbend(sb)) {
6041 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6042 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6045 + si_read_unlock(sb);
6051 +static const struct file_operations dbgaufs_xino_fop = {
6052 + .owner = THIS_MODULE,
6053 + .open = dbgaufs_xino_open,
6054 + .release = dbgaufs_xi_release,
6055 + .read = dbgaufs_xi_read
6058 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6060 + aufs_bindex_t bend;
6061 + struct au_branch *br;
6062 + struct au_xino_file *xi;
6064 + if (!au_sbi(sb)->si_dbgaufs)
6067 + bend = au_sbend(sb);
6068 + for (; bindex <= bend; bindex++) {
6069 + br = au_sbr(sb, bindex);
6070 + xi = &br->br_xino;
6071 + debugfs_remove(xi->xi_dbgaufs);
6072 + xi->xi_dbgaufs = NULL;
6076 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6078 + struct au_sbinfo *sbinfo;
6079 + struct dentry *parent;
6080 + struct au_branch *br;
6081 + struct au_xino_file *xi;
6082 + aufs_bindex_t bend;
6083 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6085 + sbinfo = au_sbi(sb);
6086 + parent = sbinfo->si_dbgaufs;
6090 + bend = au_sbend(sb);
6091 + for (; bindex <= bend; bindex++) {
6092 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6093 + br = au_sbr(sb, bindex);
6094 + xi = &br->br_xino;
6095 + AuDebugOn(xi->xi_dbgaufs);
6096 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6097 + sbinfo, &dbgaufs_xino_fop);
6098 + /* ignore an error */
6099 + if (unlikely(!xi->xi_dbgaufs))
6100 + AuWarn1("failed %s under debugfs\n", name);
6104 +/* ---------------------------------------------------------------------- */
6106 +#ifdef CONFIG_AUFS_EXPORT
6107 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6110 + struct au_sbinfo *sbinfo;
6111 + struct super_block *sb;
6113 + sbinfo = inode->i_private;
6114 + sb = sbinfo->si_sb;
6115 + si_noflush_read_lock(sb);
6116 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6117 + si_read_unlock(sb);
6121 +static const struct file_operations dbgaufs_xigen_fop = {
6122 + .owner = THIS_MODULE,
6123 + .open = dbgaufs_xigen_open,
6124 + .release = dbgaufs_xi_release,
6125 + .read = dbgaufs_xi_read
6128 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6133 + * This function is a dynamic '__init' function actually,
6134 + * so the tiny check for si_rwsem is unnecessary.
6136 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6139 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6140 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6141 + &dbgaufs_xigen_fop);
6142 + if (sbinfo->si_dbgaufs_xigen)
6148 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6152 +#endif /* CONFIG_AUFS_EXPORT */
6154 +/* ---------------------------------------------------------------------- */
6156 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6159 + * This function is a dynamic '__init' function actually,
6160 + * so the tiny check for si_rwsem is unnecessary.
6162 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6164 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6165 + sbinfo->si_dbgaufs = NULL;
6166 + kobject_put(&sbinfo->si_kobj);
6169 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6172 + char name[SysaufsSiNameLen];
6175 + * This function is a dynamic '__init' function actually,
6176 + * so the tiny check for si_rwsem is unnecessary.
6178 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6182 + AuErr1("/debug/aufs is uninitialized\n");
6187 + sysaufs_name(sbinfo, name);
6188 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6189 + if (unlikely(!sbinfo->si_dbgaufs))
6191 + kobject_get(&sbinfo->si_kobj);
6193 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6194 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6195 + &dbgaufs_xib_fop);
6196 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6199 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6200 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6201 + &dbgaufs_plink_fop);
6202 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6205 + err = dbgaufs_xigen_init(sbinfo);
6207 + goto out; /* success */
6210 + dbgaufs_si_fin(sbinfo);
6215 +/* ---------------------------------------------------------------------- */
6217 +void dbgaufs_fin(void)
6219 + debugfs_remove(dbgaufs);
6222 +int __init dbgaufs_init(void)
6227 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6232 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6233 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6234 +++ linux/fs/aufs/dbgaufs.h 2015-01-25 13:00:38.631047076 +0100
6237 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6239 + * This program, aufs is free software; you can redistribute it and/or modify
6240 + * it under the terms of the GNU General Public License as published by
6241 + * the Free Software Foundation; either version 2 of the License, or
6242 + * (at your option) any later version.
6244 + * This program is distributed in the hope that it will be useful,
6245 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6246 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6247 + * GNU General Public License for more details.
6249 + * You should have received a copy of the GNU General Public License
6250 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6254 + * debugfs interface
6257 +#ifndef __DBGAUFS_H__
6258 +#define __DBGAUFS_H__
6262 +struct super_block;
6265 +#ifdef CONFIG_DEBUG_FS
6267 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6268 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6269 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6270 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6271 +void dbgaufs_fin(void);
6272 +int __init dbgaufs_init(void);
6274 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6275 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6276 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6277 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6278 +AuStubVoid(dbgaufs_fin, void)
6279 +AuStubInt0(__init dbgaufs_init, void)
6280 +#endif /* CONFIG_DEBUG_FS */
6282 +#endif /* __KERNEL__ */
6283 +#endif /* __DBGAUFS_H__ */
6284 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6285 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6286 +++ linux/fs/aufs/dcsub.c 2015-01-25 13:00:38.631047076 +0100
6289 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6291 + * This program, aufs is free software; you can redistribute it and/or modify
6292 + * it under the terms of the GNU General Public License as published by
6293 + * the Free Software Foundation; either version 2 of the License, or
6294 + * (at your option) any later version.
6296 + * This program is distributed in the hope that it will be useful,
6297 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6298 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6299 + * GNU General Public License for more details.
6301 + * You should have received a copy of the GNU General Public License
6302 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6306 + * sub-routines for dentry cache
6311 +static void au_dpage_free(struct au_dpage *dpage)
6314 + struct dentry **p;
6316 + p = dpage->dentries;
6317 + for (i = 0; i < dpage->ndentry; i++)
6319 + free_page((unsigned long)dpage->dentries);
6322 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6328 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6329 + if (unlikely(!dpages->dpages))
6332 + p = (void *)__get_free_page(gfp);
6336 + dpages->dpages[0].ndentry = 0;
6337 + dpages->dpages[0].dentries = p;
6338 + dpages->ndpage = 1;
6339 + return 0; /* success */
6342 + kfree(dpages->dpages);
6347 +void au_dpages_free(struct au_dcsub_pages *dpages)
6350 + struct au_dpage *p;
6352 + p = dpages->dpages;
6353 + for (i = 0; i < dpages->ndpage; i++)
6354 + au_dpage_free(p++);
6355 + kfree(dpages->dpages);
6358 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6359 + struct dentry *dentry, gfp_t gfp)
6362 + struct au_dpage *dpage;
6365 + dpage = dpages->dpages + dpages->ndpage - 1;
6366 + sz = PAGE_SIZE / sizeof(dentry);
6367 + if (unlikely(dpage->ndentry >= sz)) {
6368 + AuLabel(new dpage);
6370 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6371 + p = au_kzrealloc(dpages->dpages, sz,
6372 + sz + sizeof(*dpages->dpages), gfp);
6376 + dpages->dpages = p;
6377 + dpage = dpages->dpages + dpages->ndpage;
6378 + p = (void *)__get_free_page(gfp);
6382 + dpage->ndentry = 0;
6383 + dpage->dentries = p;
6387 + AuDebugOn(au_dcount(dentry) <= 0);
6388 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6389 + return 0; /* success */
6395 +/* todo: BAD approach */
6396 +/* copied from linux/fs/dcache.c */
6404 +extern void d_walk(struct dentry *parent, void *data,
6405 + enum d_walk_ret (*enter)(void *, struct dentry *),
6406 + void (*finish)(void *));
6408 +struct ac_dpages_arg {
6410 + struct au_dcsub_pages *dpages;
6411 + struct super_block *sb;
6412 + au_dpages_test test;
6416 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6418 + enum d_walk_ret ret;
6419 + struct ac_dpages_arg *arg = _arg;
6421 + ret = D_WALK_CONTINUE;
6422 + if (dentry->d_sb == arg->sb
6423 + && !IS_ROOT(dentry)
6424 + && au_dcount(dentry) > 0
6426 + && (!arg->test || arg->test(dentry, arg->arg))) {
6427 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6428 + if (unlikely(arg->err))
6429 + ret = D_WALK_QUIT;
6435 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6436 + au_dpages_test test, void *arg)
6438 + struct ac_dpages_arg args = {
6446 + d_walk(root, &args, au_call_dpages_append, NULL);
6451 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6452 + int do_include, au_dpages_test test, void *arg)
6457 + write_seqlock(&rename_lock);
6458 + spin_lock(&dentry->d_lock);
6460 + && au_dcount(dentry) > 0
6461 + && (!test || test(dentry, arg)))
6462 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6463 + spin_unlock(&dentry->d_lock);
6464 + if (unlikely(err))
6468 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6471 + while (!IS_ROOT(dentry)) {
6472 + dentry = dentry->d_parent; /* rename_lock is locked */
6473 + spin_lock(&dentry->d_lock);
6474 + if (au_dcount(dentry) > 0
6475 + && (!test || test(dentry, arg)))
6476 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6477 + spin_unlock(&dentry->d_lock);
6478 + if (unlikely(err))
6483 + write_sequnlock(&rename_lock);
6487 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6489 + return au_di(dentry) && dentry->d_sb == arg;
6492 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6493 + struct dentry *dentry, int do_include)
6495 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6496 + au_dcsub_dpages_aufs, dentry->d_sb);
6499 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6501 + struct path path[2] = {
6510 + return path_is_under(path + 0, path + 1);
6512 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6513 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6514 +++ linux/fs/aufs/dcsub.h 2015-01-25 13:00:38.631047076 +0100
6517 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6519 + * This program, aufs is free software; you can redistribute it and/or modify
6520 + * it under the terms of the GNU General Public License as published by
6521 + * the Free Software Foundation; either version 2 of the License, or
6522 + * (at your option) any later version.
6524 + * This program is distributed in the hope that it will be useful,
6525 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6526 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6527 + * GNU General Public License for more details.
6529 + * You should have received a copy of the GNU General Public License
6530 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6534 + * sub-routines for dentry cache
6537 +#ifndef __AUFS_DCSUB_H__
6538 +#define __AUFS_DCSUB_H__
6542 +#include <linux/dcache.h>
6543 +#include <linux/fs.h>
6549 + struct dentry **dentries;
6552 +struct au_dcsub_pages {
6554 + struct au_dpage *dpages;
6557 +/* ---------------------------------------------------------------------- */
6560 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6561 +void au_dpages_free(struct au_dcsub_pages *dpages);
6562 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6563 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6564 + au_dpages_test test, void *arg);
6565 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6566 + int do_include, au_dpages_test test, void *arg);
6567 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6568 + struct dentry *dentry, int do_include);
6569 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6571 +/* ---------------------------------------------------------------------- */
6574 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6575 + * include/linux/dcache.h. Try them (in the future).
6578 +static inline int au_d_hashed_positive(struct dentry *d)
6581 + struct inode *inode = d->d_inode;
6584 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
6589 +static inline int au_d_linkable(struct dentry *d)
6592 + struct inode *inode = d->d_inode;
6594 + err = au_d_hashed_positive(d);
6597 + && (inode->i_state & I_LINKABLE))
6602 +static inline int au_d_alive(struct dentry *d)
6605 + struct inode *inode;
6609 + err = au_d_hashed_positive(d);
6611 + inode = d->d_inode;
6612 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
6618 +static inline int au_alive_dir(struct dentry *d)
6622 + err = au_d_alive(d);
6623 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
6628 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6630 + return a->len == b->len
6631 + && !memcmp(a->name, b->name, a->len);
6634 +static inline int au_dcount(struct dentry *d)
6636 + return (int)d_count(d);
6639 +#endif /* __KERNEL__ */
6640 +#endif /* __AUFS_DCSUB_H__ */
6641 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6642 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6643 +++ linux/fs/aufs/debug.c 2015-01-25 13:00:38.631047076 +0100
6646 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6648 + * This program, aufs is free software; you can redistribute it and/or modify
6649 + * it under the terms of the GNU General Public License as published by
6650 + * the Free Software Foundation; either version 2 of the License, or
6651 + * (at your option) any later version.
6653 + * This program is distributed in the hope that it will be useful,
6654 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6655 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6656 + * GNU General Public License for more details.
6658 + * You should have received a copy of the GNU General Public License
6659 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6663 + * debug print functions
6666 +#include <linux/vt_kern.h>
6669 +/* Returns 0, or -errno. arg is in kp->arg. */
6670 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6674 + err = kstrtoint(val, 0, &n);
6684 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6685 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6690 + return sprintf(buffer, "%d", atomic_read(a));
6693 +static struct kernel_param_ops param_ops_atomic_t = {
6694 + .set = param_atomic_t_set,
6695 + .get = param_atomic_t_get
6696 + /* void (*free)(void *arg) */
6699 +atomic_t aufs_debug = ATOMIC_INIT(0);
6700 +MODULE_PARM_DESC(debug, "debug print");
6701 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6703 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6704 +char *au_plevel = KERN_DEBUG;
6705 +#define dpri(fmt, ...) do { \
6707 + && strcmp(au_plevel, KERN_DEBUG)) \
6708 + || au_debug_test()) \
6709 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6712 +/* ---------------------------------------------------------------------- */
6714 +void au_dpri_whlist(struct au_nhash *whlist)
6716 + unsigned long ul, n;
6717 + struct hlist_head *head;
6718 + struct au_vdir_wh *pos;
6720 + n = whlist->nh_num;
6721 + head = whlist->nh_head;
6722 + for (ul = 0; ul < n; ul++) {
6723 + hlist_for_each_entry(pos, head, wh_hash)
6724 + dpri("b%d, %.*s, %d\n",
6726 + pos->wh_str.len, pos->wh_str.name,
6732 +void au_dpri_vdir(struct au_vdir *vdir)
6735 + union au_vdir_deblk_p p;
6738 + if (!vdir || IS_ERR(vdir)) {
6739 + dpri("err %ld\n", PTR_ERR(vdir));
6743 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6744 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6745 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6746 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6747 + p.deblk = vdir->vd_deblk[ul];
6749 + dpri("[%lu]: %p\n", ul, o);
6753 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6754 + struct dentry *wh)
6759 + if (!inode || IS_ERR(inode)) {
6760 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6764 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6765 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6766 + && sizeof(inode->i_blocks) != sizeof(u64));
6768 + n = (void *)wh->d_name.name;
6769 + l = wh->d_name.len;
6772 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6773 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6775 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6776 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6777 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6778 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6779 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6780 + inode->i_state, inode->i_flags, inode->i_version,
6781 + inode->i_generation,
6782 + l ? ", wh " : "", l, n);
6786 +void au_dpri_inode(struct inode *inode)
6788 + struct au_iinfo *iinfo;
6789 + aufs_bindex_t bindex;
6792 + err = do_pri_inode(-1, inode, -1, NULL);
6793 + if (err || !au_test_aufs(inode->i_sb))
6796 + iinfo = au_ii(inode);
6799 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6800 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6801 + if (iinfo->ii_bstart < 0)
6804 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6805 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6806 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6807 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6811 +void au_dpri_dalias(struct inode *inode)
6815 + spin_lock(&inode->i_lock);
6816 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
6817 + au_dpri_dentry(d);
6818 + spin_unlock(&inode->i_lock);
6821 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6823 + struct dentry *wh = NULL;
6825 + struct au_iinfo *iinfo;
6827 + if (!dentry || IS_ERR(dentry)) {
6828 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6831 + /* do not call dget_parent() here */
6832 + /* note: access d_xxx without d_lock */
6833 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6834 + bindex, dentry, dentry,
6835 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6836 + au_dcount(dentry), dentry->d_flags,
6837 + d_unhashed(dentry) ? "un" : "");
6839 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
6840 + iinfo = au_ii(dentry->d_inode);
6842 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6843 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6846 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
6850 +void au_dpri_dentry(struct dentry *dentry)
6852 + struct au_dinfo *dinfo;
6853 + aufs_bindex_t bindex;
6855 + struct au_hdentry *hdp;
6857 + err = do_pri_dentry(-1, dentry);
6858 + if (err || !au_test_aufs(dentry->d_sb))
6861 + dinfo = au_di(dentry);
6864 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
6865 + dinfo->di_bstart, dinfo->di_bend,
6866 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
6867 + dinfo->di_tmpfile);
6868 + if (dinfo->di_bstart < 0)
6870 + hdp = dinfo->di_hdentry;
6871 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6872 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6875 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
6879 + if (!file || IS_ERR(file)) {
6880 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
6886 + && au_test_aufs(file->f_dentry->d_sb)
6888 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
6889 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
6890 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
6891 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
6892 + file->f_version, file->f_pos, a);
6893 + if (file->f_dentry)
6894 + do_pri_dentry(bindex, file->f_dentry);
6898 +void au_dpri_file(struct file *file)
6900 + struct au_finfo *finfo;
6901 + struct au_fidir *fidir;
6902 + struct au_hfile *hfile;
6903 + aufs_bindex_t bindex;
6906 + err = do_pri_file(-1, file);
6907 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
6910 + finfo = au_fi(file);
6913 + if (finfo->fi_btop < 0)
6915 + fidir = finfo->fi_hdir;
6917 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
6919 + for (bindex = finfo->fi_btop;
6920 + bindex >= 0 && bindex <= fidir->fd_bbot;
6922 + hfile = fidir->fd_hfile + bindex;
6923 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
6927 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
6929 + struct vfsmount *mnt;
6930 + struct super_block *sb;
6932 + if (!br || IS_ERR(br))
6934 + mnt = au_br_mnt(br);
6935 + if (!mnt || IS_ERR(mnt))
6938 + if (!sb || IS_ERR(sb))
6941 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
6942 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
6944 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
6945 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
6946 + sb->s_flags, sb->s_count,
6947 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
6951 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6955 +void au_dpri_sb(struct super_block *sb)
6957 + struct au_sbinfo *sbinfo;
6958 + aufs_bindex_t bindex;
6960 + /* to reuduce stack size */
6962 + struct vfsmount mnt;
6963 + struct au_branch fake;
6966 + /* this function can be called from magic sysrq */
6967 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6968 + if (unlikely(!a)) {
6969 + dpri("no memory\n");
6973 + a->mnt.mnt_sb = sb;
6974 + a->fake.br_perm = 0;
6975 + a->fake.br_path.mnt = &a->mnt;
6976 + a->fake.br_xino.xi_file = NULL;
6977 + atomic_set(&a->fake.br_count, 0);
6978 + smp_mb(); /* atomic_set */
6979 + err = do_pri_br(-1, &a->fake);
6981 + dpri("dev 0x%x\n", sb->s_dev);
6982 + if (err || !au_test_aufs(sb))
6985 + sbinfo = au_sbi(sb);
6988 + dpri("nw %d, gen %u, kobj %d\n",
6989 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6990 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6991 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6992 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6995 +/* ---------------------------------------------------------------------- */
6997 +void au_dbg_sleep_jiffy(int jiffy)
7000 + jiffy = schedule_timeout_uninterruptible(jiffy);
7003 +void au_dbg_iattr(struct iattr *ia)
7005 +#define AuBit(name) \
7007 + if (ia->ia_valid & ATTR_ ## name) \
7008 + dpri(#name "\n"); \
7028 + dpri("ia_file %p\n", ia->ia_file);
7031 +/* ---------------------------------------------------------------------- */
7033 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7035 + struct inode *h_inode, *inode = dentry->d_inode;
7036 + struct dentry *h_dentry;
7037 + aufs_bindex_t bindex, bend, bi;
7039 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7042 + bend = au_dbend(dentry);
7043 + bi = au_ibend(inode);
7046 + bindex = au_dbstart(dentry);
7047 + bi = au_ibstart(inode);
7051 + for (; bindex <= bend; bindex++) {
7052 + h_dentry = au_h_dptr(dentry, bindex);
7055 + h_inode = au_h_iptr(inode, bindex);
7056 + if (unlikely(h_inode != h_dentry->d_inode)) {
7058 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7059 + AuDbgDentry(dentry);
7060 + AuDbgInode(inode);
7067 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
7069 + struct dentry *parent;
7071 + parent = dget_parent(dentry);
7072 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
7073 + AuDebugOn(IS_ROOT(dentry));
7074 + AuDebugOn(au_digen_test(parent, sigen));
7078 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
7080 + struct dentry *parent;
7081 + struct inode *inode;
7083 + parent = dget_parent(dentry);
7084 + inode = dentry->d_inode;
7085 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
7086 + AuDebugOn(au_digen_test(parent, sigen));
7090 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7093 + struct au_dcsub_pages dpages;
7094 + struct au_dpage *dpage;
7095 + struct dentry **dentries;
7097 + err = au_dpages_init(&dpages, GFP_NOFS);
7099 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7101 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7102 + dpage = dpages.dpages + i;
7103 + dentries = dpage->dentries;
7104 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7105 + AuDebugOn(au_digen_test(dentries[j], sigen));
7107 + au_dpages_free(&dpages);
7110 +void au_dbg_verify_kthread(void)
7112 + if (au_wkq_test()) {
7115 + * It may be recursive, but udba=notify between two aufs mounts,
7116 + * where a single ro branch is shared, is not a problem.
7122 +/* ---------------------------------------------------------------------- */
7124 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
7126 +#ifdef AuForceNoPlink
7127 + au_opt_clr(sbinfo->si_mntflags, PLINK);
7129 +#ifdef AuForceNoXino
7130 + au_opt_clr(sbinfo->si_mntflags, XINO);
7132 +#ifdef AuForceNoRefrof
7133 + au_opt_clr(sbinfo->si_mntflags, REFROF);
7135 +#ifdef AuForceHnotify
7136 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
7139 + sbinfo->si_rdblk = 0;
7140 + sbinfo->si_rdhash = 0;
7144 +int __init au_debug_init(void)
7146 + aufs_bindex_t bindex;
7147 + struct au_vdir_destr destr;
7150 + AuDebugOn(bindex >= 0);
7153 + AuDebugOn(destr.len < NAME_MAX);
7155 +#ifdef CONFIG_4KSTACKS
7156 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7159 +#ifdef AuForceNoBrs
7165 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7166 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7167 +++ linux/fs/aufs/debug.h 2015-01-25 13:00:38.631047076 +0100
7170 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7172 + * This program, aufs is free software; you can redistribute it and/or modify
7173 + * it under the terms of the GNU General Public License as published by
7174 + * the Free Software Foundation; either version 2 of the License, or
7175 + * (at your option) any later version.
7177 + * This program is distributed in the hope that it will be useful,
7178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7180 + * GNU General Public License for more details.
7182 + * You should have received a copy of the GNU General Public License
7183 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7187 + * debug print functions
7190 +#ifndef __AUFS_DEBUG_H__
7191 +#define __AUFS_DEBUG_H__
7195 +#include <linux/atomic.h>
7196 +#include <linux/module.h>
7197 +#include <linux/kallsyms.h>
7198 +#include <linux/sysrq.h>
7200 +#ifdef CONFIG_AUFS_DEBUG
7201 +#define AuDebugOn(a) BUG_ON(a)
7203 +/* module parameter */
7204 +extern atomic_t aufs_debug;
7205 +static inline void au_debug_on(void)
7207 + atomic_inc(&aufs_debug);
7209 +static inline void au_debug_off(void)
7211 + atomic_dec_if_positive(&aufs_debug);
7214 +static inline int au_debug_test(void)
7216 + return atomic_read(&aufs_debug) > 0;
7219 +#define AuDebugOn(a) do {} while (0)
7220 +AuStubVoid(au_debug_on, void)
7221 +AuStubVoid(au_debug_off, void)
7222 +AuStubInt0(au_debug_test, void)
7223 +#endif /* CONFIG_AUFS_DEBUG */
7225 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7227 +/* ---------------------------------------------------------------------- */
7231 +#define AuDbg(fmt, ...) do { \
7232 + if (au_debug_test()) \
7233 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7235 +#define AuLabel(l) AuDbg(#l "\n")
7236 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7237 +#define AuWarn1(fmt, ...) do { \
7238 + static unsigned char _c; \
7240 + pr_warn(fmt, ##__VA_ARGS__); \
7243 +#define AuErr1(fmt, ...) do { \
7244 + static unsigned char _c; \
7246 + pr_err(fmt, ##__VA_ARGS__); \
7249 +#define AuIOErr1(fmt, ...) do { \
7250 + static unsigned char _c; \
7252 + AuIOErr(fmt, ##__VA_ARGS__); \
7255 +#define AuUnsupportMsg "This operation is not supported." \
7256 + " Please report this application to aufs-users ML."
7257 +#define AuUnsupport(fmt, ...) do { \
7258 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7262 +#define AuTraceErr(e) do { \
7263 + if (unlikely((e) < 0)) \
7264 + AuDbg("err %d\n", (int)(e)); \
7267 +#define AuTraceErrPtr(p) do { \
7269 + AuDbg("err %ld\n", PTR_ERR(p)); \
7272 +/* dirty macros for debug print, use with "%.*s" and caution */
7273 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7275 +/* ---------------------------------------------------------------------- */
7280 +#ifdef CONFIG_AUFS_DEBUG
7281 +extern struct mutex au_dbg_mtx;
7282 +extern char *au_plevel;
7284 +void au_dpri_whlist(struct au_nhash *whlist);
7286 +void au_dpri_vdir(struct au_vdir *vdir);
7288 +void au_dpri_inode(struct inode *inode);
7289 +void au_dpri_dalias(struct inode *inode);
7290 +void au_dpri_dentry(struct dentry *dentry);
7292 +void au_dpri_file(struct file *filp);
7293 +struct super_block;
7294 +void au_dpri_sb(struct super_block *sb);
7296 +void au_dbg_sleep_jiffy(int jiffy);
7298 +void au_dbg_iattr(struct iattr *ia);
7300 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7301 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7302 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
7303 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
7304 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7305 +void au_dbg_verify_kthread(void);
7307 +int __init au_debug_init(void);
7308 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
7309 +#define AuDbgWhlist(w) do { \
7310 + mutex_lock(&au_dbg_mtx); \
7312 + au_dpri_whlist(w); \
7313 + mutex_unlock(&au_dbg_mtx); \
7316 +#define AuDbgVdir(v) do { \
7317 + mutex_lock(&au_dbg_mtx); \
7319 + au_dpri_vdir(v); \
7320 + mutex_unlock(&au_dbg_mtx); \
7323 +#define AuDbgInode(i) do { \
7324 + mutex_lock(&au_dbg_mtx); \
7326 + au_dpri_inode(i); \
7327 + mutex_unlock(&au_dbg_mtx); \
7330 +#define AuDbgDAlias(i) do { \
7331 + mutex_lock(&au_dbg_mtx); \
7333 + au_dpri_dalias(i); \
7334 + mutex_unlock(&au_dbg_mtx); \
7337 +#define AuDbgDentry(d) do { \
7338 + mutex_lock(&au_dbg_mtx); \
7340 + au_dpri_dentry(d); \
7341 + mutex_unlock(&au_dbg_mtx); \
7344 +#define AuDbgFile(f) do { \
7345 + mutex_lock(&au_dbg_mtx); \
7347 + au_dpri_file(f); \
7348 + mutex_unlock(&au_dbg_mtx); \
7351 +#define AuDbgSb(sb) do { \
7352 + mutex_lock(&au_dbg_mtx); \
7353 + AuDbg(#sb "\n"); \
7355 + mutex_unlock(&au_dbg_mtx); \
7358 +#define AuDbgSleep(sec) do { \
7359 + AuDbg("sleep %d sec\n", sec); \
7363 +#define AuDbgSleepJiffy(jiffy) do { \
7364 + AuDbg("sleep %d jiffies\n", jiffy); \
7365 + au_dbg_sleep_jiffy(jiffy); \
7368 +#define AuDbgIAttr(ia) do { \
7369 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
7370 + au_dbg_iattr(ia); \
7373 +#define AuDbgSym(addr) do { \
7374 + char sym[KSYM_SYMBOL_LEN]; \
7375 + sprint_symbol(sym, (unsigned long)addr); \
7376 + AuDbg("%s\n", sym); \
7379 +#define AuInfoSym(addr) do { \
7380 + char sym[KSYM_SYMBOL_LEN]; \
7381 + sprint_symbol(sym, (unsigned long)addr); \
7382 + AuInfo("%s\n", sym); \
7385 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7386 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
7387 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
7388 + unsigned int sigen)
7389 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7390 +AuStubVoid(au_dbg_verify_kthread, void)
7391 +AuStubInt0(__init au_debug_init, void)
7392 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
7394 +#define AuDbgWhlist(w) do {} while (0)
7395 +#define AuDbgVdir(v) do {} while (0)
7396 +#define AuDbgInode(i) do {} while (0)
7397 +#define AuDbgDAlias(i) do {} while (0)
7398 +#define AuDbgDentry(d) do {} while (0)
7399 +#define AuDbgFile(f) do {} while (0)
7400 +#define AuDbgSb(sb) do {} while (0)
7401 +#define AuDbgSleep(sec) do {} while (0)
7402 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
7403 +#define AuDbgIAttr(ia) do {} while (0)
7404 +#define AuDbgSym(addr) do {} while (0)
7405 +#define AuInfoSym(addr) do {} while (0)
7406 +#endif /* CONFIG_AUFS_DEBUG */
7408 +/* ---------------------------------------------------------------------- */
7410 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7411 +int __init au_sysrq_init(void);
7412 +void au_sysrq_fin(void);
7414 +#ifdef CONFIG_HW_CONSOLE
7415 +#define au_dbg_blocked() do { \
7417 + handle_sysrq('w'); \
7420 +AuStubVoid(au_dbg_blocked, void)
7424 +AuStubInt0(__init au_sysrq_init, void)
7425 +AuStubVoid(au_sysrq_fin, void)
7426 +AuStubVoid(au_dbg_blocked, void)
7427 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7429 +#endif /* __KERNEL__ */
7430 +#endif /* __AUFS_DEBUG_H__ */
7431 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7432 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7433 +++ linux/fs/aufs/dentry.c 2015-01-25 13:00:38.631047076 +0100
7436 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7438 + * This program, aufs is free software; you can redistribute it and/or modify
7439 + * it under the terms of the GNU General Public License as published by
7440 + * the Free Software Foundation; either version 2 of the License, or
7441 + * (at your option) any later version.
7443 + * This program is distributed in the hope that it will be useful,
7444 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7445 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7446 + * GNU General Public License for more details.
7448 + * You should have received a copy of the GNU General Public License
7449 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7453 + * lookup and dentry operations
7456 +#include <linux/namei.h>
7459 +#define AuLkup_ALLOW_NEG 1
7460 +#define AuLkup_IGNORE_PERM (1 << 1)
7461 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7462 +#define au_fset_lkup(flags, name) \
7463 + do { (flags) |= AuLkup_##name; } while (0)
7464 +#define au_fclr_lkup(flags, name) \
7465 + do { (flags) &= ~AuLkup_##name; } while (0)
7467 +struct au_do_lookup_args {
7468 + unsigned int flags;
7473 + * returns positive/negative dentry, NULL or an error.
7474 + * NULL means whiteout-ed or not-found.
7476 +static struct dentry*
7477 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7478 + aufs_bindex_t bindex, struct qstr *wh_name,
7479 + struct au_do_lookup_args *args)
7481 + struct dentry *h_dentry;
7482 + struct inode *h_inode, *inode;
7483 + struct au_branch *br;
7484 + int wh_found, opq;
7485 + unsigned char wh_able;
7486 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7487 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7491 + br = au_sbr(dentry->d_sb, bindex);
7492 + wh_able = !!au_br_whable(br->br_perm);
7494 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7495 + h_dentry = ERR_PTR(wh_found);
7498 + if (unlikely(wh_found < 0))
7501 + /* We found a whiteout */
7502 + /* au_set_dbend(dentry, bindex); */
7503 + au_set_dbwh(dentry, bindex);
7505 + return NULL; /* success */
7509 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7511 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7512 + if (IS_ERR(h_dentry))
7515 + h_inode = h_dentry->d_inode;
7519 + } else if (wh_found
7520 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7523 + if (au_dbend(dentry) <= bindex)
7524 + au_set_dbend(dentry, bindex);
7525 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7526 + au_set_dbstart(dentry, bindex);
7527 + au_set_h_dptr(dentry, bindex, h_dentry);
7529 + inode = dentry->d_inode;
7530 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
7531 + || (inode && !S_ISDIR(inode->i_mode)))
7532 + goto out; /* success */
7534 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7535 + opq = au_diropq_test(h_dentry);
7536 + mutex_unlock(&h_inode->i_mutex);
7538 + au_set_dbdiropq(dentry, bindex);
7539 + else if (unlikely(opq < 0)) {
7540 + au_set_h_dptr(dentry, bindex, NULL);
7541 + h_dentry = ERR_PTR(opq);
7552 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7554 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7555 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7561 + * returns the number of lower positive dentries,
7562 + * otherwise an error.
7563 + * can be called at unlinking with @type is zero.
7565 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7567 + int npositive, err;
7568 + aufs_bindex_t bindex, btail, bdiropq;
7569 + unsigned char isdir, dirperm1;
7570 + struct qstr whname;
7571 + struct au_do_lookup_args args = {
7575 + const struct qstr *name = &dentry->d_name;
7576 + struct dentry *parent;
7577 + struct inode *inode;
7578 + struct super_block *sb;
7580 + sb = dentry->d_sb;
7581 + err = au_test_shwh(sb, name);
7582 + if (unlikely(err))
7585 + err = au_wh_name_alloc(&whname, name);
7586 + if (unlikely(err))
7589 + inode = dentry->d_inode;
7590 + isdir = !!(inode && S_ISDIR(inode->i_mode));
7592 + au_fset_lkup(args.flags, ALLOW_NEG);
7593 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7596 + parent = dget_parent(dentry);
7597 + btail = au_dbtaildir(parent);
7598 + for (bindex = bstart; bindex <= btail; bindex++) {
7599 + struct dentry *h_parent, *h_dentry;
7600 + struct inode *h_inode, *h_dir;
7602 + h_dentry = au_h_dptr(dentry, bindex);
7604 + if (h_dentry->d_inode)
7606 + if (type != S_IFDIR)
7610 + h_parent = au_h_dptr(parent, bindex);
7613 + h_dir = h_parent->d_inode;
7614 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
7617 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7618 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7620 + mutex_unlock(&h_dir->i_mutex);
7621 + err = PTR_ERR(h_dentry);
7622 + if (IS_ERR(h_dentry))
7624 + au_fclr_lkup(args.flags, ALLOW_NEG);
7626 + au_fset_lkup(args.flags, IGNORE_PERM);
7628 + if (au_dbwh(dentry) >= 0)
7632 + h_inode = h_dentry->d_inode;
7637 + args.type = h_inode->i_mode & S_IFMT;
7638 + if (args.type != S_IFDIR)
7641 + /* the type of lower may be different */
7642 + bdiropq = au_dbdiropq(dentry);
7643 + if (bdiropq >= 0 && bdiropq <= bindex)
7649 + AuLabel(positive);
7650 + au_update_dbstart(dentry);
7653 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7654 + && au_dbstart(dentry) < 0)) {
7656 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7662 + kfree(whname.name);
7667 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7669 + struct dentry *dentry;
7672 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
7673 + dentry = vfsub_lkup_one(name, parent);
7675 + struct vfsub_lkup_one_args args = {
7681 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7682 + if (unlikely(wkq_err))
7683 + dentry = ERR_PTR(wkq_err);
7690 + * lookup @dentry on @bindex which should be negative.
7692 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7695 + struct dentry *parent, *h_parent, *h_dentry;
7696 + struct au_branch *br;
7698 + parent = dget_parent(dentry);
7699 + h_parent = au_h_dptr(parent, bindex);
7700 + br = au_sbr(dentry->d_sb, bindex);
7702 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7704 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7705 + err = PTR_ERR(h_dentry);
7706 + if (IS_ERR(h_dentry))
7708 + if (unlikely(h_dentry->d_inode)) {
7710 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7716 + if (bindex < au_dbstart(dentry))
7717 + au_set_dbstart(dentry, bindex);
7718 + if (au_dbend(dentry) < bindex)
7719 + au_set_dbend(dentry, bindex);
7720 + au_set_h_dptr(dentry, bindex, h_dentry);
7727 +/* ---------------------------------------------------------------------- */
7729 +/* subset of struct inode */
7731 + unsigned long i_ino;
7732 + /* unsigned int i_nlink; */
7738 + blkcnt_t i_blocks;
7743 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7745 + ia->i_ino = h_inode->i_ino;
7746 + /* ia->i_nlink = h_inode->i_nlink; */
7747 + ia->i_uid = h_inode->i_uid;
7748 + ia->i_gid = h_inode->i_gid;
7749 + ia->i_version = h_inode->i_version;
7751 + ia->i_size = h_inode->i_size;
7752 + ia->i_blocks = h_inode->i_blocks;
7754 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7757 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7759 + return ia->i_ino != h_inode->i_ino
7760 + /* || ia->i_nlink != h_inode->i_nlink */
7761 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7762 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7763 + || ia->i_version != h_inode->i_version
7765 + || ia->i_size != h_inode->i_size
7766 + || ia->i_blocks != h_inode->i_blocks
7768 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7771 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7772 + struct au_branch *br)
7775 + struct au_iattr ia;
7776 + struct inode *h_inode;
7777 + struct dentry *h_d;
7778 + struct super_block *h_sb;
7781 + memset(&ia, -1, sizeof(ia));
7782 + h_sb = h_dentry->d_sb;
7783 + h_inode = h_dentry->d_inode;
7785 + au_iattr_save(&ia, h_inode);
7786 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7787 + /* nfs d_revalidate may return 0 for negative dentry */
7788 + /* fuse d_revalidate always return 0 for negative dentry */
7791 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7792 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7793 + err = PTR_ERR(h_d);
7798 + if (unlikely(h_d != h_dentry
7799 + || h_d->d_inode != h_inode
7800 + || (h_inode && au_iattr_test(&ia, h_inode))))
7801 + err = au_busy_or_stale();
7809 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7810 + struct dentry *h_parent, struct au_branch *br)
7815 + if (udba == AuOpt_UDBA_REVAL
7816 + && !au_test_fs_remote(h_dentry->d_sb)) {
7818 + err = (h_dentry->d_parent->d_inode != h_dir);
7819 + } else if (udba != AuOpt_UDBA_NONE)
7820 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7825 +/* ---------------------------------------------------------------------- */
7827 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7830 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7831 + struct au_hdentry tmp, *p, *q;
7832 + struct au_dinfo *dinfo;
7833 + struct super_block *sb;
7835 + DiMustWriteLock(dentry);
7837 + sb = dentry->d_sb;
7838 + dinfo = au_di(dentry);
7839 + bend = dinfo->di_bend;
7840 + bwh = dinfo->di_bwh;
7841 + bdiropq = dinfo->di_bdiropq;
7842 + p = dinfo->di_hdentry + dinfo->di_bstart;
7843 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7844 + if (!p->hd_dentry)
7847 + new_bindex = au_br_index(sb, p->hd_id);
7848 + if (new_bindex == bindex)
7851 + if (dinfo->di_bwh == bindex)
7853 + if (dinfo->di_bdiropq == bindex)
7854 + bdiropq = new_bindex;
7855 + if (new_bindex < 0) {
7857 + p->hd_dentry = NULL;
7861 + /* swap two lower dentries, and loop again */
7862 + q = dinfo->di_hdentry + new_bindex;
7866 + if (tmp.hd_dentry) {
7872 + dinfo->di_bwh = -1;
7873 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7874 + dinfo->di_bwh = bwh;
7876 + dinfo->di_bdiropq = -1;
7878 + && bdiropq <= au_sbend(sb)
7879 + && au_sbr_whable(sb, bdiropq))
7880 + dinfo->di_bdiropq = bdiropq;
7883 + dinfo->di_bstart = -1;
7884 + dinfo->di_bend = -1;
7885 + bend = au_dbend(parent);
7886 + p = dinfo->di_hdentry;
7887 + for (bindex = 0; bindex <= bend; bindex++, p++)
7888 + if (p->hd_dentry) {
7889 + dinfo->di_bstart = bindex;
7893 + if (dinfo->di_bstart >= 0) {
7894 + p = dinfo->di_hdentry + bend;
7895 + for (bindex = bend; bindex >= 0; bindex--, p--)
7896 + if (p->hd_dentry) {
7897 + dinfo->di_bend = bindex;
7906 +static void au_do_hide(struct dentry *dentry)
7908 + struct inode *inode;
7910 + inode = dentry->d_inode;
7912 + if (!S_ISDIR(inode->i_mode)) {
7913 + if (inode->i_nlink && !d_unhashed(dentry))
7914 + drop_nlink(inode);
7916 + clear_nlink(inode);
7917 + /* stop next lookup */
7918 + inode->i_flags |= S_DEAD;
7920 + smp_mb(); /* necessary? */
7925 +static int au_hide_children(struct dentry *parent)
7927 + int err, i, j, ndentry;
7928 + struct au_dcsub_pages dpages;
7929 + struct au_dpage *dpage;
7930 + struct dentry *dentry;
7932 + err = au_dpages_init(&dpages, GFP_NOFS);
7933 + if (unlikely(err))
7935 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7936 + if (unlikely(err))
7939 + /* in reverse order */
7940 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7941 + dpage = dpages.dpages + i;
7942 + ndentry = dpage->ndentry;
7943 + for (j = ndentry - 1; j >= 0; j--) {
7944 + dentry = dpage->dentries[j];
7945 + if (dentry != parent)
7946 + au_do_hide(dentry);
7951 + au_dpages_free(&dpages);
7956 +static void au_hide(struct dentry *dentry)
7959 + struct inode *inode;
7961 + AuDbgDentry(dentry);
7962 + inode = dentry->d_inode;
7963 + if (inode && S_ISDIR(inode->i_mode)) {
7964 + /* shrink_dcache_parent(dentry); */
7965 + err = au_hide_children(dentry);
7966 + if (unlikely(err))
7967 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7970 + au_do_hide(dentry);
7974 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7976 + * a dirty branch is added
7977 + * - on the top of layers
7978 + * - in the middle of layers
7979 + * - to the bottom of layers
7981 + * on the added branch there exists
7984 + * - a same named entry
7986 + * * negative --> positive
7987 + * * positive --> positive
7988 + * - type is unchanged
7989 + * - type is changed
7991 + * * negative --> negative
7992 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7995 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7996 + struct au_dinfo *tmp)
7999 + aufs_bindex_t bindex, bend;
8001 + struct dentry *dentry;
8002 + struct inode *inode;
8005 + struct au_hdentry *hd;
8006 + struct inode *inode, *h_inode;
8007 + struct dentry *h_dentry;
8010 + AuDebugOn(dinfo->di_bstart < 0);
8011 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
8012 + orig_h.inode = orig_h.dentry->d_inode;
8015 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8016 + memset(&tmp_h, 0, sizeof(tmp_h));
8017 + if (tmp->di_bstart >= 0) {
8018 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
8019 + tmp_h.inode = tmp_h.dentry->d_inode;
8021 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8024 + inode = dentry->d_inode;
8025 + if (!orig_h.inode) {
8026 + AuDbg("nagative originally\n");
8032 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8033 + AuDebugOn(dinfo->di_bdiropq != -1);
8035 + if (!tmp_h.inode) {
8036 + AuDbg("negative --> negative\n");
8037 + /* should have only one negative lower */
8038 + if (tmp->di_bstart >= 0
8039 + && tmp->di_bstart < dinfo->di_bstart) {
8040 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
8041 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8042 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
8043 + au_di_cp(dinfo, tmp);
8044 + hd = tmp->di_hdentry + tmp->di_bstart;
8045 + au_set_h_dptr(dentry, tmp->di_bstart,
8046 + dget(hd->hd_dentry));
8048 + au_dbg_verify_dinode(dentry);
8050 + AuDbg("negative --> positive\n");
8052 + * similar to the behaviour of creating with bypassing
8054 + * unhash it in order to force an error in the
8055 + * succeeding create operation.
8056 + * we should not set S_DEAD here.
8059 + /* au_di_swap(tmp, dinfo); */
8060 + au_dbg_verify_dinode(dentry);
8063 + AuDbg("positive originally\n");
8064 + /* inode may be NULL */
8065 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8066 + if (!tmp_h.inode) {
8067 + AuDbg("positive --> negative\n");
8068 + /* or bypassing aufs */
8070 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
8071 + dinfo->di_bwh = tmp->di_bwh;
8073 + err = au_refresh_hinode_self(inode);
8074 + au_dbg_verify_dinode(dentry);
8075 + } else if (orig_h.mode == tmp_h.mode) {
8076 + AuDbg("positive --> positive, same type\n");
8077 + if (!S_ISDIR(orig_h.mode)
8078 + && dinfo->di_bstart > tmp->di_bstart) {
8080 + * similar to the behaviour of removing and
8085 + err = au_refresh_hinode_self(inode);
8086 + au_dbg_verify_dinode(dentry);
8088 + /* fill empty slots */
8089 + if (dinfo->di_bstart > tmp->di_bstart)
8090 + dinfo->di_bstart = tmp->di_bstart;
8091 + if (dinfo->di_bend < tmp->di_bend)
8092 + dinfo->di_bend = tmp->di_bend;
8093 + dinfo->di_bwh = tmp->di_bwh;
8094 + dinfo->di_bdiropq = tmp->di_bdiropq;
8095 + hd = tmp->di_hdentry;
8096 + bend = dinfo->di_bend;
8097 + for (bindex = tmp->di_bstart; bindex <= bend;
8099 + if (au_h_dptr(dentry, bindex))
8101 + h_dentry = hd[bindex].hd_dentry;
8104 + h_inode = h_dentry->d_inode;
8105 + AuDebugOn(!h_inode);
8106 + AuDebugOn(orig_h.mode
8107 + != (h_inode->i_mode
8109 + au_set_h_dptr(dentry, bindex,
8112 + err = au_refresh_hinode(inode, dentry);
8113 + au_dbg_verify_dinode(dentry);
8116 + AuDbg("positive --> positive, different type\n");
8117 + /* similar to the behaviour of removing and creating */
8120 + err = au_refresh_hinode_self(inode);
8121 + au_dbg_verify_dinode(dentry);
8129 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8132 + unsigned int sigen;
8133 + struct au_dinfo *dinfo, *tmp;
8134 + struct super_block *sb;
8135 + struct inode *inode;
8137 + DiMustWriteLock(dentry);
8138 + AuDebugOn(IS_ROOT(dentry));
8139 + AuDebugOn(!parent->d_inode);
8141 + sb = dentry->d_sb;
8142 + inode = dentry->d_inode;
8143 + sigen = au_sigen(sb);
8144 + err = au_digen_test(parent, sigen);
8145 + if (unlikely(err))
8148 + dinfo = au_di(dentry);
8149 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
8150 + if (unlikely(err))
8152 + ebrange = au_dbrange_test(dentry);
8154 + ebrange = au_do_refresh_hdentry(dentry, parent);
8156 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8157 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8159 + err = au_refresh_hinode_self(inode);
8160 + au_dbg_verify_dinode(dentry);
8162 + goto out_dgen; /* success */
8166 + /* temporary dinfo */
8167 + AuDbgDentry(dentry);
8169 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8170 + if (unlikely(!tmp))
8172 + au_di_swap(tmp, dinfo);
8173 + /* returns the number of positive dentries */
8175 + * if current working dir is removed, it returns an error.
8176 + * but the dentry is legal.
8178 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8179 + AuDbgDentry(dentry);
8180 + au_di_swap(tmp, dinfo);
8181 + if (err == -ENOENT)
8184 + /* compare/refresh by dinfo */
8185 + AuDbgDentry(dentry);
8186 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8187 + au_dbg_verify_dinode(dentry);
8190 + au_rw_write_unlock(&tmp->di_rwsem);
8192 + if (unlikely(err))
8196 + au_update_digen(dentry);
8198 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8199 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8200 + AuDbgDentry(dentry);
8206 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8207 + struct dentry *dentry, aufs_bindex_t bindex)
8212 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8215 + AuDbg("b%d\n", bindex);
8217 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8218 + * due to whiteout and branch permission.
8220 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8221 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8222 + /* it may return tri-state */
8223 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8225 + if (unlikely(valid < 0))
8235 +/* todo: remove this */
8236 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8237 + unsigned int flags, int do_udba)
8240 + umode_t mode, h_mode;
8241 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8242 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8243 + struct inode *h_inode, *h_cached_inode;
8244 + struct dentry *h_dentry;
8245 + struct qstr *name, *h_name;
8252 + unhashed = !!d_unhashed(dentry);
8253 + is_root = !!IS_ROOT(dentry);
8254 + name = &dentry->d_name;
8255 + tmpfile = au_di(dentry)->di_tmpfile;
8258 + * Theoretically, REVAL test should be unnecessary in case of
8260 + * But {fs,i}notify doesn't fire some necessary events,
8261 + * IN_ATTRIB for atime/nlink/pageio
8262 + * Let's do REVAL test too.
8264 + if (do_udba && inode) {
8265 + mode = (inode->i_mode & S_IFMT);
8266 + plus = (inode->i_nlink > 0);
8267 + ibs = au_ibstart(inode);
8268 + ibe = au_ibend(inode);
8271 + bstart = au_dbstart(dentry);
8273 + if (inode && S_ISDIR(inode->i_mode))
8274 + btail = au_dbtaildir(dentry);
8275 + for (bindex = bstart; bindex <= btail; bindex++) {
8276 + h_dentry = au_h_dptr(dentry, bindex);
8280 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8281 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8282 + spin_lock(&h_dentry->d_lock);
8283 + h_name = &h_dentry->d_name;
8284 + if (unlikely(do_udba
8287 + && (unhashed != !!d_unhashed(h_dentry)
8289 + && !au_qstreq(name, h_name))
8292 + && !(flags & LOOKUP_OPEN)
8293 + && (h_dentry->d_flags
8294 + & DCACHE_NFSFS_RENAMED)))
8298 + h_unhashed = d_unhashed(h_dentry);
8299 + spin_unlock(&h_dentry->d_lock);
8300 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8301 + unhashed, h_unhashed, dentry, h_dentry);
8304 + spin_unlock(&h_dentry->d_lock);
8306 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8307 + if (unlikely(err))
8308 + /* do not goto err, to keep the errno */
8311 + /* todo: plink too? */
8316 + h_inode = h_dentry->d_inode;
8317 + if (unlikely(!!inode != !!h_inode))
8322 + h_cached_inode = h_inode;
8324 + h_mode = (h_inode->i_mode & S_IFMT);
8325 + h_plus = (h_inode->i_nlink > 0);
8327 + if (inode && ibs <= bindex && bindex <= ibe)
8328 + h_cached_inode = au_h_iptr(inode, bindex);
8331 + if (unlikely(plus != h_plus && !tmpfile))
8334 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8336 + && !IS_ROOT(h_dentry)
8337 + && unhashed != d_unhashed(h_dentry)))
8340 + if (unlikely(mode != h_mode
8341 + || h_cached_inode != h_inode))
8354 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8355 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8358 + struct dentry *parent;
8360 + if (!au_digen_test(dentry, sigen))
8363 + parent = dget_parent(dentry);
8364 + di_read_lock_parent(parent, AuLock_IR);
8365 + AuDebugOn(au_digen_test(parent, sigen));
8366 + au_dbg_verify_gen(parent, sigen);
8367 + err = au_refresh_dentry(dentry, parent);
8368 + di_read_unlock(parent, AuLock_IR);
8374 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8377 + struct dentry *d, *parent;
8378 + struct inode *inode;
8380 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8381 + return simple_reval_dpath(dentry, sigen);
8383 + /* slow loop, keep it simple and stupid */
8384 + /* cf: au_cpup_dirs() */
8387 + while (au_digen_test(dentry, sigen)) {
8391 + parent = dget_parent(d);
8392 + if (!au_digen_test(parent, sigen))
8397 + inode = d->d_inode;
8399 + di_write_lock_child2(d);
8401 + /* someone might update our dentry while we were sleeping */
8402 + if (au_digen_test(d, sigen)) {
8404 + * todo: consolidate with simple_reval_dpath(),
8405 + * do_refresh() and au_reval_for_attr().
8407 + di_read_lock_parent(parent, AuLock_IR);
8408 + err = au_refresh_dentry(d, parent);
8409 + di_read_unlock(parent, AuLock_IR);
8413 + di_write_unlock(d);
8415 + if (unlikely(err))
8423 + * if valid returns 1, otherwise 0.
8425 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8428 + unsigned int sigen;
8429 + unsigned char do_udba;
8430 + struct super_block *sb;
8431 + struct inode *inode;
8433 + /* todo: support rcu-walk? */
8434 + if (flags & LOOKUP_RCU)
8438 + if (unlikely(!au_di(dentry)))
8442 + sb = dentry->d_sb;
8445 + * i_mutex of parent dir may be held,
8446 + * but we should not return 'invalid' due to busy.
8448 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8449 + if (unlikely(err)) {
8454 + inode = dentry->d_inode;
8455 + if (unlikely(inode && is_bad_inode(inode))) {
8460 + if (unlikely(au_dbrange_test(dentry))) {
8466 + sigen = au_sigen(sb);
8467 + if (au_digen_test(dentry, sigen)) {
8468 + AuDebugOn(IS_ROOT(dentry));
8469 + err = au_reval_dpath(dentry, sigen);
8470 + if (unlikely(err)) {
8475 + di_downgrade_lock(dentry, AuLock_IR);
8478 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8480 + && !(inode->i_state && I_LINKABLE)
8481 + && (IS_DEADDIR(inode) || !inode->i_nlink))
8484 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8485 + if (do_udba && inode) {
8486 + aufs_bindex_t bstart = au_ibstart(inode);
8487 + struct inode *h_inode;
8489 + if (bstart >= 0) {
8490 + h_inode = au_h_iptr(inode, bstart);
8491 + if (h_inode && au_test_higen(inode, h_inode))
8496 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8497 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8499 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8505 + di_downgrade_lock(dentry, AuLock_IR);
8507 + aufs_read_unlock(dentry, AuLock_IR);
8512 + AuDbg("%pd invalid, %d\n", dentry, valid);
8518 +static void aufs_d_release(struct dentry *dentry)
8520 + if (au_di(dentry)) {
8521 + au_di_fin(dentry);
8522 + au_hn_di_reinit(dentry);
8526 +const struct dentry_operations aufs_dop = {
8527 + .d_revalidate = aufs_d_revalidate,
8528 + .d_weak_revalidate = aufs_d_revalidate,
8529 + .d_release = aufs_d_release
8531 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8532 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8533 +++ linux/fs/aufs/dentry.h 2015-01-25 13:00:38.631047076 +0100
8536 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8538 + * This program, aufs is free software; you can redistribute it and/or modify
8539 + * it under the terms of the GNU General Public License as published by
8540 + * the Free Software Foundation; either version 2 of the License, or
8541 + * (at your option) any later version.
8543 + * This program is distributed in the hope that it will be useful,
8544 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8545 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8546 + * GNU General Public License for more details.
8548 + * You should have received a copy of the GNU General Public License
8549 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8553 + * lookup and dentry operations
8556 +#ifndef __AUFS_DENTRY_H__
8557 +#define __AUFS_DENTRY_H__
8561 +#include <linux/dcache.h>
8564 +struct au_hdentry {
8565 + struct dentry *hd_dentry;
8566 + aufs_bindex_t hd_id;
8570 + atomic_t di_generation;
8572 + struct au_rwsem di_rwsem;
8573 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8574 + unsigned char di_tmpfile; /* to allow the different name */
8575 + struct au_hdentry *di_hdentry;
8576 +} ____cacheline_aligned_in_smp;
8578 +/* ---------------------------------------------------------------------- */
8581 +extern const struct dentry_operations aufs_dop;
8583 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8584 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8585 + struct dentry *h_parent, struct au_branch *br);
8587 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8588 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8589 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8590 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8593 +void au_di_init_once(void *_di);
8594 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8595 +void au_di_free(struct au_dinfo *dinfo);
8596 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8597 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8598 +int au_di_init(struct dentry *dentry);
8599 +void au_di_fin(struct dentry *dentry);
8600 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8602 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8603 +void di_read_unlock(struct dentry *d, int flags);
8604 +void di_downgrade_lock(struct dentry *d, int flags);
8605 +void di_write_lock(struct dentry *d, unsigned int lsc);
8606 +void di_write_unlock(struct dentry *d);
8607 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8608 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8609 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8611 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8612 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8613 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8614 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8616 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8617 + struct dentry *h_dentry);
8618 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8619 +int au_dbrange_test(struct dentry *dentry);
8620 +void au_update_digen(struct dentry *dentry);
8621 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8622 +void au_update_dbstart(struct dentry *dentry);
8623 +void au_update_dbend(struct dentry *dentry);
8624 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8626 +/* ---------------------------------------------------------------------- */
8628 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8630 + return dentry->d_fsdata;
8633 +/* ---------------------------------------------------------------------- */
8635 +/* lock subclass for dinfo */
8637 + AuLsc_DI_CHILD, /* child first */
8638 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8639 + AuLsc_DI_CHILD3, /* copyup dirs */
8643 + AuLsc_DI_TMP /* temp for replacing dinfo */
8647 + * di_read_lock_child, di_write_lock_child,
8648 + * di_read_lock_child2, di_write_lock_child2,
8649 + * di_read_lock_child3, di_write_lock_child3,
8650 + * di_read_lock_parent, di_write_lock_parent,
8651 + * di_read_lock_parent2, di_write_lock_parent2,
8652 + * di_read_lock_parent3, di_write_lock_parent3,
8654 +#define AuReadLockFunc(name, lsc) \
8655 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8656 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8658 +#define AuWriteLockFunc(name, lsc) \
8659 +static inline void di_write_lock_##name(struct dentry *d) \
8660 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8662 +#define AuRWLockFuncs(name, lsc) \
8663 + AuReadLockFunc(name, lsc) \
8664 + AuWriteLockFunc(name, lsc)
8666 +AuRWLockFuncs(child, CHILD);
8667 +AuRWLockFuncs(child2, CHILD2);
8668 +AuRWLockFuncs(child3, CHILD3);
8669 +AuRWLockFuncs(parent, PARENT);
8670 +AuRWLockFuncs(parent2, PARENT2);
8671 +AuRWLockFuncs(parent3, PARENT3);
8673 +#undef AuReadLockFunc
8674 +#undef AuWriteLockFunc
8675 +#undef AuRWLockFuncs
8677 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8678 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8679 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8681 +/* ---------------------------------------------------------------------- */
8683 +/* todo: memory barrier? */
8684 +static inline unsigned int au_digen(struct dentry *d)
8686 + return atomic_read(&au_di(d)->di_generation);
8689 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8691 + hdentry->hd_dentry = NULL;
8694 +static inline void au_hdput(struct au_hdentry *hd)
8697 + dput(hd->hd_dentry);
8700 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8702 + DiMustAnyLock(dentry);
8703 + return au_di(dentry)->di_bstart;
8706 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8708 + DiMustAnyLock(dentry);
8709 + return au_di(dentry)->di_bend;
8712 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8714 + DiMustAnyLock(dentry);
8715 + return au_di(dentry)->di_bwh;
8718 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8720 + DiMustAnyLock(dentry);
8721 + return au_di(dentry)->di_bdiropq;
8724 +/* todo: hard/soft set? */
8725 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8727 + DiMustWriteLock(dentry);
8728 + au_di(dentry)->di_bstart = bindex;
8731 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8733 + DiMustWriteLock(dentry);
8734 + au_di(dentry)->di_bend = bindex;
8737 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8739 + DiMustWriteLock(dentry);
8740 + /* dbwh can be outside of bstart - bend range */
8741 + au_di(dentry)->di_bwh = bindex;
8744 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8746 + DiMustWriteLock(dentry);
8747 + au_di(dentry)->di_bdiropq = bindex;
8750 +/* ---------------------------------------------------------------------- */
8752 +#ifdef CONFIG_AUFS_HNOTIFY
8753 +static inline void au_digen_dec(struct dentry *d)
8755 + atomic_dec(&au_di(d)->di_generation);
8758 +static inline void au_hn_di_reinit(struct dentry *dentry)
8760 + dentry->d_fsdata = NULL;
8763 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8764 +#endif /* CONFIG_AUFS_HNOTIFY */
8766 +#endif /* __KERNEL__ */
8767 +#endif /* __AUFS_DENTRY_H__ */
8768 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8769 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8770 +++ linux/fs/aufs/dinfo.c 2015-01-25 13:00:38.631047076 +0100
8773 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8775 + * This program, aufs is free software; you can redistribute it and/or modify
8776 + * it under the terms of the GNU General Public License as published by
8777 + * the Free Software Foundation; either version 2 of the License, or
8778 + * (at your option) any later version.
8780 + * This program is distributed in the hope that it will be useful,
8781 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8782 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8783 + * GNU General Public License for more details.
8785 + * You should have received a copy of the GNU General Public License
8786 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8790 + * dentry private data
8795 +void au_di_init_once(void *_dinfo)
8797 + struct au_dinfo *dinfo = _dinfo;
8798 + static struct lock_class_key aufs_di;
8800 + au_rw_init(&dinfo->di_rwsem);
8801 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8804 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8806 + struct au_dinfo *dinfo;
8809 + dinfo = au_cache_alloc_dinfo();
8810 + if (unlikely(!dinfo))
8813 + nbr = au_sbend(sb) + 1;
8816 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8817 + if (dinfo->di_hdentry) {
8818 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8819 + dinfo->di_bstart = -1;
8820 + dinfo->di_bend = -1;
8821 + dinfo->di_bwh = -1;
8822 + dinfo->di_bdiropq = -1;
8823 + dinfo->di_tmpfile = 0;
8824 + for (i = 0; i < nbr; i++)
8825 + dinfo->di_hdentry[i].hd_id = -1;
8829 + au_cache_free_dinfo(dinfo);
8836 +void au_di_free(struct au_dinfo *dinfo)
8838 + struct au_hdentry *p;
8839 + aufs_bindex_t bend, bindex;
8841 + /* dentry may not be revalidated */
8842 + bindex = dinfo->di_bstart;
8843 + if (bindex >= 0) {
8844 + bend = dinfo->di_bend;
8845 + p = dinfo->di_hdentry + bindex;
8846 + while (bindex++ <= bend)
8849 + kfree(dinfo->di_hdentry);
8850 + au_cache_free_dinfo(dinfo);
8853 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8855 + struct au_hdentry *p;
8858 + AuRwMustWriteLock(&a->di_rwsem);
8859 + AuRwMustWriteLock(&b->di_rwsem);
8861 +#define DiSwap(v, name) \
8863 + v = a->di_##name; \
8864 + a->di_##name = b->di_##name; \
8865 + b->di_##name = v; \
8868 + DiSwap(p, hdentry);
8869 + DiSwap(bi, bstart);
8872 + DiSwap(bi, bdiropq);
8878 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8880 + AuRwMustWriteLock(&dst->di_rwsem);
8881 + AuRwMustWriteLock(&src->di_rwsem);
8883 + dst->di_bstart = src->di_bstart;
8884 + dst->di_bend = src->di_bend;
8885 + dst->di_bwh = src->di_bwh;
8886 + dst->di_bdiropq = src->di_bdiropq;
8890 +int au_di_init(struct dentry *dentry)
8893 + struct super_block *sb;
8894 + struct au_dinfo *dinfo;
8897 + sb = dentry->d_sb;
8898 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8900 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8901 + /* smp_mb(); */ /* atomic_set */
8902 + dentry->d_fsdata = dinfo;
8909 +void au_di_fin(struct dentry *dentry)
8911 + struct au_dinfo *dinfo;
8913 + dinfo = au_di(dentry);
8914 + AuRwDestroy(&dinfo->di_rwsem);
8915 + au_di_free(dinfo);
8918 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8921 + struct au_hdentry *hdp;
8923 + AuRwMustWriteLock(&dinfo->di_rwsem);
8926 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8928 + sz = sizeof(*hdp);
8929 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8931 + dinfo->di_hdentry = hdp;
8938 +/* ---------------------------------------------------------------------- */
8940 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8943 + case AuLsc_DI_CHILD:
8944 + ii_write_lock_child(inode);
8946 + case AuLsc_DI_CHILD2:
8947 + ii_write_lock_child2(inode);
8949 + case AuLsc_DI_CHILD3:
8950 + ii_write_lock_child3(inode);
8952 + case AuLsc_DI_PARENT:
8953 + ii_write_lock_parent(inode);
8955 + case AuLsc_DI_PARENT2:
8956 + ii_write_lock_parent2(inode);
8958 + case AuLsc_DI_PARENT3:
8959 + ii_write_lock_parent3(inode);
8966 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8969 + case AuLsc_DI_CHILD:
8970 + ii_read_lock_child(inode);
8972 + case AuLsc_DI_CHILD2:
8973 + ii_read_lock_child2(inode);
8975 + case AuLsc_DI_CHILD3:
8976 + ii_read_lock_child3(inode);
8978 + case AuLsc_DI_PARENT:
8979 + ii_read_lock_parent(inode);
8981 + case AuLsc_DI_PARENT2:
8982 + ii_read_lock_parent2(inode);
8984 + case AuLsc_DI_PARENT3:
8985 + ii_read_lock_parent3(inode);
8992 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
8994 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8996 + if (au_ftest_lock(flags, IW))
8997 + do_ii_write_lock(d->d_inode, lsc);
8998 + else if (au_ftest_lock(flags, IR))
8999 + do_ii_read_lock(d->d_inode, lsc);
9003 +void di_read_unlock(struct dentry *d, int flags)
9006 + if (au_ftest_lock(flags, IW)) {
9007 + au_dbg_verify_dinode(d);
9008 + ii_write_unlock(d->d_inode);
9009 + } else if (au_ftest_lock(flags, IR)) {
9010 + au_dbg_verify_dinode(d);
9011 + ii_read_unlock(d->d_inode);
9014 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9017 +void di_downgrade_lock(struct dentry *d, int flags)
9019 + if (d->d_inode && au_ftest_lock(flags, IR))
9020 + ii_downgrade_lock(d->d_inode);
9021 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9024 +void di_write_lock(struct dentry *d, unsigned int lsc)
9026 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9028 + do_ii_write_lock(d->d_inode, lsc);
9031 +void di_write_unlock(struct dentry *d)
9033 + au_dbg_verify_dinode(d);
9035 + ii_write_unlock(d->d_inode);
9036 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9039 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9041 + AuDebugOn(d1 == d2
9042 + || d1->d_inode == d2->d_inode
9043 + || d1->d_sb != d2->d_sb);
9045 + if (isdir && au_test_subdir(d1, d2)) {
9046 + di_write_lock_child(d1);
9047 + di_write_lock_child2(d2);
9049 + /* there should be no races */
9050 + di_write_lock_child(d2);
9051 + di_write_lock_child2(d1);
9055 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9057 + AuDebugOn(d1 == d2
9058 + || d1->d_inode == d2->d_inode
9059 + || d1->d_sb != d2->d_sb);
9061 + if (isdir && au_test_subdir(d1, d2)) {
9062 + di_write_lock_parent(d1);
9063 + di_write_lock_parent2(d2);
9065 + /* there should be no races */
9066 + di_write_lock_parent(d2);
9067 + di_write_lock_parent2(d1);
9071 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9073 + di_write_unlock(d1);
9074 + if (d1->d_inode == d2->d_inode)
9075 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9077 + di_write_unlock(d2);
9080 +/* ---------------------------------------------------------------------- */
9082 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9086 + DiMustAnyLock(dentry);
9088 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
9090 + AuDebugOn(bindex < 0);
9091 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
9092 + AuDebugOn(d && au_dcount(d) <= 0);
9097 + * extended version of au_h_dptr().
9098 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9101 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9103 + struct dentry *h_dentry;
9104 + struct inode *inode, *h_inode;
9106 + inode = dentry->d_inode;
9107 + AuDebugOn(!inode);
9110 + if (au_dbstart(dentry) <= bindex
9111 + && bindex <= au_dbend(dentry))
9112 + h_dentry = au_h_dptr(dentry, bindex);
9113 + if (h_dentry && !au_d_linkable(h_dentry)) {
9115 + goto out; /* success */
9118 + AuDebugOn(bindex < au_ibstart(inode));
9119 + AuDebugOn(au_ibend(inode) < bindex);
9120 + h_inode = au_h_iptr(inode, bindex);
9121 + h_dentry = d_find_alias(h_inode);
9123 + if (!IS_ERR(h_dentry)) {
9124 + if (!au_d_linkable(h_dentry))
9125 + goto out; /* success */
9131 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9132 + h_dentry = au_plink_lkup(inode, bindex);
9133 + AuDebugOn(!h_dentry);
9134 + if (!IS_ERR(h_dentry)) {
9135 + if (!au_d_hashed_positive(h_dentry))
9136 + goto out; /* success */
9143 + AuDbgDentry(h_dentry);
9147 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9149 + aufs_bindex_t bend, bwh;
9151 + bend = au_dbend(dentry);
9153 + bwh = au_dbwh(dentry);
9156 + if (0 < bwh && bwh < bend)
9162 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9164 + aufs_bindex_t bend, bopq;
9166 + bend = au_dbtail(dentry);
9168 + bopq = au_dbdiropq(dentry);
9169 + if (0 <= bopq && bopq < bend)
9175 +/* ---------------------------------------------------------------------- */
9177 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9178 + struct dentry *h_dentry)
9180 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9181 + struct au_branch *br;
9183 + DiMustWriteLock(dentry);
9186 + hd->hd_dentry = h_dentry;
9188 + br = au_sbr(dentry->d_sb, bindex);
9189 + hd->hd_id = br->br_id;
9193 +int au_dbrange_test(struct dentry *dentry)
9196 + aufs_bindex_t bstart, bend;
9199 + bstart = au_dbstart(dentry);
9200 + bend = au_dbend(dentry);
9202 + AuDebugOn(bend < 0 && bstart > bend);
9205 + AuDebugOn(bend >= 0);
9211 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9216 + if (unlikely(au_digen(dentry) != sigen
9217 + || au_iigen_test(dentry->d_inode, sigen)))
9223 +void au_update_digen(struct dentry *dentry)
9225 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9226 + /* smp_mb(); */ /* atomic_set */
9229 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9231 + struct au_dinfo *dinfo;
9232 + struct dentry *h_d;
9233 + struct au_hdentry *hdp;
9235 + DiMustWriteLock(dentry);
9237 + dinfo = au_di(dentry);
9238 + if (!dinfo || dinfo->di_bstart < 0)
9241 + hdp = dinfo->di_hdentry;
9242 + if (do_put_zero) {
9243 + aufs_bindex_t bindex, bend;
9245 + bend = dinfo->di_bend;
9246 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9247 + h_d = hdp[0 + bindex].hd_dentry;
9248 + if (h_d && !h_d->d_inode)
9249 + au_set_h_dptr(dentry, bindex, NULL);
9253 + dinfo->di_bstart = -1;
9254 + while (++dinfo->di_bstart <= dinfo->di_bend)
9255 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9257 + if (dinfo->di_bstart > dinfo->di_bend) {
9258 + dinfo->di_bstart = -1;
9259 + dinfo->di_bend = -1;
9264 + while (0 <= --dinfo->di_bend)
9265 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9267 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9270 +void au_update_dbstart(struct dentry *dentry)
9272 + aufs_bindex_t bindex, bend;
9273 + struct dentry *h_dentry;
9275 + bend = au_dbend(dentry);
9276 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9277 + h_dentry = au_h_dptr(dentry, bindex);
9280 + if (h_dentry->d_inode) {
9281 + au_set_dbstart(dentry, bindex);
9284 + au_set_h_dptr(dentry, bindex, NULL);
9288 +void au_update_dbend(struct dentry *dentry)
9290 + aufs_bindex_t bindex, bstart;
9291 + struct dentry *h_dentry;
9293 + bstart = au_dbstart(dentry);
9294 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9295 + h_dentry = au_h_dptr(dentry, bindex);
9298 + if (h_dentry->d_inode) {
9299 + au_set_dbend(dentry, bindex);
9302 + au_set_h_dptr(dentry, bindex, NULL);
9306 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9308 + aufs_bindex_t bindex, bend;
9310 + bend = au_dbend(dentry);
9311 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9312 + if (au_h_dptr(dentry, bindex) == h_dentry)
9316 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9317 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9318 +++ linux/fs/aufs/dir.c 2015-01-25 13:00:38.631047076 +0100
9321 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9323 + * This program, aufs is free software; you can redistribute it and/or modify
9324 + * it under the terms of the GNU General Public License as published by
9325 + * the Free Software Foundation; either version 2 of the License, or
9326 + * (at your option) any later version.
9328 + * This program is distributed in the hope that it will be useful,
9329 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9330 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9331 + * GNU General Public License for more details.
9333 + * You should have received a copy of the GNU General Public License
9334 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9338 + * directory operations
9341 +#include <linux/fs_stack.h>
9344 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9346 + unsigned int nlink;
9348 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9350 + nlink = dir->i_nlink;
9351 + nlink += h_dir->i_nlink - 2;
9352 + if (h_dir->i_nlink < 2)
9354 + smp_mb(); /* for i_nlink */
9355 + /* 0 can happen in revaliding */
9356 + set_nlink(dir, nlink);
9359 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9361 + unsigned int nlink;
9363 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9365 + nlink = dir->i_nlink;
9366 + nlink -= h_dir->i_nlink - 2;
9367 + if (h_dir->i_nlink < 2)
9369 + smp_mb(); /* for i_nlink */
9370 + /* nlink == 0 means the branch-fs is broken */
9371 + set_nlink(dir, nlink);
9374 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9377 + aufs_bindex_t bindex, bend;
9378 + struct file *h_file;
9379 + struct dentry *h_dentry;
9383 + AuDebugOn(!file_inode(file));
9384 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
9386 + bend = au_fbend_dir(file);
9387 + for (bindex = au_fbstart(file);
9388 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9390 + h_file = au_hf_dir(file, bindex);
9391 + if (h_file && file_inode(h_file))
9392 + sz += vfsub_f_size_read(h_file);
9395 + AuDebugOn(!dentry);
9396 + AuDebugOn(!dentry->d_inode);
9397 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
9399 + bend = au_dbtaildir(dentry);
9400 + for (bindex = au_dbstart(dentry);
9401 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9403 + h_dentry = au_h_dptr(dentry, bindex);
9404 + if (h_dentry && h_dentry->d_inode)
9405 + sz += i_size_read(h_dentry->d_inode);
9408 + if (sz < KMALLOC_MAX_SIZE)
9409 + sz = roundup_pow_of_two(sz);
9410 + if (sz > KMALLOC_MAX_SIZE)
9411 + sz = KMALLOC_MAX_SIZE;
9412 + else if (sz < NAME_MAX) {
9413 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9414 + sz = AUFS_RDBLK_DEF;
9419 +/* ---------------------------------------------------------------------- */
9421 +static int reopen_dir(struct file *file)
9424 + unsigned int flags;
9425 + aufs_bindex_t bindex, btail, bstart;
9426 + struct dentry *dentry, *h_dentry;
9427 + struct file *h_file;
9429 + /* open all lower dirs */
9430 + dentry = file->f_dentry;
9431 + bstart = au_dbstart(dentry);
9432 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9433 + au_set_h_fptr(file, bindex, NULL);
9434 + au_set_fbstart(file, bstart);
9436 + btail = au_dbtaildir(dentry);
9437 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9438 + au_set_h_fptr(file, bindex, NULL);
9439 + au_set_fbend_dir(file, btail);
9441 + flags = vfsub_file_flags(file);
9442 + for (bindex = bstart; bindex <= btail; bindex++) {
9443 + h_dentry = au_h_dptr(dentry, bindex);
9446 + h_file = au_hf_dir(file, bindex);
9450 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9451 + err = PTR_ERR(h_file);
9452 + if (IS_ERR(h_file))
9453 + goto out; /* close all? */
9454 + au_set_h_fptr(file, bindex, h_file);
9456 + au_update_figen(file);
9457 + /* todo: necessary? */
9458 + /* file->f_ra = h_file->f_ra; */
9465 +static int do_open_dir(struct file *file, int flags)
9468 + aufs_bindex_t bindex, btail;
9469 + struct dentry *dentry, *h_dentry;
9470 + struct file *h_file;
9472 + FiMustWriteLock(file);
9475 + dentry = file->f_dentry;
9476 + file->f_version = dentry->d_inode->i_version;
9477 + bindex = au_dbstart(dentry);
9478 + au_set_fbstart(file, bindex);
9479 + btail = au_dbtaildir(dentry);
9480 + au_set_fbend_dir(file, btail);
9481 + for (; !err && bindex <= btail; bindex++) {
9482 + h_dentry = au_h_dptr(dentry, bindex);
9486 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9487 + if (IS_ERR(h_file)) {
9488 + err = PTR_ERR(h_file);
9491 + au_set_h_fptr(file, bindex, h_file);
9493 + au_update_figen(file);
9494 + /* todo: necessary? */
9495 + /* file->f_ra = h_file->f_ra; */
9497 + return 0; /* success */
9500 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9501 + au_set_h_fptr(file, bindex, NULL);
9502 + au_set_fbstart(file, -1);
9503 + au_set_fbend_dir(file, -1);
9508 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9509 + struct file *file)
9512 + struct super_block *sb;
9513 + struct au_fidir *fidir;
9516 + sb = file->f_dentry->d_sb;
9517 + si_read_lock(sb, AuLock_FLUSH);
9518 + fidir = au_fidir_alloc(sb);
9520 + err = au_do_open(file, do_open_dir, fidir);
9521 + if (unlikely(err))
9524 + si_read_unlock(sb);
9528 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9529 + struct file *file)
9531 + struct au_vdir *vdir_cache;
9532 + struct au_finfo *finfo;
9533 + struct au_fidir *fidir;
9534 + aufs_bindex_t bindex, bend;
9536 + finfo = au_fi(file);
9537 + fidir = finfo->fi_hdir;
9539 + au_sphl_del(&finfo->fi_hlist,
9540 + &au_sbi(file->f_dentry->d_sb)->si_files);
9541 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9543 + au_vdir_free(vdir_cache);
9545 + bindex = finfo->fi_btop;
9546 + if (bindex >= 0) {
9548 + * calls fput() instead of filp_close(),
9549 + * since no dnotify or lock for the lower file.
9551 + bend = fidir->fd_bbot;
9552 + for (; bindex <= bend; bindex++)
9553 + au_set_h_fptr(file, bindex, NULL);
9556 + finfo->fi_hdir = NULL;
9558 + au_finfo_fin(file);
9562 +/* ---------------------------------------------------------------------- */
9564 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9567 + aufs_bindex_t bindex, bend;
9568 + struct file *h_file;
9571 + bend = au_fbend_dir(file);
9572 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9573 + h_file = au_hf_dir(file, bindex);
9575 + err = vfsub_flush(h_file, id);
9580 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9582 + return au_do_flush(file, id, au_do_flush_dir);
9585 +/* ---------------------------------------------------------------------- */
9587 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9590 + aufs_bindex_t bend, bindex;
9591 + struct inode *inode;
9592 + struct super_block *sb;
9595 + sb = dentry->d_sb;
9596 + inode = dentry->d_inode;
9598 + bend = au_dbend(dentry);
9599 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9600 + struct path h_path;
9602 + if (au_test_ro(sb, bindex, inode))
9604 + h_path.dentry = au_h_dptr(dentry, bindex);
9605 + if (!h_path.dentry)
9608 + h_path.mnt = au_sbr_mnt(sb, bindex);
9609 + err = vfsub_fsync(NULL, &h_path, datasync);
9615 +static int au_do_fsync_dir(struct file *file, int datasync)
9618 + aufs_bindex_t bend, bindex;
9619 + struct file *h_file;
9620 + struct super_block *sb;
9621 + struct inode *inode;
9623 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9624 + if (unlikely(err))
9627 + sb = file->f_dentry->d_sb;
9628 + inode = file_inode(file);
9629 + bend = au_fbend_dir(file);
9630 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9631 + h_file = au_hf_dir(file, bindex);
9632 + if (!h_file || au_test_ro(sb, bindex, inode))
9635 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9643 + * @file may be NULL
9645 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9649 + struct dentry *dentry;
9650 + struct super_block *sb;
9651 + struct mutex *mtx;
9654 + dentry = file->f_dentry;
9655 + mtx = &dentry->d_inode->i_mutex;
9657 + sb = dentry->d_sb;
9658 + si_noflush_read_lock(sb);
9660 + err = au_do_fsync_dir(file, datasync);
9662 + di_write_lock_child(dentry);
9663 + err = au_do_fsync_dir_no_file(dentry, datasync);
9665 + au_cpup_attr_timesizes(dentry->d_inode);
9666 + di_write_unlock(dentry);
9668 + fi_write_unlock(file);
9670 + si_read_unlock(sb);
9671 + mutex_unlock(mtx);
9675 +/* ---------------------------------------------------------------------- */
9677 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9680 + struct dentry *dentry;
9681 + struct inode *inode, *h_inode;
9682 + struct super_block *sb;
9684 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9686 + dentry = file->f_dentry;
9687 + inode = dentry->d_inode;
9690 + sb = dentry->d_sb;
9691 + si_read_lock(sb, AuLock_FLUSH);
9692 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9693 + if (unlikely(err))
9695 + err = au_alive_dir(dentry);
9697 + err = au_vdir_init(file);
9698 + di_downgrade_lock(dentry, AuLock_IR);
9699 + if (unlikely(err))
9702 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9703 + if (!au_test_nfsd()) {
9704 + err = au_vdir_fill_de(file, ctx);
9705 + fsstack_copy_attr_atime(inode, h_inode);
9708 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9709 + * encode_fh() and others.
9711 + atomic_inc(&h_inode->i_count);
9712 + di_read_unlock(dentry, AuLock_IR);
9713 + si_read_unlock(sb);
9714 + err = au_vdir_fill_de(file, ctx);
9715 + fsstack_copy_attr_atime(inode, h_inode);
9716 + fi_write_unlock(file);
9724 + di_read_unlock(dentry, AuLock_IR);
9725 + fi_write_unlock(file);
9727 + si_read_unlock(sb);
9731 +/* ---------------------------------------------------------------------- */
9733 +#define AuTestEmpty_WHONLY 1
9734 +#define AuTestEmpty_CALLED (1 << 1)
9735 +#define AuTestEmpty_SHWH (1 << 2)
9736 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9737 +#define au_fset_testempty(flags, name) \
9738 + do { (flags) |= AuTestEmpty_##name; } while (0)
9739 +#define au_fclr_testempty(flags, name) \
9740 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9742 +#ifndef CONFIG_AUFS_SHWH
9743 +#undef AuTestEmpty_SHWH
9744 +#define AuTestEmpty_SHWH 0
9747 +struct test_empty_arg {
9748 + struct dir_context ctx;
9749 + struct au_nhash *whlist;
9750 + unsigned int flags;
9752 + aufs_bindex_t bindex;
9755 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9756 + int namelen, loff_t offset __maybe_unused, u64 ino,
9757 + unsigned int d_type)
9759 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9761 + char *name = (void *)__name;
9764 + au_fset_testempty(arg->flags, CALLED);
9766 + if (name[0] == '.'
9767 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9768 + goto out; /* success */
9770 + if (namelen <= AUFS_WH_PFX_LEN
9771 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9772 + if (au_ftest_testempty(arg->flags, WHONLY)
9773 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9774 + arg->err = -ENOTEMPTY;
9778 + name += AUFS_WH_PFX_LEN;
9779 + namelen -= AUFS_WH_PFX_LEN;
9780 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9781 + arg->err = au_nhash_append_wh
9782 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9783 + au_ftest_testempty(arg->flags, SHWH));
9787 + AuTraceErr(arg->err);
9791 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9794 + struct file *h_file;
9796 + h_file = au_h_open(dentry, arg->bindex,
9797 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9798 + /*file*/NULL, /*force_wr*/0);
9799 + err = PTR_ERR(h_file);
9800 + if (IS_ERR(h_file))
9804 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9805 + && !file_inode(h_file)->i_nlink)
9810 + au_fclr_testempty(arg->flags, CALLED);
9812 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9815 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9819 + au_sbr_put(dentry->d_sb, arg->bindex);
9824 +struct do_test_empty_args {
9826 + struct dentry *dentry;
9827 + struct test_empty_arg *arg;
9830 +static void call_do_test_empty(void *args)
9832 + struct do_test_empty_args *a = args;
9833 + *a->errp = do_test_empty(a->dentry, a->arg);
9836 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9839 + struct dentry *h_dentry;
9840 + struct inode *h_inode;
9842 + h_dentry = au_h_dptr(dentry, arg->bindex);
9843 + h_inode = h_dentry->d_inode;
9844 + /* todo: i_mode changes anytime? */
9845 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9846 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9847 + mutex_unlock(&h_inode->i_mutex);
9849 + err = do_test_empty(dentry, arg);
9851 + struct do_test_empty_args args = {
9856 + unsigned int flags = arg->flags;
9858 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9859 + if (unlikely(wkq_err))
9861 + arg->flags = flags;
9867 +int au_test_empty_lower(struct dentry *dentry)
9870 + unsigned int rdhash;
9871 + aufs_bindex_t bindex, bstart, btail;
9872 + struct au_nhash whlist;
9873 + struct test_empty_arg arg = {
9875 + .actor = au_diractor(test_empty_cb)
9878 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
9880 + SiMustAnyLock(dentry->d_sb);
9882 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
9884 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
9885 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
9886 + if (unlikely(err))
9890 + arg.whlist = &whlist;
9891 + bstart = au_dbstart(dentry);
9892 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9893 + au_fset_testempty(arg.flags, SHWH);
9894 + test_empty = do_test_empty;
9895 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
9896 + test_empty = sio_test_empty;
9897 + arg.bindex = bstart;
9898 + err = test_empty(dentry, &arg);
9899 + if (unlikely(err))
9902 + au_fset_testempty(arg.flags, WHONLY);
9903 + btail = au_dbtaildir(dentry);
9904 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
9905 + struct dentry *h_dentry;
9907 + h_dentry = au_h_dptr(dentry, bindex);
9908 + if (h_dentry && h_dentry->d_inode) {
9909 + arg.bindex = bindex;
9910 + err = test_empty(dentry, &arg);
9915 + au_nhash_wh_free(&whlist);
9920 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
9923 + struct test_empty_arg arg = {
9925 + .actor = au_diractor(test_empty_cb)
9928 + aufs_bindex_t bindex, btail;
9931 + arg.whlist = whlist;
9932 + arg.flags = AuTestEmpty_WHONLY;
9933 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9934 + au_fset_testempty(arg.flags, SHWH);
9935 + btail = au_dbtaildir(dentry);
9936 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
9937 + struct dentry *h_dentry;
9939 + h_dentry = au_h_dptr(dentry, bindex);
9940 + if (h_dentry && h_dentry->d_inode) {
9941 + arg.bindex = bindex;
9942 + err = sio_test_empty(dentry, &arg);
9949 +/* ---------------------------------------------------------------------- */
9951 +const struct file_operations aufs_dir_fop = {
9952 + .owner = THIS_MODULE,
9953 + .llseek = default_llseek,
9954 + .read = generic_read_dir,
9955 + .iterate = aufs_iterate,
9956 + .unlocked_ioctl = aufs_ioctl_dir,
9957 +#ifdef CONFIG_COMPAT
9958 + .compat_ioctl = aufs_compat_ioctl_dir,
9960 + .open = aufs_open_dir,
9961 + .release = aufs_release_dir,
9962 + .flush = aufs_flush_dir,
9963 + .fsync = aufs_fsync_dir
9965 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
9966 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
9967 +++ linux/fs/aufs/dir.h 2015-01-25 13:00:38.631047076 +0100
9970 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9972 + * This program, aufs is free software; you can redistribute it and/or modify
9973 + * it under the terms of the GNU General Public License as published by
9974 + * the Free Software Foundation; either version 2 of the License, or
9975 + * (at your option) any later version.
9977 + * This program is distributed in the hope that it will be useful,
9978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9980 + * GNU General Public License for more details.
9982 + * You should have received a copy of the GNU General Public License
9983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9987 + * directory operations
9990 +#ifndef __AUFS_DIR_H__
9991 +#define __AUFS_DIR_H__
9995 +#include <linux/fs.h>
9997 +/* ---------------------------------------------------------------------- */
9999 +/* need to be faster and smaller */
10002 + unsigned int nh_num;
10003 + struct hlist_head *nh_head;
10006 +struct au_vdir_destr {
10007 + unsigned char len;
10008 + unsigned char name[0];
10011 +struct au_vdir_dehstr {
10012 + struct hlist_node hash;
10013 + struct au_vdir_destr *str;
10014 +} ____cacheline_aligned_in_smp;
10016 +struct au_vdir_de {
10018 + unsigned char de_type;
10019 + /* caution: packed */
10020 + struct au_vdir_destr de_str;
10023 +struct au_vdir_wh {
10024 + struct hlist_node wh_hash;
10025 +#ifdef CONFIG_AUFS_SHWH
10027 + aufs_bindex_t wh_bindex;
10028 + unsigned char wh_type;
10030 + aufs_bindex_t wh_bindex;
10032 + /* caution: packed */
10033 + struct au_vdir_destr wh_str;
10036 +union au_vdir_deblk_p {
10037 + unsigned char *deblk;
10038 + struct au_vdir_de *de;
10042 + unsigned char **vd_deblk;
10043 + unsigned long vd_nblk;
10045 + unsigned long ul;
10046 + union au_vdir_deblk_p p;
10049 + unsigned long vd_version;
10050 + unsigned int vd_deblk_sz;
10051 + unsigned long vd_jiffy;
10052 +} ____cacheline_aligned_in_smp;
10054 +/* ---------------------------------------------------------------------- */
10057 +extern const struct file_operations aufs_dir_fop;
10058 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10059 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10060 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10061 +int au_test_empty_lower(struct dentry *dentry);
10062 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10065 +unsigned int au_rdhash_est(loff_t sz);
10066 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10067 +void au_nhash_wh_free(struct au_nhash *whlist);
10068 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10070 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10071 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10072 + unsigned int d_type, aufs_bindex_t bindex,
10073 + unsigned char shwh);
10074 +void au_vdir_free(struct au_vdir *vdir);
10075 +int au_vdir_init(struct file *file);
10076 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10079 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10081 +#ifdef CONFIG_AUFS_RDU
10083 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10084 +#ifdef CONFIG_COMPAT
10085 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10086 + unsigned long arg);
10089 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10090 + unsigned int cmd, unsigned long arg)
10091 +#ifdef CONFIG_COMPAT
10092 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10093 + unsigned int cmd, unsigned long arg)
10097 +#endif /* __KERNEL__ */
10098 +#endif /* __AUFS_DIR_H__ */
10099 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10100 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10101 +++ linux/fs/aufs/dynop.c 2015-01-25 13:00:38.631047076 +0100
10104 + * Copyright (C) 2010-2014 Junjiro R. Okajima
10106 + * This program, aufs is free software; you can redistribute it and/or modify
10107 + * it under the terms of the GNU General Public License as published by
10108 + * the Free Software Foundation; either version 2 of the License, or
10109 + * (at your option) any later version.
10111 + * This program is distributed in the hope that it will be useful,
10112 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10113 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10114 + * GNU General Public License for more details.
10116 + * You should have received a copy of the GNU General Public License
10117 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10121 + * dynamically customizable operations for regular files
10126 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10129 + * How large will these lists be?
10130 + * Usually just a few elements, 20-30 at most for each, I guess.
10132 +static struct au_splhead dynop[AuDyLast];
10134 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
10136 + struct au_dykey *key, *tmp;
10137 + struct list_head *head;
10140 + head = &spl->head;
10142 + list_for_each_entry_rcu(tmp, head, dk_list)
10143 + if (tmp->dk_op.dy_hop == h_op) {
10145 + kref_get(&key->dk_kref);
10148 + rcu_read_unlock();
10153 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10155 + struct au_dykey **k, *found;
10156 + const void *h_op = key->dk_op.dy_hop;
10160 + k = br->br_dykey;
10161 + for (i = 0; i < AuBrDynOp; i++)
10163 + if (k[i]->dk_op.dy_hop == h_op) {
10170 + spin_lock(&br->br_dykey_lock);
10171 + for (; i < AuBrDynOp; i++)
10173 + if (k[i]->dk_op.dy_hop == h_op) {
10181 + spin_unlock(&br->br_dykey_lock);
10182 + BUG_ON(i == AuBrDynOp); /* expand the array */
10188 +/* kref_get() if @key is already added */
10189 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10191 + struct au_dykey *tmp, *found;
10192 + struct list_head *head;
10193 + const void *h_op = key->dk_op.dy_hop;
10196 + head = &spl->head;
10197 + spin_lock(&spl->spin);
10198 + list_for_each_entry(tmp, head, dk_list)
10199 + if (tmp->dk_op.dy_hop == h_op) {
10200 + kref_get(&tmp->dk_kref);
10205 + list_add_rcu(&key->dk_list, head);
10206 + spin_unlock(&spl->spin);
10213 +static void dy_free_rcu(struct rcu_head *rcu)
10215 + struct au_dykey *key;
10217 + key = container_of(rcu, struct au_dykey, dk_rcu);
10222 +static void dy_free(struct kref *kref)
10224 + struct au_dykey *key;
10225 + struct au_splhead *spl;
10227 + key = container_of(kref, struct au_dykey, dk_kref);
10228 + spl = dynop + key->dk_op.dy_type;
10229 + au_spl_del_rcu(&key->dk_list, spl);
10230 + call_rcu(&key->dk_rcu, dy_free_rcu);
10233 +void au_dy_put(struct au_dykey *key)
10235 + kref_put(&key->dk_kref, dy_free);
10238 +/* ---------------------------------------------------------------------- */
10240 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10242 +#ifdef CONFIG_AUFS_DEBUG
10243 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10244 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10246 +#define DyDbgDeclare(cnt) do {} while (0)
10247 +#define DyDbgInc(cnt) do {} while (0)
10250 +#define DySet(func, dst, src, h_op, h_sb) do { \
10252 + if (h_op->func) { \
10254 + dst.func = src.func; \
10256 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10260 +#define DySetForce(func, dst, src) do { \
10261 + AuDebugOn(!src.func); \
10263 + dst.func = src.func; \
10266 +#define DySetAop(func) \
10267 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10268 +#define DySetAopForce(func) \
10269 + DySetForce(func, dyaop->da_op, aufs_aop)
10271 +static void dy_aop(struct au_dykey *key, const void *h_op,
10272 + struct super_block *h_sb __maybe_unused)
10274 + struct au_dyaop *dyaop = (void *)key;
10275 + const struct address_space_operations *h_aop = h_op;
10276 + DyDbgDeclare(cnt);
10278 + AuDbg("%s\n", au_sbtype(h_sb));
10280 + DySetAop(writepage);
10281 + DySetAopForce(readpage); /* force */
10282 + DySetAop(writepages);
10283 + DySetAop(set_page_dirty);
10284 + DySetAop(readpages);
10285 + DySetAop(write_begin);
10286 + DySetAop(write_end);
10288 + DySetAop(invalidatepage);
10289 + DySetAop(releasepage);
10290 + DySetAop(freepage);
10291 + /* these two will be changed according to an aufs mount option */
10292 + DySetAop(direct_IO);
10293 + DySetAop(get_xip_mem);
10294 + DySetAop(migratepage);
10295 + DySetAop(launder_page);
10296 + DySetAop(is_partially_uptodate);
10297 + DySetAop(is_dirty_writeback);
10298 + DySetAop(error_remove_page);
10299 + DySetAop(swap_activate);
10300 + DySetAop(swap_deactivate);
10302 + DyDbgSize(cnt, *h_aop);
10303 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
10306 +/* ---------------------------------------------------------------------- */
10308 +static void dy_bug(struct kref *kref)
10313 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10315 + struct au_dykey *key, *old;
10316 + struct au_splhead *spl;
10319 + void (*set)(struct au_dykey *key, const void *h_op,
10320 + struct super_block *h_sb __maybe_unused);
10322 + static const struct op a[] = {
10324 + .sz = sizeof(struct au_dyaop),
10328 + const struct op *p;
10330 + spl = dynop + op->dy_type;
10331 + key = dy_gfind_get(spl, op->dy_hop);
10333 + goto out_add; /* success */
10335 + p = a + op->dy_type;
10336 + key = kzalloc(p->sz, GFP_NOFS);
10337 + if (unlikely(!key)) {
10338 + key = ERR_PTR(-ENOMEM);
10342 + key->dk_op.dy_hop = op->dy_hop;
10343 + kref_init(&key->dk_kref);
10344 + p->set(key, op->dy_hop, au_br_sb(br));
10345 + old = dy_gadd(spl, key);
10352 + old = dy_bradd(br, key);
10354 + /* its ref-count should never be zero here */
10355 + kref_put(&key->dk_kref, dy_bug);
10360 +/* ---------------------------------------------------------------------- */
10362 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10363 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10364 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10365 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10366 + * See the aufs manual in detail.
10368 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
10369 + * performance of fadvise() and madvise() may be affected.
10371 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10374 + dyaop->da_op.direct_IO = NULL;
10375 + dyaop->da_op.get_xip_mem = NULL;
10377 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10378 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
10379 + if (!dyaop->da_get_xip_mem)
10380 + dyaop->da_op.get_xip_mem = NULL;
10384 +static struct au_dyaop *dy_aget(struct au_branch *br,
10385 + const struct address_space_operations *h_aop,
10388 + struct au_dyaop *dyaop;
10389 + struct au_dynop op;
10391 + op.dy_type = AuDy_AOP;
10392 + op.dy_haop = h_aop;
10393 + dyaop = (void *)dy_get(&op, br);
10394 + if (IS_ERR(dyaop))
10396 + dy_adx(dyaop, do_dx);
10402 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10403 + struct inode *h_inode)
10406 + struct super_block *sb;
10407 + struct au_branch *br;
10408 + struct au_dyaop *dyaop;
10410 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10411 + IiMustWriteLock(inode);
10413 + sb = inode->i_sb;
10414 + br = au_sbr(sb, bindex);
10415 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10416 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10417 + err = PTR_ERR(dyaop);
10418 + if (IS_ERR(dyaop))
10419 + /* unnecessary to call dy_fput() */
10423 + inode->i_mapping->a_ops = &dyaop->da_op;
10430 + * Is it safe to replace a_ops during the inode/file is in operation?
10431 + * Yes, I hope so.
10433 +int au_dy_irefresh(struct inode *inode)
10436 + aufs_bindex_t bstart;
10437 + struct inode *h_inode;
10440 + if (S_ISREG(inode->i_mode)) {
10441 + bstart = au_ibstart(inode);
10442 + h_inode = au_h_iptr(inode, bstart);
10443 + err = au_dy_iaop(inode, bstart, h_inode);
10448 +void au_dy_arefresh(int do_dx)
10450 + struct au_splhead *spl;
10451 + struct list_head *head;
10452 + struct au_dykey *key;
10454 + spl = dynop + AuDy_AOP;
10455 + head = &spl->head;
10456 + spin_lock(&spl->spin);
10457 + list_for_each_entry(key, head, dk_list)
10458 + dy_adx((void *)key, do_dx);
10459 + spin_unlock(&spl->spin);
10462 +/* ---------------------------------------------------------------------- */
10464 +void __init au_dy_init(void)
10468 + /* make sure that 'struct au_dykey *' can be any type */
10469 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10471 + for (i = 0; i < AuDyLast; i++)
10472 + au_spl_init(dynop + i);
10475 +void au_dy_fin(void)
10479 + for (i = 0; i < AuDyLast; i++)
10480 + WARN_ON(!list_empty(&dynop[i].head));
10482 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10483 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10484 +++ linux/fs/aufs/dynop.h 2015-01-25 13:00:38.631047076 +0100
10487 + * Copyright (C) 2010-2014 Junjiro R. Okajima
10489 + * This program, aufs is free software; you can redistribute it and/or modify
10490 + * it under the terms of the GNU General Public License as published by
10491 + * the Free Software Foundation; either version 2 of the License, or
10492 + * (at your option) any later version.
10494 + * This program is distributed in the hope that it will be useful,
10495 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10496 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10497 + * GNU General Public License for more details.
10499 + * You should have received a copy of the GNU General Public License
10500 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10504 + * dynamically customizable operations (for regular files only)
10507 +#ifndef __AUFS_DYNOP_H__
10508 +#define __AUFS_DYNOP_H__
10512 +#include "inode.h"
10514 +enum {AuDy_AOP, AuDyLast};
10519 + const void *dy_hop;
10520 + const struct address_space_operations *dy_haop;
10526 + struct list_head dk_list;
10527 + struct rcu_head dk_rcu;
10529 + struct au_dynop dk_op;
10532 + * during I am in the branch local array, kref is gotten. when the
10533 + * branch is removed, kref is put.
10535 + struct kref dk_kref;
10538 +/* stop unioning since their sizes are very different from each other */
10540 + struct au_dykey da_key;
10541 + struct address_space_operations da_op; /* not const */
10542 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
10543 + void **, unsigned long *);
10546 +/* ---------------------------------------------------------------------- */
10550 +void au_dy_put(struct au_dykey *key);
10551 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10552 + struct inode *h_inode);
10553 +int au_dy_irefresh(struct inode *inode);
10554 +void au_dy_arefresh(int do_dio);
10556 +void __init au_dy_init(void);
10557 +void au_dy_fin(void);
10559 +#endif /* __KERNEL__ */
10560 +#endif /* __AUFS_DYNOP_H__ */
10561 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10562 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10563 +++ linux/fs/aufs/export.c 2015-01-25 13:00:38.631047076 +0100
10566 + * Copyright (C) 2005-2014 Junjiro R. Okajima
10568 + * This program, aufs is free software; you can redistribute it and/or modify
10569 + * it under the terms of the GNU General Public License as published by
10570 + * the Free Software Foundation; either version 2 of the License, or
10571 + * (at your option) any later version.
10573 + * This program is distributed in the hope that it will be useful,
10574 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10575 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10576 + * GNU General Public License for more details.
10578 + * You should have received a copy of the GNU General Public License
10579 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10586 +#include <linux/exportfs.h>
10587 +#include <linux/fs_struct.h>
10588 +#include <linux/namei.h>
10589 +#include <linux/nsproxy.h>
10590 +#include <linux/random.h>
10591 +#include <linux/writeback.h>
10592 +#include "../fs/mount.h"
10596 +#ifdef CONFIG_AUFS_INO_T_64
10604 +static ino_t decode_ino(__u32 *a)
10608 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10610 +#ifdef CONFIG_AUFS_INO_T_64
10616 +static void encode_ino(__u32 *a, ino_t ino)
10622 +#ifdef CONFIG_AUFS_INO_T_64
10627 +/* NFS file handle */
10631 +#ifdef CONFIG_AUFS_INO_T_64
10632 + /* support 64bit inode number */
10645 + Fh_ino = Fh_ino1,
10646 + Fh_dir_ino = Fh_dir_ino1
10649 +static int au_test_anon(struct dentry *dentry)
10651 + /* note: read d_flags without d_lock */
10652 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10655 +int au_test_nfsd(void)
10658 + struct task_struct *tsk = current;
10659 + char comm[sizeof(tsk->comm)];
10662 + if (tsk->flags & PF_KTHREAD) {
10663 + get_task_comm(comm, tsk);
10664 + ret = !strcmp(comm, "nfsd");
10670 +/* ---------------------------------------------------------------------- */
10671 +/* inode generation external table */
10673 +void au_xigen_inc(struct inode *inode)
10678 + struct super_block *sb;
10679 + struct au_sbinfo *sbinfo;
10681 + sb = inode->i_sb;
10682 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10684 + sbinfo = au_sbi(sb);
10685 + pos = inode->i_ino;
10686 + pos *= sizeof(igen);
10687 + igen = inode->i_generation + 1;
10688 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10689 + sizeof(igen), &pos);
10690 + if (sz == sizeof(igen))
10691 + return; /* success */
10693 + if (unlikely(sz >= 0))
10694 + AuIOErr("xigen error (%zd)\n", sz);
10697 +int au_xigen_new(struct inode *inode)
10702 + struct super_block *sb;
10703 + struct au_sbinfo *sbinfo;
10704 + struct file *file;
10707 + /* todo: dirty, at mount time */
10708 + if (inode->i_ino == AUFS_ROOT_INO)
10710 + sb = inode->i_sb;
10711 + SiMustAnyLock(sb);
10712 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10716 + pos = inode->i_ino;
10717 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10718 + AuIOErr1("too large i%lld\n", pos);
10721 + pos *= sizeof(inode->i_generation);
10724 + sbinfo = au_sbi(sb);
10725 + file = sbinfo->si_xigen;
10728 + if (vfsub_f_size_read(file)
10729 + < pos + sizeof(inode->i_generation)) {
10730 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10731 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10732 + sizeof(inode->i_generation), &pos);
10734 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10735 + sizeof(inode->i_generation), &pos);
10736 + if (sz == sizeof(inode->i_generation))
10737 + goto out; /* success */
10740 + if (unlikely(sz >= 0)) {
10742 + AuIOErr("xigen error (%zd)\n", sz);
10749 +int au_xigen_set(struct super_block *sb, struct file *base)
10752 + struct au_sbinfo *sbinfo;
10753 + struct file *file;
10755 + SiMustWriteLock(sb);
10757 + sbinfo = au_sbi(sb);
10758 + file = au_xino_create2(base, sbinfo->si_xigen);
10759 + err = PTR_ERR(file);
10760 + if (IS_ERR(file))
10763 + if (sbinfo->si_xigen)
10764 + fput(sbinfo->si_xigen);
10765 + sbinfo->si_xigen = file;
10771 +void au_xigen_clr(struct super_block *sb)
10773 + struct au_sbinfo *sbinfo;
10775 + SiMustWriteLock(sb);
10777 + sbinfo = au_sbi(sb);
10778 + if (sbinfo->si_xigen) {
10779 + fput(sbinfo->si_xigen);
10780 + sbinfo->si_xigen = NULL;
10784 +/* ---------------------------------------------------------------------- */
10786 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10789 + struct dentry *dentry, *d;
10790 + struct inode *inode;
10791 + unsigned int sigen;
10794 + inode = ilookup(sb, ino);
10798 + dentry = ERR_PTR(-ESTALE);
10799 + sigen = au_sigen(sb);
10800 + if (unlikely(is_bad_inode(inode)
10801 + || IS_DEADDIR(inode)
10802 + || sigen != au_iigen(inode, NULL)))
10806 + if (!dir_ino || S_ISDIR(inode->i_mode))
10807 + dentry = d_find_alias(inode);
10809 + spin_lock(&inode->i_lock);
10810 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
10811 + spin_lock(&d->d_lock);
10812 + if (!au_test_anon(d)
10813 + && d->d_parent->d_inode->i_ino == dir_ino) {
10814 + dentry = dget_dlock(d);
10815 + spin_unlock(&d->d_lock);
10818 + spin_unlock(&d->d_lock);
10820 + spin_unlock(&inode->i_lock);
10822 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10823 + /* need to refresh */
10831 + AuTraceErrPtr(dentry);
10835 +/* ---------------------------------------------------------------------- */
10837 +/* todo: dirty? */
10838 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10840 +struct au_compare_mnt_args {
10842 + struct super_block *sb;
10845 + struct vfsmount *mnt;
10848 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10850 + struct au_compare_mnt_args *a = arg;
10852 + if (mnt->mnt_sb != a->sb)
10854 + a->mnt = mntget(mnt);
10858 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10861 + struct path root;
10862 + struct au_compare_mnt_args args = {
10866 + get_fs_root(current->fs, &root);
10868 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10869 + rcu_read_unlock();
10872 + AuDebugOn(!args.mnt);
10876 +struct au_nfsd_si_lock {
10877 + unsigned int sigen;
10878 + aufs_bindex_t bindex, br_id;
10879 + unsigned char force_lock;
10882 +static int si_nfsd_read_lock(struct super_block *sb,
10883 + struct au_nfsd_si_lock *nsi_lock)
10886 + aufs_bindex_t bindex;
10888 + si_read_lock(sb, AuLock_FLUSH);
10890 + /* branch id may be wrapped around */
10892 + bindex = au_br_index(sb, nsi_lock->br_id);
10893 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
10894 + goto out; /* success */
10898 + if (!nsi_lock->force_lock)
10899 + si_read_unlock(sb);
10902 + nsi_lock->bindex = bindex;
10906 +struct find_name_by_ino {
10907 + struct dir_context ctx;
10908 + int called, found;
10915 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
10916 + loff_t offset, u64 ino, unsigned int d_type)
10918 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
10922 + if (a->ino != ino)
10925 + memcpy(a->name, name, namelen);
10926 + a->namelen = namelen;
10931 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
10932 + struct au_nfsd_si_lock *nsi_lock)
10934 + struct dentry *dentry, *parent;
10935 + struct file *file;
10936 + struct inode *dir;
10937 + struct find_name_by_ino arg = {
10939 + .actor = au_diractor(find_name_by_ino)
10944 + parent = path->dentry;
10946 + si_read_unlock(parent->d_sb);
10947 + file = vfsub_dentry_open(path, au_dir_roflags);
10948 + dentry = (void *)file;
10949 + if (IS_ERR(file))
10952 + dentry = ERR_PTR(-ENOMEM);
10953 + arg.name = (void *)__get_free_page(GFP_NOFS);
10954 + if (unlikely(!arg.name))
10961 + err = vfsub_iterate_dir(file, &arg.ctx);
10962 + } while (!err && !arg.found && arg.called);
10963 + dentry = ERR_PTR(err);
10964 + if (unlikely(err))
10966 + /* instead of ENOENT */
10967 + dentry = ERR_PTR(-ESTALE);
10971 + /* do not call vfsub_lkup_one() */
10972 + dir = parent->d_inode;
10973 + mutex_lock(&dir->i_mutex);
10974 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
10975 + mutex_unlock(&dir->i_mutex);
10976 + AuTraceErrPtr(dentry);
10977 + if (IS_ERR(dentry))
10979 + AuDebugOn(au_test_anon(dentry));
10980 + if (unlikely(!dentry->d_inode)) {
10982 + dentry = ERR_PTR(-ENOENT);
10986 + free_page((unsigned long)arg.name);
10990 + if (unlikely(nsi_lock
10991 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10992 + if (!IS_ERR(dentry)) {
10994 + dentry = ERR_PTR(-ESTALE);
10996 + AuTraceErrPtr(dentry);
11000 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11002 + struct au_nfsd_si_lock *nsi_lock)
11004 + struct dentry *dentry;
11005 + struct path path;
11007 + if (dir_ino != AUFS_ROOT_INO) {
11008 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11009 + dentry = path.dentry;
11010 + if (!path.dentry || IS_ERR(path.dentry))
11012 + AuDebugOn(au_test_anon(path.dentry));
11014 + path.dentry = dget(sb->s_root);
11016 + path.mnt = au_mnt_get(sb);
11017 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11021 + AuTraceErrPtr(dentry);
11025 +/* ---------------------------------------------------------------------- */
11027 +static int h_acceptable(void *expv, struct dentry *dentry)
11032 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11033 + char *buf, int len, struct super_block *sb)
11037 + struct path path;
11039 + p = d_path(h_rootpath, buf, len);
11044 + path.mnt = h_rootpath->mnt;
11045 + path.dentry = h_parent;
11046 + p = d_path(&path, buf, len);
11052 + path.mnt = au_mnt_get(sb);
11053 + path.dentry = sb->s_root;
11054 + p = d_path(&path, buf, len - strlen(p));
11055 + mntput(path.mnt);
11059 + p[strlen(p)] = '/';
11062 + AuTraceErrPtr(p);
11067 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11068 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11070 + struct dentry *dentry, *h_parent, *root;
11071 + struct super_block *h_sb;
11072 + char *pathname, *p;
11073 + struct vfsmount *h_mnt;
11074 + struct au_branch *br;
11076 + struct path path;
11078 + br = au_sbr(sb, nsi_lock->bindex);
11079 + h_mnt = au_br_mnt(br);
11080 + h_sb = h_mnt->mnt_sb;
11081 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11082 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11083 + fh_len - Fh_tail, fh[Fh_h_type],
11084 + h_acceptable, /*context*/NULL);
11085 + dentry = h_parent;
11086 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11087 + AuWarn1("%s decode_fh failed, %ld\n",
11088 + au_sbtype(h_sb), PTR_ERR(h_parent));
11092 + if (unlikely(au_test_anon(h_parent))) {
11093 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11094 + au_sbtype(h_sb));
11095 + goto out_h_parent;
11098 + dentry = ERR_PTR(-ENOMEM);
11099 + pathname = (void *)__get_free_page(GFP_NOFS);
11100 + if (unlikely(!pathname))
11101 + goto out_h_parent;
11103 + root = sb->s_root;
11104 + path.mnt = h_mnt;
11105 + di_read_lock_parent(root, !AuLock_IR);
11106 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11107 + di_read_unlock(root, !AuLock_IR);
11108 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11109 + dentry = (void *)p;
11111 + goto out_pathname;
11113 + si_read_unlock(sb);
11114 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11115 + dentry = ERR_PTR(err);
11116 + if (unlikely(err))
11119 + dentry = ERR_PTR(-ENOENT);
11120 + AuDebugOn(au_test_anon(path.dentry));
11121 + if (unlikely(!path.dentry->d_inode))
11124 + if (ino != path.dentry->d_inode->i_ino)
11125 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11127 + dentry = dget(path.dentry);
11132 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11133 + if (!IS_ERR(dentry)) {
11135 + dentry = ERR_PTR(-ESTALE);
11138 + free_page((unsigned long)pathname);
11142 + AuTraceErrPtr(dentry);
11146 +/* ---------------------------------------------------------------------- */
11148 +static struct dentry *
11149 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11152 + struct dentry *dentry;
11153 + __u32 *fh = fid->raw;
11154 + struct au_branch *br;
11155 + ino_t ino, dir_ino;
11156 + struct au_nfsd_si_lock nsi_lock = {
11160 + dentry = ERR_PTR(-ESTALE);
11161 + /* it should never happen, but the file handle is unreliable */
11162 + if (unlikely(fh_len < Fh_tail))
11164 + nsi_lock.sigen = fh[Fh_sigen];
11165 + nsi_lock.br_id = fh[Fh_br_id];
11167 + /* branch id may be wrapped around */
11169 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11171 + nsi_lock.force_lock = 1;
11173 + /* is this inode still cached? */
11174 + ino = decode_ino(fh + Fh_ino);
11175 + /* it should never happen */
11176 + if (unlikely(ino == AUFS_ROOT_INO))
11179 + dir_ino = decode_ino(fh + Fh_dir_ino);
11180 + dentry = decode_by_ino(sb, ino, dir_ino);
11181 + if (IS_ERR(dentry))
11186 + /* is the parent dir cached? */
11187 + br = au_sbr(sb, nsi_lock.bindex);
11188 + atomic_inc(&br->br_count);
11189 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11190 + if (IS_ERR(dentry))
11195 + /* lookup path */
11196 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11197 + if (IS_ERR(dentry))
11199 + if (unlikely(!dentry))
11200 + /* todo?: make it ESTALE */
11204 + if (!au_digen_test(dentry, au_sigen(sb))
11205 + && dentry->d_inode->i_generation == fh[Fh_igen])
11206 + goto out_unlock; /* success */
11209 + dentry = ERR_PTR(-ESTALE);
11212 + atomic_dec(&br->br_count);
11213 + si_read_unlock(sb);
11215 + AuTraceErrPtr(dentry);
11219 +#if 0 /* reserved for future use */
11220 +/* support subtreecheck option */
11221 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11222 + int fh_len, int fh_type)
11224 + struct dentry *parent;
11225 + __u32 *fh = fid->raw;
11228 + dir_ino = decode_ino(fh + Fh_dir_ino);
11229 + parent = decode_by_ino(sb, dir_ino, 0);
11230 + if (IS_ERR(parent))
11233 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11234 + dir_ino, fh, fh_len);
11237 + AuTraceErrPtr(parent);
11242 +/* ---------------------------------------------------------------------- */
11244 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11245 + struct inode *dir)
11248 + aufs_bindex_t bindex;
11249 + struct super_block *sb, *h_sb;
11250 + struct dentry *dentry, *parent, *h_parent;
11251 + struct inode *h_dir;
11252 + struct au_branch *br;
11255 + if (unlikely(*max_len <= Fh_tail)) {
11256 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11260 + err = FILEID_ROOT;
11261 + if (inode->i_ino == AUFS_ROOT_INO) {
11262 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11267 + sb = inode->i_sb;
11268 + err = si_read_lock(sb, AuLock_FLUSH);
11269 + if (unlikely(err))
11272 +#ifdef CONFIG_AUFS_DEBUG
11273 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11274 + AuWarn1("NFS-exporting requires xino\n");
11278 + ii_read_lock_child(inode);
11279 + bindex = au_ibstart(inode);
11281 + dentry = d_find_any_alias(inode);
11282 + if (unlikely(!dentry))
11284 + AuDebugOn(au_test_anon(dentry));
11285 + parent = dget_parent(dentry);
11287 + if (unlikely(!parent))
11289 + dir = parent->d_inode;
11292 + ii_read_lock_parent(dir);
11293 + h_dir = au_h_iptr(dir, bindex);
11294 + ii_read_unlock(dir);
11295 + if (unlikely(!h_dir))
11297 + h_parent = d_find_any_alias(h_dir);
11298 + if (unlikely(!h_parent))
11299 + goto out_hparent;
11302 + br = au_sbr(sb, bindex);
11303 + h_sb = au_br_sb(br);
11304 + if (unlikely(!h_sb->s_export_op)) {
11305 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11306 + goto out_hparent;
11309 + fh[Fh_br_id] = br->br_id;
11310 + fh[Fh_sigen] = au_sigen(sb);
11311 + encode_ino(fh + Fh_ino, inode->i_ino);
11312 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11313 + fh[Fh_igen] = inode->i_generation;
11315 + *max_len -= Fh_tail;
11316 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11318 + /*connectable or subtreecheck*/0);
11319 + err = fh[Fh_h_type];
11320 + *max_len += Fh_tail;
11321 + /* todo: macros? */
11322 + if (err != FILEID_INVALID)
11325 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11332 + ii_read_unlock(inode);
11333 + si_read_unlock(sb);
11335 + if (unlikely(err < 0))
11336 + err = FILEID_INVALID;
11340 +/* ---------------------------------------------------------------------- */
11342 +static int aufs_commit_metadata(struct inode *inode)
11345 + aufs_bindex_t bindex;
11346 + struct super_block *sb;
11347 + struct inode *h_inode;
11348 + int (*f)(struct inode *inode);
11350 + sb = inode->i_sb;
11351 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11352 + ii_write_lock_child(inode);
11353 + bindex = au_ibstart(inode);
11354 + AuDebugOn(bindex < 0);
11355 + h_inode = au_h_iptr(inode, bindex);
11357 + f = h_inode->i_sb->s_export_op->commit_metadata;
11359 + err = f(h_inode);
11361 + struct writeback_control wbc = {
11362 + .sync_mode = WB_SYNC_ALL,
11363 + .nr_to_write = 0 /* metadata only */
11366 + err = sync_inode(h_inode, &wbc);
11369 + au_cpup_attr_timesizes(inode);
11370 + ii_write_unlock(inode);
11371 + si_read_unlock(sb);
11375 +/* ---------------------------------------------------------------------- */
11377 +static struct export_operations aufs_export_op = {
11378 + .fh_to_dentry = aufs_fh_to_dentry,
11379 + /* .fh_to_parent = aufs_fh_to_parent, */
11380 + .encode_fh = aufs_encode_fh,
11381 + .commit_metadata = aufs_commit_metadata
11384 +void au_export_init(struct super_block *sb)
11386 + struct au_sbinfo *sbinfo;
11389 + sb->s_export_op = &aufs_export_op;
11390 + sbinfo = au_sbi(sb);
11391 + sbinfo->si_xigen = NULL;
11392 + get_random_bytes(&u, sizeof(u));
11393 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11394 + atomic_set(&sbinfo->si_xigen_next, u);
11396 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11397 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11398 +++ linux/fs/aufs/fhsm.c 2015-01-25 13:00:38.631047076 +0100
11401 + * Copyright (C) 2011-2014 Junjiro R. Okajima
11403 + * This program, aufs is free software; you can redistribute it and/or modify
11404 + * it under the terms of the GNU General Public License as published by
11405 + * the Free Software Foundation; either version 2 of the License, or
11406 + * (at your option) any later version.
11408 + * This program is distributed in the hope that it will be useful,
11409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11411 + * GNU General Public License for more details.
11413 + * You should have received a copy of the GNU General Public License
11414 + * along with this program; if not, write to the Free Software
11415 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11419 + * File-based Hierarchy Storage Management
11422 +#include <linux/anon_inodes.h>
11423 +#include <linux/poll.h>
11424 +#include <linux/seq_file.h>
11425 +#include <linux/statfs.h>
11428 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11430 + struct au_sbinfo *sbinfo;
11431 + struct au_fhsm *fhsm;
11433 + SiMustAnyLock(sb);
11435 + sbinfo = au_sbi(sb);
11436 + fhsm = &sbinfo->si_fhsm;
11437 + AuDebugOn(!fhsm);
11438 + return fhsm->fhsm_bottom;
11441 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11443 + struct au_sbinfo *sbinfo;
11444 + struct au_fhsm *fhsm;
11446 + SiMustWriteLock(sb);
11448 + sbinfo = au_sbi(sb);
11449 + fhsm = &sbinfo->si_fhsm;
11450 + AuDebugOn(!fhsm);
11451 + fhsm->fhsm_bottom = bindex;
11454 +/* ---------------------------------------------------------------------- */
11456 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11458 + struct au_br_fhsm *bf;
11460 + bf = br->br_fhsm;
11461 + MtxMustLock(&bf->bf_lock);
11463 + return !bf->bf_readable
11464 + || time_after(jiffies,
11465 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11468 +/* ---------------------------------------------------------------------- */
11470 +static void au_fhsm_notify(struct super_block *sb, int val)
11472 + struct au_sbinfo *sbinfo;
11473 + struct au_fhsm *fhsm;
11475 + SiMustAnyLock(sb);
11477 + sbinfo = au_sbi(sb);
11478 + fhsm = &sbinfo->si_fhsm;
11479 + if (au_fhsm_pid(fhsm)
11480 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11481 + atomic_set(&fhsm->fhsm_readable, val);
11483 + wake_up(&fhsm->fhsm_wqh);
11487 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11488 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11491 + struct au_branch *br;
11492 + struct au_br_fhsm *bf;
11494 + br = au_sbr(sb, bindex);
11495 + AuDebugOn(au_br_rdonly(br));
11496 + bf = br->br_fhsm;
11500 + mutex_lock(&bf->bf_lock);
11502 + MtxMustLock(&bf->bf_lock);
11504 + /* sb->s_root for NFS is unreliable */
11505 + err = au_br_stfs(br, &bf->bf_stfs);
11506 + if (unlikely(err)) {
11507 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11511 + bf->bf_jiffy = jiffies;
11512 + bf->bf_readable = 1;
11514 + au_fhsm_notify(sb, /*val*/1);
11516 + *rstfs = bf->bf_stfs;
11520 + mutex_unlock(&bf->bf_lock);
11521 + au_fhsm_notify(sb, /*val*/1);
11526 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11529 + struct au_sbinfo *sbinfo;
11530 + struct au_fhsm *fhsm;
11531 + struct au_branch *br;
11532 + struct au_br_fhsm *bf;
11534 + AuDbg("b%d, force %d\n", bindex, force);
11535 + SiMustAnyLock(sb);
11537 + sbinfo = au_sbi(sb);
11538 + fhsm = &sbinfo->si_fhsm;
11539 + if (!au_ftest_si(sbinfo, FHSM)
11540 + || fhsm->fhsm_bottom == bindex)
11543 + br = au_sbr(sb, bindex);
11544 + bf = br->br_fhsm;
11546 + mutex_lock(&bf->bf_lock);
11548 + || au_fhsm_pid(fhsm)
11549 + || au_fhsm_test_jiffy(sbinfo, br))
11550 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11552 + mutex_unlock(&bf->bf_lock);
11555 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11557 + aufs_bindex_t bindex, bend;
11558 + struct au_branch *br;
11560 + /* exclude the bottom */
11561 + bend = au_fhsm_bottom(sb);
11562 + for (bindex = 0; bindex < bend; bindex++) {
11563 + br = au_sbr(sb, bindex);
11564 + if (au_br_fhsm(br->br_perm))
11565 + au_fhsm_wrote(sb, bindex, force);
11569 +/* ---------------------------------------------------------------------- */
11571 +static unsigned int au_fhsm_poll(struct file *file,
11572 + struct poll_table_struct *wait)
11574 + unsigned int mask;
11575 + struct au_sbinfo *sbinfo;
11576 + struct au_fhsm *fhsm;
11579 + sbinfo = file->private_data;
11580 + fhsm = &sbinfo->si_fhsm;
11581 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11582 + if (atomic_read(&fhsm->fhsm_readable))
11583 + mask = POLLIN /* | POLLRDNORM */;
11585 + AuTraceErr((int)mask);
11589 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11590 + struct aufs_stfs *stfs, __s16 brid)
11594 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11596 + err = __put_user(brid, &stbr->brid);
11597 + if (unlikely(err))
11603 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11604 + struct aufs_stbr __user *stbr, size_t count)
11608 + aufs_bindex_t bindex, bend;
11609 + struct au_branch *br;
11610 + struct au_br_fhsm *bf;
11612 + /* except the bottom branch */
11615 + bend = au_fhsm_bottom(sb);
11616 + for (bindex = 0; !err && bindex < bend; bindex++) {
11617 + br = au_sbr(sb, bindex);
11618 + if (!au_br_fhsm(br->br_perm))
11621 + bf = br->br_fhsm;
11622 + mutex_lock(&bf->bf_lock);
11623 + if (bf->bf_readable) {
11625 + if (count >= sizeof(*stbr))
11626 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11629 + bf->bf_readable = 0;
11630 + count -= sizeof(*stbr);
11634 + mutex_unlock(&bf->bf_lock);
11637 + err = sizeof(*stbr) * nstbr;
11642 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11647 + aufs_bindex_t nfhsm, bindex, bend;
11648 + struct au_sbinfo *sbinfo;
11649 + struct au_fhsm *fhsm;
11650 + struct au_branch *br;
11651 + struct super_block *sb;
11654 + sbinfo = file->private_data;
11655 + fhsm = &sbinfo->si_fhsm;
11657 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11658 + if (!atomic_read(&fhsm->fhsm_readable)) {
11659 + if (vfsub_file_flags(file) & O_NONBLOCK)
11662 + err = wait_event_interruptible_locked_irq
11664 + atomic_read(&fhsm->fhsm_readable));
11666 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11667 + if (unlikely(err))
11670 + /* sb may already be dead */
11671 + au_rw_read_lock(&sbinfo->si_rwsem);
11672 + readable = atomic_read(&fhsm->fhsm_readable);
11673 + if (readable > 0) {
11674 + sb = sbinfo->si_sb;
11676 + /* exclude the bottom branch */
11678 + bend = au_fhsm_bottom(sb);
11679 + for (bindex = 0; bindex < bend; bindex++) {
11680 + br = au_sbr(sb, bindex);
11681 + if (au_br_fhsm(br->br_perm))
11685 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11686 + atomic_set(&fhsm->fhsm_readable, 0);
11687 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11691 + au_rw_read_unlock(&sbinfo->si_rwsem);
11699 +static int au_fhsm_release(struct inode *inode, struct file *file)
11701 + struct au_sbinfo *sbinfo;
11702 + struct au_fhsm *fhsm;
11704 + /* sb may already be dead */
11705 + sbinfo = file->private_data;
11706 + fhsm = &sbinfo->si_fhsm;
11707 + spin_lock(&fhsm->fhsm_spin);
11708 + fhsm->fhsm_pid = 0;
11709 + spin_unlock(&fhsm->fhsm_spin);
11710 + kobject_put(&sbinfo->si_kobj);
11715 +static const struct file_operations au_fhsm_fops = {
11716 + .owner = THIS_MODULE,
11717 + .llseek = noop_llseek,
11718 + .read = au_fhsm_read,
11719 + .poll = au_fhsm_poll,
11720 + .release = au_fhsm_release
11723 +int au_fhsm_fd(struct super_block *sb, int oflags)
11726 + struct au_sbinfo *sbinfo;
11727 + struct au_fhsm *fhsm;
11730 + if (unlikely(!capable(CAP_SYS_ADMIN)))
11734 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
11738 + sbinfo = au_sbi(sb);
11739 + fhsm = &sbinfo->si_fhsm;
11740 + spin_lock(&fhsm->fhsm_spin);
11741 + if (!fhsm->fhsm_pid)
11742 + fhsm->fhsm_pid = current->pid;
11745 + spin_unlock(&fhsm->fhsm_spin);
11746 + if (unlikely(err))
11749 + oflags |= O_RDONLY;
11750 + /* oflags |= FMODE_NONOTIFY; */
11751 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
11753 + if (unlikely(fd < 0))
11756 + /* succeed reglardless 'fhsm' status */
11757 + kobject_get(&sbinfo->si_kobj);
11758 + si_noflush_read_lock(sb);
11759 + if (au_ftest_si(sbinfo, FHSM))
11760 + au_fhsm_wrote_all(sb, /*force*/0);
11761 + si_read_unlock(sb);
11762 + goto out; /* success */
11765 + spin_lock(&fhsm->fhsm_spin);
11766 + fhsm->fhsm_pid = 0;
11767 + spin_unlock(&fhsm->fhsm_spin);
11773 +/* ---------------------------------------------------------------------- */
11775 +int au_fhsm_br_alloc(struct au_branch *br)
11780 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
11782 + au_br_fhsm_init(br->br_fhsm);
11789 +/* ---------------------------------------------------------------------- */
11791 +void au_fhsm_fin(struct super_block *sb)
11793 + au_fhsm_notify(sb, /*val*/-1);
11796 +void au_fhsm_init(struct au_sbinfo *sbinfo)
11798 + struct au_fhsm *fhsm;
11800 + fhsm = &sbinfo->si_fhsm;
11801 + spin_lock_init(&fhsm->fhsm_spin);
11802 + init_waitqueue_head(&fhsm->fhsm_wqh);
11803 + atomic_set(&fhsm->fhsm_readable, 0);
11804 + fhsm->fhsm_expire
11805 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
11806 + fhsm->fhsm_bottom = -1;
11809 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
11811 + sbinfo->si_fhsm.fhsm_expire
11812 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
11815 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
11819 + if (!au_ftest_si(sbinfo, FHSM))
11822 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
11823 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
11824 + seq_printf(seq, ",fhsm_sec=%u", u);
11826 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
11827 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
11828 +++ linux/fs/aufs/file.c 2015-01-25 13:00:38.631047076 +0100
11831 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11833 + * This program, aufs is free software; you can redistribute it and/or modify
11834 + * it under the terms of the GNU General Public License as published by
11835 + * the Free Software Foundation; either version 2 of the License, or
11836 + * (at your option) any later version.
11838 + * This program is distributed in the hope that it will be useful,
11839 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11840 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11841 + * GNU General Public License for more details.
11843 + * You should have received a copy of the GNU General Public License
11844 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11848 + * handling file/dir, and address_space operation
11851 +#ifdef CONFIG_AUFS_DEBUG
11852 +#include <linux/migrate.h>
11854 +#include <linux/pagemap.h>
11857 +/* drop flags for writing */
11858 +unsigned int au_file_roflags(unsigned int flags)
11860 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
11861 + flags |= O_RDONLY | O_NOATIME;
11865 +/* common functions to regular file and dir */
11866 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11867 + struct file *file, int force_wr)
11869 + struct file *h_file;
11870 + struct dentry *h_dentry;
11871 + struct inode *h_inode;
11872 + struct super_block *sb;
11873 + struct au_branch *br;
11874 + struct path h_path;
11875 + int err, exec_flag;
11877 + /* a race condition can happen between open and unlink/rmdir */
11878 + h_file = ERR_PTR(-ENOENT);
11879 + h_dentry = au_h_dptr(dentry, bindex);
11880 + if (au_test_nfsd() && !h_dentry)
11882 + h_inode = h_dentry->d_inode;
11883 + if (au_test_nfsd() && !h_inode)
11885 + spin_lock(&h_dentry->d_lock);
11886 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
11888 + /* || !dentry->d_inode->i_nlink */
11890 + spin_unlock(&h_dentry->d_lock);
11891 + if (unlikely(err))
11894 + sb = dentry->d_sb;
11895 + br = au_sbr(sb, bindex);
11896 + h_file = ERR_PTR(-EACCES);
11897 + exec_flag = flags & __FMODE_EXEC;
11898 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
11901 + /* drop flags for writing */
11902 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
11903 + if (force_wr && !(flags & O_WRONLY))
11905 + flags = au_file_roflags(flags);
11907 + h_file = ERR_PTR(-EROFS);
11908 + flags = au_file_roflags(flags);
11909 + if (unlikely(vfsub_native_ro(h_inode)
11910 + || IS_APPEND(h_inode)))
11912 + flags &= ~O_ACCMODE;
11913 + flags |= O_WRONLY;
11916 + flags &= ~O_CREAT;
11917 + atomic_inc(&br->br_count);
11918 + h_path.dentry = h_dentry;
11919 + h_path.mnt = au_br_mnt(br);
11920 + h_file = vfsub_dentry_open(&h_path, flags);
11921 + if (IS_ERR(h_file))
11925 + err = deny_write_access(h_file);
11926 + if (unlikely(err)) {
11928 + h_file = ERR_PTR(err);
11932 + fsnotify_open(h_file);
11933 + goto out; /* success */
11936 + atomic_dec(&br->br_count);
11941 +static int au_cmoo(struct dentry *dentry)
11944 + unsigned int udba;
11945 + struct path h_path;
11946 + struct au_pin pin;
11947 + struct au_cp_generic cpg = {
11948 + .dentry = dentry,
11953 + .flags = AuCpup_DTIME | AuCpup_HOPEN
11955 + struct inode *inode, *delegated;
11956 + struct super_block *sb;
11957 + struct au_sbinfo *sbinfo;
11958 + struct au_fhsm *fhsm;
11960 + struct au_branch *br;
11961 + struct dentry *parent;
11962 + struct au_hinode *hdir;
11964 + DiMustWriteLock(dentry);
11965 + inode = dentry->d_inode;
11966 + IiMustWriteLock(inode);
11969 + if (IS_ROOT(dentry))
11971 + cpg.bsrc = au_dbstart(dentry);
11975 + sb = dentry->d_sb;
11976 + sbinfo = au_sbi(sb);
11977 + fhsm = &sbinfo->si_fhsm;
11978 + pid = au_fhsm_pid(fhsm);
11980 + && (current->pid == pid
11981 + || current->real_parent->pid == pid))
11984 + br = au_sbr(sb, cpg.bsrc);
11985 + cmoo = au_br_cmoo(br->br_perm);
11988 + if (!S_ISREG(inode->i_mode))
11989 + cmoo &= AuBrAttr_COO_ALL;
11993 + parent = dget_parent(dentry);
11994 + di_write_lock_parent(parent);
11995 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
11997 + if (unlikely(err < 0)) {
11998 + err = 0; /* there is no upper writable branch */
12001 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12003 + /* do not respect the coo attrib for the target branch */
12004 + err = au_cpup_dirs(dentry, cpg.bdst);
12005 + if (unlikely(err))
12008 + di_downgrade_lock(parent, AuLock_IR);
12009 + udba = au_opt_udba(sb);
12010 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12011 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12012 + if (unlikely(err))
12015 + err = au_sio_cpup_simple(&cpg);
12017 + if (unlikely(err))
12019 + if (!(cmoo & AuBrWAttr_MOO))
12020 + goto out_parent; /* success */
12022 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12023 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12024 + if (unlikely(err))
12027 + h_path.mnt = au_br_mnt(br);
12028 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12029 + hdir = au_hi(parent->d_inode, cpg.bsrc);
12030 + delegated = NULL;
12031 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12033 + /* todo: keep h_dentry or not? */
12034 + if (unlikely(err == -EWOULDBLOCK)) {
12035 + pr_warn("cannot retry for NFSv4 delegation"
12036 + " for an internal unlink\n");
12039 + if (unlikely(err)) {
12040 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12044 + goto out_parent; /* success */
12047 + di_downgrade_lock(parent, AuLock_IR);
12049 + di_read_unlock(parent, AuLock_IR);
12056 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
12057 + struct au_fidir *fidir)
12060 + struct dentry *dentry;
12061 + struct au_finfo *finfo;
12063 + err = au_finfo_init(file, fidir);
12064 + if (unlikely(err))
12067 + dentry = file->f_dentry;
12068 + di_write_lock_child(dentry);
12069 + err = au_cmoo(dentry);
12070 + di_downgrade_lock(dentry, AuLock_IR);
12072 + err = open(file, vfsub_file_flags(file));
12073 + di_read_unlock(dentry, AuLock_IR);
12075 + finfo = au_fi(file);
12077 + finfo->fi_file = file;
12078 + au_sphl_add(&finfo->fi_hlist,
12079 + &au_sbi(file->f_dentry->d_sb)->si_files);
12081 + fi_write_unlock(file);
12082 + if (unlikely(err)) {
12083 + finfo->fi_hdir = NULL;
12084 + au_finfo_fin(file);
12091 +int au_reopen_nondir(struct file *file)
12094 + aufs_bindex_t bstart;
12095 + struct dentry *dentry;
12096 + struct file *h_file, *h_file_tmp;
12098 + dentry = file->f_dentry;
12099 + bstart = au_dbstart(dentry);
12100 + h_file_tmp = NULL;
12101 + if (au_fbstart(file) == bstart) {
12102 + h_file = au_hf_top(file);
12103 + if (file->f_mode == h_file->f_mode)
12104 + return 0; /* success */
12105 + h_file_tmp = h_file;
12106 + get_file(h_file_tmp);
12107 + au_set_h_fptr(file, bstart, NULL);
12109 + AuDebugOn(au_fi(file)->fi_hdir);
12112 + * file exists on both of rw and ro
12113 + * open --> dbstart and fbstart are both 0
12114 + * prepend a branch as rw, "rw" become ro
12116 + * delete the top branch, "rw" becomes rw again
12117 + * --> dbstart is 1, fbstart is still 0
12118 + * write --> fbstart is 0 but dbstart is 1
12120 + /* AuDebugOn(au_fbstart(file) < bstart); */
12122 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
12123 + file, /*force_wr*/0);
12124 + err = PTR_ERR(h_file);
12125 + if (IS_ERR(h_file)) {
12126 + if (h_file_tmp) {
12127 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
12128 + au_set_h_fptr(file, bstart, h_file_tmp);
12129 + h_file_tmp = NULL;
12131 + goto out; /* todo: close all? */
12135 + au_set_fbstart(file, bstart);
12136 + au_set_h_fptr(file, bstart, h_file);
12137 + au_update_figen(file);
12138 + /* todo: necessary? */
12139 + /* file->f_ra = h_file->f_ra; */
12143 + fput(h_file_tmp);
12147 +/* ---------------------------------------------------------------------- */
12149 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12150 + struct dentry *hi_wh)
12153 + aufs_bindex_t bstart;
12154 + struct au_dinfo *dinfo;
12155 + struct dentry *h_dentry;
12156 + struct au_hdentry *hdp;
12158 + dinfo = au_di(file->f_dentry);
12159 + AuRwMustWriteLock(&dinfo->di_rwsem);
12161 + bstart = dinfo->di_bstart;
12162 + dinfo->di_bstart = btgt;
12163 + hdp = dinfo->di_hdentry;
12164 + h_dentry = hdp[0 + btgt].hd_dentry;
12165 + hdp[0 + btgt].hd_dentry = hi_wh;
12166 + err = au_reopen_nondir(file);
12167 + hdp[0 + btgt].hd_dentry = h_dentry;
12168 + dinfo->di_bstart = bstart;
12173 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12174 + aufs_bindex_t bcpup, struct au_pin *pin)
12177 + struct inode *inode, *h_inode;
12178 + struct dentry *h_dentry, *hi_wh;
12179 + struct au_cp_generic cpg = {
12180 + .dentry = file->f_dentry,
12187 + au_update_dbstart(cpg.dentry);
12188 + inode = cpg.dentry->d_inode;
12190 + if (au_dbstart(cpg.dentry) <= bcpup
12191 + && au_dbend(cpg.dentry) >= bcpup) {
12192 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12194 + h_inode = h_dentry->d_inode;
12196 + hi_wh = au_hi_wh(inode, bcpup);
12197 + if (!hi_wh && !h_inode)
12198 + err = au_sio_cpup_wh(&cpg, file);
12200 + /* already copied-up after unlink */
12201 + err = au_reopen_wh(file, bcpup, hi_wh);
12204 + && (inode->i_nlink > 1
12205 + || (inode->i_state & I_LINKABLE))
12206 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12207 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12213 + * prepare the @file for writing.
12215 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12218 + aufs_bindex_t dbstart;
12219 + struct dentry *parent;
12220 + struct inode *inode;
12221 + struct super_block *sb;
12222 + struct file *h_file;
12223 + struct au_cp_generic cpg = {
12224 + .dentry = file->f_dentry,
12229 + .flags = AuCpup_DTIME
12232 + sb = cpg.dentry->d_sb;
12233 + inode = cpg.dentry->d_inode;
12234 + cpg.bsrc = au_fbstart(file);
12235 + err = au_test_ro(sb, cpg.bsrc, inode);
12236 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12237 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12242 + /* need to cpup or reopen */
12243 + parent = dget_parent(cpg.dentry);
12244 + di_write_lock_parent(parent);
12245 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12247 + if (unlikely(err < 0))
12251 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12252 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12253 + if (unlikely(err))
12257 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12258 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12259 + if (unlikely(err))
12262 + dbstart = au_dbstart(cpg.dentry);
12263 + if (dbstart <= cpg.bdst)
12264 + cpg.bsrc = cpg.bdst;
12266 + if (dbstart <= cpg.bdst /* just reopen */
12267 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12269 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12270 + if (IS_ERR(h_file))
12271 + err = PTR_ERR(h_file);
12273 + di_downgrade_lock(parent, AuLock_IR);
12274 + if (dbstart > cpg.bdst)
12275 + err = au_sio_cpup_simple(&cpg);
12277 + err = au_reopen_nondir(file);
12278 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12280 + } else { /* copyup as wh and reopen */
12282 + * since writable hfsplus branch is not supported,
12283 + * h_open_pre/post() are unnecessary.
12285 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12286 + di_downgrade_lock(parent, AuLock_IR);
12290 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12291 + goto out_dput; /* success */
12297 + di_downgrade_lock(parent, AuLock_IR);
12299 + di_read_unlock(parent, AuLock_IR);
12306 +/* ---------------------------------------------------------------------- */
12308 +int au_do_flush(struct file *file, fl_owner_t id,
12309 + int (*flush)(struct file *file, fl_owner_t id))
12312 + struct super_block *sb;
12313 + struct inode *inode;
12315 + inode = file_inode(file);
12316 + sb = inode->i_sb;
12317 + si_noflush_read_lock(sb);
12318 + fi_read_lock(file);
12319 + ii_read_lock_child(inode);
12321 + err = flush(file, id);
12322 + au_cpup_attr_timesizes(inode);
12324 + ii_read_unlock(inode);
12325 + fi_read_unlock(file);
12326 + si_read_unlock(sb);
12330 +/* ---------------------------------------------------------------------- */
12332 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12335 + struct au_pin pin;
12336 + struct au_finfo *finfo;
12337 + struct dentry *parent, *hi_wh;
12338 + struct inode *inode;
12339 + struct super_block *sb;
12340 + struct au_cp_generic cpg = {
12341 + .dentry = file->f_dentry,
12346 + .flags = AuCpup_DTIME
12349 + FiMustWriteLock(file);
12352 + finfo = au_fi(file);
12353 + sb = cpg.dentry->d_sb;
12354 + inode = cpg.dentry->d_inode;
12355 + cpg.bdst = au_ibstart(inode);
12356 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12359 + parent = dget_parent(cpg.dentry);
12360 + if (au_test_ro(sb, cpg.bdst, inode)) {
12361 + di_read_lock_parent(parent, !AuLock_IR);
12362 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12364 + di_read_unlock(parent, !AuLock_IR);
12365 + if (unlikely(err < 0))
12370 + di_read_lock_parent(parent, AuLock_IR);
12371 + hi_wh = au_hi_wh(inode, cpg.bdst);
12372 + if (!S_ISDIR(inode->i_mode)
12373 + && au_opt_test(au_mntflags(sb), PLINK)
12374 + && au_plink_test(inode)
12375 + && !d_unhashed(cpg.dentry)
12376 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12377 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12378 + if (unlikely(err))
12381 + /* always superio. */
12382 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12383 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12385 + err = au_sio_cpup_simple(&cpg);
12388 + } else if (hi_wh) {
12389 + /* already copied-up after unlink */
12390 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12391 + *need_reopen = 0;
12395 + di_read_unlock(parent, AuLock_IR);
12402 +static void au_do_refresh_dir(struct file *file)
12404 + aufs_bindex_t bindex, bend, new_bindex, brid;
12405 + struct au_hfile *p, tmp, *q;
12406 + struct au_finfo *finfo;
12407 + struct super_block *sb;
12408 + struct au_fidir *fidir;
12410 + FiMustWriteLock(file);
12412 + sb = file->f_dentry->d_sb;
12413 + finfo = au_fi(file);
12414 + fidir = finfo->fi_hdir;
12415 + AuDebugOn(!fidir);
12416 + p = fidir->fd_hfile + finfo->fi_btop;
12417 + brid = p->hf_br->br_id;
12418 + bend = fidir->fd_bbot;
12419 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12423 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12424 + if (new_bindex == bindex)
12426 + if (new_bindex < 0) {
12427 + au_set_h_fptr(file, bindex, NULL);
12431 + /* swap two lower inode, and loop again */
12432 + q = fidir->fd_hfile + new_bindex;
12436 + if (tmp.hf_file) {
12442 + p = fidir->fd_hfile;
12443 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
12444 + bend = au_sbend(sb);
12445 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12446 + finfo->fi_btop++, p++)
12447 + if (p->hf_file) {
12448 + if (file_inode(p->hf_file))
12450 + au_hfput(p, file);
12453 + bend = au_br_index(sb, brid);
12454 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12455 + finfo->fi_btop++, p++)
12457 + au_hfput(p, file);
12458 + bend = au_sbend(sb);
12461 + p = fidir->fd_hfile + bend;
12462 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12463 + fidir->fd_bbot--, p--)
12464 + if (p->hf_file) {
12465 + if (file_inode(p->hf_file))
12467 + au_hfput(p, file);
12469 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12473 + * after branch manipulating, refresh the file.
12475 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12477 + int err, need_reopen;
12478 + aufs_bindex_t bend, bindex;
12479 + struct dentry *dentry;
12480 + struct au_finfo *finfo;
12481 + struct au_hfile *hfile;
12483 + dentry = file->f_dentry;
12484 + finfo = au_fi(file);
12485 + if (!finfo->fi_hdir) {
12486 + hfile = &finfo->fi_htop;
12487 + AuDebugOn(!hfile->hf_file);
12488 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12489 + AuDebugOn(bindex < 0);
12490 + if (bindex != finfo->fi_btop)
12491 + au_set_fbstart(file, bindex);
12493 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12494 + if (unlikely(err))
12496 + au_do_refresh_dir(file);
12501 + if (!au_test_mmapped(file))
12502 + err = au_file_refresh_by_inode(file, &need_reopen);
12503 + if (!err && need_reopen && !d_unlinked(dentry))
12504 + err = reopen(file);
12506 + au_update_figen(file);
12507 + goto out; /* success */
12510 + /* error, close all lower files */
12511 + if (finfo->fi_hdir) {
12512 + bend = au_fbend_dir(file);
12513 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12514 + au_set_h_fptr(file, bindex, NULL);
12521 +/* common function to regular file and dir */
12522 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12526 + unsigned int sigen, figen;
12527 + aufs_bindex_t bstart;
12528 + unsigned char pseudo_link;
12529 + struct dentry *dentry;
12530 + struct inode *inode;
12533 + dentry = file->f_dentry;
12534 + inode = dentry->d_inode;
12535 + sigen = au_sigen(dentry->d_sb);
12536 + fi_write_lock(file);
12537 + figen = au_figen(file);
12538 + di_write_lock_child(dentry);
12539 + bstart = au_dbstart(dentry);
12540 + pseudo_link = (bstart != au_ibstart(inode));
12541 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12543 + di_downgrade_lock(dentry, AuLock_IR);
12544 + fi_downgrade_lock(file);
12546 + goto out; /* success */
12549 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12550 + if (au_digen_test(dentry, sigen)) {
12551 + err = au_reval_dpath(dentry, sigen);
12552 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12556 + err = refresh_file(file, reopen);
12559 + di_downgrade_lock(dentry, AuLock_IR);
12560 + fi_downgrade_lock(file);
12563 + di_write_unlock(dentry);
12564 + fi_write_unlock(file);
12571 +/* ---------------------------------------------------------------------- */
12573 +/* cf. aufs_nopage() */
12574 +/* for madvise(2) */
12575 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12577 + unlock_page(page);
12581 +/* it will never be called, but necessary to support O_DIRECT */
12582 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
12583 + struct iov_iter *iter, loff_t offset)
12584 +{ BUG(); return 0; }
12587 + * it will never be called, but madvise and fadvise behaves differently
12588 + * when get_xip_mem is defined
12590 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
12591 + int create, void **kmem, unsigned long *pfn)
12592 +{ BUG(); return 0; }
12594 +/* they will never be called. */
12595 +#ifdef CONFIG_AUFS_DEBUG
12596 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12597 + loff_t pos, unsigned len, unsigned flags,
12598 + struct page **pagep, void **fsdata)
12599 +{ AuUnsupport(); return 0; }
12600 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12601 + loff_t pos, unsigned len, unsigned copied,
12602 + struct page *page, void *fsdata)
12603 +{ AuUnsupport(); return 0; }
12604 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12605 +{ AuUnsupport(); return 0; }
12607 +static int aufs_set_page_dirty(struct page *page)
12608 +{ AuUnsupport(); return 0; }
12609 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12610 + unsigned int length)
12611 +{ AuUnsupport(); }
12612 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12613 +{ AuUnsupport(); return 0; }
12614 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12615 + struct page *page, enum migrate_mode mode)
12616 +{ AuUnsupport(); return 0; }
12617 +static int aufs_launder_page(struct page *page)
12618 +{ AuUnsupport(); return 0; }
12619 +static int aufs_is_partially_uptodate(struct page *page,
12620 + unsigned long from,
12621 + unsigned long count)
12622 +{ AuUnsupport(); return 0; }
12623 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12625 +{ AuUnsupport(); }
12626 +static int aufs_error_remove_page(struct address_space *mapping,
12627 + struct page *page)
12628 +{ AuUnsupport(); return 0; }
12629 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12631 +{ AuUnsupport(); return 0; }
12632 +static void aufs_swap_deactivate(struct file *file)
12633 +{ AuUnsupport(); }
12634 +#endif /* CONFIG_AUFS_DEBUG */
12636 +const struct address_space_operations aufs_aop = {
12637 + .readpage = aufs_readpage,
12638 + .direct_IO = aufs_direct_IO,
12639 + .get_xip_mem = aufs_get_xip_mem,
12640 +#ifdef CONFIG_AUFS_DEBUG
12641 + .writepage = aufs_writepage,
12642 + /* no writepages, because of writepage */
12643 + .set_page_dirty = aufs_set_page_dirty,
12644 + /* no readpages, because of readpage */
12645 + .write_begin = aufs_write_begin,
12646 + .write_end = aufs_write_end,
12647 + /* no bmap, no block device */
12648 + .invalidatepage = aufs_invalidatepage,
12649 + .releasepage = aufs_releasepage,
12650 + .migratepage = aufs_migratepage,
12651 + .launder_page = aufs_launder_page,
12652 + .is_partially_uptodate = aufs_is_partially_uptodate,
12653 + .is_dirty_writeback = aufs_is_dirty_writeback,
12654 + .error_remove_page = aufs_error_remove_page,
12655 + .swap_activate = aufs_swap_activate,
12656 + .swap_deactivate = aufs_swap_deactivate
12657 +#endif /* CONFIG_AUFS_DEBUG */
12659 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12660 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12661 +++ linux/fs/aufs/file.h 2015-01-25 13:00:38.631047076 +0100
12664 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12666 + * This program, aufs is free software; you can redistribute it and/or modify
12667 + * it under the terms of the GNU General Public License as published by
12668 + * the Free Software Foundation; either version 2 of the License, or
12669 + * (at your option) any later version.
12671 + * This program is distributed in the hope that it will be useful,
12672 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12673 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12674 + * GNU General Public License for more details.
12676 + * You should have received a copy of the GNU General Public License
12677 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12681 + * file operations
12684 +#ifndef __AUFS_FILE_H__
12685 +#define __AUFS_FILE_H__
12689 +#include <linux/file.h>
12690 +#include <linux/fs.h>
12691 +#include <linux/poll.h>
12692 +#include "rwsem.h"
12696 + struct file *hf_file;
12697 + struct au_branch *hf_br;
12702 + aufs_bindex_t fd_bbot;
12703 + aufs_bindex_t fd_nent;
12704 + struct au_vdir *fd_vdir_cache;
12705 + struct au_hfile fd_hfile[];
12708 +static inline int au_fidir_sz(int nent)
12710 + AuDebugOn(nent < 0);
12711 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
12715 + atomic_t fi_generation;
12717 + struct au_rwsem fi_rwsem;
12718 + aufs_bindex_t fi_btop;
12720 + /* do not union them */
12721 + struct { /* for non-dir */
12722 + struct au_hfile fi_htop;
12723 + atomic_t fi_mmapped;
12725 + struct au_fidir *fi_hdir; /* for dir only */
12727 + struct hlist_node fi_hlist;
12728 + struct file *fi_file; /* very ugly */
12729 +} ____cacheline_aligned_in_smp;
12731 +/* ---------------------------------------------------------------------- */
12734 +extern const struct address_space_operations aufs_aop;
12735 +unsigned int au_file_roflags(unsigned int flags);
12736 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12737 + struct file *file, int force_wr);
12738 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
12739 + struct au_fidir *fidir);
12740 +int au_reopen_nondir(struct file *file);
12742 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
12743 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12745 +int au_do_flush(struct file *file, fl_owner_t id,
12746 + int (*flush)(struct file *file, fl_owner_t id));
12749 +#ifdef CONFIG_AUFS_POLL
12750 +unsigned int aufs_poll(struct file *file, poll_table *wait);
12753 +#ifdef CONFIG_AUFS_BR_HFSPLUS
12755 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
12757 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12758 + struct file *h_file);
12760 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
12761 + aufs_bindex_t bindex, int force_wr)
12762 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
12763 + struct file *h_file);
12767 +extern const struct file_operations aufs_file_fop;
12768 +int au_do_open_nondir(struct file *file, int flags);
12769 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
12772 +void au_hfput(struct au_hfile *hf, struct file *file);
12773 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
12774 + struct file *h_file);
12776 +void au_update_figen(struct file *file);
12777 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
12778 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
12780 +void au_fi_init_once(void *_fi);
12781 +void au_finfo_fin(struct file *file);
12782 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
12785 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
12786 +#ifdef CONFIG_COMPAT
12787 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
12788 + unsigned long arg);
12789 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
12790 + unsigned long arg);
12793 +/* ---------------------------------------------------------------------- */
12795 +static inline struct au_finfo *au_fi(struct file *file)
12797 + return file->private_data;
12800 +/* ---------------------------------------------------------------------- */
12803 + * fi_read_lock, fi_write_lock,
12804 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
12806 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
12808 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
12809 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
12810 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
12812 +/* ---------------------------------------------------------------------- */
12814 +/* todo: hard/soft set? */
12815 +static inline aufs_bindex_t au_fbstart(struct file *file)
12817 + FiMustAnyLock(file);
12818 + return au_fi(file)->fi_btop;
12821 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
12823 + FiMustAnyLock(file);
12824 + AuDebugOn(!au_fi(file)->fi_hdir);
12825 + return au_fi(file)->fi_hdir->fd_bbot;
12828 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
12830 + FiMustAnyLock(file);
12831 + AuDebugOn(!au_fi(file)->fi_hdir);
12832 + return au_fi(file)->fi_hdir->fd_vdir_cache;
12835 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
12837 + FiMustWriteLock(file);
12838 + au_fi(file)->fi_btop = bindex;
12841 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
12843 + FiMustWriteLock(file);
12844 + AuDebugOn(!au_fi(file)->fi_hdir);
12845 + au_fi(file)->fi_hdir->fd_bbot = bindex;
12848 +static inline void au_set_fvdir_cache(struct file *file,
12849 + struct au_vdir *vdir_cache)
12851 + FiMustWriteLock(file);
12852 + AuDebugOn(!au_fi(file)->fi_hdir);
12853 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
12856 +static inline struct file *au_hf_top(struct file *file)
12858 + FiMustAnyLock(file);
12859 + AuDebugOn(au_fi(file)->fi_hdir);
12860 + return au_fi(file)->fi_htop.hf_file;
12863 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
12865 + FiMustAnyLock(file);
12866 + AuDebugOn(!au_fi(file)->fi_hdir);
12867 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
12870 +/* todo: memory barrier? */
12871 +static inline unsigned int au_figen(struct file *f)
12873 + return atomic_read(&au_fi(f)->fi_generation);
12876 +static inline void au_set_mmapped(struct file *f)
12878 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
12880 + pr_warn("fi_mmapped wrapped around\n");
12881 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
12885 +static inline void au_unset_mmapped(struct file *f)
12887 + atomic_dec(&au_fi(f)->fi_mmapped);
12890 +static inline int au_test_mmapped(struct file *f)
12892 + return atomic_read(&au_fi(f)->fi_mmapped);
12895 +/* customize vma->vm_file */
12897 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
12898 + struct file *file)
12902 + f = vma->vm_file;
12904 + vma->vm_file = file;
12909 +#define AuDbgVmRegion(file, vma) do {} while (0)
12911 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12912 + struct file *file)
12914 + au_do_vm_file_reset(vma, file);
12917 +#define AuDbgVmRegion(file, vma) \
12918 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
12920 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12921 + struct file *file)
12925 + au_do_vm_file_reset(vma, file);
12926 + f = vma->vm_region->vm_file;
12928 + vma->vm_region->vm_file = file;
12931 +#endif /* CONFIG_MMU */
12933 +/* handle vma->vm_prfile */
12934 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
12935 + struct file *file)
12938 + vma->vm_prfile = file;
12939 +#ifndef CONFIG_MMU
12941 + vma->vm_region->vm_prfile = file;
12945 +#endif /* __KERNEL__ */
12946 +#endif /* __AUFS_FILE_H__ */
12947 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
12948 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
12949 +++ linux/fs/aufs/finfo.c 2015-01-25 13:00:38.631047076 +0100
12952 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12954 + * This program, aufs is free software; you can redistribute it and/or modify
12955 + * it under the terms of the GNU General Public License as published by
12956 + * the Free Software Foundation; either version 2 of the License, or
12957 + * (at your option) any later version.
12959 + * This program is distributed in the hope that it will be useful,
12960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12962 + * GNU General Public License for more details.
12964 + * You should have received a copy of the GNU General Public License
12965 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12969 + * file private data
12974 +void au_hfput(struct au_hfile *hf, struct file *file)
12976 + /* todo: direct access f_flags */
12977 + if (vfsub_file_flags(file) & __FMODE_EXEC)
12978 + allow_write_access(hf->hf_file);
12979 + fput(hf->hf_file);
12980 + hf->hf_file = NULL;
12981 + atomic_dec(&hf->hf_br->br_count);
12982 + hf->hf_br = NULL;
12985 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
12987 + struct au_finfo *finfo = au_fi(file);
12988 + struct au_hfile *hf;
12989 + struct au_fidir *fidir;
12991 + fidir = finfo->fi_hdir;
12993 + AuDebugOn(finfo->fi_btop != bindex);
12994 + hf = &finfo->fi_htop;
12996 + hf = fidir->fd_hfile + bindex;
12998 + if (hf && hf->hf_file)
12999 + au_hfput(hf, file);
13001 + FiMustWriteLock(file);
13002 + hf->hf_file = val;
13003 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
13007 +void au_update_figen(struct file *file)
13009 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
13010 + /* smp_mb(); */ /* atomic_set */
13013 +/* ---------------------------------------------------------------------- */
13015 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13017 + struct au_fidir *fidir;
13020 + nbr = au_sbend(sb) + 1;
13022 + nbr = 2; /* initial allocate for 2 branches */
13023 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13025 + fidir->fd_bbot = -1;
13026 + fidir->fd_nent = nbr;
13027 + fidir->fd_vdir_cache = NULL;
13033 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13036 + struct au_fidir *fidir, *p;
13038 + AuRwMustWriteLock(&finfo->fi_rwsem);
13039 + fidir = finfo->fi_hdir;
13040 + AuDebugOn(!fidir);
13043 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13046 + p->fd_nent = nbr;
13047 + finfo->fi_hdir = p;
13054 +/* ---------------------------------------------------------------------- */
13056 +void au_finfo_fin(struct file *file)
13058 + struct au_finfo *finfo;
13060 + au_nfiles_dec(file->f_dentry->d_sb);
13062 + finfo = au_fi(file);
13063 + AuDebugOn(finfo->fi_hdir);
13064 + AuRwDestroy(&finfo->fi_rwsem);
13065 + au_cache_free_finfo(finfo);
13068 +void au_fi_init_once(void *_finfo)
13070 + struct au_finfo *finfo = _finfo;
13071 + static struct lock_class_key aufs_fi;
13073 + au_rw_init(&finfo->fi_rwsem);
13074 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
13077 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13080 + struct au_finfo *finfo;
13081 + struct dentry *dentry;
13084 + dentry = file->f_dentry;
13085 + finfo = au_cache_alloc_finfo();
13086 + if (unlikely(!finfo))
13090 + au_nfiles_inc(dentry->d_sb);
13091 + /* verbose coding for lock class name */
13093 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
13095 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
13096 + au_rw_write_lock(&finfo->fi_rwsem);
13097 + finfo->fi_btop = -1;
13098 + finfo->fi_hdir = fidir;
13099 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13100 + /* smp_mb(); */ /* atomic_set */
13102 + file->private_data = finfo;
13107 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13108 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13109 +++ linux/fs/aufs/f_op.c 2015-01-25 13:00:38.631047076 +0100
13112 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13114 + * This program, aufs is free software; you can redistribute it and/or modify
13115 + * it under the terms of the GNU General Public License as published by
13116 + * the Free Software Foundation; either version 2 of the License, or
13117 + * (at your option) any later version.
13119 + * This program is distributed in the hope that it will be useful,
13120 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13121 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13122 + * GNU General Public License for more details.
13124 + * You should have received a copy of the GNU General Public License
13125 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13129 + * file and vm operations
13132 +#include <linux/aio.h>
13133 +#include <linux/fs_stack.h>
13134 +#include <linux/mman.h>
13135 +#include <linux/security.h>
13138 +int au_do_open_nondir(struct file *file, int flags)
13141 + aufs_bindex_t bindex;
13142 + struct file *h_file;
13143 + struct dentry *dentry;
13144 + struct au_finfo *finfo;
13145 + struct inode *h_inode;
13147 + FiMustWriteLock(file);
13150 + dentry = file->f_dentry;
13151 + finfo = au_fi(file);
13152 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13153 + atomic_set(&finfo->fi_mmapped, 0);
13154 + bindex = au_dbstart(dentry);
13155 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13156 + if (IS_ERR(h_file))
13157 + err = PTR_ERR(h_file);
13159 + if ((flags & __O_TMPFILE)
13160 + && !(flags & O_EXCL)) {
13161 + h_inode = file_inode(h_file);
13162 + spin_lock(&h_inode->i_lock);
13163 + h_inode->i_state |= I_LINKABLE;
13164 + spin_unlock(&h_inode->i_lock);
13166 + au_set_fbstart(file, bindex);
13167 + au_set_h_fptr(file, bindex, h_file);
13168 + au_update_figen(file);
13169 + /* todo: necessary? */
13170 + /* file->f_ra = h_file->f_ra; */
13176 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13177 + struct file *file)
13180 + struct super_block *sb;
13182 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13183 + file, vfsub_file_flags(file), file->f_mode);
13185 + sb = file->f_dentry->d_sb;
13186 + si_read_lock(sb, AuLock_FLUSH);
13187 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
13188 + si_read_unlock(sb);
13192 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13194 + struct au_finfo *finfo;
13195 + aufs_bindex_t bindex;
13197 + finfo = au_fi(file);
13198 + au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files);
13199 + bindex = finfo->fi_btop;
13201 + au_set_h_fptr(file, bindex, NULL);
13203 + au_finfo_fin(file);
13207 +/* ---------------------------------------------------------------------- */
13209 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13212 + struct file *h_file;
13215 + h_file = au_hf_top(file);
13217 + err = vfsub_flush(h_file, id);
13221 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13223 + return au_do_flush(file, id, au_do_flush_nondir);
13226 +/* ---------------------------------------------------------------------- */
13228 + * read and write functions acquire [fdi]_rwsem once, but release before
13229 + * mmap_sem. This is because to stop a race condition between mmap(2).
13230 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13231 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13232 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13235 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13239 + struct dentry *dentry;
13240 + struct file *h_file;
13241 + struct super_block *sb;
13243 + dentry = file->f_dentry;
13244 + sb = dentry->d_sb;
13245 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13246 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13247 + if (unlikely(err))
13250 + h_file = au_hf_top(file);
13251 + get_file(h_file);
13252 + di_read_unlock(dentry, AuLock_IR);
13253 + fi_read_unlock(file);
13255 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13256 + err = vfsub_read_u(h_file, buf, count, ppos);
13257 + /* todo: necessary? */
13258 + /* file->f_ra = h_file->f_ra; */
13259 + /* update without lock, I don't think it a problem */
13260 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13264 + si_read_unlock(sb);
13269 + * todo: very ugly
13270 + * it locks both of i_mutex and si_rwsem for read in safe.
13271 + * if the plink maintenance mode continues forever (that is the problem),
13272 + * may loop forever.
13274 +static void au_mtx_and_read_lock(struct inode *inode)
13277 + struct super_block *sb = inode->i_sb;
13280 + mutex_lock(&inode->i_mutex);
13281 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13284 + mutex_unlock(&inode->i_mutex);
13285 + si_read_lock(sb, AuLock_NOPLMW);
13286 + si_read_unlock(sb);
13290 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13291 + size_t count, loff_t *ppos)
13295 + aufs_bindex_t bstart;
13296 + struct au_pin pin;
13297 + struct dentry *dentry;
13298 + struct inode *inode, *h_inode;
13299 + struct super_block *sb;
13300 + struct file *h_file;
13301 + char __user *buf = (char __user *)ubuf;
13303 + dentry = file->f_dentry;
13304 + sb = dentry->d_sb;
13305 + inode = dentry->d_inode;
13306 + au_mtx_and_read_lock(inode);
13308 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13309 + if (unlikely(err))
13312 + err = au_ready_to_write(file, -1, &pin);
13313 + di_downgrade_lock(dentry, AuLock_IR);
13314 + if (unlikely(err)) {
13315 + di_read_unlock(dentry, AuLock_IR);
13316 + fi_write_unlock(file);
13320 + bstart = au_fbstart(file);
13321 + h_file = au_hf_top(file);
13322 + get_file(h_file);
13323 + h_inode = file_inode(h_file);
13324 + blks = h_inode->i_blocks;
13326 + di_read_unlock(dentry, AuLock_IR);
13327 + fi_write_unlock(file);
13329 + err = vfsub_write_u(h_file, buf, count, ppos);
13330 + ii_write_lock_child(inode);
13331 + au_cpup_attr_timesizes(inode);
13332 + inode->i_mode = file_inode(h_file)->i_mode;
13333 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13335 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13336 + ii_write_unlock(inode);
13340 + si_read_unlock(sb);
13341 + mutex_unlock(&inode->i_mutex);
13345 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13346 + struct iov_iter *iov_iter)
13349 + struct file *file;
13350 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13351 + ssize_t (*aio)(struct kiocb *, const struct iovec *, unsigned long,
13354 + err = security_file_permission(h_file, rw);
13355 + if (unlikely(err))
13361 + if (rw == MAY_READ) {
13362 + iter = h_file->f_op->read_iter;
13363 + aio = h_file->f_op->aio_read;
13364 + } else if (rw == MAY_WRITE) {
13365 + iter = h_file->f_op->write_iter;
13366 + aio = h_file->f_op->aio_write;
13369 + file = kio->ki_filp;
13370 + kio->ki_filp = h_file;
13373 + err = iter(kio, iov_iter);
13375 + } else if (aio) {
13377 + err = aio(kio, iov_iter->iov, iov_iter->nr_segs, kio->ki_pos);
13380 + /* currently there is no such fs */
13382 + kio->ki_filp = file;
13388 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13391 + struct file *file, *h_file;
13392 + struct dentry *dentry;
13393 + struct super_block *sb;
13395 + file = kio->ki_filp;
13396 + dentry = file->f_dentry;
13397 + sb = dentry->d_sb;
13398 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13399 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13400 + if (unlikely(err))
13403 + h_file = au_hf_top(file);
13404 + get_file(h_file);
13405 + di_read_unlock(dentry, AuLock_IR);
13406 + fi_read_unlock(file);
13408 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13409 + /* todo: necessary? */
13410 + /* file->f_ra = h_file->f_ra; */
13411 + /* update without lock, I don't think it a problem */
13412 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13416 + si_read_unlock(sb);
13420 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13424 + aufs_bindex_t bstart;
13425 + struct au_pin pin;
13426 + struct dentry *dentry;
13427 + struct inode *inode, *h_inode;
13428 + struct file *file, *h_file;
13429 + struct super_block *sb;
13431 + file = kio->ki_filp;
13432 + dentry = file->f_dentry;
13433 + sb = dentry->d_sb;
13434 + inode = dentry->d_inode;
13435 + au_mtx_and_read_lock(inode);
13437 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13438 + if (unlikely(err))
13441 + err = au_ready_to_write(file, -1, &pin);
13442 + di_downgrade_lock(dentry, AuLock_IR);
13443 + if (unlikely(err)) {
13444 + di_read_unlock(dentry, AuLock_IR);
13445 + fi_write_unlock(file);
13449 + bstart = au_fbstart(file);
13450 + h_file = au_hf_top(file);
13451 + get_file(h_file);
13452 + h_inode = file_inode(h_file);
13453 + blks = h_inode->i_blocks;
13455 + di_read_unlock(dentry, AuLock_IR);
13456 + fi_write_unlock(file);
13458 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13459 + ii_write_lock_child(inode);
13460 + au_cpup_attr_timesizes(inode);
13461 + inode->i_mode = file_inode(h_file)->i_mode;
13462 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13464 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13465 + ii_write_unlock(inode);
13469 + si_read_unlock(sb);
13470 + mutex_unlock(&inode->i_mutex);
13474 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13475 + struct pipe_inode_info *pipe, size_t len,
13476 + unsigned int flags)
13479 + struct file *h_file;
13480 + struct dentry *dentry;
13481 + struct super_block *sb;
13483 + dentry = file->f_dentry;
13484 + sb = dentry->d_sb;
13485 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13486 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13487 + if (unlikely(err))
13491 + h_file = au_hf_top(file);
13492 + get_file(h_file);
13493 + if (au_test_loopback_kthread()) {
13494 + au_warn_loopback(h_file->f_dentry->d_sb);
13495 + if (file->f_mapping != h_file->f_mapping) {
13496 + file->f_mapping = h_file->f_mapping;
13497 + smp_mb(); /* unnecessary? */
13500 + di_read_unlock(dentry, AuLock_IR);
13501 + fi_read_unlock(file);
13503 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13504 + /* todo: necessasry? */
13505 + /* file->f_ra = h_file->f_ra; */
13506 + /* update without lock, I don't think it a problem */
13507 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13511 + si_read_unlock(sb);
13516 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13517 + size_t len, unsigned int flags)
13521 + aufs_bindex_t bstart;
13522 + struct au_pin pin;
13523 + struct dentry *dentry;
13524 + struct inode *inode, *h_inode;
13525 + struct super_block *sb;
13526 + struct file *h_file;
13528 + dentry = file->f_dentry;
13529 + sb = dentry->d_sb;
13530 + inode = dentry->d_inode;
13531 + au_mtx_and_read_lock(inode);
13533 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13534 + if (unlikely(err))
13537 + err = au_ready_to_write(file, -1, &pin);
13538 + di_downgrade_lock(dentry, AuLock_IR);
13539 + if (unlikely(err)) {
13540 + di_read_unlock(dentry, AuLock_IR);
13541 + fi_write_unlock(file);
13545 + bstart = au_fbstart(file);
13546 + h_file = au_hf_top(file);
13547 + get_file(h_file);
13548 + h_inode = file_inode(h_file);
13549 + blks = h_inode->i_blocks;
13551 + di_read_unlock(dentry, AuLock_IR);
13552 + fi_write_unlock(file);
13554 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13555 + ii_write_lock_child(inode);
13556 + au_cpup_attr_timesizes(inode);
13557 + inode->i_mode = file_inode(h_file)->i_mode;
13558 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13560 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13561 + ii_write_unlock(inode);
13565 + si_read_unlock(sb);
13566 + mutex_unlock(&inode->i_mutex);
13570 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13574 + struct au_pin pin;
13575 + struct dentry *dentry;
13576 + struct super_block *sb;
13577 + struct inode *inode;
13578 + struct file *h_file;
13580 + dentry = file->f_dentry;
13581 + sb = dentry->d_sb;
13582 + inode = dentry->d_inode;
13583 + au_mtx_and_read_lock(inode);
13585 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13586 + if (unlikely(err))
13589 + err = au_ready_to_write(file, -1, &pin);
13590 + di_downgrade_lock(dentry, AuLock_IR);
13591 + if (unlikely(err)) {
13592 + di_read_unlock(dentry, AuLock_IR);
13593 + fi_write_unlock(file);
13597 + h_file = au_hf_top(file);
13598 + get_file(h_file);
13600 + di_read_unlock(dentry, AuLock_IR);
13601 + fi_write_unlock(file);
13604 + err = do_fallocate(h_file, mode, offset, len);
13606 + ii_write_lock_child(inode);
13607 + au_cpup_attr_timesizes(inode);
13608 + inode->i_mode = file_inode(h_file)->i_mode;
13609 + ii_write_unlock(inode);
13613 + si_read_unlock(sb);
13614 + mutex_unlock(&inode->i_mutex);
13618 +/* ---------------------------------------------------------------------- */
13621 + * The locking order around current->mmap_sem.
13622 + * - in most and regular cases
13623 + * file I/O syscall -- aufs_read() or something
13624 + * -- si_rwsem for read -- mmap_sem
13625 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13627 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13628 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13629 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13630 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13631 + * It means that when aufs acquires si_rwsem for write, the process should never
13632 + * acquire mmap_sem.
13634 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13635 + * problem either since any directory is not able to be mmap-ed.
13636 + * The similar scenario is applied to aufs_readlink() too.
13639 +#if 0 /* stop calling security_file_mmap() */
13640 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13641 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13643 +static unsigned long au_arch_prot_conv(unsigned long flags)
13645 + /* currently ppc64 only */
13646 +#ifdef CONFIG_PPC64
13647 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13648 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13649 + return AuConv_VM_PROT(flags, SAO);
13651 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13656 +static unsigned long au_prot_conv(unsigned long flags)
13658 + return AuConv_VM_PROT(flags, READ)
13659 + | AuConv_VM_PROT(flags, WRITE)
13660 + | AuConv_VM_PROT(flags, EXEC)
13661 + | au_arch_prot_conv(flags);
13664 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13665 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13667 +static unsigned long au_flag_conv(unsigned long flags)
13669 + return AuConv_VM_MAP(flags, GROWSDOWN)
13670 + | AuConv_VM_MAP(flags, DENYWRITE)
13671 + | AuConv_VM_MAP(flags, LOCKED);
13675 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13678 + aufs_bindex_t bstart;
13679 + const unsigned char wlock
13680 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13681 + struct dentry *dentry;
13682 + struct super_block *sb;
13683 + struct file *h_file;
13684 + struct au_branch *br;
13685 + struct au_pin pin;
13687 + AuDbgVmRegion(file, vma);
13689 + dentry = file->f_dentry;
13690 + sb = dentry->d_sb;
13692 + si_read_lock(sb, AuLock_NOPLMW);
13693 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13694 + if (unlikely(err))
13698 + err = au_ready_to_write(file, -1, &pin);
13699 + di_write_unlock(dentry);
13700 + if (unlikely(err)) {
13701 + fi_write_unlock(file);
13706 + di_write_unlock(dentry);
13708 + bstart = au_fbstart(file);
13709 + br = au_sbr(sb, bstart);
13710 + h_file = au_hf_top(file);
13711 + get_file(h_file);
13712 + au_set_mmapped(file);
13713 + fi_write_unlock(file);
13716 + au_vm_file_reset(vma, h_file);
13718 + * we cannot call security_mmap_file() here since it may acquire
13719 + * mmap_sem or i_mutex.
13721 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13722 + * au_flag_conv(vma->vm_flags));
13725 + err = h_file->f_op->mmap(h_file, vma);
13726 + if (unlikely(err))
13729 + au_vm_prfile_set(vma, file);
13730 + /* update without lock, I don't think it a problem */
13731 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
13732 + goto out_fput; /* success */
13735 + au_unset_mmapped(file);
13736 + au_vm_file_reset(vma, file);
13741 + si_read_unlock(sb);
13747 +/* ---------------------------------------------------------------------- */
13749 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
13753 + struct au_pin pin;
13754 + struct dentry *dentry;
13755 + struct inode *inode;
13756 + struct file *h_file;
13757 + struct super_block *sb;
13759 + dentry = file->f_dentry;
13760 + inode = dentry->d_inode;
13761 + sb = dentry->d_sb;
13762 + mutex_lock(&inode->i_mutex);
13763 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13764 + if (unlikely(err))
13767 + err = 0; /* -EBADF; */ /* posix? */
13768 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13770 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13771 + if (unlikely(err))
13774 + err = au_ready_to_write(file, -1, &pin);
13775 + di_downgrade_lock(dentry, AuLock_IR);
13776 + if (unlikely(err))
13781 + h_file = au_hf_top(file);
13782 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
13783 + au_cpup_attr_timesizes(inode);
13786 + di_read_unlock(dentry, AuLock_IR);
13787 + fi_write_unlock(file);
13789 + si_read_unlock(sb);
13791 + mutex_unlock(&inode->i_mutex);
13795 +/* no one supports this operation, currently */
13797 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
13800 + struct au_pin pin;
13801 + struct dentry *dentry;
13802 + struct inode *inode;
13803 + struct file *file, *h_file;
13805 + file = kio->ki_filp;
13806 + dentry = file->f_dentry;
13807 + inode = dentry->d_inode;
13808 + au_mtx_and_read_lock(inode);
13810 + err = 0; /* -EBADF; */ /* posix? */
13811 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13813 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13814 + if (unlikely(err))
13817 + err = au_ready_to_write(file, -1, &pin);
13818 + di_downgrade_lock(dentry, AuLock_IR);
13819 + if (unlikely(err))
13824 + h_file = au_hf_top(file);
13825 + if (h_file->f_op->aio_fsync) {
13826 + struct mutex *h_mtx;
13828 + h_mtx = &file_inode(h_file)->i_mutex;
13829 + if (!is_sync_kiocb(kio)) {
13830 + get_file(h_file);
13833 + kio->ki_filp = h_file;
13834 + err = h_file->f_op->aio_fsync(kio, datasync);
13835 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13837 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
13839 + au_cpup_attr_timesizes(inode);
13840 + mutex_unlock(h_mtx);
13844 + di_read_unlock(dentry, AuLock_IR);
13845 + fi_write_unlock(file);
13847 + si_read_unlock(inode->sb);
13848 + mutex_unlock(&inode->i_mutex);
13853 +static int aufs_fasync(int fd, struct file *file, int flag)
13856 + struct file *h_file;
13857 + struct dentry *dentry;
13858 + struct super_block *sb;
13860 + dentry = file->f_dentry;
13861 + sb = dentry->d_sb;
13862 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13863 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13864 + if (unlikely(err))
13867 + h_file = au_hf_top(file);
13868 + if (h_file->f_op->fasync)
13869 + err = h_file->f_op->fasync(fd, h_file, flag);
13871 + di_read_unlock(dentry, AuLock_IR);
13872 + fi_read_unlock(file);
13875 + si_read_unlock(sb);
13879 +/* ---------------------------------------------------------------------- */
13881 +/* no one supports this operation, currently */
13883 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
13884 + size_t len, loff_t *pos , int more)
13889 +/* ---------------------------------------------------------------------- */
13891 +const struct file_operations aufs_file_fop = {
13892 + .owner = THIS_MODULE,
13894 + .llseek = default_llseek,
13896 + .read = aufs_read,
13897 + .write = aufs_write,
13898 + .read_iter = aufs_read_iter,
13899 + .write_iter = aufs_write_iter,
13901 +#ifdef CONFIG_AUFS_POLL
13902 + .poll = aufs_poll,
13904 + .unlocked_ioctl = aufs_ioctl_nondir,
13905 +#ifdef CONFIG_COMPAT
13906 + .compat_ioctl = aufs_compat_ioctl_nondir,
13908 + .mmap = aufs_mmap,
13909 + .open = aufs_open_nondir,
13910 + .flush = aufs_flush_nondir,
13911 + .release = aufs_release_nondir,
13912 + .fsync = aufs_fsync_nondir,
13913 + /* .aio_fsync = aufs_aio_fsync_nondir, */
13914 + .fasync = aufs_fasync,
13915 + /* .sendpage = aufs_sendpage, */
13916 + .splice_write = aufs_splice_write,
13917 + .splice_read = aufs_splice_read,
13919 + .aio_splice_write = aufs_aio_splice_write,
13920 + .aio_splice_read = aufs_aio_splice_read,
13922 + .fallocate = aufs_fallocate
13924 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
13925 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13926 +++ linux/fs/aufs/fstype.h 2015-01-25 13:00:38.631047076 +0100
13929 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13931 + * This program, aufs is free software; you can redistribute it and/or modify
13932 + * it under the terms of the GNU General Public License as published by
13933 + * the Free Software Foundation; either version 2 of the License, or
13934 + * (at your option) any later version.
13936 + * This program is distributed in the hope that it will be useful,
13937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13939 + * GNU General Public License for more details.
13941 + * You should have received a copy of the GNU General Public License
13942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13946 + * judging filesystem type
13949 +#ifndef __AUFS_FSTYPE_H__
13950 +#define __AUFS_FSTYPE_H__
13954 +#include <linux/fs.h>
13955 +#include <linux/magic.h>
13956 +#include <linux/romfs_fs.h>
13958 +static inline int au_test_aufs(struct super_block *sb)
13960 + return sb->s_magic == AUFS_SUPER_MAGIC;
13963 +static inline const char *au_sbtype(struct super_block *sb)
13965 + return sb->s_type->name;
13968 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
13970 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
13971 + return sb->s_magic == ROMFS_MAGIC;
13977 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
13979 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
13980 + return sb->s_magic == ISOFS_SUPER_MAGIC;
13986 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
13988 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
13989 + return sb->s_magic == CRAMFS_MAGIC;
13994 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
13996 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
13997 + return sb->s_magic == NFS_SUPER_MAGIC;
14003 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14005 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
14006 + return sb->s_magic == FUSE_SUPER_MAGIC;
14012 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14014 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
14015 + return sb->s_magic == XFS_SB_MAGIC;
14021 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14023 +#ifdef CONFIG_TMPFS
14024 + return sb->s_magic == TMPFS_MAGIC;
14030 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14032 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
14033 + return !strcmp(au_sbtype(sb), "ecryptfs");
14039 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
14041 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
14042 + return sb->s_magic == OCFS2_SUPER_MAGIC;
14048 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
14050 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
14051 + return sb->s_magic == DLMFS_MAGIC;
14057 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
14059 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
14060 + return sb->s_magic == CODA_SUPER_MAGIC;
14066 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
14068 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
14069 + return sb->s_magic == V9FS_MAGIC;
14075 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
14077 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
14078 + return sb->s_magic == EXT4_SUPER_MAGIC;
14084 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
14086 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
14087 + return !strcmp(au_sbtype(sb), "sysv");
14093 +static inline int au_test_ramfs(struct super_block *sb)
14095 + return sb->s_magic == RAMFS_MAGIC;
14098 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14100 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
14101 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14107 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14109 +#ifdef CONFIG_PROC_FS
14110 + return sb->s_magic == PROC_SUPER_MAGIC;
14116 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14118 +#ifdef CONFIG_SYSFS
14119 + return sb->s_magic == SYSFS_MAGIC;
14125 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14127 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
14128 + return sb->s_magic == CONFIGFS_MAGIC;
14134 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14136 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
14137 + return sb->s_magic == MINIX3_SUPER_MAGIC
14138 + || sb->s_magic == MINIX2_SUPER_MAGIC
14139 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14140 + || sb->s_magic == MINIX_SUPER_MAGIC
14141 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14147 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
14149 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
14150 + return sb->s_magic == CIFS_MAGIC_NUMBER;
14156 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14158 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14159 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14165 +static inline int au_test_msdos(struct super_block *sb)
14167 + return au_test_fat(sb);
14170 +static inline int au_test_vfat(struct super_block *sb)
14172 + return au_test_fat(sb);
14175 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14177 +#ifdef CONFIG_SECURITYFS
14178 + return sb->s_magic == SECURITYFS_MAGIC;
14184 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14186 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14187 + return sb->s_magic == SQUASHFS_MAGIC;
14193 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14195 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14196 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14202 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14204 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14205 + return sb->s_magic == XENFS_SUPER_MAGIC;
14211 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14213 +#ifdef CONFIG_DEBUG_FS
14214 + return sb->s_magic == DEBUGFS_MAGIC;
14220 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14222 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14223 + return sb->s_magic == NILFS_SUPER_MAGIC;
14229 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14231 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14232 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14238 +/* ---------------------------------------------------------------------- */
14240 + * they can't be an aufs branch.
14242 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14245 +#ifndef CONFIG_AUFS_BR_RAMFS
14246 + au_test_ramfs(sb) ||
14248 + au_test_procfs(sb)
14249 + || au_test_sysfs(sb)
14250 + || au_test_configfs(sb)
14251 + || au_test_debugfs(sb)
14252 + || au_test_securityfs(sb)
14253 + || au_test_xenfs(sb)
14254 + || au_test_ecryptfs(sb)
14255 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14256 + || au_test_aufs(sb); /* will be supported in next version */
14259 +static inline int au_test_fs_remote(struct super_block *sb)
14261 + return !au_test_tmpfs(sb)
14262 +#ifdef CONFIG_AUFS_BR_RAMFS
14263 + && !au_test_ramfs(sb)
14265 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14268 +/* ---------------------------------------------------------------------- */
14271 + * Note: these functions (below) are created after reading ->getattr() in all
14272 + * filesystems under linux/fs. it means we have to do so in every update...
14276 + * some filesystems require getattr to refresh the inode attributes before
14278 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14279 + * and leave the work for d_revalidate()
14281 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14283 + return au_test_nfs(sb)
14284 + || au_test_fuse(sb)
14285 + /* || au_test_ocfs2(sb) */ /* untested */
14286 + /* || au_test_btrfs(sb) */ /* untested */
14287 + /* || au_test_coda(sb) */ /* untested */
14288 + /* || au_test_v9fs(sb) */ /* untested */
14293 + * filesystems which don't maintain i_size or i_blocks.
14295 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14297 + return au_test_xfs(sb)
14298 + || au_test_btrfs(sb)
14299 + || au_test_ubifs(sb)
14300 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14301 + /* || au_test_ext4(sb) */ /* untested */
14302 + /* || au_test_ocfs2(sb) */ /* untested */
14303 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
14304 + /* || au_test_sysv(sb) */ /* untested */
14305 + /* || au_test_minix(sb) */ /* untested */
14310 + * filesystems which don't store the correct value in some of their inode
14313 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14315 + return au_test_fs_bad_iattr_size(sb)
14316 + /* || au_test_cifs(sb) */ /* untested */
14317 + || au_test_fat(sb)
14318 + || au_test_msdos(sb)
14319 + || au_test_vfat(sb);
14322 +/* they don't check i_nlink in link(2) */
14323 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14325 + return au_test_tmpfs(sb)
14326 +#ifdef CONFIG_AUFS_BR_RAMFS
14327 + || au_test_ramfs(sb)
14329 + || au_test_ubifs(sb)
14330 + || au_test_hfsplus(sb);
14334 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14336 +static inline int au_test_fs_notime(struct super_block *sb)
14338 + return au_test_nfs(sb)
14339 + || au_test_fuse(sb)
14340 + || au_test_ubifs(sb)
14341 + /* || au_test_cifs(sb) */ /* untested */
14346 + * filesystems which requires replacing i_mapping.
14348 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
14350 + return au_test_fuse(sb)
14351 + || au_test_ubifs(sb);
14354 +/* temporary support for i#1 in cramfs */
14355 +static inline int au_test_fs_unique_ino(struct inode *inode)
14357 + if (au_test_cramfs(inode->i_sb))
14358 + return inode->i_ino != 1;
14362 +/* ---------------------------------------------------------------------- */
14365 + * the filesystem where the xino files placed must support i/o after unlink and
14366 + * maintain i_size and i_blocks.
14368 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14370 + return au_test_fs_remote(sb)
14371 + || au_test_fs_bad_iattr_size(sb)
14372 + /* don't want unnecessary work for xino */
14373 + || au_test_aufs(sb)
14374 + || au_test_ecryptfs(sb)
14375 + || au_test_nilfs(sb);
14378 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14380 + return au_test_tmpfs(sb)
14381 + || au_test_ramfs(sb);
14385 + * test if the @sb is real-readonly.
14387 +static inline int au_test_fs_rr(struct super_block *sb)
14389 + return au_test_squashfs(sb)
14390 + || au_test_iso9660(sb)
14391 + || au_test_cramfs(sb)
14392 + || au_test_romfs(sb);
14395 +#endif /* __KERNEL__ */
14396 +#endif /* __AUFS_FSTYPE_H__ */
14397 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14398 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14399 +++ linux/fs/aufs/hfsnotify.c 2015-01-25 13:00:38.631047076 +0100
14402 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14404 + * This program, aufs is free software; you can redistribute it and/or modify
14405 + * it under the terms of the GNU General Public License as published by
14406 + * the Free Software Foundation; either version 2 of the License, or
14407 + * (at your option) any later version.
14409 + * This program is distributed in the hope that it will be useful,
14410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14412 + * GNU General Public License for more details.
14414 + * You should have received a copy of the GNU General Public License
14415 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14419 + * fsnotify for the lower directories
14424 +/* FS_IN_IGNORED is unnecessary */
14425 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14426 + | FS_CREATE | FS_EVENT_ON_CHILD);
14427 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14428 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14430 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14432 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14435 + au_cache_free_hnotify(hn);
14436 + smp_mb__before_atomic();
14437 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14438 + wake_up(&au_hfsn_wq);
14441 +static int au_hfsn_alloc(struct au_hinode *hinode)
14444 + struct au_hnotify *hn;
14445 + struct super_block *sb;
14446 + struct au_branch *br;
14447 + struct fsnotify_mark *mark;
14448 + aufs_bindex_t bindex;
14450 + hn = hinode->hi_notify;
14451 + sb = hn->hn_aufs_inode->i_sb;
14452 + bindex = au_br_index(sb, hinode->hi_id);
14453 + br = au_sbr(sb, bindex);
14454 + AuDebugOn(!br->br_hfsn);
14456 + mark = &hn->hn_mark;
14457 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14458 + mark->mask = AuHfsnMask;
14460 + * by udba rename or rmdir, aufs assign a new inode to the known
14461 + * h_inode, so specify 1 to allow dups.
14464 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14465 + /*mnt*/NULL, /*allow_dups*/1);
14466 + /* even if err */
14467 + fsnotify_put_mark(mark);
14473 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14475 + struct fsnotify_mark *mark;
14476 + unsigned long long ull;
14477 + struct fsnotify_group *group;
14479 + ull = atomic64_inc_return(&au_hfsn_ifree);
14482 + mark = &hn->hn_mark;
14483 + spin_lock(&mark->lock);
14484 + group = mark->group;
14485 + fsnotify_get_group(group);
14486 + spin_unlock(&mark->lock);
14488 + fsnotify_destroy_mark(mark, group);
14489 + fsnotify_put_group(group);
14492 + /* free hn by myself */
14496 +/* ---------------------------------------------------------------------- */
14498 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14500 + struct fsnotify_mark *mark;
14502 + mark = &hinode->hi_notify->hn_mark;
14503 + spin_lock(&mark->lock);
14505 + AuDebugOn(mark->mask & AuHfsnMask);
14506 + mark->mask |= AuHfsnMask;
14508 + AuDebugOn(!(mark->mask & AuHfsnMask));
14509 + mark->mask &= ~AuHfsnMask;
14511 + spin_unlock(&mark->lock);
14512 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14515 +/* ---------------------------------------------------------------------- */
14517 +/* #define AuDbgHnotify */
14518 +#ifdef AuDbgHnotify
14519 +static char *au_hfsn_name(u32 mask)
14521 +#ifdef CONFIG_AUFS_DEBUG
14522 +#define test_ret(flag) \
14524 + if (mask & flag) \
14527 + test_ret(FS_ACCESS);
14528 + test_ret(FS_MODIFY);
14529 + test_ret(FS_ATTRIB);
14530 + test_ret(FS_CLOSE_WRITE);
14531 + test_ret(FS_CLOSE_NOWRITE);
14532 + test_ret(FS_OPEN);
14533 + test_ret(FS_MOVED_FROM);
14534 + test_ret(FS_MOVED_TO);
14535 + test_ret(FS_CREATE);
14536 + test_ret(FS_DELETE);
14537 + test_ret(FS_DELETE_SELF);
14538 + test_ret(FS_MOVE_SELF);
14539 + test_ret(FS_UNMOUNT);
14540 + test_ret(FS_Q_OVERFLOW);
14541 + test_ret(FS_IN_IGNORED);
14542 + test_ret(FS_IN_ISDIR);
14543 + test_ret(FS_IN_ONESHOT);
14544 + test_ret(FS_EVENT_ON_CHILD);
14553 +/* ---------------------------------------------------------------------- */
14555 +static void au_hfsn_free_group(struct fsnotify_group *group)
14557 + struct au_br_hfsnotify *hfsn = group->private;
14563 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14564 + struct inode *inode,
14565 + struct fsnotify_mark *inode_mark,
14566 + struct fsnotify_mark *vfsmount_mark,
14567 + u32 mask, void *data, int data_type,
14568 + const unsigned char *file_name, u32 cookie)
14571 + struct au_hnotify *hnotify;
14572 + struct inode *h_dir, *h_inode;
14573 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14575 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14578 + /* if FS_UNMOUNT happens, there must be another bug */
14579 + AuDebugOn(mask & FS_UNMOUNT);
14580 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14585 +#ifdef AuDbgHnotify
14587 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14588 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14589 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14590 + h_dir->i_ino, mask, au_hfsn_name(mask),
14591 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14592 + /* WARN_ON(1); */
14597 + AuDebugOn(!inode_mark);
14598 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14599 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14605 +static struct fsnotify_ops au_hfsn_ops = {
14606 + .handle_event = au_hfsn_handle_event,
14607 + .free_group_priv = au_hfsn_free_group
14610 +/* ---------------------------------------------------------------------- */
14612 +static void au_hfsn_fin_br(struct au_branch *br)
14614 + struct au_br_hfsnotify *hfsn;
14616 + hfsn = br->br_hfsn;
14619 + fsnotify_put_group(hfsn->hfsn_group);
14624 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14627 + struct fsnotify_group *group;
14628 + struct au_br_hfsnotify *hfsn;
14631 + br->br_hfsn = NULL;
14632 + if (!au_br_hnotifyable(perm))
14636 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14637 + if (unlikely(!hfsn))
14641 + group = fsnotify_alloc_group(&au_hfsn_ops);
14642 + if (IS_ERR(group)) {
14643 + err = PTR_ERR(group);
14644 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14648 + group->private = hfsn;
14649 + hfsn->hfsn_group = group;
14650 + br->br_hfsn = hfsn;
14651 + goto out; /* success */
14659 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14664 + if (!br->br_hfsn)
14665 + err = au_hfsn_init_br(br, perm);
14670 +/* ---------------------------------------------------------------------- */
14672 +static void au_hfsn_fin(void)
14674 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14675 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14678 +const struct au_hnotify_op au_hnotify_op = {
14679 + .ctl = au_hfsn_ctl,
14680 + .alloc = au_hfsn_alloc,
14681 + .free = au_hfsn_free,
14683 + .fin = au_hfsn_fin,
14685 + .reset_br = au_hfsn_reset_br,
14686 + .fin_br = au_hfsn_fin_br,
14687 + .init_br = au_hfsn_init_br
14689 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14690 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14691 +++ linux/fs/aufs/hfsplus.c 2015-01-25 13:00:38.631047076 +0100
14694 + * Copyright (C) 2010-2014 Junjiro R. Okajima
14696 + * This program, aufs is free software; you can redistribute it and/or modify
14697 + * it under the terms of the GNU General Public License as published by
14698 + * the Free Software Foundation; either version 2 of the License, or
14699 + * (at your option) any later version.
14701 + * This program is distributed in the hope that it will be useful,
14702 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14703 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14704 + * GNU General Public License for more details.
14706 + * You should have received a copy of the GNU General Public License
14707 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14711 + * special support for filesystems which aqucires an inode mutex
14712 + * at final closing a file, eg, hfsplus.
14714 + * This trick is very simple and stupid, just to open the file before really
14715 + * neceeary open to tell hfsplus that this is not the final closing.
14716 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14717 + * and au_h_open_post() after releasing it.
14722 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14725 + struct file *h_file;
14726 + struct dentry *h_dentry;
14728 + h_dentry = au_h_dptr(dentry, bindex);
14729 + AuDebugOn(!h_dentry);
14730 + AuDebugOn(!h_dentry->d_inode);
14733 + if (au_test_hfsplus(h_dentry->d_sb)
14734 + && S_ISREG(h_dentry->d_inode->i_mode))
14735 + h_file = au_h_open(dentry, bindex,
14736 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14737 + /*file*/NULL, force_wr);
14741 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14742 + struct file *h_file)
14746 + au_sbr_put(dentry->d_sb, bindex);
14749 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14750 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14751 +++ linux/fs/aufs/hnotify.c 2015-01-25 13:00:38.631047076 +0100
14754 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14756 + * This program, aufs is free software; you can redistribute it and/or modify
14757 + * it under the terms of the GNU General Public License as published by
14758 + * the Free Software Foundation; either version 2 of the License, or
14759 + * (at your option) any later version.
14761 + * This program is distributed in the hope that it will be useful,
14762 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14763 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14764 + * GNU General Public License for more details.
14766 + * You should have received a copy of the GNU General Public License
14767 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14771 + * abstraction to notify the direct changes on lower directories
14776 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14779 + struct au_hnotify *hn;
14782 + hn = au_cache_alloc_hnotify();
14784 + hn->hn_aufs_inode = inode;
14785 + hinode->hi_notify = hn;
14786 + err = au_hnotify_op.alloc(hinode);
14788 + if (unlikely(err)) {
14789 + hinode->hi_notify = NULL;
14790 + au_cache_free_hnotify(hn);
14792 + * The upper dir was removed by udba, but the same named
14793 + * dir left. In this case, aufs assignes a new inode
14794 + * number and set the monitor again.
14795 + * For the lower dir, the old monitnor is still left.
14797 + if (err == -EEXIST)
14806 +void au_hn_free(struct au_hinode *hinode)
14808 + struct au_hnotify *hn;
14810 + hn = hinode->hi_notify;
14812 + hinode->hi_notify = NULL;
14813 + if (au_hnotify_op.free(hinode, hn))
14814 + au_cache_free_hnotify(hn);
14818 +/* ---------------------------------------------------------------------- */
14820 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14822 + if (hinode->hi_notify)
14823 + au_hnotify_op.ctl(hinode, do_set);
14826 +void au_hn_reset(struct inode *inode, unsigned int flags)
14828 + aufs_bindex_t bindex, bend;
14829 + struct inode *hi;
14830 + struct dentry *iwhdentry;
14832 + bend = au_ibend(inode);
14833 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14834 + hi = au_h_iptr(inode, bindex);
14838 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14839 + iwhdentry = au_hi_wh(inode, bindex);
14843 + au_set_h_iptr(inode, bindex, NULL, 0);
14844 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14845 + flags & ~AuHi_XINO);
14848 + /* mutex_unlock(&hi->i_mutex); */
14852 +/* ---------------------------------------------------------------------- */
14854 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14857 + aufs_bindex_t bindex, bend, bfound, bstart;
14858 + struct inode *h_i;
14861 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14862 + pr_warn("branch root dir was changed\n");
14867 + bend = au_ibend(inode);
14868 + bstart = au_ibstart(inode);
14869 +#if 0 /* reserved for future use */
14870 + if (bindex == bend) {
14871 + /* keep this ino in rename case */
14875 + for (bindex = bstart; bindex <= bend; bindex++)
14876 + if (au_h_iptr(inode, bindex) == h_inode) {
14883 + for (bindex = bstart; bindex <= bend; bindex++) {
14884 + h_i = au_h_iptr(inode, bindex);
14888 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14889 + /* ignore this error */
14890 + /* bad action? */
14893 + /* children inode number will be broken */
14900 +static int hn_gen_tree(struct dentry *dentry)
14902 + int err, i, j, ndentry;
14903 + struct au_dcsub_pages dpages;
14904 + struct au_dpage *dpage;
14905 + struct dentry **dentries;
14907 + err = au_dpages_init(&dpages, GFP_NOFS);
14908 + if (unlikely(err))
14910 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14911 + if (unlikely(err))
14914 + for (i = 0; i < dpages.ndpage; i++) {
14915 + dpage = dpages.dpages + i;
14916 + dentries = dpage->dentries;
14917 + ndentry = dpage->ndentry;
14918 + for (j = 0; j < ndentry; j++) {
14919 + struct dentry *d;
14927 + /* todo: reset children xino?
14928 + cached children only? */
14929 + au_iigen_dec(d->d_inode);
14934 + au_dpages_free(&dpages);
14937 + /* discard children */
14938 + dentry_unhash(dentry);
14946 + * return 0 if processed.
14948 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14949 + const unsigned int isdir)
14952 + struct dentry *d;
14953 + struct qstr *dname;
14956 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14957 + pr_warn("branch root dir was changed\n");
14963 + AuDebugOn(!name);
14964 + au_iigen_dec(inode);
14965 + spin_lock(&inode->i_lock);
14966 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
14967 + spin_lock(&d->d_lock);
14968 + dname = &d->d_name;
14969 + if (dname->len != nlen
14970 + && memcmp(dname->name, name, nlen)) {
14971 + spin_unlock(&d->d_lock);
14976 + spin_unlock(&d->d_lock);
14979 + spin_unlock(&inode->i_lock);
14981 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14982 + d = d_find_any_alias(inode);
14984 + au_iigen_dec(inode);
14988 + spin_lock(&d->d_lock);
14989 + dname = &d->d_name;
14990 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14991 + spin_unlock(&d->d_lock);
14992 + err = hn_gen_tree(d);
14993 + spin_lock(&d->d_lock);
14995 + spin_unlock(&d->d_lock);
15004 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15007 + struct inode *inode;
15009 + inode = dentry->d_inode;
15010 + if (IS_ROOT(dentry)
15011 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
15013 + pr_warn("branch root dir was changed\n");
15019 + au_digen_dec(dentry);
15021 + au_iigen_dec(inode);
15023 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15025 + err = hn_gen_tree(dentry);
15032 +/* ---------------------------------------------------------------------- */
15034 +/* hnotify job flags */
15035 +#define AuHnJob_XINO0 1
15036 +#define AuHnJob_GEN (1 << 1)
15037 +#define AuHnJob_DIRENT (1 << 2)
15038 +#define AuHnJob_ISDIR (1 << 3)
15039 +#define AuHnJob_TRYXINO0 (1 << 4)
15040 +#define AuHnJob_MNTPNT (1 << 5)
15041 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15042 +#define au_fset_hnjob(flags, name) \
15043 + do { (flags) |= AuHnJob_##name; } while (0)
15044 +#define au_fclr_hnjob(flags, name) \
15045 + do { (flags) &= ~AuHnJob_##name; } while (0)
15053 +struct au_hnotify_args {
15054 + struct inode *h_dir, *dir, *h_child_inode;
15056 + unsigned int flags[AuHnLast];
15057 + unsigned int h_child_nlen;
15058 + char h_child_name[];
15061 +struct hn_job_args {
15062 + unsigned int flags;
15063 + struct inode *inode, *h_inode, *dir, *h_dir;
15064 + struct dentry *dentry;
15069 +static int hn_job(struct hn_job_args *a)
15071 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15075 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15076 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15078 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15081 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
15082 + if (!a->h_inode->i_nlink
15083 + && !(a->h_inode->i_state & I_LINKABLE))
15084 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15085 + mutex_unlock(&a->h_inode->i_mutex);
15088 + /* make the generation obsolete */
15089 + if (au_ftest_hnjob(a->flags, GEN)) {
15092 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15094 + if (e && a->dentry)
15095 + hn_gen_by_name(a->dentry, isdir);
15096 + /* ignore this error */
15099 + /* make dir entries obsolete */
15100 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15101 + struct au_vdir *vdir;
15103 + vdir = au_ivdir(a->inode);
15105 + vdir->vd_jiffy = 0;
15106 + /* IMustLock(a->inode); */
15107 + /* a->inode->i_version++; */
15110 + /* can do nothing but warn */
15111 + if (au_ftest_hnjob(a->flags, MNTPNT)
15113 + && d_mountpoint(a->dentry))
15114 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15119 +/* ---------------------------------------------------------------------- */
15121 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15122 + struct inode *dir)
15124 + struct dentry *dentry, *d, *parent;
15125 + struct qstr *dname;
15127 + parent = d_find_any_alias(dir);
15132 + spin_lock(&parent->d_lock);
15133 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15134 + /* AuDbg("%pd\n", d); */
15135 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15136 + dname = &d->d_name;
15137 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15138 + goto cont_unlock;
15142 + goto cont_unlock;
15143 + if (au_dcount(d) > 0) {
15144 + dentry = dget_dlock(d);
15145 + spin_unlock(&d->d_lock);
15150 + spin_unlock(&d->d_lock);
15152 + spin_unlock(&parent->d_lock);
15156 + di_write_lock_child(dentry);
15161 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15162 + aufs_bindex_t bindex, ino_t h_ino)
15164 + struct inode *inode;
15169 + err = au_xino_read(sb, bindex, h_ino, &ino);
15171 + inode = ilookup(sb, ino);
15175 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15176 + pr_warn("wrong root branch\n");
15182 + ii_write_lock_child(inode);
15188 +static void au_hn_bh(void *_args)
15190 + struct au_hnotify_args *a = _args;
15191 + struct super_block *sb;
15192 + aufs_bindex_t bindex, bend, bfound;
15193 + unsigned char xino, try_iput;
15195 + struct inode *inode;
15197 + struct hn_job_args args;
15198 + struct dentry *dentry;
15199 + struct au_sbinfo *sbinfo;
15201 + AuDebugOn(!_args);
15202 + AuDebugOn(!a->h_dir);
15203 + AuDebugOn(!a->dir);
15204 + AuDebugOn(!a->mask);
15205 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15206 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15207 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15212 + * do not lock a->dir->i_mutex here
15213 + * because of d_revalidate() may cause a deadlock.
15215 + sb = a->dir->i_sb;
15217 + sbinfo = au_sbi(sb);
15218 + AuDebugOn(!sbinfo);
15219 + si_write_lock(sb, AuLock_NOPLMW);
15221 + ii_read_lock_parent(a->dir);
15223 + bend = au_ibend(a->dir);
15224 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
15225 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15229 + ii_read_unlock(a->dir);
15230 + if (unlikely(bfound < 0))
15233 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15235 + if (a->h_child_inode)
15236 + h_ino = a->h_child_inode->i_ino;
15238 + if (a->h_child_nlen
15239 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15240 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15241 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15245 + inode = dentry->d_inode;
15246 + if (xino && !inode && h_ino
15247 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15248 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15249 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15250 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15254 + args.flags = a->flags[AuHn_CHILD];
15255 + args.dentry = dentry;
15256 + args.inode = inode;
15257 + args.h_inode = a->h_child_inode;
15258 + args.dir = a->dir;
15259 + args.h_dir = a->h_dir;
15260 + args.h_name = a->h_child_name;
15261 + args.h_nlen = a->h_child_nlen;
15262 + err = hn_job(&args);
15264 + if (au_di(dentry))
15265 + di_write_unlock(dentry);
15268 + if (inode && try_iput) {
15269 + ii_write_unlock(inode);
15273 + ii_write_lock_parent(a->dir);
15274 + args.flags = a->flags[AuHn_PARENT];
15275 + args.dentry = NULL;
15276 + args.inode = a->dir;
15277 + args.h_inode = a->h_dir;
15279 + args.h_dir = NULL;
15280 + args.h_name = NULL;
15282 + err = hn_job(&args);
15283 + ii_write_unlock(a->dir);
15286 + iput(a->h_child_inode);
15289 + si_write_unlock(sb);
15290 + au_nwt_done(&sbinfo->si_nowait);
15294 +/* ---------------------------------------------------------------------- */
15296 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15297 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15300 + unsigned int flags[AuHnLast], f;
15301 + unsigned char isdir, isroot, wh;
15302 + struct inode *dir;
15303 + struct au_hnotify_args *args;
15304 + char *p, *h_child_name;
15307 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15308 + dir = igrab(hnotify->hn_aufs_inode);
15312 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15314 + h_child_name = (void *)h_child_qstr->name;
15315 + len = h_child_qstr->len;
15316 + if (h_child_name) {
15317 + if (len > AUFS_WH_PFX_LEN
15318 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15319 + h_child_name += AUFS_WH_PFX_LEN;
15320 + len -= AUFS_WH_PFX_LEN;
15326 + if (h_child_inode)
15327 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15328 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15329 + flags[AuHn_CHILD] = 0;
15331 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15332 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15333 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15334 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15335 + case FS_MOVED_FROM:
15336 + case FS_MOVED_TO:
15337 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15338 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15341 + AuDebugOn(!h_child_name);
15346 + * aufs never be able to get this child inode.
15347 + * revalidation should be in d_revalidate()
15348 + * by checking i_nlink, i_generation or d_unhashed().
15350 + AuDebugOn(!h_child_name);
15351 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15352 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15360 + h_child_inode = NULL;
15363 + /* iput() and kfree() will be called in au_hnotify() */
15364 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15365 + if (unlikely(!args)) {
15366 + AuErr1("no memory\n");
15370 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15371 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15372 + args->mask = mask;
15374 + args->h_dir = igrab(h_dir);
15375 + if (h_child_inode)
15376 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15377 + args->h_child_inode = h_child_inode;
15378 + args->h_child_nlen = len;
15380 + p = (void *)args;
15381 + p += sizeof(*args);
15382 + memcpy(p, h_child_name, len);
15386 + /* NFS fires the event for silly-renamed one from kworker */
15388 + if (!dir->i_nlink
15389 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15391 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15392 + if (unlikely(err)) {
15393 + pr_err("wkq %d\n", err);
15394 + iput(args->h_child_inode);
15395 + iput(args->h_dir);
15404 +/* ---------------------------------------------------------------------- */
15406 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15410 + AuDebugOn(!(udba & AuOptMask_UDBA));
15413 + if (au_hnotify_op.reset_br)
15414 + err = au_hnotify_op.reset_br(udba, br, perm);
15419 +int au_hnotify_init_br(struct au_branch *br, int perm)
15424 + if (au_hnotify_op.init_br)
15425 + err = au_hnotify_op.init_br(br, perm);
15430 +void au_hnotify_fin_br(struct au_branch *br)
15432 + if (au_hnotify_op.fin_br)
15433 + au_hnotify_op.fin_br(br);
15436 +static void au_hn_destroy_cache(void)
15438 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15439 + au_cachep[AuCache_HNOTIFY] = NULL;
15442 +int __init au_hnotify_init(void)
15447 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15448 + if (au_cachep[AuCache_HNOTIFY]) {
15450 + if (au_hnotify_op.init)
15451 + err = au_hnotify_op.init();
15452 + if (unlikely(err))
15453 + au_hn_destroy_cache();
15459 +void au_hnotify_fin(void)
15461 + if (au_hnotify_op.fin)
15462 + au_hnotify_op.fin();
15463 + /* cf. au_cache_fin() */
15464 + if (au_cachep[AuCache_HNOTIFY])
15465 + au_hn_destroy_cache();
15467 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15468 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15469 +++ linux/fs/aufs/iinfo.c 2015-01-25 13:00:38.631047076 +0100
15472 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15474 + * This program, aufs is free software; you can redistribute it and/or modify
15475 + * it under the terms of the GNU General Public License as published by
15476 + * the Free Software Foundation; either version 2 of the License, or
15477 + * (at your option) any later version.
15479 + * This program is distributed in the hope that it will be useful,
15480 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15481 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15482 + * GNU General Public License for more details.
15484 + * You should have received a copy of the GNU General Public License
15485 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15489 + * inode private data
15494 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15496 + struct inode *h_inode;
15498 + IiMustAnyLock(inode);
15500 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15501 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15505 +/* todo: hard/soft set? */
15506 +void au_hiput(struct au_hinode *hinode)
15508 + au_hn_free(hinode);
15509 + dput(hinode->hi_whdentry);
15510 + iput(hinode->hi_inode);
15513 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15515 + unsigned int flags;
15516 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15519 + if (au_opt_test(mnt_flags, XINO))
15520 + au_fset_hi(flags, XINO);
15521 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15522 + au_fset_hi(flags, HNOTIFY);
15526 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15527 + struct inode *h_inode, unsigned int flags)
15529 + struct au_hinode *hinode;
15530 + struct inode *hi;
15531 + struct au_iinfo *iinfo = au_ii(inode);
15533 + IiMustWriteLock(inode);
15535 + hinode = iinfo->ii_hinode + bindex;
15536 + hi = hinode->hi_inode;
15537 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15540 + au_hiput(hinode);
15541 + hinode->hi_inode = h_inode;
15544 + struct super_block *sb = inode->i_sb;
15545 + struct au_branch *br;
15547 + AuDebugOn(inode->i_mode
15548 + && (h_inode->i_mode & S_IFMT)
15549 + != (inode->i_mode & S_IFMT));
15550 + if (bindex == iinfo->ii_bstart)
15551 + au_cpup_igen(inode, h_inode);
15552 + br = au_sbr(sb, bindex);
15553 + hinode->hi_id = br->br_id;
15554 + if (au_ftest_hi(flags, XINO)) {
15555 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15557 + if (unlikely(err))
15558 + AuIOErr1("failed au_xino_write() %d\n", err);
15561 + if (au_ftest_hi(flags, HNOTIFY)
15562 + && au_br_hnotifyable(br->br_perm)) {
15563 + err = au_hn_alloc(hinode, inode);
15564 + if (unlikely(err))
15565 + AuIOErr1("au_hn_alloc() %d\n", err);
15570 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15571 + struct dentry *h_wh)
15573 + struct au_hinode *hinode;
15575 + IiMustWriteLock(inode);
15577 + hinode = au_ii(inode)->ii_hinode + bindex;
15578 + AuDebugOn(hinode->hi_whdentry);
15579 + hinode->hi_whdentry = h_wh;
15582 +void au_update_iigen(struct inode *inode, int half)
15584 + struct au_iinfo *iinfo;
15585 + struct au_iigen *iigen;
15586 + unsigned int sigen;
15588 + sigen = au_sigen(inode->i_sb);
15589 + iinfo = au_ii(inode);
15590 + iigen = &iinfo->ii_generation;
15591 + spin_lock(&iinfo->ii_genspin);
15592 + iigen->ig_generation = sigen;
15594 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15596 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15597 + spin_unlock(&iinfo->ii_genspin);
15600 +/* it may be called at remount time, too */
15601 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15603 + struct au_iinfo *iinfo;
15604 + aufs_bindex_t bindex, bend;
15606 + iinfo = au_ii(inode);
15610 + IiMustWriteLock(inode);
15612 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15613 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15615 + struct inode *h_i;
15617 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15620 + && !(h_i->i_state & I_LINKABLE))
15621 + au_set_h_iptr(inode, bindex, NULL, 0);
15625 + iinfo->ii_bstart = -1;
15626 + iinfo->ii_bend = -1;
15627 + bend = au_sbend(inode->i_sb);
15628 + for (bindex = 0; bindex <= bend; bindex++)
15629 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15630 + iinfo->ii_bstart = bindex;
15633 + if (iinfo->ii_bstart >= 0)
15634 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15635 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15636 + iinfo->ii_bend = bindex;
15639 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15642 +/* ---------------------------------------------------------------------- */
15644 +void au_icntnr_init_once(void *_c)
15646 + struct au_icntnr *c = _c;
15647 + struct au_iinfo *iinfo = &c->iinfo;
15648 + static struct lock_class_key aufs_ii;
15650 + spin_lock_init(&iinfo->ii_genspin);
15651 + au_rw_init(&iinfo->ii_rwsem);
15652 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15653 + inode_init_once(&c->vfs_inode);
15656 +int au_iinfo_init(struct inode *inode)
15658 + struct au_iinfo *iinfo;
15659 + struct super_block *sb;
15662 + sb = inode->i_sb;
15663 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15664 + nbr = au_sbend(sb) + 1;
15665 + if (unlikely(nbr <= 0))
15667 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15668 + if (iinfo->ii_hinode) {
15669 + au_ninodes_inc(sb);
15670 + for (i = 0; i < nbr; i++)
15671 + iinfo->ii_hinode[i].hi_id = -1;
15673 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15674 + iinfo->ii_bstart = -1;
15675 + iinfo->ii_bend = -1;
15676 + iinfo->ii_vdir = NULL;
15682 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15685 + struct au_hinode *hip;
15687 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15690 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15692 + sz = sizeof(*hip);
15693 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15695 + iinfo->ii_hinode = hip;
15702 +void au_iinfo_fin(struct inode *inode)
15704 + struct au_iinfo *iinfo;
15705 + struct au_hinode *hi;
15706 + struct super_block *sb;
15707 + aufs_bindex_t bindex, bend;
15708 + const unsigned char unlinked = !inode->i_nlink;
15710 + iinfo = au_ii(inode);
15711 + /* bad_inode case */
15715 + sb = inode->i_sb;
15716 + au_ninodes_dec(sb);
15717 + if (si_pid_test(sb))
15718 + au_xino_delete_inode(inode, unlinked);
15721 + * it is safe to hide the dependency between sbinfo and
15725 + si_noflush_read_lock(sb);
15726 + au_xino_delete_inode(inode, unlinked);
15727 + si_read_unlock(sb);
15731 + if (iinfo->ii_vdir)
15732 + au_vdir_free(iinfo->ii_vdir);
15734 + bindex = iinfo->ii_bstart;
15735 + if (bindex >= 0) {
15736 + hi = iinfo->ii_hinode + bindex;
15737 + bend = iinfo->ii_bend;
15738 + while (bindex++ <= bend) {
15739 + if (hi->hi_inode)
15744 + kfree(iinfo->ii_hinode);
15745 + iinfo->ii_hinode = NULL;
15746 + AuRwDestroy(&iinfo->ii_rwsem);
15748 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15749 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15750 +++ linux/fs/aufs/inode.c 2015-01-25 13:00:38.631047076 +0100
15753 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15755 + * This program, aufs is free software; you can redistribute it and/or modify
15756 + * it under the terms of the GNU General Public License as published by
15757 + * the Free Software Foundation; either version 2 of the License, or
15758 + * (at your option) any later version.
15760 + * This program is distributed in the hope that it will be useful,
15761 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15762 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15763 + * GNU General Public License for more details.
15765 + * You should have received a copy of the GNU General Public License
15766 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15770 + * inode functions
15775 +struct inode *au_igrab(struct inode *inode)
15778 + AuDebugOn(!atomic_read(&inode->i_count));
15784 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15786 + au_cpup_attr_all(inode, /*force*/0);
15787 + au_update_iigen(inode, /*half*/1);
15789 + inode->i_version++;
15792 +static int au_ii_refresh(struct inode *inode, int *update)
15796 + aufs_bindex_t bindex, new_bindex;
15797 + struct super_block *sb;
15798 + struct au_iinfo *iinfo;
15799 + struct au_hinode *p, *q, tmp;
15801 + IiMustWriteLock(inode);
15804 + sb = inode->i_sb;
15805 + type = inode->i_mode & S_IFMT;
15806 + iinfo = au_ii(inode);
15807 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15808 + if (unlikely(err))
15811 + AuDebugOn(iinfo->ii_bstart < 0);
15812 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15813 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15815 + if (!p->hi_inode)
15818 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15819 + new_bindex = au_br_index(sb, p->hi_id);
15820 + if (new_bindex == bindex)
15823 + if (new_bindex < 0) {
15826 + p->hi_inode = NULL;
15830 + if (new_bindex < iinfo->ii_bstart)
15831 + iinfo->ii_bstart = new_bindex;
15832 + if (iinfo->ii_bend < new_bindex)
15833 + iinfo->ii_bend = new_bindex;
15834 + /* swap two lower inode, and loop again */
15835 + q = iinfo->ii_hinode + new_bindex;
15839 + if (tmp.hi_inode) {
15844 + au_update_ibrange(inode, /*do_put_zero*/0);
15845 + e = au_dy_irefresh(inode);
15846 + if (unlikely(e && !err))
15854 +int au_refresh_hinode_self(struct inode *inode)
15858 + err = au_ii_refresh(inode, &update);
15860 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
15866 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
15868 + int err, e, update;
15869 + unsigned int flags;
15871 + aufs_bindex_t bindex, bend;
15872 + unsigned char isdir;
15873 + struct au_hinode *p;
15874 + struct au_iinfo *iinfo;
15876 + err = au_ii_refresh(inode, &update);
15877 + if (unlikely(err))
15881 + iinfo = au_ii(inode);
15882 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15883 + mode = (inode->i_mode & S_IFMT);
15884 + isdir = S_ISDIR(mode);
15885 + flags = au_hi_flags(inode, isdir);
15886 + bend = au_dbend(dentry);
15887 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15888 + struct inode *h_i;
15889 + struct dentry *h_d;
15891 + h_d = au_h_dptr(dentry, bindex);
15892 + if (!h_d || !h_d->d_inode)
15895 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
15896 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15897 + h_i = au_h_iptr(inode, bindex);
15899 + if (h_i == h_d->d_inode)
15905 + if (bindex < iinfo->ii_bstart)
15906 + iinfo->ii_bstart = bindex;
15907 + if (iinfo->ii_bend < bindex)
15908 + iinfo->ii_bend = bindex;
15909 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
15912 + au_update_ibrange(inode, /*do_put_zero*/0);
15913 + e = au_dy_irefresh(inode);
15914 + if (unlikely(e && !err))
15917 + au_refresh_hinode_attr(inode, update && isdir);
15924 +static int set_inode(struct inode *inode, struct dentry *dentry)
15927 + unsigned int flags;
15929 + aufs_bindex_t bindex, bstart, btail;
15930 + unsigned char isdir;
15931 + struct dentry *h_dentry;
15932 + struct inode *h_inode;
15933 + struct au_iinfo *iinfo;
15935 + IiMustWriteLock(inode);
15939 + bstart = au_dbstart(dentry);
15940 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
15941 + mode = h_inode->i_mode;
15942 + switch (mode & S_IFMT) {
15944 + btail = au_dbtail(dentry);
15945 + inode->i_op = &aufs_iop;
15946 + inode->i_fop = &aufs_file_fop;
15947 + err = au_dy_iaop(inode, bstart, h_inode);
15948 + if (unlikely(err))
15953 + btail = au_dbtaildir(dentry);
15954 + inode->i_op = &aufs_dir_iop;
15955 + inode->i_fop = &aufs_dir_fop;
15958 + btail = au_dbtail(dentry);
15959 + inode->i_op = &aufs_symlink_iop;
15965 + btail = au_dbtail(dentry);
15966 + inode->i_op = &aufs_iop;
15967 + init_special_inode(inode, mode, h_inode->i_rdev);
15970 + AuIOErr("Unknown file type 0%o\n", mode);
15975 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
15976 + flags = au_hi_flags(inode, isdir);
15977 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
15978 + && au_ftest_hi(flags, HNOTIFY)
15979 + && dentry->d_name.len > AUFS_WH_PFX_LEN
15980 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
15981 + au_fclr_hi(flags, HNOTIFY);
15982 + iinfo = au_ii(inode);
15983 + iinfo->ii_bstart = bstart;
15984 + iinfo->ii_bend = btail;
15985 + for (bindex = bstart; bindex <= btail; bindex++) {
15986 + h_dentry = au_h_dptr(dentry, bindex);
15988 + au_set_h_iptr(inode, bindex,
15989 + au_igrab(h_dentry->d_inode), flags);
15991 + au_cpup_attr_all(inode, /*force*/1);
15993 + * to force calling aufs_get_acl() every time,
15994 + * do not call cache_no_acl() for aufs inode.
16002 + * successful returns with iinfo write_locked
16004 + * zero: success, matched
16005 + * plus: no error, but unmatched
16007 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16010 + unsigned int gen;
16011 + struct au_iigen iigen;
16012 + aufs_bindex_t bindex, bend;
16013 + struct inode *h_inode, *h_dinode;
16016 + * before this function, if aufs got any iinfo lock, it must be only
16017 + * one, the parent dir.
16018 + * it can happen by UDBA and the obsoleted inode number.
16021 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16025 + ii_write_lock_new_child(inode);
16026 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
16027 + bend = au_ibend(inode);
16028 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
16029 + h_inode = au_h_iptr(inode, bindex);
16030 + if (!h_inode || h_inode != h_dinode)
16034 + gen = au_iigen(inode, &iigen);
16035 + if (gen == au_digen(dentry)
16036 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
16039 + /* fully refresh inode using dentry */
16040 + err = au_refresh_hinode(inode, dentry);
16042 + au_update_iigen(inode, /*half*/0);
16046 + if (unlikely(err))
16047 + ii_write_unlock(inode);
16052 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16053 + unsigned int d_type, ino_t *ino)
16056 + struct mutex *mtx;
16058 + /* prevent hardlinked inode number from race condition */
16060 + if (d_type != DT_DIR) {
16061 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16064 + err = au_xino_read(sb, bindex, h_ino, ino);
16065 + if (unlikely(err))
16070 + *ino = au_xino_new_ino(sb);
16071 + if (unlikely(!*ino))
16073 + err = au_xino_write(sb, bindex, h_ino, *ino);
16074 + if (unlikely(err))
16080 + mutex_unlock(mtx);
16084 +/* successful returns with iinfo write_locked */
16085 +/* todo: return with unlocked? */
16086 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16088 + struct inode *inode, *h_inode;
16089 + struct dentry *h_dentry;
16090 + struct super_block *sb;
16091 + struct mutex *mtx;
16092 + ino_t h_ino, ino;
16094 + aufs_bindex_t bstart;
16096 + sb = dentry->d_sb;
16097 + bstart = au_dbstart(dentry);
16098 + h_dentry = au_h_dptr(dentry, bstart);
16099 + h_inode = h_dentry->d_inode;
16100 + h_ino = h_inode->i_ino;
16103 + * stop 'race'-ing between hardlinks under different
16107 + if (!S_ISDIR(h_inode->i_mode))
16108 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
16113 + err = au_xino_read(sb, bstart, h_ino, &ino);
16114 + inode = ERR_PTR(err);
16115 + if (unlikely(err))
16119 + ino = au_xino_new_ino(sb);
16120 + if (unlikely(!ino)) {
16121 + inode = ERR_PTR(-EIO);
16126 + AuDbg("i%lu\n", (unsigned long)ino);
16127 + inode = au_iget_locked(sb, ino);
16128 + err = PTR_ERR(inode);
16129 + if (IS_ERR(inode))
16132 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16133 + if (inode->i_state & I_NEW) {
16134 + /* verbose coding for lock class name */
16135 + if (unlikely(S_ISLNK(h_inode->i_mode)))
16136 + au_rw_class(&au_ii(inode)->ii_rwsem,
16137 + au_lc_key + AuLcSymlink_IIINFO);
16138 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
16139 + au_rw_class(&au_ii(inode)->ii_rwsem,
16140 + au_lc_key + AuLcDir_IIINFO);
16141 + else /* likely */
16142 + au_rw_class(&au_ii(inode)->ii_rwsem,
16143 + au_lc_key + AuLcNonDir_IIINFO);
16145 + ii_write_lock_new_child(inode);
16146 + err = set_inode(inode, dentry);
16148 + unlock_new_inode(inode);
16149 + goto out; /* success */
16153 + * iget_failed() calls iput(), but we need to call
16154 + * ii_write_unlock() after iget_failed(). so dirty hack for
16157 + atomic_inc(&inode->i_count);
16158 + iget_failed(inode);
16159 + ii_write_unlock(inode);
16160 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
16161 + /* ignore this error */
16163 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16165 + * horrible race condition between lookup, readdir and copyup
16166 + * (or something).
16169 + mutex_unlock(mtx);
16170 + err = reval_inode(inode, dentry);
16171 + if (unlikely(err < 0)) {
16178 + goto out; /* success */
16183 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
16184 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16185 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16186 + bstart, au_sbtype(h_dentry->d_sb), dentry,
16187 + (unsigned long)h_ino, (unsigned long)ino);
16189 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
16193 + mutex_unlock(mtx);
16199 + inode = ERR_PTR(err);
16202 + mutex_unlock(mtx);
16206 +/* ---------------------------------------------------------------------- */
16208 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16209 + struct inode *inode)
16212 + struct inode *hi;
16214 + err = au_br_rdonly(au_sbr(sb, bindex));
16216 + /* pseudo-link after flushed may happen out of bounds */
16219 + && au_ibstart(inode) <= bindex
16220 + && bindex <= au_ibend(inode)) {
16222 + * permission check is unnecessary since vfsub routine
16223 + * will be called later
16225 + hi = au_h_iptr(inode, bindex);
16227 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16233 +int au_test_h_perm(struct inode *h_inode, int mask)
16235 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16237 + return inode_permission(h_inode, mask);
16240 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16242 + if (au_test_nfs(h_inode->i_sb)
16243 + && (mask & MAY_WRITE)
16244 + && S_ISDIR(h_inode->i_mode))
16245 + mask |= MAY_READ; /* force permission check */
16246 + return au_test_h_perm(h_inode, mask);
16248 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16249 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16250 +++ linux/fs/aufs/inode.h 2015-01-25 13:00:38.631047076 +0100
16253 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16255 + * This program, aufs is free software; you can redistribute it and/or modify
16256 + * it under the terms of the GNU General Public License as published by
16257 + * the Free Software Foundation; either version 2 of the License, or
16258 + * (at your option) any later version.
16260 + * This program is distributed in the hope that it will be useful,
16261 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16262 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16263 + * GNU General Public License for more details.
16265 + * You should have received a copy of the GNU General Public License
16266 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16270 + * inode operations
16273 +#ifndef __AUFS_INODE_H__
16274 +#define __AUFS_INODE_H__
16278 +#include <linux/fsnotify.h>
16279 +#include "rwsem.h"
16283 +struct au_hnotify {
16284 +#ifdef CONFIG_AUFS_HNOTIFY
16285 +#ifdef CONFIG_AUFS_HFSNOTIFY
16286 + /* never use fsnotify_add_vfsmount_mark() */
16287 + struct fsnotify_mark hn_mark;
16289 + struct inode *hn_aufs_inode; /* no get/put */
16291 +} ____cacheline_aligned_in_smp;
16293 +struct au_hinode {
16294 + struct inode *hi_inode;
16295 + aufs_bindex_t hi_id;
16296 +#ifdef CONFIG_AUFS_HNOTIFY
16297 + struct au_hnotify *hi_notify;
16300 + /* reference to the copied-up whiteout with get/put */
16301 + struct dentry *hi_whdentry;
16305 +#define AuIG_HALF_REFRESHED 1
16306 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16307 +#define au_ig_fset(flags, name) \
16308 + do { (flags) |= AuIG_##name; } while (0)
16309 +#define au_ig_fclr(flags, name) \
16310 + do { (flags) &= ~AuIG_##name; } while (0)
16313 + __u32 ig_generation, ig_flags;
16318 + spinlock_t ii_genspin;
16319 + struct au_iigen ii_generation;
16320 + struct super_block *ii_hsb1; /* no get/put */
16322 + struct au_rwsem ii_rwsem;
16323 + aufs_bindex_t ii_bstart, ii_bend;
16325 + struct au_hinode *ii_hinode;
16326 + struct au_vdir *ii_vdir;
16329 +struct au_icntnr {
16330 + struct au_iinfo iinfo;
16331 + struct inode vfs_inode;
16332 +} ____cacheline_aligned_in_smp;
16334 +/* au_pin flags */
16335 +#define AuPin_DI_LOCKED 1
16336 +#define AuPin_MNT_WRITE (1 << 1)
16337 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16338 +#define au_fset_pin(flags, name) \
16339 + do { (flags) |= AuPin_##name; } while (0)
16340 +#define au_fclr_pin(flags, name) \
16341 + do { (flags) &= ~AuPin_##name; } while (0)
16345 + struct dentry *dentry;
16346 + unsigned int udba;
16347 + unsigned char lsc_di, lsc_hi, flags;
16348 + aufs_bindex_t bindex;
16351 + struct dentry *parent;
16352 + struct au_hinode *hdir;
16353 + struct vfsmount *h_mnt;
16355 + /* temporary unlock/relock for copyup */
16356 + struct dentry *h_dentry, *h_parent;
16357 + struct au_branch *br;
16358 + struct task_struct *task;
16361 +void au_pin_hdir_unlock(struct au_pin *p);
16362 +int au_pin_hdir_lock(struct au_pin *p);
16363 +int au_pin_hdir_relock(struct au_pin *p);
16364 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16365 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16366 +void au_pin_hdir_release(struct au_pin *p);
16368 +/* ---------------------------------------------------------------------- */
16370 +static inline struct au_iinfo *au_ii(struct inode *inode)
16372 + struct au_iinfo *iinfo;
16374 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16375 + if (iinfo->ii_hinode)
16377 + return NULL; /* debugging bad_inode case */
16380 +/* ---------------------------------------------------------------------- */
16383 +struct inode *au_igrab(struct inode *inode);
16384 +int au_refresh_hinode_self(struct inode *inode);
16385 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16386 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16387 + unsigned int d_type, ino_t *ino);
16388 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16389 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16390 + struct inode *inode);
16391 +int au_test_h_perm(struct inode *h_inode, int mask);
16392 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16394 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16395 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16397 +#ifdef CONFIG_AUFS_SHWH
16398 + return au_ino(sb, bindex, h_ino, d_type, ino);
16405 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
16407 +/* au_wr_dir flags */
16408 +#define AuWrDir_ADD_ENTRY 1
16409 +#define AuWrDir_TMP_WHENTRY (1 << 1)
16410 +#define AuWrDir_ISDIR (1 << 2)
16411 +#define AuWrDir_TMPFILE (1 << 3)
16412 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16413 +#define au_fset_wrdir(flags, name) \
16414 + do { (flags) |= AuWrDir_##name; } while (0)
16415 +#define au_fclr_wrdir(flags, name) \
16416 + do { (flags) &= ~AuWrDir_##name; } while (0)
16418 +struct au_wr_dir_args {
16419 + aufs_bindex_t force_btgt;
16420 + unsigned char flags;
16422 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16423 + struct au_wr_dir_args *args);
16425 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16426 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16427 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16428 + unsigned int udba, unsigned char flags);
16429 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16430 + unsigned int udba, unsigned char flags) __must_check;
16431 +int au_do_pin(struct au_pin *pin) __must_check;
16432 +void au_unpin(struct au_pin *pin);
16433 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16435 +#define AuIcpup_DID_CPUP 1
16436 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16437 +#define au_fset_icpup(flags, name) \
16438 + do { (flags) |= AuIcpup_##name; } while (0)
16439 +#define au_fclr_icpup(flags, name) \
16440 + do { (flags) &= ~AuIcpup_##name; } while (0)
16442 +struct au_icpup_args {
16443 + unsigned char flags;
16444 + unsigned char pin_flags;
16445 + aufs_bindex_t btgt;
16446 + unsigned int udba;
16447 + struct au_pin pin;
16448 + struct path h_path;
16449 + struct inode *h_inode;
16452 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16453 + struct au_icpup_args *a);
16455 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16458 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16459 + struct dentry *h_parent, int isdir);
16460 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16462 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16463 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16465 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16466 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16467 + struct dentry *dentry);
16468 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16471 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16472 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16473 + struct dentry *h_parent, int isdir);
16474 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16475 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16478 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16479 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16480 + struct inode *dir, struct dentry *dentry);
16483 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16484 +void au_hiput(struct au_hinode *hinode);
16485 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16486 + struct dentry *h_wh);
16487 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16489 +/* hinode flags */
16490 +#define AuHi_XINO 1
16491 +#define AuHi_HNOTIFY (1 << 1)
16492 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16493 +#define au_fset_hi(flags, name) \
16494 + do { (flags) |= AuHi_##name; } while (0)
16495 +#define au_fclr_hi(flags, name) \
16496 + do { (flags) &= ~AuHi_##name; } while (0)
16498 +#ifndef CONFIG_AUFS_HNOTIFY
16499 +#undef AuHi_HNOTIFY
16500 +#define AuHi_HNOTIFY 0
16503 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16504 + struct inode *h_inode, unsigned int flags);
16506 +void au_update_iigen(struct inode *inode, int half);
16507 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16509 +void au_icntnr_init_once(void *_c);
16510 +int au_iinfo_init(struct inode *inode);
16511 +void au_iinfo_fin(struct inode *inode);
16512 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16514 +#ifdef CONFIG_PROC_FS
16516 +int au_plink_maint(struct super_block *sb, int flags);
16517 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16518 +int au_plink_maint_enter(struct super_block *sb);
16519 +#ifdef CONFIG_AUFS_DEBUG
16520 +void au_plink_list(struct super_block *sb);
16522 +AuStubVoid(au_plink_list, struct super_block *sb)
16524 +int au_plink_test(struct inode *inode);
16525 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16526 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16527 + struct dentry *h_dentry);
16528 +void au_plink_put(struct super_block *sb, int verbose);
16529 +void au_plink_clean(struct super_block *sb, int verbose);
16530 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16532 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16533 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16534 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16535 +AuStubVoid(au_plink_list, struct super_block *sb);
16536 +AuStubInt0(au_plink_test, struct inode *inode);
16537 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16538 + struct inode *inode, aufs_bindex_t bindex);
16539 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16540 + struct dentry *h_dentry);
16541 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16542 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16543 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16544 +#endif /* CONFIG_PROC_FS */
16546 +#ifdef CONFIG_AUFS_XATTR
16548 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags);
16549 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16550 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
16552 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
16553 + size_t size, int flags);
16554 +int aufs_removexattr(struct dentry *dentry, const char *name);
16556 +/* void au_xattr_init(struct super_block *sb); */
16558 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16559 + int ignore_flags);
16560 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16563 +#ifdef CONFIG_FS_POSIX_ACL
16564 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16565 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16568 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16575 +struct au_srxattr {
16579 + const char *name;
16580 + const void *value;
16585 + const char *name;
16588 + struct posix_acl *acl;
16593 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
16596 +/* ---------------------------------------------------------------------- */
16598 +/* lock subclass for iinfo */
16600 + AuLsc_II_CHILD, /* child first */
16601 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16602 + AuLsc_II_CHILD3, /* copyup dirs */
16603 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16604 + AuLsc_II_PARENT2,
16605 + AuLsc_II_PARENT3, /* copyup dirs */
16606 + AuLsc_II_NEW_CHILD
16610 + * ii_read_lock_child, ii_write_lock_child,
16611 + * ii_read_lock_child2, ii_write_lock_child2,
16612 + * ii_read_lock_child3, ii_write_lock_child3,
16613 + * ii_read_lock_parent, ii_write_lock_parent,
16614 + * ii_read_lock_parent2, ii_write_lock_parent2,
16615 + * ii_read_lock_parent3, ii_write_lock_parent3,
16616 + * ii_read_lock_new_child, ii_write_lock_new_child,
16618 +#define AuReadLockFunc(name, lsc) \
16619 +static inline void ii_read_lock_##name(struct inode *i) \
16621 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16624 +#define AuWriteLockFunc(name, lsc) \
16625 +static inline void ii_write_lock_##name(struct inode *i) \
16627 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16630 +#define AuRWLockFuncs(name, lsc) \
16631 + AuReadLockFunc(name, lsc) \
16632 + AuWriteLockFunc(name, lsc)
16634 +AuRWLockFuncs(child, CHILD);
16635 +AuRWLockFuncs(child2, CHILD2);
16636 +AuRWLockFuncs(child3, CHILD3);
16637 +AuRWLockFuncs(parent, PARENT);
16638 +AuRWLockFuncs(parent2, PARENT2);
16639 +AuRWLockFuncs(parent3, PARENT3);
16640 +AuRWLockFuncs(new_child, NEW_CHILD);
16642 +#undef AuReadLockFunc
16643 +#undef AuWriteLockFunc
16644 +#undef AuRWLockFuncs
16647 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16649 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16651 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16652 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16653 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16655 +/* ---------------------------------------------------------------------- */
16657 +static inline void au_icntnr_init(struct au_icntnr *c)
16659 +#ifdef CONFIG_AUFS_DEBUG
16660 + c->vfs_inode.i_mode = 0;
16664 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
16666 + unsigned int gen;
16667 + struct au_iinfo *iinfo;
16669 + iinfo = au_ii(inode);
16670 + spin_lock(&iinfo->ii_genspin);
16672 + *iigen = iinfo->ii_generation;
16673 + gen = iinfo->ii_generation.ig_generation;
16674 + spin_unlock(&iinfo->ii_genspin);
16679 +/* tiny test for inode number */
16680 +/* tmpfs generation is too rough */
16681 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16683 + struct au_iinfo *iinfo;
16685 + iinfo = au_ii(inode);
16686 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16687 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16688 + && iinfo->ii_higen == h_inode->i_generation);
16691 +static inline void au_iigen_dec(struct inode *inode)
16693 + struct au_iinfo *iinfo;
16695 + iinfo = au_ii(inode);
16696 + spin_lock(&iinfo->ii_genspin);
16697 + iinfo->ii_generation.ig_generation--;
16698 + spin_unlock(&iinfo->ii_genspin);
16701 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16706 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16712 +/* ---------------------------------------------------------------------- */
16714 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16715 + aufs_bindex_t bindex)
16717 + IiMustAnyLock(inode);
16718 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16721 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16723 + IiMustAnyLock(inode);
16724 + return au_ii(inode)->ii_bstart;
16727 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16729 + IiMustAnyLock(inode);
16730 + return au_ii(inode)->ii_bend;
16733 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16735 + IiMustAnyLock(inode);
16736 + return au_ii(inode)->ii_vdir;
16739 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16741 + IiMustAnyLock(inode);
16742 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16745 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16747 + IiMustWriteLock(inode);
16748 + au_ii(inode)->ii_bstart = bindex;
16751 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16753 + IiMustWriteLock(inode);
16754 + au_ii(inode)->ii_bend = bindex;
16757 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16759 + IiMustWriteLock(inode);
16760 + au_ii(inode)->ii_vdir = vdir;
16763 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16765 + IiMustAnyLock(inode);
16766 + return au_ii(inode)->ii_hinode + bindex;
16769 +/* ---------------------------------------------------------------------- */
16771 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16774 + return pin->parent;
16778 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16780 + if (pin && pin->hdir)
16781 + return pin->hdir->hi_inode;
16785 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16788 + return pin->hdir;
16792 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16795 + pin->dentry = dentry;
16798 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16799 + unsigned char lflag)
16803 + au_fset_pin(pin->flags, DI_LOCKED);
16805 + au_fclr_pin(pin->flags, DI_LOCKED);
16809 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16812 + dput(pin->parent);
16813 + pin->parent = dget(parent);
16817 +/* ---------------------------------------------------------------------- */
16820 +#ifdef CONFIG_AUFS_HNOTIFY
16821 +struct au_hnotify_op {
16822 + void (*ctl)(struct au_hinode *hinode, int do_set);
16823 + int (*alloc)(struct au_hinode *hinode);
16826 + * if it returns true, the the caller should free hinode->hi_notify,
16827 + * otherwise ->free() frees it.
16829 + int (*free)(struct au_hinode *hinode,
16830 + struct au_hnotify *hn) __must_check;
16832 + void (*fin)(void);
16833 + int (*init)(void);
16835 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16836 + void (*fin_br)(struct au_branch *br);
16837 + int (*init_br)(struct au_branch *br, int perm);
16841 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
16842 +void au_hn_free(struct au_hinode *hinode);
16843 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
16844 +void au_hn_reset(struct inode *inode, unsigned int flags);
16845 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
16846 + struct qstr *h_child_qstr, struct inode *h_child_inode);
16847 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
16848 +int au_hnotify_init_br(struct au_branch *br, int perm);
16849 +void au_hnotify_fin_br(struct au_branch *br);
16850 +int __init au_hnotify_init(void);
16851 +void au_hnotify_fin(void);
16854 +extern const struct au_hnotify_op au_hnotify_op;
16857 +void au_hn_init(struct au_hinode *hinode)
16859 + hinode->hi_notify = NULL;
16862 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16864 + return hinode->hi_notify;
16868 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
16869 + struct au_hinode *hinode __maybe_unused,
16870 + struct inode *inode __maybe_unused)
16871 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
16872 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
16873 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
16874 + int do_set __maybe_unused)
16875 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
16876 + unsigned int flags __maybe_unused)
16877 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
16878 + struct au_branch *br __maybe_unused,
16879 + int perm __maybe_unused)
16880 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
16881 + int perm __maybe_unused)
16882 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
16883 +AuStubInt0(__init au_hnotify_init, void)
16884 +AuStubVoid(au_hnotify_fin, void)
16885 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
16886 +#endif /* CONFIG_AUFS_HNOTIFY */
16888 +static inline void au_hn_suspend(struct au_hinode *hdir)
16890 + au_hn_ctl(hdir, /*do_set*/0);
16893 +static inline void au_hn_resume(struct au_hinode *hdir)
16895 + au_hn_ctl(hdir, /*do_set*/1);
16898 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
16900 + mutex_lock(&hdir->hi_inode->i_mutex);
16901 + au_hn_suspend(hdir);
16904 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
16905 + unsigned int sc __maybe_unused)
16907 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
16908 + au_hn_suspend(hdir);
16911 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
16913 + au_hn_resume(hdir);
16914 + mutex_unlock(&hdir->hi_inode->i_mutex);
16917 +#endif /* __KERNEL__ */
16918 +#endif /* __AUFS_INODE_H__ */
16919 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
16920 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
16921 +++ linux/fs/aufs/ioctl.c 2015-01-25 13:00:38.631047076 +0100
16924 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16926 + * This program, aufs is free software; you can redistribute it and/or modify
16927 + * it under the terms of the GNU General Public License as published by
16928 + * the Free Software Foundation; either version 2 of the License, or
16929 + * (at your option) any later version.
16931 + * This program is distributed in the hope that it will be useful,
16932 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16933 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16934 + * GNU General Public License for more details.
16936 + * You should have received a copy of the GNU General Public License
16937 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16942 + * plink-management and readdir in userspace.
16943 + * assist the pathconf(3) wrapper library.
16945 + * File-based Hierarchical Storage Management.
16948 +#include <linux/compat.h>
16949 +#include <linux/file.h>
16952 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16955 + aufs_bindex_t wbi, bindex, bend;
16956 + struct file *h_file;
16957 + struct super_block *sb;
16958 + struct dentry *root;
16959 + struct au_branch *br;
16960 + struct aufs_wbr_fd wbrfd = {
16961 + .oflags = au_dir_roflags,
16964 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
16965 + | O_NOATIME | O_CLOEXEC;
16967 + AuDebugOn(wbrfd.oflags & ~valid);
16970 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
16971 + if (unlikely(err)) {
16977 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
16978 + wbrfd.oflags |= au_dir_roflags;
16979 + AuDbg("0%o\n", wbrfd.oflags);
16980 + if (unlikely(wbrfd.oflags & ~valid))
16984 + fd = get_unused_fd();
16986 + if (unlikely(fd < 0))
16989 + h_file = ERR_PTR(-EINVAL);
16992 + sb = path->dentry->d_sb;
16993 + root = sb->s_root;
16994 + aufs_read_lock(root, AuLock_IR);
16995 + bend = au_sbend(sb);
16996 + if (wbrfd.brid >= 0) {
16997 + wbi = au_br_index(sb, wbrfd.brid);
16998 + if (unlikely(wbi < 0 || wbi > bend))
17002 + h_file = ERR_PTR(-ENOENT);
17003 + br = au_sbr(sb, wbi);
17004 + if (!au_br_writable(br->br_perm)) {
17008 + bindex = wbi + 1;
17010 + for (; bindex <= bend; bindex++) {
17011 + br = au_sbr(sb, bindex);
17012 + if (au_br_writable(br->br_perm)) {
17014 + br = au_sbr(sb, wbi);
17019 + AuDbg("wbi %d\n", wbi);
17021 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17025 + aufs_read_unlock(root, AuLock_IR);
17026 + err = PTR_ERR(h_file);
17027 + if (IS_ERR(h_file))
17030 + atomic_dec(&br->br_count); /* cf. au_h_open() */
17031 + fd_install(fd, h_file);
17033 + goto out; /* success */
17036 + put_unused_fd(fd);
17042 +/* ---------------------------------------------------------------------- */
17044 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17047 + struct dentry *dentry;
17050 + case AUFS_CTL_RDU:
17051 + case AUFS_CTL_RDU_INO:
17052 + err = au_rdu_ioctl(file, cmd, arg);
17055 + case AUFS_CTL_WBR_FD:
17056 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17059 + case AUFS_CTL_IBUSY:
17060 + err = au_ibusy_ioctl(file, arg);
17063 + case AUFS_CTL_BRINFO:
17064 + err = au_brinfo_ioctl(file, arg);
17067 + case AUFS_CTL_FHSM_FD:
17068 + dentry = file->f_dentry;
17069 + if (IS_ROOT(dentry))
17070 + err = au_fhsm_fd(dentry->d_sb, arg);
17076 + /* do not call the lower */
17077 + AuDbg("0x%x\n", cmd);
17085 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17090 + case AUFS_CTL_MVDOWN:
17091 + err = au_mvdown(file->f_dentry, (void __user *)arg);
17094 + case AUFS_CTL_WBR_FD:
17095 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17099 + /* do not call the lower */
17100 + AuDbg("0x%x\n", cmd);
17108 +#ifdef CONFIG_COMPAT
17109 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17110 + unsigned long arg)
17115 + case AUFS_CTL_RDU:
17116 + case AUFS_CTL_RDU_INO:
17117 + err = au_rdu_compat_ioctl(file, cmd, arg);
17120 + case AUFS_CTL_IBUSY:
17121 + err = au_ibusy_compat_ioctl(file, arg);
17124 + case AUFS_CTL_BRINFO:
17125 + err = au_brinfo_compat_ioctl(file, arg);
17129 + err = aufs_ioctl_dir(file, cmd, arg);
17136 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17137 + unsigned long arg)
17139 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17142 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17143 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17144 +++ linux/fs/aufs/i_op_add.c 2015-01-25 13:00:38.631047076 +0100
17147 + * Copyright (C) 2005-2014 Junjiro R. Okajima
17149 + * This program, aufs is free software; you can redistribute it and/or modify
17150 + * it under the terms of the GNU General Public License as published by
17151 + * the Free Software Foundation; either version 2 of the License, or
17152 + * (at your option) any later version.
17154 + * This program is distributed in the hope that it will be useful,
17155 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17156 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17157 + * GNU General Public License for more details.
17159 + * You should have received a copy of the GNU General Public License
17160 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17164 + * inode operations (add entry)
17170 + * final procedure of adding a new entry, except link(2).
17171 + * remove whiteout, instantiate, copyup the parent dir's times and size
17172 + * and update version.
17173 + * if it failed, re-create the removed whiteout.
17175 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17176 + struct dentry *wh_dentry, struct dentry *dentry)
17179 + aufs_bindex_t bwh;
17180 + struct path h_path;
17181 + struct super_block *sb;
17182 + struct inode *inode, *h_dir;
17183 + struct dentry *wh;
17188 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
17189 + IMustLock(h_dir);
17190 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17191 + bwh = au_dbwh(dentry);
17192 + h_path.dentry = wh_dentry;
17193 + h_path.mnt = au_sbr_mnt(sb, bindex);
17194 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17196 + if (unlikely(err))
17200 + inode = au_new_inode(dentry, /*must_new*/1);
17201 + if (!IS_ERR(inode)) {
17202 + d_instantiate(dentry, inode);
17203 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
17205 + if (au_ibstart(dir) == au_dbstart(dentry))
17206 + au_cpup_attr_timesizes(dir);
17207 + dir->i_version++;
17208 + au_fhsm_wrote(sb, bindex, /*force*/0);
17209 + return 0; /* success */
17212 + err = PTR_ERR(inode);
17217 + /* dir inode is locked */
17218 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17219 + rerr = PTR_ERR(wh);
17220 + if (IS_ERR(wh)) {
17221 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17222 + dentry, err, rerr);
17231 +static int au_d_may_add(struct dentry *dentry)
17236 + if (unlikely(d_unhashed(dentry)))
17238 + if (unlikely(dentry->d_inode))
17244 + * simple tests for the adding inode operations.
17245 + * following the checks in vfs, plus the parent-child relationship.
17247 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17248 + struct dentry *h_parent, int isdir)
17252 + struct dentry *h_dentry;
17253 + struct inode *h_inode;
17255 + err = -ENAMETOOLONG;
17256 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17259 + h_dentry = au_h_dptr(dentry, bindex);
17260 + h_inode = h_dentry->d_inode;
17261 + if (!dentry->d_inode) {
17263 + if (unlikely(h_inode))
17266 + /* rename(2) case */
17268 + if (unlikely(!h_inode || !h_inode->i_nlink))
17271 + h_mode = h_inode->i_mode;
17274 + if (unlikely(S_ISDIR(h_mode)))
17276 + } else if (unlikely(!S_ISDIR(h_mode))) {
17283 + /* expected parent dir is locked */
17284 + if (unlikely(h_parent != h_dentry->d_parent))
17293 + * initial procedure of adding a new entry.
17294 + * prepare writable branch and the parent dir, lock it,
17295 + * and lookup whiteout for the new entry.
17297 +static struct dentry*
17298 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17299 + struct dentry *src_dentry, struct au_pin *pin,
17300 + struct au_wr_dir_args *wr_dir_args)
17302 + struct dentry *wh_dentry, *h_parent;
17303 + struct super_block *sb;
17304 + struct au_branch *br;
17306 + unsigned int udba;
17307 + aufs_bindex_t bcpup;
17309 + AuDbg("%pd\n", dentry);
17311 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17313 + wh_dentry = ERR_PTR(err);
17314 + if (unlikely(err < 0))
17317 + sb = dentry->d_sb;
17318 + udba = au_opt_udba(sb);
17319 + err = au_pin(pin, dentry, bcpup, udba,
17320 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17321 + wh_dentry = ERR_PTR(err);
17322 + if (unlikely(err))
17325 + h_parent = au_pinned_h_parent(pin);
17326 + if (udba != AuOpt_UDBA_NONE
17327 + && au_dbstart(dentry) == bcpup)
17328 + err = au_may_add(dentry, bcpup, h_parent,
17329 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17330 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17331 + err = -ENAMETOOLONG;
17332 + wh_dentry = ERR_PTR(err);
17333 + if (unlikely(err))
17336 + br = au_sbr(sb, bcpup);
17338 + struct path tmp = {
17339 + .dentry = h_parent,
17340 + .mnt = au_br_mnt(br)
17342 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17345 + wh_dentry = NULL;
17346 + if (bcpup != au_dbwh(dentry))
17347 + goto out; /* success */
17349 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17352 + if (IS_ERR(wh_dentry))
17355 + return wh_dentry;
17358 +/* ---------------------------------------------------------------------- */
17360 +enum { Mknod, Symlink, Creat };
17361 +struct simple_arg {
17369 + const char *symname;
17378 +static int add_simple(struct inode *dir, struct dentry *dentry,
17379 + struct simple_arg *arg)
17382 + aufs_bindex_t bstart;
17383 + unsigned char created;
17384 + struct dentry *wh_dentry, *parent;
17385 + struct inode *h_dir;
17386 + /* to reuduce stack size */
17388 + struct au_dtime dt;
17389 + struct au_pin pin;
17390 + struct path h_path;
17391 + struct au_wr_dir_args wr_dir_args;
17394 + AuDbg("%pd\n", dentry);
17398 + a = kmalloc(sizeof(*a), GFP_NOFS);
17399 + if (unlikely(!a))
17401 + a->wr_dir_args.force_btgt = -1;
17402 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17404 + parent = dentry->d_parent; /* dir inode is locked */
17405 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17406 + if (unlikely(err))
17408 + err = au_d_may_add(dentry);
17409 + if (unlikely(err))
17411 + di_write_lock_parent(parent);
17412 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17413 + &a->pin, &a->wr_dir_args);
17414 + err = PTR_ERR(wh_dentry);
17415 + if (IS_ERR(wh_dentry))
17418 + bstart = au_dbstart(dentry);
17419 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17420 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17421 + h_dir = au_pinned_h_dir(&a->pin);
17422 + switch (arg->type) {
17424 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17425 + arg->u.c.want_excl);
17428 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17431 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17439 + err = epilog(dir, bstart, wh_dentry, dentry);
17442 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
17443 + /* no delegation since it is just created */
17444 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17447 + AuIOErr("%pd revert failure(%d, %d)\n",
17448 + dentry, err, rerr);
17451 + au_dtime_revert(&a->dt);
17454 + au_unpin(&a->pin);
17458 + di_write_unlock(parent);
17460 + if (unlikely(err)) {
17461 + au_update_dbstart(dentry);
17464 + aufs_read_unlock(dentry, AuLock_DW);
17471 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17474 + struct simple_arg arg = {
17481 + return add_simple(dir, dentry, &arg);
17484 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17486 + struct simple_arg arg = {
17488 + .u.s.symname = symname
17490 + return add_simple(dir, dentry, &arg);
17493 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17496 + struct simple_arg arg = {
17500 + .want_excl = want_excl
17503 + return add_simple(dir, dentry, &arg);
17506 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17509 + aufs_bindex_t bindex;
17510 + struct super_block *sb;
17511 + struct dentry *parent, *h_parent, *h_dentry;
17512 + struct inode *h_dir, *inode;
17513 + struct vfsmount *h_mnt;
17514 + struct au_wr_dir_args wr_dir_args = {
17515 + .force_btgt = -1,
17516 + .flags = AuWrDir_TMPFILE
17519 + /* copy-up may happen */
17520 + mutex_lock(&dir->i_mutex);
17523 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17524 + if (unlikely(err))
17527 + err = au_di_init(dentry);
17528 + if (unlikely(err))
17532 + parent = d_find_any_alias(dir);
17533 + AuDebugOn(!parent);
17534 + di_write_lock_parent(parent);
17535 + if (unlikely(parent->d_inode != dir))
17538 + err = au_digen_test(parent, au_sigen(sb));
17539 + if (unlikely(err))
17542 + bindex = au_dbstart(parent);
17543 + au_set_dbstart(dentry, bindex);
17544 + au_set_dbend(dentry, bindex);
17545 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17547 + if (unlikely(err < 0))
17550 + err = -EOPNOTSUPP;
17551 + h_dir = au_h_iptr(dir, bindex);
17552 + if (unlikely(!h_dir->i_op->tmpfile))
17555 + h_mnt = au_sbr_mnt(sb, bindex);
17556 + err = vfsub_mnt_want_write(h_mnt);
17557 + if (unlikely(err))
17560 + h_parent = au_h_dptr(parent, bindex);
17561 + err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC);
17562 + if (unlikely(err))
17566 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17567 + if (unlikely(!h_dentry))
17570 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17571 + if (unlikely(err))
17574 + au_set_dbstart(dentry, bindex);
17575 + au_set_dbend(dentry, bindex);
17576 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17577 + inode = au_new_inode(dentry, /*must_new*/1);
17578 + if (IS_ERR(inode)) {
17579 + err = PTR_ERR(inode);
17580 + au_set_h_dptr(dentry, bindex, NULL);
17581 + au_set_dbstart(dentry, -1);
17582 + au_set_dbend(dentry, -1);
17584 + if (!inode->i_nlink)
17585 + set_nlink(inode, 1);
17586 + d_tmpfile(dentry, inode);
17587 + au_di(dentry)->di_tmpfile = 1;
17589 + /* update without i_mutex */
17590 + if (au_ibstart(dir) == au_dbstart(dentry))
17591 + au_cpup_attr_timesizes(dir);
17597 + vfsub_mnt_drop_write(h_mnt);
17599 + di_write_unlock(parent);
17601 + di_write_unlock(dentry);
17604 + /* verbose coding for lock class name */
17605 + au_rw_class(&au_di(dentry)->di_rwsem,
17606 + au_lc_key + AuLcNonDir_DIINFO);
17611 + au_di_fin(dentry);
17612 + dentry->d_fsdata = NULL;
17615 + si_read_unlock(sb);
17617 + mutex_unlock(&dir->i_mutex);
17621 +/* ---------------------------------------------------------------------- */
17623 +struct au_link_args {
17624 + aufs_bindex_t bdst, bsrc;
17625 + struct au_pin pin;
17626 + struct path h_path;
17627 + struct dentry *src_parent, *parent;
17630 +static int au_cpup_before_link(struct dentry *src_dentry,
17631 + struct au_link_args *a)
17634 + struct dentry *h_src_dentry;
17635 + struct au_cp_generic cpg = {
17636 + .dentry = src_dentry,
17641 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17644 + di_read_lock_parent(a->src_parent, AuLock_IR);
17645 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17646 + if (unlikely(err))
17649 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17650 + err = au_pin(&a->pin, src_dentry, a->bdst,
17651 + au_opt_udba(src_dentry->d_sb),
17652 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17653 + if (unlikely(err))
17656 + err = au_sio_cpup_simple(&cpg);
17657 + au_unpin(&a->pin);
17660 + di_read_unlock(a->src_parent, AuLock_IR);
17664 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17665 + struct au_link_args *a)
17668 + unsigned char plink;
17669 + aufs_bindex_t bend;
17670 + struct dentry *h_src_dentry;
17671 + struct inode *h_inode, *inode, *delegated;
17672 + struct super_block *sb;
17673 + struct file *h_file;
17677 + sb = src_dentry->d_sb;
17678 + inode = src_dentry->d_inode;
17679 + if (au_ibstart(inode) <= a->bdst)
17680 + h_inode = au_h_iptr(inode, a->bdst);
17681 + if (!h_inode || !h_inode->i_nlink) {
17682 + /* copyup src_dentry as the name of dentry. */
17683 + bend = au_dbend(dentry);
17684 + if (bend < a->bsrc)
17685 + au_set_dbend(dentry, a->bsrc);
17686 + au_set_h_dptr(dentry, a->bsrc,
17687 + dget(au_h_dptr(src_dentry, a->bsrc)));
17688 + dget(a->h_path.dentry);
17689 + au_set_h_dptr(dentry, a->bdst, NULL);
17690 + AuDbg("temporary d_inode...\n");
17691 + spin_lock(&dentry->d_lock);
17692 + dentry->d_inode = src_dentry->d_inode; /* tmp */
17693 + spin_unlock(&dentry->d_lock);
17694 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17695 + if (IS_ERR(h_file))
17696 + err = PTR_ERR(h_file);
17698 + struct au_cp_generic cpg = {
17699 + .dentry = dentry,
17704 + .flags = AuCpup_KEEPLINO
17706 + err = au_sio_cpup_simple(&cpg);
17707 + au_h_open_post(dentry, a->bsrc, h_file);
17709 + dput(a->h_path.dentry);
17710 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17712 + au_set_h_dptr(dentry, a->bdst,
17713 + a->h_path.dentry);
17715 + spin_lock(&dentry->d_lock);
17716 + dentry->d_inode = NULL; /* restore */
17717 + spin_unlock(&dentry->d_lock);
17718 + AuDbg("temporary d_inode...done\n");
17719 + au_set_h_dptr(dentry, a->bsrc, NULL);
17720 + au_set_dbend(dentry, bend);
17722 + /* the inode of src_dentry already exists on a.bdst branch */
17723 + h_src_dentry = d_find_alias(h_inode);
17724 + if (!h_src_dentry && au_plink_test(inode)) {
17726 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17727 + err = PTR_ERR(h_src_dentry);
17728 + if (IS_ERR(h_src_dentry))
17731 + if (unlikely(!h_src_dentry->d_inode)) {
17732 + dput(h_src_dentry);
17733 + h_src_dentry = NULL;
17737 + if (h_src_dentry) {
17738 + delegated = NULL;
17739 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17740 + &a->h_path, &delegated);
17741 + if (unlikely(err == -EWOULDBLOCK)) {
17742 + pr_warn("cannot retry for NFSv4 delegation"
17743 + " for an internal link\n");
17746 + dput(h_src_dentry);
17748 + AuIOErr("no dentry found for hi%lu on b%d\n",
17749 + h_inode->i_ino, a->bdst);
17754 + if (!err && !plink)
17755 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17762 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17763 + struct dentry *dentry)
17766 + struct au_dtime dt;
17767 + struct au_link_args *a;
17768 + struct dentry *wh_dentry, *h_src_dentry;
17769 + struct inode *inode, *delegated;
17770 + struct super_block *sb;
17771 + struct au_wr_dir_args wr_dir_args = {
17772 + /* .force_btgt = -1, */
17773 + .flags = AuWrDir_ADD_ENTRY
17777 + inode = src_dentry->d_inode;
17778 + IMustLock(inode);
17781 + a = kzalloc(sizeof(*a), GFP_NOFS);
17782 + if (unlikely(!a))
17785 + a->parent = dentry->d_parent; /* dir inode is locked */
17786 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17787 + AuLock_NOPLM | AuLock_GEN);
17788 + if (unlikely(err))
17790 + err = au_d_linkable(src_dentry);
17791 + if (unlikely(err))
17793 + err = au_d_may_add(dentry);
17794 + if (unlikely(err))
17797 + a->src_parent = dget_parent(src_dentry);
17798 + wr_dir_args.force_btgt = au_ibstart(inode);
17800 + di_write_lock_parent(a->parent);
17801 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
17802 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
17804 + err = PTR_ERR(wh_dentry);
17805 + if (IS_ERR(wh_dentry))
17809 + sb = dentry->d_sb;
17810 + a->bdst = au_dbstart(dentry);
17811 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17812 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17813 + a->bsrc = au_ibstart(inode);
17814 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17815 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
17816 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
17817 + if (!h_src_dentry) {
17818 + a->bsrc = au_dbstart(src_dentry);
17819 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17820 + AuDebugOn(!h_src_dentry);
17821 + } else if (IS_ERR(h_src_dentry)) {
17822 + err = PTR_ERR(h_src_dentry);
17826 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17827 + if (a->bdst < a->bsrc
17828 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17829 + err = au_cpup_or_link(src_dentry, dentry, a);
17831 + delegated = NULL;
17832 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17833 + &a->h_path, &delegated);
17834 + if (unlikely(err == -EWOULDBLOCK)) {
17835 + pr_warn("cannot retry for NFSv4 delegation"
17836 + " for an internal link\n");
17840 + dput(h_src_dentry);
17843 + * copyup src_dentry to the branch we process,
17844 + * and then link(2) to it.
17846 + dput(h_src_dentry);
17847 + if (a->bdst < a->bsrc
17848 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17849 + au_unpin(&a->pin);
17850 + di_write_unlock(a->parent);
17851 + err = au_cpup_before_link(src_dentry, a);
17852 + di_write_lock_parent(a->parent);
17854 + err = au_pin(&a->pin, dentry, a->bdst,
17856 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17857 + if (unlikely(err))
17861 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17863 + if (h_src_dentry && h_src_dentry->d_inode) {
17864 + delegated = NULL;
17865 + err = vfsub_link(h_src_dentry,
17866 + au_pinned_h_dir(&a->pin),
17867 + &a->h_path, &delegated);
17868 + if (unlikely(err == -EWOULDBLOCK)) {
17869 + pr_warn("cannot retry"
17870 + " for NFSv4 delegation"
17871 + " for an internal link\n");
17877 + if (unlikely(err))
17881 + a->h_path.dentry = wh_dentry;
17882 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17884 + if (unlikely(err))
17888 + dir->i_version++;
17889 + if (au_ibstart(dir) == au_dbstart(dentry))
17890 + au_cpup_attr_timesizes(dir);
17891 + inc_nlink(inode);
17892 + inode->i_ctime = dir->i_ctime;
17893 + d_instantiate(dentry, au_igrab(inode));
17894 + if (d_unhashed(a->h_path.dentry))
17895 + /* some filesystem calls d_drop() */
17897 + /* some filesystems consume an inode even hardlink */
17898 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
17899 + goto out_unpin; /* success */
17902 + /* no delegation since it is just created */
17903 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17904 + /*delegated*/NULL, /*force*/0);
17905 + if (unlikely(rerr)) {
17906 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17909 + au_dtime_revert(&dt);
17911 + au_unpin(&a->pin);
17915 + di_write_unlock(a->parent);
17916 + dput(a->src_parent);
17918 + if (unlikely(err)) {
17919 + au_update_dbstart(dentry);
17922 + aufs_read_and_write_unlock2(dentry, src_dentry);
17930 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
17933 + aufs_bindex_t bindex;
17934 + unsigned char diropq;
17935 + struct path h_path;
17936 + struct dentry *wh_dentry, *parent, *opq_dentry;
17937 + struct mutex *h_mtx;
17938 + struct super_block *sb;
17940 + struct au_pin pin;
17941 + struct au_dtime dt;
17942 + } *a; /* reduce the stack usage */
17943 + struct au_wr_dir_args wr_dir_args = {
17944 + .force_btgt = -1,
17945 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
17951 + a = kmalloc(sizeof(*a), GFP_NOFS);
17952 + if (unlikely(!a))
17955 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17956 + if (unlikely(err))
17958 + err = au_d_may_add(dentry);
17959 + if (unlikely(err))
17962 + parent = dentry->d_parent; /* dir inode is locked */
17963 + di_write_lock_parent(parent);
17964 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17965 + &a->pin, &wr_dir_args);
17966 + err = PTR_ERR(wh_dentry);
17967 + if (IS_ERR(wh_dentry))
17970 + sb = dentry->d_sb;
17971 + bindex = au_dbstart(dentry);
17972 + h_path.dentry = au_h_dptr(dentry, bindex);
17973 + h_path.mnt = au_sbr_mnt(sb, bindex);
17974 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
17975 + if (unlikely(err))
17978 + /* make the dir opaque */
17980 + h_mtx = &h_path.dentry->d_inode->i_mutex;
17982 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
17983 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17984 + opq_dentry = au_diropq_create(dentry, bindex);
17985 + mutex_unlock(h_mtx);
17986 + err = PTR_ERR(opq_dentry);
17987 + if (IS_ERR(opq_dentry))
17989 + dput(opq_dentry);
17993 + err = epilog(dir, bindex, wh_dentry, dentry);
17996 + goto out_unpin; /* success */
18001 + AuLabel(revert opq);
18002 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18003 + rerr = au_diropq_remove(dentry, bindex);
18004 + mutex_unlock(h_mtx);
18006 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18007 + dentry, err, rerr);
18013 + AuLabel(revert dir);
18014 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18016 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18017 + dentry, err, rerr);
18020 + au_dtime_revert(&a->dt);
18022 + au_unpin(&a->pin);
18025 + di_write_unlock(parent);
18027 + if (unlikely(err)) {
18028 + au_update_dbstart(dentry);
18031 + aufs_read_unlock(dentry, AuLock_DW);
18037 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18038 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18039 +++ linux/fs/aufs/i_op.c 2015-01-25 13:00:38.631047076 +0100
18042 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18044 + * This program, aufs is free software; you can redistribute it and/or modify
18045 + * it under the terms of the GNU General Public License as published by
18046 + * the Free Software Foundation; either version 2 of the License, or
18047 + * (at your option) any later version.
18049 + * This program is distributed in the hope that it will be useful,
18050 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18051 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18052 + * GNU General Public License for more details.
18054 + * You should have received a copy of the GNU General Public License
18055 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18059 + * inode operations (except add/del/rename)
18062 +#include <linux/device_cgroup.h>
18063 +#include <linux/fs_stack.h>
18064 +#include <linux/mm.h>
18065 +#include <linux/namei.h>
18066 +#include <linux/security.h>
18069 +static int h_permission(struct inode *h_inode, int mask,
18070 + struct vfsmount *h_mnt, int brperm)
18073 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18076 + if ((write_mask && IS_IMMUTABLE(h_inode))
18077 + || ((mask & MAY_EXEC)
18078 + && S_ISREG(h_inode->i_mode)
18079 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
18080 + || !(h_inode->i_mode & S_IXUGO))))
18084 + * - skip the lower fs test in the case of write to ro branch.
18085 + * - nfs dir permission write check is optimized, but a policy for
18086 + * link/rename requires a real check.
18088 + if ((write_mask && !au_br_writable(brperm))
18089 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18090 + && write_mask && !(mask & MAY_READ))
18091 + || !h_inode->i_op->permission) {
18092 + /* AuLabel(generic_permission); */
18093 + err = generic_permission(h_inode, mask);
18095 + /* AuLabel(h_inode->permission); */
18096 + err = h_inode->i_op->permission(h_inode, mask);
18101 + err = devcgroup_inode_permission(h_inode, mask);
18103 + err = security_inode_permission(h_inode, mask);
18107 + /* todo: do we need to call ima_path_check()? */
18108 + struct path h_path = {
18112 + err = ima_path_check(&h_path,
18113 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18114 + IMA_COUNT_LEAVE);
18122 +static int aufs_permission(struct inode *inode, int mask)
18125 + aufs_bindex_t bindex, bend;
18126 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18127 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18128 + struct inode *h_inode;
18129 + struct super_block *sb;
18130 + struct au_branch *br;
18132 + /* todo: support rcu-walk? */
18133 + if (mask & MAY_NOT_BLOCK)
18136 + sb = inode->i_sb;
18137 + si_read_lock(sb, AuLock_FLUSH);
18138 + ii_read_lock_child(inode);
18140 + err = au_iigen_test(inode, au_sigen(sb));
18141 + if (unlikely(err))
18147 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18148 + err = au_busy_or_stale();
18149 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18150 + if (unlikely(!h_inode
18151 + || (h_inode->i_mode & S_IFMT)
18152 + != (inode->i_mode & S_IFMT)))
18156 + bindex = au_ibstart(inode);
18157 + br = au_sbr(sb, bindex);
18158 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
18161 + && !special_file(h_inode->i_mode)) {
18162 + /* test whether the upper writable branch exists */
18164 + for (; bindex >= 0; bindex--)
18165 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18173 + /* non-write to dir */
18175 + bend = au_ibend(inode);
18176 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
18177 + h_inode = au_h_iptr(inode, bindex);
18179 + err = au_busy_or_stale();
18180 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18183 + br = au_sbr(sb, bindex);
18184 + err = h_permission(h_inode, mask, au_br_mnt(br),
18190 + ii_read_unlock(inode);
18191 + si_read_unlock(sb);
18195 +/* ---------------------------------------------------------------------- */
18197 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18198 + unsigned int flags)
18200 + struct dentry *ret, *parent;
18201 + struct inode *inode;
18202 + struct super_block *sb;
18203 + int err, npositive;
18207 + /* todo: support rcu-walk? */
18208 + ret = ERR_PTR(-ECHILD);
18209 + if (flags & LOOKUP_RCU)
18212 + ret = ERR_PTR(-ENAMETOOLONG);
18213 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18217 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18218 + ret = ERR_PTR(err);
18219 + if (unlikely(err))
18222 + err = au_di_init(dentry);
18223 + ret = ERR_PTR(err);
18224 + if (unlikely(err))
18228 + npositive = 0; /* suppress a warning */
18229 + parent = dentry->d_parent; /* dir inode is locked */
18230 + di_read_lock_parent(parent, AuLock_IR);
18231 + err = au_alive_dir(parent);
18233 + err = au_digen_test(parent, au_sigen(sb));
18235 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
18239 + di_read_unlock(parent, AuLock_IR);
18240 + ret = ERR_PTR(err);
18241 + if (unlikely(err < 0))
18245 + inode = au_new_inode(dentry, /*must_new*/0);
18246 + if (IS_ERR(inode)) {
18247 + ret = (void *)inode;
18254 + atomic_inc(&inode->i_count);
18255 + ret = d_splice_alias(inode, dentry);
18257 + && PTR_ERR(ret) == -EIO
18259 + && S_ISDIR(inode->i_mode)) {
18260 + atomic_inc(&inode->i_count);
18261 + ret = d_materialise_unique(dentry, inode);
18262 + if (!IS_ERR(ret))
18263 + ii_write_unlock(inode);
18266 + if (unlikely(d_need_lookup(dentry))) {
18267 + spin_lock(&dentry->d_lock);
18268 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18269 + spin_unlock(&dentry->d_lock);
18273 + if (!IS_ERR(ret))
18276 + ii_write_unlock(inode);
18283 + di_write_unlock(dentry);
18285 + /* verbose coding for lock class name */
18286 + if (unlikely(S_ISLNK(inode->i_mode)))
18287 + au_rw_class(&au_di(dentry)->di_rwsem,
18288 + au_lc_key + AuLcSymlink_DIINFO);
18289 + else if (unlikely(S_ISDIR(inode->i_mode)))
18290 + au_rw_class(&au_di(dentry)->di_rwsem,
18291 + au_lc_key + AuLcDir_DIINFO);
18292 + else /* likely */
18293 + au_rw_class(&au_di(dentry)->di_rwsem,
18294 + au_lc_key + AuLcNonDir_DIINFO);
18297 + si_read_unlock(sb);
18302 +/* ---------------------------------------------------------------------- */
18304 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18305 + const unsigned char add_entry, aufs_bindex_t bcpup,
18306 + aufs_bindex_t bstart)
18309 + struct dentry *h_parent;
18310 + struct inode *h_dir;
18313 + IMustLock(parent->d_inode);
18315 + di_write_lock_parent(parent);
18318 + if (!au_h_dptr(parent, bcpup)) {
18319 + if (bstart > bcpup)
18320 + err = au_cpup_dirs(dentry, bcpup);
18321 + else if (bstart < bcpup)
18322 + err = au_cpdown_dirs(dentry, bcpup);
18326 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18327 + h_parent = au_h_dptr(parent, bcpup);
18328 + h_dir = h_parent->d_inode;
18329 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
18330 + err = au_lkup_neg(dentry, bcpup,
18331 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
18332 + /* todo: no unlock here */
18333 + mutex_unlock(&h_dir->i_mutex);
18335 + AuDbg("bcpup %d\n", bcpup);
18337 + if (!dentry->d_inode)
18338 + au_set_h_dptr(dentry, bstart, NULL);
18339 + au_update_dbrange(dentry, /*do_put_zero*/0);
18344 + di_write_unlock(parent);
18346 + err = bcpup; /* success */
18353 + * decide the branch and the parent dir where we will create a new entry.
18354 + * returns new bindex or an error.
18355 + * copyup the parent dir if needed.
18357 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18358 + struct au_wr_dir_args *args)
18361 + unsigned int flags;
18362 + aufs_bindex_t bcpup, bstart, src_bstart;
18363 + const unsigned char add_entry
18364 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18365 + | au_ftest_wrdir(args->flags, TMP_WHENTRY)
18366 + | au_ftest_wrdir(args->flags, TMPFILE);
18367 + struct super_block *sb;
18368 + struct dentry *parent;
18369 + struct au_sbinfo *sbinfo;
18371 + sb = dentry->d_sb;
18372 + sbinfo = au_sbi(sb);
18373 + parent = dget_parent(dentry);
18374 + bstart = au_dbstart(dentry);
18376 + if (args->force_btgt < 0) {
18377 + if (src_dentry) {
18378 + src_bstart = au_dbstart(src_dentry);
18379 + if (src_bstart < bstart)
18380 + bcpup = src_bstart;
18381 + } else if (add_entry) {
18383 + if (au_ftest_wrdir(args->flags, ISDIR))
18384 + au_fset_wbr(flags, DIR);
18385 + err = AuWbrCreate(sbinfo, dentry, flags);
18389 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
18391 + err = AuWbrCopyup(sbinfo, dentry);
18393 + if (!IS_ROOT(dentry)) {
18394 + di_read_lock_parent(parent, !AuLock_IR);
18395 + err = AuWbrCopyup(sbinfo, dentry);
18396 + di_read_unlock(parent, !AuLock_IR);
18398 + err = AuWbrCopyup(sbinfo, dentry);
18401 + if (unlikely(err < 0))
18405 + bcpup = args->force_btgt;
18406 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
18409 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18411 + if (bcpup == bstart)
18412 + goto out; /* success */
18414 + /* copyup the new parent into the branch we process */
18415 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18417 + if (!dentry->d_inode) {
18418 + au_set_h_dptr(dentry, bstart, NULL);
18419 + au_set_dbstart(dentry, bcpup);
18420 + au_set_dbend(dentry, bcpup);
18422 + AuDebugOn(add_entry
18423 + && !au_ftest_wrdir(args->flags, TMPFILE)
18424 + && !au_h_dptr(dentry, bcpup));
18432 +/* ---------------------------------------------------------------------- */
18434 +void au_pin_hdir_unlock(struct au_pin *p)
18437 + au_hn_imtx_unlock(p->hdir);
18440 +int au_pin_hdir_lock(struct au_pin *p)
18448 + /* even if an error happens later, keep this lock */
18449 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18452 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
18457 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18458 + p->h_parent, p->br);
18464 +int au_pin_hdir_relock(struct au_pin *p)
18467 + struct inode *h_i;
18468 + struct dentry *h_d[] = {
18473 + err = au_pin_hdir_lock(p);
18474 + if (unlikely(err))
18477 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18480 + h_i = h_d[i]->d_inode;
18482 + err = !h_i->i_nlink;
18489 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18491 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18492 + p->hdir->hi_inode->i_mutex.owner = task;
18496 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18499 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18500 + p->lsc_hi, 0, NULL, _RET_IP_);
18501 + au_pin_hdir_set_owner(p, current);
18505 +void au_pin_hdir_release(struct au_pin *p)
18508 + au_pin_hdir_set_owner(p, p->task);
18509 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18513 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18515 + if (pin && pin->parent)
18516 + return au_h_dptr(pin->parent, pin->bindex);
18520 +void au_unpin(struct au_pin *p)
18523 + au_pin_hdir_unlock(p);
18524 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18525 + vfsub_mnt_drop_write(p->h_mnt);
18529 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18530 + di_read_unlock(p->parent, AuLock_IR);
18531 + iput(p->hdir->hi_inode);
18533 + p->parent = NULL;
18536 + /* do not clear p->task */
18539 +int au_do_pin(struct au_pin *p)
18542 + struct super_block *sb;
18543 + struct inode *h_dir;
18546 + sb = p->dentry->d_sb;
18547 + p->br = au_sbr(sb, p->bindex);
18548 + if (IS_ROOT(p->dentry)) {
18549 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18550 + p->h_mnt = au_br_mnt(p->br);
18551 + err = vfsub_mnt_want_write(p->h_mnt);
18552 + if (unlikely(err)) {
18553 + au_fclr_pin(p->flags, MNT_WRITE);
18560 + p->h_dentry = NULL;
18561 + if (p->bindex <= au_dbend(p->dentry))
18562 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18564 + p->parent = dget_parent(p->dentry);
18565 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18566 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18569 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18570 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
18572 + h_dir = p->hdir->hi_inode;
18576 + * if DI_LOCKED is not set, then p->parent may be different
18577 + * and h_parent can be NULL.
18579 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18581 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18582 + di_read_unlock(p->parent, AuLock_IR);
18584 + p->parent = NULL;
18588 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18589 + p->h_mnt = au_br_mnt(p->br);
18590 + err = vfsub_mnt_want_write(p->h_mnt);
18591 + if (unlikely(err)) {
18592 + au_fclr_pin(p->flags, MNT_WRITE);
18593 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18594 + di_read_unlock(p->parent, AuLock_IR);
18596 + p->parent = NULL;
18602 + err = au_pin_hdir_lock(p);
18604 + goto out; /* success */
18609 + pr_err("err %d\n", err);
18610 + err = au_busy_or_stale();
18615 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
18616 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18617 + unsigned int udba, unsigned char flags)
18619 + p->dentry = dentry;
18621 + p->lsc_di = lsc_di;
18622 + p->lsc_hi = lsc_hi;
18623 + p->flags = flags;
18624 + p->bindex = bindex;
18626 + p->parent = NULL;
18630 + p->h_dentry = NULL;
18631 + p->h_parent = NULL;
18633 + p->task = current;
18636 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18637 + unsigned int udba, unsigned char flags)
18639 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
18641 + return au_do_pin(pin);
18644 +/* ---------------------------------------------------------------------- */
18647 + * ->setattr() and ->getattr() are called in various cases.
18648 + * chmod, stat: dentry is revalidated.
18649 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
18651 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
18653 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
18654 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
18657 + struct inode *inode;
18658 + struct dentry *parent;
18661 + inode = dentry->d_inode;
18662 + if (au_digen_test(dentry, sigen)) {
18663 + parent = dget_parent(dentry);
18664 + di_read_lock_parent(parent, AuLock_IR);
18665 + err = au_refresh_dentry(dentry, parent);
18666 + di_read_unlock(parent, AuLock_IR);
18674 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18675 + struct au_icpup_args *a)
18679 + aufs_bindex_t bstart, ibstart;
18680 + struct dentry *hi_wh, *parent;
18681 + struct inode *inode;
18682 + struct au_wr_dir_args wr_dir_args = {
18683 + .force_btgt = -1,
18687 + bstart = au_dbstart(dentry);
18688 + inode = dentry->d_inode;
18689 + if (S_ISDIR(inode->i_mode))
18690 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18691 + /* plink or hi_wh() case */
18692 + ibstart = au_ibstart(inode);
18693 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
18694 + wr_dir_args.force_btgt = ibstart;
18695 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18696 + if (unlikely(err < 0))
18699 + if (err != bstart)
18700 + au_fset_icpup(a->flags, DID_CPUP);
18703 + a->pin_flags = AuPin_MNT_WRITE;
18705 + if (!IS_ROOT(dentry)) {
18706 + au_fset_pin(a->pin_flags, DI_LOCKED);
18707 + parent = dget_parent(dentry);
18708 + di_write_lock_parent(parent);
18711 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
18712 + if (unlikely(err))
18715 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18716 + a->h_inode = a->h_path.dentry->d_inode;
18718 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
18719 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18720 + if (ia->ia_size < i_size_read(a->h_inode))
18721 + sz = ia->ia_size;
18722 + mutex_unlock(&a->h_inode->i_mutex);
18726 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
18727 + hi_wh = au_hi_wh(inode, a->btgt);
18729 + struct au_cp_generic cpg = {
18730 + .dentry = dentry,
18736 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
18737 + if (unlikely(err))
18739 + hi_wh = au_hi_wh(inode, a->btgt);
18740 + /* todo: revalidate hi_wh? */
18745 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
18746 + di_downgrade_lock(parent, AuLock_IR);
18750 + if (!au_ftest_icpup(a->flags, DID_CPUP))
18751 + goto out; /* success */
18753 + if (!d_unhashed(dentry)) {
18754 + struct au_cp_generic cpg = {
18755 + .dentry = dentry,
18760 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18762 + err = au_sio_cpup_simple(&cpg);
18764 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18765 + } else if (!hi_wh)
18766 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18768 + a->h_path.dentry = hi_wh; /* do not dget here */
18771 + a->h_inode = a->h_path.dentry->d_inode;
18773 + goto out; /* success */
18774 + au_unpin(&a->pin);
18777 + di_write_unlock(parent);
18782 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18786 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
18789 + struct inode *inode, *delegated;
18790 + struct super_block *sb;
18791 + struct file *file;
18792 + struct au_icpup_args *a;
18794 + inode = dentry->d_inode;
18795 + IMustLock(inode);
18798 + a = kzalloc(sizeof(*a), GFP_NOFS);
18799 + if (unlikely(!a))
18802 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
18803 + ia->ia_valid &= ~ATTR_MODE;
18806 + sb = dentry->d_sb;
18807 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18808 + if (unlikely(err))
18811 + if (ia->ia_valid & ATTR_FILE) {
18812 + /* currently ftruncate(2) only */
18813 + AuDebugOn(!S_ISREG(inode->i_mode));
18814 + file = ia->ia_file;
18815 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
18816 + if (unlikely(err))
18818 + ia->ia_file = au_hf_top(file);
18819 + a->udba = AuOpt_UDBA_NONE;
18821 + /* fchmod() doesn't pass ia_file */
18822 + a->udba = au_opt_udba(sb);
18823 + di_write_lock_child(dentry);
18824 + /* no d_unlinked(), to set UDBA_NONE for root */
18825 + if (d_unhashed(dentry))
18826 + a->udba = AuOpt_UDBA_NONE;
18827 + if (a->udba != AuOpt_UDBA_NONE) {
18828 + AuDebugOn(IS_ROOT(dentry));
18829 + err = au_reval_for_attr(dentry, au_sigen(sb));
18830 + if (unlikely(err))
18835 + err = au_pin_and_icpup(dentry, ia, a);
18836 + if (unlikely(err < 0))
18838 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
18839 + ia->ia_file = NULL;
18840 + ia->ia_valid &= ~ATTR_FILE;
18843 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
18844 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
18845 + == (ATTR_MODE | ATTR_CTIME)) {
18846 + err = security_path_chmod(&a->h_path, ia->ia_mode);
18847 + if (unlikely(err))
18849 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
18850 + && (ia->ia_valid & ATTR_CTIME)) {
18851 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
18852 + if (unlikely(err))
18856 + if (ia->ia_valid & ATTR_SIZE) {
18859 + if (ia->ia_size < i_size_read(inode))
18861 + truncate_setsize(inode, ia->ia_size);
18864 + if (ia->ia_valid & ATTR_FILE)
18866 + mutex_unlock(&a->h_inode->i_mutex);
18867 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
18868 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18870 + delegated = NULL;
18872 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
18874 + err = break_deleg_wait(&delegated);
18882 + au_cpup_attr_changeable(inode);
18885 + mutex_unlock(&a->h_inode->i_mutex);
18886 + au_unpin(&a->pin);
18887 + if (unlikely(err))
18888 + au_update_dbstart(dentry);
18890 + di_write_unlock(dentry);
18892 + fi_write_unlock(file);
18893 + ia->ia_file = file;
18894 + ia->ia_valid |= ATTR_FILE;
18897 + si_read_unlock(sb);
18905 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18906 +static int au_h_path_to_set_attr(struct dentry *dentry,
18907 + struct au_icpup_args *a, struct path *h_path)
18910 + struct super_block *sb;
18912 + sb = dentry->d_sb;
18913 + a->udba = au_opt_udba(sb);
18914 + /* no d_unlinked(), to set UDBA_NONE for root */
18915 + if (d_unhashed(dentry))
18916 + a->udba = AuOpt_UDBA_NONE;
18917 + if (a->udba != AuOpt_UDBA_NONE) {
18918 + AuDebugOn(IS_ROOT(dentry));
18919 + err = au_reval_for_attr(dentry, au_sigen(sb));
18920 + if (unlikely(err))
18923 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
18924 + if (unlikely(err < 0))
18927 + h_path->dentry = a->h_path.dentry;
18928 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
18934 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
18937 + struct path h_path;
18938 + struct super_block *sb;
18939 + struct au_icpup_args *a;
18940 + struct inode *inode, *h_inode;
18942 + inode = dentry->d_inode;
18943 + IMustLock(inode);
18946 + a = kzalloc(sizeof(*a), GFP_NOFS);
18947 + if (unlikely(!a))
18950 + sb = dentry->d_sb;
18951 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18952 + if (unlikely(err))
18955 + h_path.dentry = NULL; /* silence gcc */
18956 + di_write_lock_child(dentry);
18957 + err = au_h_path_to_set_attr(dentry, a, &h_path);
18958 + if (unlikely(err))
18961 + mutex_unlock(&a->h_inode->i_mutex);
18962 + switch (arg->type) {
18963 + case AU_XATTR_SET:
18964 + err = vfsub_setxattr(h_path.dentry,
18965 + arg->u.set.name, arg->u.set.value,
18966 + arg->u.set.size, arg->u.set.flags);
18968 + case AU_XATTR_REMOVE:
18969 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
18972 + err = -EOPNOTSUPP;
18973 + h_inode = h_path.dentry->d_inode;
18974 + if (h_inode->i_op->set_acl)
18975 + err = h_inode->i_op->set_acl(h_inode,
18976 + arg->u.acl_set.acl,
18977 + arg->u.acl_set.type);
18981 + au_cpup_attr_timesizes(inode);
18983 + au_unpin(&a->pin);
18984 + if (unlikely(err))
18985 + au_update_dbstart(dentry);
18988 + di_write_unlock(dentry);
18989 + si_read_unlock(sb);
18998 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
18999 + unsigned int nlink)
19003 + inode->i_mode = st->mode;
19004 + /* don't i_[ug]id_write() here */
19005 + inode->i_uid = st->uid;
19006 + inode->i_gid = st->gid;
19007 + inode->i_atime = st->atime;
19008 + inode->i_mtime = st->mtime;
19009 + inode->i_ctime = st->ctime;
19011 + au_cpup_attr_nlink(inode, /*force*/0);
19012 + if (S_ISDIR(inode->i_mode)) {
19013 + n = inode->i_nlink;
19016 + smp_mb(); /* for i_nlink */
19017 + /* 0 can happen */
19018 + set_nlink(inode, n);
19021 + spin_lock(&inode->i_lock);
19022 + inode->i_blocks = st->blocks;
19023 + i_size_write(inode, st->size);
19024 + spin_unlock(&inode->i_lock);
19028 + * common routine for aufs_getattr() and aufs_getxattr().
19029 + * returns zero or negative (an error).
19030 + * @dentry will be read-locked in success.
19032 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19035 + unsigned int mnt_flags, sigen;
19036 + unsigned char udba_none;
19037 + aufs_bindex_t bindex;
19038 + struct super_block *sb, *h_sb;
19039 + struct inode *inode;
19041 + h_path->mnt = NULL;
19042 + h_path->dentry = NULL;
19045 + sb = dentry->d_sb;
19046 + mnt_flags = au_mntflags(sb);
19047 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19049 + /* support fstat(2) */
19050 + if (!d_unlinked(dentry) && !udba_none) {
19051 + sigen = au_sigen(sb);
19052 + err = au_digen_test(dentry, sigen);
19054 + di_read_lock_child(dentry, AuLock_IR);
19055 + err = au_dbrange_test(dentry);
19056 + if (unlikely(err)) {
19057 + di_read_unlock(dentry, AuLock_IR);
19061 + AuDebugOn(IS_ROOT(dentry));
19062 + di_write_lock_child(dentry);
19063 + err = au_dbrange_test(dentry);
19065 + err = au_reval_for_attr(dentry, sigen);
19067 + di_downgrade_lock(dentry, AuLock_IR);
19069 + di_write_unlock(dentry);
19074 + di_read_lock_child(dentry, AuLock_IR);
19076 + inode = dentry->d_inode;
19077 + bindex = au_ibstart(inode);
19078 + h_path->mnt = au_sbr_mnt(sb, bindex);
19079 + h_sb = h_path->mnt->mnt_sb;
19081 + && !au_test_fs_bad_iattr(h_sb)
19083 + goto out; /* success */
19085 + if (au_dbstart(dentry) == bindex)
19086 + h_path->dentry = au_h_dptr(dentry, bindex);
19087 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19088 + h_path->dentry = au_plink_lkup(inode, bindex);
19089 + if (IS_ERR(h_path->dentry))
19090 + /* pretending success */
19091 + h_path->dentry = NULL;
19093 + dput(h_path->dentry);
19100 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19101 + struct dentry *dentry, struct kstat *st)
19104 + unsigned char positive;
19105 + struct path h_path;
19106 + struct inode *inode;
19107 + struct super_block *sb;
19109 + inode = dentry->d_inode;
19110 + sb = dentry->d_sb;
19111 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19112 + if (unlikely(err))
19114 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19115 + if (unlikely(err))
19117 + if (unlikely(!h_path.dentry))
19118 + /* illegally overlapped or something */
19119 + goto out_fill; /* pretending success */
19121 + positive = !!h_path.dentry->d_inode;
19123 + err = vfs_getattr(&h_path, st);
19126 + au_refresh_iattr(inode, st,
19127 + h_path.dentry->d_inode->i_nlink);
19128 + goto out_fill; /* success */
19134 + generic_fillattr(inode, st);
19136 + di_read_unlock(dentry, AuLock_IR);
19138 + si_read_unlock(sb);
19144 +/* ---------------------------------------------------------------------- */
19146 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
19150 + struct super_block *sb;
19151 + struct dentry *h_dentry;
19154 + h_dentry = au_h_dptr(dentry, bindex);
19155 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
19158 + err = security_inode_readlink(h_dentry);
19159 + if (unlikely(err))
19162 + sb = dentry->d_sb;
19163 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
19164 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
19165 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
19167 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
19173 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
19177 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19178 + if (unlikely(err))
19180 + err = au_d_hashed_positive(dentry);
19182 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
19183 + aufs_read_unlock(dentry, AuLock_IR);
19189 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
19192 + mm_segment_t old_fs;
19199 + buf.k = (void *)__get_free_page(GFP_NOFS);
19200 + if (unlikely(!buf.k))
19203 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19204 + if (unlikely(err))
19207 + err = au_d_hashed_positive(dentry);
19209 + old_fs = get_fs();
19210 + set_fs(KERNEL_DS);
19211 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
19214 + aufs_read_unlock(dentry, AuLock_IR);
19218 + /* will be freed by put_link */
19219 + nd_set_link(nd, buf.k);
19220 + return NULL; /* success */
19224 + free_page((unsigned long)buf.k);
19227 + return ERR_PTR(err);
19230 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
19231 + struct nameidata *nd, void *cookie __maybe_unused)
19235 + p = nd_get_link(nd);
19236 + if (!IS_ERR_OR_NULL(p))
19237 + free_page((unsigned long)p);
19240 +/* ---------------------------------------------------------------------- */
19242 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19245 + struct super_block *sb;
19246 + struct inode *h_inode;
19248 + sb = inode->i_sb;
19249 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19251 + si_read_lock(sb, AuLock_FLUSH);
19252 + ii_write_lock_child(inode);
19254 + h_inode = au_h_iptr(inode, au_ibstart(inode));
19255 + err = vfsub_update_time(h_inode, ts, flags);
19258 + au_cpup_attr_timesizes(inode);
19259 + ii_write_unlock(inode);
19260 + si_read_unlock(sb);
19263 + if (!err && (flags & S_VERSION))
19264 + inode_inc_iversion(inode);
19269 +/* ---------------------------------------------------------------------- */
19271 +struct inode_operations aufs_symlink_iop = {
19272 + .permission = aufs_permission,
19273 +#ifdef CONFIG_FS_POSIX_ACL
19274 + .get_acl = aufs_get_acl,
19275 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19278 + .setattr = aufs_setattr,
19279 + .getattr = aufs_getattr,
19281 +#ifdef CONFIG_AUFS_XATTR
19282 + .setxattr = aufs_setxattr,
19283 + .getxattr = aufs_getxattr,
19284 + .listxattr = aufs_listxattr,
19285 + .removexattr = aufs_removexattr,
19288 + .readlink = aufs_readlink,
19289 + .follow_link = aufs_follow_link,
19290 + .put_link = aufs_put_link,
19292 + /* .update_time = aufs_update_time */
19295 +struct inode_operations aufs_dir_iop = {
19296 + .create = aufs_create,
19297 + .lookup = aufs_lookup,
19298 + .link = aufs_link,
19299 + .unlink = aufs_unlink,
19300 + .symlink = aufs_symlink,
19301 + .mkdir = aufs_mkdir,
19302 + .rmdir = aufs_rmdir,
19303 + .mknod = aufs_mknod,
19304 + .rename = aufs_rename,
19306 + .permission = aufs_permission,
19307 +#ifdef CONFIG_FS_POSIX_ACL
19308 + .get_acl = aufs_get_acl,
19309 + .set_acl = aufs_set_acl,
19312 + .setattr = aufs_setattr,
19313 + .getattr = aufs_getattr,
19315 +#ifdef CONFIG_AUFS_XATTR
19316 + .setxattr = aufs_setxattr,
19317 + .getxattr = aufs_getxattr,
19318 + .listxattr = aufs_listxattr,
19319 + .removexattr = aufs_removexattr,
19322 + .update_time = aufs_update_time,
19323 + /* no support for atomic_open() */
19325 + .tmpfile = aufs_tmpfile
19328 +struct inode_operations aufs_iop = {
19329 + .permission = aufs_permission,
19330 +#ifdef CONFIG_FS_POSIX_ACL
19331 + .get_acl = aufs_get_acl,
19332 + .set_acl = aufs_set_acl,
19335 + .setattr = aufs_setattr,
19336 + .getattr = aufs_getattr,
19338 +#ifdef CONFIG_AUFS_XATTR
19339 + .setxattr = aufs_setxattr,
19340 + .getxattr = aufs_getxattr,
19341 + .listxattr = aufs_listxattr,
19342 + .removexattr = aufs_removexattr,
19345 + .update_time = aufs_update_time
19347 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19348 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19349 +++ linux/fs/aufs/i_op_del.c 2015-01-25 13:00:38.631047076 +0100
19352 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19354 + * This program, aufs is free software; you can redistribute it and/or modify
19355 + * it under the terms of the GNU General Public License as published by
19356 + * the Free Software Foundation; either version 2 of the License, or
19357 + * (at your option) any later version.
19359 + * This program is distributed in the hope that it will be useful,
19360 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19361 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19362 + * GNU General Public License for more details.
19364 + * You should have received a copy of the GNU General Public License
19365 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19369 + * inode operations (del entry)
19375 + * decide if a new whiteout for @dentry is necessary or not.
19376 + * when it is necessary, prepare the parent dir for the upper branch whose
19377 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19378 + * be done by caller.
19380 + * 0: wh is unnecessary
19381 + * plus: wh is necessary
19384 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19386 + int need_wh, err;
19387 + aufs_bindex_t bstart;
19388 + struct super_block *sb;
19390 + sb = dentry->d_sb;
19391 + bstart = au_dbstart(dentry);
19392 + if (*bcpup < 0) {
19394 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
19395 + err = AuWbrCopyup(au_sbi(sb), dentry);
19397 + if (unlikely(err < 0))
19401 + AuDebugOn(bstart < *bcpup
19402 + || au_test_ro(sb, *bcpup, dentry->d_inode));
19403 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19405 + if (*bcpup != bstart) {
19406 + err = au_cpup_dirs(dentry, *bcpup);
19407 + if (unlikely(err))
19411 + struct au_dinfo *dinfo, *tmp;
19413 + need_wh = -ENOMEM;
19414 + dinfo = au_di(dentry);
19415 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19417 + au_di_cp(tmp, dinfo);
19418 + au_di_swap(tmp, dinfo);
19419 + /* returns the number of positive dentries */
19420 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19421 + au_di_swap(tmp, dinfo);
19422 + au_rw_write_unlock(&tmp->di_rwsem);
19426 + AuDbg("need_wh %d\n", need_wh);
19434 + * simple tests for the del-entry operations.
19435 + * following the checks in vfs, plus the parent-child relationship.
19437 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19438 + struct dentry *h_parent, int isdir)
19442 + struct dentry *h_dentry, *h_latest;
19443 + struct inode *h_inode;
19445 + h_dentry = au_h_dptr(dentry, bindex);
19446 + h_inode = h_dentry->d_inode;
19447 + if (dentry->d_inode) {
19449 + if (unlikely(!h_inode || !h_inode->i_nlink))
19452 + h_mode = h_inode->i_mode;
19455 + if (unlikely(S_ISDIR(h_mode)))
19457 + } else if (unlikely(!S_ISDIR(h_mode))) {
19462 + /* rename(2) case */
19464 + if (unlikely(h_inode))
19469 + /* expected parent dir is locked */
19470 + if (unlikely(h_parent != h_dentry->d_parent))
19475 + * rmdir a dir may break the consistency on some filesystem.
19476 + * let's try heavy test.
19479 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19480 + && au_test_h_perm(h_parent->d_inode,
19481 + MAY_EXEC | MAY_WRITE)))
19484 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19486 + if (IS_ERR(h_latest))
19488 + if (h_latest == h_dentry)
19497 + * decide the branch where we operate for @dentry. the branch index will be set
19498 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19499 + * dir for reverting.
19500 + * when a new whiteout is necessary, create it.
19502 +static struct dentry*
19503 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19504 + struct au_dtime *dt, struct au_pin *pin)
19506 + struct dentry *wh_dentry;
19507 + struct super_block *sb;
19508 + struct path h_path;
19509 + int err, need_wh;
19510 + unsigned int udba;
19511 + aufs_bindex_t bcpup;
19513 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19514 + wh_dentry = ERR_PTR(need_wh);
19515 + if (unlikely(need_wh < 0))
19518 + sb = dentry->d_sb;
19519 + udba = au_opt_udba(sb);
19521 + err = au_pin(pin, dentry, bcpup, udba,
19522 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19523 + wh_dentry = ERR_PTR(err);
19524 + if (unlikely(err))
19527 + h_path.dentry = au_pinned_h_parent(pin);
19528 + if (udba != AuOpt_UDBA_NONE
19529 + && au_dbstart(dentry) == bcpup) {
19530 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19531 + wh_dentry = ERR_PTR(err);
19532 + if (unlikely(err))
19536 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19537 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19538 + wh_dentry = NULL;
19540 + goto out; /* success, no need to create whiteout */
19542 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19543 + if (IS_ERR(wh_dentry))
19546 + /* returns with the parent is locked and wh_dentry is dget-ed */
19547 + goto out; /* success */
19552 + return wh_dentry;
19556 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19557 + * in order to be revertible and save time for removing many child whiteouts
19559 + * returns 1 when there are too many child whiteout and caller should remove
19560 + * them asynchronously. returns 0 when the number of children is enough small to
19561 + * remove now or the branch fs is a remote fs.
19562 + * otherwise return an error.
19564 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19565 + struct au_nhash *whlist, struct inode *dir)
19567 + int rmdir_later, err, dirwh;
19568 + struct dentry *h_dentry;
19569 + struct super_block *sb;
19571 + sb = dentry->d_sb;
19572 + SiMustAnyLock(sb);
19573 + h_dentry = au_h_dptr(dentry, bindex);
19574 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19575 + if (unlikely(err))
19578 + /* stop monitoring */
19579 + au_hn_free(au_hi(dentry->d_inode, bindex));
19581 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19582 + dirwh = au_sbi(sb)->si_dirwh;
19583 + rmdir_later = (dirwh <= 1);
19584 + if (!rmdir_later)
19585 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19588 + return rmdir_later;
19591 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19592 + if (unlikely(err)) {
19593 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19594 + h_dentry, bindex, err);
19604 + * final procedure for deleting a entry.
19605 + * maintain dentry and iattr.
19607 +static void epilog(struct inode *dir, struct dentry *dentry,
19608 + aufs_bindex_t bindex)
19610 + struct inode *inode;
19612 + inode = dentry->d_inode;
19614 + inode->i_ctime = dir->i_ctime;
19616 + if (au_ibstart(dir) == bindex)
19617 + au_cpup_attr_timesizes(dir);
19618 + dir->i_version++;
19622 + * when an error happened, remove the created whiteout and revert everything.
19624 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
19625 + aufs_bindex_t bwh, struct dentry *wh_dentry,
19626 + struct dentry *dentry, struct au_dtime *dt)
19629 + struct path h_path = {
19630 + .dentry = wh_dentry,
19631 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
19634 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
19636 + au_set_dbwh(dentry, bwh);
19637 + au_dtime_revert(dt);
19641 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
19645 +/* ---------------------------------------------------------------------- */
19647 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
19650 + aufs_bindex_t bwh, bindex, bstart;
19651 + struct inode *inode, *h_dir, *delegated;
19652 + struct dentry *parent, *wh_dentry;
19653 + /* to reuduce stack size */
19655 + struct au_dtime dt;
19656 + struct au_pin pin;
19657 + struct path h_path;
19663 + a = kmalloc(sizeof(*a), GFP_NOFS);
19664 + if (unlikely(!a))
19667 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19668 + if (unlikely(err))
19670 + err = au_d_hashed_positive(dentry);
19671 + if (unlikely(err))
19673 + inode = dentry->d_inode;
19674 + IMustLock(inode);
19676 + if (unlikely(S_ISDIR(inode->i_mode)))
19677 + goto out_unlock; /* possible? */
19679 + bstart = au_dbstart(dentry);
19680 + bwh = au_dbwh(dentry);
19682 + parent = dentry->d_parent; /* dir inode is locked */
19683 + di_write_lock_parent(parent);
19684 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
19686 + err = PTR_ERR(wh_dentry);
19687 + if (IS_ERR(wh_dentry))
19690 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
19691 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19692 + dget(a->h_path.dentry);
19693 + if (bindex == bstart) {
19694 + h_dir = au_pinned_h_dir(&a->pin);
19695 + delegated = NULL;
19696 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
19697 + if (unlikely(err == -EWOULDBLOCK)) {
19698 + pr_warn("cannot retry for NFSv4 delegation"
19699 + " for an internal unlink\n");
19703 + /* dir inode is locked */
19704 + h_dir = wh_dentry->d_parent->d_inode;
19705 + IMustLock(h_dir);
19710 + vfsub_drop_nlink(inode);
19711 + epilog(dir, dentry, bindex);
19713 + /* update target timestamps */
19714 + if (bindex == bstart) {
19715 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
19717 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
19719 + /* todo: this timestamp may be reverted later */
19720 + inode->i_ctime = h_dir->i_ctime;
19721 + goto out_unpin; /* success */
19728 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19735 + au_unpin(&a->pin);
19737 + dput(a->h_path.dentry);
19739 + di_write_unlock(parent);
19741 + aufs_read_unlock(dentry, AuLock_DW);
19748 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
19750 + int err, rmdir_later;
19751 + aufs_bindex_t bwh, bindex, bstart;
19752 + struct inode *inode;
19753 + struct dentry *parent, *wh_dentry, *h_dentry;
19754 + struct au_whtmp_rmdir *args;
19755 + /* to reuduce stack size */
19757 + struct au_dtime dt;
19758 + struct au_pin pin;
19764 + a = kmalloc(sizeof(*a), GFP_NOFS);
19765 + if (unlikely(!a))
19768 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
19769 + if (unlikely(err))
19771 + err = au_alive_dir(dentry);
19772 + if (unlikely(err))
19774 + inode = dentry->d_inode;
19775 + IMustLock(inode);
19777 + if (unlikely(!S_ISDIR(inode->i_mode)))
19778 + goto out_unlock; /* possible? */
19781 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
19782 + if (unlikely(!args))
19785 + parent = dentry->d_parent; /* dir inode is locked */
19786 + di_write_lock_parent(parent);
19787 + err = au_test_empty(dentry, &args->whlist);
19788 + if (unlikely(err))
19791 + bstart = au_dbstart(dentry);
19792 + bwh = au_dbwh(dentry);
19794 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
19796 + err = PTR_ERR(wh_dentry);
19797 + if (IS_ERR(wh_dentry))
19800 + h_dentry = au_h_dptr(dentry, bstart);
19803 + if (bindex == bstart) {
19804 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
19806 + rmdir_later = err;
19810 + /* stop monitoring */
19811 + au_hn_free(au_hi(inode, bstart));
19813 + /* dir inode is locked */
19814 + IMustLock(wh_dentry->d_parent->d_inode);
19819 + vfsub_dead_dir(inode);
19820 + au_set_dbdiropq(dentry, -1);
19821 + epilog(dir, dentry, bindex);
19823 + if (rmdir_later) {
19824 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
19828 + goto out_unpin; /* success */
19836 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19843 + au_unpin(&a->pin);
19847 + di_write_unlock(parent);
19849 + au_whtmp_rmdir_free(args);
19851 + aufs_read_unlock(dentry, AuLock_DW);
19858 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
19859 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
19860 +++ linux/fs/aufs/i_op_ren.c 2015-01-25 13:00:38.631047076 +0100
19863 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19865 + * This program, aufs is free software; you can redistribute it and/or modify
19866 + * it under the terms of the GNU General Public License as published by
19867 + * the Free Software Foundation; either version 2 of the License, or
19868 + * (at your option) any later version.
19870 + * This program is distributed in the hope that it will be useful,
19871 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19872 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19873 + * GNU General Public License for more details.
19875 + * You should have received a copy of the GNU General Public License
19876 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19880 + * inode operation (rename entry)
19881 + * todo: this is crazy monster
19886 +enum { AuSRC, AuDST, AuSrcDst };
19887 +enum { AuPARENT, AuCHILD, AuParentChild };
19889 +#define AuRen_ISDIR 1
19890 +#define AuRen_ISSAMEDIR (1 << 1)
19891 +#define AuRen_WHSRC (1 << 2)
19892 +#define AuRen_WHDST (1 << 3)
19893 +#define AuRen_MNT_WRITE (1 << 4)
19894 +#define AuRen_DT_DSTDIR (1 << 5)
19895 +#define AuRen_DIROPQ (1 << 6)
19896 +#define AuRen_CPUP (1 << 7)
19897 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
19898 +#define au_fset_ren(flags, name) \
19899 + do { (flags) |= AuRen_##name; } while (0)
19900 +#define au_fclr_ren(flags, name) \
19901 + do { (flags) &= ~AuRen_##name; } while (0)
19903 +struct au_ren_args {
19905 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
19907 + struct inode *dir, *inode;
19908 + struct au_hinode *hdir;
19909 + struct au_dtime dt[AuParentChild];
19910 + aufs_bindex_t bstart;
19913 +#define src_dentry sd[AuSRC].dentry
19914 +#define src_dir sd[AuSRC].dir
19915 +#define src_inode sd[AuSRC].inode
19916 +#define src_h_dentry sd[AuSRC].h_dentry
19917 +#define src_parent sd[AuSRC].parent
19918 +#define src_h_parent sd[AuSRC].h_parent
19919 +#define src_wh_dentry sd[AuSRC].wh_dentry
19920 +#define src_hdir sd[AuSRC].hdir
19921 +#define src_h_dir sd[AuSRC].hdir->hi_inode
19922 +#define src_dt sd[AuSRC].dt
19923 +#define src_bstart sd[AuSRC].bstart
19925 +#define dst_dentry sd[AuDST].dentry
19926 +#define dst_dir sd[AuDST].dir
19927 +#define dst_inode sd[AuDST].inode
19928 +#define dst_h_dentry sd[AuDST].h_dentry
19929 +#define dst_parent sd[AuDST].parent
19930 +#define dst_h_parent sd[AuDST].h_parent
19931 +#define dst_wh_dentry sd[AuDST].wh_dentry
19932 +#define dst_hdir sd[AuDST].hdir
19933 +#define dst_h_dir sd[AuDST].hdir->hi_inode
19934 +#define dst_dt sd[AuDST].dt
19935 +#define dst_bstart sd[AuDST].bstart
19937 + struct dentry *h_trap;
19938 + struct au_branch *br;
19939 + struct au_hinode *src_hinode;
19940 + struct path h_path;
19941 + struct au_nhash whlist;
19942 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
19944 + unsigned int flags;
19946 + struct au_whtmp_rmdir *thargs;
19947 + struct dentry *h_dst;
19950 +/* ---------------------------------------------------------------------- */
19953 + * functions for reverting.
19954 + * when an error happened in a single rename systemcall, we should revert
19955 + * everything as if nothing happend.
19956 + * we don't need to revert the copied-up/down the parent dir since they are
19960 +#define RevertFailure(fmt, ...) do { \
19961 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
19962 + ##__VA_ARGS__, err, rerr); \
19966 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
19970 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
19971 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
19972 + au_hn_imtx_unlock(a->src_hinode);
19973 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
19975 + RevertFailure("remove diropq %pd", a->src_dentry);
19978 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
19981 + struct inode *delegated;
19983 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
19984 + a->src_h_parent);
19985 + rerr = PTR_ERR(a->h_path.dentry);
19986 + if (IS_ERR(a->h_path.dentry)) {
19987 + RevertFailure("lkup one %pd", a->src_dentry);
19991 + delegated = NULL;
19992 + rerr = vfsub_rename(a->dst_h_dir,
19993 + au_h_dptr(a->src_dentry, a->btgt),
19994 + a->src_h_dir, &a->h_path, &delegated);
19995 + if (unlikely(rerr == -EWOULDBLOCK)) {
19996 + pr_warn("cannot retry for NFSv4 delegation"
19997 + " for an internal rename\n");
20000 + d_drop(a->h_path.dentry);
20001 + dput(a->h_path.dentry);
20002 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20004 + RevertFailure("rename %pd", a->src_dentry);
20007 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
20011 + a->h_path.dentry = a->dst_h_dentry;
20012 + /* no delegation since it is just created */
20013 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL,
20015 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
20016 + au_set_dbstart(a->src_dentry, a->src_bstart);
20018 + RevertFailure("unlink %pd", a->dst_h_dentry);
20021 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20024 + struct inode *delegated;
20026 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20027 + a->dst_h_parent);
20028 + rerr = PTR_ERR(a->h_path.dentry);
20029 + if (IS_ERR(a->h_path.dentry)) {
20030 + RevertFailure("lkup one %pd", a->dst_dentry);
20033 + if (a->h_path.dentry->d_inode) {
20034 + d_drop(a->h_path.dentry);
20035 + dput(a->h_path.dentry);
20039 + delegated = NULL;
20040 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20042 + if (unlikely(rerr == -EWOULDBLOCK)) {
20043 + pr_warn("cannot retry for NFSv4 delegation"
20044 + " for an internal rename\n");
20047 + d_drop(a->h_path.dentry);
20048 + dput(a->h_path.dentry);
20050 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20052 + RevertFailure("rename %pd", a->h_dst);
20055 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20059 + a->h_path.dentry = a->src_wh_dentry;
20060 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20061 + au_set_dbwh(a->src_dentry, a->src_bwh);
20063 + RevertFailure("unlink %pd", a->src_wh_dentry);
20065 +#undef RevertFailure
20067 +/* ---------------------------------------------------------------------- */
20070 + * when we have to copyup the renaming entry, do it with the rename-target name
20071 + * in order to minimize the cost (the later actual rename is unnecessary).
20072 + * otherwise rename it on the target branch.
20074 +static int au_ren_or_cpup(struct au_ren_args *a)
20077 + struct dentry *d;
20078 + struct inode *delegated;
20080 + d = a->src_dentry;
20081 + if (au_dbstart(d) == a->btgt) {
20082 + a->h_path.dentry = a->dst_h_dentry;
20083 + if (au_ftest_ren(a->flags, DIROPQ)
20084 + && au_dbdiropq(d) == a->btgt)
20085 + au_fclr_ren(a->flags, DIROPQ);
20086 + AuDebugOn(au_dbstart(d) != a->btgt);
20087 + delegated = NULL;
20088 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20089 + a->dst_h_dir, &a->h_path, &delegated);
20090 + if (unlikely(err == -EWOULDBLOCK)) {
20091 + pr_warn("cannot retry for NFSv4 delegation"
20092 + " for an internal rename\n");
20098 + if (!err && a->h_dst)
20099 + /* it will be set to dinfo later */
20105 +/* cf. aufs_rmdir() */
20106 +static int au_ren_del_whtmp(struct au_ren_args *a)
20109 + struct inode *dir;
20111 + dir = a->dst_dir;
20112 + SiMustAnyLock(dir->i_sb);
20113 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20114 + au_sbi(dir->i_sb)->si_dirwh)
20115 + || au_test_fs_remote(a->h_dst->d_sb)) {
20116 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20117 + if (unlikely(err))
20118 + pr_warn("failed removing whtmp dir %pd (%d), "
20119 + "ignored.\n", a->h_dst, err);
20121 + au_nhash_wh_free(&a->thargs->whlist);
20122 + a->thargs->whlist = a->whlist;
20123 + a->whlist.nh_num = 0;
20124 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20126 + a->thargs = NULL;
20132 +/* make it 'opaque' dir. */
20133 +static int au_ren_diropq(struct au_ren_args *a)
20136 + struct dentry *diropq;
20139 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20140 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20141 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20142 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20143 + au_hn_imtx_unlock(a->src_hinode);
20144 + if (IS_ERR(diropq))
20145 + err = PTR_ERR(diropq);
20152 +static int do_rename(struct au_ren_args *a)
20155 + struct dentry *d, *h_d;
20157 + /* prepare workqueue args for asynchronous rmdir */
20158 + h_d = a->dst_h_dentry;
20159 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
20161 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20162 + if (unlikely(!a->thargs))
20164 + a->h_dst = dget(h_d);
20167 + /* create whiteout for src_dentry */
20168 + if (au_ftest_ren(a->flags, WHSRC)) {
20169 + a->src_bwh = au_dbwh(a->src_dentry);
20170 + AuDebugOn(a->src_bwh >= 0);
20172 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20173 + err = PTR_ERR(a->src_wh_dentry);
20174 + if (IS_ERR(a->src_wh_dentry))
20178 + /* lookup whiteout for dentry */
20179 + if (au_ftest_ren(a->flags, WHDST)) {
20180 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20182 + err = PTR_ERR(h_d);
20185 + if (!h_d->d_inode)
20188 + a->dst_wh_dentry = h_d;
20191 + /* rename dentry to tmpwh */
20193 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20194 + if (unlikely(err))
20197 + d = a->dst_dentry;
20198 + au_set_h_dptr(d, a->btgt, NULL);
20199 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20200 + if (unlikely(err))
20202 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20205 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
20207 + /* rename by vfs_rename or cpup */
20208 + d = a->dst_dentry;
20209 + if (au_ftest_ren(a->flags, ISDIR)
20210 + && (a->dst_wh_dentry
20211 + || au_dbdiropq(d) == a->btgt
20212 + /* hide the lower to keep xino */
20213 + || a->btgt < au_dbend(d)
20214 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20215 + au_fset_ren(a->flags, DIROPQ);
20216 + err = au_ren_or_cpup(a);
20217 + if (unlikely(err))
20218 + /* leave the copied-up one */
20221 + /* make dir opaque */
20222 + if (au_ftest_ren(a->flags, DIROPQ)) {
20223 + err = au_ren_diropq(a);
20224 + if (unlikely(err))
20228 + /* update target timestamps */
20229 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
20230 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20231 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20232 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
20234 + /* remove whiteout for dentry */
20235 + if (a->dst_wh_dentry) {
20236 + a->h_path.dentry = a->dst_wh_dentry;
20237 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20239 + if (unlikely(err))
20243 + /* remove whtmp */
20245 + au_ren_del_whtmp(a); /* ignore this error */
20247 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20249 + goto out_success;
20252 + if (au_ftest_ren(a->flags, DIROPQ))
20253 + au_ren_rev_diropq(err, a);
20255 + if (!au_ftest_ren(a->flags, CPUP))
20256 + au_ren_rev_rename(err, a);
20258 + au_ren_rev_cpup(err, a);
20262 + au_ren_rev_whtmp(err, a);
20264 + dput(a->dst_wh_dentry);
20265 + a->dst_wh_dentry = NULL;
20267 + if (a->src_wh_dentry)
20268 + au_ren_rev_whsrc(err, a);
20270 + dput(a->src_wh_dentry);
20271 + dput(a->dst_wh_dentry);
20275 + au_whtmp_rmdir_free(a->thargs);
20276 + a->thargs = NULL;
20282 +/* ---------------------------------------------------------------------- */
20285 + * test if @dentry dir can be rename destination or not.
20286 + * success means, it is a logically empty dir.
20288 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20290 + return au_test_empty(dentry, whlist);
20294 + * test if @dentry dir can be rename source or not.
20295 + * if it can, return 0 and @children is filled.
20297 + * - it is a logically empty dir.
20298 + * - or, it exists on writable branch and has no children including whiteouts
20299 + * on the lower branch.
20301 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20304 + unsigned int rdhash;
20305 + aufs_bindex_t bstart;
20307 + bstart = au_dbstart(dentry);
20308 + if (bstart != btgt) {
20309 + struct au_nhash whlist;
20311 + SiMustAnyLock(dentry->d_sb);
20312 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20314 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20316 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20317 + if (unlikely(err))
20319 + err = au_test_empty(dentry, &whlist);
20320 + au_nhash_wh_free(&whlist);
20324 + if (bstart == au_dbtaildir(dentry))
20325 + return 0; /* success */
20327 + err = au_test_empty_lower(dentry);
20330 + if (err == -ENOTEMPTY) {
20331 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20332 + " is not supported\n");
20338 +/* side effect: sets whlist and h_dentry */
20339 +static int au_ren_may_dir(struct au_ren_args *a)
20342 + unsigned int rdhash;
20343 + struct dentry *d;
20345 + d = a->dst_dentry;
20346 + SiMustAnyLock(d->d_sb);
20349 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20350 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20352 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20353 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20354 + if (unlikely(err))
20357 + au_set_dbstart(d, a->dst_bstart);
20358 + err = may_rename_dstdir(d, &a->whlist);
20359 + au_set_dbstart(d, a->btgt);
20361 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
20362 + if (unlikely(err))
20365 + d = a->src_dentry;
20366 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
20367 + if (au_ftest_ren(a->flags, ISDIR)) {
20368 + err = may_rename_srcdir(d, a->btgt);
20369 + if (unlikely(err)) {
20370 + au_nhash_wh_free(&a->whlist);
20371 + a->whlist.nh_num = 0;
20378 +/* ---------------------------------------------------------------------- */
20381 + * simple tests for rename.
20382 + * following the checks in vfs, plus the parent-child relationship.
20384 +static int au_may_ren(struct au_ren_args *a)
20387 + struct inode *h_inode;
20389 + if (a->src_bstart == a->btgt) {
20390 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20391 + au_ftest_ren(a->flags, ISDIR));
20392 + if (unlikely(err))
20395 + if (unlikely(a->src_h_dentry == a->h_trap))
20400 + if (a->dst_bstart != a->btgt)
20403 + err = -ENOTEMPTY;
20404 + if (unlikely(a->dst_h_dentry == a->h_trap))
20408 + h_inode = a->dst_h_dentry->d_inode;
20409 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20410 + if (!a->dst_dentry->d_inode) {
20411 + if (unlikely(h_inode))
20413 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
20416 + if (unlikely(!h_inode || !h_inode->i_nlink))
20418 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
20420 + if (unlikely(err))
20425 + if (unlikely(err == -ENOENT || err == -EEXIST))
20431 +/* ---------------------------------------------------------------------- */
20436 + * - src_dir and dir by lock_rename()
20437 + * - inode if exitsts
20440 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20442 + * + di_write_lock2_child()
20443 + * + di_write_lock_child()
20444 + * + ii_write_lock_child()
20445 + * + di_write_lock_child2()
20446 + * + ii_write_lock_child2()
20447 + * + src_parent and parent
20448 + * + di_write_lock_parent()
20449 + * + ii_write_lock_parent()
20450 + * + di_write_lock_parent2()
20451 + * + ii_write_lock_parent2()
20452 + * + lower src_dir and dir by vfsub_lock_rename()
20453 + * + verify the every relationships between child and parent. if any
20454 + * of them failed, unlock all and return -EBUSY.
20456 +static void au_ren_unlock(struct au_ren_args *a)
20458 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20459 + a->dst_h_parent, a->dst_hdir);
20460 + if (au_ftest_ren(a->flags, MNT_WRITE))
20461 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20464 +static int au_ren_lock(struct au_ren_args *a)
20467 + unsigned int udba;
20470 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20471 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20472 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20473 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20475 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20476 + if (unlikely(err))
20478 + au_fset_ren(a->flags, MNT_WRITE);
20479 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20480 + a->dst_h_parent, a->dst_hdir);
20481 + udba = au_opt_udba(a->src_dentry->d_sb);
20482 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
20483 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
20484 + err = au_busy_or_stale();
20485 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20486 + err = au_h_verify(a->src_h_dentry, udba,
20487 + a->src_h_parent->d_inode, a->src_h_parent,
20489 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20490 + err = au_h_verify(a->dst_h_dentry, udba,
20491 + a->dst_h_parent->d_inode, a->dst_h_parent,
20494 + goto out; /* success */
20496 + err = au_busy_or_stale();
20497 + au_ren_unlock(a);
20503 +/* ---------------------------------------------------------------------- */
20505 +static void au_ren_refresh_dir(struct au_ren_args *a)
20507 + struct inode *dir;
20509 + dir = a->dst_dir;
20510 + dir->i_version++;
20511 + if (au_ftest_ren(a->flags, ISDIR)) {
20512 + /* is this updating defined in POSIX? */
20513 + au_cpup_attr_timesizes(a->src_inode);
20514 + au_cpup_attr_nlink(dir, /*force*/1);
20517 + if (au_ibstart(dir) == a->btgt)
20518 + au_cpup_attr_timesizes(dir);
20520 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20523 + dir = a->src_dir;
20524 + dir->i_version++;
20525 + if (au_ftest_ren(a->flags, ISDIR))
20526 + au_cpup_attr_nlink(dir, /*force*/1);
20527 + if (au_ibstart(dir) == a->btgt)
20528 + au_cpup_attr_timesizes(dir);
20531 +static void au_ren_refresh(struct au_ren_args *a)
20533 + aufs_bindex_t bend, bindex;
20534 + struct dentry *d, *h_d;
20535 + struct inode *i, *h_i;
20536 + struct super_block *sb;
20538 + d = a->dst_dentry;
20541 + /* already dget-ed by au_ren_or_cpup() */
20542 + au_set_h_dptr(d, a->btgt, a->h_dst);
20544 + i = a->dst_inode;
20546 + if (!au_ftest_ren(a->flags, ISDIR))
20547 + vfsub_drop_nlink(i);
20549 + vfsub_dead_dir(i);
20550 + au_cpup_attr_timesizes(i);
20552 + au_update_dbrange(d, /*do_put_zero*/1);
20555 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20556 + au_set_h_dptr(d, bindex, NULL);
20557 + bend = au_dbend(d);
20558 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20559 + au_set_h_dptr(d, bindex, NULL);
20560 + au_update_dbrange(d, /*do_put_zero*/0);
20563 + d = a->src_dentry;
20564 + au_set_dbwh(d, -1);
20565 + bend = au_dbend(d);
20566 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20567 + h_d = au_h_dptr(d, bindex);
20569 + au_set_h_dptr(d, bindex, NULL);
20571 + au_set_dbend(d, a->btgt);
20574 + i = a->src_inode;
20575 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20576 + return; /* success */
20578 + bend = au_ibend(i);
20579 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20580 + h_i = au_h_iptr(i, bindex);
20582 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20583 + /* ignore this error */
20584 + au_set_h_iptr(i, bindex, NULL, 0);
20587 + au_set_ibend(i, a->btgt);
20590 +/* ---------------------------------------------------------------------- */
20592 +/* mainly for link(2) and rename(2) */
20593 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20595 + aufs_bindex_t bdiropq, bwh;
20596 + struct dentry *parent;
20597 + struct au_branch *br;
20599 + parent = dentry->d_parent;
20600 + IMustLock(parent->d_inode); /* dir is locked */
20602 + bdiropq = au_dbdiropq(parent);
20603 + bwh = au_dbwh(dentry);
20604 + br = au_sbr(dentry->d_sb, btgt);
20605 + if (au_br_rdonly(br)
20606 + || (0 <= bdiropq && bdiropq < btgt)
20607 + || (0 <= bwh && bwh < btgt))
20610 + AuDbg("btgt %d\n", btgt);
20614 +/* sets src_bstart, dst_bstart and btgt */
20615 +static int au_ren_wbr(struct au_ren_args *a)
20618 + struct au_wr_dir_args wr_dir_args = {
20619 + /* .force_btgt = -1, */
20620 + .flags = AuWrDir_ADD_ENTRY
20623 + a->src_bstart = au_dbstart(a->src_dentry);
20624 + a->dst_bstart = au_dbstart(a->dst_dentry);
20625 + if (au_ftest_ren(a->flags, ISDIR))
20626 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20627 + wr_dir_args.force_btgt = a->src_bstart;
20628 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20629 + wr_dir_args.force_btgt = a->dst_bstart;
20630 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20631 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
20637 +static void au_ren_dt(struct au_ren_args *a)
20639 + a->h_path.dentry = a->src_h_parent;
20640 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
20641 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
20642 + a->h_path.dentry = a->dst_h_parent;
20643 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
20646 + au_fclr_ren(a->flags, DT_DSTDIR);
20647 + if (!au_ftest_ren(a->flags, ISDIR))
20650 + a->h_path.dentry = a->src_h_dentry;
20651 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
20652 + if (a->dst_h_dentry->d_inode) {
20653 + au_fset_ren(a->flags, DT_DSTDIR);
20654 + a->h_path.dentry = a->dst_h_dentry;
20655 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
20659 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
20661 + struct dentry *h_d;
20662 + struct mutex *h_mtx;
20664 + au_dtime_revert(a->src_dt + AuPARENT);
20665 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
20666 + au_dtime_revert(a->dst_dt + AuPARENT);
20668 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
20669 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
20670 + h_mtx = &h_d->d_inode->i_mutex;
20671 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20672 + au_dtime_revert(a->src_dt + AuCHILD);
20673 + mutex_unlock(h_mtx);
20675 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
20676 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
20677 + h_mtx = &h_d->d_inode->i_mutex;
20678 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20679 + au_dtime_revert(a->dst_dt + AuCHILD);
20680 + mutex_unlock(h_mtx);
20685 +/* ---------------------------------------------------------------------- */
20687 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
20688 + struct inode *_dst_dir, struct dentry *_dst_dentry)
20691 + /* reduce stack space */
20692 + struct au_ren_args *a;
20694 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
20695 + IMustLock(_src_dir);
20696 + IMustLock(_dst_dir);
20699 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
20700 + a = kzalloc(sizeof(*a), GFP_NOFS);
20701 + if (unlikely(!a))
20704 + a->src_dir = _src_dir;
20705 + a->src_dentry = _src_dentry;
20706 + a->src_inode = a->src_dentry->d_inode;
20707 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
20708 + a->dst_dir = _dst_dir;
20709 + a->dst_dentry = _dst_dentry;
20710 + a->dst_inode = a->dst_dentry->d_inode;
20711 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
20712 + if (a->dst_inode) {
20713 + IMustLock(a->dst_inode);
20714 + au_igrab(a->dst_inode);
20718 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
20719 + if (S_ISDIR(a->src_inode->i_mode)) {
20720 + au_fset_ren(a->flags, ISDIR);
20721 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
20723 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20724 + AuLock_DIR | flags);
20726 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20728 + if (unlikely(err))
20731 + err = au_d_hashed_positive(a->src_dentry);
20732 + if (unlikely(err))
20735 + if (a->dst_inode) {
20737 + * If it is a dir, VFS unhash dst_dentry before this
20738 + * function. It means we cannot rely upon d_unhashed().
20740 + if (unlikely(!a->dst_inode->i_nlink))
20742 + if (!S_ISDIR(a->dst_inode->i_mode)) {
20743 + err = au_d_hashed_positive(a->dst_dentry);
20744 + if (unlikely(err))
20746 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
20748 + } else if (unlikely(d_unhashed(a->dst_dentry)))
20752 + * is it possible?
20753 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
20754 + * there may exist a problem somewhere else.
20757 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
20760 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
20761 + di_write_lock_parent(a->dst_parent);
20763 + /* which branch we process */
20764 + err = au_ren_wbr(a);
20765 + if (unlikely(err < 0))
20767 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
20768 + a->h_path.mnt = au_br_mnt(a->br);
20770 + /* are they available to be renamed */
20771 + err = au_ren_may_dir(a);
20772 + if (unlikely(err))
20773 + goto out_children;
20775 + /* prepare the writable parent dir on the same branch */
20776 + if (a->dst_bstart == a->btgt) {
20777 + au_fset_ren(a->flags, WHDST);
20779 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
20780 + if (unlikely(err))
20781 + goto out_children;
20784 + if (a->src_dir != a->dst_dir) {
20786 + * this temporary unlock is safe,
20787 + * because both dir->i_mutex are locked.
20789 + di_write_unlock(a->dst_parent);
20790 + di_write_lock_parent(a->src_parent);
20791 + err = au_wr_dir_need_wh(a->src_dentry,
20792 + au_ftest_ren(a->flags, ISDIR),
20794 + di_write_unlock(a->src_parent);
20795 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
20796 + au_fclr_ren(a->flags, ISSAMEDIR);
20798 + err = au_wr_dir_need_wh(a->src_dentry,
20799 + au_ftest_ren(a->flags, ISDIR),
20801 + if (unlikely(err < 0))
20802 + goto out_children;
20804 + au_fset_ren(a->flags, WHSRC);
20807 + if (a->src_bstart != a->btgt) {
20808 + struct au_pin pin;
20810 + err = au_pin(&pin, a->src_dentry, a->btgt,
20811 + au_opt_udba(a->src_dentry->d_sb),
20812 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20814 + struct au_cp_generic cpg = {
20815 + .dentry = a->src_dentry,
20817 + .bsrc = a->src_bstart,
20820 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20822 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
20823 + err = au_sio_cpup_simple(&cpg);
20826 + if (unlikely(err))
20827 + goto out_children;
20828 + a->src_bstart = a->btgt;
20829 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
20830 + au_fset_ren(a->flags, WHSRC);
20833 + /* lock them all */
20834 + err = au_ren_lock(a);
20835 + if (unlikely(err))
20836 + /* leave the copied-up one */
20837 + goto out_children;
20839 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
20840 + err = au_may_ren(a);
20841 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
20842 + err = -ENAMETOOLONG;
20843 + if (unlikely(err))
20846 + /* store timestamps to be revertible */
20850 + err = do_rename(a);
20851 + if (unlikely(err))
20854 + /* update dir attributes */
20855 + au_ren_refresh_dir(a);
20857 + /* dput/iput all lower dentries */
20858 + au_ren_refresh(a);
20860 + goto out_hdir; /* success */
20863 + au_ren_rev_dt(err, a);
20865 + au_ren_unlock(a);
20867 + au_nhash_wh_free(&a->whlist);
20868 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
20869 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
20870 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
20871 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
20875 + d_move(a->src_dentry, a->dst_dentry);
20877 + au_update_dbstart(a->dst_dentry);
20878 + if (!a->dst_inode)
20879 + d_drop(a->dst_dentry);
20881 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20882 + di_write_unlock(a->dst_parent);
20884 + di_write_unlock2(a->src_parent, a->dst_parent);
20886 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
20888 + iput(a->dst_inode);
20890 + au_whtmp_rmdir_free(a->thargs);
20896 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
20897 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
20898 +++ linux/fs/aufs/Kconfig 2015-01-25 13:00:38.627713742 +0100
20901 + tristate "Aufs (Advanced multi layered unification filesystem) support"
20903 + Aufs is a stackable unification filesystem such as Unionfs,
20904 + which unifies several directories and provides a merged single
20906 + In the early days, aufs was entirely re-designed and
20907 + re-implemented Unionfs Version 1.x series. Introducing many
20908 + original ideas, approaches and improvements, it becomes totally
20909 + different from Unionfs while keeping the basic features.
20913 + prompt "Maximum number of branches"
20914 + default AUFS_BRANCH_MAX_127
20916 + Specifies the maximum number of branches (or member directories)
20917 + in a single aufs. The larger value consumes more system
20918 + resources and has a minor impact to performance.
20919 +config AUFS_BRANCH_MAX_127
20922 + Specifies the maximum number of branches (or member directories)
20923 + in a single aufs. The larger value consumes more system
20924 + resources and has a minor impact to performance.
20925 +config AUFS_BRANCH_MAX_511
20928 + Specifies the maximum number of branches (or member directories)
20929 + in a single aufs. The larger value consumes more system
20930 + resources and has a minor impact to performance.
20931 +config AUFS_BRANCH_MAX_1023
20934 + Specifies the maximum number of branches (or member directories)
20935 + in a single aufs. The larger value consumes more system
20936 + resources and has a minor impact to performance.
20937 +config AUFS_BRANCH_MAX_32767
20940 + Specifies the maximum number of branches (or member directories)
20941 + in a single aufs. The larger value consumes more system
20942 + resources and has a minor impact to performance.
20945 +config AUFS_SBILIST
20947 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
20950 + Automatic configuration for internal use.
20951 + When aufs supports Magic SysRq or /proc, enabled automatically.
20953 +config AUFS_HNOTIFY
20954 + bool "Detect direct branch access (bypassing aufs)"
20956 + If you want to modify files on branches directly, eg. bypassing aufs,
20957 + and want aufs to detect the changes of them fully, then enable this
20958 + option and use 'udba=notify' mount option.
20959 + Currently there is only one available configuration, "fsnotify".
20960 + It will have a negative impact to the performance.
20961 + See detail in aufs.5.
20964 + prompt "method" if AUFS_HNOTIFY
20965 + default AUFS_HFSNOTIFY
20966 +config AUFS_HFSNOTIFY
20971 +config AUFS_EXPORT
20972 + bool "NFS-exportable aufs"
20973 + depends on EXPORTFS
20975 + If you want to export your mounted aufs via NFS, then enable this
20976 + option. There are several requirements for this configuration.
20977 + See detail in aufs.5.
20979 +config AUFS_INO_T_64
20981 + depends on AUFS_EXPORT
20982 + depends on 64BIT && !(ALPHA || S390)
20985 + Automatic configuration for internal use.
20986 + /* typedef unsigned long/int __kernel_ino_t */
20987 + /* alpha and s390x are int */
20990 + bool "support for XATTR/EA (including Security Labels)"
20992 + If your branch fs supports XATTR/EA and you want to make them
20993 + available in aufs too, then enable this opsion and specify the
20994 + branch attributes for EA.
20995 + See detail in aufs.5.
20998 + bool "File-based Hierarchical Storage Management"
21000 + Hierarchical Storage Management (or HSM) is a well-known feature
21001 + in the storage world. Aufs provides this feature as file-based.
21002 + with multiple branches.
21003 + These multiple branches are prioritized, ie. the topmost one
21004 + should be the fastest drive and be used heavily.
21007 + bool "Readdir in userspace"
21009 + Aufs has two methods to provide a merged view for a directory,
21010 + by a user-space library and by kernel-space natively. The latter
21011 + is always enabled but sometimes large and slow.
21012 + If you enable this option, install the library in aufs2-util
21013 + package, and set some environment variables for your readdir(3),
21014 + then the work will be handled in user-space which generally
21015 + shows better performance in most cases.
21016 + See detail in aufs.5.
21019 + bool "Show whiteouts"
21021 + If you want to make the whiteouts in aufs visible, then enable
21022 + this option and specify 'shwh' mount option. Although it may
21023 + sounds like philosophy or something, but in technically it
21024 + simply shows the name of whiteout with keeping its behaviour.
21026 +config AUFS_BR_RAMFS
21027 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21029 + If you want to use ramfs as an aufs branch fs, then enable this
21030 + option. Generally tmpfs is recommended.
21031 + Aufs prohibited them to be a branch fs by default, because
21032 + initramfs becomes unusable after switch_root or something
21033 + generally. If you sets initramfs as an aufs branch and boot your
21034 + system by switch_root, you will meet a problem easily since the
21035 + files in initramfs may be inaccessible.
21036 + Unless you are going to use ramfs as an aufs branch fs without
21037 + switch_root or something, leave it N.
21039 +config AUFS_BR_FUSE
21040 + bool "Fuse fs as an aufs branch"
21041 + depends on FUSE_FS
21044 + If you want to use fuse-based userspace filesystem as an aufs
21045 + branch fs, then enable this option.
21046 + It implements the internal poll(2) operation which is
21047 + implemented by fuse only (curretnly).
21052 + Automatic configuration for internal use.
21054 +config AUFS_BR_HFSPLUS
21055 + bool "Hfsplus as an aufs branch"
21056 + depends on HFSPLUS_FS
21059 + If you want to use hfsplus fs as an aufs branch fs, then enable
21060 + this option. This option introduces a small overhead at
21061 + copying-up a file on hfsplus.
21063 +config AUFS_BDEV_LOOP
21065 + depends on BLK_DEV_LOOP
21068 + Automatic configuration for internal use.
21069 + Convert =[ym] into =y.
21072 + bool "Debug aufs"
21074 + Enable this to compile aufs internal debug code.
21075 + It will have a negative impact to the performance.
21077 +config AUFS_MAGIC_SYSRQ
21079 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21082 + Automatic configuration for internal use.
21083 + When aufs supports Magic SysRq, enabled automatically.
21085 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21086 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21087 +++ linux/fs/aufs/loop.c 2015-01-25 13:00:38.631047076 +0100
21090 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21092 + * This program, aufs is free software; you can redistribute it and/or modify
21093 + * it under the terms of the GNU General Public License as published by
21094 + * the Free Software Foundation; either version 2 of the License, or
21095 + * (at your option) any later version.
21097 + * This program is distributed in the hope that it will be useful,
21098 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21099 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21100 + * GNU General Public License for more details.
21102 + * You should have received a copy of the GNU General Public License
21103 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21107 + * support for loopback block device as a branch
21112 +/* added into drivers/block/loop.c */
21113 +static struct file *(*backing_file_func)(struct super_block *sb);
21116 + * test if two lower dentries have overlapping branches.
21118 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21120 + struct super_block *h_sb;
21121 + struct file *backing_file;
21123 + if (unlikely(!backing_file_func)) {
21124 + /* don't load "loop" module here */
21125 + backing_file_func = symbol_get(loop_backing_file);
21126 + if (unlikely(!backing_file_func))
21127 + /* "loop" module is not loaded */
21131 + h_sb = h_adding->d_sb;
21132 + backing_file = backing_file_func(h_sb);
21133 + if (!backing_file)
21136 + h_adding = backing_file->f_dentry;
21138 + * h_adding can be local NFS.
21139 + * in this case aufs cannot detect the loop.
21141 + if (unlikely(h_adding->d_sb == sb))
21143 + return !!au_test_subdir(h_adding, sb->s_root);
21146 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21147 +int au_test_loopback_kthread(void)
21150 + struct task_struct *tsk = current;
21151 + char c, comm[sizeof(tsk->comm)];
21154 + if (tsk->flags & PF_KTHREAD) {
21155 + get_task_comm(comm, tsk);
21157 + ret = ('0' <= c && c <= '9'
21158 + && !strncmp(comm, "loop", 4));
21164 +/* ---------------------------------------------------------------------- */
21166 +#define au_warn_loopback_step 16
21167 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21168 +static unsigned long *au_warn_loopback_array;
21170 +void au_warn_loopback(struct super_block *h_sb)
21172 + int i, new_nelem;
21173 + unsigned long *a, magic;
21174 + static DEFINE_SPINLOCK(spin);
21176 + magic = h_sb->s_magic;
21177 + spin_lock(&spin);
21178 + a = au_warn_loopback_array;
21179 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21180 + if (a[i] == magic) {
21181 + spin_unlock(&spin);
21185 + /* h_sb is new to us, print it */
21186 + if (i < au_warn_loopback_nelem) {
21191 + /* expand the array */
21192 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21193 + a = au_kzrealloc(au_warn_loopback_array,
21194 + au_warn_loopback_nelem * sizeof(unsigned long),
21195 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
21197 + au_warn_loopback_nelem = new_nelem;
21198 + au_warn_loopback_array = a;
21203 + spin_unlock(&spin);
21204 + AuWarn1("realloc failed, ignored\n");
21208 + spin_unlock(&spin);
21209 + pr_warn("you may want to try another patch for loopback file "
21210 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21213 +int au_loopback_init(void)
21216 + struct super_block *sb __maybe_unused;
21218 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
21221 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21222 + sizeof(unsigned long), GFP_NOFS);
21223 + if (unlikely(!au_warn_loopback_array))
21229 +void au_loopback_fin(void)
21231 + symbol_put(loop_backing_file);
21232 + kfree(au_warn_loopback_array);
21234 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21235 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21236 +++ linux/fs/aufs/loop.h 2015-01-25 13:00:38.631047076 +0100
21239 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21241 + * This program, aufs is free software; you can redistribute it and/or modify
21242 + * it under the terms of the GNU General Public License as published by
21243 + * the Free Software Foundation; either version 2 of the License, or
21244 + * (at your option) any later version.
21246 + * This program is distributed in the hope that it will be useful,
21247 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21248 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21249 + * GNU General Public License for more details.
21251 + * You should have received a copy of the GNU General Public License
21252 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21256 + * support for loopback mount as a branch
21259 +#ifndef __AUFS_LOOP_H__
21260 +#define __AUFS_LOOP_H__
21265 +struct super_block;
21267 +#ifdef CONFIG_AUFS_BDEV_LOOP
21268 +/* drivers/block/loop.c */
21269 +struct file *loop_backing_file(struct super_block *sb);
21272 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21273 +int au_test_loopback_kthread(void);
21274 +void au_warn_loopback(struct super_block *h_sb);
21276 +int au_loopback_init(void);
21277 +void au_loopback_fin(void);
21279 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21280 + struct dentry *h_adding)
21281 +AuStubInt0(au_test_loopback_kthread, void)
21282 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21284 +AuStubInt0(au_loopback_init, void)
21285 +AuStubVoid(au_loopback_fin, void)
21286 +#endif /* BLK_DEV_LOOP */
21288 +#endif /* __KERNEL__ */
21289 +#endif /* __AUFS_LOOP_H__ */
21290 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21291 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21292 +++ linux/fs/aufs/magic.mk 2015-01-25 13:00:38.631047076 +0100
21295 +# defined in ${srctree}/fs/fuse/inode.c
21297 +ifdef CONFIG_FUSE_FS
21298 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21301 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
21303 +ifdef CONFIG_OCFS2_FS
21304 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
21307 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
21309 +ifdef CONFIG_OCFS2_FS_O2CB
21310 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
21313 +# defined in ${srctree}/fs/cifs/cifsfs.c
21315 +ifdef CONFIG_CIFS_FS
21316 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
21319 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21321 +ifdef CONFIG_XFS_FS
21322 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21325 +# defined in ${srctree}/fs/configfs/mount.c
21327 +ifdef CONFIG_CONFIGFS_FS
21328 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21331 +# defined in ${srctree}/fs/9p/v9fs.h
21333 +ifdef CONFIG_9P_FS
21334 +ccflags-y += -DV9FS_MAGIC=0x01021997
21337 +# defined in ${srctree}/fs/ubifs/ubifs.h
21339 +ifdef CONFIG_UBIFS_FS
21340 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21343 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21345 +ifdef CONFIG_HFSPLUS_FS
21346 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21348 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21349 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21350 +++ linux/fs/aufs/Makefile 2015-01-25 13:00:38.627713742 +0100
21353 +include ${src}/magic.mk
21354 +ifeq (${CONFIG_AUFS_FS},m)
21355 +include ${src}/conf.mk
21357 +-include ${src}/priv_def.mk
21359 +# cf. include/linux/kernel.h
21361 +ccflags-y += -DDEBUG
21362 +# sparse requires the full pathname
21364 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21366 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21369 +obj-$(CONFIG_AUFS_FS) += aufs.o
21370 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21371 + wkq.o vfsub.o dcsub.o \
21372 + cpup.o whout.o wbr_policy.o \
21373 + dinfo.o dentry.o \
21375 + finfo.o file.o f_op.o \
21377 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21381 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21382 +aufs-$(CONFIG_SYSFS) += sysfs.o
21383 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21384 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21385 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21386 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21387 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21388 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21389 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21390 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21391 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21392 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21393 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21394 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21395 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21396 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21397 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21398 +++ linux/fs/aufs/module.c 2015-01-25 13:00:38.634380408 +0100
21401 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21403 + * This program, aufs is free software; you can redistribute it and/or modify
21404 + * it under the terms of the GNU General Public License as published by
21405 + * the Free Software Foundation; either version 2 of the License, or
21406 + * (at your option) any later version.
21408 + * This program is distributed in the hope that it will be useful,
21409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21411 + * GNU General Public License for more details.
21413 + * You should have received a copy of the GNU General Public License
21414 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21418 + * module global variables and operations
21421 +#include <linux/module.h>
21422 +#include <linux/seq_file.h>
21425 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21427 + if (new_sz <= nused)
21430 + p = krealloc(p, new_sz, gfp);
21432 + memset(p + nused, 0, new_sz - nused);
21436 +/* ---------------------------------------------------------------------- */
21441 +struct kmem_cache *au_cachep[AuCache_Last];
21442 +static int __init au_cache_init(void)
21444 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21445 + if (au_cachep[AuCache_DINFO])
21446 + /* SLAB_DESTROY_BY_RCU */
21447 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21448 + au_icntnr_init_once);
21449 + if (au_cachep[AuCache_ICNTNR])
21450 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21451 + au_fi_init_once);
21452 + if (au_cachep[AuCache_FINFO])
21453 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21454 + if (au_cachep[AuCache_VDIR])
21455 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21456 + if (au_cachep[AuCache_DEHSTR])
21462 +static void au_cache_fin(void)
21467 + * Make sure all delayed rcu free inodes are flushed before we
21472 + /* excluding AuCache_HNOTIFY */
21473 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21474 + for (i = 0; i < AuCache_HNOTIFY; i++)
21475 + if (au_cachep[i]) {
21476 + kmem_cache_destroy(au_cachep[i]);
21477 + au_cachep[i] = NULL;
21481 +/* ---------------------------------------------------------------------- */
21483 +int au_dir_roflags;
21485 +#ifdef CONFIG_AUFS_SBILIST
21487 + * iterate_supers_type() doesn't protect us from
21488 + * remounting (branch management)
21490 +struct au_splhead au_sbilist;
21493 +struct lock_class_key au_lc_key[AuLcKey_Last];
21496 + * functions for module interface.
21498 +MODULE_LICENSE("GPL");
21499 +/* MODULE_LICENSE("GPL v2"); */
21500 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21501 +MODULE_DESCRIPTION(AUFS_NAME
21502 + " -- Advanced multi layered unification filesystem");
21503 +MODULE_VERSION(AUFS_VERSION);
21504 +MODULE_ALIAS_FS(AUFS_NAME);
21506 +/* this module parameter has no meaning when SYSFS is disabled */
21507 +int sysaufs_brs = 1;
21508 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21509 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21511 +/* this module parameter has no meaning when USER_NS is disabled */
21512 +static bool au_userns;
21513 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21514 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21516 +/* ---------------------------------------------------------------------- */
21518 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21520 +int au_seq_path(struct seq_file *seq, struct path *path)
21522 + return seq_path(seq, path, au_esc_chars);
21525 +/* ---------------------------------------------------------------------- */
21527 +static int __init aufs_init(void)
21532 + p = au_esc_chars;
21533 + for (i = 1; i <= ' '; i++)
21539 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21541 + au_sbilist_init();
21542 + sysaufs_brs_init();
21545 + err = sysaufs_init();
21546 + if (unlikely(err))
21548 + err = au_procfs_init();
21549 + if (unlikely(err))
21550 + goto out_sysaufs;
21551 + err = au_wkq_init();
21552 + if (unlikely(err))
21554 + err = au_loopback_init();
21555 + if (unlikely(err))
21557 + err = au_hnotify_init();
21558 + if (unlikely(err))
21559 + goto out_loopback;
21560 + err = au_sysrq_init();
21561 + if (unlikely(err))
21563 + err = au_cache_init();
21564 + if (unlikely(err))
21567 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21568 + err = register_filesystem(&aufs_fs_type);
21569 + if (unlikely(err))
21572 + /* since we define pr_fmt, call printk directly */
21573 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21574 + goto out; /* success */
21581 + au_hnotify_fin();
21583 + au_loopback_fin();
21595 +static void __exit aufs_exit(void)
21597 + unregister_filesystem(&aufs_fs_type);
21600 + au_hnotify_fin();
21601 + au_loopback_fin();
21608 +module_init(aufs_init);
21609 +module_exit(aufs_exit);
21610 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21611 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21612 +++ linux/fs/aufs/module.h 2015-01-25 13:00:38.634380408 +0100
21615 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21617 + * This program, aufs is free software; you can redistribute it and/or modify
21618 + * it under the terms of the GNU General Public License as published by
21619 + * the Free Software Foundation; either version 2 of the License, or
21620 + * (at your option) any later version.
21622 + * This program is distributed in the hope that it will be useful,
21623 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21624 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21625 + * GNU General Public License for more details.
21627 + * You should have received a copy of the GNU General Public License
21628 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21632 + * module initialization and module-global
21635 +#ifndef __AUFS_MODULE_H__
21636 +#define __AUFS_MODULE_H__
21640 +#include <linux/slab.h>
21645 +/* module parameters */
21646 +extern int sysaufs_brs;
21648 +/* ---------------------------------------------------------------------- */
21650 +extern int au_dir_roflags;
21653 + AuLcNonDir_FIINFO,
21654 + AuLcNonDir_DIINFO,
21655 + AuLcNonDir_IIINFO,
21661 + AuLcSymlink_DIINFO,
21662 + AuLcSymlink_IIINFO,
21666 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
21668 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
21669 +int au_seq_path(struct seq_file *seq, struct path *path);
21671 +#ifdef CONFIG_PROC_FS
21673 +int __init au_procfs_init(void);
21674 +void au_procfs_fin(void);
21676 +AuStubInt0(au_procfs_init, void);
21677 +AuStubVoid(au_procfs_fin, void);
21680 +/* ---------------------------------------------------------------------- */
21689 + AuCache_HNOTIFY, /* must be last */
21693 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
21694 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
21695 +#define AuCacheCtor(type, ctor) \
21696 + kmem_cache_create(#type, sizeof(struct type), \
21697 + __alignof__(struct type), AuCacheFlags, ctor)
21699 +extern struct kmem_cache *au_cachep[];
21701 +#define AuCacheFuncs(name, index) \
21702 +static inline struct au_##name *au_cache_alloc_##name(void) \
21703 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
21704 +static inline void au_cache_free_##name(struct au_##name *p) \
21705 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
21707 +AuCacheFuncs(dinfo, DINFO);
21708 +AuCacheFuncs(icntnr, ICNTNR);
21709 +AuCacheFuncs(finfo, FINFO);
21710 +AuCacheFuncs(vdir, VDIR);
21711 +AuCacheFuncs(vdir_dehstr, DEHSTR);
21712 +#ifdef CONFIG_AUFS_HNOTIFY
21713 +AuCacheFuncs(hnotify, HNOTIFY);
21716 +#endif /* __KERNEL__ */
21717 +#endif /* __AUFS_MODULE_H__ */
21718 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
21719 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
21720 +++ linux/fs/aufs/mvdown.c 2015-01-25 13:00:38.634380408 +0100
21723 + * Copyright (C) 2011-2014 Junjiro R. Okajima
21725 + * This program, aufs is free software; you can redistribute it and/or modify
21726 + * it under the terms of the GNU General Public License as published by
21727 + * the Free Software Foundation; either version 2 of the License, or
21728 + * (at your option) any later version.
21730 + * This program is distributed in the hope that it will be useful,
21731 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21732 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21733 + * GNU General Public License for more details.
21735 + * You should have received a copy of the GNU General Public License
21736 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21740 + * move-down, opposite of copy-up
21745 +struct au_mvd_args {
21747 + struct super_block *h_sb;
21748 + struct dentry *h_parent;
21749 + struct au_hinode *hdir;
21750 + struct inode *h_dir, *h_inode;
21751 + struct au_pin pin;
21752 + } info[AUFS_MVDOWN_NARRAY];
21754 + struct aufs_mvdown mvdown;
21755 + struct dentry *dentry, *parent;
21756 + struct inode *inode, *dir;
21757 + struct super_block *sb;
21758 + aufs_bindex_t bopq, bwh, bfound;
21759 + unsigned char rename_lock;
21762 +#define mvd_errno mvdown.au_errno
21763 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
21764 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
21765 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
21766 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
21768 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
21769 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
21770 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
21771 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
21772 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
21773 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
21775 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
21776 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
21777 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
21778 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
21779 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
21780 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
21782 +#define AU_MVD_PR(flag, ...) do { \
21784 + pr_err(__VA_ARGS__); \
21787 +static int find_lower_writable(struct au_mvd_args *a)
21789 + struct super_block *sb;
21790 + aufs_bindex_t bindex, bend;
21791 + struct au_branch *br;
21794 + bindex = a->mvd_bsrc;
21795 + bend = au_sbend(sb);
21796 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
21797 + for (bindex++; bindex <= bend; bindex++) {
21798 + br = au_sbr(sb, bindex);
21799 + if (au_br_fhsm(br->br_perm)
21800 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
21803 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
21804 + for (bindex++; bindex <= bend; bindex++) {
21805 + br = au_sbr(sb, bindex);
21806 + if (!au_br_rdonly(br))
21810 + for (bindex++; bindex <= bend; bindex++) {
21811 + br = au_sbr(sb, bindex);
21812 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21813 + if (au_br_rdonly(br))
21815 + |= AUFS_MVDOWN_ROLOWER_R;
21823 +/* make the parent dir on bdst */
21824 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
21829 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
21830 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
21831 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
21832 + a->mvd_h_dst_parent = NULL;
21833 + if (au_dbend(a->parent) >= a->mvd_bdst)
21834 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21835 + if (!a->mvd_h_dst_parent) {
21836 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
21837 + if (unlikely(err)) {
21838 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
21841 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21849 +/* lock them all */
21850 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
21853 + struct dentry *h_trap;
21855 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
21856 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
21857 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
21858 + au_opt_udba(a->sb),
21859 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21861 + if (unlikely(err)) {
21862 + AU_MVD_PR(dmsg, "pin_dst failed\n");
21866 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
21867 + a->rename_lock = 0;
21868 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
21869 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
21870 + au_opt_udba(a->sb),
21871 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21872 + err = au_do_pin(&a->mvd_pin_src);
21874 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
21875 + if (unlikely(err)) {
21876 + AU_MVD_PR(dmsg, "pin_src failed\n");
21879 + goto out; /* success */
21882 + a->rename_lock = 1;
21883 + au_pin_hdir_unlock(&a->mvd_pin_dst);
21884 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
21885 + au_opt_udba(a->sb),
21886 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21888 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
21889 + if (unlikely(err)) {
21890 + AU_MVD_PR(dmsg, "pin_src failed\n");
21891 + au_pin_hdir_lock(&a->mvd_pin_dst);
21894 + au_pin_hdir_unlock(&a->mvd_pin_src);
21895 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21896 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21898 + err = (h_trap != a->mvd_h_src_parent);
21900 + err = (h_trap != a->mvd_h_dst_parent);
21902 + BUG_ON(err); /* it should never happen */
21903 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
21906 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21907 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21908 + au_pin_hdir_lock(&a->mvd_pin_src);
21909 + au_unpin(&a->mvd_pin_src);
21910 + au_pin_hdir_lock(&a->mvd_pin_dst);
21913 + goto out; /* success */
21916 + au_unpin(&a->mvd_pin_dst);
21922 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
21924 + if (!a->rename_lock)
21925 + au_unpin(&a->mvd_pin_src);
21927 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21928 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21929 + au_pin_hdir_lock(&a->mvd_pin_src);
21930 + au_unpin(&a->mvd_pin_src);
21931 + au_pin_hdir_lock(&a->mvd_pin_dst);
21933 + au_unpin(&a->mvd_pin_dst);
21936 +/* copy-down the file */
21937 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
21940 + struct au_cp_generic cpg = {
21941 + .dentry = a->dentry,
21942 + .bdst = a->mvd_bdst,
21943 + .bsrc = a->mvd_bsrc,
21945 + .pin = &a->mvd_pin_dst,
21946 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21949 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
21950 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21951 + au_fset_cpup(cpg.flags, OVERWRITE);
21952 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
21953 + au_fset_cpup(cpg.flags, RWDST);
21954 + err = au_sio_cpdown_simple(&cpg);
21955 + if (unlikely(err))
21956 + AU_MVD_PR(dmsg, "cpdown failed\n");
21963 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
21966 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
21969 + struct path h_path;
21970 + struct au_branch *br;
21971 + struct inode *delegated;
21973 + br = au_sbr(a->sb, a->mvd_bdst);
21974 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
21975 + err = PTR_ERR(h_path.dentry);
21976 + if (IS_ERR(h_path.dentry)) {
21977 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
21982 + if (h_path.dentry->d_inode) {
21983 + h_path.mnt = au_br_mnt(br);
21984 + delegated = NULL;
21985 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
21986 + &delegated, /*force*/0);
21987 + if (unlikely(err == -EWOULDBLOCK)) {
21988 + pr_warn("cannot retry for NFSv4 delegation"
21989 + " for an internal unlink\n");
21992 + if (unlikely(err))
21993 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
21995 + dput(h_path.dentry);
22003 + * unlink the topmost h_dentry
22005 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22008 + struct path h_path;
22009 + struct inode *delegated;
22011 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22012 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22013 + delegated = NULL;
22014 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22015 + if (unlikely(err == -EWOULDBLOCK)) {
22016 + pr_warn("cannot retry for NFSv4 delegation"
22017 + " for an internal unlink\n");
22020 + if (unlikely(err))
22021 + AU_MVD_PR(dmsg, "unlink failed\n");
22027 +/* Since mvdown succeeded, we ignore an error of this function */
22028 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22031 + struct au_branch *br;
22033 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22034 + br = au_sbr(a->sb, a->mvd_bsrc);
22035 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22037 + br = au_sbr(a->sb, a->mvd_bdst);
22038 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22039 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22042 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22044 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22048 + * copy-down the file and unlink the bsrc file.
22049 + * - unlink the bdst whout if exist
22050 + * - copy-down the file (with whtmp name and rename)
22051 + * - unlink the bsrc file
22053 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22057 + err = au_do_mkdir(dmsg, a);
22059 + err = au_do_lock(dmsg, a);
22060 + if (unlikely(err))
22064 + * do not revert the activities we made on bdst since they should be
22065 + * harmless in aufs.
22068 + err = au_do_cpdown(dmsg, a);
22070 + err = au_do_unlink_wh(dmsg, a);
22071 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22072 + err = au_do_unlink(dmsg, a);
22073 + if (unlikely(err))
22076 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22077 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22078 + if (find_lower_writable(a) < 0)
22079 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22081 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22082 + au_do_stfs(dmsg, a);
22084 + /* maintain internal array */
22085 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22086 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22087 + au_set_dbstart(a->dentry, a->mvd_bdst);
22088 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22089 + au_set_ibstart(a->inode, a->mvd_bdst);
22091 + if (au_dbend(a->dentry) < a->mvd_bdst)
22092 + au_set_dbend(a->dentry, a->mvd_bdst);
22093 + if (au_ibend(a->inode) < a->mvd_bdst)
22094 + au_set_ibend(a->inode, a->mvd_bdst);
22097 + au_do_unlock(dmsg, a);
22103 +/* ---------------------------------------------------------------------- */
22105 +/* make sure the file is idle */
22106 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22108 + int err, plinked;
22111 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22112 + if (au_dbstart(a->dentry) == a->mvd_bsrc
22113 + && au_dcount(a->dentry) == 1
22114 + && atomic_read(&a->inode->i_count) == 1
22115 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22116 + && (!plinked || !au_plink_test(a->inode))
22117 + && a->inode->i_nlink == 1)
22122 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22123 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
22124 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22125 + a->mvd_h_src_inode->i_nlink,
22126 + plinked, plinked ? au_plink_test(a->inode) : 0);
22133 +/* make sure the parent dir is fine */
22134 +static int au_mvd_args_parent(const unsigned char dmsg,
22135 + struct au_mvd_args *a)
22138 + aufs_bindex_t bindex;
22141 + if (unlikely(au_alive_dir(a->parent))) {
22143 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22147 + a->bopq = au_dbdiropq(a->parent);
22148 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22149 + AuDbg("b%d\n", bindex);
22150 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22151 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22153 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22154 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22155 + a->bopq, a->mvd_bdst);
22163 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22164 + struct au_mvd_args *a)
22167 + struct au_dinfo *dinfo, *tmp;
22169 + /* lookup the next lower positive entry */
22171 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22172 + if (unlikely(!tmp))
22177 + dinfo = au_di(a->dentry);
22178 + au_di_cp(tmp, dinfo);
22179 + au_di_swap(tmp, dinfo);
22181 + /* returns the number of positive dentries */
22182 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
22184 + a->bwh = au_dbwh(a->dentry);
22185 + else if (err > 0)
22186 + a->bfound = au_dbstart(a->dentry);
22188 + au_di_swap(tmp, dinfo);
22189 + au_rw_write_unlock(&tmp->di_rwsem);
22191 + if (unlikely(err < 0))
22192 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22195 + * here, we have these cases.
22197 + * no positive dentry under bsrc. there are more sub-cases.
22199 + * there no whiteout, we can safely move-down.
22202 + * bsrc < bwh && bwh < bdst
22203 + * there is a whiteout on RO branch. cannot proceed.
22205 + * there is a whiteout on the RW target branch. it should
22208 + * there is a whiteout somewhere unrelated branch.
22209 + * -1 < bfound && bfound <= bsrc
22212 + * found, but it is on RO branch between bsrc and bdst. cannot
22215 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22218 + * found, after we create the file on bdst, it will be hidden.
22221 + AuDebugOn(a->bfound == -1
22223 + && a->bwh <= a->mvd_bsrc);
22224 + AuDebugOn(-1 < a->bfound
22225 + && a->bfound <= a->mvd_bsrc);
22228 + if (a->bfound == -1
22229 + && a->mvd_bsrc < a->bwh
22231 + && a->bwh < a->mvd_bdst) {
22232 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22233 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22234 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22236 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22237 + a->mvd_errno = EAU_MVDOWN_UPPER;
22238 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22239 + a->mvd_bdst, a->bfound);
22243 + err = 0; /* success */
22250 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22255 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22256 + && a->bfound == a->mvd_bdst)
22262 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
22265 + struct au_branch *br;
22268 + if (unlikely(S_ISDIR(a->inode->i_mode)))
22272 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
22273 + a->mvd_bsrc = au_ibstart(a->inode);
22275 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
22276 + if (unlikely(a->mvd_bsrc < 0
22277 + || (a->mvd_bsrc < au_dbstart(a->dentry)
22278 + || au_dbend(a->dentry) < a->mvd_bsrc
22279 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
22280 + || (a->mvd_bsrc < au_ibstart(a->inode)
22281 + || au_ibend(a->inode) < a->mvd_bsrc
22282 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
22283 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
22284 + AU_MVD_PR(dmsg, "no upper\n");
22288 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
22289 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22290 + AU_MVD_PR(dmsg, "on the bottom\n");
22293 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
22294 + br = au_sbr(a->sb, a->mvd_bsrc);
22295 + err = au_br_rdonly(br);
22296 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
22297 + if (unlikely(err))
22299 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
22300 + || IS_APPEND(a->mvd_h_src_inode))) {
22302 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22308 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22309 + a->mvd_bdst = find_lower_writable(a);
22310 + if (unlikely(a->mvd_bdst < 0)) {
22311 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22312 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22316 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22317 + if (unlikely(a->mvd_bdst < 0
22318 + || au_sbend(a->sb) < a->mvd_bdst)) {
22319 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22320 + AU_MVD_PR(dmsg, "no lower brid\n");
22325 + err = au_mvd_args_busy(dmsg, a);
22327 + err = au_mvd_args_parent(dmsg, a);
22329 + err = au_mvd_args_intermediate(dmsg, a);
22331 + err = au_mvd_args_exist(dmsg, a);
22333 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22340 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22343 + unsigned char dmsg;
22344 + struct au_mvd_args *args;
22347 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22351 + args = kmalloc(sizeof(*args), GFP_NOFS);
22352 + if (unlikely(!args))
22355 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22357 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22358 + if (unlikely(err)) {
22363 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22364 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22365 + args->mvdown.au_errno = 0;
22366 + args->dentry = dentry;
22367 + args->inode = dentry->d_inode;
22368 + args->sb = dentry->d_sb;
22371 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22372 + args->parent = dget_parent(dentry);
22373 + args->dir = args->parent->d_inode;
22374 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
22375 + dput(args->parent);
22376 + if (unlikely(args->parent != dentry->d_parent)) {
22377 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22381 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
22382 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
22383 + if (unlikely(err))
22386 + di_write_lock_parent(args->parent);
22387 + err = au_mvd_args(dmsg, args);
22388 + if (unlikely(err))
22391 + err = au_do_mvdown(dmsg, args);
22392 + if (unlikely(err))
22395 + au_cpup_attr_timesizes(args->dir);
22396 + au_cpup_attr_timesizes(args->inode);
22397 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
22398 + /* au_digen_dec(dentry); */
22401 + di_write_unlock(args->parent);
22402 + aufs_read_unlock(dentry, AuLock_DW);
22404 + mutex_unlock(&args->inode->i_mutex);
22406 + mutex_unlock(&args->dir->i_mutex);
22408 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22416 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22417 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22418 +++ linux/fs/aufs/opts.c 2015-01-25 13:00:38.634380408 +0100
22421 + * Copyright (C) 2005-2014 Junjiro R. Okajima
22423 + * This program, aufs is free software; you can redistribute it and/or modify
22424 + * it under the terms of the GNU General Public License as published by
22425 + * the Free Software Foundation; either version 2 of the License, or
22426 + * (at your option) any later version.
22428 + * This program is distributed in the hope that it will be useful,
22429 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22430 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22431 + * GNU General Public License for more details.
22433 + * You should have received a copy of the GNU General Public License
22434 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22438 + * mount options/flags
22441 +#include <linux/namei.h>
22442 +#include <linux/types.h> /* a distribution requires */
22443 +#include <linux/parser.h>
22446 +/* ---------------------------------------------------------------------- */
22450 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
22451 + Opt_idel, Opt_imod, Opt_ireorder,
22452 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
22453 + Opt_rdblk_def, Opt_rdhash_def,
22454 + Opt_xino, Opt_zxino, Opt_noxino,
22455 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22456 + Opt_trunc_xino_path, Opt_itrunc_xino,
22457 + Opt_trunc_xib, Opt_notrunc_xib,
22458 + Opt_shwh, Opt_noshwh,
22459 + Opt_plink, Opt_noplink, Opt_list_plink,
22461 + Opt_dio, Opt_nodio,
22462 + /* Opt_lock, Opt_unlock, */
22463 + Opt_cmd, Opt_cmd_args,
22464 + Opt_diropq_a, Opt_diropq_w,
22465 + Opt_warn_perm, Opt_nowarn_perm,
22466 + Opt_wbr_copyup, Opt_wbr_create,
22468 + Opt_refrof, Opt_norefrof,
22469 + Opt_verbose, Opt_noverbose,
22470 + Opt_sum, Opt_nosum, Opt_wsum,
22471 + Opt_dirperm1, Opt_nodirperm1,
22472 + Opt_acl, Opt_noacl,
22473 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22476 +static match_table_t options = {
22477 + {Opt_br, "br=%s"},
22478 + {Opt_br, "br:%s"},
22480 + {Opt_add, "add=%d:%s"},
22481 + {Opt_add, "add:%d:%s"},
22482 + {Opt_add, "ins=%d:%s"},
22483 + {Opt_add, "ins:%d:%s"},
22484 + {Opt_append, "append=%s"},
22485 + {Opt_append, "append:%s"},
22486 + {Opt_prepend, "prepend=%s"},
22487 + {Opt_prepend, "prepend:%s"},
22489 + {Opt_del, "del=%s"},
22490 + {Opt_del, "del:%s"},
22491 + /* {Opt_idel, "idel:%d"}, */
22492 + {Opt_mod, "mod=%s"},
22493 + {Opt_mod, "mod:%s"},
22494 + /* {Opt_imod, "imod:%d:%s"}, */
22496 + {Opt_dirwh, "dirwh=%d"},
22498 + {Opt_xino, "xino=%s"},
22499 + {Opt_noxino, "noxino"},
22500 + {Opt_trunc_xino, "trunc_xino"},
22501 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22502 + {Opt_notrunc_xino, "notrunc_xino"},
22503 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22504 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22505 + /* {Opt_zxino, "zxino=%s"}, */
22506 + {Opt_trunc_xib, "trunc_xib"},
22507 + {Opt_notrunc_xib, "notrunc_xib"},
22509 +#ifdef CONFIG_PROC_FS
22510 + {Opt_plink, "plink"},
22512 + {Opt_ignore_silent, "plink"},
22515 + {Opt_noplink, "noplink"},
22517 +#ifdef CONFIG_AUFS_DEBUG
22518 + {Opt_list_plink, "list_plink"},
22521 + {Opt_udba, "udba=%s"},
22523 + {Opt_dio, "dio"},
22524 + {Opt_nodio, "nodio"},
22526 +#ifdef CONFIG_AUFS_FHSM
22527 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22529 + {Opt_ignore_silent, "fhsm_sec=%d"},
22532 + {Opt_diropq_a, "diropq=always"},
22533 + {Opt_diropq_a, "diropq=a"},
22534 + {Opt_diropq_w, "diropq=whiteouted"},
22535 + {Opt_diropq_w, "diropq=w"},
22537 + {Opt_warn_perm, "warn_perm"},
22538 + {Opt_nowarn_perm, "nowarn_perm"},
22540 + /* keep them temporary */
22541 + {Opt_ignore_silent, "nodlgt"},
22542 + {Opt_ignore_silent, "clean_plink"},
22544 +#ifdef CONFIG_AUFS_SHWH
22545 + {Opt_shwh, "shwh"},
22547 + {Opt_noshwh, "noshwh"},
22549 + {Opt_dirperm1, "dirperm1"},
22550 + {Opt_nodirperm1, "nodirperm1"},
22552 + {Opt_rendir, "rendir=%d"},
22554 + {Opt_refrof, "refrof"},
22555 + {Opt_norefrof, "norefrof"},
22557 + {Opt_verbose, "verbose"},
22558 + {Opt_verbose, "v"},
22559 + {Opt_noverbose, "noverbose"},
22560 + {Opt_noverbose, "quiet"},
22561 + {Opt_noverbose, "q"},
22562 + {Opt_noverbose, "silent"},
22564 + {Opt_sum, "sum"},
22565 + {Opt_nosum, "nosum"},
22566 + {Opt_wsum, "wsum"},
22568 + {Opt_rdcache, "rdcache=%d"},
22569 + {Opt_rdblk, "rdblk=%d"},
22570 + {Opt_rdblk_def, "rdblk=def"},
22571 + {Opt_rdhash, "rdhash=%d"},
22572 + {Opt_rdhash_def, "rdhash=def"},
22574 + {Opt_wbr_create, "create=%s"},
22575 + {Opt_wbr_create, "create_policy=%s"},
22576 + {Opt_wbr_copyup, "cpup=%s"},
22577 + {Opt_wbr_copyup, "copyup=%s"},
22578 + {Opt_wbr_copyup, "copyup_policy=%s"},
22580 + /* generic VFS flag */
22581 +#ifdef CONFIG_FS_POSIX_ACL
22582 + {Opt_acl, "acl"},
22583 + {Opt_noacl, "noacl"},
22585 + {Opt_ignore_silent, "acl"},
22586 + {Opt_ignore_silent, "noacl"},
22589 + /* internal use for the scripts */
22590 + {Opt_ignore_silent, "si=%s"},
22592 + {Opt_br, "dirs=%s"},
22593 + {Opt_ignore, "debug=%d"},
22594 + {Opt_ignore, "delete=whiteout"},
22595 + {Opt_ignore, "delete=all"},
22596 + {Opt_ignore, "imap=%s"},
22598 + /* temporary workaround, due to old mount(8)? */
22599 + {Opt_ignore_silent, "relatime"},
22604 +/* ---------------------------------------------------------------------- */
22606 +static const char *au_parser_pattern(int val, match_table_t tbl)
22608 + struct match_token *p;
22611 + while (p->pattern) {
22612 + if (p->token == val)
22613 + return p->pattern;
22620 +static const char *au_optstr(int *val, match_table_t tbl)
22622 + struct match_token *p;
22627 + while (p->token) {
22628 + if ((v & p->token) == p->token) {
22629 + *val &= ~p->token;
22630 + return p->pattern;
22637 +/* ---------------------------------------------------------------------- */
22639 +static match_table_t brperm = {
22640 + {AuBrPerm_RO, AUFS_BRPERM_RO},
22641 + {AuBrPerm_RR, AUFS_BRPERM_RR},
22642 + {AuBrPerm_RW, AUFS_BRPERM_RW},
22646 +static match_table_t brattr = {
22648 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
22649 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
22650 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
22651 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
22652 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
22653 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
22654 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
22655 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
22656 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
22657 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
22658 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
22660 + /* ro/rr branch */
22661 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
22664 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
22665 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
22670 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
22677 + p = strchr(str, '+');
22680 + v = match_token(str, table, args);
22682 + if (v & AuBrAttr_CMOO_Mask)
22683 + attr &= ~AuBrAttr_CMOO_Mask;
22688 + pr_warn("ignored branch attribute %s\n", str);
22698 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
22706 + p = au_optstr(&perm, brattr);
22709 + memcpy(q, p, sz + 1);
22715 + p = au_optstr(&perm, brattr);
22719 + memcpy(q, p, sz + 1);
22725 + return q - str->a;
22728 +static int noinline_for_stack br_perm_val(char *perm)
22730 + int val, bad, sz;
22732 + substring_t args[MAX_OPT_ARGS];
22733 + au_br_perm_str_t attr;
22735 + p = strchr(perm, '+');
22738 + val = match_token(perm, brperm, args);
22742 + pr_warn("ignored branch permission %s\n", perm);
22743 + val = AuBrPerm_RO;
22749 + val |= br_attr_val(p + 1, brattr, args);
22752 + switch (val & AuBrPerm_Mask) {
22753 + case AuBrPerm_RO:
22754 + case AuBrPerm_RR:
22755 + bad = val & AuBrWAttr_Mask;
22756 + val &= ~AuBrWAttr_Mask;
22758 + case AuBrPerm_RW:
22759 + bad = val & AuBrRAttr_Mask;
22760 + val &= ~AuBrRAttr_Mask;
22765 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
22766 + * does not treat it as an error, just warning.
22767 + * this is a tiny guard for the user operation.
22769 + if (val & AuBrAttr_UNPIN) {
22770 + bad |= AuBrAttr_UNPIN;
22771 + val &= ~AuBrAttr_UNPIN;
22774 + if (unlikely(bad)) {
22775 + sz = au_do_optstr_br_attr(&attr, bad);
22777 + pr_warn("ignored branch attribute %s\n", attr.a);
22784 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
22786 + au_br_perm_str_t attr;
22792 + p = au_optstr(&perm, brperm);
22793 + AuDebugOn(!p || !*p);
22795 + memcpy(q, p, sz + 1);
22798 + sz = au_do_optstr_br_attr(&attr, perm);
22801 + memcpy(q, attr.a, sz + 1);
22804 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
22807 +/* ---------------------------------------------------------------------- */
22809 +static match_table_t udbalevel = {
22810 + {AuOpt_UDBA_REVAL, "reval"},
22811 + {AuOpt_UDBA_NONE, "none"},
22812 +#ifdef CONFIG_AUFS_HNOTIFY
22813 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
22814 +#ifdef CONFIG_AUFS_HFSNOTIFY
22815 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
22821 +static int noinline_for_stack udba_val(char *str)
22823 + substring_t args[MAX_OPT_ARGS];
22825 + return match_token(str, udbalevel, args);
22828 +const char *au_optstr_udba(int udba)
22830 + return au_parser_pattern(udba, udbalevel);
22833 +/* ---------------------------------------------------------------------- */
22835 +static match_table_t au_wbr_create_policy = {
22836 + {AuWbrCreate_TDP, "tdp"},
22837 + {AuWbrCreate_TDP, "top-down-parent"},
22838 + {AuWbrCreate_RR, "rr"},
22839 + {AuWbrCreate_RR, "round-robin"},
22840 + {AuWbrCreate_MFS, "mfs"},
22841 + {AuWbrCreate_MFS, "most-free-space"},
22842 + {AuWbrCreate_MFSV, "mfs:%d"},
22843 + {AuWbrCreate_MFSV, "most-free-space:%d"},
22845 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
22846 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
22847 + {AuWbrCreate_PMFS, "pmfs"},
22848 + {AuWbrCreate_PMFSV, "pmfs:%d"},
22849 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
22850 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
22856 + * cf. linux/lib/parser.c and cmdline.c
22857 + * gave up calling memparse() since it uses simple_strtoull() instead of
22860 +static int noinline_for_stack
22861 +au_match_ull(substring_t *s, unsigned long long *result)
22864 + unsigned int len;
22868 + len = s->to - s->from;
22869 + if (len + 1 <= sizeof(a)) {
22870 + memcpy(a, s->from, len);
22872 + err = kstrtoull(a, 0, result);
22877 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
22878 + struct au_opt_wbr_create *create)
22881 + unsigned long long ull;
22884 + if (!au_match_ull(arg, &ull))
22885 + create->mfsrr_watermark = ull;
22887 + pr_err("bad integer in %s\n", str);
22894 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
22895 + struct au_opt_wbr_create *create)
22900 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
22901 + create->mfs_second = n;
22903 + pr_err("bad integer in %s\n", str);
22910 +static int noinline_for_stack
22911 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
22914 + substring_t args[MAX_OPT_ARGS];
22916 + err = match_token(str, au_wbr_create_policy, args);
22917 + create->wbr_create = err;
22919 + case AuWbrCreate_MFSRRV:
22920 + case AuWbrCreate_PMFSRRV:
22921 + e = au_wbr_mfs_wmark(&args[0], str, create);
22923 + e = au_wbr_mfs_sec(&args[1], str, create);
22927 + case AuWbrCreate_MFSRR:
22928 + case AuWbrCreate_PMFSRR:
22929 + e = au_wbr_mfs_wmark(&args[0], str, create);
22930 + if (unlikely(e)) {
22935 + case AuWbrCreate_MFS:
22936 + case AuWbrCreate_PMFS:
22937 + create->mfs_second = AUFS_MFS_DEF_SEC;
22939 + case AuWbrCreate_MFSV:
22940 + case AuWbrCreate_PMFSV:
22941 + e = au_wbr_mfs_sec(&args[0], str, create);
22950 +const char *au_optstr_wbr_create(int wbr_create)
22952 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
22955 +static match_table_t au_wbr_copyup_policy = {
22956 + {AuWbrCopyup_TDP, "tdp"},
22957 + {AuWbrCopyup_TDP, "top-down-parent"},
22958 + {AuWbrCopyup_BUP, "bup"},
22959 + {AuWbrCopyup_BUP, "bottom-up-parent"},
22960 + {AuWbrCopyup_BU, "bu"},
22961 + {AuWbrCopyup_BU, "bottom-up"},
22965 +static int noinline_for_stack au_wbr_copyup_val(char *str)
22967 + substring_t args[MAX_OPT_ARGS];
22969 + return match_token(str, au_wbr_copyup_policy, args);
22972 +const char *au_optstr_wbr_copyup(int wbr_copyup)
22974 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
22977 +/* ---------------------------------------------------------------------- */
22979 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
22981 +static void dump_opts(struct au_opts *opts)
22983 +#ifdef CONFIG_AUFS_DEBUG
22984 + /* reduce stack space */
22986 + struct au_opt_add *add;
22987 + struct au_opt_del *del;
22988 + struct au_opt_mod *mod;
22989 + struct au_opt_xino *xino;
22990 + struct au_opt_xino_itrunc *xino_itrunc;
22991 + struct au_opt_wbr_create *create;
22993 + struct au_opt *opt;
22996 + while (opt->type != Opt_tail) {
22997 + switch (opt->type) {
22999 + u.add = &opt->add;
23000 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23001 + u.add->bindex, u.add->pathname, u.add->perm,
23002 + u.add->path.dentry);
23006 + u.del = &opt->del;
23007 + AuDbg("del {%s, %p}\n",
23008 + u.del->pathname, u.del->h_path.dentry);
23012 + u.mod = &opt->mod;
23013 + AuDbg("mod {%s, 0x%x, %p}\n",
23014 + u.mod->path, u.mod->perm, u.mod->h_root);
23017 + u.add = &opt->add;
23018 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23019 + u.add->bindex, u.add->pathname, u.add->perm,
23020 + u.add->path.dentry);
23022 + case Opt_prepend:
23023 + u.add = &opt->add;
23024 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23025 + u.add->bindex, u.add->pathname, u.add->perm,
23026 + u.add->path.dentry);
23029 + AuDbg("dirwh %d\n", opt->dirwh);
23031 + case Opt_rdcache:
23032 + AuDbg("rdcache %d\n", opt->rdcache);
23035 + AuDbg("rdblk %u\n", opt->rdblk);
23037 + case Opt_rdblk_def:
23038 + AuDbg("rdblk_def\n");
23041 + AuDbg("rdhash %u\n", opt->rdhash);
23043 + case Opt_rdhash_def:
23044 + AuDbg("rdhash_def\n");
23047 + u.xino = &opt->xino;
23048 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23050 + case Opt_trunc_xino:
23051 + AuLabel(trunc_xino);
23053 + case Opt_notrunc_xino:
23054 + AuLabel(notrunc_xino);
23056 + case Opt_trunc_xino_path:
23057 + case Opt_itrunc_xino:
23058 + u.xino_itrunc = &opt->xino_itrunc;
23059 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23065 + case Opt_trunc_xib:
23066 + AuLabel(trunc_xib);
23068 + case Opt_notrunc_xib:
23069 + AuLabel(notrunc_xib);
23077 + case Opt_dirperm1:
23078 + AuLabel(dirperm1);
23080 + case Opt_nodirperm1:
23081 + AuLabel(nodirperm1);
23086 + case Opt_noplink:
23087 + AuLabel(noplink);
23089 + case Opt_list_plink:
23090 + AuLabel(list_plink);
23093 + AuDbg("udba %d, %s\n",
23094 + opt->udba, au_optstr_udba(opt->udba));
23102 + case Opt_diropq_a:
23103 + AuLabel(diropq_a);
23105 + case Opt_diropq_w:
23106 + AuLabel(diropq_w);
23108 + case Opt_warn_perm:
23109 + AuLabel(warn_perm);
23111 + case Opt_nowarn_perm:
23112 + AuLabel(nowarn_perm);
23117 + case Opt_norefrof:
23118 + AuLabel(norefrof);
23120 + case Opt_verbose:
23121 + AuLabel(verbose);
23123 + case Opt_noverbose:
23124 + AuLabel(noverbose);
23135 + case Opt_wbr_create:
23136 + u.create = &opt->wbr_create;
23137 + AuDbg("create %d, %s\n", u.create->wbr_create,
23138 + au_optstr_wbr_create(u.create->wbr_create));
23139 + switch (u.create->wbr_create) {
23140 + case AuWbrCreate_MFSV:
23141 + case AuWbrCreate_PMFSV:
23142 + AuDbg("%d sec\n", u.create->mfs_second);
23144 + case AuWbrCreate_MFSRR:
23145 + AuDbg("%llu watermark\n",
23146 + u.create->mfsrr_watermark);
23148 + case AuWbrCreate_MFSRRV:
23149 + case AuWbrCreate_PMFSRRV:
23150 + AuDbg("%llu watermark, %d sec\n",
23151 + u.create->mfsrr_watermark,
23152 + u.create->mfs_second);
23156 + case Opt_wbr_copyup:
23157 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23158 + au_optstr_wbr_copyup(opt->wbr_copyup));
23160 + case Opt_fhsm_sec:
23161 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23177 +void au_opts_free(struct au_opts *opts)
23179 + struct au_opt *opt;
23182 + while (opt->type != Opt_tail) {
23183 + switch (opt->type) {
23186 + case Opt_prepend:
23187 + path_put(&opt->add.path);
23191 + path_put(&opt->del.h_path);
23195 + dput(opt->mod.h_root);
23198 + fput(opt->xino.file);
23205 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23206 + aufs_bindex_t bindex)
23209 + struct au_opt_add *add = &opt->add;
23212 + add->bindex = bindex;
23213 + add->perm = AuBrPerm_RO;
23214 + add->pathname = opt_str;
23215 + p = strchr(opt_str, '=');
23219 + add->perm = br_perm_val(p);
23222 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23225 + add->perm = AuBrPerm_RO;
23226 + if (au_test_fs_rr(add->path.dentry->d_sb))
23227 + add->perm = AuBrPerm_RR;
23228 + else if (!bindex && !(sb_flags & MS_RDONLY))
23229 + add->perm = AuBrPerm_RW;
23231 + opt->type = Opt_add;
23234 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23241 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23245 + del->pathname = args[0].from;
23246 + AuDbg("del path %s\n", del->pathname);
23248 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23249 + if (unlikely(err))
23250 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23255 +#if 0 /* reserved for future use */
23256 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23257 + struct au_opt_del *del, substring_t args[])
23260 + struct dentry *root;
23263 + root = sb->s_root;
23264 + aufs_read_lock(root, AuLock_FLUSH);
23265 + if (bindex < 0 || au_sbend(sb) < bindex) {
23266 + pr_err("out of bounds, %d\n", bindex);
23271 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
23272 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
23275 + aufs_read_unlock(root, !AuLock_IR);
23280 +static int noinline_for_stack
23281 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
23284 + struct path path;
23288 + mod->path = args[0].from;
23289 + p = strchr(mod->path, '=');
23290 + if (unlikely(!p)) {
23291 + pr_err("no permssion %s\n", args[0].from);
23296 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
23297 + if (unlikely(err)) {
23298 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23302 + mod->perm = br_perm_val(p);
23303 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23304 + mod->h_root = dget(path.dentry);
23311 +#if 0 /* reserved for future use */
23312 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23313 + struct au_opt_mod *mod, substring_t args[])
23316 + struct dentry *root;
23319 + root = sb->s_root;
23320 + aufs_read_lock(root, AuLock_FLUSH);
23321 + if (bindex < 0 || au_sbend(sb) < bindex) {
23322 + pr_err("out of bounds, %d\n", bindex);
23327 + mod->perm = br_perm_val(args[1].from);
23328 + AuDbg("mod path %s, perm 0x%x, %s\n",
23329 + mod->path, mod->perm, args[1].from);
23330 + mod->h_root = dget(au_h_dptr(root, bindex));
23333 + aufs_read_unlock(root, !AuLock_IR);
23338 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23339 + substring_t args[])
23342 + struct file *file;
23344 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23345 + err = PTR_ERR(file);
23346 + if (IS_ERR(file))
23350 + if (unlikely(file->f_dentry->d_sb == sb)) {
23352 + pr_err("%s must be outside\n", args[0].from);
23357 + xino->file = file;
23358 + xino->path = args[0].from;
23364 +static int noinline_for_stack
23365 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23366 + struct au_opt_xino_itrunc *xino_itrunc,
23367 + substring_t args[])
23370 + aufs_bindex_t bend, bindex;
23371 + struct path path;
23372 + struct dentry *root;
23374 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23375 + if (unlikely(err)) {
23376 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23380 + xino_itrunc->bindex = -1;
23381 + root = sb->s_root;
23382 + aufs_read_lock(root, AuLock_FLUSH);
23383 + bend = au_sbend(sb);
23384 + for (bindex = 0; bindex <= bend; bindex++) {
23385 + if (au_h_dptr(root, bindex) == path.dentry) {
23386 + xino_itrunc->bindex = bindex;
23390 + aufs_read_unlock(root, !AuLock_IR);
23393 + if (unlikely(xino_itrunc->bindex < 0)) {
23394 + pr_err("no such branch %s\n", args[0].from);
23402 +/* called without aufs lock */
23403 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23405 + int err, n, token;
23406 + aufs_bindex_t bindex;
23407 + unsigned char skipped;
23408 + struct dentry *root;
23409 + struct au_opt *opt, *opt_tail;
23411 + /* reduce the stack space */
23413 + struct au_opt_xino_itrunc *xino_itrunc;
23414 + struct au_opt_wbr_create *create;
23417 + substring_t args[MAX_OPT_ARGS];
23421 + a = kmalloc(sizeof(*a), GFP_NOFS);
23422 + if (unlikely(!a))
23425 + root = sb->s_root;
23429 + opt_tail = opt + opts->max_opt - 1;
23430 + opt->type = Opt_tail;
23431 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23434 + token = match_token(opt_str, options, a->args);
23438 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23440 + err = opt_add(opt, opt_str, opts->sb_flags,
23442 + if (unlikely(!err && ++opt > opt_tail)) {
23446 + opt->type = Opt_tail;
23451 + if (unlikely(match_int(&a->args[0], &n))) {
23452 + pr_err("bad integer in %s\n", opt_str);
23456 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23459 + opt->type = token;
23462 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23463 + /*dummy bindex*/1);
23465 + opt->type = token;
23467 + case Opt_prepend:
23468 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23471 + opt->type = token;
23474 + err = au_opts_parse_del(&opt->del, a->args);
23476 + opt->type = token;
23478 +#if 0 /* reserved for future use */
23480 + del->pathname = "(indexed)";
23481 + if (unlikely(match_int(&args[0], &n))) {
23482 + pr_err("bad integer in %s\n", opt_str);
23485 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23487 + opt->type = token;
23491 + err = au_opts_parse_mod(&opt->mod, a->args);
23493 + opt->type = token;
23495 +#ifdef IMOD /* reserved for future use */
23497 + u.mod->path = "(indexed)";
23498 + if (unlikely(match_int(&a->args[0], &n))) {
23499 + pr_err("bad integer in %s\n", opt_str);
23502 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23504 + opt->type = token;
23508 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23510 + opt->type = token;
23513 + case Opt_trunc_xino_path:
23514 + err = au_opts_parse_xino_itrunc_path
23515 + (sb, &opt->xino_itrunc, a->args);
23517 + opt->type = token;
23520 + case Opt_itrunc_xino:
23521 + u.xino_itrunc = &opt->xino_itrunc;
23522 + if (unlikely(match_int(&a->args[0], &n))) {
23523 + pr_err("bad integer in %s\n", opt_str);
23526 + u.xino_itrunc->bindex = n;
23527 + aufs_read_lock(root, AuLock_FLUSH);
23528 + if (n < 0 || au_sbend(sb) < n) {
23529 + pr_err("out of bounds, %d\n", n);
23530 + aufs_read_unlock(root, !AuLock_IR);
23533 + aufs_read_unlock(root, !AuLock_IR);
23535 + opt->type = token;
23539 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23542 + opt->type = token;
23545 + case Opt_rdcache:
23546 + if (unlikely(match_int(&a->args[0], &n))) {
23547 + pr_err("bad integer in %s\n", opt_str);
23550 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23551 + pr_err("rdcache must be smaller than %d\n",
23552 + AUFS_RDCACHE_MAX);
23555 + opt->rdcache = n;
23557 + opt->type = token;
23560 + if (unlikely(match_int(&a->args[0], &n)
23562 + || n > KMALLOC_MAX_SIZE)) {
23563 + pr_err("bad integer in %s\n", opt_str);
23566 + if (unlikely(n && n < NAME_MAX)) {
23567 + pr_err("rdblk must be larger than %d\n",
23573 + opt->type = token;
23576 + if (unlikely(match_int(&a->args[0], &n)
23578 + || n * sizeof(struct hlist_head)
23579 + > KMALLOC_MAX_SIZE)) {
23580 + pr_err("bad integer in %s\n", opt_str);
23585 + opt->type = token;
23588 + case Opt_trunc_xino:
23589 + case Opt_notrunc_xino:
23591 + case Opt_trunc_xib:
23592 + case Opt_notrunc_xib:
23595 + case Opt_dirperm1:
23596 + case Opt_nodirperm1:
23598 + case Opt_noplink:
23599 + case Opt_list_plink:
23602 + case Opt_diropq_a:
23603 + case Opt_diropq_w:
23604 + case Opt_warn_perm:
23605 + case Opt_nowarn_perm:
23607 + case Opt_norefrof:
23608 + case Opt_verbose:
23609 + case Opt_noverbose:
23613 + case Opt_rdblk_def:
23614 + case Opt_rdhash_def:
23618 + opt->type = token;
23622 + opt->udba = udba_val(a->args[0].from);
23623 + if (opt->udba >= 0) {
23625 + opt->type = token;
23627 + pr_err("wrong value, %s\n", opt_str);
23630 + case Opt_wbr_create:
23631 + u.create = &opt->wbr_create;
23632 + u.create->wbr_create
23633 + = au_wbr_create_val(a->args[0].from, u.create);
23634 + if (u.create->wbr_create >= 0) {
23636 + opt->type = token;
23638 + pr_err("wrong value, %s\n", opt_str);
23640 + case Opt_wbr_copyup:
23641 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23642 + if (opt->wbr_copyup >= 0) {
23644 + opt->type = token;
23646 + pr_err("wrong value, %s\n", opt_str);
23649 + case Opt_fhsm_sec:
23650 + if (unlikely(match_int(&a->args[0], &n)
23652 + pr_err("bad integer in %s\n", opt_str);
23655 + if (sysaufs_brs) {
23656 + opt->fhsm_second = n;
23657 + opt->type = token;
23659 + pr_warn("ignored %s\n", opt_str);
23664 + pr_warn("ignored %s\n", opt_str);
23666 + case Opt_ignore_silent:
23671 + pr_err("unknown option %s\n", opt_str);
23675 + if (!err && !skipped) {
23676 + if (unlikely(++opt > opt_tail)) {
23679 + opt->type = Opt_tail;
23682 + opt->type = Opt_tail;
23688 + if (unlikely(err))
23689 + au_opts_free(opts);
23695 +static int au_opt_wbr_create(struct super_block *sb,
23696 + struct au_opt_wbr_create *create)
23699 + struct au_sbinfo *sbinfo;
23701 + SiMustWriteLock(sb);
23703 + err = 1; /* handled */
23704 + sbinfo = au_sbi(sb);
23705 + if (sbinfo->si_wbr_create_ops->fin) {
23706 + err = sbinfo->si_wbr_create_ops->fin(sb);
23711 + sbinfo->si_wbr_create = create->wbr_create;
23712 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
23713 + switch (create->wbr_create) {
23714 + case AuWbrCreate_MFSRRV:
23715 + case AuWbrCreate_MFSRR:
23716 + case AuWbrCreate_PMFSRR:
23717 + case AuWbrCreate_PMFSRRV:
23718 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
23720 + case AuWbrCreate_MFS:
23721 + case AuWbrCreate_MFSV:
23722 + case AuWbrCreate_PMFS:
23723 + case AuWbrCreate_PMFSV:
23724 + sbinfo->si_wbr_mfs.mfs_expire
23725 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
23729 + if (sbinfo->si_wbr_create_ops->init)
23730 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
23737 + * plus: processed without an error
23738 + * zero: unprocessed
23740 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
23741 + struct au_opts *opts)
23744 + struct au_sbinfo *sbinfo;
23746 + SiMustWriteLock(sb);
23748 + err = 1; /* handled */
23749 + sbinfo = au_sbi(sb);
23750 + switch (opt->type) {
23752 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23753 + sbinfo->si_mntflags |= opt->udba;
23754 + opts->given_udba |= opt->udba;
23758 + au_opt_set(sbinfo->si_mntflags, PLINK);
23760 + case Opt_noplink:
23761 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23762 + au_plink_put(sb, /*verbose*/1);
23763 + au_opt_clr(sbinfo->si_mntflags, PLINK);
23765 + case Opt_list_plink:
23766 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23767 + au_plink_list(sb);
23771 + au_opt_set(sbinfo->si_mntflags, DIO);
23772 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23775 + au_opt_clr(sbinfo->si_mntflags, DIO);
23776 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23779 + case Opt_fhsm_sec:
23780 + au_fhsm_set(sbinfo, opt->fhsm_second);
23783 + case Opt_diropq_a:
23784 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23786 + case Opt_diropq_w:
23787 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23790 + case Opt_warn_perm:
23791 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
23793 + case Opt_nowarn_perm:
23794 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
23798 + au_opt_set(sbinfo->si_mntflags, REFROF);
23800 + case Opt_norefrof:
23801 + au_opt_clr(sbinfo->si_mntflags, REFROF);
23804 + case Opt_verbose:
23805 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
23807 + case Opt_noverbose:
23808 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
23812 + au_opt_set(sbinfo->si_mntflags, SUM);
23815 + au_opt_clr(sbinfo->si_mntflags, SUM);
23816 + au_opt_set(sbinfo->si_mntflags, SUM_W);
23818 + au_opt_clr(sbinfo->si_mntflags, SUM);
23819 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
23822 + case Opt_wbr_create:
23823 + err = au_opt_wbr_create(sb, &opt->wbr_create);
23825 + case Opt_wbr_copyup:
23826 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
23827 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
23831 + sbinfo->si_dirwh = opt->dirwh;
23834 + case Opt_rdcache:
23835 + sbinfo->si_rdcache
23836 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
23839 + sbinfo->si_rdblk = opt->rdblk;
23841 + case Opt_rdblk_def:
23842 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
23845 + sbinfo->si_rdhash = opt->rdhash;
23847 + case Opt_rdhash_def:
23848 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
23852 + au_opt_set(sbinfo->si_mntflags, SHWH);
23855 + au_opt_clr(sbinfo->si_mntflags, SHWH);
23858 + case Opt_dirperm1:
23859 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
23861 + case Opt_nodirperm1:
23862 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
23865 + case Opt_trunc_xino:
23866 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
23868 + case Opt_notrunc_xino:
23869 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
23872 + case Opt_trunc_xino_path:
23873 + case Opt_itrunc_xino:
23874 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
23879 + case Opt_trunc_xib:
23880 + au_fset_opts(opts->flags, TRUNC_XIB);
23882 + case Opt_notrunc_xib:
23883 + au_fclr_opts(opts->flags, TRUNC_XIB);
23887 + sb->s_flags |= MS_POSIXACL;
23890 + sb->s_flags &= ~MS_POSIXACL;
23902 + * returns tri-state.
23903 + * plus: processed without an error
23904 + * zero: unprocessed
23907 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
23908 + struct au_opts *opts)
23910 + int err, do_refresh;
23913 + switch (opt->type) {
23915 + opt->add.bindex = au_sbend(sb) + 1;
23916 + if (opt->add.bindex < 0)
23917 + opt->add.bindex = 0;
23919 + case Opt_prepend:
23920 + opt->add.bindex = 0;
23921 + add: /* indented label */
23923 + err = au_br_add(sb, &opt->add,
23924 + au_ftest_opts(opts->flags, REMOUNT));
23927 + au_fset_opts(opts->flags, REFRESH);
23933 + err = au_br_del(sb, &opt->del,
23934 + au_ftest_opts(opts->flags, REMOUNT));
23937 + au_fset_opts(opts->flags, TRUNC_XIB);
23938 + au_fset_opts(opts->flags, REFRESH);
23944 + err = au_br_mod(sb, &opt->mod,
23945 + au_ftest_opts(opts->flags, REMOUNT),
23950 + au_fset_opts(opts->flags, REFRESH);
23958 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
23959 + struct au_opt_xino **opt_xino,
23960 + struct au_opts *opts)
23963 + aufs_bindex_t bend, bindex;
23964 + struct dentry *root, *parent, *h_root;
23967 + switch (opt->type) {
23969 + err = au_xino_set(sb, &opt->xino,
23970 + !!au_ftest_opts(opts->flags, REMOUNT));
23971 + if (unlikely(err))
23974 + *opt_xino = &opt->xino;
23975 + au_xino_brid_set(sb, -1);
23977 + /* safe d_parent access */
23978 + parent = opt->xino.file->f_dentry->d_parent;
23979 + root = sb->s_root;
23980 + bend = au_sbend(sb);
23981 + for (bindex = 0; bindex <= bend; bindex++) {
23982 + h_root = au_h_dptr(root, bindex);
23983 + if (h_root == parent) {
23984 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
23992 + au_xino_brid_set(sb, -1);
23993 + *opt_xino = (void *)-1;
24000 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24001 + unsigned int pending)
24004 + aufs_bindex_t bindex, bend;
24005 + unsigned char do_plink, skip, do_free;
24006 + struct au_branch *br;
24007 + struct au_wbr *wbr;
24008 + struct dentry *root;
24009 + struct inode *dir, *h_dir;
24010 + struct au_sbinfo *sbinfo;
24011 + struct au_hinode *hdir;
24013 + SiMustAnyLock(sb);
24015 + sbinfo = au_sbi(sb);
24016 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24018 + if (!(sb_flags & MS_RDONLY)) {
24019 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24020 + pr_warn("first branch should be rw\n");
24021 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24022 + pr_warn("shwh should be used with ro\n");
24025 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24026 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24027 + pr_warn("udba=*notify requires xino\n");
24029 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24030 + pr_warn("dirperm1 breaks the protection"
24031 + " by the permission bits on the lower branch\n");
24035 + root = sb->s_root;
24036 + dir = root->d_inode;
24037 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24038 + bend = au_sbend(sb);
24039 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24041 + h_dir = au_h_iptr(dir, bindex);
24042 + br = au_sbr(sb, bindex);
24044 + if ((br->br_perm & AuBrAttr_ICEX)
24045 + && !h_dir->i_op->listxattr)
24046 + br->br_perm &= ~AuBrAttr_ICEX;
24048 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24049 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24050 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24054 + wbr = br->br_wbr;
24056 + wbr_wh_read_lock(wbr);
24058 + if (!au_br_writable(br->br_perm)) {
24061 + || (!wbr->wbr_whbase
24062 + && !wbr->wbr_plink
24063 + && !wbr->wbr_orph));
24064 + } else if (!au_br_wh_linkable(br->br_perm)) {
24065 + /* skip = (!br->br_whbase && !br->br_orph); */
24066 + skip = (!wbr || !wbr->wbr_whbase);
24067 + if (skip && wbr) {
24069 + skip = !!wbr->wbr_plink;
24071 + skip = !wbr->wbr_plink;
24074 + /* skip = (br->br_whbase && br->br_ohph); */
24075 + skip = (wbr && wbr->wbr_whbase);
24078 + skip = !!wbr->wbr_plink;
24080 + skip = !wbr->wbr_plink;
24084 + wbr_wh_read_unlock(wbr);
24086 + if (au_br_fhsm(br->br_perm)) {
24088 + AuDebugOn(!br->br_fhsm);
24094 + hdir = au_hi(dir, bindex);
24095 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
24097 + wbr_wh_write_lock(wbr);
24098 + err = au_wh_init(br, sb);
24100 + wbr_wh_write_unlock(wbr);
24101 + au_hn_imtx_unlock(hdir);
24103 + if (!err && do_free) {
24105 + br->br_wbr = NULL;
24110 + au_fset_si(sbinfo, FHSM);
24111 + for (bindex = bend; bindex >= 0; bindex--) {
24112 + br = au_sbr(sb, bindex);
24113 + if (au_br_fhsm(br->br_perm)) {
24114 + au_fhsm_set_bottom(sb, bindex);
24119 + au_fclr_si(sbinfo, FHSM);
24120 + au_fhsm_set_bottom(sb, -1);
24126 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24129 + unsigned int tmp;
24130 + aufs_bindex_t bindex, bend;
24131 + struct au_opt *opt;
24132 + struct au_opt_xino *opt_xino, xino;
24133 + struct au_sbinfo *sbinfo;
24134 + struct au_branch *br;
24135 + struct inode *dir;
24137 + SiMustWriteLock(sb);
24142 + while (err >= 0 && opt->type != Opt_tail)
24143 + err = au_opt_simple(sb, opt++, opts);
24146 + else if (unlikely(err < 0))
24149 + /* disable xino and udba temporary */
24150 + sbinfo = au_sbi(sb);
24151 + tmp = sbinfo->si_mntflags;
24152 + au_opt_clr(sbinfo->si_mntflags, XINO);
24153 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24156 + while (err >= 0 && opt->type != Opt_tail)
24157 + err = au_opt_br(sb, opt++, opts);
24160 + else if (unlikely(err < 0))
24163 + bend = au_sbend(sb);
24164 + if (unlikely(bend < 0)) {
24166 + pr_err("no branches\n");
24170 + if (au_opt_test(tmp, XINO))
24171 + au_opt_set(sbinfo->si_mntflags, XINO);
24173 + while (!err && opt->type != Opt_tail)
24174 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24175 + if (unlikely(err))
24178 + err = au_opts_verify(sb, sb->s_flags, tmp);
24179 + if (unlikely(err))
24182 + /* restore xino */
24183 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24184 + xino.file = au_xino_def(sb);
24185 + err = PTR_ERR(xino.file);
24186 + if (IS_ERR(xino.file))
24189 + err = au_xino_set(sb, &xino, /*remount*/0);
24191 + if (unlikely(err))
24195 + /* restore udba */
24196 + tmp &= AuOptMask_UDBA;
24197 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24198 + sbinfo->si_mntflags |= tmp;
24199 + bend = au_sbend(sb);
24200 + for (bindex = 0; bindex <= bend; bindex++) {
24201 + br = au_sbr(sb, bindex);
24202 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24203 + if (unlikely(err))
24204 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24206 + /* go on even if err */
24208 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24209 + dir = sb->s_root->d_inode;
24210 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24217 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24220 + struct inode *dir;
24221 + struct au_opt_xino *opt_xino;
24222 + struct au_opt *opt;
24223 + struct au_sbinfo *sbinfo;
24225 + SiMustWriteLock(sb);
24227 + dir = sb->s_root->d_inode;
24228 + sbinfo = au_sbi(sb);
24232 + while (err >= 0 && opt->type != Opt_tail) {
24233 + err = au_opt_simple(sb, opt, opts);
24235 + err = au_opt_br(sb, opt, opts);
24237 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24243 + /* go on even err */
24245 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24246 + if (unlikely(rerr && !err))
24249 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24250 + rerr = au_xib_trunc(sb);
24251 + if (unlikely(rerr && !err))
24255 + /* will be handled by the caller */
24256 + if (!au_ftest_opts(opts->flags, REFRESH)
24257 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
24258 + au_fset_opts(opts->flags, REFRESH);
24260 + AuDbg("status 0x%x\n", opts->flags);
24264 +/* ---------------------------------------------------------------------- */
24266 +unsigned int au_opt_udba(struct super_block *sb)
24268 + return au_mntflags(sb) & AuOptMask_UDBA;
24270 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
24271 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
24272 +++ linux/fs/aufs/opts.h 2015-01-25 13:00:38.634380408 +0100
24275 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24277 + * This program, aufs is free software; you can redistribute it and/or modify
24278 + * it under the terms of the GNU General Public License as published by
24279 + * the Free Software Foundation; either version 2 of the License, or
24280 + * (at your option) any later version.
24282 + * This program is distributed in the hope that it will be useful,
24283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24285 + * GNU General Public License for more details.
24287 + * You should have received a copy of the GNU General Public License
24288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24292 + * mount options/flags
24295 +#ifndef __AUFS_OPTS_H__
24296 +#define __AUFS_OPTS_H__
24300 +#include <linux/path.h>
24301 +#include "branch.h"
24304 +struct super_block;
24306 +/* ---------------------------------------------------------------------- */
24309 +#define AuOpt_XINO 1 /* external inode number bitmap
24310 + and translation table */
24311 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24312 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24313 +#define AuOpt_UDBA_REVAL (1 << 3)
24314 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24315 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24316 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24317 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24319 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
24320 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24321 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24322 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24323 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24324 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24325 +#define AuOpt_DIO (1 << 14) /* direct io */
24327 +#ifndef CONFIG_AUFS_HNOTIFY
24328 +#undef AuOpt_UDBA_HNOTIFY
24329 +#define AuOpt_UDBA_HNOTIFY 0
24331 +#ifndef CONFIG_AUFS_SHWH
24333 +#define AuOpt_SHWH 0
24336 +#define AuOpt_Def (AuOpt_XINO \
24337 + | AuOpt_UDBA_REVAL \
24339 + /* | AuOpt_DIRPERM1 */ \
24340 + | AuOpt_WARN_PERM)
24341 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24342 + | AuOpt_UDBA_REVAL \
24343 + | AuOpt_UDBA_HNOTIFY)
24345 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24346 +#define au_opt_set(flags, name) do { \
24347 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24348 + ((flags) |= AuOpt_##name); \
24350 +#define au_opt_set_udba(flags, name) do { \
24351 + (flags) &= ~AuOptMask_UDBA; \
24352 + ((flags) |= AuOpt_##name); \
24354 +#define au_opt_clr(flags, name) do { \
24355 + ((flags) &= ~AuOpt_##name); \
24358 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24360 +#ifdef CONFIG_PROC_FS
24363 + return mntflags & ~AuOpt_PLINK;
24367 +/* ---------------------------------------------------------------------- */
24369 +/* policies to select one among multiple writable branches */
24371 + AuWbrCreate_TDP, /* top down parent */
24372 + AuWbrCreate_RR, /* round robin */
24373 + AuWbrCreate_MFS, /* most free space */
24374 + AuWbrCreate_MFSV, /* mfs with seconds */
24375 + AuWbrCreate_MFSRR, /* mfs then rr */
24376 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24377 + AuWbrCreate_PMFS, /* parent and mfs */
24378 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24379 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24380 + AuWbrCreate_PMFSRRV, /* plus seconds */
24382 + AuWbrCreate_Def = AuWbrCreate_TDP
24386 + AuWbrCopyup_TDP, /* top down parent */
24387 + AuWbrCopyup_BUP, /* bottom up parent */
24388 + AuWbrCopyup_BU, /* bottom up */
24390 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24393 +/* ---------------------------------------------------------------------- */
24395 +struct au_opt_add {
24396 + aufs_bindex_t bindex;
24399 + struct path path;
24402 +struct au_opt_del {
24404 + struct path h_path;
24407 +struct au_opt_mod {
24410 + struct dentry *h_root;
24413 +struct au_opt_xino {
24415 + struct file *file;
24418 +struct au_opt_xino_itrunc {
24419 + aufs_bindex_t bindex;
24422 +struct au_opt_wbr_create {
24425 + unsigned long long mfsrr_watermark;
24431 + struct au_opt_xino xino;
24432 + struct au_opt_xino_itrunc xino_itrunc;
24433 + struct au_opt_add add;
24434 + struct au_opt_del del;
24435 + struct au_opt_mod mod;
24438 + unsigned int rdblk;
24439 + unsigned int rdhash;
24441 + struct au_opt_wbr_create wbr_create;
24443 + unsigned int fhsm_second;
24448 +#define AuOpts_REMOUNT 1
24449 +#define AuOpts_REFRESH (1 << 1)
24450 +#define AuOpts_TRUNC_XIB (1 << 2)
24451 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24452 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24453 +#define au_fset_opts(flags, name) \
24454 + do { (flags) |= AuOpts_##name; } while (0)
24455 +#define au_fclr_opts(flags, name) \
24456 + do { (flags) &= ~AuOpts_##name; } while (0)
24459 + struct au_opt *opt;
24462 + unsigned int given_udba;
24463 + unsigned int flags;
24464 + unsigned long sb_flags;
24467 +/* ---------------------------------------------------------------------- */
24469 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24470 +const char *au_optstr_udba(int udba);
24471 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24472 +const char *au_optstr_wbr_create(int wbr_create);
24474 +void au_opts_free(struct au_opts *opts);
24475 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24476 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24477 + unsigned int pending);
24478 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24479 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24481 +unsigned int au_opt_udba(struct super_block *sb);
24483 +/* ---------------------------------------------------------------------- */
24485 +#endif /* __KERNEL__ */
24486 +#endif /* __AUFS_OPTS_H__ */
24487 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24488 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24489 +++ linux/fs/aufs/plink.c 2015-01-25 13:00:38.634380408 +0100
24492 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24494 + * This program, aufs is free software; you can redistribute it and/or modify
24495 + * it under the terms of the GNU General Public License as published by
24496 + * the Free Software Foundation; either version 2 of the License, or
24497 + * (at your option) any later version.
24499 + * This program is distributed in the hope that it will be useful,
24500 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24501 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24502 + * GNU General Public License for more details.
24504 + * You should have received a copy of the GNU General Public License
24505 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24515 + * the pseudo-link maintenance mode.
24516 + * during a user process maintains the pseudo-links,
24517 + * prohibit adding a new plink and branch manipulation.
24521 + * For entry functions which will handle plink, and i_mutex is already held
24523 + * They cannot wait and should return an error at once.
24524 + * Callers has to check the error.
24526 + * For entry functions which will handle plink, but i_mutex is not held
24528 + * They can wait the plink maintenance mode to finish.
24530 + * They behave like F_SETLK and F_SETLKW.
24531 + * If the caller never handle plink, then both flags are unnecessary.
24534 +int au_plink_maint(struct super_block *sb, int flags)
24538 + struct au_sbinfo *sbi;
24540 + SiMustAnyLock(sb);
24543 + if (!au_opt_test(au_mntflags(sb), PLINK))
24546 + sbi = au_sbi(sb);
24547 + pid = sbi->si_plink_maint_pid;
24548 + if (!pid || pid == current->pid)
24551 + /* todo: it highly depends upon /sbin/mount.aufs */
24553 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24554 + rcu_read_unlock();
24558 + if (au_ftest_lock(flags, NOPLMW)) {
24559 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24560 + /* AuDebugOn(!lockdep_depth(current)); */
24561 + while (sbi->si_plink_maint_pid) {
24562 + si_read_unlock(sb);
24563 + /* gave up wake_up_bit() */
24564 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24566 + if (au_ftest_lock(flags, FLUSH))
24567 + au_nwt_flush(&sbi->si_nowait);
24568 + si_noflush_read_lock(sb);
24570 + } else if (au_ftest_lock(flags, NOPLM)) {
24571 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24579 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24581 + spin_lock(&sbinfo->si_plink_maint_lock);
24582 + sbinfo->si_plink_maint_pid = 0;
24583 + spin_unlock(&sbinfo->si_plink_maint_lock);
24584 + wake_up_all(&sbinfo->si_plink_wq);
24587 +int au_plink_maint_enter(struct super_block *sb)
24590 + struct au_sbinfo *sbinfo;
24593 + sbinfo = au_sbi(sb);
24594 + /* make sure i am the only one in this fs */
24595 + si_write_lock(sb, AuLock_FLUSH);
24596 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24597 + spin_lock(&sbinfo->si_plink_maint_lock);
24598 + if (!sbinfo->si_plink_maint_pid)
24599 + sbinfo->si_plink_maint_pid = current->pid;
24602 + spin_unlock(&sbinfo->si_plink_maint_lock);
24604 + si_write_unlock(sb);
24609 +/* ---------------------------------------------------------------------- */
24611 +#ifdef CONFIG_AUFS_DEBUG
24612 +void au_plink_list(struct super_block *sb)
24615 + struct au_sbinfo *sbinfo;
24616 + struct hlist_head *plink_hlist;
24617 + struct pseudo_link *plink;
24619 + SiMustAnyLock(sb);
24621 + sbinfo = au_sbi(sb);
24622 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24623 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24625 + for (i = 0; i < AuPlink_NHASH; i++) {
24626 + plink_hlist = &sbinfo->si_plink[i].head;
24628 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24629 + AuDbg("%lu\n", plink->inode->i_ino);
24630 + rcu_read_unlock();
24635 +/* is the inode pseudo-linked? */
24636 +int au_plink_test(struct inode *inode)
24639 + struct au_sbinfo *sbinfo;
24640 + struct hlist_head *plink_hlist;
24641 + struct pseudo_link *plink;
24643 + sbinfo = au_sbi(inode->i_sb);
24644 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24645 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
24646 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24649 + i = au_plink_hash(inode->i_ino);
24650 + plink_hlist = &sbinfo->si_plink[i].head;
24652 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24653 + if (plink->inode == inode) {
24657 + rcu_read_unlock();
24661 +/* ---------------------------------------------------------------------- */
24664 + * generate a name for plink.
24665 + * the file will be stored under AUFS_WH_PLINKDIR.
24667 +/* 20 is max digits length of ulong 64 */
24668 +#define PLINK_NAME_LEN ((20 + 1) * 2)
24670 +static int plink_name(char *name, int len, struct inode *inode,
24671 + aufs_bindex_t bindex)
24674 + struct inode *h_inode;
24676 + h_inode = au_h_iptr(inode, bindex);
24677 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
24681 +struct au_do_plink_lkup_args {
24682 + struct dentry **errp;
24683 + struct qstr *tgtname;
24684 + struct dentry *h_parent;
24685 + struct au_branch *br;
24688 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
24689 + struct dentry *h_parent,
24690 + struct au_branch *br)
24692 + struct dentry *h_dentry;
24693 + struct mutex *h_mtx;
24695 + h_mtx = &h_parent->d_inode->i_mutex;
24696 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
24697 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
24698 + mutex_unlock(h_mtx);
24702 +static void au_call_do_plink_lkup(void *args)
24704 + struct au_do_plink_lkup_args *a = args;
24705 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
24708 +/* lookup the plink-ed @inode under the branch at @bindex */
24709 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
24711 + struct dentry *h_dentry, *h_parent;
24712 + struct au_branch *br;
24713 + struct inode *h_dir;
24715 + char a[PLINK_NAME_LEN];
24716 + struct qstr tgtname = QSTR_INIT(a, 0);
24718 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24720 + br = au_sbr(inode->i_sb, bindex);
24721 + h_parent = br->br_wbr->wbr_plink;
24722 + h_dir = h_parent->d_inode;
24723 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24725 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24726 + struct au_do_plink_lkup_args args = {
24727 + .errp = &h_dentry,
24728 + .tgtname = &tgtname,
24729 + .h_parent = h_parent,
24733 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
24734 + if (unlikely(wkq_err))
24735 + h_dentry = ERR_PTR(wkq_err);
24737 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
24742 +/* create a pseudo-link */
24743 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
24744 + struct dentry *h_dentry, struct au_branch *br)
24747 + struct path h_path = {
24748 + .mnt = au_br_mnt(br)
24750 + struct inode *h_dir, *delegated;
24752 + h_dir = h_parent->d_inode;
24753 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
24755 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
24756 + err = PTR_ERR(h_path.dentry);
24757 + if (IS_ERR(h_path.dentry))
24761 + /* wh.plink dir is not monitored */
24762 + /* todo: is it really safe? */
24763 + if (h_path.dentry->d_inode
24764 + && h_path.dentry->d_inode != h_dentry->d_inode) {
24765 + delegated = NULL;
24766 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
24767 + if (unlikely(err == -EWOULDBLOCK)) {
24768 + pr_warn("cannot retry for NFSv4 delegation"
24769 + " for an internal unlink\n");
24772 + dput(h_path.dentry);
24773 + h_path.dentry = NULL;
24777 + if (!err && !h_path.dentry->d_inode) {
24778 + delegated = NULL;
24779 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
24780 + if (unlikely(err == -EWOULDBLOCK)) {
24781 + pr_warn("cannot retry for NFSv4 delegation"
24782 + " for an internal link\n");
24786 + dput(h_path.dentry);
24789 + mutex_unlock(&h_dir->i_mutex);
24793 +struct do_whplink_args {
24795 + struct qstr *tgt;
24796 + struct dentry *h_parent;
24797 + struct dentry *h_dentry;
24798 + struct au_branch *br;
24801 +static void call_do_whplink(void *args)
24803 + struct do_whplink_args *a = args;
24804 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
24807 +static int whplink(struct dentry *h_dentry, struct inode *inode,
24808 + aufs_bindex_t bindex, struct au_branch *br)
24810 + int err, wkq_err;
24811 + struct au_wbr *wbr;
24812 + struct dentry *h_parent;
24813 + struct inode *h_dir;
24814 + char a[PLINK_NAME_LEN];
24815 + struct qstr tgtname = QSTR_INIT(a, 0);
24817 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
24818 + h_parent = wbr->wbr_plink;
24819 + h_dir = h_parent->d_inode;
24820 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24822 + /* always superio. */
24823 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24824 + struct do_whplink_args args = {
24827 + .h_parent = h_parent,
24828 + .h_dentry = h_dentry,
24831 + wkq_err = au_wkq_wait(call_do_whplink, &args);
24832 + if (unlikely(wkq_err))
24835 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
24840 +/* free a single plink */
24841 +static void do_put_plink(struct pseudo_link *plink, int do_del)
24844 + hlist_del(&plink->hlist);
24845 + iput(plink->inode);
24849 +static void do_put_plink_rcu(struct rcu_head *rcu)
24851 + struct pseudo_link *plink;
24853 + plink = container_of(rcu, struct pseudo_link, rcu);
24854 + iput(plink->inode);
24859 + * create a new pseudo-link for @h_dentry on @bindex.
24860 + * the linked inode is held in aufs @inode.
24862 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
24863 + struct dentry *h_dentry)
24865 + struct super_block *sb;
24866 + struct au_sbinfo *sbinfo;
24867 + struct hlist_head *plink_hlist;
24868 + struct pseudo_link *plink, *tmp;
24869 + struct au_sphlhead *sphl;
24870 + int found, err, cnt, i;
24872 + sb = inode->i_sb;
24873 + sbinfo = au_sbi(sb);
24874 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24875 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24877 + found = au_plink_test(inode);
24881 + i = au_plink_hash(inode->i_ino);
24882 + sphl = sbinfo->si_plink + i;
24883 + plink_hlist = &sphl->head;
24884 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
24886 + tmp->inode = au_igrab(inode);
24892 + spin_lock(&sphl->spin);
24893 + hlist_for_each_entry(plink, plink_hlist, hlist) {
24894 + if (plink->inode == inode) {
24900 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
24901 + spin_unlock(&sphl->spin);
24903 + cnt = au_sphl_count(sphl);
24904 +#define msg "unexpectedly unblanced or too many pseudo-links"
24905 + if (cnt > AUFS_PLINK_WARN)
24906 + AuWarn1(msg ", %d\n", cnt);
24908 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
24910 + do_put_plink(tmp, 0);
24915 + if (unlikely(err)) {
24916 + pr_warn("err %d, damaged pseudo link.\n", err);
24918 + au_sphl_del_rcu(&tmp->hlist, sphl);
24919 + call_rcu(&tmp->rcu, do_put_plink_rcu);
24924 +/* free all plinks */
24925 +void au_plink_put(struct super_block *sb, int verbose)
24928 + struct au_sbinfo *sbinfo;
24929 + struct hlist_head *plink_hlist;
24930 + struct hlist_node *tmp;
24931 + struct pseudo_link *plink;
24933 + SiMustWriteLock(sb);
24935 + sbinfo = au_sbi(sb);
24936 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24937 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24939 + /* no spin_lock since sbinfo is write-locked */
24941 + for (i = 0; i < AuPlink_NHASH; i++) {
24942 + plink_hlist = &sbinfo->si_plink[i].head;
24943 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
24944 + pr_warn("pseudo-link is not flushed");
24947 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
24948 + do_put_plink(plink, 0);
24949 + INIT_HLIST_HEAD(plink_hlist);
24953 +void au_plink_clean(struct super_block *sb, int verbose)
24955 + struct dentry *root;
24957 + root = sb->s_root;
24958 + aufs_write_lock(root);
24959 + if (au_opt_test(au_mntflags(sb), PLINK))
24960 + au_plink_put(sb, verbose);
24961 + aufs_write_unlock(root);
24964 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
24967 + aufs_bindex_t bstart, bend, bindex;
24970 + bstart = au_ibstart(inode);
24971 + bend = au_ibend(inode);
24972 + if (bstart >= 0) {
24973 + for (bindex = bstart; bindex <= bend; bindex++) {
24974 + if (!au_h_iptr(inode, bindex)
24975 + || au_ii_br_id(inode, bindex) != br_id)
24977 + au_set_h_iptr(inode, bindex, NULL, 0);
24982 + for (bindex = bstart; bindex <= bend; bindex++)
24983 + if (au_h_iptr(inode, bindex)) {
24993 +/* free the plinks on a branch specified by @br_id */
24994 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
24996 + struct au_sbinfo *sbinfo;
24997 + struct hlist_head *plink_hlist;
24998 + struct hlist_node *tmp;
24999 + struct pseudo_link *plink;
25000 + struct inode *inode;
25003 + SiMustWriteLock(sb);
25005 + sbinfo = au_sbi(sb);
25006 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25007 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25009 + /* no spin_lock since sbinfo is write-locked */
25010 + for (i = 0; i < AuPlink_NHASH; i++) {
25011 + plink_hlist = &sbinfo->si_plink[i].head;
25012 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
25013 + inode = au_igrab(plink->inode);
25014 + ii_write_lock_child(inode);
25015 + do_put = au_plink_do_half_refresh(inode, br_id);
25017 + do_put_plink(plink, 1);
25018 + ii_write_unlock(inode);
25023 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25024 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25025 +++ linux/fs/aufs/poll.c 2015-01-25 13:00:38.634380408 +0100
25028 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25030 + * This program, aufs is free software; you can redistribute it and/or modify
25031 + * it under the terms of the GNU General Public License as published by
25032 + * the Free Software Foundation; either version 2 of the License, or
25033 + * (at your option) any later version.
25035 + * This program is distributed in the hope that it will be useful,
25036 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25037 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25038 + * GNU General Public License for more details.
25040 + * You should have received a copy of the GNU General Public License
25041 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25046 + * There is only one filesystem which implements ->poll operation, currently.
25051 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25053 + unsigned int mask;
25055 + struct file *h_file;
25056 + struct dentry *dentry;
25057 + struct super_block *sb;
25059 + /* We should pretend an error happened. */
25060 + mask = POLLERR /* | POLLIN | POLLOUT */;
25061 + dentry = file->f_dentry;
25062 + sb = dentry->d_sb;
25063 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25064 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
25065 + if (unlikely(err))
25068 + /* it is not an error if h_file has no operation */
25069 + mask = DEFAULT_POLLMASK;
25070 + h_file = au_hf_top(file);
25071 + if (h_file->f_op->poll)
25072 + mask = h_file->f_op->poll(h_file, wait);
25074 + di_read_unlock(dentry, AuLock_IR);
25075 + fi_read_unlock(file);
25078 + si_read_unlock(sb);
25079 + AuTraceErr((int)mask);
25082 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25083 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25084 +++ linux/fs/aufs/posix_acl.c 2015-01-25 13:00:38.634380408 +0100
25087 + * Copyright (C) 2014 Junjiro R. Okajima
25089 + * This program, aufs is free software; you can redistribute it and/or modify
25090 + * it under the terms of the GNU General Public License as published by
25091 + * the Free Software Foundation; either version 2 of the License, or
25092 + * (at your option) any later version.
25094 + * This program is distributed in the hope that it will be useful,
25095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25097 + * GNU General Public License for more details.
25099 + * You should have received a copy of the GNU General Public License
25100 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25104 + * posix acl operations
25107 +#include <linux/fs.h>
25108 +#include <linux/posix_acl.h>
25111 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25113 + struct posix_acl *acl;
25115 + aufs_bindex_t bindex;
25116 + struct inode *h_inode;
25117 + struct super_block *sb;
25120 + sb = inode->i_sb;
25121 + si_read_lock(sb, AuLock_FLUSH);
25122 + ii_read_lock_child(inode);
25123 + if (!(sb->s_flags & MS_POSIXACL))
25126 + bindex = au_ibstart(inode);
25127 + h_inode = au_h_iptr(inode, bindex);
25128 + if (unlikely(!h_inode
25129 + || ((h_inode->i_mode & S_IFMT)
25130 + != (inode->i_mode & S_IFMT)))) {
25131 + err = au_busy_or_stale();
25132 + acl = ERR_PTR(err);
25136 + /* always topmost only */
25137 + acl = get_acl(h_inode, type);
25140 + ii_read_unlock(inode);
25141 + si_read_unlock(sb);
25143 + AuTraceErrPtr(acl);
25147 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25151 + struct dentry *dentry;
25152 + struct au_srxattr arg = {
25153 + .type = AU_ACL_SET,
25160 + mutex_lock(&inode->i_mutex);
25161 + if (inode->i_ino == AUFS_ROOT_INO)
25162 + dentry = dget(inode->i_sb->s_root);
25164 + dentry = d_find_alias(inode);
25166 + dentry = d_find_any_alias(inode);
25168 + pr_warn("cannot handle this inode, "
25169 + "please report to aufs-users ML\n");
25175 + ssz = au_srxattr(dentry, &arg);
25182 + mutex_unlock(&inode->i_mutex);
25185 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25186 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25187 +++ linux/fs/aufs/procfs.c 2015-01-25 13:00:38.634380408 +0100
25190 + * Copyright (C) 2010-2014 Junjiro R. Okajima
25192 + * This program, aufs is free software; you can redistribute it and/or modify
25193 + * it under the terms of the GNU General Public License as published by
25194 + * the Free Software Foundation; either version 2 of the License, or
25195 + * (at your option) any later version.
25197 + * This program is distributed in the hope that it will be useful,
25198 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25199 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25200 + * GNU General Public License for more details.
25202 + * You should have received a copy of the GNU General Public License
25203 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25207 + * procfs interfaces
25210 +#include <linux/proc_fs.h>
25213 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25215 + struct au_sbinfo *sbinfo;
25217 + sbinfo = file->private_data;
25219 + au_plink_maint_leave(sbinfo);
25220 + kobject_put(&sbinfo->si_kobj);
25226 +static void au_procfs_plm_write_clean(struct file *file)
25228 + struct au_sbinfo *sbinfo;
25230 + sbinfo = file->private_data;
25232 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25235 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25238 + struct super_block *sb;
25239 + struct au_sbinfo *sbinfo;
25242 + if (unlikely(file->private_data))
25246 + /* don't use au_sbilist_lock() here */
25247 + spin_lock(&au_sbilist.spin);
25248 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25249 + if (id == sysaufs_si_id(sbinfo)) {
25250 + kobject_get(&sbinfo->si_kobj);
25251 + sb = sbinfo->si_sb;
25254 + spin_unlock(&au_sbilist.spin);
25257 + if (unlikely(!sb))
25260 + err = au_plink_maint_enter(sb);
25262 + /* keep kobject_get() */
25263 + file->private_data = sbinfo;
25265 + kobject_put(&sbinfo->si_kobj);
25271 + * Accept a valid "si=xxxx" only.
25272 + * Once it is accepted successfully, accept "clean" too.
25274 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
25275 + size_t count, loff_t *ppos)
25278 + unsigned long id;
25279 + /* last newline is allowed */
25280 + char buf[3 + sizeof(unsigned long) * 2 + 1];
25283 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25287 + if (unlikely(count > sizeof(buf)))
25290 + err = copy_from_user(buf, ubuf, count);
25291 + if (unlikely(err)) {
25298 + if (!strcmp("clean", buf)) {
25299 + au_procfs_plm_write_clean(file);
25300 + goto out_success;
25301 + } else if (unlikely(strncmp("si=", buf, 3)))
25304 + err = kstrtoul(buf + 3, 16, &id);
25305 + if (unlikely(err))
25308 + err = au_procfs_plm_write_si(file, id);
25309 + if (unlikely(err))
25313 + err = count; /* success */
25318 +static const struct file_operations au_procfs_plm_fop = {
25319 + .write = au_procfs_plm_write,
25320 + .release = au_procfs_plm_release,
25321 + .owner = THIS_MODULE
25324 +/* ---------------------------------------------------------------------- */
25326 +static struct proc_dir_entry *au_procfs_dir;
25328 +void au_procfs_fin(void)
25330 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25331 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25334 +int __init au_procfs_init(void)
25337 + struct proc_dir_entry *entry;
25340 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25341 + if (unlikely(!au_procfs_dir))
25344 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25345 + au_procfs_dir, &au_procfs_plm_fop);
25346 + if (unlikely(!entry))
25350 + goto out; /* success */
25354 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25358 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25359 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25360 +++ linux/fs/aufs/rdu.c 2015-01-25 13:00:38.634380408 +0100
25363 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25365 + * This program, aufs is free software; you can redistribute it and/or modify
25366 + * it under the terms of the GNU General Public License as published by
25367 + * the Free Software Foundation; either version 2 of the License, or
25368 + * (at your option) any later version.
25370 + * This program is distributed in the hope that it will be useful,
25371 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25372 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25373 + * GNU General Public License for more details.
25375 + * You should have received a copy of the GNU General Public License
25376 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25380 + * readdir in userspace.
25383 +#include <linux/compat.h>
25384 +#include <linux/fs_stack.h>
25385 +#include <linux/security.h>
25388 +/* bits for struct aufs_rdu.flags */
25389 +#define AuRdu_CALLED 1
25390 +#define AuRdu_CONT (1 << 1)
25391 +#define AuRdu_FULL (1 << 2)
25392 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25393 +#define au_fset_rdu(flags, name) \
25394 + do { (flags) |= AuRdu_##name; } while (0)
25395 +#define au_fclr_rdu(flags, name) \
25396 + do { (flags) &= ~AuRdu_##name; } while (0)
25398 +struct au_rdu_arg {
25399 + struct dir_context ctx;
25400 + struct aufs_rdu *rdu;
25401 + union au_rdu_ent_ul ent;
25402 + unsigned long end;
25404 + struct super_block *sb;
25408 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25409 + loff_t offset, u64 h_ino, unsigned int d_type)
25412 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25413 + struct aufs_rdu *rdu = arg->rdu;
25414 + struct au_rdu_ent ent;
25418 + au_fset_rdu(rdu->cookie.flags, CALLED);
25419 + len = au_rdu_len(nlen);
25420 + if (arg->ent.ul + len < arg->end) {
25422 + ent.bindex = rdu->cookie.bindex;
25423 + ent.type = d_type;
25425 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25426 + ent.type = DT_UNKNOWN;
25428 + /* unnecessary to support mmap_sem since this is a dir */
25430 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25432 + if (copy_to_user(arg->ent.e->name, name, nlen))
25434 + /* the terminating NULL */
25435 + if (__put_user(0, arg->ent.e->name + nlen))
25438 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25439 + arg->ent.ul += len;
25443 + au_fset_rdu(rdu->cookie.flags, FULL);
25445 + rdu->tail = arg->ent;
25449 + /* AuTraceErr(err); */
25453 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25457 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25459 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25460 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25462 + if (unlikely(offset != cookie->h_pos))
25468 + au_fclr_rdu(cookie->flags, CALLED);
25470 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25474 + && au_ftest_rdu(cookie->flags, CALLED)
25475 + && !au_ftest_rdu(cookie->flags, FULL));
25476 + cookie->h_pos = h_file->f_pos;
25483 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25486 + aufs_bindex_t bend;
25487 + struct au_rdu_arg arg = {
25489 + .actor = au_diractor(au_rdu_fill)
25492 + struct dentry *dentry;
25493 + struct inode *inode;
25494 + struct file *h_file;
25495 + struct au_rdu_cookie *cookie = &rdu->cookie;
25497 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25498 + if (unlikely(err)) {
25504 + rdu->tail = rdu->ent;
25507 + arg.ent = rdu->ent;
25508 + arg.end = arg.ent.ul;
25509 + arg.end += rdu->sz;
25512 + if (unlikely(!file->f_op->iterate))
25515 + err = security_file_permission(file, MAY_READ);
25517 + if (unlikely(err))
25520 + dentry = file->f_dentry;
25521 + inode = dentry->d_inode;
25523 + mutex_lock(&inode->i_mutex);
25525 + err = mutex_lock_killable(&inode->i_mutex);
25527 + if (unlikely(err))
25531 + arg.sb = inode->i_sb;
25532 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25533 + if (unlikely(err))
25535 + err = au_alive_dir(dentry);
25536 + if (unlikely(err))
25538 + /* todo: reval? */
25539 + fi_read_lock(file);
25542 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25543 + && cookie->generation != au_figen(file)))
25548 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25550 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25552 + bend = au_fbstart(file);
25553 + if (cookie->bindex < bend)
25554 + cookie->bindex = bend;
25555 + bend = au_fbend_dir(file);
25556 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25557 + for (; !err && cookie->bindex <= bend;
25558 + cookie->bindex++, cookie->h_pos = 0) {
25559 + h_file = au_hf_dir(file, cookie->bindex);
25563 + au_fclr_rdu(cookie->flags, FULL);
25564 + err = au_rdu_do(h_file, &arg);
25566 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25569 + AuDbg("rent %llu\n", rdu->rent);
25571 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25572 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25573 + au_fset_rdu(cookie->flags, CONT);
25574 + cookie->generation = au_figen(file);
25577 + ii_read_lock_child(inode);
25578 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25579 + ii_read_unlock(inode);
25582 + fi_read_unlock(file);
25584 + si_read_unlock(arg.sb);
25586 + mutex_unlock(&inode->i_mutex);
25592 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25596 + unsigned long long nent;
25597 + union au_rdu_ent_ul *u;
25598 + struct au_rdu_ent ent;
25599 + struct super_block *sb;
25602 + nent = rdu->nent;
25604 + sb = file->f_dentry->d_sb;
25605 + si_read_lock(sb, AuLock_FLUSH);
25606 + while (nent-- > 0) {
25607 + /* unnecessary to support mmap_sem since this is a dir */
25608 + err = copy_from_user(&ent, u->e, sizeof(ent));
25610 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25611 + if (unlikely(err)) {
25617 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25619 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25621 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25623 + if (unlikely(err)) {
25628 + err = __put_user(ino, &u->e->ino);
25629 + if (unlikely(err)) {
25634 + u->ul += au_rdu_len(ent.nlen);
25636 + si_read_unlock(sb);
25641 +/* ---------------------------------------------------------------------- */
25643 +static int au_rdu_verify(struct aufs_rdu *rdu)
25645 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
25646 + "%llu, b%d, 0x%x, g%u}\n",
25647 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
25649 + rdu->rent, rdu->shwh, rdu->full,
25650 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
25651 + rdu->cookie.generation);
25653 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
25657 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
25661 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25664 + struct aufs_rdu rdu;
25665 + void __user *p = (void __user *)arg;
25667 + err = copy_from_user(&rdu, p, sizeof(rdu));
25668 + if (unlikely(err)) {
25673 + err = au_rdu_verify(&rdu);
25674 + if (unlikely(err))
25678 + case AUFS_CTL_RDU:
25679 + err = au_rdu(file, &rdu);
25680 + if (unlikely(err))
25683 + e = copy_to_user(p, &rdu, sizeof(rdu));
25684 + if (unlikely(e)) {
25689 + case AUFS_CTL_RDU_INO:
25690 + err = au_rdu_ino(file, &rdu);
25694 + /* err = -ENOTTY; */
25703 +#ifdef CONFIG_COMPAT
25704 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25707 + struct aufs_rdu rdu;
25708 + void __user *p = compat_ptr(arg);
25710 + /* todo: get_user()? */
25711 + err = copy_from_user(&rdu, p, sizeof(rdu));
25712 + if (unlikely(err)) {
25717 + rdu.ent.e = compat_ptr(rdu.ent.ul);
25718 + err = au_rdu_verify(&rdu);
25719 + if (unlikely(err))
25723 + case AUFS_CTL_RDU:
25724 + err = au_rdu(file, &rdu);
25725 + if (unlikely(err))
25728 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
25729 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
25730 + e = copy_to_user(p, &rdu, sizeof(rdu));
25731 + if (unlikely(e)) {
25736 + case AUFS_CTL_RDU_INO:
25737 + err = au_rdu_ino(file, &rdu);
25741 + /* err = -ENOTTY; */
25750 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
25751 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
25752 +++ linux/fs/aufs/rwsem.h 2015-01-25 13:00:38.634380408 +0100
25755 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25757 + * This program, aufs is free software; you can redistribute it and/or modify
25758 + * it under the terms of the GNU General Public License as published by
25759 + * the Free Software Foundation; either version 2 of the License, or
25760 + * (at your option) any later version.
25762 + * This program is distributed in the hope that it will be useful,
25763 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25764 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25765 + * GNU General Public License for more details.
25767 + * You should have received a copy of the GNU General Public License
25768 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25772 + * simple read-write semaphore wrappers
25775 +#ifndef __AUFS_RWSEM_H__
25776 +#define __AUFS_RWSEM_H__
25780 +#include "debug.h"
25783 + struct rw_semaphore rwsem;
25784 +#ifdef CONFIG_AUFS_DEBUG
25785 + /* just for debugging, not almighty counter */
25786 + atomic_t rcnt, wcnt;
25790 +#ifdef CONFIG_AUFS_DEBUG
25791 +#define AuDbgCntInit(rw) do { \
25792 + atomic_set(&(rw)->rcnt, 0); \
25793 + atomic_set(&(rw)->wcnt, 0); \
25794 + smp_mb(); /* atomic set */ \
25797 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
25798 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
25799 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
25800 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
25802 +#define AuDbgCntInit(rw) do {} while (0)
25803 +#define AuDbgRcntInc(rw) do {} while (0)
25804 +#define AuDbgRcntDec(rw) do {} while (0)
25805 +#define AuDbgWcntInc(rw) do {} while (0)
25806 +#define AuDbgWcntDec(rw) do {} while (0)
25807 +#endif /* CONFIG_AUFS_DEBUG */
25809 +/* to debug easier, do not make them inlined functions */
25810 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
25811 +/* rwsem_is_locked() is unusable */
25812 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
25813 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
25814 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
25815 + && atomic_read(&(rw)->wcnt) <= 0)
25816 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
25817 + || atomic_read(&(rw)->wcnt))
25819 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
25821 +static inline void au_rw_init(struct au_rwsem *rw)
25823 + AuDbgCntInit(rw);
25824 + init_rwsem(&rw->rwsem);
25827 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
25830 + down_write(&rw->rwsem);
25831 + AuDbgWcntInc(rw);
25834 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
25835 + unsigned int lsc)
25838 + down_write_nested(&rw->rwsem, lsc);
25839 + AuDbgWcntInc(rw);
25842 +static inline void au_rw_read_lock(struct au_rwsem *rw)
25844 + down_read(&rw->rwsem);
25845 + AuDbgRcntInc(rw);
25848 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
25850 + down_read_nested(&rw->rwsem, lsc);
25851 + AuDbgRcntInc(rw);
25854 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
25856 + AuRwMustReadLock(rw);
25857 + AuDbgRcntDec(rw);
25858 + up_read(&rw->rwsem);
25861 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
25863 + AuRwMustWriteLock(rw);
25864 + AuDbgRcntInc(rw);
25865 + AuDbgWcntDec(rw);
25866 + downgrade_write(&rw->rwsem);
25869 +static inline void au_rw_write_lock(struct au_rwsem *rw)
25871 + down_write(&rw->rwsem);
25872 + AuDbgWcntInc(rw);
25875 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
25876 + unsigned int lsc)
25878 + down_write_nested(&rw->rwsem, lsc);
25879 + AuDbgWcntInc(rw);
25882 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
25884 + AuRwMustWriteLock(rw);
25885 + AuDbgWcntDec(rw);
25886 + up_write(&rw->rwsem);
25889 +/* why is not _nested version defined */
25890 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
25894 + ret = down_read_trylock(&rw->rwsem);
25896 + AuDbgRcntInc(rw);
25900 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
25904 + ret = down_write_trylock(&rw->rwsem);
25906 + AuDbgWcntInc(rw);
25910 +#undef AuDbgCntInit
25911 +#undef AuDbgRcntInc
25912 +#undef AuDbgRcntDec
25913 +#undef AuDbgWcntInc
25914 +#undef AuDbgWcntDec
25916 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25917 +static inline void prefix##_read_lock(param) \
25918 +{ au_rw_read_lock(rwsem); } \
25919 +static inline void prefix##_write_lock(param) \
25920 +{ au_rw_write_lock(rwsem); } \
25921 +static inline int prefix##_read_trylock(param) \
25922 +{ return au_rw_read_trylock(rwsem); } \
25923 +static inline int prefix##_write_trylock(param) \
25924 +{ return au_rw_write_trylock(rwsem); }
25925 +/* why is not _nested version defined */
25926 +/* static inline void prefix##_read_trylock_nested(param, lsc)
25927 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
25928 +static inline void prefix##_write_trylock_nestd(param, lsc)
25929 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
25931 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
25932 +static inline void prefix##_read_unlock(param) \
25933 +{ au_rw_read_unlock(rwsem); } \
25934 +static inline void prefix##_write_unlock(param) \
25935 +{ au_rw_write_unlock(rwsem); } \
25936 +static inline void prefix##_downgrade_lock(param) \
25937 +{ au_rw_dgrade_lock(rwsem); }
25939 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
25940 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25941 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
25943 +#endif /* __KERNEL__ */
25944 +#endif /* __AUFS_RWSEM_H__ */
25945 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
25946 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
25947 +++ linux/fs/aufs/sbinfo.c 2015-01-25 13:00:38.634380408 +0100
25950 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25952 + * This program, aufs is free software; you can redistribute it and/or modify
25953 + * it under the terms of the GNU General Public License as published by
25954 + * the Free Software Foundation; either version 2 of the License, or
25955 + * (at your option) any later version.
25957 + * This program is distributed in the hope that it will be useful,
25958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25960 + * GNU General Public License for more details.
25962 + * You should have received a copy of the GNU General Public License
25963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25967 + * superblock private data
25973 + * they are necessary regardless sysfs is disabled.
25975 +void au_si_free(struct kobject *kobj)
25978 + struct au_sbinfo *sbinfo;
25979 + char *locked __maybe_unused; /* debug only */
25981 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
25982 + for (i = 0; i < AuPlink_NHASH; i++)
25983 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
25984 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
25986 + au_rw_write_lock(&sbinfo->si_rwsem);
25987 + au_br_free(sbinfo);
25988 + au_rw_write_unlock(&sbinfo->si_rwsem);
25990 + AuDebugOn(radix_tree_gang_lookup
25991 + (&sbinfo->au_si_pid.tree, (void **)&locked,
25992 + /*first_index*/PID_MAX_DEFAULT - 1,
25993 + /*max_items*/sizeof(locked)/sizeof(*locked)));
25995 + kfree(sbinfo->si_branch);
25996 + kfree(sbinfo->au_si_pid.bitmap);
25997 + mutex_destroy(&sbinfo->si_xib_mtx);
25998 + AuRwDestroy(&sbinfo->si_rwsem);
26003 +int au_si_alloc(struct super_block *sb)
26006 + struct au_sbinfo *sbinfo;
26007 + static struct lock_class_key aufs_si;
26010 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26011 + if (unlikely(!sbinfo))
26014 + BUILD_BUG_ON(sizeof(unsigned long) !=
26015 + sizeof(*sbinfo->au_si_pid.bitmap));
26016 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
26017 + sizeof(*sbinfo->au_si_pid.bitmap),
26019 + if (unlikely(!sbinfo->au_si_pid.bitmap))
26022 + /* will be reallocated separately */
26023 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26024 + if (unlikely(!sbinfo->si_branch))
26027 + err = sysaufs_si_init(sbinfo);
26028 + if (unlikely(err))
26031 + au_nwt_init(&sbinfo->si_nowait);
26032 + au_rw_init_wlock(&sbinfo->si_rwsem);
26033 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
26034 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
26035 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
26037 + atomic_long_set(&sbinfo->si_ninodes, 0);
26038 + atomic_long_set(&sbinfo->si_nfiles, 0);
26040 + sbinfo->si_bend = -1;
26041 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26043 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26044 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26045 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26046 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26048 + au_fhsm_init(sbinfo);
26050 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26052 + sbinfo->si_xino_jiffy = jiffies;
26053 + sbinfo->si_xino_expire
26054 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26055 + mutex_init(&sbinfo->si_xib_mtx);
26056 + sbinfo->si_xino_brid = -1;
26057 + /* leave si_xib_last_pindex and si_xib_next_bit */
26059 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26060 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26061 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26062 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26064 + for (i = 0; i < AuPlink_NHASH; i++)
26065 + au_sphl_init(sbinfo->si_plink + i);
26066 + init_waitqueue_head(&sbinfo->si_plink_wq);
26067 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26069 + au_sphl_init(&sbinfo->si_files);
26071 + /* leave other members for sysaufs and si_mnt. */
26072 + sbinfo->si_sb = sb;
26073 + sb->s_fs_info = sbinfo;
26075 + au_debug_sbinfo_init(sbinfo);
26076 + return 0; /* success */
26079 + kfree(sbinfo->si_branch);
26081 + kfree(sbinfo->au_si_pid.bitmap);
26088 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
26091 + struct au_branch **brp;
26093 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26096 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
26097 + if (unlikely(!sz))
26098 + sz = sizeof(*brp);
26099 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
26101 + sbinfo->si_branch = brp;
26108 +/* ---------------------------------------------------------------------- */
26110 +unsigned int au_sigen_inc(struct super_block *sb)
26112 + unsigned int gen;
26114 + SiMustWriteLock(sb);
26116 + gen = ++au_sbi(sb)->si_generation;
26117 + au_update_digen(sb->s_root);
26118 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
26119 + sb->s_root->d_inode->i_version++;
26123 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26125 + aufs_bindex_t br_id;
26127 + struct au_sbinfo *sbinfo;
26129 + SiMustWriteLock(sb);
26131 + sbinfo = au_sbi(sb);
26132 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26133 + br_id = ++sbinfo->si_last_br_id;
26134 + AuDebugOn(br_id < 0);
26135 + if (br_id && au_br_index(sb, br_id) < 0)
26142 +/* ---------------------------------------------------------------------- */
26144 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26145 +int si_read_lock(struct super_block *sb, int flags)
26150 + if (au_ftest_lock(flags, FLUSH))
26151 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26153 + si_noflush_read_lock(sb);
26154 + err = au_plink_maint(sb, flags);
26155 + if (unlikely(err))
26156 + si_read_unlock(sb);
26161 +int si_write_lock(struct super_block *sb, int flags)
26165 + if (au_ftest_lock(flags, FLUSH))
26166 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26168 + si_noflush_write_lock(sb);
26169 + err = au_plink_maint(sb, flags);
26170 + if (unlikely(err))
26171 + si_write_unlock(sb);
26176 +/* dentry and super_block lock. call at entry point */
26177 +int aufs_read_lock(struct dentry *dentry, int flags)
26180 + struct super_block *sb;
26182 + sb = dentry->d_sb;
26183 + err = si_read_lock(sb, flags);
26184 + if (unlikely(err))
26187 + if (au_ftest_lock(flags, DW))
26188 + di_write_lock_child(dentry);
26190 + di_read_lock_child(dentry, flags);
26192 + if (au_ftest_lock(flags, GEN)) {
26193 + err = au_digen_test(dentry, au_sigen(sb));
26194 + AuDebugOn(!err && au_dbrange_test(dentry));
26195 + if (unlikely(err))
26196 + aufs_read_unlock(dentry, flags);
26203 +void aufs_read_unlock(struct dentry *dentry, int flags)
26205 + if (au_ftest_lock(flags, DW))
26206 + di_write_unlock(dentry);
26208 + di_read_unlock(dentry, flags);
26209 + si_read_unlock(dentry->d_sb);
26212 +void aufs_write_lock(struct dentry *dentry)
26214 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26215 + di_write_lock_child(dentry);
26218 +void aufs_write_unlock(struct dentry *dentry)
26220 + di_write_unlock(dentry);
26221 + si_write_unlock(dentry->d_sb);
26224 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26227 + unsigned int sigen;
26228 + struct super_block *sb;
26231 + err = si_read_lock(sb, flags);
26232 + if (unlikely(err))
26235 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
26237 + if (au_ftest_lock(flags, GEN)) {
26238 + sigen = au_sigen(sb);
26239 + err = au_digen_test(d1, sigen);
26240 + AuDebugOn(!err && au_dbrange_test(d1));
26242 + err = au_digen_test(d2, sigen);
26243 + AuDebugOn(!err && au_dbrange_test(d2));
26245 + if (unlikely(err))
26246 + aufs_read_and_write_unlock2(d1, d2);
26253 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26255 + di_write_unlock2(d1, d2);
26256 + si_read_unlock(d1->d_sb);
26259 +/* ---------------------------------------------------------------------- */
26261 +int si_pid_test_slow(struct super_block *sb)
26266 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
26267 + rcu_read_unlock();
26269 + return (long)!!p;
26272 +void si_pid_set_slow(struct super_block *sb)
26275 + struct au_sbinfo *sbinfo;
26277 + AuDebugOn(si_pid_test_slow(sb));
26279 + sbinfo = au_sbi(sb);
26280 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
26282 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26283 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
26284 + /*any valid ptr*/sb);
26285 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26287 + radix_tree_preload_end();
26290 +void si_pid_clr_slow(struct super_block *sb)
26293 + struct au_sbinfo *sbinfo;
26295 + AuDebugOn(!si_pid_test_slow(sb));
26297 + sbinfo = au_sbi(sb);
26298 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26299 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
26300 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26302 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26303 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26304 +++ linux/fs/aufs/spl.h 2015-01-25 13:00:38.634380408 +0100
26307 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26309 + * This program, aufs is free software; you can redistribute it and/or modify
26310 + * it under the terms of the GNU General Public License as published by
26311 + * the Free Software Foundation; either version 2 of the License, or
26312 + * (at your option) any later version.
26314 + * This program is distributed in the hope that it will be useful,
26315 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26316 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26317 + * GNU General Public License for more details.
26319 + * You should have received a copy of the GNU General Public License
26320 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26324 + * simple list protected by a spinlock
26327 +#ifndef __AUFS_SPL_H__
26328 +#define __AUFS_SPL_H__
26332 +struct au_splhead {
26334 + struct list_head head;
26337 +static inline void au_spl_init(struct au_splhead *spl)
26339 + spin_lock_init(&spl->spin);
26340 + INIT_LIST_HEAD(&spl->head);
26343 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26345 + spin_lock(&spl->spin);
26346 + list_add(list, &spl->head);
26347 + spin_unlock(&spl->spin);
26350 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26352 + spin_lock(&spl->spin);
26354 + spin_unlock(&spl->spin);
26357 +static inline void au_spl_del_rcu(struct list_head *list,
26358 + struct au_splhead *spl)
26360 + spin_lock(&spl->spin);
26361 + list_del_rcu(list);
26362 + spin_unlock(&spl->spin);
26365 +/* ---------------------------------------------------------------------- */
26367 +struct au_sphlhead {
26369 + struct hlist_head head;
26372 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26374 + spin_lock_init(&sphl->spin);
26375 + INIT_HLIST_HEAD(&sphl->head);
26378 +static inline void au_sphl_add(struct hlist_node *hlist,
26379 + struct au_sphlhead *sphl)
26381 + spin_lock(&sphl->spin);
26382 + hlist_add_head(hlist, &sphl->head);
26383 + spin_unlock(&sphl->spin);
26386 +static inline void au_sphl_del(struct hlist_node *hlist,
26387 + struct au_sphlhead *sphl)
26389 + spin_lock(&sphl->spin);
26390 + hlist_del(hlist);
26391 + spin_unlock(&sphl->spin);
26394 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26395 + struct au_sphlhead *sphl)
26397 + spin_lock(&sphl->spin);
26398 + hlist_del_rcu(hlist);
26399 + spin_unlock(&sphl->spin);
26402 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26404 + unsigned long cnt;
26405 + struct hlist_node *pos;
26408 + spin_lock(&sphl->spin);
26409 + hlist_for_each(pos, &sphl->head)
26411 + spin_unlock(&sphl->spin);
26415 +#endif /* __KERNEL__ */
26416 +#endif /* __AUFS_SPL_H__ */
26417 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26418 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26419 +++ linux/fs/aufs/super.c 2015-01-25 13:00:38.634380408 +0100
26422 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26424 + * This program, aufs is free software; you can redistribute it and/or modify
26425 + * it under the terms of the GNU General Public License as published by
26426 + * the Free Software Foundation; either version 2 of the License, or
26427 + * (at your option) any later version.
26429 + * This program is distributed in the hope that it will be useful,
26430 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26431 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26432 + * GNU General Public License for more details.
26434 + * You should have received a copy of the GNU General Public License
26435 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26439 + * mount and super_block operations
26442 +#include <linux/mm.h>
26443 +#include <linux/module.h>
26444 +#include <linux/seq_file.h>
26445 +#include <linux/statfs.h>
26446 +#include <linux/vmalloc.h>
26447 +#include <linux/writeback.h>
26451 + * super_operations
26453 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26455 + struct au_icntnr *c;
26457 + c = au_cache_alloc_icntnr();
26459 + au_icntnr_init(c);
26460 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26461 + c->iinfo.ii_hinode = NULL;
26462 + return &c->vfs_inode;
26467 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26469 + struct inode *inode = container_of(head, struct inode, i_rcu);
26471 + INIT_HLIST_HEAD(&inode->i_dentry);
26472 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26475 +static void aufs_destroy_inode(struct inode *inode)
26477 + au_iinfo_fin(inode);
26478 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26481 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26483 + struct inode *inode;
26486 + inode = iget_locked(sb, ino);
26487 + if (unlikely(!inode)) {
26488 + inode = ERR_PTR(-ENOMEM);
26491 + if (!(inode->i_state & I_NEW))
26494 + err = au_xigen_new(inode);
26496 + err = au_iinfo_init(inode);
26498 + inode->i_version++;
26500 + iget_failed(inode);
26501 + inode = ERR_PTR(err);
26505 + /* never return NULL */
26506 + AuDebugOn(!inode);
26507 + AuTraceErrPtr(inode);
26511 +/* lock free root dinfo */
26512 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26515 + aufs_bindex_t bindex, bend;
26516 + struct path path;
26517 + struct au_hdentry *hdp;
26518 + struct au_branch *br;
26519 + au_br_perm_str_t perm;
26522 + bend = au_sbend(sb);
26523 + hdp = au_di(sb->s_root)->di_hdentry;
26524 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26525 + br = au_sbr(sb, bindex);
26526 + path.mnt = au_br_mnt(br);
26527 + path.dentry = hdp[bindex].hd_dentry;
26528 + err = au_seq_path(seq, &path);
26530 + au_optstr_br_perm(&perm, br->br_perm);
26531 + err = seq_printf(seq, "=%s", perm.a);
26535 + if (!err && bindex != bend)
26536 + err = seq_putc(seq, ':');
26542 +static void au_show_wbr_create(struct seq_file *m, int v,
26543 + struct au_sbinfo *sbinfo)
26547 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26549 + seq_puts(m, ",create=");
26550 + pat = au_optstr_wbr_create(v);
26552 + case AuWbrCreate_TDP:
26553 + case AuWbrCreate_RR:
26554 + case AuWbrCreate_MFS:
26555 + case AuWbrCreate_PMFS:
26556 + seq_puts(m, pat);
26558 + case AuWbrCreate_MFSV:
26559 + seq_printf(m, /*pat*/"mfs:%lu",
26560 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26563 + case AuWbrCreate_PMFSV:
26564 + seq_printf(m, /*pat*/"pmfs:%lu",
26565 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26568 + case AuWbrCreate_MFSRR:
26569 + seq_printf(m, /*pat*/"mfsrr:%llu",
26570 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26572 + case AuWbrCreate_MFSRRV:
26573 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26574 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26575 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26578 + case AuWbrCreate_PMFSRR:
26579 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26580 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26582 + case AuWbrCreate_PMFSRRV:
26583 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26584 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26585 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26591 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26593 +#ifdef CONFIG_SYSFS
26597 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26598 + aufs_bindex_t bindex, brid;
26599 + struct qstr *name;
26601 + struct dentry *d, *h_root;
26602 + struct au_hdentry *hdp;
26604 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26607 + f = au_sbi(sb)->si_xib;
26611 + /* stop printing the default xino path on the first writable branch */
26613 + brid = au_xino_brid(sb);
26615 + bindex = au_br_index(sb, brid);
26616 + hdp = au_di(sb->s_root)->di_hdentry;
26617 + h_root = hdp[0 + bindex].hd_dentry;
26620 + name = &d->d_name;
26621 + /* safe ->d_parent because the file is unlinked */
26622 + if (d->d_parent == h_root
26623 + && name->len == len
26624 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26627 + seq_puts(seq, ",xino=");
26628 + err = au_xino_path(seq, f);
26635 +/* seq_file will re-call me in case of too long string */
26636 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26639 + unsigned int mnt_flags, v;
26640 + struct super_block *sb;
26641 + struct au_sbinfo *sbinfo;
26643 +#define AuBool(name, str) do { \
26644 + v = au_opt_test(mnt_flags, name); \
26645 + if (v != au_opt_test(AuOpt_Def, name)) \
26646 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
26649 +#define AuStr(name, str) do { \
26650 + v = mnt_flags & AuOptMask_##name; \
26651 + if (v != (AuOpt_Def & AuOptMask_##name)) \
26652 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
26655 +#define AuUInt(name, str, val) do { \
26656 + if (val != AUFS_##name##_DEF) \
26657 + seq_printf(m, "," #str "=%u", val); \
26660 + sb = dentry->d_sb;
26661 + if (sb->s_flags & MS_POSIXACL)
26662 + seq_puts(m, ",acl");
26664 + /* lock free root dinfo */
26665 + si_noflush_read_lock(sb);
26666 + sbinfo = au_sbi(sb);
26667 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
26669 + mnt_flags = au_mntflags(sb);
26670 + if (au_opt_test(mnt_flags, XINO)) {
26671 + err = au_show_xino(m, sb);
26672 + if (unlikely(err))
26675 + seq_puts(m, ",noxino");
26677 + AuBool(TRUNC_XINO, trunc_xino);
26678 + AuStr(UDBA, udba);
26679 + AuBool(SHWH, shwh);
26680 + AuBool(PLINK, plink);
26681 + AuBool(DIO, dio);
26682 + AuBool(DIRPERM1, dirperm1);
26683 + /* AuBool(REFROF, refrof); */
26685 + v = sbinfo->si_wbr_create;
26686 + if (v != AuWbrCreate_Def)
26687 + au_show_wbr_create(m, v, sbinfo);
26689 + v = sbinfo->si_wbr_copyup;
26690 + if (v != AuWbrCopyup_Def)
26691 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
26693 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
26694 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
26695 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
26697 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
26699 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
26700 + AuUInt(RDCACHE, rdcache, v);
26702 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
26703 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
26705 + au_fhsm_show(m, sbinfo);
26707 + AuBool(SUM, sum);
26708 + /* AuBool(SUM_W, wsum); */
26709 + AuBool(WARN_PERM, warn_perm);
26710 + AuBool(VERBOSE, verbose);
26713 + /* be sure to print "br:" last */
26714 + if (!sysaufs_brs) {
26715 + seq_puts(m, ",br:");
26716 + au_show_brs(m, sb);
26718 + si_read_unlock(sb);
26726 +/* ---------------------------------------------------------------------- */
26728 +/* sum mode which returns the summation for statfs(2) */
26730 +static u64 au_add_till_max(u64 a, u64 b)
26738 + return ULLONG_MAX;
26741 +static u64 au_mul_till_max(u64 a, long mul)
26749 + return ULLONG_MAX;
26752 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
26755 + long bsize, factor;
26756 + u64 blocks, bfree, bavail, files, ffree;
26757 + aufs_bindex_t bend, bindex, i;
26758 + unsigned char shared;
26759 + struct path h_path;
26760 + struct super_block *h_sb;
26763 + bsize = LONG_MAX;
26769 + bend = au_sbend(sb);
26770 + for (bindex = 0; bindex <= bend; bindex++) {
26771 + h_path.mnt = au_sbr_mnt(sb, bindex);
26772 + h_sb = h_path.mnt->mnt_sb;
26774 + for (i = 0; !shared && i < bindex; i++)
26775 + shared = (au_sbr_sb(sb, i) == h_sb);
26779 + /* sb->s_root for NFS is unreliable */
26780 + h_path.dentry = h_path.mnt->mnt_root;
26781 + err = vfs_statfs(&h_path, buf);
26782 + if (unlikely(err))
26785 + if (bsize > buf->f_bsize) {
26787 + * we will reduce bsize, so we have to expand blocks
26788 + * etc. to match them again
26790 + factor = (bsize / buf->f_bsize);
26791 + blocks = au_mul_till_max(blocks, factor);
26792 + bfree = au_mul_till_max(bfree, factor);
26793 + bavail = au_mul_till_max(bavail, factor);
26794 + bsize = buf->f_bsize;
26797 + factor = (buf->f_bsize / bsize);
26798 + blocks = au_add_till_max(blocks,
26799 + au_mul_till_max(buf->f_blocks, factor));
26800 + bfree = au_add_till_max(bfree,
26801 + au_mul_till_max(buf->f_bfree, factor));
26802 + bavail = au_add_till_max(bavail,
26803 + au_mul_till_max(buf->f_bavail, factor));
26804 + files = au_add_till_max(files, buf->f_files);
26805 + ffree = au_add_till_max(ffree, buf->f_ffree);
26808 + buf->f_bsize = bsize;
26809 + buf->f_blocks = blocks;
26810 + buf->f_bfree = bfree;
26811 + buf->f_bavail = bavail;
26812 + buf->f_files = files;
26813 + buf->f_ffree = ffree;
26814 + buf->f_frsize = 0;
26820 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
26823 + struct path h_path;
26824 + struct super_block *sb;
26826 + /* lock free root dinfo */
26827 + sb = dentry->d_sb;
26828 + si_noflush_read_lock(sb);
26829 + if (!au_opt_test(au_mntflags(sb), SUM)) {
26830 + /* sb->s_root for NFS is unreliable */
26831 + h_path.mnt = au_sbr_mnt(sb, 0);
26832 + h_path.dentry = h_path.mnt->mnt_root;
26833 + err = vfs_statfs(&h_path, buf);
26835 + err = au_statfs_sum(sb, buf);
26836 + si_read_unlock(sb);
26839 + buf->f_type = AUFS_SUPER_MAGIC;
26840 + buf->f_namelen = AUFS_MAX_NAMELEN;
26841 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
26843 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
26848 +/* ---------------------------------------------------------------------- */
26850 +static int aufs_sync_fs(struct super_block *sb, int wait)
26853 + aufs_bindex_t bend, bindex;
26854 + struct au_branch *br;
26855 + struct super_block *h_sb;
26858 + si_noflush_read_lock(sb);
26859 + bend = au_sbend(sb);
26860 + for (bindex = 0; bindex <= bend; bindex++) {
26861 + br = au_sbr(sb, bindex);
26862 + if (!au_br_writable(br->br_perm))
26865 + h_sb = au_sbr_sb(sb, bindex);
26866 + if (h_sb->s_op->sync_fs) {
26867 + e = h_sb->s_op->sync_fs(h_sb, wait);
26868 + if (unlikely(e && !err))
26870 + /* go on even if an error happens */
26873 + si_read_unlock(sb);
26878 +/* ---------------------------------------------------------------------- */
26880 +/* final actions when unmounting a file system */
26881 +static void aufs_put_super(struct super_block *sb)
26883 + struct au_sbinfo *sbinfo;
26885 + sbinfo = au_sbi(sb);
26889 + dbgaufs_si_fin(sbinfo);
26890 + kobject_put(&sbinfo->si_kobj);
26893 +/* ---------------------------------------------------------------------- */
26895 +void au_array_free(void *array)
26898 + if (!is_vmalloc_addr(array))
26905 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
26908 + unsigned long long n, sz;
26915 + if (*hint > ULLONG_MAX / sizeof(array)) {
26916 + array = ERR_PTR(-EMFILE);
26917 + pr_err("hint %llu\n", *hint);
26921 + sz = sizeof(array) * *hint;
26922 + array = kzalloc(sz, GFP_NOFS);
26923 + if (unlikely(!array))
26924 + array = vzalloc(sz);
26925 + if (unlikely(!array)) {
26926 + array = ERR_PTR(-ENOMEM);
26930 + n = cb(array, *hint, arg);
26931 + AuDebugOn(n > *hint);
26938 +static unsigned long long au_iarray_cb(void *a,
26939 + unsigned long long max __maybe_unused,
26942 + unsigned long long n;
26943 + struct inode **p, *inode;
26944 + struct list_head *head;
26949 + spin_lock(&inode_sb_list_lock);
26950 + list_for_each_entry(inode, head, i_sb_list) {
26951 + if (!is_bad_inode(inode)
26952 + && au_ii(inode)->ii_bstart >= 0) {
26953 + spin_lock(&inode->i_lock);
26954 + if (atomic_read(&inode->i_count)) {
26958 + AuDebugOn(n > max);
26960 + spin_unlock(&inode->i_lock);
26963 + spin_unlock(&inode_sb_list_lock);
26968 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
26970 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
26971 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
26974 +void au_iarray_free(struct inode **a, unsigned long long max)
26976 + unsigned long long ull;
26978 + for (ull = 0; ull < max; ull++)
26980 + au_array_free(a);
26983 +/* ---------------------------------------------------------------------- */
26986 + * refresh dentry and inode at remount time.
26988 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
26989 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
26990 + struct dentry *parent)
26994 + di_write_lock_child(dentry);
26995 + di_read_lock_parent(parent, AuLock_IR);
26996 + err = au_refresh_dentry(dentry, parent);
26997 + if (!err && dir_flags)
26998 + au_hn_reset(dentry->d_inode, dir_flags);
26999 + di_read_unlock(parent, AuLock_IR);
27000 + di_write_unlock(dentry);
27005 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27006 + struct au_sbinfo *sbinfo,
27007 + const unsigned int dir_flags)
27010 + struct dentry *parent;
27011 + struct inode *inode;
27014 + parent = dget_parent(dentry);
27015 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27016 + inode = dentry->d_inode;
27018 + if (!S_ISDIR(inode->i_mode))
27019 + err = au_do_refresh(dentry, /*dir_flags*/0,
27022 + err = au_do_refresh(dentry, dir_flags, parent);
27023 + if (unlikely(err))
27024 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27027 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27028 + AuDbgDentry(dentry);
27036 +static int au_refresh_d(struct super_block *sb)
27038 + int err, i, j, ndentry, e;
27039 + unsigned int sigen;
27040 + struct au_dcsub_pages dpages;
27041 + struct au_dpage *dpage;
27042 + struct dentry **dentries, *d;
27043 + struct au_sbinfo *sbinfo;
27044 + struct dentry *root = sb->s_root;
27045 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
27047 + err = au_dpages_init(&dpages, GFP_NOFS);
27048 + if (unlikely(err))
27050 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27051 + if (unlikely(err))
27054 + sigen = au_sigen(sb);
27055 + sbinfo = au_sbi(sb);
27056 + for (i = 0; i < dpages.ndpage; i++) {
27057 + dpage = dpages.dpages + i;
27058 + dentries = dpage->dentries;
27059 + ndentry = dpage->ndentry;
27060 + for (j = 0; j < ndentry; j++) {
27062 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
27063 + if (unlikely(e && !err))
27065 + /* go on even err */
27070 + au_dpages_free(&dpages);
27075 +static int au_refresh_i(struct super_block *sb)
27078 + unsigned int sigen;
27079 + unsigned long long max, ull;
27080 + struct inode *inode, **array;
27082 + array = au_iarray_alloc(sb, &max);
27083 + err = PTR_ERR(array);
27084 + if (IS_ERR(array))
27088 + sigen = au_sigen(sb);
27089 + for (ull = 0; ull < max; ull++) {
27090 + inode = array[ull];
27091 + if (unlikely(!inode))
27093 + if (au_iigen(inode, NULL) != sigen) {
27094 + ii_write_lock_child(inode);
27095 + e = au_refresh_hinode_self(inode);
27096 + ii_write_unlock(inode);
27097 + if (unlikely(e)) {
27098 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27101 + /* go on even if err */
27106 + au_iarray_free(array, max);
27112 +static void au_remount_refresh(struct super_block *sb)
27115 + unsigned int udba;
27116 + aufs_bindex_t bindex, bend;
27117 + struct dentry *root;
27118 + struct inode *inode;
27119 + struct au_branch *br;
27121 + au_sigen_inc(sb);
27122 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
27124 + root = sb->s_root;
27125 + DiMustNoWaiters(root);
27126 + inode = root->d_inode;
27127 + IiMustNoWaiters(inode);
27129 + udba = au_opt_udba(sb);
27130 + bend = au_sbend(sb);
27131 + for (bindex = 0; bindex <= bend; bindex++) {
27132 + br = au_sbr(sb, bindex);
27133 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27134 + if (unlikely(err))
27135 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27137 + /* go on even if err */
27139 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27141 + di_write_unlock(root);
27142 + err = au_refresh_d(sb);
27143 + e = au_refresh_i(sb);
27144 + if (unlikely(e && !err))
27146 + /* aufs_write_lock() calls ..._child() */
27147 + di_write_lock_child(root);
27149 + au_cpup_attr_all(inode, /*force*/1);
27151 + if (unlikely(err))
27152 + AuIOErr("refresh failed, ignored, %d\n", err);
27155 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27156 +static int cvt_err(int err)
27170 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27173 + unsigned int mntflags;
27174 + struct au_opts opts;
27175 + struct dentry *root;
27176 + struct inode *inode;
27177 + struct au_sbinfo *sbinfo;
27180 + root = sb->s_root;
27181 + if (!data || !*data) {
27182 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27184 + di_write_lock_child(root);
27185 + err = au_opts_verify(sb, *flags, /*pending*/0);
27186 + aufs_write_unlock(root);
27192 + memset(&opts, 0, sizeof(opts));
27193 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27194 + if (unlikely(!opts.opt))
27196 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27197 + opts.flags = AuOpts_REMOUNT;
27198 + opts.sb_flags = *flags;
27200 + /* parse it before aufs lock */
27201 + err = au_opts_parse(sb, data, &opts);
27202 + if (unlikely(err))
27205 + sbinfo = au_sbi(sb);
27206 + inode = root->d_inode;
27207 + mutex_lock(&inode->i_mutex);
27208 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27209 + if (unlikely(err))
27211 + di_write_lock_child(root);
27213 + /* au_opts_remount() may return an error */
27214 + err = au_opts_remount(sb, &opts);
27215 + au_opts_free(&opts);
27217 + if (au_ftest_opts(opts.flags, REFRESH))
27218 + au_remount_refresh(sb);
27220 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27221 + mntflags = au_mntflags(sb);
27222 + do_dx = !!au_opt_test(mntflags, DIO);
27223 + au_dy_arefresh(do_dx);
27226 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27227 + aufs_write_unlock(root);
27230 + mutex_unlock(&inode->i_mutex);
27232 + free_page((unsigned long)opts.opt);
27234 + err = cvt_err(err);
27239 +static const struct super_operations aufs_sop = {
27240 + .alloc_inode = aufs_alloc_inode,
27241 + .destroy_inode = aufs_destroy_inode,
27242 + /* always deleting, no clearing */
27243 + .drop_inode = generic_delete_inode,
27244 + .show_options = aufs_show_options,
27245 + .statfs = aufs_statfs,
27246 + .put_super = aufs_put_super,
27247 + .sync_fs = aufs_sync_fs,
27248 + .remount_fs = aufs_remount_fs
27251 +/* ---------------------------------------------------------------------- */
27253 +static int alloc_root(struct super_block *sb)
27256 + struct inode *inode;
27257 + struct dentry *root;
27260 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
27261 + err = PTR_ERR(inode);
27262 + if (IS_ERR(inode))
27265 + inode->i_op = &aufs_dir_iop;
27266 + inode->i_fop = &aufs_dir_fop;
27267 + inode->i_mode = S_IFDIR;
27268 + set_nlink(inode, 2);
27269 + unlock_new_inode(inode);
27271 + root = d_make_root(inode);
27272 + if (unlikely(!root))
27274 + err = PTR_ERR(root);
27275 + if (IS_ERR(root))
27278 + err = au_di_init(root);
27280 + sb->s_root = root;
27281 + return 0; /* success */
27289 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27290 + int silent __maybe_unused)
27293 + struct au_opts opts;
27294 + struct dentry *root;
27295 + struct inode *inode;
27296 + char *arg = raw_data;
27298 + if (unlikely(!arg || !*arg)) {
27300 + pr_err("no arg\n");
27305 + memset(&opts, 0, sizeof(opts));
27306 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27307 + if (unlikely(!opts.opt))
27309 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27310 + opts.sb_flags = sb->s_flags;
27312 + err = au_si_alloc(sb);
27313 + if (unlikely(err))
27316 + /* all timestamps always follow the ones on the branch */
27317 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27318 + sb->s_op = &aufs_sop;
27319 + sb->s_d_op = &aufs_dop;
27320 + sb->s_magic = AUFS_SUPER_MAGIC;
27321 + sb->s_maxbytes = 0;
27322 + sb->s_stack_depth = 1;
27323 + au_export_init(sb);
27324 + /* au_xattr_init(sb); */
27326 + err = alloc_root(sb);
27327 + if (unlikely(err)) {
27328 + si_write_unlock(sb);
27331 + root = sb->s_root;
27332 + inode = root->d_inode;
27335 + * actually we can parse options regardless aufs lock here.
27336 + * but at remount time, parsing must be done before aufs lock.
27337 + * so we follow the same rule.
27339 + ii_write_lock_parent(inode);
27340 + aufs_write_unlock(root);
27341 + err = au_opts_parse(sb, arg, &opts);
27342 + if (unlikely(err))
27345 + /* lock vfs_inode first, then aufs. */
27346 + mutex_lock(&inode->i_mutex);
27347 + aufs_write_lock(root);
27348 + err = au_opts_mount(sb, &opts);
27349 + au_opts_free(&opts);
27350 + aufs_write_unlock(root);
27351 + mutex_unlock(&inode->i_mutex);
27353 + goto out_opts; /* success */
27357 + sb->s_root = NULL;
27359 + dbgaufs_si_fin(au_sbi(sb));
27360 + kobject_put(&au_sbi(sb)->si_kobj);
27361 + sb->s_fs_info = NULL;
27363 + free_page((unsigned long)opts.opt);
27366 + err = cvt_err(err);
27371 +/* ---------------------------------------------------------------------- */
27373 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27374 + const char *dev_name __maybe_unused,
27377 + struct dentry *root;
27378 + struct super_block *sb;
27380 + /* all timestamps always follow the ones on the branch */
27381 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27382 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27383 + if (IS_ERR(root))
27387 + si_write_lock(sb, !AuLock_FLUSH);
27388 + sysaufs_brs_add(sb, 0);
27389 + si_write_unlock(sb);
27390 + au_sbilist_add(sb);
27396 +static void aufs_kill_sb(struct super_block *sb)
27398 + struct au_sbinfo *sbinfo;
27400 + sbinfo = au_sbi(sb);
27402 + au_sbilist_del(sb);
27403 + aufs_write_lock(sb->s_root);
27405 + if (sbinfo->si_wbr_create_ops->fin)
27406 + sbinfo->si_wbr_create_ops->fin(sb);
27407 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27408 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27409 + au_remount_refresh(sb);
27411 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27412 + au_plink_put(sb, /*verbose*/1);
27414 + sbinfo->si_sb = NULL;
27415 + aufs_write_unlock(sb->s_root);
27416 + au_nwt_flush(&sbinfo->si_nowait);
27418 + kill_anon_super(sb);
27421 +struct file_system_type aufs_fs_type = {
27422 + .name = AUFS_FSTYPE,
27423 + /* a race between rename and others */
27424 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27425 + .mount = aufs_mount,
27426 + .kill_sb = aufs_kill_sb,
27427 + /* no need to __module_get() and module_put(). */
27428 + .owner = THIS_MODULE,
27430 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27431 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27432 +++ linux/fs/aufs/super.h 2015-01-25 13:00:38.634380408 +0100
27435 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27437 + * This program, aufs is free software; you can redistribute it and/or modify
27438 + * it under the terms of the GNU General Public License as published by
27439 + * the Free Software Foundation; either version 2 of the License, or
27440 + * (at your option) any later version.
27442 + * This program is distributed in the hope that it will be useful,
27443 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27444 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27445 + * GNU General Public License for more details.
27447 + * You should have received a copy of the GNU General Public License
27448 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27452 + * super_block operations
27455 +#ifndef __AUFS_SUPER_H__
27456 +#define __AUFS_SUPER_H__
27460 +#include <linux/fs.h>
27461 +#include "rwsem.h"
27465 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
27466 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
27469 +/* policies to select one among multiple writable branches */
27470 +struct au_wbr_copyup_operations {
27471 + int (*copyup)(struct dentry *dentry);
27474 +#define AuWbr_DIR 1 /* target is a dir */
27475 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27477 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27478 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27479 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27481 +struct au_wbr_create_operations {
27482 + int (*create)(struct dentry *dentry, unsigned int flags);
27483 + int (*init)(struct super_block *sb);
27484 + int (*fin)(struct super_block *sb);
27487 +struct au_wbr_mfs {
27488 + struct mutex mfs_lock; /* protect this structure */
27489 + unsigned long mfs_jiffy;
27490 + unsigned long mfs_expire;
27491 + aufs_bindex_t mfs_bindex;
27493 + unsigned long long mfsrr_bytes;
27494 + unsigned long long mfsrr_watermark;
27497 +struct pseudo_link {
27499 + struct hlist_node hlist;
27500 + struct rcu_head rcu;
27502 + struct inode *inode;
27505 +#define AuPlink_NHASH 100
27506 +static inline int au_plink_hash(ino_t ino)
27508 + return ino % AuPlink_NHASH;
27511 +/* File-based Hierarchical Storage Management */
27513 +#ifdef CONFIG_AUFS_FHSM
27514 + /* allow only one process who can receive the notification */
27515 + spinlock_t fhsm_spin;
27517 + wait_queue_head_t fhsm_wqh;
27518 + atomic_t fhsm_readable;
27520 + /* these are protected by si_rwsem */
27521 + unsigned long fhsm_expire;
27522 + aufs_bindex_t fhsm_bottom;
27527 +struct au_sbinfo {
27528 + /* nowait tasks in the system-wide workqueue */
27529 + struct au_nowait_tasks si_nowait;
27532 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27533 + * rwsem for au_sbinfo is necessary.
27535 + struct au_rwsem si_rwsem;
27537 + /* prevent recursive locking in deleting inode */
27539 + unsigned long *bitmap;
27540 + spinlock_t tree_lock;
27541 + struct radix_tree_root tree;
27545 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27548 + atomic_long_t si_ninodes, si_nfiles;
27550 + /* branch management */
27551 + unsigned int si_generation;
27553 + /* see above flags */
27554 + unsigned char au_si_status;
27556 + aufs_bindex_t si_bend;
27558 + /* dirty trick to keep br_id plus */
27559 + unsigned int si_last_br_id :
27560 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27561 + struct au_branch **si_branch;
27563 + /* policy to select a writable branch */
27564 + unsigned char si_wbr_copyup;
27565 + unsigned char si_wbr_create;
27566 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27567 + struct au_wbr_create_operations *si_wbr_create_ops;
27569 + /* round robin */
27570 + atomic_t si_wbr_rr_next;
27572 + /* most free space */
27573 + struct au_wbr_mfs si_wbr_mfs;
27575 + /* File-based Hierarchical Storage Management */
27576 + struct au_fhsm si_fhsm;
27578 + /* mount flags */
27579 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27580 + unsigned int si_mntflags;
27582 + /* external inode number (bitmap and translation table) */
27583 + au_readf_t si_xread;
27584 + au_writef_t si_xwrite;
27585 + struct file *si_xib;
27586 + struct mutex si_xib_mtx; /* protect xib members */
27587 + unsigned long *si_xib_buf;
27588 + unsigned long si_xib_last_pindex;
27589 + int si_xib_next_bit;
27590 + aufs_bindex_t si_xino_brid;
27591 + unsigned long si_xino_jiffy;
27592 + unsigned long si_xino_expire;
27593 + /* reserved for future use */
27594 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
27596 +#ifdef CONFIG_AUFS_EXPORT
27597 + /* i_generation */
27598 + struct file *si_xigen;
27599 + atomic_t si_xigen_next;
27602 + /* vdir parameters */
27603 + unsigned long si_rdcache; /* max cache time in jiffies */
27604 + unsigned int si_rdblk; /* deblk size */
27605 + unsigned int si_rdhash; /* hash size */
27608 + * If the number of whiteouts are larger than si_dirwh, leave all of
27609 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
27610 + * future fsck.aufs or kernel thread will remove them later.
27611 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
27613 + unsigned int si_dirwh;
27616 + * rename(2) a directory with all children.
27618 + /* reserved for future use */
27619 + /* int si_rendir; */
27621 + /* pseudo_link list */
27622 + struct au_sphlhead si_plink[AuPlink_NHASH];
27623 + wait_queue_head_t si_plink_wq;
27624 + spinlock_t si_plink_maint_lock;
27625 + pid_t si_plink_maint_pid;
27628 + struct au_sphlhead si_files;
27631 + * sysfs and lifetime management.
27632 + * this is not a small structure and it may be a waste of memory in case
27633 + * of sysfs is disabled, particulary when many aufs-es are mounted.
27634 + * but using sysfs is majority.
27636 + struct kobject si_kobj;
27637 +#ifdef CONFIG_DEBUG_FS
27638 + struct dentry *si_dbgaufs;
27639 + struct dentry *si_dbgaufs_plink;
27640 + struct dentry *si_dbgaufs_xib;
27641 +#ifdef CONFIG_AUFS_EXPORT
27642 + struct dentry *si_dbgaufs_xigen;
27646 +#ifdef CONFIG_AUFS_SBILIST
27647 + struct list_head si_list;
27650 + /* dirty, necessary for unmounting, sysfs and sysrq */
27651 + struct super_block *si_sb;
27654 +/* sbinfo status flags */
27656 + * set true when refresh_dirs() failed at remount time.
27657 + * then try refreshing dirs at access time again.
27658 + * if it is false, refreshing dirs at access time is unnecesary
27660 +#define AuSi_FAILED_REFRESH_DIR 1
27662 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
27664 +#ifndef CONFIG_AUFS_FHSM
27666 +#define AuSi_FHSM 0
27669 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
27670 + unsigned int flag)
27672 + AuRwMustAnyLock(&sbi->si_rwsem);
27673 + return sbi->au_si_status & flag;
27675 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
27676 +#define au_fset_si(sbinfo, name) do { \
27677 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27678 + (sbinfo)->au_si_status |= AuSi_##name; \
27680 +#define au_fclr_si(sbinfo, name) do { \
27681 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27682 + (sbinfo)->au_si_status &= ~AuSi_##name; \
27685 +/* ---------------------------------------------------------------------- */
27687 +/* policy to select one among writable branches */
27688 +#define AuWbrCopyup(sbinfo, ...) \
27689 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
27690 +#define AuWbrCreate(sbinfo, ...) \
27691 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
27693 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
27694 +#define AuLock_DW 1 /* write-lock dentry */
27695 +#define AuLock_IR (1 << 1) /* read-lock inode */
27696 +#define AuLock_IW (1 << 2) /* write-lock inode */
27697 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
27698 +#define AuLock_DIR (1 << 4) /* target is a dir */
27699 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
27700 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
27701 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
27702 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
27703 +#define au_fset_lock(flags, name) \
27704 + do { (flags) |= AuLock_##name; } while (0)
27705 +#define au_fclr_lock(flags, name) \
27706 + do { (flags) &= ~AuLock_##name; } while (0)
27708 +/* ---------------------------------------------------------------------- */
27711 +extern struct file_system_type aufs_fs_type;
27712 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
27713 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
27715 +void au_array_free(void *array);
27716 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
27717 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
27718 +void au_iarray_free(struct inode **a, unsigned long long max);
27721 +void au_si_free(struct kobject *kobj);
27722 +int au_si_alloc(struct super_block *sb);
27723 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
27725 +unsigned int au_sigen_inc(struct super_block *sb);
27726 +aufs_bindex_t au_new_br_id(struct super_block *sb);
27728 +int si_read_lock(struct super_block *sb, int flags);
27729 +int si_write_lock(struct super_block *sb, int flags);
27730 +int aufs_read_lock(struct dentry *dentry, int flags);
27731 +void aufs_read_unlock(struct dentry *dentry, int flags);
27732 +void aufs_write_lock(struct dentry *dentry);
27733 +void aufs_write_unlock(struct dentry *dentry);
27734 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
27735 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
27737 +int si_pid_test_slow(struct super_block *sb);
27738 +void si_pid_set_slow(struct super_block *sb);
27739 +void si_pid_clr_slow(struct super_block *sb);
27741 +/* wbr_policy.c */
27742 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
27743 +extern struct au_wbr_create_operations au_wbr_create_ops[];
27744 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
27745 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
27746 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
27749 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
27751 +#ifdef CONFIG_AUFS_FHSM
27754 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
27758 + spin_lock(&fhsm->fhsm_spin);
27759 + pid = fhsm->fhsm_pid;
27760 + spin_unlock(&fhsm->fhsm_spin);
27765 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
27766 +void au_fhsm_wrote_all(struct super_block *sb, int force);
27767 +int au_fhsm_fd(struct super_block *sb, int oflags);
27768 +int au_fhsm_br_alloc(struct au_branch *br);
27769 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
27770 +void au_fhsm_fin(struct super_block *sb);
27771 +void au_fhsm_init(struct au_sbinfo *sbinfo);
27772 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
27773 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
27775 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
27777 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
27778 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
27779 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
27780 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
27781 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
27782 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
27783 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
27784 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
27785 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
27788 +/* ---------------------------------------------------------------------- */
27790 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
27792 + return sb->s_fs_info;
27795 +/* ---------------------------------------------------------------------- */
27797 +#ifdef CONFIG_AUFS_EXPORT
27798 +int au_test_nfsd(void);
27799 +void au_export_init(struct super_block *sb);
27800 +void au_xigen_inc(struct inode *inode);
27801 +int au_xigen_new(struct inode *inode);
27802 +int au_xigen_set(struct super_block *sb, struct file *base);
27803 +void au_xigen_clr(struct super_block *sb);
27805 +static inline int au_busy_or_stale(void)
27807 + if (!au_test_nfsd())
27812 +AuStubInt0(au_test_nfsd, void)
27813 +AuStubVoid(au_export_init, struct super_block *sb)
27814 +AuStubVoid(au_xigen_inc, struct inode *inode)
27815 +AuStubInt0(au_xigen_new, struct inode *inode)
27816 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
27817 +AuStubVoid(au_xigen_clr, struct super_block *sb)
27818 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
27819 +#endif /* CONFIG_AUFS_EXPORT */
27821 +/* ---------------------------------------------------------------------- */
27823 +#ifdef CONFIG_AUFS_SBILIST
27825 +extern struct au_splhead au_sbilist;
27827 +static inline void au_sbilist_init(void)
27829 + au_spl_init(&au_sbilist);
27832 +static inline void au_sbilist_add(struct super_block *sb)
27834 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
27837 +static inline void au_sbilist_del(struct super_block *sb)
27839 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
27842 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
27843 +static inline void au_sbilist_lock(void)
27845 + spin_lock(&au_sbilist.spin);
27848 +static inline void au_sbilist_unlock(void)
27850 + spin_unlock(&au_sbilist.spin);
27852 +#define AuGFP_SBILIST GFP_ATOMIC
27854 +AuStubVoid(au_sbilist_lock, void)
27855 +AuStubVoid(au_sbilist_unlock, void)
27856 +#define AuGFP_SBILIST GFP_NOFS
27857 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
27859 +AuStubVoid(au_sbilist_init, void)
27860 +AuStubVoid(au_sbilist_add, struct super_block *sb)
27861 +AuStubVoid(au_sbilist_del, struct super_block *sb)
27862 +AuStubVoid(au_sbilist_lock, void)
27863 +AuStubVoid(au_sbilist_unlock, void)
27864 +#define AuGFP_SBILIST GFP_NOFS
27867 +/* ---------------------------------------------------------------------- */
27869 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
27872 + * This function is a dynamic '__init' function actually,
27873 + * so the tiny check for si_rwsem is unnecessary.
27875 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
27876 +#ifdef CONFIG_DEBUG_FS
27877 + sbinfo->si_dbgaufs = NULL;
27878 + sbinfo->si_dbgaufs_plink = NULL;
27879 + sbinfo->si_dbgaufs_xib = NULL;
27880 +#ifdef CONFIG_AUFS_EXPORT
27881 + sbinfo->si_dbgaufs_xigen = NULL;
27886 +/* ---------------------------------------------------------------------- */
27888 +static inline pid_t si_pid_bit(void)
27890 + /* the origin of pid is 1, but the bitmap's is 0 */
27891 + return current->pid - 1;
27894 +static inline int si_pid_test(struct super_block *sb)
27898 + bit = si_pid_bit();
27899 + if (bit < PID_MAX_DEFAULT)
27900 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27901 + return si_pid_test_slow(sb);
27904 +static inline void si_pid_set(struct super_block *sb)
27908 + bit = si_pid_bit();
27909 + if (bit < PID_MAX_DEFAULT) {
27910 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27911 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27914 + si_pid_set_slow(sb);
27917 +static inline void si_pid_clr(struct super_block *sb)
27921 + bit = si_pid_bit();
27922 + if (bit < PID_MAX_DEFAULT) {
27923 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27924 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27927 + si_pid_clr_slow(sb);
27930 +/* ---------------------------------------------------------------------- */
27932 +/* lock superblock. mainly for entry point functions */
27934 + * __si_read_lock, __si_write_lock,
27935 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
27937 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
27939 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
27940 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
27941 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
27943 +static inline void si_noflush_read_lock(struct super_block *sb)
27945 + __si_read_lock(sb);
27949 +static inline int si_noflush_read_trylock(struct super_block *sb)
27953 + locked = __si_read_trylock(sb);
27959 +static inline void si_noflush_write_lock(struct super_block *sb)
27961 + __si_write_lock(sb);
27965 +static inline int si_noflush_write_trylock(struct super_block *sb)
27969 + locked = __si_write_trylock(sb);
27975 +#if 0 /* unused */
27976 +static inline int si_read_trylock(struct super_block *sb, int flags)
27978 + if (au_ftest_lock(flags, FLUSH))
27979 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27980 + return si_noflush_read_trylock(sb);
27984 +static inline void si_read_unlock(struct super_block *sb)
27987 + __si_read_unlock(sb);
27990 +#if 0 /* unused */
27991 +static inline int si_write_trylock(struct super_block *sb, int flags)
27993 + if (au_ftest_lock(flags, FLUSH))
27994 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27995 + return si_noflush_write_trylock(sb);
27999 +static inline void si_write_unlock(struct super_block *sb)
28002 + __si_write_unlock(sb);
28005 +#if 0 /* unused */
28006 +static inline void si_downgrade_lock(struct super_block *sb)
28008 + __si_downgrade_lock(sb);
28012 +/* ---------------------------------------------------------------------- */
28014 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
28016 + SiMustAnyLock(sb);
28017 + return au_sbi(sb)->si_bend;
28020 +static inline unsigned int au_mntflags(struct super_block *sb)
28022 + SiMustAnyLock(sb);
28023 + return au_sbi(sb)->si_mntflags;
28026 +static inline unsigned int au_sigen(struct super_block *sb)
28028 + SiMustAnyLock(sb);
28029 + return au_sbi(sb)->si_generation;
28032 +static inline void au_ninodes_inc(struct super_block *sb)
28034 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
28037 +static inline void au_ninodes_dec(struct super_block *sb)
28039 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
28040 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
28043 +static inline void au_nfiles_inc(struct super_block *sb)
28045 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
28048 +static inline void au_nfiles_dec(struct super_block *sb)
28050 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
28051 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
28054 +static inline struct au_branch *au_sbr(struct super_block *sb,
28055 + aufs_bindex_t bindex)
28057 + SiMustAnyLock(sb);
28058 + return au_sbi(sb)->si_branch[0 + bindex];
28061 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28063 + SiMustWriteLock(sb);
28064 + au_sbi(sb)->si_xino_brid = brid;
28067 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28069 + SiMustAnyLock(sb);
28070 + return au_sbi(sb)->si_xino_brid;
28073 +#endif /* __KERNEL__ */
28074 +#endif /* __AUFS_SUPER_H__ */
28075 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28076 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28077 +++ linux/fs/aufs/sysaufs.c 2015-01-25 13:00:38.634380408 +0100
28080 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28082 + * This program, aufs is free software; you can redistribute it and/or modify
28083 + * it under the terms of the GNU General Public License as published by
28084 + * the Free Software Foundation; either version 2 of the License, or
28085 + * (at your option) any later version.
28087 + * This program is distributed in the hope that it will be useful,
28088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28090 + * GNU General Public License for more details.
28092 + * You should have received a copy of the GNU General Public License
28093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28097 + * sysfs interface and lifetime management
28098 + * they are necessary regardless sysfs is disabled.
28101 +#include <linux/random.h>
28104 +unsigned long sysaufs_si_mask;
28105 +struct kset *sysaufs_kset;
28107 +#define AuSiAttr(_name) { \
28108 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28109 + .show = sysaufs_si_##_name, \
28112 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28113 +struct attribute *sysaufs_si_attrs[] = {
28114 + &sysaufs_si_attr_xi_path.attr,
28118 +static const struct sysfs_ops au_sbi_ops = {
28119 + .show = sysaufs_si_show
28122 +static struct kobj_type au_sbi_ktype = {
28123 + .release = au_si_free,
28124 + .sysfs_ops = &au_sbi_ops,
28125 + .default_attrs = sysaufs_si_attrs
28128 +/* ---------------------------------------------------------------------- */
28130 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28134 + sbinfo->si_kobj.kset = sysaufs_kset;
28135 + /* cf. sysaufs_name() */
28136 + err = kobject_init_and_add
28137 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28138 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28140 + dbgaufs_si_null(sbinfo);
28142 + err = dbgaufs_si_init(sbinfo);
28143 + if (unlikely(err))
28144 + kobject_put(&sbinfo->si_kobj);
28149 +void sysaufs_fin(void)
28152 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28153 + kset_unregister(sysaufs_kset);
28156 +int __init sysaufs_init(void)
28161 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28162 + } while (!sysaufs_si_mask);
28165 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28166 + if (unlikely(!sysaufs_kset))
28168 + err = PTR_ERR(sysaufs_kset);
28169 + if (IS_ERR(sysaufs_kset))
28171 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28172 + if (unlikely(err)) {
28173 + kset_unregister(sysaufs_kset);
28177 + err = dbgaufs_init();
28178 + if (unlikely(err))
28183 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28184 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28185 +++ linux/fs/aufs/sysaufs.h 2015-01-25 13:00:38.634380408 +0100
28188 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28190 + * This program, aufs is free software; you can redistribute it and/or modify
28191 + * it under the terms of the GNU General Public License as published by
28192 + * the Free Software Foundation; either version 2 of the License, or
28193 + * (at your option) any later version.
28195 + * This program is distributed in the hope that it will be useful,
28196 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28197 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28198 + * GNU General Public License for more details.
28200 + * You should have received a copy of the GNU General Public License
28201 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28205 + * sysfs interface and mount lifetime management
28208 +#ifndef __SYSAUFS_H__
28209 +#define __SYSAUFS_H__
28213 +#include <linux/sysfs.h>
28214 +#include "module.h"
28216 +struct super_block;
28219 +struct sysaufs_si_attr {
28220 + struct attribute attr;
28221 + int (*show)(struct seq_file *seq, struct super_block *sb);
28224 +/* ---------------------------------------------------------------------- */
28227 +extern unsigned long sysaufs_si_mask;
28228 +extern struct kset *sysaufs_kset;
28229 +extern struct attribute *sysaufs_si_attrs[];
28230 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28231 +int __init sysaufs_init(void);
28232 +void sysaufs_fin(void);
28234 +/* ---------------------------------------------------------------------- */
28236 +/* some people doesn't like to show a pointer in kernel */
28237 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28239 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28242 +#define SysaufsSiNamePrefix "si_"
28243 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
28244 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
28246 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
28247 + sysaufs_si_id(sbinfo));
28251 +#ifdef CONFIG_SYSFS
28253 +extern struct attribute_group *sysaufs_attr_group;
28255 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
28256 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28258 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
28259 +#ifdef CONFIG_COMPAT
28260 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
28263 +void sysaufs_br_init(struct au_branch *br);
28264 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
28265 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
28267 +#define sysaufs_brs_init() do {} while (0)
28270 +#define sysaufs_attr_group NULL
28272 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
28273 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
28274 + struct attribute *attr, char *buf)
28275 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
28276 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
28277 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28279 +static inline void sysaufs_brs_init(void)
28284 +#endif /* CONFIG_SYSFS */
28286 +#endif /* __KERNEL__ */
28287 +#endif /* __SYSAUFS_H__ */
28288 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
28289 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28290 +++ linux/fs/aufs/sysfs.c 2015-01-25 13:00:38.634380408 +0100
28293 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28295 + * This program, aufs is free software; you can redistribute it and/or modify
28296 + * it under the terms of the GNU General Public License as published by
28297 + * the Free Software Foundation; either version 2 of the License, or
28298 + * (at your option) any later version.
28300 + * This program is distributed in the hope that it will be useful,
28301 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28302 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28303 + * GNU General Public License for more details.
28305 + * You should have received a copy of the GNU General Public License
28306 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28310 + * sysfs interface
28313 +#include <linux/compat.h>
28314 +#include <linux/seq_file.h>
28317 +#ifdef CONFIG_AUFS_FS_MODULE
28318 +/* this entry violates the "one line per file" policy of sysfs */
28319 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28323 + static char *conf =
28324 +/* this file is generated at compiling */
28325 +#include "conf.str"
28328 + err = snprintf(buf, PAGE_SIZE, conf);
28329 + if (unlikely(err >= PAGE_SIZE))
28334 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28337 +static struct attribute *au_attr[] = {
28338 +#ifdef CONFIG_AUFS_FS_MODULE
28339 + &au_config_attr.attr,
28341 + NULL, /* need to NULL terminate the list of attributes */
28344 +static struct attribute_group sysaufs_attr_group_body = {
28348 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28350 +/* ---------------------------------------------------------------------- */
28352 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28356 + SiMustAnyLock(sb);
28359 + if (au_opt_test(au_mntflags(sb), XINO)) {
28360 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28361 + seq_putc(seq, '\n');
28367 + * the lifetime of branch is independent from the entry under sysfs.
28368 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28371 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28372 + aufs_bindex_t bindex, int idx)
28375 + struct path path;
28376 + struct dentry *root;
28377 + struct au_branch *br;
28378 + au_br_perm_str_t perm;
28380 + AuDbg("b%d\n", bindex);
28383 + root = sb->s_root;
28384 + di_read_lock_parent(root, !AuLock_IR);
28385 + br = au_sbr(sb, bindex);
28388 + case AuBrSysfs_BR:
28389 + path.mnt = au_br_mnt(br);
28390 + path.dentry = au_h_dptr(root, bindex);
28391 + au_seq_path(seq, &path);
28392 + au_optstr_br_perm(&perm, br->br_perm);
28393 + err = seq_printf(seq, "=%s\n", perm.a);
28395 + case AuBrSysfs_BRID:
28396 + err = seq_printf(seq, "%d\n", br->br_id);
28399 + di_read_unlock(root, !AuLock_IR);
28406 +/* ---------------------------------------------------------------------- */
28408 +static struct seq_file *au_seq(char *p, ssize_t len)
28410 + struct seq_file *seq;
28412 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28414 + /* mutex_init(&seq.lock); */
28417 + return seq; /* success */
28420 + seq = ERR_PTR(-ENOMEM);
28424 +#define SysaufsBr_PREFIX "br"
28425 +#define SysaufsBrid_PREFIX "brid"
28427 +/* todo: file size may exceed PAGE_SIZE */
28428 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28434 + aufs_bindex_t bend;
28435 + struct au_sbinfo *sbinfo;
28436 + struct super_block *sb;
28437 + struct seq_file *seq;
28439 + struct attribute **cattr;
28441 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28442 + sb = sbinfo->si_sb;
28445 + * prevent a race condition between sysfs and aufs.
28446 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28447 + * prohibits maintaining the sysfs entries.
28448 + * hew we acquire read lock after sysfs_get_active_two().
28449 + * on the other hand, the remount process may maintain the sysfs/aufs
28450 + * entries after acquiring write lock.
28451 + * it can cause a deadlock.
28452 + * simply we gave up processing read here.
28455 + if (unlikely(!si_noflush_read_trylock(sb)))
28458 + seq = au_seq(buf, PAGE_SIZE);
28459 + err = PTR_ERR(seq);
28463 + name = (void *)attr->name;
28464 + cattr = sysaufs_si_attrs;
28466 + if (!strcmp(name, (*cattr)->name)) {
28467 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28474 + if (!strncmp(name, SysaufsBrid_PREFIX,
28475 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28476 + idx = AuBrSysfs_BRID;
28477 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28478 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28479 + sizeof(SysaufsBr_PREFIX) - 1)) {
28480 + idx = AuBrSysfs_BR;
28481 + name += sizeof(SysaufsBr_PREFIX) - 1;
28485 + err = kstrtol(name, 10, &l);
28487 + bend = au_sbend(sb);
28489 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28496 + err = seq->count;
28497 + /* sysfs limit */
28498 + if (unlikely(err == PAGE_SIZE))
28503 + si_read_unlock(sb);
28508 +/* ---------------------------------------------------------------------- */
28510 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28514 + aufs_bindex_t bindex, bend;
28517 + struct seq_file *seq;
28518 + struct au_branch *br;
28520 + si_read_lock(sb, AuLock_FLUSH);
28521 + bend = au_sbend(sb);
28527 + buf = (void *)__get_free_page(GFP_NOFS);
28528 + if (unlikely(!buf))
28531 + seq = au_seq(buf, PAGE_SIZE);
28532 + err = PTR_ERR(seq);
28536 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28537 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28538 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28539 + if (unlikely(err))
28542 + br = au_sbr(sb, bindex);
28543 + brid = br->br_id;
28544 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28545 + err = __put_user(brid, &arg->id);
28546 + if (unlikely(err))
28549 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28550 + err = __put_user(br->br_perm, &arg->perm);
28551 + if (unlikely(err))
28554 + au_seq_path(seq, &br->br_path);
28555 + err = seq_putc(seq, '\0');
28556 + if (!err && seq->count <= sz) {
28557 + err = copy_to_user(arg->path, seq->buf, seq->count);
28559 + if (unlikely(err))
28566 + if (unlikely(err))
28572 + free_page((unsigned long)buf);
28574 + si_read_unlock(sb);
28578 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28580 + return au_brinfo(file->f_dentry->d_sb, (void __user *)arg);
28583 +#ifdef CONFIG_COMPAT
28584 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
28586 + return au_brinfo(file->f_dentry->d_sb, compat_ptr(arg));
28590 +/* ---------------------------------------------------------------------- */
28592 +void sysaufs_br_init(struct au_branch *br)
28595 + struct au_brsysfs *br_sysfs;
28596 + struct attribute *attr;
28598 + br_sysfs = br->br_sysfs;
28599 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28600 + attr = &br_sysfs->attr;
28601 + sysfs_attr_init(attr);
28602 + attr->name = br_sysfs->name;
28603 + attr->mode = S_IRUGO;
28608 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28610 + struct au_branch *br;
28611 + struct kobject *kobj;
28612 + struct au_brsysfs *br_sysfs;
28614 + aufs_bindex_t bend;
28616 + dbgaufs_brs_del(sb, bindex);
28618 + if (!sysaufs_brs)
28621 + kobj = &au_sbi(sb)->si_kobj;
28622 + bend = au_sbend(sb);
28623 + for (; bindex <= bend; bindex++) {
28624 + br = au_sbr(sb, bindex);
28625 + br_sysfs = br->br_sysfs;
28626 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28627 + sysfs_remove_file(kobj, &br_sysfs->attr);
28633 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
28636 + aufs_bindex_t bend;
28637 + struct kobject *kobj;
28638 + struct au_branch *br;
28639 + struct au_brsysfs *br_sysfs;
28641 + dbgaufs_brs_add(sb, bindex);
28643 + if (!sysaufs_brs)
28646 + kobj = &au_sbi(sb)->si_kobj;
28647 + bend = au_sbend(sb);
28648 + for (; bindex <= bend; bindex++) {
28649 + br = au_sbr(sb, bindex);
28650 + br_sysfs = br->br_sysfs;
28651 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
28652 + SysaufsBr_PREFIX "%d", bindex);
28653 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
28654 + SysaufsBrid_PREFIX "%d", bindex);
28655 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28656 + err = sysfs_create_file(kobj, &br_sysfs->attr);
28657 + if (unlikely(err))
28658 + pr_warn("failed %s under sysfs(%d)\n",
28659 + br_sysfs->name, err);
28664 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
28665 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
28666 +++ linux/fs/aufs/sysrq.c 2015-01-25 13:00:38.634380408 +0100
28669 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28671 + * This program, aufs is free software; you can redistribute it and/or modify
28672 + * it under the terms of the GNU General Public License as published by
28673 + * the Free Software Foundation; either version 2 of the License, or
28674 + * (at your option) any later version.
28676 + * This program is distributed in the hope that it will be useful,
28677 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28678 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28679 + * GNU General Public License for more details.
28681 + * You should have received a copy of the GNU General Public License
28682 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28686 + * magic sysrq hanlder
28689 +/* #include <linux/sysrq.h> */
28690 +#include <linux/writeback.h>
28693 +/* ---------------------------------------------------------------------- */
28695 +static void sysrq_sb(struct super_block *sb)
28698 + struct au_sbinfo *sbinfo;
28699 + struct file *file;
28700 + struct au_sphlhead *files;
28701 + struct au_finfo *finfo;
28703 + plevel = au_plevel;
28704 + au_plevel = KERN_WARNING;
28706 + /* since we define pr_fmt, call printk directly */
28707 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
28709 + sbinfo = au_sbi(sb);
28710 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
28711 + pr("superblock\n");
28715 + pr("root dentry\n");
28716 + au_dpri_dentry(sb->s_root);
28717 + pr("root inode\n");
28718 + au_dpri_inode(sb->s_root->d_inode);
28723 + int err, i, j, ndentry;
28724 + struct au_dcsub_pages dpages;
28725 + struct au_dpage *dpage;
28727 + err = au_dpages_init(&dpages, GFP_ATOMIC);
28728 + if (unlikely(err))
28730 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
28732 + for (i = 0; i < dpages.ndpage; i++) {
28733 + dpage = dpages.dpages + i;
28734 + ndentry = dpage->ndentry;
28735 + for (j = 0; j < ndentry; j++)
28736 + au_dpri_dentry(dpage->dentries[j]);
28738 + au_dpages_free(&dpages);
28746 + pr("isolated inode\n");
28747 + spin_lock(&inode_sb_list_lock);
28748 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
28749 + spin_lock(&i->i_lock);
28750 + if (1 || hlist_empty(&i->i_dentry))
28751 + au_dpri_inode(i);
28752 + spin_unlock(&i->i_lock);
28754 + spin_unlock(&inode_sb_list_lock);
28758 + files = &au_sbi(sb)->si_files;
28759 + spin_lock(&files->spin);
28760 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
28763 + file = finfo->fi_file;
28764 + mode = file_inode(file)->i_mode;
28765 + if (!special_file(mode))
28766 + au_dpri_file(file);
28768 + spin_unlock(&files->spin);
28772 + au_plevel = plevel;
28775 +/* ---------------------------------------------------------------------- */
28777 +/* module parameter */
28778 +static char *aufs_sysrq_key = "a";
28779 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
28780 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
28782 +static void au_sysrq(int key __maybe_unused)
28784 + struct au_sbinfo *sbinfo;
28787 + au_sbilist_lock();
28788 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
28789 + sysrq_sb(sbinfo->si_sb);
28790 + au_sbilist_unlock();
28794 +static struct sysrq_key_op au_sysrq_op = {
28795 + .handler = au_sysrq,
28796 + .help_msg = "Aufs",
28797 + .action_msg = "Aufs",
28798 + .enable_mask = SYSRQ_ENABLE_DUMP
28801 +/* ---------------------------------------------------------------------- */
28803 +int __init au_sysrq_init(void)
28809 + key = *aufs_sysrq_key;
28810 + if ('a' <= key && key <= 'z')
28811 + err = register_sysrq_key(key, &au_sysrq_op);
28812 + if (unlikely(err))
28813 + pr_err("err %d, sysrq=%c\n", err, key);
28817 +void au_sysrq_fin(void)
28821 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
28822 + if (unlikely(err))
28823 + pr_err("err %d (ignored)\n", err);
28825 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
28826 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
28827 +++ linux/fs/aufs/vdir.c 2015-01-25 13:00:38.634380408 +0100
28830 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28832 + * This program, aufs is free software; you can redistribute it and/or modify
28833 + * it under the terms of the GNU General Public License as published by
28834 + * the Free Software Foundation; either version 2 of the License, or
28835 + * (at your option) any later version.
28837 + * This program is distributed in the hope that it will be useful,
28838 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28839 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28840 + * GNU General Public License for more details.
28842 + * You should have received a copy of the GNU General Public License
28843 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28847 + * virtual or vertical directory
28852 +static unsigned int calc_size(int nlen)
28854 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
28857 +static int set_deblk_end(union au_vdir_deblk_p *p,
28858 + union au_vdir_deblk_p *deblk_end)
28860 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
28861 + p->de->de_str.len = 0;
28865 + return -1; /* error */
28868 +/* returns true or false */
28869 +static int is_deblk_end(union au_vdir_deblk_p *p,
28870 + union au_vdir_deblk_p *deblk_end)
28872 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
28873 + return !p->de->de_str.len;
28877 +static unsigned char *last_deblk(struct au_vdir *vdir)
28879 + return vdir->vd_deblk[vdir->vd_nblk - 1];
28882 +/* ---------------------------------------------------------------------- */
28884 +/* estimate the apropriate size for name hash table */
28885 +unsigned int au_rdhash_est(loff_t sz)
28893 + if (sz < AUFS_RDHASH_DEF)
28894 + n = AUFS_RDHASH_DEF;
28895 + /* pr_info("n %u\n", n); */
28900 + * the allocated memory has to be freed by
28901 + * au_nhash_wh_free() or au_nhash_de_free().
28903 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
28905 + struct hlist_head *head;
28909 + sz = sizeof(*nhash->nh_head) * num_hash;
28910 + head = kmalloc(sz, gfp);
28912 + nhash->nh_num = num_hash;
28913 + nhash->nh_head = head;
28914 + for (u = 0; u < num_hash; u++)
28915 + INIT_HLIST_HEAD(head++);
28916 + return 0; /* success */
28922 +static void nhash_count(struct hlist_head *head)
28926 + struct hlist_node *pos;
28929 + hlist_for_each(pos, head)
28931 + pr_info("%lu\n", n);
28935 +static void au_nhash_wh_do_free(struct hlist_head *head)
28937 + struct au_vdir_wh *pos;
28938 + struct hlist_node *node;
28940 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
28944 +static void au_nhash_de_do_free(struct hlist_head *head)
28946 + struct au_vdir_dehstr *pos;
28947 + struct hlist_node *node;
28949 + hlist_for_each_entry_safe(pos, node, head, hash)
28950 + au_cache_free_vdir_dehstr(pos);
28953 +static void au_nhash_do_free(struct au_nhash *nhash,
28954 + void (*free)(struct hlist_head *head))
28957 + struct hlist_head *head;
28959 + n = nhash->nh_num;
28963 + head = nhash->nh_head;
28964 + while (n-- > 0) {
28965 + nhash_count(head);
28968 + kfree(nhash->nh_head);
28971 +void au_nhash_wh_free(struct au_nhash *whlist)
28973 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
28976 +static void au_nhash_de_free(struct au_nhash *delist)
28978 + au_nhash_do_free(delist, au_nhash_de_do_free);
28981 +/* ---------------------------------------------------------------------- */
28983 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
28987 + unsigned int u, n;
28988 + struct hlist_head *head;
28989 + struct au_vdir_wh *pos;
28992 + n = whlist->nh_num;
28993 + head = whlist->nh_head;
28994 + for (u = 0; u < n; u++, head++)
28995 + hlist_for_each_entry(pos, head, wh_hash)
28996 + if (pos->wh_bindex == btgt && ++num > limit)
29001 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29002 + unsigned char *name,
29003 + unsigned int len)
29006 + /* const unsigned int magic_bit = 12; */
29008 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29013 + /* v = hash_long(v, magic_bit); */
29014 + v %= nhash->nh_num;
29015 + return nhash->nh_head + v;
29018 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29021 + return str->len == nlen && !memcmp(str->name, name, nlen);
29024 +/* returns found or not */
29025 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29027 + struct hlist_head *head;
29028 + struct au_vdir_wh *pos;
29029 + struct au_vdir_destr *str;
29031 + head = au_name_hash(whlist, name, nlen);
29032 + hlist_for_each_entry(pos, head, wh_hash) {
29033 + str = &pos->wh_str;
29034 + AuDbg("%.*s\n", str->len, str->name);
29035 + if (au_nhash_test_name(str, name, nlen))
29041 +/* returns found(true) or not */
29042 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29044 + struct hlist_head *head;
29045 + struct au_vdir_dehstr *pos;
29046 + struct au_vdir_destr *str;
29048 + head = au_name_hash(delist, name, nlen);
29049 + hlist_for_each_entry(pos, head, hash) {
29051 + AuDbg("%.*s\n", str->len, str->name);
29052 + if (au_nhash_test_name(str, name, nlen))
29058 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29059 + unsigned char d_type)
29061 +#ifdef CONFIG_AUFS_SHWH
29062 + wh->wh_ino = ino;
29063 + wh->wh_type = d_type;
29067 +/* ---------------------------------------------------------------------- */
29069 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29070 + unsigned int d_type, aufs_bindex_t bindex,
29071 + unsigned char shwh)
29074 + struct au_vdir_destr *str;
29075 + struct au_vdir_wh *wh;
29077 + AuDbg("%.*s\n", nlen, name);
29078 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29081 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29082 + if (unlikely(!wh))
29086 + wh->wh_bindex = bindex;
29088 + au_shwh_init_wh(wh, ino, d_type);
29089 + str = &wh->wh_str;
29091 + memcpy(str->name, name, nlen);
29092 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29099 +static int append_deblk(struct au_vdir *vdir)
29102 + unsigned long ul;
29103 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29104 + union au_vdir_deblk_p p, deblk_end;
29105 + unsigned char **o;
29108 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29110 + if (unlikely(!o))
29113 + vdir->vd_deblk = o;
29114 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29116 + ul = vdir->vd_nblk++;
29117 + vdir->vd_deblk[ul] = p.deblk;
29118 + vdir->vd_last.ul = ul;
29119 + vdir->vd_last.p.deblk = p.deblk;
29120 + deblk_end.deblk = p.deblk + deblk_sz;
29121 + err = set_deblk_end(&p, &deblk_end);
29128 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29129 + unsigned int d_type, struct au_nhash *delist)
29133 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29134 + union au_vdir_deblk_p p, *room, deblk_end;
29135 + struct au_vdir_dehstr *dehstr;
29137 + p.deblk = last_deblk(vdir);
29138 + deblk_end.deblk = p.deblk + deblk_sz;
29139 + room = &vdir->vd_last.p;
29140 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29141 + || !is_deblk_end(room, &deblk_end));
29143 + sz = calc_size(nlen);
29144 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29145 + err = append_deblk(vdir);
29146 + if (unlikely(err))
29149 + p.deblk = last_deblk(vdir);
29150 + deblk_end.deblk = p.deblk + deblk_sz;
29152 + AuDebugOn(room->deblk != p.deblk);
29156 + dehstr = au_cache_alloc_vdir_dehstr();
29157 + if (unlikely(!dehstr))
29160 + dehstr->str = &room->de->de_str;
29161 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29162 + room->de->de_ino = ino;
29163 + room->de->de_type = d_type;
29164 + room->de->de_str.len = nlen;
29165 + memcpy(room->de->de_str.name, name, nlen);
29168 + room->deblk += sz;
29169 + if (unlikely(set_deblk_end(room, &deblk_end)))
29170 + err = append_deblk(vdir);
29177 +/* ---------------------------------------------------------------------- */
29179 +void au_vdir_free(struct au_vdir *vdir)
29181 + unsigned char **deblk;
29183 + deblk = vdir->vd_deblk;
29184 + while (vdir->vd_nblk--)
29186 + kfree(vdir->vd_deblk);
29187 + au_cache_free_vdir(vdir);
29190 +static struct au_vdir *alloc_vdir(struct file *file)
29192 + struct au_vdir *vdir;
29193 + struct super_block *sb;
29196 + sb = file->f_dentry->d_sb;
29197 + SiMustAnyLock(sb);
29200 + vdir = au_cache_alloc_vdir();
29201 + if (unlikely(!vdir))
29204 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29205 + if (unlikely(!vdir->vd_deblk))
29208 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29209 + if (!vdir->vd_deblk_sz) {
29210 + /* estimate the apropriate size for deblk */
29211 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29212 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29214 + vdir->vd_nblk = 0;
29215 + vdir->vd_version = 0;
29216 + vdir->vd_jiffy = 0;
29217 + err = append_deblk(vdir);
29219 + return vdir; /* success */
29221 + kfree(vdir->vd_deblk);
29224 + au_cache_free_vdir(vdir);
29226 + vdir = ERR_PTR(err);
29230 +static int reinit_vdir(struct au_vdir *vdir)
29233 + union au_vdir_deblk_p p, deblk_end;
29235 + while (vdir->vd_nblk > 1) {
29236 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
29237 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
29240 + p.deblk = vdir->vd_deblk[0];
29241 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
29242 + err = set_deblk_end(&p, &deblk_end);
29243 + /* keep vd_dblk_sz */
29244 + vdir->vd_last.ul = 0;
29245 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29246 + vdir->vd_version = 0;
29247 + vdir->vd_jiffy = 0;
29252 +/* ---------------------------------------------------------------------- */
29254 +#define AuFillVdir_CALLED 1
29255 +#define AuFillVdir_WHABLE (1 << 1)
29256 +#define AuFillVdir_SHWH (1 << 2)
29257 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
29258 +#define au_fset_fillvdir(flags, name) \
29259 + do { (flags) |= AuFillVdir_##name; } while (0)
29260 +#define au_fclr_fillvdir(flags, name) \
29261 + do { (flags) &= ~AuFillVdir_##name; } while (0)
29263 +#ifndef CONFIG_AUFS_SHWH
29264 +#undef AuFillVdir_SHWH
29265 +#define AuFillVdir_SHWH 0
29268 +struct fillvdir_arg {
29269 + struct dir_context ctx;
29270 + struct file *file;
29271 + struct au_vdir *vdir;
29272 + struct au_nhash delist;
29273 + struct au_nhash whlist;
29274 + aufs_bindex_t bindex;
29275 + unsigned int flags;
29279 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29280 + loff_t offset __maybe_unused, u64 h_ino,
29281 + unsigned int d_type)
29283 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29284 + char *name = (void *)__name;
29285 + struct super_block *sb;
29287 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29290 + sb = arg->file->f_dentry->d_sb;
29291 + au_fset_fillvdir(arg->flags, CALLED);
29293 + if (nlen <= AUFS_WH_PFX_LEN
29294 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29295 + if (test_known(&arg->delist, name, nlen)
29296 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29297 + goto out; /* already exists or whiteouted */
29299 + sb = arg->file->f_dentry->d_sb;
29300 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29302 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29303 + d_type = DT_UNKNOWN;
29304 + arg->err = append_de(arg->vdir, name, nlen, ino,
29305 + d_type, &arg->delist);
29307 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29308 + name += AUFS_WH_PFX_LEN;
29309 + nlen -= AUFS_WH_PFX_LEN;
29310 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29311 + goto out; /* already whiteouted */
29314 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29317 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29318 + d_type = DT_UNKNOWN;
29319 + arg->err = au_nhash_append_wh
29320 + (&arg->whlist, name, nlen, ino, d_type,
29321 + arg->bindex, shwh);
29327 + arg->vdir->vd_jiffy = jiffies;
29329 + AuTraceErr(arg->err);
29333 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29334 + struct au_nhash *whlist, struct au_nhash *delist)
29336 +#ifdef CONFIG_AUFS_SHWH
29338 + unsigned int nh, u;
29339 + struct hlist_head *head;
29340 + struct au_vdir_wh *pos;
29341 + struct hlist_node *n;
29343 + struct au_vdir_destr *destr;
29345 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29348 + o = p = (void *)__get_free_page(GFP_NOFS);
29349 + if (unlikely(!p))
29353 + nh = whlist->nh_num;
29354 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29355 + p += AUFS_WH_PFX_LEN;
29356 + for (u = 0; u < nh; u++) {
29357 + head = whlist->nh_head + u;
29358 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29359 + destr = &pos->wh_str;
29360 + memcpy(p, destr->name, destr->len);
29361 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29362 + pos->wh_ino, pos->wh_type, delist);
29363 + if (unlikely(err))
29368 + free_page((unsigned long)o);
29378 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29381 + unsigned int rdhash;
29383 + aufs_bindex_t bend, bindex, bstart;
29384 + unsigned char shwh;
29385 + struct file *hf, *file;
29386 + struct super_block *sb;
29388 + file = arg->file;
29389 + sb = file->f_dentry->d_sb;
29390 + SiMustAnyLock(sb);
29392 + rdhash = au_sbi(sb)->si_rdhash;
29394 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29395 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29396 + if (unlikely(err))
29398 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29399 + if (unlikely(err))
29405 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29407 + au_fset_fillvdir(arg->flags, SHWH);
29409 + bstart = au_fbstart(file);
29410 + bend = au_fbend_dir(file);
29411 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29412 + hf = au_hf_dir(file, bindex);
29416 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29418 + if (unlikely(offset))
29421 + arg->bindex = bindex;
29422 + au_fclr_fillvdir(arg->flags, WHABLE);
29424 + || (bindex != bend
29425 + && au_br_whable(au_sbr_perm(sb, bindex))))
29426 + au_fset_fillvdir(arg->flags, WHABLE);
29429 + au_fclr_fillvdir(arg->flags, CALLED);
29431 + err = vfsub_iterate_dir(hf, &arg->ctx);
29434 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29437 + * dir_relax() may be good for concurrency, but aufs should not
29438 + * use it since it will cause a lockdep problem.
29442 + if (!err && shwh)
29443 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29445 + au_nhash_wh_free(&arg->whlist);
29448 + au_nhash_de_free(&arg->delist);
29453 +static int read_vdir(struct file *file, int may_read)
29456 + unsigned long expire;
29457 + unsigned char do_read;
29458 + struct fillvdir_arg arg = {
29460 + .actor = au_diractor(fillvdir)
29463 + struct inode *inode;
29464 + struct au_vdir *vdir, *allocated;
29467 + inode = file_inode(file);
29468 + IMustLock(inode);
29469 + SiMustAnyLock(inode->i_sb);
29471 + allocated = NULL;
29473 + expire = au_sbi(inode->i_sb)->si_rdcache;
29474 + vdir = au_ivdir(inode);
29477 + vdir = alloc_vdir(file);
29478 + err = PTR_ERR(vdir);
29479 + if (IS_ERR(vdir))
29482 + allocated = vdir;
29483 + } else if (may_read
29484 + && (inode->i_version != vdir->vd_version
29485 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29487 + err = reinit_vdir(vdir);
29488 + if (unlikely(err))
29493 + return 0; /* success */
29497 + err = au_do_read_vdir(&arg);
29499 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29500 + vdir->vd_version = inode->i_version;
29501 + vdir->vd_last.ul = 0;
29502 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29504 + au_set_ivdir(inode, allocated);
29505 + } else if (allocated)
29506 + au_vdir_free(allocated);
29512 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29515 + unsigned long ul, n;
29516 + const unsigned int deblk_sz = src->vd_deblk_sz;
29518 + AuDebugOn(tgt->vd_nblk != 1);
29521 + if (tgt->vd_nblk < src->vd_nblk) {
29522 + unsigned char **p;
29524 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29526 + if (unlikely(!p))
29528 + tgt->vd_deblk = p;
29531 + if (tgt->vd_deblk_sz != deblk_sz) {
29532 + unsigned char *p;
29534 + tgt->vd_deblk_sz = deblk_sz;
29535 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29536 + if (unlikely(!p))
29538 + tgt->vd_deblk[0] = p;
29540 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29541 + tgt->vd_version = src->vd_version;
29542 + tgt->vd_jiffy = src->vd_jiffy;
29544 + n = src->vd_nblk;
29545 + for (ul = 1; ul < n; ul++) {
29546 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29548 + if (unlikely(!tgt->vd_deblk[ul]))
29552 + tgt->vd_nblk = n;
29553 + tgt->vd_last.ul = tgt->vd_last.ul;
29554 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29555 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29556 + - src->vd_deblk[src->vd_last.ul];
29558 + return 0; /* success */
29561 + rerr = reinit_vdir(tgt);
29566 +int au_vdir_init(struct file *file)
29569 + struct inode *inode;
29570 + struct au_vdir *vdir_cache, *allocated;
29572 + /* test file->f_pos here instead of ctx->pos */
29573 + err = read_vdir(file, !file->f_pos);
29574 + if (unlikely(err))
29577 + allocated = NULL;
29578 + vdir_cache = au_fvdir_cache(file);
29579 + if (!vdir_cache) {
29580 + vdir_cache = alloc_vdir(file);
29581 + err = PTR_ERR(vdir_cache);
29582 + if (IS_ERR(vdir_cache))
29584 + allocated = vdir_cache;
29585 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29586 + /* test file->f_pos here instead of ctx->pos */
29587 + err = reinit_vdir(vdir_cache);
29588 + if (unlikely(err))
29591 + return 0; /* success */
29593 + inode = file_inode(file);
29594 + err = copy_vdir(vdir_cache, au_ivdir(inode));
29596 + file->f_version = inode->i_version;
29598 + au_set_fvdir_cache(file, allocated);
29599 + } else if (allocated)
29600 + au_vdir_free(allocated);
29606 +static loff_t calc_offset(struct au_vdir *vdir)
29609 + union au_vdir_deblk_p p;
29611 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29612 + offset = vdir->vd_last.p.deblk - p.deblk;
29613 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
29617 +/* returns true or false */
29618 +static int seek_vdir(struct file *file, struct dir_context *ctx)
29621 + unsigned int deblk_sz;
29622 + unsigned long ul, n;
29624 + union au_vdir_deblk_p p, deblk_end;
29625 + struct au_vdir *vdir_cache;
29628 + vdir_cache = au_fvdir_cache(file);
29629 + offset = calc_offset(vdir_cache);
29630 + AuDbg("offset %lld\n", offset);
29631 + if (ctx->pos == offset)
29634 + vdir_cache->vd_last.ul = 0;
29635 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
29640 + deblk_sz = vdir_cache->vd_deblk_sz;
29641 + ul = div64_u64(ctx->pos, deblk_sz);
29642 + AuDbg("ul %lu\n", ul);
29643 + if (ul >= vdir_cache->vd_nblk)
29646 + n = vdir_cache->vd_nblk;
29647 + for (; ul < n; ul++) {
29648 + p.deblk = vdir_cache->vd_deblk[ul];
29649 + deblk_end.deblk = p.deblk + deblk_sz;
29651 + offset *= deblk_sz;
29652 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
29655 + l = calc_size(p.de->de_str.len);
29659 + if (!is_deblk_end(&p, &deblk_end)) {
29661 + vdir_cache->vd_last.ul = ul;
29662 + vdir_cache->vd_last.p = p;
29669 + AuTraceErr(!valid);
29673 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
29675 + unsigned int l, deblk_sz;
29676 + union au_vdir_deblk_p deblk_end;
29677 + struct au_vdir *vdir_cache;
29678 + struct au_vdir_de *de;
29680 + vdir_cache = au_fvdir_cache(file);
29681 + if (!seek_vdir(file, ctx))
29684 + deblk_sz = vdir_cache->vd_deblk_sz;
29686 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29687 + deblk_end.deblk += deblk_sz;
29688 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
29689 + de = vdir_cache->vd_last.p.de;
29690 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
29691 + de->de_str.len, de->de_str.name, ctx->pos,
29692 + (unsigned long)de->de_ino, de->de_type);
29693 + if (unlikely(!dir_emit(ctx, de->de_str.name,
29694 + de->de_str.len, de->de_ino,
29696 + /* todo: ignore the error caused by udba? */
29697 + /* return err; */
29701 + l = calc_size(de->de_str.len);
29702 + vdir_cache->vd_last.p.deblk += l;
29705 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
29706 + vdir_cache->vd_last.ul++;
29707 + vdir_cache->vd_last.p.deblk
29708 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29709 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
29718 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
29719 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
29720 +++ linux/fs/aufs/vfsub.c 2015-01-25 13:00:38.634380408 +0100
29723 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29725 + * This program, aufs is free software; you can redistribute it and/or modify
29726 + * it under the terms of the GNU General Public License as published by
29727 + * the Free Software Foundation; either version 2 of the License, or
29728 + * (at your option) any later version.
29730 + * This program is distributed in the hope that it will be useful,
29731 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29732 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29733 + * GNU General Public License for more details.
29735 + * You should have received a copy of the GNU General Public License
29736 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29740 + * sub-routines for VFS
29743 +#include <linux/ima.h>
29744 +#include <linux/namei.h>
29745 +#include <linux/security.h>
29746 +#include <linux/splice.h>
29749 +int vfsub_update_h_iattr(struct path *h_path, int *did)
29753 + struct super_block *h_sb;
29755 + /* for remote fs, leave work for its getattr or d_revalidate */
29756 + /* for bad i_attr fs, handle them in aufs_getattr() */
29757 + /* still some fs may acquire i_mutex. we need to skip them */
29761 + h_sb = h_path->dentry->d_sb;
29762 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
29764 + err = vfs_getattr(h_path, &st);
29769 +/* ---------------------------------------------------------------------- */
29771 +struct file *vfsub_dentry_open(struct path *path, int flags)
29773 + struct file *file;
29775 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
29777 + if (!IS_ERR_OR_NULL(file)
29778 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
29779 + i_readcount_inc(path->dentry->d_inode);
29784 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
29786 + struct file *file;
29789 + file = filp_open(path,
29790 + oflags /* | __FMODE_NONOTIFY */,
29793 + if (IS_ERR(file))
29795 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29801 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
29805 + err = kern_path(name, flags, path);
29806 + if (!err && path->dentry->d_inode)
29807 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
29811 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
29814 + struct path path = {
29818 + /* VFS checks it too, but by WARN_ON_ONCE() */
29819 + IMustLock(parent->d_inode);
29821 + path.dentry = lookup_one_len(name, parent, len);
29822 + if (IS_ERR(path.dentry))
29824 + if (path.dentry->d_inode)
29825 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
29828 + AuTraceErrPtr(path.dentry);
29829 + return path.dentry;
29832 +void vfsub_call_lkup_one(void *args)
29834 + struct vfsub_lkup_one_args *a = args;
29835 + *a->errp = vfsub_lkup_one(a->name, a->parent);
29838 +/* ---------------------------------------------------------------------- */
29840 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
29841 + struct dentry *d2, struct au_hinode *hdir2)
29843 + struct dentry *d;
29846 + d = lock_rename(d1, d2);
29848 + au_hn_suspend(hdir1);
29849 + if (hdir1 != hdir2)
29850 + au_hn_suspend(hdir2);
29855 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
29856 + struct dentry *d2, struct au_hinode *hdir2)
29858 + au_hn_resume(hdir1);
29859 + if (hdir1 != hdir2)
29860 + au_hn_resume(hdir2);
29862 + unlock_rename(d1, d2);
29866 +/* ---------------------------------------------------------------------- */
29868 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
29871 + struct dentry *d;
29875 + d = path->dentry;
29876 + path->dentry = d->d_parent;
29877 + err = security_path_mknod(path, d, mode, 0);
29878 + path->dentry = d;
29879 + if (unlikely(err))
29883 + err = vfs_create(dir, path->dentry, mode, want_excl);
29886 + struct path tmp = *path;
29889 + vfsub_update_h_iattr(&tmp, &did);
29891 + tmp.dentry = path->dentry->d_parent;
29892 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29901 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
29904 + struct dentry *d;
29908 + d = path->dentry;
29909 + path->dentry = d->d_parent;
29910 + err = security_path_symlink(path, d, symname);
29911 + path->dentry = d;
29912 + if (unlikely(err))
29916 + err = vfs_symlink(dir, path->dentry, symname);
29919 + struct path tmp = *path;
29922 + vfsub_update_h_iattr(&tmp, &did);
29924 + tmp.dentry = path->dentry->d_parent;
29925 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29934 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
29937 + struct dentry *d;
29941 + d = path->dentry;
29942 + path->dentry = d->d_parent;
29943 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
29944 + path->dentry = d;
29945 + if (unlikely(err))
29949 + err = vfs_mknod(dir, path->dentry, mode, dev);
29952 + struct path tmp = *path;
29955 + vfsub_update_h_iattr(&tmp, &did);
29957 + tmp.dentry = path->dentry->d_parent;
29958 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29967 +static int au_test_nlink(struct inode *inode)
29969 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
29971 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
29972 + || inode->i_nlink < link_max)
29977 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
29978 + struct inode **delegated_inode)
29981 + struct dentry *d;
29985 + err = au_test_nlink(src_dentry->d_inode);
29986 + if (unlikely(err))
29989 + /* we don't call may_linkat() */
29990 + d = path->dentry;
29991 + path->dentry = d->d_parent;
29992 + err = security_path_link(src_dentry, path, d);
29993 + path->dentry = d;
29994 + if (unlikely(err))
29998 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30001 + struct path tmp = *path;
30004 + /* fuse has different memory inode for the same inumber */
30005 + vfsub_update_h_iattr(&tmp, &did);
30007 + tmp.dentry = path->dentry->d_parent;
30008 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30009 + tmp.dentry = src_dentry;
30010 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30019 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30020 + struct inode *dir, struct path *path,
30021 + struct inode **delegated_inode)
30024 + struct path tmp = {
30027 + struct dentry *d;
30030 + IMustLock(src_dir);
30032 + d = path->dentry;
30033 + path->dentry = d->d_parent;
30034 + tmp.dentry = src_dentry->d_parent;
30035 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30036 + path->dentry = d;
30037 + if (unlikely(err))
30041 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30042 + delegated_inode, /*flags*/0);
30047 + tmp.dentry = d->d_parent;
30048 + vfsub_update_h_iattr(&tmp, &did);
30050 + tmp.dentry = src_dentry;
30051 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30052 + tmp.dentry = src_dentry->d_parent;
30053 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30062 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30065 + struct dentry *d;
30069 + d = path->dentry;
30070 + path->dentry = d->d_parent;
30071 + err = security_path_mkdir(path, d, mode);
30072 + path->dentry = d;
30073 + if (unlikely(err))
30077 + err = vfs_mkdir(dir, path->dentry, mode);
30080 + struct path tmp = *path;
30083 + vfsub_update_h_iattr(&tmp, &did);
30085 + tmp.dentry = path->dentry->d_parent;
30086 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30095 +int vfsub_rmdir(struct inode *dir, struct path *path)
30098 + struct dentry *d;
30102 + d = path->dentry;
30103 + path->dentry = d->d_parent;
30104 + err = security_path_rmdir(path, d);
30105 + path->dentry = d;
30106 + if (unlikely(err))
30110 + err = vfs_rmdir(dir, path->dentry);
30113 + struct path tmp = {
30114 + .dentry = path->dentry->d_parent,
30118 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30125 +/* ---------------------------------------------------------------------- */
30127 +/* todo: support mmap_sem? */
30128 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30134 + err = vfs_read(file, ubuf, count, ppos);
30137 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30141 +/* todo: kernel_read()? */
30142 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30146 + mm_segment_t oldfs;
30153 + oldfs = get_fs();
30154 + set_fs(KERNEL_DS);
30155 + err = vfsub_read_u(file, buf.u, count, ppos);
30160 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30166 + err = vfs_write(file, ubuf, count, ppos);
30169 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30173 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
30176 + mm_segment_t oldfs;
30179 + const char __user *u;
30183 + oldfs = get_fs();
30184 + set_fs(KERNEL_DS);
30185 + err = vfsub_write_u(file, buf.u, count, ppos);
30190 +int vfsub_flush(struct file *file, fl_owner_t id)
30195 + if (file->f_op->flush) {
30196 + if (!au_test_nfs(file->f_dentry->d_sb))
30197 + err = file->f_op->flush(file, id);
30200 + err = file->f_op->flush(file, id);
30204 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30210 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30214 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30217 + err = iterate_dir(file, ctx);
30220 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30224 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30225 + struct pipe_inode_info *pipe, size_t len,
30226 + unsigned int flags)
30231 + err = do_splice_to(in, ppos, pipe, len, flags);
30233 + file_accessed(in);
30235 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30239 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30240 + loff_t *ppos, size_t len, unsigned int flags)
30245 + err = do_splice_from(pipe, out, ppos, len, flags);
30248 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30252 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30256 + /* file can be NULL */
30258 + err = vfs_fsync(file, datasync);
30262 + AuDebugOn(!file);
30263 + path = &file->f_path;
30265 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30270 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30271 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30272 + struct file *h_file)
30275 + struct inode *h_inode;
30276 + struct super_block *h_sb;
30279 + err = vfsub_truncate(h_path, length);
30283 + h_inode = h_path->dentry->d_inode;
30284 + h_sb = h_inode->i_sb;
30286 + sb_start_write(h_sb);
30288 + err = locks_verify_truncate(h_inode, h_file, length);
30290 + err = security_path_truncate(h_path);
30293 + err = do_truncate(h_path->dentry, length, attr, h_file);
30297 + sb_end_write(h_sb);
30304 +/* ---------------------------------------------------------------------- */
30306 +struct au_vfsub_mkdir_args {
30308 + struct inode *dir;
30309 + struct path *path;
30313 +static void au_call_vfsub_mkdir(void *args)
30315 + struct au_vfsub_mkdir_args *a = args;
30316 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30319 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30321 + int err, do_sio, wkq_err;
30323 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30326 + err = vfsub_mkdir(dir, path, mode);
30329 + struct au_vfsub_mkdir_args args = {
30335 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30336 + if (unlikely(wkq_err))
30343 +struct au_vfsub_rmdir_args {
30345 + struct inode *dir;
30346 + struct path *path;
30349 +static void au_call_vfsub_rmdir(void *args)
30351 + struct au_vfsub_rmdir_args *a = args;
30352 + *a->errp = vfsub_rmdir(a->dir, a->path);
30355 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30357 + int err, do_sio, wkq_err;
30359 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30362 + err = vfsub_rmdir(dir, path);
30365 + struct au_vfsub_rmdir_args args = {
30370 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30371 + if (unlikely(wkq_err))
30378 +/* ---------------------------------------------------------------------- */
30380 +struct notify_change_args {
30382 + struct path *path;
30383 + struct iattr *ia;
30384 + struct inode **delegated_inode;
30387 +static void call_notify_change(void *args)
30389 + struct notify_change_args *a = args;
30390 + struct inode *h_inode;
30392 + h_inode = a->path->dentry->d_inode;
30393 + IMustLock(h_inode);
30395 + *a->errp = -EPERM;
30396 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30398 + *a->errp = notify_change(a->path->dentry, a->ia,
30399 + a->delegated_inode);
30402 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30404 + AuTraceErr(*a->errp);
30407 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30408 + struct inode **delegated_inode)
30411 + struct notify_change_args args = {
30415 + .delegated_inode = delegated_inode
30418 + call_notify_change(&args);
30423 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30424 + struct inode **delegated_inode)
30426 + int err, wkq_err;
30427 + struct notify_change_args args = {
30431 + .delegated_inode = delegated_inode
30434 + wkq_err = au_wkq_wait(call_notify_change, &args);
30435 + if (unlikely(wkq_err))
30441 +/* ---------------------------------------------------------------------- */
30443 +struct unlink_args {
30445 + struct inode *dir;
30446 + struct path *path;
30447 + struct inode **delegated_inode;
30450 +static void call_unlink(void *args)
30452 + struct unlink_args *a = args;
30453 + struct dentry *d = a->path->dentry;
30454 + struct inode *h_inode;
30455 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30456 + && au_dcount(d) == 1);
30458 + IMustLock(a->dir);
30460 + a->path->dentry = d->d_parent;
30461 + *a->errp = security_path_unlink(a->path, d);
30462 + a->path->dentry = d;
30463 + if (unlikely(*a->errp))
30466 + if (!stop_sillyrename)
30468 + h_inode = d->d_inode;
30473 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30476 + struct path tmp = {
30477 + .dentry = d->d_parent,
30478 + .mnt = a->path->mnt
30480 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30483 + if (!stop_sillyrename)
30488 + AuTraceErr(*a->errp);
30492 + * @dir: must be locked.
30493 + * @dentry: target dentry.
30495 +int vfsub_unlink(struct inode *dir, struct path *path,
30496 + struct inode **delegated_inode, int force)
30499 + struct unlink_args args = {
30503 + .delegated_inode = delegated_inode
30507 + call_unlink(&args);
30511 + wkq_err = au_wkq_wait(call_unlink, &args);
30512 + if (unlikely(wkq_err))
30518 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
30519 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
30520 +++ linux/fs/aufs/vfsub.h 2015-01-25 13:00:38.634380408 +0100
30523 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30525 + * This program, aufs is free software; you can redistribute it and/or modify
30526 + * it under the terms of the GNU General Public License as published by
30527 + * the Free Software Foundation; either version 2 of the License, or
30528 + * (at your option) any later version.
30530 + * This program is distributed in the hope that it will be useful,
30531 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30532 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30533 + * GNU General Public License for more details.
30535 + * You should have received a copy of the GNU General Public License
30536 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30540 + * sub-routines for VFS
30543 +#ifndef __AUFS_VFSUB_H__
30544 +#define __AUFS_VFSUB_H__
30548 +#include <linux/fs.h>
30549 +#include <linux/lglock.h>
30550 +#include <linux/mount.h>
30551 +#include <linux/xattr.h>
30552 +#include "debug.h"
30554 +/* copied from linux/fs/internal.h */
30555 +/* todo: BAD approach!! */
30556 +extern void __mnt_drop_write(struct vfsmount *);
30557 +extern spinlock_t inode_sb_list_lock;
30559 +/* ---------------------------------------------------------------------- */
30561 +/* lock subclass for lower inode */
30562 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
30563 +/* reduce? gave up. */
30565 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
30566 + AuLsc_I_PARENT, /* lower inode, parent first */
30567 + AuLsc_I_PARENT2, /* copyup dirs */
30568 + AuLsc_I_PARENT3, /* copyup wh */
30574 +/* to debug easier, do not make them inlined functions */
30575 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
30576 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
30578 +/* ---------------------------------------------------------------------- */
30580 +static inline void vfsub_drop_nlink(struct inode *inode)
30582 + AuDebugOn(!inode->i_nlink);
30583 + drop_nlink(inode);
30586 +static inline void vfsub_dead_dir(struct inode *inode)
30588 + AuDebugOn(!S_ISDIR(inode->i_mode));
30589 + inode->i_flags |= S_DEAD;
30590 + clear_nlink(inode);
30593 +static inline int vfsub_native_ro(struct inode *inode)
30595 + return (inode->i_sb->s_flags & MS_RDONLY)
30596 + || IS_RDONLY(inode)
30597 + /* || IS_APPEND(inode) */
30598 + || IS_IMMUTABLE(inode);
30601 +/* ---------------------------------------------------------------------- */
30603 +int vfsub_update_h_iattr(struct path *h_path, int *did);
30604 +struct file *vfsub_dentry_open(struct path *path, int flags);
30605 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
30606 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
30608 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30611 +struct vfsub_lkup_one_args {
30612 + struct dentry **errp;
30613 + struct qstr *name;
30614 + struct dentry *parent;
30617 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
30618 + struct dentry *parent)
30620 + return vfsub_lookup_one_len(name->name, parent, name->len);
30623 +void vfsub_call_lkup_one(void *args);
30625 +/* ---------------------------------------------------------------------- */
30627 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
30632 + err = mnt_want_write(mnt);
30637 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
30640 + mnt_drop_write(mnt);
30644 +static inline void vfsub_mnt_drop_write_file(struct file *file)
30647 + mnt_drop_write_file(file);
30651 +/* ---------------------------------------------------------------------- */
30654 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30655 + struct dentry *d2, struct au_hinode *hdir2);
30656 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30657 + struct dentry *d2, struct au_hinode *hdir2);
30659 +int vfsub_create(struct inode *dir, struct path *path, int mode,
30661 +int vfsub_symlink(struct inode *dir, struct path *path,
30662 + const char *symname);
30663 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
30664 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
30665 + struct path *path, struct inode **delegated_inode);
30666 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
30667 + struct inode *hdir, struct path *path,
30668 + struct inode **delegated_inode);
30669 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
30670 +int vfsub_rmdir(struct inode *dir, struct path *path);
30672 +/* ---------------------------------------------------------------------- */
30674 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30676 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30678 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30680 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
30682 +int vfsub_flush(struct file *file, fl_owner_t id);
30683 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
30685 +/* just for type-check */
30686 +static inline filldir_t au_diractor(int (*func)(struct dir_context *,
30687 + const char *, int, loff_t, u64,
30690 + return (filldir_t)func;
30694 +static inline loff_t vfsub_f_size_read(struct file *file)
30696 + return i_size_read(file_inode(file));
30699 +static inline unsigned int vfsub_file_flags(struct file *file)
30701 + unsigned int flags;
30703 + spin_lock(&file->f_lock);
30704 + flags = file->f_flags;
30705 + spin_unlock(&file->f_lock);
30710 +static inline void vfsub_file_accessed(struct file *h_file)
30712 + file_accessed(h_file);
30713 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
30716 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
30717 + struct dentry *h_dentry)
30719 + struct path h_path = {
30720 + .dentry = h_dentry,
30723 + touch_atime(&h_path);
30724 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
30727 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
30730 + return update_time(h_inode, ts, flags);
30731 + /* no vfsub_update_h_iattr() since we don't have struct path */
30734 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30735 + struct pipe_inode_info *pipe, size_t len,
30736 + unsigned int flags);
30737 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30738 + loff_t *ppos, size_t len, unsigned int flags);
30740 +static inline long vfsub_truncate(struct path *path, loff_t length)
30745 + err = vfs_truncate(path, length);
30750 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30751 + struct file *h_file);
30752 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
30754 +/* ---------------------------------------------------------------------- */
30756 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
30761 + err = vfs_llseek(file, offset, origin);
30766 +/* ---------------------------------------------------------------------- */
30768 +/* dirty workaround for strict type of fmode_t */
30774 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
30776 + union vfsub_fmu u = {
30780 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
30785 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
30787 + union vfsub_fmu u = {
30794 +/* ---------------------------------------------------------------------- */
30796 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
30797 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
30798 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30799 + struct inode **delegated_inode);
30800 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30801 + struct inode **delegated_inode);
30802 +int vfsub_unlink(struct inode *dir, struct path *path,
30803 + struct inode **delegated_inode, int force);
30805 +/* ---------------------------------------------------------------------- */
30807 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
30808 + const void *value, size_t size, int flags)
30813 + err = vfs_setxattr(dentry, name, value, size, flags);
30819 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
30824 + err = vfs_removexattr(dentry, name);
30830 +#endif /* __KERNEL__ */
30831 +#endif /* __AUFS_VFSUB_H__ */
30832 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
30833 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
30834 +++ linux/fs/aufs/wbr_policy.c 2015-01-25 13:00:38.634380408 +0100
30837 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30839 + * This program, aufs is free software; you can redistribute it and/or modify
30840 + * it under the terms of the GNU General Public License as published by
30841 + * the Free Software Foundation; either version 2 of the License, or
30842 + * (at your option) any later version.
30844 + * This program is distributed in the hope that it will be useful,
30845 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30846 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30847 + * GNU General Public License for more details.
30849 + * You should have received a copy of the GNU General Public License
30850 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30854 + * policies for selecting one among multiple writable branches
30857 +#include <linux/statfs.h>
30860 +/* subset of cpup_attr() */
30861 +static noinline_for_stack
30862 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
30866 + struct inode *h_isrc;
30868 + h_isrc = h_src->d_inode;
30869 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
30870 + ia.ia_mode = h_isrc->i_mode;
30871 + ia.ia_uid = h_isrc->i_uid;
30872 + ia.ia_gid = h_isrc->i_gid;
30873 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
30874 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
30875 + /* no delegation since it is just created */
30876 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30878 + /* is this nfs only? */
30879 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
30880 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
30881 + ia.ia_mode = h_isrc->i_mode;
30882 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30888 +#define AuCpdown_PARENT_OPQ 1
30889 +#define AuCpdown_WHED (1 << 1)
30890 +#define AuCpdown_MADE_DIR (1 << 2)
30891 +#define AuCpdown_DIROPQ (1 << 3)
30892 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
30893 +#define au_fset_cpdown(flags, name) \
30894 + do { (flags) |= AuCpdown_##name; } while (0)
30895 +#define au_fclr_cpdown(flags, name) \
30896 + do { (flags) &= ~AuCpdown_##name; } while (0)
30898 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
30899 + unsigned int *flags)
30902 + struct dentry *opq_dentry;
30904 + opq_dentry = au_diropq_create(dentry, bdst);
30905 + err = PTR_ERR(opq_dentry);
30906 + if (IS_ERR(opq_dentry))
30908 + dput(opq_dentry);
30909 + au_fset_cpdown(*flags, DIROPQ);
30915 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
30916 + struct inode *dir, aufs_bindex_t bdst)
30919 + struct path h_path;
30920 + struct au_branch *br;
30922 + br = au_sbr(dentry->d_sb, bdst);
30923 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
30924 + err = PTR_ERR(h_path.dentry);
30925 + if (IS_ERR(h_path.dentry))
30929 + if (h_path.dentry->d_inode) {
30930 + h_path.mnt = au_br_mnt(br);
30931 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
30934 + dput(h_path.dentry);
30940 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
30941 + struct au_pin *pin,
30942 + struct dentry *h_parent, void *arg)
30945 + aufs_bindex_t bopq, bstart;
30946 + struct path h_path;
30947 + struct dentry *parent;
30948 + struct inode *h_dir, *h_inode, *inode, *dir;
30949 + unsigned int *flags = arg;
30951 + bstart = au_dbstart(dentry);
30952 + /* dentry is di-locked */
30953 + parent = dget_parent(dentry);
30954 + dir = parent->d_inode;
30955 + h_dir = h_parent->d_inode;
30956 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
30957 + IMustLock(h_dir);
30959 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
30960 + if (unlikely(err < 0))
30962 + h_path.dentry = au_h_dptr(dentry, bdst);
30963 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
30964 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
30965 + S_IRWXU | S_IRUGO | S_IXUGO);
30966 + if (unlikely(err))
30968 + au_fset_cpdown(*flags, MADE_DIR);
30970 + bopq = au_dbdiropq(dentry);
30971 + au_fclr_cpdown(*flags, WHED);
30972 + au_fclr_cpdown(*flags, DIROPQ);
30973 + if (au_dbwh(dentry) == bdst)
30974 + au_fset_cpdown(*flags, WHED);
30975 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
30976 + au_fset_cpdown(*flags, PARENT_OPQ);
30977 + h_inode = h_path.dentry->d_inode;
30978 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
30979 + if (au_ftest_cpdown(*flags, WHED)) {
30980 + err = au_cpdown_dir_opq(dentry, bdst, flags);
30981 + if (unlikely(err)) {
30982 + mutex_unlock(&h_inode->i_mutex);
30987 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
30988 + mutex_unlock(&h_inode->i_mutex);
30989 + if (unlikely(err))
30992 + if (au_ftest_cpdown(*flags, WHED)) {
30993 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
30994 + if (unlikely(err))
30998 + inode = dentry->d_inode;
30999 + if (au_ibend(inode) < bdst)
31000 + au_set_ibend(inode, bdst);
31001 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31002 + au_hi_flags(inode, /*isdir*/1));
31003 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31004 + goto out; /* success */
31008 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31009 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31010 + rerr = au_diropq_remove(dentry, bdst);
31011 + mutex_unlock(&h_inode->i_mutex);
31012 + if (unlikely(rerr)) {
31013 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31014 + dentry, bdst, rerr);
31020 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31021 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31022 + if (unlikely(rerr)) {
31023 + AuIOErr("failed removing %pd b%d (%d)\n",
31024 + dentry, bdst, rerr);
31029 + au_set_h_dptr(dentry, bdst, NULL);
31030 + if (au_dbend(dentry) == bdst)
31031 + au_update_dbend(dentry);
31037 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31040 + unsigned int flags;
31043 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31048 +/* ---------------------------------------------------------------------- */
31050 +/* policies for create */
31052 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31054 + int err, i, j, ndentry;
31055 + aufs_bindex_t bopq;
31056 + struct au_dcsub_pages dpages;
31057 + struct au_dpage *dpage;
31058 + struct dentry **dentries, *parent, *d;
31060 + err = au_dpages_init(&dpages, GFP_NOFS);
31061 + if (unlikely(err))
31063 + parent = dget_parent(dentry);
31064 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31065 + if (unlikely(err))
31069 + for (i = 0; i < dpages.ndpage; i++) {
31070 + dpage = dpages.dpages + i;
31071 + dentries = dpage->dentries;
31072 + ndentry = dpage->ndentry;
31073 + for (j = 0; j < ndentry; j++) {
31075 + di_read_lock_parent2(d, !AuLock_IR);
31076 + bopq = au_dbdiropq(d);
31077 + di_read_unlock(d, !AuLock_IR);
31078 + if (bopq >= 0 && bopq < err)
31085 + au_dpages_free(&dpages);
31090 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31092 + for (; bindex >= 0; bindex--)
31093 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31098 +/* top down parent */
31099 +static int au_wbr_create_tdp(struct dentry *dentry,
31100 + unsigned int flags __maybe_unused)
31103 + aufs_bindex_t bstart, bindex;
31104 + struct super_block *sb;
31105 + struct dentry *parent, *h_parent;
31107 + sb = dentry->d_sb;
31108 + bstart = au_dbstart(dentry);
31110 + if (!au_br_rdonly(au_sbr(sb, bstart)))
31114 + parent = dget_parent(dentry);
31115 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
31116 + h_parent = au_h_dptr(parent, bindex);
31117 + if (!h_parent || !h_parent->d_inode)
31120 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31127 + /* bottom up here */
31128 + if (unlikely(err < 0)) {
31129 + err = au_wbr_bu(sb, bstart - 1);
31131 + err = au_wbr_nonopq(dentry, err);
31135 + AuDbg("b%d\n", err);
31139 +/* ---------------------------------------------------------------------- */
31141 +/* an exception for the policy other than tdp */
31142 +static int au_wbr_create_exp(struct dentry *dentry)
31145 + aufs_bindex_t bwh, bdiropq;
31146 + struct dentry *parent;
31149 + bwh = au_dbwh(dentry);
31150 + parent = dget_parent(dentry);
31151 + bdiropq = au_dbdiropq(parent);
31153 + if (bdiropq >= 0)
31154 + err = min(bdiropq, bwh);
31157 + AuDbg("%d\n", err);
31158 + } else if (bdiropq >= 0) {
31160 + AuDbg("%d\n", err);
31165 + err = au_wbr_nonopq(dentry, err);
31167 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
31170 + AuDbg("%d\n", err);
31174 +/* ---------------------------------------------------------------------- */
31177 +static int au_wbr_create_init_rr(struct super_block *sb)
31181 + err = au_wbr_bu(sb, au_sbend(sb));
31182 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
31185 + AuDbg("b%d\n", err);
31189 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
31193 + aufs_bindex_t bindex, bend;
31194 + struct super_block *sb;
31197 + err = au_wbr_create_exp(dentry);
31201 + sb = dentry->d_sb;
31202 + next = &au_sbi(sb)->si_wbr_rr_next;
31203 + bend = au_sbend(sb);
31205 + for (bindex = 0; bindex <= bend; bindex++) {
31206 + if (!au_ftest_wbr(flags, DIR)) {
31207 + err = atomic_dec_return(next) + 1;
31208 + /* modulo for 0 is meaningless */
31209 + if (unlikely(!err))
31210 + err = atomic_dec_return(next) + 1;
31212 + err = atomic_read(next);
31213 + AuDbg("%d\n", err);
31216 + AuDbg("%d\n", err);
31217 + if (!au_br_rdonly(au_sbr(sb, err)))
31223 + err = au_wbr_nonopq(dentry, err);
31226 + AuDbg("%d\n", err);
31230 +/* ---------------------------------------------------------------------- */
31232 +/* most free space */
31233 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31235 + struct super_block *sb;
31236 + struct au_branch *br;
31237 + struct au_wbr_mfs *mfs;
31238 + struct dentry *h_parent;
31239 + aufs_bindex_t bindex, bend;
31241 + unsigned long long b, bavail;
31242 + struct path h_path;
31243 + /* reduce the stack usage */
31244 + struct kstatfs *st;
31246 + st = kmalloc(sizeof(*st), GFP_NOFS);
31247 + if (unlikely(!st)) {
31248 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31253 + sb = dentry->d_sb;
31254 + mfs = &au_sbi(sb)->si_wbr_mfs;
31255 + MtxMustLock(&mfs->mfs_lock);
31256 + mfs->mfs_bindex = -EROFS;
31257 + mfs->mfsrr_bytes = 0;
31260 + bend = au_sbend(sb);
31262 + bindex = au_dbstart(parent);
31263 + bend = au_dbtaildir(parent);
31266 + for (; bindex <= bend; bindex++) {
31268 + h_parent = au_h_dptr(parent, bindex);
31269 + if (!h_parent || !h_parent->d_inode)
31272 + br = au_sbr(sb, bindex);
31273 + if (au_br_rdonly(br))
31276 + /* sb->s_root for NFS is unreliable */
31277 + h_path.mnt = au_br_mnt(br);
31278 + h_path.dentry = h_path.mnt->mnt_root;
31279 + err = vfs_statfs(&h_path, st);
31280 + if (unlikely(err)) {
31281 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31285 + /* when the available size is equal, select the lower one */
31286 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31287 + || sizeof(b) < sizeof(st->f_bsize));
31288 + b = st->f_bavail * st->f_bsize;
31289 + br->br_wbr->wbr_bytes = b;
31290 + if (b >= bavail) {
31292 + mfs->mfs_bindex = bindex;
31293 + mfs->mfs_jiffy = jiffies;
31297 + mfs->mfsrr_bytes = bavail;
31298 + AuDbg("b%d\n", mfs->mfs_bindex);
31302 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31305 + struct dentry *parent;
31306 + struct super_block *sb;
31307 + struct au_wbr_mfs *mfs;
31309 + err = au_wbr_create_exp(dentry);
31313 + sb = dentry->d_sb;
31315 + if (au_ftest_wbr(flags, PARENT))
31316 + parent = dget_parent(dentry);
31317 + mfs = &au_sbi(sb)->si_wbr_mfs;
31318 + mutex_lock(&mfs->mfs_lock);
31319 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31320 + || mfs->mfs_bindex < 0
31321 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31322 + au_mfs(dentry, parent);
31323 + mutex_unlock(&mfs->mfs_lock);
31324 + err = mfs->mfs_bindex;
31328 + err = au_wbr_nonopq(dentry, err);
31331 + AuDbg("b%d\n", err);
31335 +static int au_wbr_create_init_mfs(struct super_block *sb)
31337 + struct au_wbr_mfs *mfs;
31339 + mfs = &au_sbi(sb)->si_wbr_mfs;
31340 + mutex_init(&mfs->mfs_lock);
31341 + mfs->mfs_jiffy = 0;
31342 + mfs->mfs_bindex = -EROFS;
31347 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31349 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31353 +/* ---------------------------------------------------------------------- */
31355 +/* most free space and then round robin */
31356 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31359 + struct au_wbr_mfs *mfs;
31361 + err = au_wbr_create_mfs(dentry, flags);
31363 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31364 + mutex_lock(&mfs->mfs_lock);
31365 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31366 + err = au_wbr_create_rr(dentry, flags);
31367 + mutex_unlock(&mfs->mfs_lock);
31370 + AuDbg("b%d\n", err);
31374 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31378 + au_wbr_create_init_mfs(sb); /* ignore */
31379 + err = au_wbr_create_init_rr(sb);
31384 +/* ---------------------------------------------------------------------- */
31386 +/* top down parent and most free space */
31387 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31390 + unsigned long long b;
31391 + aufs_bindex_t bindex, bstart, bend;
31392 + struct super_block *sb;
31393 + struct dentry *parent, *h_parent;
31394 + struct au_branch *br;
31396 + err = au_wbr_create_tdp(dentry, flags);
31397 + if (unlikely(err < 0))
31399 + parent = dget_parent(dentry);
31400 + bstart = au_dbstart(parent);
31401 + bend = au_dbtaildir(parent);
31402 + if (bstart == bend)
31403 + goto out_parent; /* success */
31405 + e2 = au_wbr_create_mfs(dentry, flags);
31407 + goto out_parent; /* success */
31409 + /* when the available size is equal, select upper one */
31410 + sb = dentry->d_sb;
31411 + br = au_sbr(sb, err);
31412 + b = br->br_wbr->wbr_bytes;
31413 + AuDbg("b%d, %llu\n", err, b);
31415 + for (bindex = bstart; bindex <= bend; bindex++) {
31416 + h_parent = au_h_dptr(parent, bindex);
31417 + if (!h_parent || !h_parent->d_inode)
31420 + br = au_sbr(sb, bindex);
31421 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31422 + b = br->br_wbr->wbr_bytes;
31424 + AuDbg("b%d, %llu\n", err, b);
31429 + err = au_wbr_nonopq(dentry, err);
31434 + AuDbg("b%d\n", err);
31438 +/* ---------------------------------------------------------------------- */
31441 + * - top down parent
31442 + * - most free space with parent
31443 + * - most free space round-robin regardless parent
31445 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31448 + unsigned long long watermark;
31449 + struct super_block *sb;
31450 + struct au_branch *br;
31451 + struct au_wbr_mfs *mfs;
31453 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31454 + if (unlikely(err < 0))
31457 + sb = dentry->d_sb;
31458 + br = au_sbr(sb, err);
31459 + mfs = &au_sbi(sb)->si_wbr_mfs;
31460 + mutex_lock(&mfs->mfs_lock);
31461 + watermark = mfs->mfsrr_watermark;
31462 + mutex_unlock(&mfs->mfs_lock);
31463 + if (br->br_wbr->wbr_bytes < watermark)
31464 + /* regardless the parent dir */
31465 + err = au_wbr_create_mfsrr(dentry, flags);
31468 + AuDbg("b%d\n", err);
31472 +/* ---------------------------------------------------------------------- */
31474 +/* policies for copyup */
31476 +/* top down parent */
31477 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31479 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31482 +/* bottom up parent */
31483 +static int au_wbr_copyup_bup(struct dentry *dentry)
31486 + aufs_bindex_t bindex, bstart;
31487 + struct dentry *parent, *h_parent;
31488 + struct super_block *sb;
31491 + sb = dentry->d_sb;
31492 + parent = dget_parent(dentry);
31493 + bstart = au_dbstart(parent);
31494 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31495 + h_parent = au_h_dptr(parent, bindex);
31496 + if (!h_parent || !h_parent->d_inode)
31499 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31506 + /* bottom up here */
31507 + if (unlikely(err < 0))
31508 + err = au_wbr_bu(sb, bstart - 1);
31510 + AuDbg("b%d\n", err);
31515 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
31519 + err = au_wbr_bu(dentry->d_sb, bstart);
31520 + AuDbg("b%d\n", err);
31521 + if (err > bstart)
31522 + err = au_wbr_nonopq(dentry, err);
31524 + AuDbg("b%d\n", err);
31528 +static int au_wbr_copyup_bu(struct dentry *dentry)
31531 + aufs_bindex_t bstart;
31533 + bstart = au_dbstart(dentry);
31534 + err = au_wbr_do_copyup_bu(dentry, bstart);
31538 +/* ---------------------------------------------------------------------- */
31540 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
31541 + [AuWbrCopyup_TDP] = {
31542 + .copyup = au_wbr_copyup_tdp
31544 + [AuWbrCopyup_BUP] = {
31545 + .copyup = au_wbr_copyup_bup
31547 + [AuWbrCopyup_BU] = {
31548 + .copyup = au_wbr_copyup_bu
31552 +struct au_wbr_create_operations au_wbr_create_ops[] = {
31553 + [AuWbrCreate_TDP] = {
31554 + .create = au_wbr_create_tdp
31556 + [AuWbrCreate_RR] = {
31557 + .create = au_wbr_create_rr,
31558 + .init = au_wbr_create_init_rr
31560 + [AuWbrCreate_MFS] = {
31561 + .create = au_wbr_create_mfs,
31562 + .init = au_wbr_create_init_mfs,
31563 + .fin = au_wbr_create_fin_mfs
31565 + [AuWbrCreate_MFSV] = {
31566 + .create = au_wbr_create_mfs,
31567 + .init = au_wbr_create_init_mfs,
31568 + .fin = au_wbr_create_fin_mfs
31570 + [AuWbrCreate_MFSRR] = {
31571 + .create = au_wbr_create_mfsrr,
31572 + .init = au_wbr_create_init_mfsrr,
31573 + .fin = au_wbr_create_fin_mfs
31575 + [AuWbrCreate_MFSRRV] = {
31576 + .create = au_wbr_create_mfsrr,
31577 + .init = au_wbr_create_init_mfsrr,
31578 + .fin = au_wbr_create_fin_mfs
31580 + [AuWbrCreate_PMFS] = {
31581 + .create = au_wbr_create_pmfs,
31582 + .init = au_wbr_create_init_mfs,
31583 + .fin = au_wbr_create_fin_mfs
31585 + [AuWbrCreate_PMFSV] = {
31586 + .create = au_wbr_create_pmfs,
31587 + .init = au_wbr_create_init_mfs,
31588 + .fin = au_wbr_create_fin_mfs
31590 + [AuWbrCreate_PMFSRR] = {
31591 + .create = au_wbr_create_pmfsrr,
31592 + .init = au_wbr_create_init_mfsrr,
31593 + .fin = au_wbr_create_fin_mfs
31595 + [AuWbrCreate_PMFSRRV] = {
31596 + .create = au_wbr_create_pmfsrr,
31597 + .init = au_wbr_create_init_mfsrr,
31598 + .fin = au_wbr_create_fin_mfs
31601 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
31602 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
31603 +++ linux/fs/aufs/whout.c 2015-01-25 13:00:38.634380408 +0100
31606 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31608 + * This program, aufs is free software; you can redistribute it and/or modify
31609 + * it under the terms of the GNU General Public License as published by
31610 + * the Free Software Foundation; either version 2 of the License, or
31611 + * (at your option) any later version.
31613 + * This program is distributed in the hope that it will be useful,
31614 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31615 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31616 + * GNU General Public License for more details.
31618 + * You should have received a copy of the GNU General Public License
31619 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31623 + * whiteout for logical deletion and opaque directory
31628 +#define WH_MASK S_IRUGO
31631 + * If a directory contains this file, then it is opaque. We start with the
31632 + * .wh. flag so that it is blocked by lookup.
31634 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
31635 + sizeof(AUFS_WH_DIROPQ) - 1);
31638 + * generate whiteout name, which is NOT terminated by NULL.
31639 + * @name: original d_name.name
31640 + * @len: original d_name.len
31641 + * @wh: whiteout qstr
31642 + * returns zero when succeeds, otherwise error.
31643 + * succeeded value as wh->name should be freed by kfree().
31645 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
31649 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
31650 + return -ENAMETOOLONG;
31652 + wh->len = name->len + AUFS_WH_PFX_LEN;
31653 + p = kmalloc(wh->len, GFP_NOFS);
31656 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31657 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
31664 +/* ---------------------------------------------------------------------- */
31667 + * test if the @wh_name exists under @h_parent.
31668 + * @try_sio specifies the necessary of super-io.
31670 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
31673 + struct dentry *wh_dentry;
31676 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
31678 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
31679 + err = PTR_ERR(wh_dentry);
31680 + if (IS_ERR(wh_dentry))
31684 + if (!wh_dentry->d_inode)
31685 + goto out_wh; /* success */
31688 + if (S_ISREG(wh_dentry->d_inode->i_mode))
31689 + goto out_wh; /* success */
31692 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
31693 + wh_dentry, wh_dentry->d_inode->i_mode);
31702 + * test if the @h_dentry sets opaque or not.
31704 +int au_diropq_test(struct dentry *h_dentry)
31707 + struct inode *h_dir;
31709 + h_dir = h_dentry->d_inode;
31710 + err = au_wh_test(h_dentry, &diropq_name,
31711 + au_test_h_perm_sio(h_dir, MAY_EXEC));
31716 + * returns a negative dentry whose name is unique and temporary.
31718 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31719 + struct qstr *prefix)
31721 + struct dentry *dentry;
31723 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
31725 + /* strict atomic_t is unnecessary here */
31726 + static unsigned short cnt;
31729 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
31732 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
31733 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
31734 + dentry = ERR_PTR(-ENAMETOOLONG);
31735 + if (unlikely(qs.len > NAME_MAX))
31737 + dentry = ERR_PTR(-ENOMEM);
31738 + name = kmalloc(qs.len + 1, GFP_NOFS);
31739 + if (unlikely(!name))
31743 + /* doubly whiteout-ed */
31744 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
31745 + p = name + AUFS_WH_PFX_LEN * 2;
31746 + memcpy(p, prefix->name, prefix->len);
31747 + p += prefix->len;
31749 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
31752 + for (i = 0; i < 3; i++) {
31753 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
31754 + dentry = au_sio_lkup_one(&qs, h_parent);
31755 + if (IS_ERR(dentry) || !dentry->d_inode)
31759 + /* pr_warn("could not get random name\n"); */
31760 + dentry = ERR_PTR(-EEXIST);
31761 + AuDbg("%.*s\n", AuLNPair(&qs));
31765 + if (name != defname)
31768 + AuTraceErrPtr(dentry);
31773 + * rename the @h_dentry on @br to the whiteouted temporary name.
31775 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
31778 + struct path h_path = {
31779 + .mnt = au_br_mnt(br)
31781 + struct inode *h_dir, *delegated;
31782 + struct dentry *h_parent;
31784 + h_parent = h_dentry->d_parent; /* dir inode is locked */
31785 + h_dir = h_parent->d_inode;
31786 + IMustLock(h_dir);
31788 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
31789 + err = PTR_ERR(h_path.dentry);
31790 + if (IS_ERR(h_path.dentry))
31793 + /* under the same dir, no need to lock_rename() */
31794 + delegated = NULL;
31795 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
31797 + if (unlikely(err == -EWOULDBLOCK)) {
31798 + pr_warn("cannot retry for NFSv4 delegation"
31799 + " for an internal rename\n");
31802 + dput(h_path.dentry);
31809 +/* ---------------------------------------------------------------------- */
31811 + * functions for removing a whiteout
31814 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
31817 + struct inode *delegated;
31820 + * forces superio when the dir has a sticky bit.
31821 + * this may be a violation of unix fs semantics.
31823 + force = (h_dir->i_mode & S_ISVTX)
31824 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
31825 + delegated = NULL;
31826 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
31827 + if (unlikely(err == -EWOULDBLOCK)) {
31828 + pr_warn("cannot retry for NFSv4 delegation"
31829 + " for an internal unlink\n");
31835 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
31836 + struct dentry *dentry)
31840 + err = do_unlink_wh(h_dir, h_path);
31841 + if (!err && dentry)
31842 + au_set_dbwh(dentry, -1);
31847 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
31848 + struct au_branch *br)
31851 + struct path h_path = {
31852 + .mnt = au_br_mnt(br)
31856 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
31857 + if (IS_ERR(h_path.dentry))
31858 + err = PTR_ERR(h_path.dentry);
31860 + if (h_path.dentry->d_inode
31861 + && S_ISREG(h_path.dentry->d_inode->i_mode))
31862 + err = do_unlink_wh(h_parent->d_inode, &h_path);
31863 + dput(h_path.dentry);
31869 +/* ---------------------------------------------------------------------- */
31871 + * initialize/clean whiteout for a branch
31874 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
31878 + struct inode *delegated;
31880 + if (!whpath->dentry->d_inode)
31884 + err = vfsub_rmdir(h_dir, whpath);
31886 + delegated = NULL;
31887 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
31888 + if (unlikely(err == -EWOULDBLOCK)) {
31889 + pr_warn("cannot retry for NFSv4 delegation"
31890 + " for an internal unlink\n");
31894 + if (unlikely(err))
31895 + pr_warn("failed removing %pd (%d), ignored.\n",
31896 + whpath->dentry, err);
31899 +static int test_linkable(struct dentry *h_root)
31901 + struct inode *h_dir = h_root->d_inode;
31903 + if (h_dir->i_op->link)
31906 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
31907 + h_root, au_sbtype(h_root->d_sb));
31911 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
31912 +static int au_whdir(struct inode *h_dir, struct path *path)
31917 + if (!path->dentry->d_inode) {
31918 + int mode = S_IRWXU;
31920 + if (au_test_nfs(path->dentry->d_sb))
31922 + err = vfsub_mkdir(h_dir, path, mode);
31923 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
31926 + pr_err("unknown %pd exists\n", path->dentry);
31931 +struct au_wh_base {
31932 + const struct qstr *name;
31933 + struct dentry *dentry;
31936 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
31937 + struct path *h_path)
31939 + h_path->dentry = base[AuBrWh_BASE].dentry;
31940 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31941 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31942 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31943 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31944 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31948 + * returns tri-state,
31949 + * minus: error, caller should print the message
31951 + * plus: error, caller should NOT print the message
31953 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
31954 + int do_plink, struct au_wh_base base[],
31955 + struct path *h_path)
31958 + struct inode *h_dir;
31960 + h_dir = h_root->d_inode;
31961 + h_path->dentry = base[AuBrWh_BASE].dentry;
31962 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31963 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31965 + err = test_linkable(h_root);
31966 + if (unlikely(err)) {
31971 + err = au_whdir(h_dir, h_path);
31972 + if (unlikely(err))
31974 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
31976 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31977 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31978 + err = au_whdir(h_dir, h_path);
31979 + if (unlikely(err))
31981 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
31988 + * for the moment, aufs supports the branch filesystem which does not support
31989 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
31990 + * copyup failed. finally, such filesystem will not be used as the writable
31993 + * returns tri-state, see above.
31995 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
31996 + int do_plink, struct au_wh_base base[],
31997 + struct path *h_path)
32000 + struct inode *h_dir;
32002 + WbrWhMustWriteLock(wbr);
32004 + err = test_linkable(h_root);
32005 + if (unlikely(err)) {
32011 + * todo: should this create be done in /sbin/mount.aufs helper?
32014 + h_dir = h_root->d_inode;
32015 + if (!base[AuBrWh_BASE].dentry->d_inode) {
32016 + h_path->dentry = base[AuBrWh_BASE].dentry;
32017 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32018 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
32021 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32022 + if (unlikely(err))
32025 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32027 + err = au_whdir(h_dir, h_path);
32028 + if (unlikely(err))
32030 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32032 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32033 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32035 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32036 + err = au_whdir(h_dir, h_path);
32037 + if (unlikely(err))
32039 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32046 + * initialize the whiteout base file/dir for @br.
32048 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32051 + const unsigned char do_plink
32052 + = !!au_opt_test(au_mntflags(sb), PLINK);
32053 + struct inode *h_dir;
32054 + struct path path = br->br_path;
32055 + struct dentry *h_root = path.dentry;
32056 + struct au_wbr *wbr = br->br_wbr;
32057 + static const struct qstr base_name[] = {
32058 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32059 + sizeof(AUFS_BASE_NAME) - 1),
32060 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32061 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32062 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32063 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32065 + struct au_wh_base base[] = {
32066 + [AuBrWh_BASE] = {
32067 + .name = base_name + AuBrWh_BASE,
32070 + [AuBrWh_PLINK] = {
32071 + .name = base_name + AuBrWh_PLINK,
32074 + [AuBrWh_ORPH] = {
32075 + .name = base_name + AuBrWh_ORPH,
32081 + WbrWhMustWriteLock(wbr);
32083 + for (i = 0; i < AuBrWh_Last; i++) {
32084 + /* doubly whiteouted */
32085 + struct dentry *d;
32087 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32088 + err = PTR_ERR(d);
32092 + base[i].dentry = d;
32094 + && wbr->wbr_wh[i]
32095 + && wbr->wbr_wh[i] != base[i].dentry);
32099 + for (i = 0; i < AuBrWh_Last; i++) {
32100 + dput(wbr->wbr_wh[i]);
32101 + wbr->wbr_wh[i] = NULL;
32105 + if (!au_br_writable(br->br_perm)) {
32106 + h_dir = h_root->d_inode;
32107 + au_wh_init_ro(h_dir, base, &path);
32108 + } else if (!au_br_wh_linkable(br->br_perm)) {
32109 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32115 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32121 + goto out; /* success */
32124 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32125 + err, h_root, au_sbtype(h_root->d_sb));
32127 + for (i = 0; i < AuBrWh_Last; i++)
32128 + dput(base[i].dentry);
32132 +/* ---------------------------------------------------------------------- */
32134 + * whiteouts are all hard-linked usually.
32135 + * when its link count reaches a ceiling, we create a new whiteout base
32136 + * asynchronously.
32139 +struct reinit_br_wh {
32140 + struct super_block *sb;
32141 + struct au_branch *br;
32144 +static void reinit_br_wh(void *arg)
32147 + aufs_bindex_t bindex;
32148 + struct path h_path;
32149 + struct reinit_br_wh *a = arg;
32150 + struct au_wbr *wbr;
32151 + struct inode *dir, *delegated;
32152 + struct dentry *h_root;
32153 + struct au_hinode *hdir;
32156 + wbr = a->br->br_wbr;
32157 + /* big aufs lock */
32158 + si_noflush_write_lock(a->sb);
32159 + if (!au_br_writable(a->br->br_perm))
32161 + bindex = au_br_index(a->sb, a->br->br_id);
32162 + if (unlikely(bindex < 0))
32165 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
32166 + dir = a->sb->s_root->d_inode;
32167 + hdir = au_hi(dir, bindex);
32168 + h_root = au_h_dptr(a->sb->s_root, bindex);
32169 + AuDebugOn(h_root != au_br_dentry(a->br));
32171 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32172 + wbr_wh_write_lock(wbr);
32173 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
32176 + h_path.dentry = wbr->wbr_whbase;
32177 + h_path.mnt = au_br_mnt(a->br);
32178 + delegated = NULL;
32179 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
32181 + if (unlikely(err == -EWOULDBLOCK)) {
32182 + pr_warn("cannot retry for NFSv4 delegation"
32183 + " for an internal unlink\n");
32187 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
32190 + dput(wbr->wbr_whbase);
32191 + wbr->wbr_whbase = NULL;
32193 + err = au_wh_init(a->br, a->sb);
32194 + wbr_wh_write_unlock(wbr);
32195 + au_hn_imtx_unlock(hdir);
32196 + di_read_unlock(a->sb->s_root, AuLock_IR);
32198 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
32202 + atomic_dec(&wbr->wbr_wh_running);
32203 + atomic_dec(&a->br->br_count);
32204 + si_write_unlock(a->sb);
32205 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32207 + if (unlikely(err))
32208 + AuIOErr("err %d\n", err);
32211 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32213 + int do_dec, wkq_err;
32214 + struct reinit_br_wh *arg;
32217 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32220 + /* ignore ENOMEM */
32221 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32224 + * dec(wh_running), kfree(arg) and dec(br_count)
32225 + * in reinit function
32229 + atomic_inc(&br->br_count);
32230 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32231 + if (unlikely(wkq_err)) {
32232 + atomic_dec(&br->br_wbr->wbr_wh_running);
32233 + atomic_dec(&br->br_count);
32241 + atomic_dec(&br->br_wbr->wbr_wh_running);
32244 +/* ---------------------------------------------------------------------- */
32247 + * create the whiteout @wh.
32249 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32250 + struct dentry *wh)
32253 + struct path h_path = {
32256 + struct au_branch *br;
32257 + struct au_wbr *wbr;
32258 + struct dentry *h_parent;
32259 + struct inode *h_dir, *delegated;
32261 + h_parent = wh->d_parent; /* dir inode is locked */
32262 + h_dir = h_parent->d_inode;
32263 + IMustLock(h_dir);
32265 + br = au_sbr(sb, bindex);
32266 + h_path.mnt = au_br_mnt(br);
32267 + wbr = br->br_wbr;
32268 + wbr_wh_read_lock(wbr);
32269 + if (wbr->wbr_whbase) {
32270 + delegated = NULL;
32271 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32272 + if (unlikely(err == -EWOULDBLOCK)) {
32273 + pr_warn("cannot retry for NFSv4 delegation"
32274 + " for an internal link\n");
32277 + if (!err || err != -EMLINK)
32280 + /* link count full. re-initialize br_whbase. */
32281 + kick_reinit_br_wh(sb, br);
32284 + /* return this error in this context */
32285 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32287 + au_fhsm_wrote(sb, bindex, /*force*/0);
32290 + wbr_wh_read_unlock(wbr);
32294 +/* ---------------------------------------------------------------------- */
32297 + * create or remove the diropq.
32299 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32300 + unsigned int flags)
32302 + struct dentry *opq_dentry, *h_dentry;
32303 + struct super_block *sb;
32304 + struct au_branch *br;
32307 + sb = dentry->d_sb;
32308 + br = au_sbr(sb, bindex);
32309 + h_dentry = au_h_dptr(dentry, bindex);
32310 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32311 + if (IS_ERR(opq_dentry))
32314 + if (au_ftest_diropq(flags, CREATE)) {
32315 + err = link_or_create_wh(sb, bindex, opq_dentry);
32317 + au_set_dbdiropq(dentry, bindex);
32318 + goto out; /* success */
32321 + struct path tmp = {
32322 + .dentry = opq_dentry,
32323 + .mnt = au_br_mnt(br)
32325 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
32327 + au_set_dbdiropq(dentry, -1);
32329 + dput(opq_dentry);
32330 + opq_dentry = ERR_PTR(err);
32333 + return opq_dentry;
32336 +struct do_diropq_args {
32337 + struct dentry **errp;
32338 + struct dentry *dentry;
32339 + aufs_bindex_t bindex;
32340 + unsigned int flags;
32343 +static void call_do_diropq(void *args)
32345 + struct do_diropq_args *a = args;
32346 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32349 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32350 + unsigned int flags)
32352 + struct dentry *diropq, *h_dentry;
32354 + h_dentry = au_h_dptr(dentry, bindex);
32355 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
32356 + diropq = do_diropq(dentry, bindex, flags);
32359 + struct do_diropq_args args = {
32361 + .dentry = dentry,
32362 + .bindex = bindex,
32366 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32367 + if (unlikely(wkq_err))
32368 + diropq = ERR_PTR(wkq_err);
32374 +/* ---------------------------------------------------------------------- */
32377 + * lookup whiteout dentry.
32378 + * @h_parent: lower parent dentry which must exist and be locked
32379 + * @base_name: name of dentry which will be whiteouted
32380 + * returns dentry for whiteout.
32382 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32383 + struct au_branch *br)
32386 + struct qstr wh_name;
32387 + struct dentry *wh_dentry;
32389 + err = au_wh_name_alloc(&wh_name, base_name);
32390 + wh_dentry = ERR_PTR(err);
32392 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32393 + kfree(wh_name.name);
32395 + return wh_dentry;
32399 + * link/create a whiteout for @dentry on @bindex.
32401 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32402 + struct dentry *h_parent)
32404 + struct dentry *wh_dentry;
32405 + struct super_block *sb;
32408 + sb = dentry->d_sb;
32409 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32410 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
32411 + err = link_or_create_wh(sb, bindex, wh_dentry);
32413 + au_set_dbwh(dentry, bindex);
32414 + au_fhsm_wrote(sb, bindex, /*force*/0);
32417 + wh_dentry = ERR_PTR(err);
32421 + return wh_dentry;
32424 +/* ---------------------------------------------------------------------- */
32426 +/* Delete all whiteouts in this directory on branch bindex. */
32427 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32428 + aufs_bindex_t bindex, struct au_branch *br)
32431 + unsigned long ul, n;
32432 + struct qstr wh_name;
32434 + struct hlist_head *head;
32435 + struct au_vdir_wh *pos;
32436 + struct au_vdir_destr *str;
32439 + p = (void *)__get_free_page(GFP_NOFS);
32440 + wh_name.name = p;
32441 + if (unlikely(!wh_name.name))
32445 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32446 + p += AUFS_WH_PFX_LEN;
32447 + n = whlist->nh_num;
32448 + head = whlist->nh_head;
32449 + for (ul = 0; !err && ul < n; ul++, head++) {
32450 + hlist_for_each_entry(pos, head, wh_hash) {
32451 + if (pos->wh_bindex != bindex)
32454 + str = &pos->wh_str;
32455 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32456 + memcpy(p, str->name, str->len);
32457 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32458 + err = unlink_wh_name(h_dentry, &wh_name, br);
32463 + AuIOErr("whiteout name too long %.*s\n",
32464 + str->len, str->name);
32469 + free_page((unsigned long)wh_name.name);
32475 +struct del_wh_children_args {
32477 + struct dentry *h_dentry;
32478 + struct au_nhash *whlist;
32479 + aufs_bindex_t bindex;
32480 + struct au_branch *br;
32483 +static void call_del_wh_children(void *args)
32485 + struct del_wh_children_args *a = args;
32486 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32489 +/* ---------------------------------------------------------------------- */
32491 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32493 + struct au_whtmp_rmdir *whtmp;
32495 + unsigned int rdhash;
32497 + SiMustAnyLock(sb);
32499 + whtmp = kmalloc(sizeof(*whtmp), gfp);
32500 + if (unlikely(!whtmp)) {
32501 + whtmp = ERR_PTR(-ENOMEM);
32505 + whtmp->dir = NULL;
32506 + whtmp->br = NULL;
32507 + whtmp->wh_dentry = NULL;
32508 + /* no estimation for dir size */
32509 + rdhash = au_sbi(sb)->si_rdhash;
32511 + rdhash = AUFS_RDHASH_DEF;
32512 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32513 + if (unlikely(err)) {
32515 + whtmp = ERR_PTR(err);
32522 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
32525 + atomic_dec(&whtmp->br->br_count);
32526 + dput(whtmp->wh_dentry);
32527 + iput(whtmp->dir);
32528 + au_nhash_wh_free(&whtmp->whlist);
32533 + * rmdir the whiteouted temporary named dir @h_dentry.
32534 + * @whlist: whiteouted children.
32536 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32537 + struct dentry *wh_dentry, struct au_nhash *whlist)
32540 + struct path h_tmp;
32541 + struct inode *wh_inode, *h_dir;
32542 + struct au_branch *br;
32544 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
32545 + IMustLock(h_dir);
32547 + br = au_sbr(dir->i_sb, bindex);
32548 + wh_inode = wh_dentry->d_inode;
32549 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
32552 + * someone else might change some whiteouts while we were sleeping.
32553 + * it means this whlist may have an obsoleted entry.
32555 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
32556 + err = del_wh_children(wh_dentry, whlist, bindex, br);
32559 + struct del_wh_children_args args = {
32561 + .h_dentry = wh_dentry,
32562 + .whlist = whlist,
32563 + .bindex = bindex,
32567 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
32568 + if (unlikely(wkq_err))
32571 + mutex_unlock(&wh_inode->i_mutex);
32574 + h_tmp.dentry = wh_dentry;
32575 + h_tmp.mnt = au_br_mnt(br);
32576 + err = vfsub_rmdir(h_dir, &h_tmp);
32580 + if (au_ibstart(dir) == bindex) {
32581 + /* todo: dir->i_mutex is necessary */
32582 + au_cpup_attr_timesizes(dir);
32583 + vfsub_drop_nlink(dir);
32585 + return 0; /* success */
32588 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
32592 +static void call_rmdir_whtmp(void *args)
32595 + aufs_bindex_t bindex;
32596 + struct au_whtmp_rmdir *a = args;
32597 + struct super_block *sb;
32598 + struct dentry *h_parent;
32599 + struct inode *h_dir;
32600 + struct au_hinode *hdir;
32602 + /* rmdir by nfsd may cause deadlock with this i_mutex */
32603 + /* mutex_lock(&a->dir->i_mutex); */
32605 + sb = a->dir->i_sb;
32606 + si_read_lock(sb, !AuLock_FLUSH);
32607 + if (!au_br_writable(a->br->br_perm))
32609 + bindex = au_br_index(sb, a->br->br_id);
32610 + if (unlikely(bindex < 0))
32614 + ii_write_lock_parent(a->dir);
32615 + h_parent = dget_parent(a->wh_dentry);
32616 + h_dir = h_parent->d_inode;
32617 + hdir = au_hi(a->dir, bindex);
32618 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
32619 + if (unlikely(err))
32621 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32622 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
32625 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
32626 + au_hn_imtx_unlock(hdir);
32627 + vfsub_mnt_drop_write(au_br_mnt(a->br));
32631 + ii_write_unlock(a->dir);
32633 + /* mutex_unlock(&a->dir->i_mutex); */
32634 + au_whtmp_rmdir_free(a);
32635 + si_read_unlock(sb);
32636 + au_nwt_done(&au_sbi(sb)->si_nowait);
32637 + if (unlikely(err))
32638 + AuIOErr("err %d\n", err);
32641 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32642 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
32645 + struct super_block *sb;
32649 + /* all post-process will be done in do_rmdir_whtmp(). */
32651 + args->dir = au_igrab(dir);
32652 + args->br = au_sbr(sb, bindex);
32653 + atomic_inc(&args->br->br_count);
32654 + args->wh_dentry = dget(wh_dentry);
32655 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
32656 + if (unlikely(wkq_err)) {
32657 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
32658 + au_whtmp_rmdir_free(args);
32661 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
32662 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
32663 +++ linux/fs/aufs/whout.h 2015-01-25 13:00:38.634380408 +0100
32666 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32668 + * This program, aufs is free software; you can redistribute it and/or modify
32669 + * it under the terms of the GNU General Public License as published by
32670 + * the Free Software Foundation; either version 2 of the License, or
32671 + * (at your option) any later version.
32673 + * This program is distributed in the hope that it will be useful,
32674 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32676 + * GNU General Public License for more details.
32678 + * You should have received a copy of the GNU General Public License
32679 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32683 + * whiteout for logical deletion and opaque directory
32686 +#ifndef __AUFS_WHOUT_H__
32687 +#define __AUFS_WHOUT_H__
32694 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
32696 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
32697 +int au_diropq_test(struct dentry *h_dentry);
32698 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32699 + struct qstr *prefix);
32700 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
32701 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32702 + struct dentry *dentry);
32703 +int au_wh_init(struct au_branch *br, struct super_block *sb);
32705 +/* diropq flags */
32706 +#define AuDiropq_CREATE 1
32707 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
32708 +#define au_fset_diropq(flags, name) \
32709 + do { (flags) |= AuDiropq_##name; } while (0)
32710 +#define au_fclr_diropq(flags, name) \
32711 + do { (flags) &= ~AuDiropq_##name; } while (0)
32713 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32714 + unsigned int flags);
32715 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32716 + struct au_branch *br);
32717 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32718 + struct dentry *h_parent);
32720 +/* real rmdir for the whiteout-ed dir */
32721 +struct au_whtmp_rmdir {
32722 + struct inode *dir;
32723 + struct au_branch *br;
32724 + struct dentry *wh_dentry;
32725 + struct au_nhash whlist;
32728 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
32729 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
32730 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32731 + struct dentry *wh_dentry, struct au_nhash *whlist);
32732 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32733 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
32735 +/* ---------------------------------------------------------------------- */
32737 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
32738 + aufs_bindex_t bindex)
32740 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
32743 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
32745 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
32748 +#endif /* __KERNEL__ */
32749 +#endif /* __AUFS_WHOUT_H__ */
32750 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
32751 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
32752 +++ linux/fs/aufs/wkq.c 2015-01-25 13:00:38.634380408 +0100
32755 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32757 + * This program, aufs is free software; you can redistribute it and/or modify
32758 + * it under the terms of the GNU General Public License as published by
32759 + * the Free Software Foundation; either version 2 of the License, or
32760 + * (at your option) any later version.
32762 + * This program is distributed in the hope that it will be useful,
32763 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32764 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32765 + * GNU General Public License for more details.
32767 + * You should have received a copy of the GNU General Public License
32768 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32772 + * workqueue for asynchronous/super-io operations
32773 + * todo: try new dredential scheme
32776 +#include <linux/module.h>
32779 +/* internal workqueue named AUFS_WKQ_NAME */
32781 +static struct workqueue_struct *au_wkq;
32783 +struct au_wkinfo {
32784 + struct work_struct wk;
32785 + struct kobject *kobj;
32787 + unsigned int flags; /* see wkq.h */
32789 + au_wkq_func_t func;
32792 + struct completion *comp;
32795 +/* ---------------------------------------------------------------------- */
32797 +static void wkq_func(struct work_struct *wk)
32799 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
32801 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
32802 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
32804 + wkinfo->func(wkinfo->args);
32805 + if (au_ftest_wkq(wkinfo->flags, WAIT))
32806 + complete(wkinfo->comp);
32808 + kobject_put(wkinfo->kobj);
32809 + module_put(THIS_MODULE); /* todo: ?? */
32815 + * Since struct completion is large, try allocating it dynamically.
32817 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
32818 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
32820 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32822 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
32824 + init_completion(*comp);
32825 + wkinfo->comp = *comp;
32831 +static void au_wkq_comp_free(struct completion *comp)
32839 +#define AuWkqCompDeclare(name) \
32840 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
32841 + struct completion *comp = &_ ## name
32843 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32845 + wkinfo->comp = *comp;
32849 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
32853 +#endif /* 4KSTACKS */
32855 +static void au_wkq_run(struct au_wkinfo *wkinfo)
32857 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
32858 + if (au_wkq_test()) {
32859 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
32860 + " due to a dead dir by UDBA?\n");
32861 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
32864 + au_dbg_verify_kthread();
32866 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
32867 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
32868 + queue_work(au_wkq, &wkinfo->wk);
32870 + INIT_WORK(&wkinfo->wk, wkq_func);
32871 + schedule_work(&wkinfo->wk);
32876 + * Be careful. It is easy to make deadlock happen.
32877 + * processA: lock, wkq and wait
32878 + * processB: wkq and wait, lock in wkq
32881 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
32884 + AuWkqCompDeclare(comp);
32885 + struct au_wkinfo wkinfo = {
32891 + err = au_wkq_comp_alloc(&wkinfo, &comp);
32893 + au_wkq_run(&wkinfo);
32894 + /* no timeout, no interrupt */
32895 + wait_for_completion(wkinfo.comp);
32896 + au_wkq_comp_free(comp);
32897 + destroy_work_on_stack(&wkinfo.wk);
32905 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
32906 + * problem in a concurrent umounting.
32908 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
32909 + unsigned int flags)
32912 + struct au_wkinfo *wkinfo;
32914 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
32917 + * wkq_func() must free this wkinfo.
32918 + * it highly depends upon the implementation of workqueue.
32921 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
32923 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
32924 + wkinfo->flags = flags & ~AuWkq_WAIT;
32925 + wkinfo->func = func;
32926 + wkinfo->args = args;
32927 + wkinfo->comp = NULL;
32928 + kobject_get(wkinfo->kobj);
32929 + __module_get(THIS_MODULE); /* todo: ?? */
32931 + au_wkq_run(wkinfo);
32934 + au_nwt_done(&au_sbi(sb)->si_nowait);
32940 +/* ---------------------------------------------------------------------- */
32942 +void au_nwt_init(struct au_nowait_tasks *nwt)
32944 + atomic_set(&nwt->nw_len, 0);
32945 + /* smp_mb(); */ /* atomic_set */
32946 + init_waitqueue_head(&nwt->nw_wq);
32949 +void au_wkq_fin(void)
32951 + destroy_workqueue(au_wkq);
32954 +int __init au_wkq_init(void)
32959 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
32960 + if (IS_ERR(au_wkq))
32961 + err = PTR_ERR(au_wkq);
32962 + else if (!au_wkq)
32967 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
32968 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
32969 +++ linux/fs/aufs/wkq.h 2015-01-25 13:00:38.634380408 +0100
32972 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32974 + * This program, aufs is free software; you can redistribute it and/or modify
32975 + * it under the terms of the GNU General Public License as published by
32976 + * the Free Software Foundation; either version 2 of the License, or
32977 + * (at your option) any later version.
32979 + * This program is distributed in the hope that it will be useful,
32980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32982 + * GNU General Public License for more details.
32984 + * You should have received a copy of the GNU General Public License
32985 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32989 + * workqueue for asynchronous/super-io operations
32990 + * todo: try new credentials management scheme
32993 +#ifndef __AUFS_WKQ_H__
32994 +#define __AUFS_WKQ_H__
32998 +struct super_block;
33000 +/* ---------------------------------------------------------------------- */
33003 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
33005 +struct au_nowait_tasks {
33007 + wait_queue_head_t nw_wq;
33010 +/* ---------------------------------------------------------------------- */
33012 +typedef void (*au_wkq_func_t)(void *args);
33015 +#define AuWkq_WAIT 1
33016 +#define AuWkq_NEST (1 << 1)
33017 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33018 +#define au_fset_wkq(flags, name) \
33019 + do { (flags) |= AuWkq_##name; } while (0)
33020 +#define au_fclr_wkq(flags, name) \
33021 + do { (flags) &= ~AuWkq_##name; } while (0)
33023 +#ifndef CONFIG_AUFS_HNOTIFY
33025 +#define AuWkq_NEST 0
33029 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33030 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33031 + unsigned int flags);
33032 +void au_nwt_init(struct au_nowait_tasks *nwt);
33033 +int __init au_wkq_init(void);
33034 +void au_wkq_fin(void);
33036 +/* ---------------------------------------------------------------------- */
33038 +static inline int au_wkq_test(void)
33040 + return current->flags & PF_WQ_WORKER;
33043 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33045 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33048 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33050 + if (atomic_dec_and_test(&nwt->nw_len))
33051 + wake_up_all(&nwt->nw_wq);
33054 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33056 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
33060 +#endif /* __KERNEL__ */
33061 +#endif /* __AUFS_WKQ_H__ */
33062 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33063 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33064 +++ linux/fs/aufs/xattr.c 2015-01-25 13:00:38.634380408 +0100
33067 + * Copyright (C) 2014 Junjiro R. Okajima
33069 + * This program, aufs is free software; you can redistribute it and/or modify
33070 + * it under the terms of the GNU General Public License as published by
33071 + * the Free Software Foundation; either version 2 of the License, or
33072 + * (at your option) any later version.
33074 + * This program is distributed in the hope that it will be useful,
33075 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33076 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33077 + * GNU General Public License for more details.
33079 + * You should have received a copy of the GNU General Public License
33080 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33084 + * handling xattr functions
33087 +#include <linux/xattr.h>
33090 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33092 + if (!ignore_flags)
33100 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33105 +#define cmp(brattr, prefix) do { \
33106 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33107 + XATTR_##prefix##_PREFIX_LEN)) { \
33108 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33114 + cmp(SEC, SECURITY);
33115 + cmp(SYS, SYSTEM);
33116 + cmp(TR, TRUSTED);
33120 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33127 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
33129 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
33130 + char *name, char **buf, unsigned int ignore_flags)
33134 + struct inode *h_idst;
33136 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
33138 + if (unlikely(err <= 0)) {
33140 + if (err == -ENODATA
33141 + || (err == -EOPNOTSUPP
33142 + && (ignore_flags & au_xattr_out_of_list)))
33147 + /* unlock it temporary */
33148 + h_idst = h_dst->d_inode;
33149 + mutex_unlock(&h_idst->i_mutex);
33150 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
33151 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33152 + if (unlikely(err)) {
33153 + AuDbg("%s, err %d\n", name, err);
33154 + err = au_xattr_ignore(err, name, ignore_flags);
33161 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags)
33163 + int err, unlocked, acl_access, acl_default;
33165 + struct inode *h_isrc, *h_idst;
33166 + char *value, *p, *o, *e;
33168 + /* try stopping to update the source inode while we are referencing */
33169 + /* there should not be the parent-child relation ship between them */
33170 + h_isrc = h_src->d_inode;
33171 + h_idst = h_dst->d_inode;
33172 + mutex_unlock(&h_idst->i_mutex);
33173 + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
33174 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33177 + /* some filesystems don't list POSIX ACL, for example tmpfs */
33178 + ssz = vfs_listxattr(h_src, NULL, 0);
33180 + if (unlikely(err < 0)) {
33182 + if (err == -ENODATA
33183 + || err == -EOPNOTSUPP)
33184 + err = 0; /* ignore */
33193 + p = kmalloc(ssz, GFP_NOFS);
33195 + if (unlikely(!p))
33197 + err = vfs_listxattr(h_src, p, ssz);
33199 + mutex_unlock(&h_isrc->i_mutex);
33201 + AuDbg("err %d, ssz %zd\n", err, ssz);
33202 + if (unlikely(err < 0))
33210 + while (!err && p < e) {
33211 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33212 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33213 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33214 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33216 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags);
33217 + p += strlen(p) + 1;
33220 + ignore_flags |= au_xattr_out_of_list;
33221 + if (!err && !acl_access) {
33222 + err = au_do_cpup_xattr(h_dst, h_src,
33223 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33227 + if (!err && !acl_default) {
33228 + err = au_do_cpup_xattr(h_dst, h_src,
33229 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33240 + mutex_unlock(&h_isrc->i_mutex);
33245 +/* ---------------------------------------------------------------------- */
33252 +struct au_lgxattr {
33260 + const char *name;
33267 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33270 + struct path h_path;
33271 + struct super_block *sb;
33273 + sb = dentry->d_sb;
33274 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33275 + if (unlikely(err))
33277 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33278 + if (unlikely(err))
33280 + if (unlikely(!h_path.dentry))
33281 + /* illegally overlapped or something */
33282 + goto out_di; /* pretending success */
33284 + /* always topmost entry only */
33285 + switch (arg->type) {
33286 + case AU_XATTR_LIST:
33287 + err = vfs_listxattr(h_path.dentry,
33288 + arg->u.list.list, arg->u.list.size);
33290 + case AU_XATTR_GET:
33291 + err = vfs_getxattr(h_path.dentry,
33292 + arg->u.get.name, arg->u.get.value,
33293 + arg->u.get.size);
33298 + di_read_unlock(dentry, AuLock_IR);
33300 + si_read_unlock(sb);
33306 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33308 + struct au_lgxattr arg = {
33309 + .type = AU_XATTR_LIST,
33316 + return au_lgxattr(dentry, &arg);
33319 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
33322 + struct au_lgxattr arg = {
33323 + .type = AU_XATTR_GET,
33331 + return au_lgxattr(dentry, &arg);
33334 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33335 + size_t size, int flags)
33337 + struct au_srxattr arg = {
33338 + .type = AU_XATTR_SET,
33347 + return au_srxattr(dentry, &arg);
33350 +int aufs_removexattr(struct dentry *dentry, const char *name)
33352 + struct au_srxattr arg = {
33353 + .type = AU_XATTR_REMOVE,
33359 + return au_srxattr(dentry, &arg);
33362 +/* ---------------------------------------------------------------------- */
33365 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33366 + const char *name, size_t name_len, int type)
33368 + return aufs_listxattr(dentry, list, list_size);
33371 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33372 + size_t size, int type)
33374 + return aufs_getxattr(dentry, name, buffer, size);
33377 +static int au_xattr_set(struct dentry *dentry, const char *name,
33378 + const void *value, size_t size, int flags, int type)
33380 + return aufs_setxattr(dentry, name, value, size, flags);
33383 +static const struct xattr_handler au_xattr_handler = {
33384 + /* no prefix, no flags */
33385 + .list = au_xattr_list,
33386 + .get = au_xattr_get,
33387 + .set = au_xattr_set
33388 + /* why no remove? */
33391 +static const struct xattr_handler *au_xattr_handlers[] = {
33392 + &au_xattr_handler
33395 +void au_xattr_init(struct super_block *sb)
33397 + /* sb->s_xattr = au_xattr_handlers; */
33400 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33401 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33402 +++ linux/fs/aufs/xino.c 2015-01-25 13:00:38.634380408 +0100
33405 + * Copyright (C) 2005-2014 Junjiro R. Okajima
33407 + * This program, aufs is free software; you can redistribute it and/or modify
33408 + * it under the terms of the GNU General Public License as published by
33409 + * the Free Software Foundation; either version 2 of the License, or
33410 + * (at your option) any later version.
33412 + * This program is distributed in the hope that it will be useful,
33413 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33414 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33415 + * GNU General Public License for more details.
33417 + * You should have received a copy of the GNU General Public License
33418 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33422 + * external inode number translation table and bitmap
33425 +#include <linux/seq_file.h>
33426 +#include <linux/statfs.h>
33429 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33430 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
33434 + mm_segment_t oldfs;
33441 + oldfs = get_fs();
33442 + set_fs(KERNEL_DS);
33444 + /* todo: signal_pending? */
33445 + err = func(file, buf.u, size, pos);
33446 + } while (err == -EAGAIN || err == -EINTR);
33449 +#if 0 /* reserved for future use */
33451 + fsnotify_access(file->f_dentry);
33457 +/* ---------------------------------------------------------------------- */
33459 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
33460 + size_t size, loff_t *pos)
33463 + mm_segment_t oldfs;
33466 + const char __user *u;
33470 + oldfs = get_fs();
33471 + set_fs(KERNEL_DS);
33473 + /* todo: signal_pending? */
33474 + err = func(file, buf.u, size, pos);
33475 + } while (err == -EAGAIN || err == -EINTR);
33478 +#if 0 /* reserved for future use */
33480 + fsnotify_modify(file->f_dentry);
33486 +struct do_xino_fwrite_args {
33488 + au_writef_t func;
33489 + struct file *file;
33495 +static void call_do_xino_fwrite(void *args)
33497 + struct do_xino_fwrite_args *a = args;
33498 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
33501 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
33506 + /* todo: signal block and no wkq? */
33507 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
33509 + err = do_xino_fwrite(func, file, buf, size, pos);
33513 + * it breaks RLIMIT_FSIZE and normal user's limit,
33514 + * users should care about quota and real 'filesystem full.'
33517 + struct do_xino_fwrite_args args = {
33526 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
33527 + if (unlikely(wkq_err))
33534 +/* ---------------------------------------------------------------------- */
33537 + * create a new xinofile at the same place/path as @base_file.
33539 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
33541 + struct file *file;
33542 + struct dentry *base, *parent;
33543 + struct inode *dir, *delegated;
33544 + struct qstr *name;
33545 + struct path path;
33548 + base = base_file->f_dentry;
33549 + parent = base->d_parent; /* dir inode is locked */
33550 + dir = parent->d_inode;
33553 + file = ERR_PTR(-EINVAL);
33554 + name = &base->d_name;
33555 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
33556 + if (IS_ERR(path.dentry)) {
33557 + file = (void *)path.dentry;
33558 + pr_err("%pd lookup err %ld\n",
33559 + base, PTR_ERR(path.dentry));
33563 + /* no need to mnt_want_write() since we call dentry_open() later */
33564 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
33565 + if (unlikely(err)) {
33566 + file = ERR_PTR(err);
33567 + pr_err("%pd create err %d\n", base, err);
33571 + path.mnt = base_file->f_path.mnt;
33572 + file = vfsub_dentry_open(&path,
33573 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33574 + /* | __FMODE_NONOTIFY */);
33575 + if (IS_ERR(file)) {
33576 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
33580 + delegated = NULL;
33581 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
33582 + if (unlikely(err == -EWOULDBLOCK)) {
33583 + pr_warn("cannot retry for NFSv4 delegation"
33584 + " for an internal unlink\n");
33587 + if (unlikely(err)) {
33588 + pr_err("%pd unlink err %d\n", base, err);
33593 + /* no one can touch copy_src xino */
33594 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
33595 + if (unlikely(err)) {
33596 + pr_err("%pd copy err %d\n", base, err);
33600 + goto out_dput; /* success */
33604 + file = ERR_PTR(err);
33606 + dput(path.dentry);
33611 +struct au_xino_lock_dir {
33612 + struct au_hinode *hdir;
33613 + struct dentry *parent;
33614 + struct mutex *mtx;
33617 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
33618 + struct au_xino_lock_dir *ldir)
33620 + aufs_bindex_t brid, bindex;
33622 + ldir->hdir = NULL;
33624 + brid = au_xino_brid(sb);
33626 + bindex = au_br_index(sb, brid);
33627 + if (bindex >= 0) {
33628 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
33629 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
33631 + ldir->parent = dget_parent(xino->f_dentry);
33632 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
33633 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
33637 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
33640 + au_hn_imtx_unlock(ldir->hdir);
33642 + mutex_unlock(ldir->mtx);
33643 + dput(ldir->parent);
33647 +/* ---------------------------------------------------------------------- */
33649 +/* trucate xino files asynchronously */
33651 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
33654 + unsigned long jiffy;
33656 + aufs_bindex_t bi, bend;
33657 + struct kstatfs *st;
33658 + struct au_branch *br;
33659 + struct file *new_xino, *file;
33660 + struct super_block *h_sb;
33661 + struct au_xino_lock_dir ldir;
33664 + st = kzalloc(sizeof(*st), GFP_NOFS);
33665 + if (unlikely(!st))
33669 + bend = au_sbend(sb);
33670 + if (unlikely(bindex < 0 || bend < bindex))
33672 + br = au_sbr(sb, bindex);
33673 + file = br->br_xino.xi_file;
33677 + err = vfs_statfs(&file->f_path, st);
33678 + if (unlikely(err))
33679 + AuErr1("statfs err %d, ignored\n", err);
33681 + blocks = file_inode(file)->i_blocks;
33682 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33683 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
33685 + au_xino_lock_dir(sb, file, &ldir);
33686 + /* mnt_want_write() is unnecessary here */
33687 + new_xino = au_xino_create2(file, file);
33688 + au_xino_unlock_dir(&ldir);
33689 + err = PTR_ERR(new_xino);
33690 + if (IS_ERR(new_xino)) {
33691 + pr_err("err %d, ignored\n", err);
33696 + br->br_xino.xi_file = new_xino;
33698 + h_sb = au_br_sb(br);
33699 + for (bi = 0; bi <= bend; bi++) {
33700 + if (unlikely(bi == bindex))
33702 + br = au_sbr(sb, bi);
33703 + if (au_br_sb(br) != h_sb)
33706 + fput(br->br_xino.xi_file);
33707 + br->br_xino.xi_file = new_xino;
33708 + get_file(new_xino);
33711 + err = vfs_statfs(&new_xino->f_path, st);
33713 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33714 + bindex, (u64)file_inode(new_xino)->i_blocks,
33715 + st->f_bfree, st->f_blocks);
33716 + if (file_inode(new_xino)->i_blocks < blocks)
33717 + au_sbi(sb)->si_xino_jiffy = jiffy;
33719 + AuErr1("statfs err %d, ignored\n", err);
33727 +struct xino_do_trunc_args {
33728 + struct super_block *sb;
33729 + struct au_branch *br;
33732 +static void xino_do_trunc(void *_args)
33734 + struct xino_do_trunc_args *args = _args;
33735 + struct super_block *sb;
33736 + struct au_branch *br;
33737 + struct inode *dir;
33739 + aufs_bindex_t bindex;
33743 + dir = sb->s_root->d_inode;
33746 + si_noflush_write_lock(sb);
33747 + ii_read_lock_parent(dir);
33748 + bindex = au_br_index(sb, br->br_id);
33749 + err = au_xino_trunc(sb, bindex);
33750 + ii_read_unlock(dir);
33751 + if (unlikely(err))
33752 + pr_warn("err b%d, (%d)\n", bindex, err);
33753 + atomic_dec(&br->br_xino_running);
33754 + atomic_dec(&br->br_count);
33755 + si_write_unlock(sb);
33756 + au_nwt_done(&au_sbi(sb)->si_nowait);
33760 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
33763 + struct kstatfs st;
33764 + struct au_sbinfo *sbinfo;
33766 + /* todo: si_xino_expire and the ratio should be customizable */
33767 + sbinfo = au_sbi(sb);
33768 + if (time_before(jiffies,
33769 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
33772 + /* truncation border */
33773 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
33774 + if (unlikely(err)) {
33775 + AuErr1("statfs err %d, ignored\n", err);
33778 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
33784 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
33786 + struct xino_do_trunc_args *args;
33789 + if (!xino_trunc_test(sb, br))
33792 + if (atomic_inc_return(&br->br_xino_running) > 1)
33795 + /* lock and kfree() will be called in trunc_xino() */
33796 + args = kmalloc(sizeof(*args), GFP_NOFS);
33797 + if (unlikely(!args)) {
33798 + AuErr1("no memory\n");
33802 + atomic_inc(&br->br_count);
33805 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
33807 + return; /* success */
33809 + pr_err("wkq %d\n", wkq_err);
33810 + atomic_dec(&br->br_count);
33815 + atomic_dec(&br->br_xino_running);
33818 +/* ---------------------------------------------------------------------- */
33820 +static int au_xino_do_write(au_writef_t write, struct file *file,
33821 + ino_t h_ino, ino_t ino)
33827 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
33828 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
33831 + pos *= sizeof(ino);
33832 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
33833 + if (sz == sizeof(ino))
33834 + return 0; /* success */
33836 + AuIOErr("write failed (%zd)\n", sz);
33841 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
33842 + * at the position of @h_ino.
33843 + * even if @ino is zero, it is written to the xinofile and means no entry.
33844 + * if the size of the xino file on a specific filesystem exceeds the watermark,
33845 + * try truncating it.
33847 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
33851 + unsigned int mnt_flags;
33852 + struct au_branch *br;
33854 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
33855 + || ((loff_t)-1) > 0);
33856 + SiMustAnyLock(sb);
33858 + mnt_flags = au_mntflags(sb);
33859 + if (!au_opt_test(mnt_flags, XINO))
33862 + br = au_sbr(sb, bindex);
33863 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
33866 + if (au_opt_test(mnt_flags, TRUNC_XINO)
33867 + && au_test_fs_trunc_xino(au_br_sb(br)))
33868 + xino_try_trunc(sb, br);
33869 + return 0; /* success */
33872 + AuIOErr("write failed (%d)\n", err);
33876 +/* ---------------------------------------------------------------------- */
33878 +/* aufs inode number bitmap */
33880 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
33881 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
33885 + AuDebugOn(bit < 0 || page_bits <= bit);
33886 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
33890 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
33892 + AuDebugOn(ino < AUFS_FIRST_INO);
33893 + ino -= AUFS_FIRST_INO;
33894 + *pindex = ino / page_bits;
33895 + *bit = ino % page_bits;
33898 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
33903 + struct au_sbinfo *sbinfo;
33904 + struct file *xib;
33905 + unsigned long *p;
33907 + sbinfo = au_sbi(sb);
33908 + MtxMustLock(&sbinfo->si_xib_mtx);
33909 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
33910 + || !au_opt_test(sbinfo->si_mntflags, XINO));
33912 + if (pindex == sbinfo->si_xib_last_pindex)
33915 + xib = sbinfo->si_xib;
33916 + p = sbinfo->si_xib_buf;
33917 + pos = sbinfo->si_xib_last_pindex;
33918 + pos *= PAGE_SIZE;
33919 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
33920 + if (unlikely(sz != PAGE_SIZE))
33924 + pos *= PAGE_SIZE;
33925 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
33926 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
33928 + memset(p, 0, PAGE_SIZE);
33929 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
33931 + if (sz == PAGE_SIZE) {
33932 + sbinfo->si_xib_last_pindex = pindex;
33933 + return 0; /* success */
33937 + AuIOErr1("write failed (%zd)\n", sz);
33944 +/* ---------------------------------------------------------------------- */
33946 +static void au_xib_clear_bit(struct inode *inode)
33949 + unsigned long pindex;
33950 + struct super_block *sb;
33951 + struct au_sbinfo *sbinfo;
33953 + AuDebugOn(inode->i_nlink);
33955 + sb = inode->i_sb;
33956 + xib_calc_bit(inode->i_ino, &pindex, &bit);
33957 + AuDebugOn(page_bits <= bit);
33958 + sbinfo = au_sbi(sb);
33959 + mutex_lock(&sbinfo->si_xib_mtx);
33960 + err = xib_pindex(sb, pindex);
33962 + clear_bit(bit, sbinfo->si_xib_buf);
33963 + sbinfo->si_xib_next_bit = bit;
33965 + mutex_unlock(&sbinfo->si_xib_mtx);
33968 +/* for s_op->delete_inode() */
33969 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
33972 + unsigned int mnt_flags;
33973 + aufs_bindex_t bindex, bend, bi;
33974 + unsigned char try_trunc;
33975 + struct au_iinfo *iinfo;
33976 + struct super_block *sb;
33977 + struct au_hinode *hi;
33978 + struct inode *h_inode;
33979 + struct au_branch *br;
33980 + au_writef_t xwrite;
33982 + sb = inode->i_sb;
33983 + mnt_flags = au_mntflags(sb);
33984 + if (!au_opt_test(mnt_flags, XINO)
33985 + || inode->i_ino == AUFS_ROOT_INO)
33989 + au_xigen_inc(inode);
33990 + au_xib_clear_bit(inode);
33993 + iinfo = au_ii(inode);
33997 + bindex = iinfo->ii_bstart;
34001 + xwrite = au_sbi(sb)->si_xwrite;
34002 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
34003 + hi = iinfo->ii_hinode + bindex;
34004 + bend = iinfo->ii_bend;
34005 + for (; bindex <= bend; bindex++, hi++) {
34006 + h_inode = hi->hi_inode;
34008 + || (!unlinked && h_inode->i_nlink))
34011 + /* inode may not be revalidated */
34012 + bi = au_br_index(sb, hi->hi_id);
34016 + br = au_sbr(sb, bi);
34017 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34018 + h_inode->i_ino, /*ino*/0);
34019 + if (!err && try_trunc
34020 + && au_test_fs_trunc_xino(au_br_sb(br)))
34021 + xino_try_trunc(sb, br);
34025 +/* get an unused inode number from bitmap */
34026 +ino_t au_xino_new_ino(struct super_block *sb)
34029 + unsigned long *p, pindex, ul, pend;
34030 + struct au_sbinfo *sbinfo;
34031 + struct file *file;
34032 + int free_bit, err;
34034 + if (!au_opt_test(au_mntflags(sb), XINO))
34035 + return iunique(sb, AUFS_FIRST_INO);
34037 + sbinfo = au_sbi(sb);
34038 + mutex_lock(&sbinfo->si_xib_mtx);
34039 + p = sbinfo->si_xib_buf;
34040 + free_bit = sbinfo->si_xib_next_bit;
34041 + if (free_bit < page_bits && !test_bit(free_bit, p))
34042 + goto out; /* success */
34043 + free_bit = find_first_zero_bit(p, page_bits);
34044 + if (free_bit < page_bits)
34045 + goto out; /* success */
34047 + pindex = sbinfo->si_xib_last_pindex;
34048 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34049 + err = xib_pindex(sb, ul);
34050 + if (unlikely(err))
34052 + free_bit = find_first_zero_bit(p, page_bits);
34053 + if (free_bit < page_bits)
34054 + goto out; /* success */
34057 + file = sbinfo->si_xib;
34058 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34059 + for (ul = pindex + 1; ul <= pend; ul++) {
34060 + err = xib_pindex(sb, ul);
34061 + if (unlikely(err))
34063 + free_bit = find_first_zero_bit(p, page_bits);
34064 + if (free_bit < page_bits)
34065 + goto out; /* success */
34070 + set_bit(free_bit, p);
34071 + sbinfo->si_xib_next_bit = free_bit + 1;
34072 + pindex = sbinfo->si_xib_last_pindex;
34073 + mutex_unlock(&sbinfo->si_xib_mtx);
34074 + ino = xib_calc_ino(pindex, free_bit);
34075 + AuDbg("i%lu\n", (unsigned long)ino);
34078 + mutex_unlock(&sbinfo->si_xib_mtx);
34084 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34085 + * at the position of @h_ino.
34086 + * if @ino does not exist and @do_new is true, get new one.
34088 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34094 + struct file *file;
34095 + struct au_sbinfo *sbinfo;
34098 + if (!au_opt_test(au_mntflags(sb), XINO))
34099 + return 0; /* no xino */
34102 + sbinfo = au_sbi(sb);
34104 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
34105 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34108 + pos *= sizeof(*ino);
34110 + file = au_sbr(sb, bindex)->br_xino.xi_file;
34111 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
34112 + return 0; /* no ino */
34114 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
34115 + if (sz == sizeof(*ino))
34116 + return 0; /* success */
34119 + if (unlikely(sz >= 0)) {
34121 + AuIOErr("xino read error (%zd)\n", sz);
34127 +/* ---------------------------------------------------------------------- */
34129 +/* create and set a new xino file */
34131 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
34133 + struct file *file;
34134 + struct dentry *h_parent, *d;
34135 + struct inode *h_dir;
34139 + * at mount-time, and the xino file is the default path,
34140 + * hnotify is disabled so we have no notify events to ignore.
34141 + * when a user specified the xino, we cannot get au_hdir to be ignored.
34143 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34144 + /* | __FMODE_NONOTIFY */,
34145 + S_IRUGO | S_IWUGO);
34146 + if (IS_ERR(file)) {
34148 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
34152 + /* keep file count */
34153 + h_parent = dget_parent(file->f_dentry);
34154 + h_dir = h_parent->d_inode;
34155 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
34156 + /* mnt_want_write() is unnecessary here */
34157 + /* no delegation since it is just created */
34158 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
34159 + mutex_unlock(&h_dir->i_mutex);
34161 + if (unlikely(err)) {
34163 + pr_err("unlink %s(%d)\n", fname, err);
34168 + d = file->f_dentry;
34169 + if (unlikely(sb == d->d_sb)) {
34171 + pr_err("%s must be outside\n", fname);
34174 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34176 + pr_err("xino doesn't support %s(%s)\n",
34177 + fname, au_sbtype(d->d_sb));
34180 + return file; /* success */
34184 + file = ERR_PTR(err);
34189 + * find another branch who is on the same filesystem of the specified
34190 + * branch{@btgt}. search until @bend.
34192 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34193 + aufs_bindex_t bend)
34195 + aufs_bindex_t bindex;
34196 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34198 + for (bindex = 0; bindex < btgt; bindex++)
34199 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34201 + for (bindex++; bindex <= bend; bindex++)
34202 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34207 +/* ---------------------------------------------------------------------- */
34210 + * initialize the xinofile for the specified branch @br
34211 + * at the place/path where @base_file indicates.
34212 + * test whether another branch is on the same filesystem or not,
34213 + * if @do_test is true.
34215 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34216 + struct file *base_file, int do_test)
34220 + aufs_bindex_t bend, bindex;
34221 + struct au_branch *shared_br, *b;
34222 + struct file *file;
34223 + struct super_block *tgt_sb;
34225 + shared_br = NULL;
34226 + bend = au_sbend(sb);
34228 + tgt_sb = au_br_sb(br);
34229 + for (bindex = 0; bindex <= bend; bindex++) {
34230 + b = au_sbr(sb, bindex);
34231 + if (tgt_sb == au_br_sb(b)) {
34238 + if (!shared_br || !shared_br->br_xino.xi_file) {
34239 + struct au_xino_lock_dir ldir;
34241 + au_xino_lock_dir(sb, base_file, &ldir);
34242 + /* mnt_want_write() is unnecessary here */
34243 + file = au_xino_create2(base_file, NULL);
34244 + au_xino_unlock_dir(&ldir);
34245 + err = PTR_ERR(file);
34246 + if (IS_ERR(file))
34248 + br->br_xino.xi_file = file;
34250 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34251 + get_file(br->br_xino.xi_file);
34254 + ino = AUFS_ROOT_INO;
34255 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34257 + if (unlikely(err)) {
34258 + fput(br->br_xino.xi_file);
34259 + br->br_xino.xi_file = NULL;
34266 +/* ---------------------------------------------------------------------- */
34268 +/* trucate a xino bitmap file */
34271 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34275 + unsigned long pindex;
34276 + loff_t pos, pend;
34277 + struct au_sbinfo *sbinfo;
34280 + unsigned long *p;
34283 + sbinfo = au_sbi(sb);
34284 + MtxMustLock(&sbinfo->si_xib_mtx);
34285 + p = sbinfo->si_xib_buf;
34286 + func = sbinfo->si_xread;
34287 + pend = vfsub_f_size_read(file);
34289 + while (pos < pend) {
34290 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34292 + if (unlikely(sz <= 0))
34296 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34297 + if (unlikely(*ino < AUFS_FIRST_INO))
34300 + xib_calc_bit(*ino, &pindex, &bit);
34301 + AuDebugOn(page_bits <= bit);
34302 + err = xib_pindex(sb, pindex);
34314 +static int xib_restore(struct super_block *sb)
34317 + aufs_bindex_t bindex, bend;
34321 + page = (void *)__get_free_page(GFP_NOFS);
34322 + if (unlikely(!page))
34326 + bend = au_sbend(sb);
34327 + for (bindex = 0; !err && bindex <= bend; bindex++)
34328 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34329 + err = do_xib_restore
34330 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34332 + AuDbg("b%d\n", bindex);
34333 + free_page((unsigned long)page);
34339 +int au_xib_trunc(struct super_block *sb)
34344 + struct au_xino_lock_dir ldir;
34345 + struct au_sbinfo *sbinfo;
34346 + unsigned long *p;
34347 + struct file *file;
34349 + SiMustWriteLock(sb);
34352 + sbinfo = au_sbi(sb);
34353 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34356 + file = sbinfo->si_xib;
34357 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34360 + au_xino_lock_dir(sb, file, &ldir);
34361 + /* mnt_want_write() is unnecessary here */
34362 + file = au_xino_create2(sbinfo->si_xib, NULL);
34363 + au_xino_unlock_dir(&ldir);
34364 + err = PTR_ERR(file);
34365 + if (IS_ERR(file))
34367 + fput(sbinfo->si_xib);
34368 + sbinfo->si_xib = file;
34370 + p = sbinfo->si_xib_buf;
34371 + memset(p, 0, PAGE_SIZE);
34373 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34374 + if (unlikely(sz != PAGE_SIZE)) {
34376 + AuIOErr("err %d\n", err);
34382 + mutex_lock(&sbinfo->si_xib_mtx);
34383 + /* mnt_want_write() is unnecessary here */
34384 + err = xib_restore(sb);
34385 + mutex_unlock(&sbinfo->si_xib_mtx);
34391 +/* ---------------------------------------------------------------------- */
34394 + * xino mount option handlers
34396 +static au_readf_t find_readf(struct file *h_file)
34398 + const struct file_operations *fop = h_file->f_op;
34401 + return fop->read;
34402 + if (fop->aio_read)
34403 + return do_sync_read;
34404 + if (fop->read_iter)
34405 + return new_sync_read;
34406 + return ERR_PTR(-ENOSYS);
34409 +static au_writef_t find_writef(struct file *h_file)
34411 + const struct file_operations *fop = h_file->f_op;
34414 + return fop->write;
34415 + if (fop->aio_write)
34416 + return do_sync_write;
34417 + if (fop->write_iter)
34418 + return new_sync_write;
34419 + return ERR_PTR(-ENOSYS);
34423 +static void xino_clear_xib(struct super_block *sb)
34425 + struct au_sbinfo *sbinfo;
34427 + SiMustWriteLock(sb);
34429 + sbinfo = au_sbi(sb);
34430 + sbinfo->si_xread = NULL;
34431 + sbinfo->si_xwrite = NULL;
34432 + if (sbinfo->si_xib)
34433 + fput(sbinfo->si_xib);
34434 + sbinfo->si_xib = NULL;
34435 + free_page((unsigned long)sbinfo->si_xib_buf);
34436 + sbinfo->si_xib_buf = NULL;
34439 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34443 + struct au_sbinfo *sbinfo;
34444 + struct file *file;
34446 + SiMustWriteLock(sb);
34448 + sbinfo = au_sbi(sb);
34449 + file = au_xino_create2(base, sbinfo->si_xib);
34450 + err = PTR_ERR(file);
34451 + if (IS_ERR(file))
34453 + if (sbinfo->si_xib)
34454 + fput(sbinfo->si_xib);
34455 + sbinfo->si_xib = file;
34456 + sbinfo->si_xread = find_readf(file);
34457 + sbinfo->si_xwrite = find_writef(file);
34460 + if (!sbinfo->si_xib_buf)
34461 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34462 + if (unlikely(!sbinfo->si_xib_buf))
34465 + sbinfo->si_xib_last_pindex = 0;
34466 + sbinfo->si_xib_next_bit = 0;
34467 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34469 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34470 + PAGE_SIZE, &pos);
34471 + if (unlikely(err != PAGE_SIZE))
34475 + goto out; /* success */
34478 + free_page((unsigned long)sbinfo->si_xib_buf);
34479 + sbinfo->si_xib_buf = NULL;
34483 + fput(sbinfo->si_xib);
34484 + sbinfo->si_xib = NULL;
34485 + sbinfo->si_xread = NULL;
34486 + sbinfo->si_xwrite = NULL;
34491 +/* xino for each branch */
34492 +static void xino_clear_br(struct super_block *sb)
34494 + aufs_bindex_t bindex, bend;
34495 + struct au_branch *br;
34497 + bend = au_sbend(sb);
34498 + for (bindex = 0; bindex <= bend; bindex++) {
34499 + br = au_sbr(sb, bindex);
34500 + if (!br || !br->br_xino.xi_file)
34503 + fput(br->br_xino.xi_file);
34504 + br->br_xino.xi_file = NULL;
34508 +static int au_xino_set_br(struct super_block *sb, struct file *base)
34512 + aufs_bindex_t bindex, bend, bshared;
34514 + struct file *old, *new;
34516 + struct au_branch *br;
34517 + struct inode *inode;
34518 + au_writef_t writef;
34520 + SiMustWriteLock(sb);
34523 + bend = au_sbend(sb);
34524 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
34525 + if (unlikely(!fpair))
34528 + inode = sb->s_root->d_inode;
34529 + ino = AUFS_ROOT_INO;
34530 + writef = au_sbi(sb)->si_xwrite;
34531 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34532 + br = au_sbr(sb, bindex);
34533 + bshared = is_sb_shared(sb, bindex, bindex - 1);
34534 + if (bshared >= 0) {
34535 + /* shared xino */
34536 + *p = fpair[bshared];
34537 + get_file(p->new);
34542 + p->old = br->br_xino.xi_file;
34543 + p->new = au_xino_create2(base, br->br_xino.xi_file);
34544 + err = PTR_ERR(p->new);
34545 + if (IS_ERR(p->new)) {
34551 + err = au_xino_do_write(writef, p->new,
34552 + au_h_iptr(inode, bindex)->i_ino, ino);
34553 + if (unlikely(err))
34557 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34558 + br = au_sbr(sb, bindex);
34559 + if (br->br_xino.xi_file)
34560 + fput(br->br_xino.xi_file);
34561 + get_file(p->new);
34562 + br->br_xino.xi_file = p->new;
34566 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
34576 +void au_xino_clr(struct super_block *sb)
34578 + struct au_sbinfo *sbinfo;
34580 + au_xigen_clr(sb);
34581 + xino_clear_xib(sb);
34582 + xino_clear_br(sb);
34583 + sbinfo = au_sbi(sb);
34584 + /* lvalue, do not call au_mntflags() */
34585 + au_opt_clr(sbinfo->si_mntflags, XINO);
34588 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
34591 + struct dentry *parent, *cur_parent;
34592 + struct qstr *dname, *cur_name;
34593 + struct file *cur_xino;
34594 + struct inode *dir;
34595 + struct au_sbinfo *sbinfo;
34597 + SiMustWriteLock(sb);
34600 + sbinfo = au_sbi(sb);
34601 + parent = dget_parent(xino->file->f_dentry);
34604 + dname = &xino->file->f_dentry->d_name;
34605 + cur_xino = sbinfo->si_xib;
34607 + cur_parent = dget_parent(cur_xino->f_dentry);
34608 + cur_name = &cur_xino->f_dentry->d_name;
34609 + skip = (cur_parent == parent
34610 + && au_qstreq(dname, cur_name));
34611 + dput(cur_parent);
34617 + au_opt_set(sbinfo->si_mntflags, XINO);
34618 + dir = parent->d_inode;
34619 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
34620 + /* mnt_want_write() is unnecessary here */
34621 + err = au_xino_set_xib(sb, xino->file);
34623 + err = au_xigen_set(sb, xino->file);
34625 + err = au_xino_set_br(sb, xino->file);
34626 + mutex_unlock(&dir->i_mutex);
34628 + goto out; /* success */
34631 + AuIOErr("failed creating xino(%d).\n", err);
34632 + au_xigen_clr(sb);
34633 + xino_clear_xib(sb);
34640 +/* ---------------------------------------------------------------------- */
34643 + * create a xinofile at the default place/path.
34645 +struct file *au_xino_def(struct super_block *sb)
34647 + struct file *file;
34649 + struct au_branch *br;
34650 + struct super_block *h_sb;
34651 + struct path path;
34652 + aufs_bindex_t bend, bindex, bwr;
34655 + bend = au_sbend(sb);
34657 + for (bindex = 0; bindex <= bend; bindex++) {
34658 + br = au_sbr(sb, bindex);
34659 + if (au_br_writable(br->br_perm)
34660 + && !au_test_fs_bad_xino(au_br_sb(br))) {
34667 + file = ERR_PTR(-ENOMEM);
34668 + page = (void *)__get_free_page(GFP_NOFS);
34669 + if (unlikely(!page))
34671 + path.mnt = au_br_mnt(br);
34672 + path.dentry = au_h_dptr(sb->s_root, bwr);
34673 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
34674 + file = (void *)p;
34675 + if (!IS_ERR(p)) {
34676 + strcat(p, "/" AUFS_XINO_FNAME);
34677 + AuDbg("%s\n", p);
34678 + file = au_xino_create(sb, p, /*silent*/0);
34679 + if (!IS_ERR(file))
34680 + au_xino_brid_set(sb, br->br_id);
34682 + free_page((unsigned long)page);
34684 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
34685 + if (IS_ERR(file))
34687 + h_sb = file->f_dentry->d_sb;
34688 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
34689 + pr_err("xino doesn't support %s(%s)\n",
34690 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
34692 + file = ERR_PTR(-EINVAL);
34694 + if (!IS_ERR(file))
34695 + au_xino_brid_set(sb, -1);
34702 +/* ---------------------------------------------------------------------- */
34704 +int au_xino_path(struct seq_file *seq, struct file *file)
34708 + err = au_seq_path(seq, &file->f_path);
34709 + if (unlikely(err < 0))
34713 +#define Deleted "\\040(deleted)"
34714 + seq->count -= sizeof(Deleted) - 1;
34715 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
34716 + sizeof(Deleted) - 1));
34722 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
34723 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
34724 +++ linux/include/uapi/linux/aufs_type.h 2015-01-25 13:00:38.637713742 +0100
34727 + * Copyright (C) 2005-2014 Junjiro R. Okajima
34729 + * This program, aufs is free software; you can redistribute it and/or modify
34730 + * it under the terms of the GNU General Public License as published by
34731 + * the Free Software Foundation; either version 2 of the License, or
34732 + * (at your option) any later version.
34734 + * This program is distributed in the hope that it will be useful,
34735 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34736 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34737 + * GNU General Public License for more details.
34739 + * You should have received a copy of the GNU General Public License
34740 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34743 +#ifndef __AUFS_TYPE_H__
34744 +#define __AUFS_TYPE_H__
34746 +#define AUFS_NAME "aufs"
34750 + * define it before including all other headers.
34751 + * sched.h may use pr_* macros before defining "current", so define the
34752 + * no-current version first, and re-define later.
34754 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
34755 +#include <linux/sched.h>
34757 +#define pr_fmt(fmt) \
34758 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
34759 + (int)sizeof(current->comm), current->comm, current->pid
34761 +#include <stdint.h>
34762 +#include <sys/types.h>
34763 +#endif /* __KERNEL__ */
34765 +#include <linux/limits.h>
34767 +#define AUFS_VERSION "3.18.1+-20150119"
34769 +/* todo? move this to linux-2.6.19/include/magic.h */
34770 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
34772 +/* ---------------------------------------------------------------------- */
34774 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
34775 +typedef int8_t aufs_bindex_t;
34776 +#define AUFS_BRANCH_MAX 127
34778 +typedef int16_t aufs_bindex_t;
34779 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
34780 +#define AUFS_BRANCH_MAX 511
34781 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
34782 +#define AUFS_BRANCH_MAX 1023
34783 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
34784 +#define AUFS_BRANCH_MAX 32767
34789 +#ifndef AUFS_BRANCH_MAX
34790 +#error unknown CONFIG_AUFS_BRANCH_MAX value
34792 +#endif /* __KERNEL__ */
34794 +/* ---------------------------------------------------------------------- */
34796 +#define AUFS_FSTYPE AUFS_NAME
34798 +#define AUFS_ROOT_INO 2
34799 +#define AUFS_FIRST_INO 11
34801 +#define AUFS_WH_PFX ".wh."
34802 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
34803 +#define AUFS_WH_TMP_LEN 4
34804 +/* a limit for rmdir/rename a dir and copyup */
34805 +#define AUFS_MAX_NAMELEN (NAME_MAX \
34806 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
34808 + - AUFS_WH_TMP_LEN) /* hex */
34809 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
34810 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
34811 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
34812 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
34813 +#define AUFS_DIRWH_DEF 3
34814 +#define AUFS_RDCACHE_DEF 10 /* seconds */
34815 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
34816 +#define AUFS_RDBLK_DEF 512 /* bytes */
34817 +#define AUFS_RDHASH_DEF 32
34818 +#define AUFS_WKQ_NAME AUFS_NAME "d"
34819 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
34820 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
34821 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
34822 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
34824 +/* pseudo-link maintenace under /proc */
34825 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
34826 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
34827 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
34829 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
34830 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
34832 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
34833 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
34834 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
34836 +/* doubly whiteouted */
34837 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
34838 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
34839 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
34841 +/* branch permissions and attributes */
34842 +#define AUFS_BRPERM_RW "rw"
34843 +#define AUFS_BRPERM_RO "ro"
34844 +#define AUFS_BRPERM_RR "rr"
34845 +#define AUFS_BRATTR_COO_REG "coo_reg"
34846 +#define AUFS_BRATTR_COO_ALL "coo_all"
34847 +#define AUFS_BRATTR_FHSM "fhsm"
34848 +#define AUFS_BRATTR_UNPIN "unpin"
34849 +#define AUFS_BRATTR_ICEX "icex"
34850 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
34851 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
34852 +#define AUFS_BRATTR_ICEX_TR "icextr"
34853 +#define AUFS_BRATTR_ICEX_USR "icexusr"
34854 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
34855 +#define AUFS_BRRATTR_WH "wh"
34856 +#define AUFS_BRWATTR_NLWH "nolwh"
34857 +#define AUFS_BRWATTR_MOO "moo"
34859 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
34860 +#define AuBrPerm_RO (1 << 1) /* readonly */
34861 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
34862 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
34864 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
34865 +#define AuBrAttr_COO_ALL (1 << 4)
34866 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
34868 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
34869 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
34870 + branch. meaningless since
34871 + linux-3.18-rc1 */
34873 +/* ignore error in copying XATTR */
34874 +#define AuBrAttr_ICEX_SEC (1 << 7)
34875 +#define AuBrAttr_ICEX_SYS (1 << 8)
34876 +#define AuBrAttr_ICEX_TR (1 << 9)
34877 +#define AuBrAttr_ICEX_USR (1 << 10)
34878 +#define AuBrAttr_ICEX_OTH (1 << 11)
34879 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
34880 + | AuBrAttr_ICEX_SYS \
34881 + | AuBrAttr_ICEX_TR \
34882 + | AuBrAttr_ICEX_USR \
34883 + | AuBrAttr_ICEX_OTH)
34885 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
34886 +#define AuBrRAttr_Mask AuBrRAttr_WH
34888 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
34889 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
34890 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
34892 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
34894 +/* #warning test userspace */
34896 +#ifndef CONFIG_AUFS_FHSM
34897 +#undef AuBrAttr_FHSM
34898 +#define AuBrAttr_FHSM 0
34900 +#ifndef CONFIG_AUFS_XATTR
34901 +#undef AuBrAttr_ICEX
34902 +#define AuBrAttr_ICEX 0
34903 +#undef AuBrAttr_ICEX_SEC
34904 +#define AuBrAttr_ICEX_SEC 0
34905 +#undef AuBrAttr_ICEX_SYS
34906 +#define AuBrAttr_ICEX_SYS 0
34907 +#undef AuBrAttr_ICEX_TR
34908 +#define AuBrAttr_ICEX_TR 0
34909 +#undef AuBrAttr_ICEX_USR
34910 +#define AuBrAttr_ICEX_USR 0
34911 +#undef AuBrAttr_ICEX_OTH
34912 +#define AuBrAttr_ICEX_OTH 0
34916 +/* the longest combination */
34917 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
34918 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
34919 + "+" AUFS_BRATTR_COO_REG \
34920 + "+" AUFS_BRATTR_FHSM \
34921 + "+" AUFS_BRATTR_UNPIN \
34922 + "+" AUFS_BRATTR_ICEX_SEC \
34923 + "+" AUFS_BRATTR_ICEX_SYS \
34924 + "+" AUFS_BRATTR_ICEX_USR \
34925 + "+" AUFS_BRATTR_ICEX_OTH \
34926 + "+" AUFS_BRWATTR_NLWH)
34929 + char a[AuBrPermStrSz];
34930 +} au_br_perm_str_t;
34932 +static inline int au_br_writable(int brperm)
34934 + return brperm & AuBrPerm_RW;
34937 +static inline int au_br_whable(int brperm)
34939 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
34942 +static inline int au_br_wh_linkable(int brperm)
34944 + return !(brperm & AuBrWAttr_NoLinkWH);
34947 +static inline int au_br_cmoo(int brperm)
34949 + return brperm & AuBrAttr_CMOO_Mask;
34952 +static inline int au_br_fhsm(int brperm)
34954 + return brperm & AuBrAttr_FHSM;
34957 +/* ---------------------------------------------------------------------- */
34961 + /* readdir in userspace */
34965 + AuCtl_WBR_FD, /* pathconf wrapper */
34966 + AuCtl_IBUSY, /* busy inode */
34967 + AuCtl_MVDOWN, /* move-down */
34968 + AuCtl_BR, /* info about branches */
34969 + AuCtl_FHSM_FD /* connection for fhsm */
34972 +/* borrowed from linux/include/linux/kernel.h */
34974 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
34975 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
34978 +/* borrowed from linux/include/linux/compiler-gcc3.h */
34980 +#define __aligned(x) __attribute__((aligned(x)))
34985 +#define __packed __attribute__((packed))
34989 +struct au_rdu_cookie {
34994 + uint32_t generation;
34997 +struct au_rdu_ent {
35006 +static inline int au_rdu_len(int nlen)
35008 + /* include the terminating NULL */
35009 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35010 + sizeof(uint64_t));
35013 +union au_rdu_ent_ul {
35014 + struct au_rdu_ent __user *e;
35026 + uint64_t sz; /* AuCtl_RDU */
35027 + uint64_t nent; /* AuCtl_RDU_INO */
35029 + union au_rdu_ent_ul ent;
35030 + uint16_t verify[AufsCtlRduV_End];
35032 + /* input/output */
35036 + union au_rdu_ent_ul tail;
35037 + /* number of entries which were added in a single call */
35042 + struct au_rdu_cookie cookie;
35045 +/* ---------------------------------------------------------------------- */
35047 +struct aufs_wbr_fd {
35052 +/* ---------------------------------------------------------------------- */
35054 +struct aufs_ibusy {
35055 + uint64_t ino, h_ino;
35059 +/* ---------------------------------------------------------------------- */
35061 +/* error code for move-down */
35062 +/* the actual message strings are implemented in aufs-util.git */
35064 + EAU_MVDOWN_OPAQUE = 1,
35065 + EAU_MVDOWN_WHITEOUT,
35066 + EAU_MVDOWN_UPPER,
35067 + EAU_MVDOWN_BOTTOM,
35068 + EAU_MVDOWN_NOUPPER,
35069 + EAU_MVDOWN_NOLOWERBR,
35073 +/* flags for move-down */
35074 +#define AUFS_MVDOWN_DMSG 1
35075 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35076 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35077 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35078 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35079 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35080 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35081 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35082 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35083 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35084 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35085 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35086 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35088 +/* index for move-down */
35090 + AUFS_MVDOWN_UPPER,
35091 + AUFS_MVDOWN_LOWER,
35092 + AUFS_MVDOWN_NARRAY
35096 + * additional info of move-down
35097 + * number of free blocks and inodes.
35098 + * subset of struct kstatfs, but smaller and always 64bit.
35100 +struct aufs_stfs {
35101 + uint64_t f_blocks;
35102 + uint64_t f_bavail;
35103 + uint64_t f_files;
35104 + uint64_t f_ffree;
35107 +struct aufs_stbr {
35108 + int16_t brid; /* optional input */
35109 + int16_t bindex; /* output */
35110 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35113 +struct aufs_mvdown {
35114 + uint32_t flags; /* input/output */
35115 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35116 + int8_t au_errno; /* output */
35119 +/* ---------------------------------------------------------------------- */
35121 +union aufs_brinfo {
35122 + /* PATH_MAX may differ between kernel-space and user-space */
35123 + char _spacer[4096];
35131 +/* ---------------------------------------------------------------------- */
35133 +#define AuCtlType 'A'
35134 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35135 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35136 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35137 + struct aufs_wbr_fd)
35138 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35139 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35140 + struct aufs_mvdown)
35141 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35142 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35144 +#endif /* __AUFS_TYPE_H__ */
35145 aufs3.18.1+ loopback patch
35147 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
35148 index 30efd68..77b31b4 100644
35149 --- a/drivers/block/loop.c
35150 +++ b/drivers/block/loop.c
35151 @@ -514,7 +514,7 @@ out:
35154 struct switch_request {
35155 - struct file *file;
35156 + struct file *file, *virt_file;
35157 struct completion wait;
35160 @@ -576,7 +576,8 @@ static int loop_thread(void *data)
35161 * First it needs to flush existing IO, it does this by sending a magic
35162 * BIO down the pipe. The completion of this BIO does the actual switch.
35164 -static int loop_switch(struct loop_device *lo, struct file *file)
35165 +static int loop_switch(struct loop_device *lo, struct file *file,
35166 + struct file *virt_file)
35168 struct switch_request w;
35169 struct bio *bio = bio_alloc(GFP_KERNEL, 0);
35170 @@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file)
35172 init_completion(&w.wait);
35174 + w.virt_file = virt_file;
35175 bio->bi_private = &w;
35176 bio->bi_bdev = NULL;
35177 loop_make_request(lo->lo_queue, bio);
35178 @@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo)
35179 if (!lo->lo_thread)
35182 - return loop_switch(lo, NULL);
35183 + return loop_switch(lo, NULL, NULL);
35187 @@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35188 mapping = file->f_mapping;
35189 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
35190 lo->lo_backing_file = file;
35191 + lo->lo_backing_virt_file = p->virt_file;
35192 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
35193 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
35194 lo->old_gfp_mask = mapping_gfp_mask(mapping);
35195 @@ -627,6 +630,13 @@ out:
35196 complete(&p->wait);
35199 +static struct file *loop_real_file(struct file *file)
35201 + struct file *f = NULL;
35202 + if (file->f_dentry->d_sb->s_op->real_loop)
35203 + f = file->f_dentry->d_sb->s_op->real_loop(file);
35208 * loop_change_fd switched the backing store of a loopback device to
35209 @@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35212 struct file *file, *old_file;
35213 + struct file *f, *virt_file = NULL, *old_virt_file;
35214 struct inode *inode;
35217 @@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35221 + f = loop_real_file(file);
35223 + virt_file = file;
35228 inode = file->f_mapping->host;
35229 old_file = lo->lo_backing_file;
35230 + old_virt_file = lo->lo_backing_virt_file;
35234 @@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35237 /* and ... switch */
35238 - error = loop_switch(lo, file);
35239 + error = loop_switch(lo, file, virt_file);
35244 + if (old_virt_file)
35245 + fput(old_virt_file);
35246 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
35247 ioctl_by_bdev(bdev, BLKRRPART, 0);
35257 @@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo)
35258 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35259 struct block_device *bdev, unsigned int arg)
35261 - struct file *file, *f;
35262 + struct file *file, *f, *virt_file = NULL;
35263 struct inode *inode;
35264 struct address_space *mapping;
35265 unsigned lo_blocksize;
35266 @@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35270 + f = loop_real_file(file);
35272 + virt_file = file;
35278 if (lo->lo_state != Lo_unbound)
35279 @@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35280 lo->lo_device = bdev;
35281 lo->lo_flags = lo_flags;
35282 lo->lo_backing_file = file;
35283 + lo->lo_backing_virt_file = virt_file;
35284 lo->transfer = transfer_none;
35286 lo->lo_sizelimit = 0;
35287 @@ -948,6 +977,7 @@ out_clr:
35288 lo->lo_thread = NULL;
35289 lo->lo_device = NULL;
35290 lo->lo_backing_file = NULL;
35291 + lo->lo_backing_virt_file = NULL;
35293 set_capacity(lo->lo_disk, 0);
35294 invalidate_bdev(bdev);
35295 @@ -957,6 +987,8 @@ out_clr:
35296 lo->lo_state = Lo_unbound;
35302 /* This is safe: open() is still holding a reference. */
35303 module_put(THIS_MODULE);
35304 @@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
35305 static int loop_clr_fd(struct loop_device *lo)
35307 struct file *filp = lo->lo_backing_file;
35308 + struct file *virt_filp = lo->lo_backing_virt_file;
35309 gfp_t gfp = lo->old_gfp_mask;
35310 struct block_device *bdev = lo->lo_device;
35312 @@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo)
35314 spin_lock_irq(&lo->lo_lock);
35315 lo->lo_backing_file = NULL;
35316 + lo->lo_backing_virt_file = NULL;
35317 spin_unlock_irq(&lo->lo_lock);
35319 loop_release_xfer(lo);
35320 @@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo)
35321 * bd_mutex which is usually taken before lo_ctl_mutex.
35329 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
35330 index 90df5d6..cb91822 100644
35331 --- a/drivers/block/loop.h
35332 +++ b/drivers/block/loop.h
35333 @@ -44,7 +44,7 @@ struct loop_device {
35334 int (*ioctl)(struct loop_device *, int cmd,
35335 unsigned long arg);
35337 - struct file * lo_backing_file;
35338 + struct file * lo_backing_file, *lo_backing_virt_file;
35339 struct block_device *lo_device;
35340 unsigned lo_blocksize;
35342 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
35343 index 3dd9138..63a424c 100644
35344 --- a/fs/aufs/f_op.c
35345 +++ b/fs/aufs/f_op.c
35346 @@ -367,7 +367,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
35348 h_file = au_hf_top(file);
35350 - if (au_test_loopback_kthread()) {
35351 + if (0 && au_test_loopback_kthread()) {
35352 au_warn_loopback(h_file->f_dentry->d_sb);
35353 if (file->f_mapping != h_file->f_mapping) {
35354 file->f_mapping = h_file->f_mapping;
35355 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
35356 index 3b03b52..4ab749d 100644
35357 --- a/fs/aufs/loop.c
35358 +++ b/fs/aufs/loop.c
35359 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
35360 symbol_put(loop_backing_file);
35361 kfree(au_warn_loopback_array);
35364 +/* ---------------------------------------------------------------------- */
35366 +/* support the loopback block device insude aufs */
35368 +struct file *aufs_real_loop(struct file *file)
35372 + BUG_ON(!au_test_aufs(file->f_dentry->d_sb));
35373 + fi_read_lock(file);
35374 + f = au_hf_top(file);
35375 + fi_read_unlock(file);
35379 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
35380 index da8b756..28cb7ea 100644
35381 --- a/fs/aufs/loop.h
35382 +++ b/fs/aufs/loop.h
35383 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
35385 int au_loopback_init(void);
35386 void au_loopback_fin(void);
35388 +struct file *aufs_real_loop(struct file *file);
35390 +AuStub(struct file *, loop_backing_file, return NULL)
35392 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
35393 struct dentry *h_adding)
35394 AuStubInt0(au_test_loopback_kthread, void)
35395 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
35397 AuStubInt0(au_loopback_init, void)
35398 AuStubVoid(au_loopback_fin, void)
35400 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
35401 #endif /* BLK_DEV_LOOP */
35403 #endif /* __KERNEL__ */
35404 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
35405 index 2ec0b4f..65a6781 100644
35406 --- a/fs/aufs/super.c
35407 +++ b/fs/aufs/super.c
35408 @@ -812,7 +812,10 @@ static const struct super_operations aufs_sop = {
35409 .statfs = aufs_statfs,
35410 .put_super = aufs_put_super,
35411 .sync_fs = aufs_sync_fs,
35412 - .remount_fs = aufs_remount_fs
35413 + .remount_fs = aufs_remount_fs,
35414 +#ifdef CONFIG_AUFS_BDEV_LOOP
35415 + .real_loop = aufs_real_loop
35419 /* ---------------------------------------------------------------------- */
35420 diff --git a/include/linux/fs.h b/include/linux/fs.h
35421 index aabcbba..1a634f5 100644
35422 --- a/include/linux/fs.h
35423 +++ b/include/linux/fs.h
35424 @@ -1594,6 +1594,10 @@ struct super_operations {
35425 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
35426 long (*nr_cached_objects)(struct super_block *, int);
35427 long (*free_cached_objects)(struct super_block *, long, int);
35428 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
35430 + struct file *(*real_loop)(struct file *);
35435 diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
35436 index 50777b5..f9c6b3d 100644
35437 --- a/include/linux/shmem_fs.h
35438 +++ b/include/linux/shmem_fs.h
35439 @@ -26,10 +26,13 @@ struct shmem_inode_info {
35442 struct shmem_sb_info {
35443 + struct mutex idr_lock;
35445 + struct idr idr; /* manages inode-number */
35446 unsigned long max_blocks; /* How many blocks are allowed */
35447 struct percpu_counter used_blocks; /* How many are allocated */
35448 - unsigned long max_inodes; /* How many inodes are allowed */
35449 - unsigned long free_inodes; /* How many are left for allocation */
35450 + int max_inodes; /* How many inodes are allowed */
35451 + int free_inodes; /* How many are left for allocation */
35452 spinlock_t stat_lock; /* Serialize shmem_sb_info changes */
35453 kuid_t uid; /* Mount uid for root directory */
35454 kgid_t gid; /* Mount gid for root directory */
35455 diff --git a/mm/shmem.c b/mm/shmem.c
35456 index 185836b..ac7f9fb 100644
35459 @@ -110,9 +110,13 @@ static unsigned long shmem_default_max_blocks(void)
35460 return totalram_pages / 2;
35463 -static unsigned long shmem_default_max_inodes(void)
35464 +static int shmem_default_max_inodes(void)
35466 - return min(totalram_pages - totalhigh_pages, totalram_pages / 2);
35467 + unsigned long ul;
35470 + ul = min3(ul, totalram_pages - totalhigh_pages, totalram_pages / 2);
35475 @@ -592,6 +596,7 @@ static int shmem_setattr(struct dentry *dentry, struct iattr *attr)
35476 static void shmem_evict_inode(struct inode *inode)
35478 struct shmem_inode_info *info = SHMEM_I(inode);
35479 + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
35481 if (inode->i_mapping->a_ops == &shmem_aops) {
35482 shmem_unacct_size(info->flags, inode->i_size);
35483 @@ -607,6 +612,11 @@ static void shmem_evict_inode(struct inode *inode)
35485 simple_xattrs_free(&info->xattrs);
35486 WARN_ON(inode->i_blocks);
35487 + if (!sbinfo->idr_nouse && inode->i_ino) {
35488 + mutex_lock(&sbinfo->idr_lock);
35489 + idr_remove(&sbinfo->idr, inode->i_ino);
35490 + mutex_unlock(&sbinfo->idr_lock);
35492 shmem_free_inode(inode->i_sb);
35493 clear_inode(inode);
35495 @@ -1406,13 +1416,13 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
35496 struct inode *inode;
35497 struct shmem_inode_info *info;
35498 struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
35501 if (shmem_reserve_inode(sb))
35504 inode = new_inode(sb);
35506 - inode->i_ino = get_next_ino();
35507 inode_init_owner(inode, dir, mode);
35508 inode->i_blocks = 0;
35509 inode->i_mapping->backing_dev_info = &shmem_backing_dev_info;
35510 @@ -1454,6 +1464,25 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
35511 mpol_shared_policy_init(&info->policy, NULL);
35515 + if (!sbinfo->idr_nouse) {
35516 + /* inum 0 and 1 are unused */
35517 + mutex_lock(&sbinfo->idr_lock);
35518 + ino = idr_alloc(&sbinfo->idr, inode, 2, INT_MAX,
35521 + inode->i_ino = ino;
35522 + mutex_unlock(&sbinfo->idr_lock);
35523 + __insert_inode_hash(inode, inode->i_ino);
35525 + inode->i_ino = 0;
35526 + mutex_unlock(&sbinfo->idr_lock);
35528 + /* shmem_free_inode() will be called */
35532 + inode->i_ino = get_next_ino();
35534 shmem_free_inode(sb);
35536 @@ -2674,8 +2703,7 @@ static struct dentry *shmem_get_parent(struct dentry *child)
35537 static int shmem_match(struct inode *ino, void *vfh)
35540 - __u64 inum = fh[2];
35541 - inum = (inum << 32) | fh[1];
35542 + __u64 inum = fh[1];
35543 return ino->i_ino == inum && fh[0] == ino->i_generation;
35546 @@ -2686,14 +2714,11 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb,
35547 struct dentry *dentry = NULL;
35554 - inum = fid->raw[2];
35555 - inum = (inum << 32) | fid->raw[1];
35557 - inode = ilookup5(sb, (unsigned long)(inum + fid->raw[0]),
35558 - shmem_match, fid->raw);
35559 + inum = fid->raw[1];
35560 + inode = ilookup5(sb, inum, shmem_match, fid->raw);
35562 dentry = d_find_alias(inode);
35564 @@ -2705,30 +2730,15 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb,
35565 static int shmem_encode_fh(struct inode *inode, __u32 *fh, int *len,
35566 struct inode *parent)
35572 return FILEID_INVALID;
35575 - if (inode_unhashed(inode)) {
35576 - /* Unfortunately insert_inode_hash is not idempotent,
35577 - * so as we hash inodes here rather than at creation
35578 - * time, we need a lock to ensure we only try
35581 - static DEFINE_SPINLOCK(lock);
35582 - spin_lock(&lock);
35583 - if (inode_unhashed(inode))
35584 - __insert_inode_hash(inode,
35585 - inode->i_ino + inode->i_generation);
35586 - spin_unlock(&lock);
35589 fh[0] = inode->i_generation;
35590 fh[1] = inode->i_ino;
35591 - fh[2] = ((__u64)inode->i_ino) >> 32;
35598 @@ -2793,7 +2803,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
35600 } else if (!strcmp(this_char,"nr_inodes")) {
35601 sbinfo->max_inodes = memparse(value, &rest);
35603 + if (*rest || sbinfo->max_inodes < 2)
35605 } else if (!strcmp(this_char,"mode")) {
35607 @@ -2846,7 +2856,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
35609 struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
35610 struct shmem_sb_info config = *sbinfo;
35611 - unsigned long inodes;
35613 int error = -EINVAL;
35615 config.mpol = NULL;
35616 @@ -2894,7 +2904,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root)
35617 seq_printf(seq, ",size=%luk",
35618 sbinfo->max_blocks << (PAGE_CACHE_SHIFT - 10));
35619 if (sbinfo->max_inodes != shmem_default_max_inodes())
35620 - seq_printf(seq, ",nr_inodes=%lu", sbinfo->max_inodes);
35621 + seq_printf(seq, ",nr_inodes=%d", sbinfo->max_inodes);
35622 if (sbinfo->mode != (S_IRWXUGO | S_ISVTX))
35623 seq_printf(seq, ",mode=%03ho", sbinfo->mode);
35624 if (!uid_eq(sbinfo->uid, GLOBAL_ROOT_UID))
35625 @@ -2983,6 +2993,8 @@ static void shmem_put_super(struct super_block *sb)
35627 struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
35629 + if (!sbinfo->idr_nouse)
35630 + idr_destroy(&sbinfo->idr);
35631 percpu_counter_destroy(&sbinfo->used_blocks);
35632 mpol_put(sbinfo->mpol);
35634 @@ -3001,6 +3013,8 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
35638 + mutex_init(&sbinfo->idr_lock);
35639 + idr_init(&sbinfo->idr);
35640 sbinfo->mode = S_IRWXUGO | S_ISVTX;
35641 sbinfo->uid = current_fsuid();
35642 sbinfo->gid = current_fsgid();
35643 @@ -3104,6 +3118,15 @@ static void shmem_destroy_inodecache(void)
35644 kmem_cache_destroy(shmem_inode_cachep);
35647 +static __init void shmem_no_idr(struct super_block *sb)
35649 + struct shmem_sb_info *sbinfo;
35651 + sbinfo = SHMEM_SB(sb);
35652 + sbinfo->idr_nouse = true;
35653 + idr_destroy(&sbinfo->idr);
35656 static const struct address_space_operations shmem_aops = {
35657 .writepage = shmem_writepage,
35658 .set_page_dirty = __set_page_dirty_no_writeback,
35659 @@ -3246,6 +3269,7 @@ int __init shmem_init(void)
35660 printk(KERN_ERR "Could not kern_mount tmpfs\n");
35663 + shmem_no_idr(shm_mnt->mnt_sb);
35667 diff --git a/fs/inode.c b/fs/inode.c
35668 index 26753ba..61e0af2 100644
35671 @@ -840,6 +840,8 @@ unsigned int get_next_ino(void)
35672 unsigned int *p = &get_cpu_var(last_ino);
35673 unsigned int res = *p;
35678 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
35679 static atomic_t shared_last_ino;
35680 @@ -849,7 +851,9 @@ unsigned int get_next_ino(void)
35685 + if (unlikely(!++res))
35686 + goto start; /* never zero */
35688 put_cpu_var(last_ino);