3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 7385e54..d5c769c 100644
7 @@ -208,6 +208,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 47ac07b..0c6a294 100644
19 @@ -125,3 +125,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 3ce25b5..9faebdc 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
38 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39 index 66e8c3b..ec278ac 100644
40 --- a/drivers/block/loop.c
41 +++ b/drivers/block/loop.c
42 @@ -692,6 +692,24 @@ static inline int is_loop_device(struct file *file)
43 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
48 + * no get/put for file.
50 +struct file *loop_backing_file(struct super_block *sb)
53 + struct loop_device *l;
56 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
57 + l = sb->s_bdev->bd_disk->private_data;
58 + ret = l->lo_backing_file;
62 +EXPORT_SYMBOL(loop_backing_file);
64 /* loop sysfs attributes */
66 static ssize_t loop_attr_show(struct device *dev, char *page,
67 diff --git a/fs/inode.c b/fs/inode.c
68 index 4bcdad3..bc83168 100644
71 @@ -1497,7 +1497,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
72 * This does the actual work of updating an inodes time or version. Must have
73 * had called mnt_want_write() before calling this.
75 -static int update_time(struct inode *inode, struct timespec *time, int flags)
76 +int update_time(struct inode *inode, struct timespec *time, int flags)
78 if (inode->i_op->update_time)
79 return inode->i_op->update_time(inode, time, flags);
80 diff --git a/fs/splice.c b/fs/splice.c
81 index 12028fa..f26cbaf 100644
84 @@ -1111,8 +1111,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
86 * Attempt to initiate a splice from pipe to file.
88 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
89 - loff_t *ppos, size_t len, unsigned int flags)
90 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
91 + loff_t *ppos, size_t len, unsigned int flags)
93 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
94 loff_t *, size_t, unsigned int);
95 @@ -1128,9 +1128,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
97 * Attempt to initiate a splice from a file to a pipe.
99 -static long do_splice_to(struct file *in, loff_t *ppos,
100 - struct pipe_inode_info *pipe, size_t len,
101 - unsigned int flags)
102 +long do_splice_to(struct file *in, loff_t *ppos,
103 + struct pipe_inode_info *pipe, size_t len,
104 + unsigned int flags)
106 ssize_t (*splice_read)(struct file *, loff_t *,
107 struct pipe_inode_info *, size_t, unsigned int);
108 diff --git a/include/linux/fs.h b/include/linux/fs.h
109 index 23b2a35..f3f635c 100644
110 --- a/include/linux/fs.h
111 +++ b/include/linux/fs.h
112 @@ -2669,6 +2669,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
113 extern int inode_newsize_ok(const struct inode *, loff_t offset);
114 extern void setattr_copy(struct inode *inode, const struct iattr *attr);
116 +extern int update_time(struct inode *, struct timespec *, int);
117 extern int file_update_time(struct file *file);
119 extern int generic_show_options(struct seq_file *m, struct dentry *root);
120 diff --git a/include/linux/splice.h b/include/linux/splice.h
121 index 0e43906..304169e 100644
122 --- a/include/linux/splice.h
123 +++ b/include/linux/splice.h
124 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
125 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
127 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
129 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
130 + loff_t *ppos, size_t len, unsigned int flags);
131 +extern long do_splice_to(struct file *in, loff_t *ppos,
132 + struct pipe_inode_info *pipe, size_t len,
133 + unsigned int flags);
135 aufs3.14 loopback patch
137 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
138 index ec278ac..1894990 100644
139 --- a/drivers/block/loop.c
140 +++ b/drivers/block/loop.c
141 @@ -514,7 +514,7 @@ out:
144 struct switch_request {
146 + struct file *file, *virt_file;
147 struct completion wait;
150 @@ -576,7 +576,8 @@ static int loop_thread(void *data)
151 * First it needs to flush existing IO, it does this by sending a magic
152 * BIO down the pipe. The completion of this BIO does the actual switch.
154 -static int loop_switch(struct loop_device *lo, struct file *file)
155 +static int loop_switch(struct loop_device *lo, struct file *file,
156 + struct file *virt_file)
158 struct switch_request w;
159 struct bio *bio = bio_alloc(GFP_KERNEL, 0);
160 @@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file)
162 init_completion(&w.wait);
164 + w.virt_file = virt_file;
165 bio->bi_private = &w;
167 loop_make_request(lo->lo_queue, bio);
168 @@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo)
172 - return loop_switch(lo, NULL);
173 + return loop_switch(lo, NULL, NULL);
177 @@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
178 mapping = file->f_mapping;
179 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
180 lo->lo_backing_file = file;
181 + lo->lo_backing_virt_file = p->virt_file;
182 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
183 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
184 lo->old_gfp_mask = mapping_gfp_mask(mapping);
185 @@ -627,6 +630,13 @@ out:
189 +static struct file *loop_real_file(struct file *file)
191 + struct file *f = NULL;
192 + if (file->f_dentry->d_sb->s_op->real_loop)
193 + f = file->f_dentry->d_sb->s_op->real_loop(file);
198 * loop_change_fd switched the backing store of a loopback device to
199 @@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
202 struct file *file, *old_file;
203 + struct file *f, *virt_file = NULL, *old_virt_file;
207 @@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
211 + f = loop_real_file(file);
218 inode = file->f_mapping->host;
219 old_file = lo->lo_backing_file;
220 + old_virt_file = lo->lo_backing_virt_file;
224 @@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
228 - error = loop_switch(lo, file);
229 + error = loop_switch(lo, file, virt_file);
235 + fput(old_virt_file);
236 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
237 ioctl_by_bdev(bdev, BLKRRPART, 0);
247 @@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo)
248 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
249 struct block_device *bdev, unsigned int arg)
251 - struct file *file, *f;
252 + struct file *file, *f, *virt_file = NULL;
254 struct address_space *mapping;
255 unsigned lo_blocksize;
256 @@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
260 + f = loop_real_file(file);
268 if (lo->lo_state != Lo_unbound)
269 @@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
270 lo->lo_device = bdev;
271 lo->lo_flags = lo_flags;
272 lo->lo_backing_file = file;
273 + lo->lo_backing_virt_file = virt_file;
274 lo->transfer = transfer_none;
276 lo->lo_sizelimit = 0;
277 @@ -948,6 +977,7 @@ out_clr:
278 lo->lo_thread = NULL;
279 lo->lo_device = NULL;
280 lo->lo_backing_file = NULL;
281 + lo->lo_backing_virt_file = NULL;
283 set_capacity(lo->lo_disk, 0);
284 invalidate_bdev(bdev);
285 @@ -957,6 +987,8 @@ out_clr:
286 lo->lo_state = Lo_unbound;
292 /* This is safe: open() is still holding a reference. */
293 module_put(THIS_MODULE);
294 @@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
295 static int loop_clr_fd(struct loop_device *lo)
297 struct file *filp = lo->lo_backing_file;
298 + struct file *virt_filp = lo->lo_backing_virt_file;
299 gfp_t gfp = lo->old_gfp_mask;
300 struct block_device *bdev = lo->lo_device;
302 @@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo)
304 spin_lock_irq(&lo->lo_lock);
305 lo->lo_backing_file = NULL;
306 + lo->lo_backing_virt_file = NULL;
307 spin_unlock_irq(&lo->lo_lock);
309 loop_release_xfer(lo);
310 @@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo)
311 * bd_mutex which is usually taken before lo_ctl_mutex.
319 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
320 index 90df5d6..cb91822 100644
321 --- a/drivers/block/loop.h
322 +++ b/drivers/block/loop.h
323 @@ -44,7 +44,7 @@ struct loop_device {
324 int (*ioctl)(struct loop_device *, int cmd,
327 - struct file * lo_backing_file;
328 + struct file * lo_backing_file, *lo_backing_virt_file;
329 struct block_device *lo_device;
330 unsigned lo_blocksize;
332 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
333 index 2e0302d..b35af58 100644
336 @@ -337,7 +337,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
338 h_file = au_hf_top(file);
340 - if (au_test_loopback_kthread()) {
341 + if (0 && au_test_loopback_kthread()) {
342 au_warn_loopback(h_file->f_dentry->d_sb);
343 if (file->f_mapping != h_file->f_mapping) {
344 file->f_mapping = h_file->f_mapping;
345 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
346 index 3b03b52..4ab749d 100644
349 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
350 symbol_put(loop_backing_file);
351 kfree(au_warn_loopback_array);
354 +/* ---------------------------------------------------------------------- */
356 +/* support the loopback block device insude aufs */
358 +struct file *aufs_real_loop(struct file *file)
362 + BUG_ON(!au_test_aufs(file->f_dentry->d_sb));
363 + fi_read_lock(file);
364 + f = au_hf_top(file);
365 + fi_read_unlock(file);
369 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
370 index da8b756..28cb7ea 100644
373 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
375 int au_loopback_init(void);
376 void au_loopback_fin(void);
378 +struct file *aufs_real_loop(struct file *file);
380 +AuStub(struct file *, loop_backing_file, return NULL)
382 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
383 struct dentry *h_adding)
384 AuStubInt0(au_test_loopback_kthread, void)
385 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
387 AuStubInt0(au_loopback_init, void)
388 AuStubVoid(au_loopback_fin, void)
390 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
391 #endif /* BLK_DEV_LOOP */
393 #endif /* __KERNEL__ */
394 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
395 index b609e5a..e3909ed 100644
396 --- a/fs/aufs/super.c
397 +++ b/fs/aufs/super.c
398 @@ -807,7 +807,10 @@ static const struct super_operations aufs_sop = {
399 .statfs = aufs_statfs,
400 .put_super = aufs_put_super,
401 .sync_fs = aufs_sync_fs,
402 - .remount_fs = aufs_remount_fs
403 + .remount_fs = aufs_remount_fs,
404 +#ifdef CONFIG_AUFS_BDEV_LOOP
405 + .real_loop = aufs_real_loop
409 /* ---------------------------------------------------------------------- */
410 diff --git a/include/linux/fs.h b/include/linux/fs.h
411 index f3f635c..c4308ca 100644
412 --- a/include/linux/fs.h
413 +++ b/include/linux/fs.h
414 @@ -1626,6 +1626,10 @@ struct super_operations {
415 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
416 long (*nr_cached_objects)(struct super_block *, int);
417 long (*free_cached_objects)(struct super_block *, long, int);
418 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
420 + struct file *(*real_loop)(struct file *);
427 diff --git a/fs/buffer.c b/fs/buffer.c
428 index 27265a8..75427a6 100644
431 @@ -2448,7 +2448,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
432 * Update file times before taking page lock. We may end up failing the
433 * fault so this update may be superfluous but who really cares...
435 - file_update_time(vma->vm_file);
436 + vma_file_update_time(vma);
438 ret = __block_page_mkwrite(vma, vmf, get_block);
439 sb_end_pagefault(sb);
440 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
441 index d4a3574..e44a744 100644
442 --- a/fs/proc/nommu.c
443 +++ b/fs/proc/nommu.c
444 @@ -45,7 +45,9 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
445 file = region->vm_file;
448 - struct inode *inode = file_inode(region->vm_file);
449 + struct inode *inode;
450 + file = vmr_pr_or_file(region);
451 + inode = file_inode(file);
452 dev = inode->i_sb->s_dev;
455 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
456 index fb52b54..1aca72e 100644
457 --- a/fs/proc/task_mmu.c
458 +++ b/fs/proc/task_mmu.c
459 @@ -264,7 +264,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
460 const char *name = NULL;
463 - struct inode *inode = file_inode(vma->vm_file);
464 + struct inode *inode;
465 + file = vma_pr_or_file(vma);
466 + inode = file_inode(file);
467 dev = inode->i_sb->s_dev;
469 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
470 @@ -1407,6 +1409,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
471 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
474 + file = vma_pr_or_file(vma);
475 seq_printf(m, " file=");
476 seq_path(m, &file->f_path, "\n\t= ");
477 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
478 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
479 index 678455d..ad0ce45 100644
480 --- a/fs/proc/task_nommu.c
481 +++ b/fs/proc/task_nommu.c
482 @@ -141,7 +141,9 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
486 - struct inode *inode = file_inode(vma->vm_file);
487 + struct inode *inode;
488 + file = vma_pr_or_file(file);
489 + inode = file_inode(file);
490 dev = inode->i_sb->s_dev;
492 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
493 diff --git a/include/linux/mm.h b/include/linux/mm.h
494 index c1b7414..02036e0 100644
495 --- a/include/linux/mm.h
496 +++ b/include/linux/mm.h
498 #include <linux/pfn.h>
499 #include <linux/bit_spinlock.h>
500 #include <linux/shrinker.h>
501 +#include <linux/dcache.h>
502 +#include <linux/file.h>
503 +#include <linux/fs.h>
507 @@ -1152,6 +1155,87 @@ static inline int fixup_user_fault(struct task_struct *tsk,
512 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
513 + * in /proc/PID/maps.
515 +/* #define AUFS_DEBUG_MMAP */
516 +static inline void aufs_trace(struct file *f, struct file *pr,
517 + const char func[], int line, const char func2[])
519 +#ifdef AUFS_DEBUG_MMAP
521 + pr_info("%s:%d: %s, %p\n", func, line, func2,
522 + f ? (char *)f->f_dentry->d_name.name : "(null)");
526 +static inline struct file *vmr_do_pr_or_file(struct vm_region *region,
527 + const char func[], int line)
529 + struct file *f = region->vm_file, *pr = region->vm_prfile;
530 + aufs_trace(f, pr, func, line, __func__);
531 + return (f && pr) ? pr : f;
534 +static inline void vmr_do_fput(struct vm_region *region,
535 + const char func[], int line)
537 + struct file *f = region->vm_file, *pr = region->vm_prfile;
538 + aufs_trace(f, pr, func, line, __func__);
544 +static inline void vma_do_file_update_time(struct vm_area_struct *vma,
545 + const char func[], int line)
547 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
548 + aufs_trace(f, pr, func, line, __func__);
549 + file_update_time(f);
551 + file_update_time(pr);
554 +static inline struct file *vma_do_pr_or_file(struct vm_area_struct *vma,
555 + const char func[], int line)
557 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
558 + aufs_trace(f, pr, func, line, __func__);
559 + return (f && pr) ? pr : f;
562 +static inline void vma_do_get_file(struct vm_area_struct *vma,
563 + const char func[], int line)
565 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
566 + aufs_trace(f, pr, func, line, __func__);
572 +static inline void vma_do_fput(struct vm_area_struct *vma,
573 + const char func[], int line)
575 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
576 + aufs_trace(f, pr, func, line, __func__);
582 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
584 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
585 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
587 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
589 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
590 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
592 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
593 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
594 void *buf, int len, int write);
595 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
596 index 290901a..c21588b 100644
597 --- a/include/linux/mm_types.h
598 +++ b/include/linux/mm_types.h
599 @@ -231,6 +231,7 @@ struct vm_region {
600 unsigned long vm_top; /* region allocated to here */
601 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
602 struct file *vm_file; /* the backing file or NULL */
603 + struct file *vm_prfile; /* the virtual backing file or NULL */
605 int vm_usage; /* region usage count (access under nommu_region_sem) */
606 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
607 @@ -299,6 +300,7 @@ struct vm_area_struct {
608 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
609 units, *not* PAGE_CACHE_SIZE */
610 struct file * vm_file; /* File we map to (can be NULL). */
611 + struct file *vm_prfile; /* shadow of vm_file */
612 void * vm_private_data; /* was vm_pte (shared mem) */
615 diff --git a/kernel/fork.c b/kernel/fork.c
616 index a17621c..40d9f6a 100644
619 @@ -412,7 +412,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
620 struct inode *inode = file_inode(file);
621 struct address_space *mapping = file->f_mapping;
625 if (tmp->vm_flags & VM_DENYWRITE)
626 atomic_dec(&inode->i_writecount);
627 mutex_lock(&mapping->i_mmap_mutex);
628 diff --git a/mm/filemap.c b/mm/filemap.c
629 index 7a13f6a..f1805df 100644
632 @@ -1733,7 +1733,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
633 int ret = VM_FAULT_LOCKED;
635 sb_start_pagefault(inode->i_sb);
636 - file_update_time(vma->vm_file);
637 + vma_file_update_time(vma);
639 if (page->mapping != inode->i_mapping) {
641 diff --git a/mm/fremap.c b/mm/fremap.c
642 index 34feba6..d857364 100644
645 @@ -227,7 +227,9 @@ get_write_lock:
646 /* mmap_region may free vma; grab the info now */
647 vm_flags = vma->vm_flags;
650 addr = mmap_region(file, start, size, vm_flags, pgoff);
653 if (IS_ERR_VALUE(addr)) {
655 diff --git a/mm/madvise.c b/mm/madvise.c
656 index 539eeb9..5e700b1 100644
659 @@ -327,12 +327,12 @@ static long madvise_remove(struct vm_area_struct *vma,
660 * vma's reference to the file) can go away as soon as we drop
665 up_read(¤t->mm->mmap_sem);
666 error = do_fallocate(f,
667 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
668 offset, end - start);
671 down_read(¤t->mm->mmap_sem);
674 diff --git a/mm/memory.c b/mm/memory.c
675 index 22dfa61..81813d9 100644
678 @@ -2755,7 +2755,7 @@ reuse:
679 set_page_dirty_balance(dirty_page, page_mkwrite);
680 /* file_update_time outside page_lock */
682 - file_update_time(vma->vm_file);
683 + vma_file_update_time(vma);
685 put_page(dirty_page);
687 @@ -3467,7 +3467,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
689 /* file_update_time outside page_lock */
690 if (vma->vm_file && !page_mkwrite)
691 - file_update_time(vma->vm_file);
692 + vma_file_update_time(vma);
694 unlock_page(vmf.page);
696 diff --git a/mm/mmap.c b/mm/mmap.c
697 index 20ff0c3..f743033 100644
700 @@ -249,7 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
701 if (vma->vm_ops && vma->vm_ops->close)
702 vma->vm_ops->close(vma);
704 - fput(vma->vm_file);
706 mpol_put(vma_policy(vma));
707 kmem_cache_free(vm_area_cachep, vma);
709 @@ -859,7 +859,7 @@ again: remove_next = 1 + (end > next->vm_end);
712 uprobe_munmap(next, next->vm_start, next->vm_end);
717 anon_vma_merge(vma, next);
718 @@ -1639,8 +1639,8 @@ out:
720 if (vm_flags & VM_DENYWRITE)
721 allow_write_access(file);
726 /* Undo any partial mapping done by a device driver. */
727 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
728 @@ -2429,7 +2429,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
732 - get_file(new->vm_file);
735 if (new->vm_ops && new->vm_ops->open)
736 new->vm_ops->open(new);
737 @@ -2448,7 +2448,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
738 if (new->vm_ops && new->vm_ops->close)
739 new->vm_ops->close(new);
741 - fput(new->vm_file);
743 unlink_anon_vmas(new);
745 mpol_put(vma_policy(new));
746 @@ -2837,7 +2837,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
747 if (anon_vma_clone(new_vma, vma))
748 goto out_free_mempol;
749 if (new_vma->vm_file)
750 - get_file(new_vma->vm_file);
751 + vma_get_file(new_vma);
752 if (new_vma->vm_ops && new_vma->vm_ops->open)
753 new_vma->vm_ops->open(new_vma);
754 vma_link(mm, new_vma, prev, rb_link, rb_parent);
755 diff --git a/mm/msync.c b/mm/msync.c
756 index 632df45..02d770e 100644
759 @@ -80,10 +80,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
761 if ((flags & MS_SYNC) && file &&
762 (vma->vm_flags & VM_SHARED)) {
765 up_read(&mm->mmap_sem);
766 error = vfs_fsync(file, 0);
769 if (error || start >= end)
771 down_read(&mm->mmap_sem);
772 diff --git a/mm/nommu.c b/mm/nommu.c
773 index 8740213..ea7e336 100644
776 @@ -653,7 +653,7 @@ static void __put_nommu_region(struct vm_region *region)
777 up_write(&nommu_region_sem);
780 - fput(region->vm_file);
783 /* IO memory and memory shared directly out of the pagecache
784 * from ramfs/tmpfs mustn't be released here */
785 @@ -811,7 +811,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
786 if (vma->vm_ops && vma->vm_ops->close)
787 vma->vm_ops->close(vma);
789 - fput(vma->vm_file);
791 put_nommu_region(vma->vm_region);
792 kmem_cache_free(vm_area_cachep, vma);
794 @@ -1377,7 +1377,7 @@ unsigned long do_mmap_pgoff(struct file *file,
795 goto error_just_free;
798 - fput(region->vm_file);
800 kmem_cache_free(vm_region_jar, region);
803 @@ -1453,10 +1453,10 @@ error_just_free:
804 up_write(&nommu_region_sem);
807 - fput(region->vm_file);
809 kmem_cache_free(vm_region_jar, region);
811 - fput(vma->vm_file);
813 kmem_cache_free(vm_area_cachep, vma);
814 kleave(" = %d", ret);
816 aufs3.14 standalone patch
818 diff --git a/fs/inode.c b/fs/inode.c
819 index bc83168..6dd1207 100644
822 @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
823 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
825 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
826 +EXPORT_SYMBOL(inode_sb_list_lock);
829 * Empty aops. Can be used for the cases where the user does not
830 @@ -1513,6 +1514,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
831 mark_inode_dirty_sync(inode);
834 +EXPORT_SYMBOL(update_time);
837 * touch_atime - update the access time
838 diff --git a/fs/namespace.c b/fs/namespace.c
839 index 2ffc5a2..785a51f 100644
842 @@ -455,6 +455,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
843 mnt_dec_writers(real_mount(mnt));
846 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
849 * mnt_drop_write - give up write access to a mount
850 @@ -1555,6 +1556,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
854 +EXPORT_SYMBOL(iterate_mounts);
856 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
858 diff --git a/fs/notify/group.c b/fs/notify/group.c
859 index ad19959..adf290d 100644
860 --- a/fs/notify/group.c
861 +++ b/fs/notify/group.c
863 #include <linux/srcu.h>
864 #include <linux/rculist.h>
865 #include <linux/wait.h>
866 +#include <linux/module.h>
868 #include <linux/fsnotify_backend.h>
869 #include "fsnotify.h"
870 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
872 atomic_inc(&group->refcnt);
874 +EXPORT_SYMBOL(fsnotify_get_group);
877 * Drop a reference to a group. Free it if it's through.
878 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
879 if (atomic_dec_and_test(&group->refcnt))
880 fsnotify_final_destroy_group(group);
882 +EXPORT_SYMBOL(fsnotify_put_group);
885 * Create a new fsnotify_group and hold a reference for the group returned.
886 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
890 +EXPORT_SYMBOL(fsnotify_alloc_group);
892 int fsnotify_fasync(int fd, struct file *file, int on)
894 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
895 index 923fe4a..176b435 100644
896 --- a/fs/notify/mark.c
897 +++ b/fs/notify/mark.c
898 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
899 mark->free_mark(mark);
902 +EXPORT_SYMBOL(fsnotify_put_mark);
905 * Any time a mark is getting freed we end up here.
906 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
907 fsnotify_destroy_mark_locked(mark, group);
908 mutex_unlock(&group->mark_mutex);
910 +EXPORT_SYMBOL(fsnotify_destroy_mark);
912 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
914 @@ -275,6 +277,7 @@ err:
918 +EXPORT_SYMBOL(fsnotify_add_mark);
920 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
921 struct inode *inode, struct vfsmount *mnt, int allow_dups)
922 @@ -336,6 +339,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
923 atomic_set(&mark->refcnt, 1);
924 mark->free_mark = free_mark;
926 +EXPORT_SYMBOL(fsnotify_init_mark);
928 static int fsnotify_mark_destroy(void *ignored)
930 diff --git a/fs/open.c b/fs/open.c
931 index b9ed8b2..3ea66972 100644
934 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
935 mutex_unlock(&dentry->d_inode->i_mutex);
938 +EXPORT_SYMBOL(do_truncate);
940 long vfs_truncate(struct path *path, loff_t length)
942 diff --git a/fs/splice.c b/fs/splice.c
943 index f26cbaf..ac02366 100644
946 @@ -1124,6 +1124,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
948 return splice_write(pipe, out, ppos, len, flags);
950 +EXPORT_SYMBOL(do_splice_from);
953 * Attempt to initiate a splice from a file to a pipe.
954 @@ -1150,6 +1151,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
956 return splice_read(in, ppos, pipe, len, flags);
958 +EXPORT_SYMBOL(do_splice_to);
961 * splice_direct_to_actor - splices data directly between two non-pipes
962 diff --git a/security/commoncap.c b/security/commoncap.c
963 index b9d613e..ba3b618 100644
964 --- a/security/commoncap.c
965 +++ b/security/commoncap.c
966 @@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
970 +EXPORT_SYMBOL(cap_mmap_addr);
972 int cap_mmap_file(struct file *file, unsigned long reqprot,
973 unsigned long prot, unsigned long flags)
977 +EXPORT_SYMBOL(cap_mmap_file);
978 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
979 index d3b6d2c..5076912 100644
980 --- a/security/device_cgroup.c
981 +++ b/security/device_cgroup.c
983 #include <linux/device_cgroup.h>
984 #include <linux/cgroup.h>
985 #include <linux/ctype.h>
986 +#include <linux/export.h>
987 #include <linux/list.h>
988 #include <linux/uaccess.h>
989 #include <linux/seq_file.h>
990 @@ -744,6 +745,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
991 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
994 +EXPORT_SYMBOL(__devcgroup_inode_permission);
996 int devcgroup_inode_mknod(int mode, dev_t dev)
998 diff --git a/security/security.c b/security/security.c
999 index 919cad9..f9e9e17 100644
1000 --- a/security/security.c
1001 +++ b/security/security.c
1002 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
1004 return security_ops->path_rmdir(dir, dentry);
1006 +EXPORT_SYMBOL(security_path_rmdir);
1008 int security_path_unlink(struct path *dir, struct dentry *dentry)
1010 @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
1012 return security_ops->path_symlink(dir, dentry, old_name);
1014 +EXPORT_SYMBOL(security_path_symlink);
1016 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
1017 struct dentry *new_dentry)
1018 @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
1020 return security_ops->path_link(old_dentry, new_dir, new_dentry);
1022 +EXPORT_SYMBOL(security_path_link);
1024 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
1025 struct path *new_dir, struct dentry *new_dentry)
1026 @@ -449,6 +452,7 @@ int security_path_truncate(struct path *path)
1028 return security_ops->path_truncate(path);
1030 +EXPORT_SYMBOL(security_path_truncate);
1032 int security_path_chmod(struct path *path, umode_t mode)
1034 @@ -456,6 +460,7 @@ int security_path_chmod(struct path *path, umode_t mode)
1036 return security_ops->path_chmod(path, mode);
1038 +EXPORT_SYMBOL(security_path_chmod);
1040 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
1042 @@ -463,6 +468,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
1044 return security_ops->path_chown(path, uid, gid);
1046 +EXPORT_SYMBOL(security_path_chown);
1048 int security_path_chroot(struct path *path)
1050 @@ -539,6 +545,7 @@ int security_inode_readlink(struct dentry *dentry)
1052 return security_ops->inode_readlink(dentry);
1054 +EXPORT_SYMBOL(security_inode_readlink);
1056 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
1058 @@ -553,6 +560,7 @@ int security_inode_permission(struct inode *inode, int mask)
1060 return security_ops->inode_permission(inode, mask);
1062 +EXPORT_SYMBOL(security_inode_permission);
1064 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1066 @@ -675,6 +683,7 @@ int security_file_permission(struct file *file, int mask)
1068 return fsnotify_perm(file, mask);
1070 +EXPORT_SYMBOL(security_file_permission);
1072 int security_file_alloc(struct file *file)
1074 @@ -735,6 +744,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1076 return ima_file_mmap(file, prot);
1078 +EXPORT_SYMBOL(security_mmap_file);
1080 int security_mmap_addr(unsigned long addr)
1082 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1083 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1084 +++ linux/Documentation/ABI/testing/debugfs-aufs 2014-04-24 22:11:10.471931783 +0200
1086 +What: /debug/aufs/si_<id>/
1088 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1090 + Under /debug/aufs, a directory named si_<id> is created
1091 + per aufs mount, where <id> is a unique id generated
1094 +What: /debug/aufs/si_<id>/plink
1096 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1098 + It has three lines and shows the information about the
1099 + pseudo-link. The first line is a single number
1100 + representing a number of buckets. The second line is a
1101 + number of pseudo-links per buckets (separated by a
1102 + blank). The last line is a single number representing a
1103 + total number of psedo-links.
1104 + When the aufs mount option 'noplink' is specified, it
1105 + will show "1\n0\n0\n".
1107 +What: /debug/aufs/si_<id>/xib
1109 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1111 + It shows the consumed blocks by xib (External Inode Number
1112 + Bitmap), its block size and file size.
1113 + When the aufs mount option 'noxino' is specified, it
1114 + will be empty. About XINO files, see the aufs manual.
1116 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1118 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1120 + It shows the consumed blocks by xino (External Inode Number
1121 + Translation Table), its link count, block size and file
1123 + When the aufs mount option 'noxino' is specified, it
1124 + will be empty. About XINO files, see the aufs manual.
1126 +What: /debug/aufs/si_<id>/xigen
1128 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1130 + It shows the consumed blocks by xigen (External Inode
1131 + Generation Table), its block size and file size.
1132 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1134 + When the aufs mount option 'noxino' is specified, it
1135 + will be empty. About XINO files, see the aufs manual.
1136 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1137 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1138 +++ linux/Documentation/ABI/testing/sysfs-aufs 2014-04-24 22:11:10.471931783 +0200
1140 +What: /sys/fs/aufs/si_<id>/
1142 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1144 + Under /sys/fs/aufs, a directory named si_<id> is created
1145 + per aufs mount, where <id> is a unique id generated
1148 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1150 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1152 + It shows the abolute path of a member directory (which
1153 + is called branch) in aufs, and its permission.
1155 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1157 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1159 + It shows the id of a member directory (which is called
1162 +What: /sys/fs/aufs/si_<id>/xi_path
1164 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1166 + It shows the abolute path of XINO (External Inode Number
1167 + Bitmap, Translation Table and Generation Table) file
1168 + even if it is the default path.
1169 + When the aufs mount option 'noxino' is specified, it
1170 + will be empty. About XINO files, see the aufs manual.
1171 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1172 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1173 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2014-04-24 22:11:10.471931783 +0200
1176 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1178 +# This program is free software; you can redistribute it and/or modify
1179 +# it under the terms of the GNU General Public License as published by
1180 +# the Free Software Foundation; either version 2 of the License, or
1181 +# (at your option) any later version.
1183 +# This program is distributed in the hope that it will be useful,
1184 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1185 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1186 +# GNU General Public License for more details.
1188 +# You should have received a copy of the GNU General Public License
1189 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1192 +----------------------------------------
1194 +aufs [ei ju: ef es] | [a u f s]
1195 +1. abbrev. for "advanced multi-layered unification filesystem".
1196 +2. abbrev. for "another unionfs".
1197 +3. abbrev. for "auf das" in German which means "on the" in English.
1198 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1199 + But "Filesystem aufs Filesystem" is hard to understand.
1201 +AUFS is a filesystem with features:
1202 +- multi layered stackable unification filesystem, the member directory
1203 + is called as a branch.
1204 +- branch permission and attribute, 'readonly', 'real-readonly',
1205 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
1207 +- internal "file copy-on-write".
1208 +- logical deletion, whiteout.
1209 +- dynamic branch manipulation, adding, deleting and changing permission.
1210 +- allow bypassing aufs, user's direct branch access.
1211 +- external inode number translation table and bitmap which maintains the
1212 + persistent aufs inode number.
1213 +- seekable directory, including NFS readdir.
1214 +- file mapping, mmap and sharing pages.
1215 +- pseudo-link, hardlink over branches.
1216 +- loopback mounted filesystem as a branch.
1217 +- several policies to select one among multiple writable branches.
1218 +- revert a single systemcall when an error occurs in aufs.
1222 +Multi Layered Stackable Unification Filesystem
1223 +----------------------------------------------------------------------
1224 +Most people already knows what it is.
1225 +It is a filesystem which unifies several directories and provides a
1226 +merged single directory. When users access a file, the access will be
1227 +passed/re-directed/converted (sorry, I am not sure which English word is
1228 +correct) to the real file on the member filesystem. The member
1229 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1230 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1231 +readonly branch is handled by creating 'whiteout' on the upper writable
1234 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1235 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1236 +different approaches to implement the merged-view.
1237 +The former tries putting it into VFS, and the latter implements as a
1238 +separate filesystem.
1239 +(If I misunderstand about these implementations, please let me know and
1240 +I shall correct it. Because it is a long time ago when I read their
1241 +source files last time).
1243 +UnionMount's approach will be able to small, but may be hard to share
1244 +branches between several UnionMount since the whiteout in it is
1245 +implemented in the inode on branch filesystem and always
1246 +shared. According to Bharata's post, readdir does not seems to be
1248 +There are several missing features known in this implementations such as
1249 +- for users, the inode number may change silently. eg. copy-up.
1250 +- link(2) may break by copy-up.
1251 +- read(2) may get an obsoleted filedata (fstat(2) too).
1252 +- fcntl(F_SETLK) may be broken by copy-up.
1253 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1256 +Unionfs has a longer history. When I started implementing a stacking filesystem
1257 +(Aug 2005), it already existed. It has virtual super_block, inode,
1258 +dentry and file objects and they have an array pointing lower same kind
1259 +objects. After contributing many patches for Unionfs, I re-started my
1260 +project AUFS (Jun 2006).
1262 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1263 +implemented my own ideas, approaches and enhancements and it became
1264 +totally different one.
1266 +Comparing DM snapshot and fs based implementation
1267 +- the number of bytes to be copied between devices is much smaller.
1268 +- the type of filesystem must be one and only.
1269 +- the fs must be writable, no readonly fs, even for the lower original
1270 + device. so the compression fs will not be usable. but if we use
1271 + loopback mount, we may address this issue.
1273 + mount /cdrom/squashfs.img /sq
1274 + losetup /sq/ext2.img
1275 + losetup /somewhere/cow
1276 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1277 +- it will be difficult (or needs more operations) to extract the
1278 + difference between the original device and COW.
1279 +- DM snapshot-merge may help a lot when users try merging. in the
1280 + fs-layer union, users will use rsync(1).
1283 +Several characters/aspects of aufs
1284 +----------------------------------------------------------------------
1286 +Aufs has several characters or aspects.
1287 +1. a filesystem, callee of VFS helper
1288 +2. sub-VFS, caller of VFS helper for branches
1289 +3. a virtual filesystem which maintains persistent inode number
1290 +4. reader/writer of files on branches such like an application
1292 +1. Callee of VFS Helper
1293 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1294 +unlink(2) from an application reaches sys_unlink() kernel function and
1295 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1296 +calls filesystem specific unlink operation. Actually aufs implements the
1297 +unlink operation but it behaves like a redirector.
1299 +2. Caller of VFS Helper for Branches
1300 +aufs_unlink() passes the unlink request to the branch filesystem as if
1301 +it were called from VFS. So the called unlink operation of the branch
1302 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1303 +every necessary pre/post operation for the branch filesystem.
1304 +- acquire the lock for the parent dir on a branch
1305 +- lookup in a branch
1306 +- revalidate dentry on a branch
1307 +- mnt_want_write() for a branch
1308 +- vfs_unlink() for a branch
1309 +- mnt_drop_write() for a branch
1310 +- release the lock on a branch
1312 +3. Persistent Inode Number
1313 +One of the most important issue for a filesystem is to maintain inode
1314 +numbers. This is particularly important to support exporting a
1315 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1316 +backend block device for its own. But some storage is necessary to
1317 +maintain inode number. It may be a large space and may not suit to keep
1318 +in memory. Aufs rents some space from its first writable branch
1319 +filesystem (by default) and creates file(s) on it. These files are
1320 +created by aufs internally and removed soon (currently) keeping opened.
1321 +Note: Because these files are removed, they are totally gone after
1322 + unmounting aufs. It means the inode numbers are not persistent
1323 + across unmount or reboot. I have a plan to make them really
1324 + persistent which will be important for aufs on NFS server.
1326 +4. Read/Write Files Internally (copy-on-write)
1327 +Because a branch can be readonly, when you write a file on it, aufs will
1328 +"copy-up" it to the upper writable branch internally. And then write the
1329 +originally requested thing to the file. Generally kernel doesn't
1330 +open/read/write file actively. In aufs, even a single write may cause a
1331 +internal "file copy". This behaviour is very similar to cp(1) command.
1333 +Some people may think it is better to pass such work to user space
1334 +helper, instead of doing in kernel space. Actually I am still thinking
1335 +about it. But currently I have implemented it in kernel space.
1336 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1337 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1338 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2014-04-24 22:11:10.471931783 +0200
1341 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1343 +# This program is free software; you can redistribute it and/or modify
1344 +# it under the terms of the GNU General Public License as published by
1345 +# the Free Software Foundation; either version 2 of the License, or
1346 +# (at your option) any later version.
1348 +# This program is distributed in the hope that it will be useful,
1349 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1350 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1351 +# GNU General Public License for more details.
1353 +# You should have received a copy of the GNU General Public License
1354 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1356 +Basic Aufs Internal Structure
1358 +Superblock/Inode/Dentry/File Objects
1359 +----------------------------------------------------------------------
1360 +As like an ordinary filesystem, aufs has its own
1361 +superblock/inode/dentry/file objects. All these objects have a
1362 +dynamically allocated array and store the same kind of pointers to the
1363 +lower filesystem, branch.
1364 +For example, when you build a union with one readwrite branch and one
1365 +readonly, mounted /au, /rw and /ro respectively.
1367 +- /ro/fileA exists but /rw/fileA
1369 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1370 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1374 +This style of an array is essentially same to the aufs
1375 +superblock/inode/dentry/file objects.
1377 +Because aufs supports manipulating branches, ie. add/delete/change
1378 +dynamically, these objects has its own generation. When branches are
1379 +changed, the generation in aufs superblock is incremented. And a
1380 +generation in other object are compared when it is accessed.
1381 +When a generation in other objects are obsoleted, aufs refreshes the
1386 +----------------------------------------------------------------------
1387 +Additionally aufs superblock has some data for policies to select one
1388 +among multiple writable branches, XIB files, pseudo-links and kobject.
1389 +See below in detail.
1390 +About the policies which supports copy-down a directory, see policy.txt
1394 +Branch and XINO(External Inode Number Translation Table)
1395 +----------------------------------------------------------------------
1396 +Every branch has its own xino (external inode number translation table)
1397 +file. The xino file is created and unlinked by aufs internally. When two
1398 +members of a union exist on the same filesystem, they share the single
1400 +The struct of a xino file is simple, just a sequence of aufs inode
1401 +numbers which is indexed by the lower inode number.
1402 +In the above sample, assume the inode number of /ro/fileA is i111 and
1403 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1404 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1406 +When the inode numbers are not contiguous, the xino file will be sparse
1407 +which has a hole in it and doesn't consume as much disk space as it
1408 +might appear. If your branch filesystem consumes disk space for such
1409 +holes, then you should specify 'xino=' option at mounting aufs.
1411 +Also a writable branch has three kinds of "whiteout bases". All these
1412 +are existed when the branch is joined to aufs and the names are
1413 +whiteout-ed doubly, so that users will never see their names in aufs
1415 +1. a regular file which will be linked to all whiteouts.
1416 +2. a directory to store a pseudo-link.
1417 +3. a directory to store an "orphan-ed" file temporary.
1420 + When you remove a file on a readonly branch, aufs handles it as a
1421 + logical deletion and creates a whiteout on the upper writable branch
1422 + as a hardlink of this file in order not to consume inode on the
1425 + See below, Pseudo-link.
1427 + When "fileC" exists on the lower readonly branch only and it is
1428 + opened and removed with its parent dir, and then user writes
1429 + something into it, then aufs copies-up fileC to this
1430 + directory. Because there is no other dir to store fileC. After
1431 + creating a file under this dir, the file is unlinked.
1433 +Because aufs supports manipulating branches, ie. add/delete/change
1434 +dynamically, a branch has its own id. When the branch order changes, aufs
1435 +finds the new index by searching the branch id.
1439 +----------------------------------------------------------------------
1440 +Assume "fileA" exists on the lower readonly branch only and it is
1441 +hardlinked to "fileB" on the branch. When you write something to fileA,
1442 +aufs copies-up it to the upper writable branch. Additionally aufs
1443 +creates a hardlink under the Pseudo-link Directory of the writable
1444 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1445 +simple list. If fileB is read after unlinking fileA, aufs returns
1446 +filedata from the pseudo-link instead of the lower readonly
1447 +branch. Because the pseudo-link is based upon the inode, to keep the
1448 +inode number by xino (see above) is important.
1450 +All the hardlinks under the Pseudo-link Directory of the writable branch
1451 +should be restored in a proper location later. Aufs provides a utility
1452 +to do this. The userspace helpers executed at remounting and unmounting
1454 +During this utility is running, it puts aufs into the pseudo-link
1455 +maintenance mode. In this mode, only the process which began the
1456 +maintenance mode (and its child processes) is allowed to operate in
1457 +aufs. Some other processes which are not related to the pseudo-link will
1458 +be allowed to run too, but the rest have to return an error or wait
1459 +until the maintenance mode ends. If a process already acquires an inode
1460 +mutex (in VFS), it has to return an error.
1463 +XIB(external inode number bitmap)
1464 +----------------------------------------------------------------------
1465 +Addition to the xino file per a branch, aufs has an external inode number
1466 +bitmap in a superblock object. It is also a file such like a xino file.
1467 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1469 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1471 +Aufs implements a feature to truncate/refresh both of xino and xib to
1472 +reduce the number of consumed disk blocks for these files.
1475 +Virtual or Vertical Dir, and Readdir in Userspace
1476 +----------------------------------------------------------------------
1477 +In order to support multiple layers (branches), aufs readdir operation
1478 +constructs a virtual dir block on memory. For readdir, aufs calls
1479 +vfs_readdir() internally for each dir on branches, merges their entries
1480 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1481 +object. So the file object has its entry list until it is closed. The
1482 +entry list will be updated when the file position is zero and becomes
1483 +old. This decision is made in aufs automatically.
1485 +The dynamically allocated memory block for the name of entries has a
1486 +unit of 512 bytes (by default) and stores the names contiguously (no
1487 +padding). Another block for each entry is handled by kmem_cache too.
1488 +During building dir blocks, aufs creates hash list and judging whether
1489 +the entry is whiteouted by its upper branch or already listed.
1490 +The merged result is cached in the corresponding inode object and
1491 +maintained by a customizable life-time option.
1493 +Some people may call it can be a security hole or invite DoS attack
1494 +since the opened and once readdir-ed dir (file object) holds its entry
1495 +list and becomes a pressure for system memory. But I'd say it is similar
1496 +to files under /proc or /sys. The virtual files in them also holds a
1497 +memory page (generally) while they are opened. When an idea to reduce
1498 +memory for them is introduced, it will be applied to aufs too.
1499 +For those who really hate this situation, I've developed readdir(3)
1500 +library which operates this merging in userspace. You just need to set
1501 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1502 +kernel space for readdir(3).
1506 +----------------------------------------------------------------------
1507 +Aufs sometimes requires privilege access to a branch. For instance,
1508 +in copy-up/down operation. When a user process is going to make changes
1509 +to a file which exists in the lower readonly branch only, and the mode
1510 +of one of ancestor directories may not be writable by a user
1511 +process. Here aufs copy-up the file with its ancestors and they may
1512 +require privilege to set its owner/group/mode/etc.
1513 +This is a typical case of a application character of aufs (see
1516 +Aufs uses workqueue synchronously for this case. It creates its own
1517 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1518 +passes the request to call mkdir or write (for example), and wait for
1519 +its completion. This approach solves a problem of a signal handler
1521 +If aufs didn't adopt the workqueue and changed the privilege of the
1522 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
1523 +then the user process might gain a privilege or the generated core file
1524 +was owned by a superuser.
1526 +Also aufs uses the system global workqueue ("events" kernel thread) too
1527 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1528 +whiteout base and etc. This is unrelated to a privilege.
1529 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1530 +superblock at the beginning, at the same time waits for the completion
1531 +of all queued asynchronous tasks.
1535 +----------------------------------------------------------------------
1536 +The whiteout in aufs is very similar to Unionfs's. That is represented
1537 +by its filename. UnionMount takes an approach of a file mode, but I am
1538 +afraid several utilities (find(1) or something) will have to support it.
1540 +Basically the whiteout represents "logical deletion" which stops aufs to
1541 +lookup further, but also it represents "dir is opaque" which also stop
1544 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1545 +In order to make several functions in a single systemcall to be
1546 +revertible, aufs adopts an approach to rename a directory to a temporary
1547 +unique whiteouted name.
1548 +For example, in rename(2) dir where the target dir already existed, aufs
1549 +renames the target dir to a temporary unique whiteouted name before the
1550 +actual rename on a branch and then handles other actions (make it opaque,
1551 +update the attributes, etc). If an error happens in these actions, aufs
1552 +simply renames the whiteouted name back and returns an error. If all are
1553 +succeeded, aufs registers a function to remove the whiteouted unique
1554 +temporary name completely and asynchronously to the system global
1559 +----------------------------------------------------------------------
1560 +It is a well-known feature or concept.
1561 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1562 +internally and makes change to the new file on the upper writable branch.
1563 +When the trigger systemcall does not update the timestamps of the parent
1564 +dir, aufs reverts it after copy-up.
1567 +Move-down (aufs3.9 and later)
1568 +----------------------------------------------------------------------
1569 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1570 +the lower readonly branch to the upper writable branch when a user
1571 +changes something about the file.
1572 +"Move-down" is an opposite action of copy-up. Basically this action is
1573 +ran manually instead of automatically and internally.
1575 +Sometimes users want to move-down a file from the upper writable branch
1576 +to the lower readonly or writable branch. For instance,
1577 +- the free space of the upper writable branch is going to run out.
1578 +- create a new intermediate branch between the upper and lower branch.
1581 +For this purpose, use "aumvdown" command in aufs-util.git.
1582 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1583 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1584 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2014-04-24 22:11:10.471931783 +0200
1587 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1589 +# This program is free software; you can redistribute it and/or modify
1590 +# it under the terms of the GNU General Public License as published by
1591 +# the Free Software Foundation; either version 2 of the License, or
1592 +# (at your option) any later version.
1594 +# This program is distributed in the hope that it will be useful,
1595 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1596 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1597 +# GNU General Public License for more details.
1599 +# You should have received a copy of the GNU General Public License
1600 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1603 +----------------------------------------------------------------------
1604 +Since aufs has a character of sub-VFS (see Introduction), it operates
1605 +lookup for branches as VFS does. It may be a heavy work. Generally
1606 +speaking struct nameidata is a bigger structure and includes many
1607 +information. But almost all lookup operation in aufs is the simplest
1608 +case, ie. lookup only an entry directly connected to its parent. Digging
1609 +down the directory hierarchy is unnecessary.
1611 +VFS has a function lookup_one_len() for that use, but it is not usable
1612 +for a branch filesystem which requires struct nameidata. So aufs
1613 +implements a simple lookup wrapper function. When a branch filesystem
1614 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
1615 +a simplest nameidata and calls lookup_hash().
1616 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
1617 +NFS-export, then it has to support NULL as a nameidata parameter for
1618 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
1619 +aufs tests if ->s_export_op in the branch is NULL or not.
1621 +When a branch is a remote filesystem, aufs basically trusts its
1622 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1624 +For d_revalidate, aufs implements three levels of revalidate tests. See
1625 +"Revalidate Dentry and UDBA" in detail.
1629 +----------------------------------------------------------------------
1630 +Basically aufs supports any type of filesystem and block device for a
1631 +branch (actually there are some exceptions). But it is prohibited to add
1632 +a loopback mounted one whose backend file exists in a filesystem which is
1633 +already added to aufs. The reason is to protect aufs from a recursive
1634 +lookup. If it was allowed, the aufs lookup operation might re-enter a
1635 +lookup for the loopback mounted branch in the same context, and will
1639 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1640 +----------------------------------------------------------------------
1641 +Generally VFS helpers re-validate a dentry as a part of lookup.
1642 +0. digging down the directory hierarchy.
1643 +1. lock the parent dir by its i_mutex.
1644 +2. lookup the final (child) entry.
1646 +4. call the actual operation (create, unlink, etc.)
1647 +5. unlock the parent dir
1649 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1650 +called. Actually aufs implements it and checks the dentry on a branch is
1652 +But it is not enough. Because aufs has to release the lock for the
1653 +parent dir on a branch at the end of ->lookup() (step 2) and
1654 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1656 +If the file on a branch is changed directly, eg. bypassing aufs, after
1657 +aufs released the lock, then the subsequent operation may cause
1658 +something unpleasant result.
1660 +This situation is a result of VFS architecture, ->lookup() and
1661 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1662 +design from VFS's point of view. It is just not suitable for sub-VFS
1665 +Aufs supports such case by three level of revalidation which is
1666 +selectable by user.
1667 +1. Simple Revalidate
1668 + Addition to the native flow in VFS's, confirm the child-parent
1669 + relationship on the branch just after locking the parent dir on the
1670 + branch in the "actual operation" (step 4). When this validation
1671 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1672 + checks the validation of the dentry on branches.
1673 +2. Monitor Changes Internally by Inotify/Fsnotify
1674 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1675 + the dentry on the branch, and returns EBUSY if it finds different
1677 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1678 + during it is in cache. When the event is notified, aufs registers a
1679 + function to kernel 'events' thread by schedule_work(). And the
1680 + function sets some special status to the cached aufs dentry and inode
1681 + private data. If they are not cached, then aufs has nothing to
1682 + do. When the same file is accessed through aufs (step 0-3) later,
1683 + aufs will detect the status and refresh all necessary data.
1684 + In this mode, aufs has to ignore the event which is fired by aufs
1686 +3. No Extra Validation
1687 + This is the simplest test and doesn't add any additional revalidation
1688 + test, and skip therevalidatin in step 4. It is useful and improves
1689 + aufs performance when system surely hide the aufs branches from user,
1690 + by over-mounting something (or another method).
1691 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1692 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1693 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2014-04-24 22:11:10.471931783 +0200
1696 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1698 +# This program is free software; you can redistribute it and/or modify
1699 +# it under the terms of the GNU General Public License as published by
1700 +# the Free Software Foundation; either version 2 of the License, or
1701 +# (at your option) any later version.
1703 +# This program is distributed in the hope that it will be useful,
1704 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1705 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1706 +# GNU General Public License for more details.
1708 +# You should have received a copy of the GNU General Public License
1709 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1711 +Branch Manipulation
1713 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1714 +and changing its permission/attribute, there are a lot of works to do.
1718 +----------------------------------------------------------------------
1719 +o Confirm the adding dir exists outside of aufs, including loopback
1721 +- and other various attributes...
1722 +o Initialize the xino file and whiteout bases if necessary.
1725 +o Check the owner/group/mode of the directory
1726 + When the owner/group/mode of the adding directory differs from the
1727 + existing branch, aufs issues a warning because it may impose a
1729 + For example, when a upper writable branch has a world writable empty
1730 + top directory, a malicious user can create any files on the writable
1731 + branch directly, like copy-up and modify manually. If something like
1732 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1733 + writable branch, and the writable branch is world-writable, then a
1734 + malicious guy may create /etc/passwd on the writable branch directly
1735 + and the infected file will be valid in aufs.
1736 + I am afraid it can be a security issue, but nothing to do except
1737 + producing a warning.
1741 +----------------------------------------------------------------------
1742 +o Confirm the deleting branch is not busy
1743 + To be general, there is one merit to adopt "remount" interface to
1744 + manipulate branches. It is to discard caches. At deleting a branch,
1745 + aufs checks the still cached (and connected) dentries and inodes. If
1746 + there are any, then they are all in-use. An inode without its
1747 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1749 + For the cached one, aufs checks whether the same named entry exists on
1751 + If the cached one is a directory, because aufs provides a merged view
1752 + to users, as long as one dir is left on any branch aufs can show the
1753 + dir to users. In this case, the branch can be removed from aufs.
1754 + Otherwise aufs rejects deleting the branch.
1756 + If any file on the deleting branch is opened by aufs, then aufs
1760 +Modify the Permission of a Branch
1761 +----------------------------------------------------------------------
1762 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1765 +o rw --> ro: Confirm the modifying branch is not busy
1766 + Aufs rejects the request if any of these conditions are true.
1767 + - a file on the branch is mmap-ed.
1768 + - a regular file on the branch is opened for write and there is no
1769 + same named entry on the upper branch.
1770 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1771 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1772 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2014-04-24 22:11:10.471931783 +0200
1775 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1777 +# This program is free software; you can redistribute it and/or modify
1778 +# it under the terms of the GNU General Public License as published by
1779 +# the Free Software Foundation; either version 2 of the License, or
1780 +# (at your option) any later version.
1782 +# This program is distributed in the hope that it will be useful,
1783 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1784 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1785 +# GNU General Public License for more details.
1787 +# You should have received a copy of the GNU General Public License
1788 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1790 +Policies to Select One among Multiple Writable Branches
1791 +----------------------------------------------------------------------
1792 +When the number of writable branch is more than one, aufs has to decide
1793 +the target branch for file creation or copy-up. By default, the highest
1794 +writable branch which has the parent (or ancestor) dir of the target
1795 +file is chosen (top-down-parent policy).
1796 +By user's request, aufs implements some other policies to select the
1797 +writable branch, for file creation two policies, round-robin and
1798 +most-free-space policies. For copy-up three policies, top-down-parent,
1799 +bottom-up-parent and bottom-up policies.
1801 +As expected, the round-robin policy selects the branch in circular. When
1802 +you have two writable branches and creates 10 new files, 5 files will be
1803 +created for each branch. mkdir(2) systemcall is an exception. When you
1804 +create 10 new directories, all will be created on the same branch.
1805 +And the most-free-space policy selects the one which has most free
1806 +space among the writable branches. The amount of free space will be
1807 +checked by aufs internally, and users can specify its time interval.
1809 +The policies for copy-up is more simple,
1810 +top-down-parent is equivalent to the same named on in create policy,
1811 +bottom-up-parent selects the writable branch where the parent dir
1812 +exists and the nearest upper one from the copyup-source,
1813 +bottom-up selects the nearest upper writable branch from the
1814 +copyup-source, regardless the existence of the parent dir.
1816 +There are some rules or exceptions to apply these policies.
1817 +- If there is a readonly branch above the policy-selected branch and
1818 + the parent dir is marked as opaque (a variation of whiteout), or the
1819 + target (creating) file is whiteout-ed on the upper readonly branch,
1820 + then the result of the policy is ignored and the target file will be
1821 + created on the nearest upper writable branch than the readonly branch.
1822 +- If there is a writable branch above the policy-selected branch and
1823 + the parent dir is marked as opaque or the target file is whiteouted
1824 + on the branch, then the result of the policy is ignored and the target
1825 + file will be created on the highest one among the upper writable
1826 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1828 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1829 + They try selecting the branch where the source exists as possible
1830 + since copyup a large file will take long time. If it can't be,
1831 + ie. the branch where the source exists is readonly, then they will
1832 + follow the copyup policy.
1833 +- There is an exception for rename(2) when the target exists.
1834 + If the rename target exists, aufs compares the index of the branches
1835 + where the source and the target exists and selects the higher
1836 + one. If the selected branch is readonly, then aufs follows the
1838 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1839 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1840 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2014-04-24 22:11:10.471931783 +0200
1843 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1845 +# This program is free software; you can redistribute it and/or modify
1846 +# it under the terms of the GNU General Public License as published by
1847 +# the Free Software Foundation; either version 2 of the License, or
1848 +# (at your option) any later version.
1850 +# This program is distributed in the hope that it will be useful,
1851 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1852 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1853 +# GNU General Public License for more details.
1855 +# You should have received a copy of the GNU General Public License
1856 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1858 +mmap(2) -- File Memory Mapping
1859 +----------------------------------------------------------------------
1860 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1861 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1863 +This approach is simple and good, but there is one problem.
1864 +Under /proc, several entries show the mmap-ped files by its path (with
1865 +device and inode number), and the printed path will be the path on the
1866 +branch fs's instead of virtual aufs's.
1867 +This is not a problem in most cases, but some utilities lsof(1) (and its
1868 +user) may expect the path on aufs.
1870 +To address this issue, aufs adds a new member called vm_prfile in struct
1871 +vm_area_struct (and struct vm_region). The original vm_file points to
1872 +the file on the branch fs in order to handle everything correctly as
1873 +usual. The new vm_prfile points to a virtual file in aufs, and the
1874 +show-functions in procfs refers to vm_prfile if it is set.
1875 +Also we need to maintain several other places where touching vm_file
1877 +- fork()/clone() copies vma and the reference count of vm_file is
1879 +- merging vma maintains the ref count too.
1881 +This is not a good approach. It just faking the printed path. But it
1882 +leaves all behaviour around f_mapping unchanged. This is surely an
1884 +Actually aufs had adopted another complicated approach which calls
1885 +generic_file_mmap() and handles struct vm_operations_struct. In this
1886 +approach, aufs met a hard problem and I could not solve it without
1887 +switching the approach.
1888 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1889 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1890 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2014-04-24 22:11:10.471931783 +0200
1893 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1895 +# This program is free software; you can redistribute it and/or modify
1896 +# it under the terms of the GNU General Public License as published by
1897 +# the Free Software Foundation; either version 2 of the License, or
1898 +# (at your option) any later version.
1900 +# This program is distributed in the hope that it will be useful,
1901 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1902 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1903 +# GNU General Public License for more details.
1905 +# You should have received a copy of the GNU General Public License
1906 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1908 +Export Aufs via NFS
1909 +----------------------------------------------------------------------
1910 +Here is an approach.
1911 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1913 +- iget_locked(): initialize aufs inode generation for a new inode, and
1914 + store it in xigen file.
1915 +- destroy_inode(): increment aufs inode generation and store it in xigen
1916 + file. it is necessary even if it is not unlinked, because any data of
1917 + inode may be changed by UDBA.
1918 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1919 + build file handle by
1920 + + branch id (4 bytes)
1921 + + superblock generation (4 bytes)
1922 + + inode number (4 or 8 bytes)
1923 + + parent dir inode number (4 or 8 bytes)
1924 + + inode generation (4 bytes))
1925 + + return value of exportfs_encode_fh() for the parent on a branch (4
1927 + + file handle for a branch (by exportfs_encode_fh())
1929 + + find the index of a branch from its id in handle, and check it is
1930 + still exist in aufs.
1931 + + 1st level: get the inode number from handle and search it in cache.
1932 + + 2nd level: if not found, get the parent inode number from handle and
1933 + search it in cache. and then open the parent dir, find the matching
1934 + inode number by vfs_readdir() and get its name, and call
1935 + lookup_one_len() for the target dentry.
1936 + + 3rd level: if the parent dir is not cached, call
1937 + exportfs_decode_fh() for a branch and get the parent on a branch,
1938 + build a pathname of it, convert it a pathname in aufs, call
1939 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1941 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1942 + for every branch, but not itself. to get this, (currently) aufs
1943 + searches in current->nsproxy->mnt_ns list. it may not be a good
1944 + idea, but I didn't get other approach.
1945 + + test the generation of the gotten inode.
1946 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1947 + convert it into ESTALE for NFSD.
1948 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1949 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1950 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1951 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1952 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2014-04-24 22:11:10.471931783 +0200
1955 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1957 +# This program is free software; you can redistribute it and/or modify
1958 +# it under the terms of the GNU General Public License as published by
1959 +# the Free Software Foundation; either version 2 of the License, or
1960 +# (at your option) any later version.
1962 +# This program is distributed in the hope that it will be useful,
1963 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1964 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1965 +# GNU General Public License for more details.
1967 +# You should have received a copy of the GNU General Public License
1968 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1970 +Show Whiteout Mode (shwh)
1971 +----------------------------------------------------------------------
1972 +Generally aufs hides the name of whiteouts. But in some cases, to show
1973 +them is very useful for users. For instance, creating a new middle layer
1974 +(branch) by merging existing layers.
1976 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1977 +When you have three branches,
1978 +- Bottom: 'system', squashfs (underlying base system), read-only
1979 +- Middle: 'mods', squashfs, read-only
1980 +- Top: 'overlay', ram (tmpfs), read-write
1982 +The top layer is loaded at boot time and saved at shutdown, to preserve
1983 +the changes made to the system during the session.
1984 +When larger changes have been made, or smaller changes have accumulated,
1985 +the size of the saved top layer data grows. At this point, it would be
1986 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1987 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1988 +restoring save and load speed.
1990 +This merging is simplified by the use of another aufs mount, of just the
1991 +two overlay branches using the 'shwh' option.
1992 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1993 + aufs /livesys/merge_union
1995 +A merged view of these two branches is then available at
1996 +/livesys/merge_union, and the new feature is that the whiteouts are
1998 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1999 +writing to all branches. Also the default mode for all branches is 'ro'.
2000 +It is now possible to save the combined contents of the two overlay
2001 +branches to a new squashfs, e.g.:
2002 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2004 +This new squashfs archive can be stored on the boot device and the
2005 +initramfs will use it to replace the old one at the next boot.
2006 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2007 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2008 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2014-04-24 22:11:10.471931783 +0200
2011 +# Copyright (C) 2010-2014 Junjiro R. Okajima
2013 +# This program is free software; you can redistribute it and/or modify
2014 +# it under the terms of the GNU General Public License as published by
2015 +# the Free Software Foundation; either version 2 of the License, or
2016 +# (at your option) any later version.
2018 +# This program is distributed in the hope that it will be useful,
2019 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2020 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2021 +# GNU General Public License for more details.
2023 +# You should have received a copy of the GNU General Public License
2024 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2026 +Dynamically customizable FS operations
2027 +----------------------------------------------------------------------
2028 +Generally FS operations (struct inode_operations, struct
2029 +address_space_operations, struct file_operations, etc.) are defined as
2030 +"static const", but it never means that FS have only one set of
2031 +operation. Some FS have multiple sets of them. For instance, ext2 has
2032 +three sets, one for XIP, for NOBH, and for normal.
2033 +Since aufs overrides and redirects these operations, sometimes aufs has
2034 +to change its behaviour according to the branch FS type. More imporantly
2035 +VFS acts differently if a function (member in the struct) is set or
2036 +not. It means aufs should have several sets of operations and select one
2037 +among them according to the branch FS definition.
2039 +In order to solve this problem and not to affect the behavour of VFS,
2040 +aufs defines these operations dynamically. For instance, aufs defines
2041 +aio_read function for struct file_operations, but it may not be set to
2042 +the file_operations. When the branch FS doesn't have it, aufs doesn't
2043 +set it to its file_operations while the function definition itself is
2044 +still alive. So the behaviour of io_submit(2) will not change, and it
2045 +will return an error when aio_read is not defined.
2047 +The lifetime of these dynamically generated operation object is
2048 +maintained by aufs branch object. When the branch is removed from aufs,
2049 +the reference counter of the object is decremented. When it reaches
2050 +zero, the dynamically generated operation object will be freed.
2052 +This approach is designed to support AIO (io_submit), Direcit I/O and
2054 +Currently this approach is applied to file_operations and
2055 +vm_operations_struct for regular files only.
2056 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
2057 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
2058 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2014-04-24 22:11:10.471931783 +0200
2061 +# Copyright (C) 2005-2014 Junjiro R. Okajima
2063 +# This program is free software; you can redistribute it and/or modify
2064 +# it under the terms of the GNU General Public License as published by
2065 +# the Free Software Foundation; either version 2 of the License, or
2066 +# (at your option) any later version.
2068 +# This program is distributed in the hope that it will be useful,
2069 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2070 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2071 +# GNU General Public License for more details.
2073 +# You should have received a copy of the GNU General Public License
2074 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2078 +Restoring some features which was implemented in aufs1.
2079 +They were dropped in aufs2 in order to make source files simpler and
2080 +easier to be reviewed.
2083 +Test Only the Highest One for the Directory Permission (dirperm1 option)
2084 +----------------------------------------------------------------------
2085 +Let's try case study.
2086 +- aufs has two branches, upper readwrite and lower readonly.
2088 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
2089 +- user invoked "chmod a+rx /au/dirA"
2090 +- then "dirA" becomes world readable?
2092 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
2093 +or it may be a natively readonly filesystem. If aufs respects the lower
2094 +branch, it should not respond readdir request from other users. But user
2095 +allowed it by chmod. Should really aufs rejects showing the entries
2098 +To be honest, I don't have a best solution for this case. So I
2099 +implemented 'dirperm1' and 'nodirperm1' option in aufs1, and leave it to
2101 +When dirperm1 is specified, aufs checks only the highest one for the
2102 +directory permission, and shows the entries. Otherwise, as usual, checks
2103 +every dir existing on all branches and rejects the request.
2105 +As a side effect, dirperm1 option improves the performance of aufs
2106 +because the number of permission check is reduced.
2109 +Being Another Aufs's Readonly Branch (robr)
2110 +----------------------------------------------------------------------
2111 +Aufs1 allows aufs to be another aufs's readonly branch.
2112 +This feature was developed by a user's request. But it may not be used
2116 +Copy-up on Open (coo=)
2117 +----------------------------------------------------------------------
2118 +By default the internal copy-up is executed when it is really necessary.
2119 +It is not done when a file is opened for writing, but when write(2) is
2120 +done. Users who have many (over 100) branches want to know and analyse
2121 +when and what file is copied-up. To insert a new upper branch which
2122 +contains such files only may improve the performance of aufs.
2124 +Aufs1 implemented "coo=none | leaf | all" option.
2127 +Refresh the Opened File (refrof)
2128 +----------------------------------------------------------------------
2129 +This option is implemented in aufs1 but incomplete.
2131 +When user reads from a file, he expects to get its latest filedata
2132 +generally. If the file is removed and a new same named file is created,
2133 +the content he gets is unchanged, ie. the unlinked filedata.
2135 +Let's try case study again.
2136 +- aufs has two branches.
2138 +- "fileA" exists under /ro, but /rw.
2139 +- user opened "/au/fileA".
2140 +- he or someone else inserts a branch (/new) between /rw and /ro.
2141 + /au = /rw + /new + /ro
2142 +- the new branch has "fileA".
2143 +- user reads from the opened "fileA"
2144 +- which filedata should aufs return, from /ro or /new?
2146 +Some people says it has to be "from /ro" and it is a semantics of Unix.
2147 +The others say it should be "from /new" because the file is not removed
2148 +and it is equivalent to the case of someone else modifies the file.
2150 +Here again I don't have a best and final answer. I got an idea to
2151 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
2152 +Opened File) is specified (by default), aufs returns the filedata from
2154 +Otherwise from /new.
2155 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2156 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2157 +++ linux/Documentation/filesystems/aufs/README 2014-04-24 22:11:10.471931783 +0200
2160 +Aufs3 -- advanced multi layered unification filesystem version 3.x
2166 +----------------------------------------
2167 +In the early days, aufs was entirely re-designed and re-implemented
2168 +Unionfs Version 1.x series. After many original ideas, approaches,
2169 +improvements and implementations, it becomes totally different from
2170 +Unionfs while keeping the basic features.
2171 +Recently, Unionfs Version 2.x series begin taking some of the same
2172 +approaches to aufs1's.
2173 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2174 +University and his team.
2176 +Aufs3 supports linux-3.0 and later.
2177 +If you want older kernel version support, try aufs2-2.6.git or
2178 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2180 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2181 +According to Christoph Hellwig, linux rejects all union-type filesystems
2183 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2187 +----------------------------------------
2188 +- unite several directories into a single virtual filesystem. The member
2189 + directory is called as a branch.
2190 +- you can specify the permission flags to the branch, which are 'readonly',
2191 + 'readwrite' and 'whiteout-able.'
2192 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2193 + readonly branch are modifiable logically.
2194 +- dynamic branch manipulation, add, del.
2197 +Also there are many enhancements in aufs1, such as:
2198 +- readdir(3) in userspace.
2199 +- keep inode number by external inode number table
2200 +- keep the timestamps of file/dir in internal copyup operation
2201 +- seekable directory, supporting NFS readdir.
2202 +- whiteout is hardlinked in order to reduce the consumption of inodes
2204 +- do not copyup, nor create a whiteout when it is unnecessary
2205 +- revert a single systemcall when an error occurs in aufs
2206 +- remount interface instead of ioctl
2207 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2208 +- loopback mounted filesystem as a branch
2209 +- kernel thread for removing the dir who has a plenty of whiteouts
2210 +- support copyup sparse file (a file which has a 'hole' in it)
2211 +- default permission flags for branches
2212 +- selectable permission flags for ro branch, whether whiteout can
2215 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2216 +- support multiple writable branches, some policies to select one
2217 + among multiple writable branches.
2218 +- a new semantics for link(2) and rename(2) to support multiple
2219 + writable branches.
2220 +- no glibc changes are required.
2221 +- pseudo hardlink (hardlink over branches)
2222 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2223 + including NFS or remote filesystem branch.
2224 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2227 +Currently these features are dropped temporary from aufs3.
2228 +See design/08plan.txt in detail.
2229 +- test only the highest one for the directory permission (dirperm1)
2230 +- copyup on open (coo=)
2231 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2233 +- statistics of aufs thread (/sys/fs/aufs/stat)
2234 +- delegation mode (dlgt)
2235 + a delegation of the internal branch access to support task I/O
2236 + accounting, which also supports Linux Security Modules (LSM) mainly
2237 + for Suse AppArmor.
2238 +- intent.open/create (file open in a single lookup)
2240 +Features or just an idea in the future (see also design/*.txt),
2241 +- reorder the branch index without del/re-add.
2242 +- permanent xino files for NFSD
2243 +- an option for refreshing the opened files after add/del branches
2244 +- 'move' policy for copy-up between two writable branches, after
2245 + checking free space.
2246 +- light version, without branch manipulation. (unnecessary?)
2247 +- copyup in userspace
2248 +- inotify in userspace
2254 +----------------------------------------
2255 +There were three GIT trees for aufs3, aufs3-linux.git,
2256 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
2258 +While the aufs-util is always necessary, you need either of aufs3-linux
2259 +or aufs3-standalone.
2261 +The aufs3-linux tree includes the whole linux mainline GIT tree,
2262 +git://git.kernel.org/.../torvalds/linux.git.
2263 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2264 +build aufs3 as an external kernel module.
2266 +On the other hand, the aufs3-standalone tree has only aufs source files
2267 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2269 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
2270 +represents the linux kernel version, "linux-3.x". For instance,
2271 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
2272 +"aufs3.x-rcN" branch.
2275 +$ git clone --reference /your/linux/git/tree \
2276 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
2278 +- if you don't have linux GIT tree, then remove "--reference ..."
2279 +$ cd aufs3-linux.git
2280 +$ git checkout origin/aufs3.0
2282 +o aufs3-standalone tree
2283 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
2284 + aufs3-standalone.git
2285 +$ cd aufs3-standalone.git
2286 +$ git checkout origin/aufs3.0
2289 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
2292 +$ git checkout origin/aufs3.0
2294 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
2295 +The minor version number, 'x' in '3.x', of aufs may not always
2296 +follow the minor version number of the kernel.
2297 +Because changes in the kernel that cause the use of a new
2298 +minor version number do not always require changes to aufs-util.
2300 +Since aufs-util has its own minor version number, you may not be
2301 +able to find a GIT branch in aufs-util for your kernel's
2302 +exact minor version number.
2303 +In this case, you should git-checkout the branch for the
2304 +nearest lower number.
2306 +For (an unreleased) example:
2307 +If you are using "linux-3.10" and the "aufs3.10" branch
2308 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
2309 +or something numerically smaller is the branch for your kernel.
2311 +Also you can view all branches by
2315 +3. Configuration and Compilation
2316 +----------------------------------------
2317 +Make sure you have git-checkout'ed the correct branch.
2319 +For aufs3-linux tree,
2320 +- enable CONFIG_AUFS_FS.
2321 +- set other aufs configurations if necessary.
2323 +For aufs3-standalone tree,
2324 +There are several ways to build.
2327 +- apply ./aufs3-kbuild.patch to your kernel source files.
2328 +- apply ./aufs3-base.patch too.
2329 +- apply ./aufs3-mmap.patch too.
2330 +- apply ./aufs3-standalone.patch too, if you have a plan to set
2331 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
2332 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2333 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2334 +- enable CONFIG_AUFS_FS, you can select either
2336 +- and build your kernel as usual.
2337 +- install the built kernel.
2338 + Note: Since linux-3.9, every filesystem module requires an alias
2339 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2340 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2341 +- install the header files too by "make headers_install" to the
2342 + directory where you specify. By default, it is $PWD/usr.
2343 + "make help" shows a brief note for headers_install.
2344 +- and reboot your system.
2347 +- module only (CONFIG_AUFS_FS=m).
2348 +- apply ./aufs3-base.patch to your kernel source files.
2349 +- apply ./aufs3-mmap.patch too.
2350 +- apply ./aufs3-standalone.patch too.
2351 +- build your kernel, don't forget "make headers_install", and reboot.
2352 +- edit ./config.mk and set other aufs configurations if necessary.
2353 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2354 + every aufs configurations.
2355 +- build the module by simple "make".
2356 + Note: Since linux-3.9, every filesystem module requires an alias
2357 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2358 + modules.aliases file.
2359 +- you can specify ${KDIR} make variable which points to your kernel
2361 +- install the files
2362 + + run "make install" to install the aufs module, or copy the built
2363 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2364 + + run "make install_headers" (instead of headers_install) to install
2365 + the modified aufs header file (you can specify DESTDIR which is
2366 + available in aufs standalone version's Makefile only), or copy
2367 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2368 + you like manually. By default, the target directory is $PWD/usr.
2369 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
2370 + kernel source tree.
2372 +Note: The header file aufs_type.h is necessary to build aufs-util
2373 + as well as "make headers_install" in the kernel source tree.
2374 + headers_install is subject to be forgotten, but it is essentially
2375 + necessary, not only for building aufs-util.
2376 + You may not meet problems without headers_install in some older
2380 +- read README in aufs-util, build and install it
2381 +- note that your distribution may contain an obsoleted version of
2382 + aufs_type.h in /usr/include/linux or something. When you build aufs
2383 + utilities, make sure that your compiler refers the correct aufs header
2384 + file which is built by "make headers_install."
2385 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2386 + then run "make install_ulib" too. And refer to the aufs manual in
2391 +----------------------------------------
2392 +At first, make sure aufs-util are installed, and please read the aufs
2393 +manual, aufs.5 in aufs-util.git tree.
2397 +$ mkdir /tmp/rw /tmp/aufs
2398 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2400 +Here is another example. The result is equivalent.
2401 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2403 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2404 +# mount -o remount,append:${HOME} /tmp/aufs
2406 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2407 +you modify a file under /tmp/aufs, the one on your home directory is
2408 +not affected, instead the same named file will be newly created under
2409 +/tmp/rw. And all of your modification to a file will be applied to
2410 +the one under /tmp/rw. This is called the file based Copy on Write
2412 +Aufs mount options are described in aufs.5.
2413 +If you run chroot or something and make your aufs as a root directory,
2414 +then you need to customize the shutdown script. See the aufs manual in
2417 +Additionally, there are some sample usages of aufs which are a
2418 +diskless system with network booting, and LiveCD over NFS.
2419 +See sample dir in CVS tree on SourceForge.
2423 +----------------------------------------
2424 +When you have any problems or strange behaviour in aufs, please let me
2426 +- /proc/mounts (instead of the output of mount(8))
2427 +- /sys/module/aufs/*
2428 +- /sys/fs/aufs/* (if you have them)
2429 +- /debug/aufs/* (if you have them)
2430 +- linux kernel version
2431 + if your kernel is not plain, for example modified by distributor,
2432 + the url where i can download its source is necessary too.
2433 +- aufs version which was printed at loading the module or booting the
2434 + system, instead of the date you downloaded.
2435 +- configuration (define/undefine CONFIG_AUFS_xxx)
2436 +- kernel configuration or /proc/config.gz (if you have it)
2437 +- behaviour which you think to be incorrect
2438 +- actual operation, reproducible one is better
2439 +- mailto: aufs-users at lists.sourceforge.net
2441 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2442 +and Feature Requests) on SourceForge. Please join and write to
2446 +6. Acknowledgements
2447 +----------------------------------------
2448 +Thanks to everyone who have tried and are using aufs, whoever
2449 +have reported a bug or any feedback.
2451 +Especially donators:
2452 +Tomas Matejicek(slax.org) made a donation (much more than once).
2453 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2454 + scripts) is making "doubling" donations.
2455 + Unfortunately I cannot list all of the donators, but I really
2457 + It ends Aug 2010, but the ordinary donation URL is still available.
2458 + <http://sourceforge.net/donate/index.php?group_id=167503>
2459 +Dai Itasaka made a donation (2007/8).
2460 +Chuck Smith made a donation (2008/4, 10 and 12).
2461 +Henk Schoneveld made a donation (2008/9).
2462 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2463 +Francois Dupoux made a donation (2008/11).
2464 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2465 + aufs2 GIT tree (2009/2).
2466 +William Grant made a donation (2009/3).
2467 +Patrick Lane made a donation (2009/4).
2468 +The Mail Archive (mail-archive.com) made donations (2009/5).
2469 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2470 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2471 +Pavel Pronskiy made a donation (2011/2).
2472 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2473 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2474 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2476 +Sam Liddicott made a donation (2011/9).
2477 +Era Scarecrow made a donation (2013/4).
2478 +Bor Ratajc made a donation (2013/4).
2479 +Alessandro Gorreta made a donation (2013/4).
2480 +POIRETTE Marc made a donation (2013/4).
2481 +Alessandro Gorreta made a donation (2013/4).
2482 +lauri kasvandik made a donation (2013/5).
2483 +"pemasu from Finland" made a donation (2013/7).
2484 +The Parted Magic Project made a donation (2013/9 and 11).
2485 +Pavel Barta made a donation (2013/10).
2487 +Thank you very much.
2488 +Donations are always, including future donations, very important and
2489 +helpful for me to keep on developing aufs.
2493 +----------------------------------------
2494 +If you are an experienced user, no explanation is needed. Aufs is
2495 +just a linux filesystem.
2500 +# Local variables: ;
2503 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2504 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2505 +++ linux/fs/aufs/aufs.h 2014-04-24 22:11:10.848602379 +0200
2508 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2510 + * This program, aufs is free software; you can redistribute it and/or modify
2511 + * it under the terms of the GNU General Public License as published by
2512 + * the Free Software Foundation; either version 2 of the License, or
2513 + * (at your option) any later version.
2515 + * This program is distributed in the hope that it will be useful,
2516 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2517 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2518 + * GNU General Public License for more details.
2520 + * You should have received a copy of the GNU General Public License
2521 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2525 + * all header files
2533 +#define AuStub(type, name, body, ...) \
2534 + static inline type name(__VA_ARGS__) { body; }
2536 +#define AuStubVoid(name, ...) \
2537 + AuStub(void, name, , __VA_ARGS__)
2538 +#define AuStubInt0(name, ...) \
2539 + AuStub(int, name, return 0, __VA_ARGS__)
2543 +#include "branch.h"
2546 +#include "dbgaufs.h"
2547 +#include "dentry.h"
2551 +#include "fstype.h"
2554 +#include "module.h"
2559 +#include "sysaufs.h"
2564 +#endif /* __KERNEL__ */
2565 +#endif /* __AUFS_H__ */
2566 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2567 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2568 +++ linux/fs/aufs/branch.c 2014-04-24 22:11:10.848602379 +0200
2571 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2573 + * This program, aufs is free software; you can redistribute it and/or modify
2574 + * it under the terms of the GNU General Public License as published by
2575 + * the Free Software Foundation; either version 2 of the License, or
2576 + * (at your option) any later version.
2578 + * This program is distributed in the hope that it will be useful,
2579 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2580 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2581 + * GNU General Public License for more details.
2583 + * You should have received a copy of the GNU General Public License
2584 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2588 + * branch management
2591 +#include <linux/compat.h>
2592 +#include <linux/statfs.h>
2596 + * free a single branch
2599 +/* prohibit rmdir to the root of the branch */
2600 +/* todo: another new flag? */
2601 +static void au_br_dflags_force(struct au_branch *br)
2603 + struct dentry *h_dentry;
2605 + h_dentry = au_br_dentry(br);
2606 + spin_lock(&h_dentry->d_lock);
2607 + br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
2608 + h_dentry->d_flags |= DCACHE_MOUNTED;
2609 + spin_unlock(&h_dentry->d_lock);
2612 +/* restore its d_flags */
2613 +static void au_br_dflags_restore(struct au_branch *br)
2615 + struct dentry *h_dentry;
2617 + if (br->br_dflags)
2620 + h_dentry = au_br_dentry(br);
2621 + spin_lock(&h_dentry->d_lock);
2622 + h_dentry->d_flags &= ~DCACHE_MOUNTED;
2623 + spin_unlock(&h_dentry->d_lock);
2626 +static void au_br_do_free(struct au_branch *br)
2629 + struct au_wbr *wbr;
2630 + struct au_dykey **key;
2632 + au_hnotify_fin_br(br);
2634 + if (br->br_xino.xi_file)
2635 + fput(br->br_xino.xi_file);
2636 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2638 + AuDebugOn(atomic_read(&br->br_count));
2642 + for (i = 0; i < AuBrWh_Last; i++)
2643 + dput(wbr->wbr_wh[i]);
2644 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2645 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2648 + key = br->br_dykey;
2649 + for (i = 0; i < AuBrDynOp; i++, key++)
2655 + au_br_dflags_restore(br);
2657 + /* recursive lock, s_umount of branch's */
2659 + path_put(&br->br_path);
2666 + * frees all branches
2668 +void au_br_free(struct au_sbinfo *sbinfo)
2670 + aufs_bindex_t bmax;
2671 + struct au_branch **br;
2673 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2675 + bmax = sbinfo->si_bend + 1;
2676 + br = sbinfo->si_branch;
2678 + au_br_do_free(*br++);
2682 + * find the index of a branch which is specified by @br_id.
2684 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2686 + aufs_bindex_t bindex, bend;
2688 + bend = au_sbend(sb);
2689 + for (bindex = 0; bindex <= bend; bindex++)
2690 + if (au_sbr_id(sb, bindex) == br_id)
2695 +/* ---------------------------------------------------------------------- */
2701 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2702 + struct dentry *h_root)
2704 + if (unlikely(h_adding == h_root
2705 + || au_test_loopback_overlap(sb, h_adding)))
2707 + if (h_adding->d_sb != h_root->d_sb)
2709 + return au_test_subdir(h_adding, h_root)
2710 + || au_test_subdir(h_root, h_adding);
2714 + * returns a newly allocated branch. @new_nbranch is a number of branches
2715 + * after adding a branch.
2717 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2720 + struct au_branch *add_branch;
2721 + struct dentry *root;
2725 + root = sb->s_root;
2726 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2727 + if (unlikely(!add_branch))
2730 + err = au_hnotify_init_br(add_branch, perm);
2731 + if (unlikely(err))
2734 + add_branch->br_wbr = NULL;
2735 + if (au_br_writable(perm)) {
2736 + /* may be freed separately at changing the branch permission */
2737 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2739 + if (unlikely(!add_branch->br_wbr))
2743 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2745 + err = au_di_realloc(au_di(root), new_nbranch);
2747 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2749 + return add_branch; /* success */
2751 + kfree(add_branch->br_wbr);
2754 + au_hnotify_fin_br(add_branch);
2756 + kfree(add_branch);
2758 + return ERR_PTR(err);
2762 + * test if the branch permission is legal or not.
2764 +static int test_br(struct inode *inode, int brperm, char *path)
2768 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2773 + pr_err("write permission for readonly mount or inode, %s\n", path);
2781 + * 0: success, the caller will add it
2782 + * plus: success, it is already unified, the caller should ignore it
2785 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2788 + aufs_bindex_t bend, bindex;
2789 + struct dentry *root;
2790 + struct inode *inode, *h_inode;
2792 + root = sb->s_root;
2793 + bend = au_sbend(sb);
2794 + if (unlikely(bend >= 0
2795 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2799 + pr_err("%s duplicated\n", add->pathname);
2804 + err = -ENOSPC; /* -E2BIG; */
2805 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2806 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2807 + pr_err("number of branches exceeded %s\n", add->pathname);
2812 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2813 + pr_err("bad index %d\n", add->bindex);
2817 + inode = add->path.dentry->d_inode;
2819 + if (unlikely(!inode->i_nlink)) {
2820 + pr_err("no existence %s\n", add->pathname);
2825 + if (unlikely(inode->i_sb == sb)) {
2826 + pr_err("%s must be outside\n", add->pathname);
2830 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2831 + pr_err("unsupported filesystem, %s (%s)\n",
2832 + add->pathname, au_sbtype(inode->i_sb));
2836 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2837 + if (unlikely(err))
2841 + return 0; /* success */
2844 + for (bindex = 0; bindex <= bend; bindex++)
2845 + if (unlikely(test_overlap(sb, add->path.dentry,
2846 + au_h_dptr(root, bindex)))) {
2847 + pr_err("%s is overlapped\n", add->pathname);
2852 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2853 + h_inode = au_h_dptr(root, 0)->d_inode;
2854 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2855 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2856 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2857 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2859 + i_uid_read(inode), i_gid_read(inode),
2860 + (inode->i_mode & S_IALLUGO),
2861 + i_uid_read(h_inode), i_gid_read(h_inode),
2862 + (h_inode->i_mode & S_IALLUGO));
2870 + * initialize or clean the whiteouts for an adding branch
2872 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2875 + int err, old_perm;
2876 + aufs_bindex_t bindex;
2877 + struct mutex *h_mtx;
2878 + struct au_wbr *wbr;
2879 + struct au_hinode *hdir;
2881 + err = vfsub_mnt_want_write(au_br_mnt(br));
2882 + if (unlikely(err))
2886 + old_perm = br->br_perm;
2887 + br->br_perm = new_perm;
2890 + bindex = au_br_index(sb, br->br_id);
2891 + if (0 <= bindex) {
2892 + hdir = au_hi(sb->s_root->d_inode, bindex);
2893 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2895 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2896 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2899 + err = au_wh_init(br, sb);
2901 + wbr_wh_write_lock(wbr);
2902 + err = au_wh_init(br, sb);
2903 + wbr_wh_write_unlock(wbr);
2906 + au_hn_imtx_unlock(hdir);
2908 + mutex_unlock(h_mtx);
2909 + vfsub_mnt_drop_write(au_br_mnt(br));
2910 + br->br_perm = old_perm;
2912 + if (!err && wbr && !au_br_writable(new_perm)) {
2914 + br->br_wbr = NULL;
2921 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2925 + struct kstatfs kst;
2926 + struct au_wbr *wbr;
2929 + au_rw_init(&wbr->wbr_wh_rwsem);
2930 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2931 + atomic_set(&wbr->wbr_wh_running, 0);
2932 + wbr->wbr_bytes = 0;
2935 + * a limit for rmdir/rename a dir
2936 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
2938 + err = vfs_statfs(&br->br_path, &kst);
2939 + if (unlikely(err))
2942 + if (kst.f_namelen >= NAME_MAX)
2943 + err = au_br_init_wh(sb, br, perm);
2945 + pr_err("%pd(%s), unsupported namelen %ld\n",
2947 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2953 +/* intialize a new branch */
2954 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2955 + struct au_opt_add *add)
2960 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2961 + mutex_init(&br->br_xino.xi_nondir_mtx);
2962 + br->br_perm = add->perm;
2963 + BUILD_BUG_ON(sizeof(br->br_dflags)
2964 + != sizeof(br->br_path.dentry->d_flags));
2965 + br->br_dflags = DCACHE_MOUNTED;
2966 + br->br_path = add->path; /* set first, path_get() later */
2967 + spin_lock_init(&br->br_dykey_lock);
2968 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2969 + atomic_set(&br->br_count, 0);
2970 + atomic_set(&br->br_xino_running, 0);
2971 + br->br_id = au_new_br_id(sb);
2972 + AuDebugOn(br->br_id < 0);
2974 + if (au_br_writable(add->perm)) {
2975 + err = au_wbr_init(br, sb, add->perm);
2976 + if (unlikely(err))
2980 + if (au_opt_test(au_mntflags(sb), XINO)) {
2981 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2982 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2983 + if (unlikely(err)) {
2984 + AuDebugOn(br->br_xino.xi_file);
2989 + sysaufs_br_init(br);
2990 + path_get(&br->br_path);
2991 + goto out; /* success */
2994 + memset(&br->br_path, 0, sizeof(br->br_path));
2999 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3000 + struct au_branch *br, aufs_bindex_t bend,
3001 + aufs_bindex_t amount)
3003 + struct au_branch **brp;
3005 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3007 + brp = sbinfo->si_branch + bindex;
3008 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3010 + sbinfo->si_bend++;
3011 + if (unlikely(bend < 0))
3012 + sbinfo->si_bend = 0;
3015 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3016 + aufs_bindex_t bend, aufs_bindex_t amount)
3018 + struct au_hdentry *hdp;
3020 + AuRwMustWriteLock(&dinfo->di_rwsem);
3022 + hdp = dinfo->di_hdentry + bindex;
3023 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3024 + au_h_dentry_init(hdp);
3026 + if (unlikely(bend < 0))
3027 + dinfo->di_bstart = 0;
3030 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3031 + aufs_bindex_t bend, aufs_bindex_t amount)
3033 + struct au_hinode *hip;
3035 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3037 + hip = iinfo->ii_hinode + bindex;
3038 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3039 + hip->hi_inode = NULL;
3042 + if (unlikely(bend < 0))
3043 + iinfo->ii_bstart = 0;
3046 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3047 + aufs_bindex_t bindex)
3049 + struct dentry *root, *h_dentry;
3050 + struct inode *root_inode;
3051 + aufs_bindex_t bend, amount;
3053 + au_br_dflags_force(br);
3055 + root = sb->s_root;
3056 + root_inode = root->d_inode;
3057 + bend = au_sbend(sb);
3058 + amount = bend + 1 - bindex;
3059 + h_dentry = au_br_dentry(br);
3060 + au_sbilist_lock();
3061 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3062 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3063 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3064 + au_set_h_dptr(root, bindex, dget(h_dentry));
3065 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
3067 + au_sbilist_unlock();
3070 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3073 + aufs_bindex_t bend, add_bindex;
3074 + struct dentry *root, *h_dentry;
3075 + struct inode *root_inode;
3076 + struct au_branch *add_branch;
3078 + root = sb->s_root;
3079 + root_inode = root->d_inode;
3080 + IMustLock(root_inode);
3081 + err = test_add(sb, add, remount);
3082 + if (unlikely(err < 0))
3086 + goto out; /* success */
3089 + bend = au_sbend(sb);
3090 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3091 + err = PTR_ERR(add_branch);
3092 + if (IS_ERR(add_branch))
3095 + err = au_br_init(add_branch, sb, add);
3096 + if (unlikely(err)) {
3097 + au_br_do_free(add_branch);
3101 + add_bindex = add->bindex;
3103 + au_br_do_add(sb, add_branch, add_bindex);
3105 + sysaufs_brs_del(sb, add_bindex);
3106 + au_br_do_add(sb, add_branch, add_bindex);
3107 + sysaufs_brs_add(sb, add_bindex);
3110 + h_dentry = add->path.dentry;
3111 + if (!add_bindex) {
3112 + au_cpup_attr_all(root_inode, /*force*/1);
3113 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3115 + au_add_nlink(root_inode, h_dentry->d_inode);
3118 + * this test/set prevents aufs from handling unnecesary notify events
3119 + * of xino files, in case of re-adding a writable branch which was
3120 + * once detached from aufs.
3122 + if (au_xino_brid(sb) < 0
3123 + && au_br_writable(add_branch->br_perm)
3124 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3125 + && add_branch->br_xino.xi_file
3126 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
3127 + au_xino_brid_set(sb, add_branch->br_id);
3133 +/* ---------------------------------------------------------------------- */
3139 +/* to show the line number, do not make it inlined function */
3140 +#define AuVerbose(do_info, fmt, ...) do { \
3142 + pr_info(fmt, ##__VA_ARGS__); \
3145 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3146 + aufs_bindex_t bend)
3148 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3151 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3152 + aufs_bindex_t bend)
3154 + return au_test_ibusy(dentry->d_inode, bstart, bend);
3158 + * test if the branch is deletable or not.
3160 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3161 + unsigned int sigen, const unsigned int verbose)
3163 + int err, i, j, ndentry;
3164 + aufs_bindex_t bstart, bend;
3165 + struct au_dcsub_pages dpages;
3166 + struct au_dpage *dpage;
3169 + err = au_dpages_init(&dpages, GFP_NOFS);
3170 + if (unlikely(err))
3172 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3173 + if (unlikely(err))
3176 + for (i = 0; !err && i < dpages.ndpage; i++) {
3177 + dpage = dpages.dpages + i;
3178 + ndentry = dpage->ndentry;
3179 + for (j = 0; !err && j < ndentry; j++) {
3180 + d = dpage->dentries[j];
3181 + AuDebugOn(!d_count(d));
3182 + if (!au_digen_test(d, sigen)) {
3183 + di_read_lock_child(d, AuLock_IR);
3184 + if (unlikely(au_dbrange_test(d))) {
3185 + di_read_unlock(d, AuLock_IR);
3189 + di_write_lock_child(d);
3190 + if (unlikely(au_dbrange_test(d))) {
3191 + di_write_unlock(d);
3194 + err = au_reval_dpath(d, sigen);
3196 + di_downgrade_lock(d, AuLock_IR);
3198 + di_write_unlock(d);
3203 + /* AuDbgDentry(d); */
3204 + bstart = au_dbstart(d);
3205 + bend = au_dbend(d);
3206 + if (bstart <= bindex
3208 + && au_h_dptr(d, bindex)
3209 + && au_test_dbusy(d, bstart, bend)) {
3211 + AuVerbose(verbose, "busy %pd\n", d);
3214 + di_read_unlock(d, AuLock_IR);
3219 + au_dpages_free(&dpages);
3224 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3225 + unsigned int sigen, const unsigned int verbose)
3228 + unsigned long long max, ull;
3229 + struct inode *i, **array;
3230 + aufs_bindex_t bstart, bend;
3232 + array = au_iarray_alloc(sb, &max);
3233 + err = PTR_ERR(array);
3234 + if (IS_ERR(array))
3238 + AuDbg("b%d\n", bindex);
3239 + for (ull = 0; !err && ull < max; ull++) {
3241 + if (i->i_ino == AUFS_ROOT_INO)
3244 + /* AuDbgInode(i); */
3245 + if (au_iigen(i, NULL) == sigen)
3246 + ii_read_lock_child(i);
3248 + ii_write_lock_child(i);
3249 + err = au_refresh_hinode_self(i);
3252 + ii_downgrade_lock(i);
3254 + ii_write_unlock(i);
3259 + bstart = au_ibstart(i);
3260 + bend = au_ibend(i);
3261 + if (bstart <= bindex
3263 + && au_h_iptr(i, bindex)
3264 + && au_test_ibusy(i, bstart, bend)) {
3266 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3269 + ii_read_unlock(i);
3271 + au_iarray_free(array, max);
3277 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3278 + const unsigned int verbose)
3281 + unsigned int sigen;
3283 + sigen = au_sigen(root->d_sb);
3284 + DiMustNoWaiters(root);
3285 + IiMustNoWaiters(root->d_inode);
3286 + di_write_unlock(root);
3287 + err = test_dentry_busy(root, bindex, sigen, verbose);
3289 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3290 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3295 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3296 + const aufs_bindex_t bindex,
3297 + const aufs_bindex_t bend)
3299 + struct au_branch **brp, **p;
3301 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3303 + brp = sbinfo->si_branch + bindex;
3304 + if (bindex < bend)
3305 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3306 + sbinfo->si_branch[0 + bend] = NULL;
3307 + sbinfo->si_bend--;
3309 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3311 + sbinfo->si_branch = p;
3312 + /* harmless error */
3315 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3316 + const aufs_bindex_t bend)
3318 + struct au_hdentry *hdp, *p;
3320 + AuRwMustWriteLock(&dinfo->di_rwsem);
3322 + hdp = dinfo->di_hdentry;
3323 + if (bindex < bend)
3324 + memmove(hdp + bindex, hdp + bindex + 1,
3325 + sizeof(*hdp) * (bend - bindex));
3326 + hdp[0 + bend].hd_dentry = NULL;
3329 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3331 + dinfo->di_hdentry = p;
3332 + /* harmless error */
3335 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3336 + const aufs_bindex_t bend)
3338 + struct au_hinode *hip, *p;
3340 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3342 + hip = iinfo->ii_hinode + bindex;
3343 + if (bindex < bend)
3344 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3345 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3346 + au_hn_init(iinfo->ii_hinode + bend);
3349 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3351 + iinfo->ii_hinode = p;
3352 + /* harmless error */
3355 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3356 + struct au_branch *br)
3358 + aufs_bindex_t bend;
3359 + struct au_sbinfo *sbinfo;
3360 + struct dentry *root, *h_root;
3361 + struct inode *inode, *h_inode;
3362 + struct au_hinode *hinode;
3364 + SiMustWriteLock(sb);
3366 + root = sb->s_root;
3367 + inode = root->d_inode;
3368 + sbinfo = au_sbi(sb);
3369 + bend = sbinfo->si_bend;
3371 + h_root = au_h_dptr(root, bindex);
3372 + hinode = au_hi(inode, bindex);
3373 + h_inode = au_igrab(hinode->hi_inode);
3376 + au_sbilist_lock();
3377 + au_br_do_del_brp(sbinfo, bindex, bend);
3378 + au_br_do_del_hdp(au_di(root), bindex, bend);
3379 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3380 + au_sbilist_unlock();
3384 + au_br_do_free(br);
3387 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3390 + unsigned int mnt_flags;
3391 + aufs_bindex_t bindex, bend, br_id;
3392 + unsigned char do_wh, verbose;
3393 + struct au_branch *br;
3394 + struct au_wbr *wbr;
3397 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
3400 + goto out; /* success */
3402 + pr_err("%s no such branch\n", del->pathname);
3405 + AuDbg("bindex b%d\n", bindex);
3408 + mnt_flags = au_mntflags(sb);
3409 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3410 + bend = au_sbend(sb);
3411 + if (unlikely(!bend)) {
3412 + AuVerbose(verbose, "no more branches left\n");
3415 + br = au_sbr(sb, bindex);
3416 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3417 + i = atomic_read(&br->br_count);
3418 + if (unlikely(i)) {
3419 + AuVerbose(verbose, "%d file(s) opened\n", i);
3424 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3426 + /* instead of WbrWhMustWriteLock(wbr) */
3427 + SiMustWriteLock(sb);
3428 + for (i = 0; i < AuBrWh_Last; i++) {
3429 + dput(wbr->wbr_wh[i]);
3430 + wbr->wbr_wh[i] = NULL;
3434 + err = test_children_busy(sb->s_root, bindex, verbose);
3435 + if (unlikely(err)) {
3442 + br_id = br->br_id;
3444 + au_br_do_del(sb, bindex, br);
3446 + sysaufs_brs_del(sb, bindex);
3447 + au_br_do_del(sb, bindex, br);
3448 + sysaufs_brs_add(sb, bindex);
3452 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
3453 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3455 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
3456 + if (au_opt_test(mnt_flags, PLINK))
3457 + au_plink_half_refresh(sb, br_id);
3459 + if (au_xino_brid(sb) == br_id)
3460 + au_xino_brid_set(sb, -1);
3461 + goto out; /* success */
3465 + rerr = au_br_init_wh(sb, br, br->br_perm);
3467 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3468 + del->pathname, rerr);
3473 +/* ---------------------------------------------------------------------- */
3475 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3478 + aufs_bindex_t bstart, bend;
3479 + struct aufs_ibusy ibusy;
3480 + struct inode *inode, *h_inode;
3483 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3486 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3488 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3489 + if (unlikely(err)) {
3496 + si_read_lock(sb, AuLock_FLUSH);
3497 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3501 + ibusy.h_ino = 0; /* invalid */
3502 + inode = ilookup(sb, ibusy.ino);
3504 + || inode->i_ino == AUFS_ROOT_INO
3505 + || is_bad_inode(inode))
3508 + ii_read_lock_child(inode);
3509 + bstart = au_ibstart(inode);
3510 + bend = au_ibend(inode);
3511 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3512 + h_inode = au_h_iptr(inode, ibusy.bindex);
3513 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3514 + ibusy.h_ino = h_inode->i_ino;
3516 + ii_read_unlock(inode);
3520 + si_read_unlock(sb);
3522 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3523 + if (unlikely(err)) {
3532 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3534 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
3537 +#ifdef CONFIG_COMPAT
3538 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3540 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
3544 +/* ---------------------------------------------------------------------- */
3547 + * change a branch permission
3550 +static void au_warn_ima(void)
3553 + /* since it doesn't support mark_files_ro() */
3554 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3558 +static int do_need_sigen_inc(int a, int b)
3560 + return au_br_whable(a) && !au_br_whable(b);
3563 +static int need_sigen_inc(int old, int new)
3565 + return do_need_sigen_inc(old, new)
3566 + || do_need_sigen_inc(new, old);
3569 +static unsigned long long au_farray_cb(void *a,
3570 + unsigned long long max __maybe_unused,
3573 + unsigned long long n;
3574 + struct file **p, *f;
3575 + struct au_sphlhead *files;
3576 + struct au_finfo *finfo;
3577 + struct super_block *sb = arg;
3581 + files = &au_sbi(sb)->si_files;
3582 + spin_lock(&files->spin);
3583 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3584 + f = finfo->fi_file;
3586 + && !special_file(file_inode(f)->i_mode)) {
3590 + AuDebugOn(n > max);
3593 + spin_unlock(&files->spin);
3598 +static struct file **au_farray_alloc(struct super_block *sb,
3599 + unsigned long long *max)
3601 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3602 + return au_array_alloc(max, au_farray_cb, sb);
3605 +static void au_farray_free(struct file **a, unsigned long long max)
3607 + unsigned long long ull;
3609 + for (ull = 0; ull < max; ull++)
3615 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3618 + unsigned int mnt_flags;
3619 + unsigned long long ull, max;
3620 + aufs_bindex_t br_id;
3621 + unsigned char verbose;
3622 + struct file *file, *hf, **array;
3623 + struct inode *inode;
3624 + struct au_hfile *hfile;
3626 + mnt_flags = au_mntflags(sb);
3627 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3629 + array = au_farray_alloc(sb, &max);
3630 + err = PTR_ERR(array);
3631 + if (IS_ERR(array))
3635 + br_id = au_sbr_id(sb, bindex);
3636 + for (ull = 0; ull < max; ull++) {
3637 + file = array[ull];
3639 + /* AuDbg("%pD\n", file); */
3640 + fi_read_lock(file);
3641 + if (unlikely(au_test_mmapped(file))) {
3643 + AuVerbose(verbose, "mmapped %pD\n", file);
3645 + FiMustNoWaiters(file);
3646 + fi_read_unlock(file);
3650 + inode = file_inode(file);
3651 + hfile = &au_fi(file)->fi_htop;
3652 + hf = hfile->hf_file;
3653 + if (!S_ISREG(inode->i_mode)
3654 + || !(file->f_mode & FMODE_WRITE)
3655 + || hfile->hf_br->br_id != br_id
3656 + || !(hf->f_mode & FMODE_WRITE))
3657 + array[ull] = NULL;
3663 + FiMustNoWaiters(file);
3664 + fi_read_unlock(file);
3672 + for (ull = 0; ull < max; ull++) {
3673 + file = array[ull];
3677 + /* todo: already flushed? */
3679 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
3680 + * approach which resets f_mode and calls mnt_drop_write() and
3681 + * file_release_write() for each file, because the branch
3682 + * attribute in aufs world is totally different from the native
3685 + /* fi_read_lock(file); */
3686 + hfile = &au_fi(file)->fi_htop;
3687 + hf = hfile->hf_file;
3688 + /* fi_read_unlock(file); */
3689 + spin_lock(&hf->f_lock);
3690 + hf->f_mode &= ~FMODE_WRITE;
3691 + spin_unlock(&hf->f_lock);
3692 + if (!file_check_writeable(hf)) {
3693 + __mnt_drop_write(hf->f_path.mnt);
3694 + file_release_write(hf);
3699 + au_farray_free(array, max);
3705 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3709 + aufs_bindex_t bindex;
3710 + struct dentry *root;
3711 + struct au_branch *br;
3713 + root = sb->s_root;
3714 + bindex = au_find_dbindex(root, mod->h_root);
3717 + return 0; /* success */
3719 + pr_err("%s no such branch\n", mod->path);
3722 + AuDbg("bindex b%d\n", bindex);
3724 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3725 + if (unlikely(err))
3728 + br = au_sbr(sb, bindex);
3729 + AuDebugOn(mod->h_root != au_br_dentry(br));
3730 + if (br->br_perm == mod->perm)
3731 + return 0; /* success */
3733 + if (au_br_writable(br->br_perm)) {
3734 + /* remove whiteout base */
3735 + err = au_br_init_wh(sb, br, mod->perm);
3736 + if (unlikely(err))
3739 + if (!au_br_writable(mod->perm)) {
3740 + /* rw --> ro, file might be mmapped */
3741 + DiMustNoWaiters(root);
3742 + IiMustNoWaiters(root->d_inode);
3743 + di_write_unlock(root);
3744 + err = au_br_mod_files_ro(sb, bindex);
3745 + /* aufs_write_lock() calls ..._child() */
3746 + di_write_lock_child(root);
3748 + if (unlikely(err)) {
3750 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3753 + rerr = au_wbr_init(br, sb, br->br_perm);
3754 + if (unlikely(rerr)) {
3755 + AuIOErr("nested error %d (%d)\n",
3757 + br->br_perm = mod->perm;
3761 + } else if (au_br_writable(mod->perm)) {
3764 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3766 + err = au_wbr_init(br, sb, mod->perm);
3767 + if (unlikely(err)) {
3768 + kfree(br->br_wbr);
3769 + br->br_wbr = NULL;
3775 + if ((br->br_perm & AuBrAttr_UNPIN)
3776 + && !(mod->perm & AuBrAttr_UNPIN))
3777 + au_br_dflags_force(br);
3778 + else if (!(br->br_perm & AuBrAttr_UNPIN)
3779 + && (mod->perm & AuBrAttr_UNPIN))
3780 + au_br_dflags_restore(br);
3781 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3782 + br->br_perm = mod->perm;
3789 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3790 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3791 +++ linux/fs/aufs/branch.h 2014-04-24 22:11:10.848602379 +0200
3794 + * Copyright (C) 2005-2014 Junjiro R. Okajima
3796 + * This program, aufs is free software; you can redistribute it and/or modify
3797 + * it under the terms of the GNU General Public License as published by
3798 + * the Free Software Foundation; either version 2 of the License, or
3799 + * (at your option) any later version.
3801 + * This program is distributed in the hope that it will be useful,
3802 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3803 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3804 + * GNU General Public License for more details.
3806 + * You should have received a copy of the GNU General Public License
3807 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3811 + * branch filesystems and xino for them
3814 +#ifndef __AUFS_BRANCH_H__
3815 +#define __AUFS_BRANCH_H__
3819 +#include <linux/mount.h>
3824 +/* ---------------------------------------------------------------------- */
3827 +struct au_xino_file {
3828 + struct file *xi_file;
3829 + struct mutex xi_nondir_mtx;
3831 + /* todo: make xino files an array to support huge inode number */
3833 +#ifdef CONFIG_DEBUG_FS
3834 + struct dentry *xi_dbgaufs;
3838 +/* members for writable branch only */
3839 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3841 + struct au_rwsem wbr_wh_rwsem;
3842 + struct dentry *wbr_wh[AuBrWh_Last];
3843 + atomic_t wbr_wh_running;
3844 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3845 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3846 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3849 + unsigned long long wbr_bytes;
3852 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3853 +#define AuBrDynOp (AuDyLast * 4)
3855 +#ifdef CONFIG_AUFS_HFSNOTIFY
3856 +/* support for asynchronous destruction */
3857 +struct au_br_hfsnotify {
3858 + struct fsnotify_group *hfsn_group;
3862 +/* sysfs entries */
3863 +struct au_brsysfs {
3865 + struct attribute attr;
3874 +/* protected by superblock rwsem */
3876 + struct au_xino_file br_xino;
3878 + aufs_bindex_t br_id;
3881 + unsigned int br_dflags;
3882 + struct path br_path;
3883 + spinlock_t br_dykey_lock;
3884 + struct au_dykey *br_dykey[AuBrDynOp];
3885 + atomic_t br_count;
3887 + struct au_wbr *br_wbr;
3889 + /* xino truncation */
3890 + atomic_t br_xino_running;
3892 +#ifdef CONFIG_AUFS_HFSNOTIFY
3893 + struct au_br_hfsnotify *br_hfsn;
3896 +#ifdef CONFIG_SYSFS
3897 + /* entries under sysfs per mount-point */
3898 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
3902 +/* ---------------------------------------------------------------------- */
3904 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
3906 + return br->br_path.mnt;
3909 +static inline struct dentry *au_br_dentry(struct au_branch *br)
3911 + return br->br_path.dentry;
3914 +static inline struct super_block *au_br_sb(struct au_branch *br)
3916 + return au_br_mnt(br)->mnt_sb;
3919 +/* branch permissions and attributes */
3920 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
3921 +#define AuBrPerm_RO (1 << 1) /* readonly */
3922 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
3923 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
3925 +#define AuBrRAttr_WH (1 << 3) /* whiteout-able */
3927 +#define AuBrWAttr_NoLinkWH (1 << 4) /* un-hardlinkable whiteouts */
3929 +#define AuBrAttr_UNPIN (1 << 5) /* rename-able top dir of
3932 +static inline int au_br_writable(int brperm)
3934 + return brperm & AuBrPerm_RW;
3937 +static inline int au_br_whable(int brperm)
3939 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
3942 +static inline int au_br_wh_linkable(int brperm)
3944 + return !(brperm & AuBrWAttr_NoLinkWH);
3947 +static inline int au_br_rdonly(struct au_branch *br)
3949 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
3950 + || !au_br_writable(br->br_perm))
3954 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3956 +#ifdef CONFIG_AUFS_HNOTIFY
3957 + return !(brperm & AuBrPerm_RR);
3963 +/* ---------------------------------------------------------------------- */
3967 +void au_br_free(struct au_sbinfo *sinfo);
3968 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3970 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3972 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3973 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3974 +#ifdef CONFIG_COMPAT
3975 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3978 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3982 +static const loff_t au_loff_max = LLONG_MAX;
3984 +int au_xib_trunc(struct super_block *sb);
3985 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
3987 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
3989 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3990 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3991 +ino_t au_xino_new_ino(struct super_block *sb);
3992 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3993 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3995 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3997 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3998 + struct file *base_file, int do_test);
3999 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4001 +struct au_opt_xino;
4002 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4003 +void au_xino_clr(struct super_block *sb);
4004 +struct file *au_xino_def(struct super_block *sb);
4005 +int au_xino_path(struct seq_file *seq, struct file *file);
4007 +/* ---------------------------------------------------------------------- */
4009 +/* Superblock to branch */
4011 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4013 + return au_sbr(sb, bindex)->br_id;
4017 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4019 + return au_br_mnt(au_sbr(sb, bindex));
4023 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4025 + return au_br_sb(au_sbr(sb, bindex));
4028 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4030 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4033 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4035 + return au_sbr(sb, bindex)->br_perm;
4038 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4040 + return au_br_whable(au_sbr_perm(sb, bindex));
4043 +/* ---------------------------------------------------------------------- */
4046 + * wbr_wh_read_lock, wbr_wh_write_lock
4047 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4049 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4051 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4052 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4053 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4055 +#endif /* __KERNEL__ */
4056 +#endif /* __AUFS_BRANCH_H__ */
4057 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4058 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4059 +++ linux/fs/aufs/conf.mk 2014-04-24 22:11:10.848602379 +0200
4062 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4066 +AuConfStr += ${1}=${${1}}
4070 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4072 + HNOTIFY HFSNOTIFY \
4082 +$(foreach i, ${AuConfAll}, \
4083 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4085 +AuConfName = ${obj}/conf.str
4086 +${AuConfName}.tmp: FORCE
4087 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4088 +${AuConfName}: ${AuConfName}.tmp
4089 + @diff -q $< $@ > /dev/null 2>&1 || { \
4090 + echo ' GEN ' $@; \
4094 +clean-files += ${AuConfName} ${AuConfName}.tmp
4095 +${obj}/sysfs.o: ${AuConfName}
4097 +-include ${srctree}/${src}/conf_priv.mk
4098 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4099 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4100 +++ linux/fs/aufs/cpup.c 2014-04-24 22:11:10.848602379 +0200
4103 + * Copyright (C) 2005-2014 Junjiro R. Okajima
4105 + * This program, aufs is free software; you can redistribute it and/or modify
4106 + * it under the terms of the GNU General Public License as published by
4107 + * the Free Software Foundation; either version 2 of the License, or
4108 + * (at your option) any later version.
4110 + * This program is distributed in the hope that it will be useful,
4111 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4112 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4113 + * GNU General Public License for more details.
4115 + * You should have received a copy of the GNU General Public License
4116 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4120 + * copy-up functions, see wbr_policy.c for copy-down
4123 +#include <linux/fs_stack.h>
4124 +#include <linux/mm.h>
4127 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4129 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4130 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4132 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4134 + dst->i_flags |= iflags & ~mask;
4135 + if (au_test_fs_notime(dst->i_sb))
4136 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4139 +void au_cpup_attr_timesizes(struct inode *inode)
4141 + struct inode *h_inode;
4143 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4144 + fsstack_copy_attr_times(inode, h_inode);
4145 + fsstack_copy_inode_size(inode, h_inode);
4148 +void au_cpup_attr_nlink(struct inode *inode, int force)
4150 + struct inode *h_inode;
4151 + struct super_block *sb;
4152 + aufs_bindex_t bindex, bend;
4155 + bindex = au_ibstart(inode);
4156 + h_inode = au_h_iptr(inode, bindex);
4158 + && !S_ISDIR(h_inode->i_mode)
4159 + && au_opt_test(au_mntflags(sb), PLINK)
4160 + && au_plink_test(inode))
4164 + * 0 can happen in revalidating.
4165 + * h_inode->i_mutex is not held, but it is harmless since once i_nlink
4166 + * reaches 0, it will never become positive.
4168 + set_nlink(inode, h_inode->i_nlink);
4171 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4172 + * it may includes whplink directory.
4174 + if (S_ISDIR(h_inode->i_mode)) {
4175 + bend = au_ibend(inode);
4176 + for (bindex++; bindex <= bend; bindex++) {
4177 + h_inode = au_h_iptr(inode, bindex);
4179 + au_add_nlink(inode, h_inode);
4184 +void au_cpup_attr_changeable(struct inode *inode)
4186 + struct inode *h_inode;
4188 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4189 + inode->i_mode = h_inode->i_mode;
4190 + inode->i_uid = h_inode->i_uid;
4191 + inode->i_gid = h_inode->i_gid;
4192 + au_cpup_attr_timesizes(inode);
4193 + au_cpup_attr_flags(inode, h_inode->i_flags);
4196 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4198 + struct au_iinfo *iinfo = au_ii(inode);
4200 + IiMustWriteLock(inode);
4202 + iinfo->ii_higen = h_inode->i_generation;
4203 + iinfo->ii_hsb1 = h_inode->i_sb;
4206 +void au_cpup_attr_all(struct inode *inode, int force)
4208 + struct inode *h_inode;
4210 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4211 + au_cpup_attr_changeable(inode);
4212 + if (inode->i_nlink > 0)
4213 + au_cpup_attr_nlink(inode, force);
4214 + inode->i_rdev = h_inode->i_rdev;
4215 + inode->i_blkbits = h_inode->i_blkbits;
4216 + au_cpup_igen(inode, h_inode);
4219 +/* ---------------------------------------------------------------------- */
4221 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4223 +/* keep the timestamps of the parent dir when cpup */
4224 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4225 + struct path *h_path)
4227 + struct inode *h_inode;
4229 + dt->dt_dentry = dentry;
4230 + dt->dt_h_path = *h_path;
4231 + h_inode = h_path->dentry->d_inode;
4232 + dt->dt_atime = h_inode->i_atime;
4233 + dt->dt_mtime = h_inode->i_mtime;
4237 +void au_dtime_revert(struct au_dtime *dt)
4239 + struct iattr attr;
4242 + attr.ia_atime = dt->dt_atime;
4243 + attr.ia_mtime = dt->dt_mtime;
4244 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4245 + | ATTR_ATIME | ATTR_ATIME_SET;
4247 + /* no delegation since this is a directory */
4248 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4249 + if (unlikely(err))
4250 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4253 +/* ---------------------------------------------------------------------- */
4255 +/* internal use only */
4256 +struct au_cpup_reg_attr {
4259 + unsigned int iflags; /* inode->i_flags */
4262 +static noinline_for_stack
4263 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4264 + struct au_cpup_reg_attr *h_src_attr)
4268 + struct path h_path;
4269 + struct inode *h_isrc, *h_idst;
4270 + struct kstat *h_st;
4272 + h_path.dentry = au_h_dptr(dst, bindex);
4273 + h_idst = h_path.dentry->d_inode;
4274 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
4275 + h_isrc = h_src->d_inode;
4276 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4277 + | ATTR_ATIME | ATTR_MTIME
4278 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4279 + if (h_src_attr && h_src_attr->valid) {
4280 + h_st = &h_src_attr->st;
4281 + ia.ia_uid = h_st->uid;
4282 + ia.ia_gid = h_st->gid;
4283 + ia.ia_atime = h_st->atime;
4284 + ia.ia_mtime = h_st->mtime;
4285 + if (h_idst->i_mode != h_st->mode
4286 + && !S_ISLNK(h_idst->i_mode)) {
4287 + ia.ia_valid |= ATTR_MODE;
4288 + ia.ia_mode = h_st->mode;
4290 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4291 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4293 + ia.ia_uid = h_isrc->i_uid;
4294 + ia.ia_gid = h_isrc->i_gid;
4295 + ia.ia_atime = h_isrc->i_atime;
4296 + ia.ia_mtime = h_isrc->i_mtime;
4297 + if (h_idst->i_mode != h_isrc->i_mode
4298 + && !S_ISLNK(h_idst->i_mode)) {
4299 + ia.ia_valid |= ATTR_MODE;
4300 + ia.ia_mode = h_isrc->i_mode;
4302 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4303 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4305 + /* no delegation since it is just created */
4306 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4308 + /* is this nfs only? */
4309 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4310 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4311 + ia.ia_mode = h_isrc->i_mode;
4312 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4318 +/* ---------------------------------------------------------------------- */
4320 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4321 + char *buf, unsigned long blksize)
4324 + size_t sz, rbytes, wbytes;
4325 + unsigned char all_zero;
4327 + struct mutex *h_mtx;
4328 + /* reduce stack usage */
4331 + zp = page_address(ZERO_PAGE(0));
4332 + if (unlikely(!zp))
4333 + return -ENOMEM; /* possible? */
4338 + AuDbg("len %lld\n", len);
4340 + if (len < blksize)
4344 + /* todo: signal_pending? */
4345 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4346 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4349 + if (unlikely(err < 0))
4353 + if (len >= rbytes && rbytes == blksize)
4354 + all_zero = !memcmp(buf, zp, rbytes);
4361 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4363 + /* todo: signal_pending? */
4364 + if (unlikely(err == -EAGAIN || err == -EINTR))
4366 + if (unlikely(err < 0))
4371 + if (unlikely(err < 0))
4377 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4379 + if (unlikely(res < 0))
4386 + /* the last block may be a hole */
4387 + if (!err && all_zero) {
4388 + AuLabel(last hole);
4391 + if (au_test_nfs(dst->f_dentry->d_sb)) {
4392 + /* nfs requires this step to make last hole */
4393 + /* is this only nfs? */
4395 + /* todo: signal_pending? */
4396 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4397 + } while (err == -EAGAIN || err == -EINTR);
4404 + ia->ia_size = dst->f_pos;
4405 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4406 + ia->ia_file = dst;
4407 + h_mtx = &file_inode(dst)->i_mutex;
4408 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4409 + /* no delegation since it is just created */
4410 + err = vfsub_notify_change(&dst->f_path, ia,
4411 + /*delegated*/NULL);
4412 + mutex_unlock(h_mtx);
4419 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4422 + unsigned long blksize;
4423 + unsigned char do_kfree;
4427 + blksize = dst->f_dentry->d_sb->s_blocksize;
4428 + if (!blksize || PAGE_SIZE < blksize)
4429 + blksize = PAGE_SIZE;
4430 + AuDbg("blksize %lu\n", blksize);
4431 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4433 + buf = kmalloc(blksize, GFP_NOFS);
4435 + buf = (void *)__get_free_page(GFP_NOFS);
4436 + if (unlikely(!buf))
4439 + if (len > (1 << 22))
4440 + AuDbg("copying a large file %lld\n", (long long)len);
4444 + err = au_do_copy_file(dst, src, len, buf, blksize);
4448 + free_page((unsigned long)buf);
4455 + * to support a sparse file which is opened with O_APPEND,
4456 + * we need to close the file.
4458 +static int au_cp_regular(struct au_cp_generic *cpg)
4461 + enum { SRC, DST };
4463 + aufs_bindex_t bindex;
4464 + unsigned int flags;
4465 + struct dentry *dentry;
4467 + struct file *file;
4471 + .bindex = cpg->bsrc,
4472 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4476 + .bindex = cpg->bdst,
4477 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4478 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4479 + .label = &&out_src
4482 + struct super_block *sb;
4484 + /* bsrc branch can be ro/rw. */
4485 + sb = cpg->dentry->d_sb;
4487 + for (i = 0; i < 2; i++, f++) {
4488 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4489 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4490 + /*file*/NULL, f->force_wr);
4491 + err = PTR_ERR(f->file);
4492 + if (IS_ERR(f->file))
4496 + /* try stopping to update while we copyup */
4497 + IMustLock(file[SRC].dentry->d_inode);
4498 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4500 + fput(file[DST].file);
4501 + au_sbr_put(sb, file[DST].bindex);
4504 + fput(file[SRC].file);
4505 + au_sbr_put(sb, file[SRC].bindex);
4510 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4511 + struct au_cpup_reg_attr *h_src_attr)
4515 + struct path h_path;
4516 + struct inode *h_src_inode;
4519 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
4520 + l = i_size_read(h_src_inode);
4521 + if (cpg->len == -1 || l < cpg->len)
4524 + /* try stopping to update while we are referencing */
4525 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4526 + au_pin_hdir_unlock(cpg->pin);
4528 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4529 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4530 + h_src_attr->iflags = h_src_inode->i_flags;
4531 + err = vfs_getattr(&h_path, &h_src_attr->st);
4532 + if (unlikely(err)) {
4533 + mutex_unlock(&h_src_inode->i_mutex);
4536 + h_src_attr->valid = 1;
4537 + err = au_cp_regular(cpg);
4538 + mutex_unlock(&h_src_inode->i_mutex);
4539 + rerr = au_pin_hdir_relock(cpg->pin);
4548 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4549 + struct inode *h_dir)
4552 + mm_segment_t old_fs;
4559 + if (unlikely(!h_src->d_inode->i_op->readlink))
4563 + sym.k = (void *)__get_free_page(GFP_NOFS);
4564 + if (unlikely(!sym.k))
4567 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4568 + old_fs = get_fs();
4569 + set_fs(KERNEL_DS);
4570 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
4575 + sym.k[symlen] = 0;
4576 + err = vfsub_symlink(h_dir, h_path, sym.k);
4578 + free_page((unsigned long)sym.k);
4584 +static noinline_for_stack
4585 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
4586 + struct au_cpup_reg_attr *h_src_attr)
4590 + unsigned int mnt_flags;
4591 + unsigned char isdir;
4592 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
4593 + struct au_dtime dt;
4594 + struct path h_path;
4595 + struct dentry *h_src, *h_dst, *h_parent;
4596 + struct inode *h_inode, *h_dir;
4597 + struct super_block *sb;
4599 + /* bsrc branch can be ro/rw. */
4600 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4601 + h_inode = h_src->d_inode;
4602 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
4604 + /* try stopping to be referenced while we are creating */
4605 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4606 + if (au_ftest_cpup(cpg->flags, RENAME))
4607 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
4608 + AUFS_WH_PFX_LEN));
4609 + h_parent = h_dst->d_parent; /* dir inode is locked */
4610 + h_dir = h_parent->d_inode;
4612 + AuDebugOn(h_parent != h_dst->d_parent);
4614 + sb = cpg->dentry->d_sb;
4615 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4617 + h_path.dentry = h_parent;
4618 + au_dtime_store(&dt, dst_parent, &h_path);
4620 + h_path.dentry = h_dst;
4623 + mode = h_inode->i_mode;
4624 + switch (mode & S_IFMT) {
4626 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
4627 + /*want_excl*/true);
4629 + err = au_do_cpup_regular(cpg, h_src_attr);
4633 + err = vfsub_mkdir(h_dir, &h_path, mode);
4636 + * strange behaviour from the users view,
4637 + * particularry setattr case
4639 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
4640 + au_cpup_attr_nlink(dst_parent->d_inode,
4642 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
4646 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4650 + AuDebugOn(!capable(CAP_MKNOD));
4654 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4657 + AuIOErr("Unknown inode type 0%o\n", mode);
4661 + mnt_flags = au_mntflags(sb);
4662 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4664 + && au_opt_test(mnt_flags, XINO)
4665 + && h_inode->i_nlink == 1
4666 + /* todo: unnecessary? */
4667 + /* && cpg->dentry->d_inode->i_nlink == 1 */
4668 + && cpg->bdst < cpg->bsrc
4669 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4670 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4671 + /* ignore this error */
4674 + au_dtime_revert(&dt);
4678 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4681 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4682 + struct inode *h_dir;
4683 + aufs_bindex_t bdst;
4685 + dentry = cpg->dentry;
4687 + h_dentry = au_h_dptr(dentry, bdst);
4688 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
4690 + au_set_h_dptr(dentry, bdst, NULL);
4691 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4693 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4694 + au_set_h_dptr(dentry, bdst, h_dentry);
4697 + parent = dget_parent(dentry);
4698 + h_parent = au_h_dptr(parent, bdst);
4700 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
4701 + if (IS_ERR(h_path->dentry))
4702 + err = PTR_ERR(h_path->dentry);
4704 + if (unlikely(err))
4707 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4708 + h_dir = h_parent->d_inode;
4710 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
4711 + /* no delegation since it is just created */
4712 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
4713 + dput(h_path->dentry);
4720 + * copyup the @dentry from @bsrc to @bdst.
4721 + * the caller must set the both of lower dentries.
4722 + * @len is for truncating when it is -1 copyup the entire file.
4723 + * in link/rename cases, @dst_parent may be different from the real one.
4724 + * basic->bsrc can be larger than basic->bdst.
4726 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4729 + aufs_bindex_t old_ibstart;
4730 + unsigned char isdir, plink;
4731 + struct dentry *h_src, *h_dst, *h_parent;
4732 + struct inode *dst_inode, *h_dir, *inode, *delegated;
4733 + struct super_block *sb;
4734 + struct au_branch *br;
4735 + /* to reuduce stack size */
4737 + struct au_dtime dt;
4738 + struct path h_path;
4739 + struct au_cpup_reg_attr h_src_attr;
4743 + a = kmalloc(sizeof(*a), GFP_NOFS);
4746 + a->h_src_attr.valid = 0;
4748 + sb = cpg->dentry->d_sb;
4749 + br = au_sbr(sb, cpg->bdst);
4750 + a->h_path.mnt = au_br_mnt(br);
4751 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4752 + h_parent = h_dst->d_parent; /* dir inode is locked */
4753 + h_dir = h_parent->d_inode;
4756 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4757 + inode = cpg->dentry->d_inode;
4760 + dst_parent = dget_parent(cpg->dentry);
4764 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4765 + dst_inode = au_h_iptr(inode, cpg->bdst);
4767 + if (unlikely(!plink)) {
4769 + AuIOErr("hi%lu(i%lu) exists on b%d "
4770 + "but plink is disabled\n",
4771 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4775 + if (dst_inode->i_nlink) {
4776 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4778 + h_src = au_plink_lkup(inode, cpg->bdst);
4779 + err = PTR_ERR(h_src);
4780 + if (IS_ERR(h_src))
4782 + if (unlikely(!h_src->d_inode)) {
4784 + AuIOErr("i%lu exists on a upper branch "
4785 + "but not pseudo-linked\n",
4792 + a->h_path.dentry = h_parent;
4793 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4796 + a->h_path.dentry = h_dst;
4798 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
4799 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4800 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4802 + au_dtime_revert(&a->dt);
4803 + if (unlikely(err == -EWOULDBLOCK)) {
4804 + pr_warn("cannot retry for NFSv4 delegation"
4805 + " for an internal link\n");
4811 + /* todo: cpup_wh_file? */
4813 + au_update_ibrange(inode, /*do_put_zero*/1);
4816 + isdir = S_ISDIR(inode->i_mode);
4817 + old_ibstart = au_ibstart(inode);
4818 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4819 + if (unlikely(err))
4821 + dst_inode = h_dst->d_inode;
4822 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
4823 + /* todo: necessary? */
4824 + /* au_pin_hdir_unlock(cpg->pin); */
4826 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
4827 + if (unlikely(err)) {
4828 + /* todo: necessary? */
4829 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
4830 + mutex_unlock(&dst_inode->i_mutex);
4834 + if (cpg->bdst < old_ibstart) {
4835 + if (S_ISREG(inode->i_mode)) {
4836 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
4837 + if (unlikely(err)) {
4838 + /* ignore an error */
4839 + /* au_pin_hdir_relock(cpg->pin); */
4840 + mutex_unlock(&dst_inode->i_mutex);
4844 + au_set_ibstart(inode, cpg->bdst);
4846 + au_set_ibend(inode, cpg->bdst);
4847 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
4848 + au_hi_flags(inode, isdir));
4850 + /* todo: necessary? */
4851 + /* err = au_pin_hdir_relock(cpg->pin); */
4852 + mutex_unlock(&dst_inode->i_mutex);
4853 + if (unlikely(err))
4857 + && h_src->d_inode->i_nlink > 1
4859 + au_plink_append(inode, cpg->bdst, h_dst);
4861 + if (au_ftest_cpup(cpg->flags, RENAME)) {
4862 + a->h_path.dentry = h_dst;
4863 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4866 + goto out_parent; /* success */
4870 + a->h_path.dentry = h_parent;
4871 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4872 + a->h_path.dentry = h_dst;
4874 + if (h_dst->d_inode) {
4876 + /* no delegation since it is just created */
4877 + rerr = vfsub_unlink(h_dir, &a->h_path,
4878 + /*delegated*/NULL, /*force*/0);
4880 + rerr = vfsub_rmdir(h_dir, &a->h_path);
4882 + au_dtime_revert(&a->dt);
4884 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
4895 +struct au_cpup_single_args {
4897 + struct au_cp_generic *cpg;
4898 + struct dentry *dst_parent;
4901 +static void au_call_cpup_single(void *args)
4903 + struct au_cpup_single_args *a = args;
4905 + au_pin_hdir_acquire_nest(a->cpg->pin);
4906 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
4907 + au_pin_hdir_release(a->cpg->pin);
4912 + * prevent SIGXFSZ in copy-up.
4913 + * testing CAP_MKNOD is for generic fs,
4914 + * but CAP_FSETID is for xfs only, currently.
4916 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
4919 + struct super_block *sb;
4920 + struct inode *h_dir;
4923 + sb = au_pinned_parent(pin)->d_sb;
4924 + if (!au_wkq_test()
4925 + && (!au_sbi(sb)->si_plink_maint_pid
4926 + || au_plink_maint(sb, AuLock_NOPLM))) {
4927 + switch (mode & S_IFMT) {
4929 + /* no condition about RLIMIT_FSIZE and the file size */
4934 + do_sio = !capable(CAP_MKNOD);
4938 + do_sio = ((mode & (S_ISUID | S_ISGID))
4939 + && !capable(CAP_FSETID));
4940 + /* this workaround may be removed in the future */
4942 + h_dir = au_pinned_h_dir(pin);
4943 + do_sio = h_dir->i_mode & S_ISVTX;
4951 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4954 + struct dentry *h_dentry;
4956 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4957 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
4958 + err = au_cpup_single(cpg, dst_parent);
4960 + struct au_cpup_single_args args = {
4963 + .dst_parent = dst_parent
4965 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4966 + if (unlikely(wkq_err))
4975 + * copyup the @dentry from the first active lower branch to @bdst,
4976 + * using au_cpup_single().
4978 +static int au_cpup_simple(struct au_cp_generic *cpg)
4981 + unsigned int flags_orig;
4982 + struct dentry *dentry;
4984 + AuDebugOn(cpg->bsrc < 0);
4986 + dentry = cpg->dentry;
4987 + DiMustWriteLock(dentry);
4989 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
4991 + flags_orig = cpg->flags;
4992 + au_fset_cpup(cpg->flags, RENAME);
4993 + err = au_cpup_single(cpg, NULL);
4994 + cpg->flags = flags_orig;
4996 + return 0; /* success */
4999 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5000 + au_set_dbstart(dentry, cpg->bsrc);
5006 +struct au_cpup_simple_args {
5008 + struct au_cp_generic *cpg;
5011 +static void au_call_cpup_simple(void *args)
5013 + struct au_cpup_simple_args *a = args;
5015 + au_pin_hdir_acquire_nest(a->cpg->pin);
5016 + *a->errp = au_cpup_simple(a->cpg);
5017 + au_pin_hdir_release(a->cpg->pin);
5020 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5023 + struct dentry *dentry, *parent;
5024 + struct file *h_file;
5025 + struct inode *h_dir;
5027 + dentry = cpg->dentry;
5029 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5030 + AuDebugOn(cpg->bsrc < 0);
5031 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5032 + err = PTR_ERR(h_file);
5033 + if (IS_ERR(h_file))
5037 + parent = dget_parent(dentry);
5038 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
5039 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5040 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5041 + err = au_cpup_simple(cpg);
5043 + struct au_cpup_simple_args args = {
5047 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5048 + if (unlikely(wkq_err))
5054 + au_h_open_post(dentry, cpg->bsrc, h_file);
5060 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5062 + aufs_bindex_t bsrc, bend;
5063 + struct dentry *dentry, *h_dentry;
5065 + if (cpg->bsrc < 0) {
5066 + dentry = cpg->dentry;
5067 + bend = au_dbend(dentry);
5068 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5069 + h_dentry = au_h_dptr(dentry, bsrc);
5071 + AuDebugOn(!h_dentry->d_inode);
5075 + AuDebugOn(bsrc > bend);
5078 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5079 + return au_do_sio_cpup_simple(cpg);
5082 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5084 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5085 + return au_do_sio_cpup_simple(cpg);
5088 +/* ---------------------------------------------------------------------- */
5091 + * copyup the deleted file for writing.
5093 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5094 + struct file *file)
5097 + unsigned int flags_orig;
5098 + aufs_bindex_t bsrc_orig;
5099 + struct dentry *h_d_dst, *h_d_start;
5100 + struct au_dinfo *dinfo;
5101 + struct au_hdentry *hdp;
5103 + dinfo = au_di(cpg->dentry);
5104 + AuRwMustWriteLock(&dinfo->di_rwsem);
5106 + bsrc_orig = cpg->bsrc;
5107 + cpg->bsrc = dinfo->di_bstart;
5108 + hdp = dinfo->di_hdentry;
5109 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5110 + dinfo->di_bstart = cpg->bdst;
5111 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5114 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5115 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
5117 + flags_orig = cpg->flags;
5118 + cpg->flags = !AuCpup_DTIME;
5119 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5120 + cpg->flags = flags_orig;
5123 + err = au_reopen_nondir(file);
5124 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5126 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5127 + dinfo->di_bstart = cpg->bsrc;
5128 + cpg->bsrc = bsrc_orig;
5133 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5136 + aufs_bindex_t bdst;
5137 + struct au_dtime dt;
5138 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5139 + struct au_branch *br;
5140 + struct path h_path;
5142 + dentry = cpg->dentry;
5144 + br = au_sbr(dentry->d_sb, bdst);
5145 + parent = dget_parent(dentry);
5146 + h_parent = au_h_dptr(parent, bdst);
5147 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5148 + err = PTR_ERR(wh_dentry);
5149 + if (IS_ERR(wh_dentry))
5152 + h_path.dentry = h_parent;
5153 + h_path.mnt = au_br_mnt(br);
5154 + au_dtime_store(&dt, parent, &h_path);
5155 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5156 + if (unlikely(err))
5160 + h_path.dentry = wh_dentry;
5161 + if (!S_ISDIR(wh_dentry->d_inode->i_mode)) {
5162 + /* no delegation since it is just created */
5163 + err = vfsub_unlink(h_parent->d_inode, &h_path,
5164 + /*delegated*/NULL, /*force*/0);
5166 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
5167 + if (unlikely(err)) {
5168 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5172 + au_dtime_revert(&dt);
5173 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
5182 +struct au_cpup_wh_args {
5184 + struct au_cp_generic *cpg;
5185 + struct file *file;
5188 +static void au_call_cpup_wh(void *args)
5190 + struct au_cpup_wh_args *a = args;
5192 + au_pin_hdir_acquire_nest(a->cpg->pin);
5193 + *a->errp = au_cpup_wh(a->cpg, a->file);
5194 + au_pin_hdir_release(a->cpg->pin);
5197 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5200 + aufs_bindex_t bdst;
5201 + struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
5202 + struct inode *dir, *h_dir, *h_tmpdir;
5203 + struct au_wbr *wbr;
5204 + struct au_pin wh_pin, *pin_orig;
5206 + dentry = cpg->dentry;
5208 + parent = dget_parent(dentry);
5209 + dir = parent->d_inode;
5212 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5215 + if (!h_dir->i_nlink) {
5216 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5217 + h_orph = wbr->wbr_orph;
5219 + h_parent = dget(au_h_dptr(parent, bdst));
5220 + au_set_h_dptr(parent, bdst, dget(h_orph));
5221 + h_tmpdir = h_orph->d_inode;
5222 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5225 + h_dentry = au_hf_top(file)->f_dentry;
5227 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
5228 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5229 + /* todo: au_h_open_pre()? */
5231 + pin_orig = cpg->pin;
5232 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5233 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5234 + cpg->pin = &wh_pin;
5237 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5238 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5239 + err = au_cpup_wh(cpg, file);
5241 + struct au_cpup_wh_args args = {
5246 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5247 + if (unlikely(wkq_err))
5252 + mutex_unlock(&h_tmpdir->i_mutex);
5253 + /* todo: au_h_open_post()? */
5254 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5255 + au_set_h_dptr(parent, bdst, h_parent);
5256 + AuDebugOn(!pin_orig);
5257 + cpg->pin = pin_orig;
5265 +/* ---------------------------------------------------------------------- */
5268 + * generic routine for both of copy-up and copy-down.
5270 +/* cf. revalidate function in file.c */
5271 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5272 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5273 + struct au_pin *pin,
5274 + struct dentry *h_parent, void *arg),
5278 + struct au_pin pin;
5279 + struct dentry *d, *parent, *h_parent, *real_parent;
5282 + parent = dget_parent(dentry);
5283 + if (IS_ROOT(parent))
5286 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5287 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5289 + /* do not use au_dpage */
5290 + real_parent = parent;
5293 + parent = dget_parent(dentry);
5294 + h_parent = au_h_dptr(parent, bdst);
5296 + goto out; /* success */
5298 + /* find top dir which is necessary to cpup */
5302 + parent = dget_parent(d);
5303 + di_read_lock_parent3(parent, !AuLock_IR);
5304 + h_parent = au_h_dptr(parent, bdst);
5305 + di_read_unlock(parent, !AuLock_IR);
5306 + } while (!h_parent);
5308 + if (d != real_parent)
5309 + di_write_lock_child3(d);
5311 + /* somebody else might create while we were sleeping */
5312 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
5313 + if (au_h_dptr(d, bdst))
5314 + au_update_dbstart(d);
5316 + au_pin_set_dentry(&pin, d);
5317 + err = au_do_pin(&pin);
5319 + err = cp(d, bdst, &pin, h_parent, arg);
5324 + if (d != real_parent)
5325 + di_write_unlock(d);
5326 + if (unlikely(err))
5335 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5336 + struct au_pin *pin,
5337 + struct dentry *h_parent __maybe_unused ,
5338 + void *arg __maybe_unused)
5340 + struct au_cp_generic cpg = {
5346 + .flags = AuCpup_DTIME
5348 + return au_sio_cpup_simple(&cpg);
5351 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5353 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5356 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5359 + struct dentry *parent;
5360 + struct inode *dir;
5362 + parent = dget_parent(dentry);
5363 + dir = parent->d_inode;
5365 + if (au_h_iptr(dir, bdst))
5368 + di_read_unlock(parent, AuLock_IR);
5369 + di_write_lock_parent(parent);
5370 + /* someone else might change our inode while we were sleeping */
5371 + if (!au_h_iptr(dir, bdst))
5372 + err = au_cpup_dirs(dentry, bdst);
5373 + di_downgrade_lock(parent, AuLock_IR);
5379 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5380 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5381 +++ linux/fs/aufs/cpup.h 2014-04-24 22:11:10.848602379 +0200
5384 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5386 + * This program, aufs is free software; you can redistribute it and/or modify
5387 + * it under the terms of the GNU General Public License as published by
5388 + * the Free Software Foundation; either version 2 of the License, or
5389 + * (at your option) any later version.
5391 + * This program is distributed in the hope that it will be useful,
5392 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5393 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5394 + * GNU General Public License for more details.
5396 + * You should have received a copy of the GNU General Public License
5397 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5401 + * copy-up/down functions
5404 +#ifndef __AUFS_CPUP_H__
5405 +#define __AUFS_CPUP_H__
5409 +#include <linux/path.h>
5415 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5416 +void au_cpup_attr_timesizes(struct inode *inode);
5417 +void au_cpup_attr_nlink(struct inode *inode, int force);
5418 +void au_cpup_attr_changeable(struct inode *inode);
5419 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5420 +void au_cpup_attr_all(struct inode *inode, int force);
5422 +/* ---------------------------------------------------------------------- */
5424 +struct au_cp_generic {
5425 + struct dentry *dentry;
5426 + aufs_bindex_t bdst, bsrc;
5428 + struct au_pin *pin;
5429 + unsigned int flags;
5433 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5434 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5436 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5437 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5439 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5441 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5442 + the branch is marked as RO */
5444 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5445 +#define au_fset_cpup(flags, name) \
5446 + do { (flags) |= AuCpup_##name; } while (0)
5447 +#define au_fclr_cpup(flags, name) \
5448 + do { (flags) &= ~AuCpup_##name; } while (0)
5450 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5451 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5452 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5453 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5455 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5456 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5457 + struct au_pin *pin,
5458 + struct dentry *h_parent, void *arg),
5460 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5461 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5463 +/* ---------------------------------------------------------------------- */
5465 +/* keep timestamps when copyup */
5467 + struct dentry *dt_dentry;
5468 + struct path dt_h_path;
5469 + struct timespec dt_atime, dt_mtime;
5471 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5472 + struct path *h_path);
5473 +void au_dtime_revert(struct au_dtime *dt);
5475 +#endif /* __KERNEL__ */
5476 +#endif /* __AUFS_CPUP_H__ */
5477 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5478 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5479 +++ linux/fs/aufs/dbgaufs.c 2014-04-24 22:11:10.848602379 +0200
5482 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5484 + * This program, aufs is free software; you can redistribute it and/or modify
5485 + * it under the terms of the GNU General Public License as published by
5486 + * the Free Software Foundation; either version 2 of the License, or
5487 + * (at your option) any later version.
5489 + * This program is distributed in the hope that it will be useful,
5490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5492 + * GNU General Public License for more details.
5494 + * You should have received a copy of the GNU General Public License
5495 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5499 + * debugfs interface
5502 +#include <linux/debugfs.h>
5505 +#ifndef CONFIG_SYSFS
5506 +#error DEBUG_FS depends upon SYSFS
5509 +static struct dentry *dbgaufs;
5510 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5512 +/* 20 is max digits length of ulong 64 */
5513 +struct dbgaufs_arg {
5519 + * common function for all XINO files
5521 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5522 + struct file *file)
5524 + kfree(file->private_data);
5528 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5532 + struct dbgaufs_arg *p;
5535 + p = kmalloc(sizeof(*p), GFP_NOFS);
5541 + file->private_data = p;
5545 + err = vfs_getattr(&xf->f_path, &st);
5549 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5550 + (long)file_count(xf), st.blocks, st.blksize,
5551 + (long long)st.size);
5553 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5554 + st.blocks, st.blksize,
5555 + (long long)st.size);
5556 + AuDebugOn(p->n >= sizeof(p->a));
5558 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5567 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5568 + size_t count, loff_t *ppos)
5570 + struct dbgaufs_arg *p;
5572 + p = file->private_data;
5573 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5576 +/* ---------------------------------------------------------------------- */
5578 +struct dbgaufs_plink_arg {
5583 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
5584 + struct file *file)
5586 + free_page((unsigned long)file->private_data);
5590 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
5592 + int err, i, limit;
5593 + unsigned long n, sum;
5594 + struct dbgaufs_plink_arg *p;
5595 + struct au_sbinfo *sbinfo;
5596 + struct super_block *sb;
5597 + struct au_sphlhead *sphl;
5600 + p = (void *)get_zeroed_page(GFP_NOFS);
5605 + sbinfo = inode->i_private;
5606 + sb = sbinfo->si_sb;
5607 + si_noflush_read_lock(sb);
5608 + if (au_opt_test(au_mntflags(sb), PLINK)) {
5609 + limit = PAGE_SIZE - sizeof(p->n);
5611 + /* the number of buckets */
5612 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
5617 + for (i = 0, sphl = sbinfo->si_plink;
5618 + i < AuPlink_NHASH;
5620 + n = au_sphl_count(sphl);
5623 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5626 + if (unlikely(limit <= 0))
5629 + p->a[p->n - 1] = '\n';
5631 + /* the sum of plinks */
5632 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5635 + if (unlikely(limit <= 0))
5638 +#define str "1\n0\n0\n"
5639 + p->n = sizeof(str) - 1;
5640 + strcpy(p->a, str);
5643 + si_read_unlock(sb);
5646 + file->private_data = p;
5647 + goto out; /* success */
5650 + free_page((unsigned long)p);
5655 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5656 + size_t count, loff_t *ppos)
5658 + struct dbgaufs_plink_arg *p;
5660 + p = file->private_data;
5661 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5664 +static const struct file_operations dbgaufs_plink_fop = {
5665 + .owner = THIS_MODULE,
5666 + .open = dbgaufs_plink_open,
5667 + .release = dbgaufs_plink_release,
5668 + .read = dbgaufs_plink_read
5671 +/* ---------------------------------------------------------------------- */
5673 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5676 + struct au_sbinfo *sbinfo;
5677 + struct super_block *sb;
5679 + sbinfo = inode->i_private;
5680 + sb = sbinfo->si_sb;
5681 + si_noflush_read_lock(sb);
5682 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5683 + si_read_unlock(sb);
5687 +static const struct file_operations dbgaufs_xib_fop = {
5688 + .owner = THIS_MODULE,
5689 + .open = dbgaufs_xib_open,
5690 + .release = dbgaufs_xi_release,
5691 + .read = dbgaufs_xi_read
5694 +/* ---------------------------------------------------------------------- */
5696 +#define DbgaufsXi_PREFIX "xi"
5698 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5702 + struct au_sbinfo *sbinfo;
5703 + struct super_block *sb;
5705 + struct qstr *name;
5709 + name = &file->f_dentry->d_name;
5710 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5711 + || memcmp(name->name, DbgaufsXi_PREFIX,
5712 + sizeof(DbgaufsXi_PREFIX) - 1)))
5714 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5715 + if (unlikely(err))
5718 + sbinfo = inode->i_private;
5719 + sb = sbinfo->si_sb;
5720 + si_noflush_read_lock(sb);
5721 + if (l <= au_sbend(sb)) {
5722 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5723 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5726 + si_read_unlock(sb);
5732 +static const struct file_operations dbgaufs_xino_fop = {
5733 + .owner = THIS_MODULE,
5734 + .open = dbgaufs_xino_open,
5735 + .release = dbgaufs_xi_release,
5736 + .read = dbgaufs_xi_read
5739 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5741 + aufs_bindex_t bend;
5742 + struct au_branch *br;
5743 + struct au_xino_file *xi;
5745 + if (!au_sbi(sb)->si_dbgaufs)
5748 + bend = au_sbend(sb);
5749 + for (; bindex <= bend; bindex++) {
5750 + br = au_sbr(sb, bindex);
5751 + xi = &br->br_xino;
5752 + debugfs_remove(xi->xi_dbgaufs);
5753 + xi->xi_dbgaufs = NULL;
5757 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5759 + struct au_sbinfo *sbinfo;
5760 + struct dentry *parent;
5761 + struct au_branch *br;
5762 + struct au_xino_file *xi;
5763 + aufs_bindex_t bend;
5764 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5766 + sbinfo = au_sbi(sb);
5767 + parent = sbinfo->si_dbgaufs;
5771 + bend = au_sbend(sb);
5772 + for (; bindex <= bend; bindex++) {
5773 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5774 + br = au_sbr(sb, bindex);
5775 + xi = &br->br_xino;
5776 + AuDebugOn(xi->xi_dbgaufs);
5777 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5778 + sbinfo, &dbgaufs_xino_fop);
5779 + /* ignore an error */
5780 + if (unlikely(!xi->xi_dbgaufs))
5781 + AuWarn1("failed %s under debugfs\n", name);
5785 +/* ---------------------------------------------------------------------- */
5787 +#ifdef CONFIG_AUFS_EXPORT
5788 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5791 + struct au_sbinfo *sbinfo;
5792 + struct super_block *sb;
5794 + sbinfo = inode->i_private;
5795 + sb = sbinfo->si_sb;
5796 + si_noflush_read_lock(sb);
5797 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5798 + si_read_unlock(sb);
5802 +static const struct file_operations dbgaufs_xigen_fop = {
5803 + .owner = THIS_MODULE,
5804 + .open = dbgaufs_xigen_open,
5805 + .release = dbgaufs_xi_release,
5806 + .read = dbgaufs_xi_read
5809 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5814 + * This function is a dynamic '__init' fucntion actually,
5815 + * so the tiny check for si_rwsem is unnecessary.
5817 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5820 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
5821 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5822 + &dbgaufs_xigen_fop);
5823 + if (sbinfo->si_dbgaufs_xigen)
5829 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5833 +#endif /* CONFIG_AUFS_EXPORT */
5835 +/* ---------------------------------------------------------------------- */
5837 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
5840 + * This function is a dynamic '__init' fucntion actually,
5841 + * so the tiny check for si_rwsem is unnecessary.
5843 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5845 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
5846 + sbinfo->si_dbgaufs = NULL;
5847 + kobject_put(&sbinfo->si_kobj);
5850 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
5853 + char name[SysaufsSiNameLen];
5856 + * This function is a dynamic '__init' fucntion actually,
5857 + * so the tiny check for si_rwsem is unnecessary.
5859 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5863 + AuErr1("/debug/aufs is uninitialized\n");
5868 + sysaufs_name(sbinfo, name);
5869 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
5870 + if (unlikely(!sbinfo->si_dbgaufs))
5872 + kobject_get(&sbinfo->si_kobj);
5874 + sbinfo->si_dbgaufs_xib = debugfs_create_file
5875 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5876 + &dbgaufs_xib_fop);
5877 + if (unlikely(!sbinfo->si_dbgaufs_xib))
5880 + sbinfo->si_dbgaufs_plink = debugfs_create_file
5881 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5882 + &dbgaufs_plink_fop);
5883 + if (unlikely(!sbinfo->si_dbgaufs_plink))
5886 + err = dbgaufs_xigen_init(sbinfo);
5888 + goto out; /* success */
5891 + dbgaufs_si_fin(sbinfo);
5896 +/* ---------------------------------------------------------------------- */
5898 +void dbgaufs_fin(void)
5900 + debugfs_remove(dbgaufs);
5903 +int __init dbgaufs_init(void)
5908 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
5913 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
5914 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
5915 +++ linux/fs/aufs/dbgaufs.h 2014-04-24 22:11:10.848602379 +0200
5918 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5920 + * This program, aufs is free software; you can redistribute it and/or modify
5921 + * it under the terms of the GNU General Public License as published by
5922 + * the Free Software Foundation; either version 2 of the License, or
5923 + * (at your option) any later version.
5925 + * This program is distributed in the hope that it will be useful,
5926 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5927 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5928 + * GNU General Public License for more details.
5930 + * You should have received a copy of the GNU General Public License
5931 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5935 + * debugfs interface
5938 +#ifndef __DBGAUFS_H__
5939 +#define __DBGAUFS_H__
5943 +struct super_block;
5946 +#ifdef CONFIG_DEBUG_FS
5948 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
5949 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
5950 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
5951 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
5952 +void dbgaufs_fin(void);
5953 +int __init dbgaufs_init(void);
5955 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
5956 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
5957 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
5958 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
5959 +AuStubVoid(dbgaufs_fin, void)
5960 +AuStubInt0(__init dbgaufs_init, void)
5961 +#endif /* CONFIG_DEBUG_FS */
5963 +#endif /* __KERNEL__ */
5964 +#endif /* __DBGAUFS_H__ */
5965 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
5966 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
5967 +++ linux/fs/aufs/dcsub.c 2014-04-24 22:11:10.848602379 +0200
5970 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5972 + * This program, aufs is free software; you can redistribute it and/or modify
5973 + * it under the terms of the GNU General Public License as published by
5974 + * the Free Software Foundation; either version 2 of the License, or
5975 + * (at your option) any later version.
5977 + * This program is distributed in the hope that it will be useful,
5978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5980 + * GNU General Public License for more details.
5982 + * You should have received a copy of the GNU General Public License
5983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5987 + * sub-routines for dentry cache
5992 +static void au_dpage_free(struct au_dpage *dpage)
5995 + struct dentry **p;
5997 + p = dpage->dentries;
5998 + for (i = 0; i < dpage->ndentry; i++)
6000 + free_page((unsigned long)dpage->dentries);
6003 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6009 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6010 + if (unlikely(!dpages->dpages))
6013 + p = (void *)__get_free_page(gfp);
6017 + dpages->dpages[0].ndentry = 0;
6018 + dpages->dpages[0].dentries = p;
6019 + dpages->ndpage = 1;
6020 + return 0; /* success */
6023 + kfree(dpages->dpages);
6028 +void au_dpages_free(struct au_dcsub_pages *dpages)
6031 + struct au_dpage *p;
6033 + p = dpages->dpages;
6034 + for (i = 0; i < dpages->ndpage; i++)
6035 + au_dpage_free(p++);
6036 + kfree(dpages->dpages);
6039 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6040 + struct dentry *dentry, gfp_t gfp)
6043 + struct au_dpage *dpage;
6046 + dpage = dpages->dpages + dpages->ndpage - 1;
6047 + sz = PAGE_SIZE / sizeof(dentry);
6048 + if (unlikely(dpage->ndentry >= sz)) {
6049 + AuLabel(new dpage);
6051 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6052 + p = au_kzrealloc(dpages->dpages, sz,
6053 + sz + sizeof(*dpages->dpages), gfp);
6057 + dpages->dpages = p;
6058 + dpage = dpages->dpages + dpages->ndpage;
6059 + p = (void *)__get_free_page(gfp);
6063 + dpage->ndentry = 0;
6064 + dpage->dentries = p;
6068 + AuDebugOn(!d_count(dentry));
6069 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6070 + return 0; /* success */
6076 +/* try d_walk() in linux/fs/dcache.c */
6077 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6078 + au_dpages_test test, void *arg)
6081 + struct dentry *this_parent;
6082 + struct list_head *next;
6083 + struct super_block *sb = root->d_sb;
6086 + write_seqlock(&rename_lock);
6087 + this_parent = root;
6088 + spin_lock(&this_parent->d_lock);
6090 + next = this_parent->d_subdirs.next;
6092 + if (this_parent->d_sb == sb
6093 + && !IS_ROOT(this_parent)
6094 + && au_di(this_parent)
6095 + && d_count(this_parent)
6096 + && (!test || test(this_parent, arg))) {
6097 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
6098 + if (unlikely(err))
6102 + while (next != &this_parent->d_subdirs) {
6103 + struct list_head *tmp = next;
6104 + struct dentry *dentry = list_entry(tmp, struct dentry,
6108 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
6109 + if (d_count(dentry)) {
6110 + if (!list_empty(&dentry->d_subdirs)) {
6111 + spin_unlock(&this_parent->d_lock);
6112 + spin_release(&dentry->d_lock.dep_map, 1,
6114 + this_parent = dentry;
6115 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
6119 + if (dentry->d_sb == sb
6121 + && (!test || test(dentry, arg)))
6122 + err = au_dpages_append(dpages, dentry,
6125 + spin_unlock(&dentry->d_lock);
6126 + if (unlikely(err))
6130 + if (this_parent != root) {
6131 + struct dentry *tmp;
6132 + struct dentry *child;
6134 + tmp = this_parent->d_parent;
6136 + spin_unlock(&this_parent->d_lock);
6137 + child = this_parent;
6138 + this_parent = tmp;
6139 + spin_lock(&this_parent->d_lock);
6140 + rcu_read_unlock();
6141 + next = child->d_u.d_child.next;
6146 + spin_unlock(&this_parent->d_lock);
6147 + write_sequnlock(&rename_lock);
6151 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6152 + int do_include, au_dpages_test test, void *arg)
6157 + write_seqlock(&rename_lock);
6158 + spin_lock(&dentry->d_lock);
6160 + && d_count(dentry)
6161 + && (!test || test(dentry, arg)))
6162 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6163 + spin_unlock(&dentry->d_lock);
6164 + if (unlikely(err))
6168 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6171 + while (!IS_ROOT(dentry)) {
6172 + dentry = dentry->d_parent; /* rename_lock is locked */
6173 + spin_lock(&dentry->d_lock);
6174 + if (d_count(dentry)
6175 + && (!test || test(dentry, arg)))
6176 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6177 + spin_unlock(&dentry->d_lock);
6178 + if (unlikely(err))
6183 + write_sequnlock(&rename_lock);
6187 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6189 + return au_di(dentry) && dentry->d_sb == arg;
6192 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6193 + struct dentry *dentry, int do_include)
6195 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6196 + au_dcsub_dpages_aufs, dentry->d_sb);
6199 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6201 + struct path path[2] = {
6210 + return path_is_under(path + 0, path + 1);
6212 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6213 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6214 +++ linux/fs/aufs/dcsub.h 2014-04-24 22:11:10.848602379 +0200
6217 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6219 + * This program, aufs is free software; you can redistribute it and/or modify
6220 + * it under the terms of the GNU General Public License as published by
6221 + * the Free Software Foundation; either version 2 of the License, or
6222 + * (at your option) any later version.
6224 + * This program is distributed in the hope that it will be useful,
6225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6227 + * GNU General Public License for more details.
6229 + * You should have received a copy of the GNU General Public License
6230 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6234 + * sub-routines for dentry cache
6237 +#ifndef __AUFS_DCSUB_H__
6238 +#define __AUFS_DCSUB_H__
6242 +#include <linux/dcache.h>
6243 +#include <linux/fs.h>
6249 + struct dentry **dentries;
6252 +struct au_dcsub_pages {
6254 + struct au_dpage *dpages;
6257 +/* ---------------------------------------------------------------------- */
6260 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6261 +void au_dpages_free(struct au_dcsub_pages *dpages);
6262 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6263 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6264 + au_dpages_test test, void *arg);
6265 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6266 + int do_include, au_dpages_test test, void *arg);
6267 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6268 + struct dentry *dentry, int do_include);
6269 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6271 +/* ---------------------------------------------------------------------- */
6274 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6275 + * include/linux/dcache.h. Try them (in the future).
6278 +static inline int au_d_hashed_positive(struct dentry *d)
6281 + struct inode *inode = d->d_inode;
6283 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
6288 +static inline int au_d_alive(struct dentry *d)
6291 + struct inode *inode;
6294 + err = au_d_hashed_positive(d);
6296 + inode = d->d_inode;
6297 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
6303 +static inline int au_alive_dir(struct dentry *d)
6306 + err = au_d_alive(d);
6307 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
6312 +#endif /* __KERNEL__ */
6313 +#endif /* __AUFS_DCSUB_H__ */
6314 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6315 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6316 +++ linux/fs/aufs/debug.c 2014-04-24 22:11:10.848602379 +0200
6319 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6321 + * This program, aufs is free software; you can redistribute it and/or modify
6322 + * it under the terms of the GNU General Public License as published by
6323 + * the Free Software Foundation; either version 2 of the License, or
6324 + * (at your option) any later version.
6326 + * This program is distributed in the hope that it will be useful,
6327 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6328 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6329 + * GNU General Public License for more details.
6331 + * You should have received a copy of the GNU General Public License
6332 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6336 + * debug print functions
6339 +#include <linux/vt_kern.h>
6342 +/* Returns 0, or -errno. arg is in kp->arg. */
6343 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6347 + err = kstrtoint(val, 0, &n);
6357 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6358 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6363 + return sprintf(buffer, "%d", atomic_read(a));
6366 +static struct kernel_param_ops param_ops_atomic_t = {
6367 + .set = param_atomic_t_set,
6368 + .get = param_atomic_t_get
6369 + /* void (*free)(void *arg) */
6372 +atomic_t aufs_debug = ATOMIC_INIT(0);
6373 +MODULE_PARM_DESC(debug, "debug print");
6374 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6376 +char *au_plevel = KERN_DEBUG;
6377 +#define dpri(fmt, ...) do { \
6379 + && strcmp(au_plevel, KERN_DEBUG)) \
6380 + || au_debug_test()) \
6381 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6384 +/* ---------------------------------------------------------------------- */
6386 +void au_dpri_whlist(struct au_nhash *whlist)
6388 + unsigned long ul, n;
6389 + struct hlist_head *head;
6390 + struct au_vdir_wh *pos;
6392 + n = whlist->nh_num;
6393 + head = whlist->nh_head;
6394 + for (ul = 0; ul < n; ul++) {
6395 + hlist_for_each_entry(pos, head, wh_hash)
6396 + dpri("b%d, %.*s, %d\n",
6398 + pos->wh_str.len, pos->wh_str.name,
6404 +void au_dpri_vdir(struct au_vdir *vdir)
6407 + union au_vdir_deblk_p p;
6410 + if (!vdir || IS_ERR(vdir)) {
6411 + dpri("err %ld\n", PTR_ERR(vdir));
6415 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6416 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6417 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6418 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6419 + p.deblk = vdir->vd_deblk[ul];
6421 + dpri("[%lu]: %p\n", ul, o);
6425 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6426 + struct dentry *wh)
6431 + if (!inode || IS_ERR(inode)) {
6432 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6436 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6437 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6438 + && sizeof(inode->i_blocks) != sizeof(u64));
6440 + n = (void *)wh->d_name.name;
6441 + l = wh->d_name.len;
6444 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6445 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6447 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6448 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6449 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6450 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6451 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6452 + inode->i_state, inode->i_flags, inode->i_version,
6453 + inode->i_generation,
6454 + l ? ", wh " : "", l, n);
6458 +void au_dpri_inode(struct inode *inode)
6460 + struct au_iinfo *iinfo;
6461 + aufs_bindex_t bindex;
6464 + err = do_pri_inode(-1, inode, -1, NULL);
6465 + if (err || !au_test_aufs(inode->i_sb))
6468 + iinfo = au_ii(inode);
6471 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6472 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6473 + if (iinfo->ii_bstart < 0)
6476 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6477 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6478 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6479 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6483 +void au_dpri_dalias(struct inode *inode)
6487 + spin_lock(&inode->i_lock);
6488 + hlist_for_each_entry(d, &inode->i_dentry, d_alias)
6489 + au_dpri_dentry(d);
6490 + spin_unlock(&inode->i_lock);
6493 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6495 + struct dentry *wh = NULL;
6498 + if (!dentry || IS_ERR(dentry)) {
6499 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6502 + /* do not call dget_parent() here */
6503 + /* note: access d_xxx without d_lock */
6504 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6505 + bindex, dentry, dentry,
6506 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6507 + d_count(dentry), dentry->d_flags,
6508 + d_unhashed(dentry) ? "un" : "");
6510 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
6511 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
6513 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6514 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6517 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
6521 +void au_dpri_dentry(struct dentry *dentry)
6523 + struct au_dinfo *dinfo;
6524 + aufs_bindex_t bindex;
6526 + struct au_hdentry *hdp;
6528 + err = do_pri_dentry(-1, dentry);
6529 + if (err || !au_test_aufs(dentry->d_sb))
6532 + dinfo = au_di(dentry);
6535 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
6536 + dinfo->di_bstart, dinfo->di_bend,
6537 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
6538 + if (dinfo->di_bstart < 0)
6540 + hdp = dinfo->di_hdentry;
6541 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6542 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6545 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
6549 + if (!file || IS_ERR(file)) {
6550 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
6556 + && au_test_aufs(file->f_dentry->d_sb)
6558 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
6559 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
6560 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
6561 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
6562 + file->f_version, file->f_pos, a);
6563 + if (file->f_dentry)
6564 + do_pri_dentry(bindex, file->f_dentry);
6568 +void au_dpri_file(struct file *file)
6570 + struct au_finfo *finfo;
6571 + struct au_fidir *fidir;
6572 + struct au_hfile *hfile;
6573 + aufs_bindex_t bindex;
6576 + err = do_pri_file(-1, file);
6577 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
6580 + finfo = au_fi(file);
6583 + if (finfo->fi_btop < 0)
6585 + fidir = finfo->fi_hdir;
6587 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
6589 + for (bindex = finfo->fi_btop;
6590 + bindex >= 0 && bindex <= fidir->fd_bbot;
6592 + hfile = fidir->fd_hfile + bindex;
6593 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
6597 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
6599 + struct vfsmount *mnt;
6600 + struct super_block *sb;
6602 + if (!br || IS_ERR(br))
6604 + mnt = au_br_mnt(br);
6605 + if (!mnt || IS_ERR(mnt))
6608 + if (!sb || IS_ERR(sb))
6611 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
6612 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
6614 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
6615 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
6616 + sb->s_flags, sb->s_count,
6617 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
6621 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6625 +void au_dpri_sb(struct super_block *sb)
6627 + struct au_sbinfo *sbinfo;
6628 + aufs_bindex_t bindex;
6630 + /* to reuduce stack size */
6632 + struct vfsmount mnt;
6633 + struct au_branch fake;
6636 + /* this function can be called from magic sysrq */
6637 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6638 + if (unlikely(!a)) {
6639 + dpri("no memory\n");
6643 + a->mnt.mnt_sb = sb;
6644 + a->fake.br_perm = 0;
6645 + a->fake.br_path.mnt = &a->mnt;
6646 + a->fake.br_xino.xi_file = NULL;
6647 + atomic_set(&a->fake.br_count, 0);
6648 + smp_mb(); /* atomic_set */
6649 + err = do_pri_br(-1, &a->fake);
6651 + dpri("dev 0x%x\n", sb->s_dev);
6652 + if (err || !au_test_aufs(sb))
6655 + sbinfo = au_sbi(sb);
6658 + dpri("nw %d, gen %u, kobj %d\n",
6659 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6660 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6661 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6662 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6665 +/* ---------------------------------------------------------------------- */
6667 +void au_dbg_sleep_jiffy(int jiffy)
6670 + jiffy = schedule_timeout_uninterruptible(jiffy);
6673 +void au_dbg_iattr(struct iattr *ia)
6675 +#define AuBit(name) \
6677 + if (ia->ia_valid & ATTR_ ## name) \
6678 + dpri(#name "\n"); \
6698 + dpri("ia_file %p\n", ia->ia_file);
6701 +/* ---------------------------------------------------------------------- */
6703 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
6705 + struct inode *h_inode, *inode = dentry->d_inode;
6706 + struct dentry *h_dentry;
6707 + aufs_bindex_t bindex, bend, bi;
6709 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
6712 + bend = au_dbend(dentry);
6713 + bi = au_ibend(inode);
6716 + bindex = au_dbstart(dentry);
6717 + bi = au_ibstart(inode);
6721 + for (; bindex <= bend; bindex++) {
6722 + h_dentry = au_h_dptr(dentry, bindex);
6725 + h_inode = au_h_iptr(inode, bindex);
6726 + if (unlikely(h_inode != h_dentry->d_inode)) {
6728 + AuDbg("b%d, %s:%d\n", bindex, func, line);
6729 + AuDbgDentry(dentry);
6730 + AuDbgInode(inode);
6737 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
6739 + struct dentry *parent;
6741 + parent = dget_parent(dentry);
6742 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
6743 + AuDebugOn(IS_ROOT(dentry));
6744 + AuDebugOn(au_digen_test(parent, sigen));
6748 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
6750 + struct dentry *parent;
6751 + struct inode *inode;
6753 + parent = dget_parent(dentry);
6754 + inode = dentry->d_inode;
6755 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
6756 + AuDebugOn(au_digen_test(parent, sigen));
6760 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6763 + struct au_dcsub_pages dpages;
6764 + struct au_dpage *dpage;
6765 + struct dentry **dentries;
6767 + err = au_dpages_init(&dpages, GFP_NOFS);
6769 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6771 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6772 + dpage = dpages.dpages + i;
6773 + dentries = dpage->dentries;
6774 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6775 + AuDebugOn(au_digen_test(dentries[j], sigen));
6777 + au_dpages_free(&dpages);
6780 +void au_dbg_verify_kthread(void)
6782 + if (au_wkq_test()) {
6785 + * It may be recursive, but udba=notify between two aufs mounts,
6786 + * where a single ro branch is shared, is not a problem.
6792 +/* ---------------------------------------------------------------------- */
6794 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
6796 +#ifdef AuForceNoPlink
6797 + au_opt_clr(sbinfo->si_mntflags, PLINK);
6799 +#ifdef AuForceNoXino
6800 + au_opt_clr(sbinfo->si_mntflags, XINO);
6802 +#ifdef AuForceNoRefrof
6803 + au_opt_clr(sbinfo->si_mntflags, REFROF);
6805 +#ifdef AuForceHnotify
6806 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
6809 + sbinfo->si_rdblk = 0;
6810 + sbinfo->si_rdhash = 0;
6814 +int __init au_debug_init(void)
6816 + aufs_bindex_t bindex;
6817 + struct au_vdir_destr destr;
6820 + AuDebugOn(bindex >= 0);
6823 + AuDebugOn(destr.len < NAME_MAX);
6825 +#ifdef CONFIG_4KSTACKS
6826 + pr_warn("CONFIG_4KSTACKS is defined.\n");
6829 +#ifdef AuForceNoBrs
6835 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
6836 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
6837 +++ linux/fs/aufs/debug.h 2014-04-24 22:11:10.848602379 +0200
6840 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6842 + * This program, aufs is free software; you can redistribute it and/or modify
6843 + * it under the terms of the GNU General Public License as published by
6844 + * the Free Software Foundation; either version 2 of the License, or
6845 + * (at your option) any later version.
6847 + * This program is distributed in the hope that it will be useful,
6848 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6849 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6850 + * GNU General Public License for more details.
6852 + * You should have received a copy of the GNU General Public License
6853 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6857 + * debug print functions
6860 +#ifndef __AUFS_DEBUG_H__
6861 +#define __AUFS_DEBUG_H__
6865 +#include <linux/atomic.h>
6866 +#include <linux/module.h>
6867 +#include <linux/kallsyms.h>
6868 +#include <linux/sysrq.h>
6870 +#ifdef CONFIG_AUFS_DEBUG
6871 +#define AuDebugOn(a) BUG_ON(a)
6873 +/* module parameter */
6874 +extern atomic_t aufs_debug;
6875 +static inline void au_debug_on(void)
6877 + atomic_inc(&aufs_debug);
6879 +static inline void au_debug_off(void)
6881 + atomic_dec_if_positive(&aufs_debug);
6884 +static inline int au_debug_test(void)
6886 + return atomic_read(&aufs_debug) > 0;
6889 +#define AuDebugOn(a) do {} while (0)
6890 +AuStubVoid(au_debug_on, void)
6891 +AuStubVoid(au_debug_off, void)
6892 +AuStubInt0(au_debug_test, void)
6893 +#endif /* CONFIG_AUFS_DEBUG */
6895 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
6897 +/* ---------------------------------------------------------------------- */
6901 +#define AuDbg(fmt, ...) do { \
6902 + if (au_debug_test()) \
6903 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
6905 +#define AuLabel(l) AuDbg(#l "\n")
6906 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
6907 +#define AuWarn1(fmt, ...) do { \
6908 + static unsigned char _c; \
6910 + pr_warn(fmt, ##__VA_ARGS__); \
6913 +#define AuErr1(fmt, ...) do { \
6914 + static unsigned char _c; \
6916 + pr_err(fmt, ##__VA_ARGS__); \
6919 +#define AuIOErr1(fmt, ...) do { \
6920 + static unsigned char _c; \
6922 + AuIOErr(fmt, ##__VA_ARGS__); \
6925 +#define AuUnsupportMsg "This operation is not supported." \
6926 + " Please report this application to aufs-users ML."
6927 +#define AuUnsupport(fmt, ...) do { \
6928 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
6932 +#define AuTraceErr(e) do { \
6933 + if (unlikely((e) < 0)) \
6934 + AuDbg("err %d\n", (int)(e)); \
6937 +#define AuTraceErrPtr(p) do { \
6939 + AuDbg("err %ld\n", PTR_ERR(p)); \
6942 +/* dirty macros for debug print, use with "%.*s" and caution */
6943 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
6945 +/* ---------------------------------------------------------------------- */
6950 +#ifdef CONFIG_AUFS_DEBUG
6951 +extern char *au_plevel;
6953 +void au_dpri_whlist(struct au_nhash *whlist);
6955 +void au_dpri_vdir(struct au_vdir *vdir);
6957 +void au_dpri_inode(struct inode *inode);
6958 +void au_dpri_dalias(struct inode *inode);
6959 +void au_dpri_dentry(struct dentry *dentry);
6961 +void au_dpri_file(struct file *filp);
6962 +struct super_block;
6963 +void au_dpri_sb(struct super_block *sb);
6965 +void au_dbg_sleep_jiffy(int jiffy);
6967 +void au_dbg_iattr(struct iattr *ia);
6969 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
6970 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
6971 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
6972 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
6973 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
6974 +void au_dbg_verify_kthread(void);
6976 +int __init au_debug_init(void);
6977 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
6978 +#define AuDbgWhlist(w) do { \
6980 + au_dpri_whlist(w); \
6983 +#define AuDbgVdir(v) do { \
6985 + au_dpri_vdir(v); \
6988 +#define AuDbgInode(i) do { \
6990 + au_dpri_inode(i); \
6993 +#define AuDbgDAlias(i) do { \
6995 + au_dpri_dalias(i); \
6998 +#define AuDbgDentry(d) do { \
7000 + au_dpri_dentry(d); \
7003 +#define AuDbgFile(f) do { \
7005 + au_dpri_file(f); \
7008 +#define AuDbgSb(sb) do { \
7009 + AuDbg(#sb "\n"); \
7013 +#define AuDbgSleep(sec) do { \
7014 + AuDbg("sleep %d sec\n", sec); \
7018 +#define AuDbgSleepJiffy(jiffy) do { \
7019 + AuDbg("sleep %d jiffies\n", jiffy); \
7020 + au_dbg_sleep_jiffy(jiffy); \
7023 +#define AuDbgIAttr(ia) do { \
7024 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
7025 + au_dbg_iattr(ia); \
7028 +#define AuDbgSym(addr) do { \
7029 + char sym[KSYM_SYMBOL_LEN]; \
7030 + sprint_symbol(sym, (unsigned long)addr); \
7031 + AuDbg("%s\n", sym); \
7034 +#define AuInfoSym(addr) do { \
7035 + char sym[KSYM_SYMBOL_LEN]; \
7036 + sprint_symbol(sym, (unsigned long)addr); \
7037 + AuInfo("%s\n", sym); \
7040 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7041 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
7042 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
7043 + unsigned int sigen)
7044 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7045 +AuStubVoid(au_dbg_verify_kthread, void)
7046 +AuStubInt0(__init au_debug_init, void)
7047 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
7049 +#define AuDbgWhlist(w) do {} while (0)
7050 +#define AuDbgVdir(v) do {} while (0)
7051 +#define AuDbgInode(i) do {} while (0)
7052 +#define AuDbgDAlias(i) do {} while (0)
7053 +#define AuDbgDentry(d) do {} while (0)
7054 +#define AuDbgFile(f) do {} while (0)
7055 +#define AuDbgSb(sb) do {} while (0)
7056 +#define AuDbgSleep(sec) do {} while (0)
7057 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
7058 +#define AuDbgIAttr(ia) do {} while (0)
7059 +#define AuDbgSym(addr) do {} while (0)
7060 +#define AuInfoSym(addr) do {} while (0)
7061 +#endif /* CONFIG_AUFS_DEBUG */
7063 +/* ---------------------------------------------------------------------- */
7065 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7066 +int __init au_sysrq_init(void);
7067 +void au_sysrq_fin(void);
7069 +#ifdef CONFIG_HW_CONSOLE
7070 +#define au_dbg_blocked() do { \
7072 + handle_sysrq('w'); \
7075 +AuStubVoid(au_dbg_blocked, void)
7079 +AuStubInt0(__init au_sysrq_init, void)
7080 +AuStubVoid(au_sysrq_fin, void)
7081 +AuStubVoid(au_dbg_blocked, void)
7082 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7084 +#endif /* __KERNEL__ */
7085 +#endif /* __AUFS_DEBUG_H__ */
7086 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7087 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7088 +++ linux/fs/aufs/dentry.c 2014-04-24 22:11:10.848602379 +0200
7091 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7093 + * This program, aufs is free software; you can redistribute it and/or modify
7094 + * it under the terms of the GNU General Public License as published by
7095 + * the Free Software Foundation; either version 2 of the License, or
7096 + * (at your option) any later version.
7098 + * This program is distributed in the hope that it will be useful,
7099 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7101 + * GNU General Public License for more details.
7103 + * You should have received a copy of the GNU General Public License
7104 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7108 + * lookup and dentry operations
7111 +#include <linux/namei.h>
7114 +#define AuLkup_ALLOW_NEG 1
7115 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7116 +#define au_fset_lkup(flags, name) \
7117 + do { (flags) |= AuLkup_##name; } while (0)
7118 +#define au_fclr_lkup(flags, name) \
7119 + do { (flags) &= ~AuLkup_##name; } while (0)
7121 +struct au_do_lookup_args {
7122 + unsigned int flags;
7127 + * returns positive/negative dentry, NULL or an error.
7128 + * NULL means whiteout-ed or not-found.
7130 +static struct dentry*
7131 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7132 + aufs_bindex_t bindex, struct qstr *wh_name,
7133 + struct au_do_lookup_args *args)
7135 + struct dentry *h_dentry;
7136 + struct inode *h_inode, *inode;
7137 + struct au_branch *br;
7138 + int wh_found, opq;
7139 + unsigned char wh_able;
7140 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7143 + br = au_sbr(dentry->d_sb, bindex);
7144 + wh_able = !!au_br_whable(br->br_perm);
7146 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
7147 + h_dentry = ERR_PTR(wh_found);
7150 + if (unlikely(wh_found < 0))
7153 + /* We found a whiteout */
7154 + /* au_set_dbend(dentry, bindex); */
7155 + au_set_dbwh(dentry, bindex);
7157 + return NULL; /* success */
7160 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7161 + if (IS_ERR(h_dentry))
7164 + h_inode = h_dentry->d_inode;
7168 + } else if (wh_found
7169 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7172 + if (au_dbend(dentry) <= bindex)
7173 + au_set_dbend(dentry, bindex);
7174 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7175 + au_set_dbstart(dentry, bindex);
7176 + au_set_h_dptr(dentry, bindex, h_dentry);
7178 + inode = dentry->d_inode;
7179 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
7180 + || (inode && !S_ISDIR(inode->i_mode)))
7181 + goto out; /* success */
7183 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7184 + opq = au_diropq_test(h_dentry, br);
7185 + mutex_unlock(&h_inode->i_mutex);
7187 + au_set_dbdiropq(dentry, bindex);
7188 + else if (unlikely(opq < 0)) {
7189 + au_set_h_dptr(dentry, bindex, NULL);
7190 + h_dentry = ERR_PTR(opq);
7201 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7203 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7204 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7210 + * returns the number of lower positive dentries,
7211 + * otherwise an error.
7212 + * can be called at unlinking with @type is zero.
7214 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7216 + int npositive, err;
7217 + aufs_bindex_t bindex, btail, bdiropq;
7218 + unsigned char isdir;
7219 + struct qstr whname;
7220 + struct au_do_lookup_args args = {
7224 + const struct qstr *name = &dentry->d_name;
7225 + struct dentry *parent;
7226 + struct inode *inode;
7228 + err = au_test_shwh(dentry->d_sb, name);
7229 + if (unlikely(err))
7232 + err = au_wh_name_alloc(&whname, name);
7233 + if (unlikely(err))
7236 + inode = dentry->d_inode;
7237 + isdir = !!(inode && S_ISDIR(inode->i_mode));
7239 + au_fset_lkup(args.flags, ALLOW_NEG);
7242 + parent = dget_parent(dentry);
7243 + btail = au_dbtaildir(parent);
7244 + for (bindex = bstart; bindex <= btail; bindex++) {
7245 + struct dentry *h_parent, *h_dentry;
7246 + struct inode *h_inode, *h_dir;
7248 + h_dentry = au_h_dptr(dentry, bindex);
7250 + if (h_dentry->d_inode)
7252 + if (type != S_IFDIR)
7256 + h_parent = au_h_dptr(parent, bindex);
7259 + h_dir = h_parent->d_inode;
7260 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
7263 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7264 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7266 + mutex_unlock(&h_dir->i_mutex);
7267 + err = PTR_ERR(h_dentry);
7268 + if (IS_ERR(h_dentry))
7270 + au_fclr_lkup(args.flags, ALLOW_NEG);
7272 + if (au_dbwh(dentry) >= 0)
7276 + h_inode = h_dentry->d_inode;
7281 + args.type = h_inode->i_mode & S_IFMT;
7282 + if (args.type != S_IFDIR)
7285 + /* the type of lower may be different */
7286 + bdiropq = au_dbdiropq(dentry);
7287 + if (bdiropq >= 0 && bdiropq <= bindex)
7293 + AuLabel(positive);
7294 + au_update_dbstart(dentry);
7297 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
7298 + && au_dbstart(dentry) < 0)) {
7300 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7306 + kfree(whname.name);
7311 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
7312 + struct au_branch *br)
7314 + struct dentry *dentry;
7317 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
7318 + dentry = vfsub_lkup_one(name, parent);
7320 + struct vfsub_lkup_one_args args = {
7326 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7327 + if (unlikely(wkq_err))
7328 + dentry = ERR_PTR(wkq_err);
7335 + * lookup @dentry on @bindex which should be negative.
7337 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7340 + struct dentry *parent, *h_parent, *h_dentry;
7341 + struct au_branch *br;
7343 + parent = dget_parent(dentry);
7344 + h_parent = au_h_dptr(parent, bindex);
7345 + br = au_sbr(dentry->d_sb, bindex);
7347 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7349 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent, br);
7350 + err = PTR_ERR(h_dentry);
7351 + if (IS_ERR(h_dentry))
7353 + if (unlikely(h_dentry->d_inode)) {
7355 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7361 + if (bindex < au_dbstart(dentry))
7362 + au_set_dbstart(dentry, bindex);
7363 + if (au_dbend(dentry) < bindex)
7364 + au_set_dbend(dentry, bindex);
7365 + au_set_h_dptr(dentry, bindex, h_dentry);
7372 +/* ---------------------------------------------------------------------- */
7374 +/* subset of struct inode */
7376 + unsigned long i_ino;
7377 + /* unsigned int i_nlink; */
7383 + blkcnt_t i_blocks;
7388 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7390 + ia->i_ino = h_inode->i_ino;
7391 + /* ia->i_nlink = h_inode->i_nlink; */
7392 + ia->i_uid = h_inode->i_uid;
7393 + ia->i_gid = h_inode->i_gid;
7394 + ia->i_version = h_inode->i_version;
7396 + ia->i_size = h_inode->i_size;
7397 + ia->i_blocks = h_inode->i_blocks;
7399 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7402 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7404 + return ia->i_ino != h_inode->i_ino
7405 + /* || ia->i_nlink != h_inode->i_nlink */
7406 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7407 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7408 + || ia->i_version != h_inode->i_version
7410 + || ia->i_size != h_inode->i_size
7411 + || ia->i_blocks != h_inode->i_blocks
7413 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7416 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7417 + struct au_branch *br)
7420 + struct au_iattr ia;
7421 + struct inode *h_inode;
7422 + struct dentry *h_d;
7423 + struct super_block *h_sb;
7426 + memset(&ia, -1, sizeof(ia));
7427 + h_sb = h_dentry->d_sb;
7428 + h_inode = h_dentry->d_inode;
7430 + au_iattr_save(&ia, h_inode);
7431 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7432 + /* nfs d_revalidate may return 0 for negative dentry */
7433 + /* fuse d_revalidate always return 0 for negative dentry */
7436 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7437 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7438 + err = PTR_ERR(h_d);
7443 + if (unlikely(h_d != h_dentry
7444 + || h_d->d_inode != h_inode
7445 + || (h_inode && au_iattr_test(&ia, h_inode))))
7446 + err = au_busy_or_stale();
7454 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7455 + struct dentry *h_parent, struct au_branch *br)
7460 + if (udba == AuOpt_UDBA_REVAL
7461 + && !au_test_fs_remote(h_dentry->d_sb)) {
7463 + err = (h_dentry->d_parent->d_inode != h_dir);
7464 + } else if (udba != AuOpt_UDBA_NONE)
7465 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7470 +/* ---------------------------------------------------------------------- */
7472 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7475 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7476 + struct au_hdentry tmp, *p, *q;
7477 + struct au_dinfo *dinfo;
7478 + struct super_block *sb;
7480 + DiMustWriteLock(dentry);
7482 + sb = dentry->d_sb;
7483 + dinfo = au_di(dentry);
7484 + bend = dinfo->di_bend;
7485 + bwh = dinfo->di_bwh;
7486 + bdiropq = dinfo->di_bdiropq;
7487 + p = dinfo->di_hdentry + dinfo->di_bstart;
7488 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7489 + if (!p->hd_dentry)
7492 + new_bindex = au_br_index(sb, p->hd_id);
7493 + if (new_bindex == bindex)
7496 + if (dinfo->di_bwh == bindex)
7498 + if (dinfo->di_bdiropq == bindex)
7499 + bdiropq = new_bindex;
7500 + if (new_bindex < 0) {
7502 + p->hd_dentry = NULL;
7506 + /* swap two lower dentries, and loop again */
7507 + q = dinfo->di_hdentry + new_bindex;
7511 + if (tmp.hd_dentry) {
7517 + dinfo->di_bwh = -1;
7518 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7519 + dinfo->di_bwh = bwh;
7521 + dinfo->di_bdiropq = -1;
7523 + && bdiropq <= au_sbend(sb)
7524 + && au_sbr_whable(sb, bdiropq))
7525 + dinfo->di_bdiropq = bdiropq;
7528 + dinfo->di_bstart = -1;
7529 + dinfo->di_bend = -1;
7530 + bend = au_dbend(parent);
7531 + p = dinfo->di_hdentry;
7532 + for (bindex = 0; bindex <= bend; bindex++, p++)
7533 + if (p->hd_dentry) {
7534 + dinfo->di_bstart = bindex;
7538 + if (dinfo->di_bstart >= 0) {
7539 + p = dinfo->di_hdentry + bend;
7540 + for (bindex = bend; bindex >= 0; bindex--, p--)
7541 + if (p->hd_dentry) {
7542 + dinfo->di_bend = bindex;
7551 +static void au_do_hide(struct dentry *dentry)
7553 + struct inode *inode;
7555 + inode = dentry->d_inode;
7557 + if (!S_ISDIR(inode->i_mode)) {
7558 + if (inode->i_nlink && !d_unhashed(dentry))
7559 + drop_nlink(inode);
7561 + clear_nlink(inode);
7562 + /* stop next lookup */
7563 + inode->i_flags |= S_DEAD;
7565 + smp_mb(); /* necessary? */
7570 +static int au_hide_children(struct dentry *parent)
7572 + int err, i, j, ndentry;
7573 + struct au_dcsub_pages dpages;
7574 + struct au_dpage *dpage;
7575 + struct dentry *dentry;
7577 + err = au_dpages_init(&dpages, GFP_NOFS);
7578 + if (unlikely(err))
7580 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7581 + if (unlikely(err))
7584 + /* in reverse order */
7585 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7586 + dpage = dpages.dpages + i;
7587 + ndentry = dpage->ndentry;
7588 + for (j = ndentry - 1; j >= 0; j--) {
7589 + dentry = dpage->dentries[j];
7590 + if (dentry != parent)
7591 + au_do_hide(dentry);
7596 + au_dpages_free(&dpages);
7601 +static void au_hide(struct dentry *dentry)
7604 + struct inode *inode;
7606 + AuDbgDentry(dentry);
7607 + inode = dentry->d_inode;
7608 + if (inode && S_ISDIR(inode->i_mode)) {
7609 + /* shrink_dcache_parent(dentry); */
7610 + err = au_hide_children(dentry);
7611 + if (unlikely(err))
7612 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7615 + au_do_hide(dentry);
7619 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7621 + * a dirty branch is added
7622 + * - on the top of layers
7623 + * - in the middle of layers
7624 + * - to the bottom of layers
7626 + * on the added branch there exists
7629 + * - a same named entry
7631 + * * negative --> positive
7632 + * * positive --> positive
7633 + * - type is unchanged
7634 + * - type is changed
7636 + * * negative --> negative
7637 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7640 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7641 + struct au_dinfo *tmp)
7644 + aufs_bindex_t bindex, bend;
7646 + struct dentry *dentry;
7647 + struct inode *inode;
7650 + struct au_hdentry *hd;
7651 + struct inode *inode, *h_inode;
7652 + struct dentry *h_dentry;
7655 + AuDebugOn(dinfo->di_bstart < 0);
7656 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
7657 + orig_h.inode = orig_h.dentry->d_inode;
7660 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
7661 + memset(&tmp_h, 0, sizeof(tmp_h));
7662 + if (tmp->di_bstart >= 0) {
7663 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
7664 + tmp_h.inode = tmp_h.dentry->d_inode;
7666 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
7669 + inode = dentry->d_inode;
7670 + if (!orig_h.inode) {
7671 + AuDbg("nagative originally\n");
7677 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7678 + AuDebugOn(dinfo->di_bdiropq != -1);
7680 + if (!tmp_h.inode) {
7681 + AuDbg("negative --> negative\n");
7682 + /* should have only one negative lower */
7683 + if (tmp->di_bstart >= 0
7684 + && tmp->di_bstart < dinfo->di_bstart) {
7685 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
7686 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7687 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
7688 + au_di_cp(dinfo, tmp);
7689 + hd = tmp->di_hdentry + tmp->di_bstart;
7690 + au_set_h_dptr(dentry, tmp->di_bstart,
7691 + dget(hd->hd_dentry));
7693 + au_dbg_verify_dinode(dentry);
7695 + AuDbg("negative --> positive\n");
7697 + * similar to the behaviour of creating with bypassing
7699 + * unhash it in order to force an error in the
7700 + * succeeding create operation.
7701 + * we should not set S_DEAD here.
7704 + /* au_di_swap(tmp, dinfo); */
7705 + au_dbg_verify_dinode(dentry);
7708 + AuDbg("positive originally\n");
7709 + /* inode may be NULL */
7710 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
7711 + if (!tmp_h.inode) {
7712 + AuDbg("positive --> negative\n");
7713 + /* or bypassing aufs */
7715 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
7716 + dinfo->di_bwh = tmp->di_bwh;
7718 + err = au_refresh_hinode_self(inode);
7719 + au_dbg_verify_dinode(dentry);
7720 + } else if (orig_h.mode == tmp_h.mode) {
7721 + AuDbg("positive --> positive, same type\n");
7722 + if (!S_ISDIR(orig_h.mode)
7723 + && dinfo->di_bstart > tmp->di_bstart) {
7725 + * similar to the behaviour of removing and
7730 + err = au_refresh_hinode_self(inode);
7731 + au_dbg_verify_dinode(dentry);
7733 + /* fill empty slots */
7734 + if (dinfo->di_bstart > tmp->di_bstart)
7735 + dinfo->di_bstart = tmp->di_bstart;
7736 + if (dinfo->di_bend < tmp->di_bend)
7737 + dinfo->di_bend = tmp->di_bend;
7738 + dinfo->di_bwh = tmp->di_bwh;
7739 + dinfo->di_bdiropq = tmp->di_bdiropq;
7740 + hd = tmp->di_hdentry;
7741 + bend = dinfo->di_bend;
7742 + for (bindex = tmp->di_bstart; bindex <= bend;
7744 + if (au_h_dptr(dentry, bindex))
7746 + h_dentry = hd[bindex].hd_dentry;
7749 + h_inode = h_dentry->d_inode;
7750 + AuDebugOn(!h_inode);
7751 + AuDebugOn(orig_h.mode
7752 + != (h_inode->i_mode
7754 + au_set_h_dptr(dentry, bindex,
7757 + err = au_refresh_hinode(inode, dentry);
7758 + au_dbg_verify_dinode(dentry);
7761 + AuDbg("positive --> positive, different type\n");
7762 + /* similar to the behaviour of removing and creating */
7765 + err = au_refresh_hinode_self(inode);
7766 + au_dbg_verify_dinode(dentry);
7774 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7777 + unsigned int sigen;
7778 + struct au_dinfo *dinfo, *tmp;
7779 + struct super_block *sb;
7780 + struct inode *inode;
7782 + DiMustWriteLock(dentry);
7783 + AuDebugOn(IS_ROOT(dentry));
7784 + AuDebugOn(!parent->d_inode);
7786 + sb = dentry->d_sb;
7787 + inode = dentry->d_inode;
7788 + sigen = au_sigen(sb);
7789 + err = au_digen_test(parent, sigen);
7790 + if (unlikely(err))
7793 + dinfo = au_di(dentry);
7794 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7795 + if (unlikely(err))
7797 + ebrange = au_dbrange_test(dentry);
7799 + ebrange = au_do_refresh_hdentry(dentry, parent);
7801 + if (d_unhashed(dentry) || ebrange) {
7802 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
7804 + err = au_refresh_hinode_self(inode);
7805 + au_dbg_verify_dinode(dentry);
7807 + goto out_dgen; /* success */
7811 + /* temporary dinfo */
7812 + AuDbgDentry(dentry);
7814 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
7815 + if (unlikely(!tmp))
7817 + au_di_swap(tmp, dinfo);
7818 + /* returns the number of positive dentries */
7820 + * if current working dir is removed, it returns an error.
7821 + * but the dentry is legal.
7823 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
7824 + AuDbgDentry(dentry);
7825 + au_di_swap(tmp, dinfo);
7826 + if (err == -ENOENT)
7829 + /* compare/refresh by dinfo */
7830 + AuDbgDentry(dentry);
7831 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
7832 + au_dbg_verify_dinode(dentry);
7835 + au_rw_write_unlock(&tmp->di_rwsem);
7837 + if (unlikely(err))
7841 + au_update_digen(dentry);
7843 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
7844 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
7845 + AuDbgDentry(dentry);
7851 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
7852 + struct dentry *dentry, aufs_bindex_t bindex)
7857 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
7860 + AuDbg("b%d\n", bindex);
7862 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
7863 + * due to whiteout and branch permission.
7865 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
7866 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
7867 + /* it may return tri-state */
7868 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
7870 + if (unlikely(valid < 0))
7880 +/* todo: remove this */
7881 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
7882 + unsigned int flags, int do_udba)
7885 + umode_t mode, h_mode;
7886 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
7887 + unsigned char plus, unhashed, is_root, h_plus, h_nfs;
7888 + struct inode *h_inode, *h_cached_inode;
7889 + struct dentry *h_dentry;
7890 + struct qstr *name, *h_name;
7897 + unhashed = !!d_unhashed(dentry);
7898 + is_root = !!IS_ROOT(dentry);
7899 + name = &dentry->d_name;
7902 + * Theoretically, REVAL test should be unnecessary in case of
7904 + * But {fs,i}notify doesn't fire some necessary events,
7905 + * IN_ATTRIB for atime/nlink/pageio
7906 + * IN_DELETE for NFS dentry
7907 + * Let's do REVAL test too.
7909 + if (do_udba && inode) {
7910 + mode = (inode->i_mode & S_IFMT);
7911 + plus = (inode->i_nlink > 0);
7912 + ibs = au_ibstart(inode);
7913 + ibe = au_ibend(inode);
7916 + bstart = au_dbstart(dentry);
7918 + if (inode && S_ISDIR(inode->i_mode))
7919 + btail = au_dbtaildir(dentry);
7920 + for (bindex = bstart; bindex <= btail; bindex++) {
7921 + h_dentry = au_h_dptr(dentry, bindex);
7925 + AuDbg("b%d, %pd\n", bindex, h_dentry);
7926 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
7927 + spin_lock(&h_dentry->d_lock);
7928 + h_name = &h_dentry->d_name;
7929 + if (unlikely(do_udba
7932 + && (unhashed != !!d_unhashed(h_dentry)
7933 + || name->len != h_name->len
7934 + || memcmp(name->name, h_name->name,
7937 + && !(flags & LOOKUP_OPEN)
7938 + && (h_dentry->d_flags
7939 + & DCACHE_NFSFS_RENAMED)))
7941 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
7942 + unhashed, d_unhashed(h_dentry),
7943 + dentry, h_dentry);
7944 + spin_unlock(&h_dentry->d_lock);
7947 + spin_unlock(&h_dentry->d_lock);
7949 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
7950 + if (unlikely(err))
7951 + /* do not goto err, to keep the errno */
7954 + /* todo: plink too? */
7959 + h_inode = h_dentry->d_inode;
7960 + if (unlikely(!!inode != !!h_inode))
7965 + h_cached_inode = h_inode;
7967 + h_mode = (h_inode->i_mode & S_IFMT);
7968 + h_plus = (h_inode->i_nlink > 0);
7970 + if (inode && ibs <= bindex && bindex <= ibe)
7971 + h_cached_inode = au_h_iptr(inode, bindex);
7974 + if (unlikely(plus != h_plus))
7977 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
7979 + && !IS_ROOT(h_dentry)
7980 + && unhashed != d_unhashed(h_dentry)))
7983 + if (unlikely(mode != h_mode
7984 + || h_cached_inode != h_inode))
7997 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
7998 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8001 + struct dentry *parent;
8003 + if (!au_digen_test(dentry, sigen))
8006 + parent = dget_parent(dentry);
8007 + di_read_lock_parent(parent, AuLock_IR);
8008 + AuDebugOn(au_digen_test(parent, sigen));
8009 + au_dbg_verify_gen(parent, sigen);
8010 + err = au_refresh_dentry(dentry, parent);
8011 + di_read_unlock(parent, AuLock_IR);
8017 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8020 + struct dentry *d, *parent;
8021 + struct inode *inode;
8023 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8024 + return simple_reval_dpath(dentry, sigen);
8026 + /* slow loop, keep it simple and stupid */
8027 + /* cf: au_cpup_dirs() */
8030 + while (au_digen_test(dentry, sigen)) {
8034 + parent = dget_parent(d);
8035 + if (!au_digen_test(parent, sigen))
8040 + inode = d->d_inode;
8042 + di_write_lock_child2(d);
8044 + /* someone might update our dentry while we were sleeping */
8045 + if (au_digen_test(d, sigen)) {
8047 + * todo: consolidate with simple_reval_dpath(),
8048 + * do_refresh() and au_reval_for_attr().
8050 + di_read_lock_parent(parent, AuLock_IR);
8051 + err = au_refresh_dentry(d, parent);
8052 + di_read_unlock(parent, AuLock_IR);
8056 + di_write_unlock(d);
8058 + if (unlikely(err))
8066 + * if valid returns 1, otherwise 0.
8068 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8071 + unsigned int sigen;
8072 + unsigned char do_udba;
8073 + struct super_block *sb;
8074 + struct inode *inode;
8076 + /* todo: support rcu-walk? */
8077 + if (flags & LOOKUP_RCU)
8081 + if (unlikely(!au_di(dentry)))
8084 + inode = dentry->d_inode;
8085 + if (inode && is_bad_inode(inode))
8089 + sb = dentry->d_sb;
8092 + * i_mutex of parent dir may be held,
8093 + * but we should not return 'invalid' due to busy.
8095 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8096 + if (unlikely(err)) {
8101 + if (unlikely(au_dbrange_test(dentry))) {
8107 + sigen = au_sigen(sb);
8108 + if (au_digen_test(dentry, sigen)) {
8109 + AuDebugOn(IS_ROOT(dentry));
8110 + err = au_reval_dpath(dentry, sigen);
8111 + if (unlikely(err)) {
8116 + di_downgrade_lock(dentry, AuLock_IR);
8119 + if (!(flags & LOOKUP_OPEN)
8121 + && (IS_DEADDIR(inode) || !inode->i_nlink))
8124 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8125 + if (do_udba && inode) {
8126 + aufs_bindex_t bstart = au_ibstart(inode);
8127 + struct inode *h_inode;
8129 + if (bstart >= 0) {
8130 + h_inode = au_h_iptr(inode, bstart);
8131 + if (h_inode && au_test_higen(inode, h_inode))
8136 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8137 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8139 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8145 + di_downgrade_lock(dentry, AuLock_IR);
8147 + aufs_read_unlock(dentry, AuLock_IR);
8152 + AuDbg("%pd invalid, %d\n", dentry, valid);
8158 +static void aufs_d_release(struct dentry *dentry)
8160 + if (au_di(dentry)) {
8161 + au_di_fin(dentry);
8162 + au_hn_di_reinit(dentry);
8166 +const struct dentry_operations aufs_dop = {
8167 + .d_revalidate = aufs_d_revalidate,
8168 + .d_weak_revalidate = aufs_d_revalidate,
8169 + .d_release = aufs_d_release
8171 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8172 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8173 +++ linux/fs/aufs/dentry.h 2014-04-24 22:11:10.848602379 +0200
8176 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8178 + * This program, aufs is free software; you can redistribute it and/or modify
8179 + * it under the terms of the GNU General Public License as published by
8180 + * the Free Software Foundation; either version 2 of the License, or
8181 + * (at your option) any later version.
8183 + * This program is distributed in the hope that it will be useful,
8184 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8185 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8186 + * GNU General Public License for more details.
8188 + * You should have received a copy of the GNU General Public License
8189 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8193 + * lookup and dentry operations
8196 +#ifndef __AUFS_DENTRY_H__
8197 +#define __AUFS_DENTRY_H__
8201 +#include <linux/dcache.h>
8204 +struct au_hdentry {
8205 + struct dentry *hd_dentry;
8206 + aufs_bindex_t hd_id;
8210 + atomic_t di_generation;
8212 + struct au_rwsem di_rwsem;
8213 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8214 + struct au_hdentry *di_hdentry;
8215 +} ____cacheline_aligned_in_smp;
8217 +/* ---------------------------------------------------------------------- */
8220 +extern const struct dentry_operations aufs_dop;
8222 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
8223 + struct au_branch *br);
8224 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8225 + struct dentry *h_parent, struct au_branch *br);
8227 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8228 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8229 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8230 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8233 +void au_di_init_once(void *_di);
8234 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8235 +void au_di_free(struct au_dinfo *dinfo);
8236 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8237 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8238 +int au_di_init(struct dentry *dentry);
8239 +void au_di_fin(struct dentry *dentry);
8240 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8242 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8243 +void di_read_unlock(struct dentry *d, int flags);
8244 +void di_downgrade_lock(struct dentry *d, int flags);
8245 +void di_write_lock(struct dentry *d, unsigned int lsc);
8246 +void di_write_unlock(struct dentry *d);
8247 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8248 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8249 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8251 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8252 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8253 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8254 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8256 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8257 + struct dentry *h_dentry);
8258 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8259 +int au_dbrange_test(struct dentry *dentry);
8260 +void au_update_digen(struct dentry *dentry);
8261 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8262 +void au_update_dbstart(struct dentry *dentry);
8263 +void au_update_dbend(struct dentry *dentry);
8264 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8266 +/* ---------------------------------------------------------------------- */
8268 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8270 + return dentry->d_fsdata;
8273 +/* ---------------------------------------------------------------------- */
8275 +/* lock subclass for dinfo */
8277 + AuLsc_DI_CHILD, /* child first */
8278 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8279 + AuLsc_DI_CHILD3, /* copyup dirs */
8283 + AuLsc_DI_TMP /* temp for replacing dinfo */
8287 + * di_read_lock_child, di_write_lock_child,
8288 + * di_read_lock_child2, di_write_lock_child2,
8289 + * di_read_lock_child3, di_write_lock_child3,
8290 + * di_read_lock_parent, di_write_lock_parent,
8291 + * di_read_lock_parent2, di_write_lock_parent2,
8292 + * di_read_lock_parent3, di_write_lock_parent3,
8294 +#define AuReadLockFunc(name, lsc) \
8295 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8296 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8298 +#define AuWriteLockFunc(name, lsc) \
8299 +static inline void di_write_lock_##name(struct dentry *d) \
8300 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8302 +#define AuRWLockFuncs(name, lsc) \
8303 + AuReadLockFunc(name, lsc) \
8304 + AuWriteLockFunc(name, lsc)
8306 +AuRWLockFuncs(child, CHILD);
8307 +AuRWLockFuncs(child2, CHILD2);
8308 +AuRWLockFuncs(child3, CHILD3);
8309 +AuRWLockFuncs(parent, PARENT);
8310 +AuRWLockFuncs(parent2, PARENT2);
8311 +AuRWLockFuncs(parent3, PARENT3);
8313 +#undef AuReadLockFunc
8314 +#undef AuWriteLockFunc
8315 +#undef AuRWLockFuncs
8317 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8318 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8319 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8321 +/* ---------------------------------------------------------------------- */
8323 +/* todo: memory barrier? */
8324 +static inline unsigned int au_digen(struct dentry *d)
8326 + return atomic_read(&au_di(d)->di_generation);
8329 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8331 + hdentry->hd_dentry = NULL;
8334 +static inline void au_hdput(struct au_hdentry *hd)
8337 + dput(hd->hd_dentry);
8340 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8342 + DiMustAnyLock(dentry);
8343 + return au_di(dentry)->di_bstart;
8346 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8348 + DiMustAnyLock(dentry);
8349 + return au_di(dentry)->di_bend;
8352 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8354 + DiMustAnyLock(dentry);
8355 + return au_di(dentry)->di_bwh;
8358 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8360 + DiMustAnyLock(dentry);
8361 + return au_di(dentry)->di_bdiropq;
8364 +/* todo: hard/soft set? */
8365 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8367 + DiMustWriteLock(dentry);
8368 + au_di(dentry)->di_bstart = bindex;
8371 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8373 + DiMustWriteLock(dentry);
8374 + au_di(dentry)->di_bend = bindex;
8377 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8379 + DiMustWriteLock(dentry);
8380 + /* dbwh can be outside of bstart - bend range */
8381 + au_di(dentry)->di_bwh = bindex;
8384 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8386 + DiMustWriteLock(dentry);
8387 + au_di(dentry)->di_bdiropq = bindex;
8390 +/* ---------------------------------------------------------------------- */
8392 +#ifdef CONFIG_AUFS_HNOTIFY
8393 +static inline void au_digen_dec(struct dentry *d)
8395 + atomic_dec(&au_di(d)->di_generation);
8398 +static inline void au_hn_di_reinit(struct dentry *dentry)
8400 + dentry->d_fsdata = NULL;
8403 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8404 +#endif /* CONFIG_AUFS_HNOTIFY */
8406 +#endif /* __KERNEL__ */
8407 +#endif /* __AUFS_DENTRY_H__ */
8408 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8409 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8410 +++ linux/fs/aufs/dinfo.c 2014-04-24 22:11:10.848602379 +0200
8413 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8415 + * This program, aufs is free software; you can redistribute it and/or modify
8416 + * it under the terms of the GNU General Public License as published by
8417 + * the Free Software Foundation; either version 2 of the License, or
8418 + * (at your option) any later version.
8420 + * This program is distributed in the hope that it will be useful,
8421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8423 + * GNU General Public License for more details.
8425 + * You should have received a copy of the GNU General Public License
8426 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8430 + * dentry private data
8435 +void au_di_init_once(void *_dinfo)
8437 + struct au_dinfo *dinfo = _dinfo;
8438 + static struct lock_class_key aufs_di;
8440 + au_rw_init(&dinfo->di_rwsem);
8441 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8444 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8446 + struct au_dinfo *dinfo;
8449 + dinfo = au_cache_alloc_dinfo();
8450 + if (unlikely(!dinfo))
8453 + nbr = au_sbend(sb) + 1;
8456 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8457 + if (dinfo->di_hdentry) {
8458 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8459 + dinfo->di_bstart = -1;
8460 + dinfo->di_bend = -1;
8461 + dinfo->di_bwh = -1;
8462 + dinfo->di_bdiropq = -1;
8463 + for (i = 0; i < nbr; i++)
8464 + dinfo->di_hdentry[i].hd_id = -1;
8468 + au_cache_free_dinfo(dinfo);
8475 +void au_di_free(struct au_dinfo *dinfo)
8477 + struct au_hdentry *p;
8478 + aufs_bindex_t bend, bindex;
8480 + /* dentry may not be revalidated */
8481 + bindex = dinfo->di_bstart;
8482 + if (bindex >= 0) {
8483 + bend = dinfo->di_bend;
8484 + p = dinfo->di_hdentry + bindex;
8485 + while (bindex++ <= bend)
8488 + kfree(dinfo->di_hdentry);
8489 + au_cache_free_dinfo(dinfo);
8492 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8494 + struct au_hdentry *p;
8497 + AuRwMustWriteLock(&a->di_rwsem);
8498 + AuRwMustWriteLock(&b->di_rwsem);
8500 +#define DiSwap(v, name) \
8502 + v = a->di_##name; \
8503 + a->di_##name = b->di_##name; \
8504 + b->di_##name = v; \
8507 + DiSwap(p, hdentry);
8508 + DiSwap(bi, bstart);
8511 + DiSwap(bi, bdiropq);
8517 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8519 + AuRwMustWriteLock(&dst->di_rwsem);
8520 + AuRwMustWriteLock(&src->di_rwsem);
8522 + dst->di_bstart = src->di_bstart;
8523 + dst->di_bend = src->di_bend;
8524 + dst->di_bwh = src->di_bwh;
8525 + dst->di_bdiropq = src->di_bdiropq;
8529 +int au_di_init(struct dentry *dentry)
8532 + struct super_block *sb;
8533 + struct au_dinfo *dinfo;
8536 + sb = dentry->d_sb;
8537 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8539 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8540 + /* smp_mb(); */ /* atomic_set */
8541 + dentry->d_fsdata = dinfo;
8548 +void au_di_fin(struct dentry *dentry)
8550 + struct au_dinfo *dinfo;
8552 + dinfo = au_di(dentry);
8553 + AuRwDestroy(&dinfo->di_rwsem);
8554 + au_di_free(dinfo);
8557 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8560 + struct au_hdentry *hdp;
8562 + AuRwMustWriteLock(&dinfo->di_rwsem);
8565 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8567 + sz = sizeof(*hdp);
8568 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8570 + dinfo->di_hdentry = hdp;
8577 +/* ---------------------------------------------------------------------- */
8579 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8582 + case AuLsc_DI_CHILD:
8583 + ii_write_lock_child(inode);
8585 + case AuLsc_DI_CHILD2:
8586 + ii_write_lock_child2(inode);
8588 + case AuLsc_DI_CHILD3:
8589 + ii_write_lock_child3(inode);
8591 + case AuLsc_DI_PARENT:
8592 + ii_write_lock_parent(inode);
8594 + case AuLsc_DI_PARENT2:
8595 + ii_write_lock_parent2(inode);
8597 + case AuLsc_DI_PARENT3:
8598 + ii_write_lock_parent3(inode);
8605 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8608 + case AuLsc_DI_CHILD:
8609 + ii_read_lock_child(inode);
8611 + case AuLsc_DI_CHILD2:
8612 + ii_read_lock_child2(inode);
8614 + case AuLsc_DI_CHILD3:
8615 + ii_read_lock_child3(inode);
8617 + case AuLsc_DI_PARENT:
8618 + ii_read_lock_parent(inode);
8620 + case AuLsc_DI_PARENT2:
8621 + ii_read_lock_parent2(inode);
8623 + case AuLsc_DI_PARENT3:
8624 + ii_read_lock_parent3(inode);
8631 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
8633 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8635 + if (au_ftest_lock(flags, IW))
8636 + do_ii_write_lock(d->d_inode, lsc);
8637 + else if (au_ftest_lock(flags, IR))
8638 + do_ii_read_lock(d->d_inode, lsc);
8642 +void di_read_unlock(struct dentry *d, int flags)
8645 + if (au_ftest_lock(flags, IW)) {
8646 + au_dbg_verify_dinode(d);
8647 + ii_write_unlock(d->d_inode);
8648 + } else if (au_ftest_lock(flags, IR)) {
8649 + au_dbg_verify_dinode(d);
8650 + ii_read_unlock(d->d_inode);
8653 + au_rw_read_unlock(&au_di(d)->di_rwsem);
8656 +void di_downgrade_lock(struct dentry *d, int flags)
8658 + if (d->d_inode && au_ftest_lock(flags, IR))
8659 + ii_downgrade_lock(d->d_inode);
8660 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
8663 +void di_write_lock(struct dentry *d, unsigned int lsc)
8665 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
8667 + do_ii_write_lock(d->d_inode, lsc);
8670 +void di_write_unlock(struct dentry *d)
8672 + au_dbg_verify_dinode(d);
8674 + ii_write_unlock(d->d_inode);
8675 + au_rw_write_unlock(&au_di(d)->di_rwsem);
8678 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
8680 + AuDebugOn(d1 == d2
8681 + || d1->d_inode == d2->d_inode
8682 + || d1->d_sb != d2->d_sb);
8684 + if (isdir && au_test_subdir(d1, d2)) {
8685 + di_write_lock_child(d1);
8686 + di_write_lock_child2(d2);
8688 + /* there should be no races */
8689 + di_write_lock_child(d2);
8690 + di_write_lock_child2(d1);
8694 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
8696 + AuDebugOn(d1 == d2
8697 + || d1->d_inode == d2->d_inode
8698 + || d1->d_sb != d2->d_sb);
8700 + if (isdir && au_test_subdir(d1, d2)) {
8701 + di_write_lock_parent(d1);
8702 + di_write_lock_parent2(d2);
8704 + /* there should be no races */
8705 + di_write_lock_parent(d2);
8706 + di_write_lock_parent2(d1);
8710 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
8712 + di_write_unlock(d1);
8713 + if (d1->d_inode == d2->d_inode)
8714 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
8716 + di_write_unlock(d2);
8719 +/* ---------------------------------------------------------------------- */
8721 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
8725 + DiMustAnyLock(dentry);
8727 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
8729 + AuDebugOn(bindex < 0);
8730 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
8731 + AuDebugOn(d && d_count(d) <= 0);
8736 + * extended version of au_h_dptr().
8737 + * returns a hashed and positive h_dentry in bindex, NULL, or error.
8739 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
8741 + struct dentry *h_dentry;
8742 + struct inode *inode, *h_inode;
8744 + inode = dentry->d_inode;
8745 + AuDebugOn(!inode);
8748 + if (au_dbstart(dentry) <= bindex
8749 + && bindex <= au_dbend(dentry))
8750 + h_dentry = au_h_dptr(dentry, bindex);
8751 + if (h_dentry && !au_d_hashed_positive(h_dentry)) {
8753 + goto out; /* success */
8756 + AuDebugOn(bindex < au_ibstart(inode));
8757 + AuDebugOn(au_ibend(inode) < bindex);
8758 + h_inode = au_h_iptr(inode, bindex);
8759 + h_dentry = d_find_alias(h_inode);
8761 + if (!IS_ERR(h_dentry)) {
8762 + if (!au_d_hashed_positive(h_dentry))
8763 + goto out; /* success */
8769 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8770 + h_dentry = au_plink_lkup(inode, bindex);
8771 + AuDebugOn(!h_dentry);
8772 + if (!IS_ERR(h_dentry)) {
8773 + if (!au_d_hashed_positive(h_dentry))
8774 + goto out; /* success */
8781 + AuDbgDentry(h_dentry);
8785 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8787 + aufs_bindex_t bend, bwh;
8789 + bend = au_dbend(dentry);
8791 + bwh = au_dbwh(dentry);
8794 + if (0 < bwh && bwh < bend)
8800 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
8802 + aufs_bindex_t bend, bopq;
8804 + bend = au_dbtail(dentry);
8806 + bopq = au_dbdiropq(dentry);
8807 + if (0 <= bopq && bopq < bend)
8813 +/* ---------------------------------------------------------------------- */
8815 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8816 + struct dentry *h_dentry)
8818 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
8819 + struct au_branch *br;
8821 + DiMustWriteLock(dentry);
8824 + hd->hd_dentry = h_dentry;
8826 + br = au_sbr(dentry->d_sb, bindex);
8827 + hd->hd_id = br->br_id;
8831 +int au_dbrange_test(struct dentry *dentry)
8834 + aufs_bindex_t bstart, bend;
8837 + bstart = au_dbstart(dentry);
8838 + bend = au_dbend(dentry);
8840 + AuDebugOn(bend < 0 && bstart > bend);
8843 + AuDebugOn(bend >= 0);
8849 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
8854 + if (unlikely(au_digen(dentry) != sigen
8855 + || au_iigen_test(dentry->d_inode, sigen)))
8861 +void au_update_digen(struct dentry *dentry)
8863 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
8864 + /* smp_mb(); */ /* atomic_set */
8867 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
8869 + struct au_dinfo *dinfo;
8870 + struct dentry *h_d;
8871 + struct au_hdentry *hdp;
8873 + DiMustWriteLock(dentry);
8875 + dinfo = au_di(dentry);
8876 + if (!dinfo || dinfo->di_bstart < 0)
8879 + hdp = dinfo->di_hdentry;
8880 + if (do_put_zero) {
8881 + aufs_bindex_t bindex, bend;
8883 + bend = dinfo->di_bend;
8884 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
8885 + h_d = hdp[0 + bindex].hd_dentry;
8886 + if (h_d && !h_d->d_inode)
8887 + au_set_h_dptr(dentry, bindex, NULL);
8891 + dinfo->di_bstart = -1;
8892 + while (++dinfo->di_bstart <= dinfo->di_bend)
8893 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
8895 + if (dinfo->di_bstart > dinfo->di_bend) {
8896 + dinfo->di_bstart = -1;
8897 + dinfo->di_bend = -1;
8902 + while (0 <= --dinfo->di_bend)
8903 + if (hdp[0 + dinfo->di_bend].hd_dentry)
8905 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
8908 +void au_update_dbstart(struct dentry *dentry)
8910 + aufs_bindex_t bindex, bend;
8911 + struct dentry *h_dentry;
8913 + bend = au_dbend(dentry);
8914 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
8915 + h_dentry = au_h_dptr(dentry, bindex);
8918 + if (h_dentry->d_inode) {
8919 + au_set_dbstart(dentry, bindex);
8922 + au_set_h_dptr(dentry, bindex, NULL);
8926 +void au_update_dbend(struct dentry *dentry)
8928 + aufs_bindex_t bindex, bstart;
8929 + struct dentry *h_dentry;
8931 + bstart = au_dbstart(dentry);
8932 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
8933 + h_dentry = au_h_dptr(dentry, bindex);
8936 + if (h_dentry->d_inode) {
8937 + au_set_dbend(dentry, bindex);
8940 + au_set_h_dptr(dentry, bindex, NULL);
8944 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
8946 + aufs_bindex_t bindex, bend;
8948 + bend = au_dbend(dentry);
8949 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
8950 + if (au_h_dptr(dentry, bindex) == h_dentry)
8954 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
8955 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
8956 +++ linux/fs/aufs/dir.c 2014-04-24 22:11:10.848602379 +0200
8959 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8961 + * This program, aufs is free software; you can redistribute it and/or modify
8962 + * it under the terms of the GNU General Public License as published by
8963 + * the Free Software Foundation; either version 2 of the License, or
8964 + * (at your option) any later version.
8966 + * This program is distributed in the hope that it will be useful,
8967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8969 + * GNU General Public License for more details.
8971 + * You should have received a copy of the GNU General Public License
8972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8976 + * directory operations
8979 +#include <linux/fs_stack.h>
8982 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
8984 + unsigned int nlink;
8986 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8988 + nlink = dir->i_nlink;
8989 + nlink += h_dir->i_nlink - 2;
8990 + if (h_dir->i_nlink < 2)
8992 + smp_mb(); /* for i_nlink */
8993 + /* 0 can happen in revaliding */
8994 + set_nlink(dir, nlink);
8997 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
8999 + unsigned int nlink;
9001 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9003 + nlink = dir->i_nlink;
9004 + nlink -= h_dir->i_nlink - 2;
9005 + if (h_dir->i_nlink < 2)
9007 + smp_mb(); /* for i_nlink */
9008 + /* nlink == 0 means the branch-fs is broken */
9009 + set_nlink(dir, nlink);
9012 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9015 + aufs_bindex_t bindex, bend;
9016 + struct file *h_file;
9017 + struct dentry *h_dentry;
9021 + AuDebugOn(!file_inode(file));
9022 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
9024 + bend = au_fbend_dir(file);
9025 + for (bindex = au_fbstart(file);
9026 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9028 + h_file = au_hf_dir(file, bindex);
9029 + if (h_file && file_inode(h_file))
9030 + sz += vfsub_f_size_read(h_file);
9033 + AuDebugOn(!dentry);
9034 + AuDebugOn(!dentry->d_inode);
9035 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
9037 + bend = au_dbtaildir(dentry);
9038 + for (bindex = au_dbstart(dentry);
9039 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9041 + h_dentry = au_h_dptr(dentry, bindex);
9042 + if (h_dentry && h_dentry->d_inode)
9043 + sz += i_size_read(h_dentry->d_inode);
9046 + if (sz < KMALLOC_MAX_SIZE)
9047 + sz = roundup_pow_of_two(sz);
9048 + if (sz > KMALLOC_MAX_SIZE)
9049 + sz = KMALLOC_MAX_SIZE;
9050 + else if (sz < NAME_MAX) {
9051 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9052 + sz = AUFS_RDBLK_DEF;
9057 +/* ---------------------------------------------------------------------- */
9059 +static int reopen_dir(struct file *file)
9062 + unsigned int flags;
9063 + aufs_bindex_t bindex, btail, bstart;
9064 + struct dentry *dentry, *h_dentry;
9065 + struct file *h_file;
9067 + /* open all lower dirs */
9068 + dentry = file->f_dentry;
9069 + bstart = au_dbstart(dentry);
9070 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9071 + au_set_h_fptr(file, bindex, NULL);
9072 + au_set_fbstart(file, bstart);
9074 + btail = au_dbtaildir(dentry);
9075 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9076 + au_set_h_fptr(file, bindex, NULL);
9077 + au_set_fbend_dir(file, btail);
9079 + flags = vfsub_file_flags(file);
9080 + for (bindex = bstart; bindex <= btail; bindex++) {
9081 + h_dentry = au_h_dptr(dentry, bindex);
9084 + h_file = au_hf_dir(file, bindex);
9088 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9089 + err = PTR_ERR(h_file);
9090 + if (IS_ERR(h_file))
9091 + goto out; /* close all? */
9092 + au_set_h_fptr(file, bindex, h_file);
9094 + au_update_figen(file);
9095 + /* todo: necessary? */
9096 + /* file->f_ra = h_file->f_ra; */
9103 +static int do_open_dir(struct file *file, int flags)
9106 + aufs_bindex_t bindex, btail;
9107 + struct dentry *dentry, *h_dentry;
9108 + struct file *h_file;
9110 + FiMustWriteLock(file);
9113 + dentry = file->f_dentry;
9114 + file->f_version = dentry->d_inode->i_version;
9115 + bindex = au_dbstart(dentry);
9116 + au_set_fbstart(file, bindex);
9117 + btail = au_dbtaildir(dentry);
9118 + au_set_fbend_dir(file, btail);
9119 + for (; !err && bindex <= btail; bindex++) {
9120 + h_dentry = au_h_dptr(dentry, bindex);
9124 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9125 + if (IS_ERR(h_file)) {
9126 + err = PTR_ERR(h_file);
9129 + au_set_h_fptr(file, bindex, h_file);
9131 + au_update_figen(file);
9132 + /* todo: necessary? */
9133 + /* file->f_ra = h_file->f_ra; */
9135 + return 0; /* success */
9138 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9139 + au_set_h_fptr(file, bindex, NULL);
9140 + au_set_fbstart(file, -1);
9141 + au_set_fbend_dir(file, -1);
9146 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9147 + struct file *file)
9150 + struct super_block *sb;
9151 + struct au_fidir *fidir;
9154 + sb = file->f_dentry->d_sb;
9155 + si_read_lock(sb, AuLock_FLUSH);
9156 + fidir = au_fidir_alloc(sb);
9158 + err = au_do_open(file, do_open_dir, fidir);
9159 + if (unlikely(err))
9162 + si_read_unlock(sb);
9166 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9167 + struct file *file)
9169 + struct au_vdir *vdir_cache;
9170 + struct au_finfo *finfo;
9171 + struct au_fidir *fidir;
9172 + aufs_bindex_t bindex, bend;
9174 + finfo = au_fi(file);
9175 + fidir = finfo->fi_hdir;
9177 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9179 + au_vdir_free(vdir_cache);
9181 + bindex = finfo->fi_btop;
9182 + if (bindex >= 0) {
9184 + * calls fput() instead of filp_close(),
9185 + * since no dnotify or lock for the lower file.
9187 + bend = fidir->fd_bbot;
9188 + for (; bindex <= bend; bindex++)
9189 + au_set_h_fptr(file, bindex, NULL);
9192 + finfo->fi_hdir = NULL;
9194 + au_finfo_fin(file);
9198 +/* ---------------------------------------------------------------------- */
9200 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9203 + aufs_bindex_t bindex, bend;
9204 + struct file *h_file;
9207 + bend = au_fbend_dir(file);
9208 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9209 + h_file = au_hf_dir(file, bindex);
9211 + err = vfsub_flush(h_file, id);
9216 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9218 + return au_do_flush(file, id, au_do_flush_dir);
9221 +/* ---------------------------------------------------------------------- */
9223 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9226 + aufs_bindex_t bend, bindex;
9227 + struct inode *inode;
9228 + struct super_block *sb;
9231 + sb = dentry->d_sb;
9232 + inode = dentry->d_inode;
9234 + bend = au_dbend(dentry);
9235 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9236 + struct path h_path;
9238 + if (au_test_ro(sb, bindex, inode))
9240 + h_path.dentry = au_h_dptr(dentry, bindex);
9241 + if (!h_path.dentry)
9244 + h_path.mnt = au_sbr_mnt(sb, bindex);
9245 + err = vfsub_fsync(NULL, &h_path, datasync);
9251 +static int au_do_fsync_dir(struct file *file, int datasync)
9254 + aufs_bindex_t bend, bindex;
9255 + struct file *h_file;
9256 + struct super_block *sb;
9257 + struct inode *inode;
9259 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9260 + if (unlikely(err))
9263 + sb = file->f_dentry->d_sb;
9264 + inode = file_inode(file);
9265 + bend = au_fbend_dir(file);
9266 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9267 + h_file = au_hf_dir(file, bindex);
9268 + if (!h_file || au_test_ro(sb, bindex, inode))
9271 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9279 + * @file may be NULL
9281 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9285 + struct dentry *dentry;
9286 + struct super_block *sb;
9287 + struct mutex *mtx;
9290 + dentry = file->f_dentry;
9291 + mtx = &dentry->d_inode->i_mutex;
9293 + sb = dentry->d_sb;
9294 + si_noflush_read_lock(sb);
9296 + err = au_do_fsync_dir(file, datasync);
9298 + di_write_lock_child(dentry);
9299 + err = au_do_fsync_dir_no_file(dentry, datasync);
9301 + au_cpup_attr_timesizes(dentry->d_inode);
9302 + di_write_unlock(dentry);
9304 + fi_write_unlock(file);
9306 + si_read_unlock(sb);
9307 + mutex_unlock(mtx);
9311 +/* ---------------------------------------------------------------------- */
9313 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9316 + struct dentry *dentry;
9317 + struct inode *inode, *h_inode;
9318 + struct super_block *sb;
9320 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9322 + dentry = file->f_dentry;
9323 + inode = dentry->d_inode;
9326 + sb = dentry->d_sb;
9327 + si_read_lock(sb, AuLock_FLUSH);
9328 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9329 + if (unlikely(err))
9331 + err = au_alive_dir(dentry);
9333 + err = au_vdir_init(file);
9334 + di_downgrade_lock(dentry, AuLock_IR);
9335 + if (unlikely(err))
9338 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9339 + if (!au_test_nfsd()) {
9340 + err = au_vdir_fill_de(file, ctx);
9341 + fsstack_copy_attr_atime(inode, h_inode);
9344 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9345 + * encode_fh() and others.
9347 + atomic_inc(&h_inode->i_count);
9348 + di_read_unlock(dentry, AuLock_IR);
9349 + si_read_unlock(sb);
9350 + err = au_vdir_fill_de(file, ctx);
9351 + fsstack_copy_attr_atime(inode, h_inode);
9352 + fi_write_unlock(file);
9360 + di_read_unlock(dentry, AuLock_IR);
9361 + fi_write_unlock(file);
9363 + si_read_unlock(sb);
9367 +/* ---------------------------------------------------------------------- */
9369 +#define AuTestEmpty_WHONLY 1
9370 +#define AuTestEmpty_CALLED (1 << 1)
9371 +#define AuTestEmpty_SHWH (1 << 2)
9372 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9373 +#define au_fset_testempty(flags, name) \
9374 + do { (flags) |= AuTestEmpty_##name; } while (0)
9375 +#define au_fclr_testempty(flags, name) \
9376 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9378 +#ifndef CONFIG_AUFS_SHWH
9379 +#undef AuTestEmpty_SHWH
9380 +#define AuTestEmpty_SHWH 0
9383 +struct test_empty_arg {
9384 + struct dir_context ctx;
9385 + struct au_nhash *whlist;
9386 + unsigned int flags;
9388 + aufs_bindex_t bindex;
9391 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9392 + int namelen, loff_t offset __maybe_unused, u64 ino,
9393 + unsigned int d_type)
9395 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9397 + char *name = (void *)__name;
9400 + au_fset_testempty(arg->flags, CALLED);
9402 + if (name[0] == '.'
9403 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9404 + goto out; /* success */
9406 + if (namelen <= AUFS_WH_PFX_LEN
9407 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9408 + if (au_ftest_testempty(arg->flags, WHONLY)
9409 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9410 + arg->err = -ENOTEMPTY;
9414 + name += AUFS_WH_PFX_LEN;
9415 + namelen -= AUFS_WH_PFX_LEN;
9416 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9417 + arg->err = au_nhash_append_wh
9418 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9419 + au_ftest_testempty(arg->flags, SHWH));
9423 + AuTraceErr(arg->err);
9427 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9430 + struct file *h_file;
9432 + h_file = au_h_open(dentry, arg->bindex,
9433 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9434 + /*file*/NULL, /*force_wr*/0);
9435 + err = PTR_ERR(h_file);
9436 + if (IS_ERR(h_file))
9440 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9441 + && !file_inode(h_file)->i_nlink)
9446 + au_fclr_testempty(arg->flags, CALLED);
9448 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9451 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9455 + au_sbr_put(dentry->d_sb, arg->bindex);
9460 +struct do_test_empty_args {
9462 + struct dentry *dentry;
9463 + struct test_empty_arg *arg;
9466 +static void call_do_test_empty(void *args)
9468 + struct do_test_empty_args *a = args;
9469 + *a->errp = do_test_empty(a->dentry, a->arg);
9472 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9475 + struct dentry *h_dentry;
9476 + struct inode *h_inode;
9478 + h_dentry = au_h_dptr(dentry, arg->bindex);
9479 + h_inode = h_dentry->d_inode;
9480 + /* todo: i_mode changes anytime? */
9481 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9482 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9483 + mutex_unlock(&h_inode->i_mutex);
9485 + err = do_test_empty(dentry, arg);
9487 + struct do_test_empty_args args = {
9492 + unsigned int flags = arg->flags;
9494 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9495 + if (unlikely(wkq_err))
9497 + arg->flags = flags;
9503 +int au_test_empty_lower(struct dentry *dentry)
9506 + unsigned int rdhash;
9507 + aufs_bindex_t bindex, bstart, btail;
9508 + struct au_nhash whlist;
9509 + struct test_empty_arg arg = {
9511 + .actor = au_diractor(test_empty_cb)
9515 + SiMustAnyLock(dentry->d_sb);
9517 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
9519 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
9520 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
9521 + if (unlikely(err))
9525 + arg.whlist = &whlist;
9526 + bstart = au_dbstart(dentry);
9527 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9528 + au_fset_testempty(arg.flags, SHWH);
9529 + arg.bindex = bstart;
9530 + err = do_test_empty(dentry, &arg);
9531 + if (unlikely(err))
9534 + au_fset_testempty(arg.flags, WHONLY);
9535 + btail = au_dbtaildir(dentry);
9536 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
9537 + struct dentry *h_dentry;
9539 + h_dentry = au_h_dptr(dentry, bindex);
9540 + if (h_dentry && h_dentry->d_inode) {
9541 + arg.bindex = bindex;
9542 + err = do_test_empty(dentry, &arg);
9547 + au_nhash_wh_free(&whlist);
9552 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
9555 + struct test_empty_arg arg = {
9557 + .actor = au_diractor(test_empty_cb)
9560 + aufs_bindex_t bindex, btail;
9563 + arg.whlist = whlist;
9564 + arg.flags = AuTestEmpty_WHONLY;
9565 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9566 + au_fset_testempty(arg.flags, SHWH);
9567 + btail = au_dbtaildir(dentry);
9568 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
9569 + struct dentry *h_dentry;
9571 + h_dentry = au_h_dptr(dentry, bindex);
9572 + if (h_dentry && h_dentry->d_inode) {
9573 + arg.bindex = bindex;
9574 + err = sio_test_empty(dentry, &arg);
9581 +/* ---------------------------------------------------------------------- */
9583 +const struct file_operations aufs_dir_fop = {
9584 + .owner = THIS_MODULE,
9585 + .llseek = default_llseek,
9586 + .read = generic_read_dir,
9587 + .iterate = aufs_iterate,
9588 + .unlocked_ioctl = aufs_ioctl_dir,
9589 +#ifdef CONFIG_COMPAT
9590 + .compat_ioctl = aufs_compat_ioctl_dir,
9592 + .open = aufs_open_dir,
9593 + .release = aufs_release_dir,
9594 + .flush = aufs_flush_dir,
9595 + .fsync = aufs_fsync_dir
9597 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
9598 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
9599 +++ linux/fs/aufs/dir.h 2014-04-24 22:11:10.851935747 +0200
9602 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9604 + * This program, aufs is free software; you can redistribute it and/or modify
9605 + * it under the terms of the GNU General Public License as published by
9606 + * the Free Software Foundation; either version 2 of the License, or
9607 + * (at your option) any later version.
9609 + * This program is distributed in the hope that it will be useful,
9610 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9611 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9612 + * GNU General Public License for more details.
9614 + * You should have received a copy of the GNU General Public License
9615 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9619 + * directory operations
9622 +#ifndef __AUFS_DIR_H__
9623 +#define __AUFS_DIR_H__
9627 +#include <linux/fs.h>
9629 +/* ---------------------------------------------------------------------- */
9631 +/* need to be faster and smaller */
9634 + unsigned int nh_num;
9635 + struct hlist_head *nh_head;
9638 +struct au_vdir_destr {
9639 + unsigned char len;
9640 + unsigned char name[0];
9643 +struct au_vdir_dehstr {
9644 + struct hlist_node hash;
9645 + struct au_vdir_destr *str;
9646 +} ____cacheline_aligned_in_smp;
9648 +struct au_vdir_de {
9650 + unsigned char de_type;
9651 + /* caution: packed */
9652 + struct au_vdir_destr de_str;
9655 +struct au_vdir_wh {
9656 + struct hlist_node wh_hash;
9657 +#ifdef CONFIG_AUFS_SHWH
9659 + aufs_bindex_t wh_bindex;
9660 + unsigned char wh_type;
9662 + aufs_bindex_t wh_bindex;
9664 + /* caution: packed */
9665 + struct au_vdir_destr wh_str;
9668 +union au_vdir_deblk_p {
9669 + unsigned char *deblk;
9670 + struct au_vdir_de *de;
9674 + unsigned char **vd_deblk;
9675 + unsigned long vd_nblk;
9678 + union au_vdir_deblk_p p;
9681 + unsigned long vd_version;
9682 + unsigned int vd_deblk_sz;
9683 + unsigned long vd_jiffy;
9684 +} ____cacheline_aligned_in_smp;
9686 +/* ---------------------------------------------------------------------- */
9689 +extern const struct file_operations aufs_dir_fop;
9690 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
9691 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
9692 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
9693 +int au_test_empty_lower(struct dentry *dentry);
9694 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
9697 +unsigned int au_rdhash_est(loff_t sz);
9698 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
9699 +void au_nhash_wh_free(struct au_nhash *whlist);
9700 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
9702 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
9703 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
9704 + unsigned int d_type, aufs_bindex_t bindex,
9705 + unsigned char shwh);
9706 +void au_vdir_free(struct au_vdir *vdir);
9707 +int au_vdir_init(struct file *file);
9708 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
9711 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
9713 +#ifdef CONFIG_AUFS_RDU
9715 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
9716 +#ifdef CONFIG_COMPAT
9717 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9718 + unsigned long arg);
9721 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
9722 + unsigned long arg)
9726 +#ifdef CONFIG_COMPAT
9727 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9728 + unsigned long arg)
9735 +#endif /* __KERNEL__ */
9736 +#endif /* __AUFS_DIR_H__ */
9737 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
9738 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
9739 +++ linux/fs/aufs/dynop.c 2014-04-24 22:11:10.851935747 +0200
9742 + * Copyright (C) 2010-2014 Junjiro R. Okajima
9744 + * This program, aufs is free software; you can redistribute it and/or modify
9745 + * it under the terms of the GNU General Public License as published by
9746 + * the Free Software Foundation; either version 2 of the License, or
9747 + * (at your option) any later version.
9749 + * This program is distributed in the hope that it will be useful,
9750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9752 + * GNU General Public License for more details.
9754 + * You should have received a copy of the GNU General Public License
9755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9759 + * dynamically customizable operations for regular files
9764 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9767 + * How large will these lists be?
9768 + * Usually just a few elements, 20-30 at most for each, I guess.
9770 +static struct au_splhead dynop[AuDyLast];
9772 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9774 + struct au_dykey *key, *tmp;
9775 + struct list_head *head;
9778 + head = &spl->head;
9780 + list_for_each_entry_rcu(tmp, head, dk_list)
9781 + if (tmp->dk_op.dy_hop == h_op) {
9783 + kref_get(&key->dk_kref);
9786 + rcu_read_unlock();
9791 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9793 + struct au_dykey **k, *found;
9794 + const void *h_op = key->dk_op.dy_hop;
9799 + for (i = 0; i < AuBrDynOp; i++)
9801 + if (k[i]->dk_op.dy_hop == h_op) {
9808 + spin_lock(&br->br_dykey_lock);
9809 + for (; i < AuBrDynOp; i++)
9811 + if (k[i]->dk_op.dy_hop == h_op) {
9819 + spin_unlock(&br->br_dykey_lock);
9820 + BUG_ON(i == AuBrDynOp); /* expand the array */
9826 +/* kref_get() if @key is already added */
9827 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
9829 + struct au_dykey *tmp, *found;
9830 + struct list_head *head;
9831 + const void *h_op = key->dk_op.dy_hop;
9834 + head = &spl->head;
9835 + spin_lock(&spl->spin);
9836 + list_for_each_entry(tmp, head, dk_list)
9837 + if (tmp->dk_op.dy_hop == h_op) {
9838 + kref_get(&tmp->dk_kref);
9843 + list_add_rcu(&key->dk_list, head);
9844 + spin_unlock(&spl->spin);
9851 +static void dy_free_rcu(struct rcu_head *rcu)
9853 + struct au_dykey *key;
9855 + key = container_of(rcu, struct au_dykey, dk_rcu);
9860 +static void dy_free(struct kref *kref)
9862 + struct au_dykey *key;
9863 + struct au_splhead *spl;
9865 + key = container_of(kref, struct au_dykey, dk_kref);
9866 + spl = dynop + key->dk_op.dy_type;
9867 + au_spl_del_rcu(&key->dk_list, spl);
9868 + call_rcu(&key->dk_rcu, dy_free_rcu);
9871 +void au_dy_put(struct au_dykey *key)
9873 + kref_put(&key->dk_kref, dy_free);
9876 +/* ---------------------------------------------------------------------- */
9878 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
9880 +#ifdef CONFIG_AUFS_DEBUG
9881 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
9882 +#define DyDbgInc(cnt) do { cnt++; } while (0)
9884 +#define DyDbgDeclare(cnt) do {} while (0)
9885 +#define DyDbgInc(cnt) do {} while (0)
9888 +#define DySet(func, dst, src, h_op, h_sb) do { \
9890 + if (h_op->func) { \
9892 + dst.func = src.func; \
9894 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
9898 +#define DySetForce(func, dst, src) do { \
9899 + AuDebugOn(!src.func); \
9901 + dst.func = src.func; \
9904 +#define DySetAop(func) \
9905 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
9906 +#define DySetAopForce(func) \
9907 + DySetForce(func, dyaop->da_op, aufs_aop)
9909 +static void dy_aop(struct au_dykey *key, const void *h_op,
9910 + struct super_block *h_sb __maybe_unused)
9912 + struct au_dyaop *dyaop = (void *)key;
9913 + const struct address_space_operations *h_aop = h_op;
9914 + DyDbgDeclare(cnt);
9916 + AuDbg("%s\n", au_sbtype(h_sb));
9918 + DySetAop(writepage);
9919 + DySetAopForce(readpage); /* force */
9920 + DySetAop(writepages);
9921 + DySetAop(set_page_dirty);
9922 + DySetAop(readpages);
9923 + DySetAop(write_begin);
9924 + DySetAop(write_end);
9926 + DySetAop(invalidatepage);
9927 + DySetAop(releasepage);
9928 + DySetAop(freepage);
9929 + /* these two will be changed according to an aufs mount option */
9930 + DySetAop(direct_IO);
9931 + DySetAop(get_xip_mem);
9932 + DySetAop(migratepage);
9933 + DySetAop(launder_page);
9934 + DySetAop(is_partially_uptodate);
9935 + DySetAop(is_dirty_writeback);
9936 + DySetAop(error_remove_page);
9937 + DySetAop(swap_activate);
9938 + DySetAop(swap_deactivate);
9940 + DyDbgSize(cnt, *h_aop);
9941 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
9944 +/* ---------------------------------------------------------------------- */
9946 +static void dy_bug(struct kref *kref)
9951 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
9953 + struct au_dykey *key, *old;
9954 + struct au_splhead *spl;
9957 + void (*set)(struct au_dykey *key, const void *h_op,
9958 + struct super_block *h_sb __maybe_unused);
9960 + static const struct op a[] = {
9962 + .sz = sizeof(struct au_dyaop),
9966 + const struct op *p;
9968 + spl = dynop + op->dy_type;
9969 + key = dy_gfind_get(spl, op->dy_hop);
9971 + goto out_add; /* success */
9973 + p = a + op->dy_type;
9974 + key = kzalloc(p->sz, GFP_NOFS);
9975 + if (unlikely(!key)) {
9976 + key = ERR_PTR(-ENOMEM);
9980 + key->dk_op.dy_hop = op->dy_hop;
9981 + kref_init(&key->dk_kref);
9982 + p->set(key, op->dy_hop, au_br_sb(br));
9983 + old = dy_gadd(spl, key);
9990 + old = dy_bradd(br, key);
9992 + /* its ref-count should never be zero here */
9993 + kref_put(&key->dk_kref, dy_bug);
9998 +/* ---------------------------------------------------------------------- */
10000 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10001 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
10002 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10003 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10004 + * See the aufs manual in detail.
10006 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
10007 + * performance of fadvise() and madvise() may be affected.
10009 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10012 + dyaop->da_op.direct_IO = NULL;
10013 + dyaop->da_op.get_xip_mem = NULL;
10015 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10016 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
10017 + if (!dyaop->da_get_xip_mem)
10018 + dyaop->da_op.get_xip_mem = NULL;
10022 +static struct au_dyaop *dy_aget(struct au_branch *br,
10023 + const struct address_space_operations *h_aop,
10026 + struct au_dyaop *dyaop;
10027 + struct au_dynop op;
10029 + op.dy_type = AuDy_AOP;
10030 + op.dy_haop = h_aop;
10031 + dyaop = (void *)dy_get(&op, br);
10032 + if (IS_ERR(dyaop))
10034 + dy_adx(dyaop, do_dx);
10040 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10041 + struct inode *h_inode)
10044 + struct super_block *sb;
10045 + struct au_branch *br;
10046 + struct au_dyaop *dyaop;
10048 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10049 + IiMustWriteLock(inode);
10051 + sb = inode->i_sb;
10052 + br = au_sbr(sb, bindex);
10053 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10054 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10055 + err = PTR_ERR(dyaop);
10056 + if (IS_ERR(dyaop))
10057 + /* unnecessary to call dy_fput() */
10061 + inode->i_mapping->a_ops = &dyaop->da_op;
10068 + * Is it safe to replace a_ops during the inode/file is in operation?
10069 + * Yes, I hope so.
10071 +int au_dy_irefresh(struct inode *inode)
10074 + aufs_bindex_t bstart;
10075 + struct inode *h_inode;
10078 + if (S_ISREG(inode->i_mode)) {
10079 + bstart = au_ibstart(inode);
10080 + h_inode = au_h_iptr(inode, bstart);
10081 + err = au_dy_iaop(inode, bstart, h_inode);
10086 +void au_dy_arefresh(int do_dx)
10088 + struct au_splhead *spl;
10089 + struct list_head *head;
10090 + struct au_dykey *key;
10092 + spl = dynop + AuDy_AOP;
10093 + head = &spl->head;
10094 + spin_lock(&spl->spin);
10095 + list_for_each_entry(key, head, dk_list)
10096 + dy_adx((void *)key, do_dx);
10097 + spin_unlock(&spl->spin);
10100 +/* ---------------------------------------------------------------------- */
10102 +void __init au_dy_init(void)
10106 + /* make sure that 'struct au_dykey *' can be any type */
10107 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10109 + for (i = 0; i < AuDyLast; i++)
10110 + au_spl_init(dynop + i);
10113 +void au_dy_fin(void)
10117 + for (i = 0; i < AuDyLast; i++)
10118 + WARN_ON(!list_empty(&dynop[i].head));
10120 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10121 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10122 +++ linux/fs/aufs/dynop.h 2014-04-24 22:11:10.851935747 +0200
10125 + * Copyright (C) 2010-2014 Junjiro R. Okajima
10127 + * This program, aufs is free software; you can redistribute it and/or modify
10128 + * it under the terms of the GNU General Public License as published by
10129 + * the Free Software Foundation; either version 2 of the License, or
10130 + * (at your option) any later version.
10132 + * This program is distributed in the hope that it will be useful,
10133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10135 + * GNU General Public License for more details.
10137 + * You should have received a copy of the GNU General Public License
10138 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10142 + * dynamically customizable operations (for regular files only)
10145 +#ifndef __AUFS_DYNOP_H__
10146 +#define __AUFS_DYNOP_H__
10150 +#include "inode.h"
10152 +enum {AuDy_AOP, AuDyLast};
10157 + const void *dy_hop;
10158 + const struct address_space_operations *dy_haop;
10164 + struct list_head dk_list;
10165 + struct rcu_head dk_rcu;
10167 + struct au_dynop dk_op;
10170 + * during I am in the branch local array, kref is gotten. when the
10171 + * branch is removed, kref is put.
10173 + struct kref dk_kref;
10176 +/* stop unioning since their sizes are very different from each other */
10178 + struct au_dykey da_key;
10179 + struct address_space_operations da_op; /* not const */
10180 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
10181 + void **, unsigned long *);
10184 +/* ---------------------------------------------------------------------- */
10188 +void au_dy_put(struct au_dykey *key);
10189 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10190 + struct inode *h_inode);
10191 +int au_dy_irefresh(struct inode *inode);
10192 +void au_dy_arefresh(int do_dio);
10194 +void __init au_dy_init(void);
10195 +void au_dy_fin(void);
10197 +#endif /* __KERNEL__ */
10198 +#endif /* __AUFS_DYNOP_H__ */
10199 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10200 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10201 +++ linux/fs/aufs/export.c 2014-04-24 22:11:10.851935747 +0200
10204 + * Copyright (C) 2005-2014 Junjiro R. Okajima
10206 + * This program, aufs is free software; you can redistribute it and/or modify
10207 + * it under the terms of the GNU General Public License as published by
10208 + * the Free Software Foundation; either version 2 of the License, or
10209 + * (at your option) any later version.
10211 + * This program is distributed in the hope that it will be useful,
10212 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10213 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10214 + * GNU General Public License for more details.
10216 + * You should have received a copy of the GNU General Public License
10217 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10224 +#include <linux/exportfs.h>
10225 +#include <linux/fs_struct.h>
10226 +#include <linux/namei.h>
10227 +#include <linux/nsproxy.h>
10228 +#include <linux/random.h>
10229 +#include <linux/writeback.h>
10230 +#include "../fs/mount.h"
10234 +#ifdef CONFIG_AUFS_INO_T_64
10242 +static ino_t decode_ino(__u32 *a)
10246 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10248 +#ifdef CONFIG_AUFS_INO_T_64
10254 +static void encode_ino(__u32 *a, ino_t ino)
10260 +#ifdef CONFIG_AUFS_INO_T_64
10265 +/* NFS file handle */
10269 +#ifdef CONFIG_AUFS_INO_T_64
10270 + /* support 64bit inode number */
10283 + Fh_ino = Fh_ino1,
10284 + Fh_dir_ino = Fh_dir_ino1
10287 +static int au_test_anon(struct dentry *dentry)
10289 + /* note: read d_flags without d_lock */
10290 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10293 +int au_test_nfsd(void)
10296 + struct task_struct *tsk = current;
10297 + char comm[sizeof(tsk->comm)];
10300 + if (tsk->flags & PF_KTHREAD) {
10301 + get_task_comm(comm, tsk);
10302 + ret = !strcmp(comm, "nfsd");
10308 +/* ---------------------------------------------------------------------- */
10309 +/* inode generation external table */
10311 +void au_xigen_inc(struct inode *inode)
10316 + struct super_block *sb;
10317 + struct au_sbinfo *sbinfo;
10319 + sb = inode->i_sb;
10320 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10322 + sbinfo = au_sbi(sb);
10323 + pos = inode->i_ino;
10324 + pos *= sizeof(igen);
10325 + igen = inode->i_generation + 1;
10326 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10327 + sizeof(igen), &pos);
10328 + if (sz == sizeof(igen))
10329 + return; /* success */
10331 + if (unlikely(sz >= 0))
10332 + AuIOErr("xigen error (%zd)\n", sz);
10335 +int au_xigen_new(struct inode *inode)
10340 + struct super_block *sb;
10341 + struct au_sbinfo *sbinfo;
10342 + struct file *file;
10345 + /* todo: dirty, at mount time */
10346 + if (inode->i_ino == AUFS_ROOT_INO)
10348 + sb = inode->i_sb;
10349 + SiMustAnyLock(sb);
10350 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10354 + pos = inode->i_ino;
10355 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10356 + AuIOErr1("too large i%lld\n", pos);
10359 + pos *= sizeof(inode->i_generation);
10362 + sbinfo = au_sbi(sb);
10363 + file = sbinfo->si_xigen;
10366 + if (vfsub_f_size_read(file)
10367 + < pos + sizeof(inode->i_generation)) {
10368 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10369 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10370 + sizeof(inode->i_generation), &pos);
10372 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10373 + sizeof(inode->i_generation), &pos);
10374 + if (sz == sizeof(inode->i_generation))
10375 + goto out; /* success */
10378 + if (unlikely(sz >= 0)) {
10380 + AuIOErr("xigen error (%zd)\n", sz);
10387 +int au_xigen_set(struct super_block *sb, struct file *base)
10390 + struct au_sbinfo *sbinfo;
10391 + struct file *file;
10393 + SiMustWriteLock(sb);
10395 + sbinfo = au_sbi(sb);
10396 + file = au_xino_create2(base, sbinfo->si_xigen);
10397 + err = PTR_ERR(file);
10398 + if (IS_ERR(file))
10401 + if (sbinfo->si_xigen)
10402 + fput(sbinfo->si_xigen);
10403 + sbinfo->si_xigen = file;
10409 +void au_xigen_clr(struct super_block *sb)
10411 + struct au_sbinfo *sbinfo;
10413 + SiMustWriteLock(sb);
10415 + sbinfo = au_sbi(sb);
10416 + if (sbinfo->si_xigen) {
10417 + fput(sbinfo->si_xigen);
10418 + sbinfo->si_xigen = NULL;
10422 +/* ---------------------------------------------------------------------- */
10424 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10427 + struct dentry *dentry, *d;
10428 + struct inode *inode;
10429 + unsigned int sigen;
10432 + inode = ilookup(sb, ino);
10436 + dentry = ERR_PTR(-ESTALE);
10437 + sigen = au_sigen(sb);
10438 + if (unlikely(is_bad_inode(inode)
10439 + || IS_DEADDIR(inode)
10440 + || sigen != au_iigen(inode, NULL)))
10444 + if (!dir_ino || S_ISDIR(inode->i_mode))
10445 + dentry = d_find_alias(inode);
10447 + spin_lock(&inode->i_lock);
10448 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
10449 + spin_lock(&d->d_lock);
10450 + if (!au_test_anon(d)
10451 + && d->d_parent->d_inode->i_ino == dir_ino) {
10452 + dentry = dget_dlock(d);
10453 + spin_unlock(&d->d_lock);
10456 + spin_unlock(&d->d_lock);
10458 + spin_unlock(&inode->i_lock);
10460 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10461 + /* need to refresh */
10469 + AuTraceErrPtr(dentry);
10473 +/* ---------------------------------------------------------------------- */
10475 +/* todo: dirty? */
10476 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10478 +struct au_compare_mnt_args {
10480 + struct super_block *sb;
10483 + struct vfsmount *mnt;
10486 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10488 + struct au_compare_mnt_args *a = arg;
10490 + if (mnt->mnt_sb != a->sb)
10492 + a->mnt = mntget(mnt);
10496 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10499 + struct path root;
10500 + struct au_compare_mnt_args args = {
10504 + get_fs_root(current->fs, &root);
10506 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10507 + rcu_read_unlock();
10510 + AuDebugOn(!args.mnt);
10514 +struct au_nfsd_si_lock {
10515 + unsigned int sigen;
10516 + aufs_bindex_t bindex, br_id;
10517 + unsigned char force_lock;
10520 +static int si_nfsd_read_lock(struct super_block *sb,
10521 + struct au_nfsd_si_lock *nsi_lock)
10524 + aufs_bindex_t bindex;
10526 + si_read_lock(sb, AuLock_FLUSH);
10528 + /* branch id may be wrapped around */
10530 + bindex = au_br_index(sb, nsi_lock->br_id);
10531 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
10532 + goto out; /* success */
10536 + if (!nsi_lock->force_lock)
10537 + si_read_unlock(sb);
10540 + nsi_lock->bindex = bindex;
10544 +struct find_name_by_ino {
10545 + struct dir_context ctx;
10546 + int called, found;
10553 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
10554 + loff_t offset, u64 ino, unsigned int d_type)
10556 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
10560 + if (a->ino != ino)
10563 + memcpy(a->name, name, namelen);
10564 + a->namelen = namelen;
10569 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
10570 + struct au_nfsd_si_lock *nsi_lock)
10572 + struct dentry *dentry, *parent;
10573 + struct file *file;
10574 + struct inode *dir;
10575 + struct find_name_by_ino arg = {
10577 + .actor = au_diractor(find_name_by_ino)
10582 + parent = path->dentry;
10584 + si_read_unlock(parent->d_sb);
10585 + file = vfsub_dentry_open(path, au_dir_roflags);
10586 + dentry = (void *)file;
10587 + if (IS_ERR(file))
10590 + dentry = ERR_PTR(-ENOMEM);
10591 + arg.name = (void *)__get_free_page(GFP_NOFS);
10592 + if (unlikely(!arg.name))
10599 + err = vfsub_iterate_dir(file, &arg.ctx);
10600 + } while (!err && !arg.found && arg.called);
10601 + dentry = ERR_PTR(err);
10602 + if (unlikely(err))
10604 + /* instead of ENOENT */
10605 + dentry = ERR_PTR(-ESTALE);
10609 + /* do not call vfsub_lkup_one() */
10610 + dir = parent->d_inode;
10611 + mutex_lock(&dir->i_mutex);
10612 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
10613 + mutex_unlock(&dir->i_mutex);
10614 + AuTraceErrPtr(dentry);
10615 + if (IS_ERR(dentry))
10617 + AuDebugOn(au_test_anon(dentry));
10618 + if (unlikely(!dentry->d_inode)) {
10620 + dentry = ERR_PTR(-ENOENT);
10624 + free_page((unsigned long)arg.name);
10628 + if (unlikely(nsi_lock
10629 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10630 + if (!IS_ERR(dentry)) {
10632 + dentry = ERR_PTR(-ESTALE);
10634 + AuTraceErrPtr(dentry);
10638 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
10640 + struct au_nfsd_si_lock *nsi_lock)
10642 + struct dentry *dentry;
10643 + struct path path;
10645 + if (dir_ino != AUFS_ROOT_INO) {
10646 + path.dentry = decode_by_ino(sb, dir_ino, 0);
10647 + dentry = path.dentry;
10648 + if (!path.dentry || IS_ERR(path.dentry))
10650 + AuDebugOn(au_test_anon(path.dentry));
10652 + path.dentry = dget(sb->s_root);
10654 + path.mnt = au_mnt_get(sb);
10655 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
10659 + AuTraceErrPtr(dentry);
10663 +/* ---------------------------------------------------------------------- */
10665 +static int h_acceptable(void *expv, struct dentry *dentry)
10670 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
10671 + char *buf, int len, struct super_block *sb)
10675 + struct path path;
10677 + p = d_path(h_rootpath, buf, len);
10682 + path.mnt = h_rootpath->mnt;
10683 + path.dentry = h_parent;
10684 + p = d_path(&path, buf, len);
10690 + path.mnt = au_mnt_get(sb);
10691 + path.dentry = sb->s_root;
10692 + p = d_path(&path, buf, len - strlen(p));
10693 + mntput(path.mnt);
10697 + p[strlen(p)] = '/';
10700 + AuTraceErrPtr(p);
10705 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
10706 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
10708 + struct dentry *dentry, *h_parent, *root;
10709 + struct super_block *h_sb;
10710 + char *pathname, *p;
10711 + struct vfsmount *h_mnt;
10712 + struct au_branch *br;
10714 + struct path path;
10716 + br = au_sbr(sb, nsi_lock->bindex);
10717 + h_mnt = au_br_mnt(br);
10718 + h_sb = h_mnt->mnt_sb;
10719 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
10720 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
10721 + fh_len - Fh_tail, fh[Fh_h_type],
10722 + h_acceptable, /*context*/NULL);
10723 + dentry = h_parent;
10724 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
10725 + AuWarn1("%s decode_fh failed, %ld\n",
10726 + au_sbtype(h_sb), PTR_ERR(h_parent));
10730 + if (unlikely(au_test_anon(h_parent))) {
10731 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
10732 + au_sbtype(h_sb));
10733 + goto out_h_parent;
10736 + dentry = ERR_PTR(-ENOMEM);
10737 + pathname = (void *)__get_free_page(GFP_NOFS);
10738 + if (unlikely(!pathname))
10739 + goto out_h_parent;
10741 + root = sb->s_root;
10742 + path.mnt = h_mnt;
10743 + di_read_lock_parent(root, !AuLock_IR);
10744 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
10745 + di_read_unlock(root, !AuLock_IR);
10746 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
10747 + dentry = (void *)p;
10749 + goto out_pathname;
10751 + si_read_unlock(sb);
10752 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
10753 + dentry = ERR_PTR(err);
10754 + if (unlikely(err))
10757 + dentry = ERR_PTR(-ENOENT);
10758 + AuDebugOn(au_test_anon(path.dentry));
10759 + if (unlikely(!path.dentry->d_inode))
10762 + if (ino != path.dentry->d_inode->i_ino)
10763 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10765 + dentry = dget(path.dentry);
10770 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10771 + if (!IS_ERR(dentry)) {
10773 + dentry = ERR_PTR(-ESTALE);
10776 + free_page((unsigned long)pathname);
10780 + AuTraceErrPtr(dentry);
10784 +/* ---------------------------------------------------------------------- */
10786 +static struct dentry *
10787 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10790 + struct dentry *dentry;
10791 + __u32 *fh = fid->raw;
10792 + struct au_branch *br;
10793 + ino_t ino, dir_ino;
10794 + struct au_nfsd_si_lock nsi_lock = {
10798 + dentry = ERR_PTR(-ESTALE);
10799 + /* it should never happen, but the file handle is unreliable */
10800 + if (unlikely(fh_len < Fh_tail))
10802 + nsi_lock.sigen = fh[Fh_sigen];
10803 + nsi_lock.br_id = fh[Fh_br_id];
10805 + /* branch id may be wrapped around */
10807 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
10809 + nsi_lock.force_lock = 1;
10811 + /* is this inode still cached? */
10812 + ino = decode_ino(fh + Fh_ino);
10813 + /* it should never happen */
10814 + if (unlikely(ino == AUFS_ROOT_INO))
10817 + dir_ino = decode_ino(fh + Fh_dir_ino);
10818 + dentry = decode_by_ino(sb, ino, dir_ino);
10819 + if (IS_ERR(dentry))
10824 + /* is the parent dir cached? */
10825 + br = au_sbr(sb, nsi_lock.bindex);
10826 + atomic_inc(&br->br_count);
10827 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
10828 + if (IS_ERR(dentry))
10833 + /* lookup path */
10834 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
10835 + if (IS_ERR(dentry))
10837 + if (unlikely(!dentry))
10838 + /* todo?: make it ESTALE */
10842 + if (!au_digen_test(dentry, au_sigen(sb))
10843 + && dentry->d_inode->i_generation == fh[Fh_igen])
10844 + goto out_unlock; /* success */
10847 + dentry = ERR_PTR(-ESTALE);
10850 + atomic_dec(&br->br_count);
10851 + si_read_unlock(sb);
10853 + AuTraceErrPtr(dentry);
10857 +#if 0 /* reserved for future use */
10858 +/* support subtreecheck option */
10859 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
10860 + int fh_len, int fh_type)
10862 + struct dentry *parent;
10863 + __u32 *fh = fid->raw;
10866 + dir_ino = decode_ino(fh + Fh_dir_ino);
10867 + parent = decode_by_ino(sb, dir_ino, 0);
10868 + if (IS_ERR(parent))
10871 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
10872 + dir_ino, fh, fh_len);
10875 + AuTraceErrPtr(parent);
10880 +/* ---------------------------------------------------------------------- */
10882 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
10883 + struct inode *dir)
10886 + aufs_bindex_t bindex;
10887 + struct super_block *sb, *h_sb;
10888 + struct dentry *dentry, *parent, *h_parent;
10889 + struct inode *h_dir;
10890 + struct au_branch *br;
10893 + if (unlikely(*max_len <= Fh_tail)) {
10894 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
10898 + err = FILEID_ROOT;
10899 + if (inode->i_ino == AUFS_ROOT_INO) {
10900 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
10905 + sb = inode->i_sb;
10906 + err = si_read_lock(sb, AuLock_FLUSH);
10907 + if (unlikely(err))
10910 +#ifdef CONFIG_AUFS_DEBUG
10911 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10912 + AuWarn1("NFS-exporting requires xino\n");
10916 + ii_read_lock_child(inode);
10917 + bindex = au_ibstart(inode);
10919 + dentry = d_find_alias(inode);
10920 + if (unlikely(!dentry))
10922 + AuDebugOn(au_test_anon(dentry));
10923 + parent = dget_parent(dentry);
10925 + if (unlikely(!parent))
10927 + dir = parent->d_inode;
10930 + ii_read_lock_parent(dir);
10931 + h_dir = au_h_iptr(dir, bindex);
10932 + ii_read_unlock(dir);
10933 + if (unlikely(!h_dir))
10935 + h_parent = d_find_alias(h_dir);
10936 + if (unlikely(!h_parent))
10937 + goto out_hparent;
10940 + br = au_sbr(sb, bindex);
10941 + h_sb = au_br_sb(br);
10942 + if (unlikely(!h_sb->s_export_op)) {
10943 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
10944 + goto out_hparent;
10947 + fh[Fh_br_id] = br->br_id;
10948 + fh[Fh_sigen] = au_sigen(sb);
10949 + encode_ino(fh + Fh_ino, inode->i_ino);
10950 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
10951 + fh[Fh_igen] = inode->i_generation;
10953 + *max_len -= Fh_tail;
10954 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
10956 + /*connectable or subtreecheck*/0);
10957 + err = fh[Fh_h_type];
10958 + *max_len += Fh_tail;
10959 + /* todo: macros? */
10960 + if (err != FILEID_INVALID)
10963 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
10970 + ii_read_unlock(inode);
10971 + si_read_unlock(sb);
10973 + if (unlikely(err < 0))
10974 + err = FILEID_INVALID;
10978 +/* ---------------------------------------------------------------------- */
10980 +static int aufs_commit_metadata(struct inode *inode)
10983 + aufs_bindex_t bindex;
10984 + struct super_block *sb;
10985 + struct inode *h_inode;
10986 + int (*f)(struct inode *inode);
10988 + sb = inode->i_sb;
10989 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
10990 + ii_write_lock_child(inode);
10991 + bindex = au_ibstart(inode);
10992 + AuDebugOn(bindex < 0);
10993 + h_inode = au_h_iptr(inode, bindex);
10995 + f = h_inode->i_sb->s_export_op->commit_metadata;
10997 + err = f(h_inode);
10999 + struct writeback_control wbc = {
11000 + .sync_mode = WB_SYNC_ALL,
11001 + .nr_to_write = 0 /* metadata only */
11004 + err = sync_inode(h_inode, &wbc);
11007 + au_cpup_attr_timesizes(inode);
11008 + ii_write_unlock(inode);
11009 + si_read_unlock(sb);
11013 +/* ---------------------------------------------------------------------- */
11015 +static struct export_operations aufs_export_op = {
11016 + .fh_to_dentry = aufs_fh_to_dentry,
11017 + /* .fh_to_parent = aufs_fh_to_parent, */
11018 + .encode_fh = aufs_encode_fh,
11019 + .commit_metadata = aufs_commit_metadata
11022 +void au_export_init(struct super_block *sb)
11024 + struct au_sbinfo *sbinfo;
11027 + sb->s_export_op = &aufs_export_op;
11028 + sbinfo = au_sbi(sb);
11029 + sbinfo->si_xigen = NULL;
11030 + get_random_bytes(&u, sizeof(u));
11031 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11032 + atomic_set(&sbinfo->si_xigen_next, u);
11034 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
11035 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
11036 +++ linux/fs/aufs/file.c 2014-04-24 22:11:10.851935747 +0200
11039 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11041 + * This program, aufs is free software; you can redistribute it and/or modify
11042 + * it under the terms of the GNU General Public License as published by
11043 + * the Free Software Foundation; either version 2 of the License, or
11044 + * (at your option) any later version.
11046 + * This program is distributed in the hope that it will be useful,
11047 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11048 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11049 + * GNU General Public License for more details.
11051 + * You should have received a copy of the GNU General Public License
11052 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11056 + * handling file/dir, and address_space operation
11059 +#ifdef CONFIG_AUFS_DEBUG
11060 +#include <linux/migrate.h>
11062 +#include <linux/pagemap.h>
11065 +/* drop flags for writing */
11066 +unsigned int au_file_roflags(unsigned int flags)
11068 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
11069 + flags |= O_RDONLY | O_NOATIME;
11073 +/* common functions to regular file and dir */
11074 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11075 + struct file *file, int force_wr)
11077 + struct file *h_file;
11078 + struct dentry *h_dentry;
11079 + struct inode *h_inode;
11080 + struct super_block *sb;
11081 + struct au_branch *br;
11082 + struct path h_path;
11083 + int err, exec_flag;
11085 + /* a race condition can happen between open and unlink/rmdir */
11086 + h_file = ERR_PTR(-ENOENT);
11087 + h_dentry = au_h_dptr(dentry, bindex);
11088 + if (au_test_nfsd() && !h_dentry)
11090 + h_inode = h_dentry->d_inode;
11091 + if (au_test_nfsd() && !h_inode)
11093 + spin_lock(&h_dentry->d_lock);
11094 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
11096 + /* || !dentry->d_inode->i_nlink */
11098 + spin_unlock(&h_dentry->d_lock);
11099 + if (unlikely(err))
11102 + sb = dentry->d_sb;
11103 + br = au_sbr(sb, bindex);
11104 + h_file = ERR_PTR(-EACCES);
11105 + exec_flag = flags & __FMODE_EXEC;
11106 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
11109 + /* drop flags for writing */
11110 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
11111 + if (force_wr && !(flags & O_WRONLY))
11113 + flags = au_file_roflags(flags);
11115 + h_file = ERR_PTR(-EROFS);
11116 + flags = au_file_roflags(flags);
11117 + if (unlikely(vfsub_native_ro(h_inode)
11118 + || IS_APPEND(h_inode)))
11120 + flags &= ~O_ACCMODE;
11121 + flags |= O_WRONLY;
11124 + flags &= ~O_CREAT;
11125 + atomic_inc(&br->br_count);
11126 + h_path.dentry = h_dentry;
11127 + h_path.mnt = au_br_mnt(br);
11128 + if (!au_special_file(h_inode->i_mode))
11129 + h_file = vfsub_dentry_open(&h_path, flags);
11131 + /* this block depends upon the configuration */
11132 + di_read_unlock(dentry, AuLock_IR);
11133 + fi_write_unlock(file);
11134 + si_read_unlock(sb);
11135 + h_file = vfsub_dentry_open(&h_path, flags);
11136 + si_noflush_read_lock(sb);
11137 + fi_write_lock(file);
11138 + di_read_lock_child(dentry, AuLock_IR);
11140 + if (IS_ERR(h_file))
11144 + err = deny_write_access(h_file);
11145 + if (unlikely(err)) {
11147 + h_file = ERR_PTR(err);
11151 + fsnotify_open(h_file);
11152 + goto out; /* success */
11155 + atomic_dec(&br->br_count);
11160 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11161 + struct au_fidir *fidir)
11164 + struct dentry *dentry;
11166 + err = au_finfo_init(file, fidir);
11167 + if (unlikely(err))
11170 + dentry = file->f_dentry;
11171 + di_read_lock_child(dentry, AuLock_IR);
11172 + err = open(file, vfsub_file_flags(file));
11173 + di_read_unlock(dentry, AuLock_IR);
11175 + fi_write_unlock(file);
11176 + if (unlikely(err)) {
11177 + au_fi(file)->fi_hdir = NULL;
11178 + au_finfo_fin(file);
11185 +int au_reopen_nondir(struct file *file)
11188 + aufs_bindex_t bstart;
11189 + struct dentry *dentry;
11190 + struct file *h_file, *h_file_tmp;
11192 + dentry = file->f_dentry;
11193 + AuDebugOn(au_special_file(dentry->d_inode->i_mode));
11194 + bstart = au_dbstart(dentry);
11195 + h_file_tmp = NULL;
11196 + if (au_fbstart(file) == bstart) {
11197 + h_file = au_hf_top(file);
11198 + if (file->f_mode == h_file->f_mode)
11199 + return 0; /* success */
11200 + h_file_tmp = h_file;
11201 + get_file(h_file_tmp);
11202 + au_set_h_fptr(file, bstart, NULL);
11204 + AuDebugOn(au_fi(file)->fi_hdir);
11207 + * file exists on both of rw and ro
11208 + * open --> dbstart and fbstart are both 0
11209 + * prepend a branch as rw, "rw" become ro
11211 + * delete the top branch, "rw" becomes rw again
11212 + * --> dbstart is 1, fbstart is still 0
11213 + * write --> fbstart is 0 but dbstart is 1
11215 + /* AuDebugOn(au_fbstart(file) < bstart); */
11217 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
11218 + file, /*force_wr*/0);
11219 + err = PTR_ERR(h_file);
11220 + if (IS_ERR(h_file)) {
11221 + if (h_file_tmp) {
11222 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
11223 + au_set_h_fptr(file, bstart, h_file_tmp);
11224 + h_file_tmp = NULL;
11226 + goto out; /* todo: close all? */
11230 + au_set_fbstart(file, bstart);
11231 + au_set_h_fptr(file, bstart, h_file);
11232 + au_update_figen(file);
11233 + /* todo: necessary? */
11234 + /* file->f_ra = h_file->f_ra; */
11238 + fput(h_file_tmp);
11242 +/* ---------------------------------------------------------------------- */
11244 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
11245 + struct dentry *hi_wh)
11248 + aufs_bindex_t bstart;
11249 + struct au_dinfo *dinfo;
11250 + struct dentry *h_dentry;
11251 + struct au_hdentry *hdp;
11253 + dinfo = au_di(file->f_dentry);
11254 + AuRwMustWriteLock(&dinfo->di_rwsem);
11256 + bstart = dinfo->di_bstart;
11257 + dinfo->di_bstart = btgt;
11258 + hdp = dinfo->di_hdentry;
11259 + h_dentry = hdp[0 + btgt].hd_dentry;
11260 + hdp[0 + btgt].hd_dentry = hi_wh;
11261 + err = au_reopen_nondir(file);
11262 + hdp[0 + btgt].hd_dentry = h_dentry;
11263 + dinfo->di_bstart = bstart;
11268 +static int au_ready_to_write_wh(struct file *file, loff_t len,
11269 + aufs_bindex_t bcpup, struct au_pin *pin)
11272 + struct inode *inode, *h_inode;
11273 + struct dentry *h_dentry, *hi_wh;
11274 + struct au_cp_generic cpg = {
11275 + .dentry = file->f_dentry,
11282 + au_update_dbstart(cpg.dentry);
11283 + inode = cpg.dentry->d_inode;
11285 + if (au_dbstart(cpg.dentry) <= bcpup
11286 + && au_dbend(cpg.dentry) >= bcpup) {
11287 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
11289 + h_inode = h_dentry->d_inode;
11291 + hi_wh = au_hi_wh(inode, bcpup);
11292 + if (!hi_wh && !h_inode)
11293 + err = au_sio_cpup_wh(&cpg, file);
11295 + /* already copied-up after unlink */
11296 + err = au_reopen_wh(file, bcpup, hi_wh);
11299 + && inode->i_nlink > 1
11300 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
11301 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
11307 + * prepare the @file for writing.
11309 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
11312 + aufs_bindex_t dbstart;
11313 + struct dentry *parent, *h_dentry;
11314 + struct inode *inode;
11315 + struct super_block *sb;
11316 + struct file *h_file;
11317 + struct au_cp_generic cpg = {
11318 + .dentry = file->f_dentry,
11323 + .flags = AuCpup_DTIME
11326 + sb = cpg.dentry->d_sb;
11327 + inode = cpg.dentry->d_inode;
11328 + AuDebugOn(au_special_file(inode->i_mode));
11329 + cpg.bsrc = au_fbstart(file);
11330 + err = au_test_ro(sb, cpg.bsrc, inode);
11331 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
11332 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
11337 + /* need to cpup or reopen */
11338 + parent = dget_parent(cpg.dentry);
11339 + di_write_lock_parent(parent);
11340 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
11342 + if (unlikely(err < 0))
11346 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
11347 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
11348 + if (unlikely(err))
11352 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
11353 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11354 + if (unlikely(err))
11357 + h_dentry = au_hf_top(file)->f_dentry;
11358 + dbstart = au_dbstart(cpg.dentry);
11359 + if (dbstart <= cpg.bdst) {
11360 + h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
11361 + AuDebugOn(!h_dentry);
11362 + cpg.bsrc = cpg.bdst;
11365 + if (dbstart <= cpg.bdst /* just reopen */
11366 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
11368 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
11369 + if (IS_ERR(h_file))
11370 + err = PTR_ERR(h_file);
11372 + di_downgrade_lock(parent, AuLock_IR);
11373 + if (dbstart > cpg.bdst)
11374 + err = au_sio_cpup_simple(&cpg);
11376 + err = au_reopen_nondir(file);
11377 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
11379 + } else { /* copyup as wh and reopen */
11381 + * since writable hfsplus branch is not supported,
11382 + * h_open_pre/post() are unnecessary.
11384 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
11385 + di_downgrade_lock(parent, AuLock_IR);
11389 + au_pin_set_parent_lflag(pin, /*lflag*/0);
11390 + goto out_dput; /* success */
11396 + di_downgrade_lock(parent, AuLock_IR);
11398 + di_read_unlock(parent, AuLock_IR);
11405 +/* ---------------------------------------------------------------------- */
11407 +int au_do_flush(struct file *file, fl_owner_t id,
11408 + int (*flush)(struct file *file, fl_owner_t id))
11411 + struct super_block *sb;
11412 + struct inode *inode;
11414 + inode = file_inode(file);
11415 + sb = inode->i_sb;
11416 + si_noflush_read_lock(sb);
11417 + fi_read_lock(file);
11418 + ii_read_lock_child(inode);
11420 + err = flush(file, id);
11421 + au_cpup_attr_timesizes(inode);
11423 + ii_read_unlock(inode);
11424 + fi_read_unlock(file);
11425 + si_read_unlock(sb);
11429 +/* ---------------------------------------------------------------------- */
11431 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
11434 + struct au_pin pin;
11435 + struct au_finfo *finfo;
11436 + struct dentry *parent, *hi_wh;
11437 + struct inode *inode;
11438 + struct super_block *sb;
11439 + struct au_cp_generic cpg = {
11440 + .dentry = file->f_dentry,
11445 + .flags = AuCpup_DTIME
11448 + FiMustWriteLock(file);
11451 + finfo = au_fi(file);
11452 + sb = cpg.dentry->d_sb;
11453 + inode = cpg.dentry->d_inode;
11454 + cpg.bdst = au_ibstart(inode);
11455 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
11458 + parent = dget_parent(cpg.dentry);
11459 + if (au_test_ro(sb, cpg.bdst, inode)) {
11460 + di_read_lock_parent(parent, !AuLock_IR);
11461 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
11463 + di_read_unlock(parent, !AuLock_IR);
11464 + if (unlikely(err < 0))
11469 + di_read_lock_parent(parent, AuLock_IR);
11470 + hi_wh = au_hi_wh(inode, cpg.bdst);
11471 + if (!S_ISDIR(inode->i_mode)
11472 + && au_opt_test(au_mntflags(sb), PLINK)
11473 + && au_plink_test(inode)
11474 + && !d_unhashed(cpg.dentry)
11475 + && cpg.bdst < au_dbstart(cpg.dentry)) {
11476 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
11477 + if (unlikely(err))
11480 + /* always superio. */
11481 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
11482 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11484 + err = au_sio_cpup_simple(&cpg);
11487 + } else if (hi_wh) {
11488 + /* already copied-up after unlink */
11489 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
11490 + *need_reopen = 0;
11494 + di_read_unlock(parent, AuLock_IR);
11501 +static void au_do_refresh_dir(struct file *file)
11503 + aufs_bindex_t bindex, bend, new_bindex, brid;
11504 + struct au_hfile *p, tmp, *q;
11505 + struct au_finfo *finfo;
11506 + struct super_block *sb;
11507 + struct au_fidir *fidir;
11509 + FiMustWriteLock(file);
11511 + sb = file->f_dentry->d_sb;
11512 + finfo = au_fi(file);
11513 + fidir = finfo->fi_hdir;
11514 + AuDebugOn(!fidir);
11515 + p = fidir->fd_hfile + finfo->fi_btop;
11516 + brid = p->hf_br->br_id;
11517 + bend = fidir->fd_bbot;
11518 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
11522 + new_bindex = au_br_index(sb, p->hf_br->br_id);
11523 + if (new_bindex == bindex)
11525 + if (new_bindex < 0) {
11526 + au_set_h_fptr(file, bindex, NULL);
11530 + /* swap two lower inode, and loop again */
11531 + q = fidir->fd_hfile + new_bindex;
11535 + if (tmp.hf_file) {
11541 + p = fidir->fd_hfile;
11542 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
11543 + bend = au_sbend(sb);
11544 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
11545 + finfo->fi_btop++, p++)
11546 + if (p->hf_file) {
11547 + if (file_inode(p->hf_file))
11550 + au_hfput(p, file);
11553 + bend = au_br_index(sb, brid);
11554 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
11555 + finfo->fi_btop++, p++)
11557 + au_hfput(p, file);
11558 + bend = au_sbend(sb);
11561 + p = fidir->fd_hfile + bend;
11562 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
11563 + fidir->fd_bbot--, p--)
11564 + if (p->hf_file) {
11565 + if (file_inode(p->hf_file))
11568 + au_hfput(p, file);
11570 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
11574 + * after branch manipulating, refresh the file.
11576 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
11578 + int err, need_reopen;
11579 + aufs_bindex_t bend, bindex;
11580 + struct dentry *dentry;
11581 + struct au_finfo *finfo;
11582 + struct au_hfile *hfile;
11584 + dentry = file->f_dentry;
11585 + finfo = au_fi(file);
11586 + if (!finfo->fi_hdir) {
11587 + hfile = &finfo->fi_htop;
11588 + AuDebugOn(!hfile->hf_file);
11589 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
11590 + AuDebugOn(bindex < 0);
11591 + if (bindex != finfo->fi_btop)
11592 + au_set_fbstart(file, bindex);
11594 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
11595 + if (unlikely(err))
11597 + au_do_refresh_dir(file);
11602 + if (!au_test_mmapped(file))
11603 + err = au_file_refresh_by_inode(file, &need_reopen);
11604 + if (!err && need_reopen && !d_unlinked(dentry))
11605 + err = reopen(file);
11607 + au_update_figen(file);
11608 + goto out; /* success */
11611 + /* error, close all lower files */
11612 + if (finfo->fi_hdir) {
11613 + bend = au_fbend_dir(file);
11614 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
11615 + au_set_h_fptr(file, bindex, NULL);
11622 +/* common function to regular file and dir */
11623 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11627 + unsigned int sigen, figen;
11628 + aufs_bindex_t bstart;
11629 + unsigned char pseudo_link;
11630 + struct dentry *dentry;
11631 + struct inode *inode;
11634 + dentry = file->f_dentry;
11635 + inode = dentry->d_inode;
11636 + AuDebugOn(au_special_file(inode->i_mode));
11637 + sigen = au_sigen(dentry->d_sb);
11638 + fi_write_lock(file);
11639 + figen = au_figen(file);
11640 + di_write_lock_child(dentry);
11641 + bstart = au_dbstart(dentry);
11642 + pseudo_link = (bstart != au_ibstart(inode));
11643 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
11645 + di_downgrade_lock(dentry, AuLock_IR);
11646 + fi_downgrade_lock(file);
11648 + goto out; /* success */
11651 + AuDbg("sigen %d, figen %d\n", sigen, figen);
11652 + if (au_digen_test(dentry, sigen)) {
11653 + err = au_reval_dpath(dentry, sigen);
11654 + AuDebugOn(!err && au_digen_test(dentry, sigen));
11658 + err = refresh_file(file, reopen);
11661 + di_downgrade_lock(dentry, AuLock_IR);
11662 + fi_downgrade_lock(file);
11665 + di_write_unlock(dentry);
11666 + fi_write_unlock(file);
11673 +/* ---------------------------------------------------------------------- */
11675 +/* cf. aufs_nopage() */
11676 +/* for madvise(2) */
11677 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
11679 + unlock_page(page);
11683 +/* it will never be called, but necessary to support O_DIRECT */
11684 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
11685 + const struct iovec *iov, loff_t offset,
11686 + unsigned long nr_segs)
11687 +{ BUG(); return 0; }
11690 + * it will never be called, but madvise and fadvise behaves differently
11691 + * when get_xip_mem is defined
11693 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
11694 + int create, void **kmem, unsigned long *pfn)
11695 +{ BUG(); return 0; }
11697 +/* they will never be called. */
11698 +#ifdef CONFIG_AUFS_DEBUG
11699 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
11700 + loff_t pos, unsigned len, unsigned flags,
11701 + struct page **pagep, void **fsdata)
11702 +{ AuUnsupport(); return 0; }
11703 +static int aufs_write_end(struct file *file, struct address_space *mapping,
11704 + loff_t pos, unsigned len, unsigned copied,
11705 + struct page *page, void *fsdata)
11706 +{ AuUnsupport(); return 0; }
11707 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
11708 +{ AuUnsupport(); return 0; }
11710 +static int aufs_set_page_dirty(struct page *page)
11711 +{ AuUnsupport(); return 0; }
11712 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
11713 + unsigned int length)
11714 +{ AuUnsupport(); }
11715 +static int aufs_releasepage(struct page *page, gfp_t gfp)
11716 +{ AuUnsupport(); return 0; }
11717 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
11718 + struct page *page, enum migrate_mode mode)
11719 +{ AuUnsupport(); return 0; }
11720 +static int aufs_launder_page(struct page *page)
11721 +{ AuUnsupport(); return 0; }
11722 +static int aufs_is_partially_uptodate(struct page *page,
11723 + read_descriptor_t *desc,
11724 + unsigned long from)
11725 +{ AuUnsupport(); return 0; }
11726 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
11728 +{ AuUnsupport(); }
11729 +static int aufs_error_remove_page(struct address_space *mapping,
11730 + struct page *page)
11731 +{ AuUnsupport(); return 0; }
11732 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
11734 +{ AuUnsupport(); return 0; }
11735 +static void aufs_swap_deactivate(struct file *file)
11736 +{ AuUnsupport(); }
11737 +#endif /* CONFIG_AUFS_DEBUG */
11739 +const struct address_space_operations aufs_aop = {
11740 + .readpage = aufs_readpage,
11741 + .direct_IO = aufs_direct_IO,
11742 + .get_xip_mem = aufs_get_xip_mem,
11743 +#ifdef CONFIG_AUFS_DEBUG
11744 + .writepage = aufs_writepage,
11745 + /* no writepages, because of writepage */
11746 + .set_page_dirty = aufs_set_page_dirty,
11747 + /* no readpages, because of readpage */
11748 + .write_begin = aufs_write_begin,
11749 + .write_end = aufs_write_end,
11750 + /* no bmap, no block device */
11751 + .invalidatepage = aufs_invalidatepage,
11752 + .releasepage = aufs_releasepage,
11753 + .migratepage = aufs_migratepage,
11754 + .launder_page = aufs_launder_page,
11755 + .is_partially_uptodate = aufs_is_partially_uptodate,
11756 + .is_dirty_writeback = aufs_is_dirty_writeback,
11757 + .error_remove_page = aufs_error_remove_page,
11758 + .swap_activate = aufs_swap_activate,
11759 + .swap_deactivate = aufs_swap_deactivate
11760 +#endif /* CONFIG_AUFS_DEBUG */
11762 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
11763 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
11764 +++ linux/fs/aufs/file.h 2014-04-24 22:11:10.851935747 +0200
11767 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11769 + * This program, aufs is free software; you can redistribute it and/or modify
11770 + * it under the terms of the GNU General Public License as published by
11771 + * the Free Software Foundation; either version 2 of the License, or
11772 + * (at your option) any later version.
11774 + * This program is distributed in the hope that it will be useful,
11775 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11776 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11777 + * GNU General Public License for more details.
11779 + * You should have received a copy of the GNU General Public License
11780 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11784 + * file operations
11787 +#ifndef __AUFS_FILE_H__
11788 +#define __AUFS_FILE_H__
11792 +#include <linux/file.h>
11793 +#include <linux/fs.h>
11794 +#include <linux/poll.h>
11795 +#include "rwsem.h"
11799 + struct file *hf_file;
11800 + struct au_branch *hf_br;
11805 + aufs_bindex_t fd_bbot;
11806 + aufs_bindex_t fd_nent;
11807 + struct au_vdir *fd_vdir_cache;
11808 + struct au_hfile fd_hfile[];
11811 +static inline int au_fidir_sz(int nent)
11813 + AuDebugOn(nent < 0);
11814 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
11818 + atomic_t fi_generation;
11820 + struct au_rwsem fi_rwsem;
11821 + aufs_bindex_t fi_btop;
11823 + /* do not union them */
11824 + struct { /* for non-dir */
11825 + struct au_hfile fi_htop;
11826 + atomic_t fi_mmapped;
11828 + struct au_fidir *fi_hdir; /* for dir only */
11830 + struct hlist_node fi_hlist;
11831 + struct file *fi_file; /* very ugly */
11832 +} ____cacheline_aligned_in_smp;
11834 +/* ---------------------------------------------------------------------- */
11837 +extern const struct address_space_operations aufs_aop;
11838 +unsigned int au_file_roflags(unsigned int flags);
11839 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11840 + struct file *file, int force_wr);
11841 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11842 + struct au_fidir *fidir);
11843 +int au_reopen_nondir(struct file *file);
11845 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
11846 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
11848 +int au_do_flush(struct file *file, fl_owner_t id,
11849 + int (*flush)(struct file *file, fl_owner_t id));
11852 +#ifdef CONFIG_AUFS_POLL
11853 +unsigned int aufs_poll(struct file *file, poll_table *wait);
11856 +#ifdef CONFIG_AUFS_BR_HFSPLUS
11858 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11860 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
11861 + struct file *h_file);
11864 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
11870 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
11871 + struct file *h_file);
11875 +extern const struct file_operations aufs_file_fop;
11876 +int au_do_open_nondir(struct file *file, int flags);
11877 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
11879 +#ifdef CONFIG_AUFS_SP_IATTR
11881 +struct au_finfo *au_fi_sp(struct file *file);
11882 +int au_special_file(umode_t mode);
11883 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev);
11885 +static inline struct au_finfo *au_fi_sp(struct file *file)
11889 +AuStubInt0(au_special_file, umode_t mode)
11890 +static inline void au_init_special_fop(struct inode *inode, umode_t mode,
11893 + init_special_inode(inode, mode, rdev);
11898 +void au_hfput(struct au_hfile *hf, struct file *file);
11899 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
11900 + struct file *h_file);
11902 +void au_update_figen(struct file *file);
11903 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
11904 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
11906 +void au_fi_init_once(void *_fi);
11907 +void au_finfo_fin(struct file *file);
11908 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
11911 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
11912 +#ifdef CONFIG_COMPAT
11913 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
11914 + unsigned long arg);
11915 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
11916 + unsigned long arg);
11919 +/* ---------------------------------------------------------------------- */
11921 +static inline struct au_finfo *au_fi(struct file *file)
11923 + struct au_finfo *finfo;
11925 + finfo = au_fi_sp(file);
11927 + finfo = file->private_data;
11931 +/* ---------------------------------------------------------------------- */
11934 + * fi_read_lock, fi_write_lock,
11935 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
11937 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
11939 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
11940 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
11941 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
11943 +/* ---------------------------------------------------------------------- */
11945 +/* todo: hard/soft set? */
11946 +static inline aufs_bindex_t au_fbstart(struct file *file)
11948 + FiMustAnyLock(file);
11949 + return au_fi(file)->fi_btop;
11952 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
11954 + FiMustAnyLock(file);
11955 + AuDebugOn(!au_fi(file)->fi_hdir);
11956 + return au_fi(file)->fi_hdir->fd_bbot;
11959 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
11961 + FiMustAnyLock(file);
11962 + AuDebugOn(!au_fi(file)->fi_hdir);
11963 + return au_fi(file)->fi_hdir->fd_vdir_cache;
11966 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
11968 + FiMustWriteLock(file);
11969 + au_fi(file)->fi_btop = bindex;
11972 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
11974 + FiMustWriteLock(file);
11975 + AuDebugOn(!au_fi(file)->fi_hdir);
11976 + au_fi(file)->fi_hdir->fd_bbot = bindex;
11979 +static inline void au_set_fvdir_cache(struct file *file,
11980 + struct au_vdir *vdir_cache)
11982 + FiMustWriteLock(file);
11983 + AuDebugOn(!au_fi(file)->fi_hdir);
11984 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
11987 +static inline struct file *au_hf_top(struct file *file)
11989 + FiMustAnyLock(file);
11990 + AuDebugOn(au_fi(file)->fi_hdir);
11991 + return au_fi(file)->fi_htop.hf_file;
11994 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
11996 + FiMustAnyLock(file);
11997 + AuDebugOn(!au_fi(file)->fi_hdir);
11998 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
12001 +/* todo: memory barrier? */
12002 +static inline unsigned int au_figen(struct file *f)
12004 + return atomic_read(&au_fi(f)->fi_generation);
12007 +static inline void au_set_mmapped(struct file *f)
12009 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
12011 + pr_warn("fi_mmapped wrapped around\n");
12012 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
12016 +static inline void au_unset_mmapped(struct file *f)
12018 + atomic_dec(&au_fi(f)->fi_mmapped);
12021 +static inline int au_test_mmapped(struct file *f)
12023 + return atomic_read(&au_fi(f)->fi_mmapped);
12026 +/* customize vma->vm_file */
12028 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
12029 + struct file *file)
12033 + f = vma->vm_file;
12035 + vma->vm_file = file;
12040 +#define AuDbgVmRegion(file, vma) do {} while (0)
12042 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12043 + struct file *file)
12045 + au_do_vm_file_reset(vma, file);
12048 +#define AuDbgVmRegion(file, vma) \
12049 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
12051 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12052 + struct file *file)
12056 + au_do_vm_file_reset(vma, file);
12057 + f = vma->vm_region->vm_file;
12059 + vma->vm_region->vm_file = file;
12062 +#endif /* CONFIG_MMU */
12064 +/* handle vma->vm_prfile */
12065 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
12066 + struct file *file)
12069 + vma->vm_prfile = file;
12070 +#ifndef CONFIG_MMU
12072 + vma->vm_region->vm_prfile = file;
12076 +#endif /* __KERNEL__ */
12077 +#endif /* __AUFS_FILE_H__ */
12078 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
12079 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
12080 +++ linux/fs/aufs/finfo.c 2014-04-24 22:11:10.851935747 +0200
12083 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12085 + * This program, aufs is free software; you can redistribute it and/or modify
12086 + * it under the terms of the GNU General Public License as published by
12087 + * the Free Software Foundation; either version 2 of the License, or
12088 + * (at your option) any later version.
12090 + * This program is distributed in the hope that it will be useful,
12091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12093 + * GNU General Public License for more details.
12095 + * You should have received a copy of the GNU General Public License
12096 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12100 + * file private data
12105 +void au_hfput(struct au_hfile *hf, struct file *file)
12107 + /* todo: direct access f_flags */
12108 + if (vfsub_file_flags(file) & __FMODE_EXEC)
12109 + allow_write_access(hf->hf_file);
12110 + fput(hf->hf_file);
12111 + hf->hf_file = NULL;
12112 + atomic_dec(&hf->hf_br->br_count);
12113 + hf->hf_br = NULL;
12116 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
12118 + struct au_finfo *finfo = au_fi(file);
12119 + struct au_hfile *hf;
12120 + struct au_fidir *fidir;
12122 + fidir = finfo->fi_hdir;
12124 + AuDebugOn(finfo->fi_btop != bindex);
12125 + hf = &finfo->fi_htop;
12127 + hf = fidir->fd_hfile + bindex;
12129 + if (hf && hf->hf_file)
12130 + au_hfput(hf, file);
12132 + FiMustWriteLock(file);
12133 + hf->hf_file = val;
12134 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
12138 +void au_update_figen(struct file *file)
12140 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
12141 + /* smp_mb(); */ /* atomic_set */
12144 +/* ---------------------------------------------------------------------- */
12146 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
12148 + struct au_fidir *fidir;
12151 + nbr = au_sbend(sb) + 1;
12153 + nbr = 2; /* initial allocate for 2 branches */
12154 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
12156 + fidir->fd_bbot = -1;
12157 + fidir->fd_nent = nbr;
12158 + fidir->fd_vdir_cache = NULL;
12164 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
12167 + struct au_fidir *fidir, *p;
12169 + AuRwMustWriteLock(&finfo->fi_rwsem);
12170 + fidir = finfo->fi_hdir;
12171 + AuDebugOn(!fidir);
12174 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
12177 + p->fd_nent = nbr;
12178 + finfo->fi_hdir = p;
12185 +/* ---------------------------------------------------------------------- */
12187 +void au_finfo_fin(struct file *file)
12189 + struct au_finfo *finfo;
12191 + au_nfiles_dec(file->f_dentry->d_sb);
12193 + finfo = au_fi(file);
12194 + AuDebugOn(finfo->fi_hdir);
12195 + AuRwDestroy(&finfo->fi_rwsem);
12196 + au_cache_free_finfo(finfo);
12199 +void au_fi_init_once(void *_finfo)
12201 + struct au_finfo *finfo = _finfo;
12202 + static struct lock_class_key aufs_fi;
12204 + au_rw_init(&finfo->fi_rwsem);
12205 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
12208 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
12211 + struct au_finfo *finfo;
12212 + struct dentry *dentry;
12215 + dentry = file->f_dentry;
12216 + finfo = au_cache_alloc_finfo();
12217 + if (unlikely(!finfo))
12221 + au_nfiles_inc(dentry->d_sb);
12222 + /* verbose coding for lock class name */
12224 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
12226 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
12227 + au_rw_write_lock(&finfo->fi_rwsem);
12228 + finfo->fi_btop = -1;
12229 + finfo->fi_hdir = fidir;
12230 + atomic_set(&finfo->fi_generation, au_digen(dentry));
12231 + /* smp_mb(); */ /* atomic_set */
12233 + file->private_data = finfo;
12238 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
12239 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
12240 +++ linux/fs/aufs/f_op.c 2014-04-24 22:11:10.851935747 +0200
12243 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12245 + * This program, aufs is free software; you can redistribute it and/or modify
12246 + * it under the terms of the GNU General Public License as published by
12247 + * the Free Software Foundation; either version 2 of the License, or
12248 + * (at your option) any later version.
12250 + * This program is distributed in the hope that it will be useful,
12251 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12252 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12253 + * GNU General Public License for more details.
12255 + * You should have received a copy of the GNU General Public License
12256 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12260 + * file and vm operations
12263 +#include <linux/aio.h>
12264 +#include <linux/fs_stack.h>
12265 +#include <linux/mman.h>
12266 +#include <linux/security.h>
12269 +int au_do_open_nondir(struct file *file, int flags)
12272 + aufs_bindex_t bindex;
12273 + struct file *h_file;
12274 + struct dentry *dentry;
12275 + struct au_finfo *finfo;
12277 + FiMustWriteLock(file);
12280 + dentry = file->f_dentry;
12281 + finfo = au_fi(file);
12282 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
12283 + atomic_set(&finfo->fi_mmapped, 0);
12284 + bindex = au_dbstart(dentry);
12285 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
12286 + if (IS_ERR(h_file))
12287 + err = PTR_ERR(h_file);
12289 + au_set_fbstart(file, bindex);
12290 + au_set_h_fptr(file, bindex, h_file);
12291 + au_update_figen(file);
12292 + finfo->fi_file = file;
12293 + au_sphl_add(&finfo->fi_hlist, &au_sbi(dentry->d_sb)->si_files);
12294 + /* todo: necessary? */
12295 + /* file->f_ra = h_file->f_ra; */
12301 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
12302 + struct file *file)
12305 + struct super_block *sb;
12307 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
12308 + file, vfsub_file_flags(file), file->f_mode);
12310 + sb = file->f_dentry->d_sb;
12311 + si_read_lock(sb, AuLock_FLUSH);
12312 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
12313 + si_read_unlock(sb);
12317 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
12319 + struct au_finfo *finfo;
12320 + aufs_bindex_t bindex;
12322 + finfo = au_fi(file);
12323 + au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files);
12324 + bindex = finfo->fi_btop;
12326 + au_set_h_fptr(file, bindex, NULL);
12328 + au_finfo_fin(file);
12332 +/* ---------------------------------------------------------------------- */
12334 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
12337 + struct file *h_file;
12340 + h_file = au_hf_top(file);
12342 + err = vfsub_flush(h_file, id);
12346 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
12348 + return au_do_flush(file, id, au_do_flush_nondir);
12351 +/* ---------------------------------------------------------------------- */
12353 + * read and write functions acquire [fdi]_rwsem once, but release before
12354 + * mmap_sem. This is because to stop a race condition between mmap(2).
12355 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
12356 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
12357 + * read functions after [fdi]_rwsem are released, but it should be harmless.
12360 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
12364 + struct dentry *dentry;
12365 + struct file *h_file;
12366 + struct super_block *sb;
12368 + dentry = file->f_dentry;
12369 + sb = dentry->d_sb;
12370 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12371 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12372 + if (unlikely(err))
12375 + h_file = au_hf_top(file);
12376 + get_file(h_file);
12377 + di_read_unlock(dentry, AuLock_IR);
12378 + fi_read_unlock(file);
12380 + /* filedata may be obsoleted by concurrent copyup, but no problem */
12381 + err = vfsub_read_u(h_file, buf, count, ppos);
12382 + /* todo: necessary? */
12383 + /* file->f_ra = h_file->f_ra; */
12384 + /* update without lock, I don't think it a problem */
12385 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12389 + si_read_unlock(sb);
12394 + * todo: very ugly
12395 + * it locks both of i_mutex and si_rwsem for read in safe.
12396 + * if the plink maintenance mode continues forever (that is the problem),
12397 + * may loop forever.
12399 +static void au_mtx_and_read_lock(struct inode *inode)
12402 + struct super_block *sb = inode->i_sb;
12405 + mutex_lock(&inode->i_mutex);
12406 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12409 + mutex_unlock(&inode->i_mutex);
12410 + si_read_lock(sb, AuLock_NOPLMW);
12411 + si_read_unlock(sb);
12415 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
12416 + size_t count, loff_t *ppos)
12419 + struct au_pin pin;
12420 + struct dentry *dentry;
12421 + struct super_block *sb;
12422 + struct inode *inode;
12423 + struct file *h_file;
12424 + char __user *buf = (char __user *)ubuf;
12426 + dentry = file->f_dentry;
12427 + sb = dentry->d_sb;
12428 + inode = dentry->d_inode;
12429 + au_mtx_and_read_lock(inode);
12431 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12432 + if (unlikely(err))
12435 + err = au_ready_to_write(file, -1, &pin);
12436 + di_downgrade_lock(dentry, AuLock_IR);
12437 + if (unlikely(err)) {
12438 + di_read_unlock(dentry, AuLock_IR);
12439 + fi_write_unlock(file);
12443 + h_file = au_hf_top(file);
12444 + get_file(h_file);
12446 + di_read_unlock(dentry, AuLock_IR);
12447 + fi_write_unlock(file);
12449 + err = vfsub_write_u(h_file, buf, count, ppos);
12450 + ii_write_lock_child(inode);
12451 + au_cpup_attr_timesizes(inode);
12452 + inode->i_mode = file_inode(h_file)->i_mode;
12453 + ii_write_unlock(inode);
12457 + si_read_unlock(sb);
12458 + mutex_unlock(&inode->i_mutex);
12462 +static ssize_t au_do_aio(struct file *h_file, int rw, struct kiocb *kio,
12463 + const struct iovec *iov, unsigned long nv, loff_t pos)
12466 + struct file *file;
12467 + ssize_t (*func)(struct kiocb *, const struct iovec *, unsigned long,
12470 + err = security_file_permission(h_file, rw);
12471 + if (unlikely(err))
12476 + if (rw == MAY_READ)
12477 + func = h_file->f_op->aio_read;
12478 + else if (rw == MAY_WRITE)
12479 + func = h_file->f_op->aio_write;
12481 + file = kio->ki_filp;
12482 + kio->ki_filp = h_file;
12484 + err = func(kio, iov, nv, pos);
12486 + kio->ki_filp = file;
12488 + /* currently there is no such fs */
12495 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
12496 + unsigned long nv, loff_t pos)
12499 + struct file *file, *h_file;
12500 + struct dentry *dentry;
12501 + struct super_block *sb;
12503 + file = kio->ki_filp;
12504 + dentry = file->f_dentry;
12505 + sb = dentry->d_sb;
12506 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12507 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12508 + if (unlikely(err))
12511 + h_file = au_hf_top(file);
12512 + get_file(h_file);
12513 + di_read_unlock(dentry, AuLock_IR);
12514 + fi_read_unlock(file);
12516 + err = au_do_aio(h_file, MAY_READ, kio, iov, nv, pos);
12517 + /* todo: necessary? */
12518 + /* file->f_ra = h_file->f_ra; */
12519 + /* update without lock, I don't think it a problem */
12520 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12524 + si_read_unlock(sb);
12528 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
12529 + unsigned long nv, loff_t pos)
12532 + struct au_pin pin;
12533 + struct dentry *dentry;
12534 + struct inode *inode;
12535 + struct file *file, *h_file;
12536 + struct super_block *sb;
12538 + file = kio->ki_filp;
12539 + dentry = file->f_dentry;
12540 + sb = dentry->d_sb;
12541 + inode = dentry->d_inode;
12542 + au_mtx_and_read_lock(inode);
12544 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12545 + if (unlikely(err))
12548 + err = au_ready_to_write(file, -1, &pin);
12549 + di_downgrade_lock(dentry, AuLock_IR);
12550 + if (unlikely(err)) {
12551 + di_read_unlock(dentry, AuLock_IR);
12552 + fi_write_unlock(file);
12556 + h_file = au_hf_top(file);
12557 + get_file(h_file);
12559 + di_read_unlock(dentry, AuLock_IR);
12560 + fi_write_unlock(file);
12562 + err = au_do_aio(h_file, MAY_WRITE, kio, iov, nv, pos);
12563 + ii_write_lock_child(inode);
12564 + au_cpup_attr_timesizes(inode);
12565 + inode->i_mode = file_inode(h_file)->i_mode;
12566 + ii_write_unlock(inode);
12570 + si_read_unlock(sb);
12571 + mutex_unlock(&inode->i_mutex);
12575 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
12576 + struct pipe_inode_info *pipe, size_t len,
12577 + unsigned int flags)
12580 + struct file *h_file;
12581 + struct dentry *dentry;
12582 + struct super_block *sb;
12584 + dentry = file->f_dentry;
12585 + sb = dentry->d_sb;
12586 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12587 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12588 + if (unlikely(err))
12592 + h_file = au_hf_top(file);
12593 + get_file(h_file);
12594 + if (au_test_loopback_kthread()) {
12595 + au_warn_loopback(h_file->f_dentry->d_sb);
12596 + if (file->f_mapping != h_file->f_mapping) {
12597 + file->f_mapping = h_file->f_mapping;
12598 + smp_mb(); /* unnecessary? */
12601 + di_read_unlock(dentry, AuLock_IR);
12602 + fi_read_unlock(file);
12604 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
12605 + /* todo: necessasry? */
12606 + /* file->f_ra = h_file->f_ra; */
12607 + /* update without lock, I don't think it a problem */
12608 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
12612 + si_read_unlock(sb);
12617 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
12618 + size_t len, unsigned int flags)
12621 + struct au_pin pin;
12622 + struct dentry *dentry;
12623 + struct inode *inode;
12624 + struct file *h_file;
12625 + struct super_block *sb;
12627 + dentry = file->f_dentry;
12628 + sb = dentry->d_sb;
12629 + inode = dentry->d_inode;
12630 + au_mtx_and_read_lock(inode);
12632 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12633 + if (unlikely(err))
12636 + err = au_ready_to_write(file, -1, &pin);
12637 + di_downgrade_lock(dentry, AuLock_IR);
12638 + if (unlikely(err)) {
12639 + di_read_unlock(dentry, AuLock_IR);
12640 + fi_write_unlock(file);
12644 + h_file = au_hf_top(file);
12645 + get_file(h_file);
12647 + di_read_unlock(dentry, AuLock_IR);
12648 + fi_write_unlock(file);
12650 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
12651 + ii_write_lock_child(inode);
12652 + au_cpup_attr_timesizes(inode);
12653 + inode->i_mode = file_inode(h_file)->i_mode;
12654 + ii_write_unlock(inode);
12658 + si_read_unlock(sb);
12659 + mutex_unlock(&inode->i_mutex);
12663 +/* ---------------------------------------------------------------------- */
12666 + * The locking order around current->mmap_sem.
12667 + * - in most and regular cases
12668 + * file I/O syscall -- aufs_read() or something
12669 + * -- si_rwsem for read -- mmap_sem
12670 + * (Note that [fdi]i_rwsem are released before mmap_sem).
12672 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
12673 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
12674 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
12675 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
12676 + * It means that when aufs acquires si_rwsem for write, the process should never
12677 + * acquire mmap_sem.
12679 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
12680 + * problem either since any directory is not able to be mmap-ed.
12681 + * The similar scenario is applied to aufs_readlink() too.
12684 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
12685 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
12687 +static unsigned long au_arch_prot_conv(unsigned long flags)
12689 + /* currently ppc64 only */
12690 +#ifdef CONFIG_PPC64
12691 + /* cf. linux/arch/powerpc/include/asm/mman.h */
12692 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
12693 + return AuConv_VM_PROT(flags, SAO);
12695 + AuDebugOn(arch_calc_vm_prot_bits(-1));
12700 +static unsigned long au_prot_conv(unsigned long flags)
12702 + return AuConv_VM_PROT(flags, READ)
12703 + | AuConv_VM_PROT(flags, WRITE)
12704 + | AuConv_VM_PROT(flags, EXEC)
12705 + | au_arch_prot_conv(flags);
12708 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
12709 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
12711 +static unsigned long au_flag_conv(unsigned long flags)
12713 + return AuConv_VM_MAP(flags, GROWSDOWN)
12714 + | AuConv_VM_MAP(flags, DENYWRITE)
12715 + | AuConv_VM_MAP(flags, LOCKED);
12718 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
12721 + aufs_bindex_t bstart;
12722 + const unsigned char wlock
12723 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
12724 + struct dentry *dentry;
12725 + struct super_block *sb;
12726 + struct file *h_file;
12727 + struct au_branch *br;
12728 + struct au_pin pin;
12730 + AuDbgVmRegion(file, vma);
12732 + dentry = file->f_dentry;
12733 + sb = dentry->d_sb;
12735 + si_read_lock(sb, AuLock_NOPLMW);
12736 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12737 + if (unlikely(err))
12741 + err = au_ready_to_write(file, -1, &pin);
12742 + di_write_unlock(dentry);
12743 + if (unlikely(err)) {
12744 + fi_write_unlock(file);
12749 + di_write_unlock(dentry);
12751 + bstart = au_fbstart(file);
12752 + br = au_sbr(sb, bstart);
12753 + h_file = au_hf_top(file);
12754 + get_file(h_file);
12755 + au_set_mmapped(file);
12756 + fi_write_unlock(file);
12759 + au_vm_file_reset(vma, h_file);
12760 + err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
12761 + au_flag_conv(vma->vm_flags));
12763 + err = h_file->f_op->mmap(h_file, vma);
12764 + if (unlikely(err))
12767 + au_vm_prfile_set(vma, file);
12768 + /* update without lock, I don't think it a problem */
12769 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
12770 + goto out_fput; /* success */
12773 + au_unset_mmapped(file);
12774 + au_vm_file_reset(vma, file);
12779 + si_read_unlock(sb);
12785 +/* ---------------------------------------------------------------------- */
12787 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
12791 + struct au_pin pin;
12792 + struct dentry *dentry;
12793 + struct inode *inode;
12794 + struct file *h_file;
12795 + struct super_block *sb;
12797 + dentry = file->f_dentry;
12798 + inode = dentry->d_inode;
12799 + sb = dentry->d_sb;
12800 + mutex_lock(&inode->i_mutex);
12801 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
12802 + if (unlikely(err))
12805 + err = 0; /* -EBADF; */ /* posix? */
12806 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12808 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12809 + if (unlikely(err))
12812 + err = au_ready_to_write(file, -1, &pin);
12813 + di_downgrade_lock(dentry, AuLock_IR);
12814 + if (unlikely(err))
12819 + h_file = au_hf_top(file);
12820 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
12821 + au_cpup_attr_timesizes(inode);
12824 + di_read_unlock(dentry, AuLock_IR);
12825 + fi_write_unlock(file);
12827 + si_read_unlock(sb);
12829 + mutex_unlock(&inode->i_mutex);
12833 +/* no one supports this operation, currently */
12835 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
12838 + struct au_pin pin;
12839 + struct dentry *dentry;
12840 + struct inode *inode;
12841 + struct file *file, *h_file;
12843 + file = kio->ki_filp;
12844 + dentry = file->f_dentry;
12845 + inode = dentry->d_inode;
12846 + au_mtx_and_read_lock(inode);
12848 + err = 0; /* -EBADF; */ /* posix? */
12849 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
12851 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
12852 + if (unlikely(err))
12855 + err = au_ready_to_write(file, -1, &pin);
12856 + di_downgrade_lock(dentry, AuLock_IR);
12857 + if (unlikely(err))
12862 + h_file = au_hf_top(file);
12863 + if (h_file->f_op->aio_fsync) {
12864 + struct mutex *h_mtx;
12866 + h_mtx = &file_inode(h_file)->i_mutex;
12867 + if (!is_sync_kiocb(kio)) {
12868 + get_file(h_file);
12871 + kio->ki_filp = h_file;
12872 + err = h_file->f_op->aio_fsync(kio, datasync);
12873 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
12875 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
12877 + au_cpup_attr_timesizes(inode);
12878 + mutex_unlock(h_mtx);
12882 + di_read_unlock(dentry, AuLock_IR);
12883 + fi_write_unlock(file);
12885 + si_read_unlock(inode->sb);
12886 + mutex_unlock(&inode->i_mutex);
12891 +static int aufs_fasync(int fd, struct file *file, int flag)
12894 + struct file *h_file;
12895 + struct dentry *dentry;
12896 + struct super_block *sb;
12898 + dentry = file->f_dentry;
12899 + sb = dentry->d_sb;
12900 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
12901 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
12902 + if (unlikely(err))
12905 + h_file = au_hf_top(file);
12906 + if (h_file->f_op->fasync)
12907 + err = h_file->f_op->fasync(fd, h_file, flag);
12909 + di_read_unlock(dentry, AuLock_IR);
12910 + fi_read_unlock(file);
12913 + si_read_unlock(sb);
12917 +/* ---------------------------------------------------------------------- */
12919 +/* no one supports this operation, currently */
12921 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
12922 + size_t len, loff_t *pos , int more)
12927 +/* ---------------------------------------------------------------------- */
12929 +const struct file_operations aufs_file_fop = {
12930 + .owner = THIS_MODULE,
12932 + .llseek = default_llseek,
12934 + .read = aufs_read,
12935 + .write = aufs_write,
12936 + .aio_read = aufs_aio_read,
12937 + .aio_write = aufs_aio_write,
12938 +#ifdef CONFIG_AUFS_POLL
12939 + .poll = aufs_poll,
12941 + .unlocked_ioctl = aufs_ioctl_nondir,
12942 +#ifdef CONFIG_COMPAT
12943 + .compat_ioctl = aufs_compat_ioctl_nondir,
12945 + .mmap = aufs_mmap,
12946 + .open = aufs_open_nondir,
12947 + .flush = aufs_flush_nondir,
12948 + .release = aufs_release_nondir,
12949 + .fsync = aufs_fsync_nondir,
12950 + /* .aio_fsync = aufs_aio_fsync_nondir, */
12951 + .fasync = aufs_fasync,
12952 + /* .sendpage = aufs_sendpage, */
12953 + .splice_write = aufs_splice_write,
12954 + .splice_read = aufs_splice_read,
12956 + .aio_splice_write = aufs_aio_splice_write,
12957 + .aio_splice_read = aufs_aio_splice_read
12960 diff -urN /usr/share/empty/fs/aufs/f_op_sp.c linux/fs/aufs/f_op_sp.c
12961 --- /usr/share/empty/fs/aufs/f_op_sp.c 1970-01-01 01:00:00.000000000 +0100
12962 +++ linux/fs/aufs/f_op_sp.c 2014-04-24 22:11:10.851935747 +0200
12965 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12967 + * This program, aufs is free software; you can redistribute it and/or modify
12968 + * it under the terms of the GNU General Public License as published by
12969 + * the Free Software Foundation; either version 2 of the License, or
12970 + * (at your option) any later version.
12972 + * This program is distributed in the hope that it will be useful,
12973 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12975 + * GNU General Public License for more details.
12977 + * You should have received a copy of the GNU General Public License
12978 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12982 + * file operations for special files.
12983 + * while they exist in aufs virtually,
12984 + * their file I/O is handled out of aufs.
12987 +#include <linux/aio.h>
12991 + * I don't think the size of this list grows much.
12992 + * so here is a very simple list implemented in order to find finfo matching a
12995 +static struct au_sphlhead au_finfo_sp = {
12996 + .spin = __SPIN_LOCK_INITIALIZER(au_finfo_sp.spin),
12997 + .head = HLIST_HEAD_INIT
13000 +struct au_finfo_sp {
13001 + struct hlist_node hlist;
13002 + struct file *file;
13003 + struct au_finfo *finfo;
13006 +struct au_finfo *au_fi_sp(struct file *file)
13008 + struct au_finfo *finfo;
13009 + struct au_finfo_sp *sp;
13012 + spin_lock(&au_finfo_sp.spin);
13013 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
13014 + if (sp->file != file)
13016 + finfo = sp->finfo;
13019 + spin_unlock(&au_finfo_sp.spin);
13024 +static int au_fi_sp_add(struct file *file)
13027 + struct au_finfo_sp *sp;
13030 + sp = kmalloc(sizeof(*sp), GFP_NOFS);
13034 + sp->finfo = file->private_data;
13035 + spin_lock(&au_finfo_sp.spin);
13036 + hlist_add_head(&sp->hlist, &au_finfo_sp.head);
13037 + spin_unlock(&au_finfo_sp.spin);
13042 +static void au_fi_sp_del(struct file *file)
13044 + struct au_finfo_sp *sp, *do_free;
13047 + spin_lock(&au_finfo_sp.spin);
13048 + hlist_for_each_entry(sp, &au_finfo_sp.head, hlist) {
13049 + if (sp->file != file)
13051 + hlist_del(&sp->hlist);
13055 + spin_unlock(&au_finfo_sp.spin);
13059 +/* ---------------------------------------------------------------------- */
13061 +static ssize_t aufs_aio_read_sp(struct kiocb *kio, const struct iovec *iov,
13062 + unsigned long nv, loff_t pos)
13065 + aufs_bindex_t bstart;
13066 + unsigned char wbr;
13067 + struct file *file, *h_file;
13068 + struct super_block *sb;
13070 + file = kio->ki_filp;
13071 + sb = file->f_dentry->d_sb;
13072 + si_read_lock(sb, AuLock_FLUSH);
13073 + fi_read_lock(file);
13074 + bstart = au_fbstart(file);
13075 + h_file = au_hf_top(file);
13076 + fi_read_unlock(file);
13077 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
13078 + si_read_unlock(sb);
13080 + /* do not change the file in kio */
13081 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_read);
13082 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
13083 + if (err > 0 && wbr)
13084 + file_accessed(h_file);
13089 +static ssize_t aufs_aio_write_sp(struct kiocb *kio, const struct iovec *iov,
13090 + unsigned long nv, loff_t pos)
13093 + aufs_bindex_t bstart;
13094 + unsigned char wbr;
13095 + struct super_block *sb;
13096 + struct file *file, *h_file;
13098 + file = kio->ki_filp;
13099 + sb = file->f_dentry->d_sb;
13100 + si_read_lock(sb, AuLock_FLUSH);
13101 + fi_read_lock(file);
13102 + bstart = au_fbstart(file);
13103 + h_file = au_hf_top(file);
13104 + fi_read_unlock(file);
13105 + wbr = !!au_br_writable(au_sbr(sb, bstart)->br_perm);
13106 + si_read_unlock(sb);
13108 + /* do not change the file in kio */
13109 + AuDebugOn(!h_file->f_op || !h_file->f_op->aio_write);
13110 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
13114 +/* ---------------------------------------------------------------------- */
13116 +static int aufs_release_sp(struct inode *inode, struct file *file)
13119 + struct file *h_file;
13121 + fi_read_lock(file);
13122 + h_file = au_hf_top(file);
13123 + fi_read_unlock(file);
13124 + /* close this fifo in aufs */
13125 + err = h_file->f_op->release(inode, file); /* ignore */
13126 + aufs_release_nondir(inode, file); /* ignore */
13127 + au_fi_sp_del(file);
13131 +/* ---------------------------------------------------------------------- */
13133 +/* currently, support only FIFO */
13135 + AuSp_FIFO, AuSp_FIFO_R, AuSp_FIFO_W, AuSp_FIFO_RW,
13136 + /* AuSp_SOCK, AuSp_CHR, AuSp_BLK, */
13139 +static int aufs_open_sp(struct inode *inode, struct file *file);
13140 +static struct au_sp_fop {
13142 + struct file_operations fop; /* not 'const' */
13144 +} au_sp_fop[AuSp_Last] = {
13147 + .owner = THIS_MODULE,
13148 + .open = aufs_open_sp
13153 +static void au_init_fop_sp(struct file *file)
13155 + struct au_sp_fop *p;
13157 + struct file *h_file;
13160 + if (unlikely(!p->done)) {
13161 + /* initialize first time only */
13162 + static DEFINE_SPINLOCK(spin);
13164 + spin_lock(&spin);
13166 + BUILD_BUG_ON(sizeof(au_sp_fop)/sizeof(*au_sp_fop)
13168 + for (i = 0; i < AuSp_Last; i++)
13169 + spin_lock_init(&p[i].spin);
13172 + spin_unlock(&spin);
13175 + switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
13179 + case FMODE_WRITE:
13182 + case FMODE_READ | FMODE_WRITE:
13183 + i = AuSp_FIFO_RW;
13190 + if (unlikely(!p->done)) {
13191 + /* initialize first time only */
13192 + h_file = au_hf_top(file);
13193 + spin_lock(&p->spin);
13195 + p->fop = *h_file->f_op;
13196 + p->fop.owner = THIS_MODULE;
13197 + if (p->fop.aio_read)
13198 + p->fop.aio_read = aufs_aio_read_sp;
13199 + if (p->fop.aio_write)
13200 + p->fop.aio_write = aufs_aio_write_sp;
13201 + p->fop.release = aufs_release_sp;
13204 + spin_unlock(&p->spin);
13206 + file->f_op = &p->fop;
13209 +static int au_cpup_sp(struct dentry *dentry)
13212 + struct au_pin pin;
13213 + struct au_wr_dir_args wr_dir_args = {
13214 + .force_btgt = -1,
13217 + struct au_cp_generic cpg = {
13218 + .dentry = dentry,
13223 + .flags = AuCpup_DTIME
13226 + AuDbg("%pd\n", dentry);
13228 + di_read_unlock(dentry, AuLock_IR);
13229 + di_write_lock_child(dentry);
13230 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
13231 + if (unlikely(err < 0))
13235 + if (cpg.bdst == au_dbstart(dentry))
13236 + goto out; /* success */
13238 + err = au_pin(&pin, dentry, cpg.bdst, au_opt_udba(dentry->d_sb),
13239 + AuPin_MNT_WRITE);
13241 + err = au_sio_cpup_simple(&cpg);
13246 + di_downgrade_lock(dentry, AuLock_IR);
13250 +static int au_do_open_sp(struct file *file, int flags)
13253 + struct dentry *dentry;
13254 + struct super_block *sb;
13255 + struct file *h_file;
13256 + struct inode *h_inode;
13258 + err = au_fi_sp_add(file);
13259 + if (unlikely(err))
13262 + dentry = file->f_dentry;
13263 + AuDbg("%pd\n", dentry);
13266 + * try copying-up.
13267 + * operate on the ro branch is not an error.
13269 + au_cpup_sp(dentry); /* ignore */
13271 + /* prepare h_file */
13272 + err = au_do_open_nondir(file, vfsub_file_flags(file));
13273 + if (unlikely(err))
13276 + sb = dentry->d_sb;
13277 + h_file = au_hf_top(file);
13278 + h_inode = file_inode(h_file);
13279 + di_read_unlock(dentry, AuLock_IR);
13280 + fi_write_unlock(file);
13281 + si_read_unlock(sb);
13282 + /* open this fifo in aufs */
13283 + err = h_inode->i_fop->open(file_inode(file), file);
13284 + si_noflush_read_lock(sb);
13285 + fi_write_lock(file);
13286 + di_read_lock_child(dentry, AuLock_IR);
13288 + au_init_fop_sp(file);
13289 + goto out; /* success */
13293 + au_fi_sp_del(file);
13298 +static int aufs_open_sp(struct inode *inode, struct file *file)
13301 + struct super_block *sb;
13303 + sb = file->f_dentry->d_sb;
13304 + si_read_lock(sb, AuLock_FLUSH);
13305 + err = au_do_open(file, au_do_open_sp, /*fidir*/NULL);
13306 + si_read_unlock(sb);
13310 +/* ---------------------------------------------------------------------- */
13312 +void au_init_special_fop(struct inode *inode, umode_t mode, dev_t rdev)
13314 + init_special_inode(inode, mode, rdev);
13316 + switch (mode & S_IFMT) {
13318 + inode->i_fop = &au_sp_fop[AuSp_FIFO].fop;
13329 +int au_special_file(umode_t mode)
13334 + switch (mode & S_IFMT) {
13346 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
13347 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13348 +++ linux/fs/aufs/fstype.h 2014-04-24 22:11:10.851935747 +0200
13351 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13353 + * This program, aufs is free software; you can redistribute it and/or modify
13354 + * it under the terms of the GNU General Public License as published by
13355 + * the Free Software Foundation; either version 2 of the License, or
13356 + * (at your option) any later version.
13358 + * This program is distributed in the hope that it will be useful,
13359 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13360 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13361 + * GNU General Public License for more details.
13363 + * You should have received a copy of the GNU General Public License
13364 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13368 + * judging filesystem type
13371 +#ifndef __AUFS_FSTYPE_H__
13372 +#define __AUFS_FSTYPE_H__
13376 +#include <linux/fs.h>
13377 +#include <linux/magic.h>
13378 +#include <linux/romfs_fs.h>
13380 +static inline int au_test_aufs(struct super_block *sb)
13382 + return sb->s_magic == AUFS_SUPER_MAGIC;
13385 +static inline const char *au_sbtype(struct super_block *sb)
13387 + return sb->s_type->name;
13390 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
13392 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
13393 + return sb->s_magic == ROMFS_MAGIC;
13399 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
13401 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
13402 + return sb->s_magic == ISOFS_SUPER_MAGIC;
13408 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
13410 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
13411 + return sb->s_magic == CRAMFS_MAGIC;
13416 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
13418 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
13419 + return sb->s_magic == NFS_SUPER_MAGIC;
13425 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
13427 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
13428 + return sb->s_magic == FUSE_SUPER_MAGIC;
13434 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
13436 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
13437 + return sb->s_magic == XFS_SB_MAGIC;
13443 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
13445 +#ifdef CONFIG_TMPFS
13446 + return sb->s_magic == TMPFS_MAGIC;
13452 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
13454 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
13455 + return !strcmp(au_sbtype(sb), "ecryptfs");
13461 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
13463 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
13464 + return sb->s_magic == OCFS2_SUPER_MAGIC;
13470 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
13472 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
13473 + return sb->s_magic == DLMFS_MAGIC;
13479 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
13481 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
13482 + return sb->s_magic == CODA_SUPER_MAGIC;
13488 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
13490 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
13491 + return sb->s_magic == V9FS_MAGIC;
13497 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
13499 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
13500 + return sb->s_magic == EXT4_SUPER_MAGIC;
13506 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
13508 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
13509 + return !strcmp(au_sbtype(sb), "sysv");
13515 +static inline int au_test_ramfs(struct super_block *sb)
13517 + return sb->s_magic == RAMFS_MAGIC;
13520 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
13522 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
13523 + return sb->s_magic == UBIFS_SUPER_MAGIC;
13529 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
13531 +#ifdef CONFIG_PROC_FS
13532 + return sb->s_magic == PROC_SUPER_MAGIC;
13538 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
13540 +#ifdef CONFIG_SYSFS
13541 + return sb->s_magic == SYSFS_MAGIC;
13547 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
13549 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
13550 + return sb->s_magic == CONFIGFS_MAGIC;
13556 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
13558 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
13559 + return sb->s_magic == MINIX3_SUPER_MAGIC
13560 + || sb->s_magic == MINIX2_SUPER_MAGIC
13561 + || sb->s_magic == MINIX2_SUPER_MAGIC2
13562 + || sb->s_magic == MINIX_SUPER_MAGIC
13563 + || sb->s_magic == MINIX_SUPER_MAGIC2;
13569 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
13571 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
13572 + return sb->s_magic == CIFS_MAGIC_NUMBER;
13578 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
13580 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
13581 + return sb->s_magic == MSDOS_SUPER_MAGIC;
13587 +static inline int au_test_msdos(struct super_block *sb)
13589 + return au_test_fat(sb);
13592 +static inline int au_test_vfat(struct super_block *sb)
13594 + return au_test_fat(sb);
13597 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
13599 +#ifdef CONFIG_SECURITYFS
13600 + return sb->s_magic == SECURITYFS_MAGIC;
13606 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
13608 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
13609 + return sb->s_magic == SQUASHFS_MAGIC;
13615 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
13617 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
13618 + return sb->s_magic == BTRFS_SUPER_MAGIC;
13624 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
13626 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
13627 + return sb->s_magic == XENFS_SUPER_MAGIC;
13633 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
13635 +#ifdef CONFIG_DEBUG_FS
13636 + return sb->s_magic == DEBUGFS_MAGIC;
13642 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
13644 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
13645 + return sb->s_magic == NILFS_SUPER_MAGIC;
13651 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
13653 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
13654 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
13660 +/* ---------------------------------------------------------------------- */
13662 + * they can't be an aufs branch.
13664 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
13667 +#ifndef CONFIG_AUFS_BR_RAMFS
13668 + au_test_ramfs(sb) ||
13670 + au_test_procfs(sb)
13671 + || au_test_sysfs(sb)
13672 + || au_test_configfs(sb)
13673 + || au_test_debugfs(sb)
13674 + || au_test_securityfs(sb)
13675 + || au_test_xenfs(sb)
13676 + || au_test_ecryptfs(sb)
13677 + /* || !strcmp(au_sbtype(sb), "unionfs") */
13678 + || au_test_aufs(sb); /* will be supported in next version */
13681 +static inline int au_test_fs_remote(struct super_block *sb)
13683 + return !au_test_tmpfs(sb)
13684 +#ifdef CONFIG_AUFS_BR_RAMFS
13685 + && !au_test_ramfs(sb)
13687 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
13690 +/* ---------------------------------------------------------------------- */
13693 + * Note: these functions (below) are created after reading ->getattr() in all
13694 + * filesystems under linux/fs. it means we have to do so in every update...
13698 + * some filesystems require getattr to refresh the inode attributes before
13700 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
13701 + * and leave the work for d_revalidate()
13703 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
13705 + return au_test_nfs(sb)
13706 + || au_test_fuse(sb)
13707 + /* || au_test_ocfs2(sb) */ /* untested */
13708 + /* || au_test_btrfs(sb) */ /* untested */
13709 + /* || au_test_coda(sb) */ /* untested */
13710 + /* || au_test_v9fs(sb) */ /* untested */
13715 + * filesystems which don't maintain i_size or i_blocks.
13717 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
13719 + return au_test_xfs(sb)
13720 + || au_test_btrfs(sb)
13721 + || au_test_ubifs(sb)
13722 + || au_test_hfsplus(sb) /* maintained, but incorrect */
13723 + /* || au_test_ext4(sb) */ /* untested */
13724 + /* || au_test_ocfs2(sb) */ /* untested */
13725 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
13726 + /* || au_test_sysv(sb) */ /* untested */
13727 + /* || au_test_minix(sb) */ /* untested */
13732 + * filesystems which don't store the correct value in some of their inode
13735 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
13737 + return au_test_fs_bad_iattr_size(sb)
13738 + /* || au_test_cifs(sb) */ /* untested */
13739 + || au_test_fat(sb)
13740 + || au_test_msdos(sb)
13741 + || au_test_vfat(sb);
13744 +/* they don't check i_nlink in link(2) */
13745 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
13747 + return au_test_tmpfs(sb)
13748 +#ifdef CONFIG_AUFS_BR_RAMFS
13749 + || au_test_ramfs(sb)
13751 + || au_test_ubifs(sb)
13752 + || au_test_hfsplus(sb);
13756 + * filesystems which sets S_NOATIME and S_NOCMTIME.
13758 +static inline int au_test_fs_notime(struct super_block *sb)
13760 + return au_test_nfs(sb)
13761 + || au_test_fuse(sb)
13762 + || au_test_ubifs(sb)
13763 + /* || au_test_cifs(sb) */ /* untested */
13768 + * filesystems which requires replacing i_mapping.
13770 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
13772 + return au_test_fuse(sb)
13773 + || au_test_ubifs(sb);
13776 +/* temporary support for i#1 in cramfs */
13777 +static inline int au_test_fs_unique_ino(struct inode *inode)
13779 + if (au_test_cramfs(inode->i_sb))
13780 + return inode->i_ino != 1;
13784 +/* ---------------------------------------------------------------------- */
13787 + * the filesystem where the xino files placed must support i/o after unlink and
13788 + * maintain i_size and i_blocks.
13790 +static inline int au_test_fs_bad_xino(struct super_block *sb)
13792 + return au_test_fs_remote(sb)
13793 + || au_test_fs_bad_iattr_size(sb)
13794 + /* don't want unnecessary work for xino */
13795 + || au_test_aufs(sb)
13796 + || au_test_ecryptfs(sb)
13797 + || au_test_nilfs(sb);
13800 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
13802 + return au_test_tmpfs(sb)
13803 + || au_test_ramfs(sb);
13807 + * test if the @sb is real-readonly.
13809 +static inline int au_test_fs_rr(struct super_block *sb)
13811 + return au_test_squashfs(sb)
13812 + || au_test_iso9660(sb)
13813 + || au_test_cramfs(sb)
13814 + || au_test_romfs(sb);
13817 +#endif /* __KERNEL__ */
13818 +#endif /* __AUFS_FSTYPE_H__ */
13819 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
13820 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
13821 +++ linux/fs/aufs/hfsnotify.c 2014-04-24 22:11:10.851935747 +0200
13824 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13826 + * This program, aufs is free software; you can redistribute it and/or modify
13827 + * it under the terms of the GNU General Public License as published by
13828 + * the Free Software Foundation; either version 2 of the License, or
13829 + * (at your option) any later version.
13831 + * This program is distributed in the hope that it will be useful,
13832 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13833 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13834 + * GNU General Public License for more details.
13836 + * You should have received a copy of the GNU General Public License
13837 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13841 + * fsnotify for the lower directories
13846 +/* FS_IN_IGNORED is unnecessary */
13847 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
13848 + | FS_CREATE | FS_EVENT_ON_CHILD);
13849 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
13850 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
13852 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
13854 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
13857 + au_cache_free_hnotify(hn);
13858 + smp_mb__before_atomic_dec();
13859 + if (atomic64_dec_and_test(&au_hfsn_ifree))
13860 + wake_up(&au_hfsn_wq);
13863 +static int au_hfsn_alloc(struct au_hinode *hinode)
13866 + struct au_hnotify *hn;
13867 + struct super_block *sb;
13868 + struct au_branch *br;
13869 + struct fsnotify_mark *mark;
13870 + aufs_bindex_t bindex;
13872 + hn = hinode->hi_notify;
13873 + sb = hn->hn_aufs_inode->i_sb;
13874 + bindex = au_br_index(sb, hinode->hi_id);
13875 + br = au_sbr(sb, bindex);
13876 + AuDebugOn(!br->br_hfsn);
13878 + mark = &hn->hn_mark;
13879 + fsnotify_init_mark(mark, au_hfsn_free_mark);
13880 + mark->mask = AuHfsnMask;
13882 + * by udba rename or rmdir, aufs assign a new inode to the known
13883 + * h_inode, so specify 1 to allow dups.
13885 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
13886 + /*mnt*/NULL, /*allow_dups*/1);
13887 + /* even if err */
13888 + fsnotify_put_mark(mark);
13893 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
13895 + struct fsnotify_mark *mark;
13896 + unsigned long long ull;
13897 + struct fsnotify_group *group;
13899 + ull = atomic64_inc_return(&au_hfsn_ifree);
13902 + mark = &hn->hn_mark;
13903 + spin_lock(&mark->lock);
13904 + group = mark->group;
13905 + fsnotify_get_group(group);
13906 + spin_unlock(&mark->lock);
13907 + fsnotify_destroy_mark(mark, group);
13908 + fsnotify_put_group(group);
13910 + /* free hn by myself */
13914 +/* ---------------------------------------------------------------------- */
13916 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
13918 + struct fsnotify_mark *mark;
13920 + mark = &hinode->hi_notify->hn_mark;
13921 + spin_lock(&mark->lock);
13923 + AuDebugOn(mark->mask & AuHfsnMask);
13924 + mark->mask |= AuHfsnMask;
13926 + AuDebugOn(!(mark->mask & AuHfsnMask));
13927 + mark->mask &= ~AuHfsnMask;
13929 + spin_unlock(&mark->lock);
13930 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
13933 +/* ---------------------------------------------------------------------- */
13935 +/* #define AuDbgHnotify */
13936 +#ifdef AuDbgHnotify
13937 +static char *au_hfsn_name(u32 mask)
13939 +#ifdef CONFIG_AUFS_DEBUG
13940 +#define test_ret(flag) \
13942 + if (mask & flag) \
13945 + test_ret(FS_ACCESS);
13946 + test_ret(FS_MODIFY);
13947 + test_ret(FS_ATTRIB);
13948 + test_ret(FS_CLOSE_WRITE);
13949 + test_ret(FS_CLOSE_NOWRITE);
13950 + test_ret(FS_OPEN);
13951 + test_ret(FS_MOVED_FROM);
13952 + test_ret(FS_MOVED_TO);
13953 + test_ret(FS_CREATE);
13954 + test_ret(FS_DELETE);
13955 + test_ret(FS_DELETE_SELF);
13956 + test_ret(FS_MOVE_SELF);
13957 + test_ret(FS_UNMOUNT);
13958 + test_ret(FS_Q_OVERFLOW);
13959 + test_ret(FS_IN_IGNORED);
13960 + test_ret(FS_IN_ISDIR);
13961 + test_ret(FS_IN_ONESHOT);
13962 + test_ret(FS_EVENT_ON_CHILD);
13971 +/* ---------------------------------------------------------------------- */
13973 +static void au_hfsn_free_group(struct fsnotify_group *group)
13975 + struct au_br_hfsnotify *hfsn = group->private;
13981 +static int au_hfsn_handle_event(struct fsnotify_group *group,
13982 + struct inode *inode,
13983 + struct fsnotify_mark *inode_mark,
13984 + struct fsnotify_mark *vfsmount_mark,
13985 + u32 mask, void *data, int data_type,
13986 + const unsigned char *file_name, u32 cookie)
13989 + struct au_hnotify *hnotify;
13990 + struct inode *h_dir, *h_inode;
13991 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
13993 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
13996 + /* if FS_UNMOUNT happens, there must be another bug */
13997 + AuDebugOn(mask & FS_UNMOUNT);
13998 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14003 +#ifdef AuDbgHnotify
14005 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14006 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14007 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14008 + h_dir->i_ino, mask, au_hfsn_name(mask),
14009 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14010 + /* WARN_ON(1); */
14015 + AuDebugOn(!inode_mark);
14016 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14017 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14023 +static struct fsnotify_ops au_hfsn_ops = {
14024 + .handle_event = au_hfsn_handle_event,
14025 + .free_group_priv = au_hfsn_free_group
14028 +/* ---------------------------------------------------------------------- */
14030 +static void au_hfsn_fin_br(struct au_branch *br)
14032 + struct au_br_hfsnotify *hfsn;
14034 + hfsn = br->br_hfsn;
14036 + fsnotify_put_group(hfsn->hfsn_group);
14039 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14042 + struct fsnotify_group *group;
14043 + struct au_br_hfsnotify *hfsn;
14046 + br->br_hfsn = NULL;
14047 + if (!au_br_hnotifyable(perm))
14051 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14052 + if (unlikely(!hfsn))
14056 + group = fsnotify_alloc_group(&au_hfsn_ops);
14057 + if (IS_ERR(group)) {
14058 + err = PTR_ERR(group);
14059 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14063 + group->private = hfsn;
14064 + hfsn->hfsn_group = group;
14065 + br->br_hfsn = hfsn;
14066 + goto out; /* success */
14074 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14079 + if (!br->br_hfsn)
14080 + err = au_hfsn_init_br(br, perm);
14085 +/* ---------------------------------------------------------------------- */
14087 +static void au_hfsn_fin(void)
14089 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14090 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14093 +const struct au_hnotify_op au_hnotify_op = {
14094 + .ctl = au_hfsn_ctl,
14095 + .alloc = au_hfsn_alloc,
14096 + .free = au_hfsn_free,
14098 + .fin = au_hfsn_fin,
14100 + .reset_br = au_hfsn_reset_br,
14101 + .fin_br = au_hfsn_fin_br,
14102 + .init_br = au_hfsn_init_br
14104 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14105 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14106 +++ linux/fs/aufs/hfsplus.c 2014-04-24 22:11:10.851935747 +0200
14109 + * Copyright (C) 2010-2014 Junjiro R. Okajima
14111 + * This program, aufs is free software; you can redistribute it and/or modify
14112 + * it under the terms of the GNU General Public License as published by
14113 + * the Free Software Foundation; either version 2 of the License, or
14114 + * (at your option) any later version.
14116 + * This program is distributed in the hope that it will be useful,
14117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14119 + * GNU General Public License for more details.
14121 + * You should have received a copy of the GNU General Public License
14122 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14126 + * special support for filesystems which aqucires an inode mutex
14127 + * at final closing a file, eg, hfsplus.
14129 + * This trick is very simple and stupid, just to open the file before really
14130 + * neceeary open to tell hfsplus that this is not the final closing.
14131 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14132 + * and au_h_open_post() after releasing it.
14137 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14140 + struct file *h_file;
14141 + struct dentry *h_dentry;
14143 + h_dentry = au_h_dptr(dentry, bindex);
14144 + AuDebugOn(!h_dentry);
14145 + AuDebugOn(!h_dentry->d_inode);
14148 + if (au_test_hfsplus(h_dentry->d_sb)
14149 + && S_ISREG(h_dentry->d_inode->i_mode))
14150 + h_file = au_h_open(dentry, bindex,
14151 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14152 + /*file*/NULL, force_wr);
14156 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14157 + struct file *h_file)
14161 + au_sbr_put(dentry->d_sb, bindex);
14164 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14165 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14166 +++ linux/fs/aufs/hnotify.c 2014-04-24 22:11:10.851935747 +0200
14169 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14171 + * This program, aufs is free software; you can redistribute it and/or modify
14172 + * it under the terms of the GNU General Public License as published by
14173 + * the Free Software Foundation; either version 2 of the License, or
14174 + * (at your option) any later version.
14176 + * This program is distributed in the hope that it will be useful,
14177 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14178 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14179 + * GNU General Public License for more details.
14181 + * You should have received a copy of the GNU General Public License
14182 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14186 + * abstraction to notify the direct changes on lower directories
14191 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14194 + struct au_hnotify *hn;
14197 + hn = au_cache_alloc_hnotify();
14199 + hn->hn_aufs_inode = inode;
14200 + hinode->hi_notify = hn;
14201 + err = au_hnotify_op.alloc(hinode);
14203 + if (unlikely(err)) {
14204 + hinode->hi_notify = NULL;
14205 + au_cache_free_hnotify(hn);
14207 + * The upper dir was removed by udba, but the same named
14208 + * dir left. In this case, aufs assignes a new inode
14209 + * number and set the monitor again.
14210 + * For the lower dir, the old monitnor is still left.
14212 + if (err == -EEXIST)
14221 +void au_hn_free(struct au_hinode *hinode)
14223 + struct au_hnotify *hn;
14225 + hn = hinode->hi_notify;
14227 + hinode->hi_notify = NULL;
14228 + if (au_hnotify_op.free(hinode, hn))
14229 + au_cache_free_hnotify(hn);
14233 +/* ---------------------------------------------------------------------- */
14235 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14237 + if (hinode->hi_notify)
14238 + au_hnotify_op.ctl(hinode, do_set);
14241 +void au_hn_reset(struct inode *inode, unsigned int flags)
14243 + aufs_bindex_t bindex, bend;
14244 + struct inode *hi;
14245 + struct dentry *iwhdentry;
14247 + bend = au_ibend(inode);
14248 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14249 + hi = au_h_iptr(inode, bindex);
14253 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14254 + iwhdentry = au_hi_wh(inode, bindex);
14258 + au_set_h_iptr(inode, bindex, NULL, 0);
14259 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14260 + flags & ~AuHi_XINO);
14263 + /* mutex_unlock(&hi->i_mutex); */
14267 +/* ---------------------------------------------------------------------- */
14269 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14272 + aufs_bindex_t bindex, bend, bfound, bstart;
14273 + struct inode *h_i;
14276 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14277 + pr_warn("branch root dir was changed\n");
14282 + bend = au_ibend(inode);
14283 + bstart = au_ibstart(inode);
14284 +#if 0 /* reserved for future use */
14285 + if (bindex == bend) {
14286 + /* keep this ino in rename case */
14290 + for (bindex = bstart; bindex <= bend; bindex++)
14291 + if (au_h_iptr(inode, bindex) == h_inode) {
14298 + for (bindex = bstart; bindex <= bend; bindex++) {
14299 + h_i = au_h_iptr(inode, bindex);
14303 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14304 + /* ignore this error */
14305 + /* bad action? */
14308 + /* children inode number will be broken */
14315 +static int hn_gen_tree(struct dentry *dentry)
14317 + int err, i, j, ndentry;
14318 + struct au_dcsub_pages dpages;
14319 + struct au_dpage *dpage;
14320 + struct dentry **dentries;
14322 + err = au_dpages_init(&dpages, GFP_NOFS);
14323 + if (unlikely(err))
14325 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14326 + if (unlikely(err))
14329 + for (i = 0; i < dpages.ndpage; i++) {
14330 + dpage = dpages.dpages + i;
14331 + dentries = dpage->dentries;
14332 + ndentry = dpage->ndentry;
14333 + for (j = 0; j < ndentry; j++) {
14334 + struct dentry *d;
14342 + /* todo: reset children xino?
14343 + cached children only? */
14344 + au_iigen_dec(d->d_inode);
14349 + au_dpages_free(&dpages);
14352 + /* discard children */
14353 + dentry_unhash(dentry);
14361 + * return 0 if processed.
14363 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14364 + const unsigned int isdir)
14367 + struct dentry *d;
14368 + struct qstr *dname;
14371 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14372 + pr_warn("branch root dir was changed\n");
14378 + AuDebugOn(!name);
14379 + au_iigen_dec(inode);
14380 + spin_lock(&inode->i_lock);
14381 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
14382 + spin_lock(&d->d_lock);
14383 + dname = &d->d_name;
14384 + if (dname->len != nlen
14385 + && memcmp(dname->name, name, nlen)) {
14386 + spin_unlock(&d->d_lock);
14391 + spin_unlock(&d->d_lock);
14394 + spin_unlock(&inode->i_lock);
14396 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14397 + d = d_find_alias(inode);
14399 + au_iigen_dec(inode);
14403 + spin_lock(&d->d_lock);
14404 + dname = &d->d_name;
14405 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14406 + spin_unlock(&d->d_lock);
14407 + err = hn_gen_tree(d);
14408 + spin_lock(&d->d_lock);
14410 + spin_unlock(&d->d_lock);
14419 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
14422 + struct inode *inode;
14424 + inode = dentry->d_inode;
14425 + if (IS_ROOT(dentry)
14426 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
14428 + pr_warn("branch root dir was changed\n");
14434 + au_digen_dec(dentry);
14436 + au_iigen_dec(inode);
14438 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
14440 + err = hn_gen_tree(dentry);
14447 +/* ---------------------------------------------------------------------- */
14449 +/* hnotify job flags */
14450 +#define AuHnJob_XINO0 1
14451 +#define AuHnJob_GEN (1 << 1)
14452 +#define AuHnJob_DIRENT (1 << 2)
14453 +#define AuHnJob_ISDIR (1 << 3)
14454 +#define AuHnJob_TRYXINO0 (1 << 4)
14455 +#define AuHnJob_MNTPNT (1 << 5)
14456 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
14457 +#define au_fset_hnjob(flags, name) \
14458 + do { (flags) |= AuHnJob_##name; } while (0)
14459 +#define au_fclr_hnjob(flags, name) \
14460 + do { (flags) &= ~AuHnJob_##name; } while (0)
14468 +struct au_hnotify_args {
14469 + struct inode *h_dir, *dir, *h_child_inode;
14471 + unsigned int flags[AuHnLast];
14472 + unsigned int h_child_nlen;
14473 + char h_child_name[];
14476 +struct hn_job_args {
14477 + unsigned int flags;
14478 + struct inode *inode, *h_inode, *dir, *h_dir;
14479 + struct dentry *dentry;
14484 +static int hn_job(struct hn_job_args *a)
14486 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
14489 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
14490 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14492 + if (au_ftest_hnjob(a->flags, TRYXINO0)
14495 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
14496 + if (!a->h_inode->i_nlink)
14497 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14498 + mutex_unlock(&a->h_inode->i_mutex);
14501 + /* make the generation obsolete */
14502 + if (au_ftest_hnjob(a->flags, GEN)) {
14505 + err = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
14507 + if (err && a->dentry)
14508 + hn_gen_by_name(a->dentry, isdir);
14509 + /* ignore this error */
14512 + /* make dir entries obsolete */
14513 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
14514 + struct au_vdir *vdir;
14516 + vdir = au_ivdir(a->inode);
14518 + vdir->vd_jiffy = 0;
14519 + /* IMustLock(a->inode); */
14520 + /* a->inode->i_version++; */
14523 + /* can do nothing but warn */
14524 + if (au_ftest_hnjob(a->flags, MNTPNT)
14526 + && d_mountpoint(a->dentry))
14527 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
14532 +/* ---------------------------------------------------------------------- */
14534 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
14535 + struct inode *dir)
14537 + struct dentry *dentry, *d, *parent;
14538 + struct qstr *dname;
14540 + parent = d_find_alias(dir);
14545 + spin_lock(&parent->d_lock);
14546 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
14547 + /* AuDbg("%pd\n", d); */
14548 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
14549 + dname = &d->d_name;
14550 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
14551 + goto cont_unlock;
14555 + goto cont_unlock;
14556 + if (d_count(d)) {
14557 + dentry = dget_dlock(d);
14558 + spin_unlock(&d->d_lock);
14563 + spin_unlock(&d->d_lock);
14565 + spin_unlock(&parent->d_lock);
14569 + di_write_lock_child(dentry);
14574 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
14575 + aufs_bindex_t bindex, ino_t h_ino)
14577 + struct inode *inode;
14582 + err = au_xino_read(sb, bindex, h_ino, &ino);
14584 + inode = ilookup(sb, ino);
14588 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14589 + pr_warn("wrong root branch\n");
14595 + ii_write_lock_child(inode);
14601 +static void au_hn_bh(void *_args)
14603 + struct au_hnotify_args *a = _args;
14604 + struct super_block *sb;
14605 + aufs_bindex_t bindex, bend, bfound;
14606 + unsigned char xino, try_iput;
14608 + struct inode *inode;
14610 + struct hn_job_args args;
14611 + struct dentry *dentry;
14612 + struct au_sbinfo *sbinfo;
14614 + AuDebugOn(!_args);
14615 + AuDebugOn(!a->h_dir);
14616 + AuDebugOn(!a->dir);
14617 + AuDebugOn(!a->mask);
14618 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
14619 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
14620 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
14625 + * do not lock a->dir->i_mutex here
14626 + * because of d_revalidate() may cause a deadlock.
14628 + sb = a->dir->i_sb;
14630 + sbinfo = au_sbi(sb);
14631 + AuDebugOn(!sbinfo);
14632 + si_write_lock(sb, AuLock_NOPLMW);
14634 + ii_read_lock_parent(a->dir);
14636 + bend = au_ibend(a->dir);
14637 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
14638 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
14642 + ii_read_unlock(a->dir);
14643 + if (unlikely(bfound < 0))
14646 + xino = !!au_opt_test(au_mntflags(sb), XINO);
14648 + if (a->h_child_inode)
14649 + h_ino = a->h_child_inode->i_ino;
14651 + if (a->h_child_nlen
14652 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
14653 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
14654 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
14658 + inode = dentry->d_inode;
14659 + if (xino && !inode && h_ino
14660 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
14661 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
14662 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
14663 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
14667 + args.flags = a->flags[AuHn_CHILD];
14668 + args.dentry = dentry;
14669 + args.inode = inode;
14670 + args.h_inode = a->h_child_inode;
14671 + args.dir = a->dir;
14672 + args.h_dir = a->h_dir;
14673 + args.h_name = a->h_child_name;
14674 + args.h_nlen = a->h_child_nlen;
14675 + err = hn_job(&args);
14677 + if (au_di(dentry))
14678 + di_write_unlock(dentry);
14681 + if (inode && try_iput) {
14682 + ii_write_unlock(inode);
14686 + ii_write_lock_parent(a->dir);
14687 + args.flags = a->flags[AuHn_PARENT];
14688 + args.dentry = NULL;
14689 + args.inode = a->dir;
14690 + args.h_inode = a->h_dir;
14692 + args.h_dir = NULL;
14693 + args.h_name = NULL;
14695 + err = hn_job(&args);
14696 + ii_write_unlock(a->dir);
14699 + iput(a->h_child_inode);
14702 + si_write_unlock(sb);
14703 + au_nwt_done(&sbinfo->si_nowait);
14707 +/* ---------------------------------------------------------------------- */
14709 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
14710 + struct qstr *h_child_qstr, struct inode *h_child_inode)
14713 + unsigned int flags[AuHnLast], f;
14714 + unsigned char isdir, isroot, wh;
14715 + struct inode *dir;
14716 + struct au_hnotify_args *args;
14717 + char *p, *h_child_name;
14720 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
14721 + dir = igrab(hnotify->hn_aufs_inode);
14725 + isroot = (dir->i_ino == AUFS_ROOT_INO);
14727 + h_child_name = (void *)h_child_qstr->name;
14728 + len = h_child_qstr->len;
14729 + if (h_child_name) {
14730 + if (len > AUFS_WH_PFX_LEN
14731 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
14732 + h_child_name += AUFS_WH_PFX_LEN;
14733 + len -= AUFS_WH_PFX_LEN;
14739 + if (h_child_inode)
14740 + isdir = !!S_ISDIR(h_child_inode->i_mode);
14741 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
14742 + flags[AuHn_CHILD] = 0;
14744 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
14745 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
14746 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
14747 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
14748 + case FS_MOVED_FROM:
14749 + case FS_MOVED_TO:
14750 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
14751 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14754 + AuDebugOn(!h_child_name);
14759 + * aufs never be able to get this child inode.
14760 + * revalidation should be in d_revalidate()
14761 + * by checking i_nlink, i_generation or d_unhashed().
14763 + AuDebugOn(!h_child_name);
14764 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
14765 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14773 + h_child_inode = NULL;
14776 + /* iput() and kfree() will be called in au_hnotify() */
14777 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
14778 + if (unlikely(!args)) {
14779 + AuErr1("no memory\n");
14783 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
14784 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
14785 + args->mask = mask;
14787 + args->h_dir = igrab(h_dir);
14788 + if (h_child_inode)
14789 + h_child_inode = igrab(h_child_inode); /* can be NULL */
14790 + args->h_child_inode = h_child_inode;
14791 + args->h_child_nlen = len;
14793 + p = (void *)args;
14794 + p += sizeof(*args);
14795 + memcpy(p, h_child_name, len);
14800 + if (!dir->i_nlink)
14802 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
14803 + if (unlikely(err)) {
14804 + pr_err("wkq %d\n", err);
14805 + iput(args->h_child_inode);
14806 + iput(args->h_dir);
14815 +/* ---------------------------------------------------------------------- */
14817 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
14821 + AuDebugOn(!(udba & AuOptMask_UDBA));
14824 + if (au_hnotify_op.reset_br)
14825 + err = au_hnotify_op.reset_br(udba, br, perm);
14830 +int au_hnotify_init_br(struct au_branch *br, int perm)
14835 + if (au_hnotify_op.init_br)
14836 + err = au_hnotify_op.init_br(br, perm);
14841 +void au_hnotify_fin_br(struct au_branch *br)
14843 + if (au_hnotify_op.fin_br)
14844 + au_hnotify_op.fin_br(br);
14847 +static void au_hn_destroy_cache(void)
14849 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
14850 + au_cachep[AuCache_HNOTIFY] = NULL;
14853 +int __init au_hnotify_init(void)
14858 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
14859 + if (au_cachep[AuCache_HNOTIFY]) {
14861 + if (au_hnotify_op.init)
14862 + err = au_hnotify_op.init();
14863 + if (unlikely(err))
14864 + au_hn_destroy_cache();
14870 +void au_hnotify_fin(void)
14872 + if (au_hnotify_op.fin)
14873 + au_hnotify_op.fin();
14874 + /* cf. au_cache_fin() */
14875 + if (au_cachep[AuCache_HNOTIFY])
14876 + au_hn_destroy_cache();
14878 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
14879 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
14880 +++ linux/fs/aufs/iinfo.c 2014-04-24 22:11:10.855269116 +0200
14883 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14885 + * This program, aufs is free software; you can redistribute it and/or modify
14886 + * it under the terms of the GNU General Public License as published by
14887 + * the Free Software Foundation; either version 2 of the License, or
14888 + * (at your option) any later version.
14890 + * This program is distributed in the hope that it will be useful,
14891 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14892 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14893 + * GNU General Public License for more details.
14895 + * You should have received a copy of the GNU General Public License
14896 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14900 + * inode private data
14905 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
14907 + struct inode *h_inode;
14909 + IiMustAnyLock(inode);
14911 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
14912 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14916 +/* todo: hard/soft set? */
14917 +void au_hiput(struct au_hinode *hinode)
14919 + au_hn_free(hinode);
14920 + dput(hinode->hi_whdentry);
14921 + iput(hinode->hi_inode);
14924 +unsigned int au_hi_flags(struct inode *inode, int isdir)
14926 + unsigned int flags;
14927 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
14930 + if (au_opt_test(mnt_flags, XINO))
14931 + au_fset_hi(flags, XINO);
14932 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
14933 + au_fset_hi(flags, HNOTIFY);
14937 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
14938 + struct inode *h_inode, unsigned int flags)
14940 + struct au_hinode *hinode;
14941 + struct inode *hi;
14942 + struct au_iinfo *iinfo = au_ii(inode);
14944 + IiMustWriteLock(inode);
14946 + hinode = iinfo->ii_hinode + bindex;
14947 + hi = hinode->hi_inode;
14948 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
14951 + au_hiput(hinode);
14952 + hinode->hi_inode = h_inode;
14955 + struct super_block *sb = inode->i_sb;
14956 + struct au_branch *br;
14958 + AuDebugOn(inode->i_mode
14959 + && (h_inode->i_mode & S_IFMT)
14960 + != (inode->i_mode & S_IFMT));
14961 + if (bindex == iinfo->ii_bstart)
14962 + au_cpup_igen(inode, h_inode);
14963 + br = au_sbr(sb, bindex);
14964 + hinode->hi_id = br->br_id;
14965 + if (au_ftest_hi(flags, XINO)) {
14966 + err = au_xino_write(sb, bindex, h_inode->i_ino,
14968 + if (unlikely(err))
14969 + AuIOErr1("failed au_xino_write() %d\n", err);
14972 + if (au_ftest_hi(flags, HNOTIFY)
14973 + && au_br_hnotifyable(br->br_perm)) {
14974 + err = au_hn_alloc(hinode, inode);
14975 + if (unlikely(err))
14976 + AuIOErr1("au_hn_alloc() %d\n", err);
14981 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
14982 + struct dentry *h_wh)
14984 + struct au_hinode *hinode;
14986 + IiMustWriteLock(inode);
14988 + hinode = au_ii(inode)->ii_hinode + bindex;
14989 + AuDebugOn(hinode->hi_whdentry);
14990 + hinode->hi_whdentry = h_wh;
14993 +void au_update_iigen(struct inode *inode, int half)
14995 + struct au_iinfo *iinfo;
14996 + struct au_iigen *iigen;
14997 + unsigned int sigen;
14999 + sigen = au_sigen(inode->i_sb);
15000 + iinfo = au_ii(inode);
15001 + iigen = &iinfo->ii_generation;
15002 + spin_lock(&iinfo->ii_genspin);
15003 + iigen->ig_generation = sigen;
15005 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15007 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15008 + spin_unlock(&iinfo->ii_genspin);
15011 +/* it may be called at remount time, too */
15012 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15014 + struct au_iinfo *iinfo;
15015 + aufs_bindex_t bindex, bend;
15017 + iinfo = au_ii(inode);
15021 + IiMustWriteLock(inode);
15023 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15024 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15026 + struct inode *h_i;
15028 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15029 + if (h_i && !h_i->i_nlink)
15030 + au_set_h_iptr(inode, bindex, NULL, 0);
15034 + iinfo->ii_bstart = -1;
15035 + iinfo->ii_bend = -1;
15036 + bend = au_sbend(inode->i_sb);
15037 + for (bindex = 0; bindex <= bend; bindex++)
15038 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15039 + iinfo->ii_bstart = bindex;
15042 + if (iinfo->ii_bstart >= 0)
15043 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15044 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15045 + iinfo->ii_bend = bindex;
15048 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15051 +/* ---------------------------------------------------------------------- */
15053 +void au_icntnr_init_once(void *_c)
15055 + struct au_icntnr *c = _c;
15056 + struct au_iinfo *iinfo = &c->iinfo;
15057 + static struct lock_class_key aufs_ii;
15059 + spin_lock_init(&iinfo->ii_genspin);
15060 + au_rw_init(&iinfo->ii_rwsem);
15061 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15062 + inode_init_once(&c->vfs_inode);
15065 +int au_iinfo_init(struct inode *inode)
15067 + struct au_iinfo *iinfo;
15068 + struct super_block *sb;
15071 + sb = inode->i_sb;
15072 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15073 + nbr = au_sbend(sb) + 1;
15074 + if (unlikely(nbr <= 0))
15076 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15077 + if (iinfo->ii_hinode) {
15078 + au_ninodes_inc(sb);
15079 + for (i = 0; i < nbr; i++)
15080 + iinfo->ii_hinode[i].hi_id = -1;
15082 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15083 + iinfo->ii_bstart = -1;
15084 + iinfo->ii_bend = -1;
15085 + iinfo->ii_vdir = NULL;
15091 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15094 + struct au_hinode *hip;
15096 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15099 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15101 + sz = sizeof(*hip);
15102 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15104 + iinfo->ii_hinode = hip;
15111 +void au_iinfo_fin(struct inode *inode)
15113 + struct au_iinfo *iinfo;
15114 + struct au_hinode *hi;
15115 + struct super_block *sb;
15116 + aufs_bindex_t bindex, bend;
15117 + const unsigned char unlinked = !inode->i_nlink;
15119 + iinfo = au_ii(inode);
15120 + /* bad_inode case */
15124 + sb = inode->i_sb;
15125 + au_ninodes_dec(sb);
15126 + if (si_pid_test(sb))
15127 + au_xino_delete_inode(inode, unlinked);
15130 + * it is safe to hide the dependency between sbinfo and
15134 + si_noflush_read_lock(sb);
15135 + au_xino_delete_inode(inode, unlinked);
15136 + si_read_unlock(sb);
15140 + if (iinfo->ii_vdir)
15141 + au_vdir_free(iinfo->ii_vdir);
15143 + bindex = iinfo->ii_bstart;
15144 + if (bindex >= 0) {
15145 + hi = iinfo->ii_hinode + bindex;
15146 + bend = iinfo->ii_bend;
15147 + while (bindex++ <= bend) {
15148 + if (hi->hi_inode)
15153 + kfree(iinfo->ii_hinode);
15154 + iinfo->ii_hinode = NULL;
15155 + AuRwDestroy(&iinfo->ii_rwsem);
15157 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15158 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15159 +++ linux/fs/aufs/inode.c 2014-04-24 22:11:10.855269116 +0200
15162 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15164 + * This program, aufs is free software; you can redistribute it and/or modify
15165 + * it under the terms of the GNU General Public License as published by
15166 + * the Free Software Foundation; either version 2 of the License, or
15167 + * (at your option) any later version.
15169 + * This program is distributed in the hope that it will be useful,
15170 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15171 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15172 + * GNU General Public License for more details.
15174 + * You should have received a copy of the GNU General Public License
15175 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15179 + * inode functions
15184 +struct inode *au_igrab(struct inode *inode)
15187 + AuDebugOn(!atomic_read(&inode->i_count));
15193 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15195 + au_cpup_attr_all(inode, /*force*/0);
15196 + au_update_iigen(inode, /*half*/1);
15198 + inode->i_version++;
15201 +static int au_ii_refresh(struct inode *inode, int *update)
15205 + aufs_bindex_t bindex, new_bindex;
15206 + struct super_block *sb;
15207 + struct au_iinfo *iinfo;
15208 + struct au_hinode *p, *q, tmp;
15210 + IiMustWriteLock(inode);
15213 + sb = inode->i_sb;
15214 + type = inode->i_mode & S_IFMT;
15215 + iinfo = au_ii(inode);
15216 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15217 + if (unlikely(err))
15220 + AuDebugOn(iinfo->ii_bstart < 0);
15221 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15222 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15224 + if (!p->hi_inode)
15227 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15228 + new_bindex = au_br_index(sb, p->hi_id);
15229 + if (new_bindex == bindex)
15232 + if (new_bindex < 0) {
15235 + p->hi_inode = NULL;
15239 + if (new_bindex < iinfo->ii_bstart)
15240 + iinfo->ii_bstart = new_bindex;
15241 + if (iinfo->ii_bend < new_bindex)
15242 + iinfo->ii_bend = new_bindex;
15243 + /* swap two lower inode, and loop again */
15244 + q = iinfo->ii_hinode + new_bindex;
15248 + if (tmp.hi_inode) {
15253 + au_update_ibrange(inode, /*do_put_zero*/0);
15254 + e = au_dy_irefresh(inode);
15255 + if (unlikely(e && !err))
15263 +int au_refresh_hinode_self(struct inode *inode)
15267 + err = au_ii_refresh(inode, &update);
15269 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
15275 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
15277 + int err, e, update;
15278 + unsigned int flags;
15280 + aufs_bindex_t bindex, bend;
15281 + unsigned char isdir;
15282 + struct au_hinode *p;
15283 + struct au_iinfo *iinfo;
15285 + err = au_ii_refresh(inode, &update);
15286 + if (unlikely(err))
15290 + iinfo = au_ii(inode);
15291 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15292 + mode = (inode->i_mode & S_IFMT);
15293 + isdir = S_ISDIR(mode);
15294 + flags = au_hi_flags(inode, isdir);
15295 + bend = au_dbend(dentry);
15296 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15297 + struct inode *h_i;
15298 + struct dentry *h_d;
15300 + h_d = au_h_dptr(dentry, bindex);
15301 + if (!h_d || !h_d->d_inode)
15304 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
15305 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15306 + h_i = au_h_iptr(inode, bindex);
15308 + if (h_i == h_d->d_inode)
15314 + if (bindex < iinfo->ii_bstart)
15315 + iinfo->ii_bstart = bindex;
15316 + if (iinfo->ii_bend < bindex)
15317 + iinfo->ii_bend = bindex;
15318 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
15321 + au_update_ibrange(inode, /*do_put_zero*/0);
15322 + e = au_dy_irefresh(inode);
15323 + if (unlikely(e && !err))
15326 + au_refresh_hinode_attr(inode, update && isdir);
15333 +static int set_inode(struct inode *inode, struct dentry *dentry)
15336 + unsigned int flags;
15338 + aufs_bindex_t bindex, bstart, btail;
15339 + unsigned char isdir;
15340 + struct dentry *h_dentry;
15341 + struct inode *h_inode;
15342 + struct au_iinfo *iinfo;
15344 + IiMustWriteLock(inode);
15348 + bstart = au_dbstart(dentry);
15349 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
15350 + mode = h_inode->i_mode;
15351 + switch (mode & S_IFMT) {
15353 + btail = au_dbtail(dentry);
15354 + inode->i_op = &aufs_iop;
15355 + inode->i_fop = &aufs_file_fop;
15356 + err = au_dy_iaop(inode, bstart, h_inode);
15357 + if (unlikely(err))
15362 + btail = au_dbtaildir(dentry);
15363 + inode->i_op = &aufs_dir_iop;
15364 + inode->i_fop = &aufs_dir_fop;
15367 + btail = au_dbtail(dentry);
15368 + inode->i_op = &aufs_symlink_iop;
15374 + btail = au_dbtail(dentry);
15375 + inode->i_op = &aufs_iop;
15376 + au_init_special_fop(inode, mode, h_inode->i_rdev);
15379 + AuIOErr("Unknown file type 0%o\n", mode);
15384 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
15385 + flags = au_hi_flags(inode, isdir);
15386 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
15387 + && au_ftest_hi(flags, HNOTIFY)
15388 + && dentry->d_name.len > AUFS_WH_PFX_LEN
15389 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
15390 + au_fclr_hi(flags, HNOTIFY);
15391 + iinfo = au_ii(inode);
15392 + iinfo->ii_bstart = bstart;
15393 + iinfo->ii_bend = btail;
15394 + for (bindex = bstart; bindex <= btail; bindex++) {
15395 + h_dentry = au_h_dptr(dentry, bindex);
15397 + au_set_h_iptr(inode, bindex,
15398 + au_igrab(h_dentry->d_inode), flags);
15400 + au_cpup_attr_all(inode, /*force*/1);
15407 + * successful returns with iinfo write_locked
15409 + * zero: success, matched
15410 + * plus: no error, but unmatched
15412 +static int reval_inode(struct inode *inode, struct dentry *dentry)
15415 + unsigned int gen;
15416 + struct au_iigen iigen;
15417 + aufs_bindex_t bindex, bend;
15418 + struct inode *h_inode, *h_dinode;
15421 + * before this function, if aufs got any iinfo lock, it must be only
15422 + * one, the parent dir.
15423 + * it can happen by UDBA and the obsoleted inode number.
15426 + if (unlikely(inode->i_ino == parent_ino(dentry)))
15430 + ii_write_lock_new_child(inode);
15431 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
15432 + bend = au_ibend(inode);
15433 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
15434 + h_inode = au_h_iptr(inode, bindex);
15435 + if (!h_inode || h_inode != h_dinode)
15439 + gen = au_iigen(inode, &iigen);
15440 + if (gen == au_digen(dentry)
15441 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
15444 + /* fully refresh inode using dentry */
15445 + err = au_refresh_hinode(inode, dentry);
15447 + au_update_iigen(inode, /*half*/0);
15451 + if (unlikely(err))
15452 + ii_write_unlock(inode);
15457 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15458 + unsigned int d_type, ino_t *ino)
15461 + struct mutex *mtx;
15463 + /* prevent hardlinked inode number from race condition */
15465 + if (d_type != DT_DIR) {
15466 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
15469 + err = au_xino_read(sb, bindex, h_ino, ino);
15470 + if (unlikely(err))
15475 + *ino = au_xino_new_ino(sb);
15476 + if (unlikely(!*ino))
15478 + err = au_xino_write(sb, bindex, h_ino, *ino);
15479 + if (unlikely(err))
15485 + mutex_unlock(mtx);
15489 +/* successful returns with iinfo write_locked */
15490 +/* todo: return with unlocked? */
15491 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
15493 + struct inode *inode, *h_inode;
15494 + struct dentry *h_dentry;
15495 + struct super_block *sb;
15496 + struct mutex *mtx;
15497 + ino_t h_ino, ino;
15499 + aufs_bindex_t bstart;
15501 + sb = dentry->d_sb;
15502 + bstart = au_dbstart(dentry);
15503 + h_dentry = au_h_dptr(dentry, bstart);
15504 + h_inode = h_dentry->d_inode;
15505 + h_ino = h_inode->i_ino;
15508 + * stop 'race'-ing between hardlinks under different
15512 + if (!S_ISDIR(h_inode->i_mode))
15513 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
15518 + err = au_xino_read(sb, bstart, h_ino, &ino);
15519 + inode = ERR_PTR(err);
15520 + if (unlikely(err))
15524 + ino = au_xino_new_ino(sb);
15525 + if (unlikely(!ino)) {
15526 + inode = ERR_PTR(-EIO);
15531 + AuDbg("i%lu\n", (unsigned long)ino);
15532 + inode = au_iget_locked(sb, ino);
15533 + err = PTR_ERR(inode);
15534 + if (IS_ERR(inode))
15537 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
15538 + if (inode->i_state & I_NEW) {
15539 + /* verbose coding for lock class name */
15540 + if (unlikely(S_ISLNK(h_inode->i_mode)))
15541 + au_rw_class(&au_ii(inode)->ii_rwsem,
15542 + au_lc_key + AuLcSymlink_IIINFO);
15543 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
15544 + au_rw_class(&au_ii(inode)->ii_rwsem,
15545 + au_lc_key + AuLcDir_IIINFO);
15546 + else /* likely */
15547 + au_rw_class(&au_ii(inode)->ii_rwsem,
15548 + au_lc_key + AuLcNonDir_IIINFO);
15550 + ii_write_lock_new_child(inode);
15551 + err = set_inode(inode, dentry);
15553 + unlock_new_inode(inode);
15554 + goto out; /* success */
15558 + * iget_failed() calls iput(), but we need to call
15559 + * ii_write_unlock() after iget_failed(). so dirty hack for
15562 + atomic_inc(&inode->i_count);
15563 + iget_failed(inode);
15564 + ii_write_unlock(inode);
15565 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
15566 + /* ignore this error */
15568 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
15570 + * horrible race condition between lookup, readdir and copyup
15571 + * (or something).
15574 + mutex_unlock(mtx);
15575 + err = reval_inode(inode, dentry);
15576 + if (unlikely(err < 0)) {
15583 + goto out; /* success */
15588 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
15589 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
15590 + " b%d, %s, %pd, hi%lu, i%lu.\n",
15591 + bstart, au_sbtype(h_dentry->d_sb), dentry,
15592 + (unsigned long)h_ino, (unsigned long)ino);
15594 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
15598 + mutex_unlock(mtx);
15604 + inode = ERR_PTR(err);
15607 + mutex_unlock(mtx);
15611 +/* ---------------------------------------------------------------------- */
15613 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15614 + struct inode *inode)
15618 + err = au_br_rdonly(au_sbr(sb, bindex));
15620 + /* pseudo-link after flushed may happen out of bounds */
15623 + && au_ibstart(inode) <= bindex
15624 + && bindex <= au_ibend(inode)) {
15626 + * permission check is unnecessary since vfsub routine
15627 + * will be called later
15629 + struct inode *hi = au_h_iptr(inode, bindex);
15631 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
15637 +int au_test_h_perm(struct inode *h_inode, int mask)
15639 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
15641 + return inode_permission(h_inode, mask);
15644 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
15646 + if (au_test_nfs(h_inode->i_sb)
15647 + && (mask & MAY_WRITE)
15648 + && S_ISDIR(h_inode->i_mode))
15649 + mask |= MAY_READ; /* force permission check */
15650 + return au_test_h_perm(h_inode, mask);
15652 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
15653 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
15654 +++ linux/fs/aufs/inode.h 2014-04-24 22:11:10.855269116 +0200
15657 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15659 + * This program, aufs is free software; you can redistribute it and/or modify
15660 + * it under the terms of the GNU General Public License as published by
15661 + * the Free Software Foundation; either version 2 of the License, or
15662 + * (at your option) any later version.
15664 + * This program is distributed in the hope that it will be useful,
15665 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15666 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15667 + * GNU General Public License for more details.
15669 + * You should have received a copy of the GNU General Public License
15670 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15674 + * inode operations
15677 +#ifndef __AUFS_INODE_H__
15678 +#define __AUFS_INODE_H__
15682 +#include <linux/fsnotify.h>
15683 +#include "rwsem.h"
15687 +struct au_hnotify {
15688 +#ifdef CONFIG_AUFS_HNOTIFY
15689 +#ifdef CONFIG_AUFS_HFSNOTIFY
15690 + /* never use fsnotify_add_vfsmount_mark() */
15691 + struct fsnotify_mark hn_mark;
15693 + struct inode *hn_aufs_inode; /* no get/put */
15695 +} ____cacheline_aligned_in_smp;
15697 +struct au_hinode {
15698 + struct inode *hi_inode;
15699 + aufs_bindex_t hi_id;
15700 +#ifdef CONFIG_AUFS_HNOTIFY
15701 + struct au_hnotify *hi_notify;
15704 + /* reference to the copied-up whiteout with get/put */
15705 + struct dentry *hi_whdentry;
15709 +#define AuIG_HALF_REFRESHED 1
15710 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
15711 +#define au_ig_fset(flags, name) \
15712 + do { (flags) |= AuIG_##name; } while (0)
15713 +#define au_ig_fclr(flags, name) \
15714 + do { (flags) &= ~AuIG_##name; } while (0)
15717 + __u32 ig_generation, ig_flags;
15722 + spinlock_t ii_genspin;
15723 + struct au_iigen ii_generation;
15724 + struct super_block *ii_hsb1; /* no get/put */
15726 + struct au_rwsem ii_rwsem;
15727 + aufs_bindex_t ii_bstart, ii_bend;
15729 + struct au_hinode *ii_hinode;
15730 + struct au_vdir *ii_vdir;
15733 +struct au_icntnr {
15734 + struct au_iinfo iinfo;
15735 + struct inode vfs_inode;
15736 +} ____cacheline_aligned_in_smp;
15738 +/* au_pin flags */
15739 +#define AuPin_DI_LOCKED 1
15740 +#define AuPin_MNT_WRITE (1 << 1)
15741 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
15742 +#define au_fset_pin(flags, name) \
15743 + do { (flags) |= AuPin_##name; } while (0)
15744 +#define au_fclr_pin(flags, name) \
15745 + do { (flags) &= ~AuPin_##name; } while (0)
15749 + struct dentry *dentry;
15750 + unsigned int udba;
15751 + unsigned char lsc_di, lsc_hi, flags;
15752 + aufs_bindex_t bindex;
15755 + struct dentry *parent;
15756 + struct au_hinode *hdir;
15757 + struct vfsmount *h_mnt;
15759 + /* temporary unlock/relock for copyup */
15760 + struct dentry *h_dentry, *h_parent;
15761 + struct au_branch *br;
15762 + struct task_struct *task;
15765 +void au_pin_hdir_unlock(struct au_pin *p);
15766 +int au_pin_hdir_relock(struct au_pin *p);
15767 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
15768 +void au_pin_hdir_acquire_nest(struct au_pin *p);
15769 +void au_pin_hdir_release(struct au_pin *p);
15771 +/* ---------------------------------------------------------------------- */
15773 +static inline struct au_iinfo *au_ii(struct inode *inode)
15775 + struct au_iinfo *iinfo;
15777 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15778 + if (iinfo->ii_hinode)
15780 + return NULL; /* debugging bad_inode case */
15783 +/* ---------------------------------------------------------------------- */
15786 +struct inode *au_igrab(struct inode *inode);
15787 +int au_refresh_hinode_self(struct inode *inode);
15788 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
15789 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15790 + unsigned int d_type, ino_t *ino);
15791 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
15792 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
15793 + struct inode *inode);
15794 +int au_test_h_perm(struct inode *h_inode, int mask);
15795 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
15797 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
15798 + ino_t h_ino, unsigned int d_type, ino_t *ino)
15800 +#ifdef CONFIG_AUFS_SHWH
15801 + return au_ino(sb, bindex, h_ino, d_type, ino);
15808 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
15810 +/* au_wr_dir flags */
15811 +#define AuWrDir_ADD_ENTRY 1
15812 +#define AuWrDir_TMP_WHENTRY (1 << 1)
15813 +#define AuWrDir_ISDIR (1 << 2)
15814 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
15815 +#define au_fset_wrdir(flags, name) \
15816 + do { (flags) |= AuWrDir_##name; } while (0)
15817 +#define au_fclr_wrdir(flags, name) \
15818 + do { (flags) &= ~AuWrDir_##name; } while (0)
15820 +struct au_wr_dir_args {
15821 + aufs_bindex_t force_btgt;
15822 + unsigned char flags;
15824 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
15825 + struct au_wr_dir_args *args);
15827 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
15828 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
15829 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
15830 + unsigned int udba, unsigned char flags);
15831 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
15832 + unsigned int udba, unsigned char flags) __must_check;
15833 +int au_do_pin(struct au_pin *pin) __must_check;
15834 +void au_unpin(struct au_pin *pin);
15837 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
15838 + struct dentry *h_parent, int isdir);
15839 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
15841 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
15842 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
15844 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
15845 + struct dentry *dentry);
15846 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
15849 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
15850 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
15851 + struct dentry *h_parent, int isdir);
15852 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
15853 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
15856 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
15857 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
15858 + struct inode *dir, struct dentry *dentry);
15861 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
15862 +void au_hiput(struct au_hinode *hinode);
15863 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15864 + struct dentry *h_wh);
15865 +unsigned int au_hi_flags(struct inode *inode, int isdir);
15867 +/* hinode flags */
15868 +#define AuHi_XINO 1
15869 +#define AuHi_HNOTIFY (1 << 1)
15870 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
15871 +#define au_fset_hi(flags, name) \
15872 + do { (flags) |= AuHi_##name; } while (0)
15873 +#define au_fclr_hi(flags, name) \
15874 + do { (flags) &= ~AuHi_##name; } while (0)
15876 +#ifndef CONFIG_AUFS_HNOTIFY
15877 +#undef AuHi_HNOTIFY
15878 +#define AuHi_HNOTIFY 0
15881 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15882 + struct inode *h_inode, unsigned int flags);
15884 +void au_update_iigen(struct inode *inode, int half);
15885 +void au_update_ibrange(struct inode *inode, int do_put_zero);
15887 +void au_icntnr_init_once(void *_c);
15888 +int au_iinfo_init(struct inode *inode);
15889 +void au_iinfo_fin(struct inode *inode);
15890 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
15892 +#ifdef CONFIG_PROC_FS
15894 +int au_plink_maint(struct super_block *sb, int flags);
15895 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
15896 +int au_plink_maint_enter(struct super_block *sb);
15897 +#ifdef CONFIG_AUFS_DEBUG
15898 +void au_plink_list(struct super_block *sb);
15900 +AuStubVoid(au_plink_list, struct super_block *sb)
15902 +int au_plink_test(struct inode *inode);
15903 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
15904 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
15905 + struct dentry *h_dentry);
15906 +void au_plink_put(struct super_block *sb, int verbose);
15907 +void au_plink_clean(struct super_block *sb, int verbose);
15908 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
15910 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
15911 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
15912 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
15913 +AuStubVoid(au_plink_list, struct super_block *sb);
15914 +AuStubInt0(au_plink_test, struct inode *inode);
15915 +AuStub(struct dentry *, au_plink_lkup, return NULL,
15916 + struct inode *inode, aufs_bindex_t bindex);
15917 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
15918 + struct dentry *h_dentry);
15919 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
15920 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
15921 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
15922 +#endif /* CONFIG_PROC_FS */
15924 +/* ---------------------------------------------------------------------- */
15926 +/* lock subclass for iinfo */
15928 + AuLsc_II_CHILD, /* child first */
15929 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
15930 + AuLsc_II_CHILD3, /* copyup dirs */
15931 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
15932 + AuLsc_II_PARENT2,
15933 + AuLsc_II_PARENT3, /* copyup dirs */
15934 + AuLsc_II_NEW_CHILD
15938 + * ii_read_lock_child, ii_write_lock_child,
15939 + * ii_read_lock_child2, ii_write_lock_child2,
15940 + * ii_read_lock_child3, ii_write_lock_child3,
15941 + * ii_read_lock_parent, ii_write_lock_parent,
15942 + * ii_read_lock_parent2, ii_write_lock_parent2,
15943 + * ii_read_lock_parent3, ii_write_lock_parent3,
15944 + * ii_read_lock_new_child, ii_write_lock_new_child,
15946 +#define AuReadLockFunc(name, lsc) \
15947 +static inline void ii_read_lock_##name(struct inode *i) \
15949 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15952 +#define AuWriteLockFunc(name, lsc) \
15953 +static inline void ii_write_lock_##name(struct inode *i) \
15955 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
15958 +#define AuRWLockFuncs(name, lsc) \
15959 + AuReadLockFunc(name, lsc) \
15960 + AuWriteLockFunc(name, lsc)
15962 +AuRWLockFuncs(child, CHILD);
15963 +AuRWLockFuncs(child2, CHILD2);
15964 +AuRWLockFuncs(child3, CHILD3);
15965 +AuRWLockFuncs(parent, PARENT);
15966 +AuRWLockFuncs(parent2, PARENT2);
15967 +AuRWLockFuncs(parent3, PARENT3);
15968 +AuRWLockFuncs(new_child, NEW_CHILD);
15970 +#undef AuReadLockFunc
15971 +#undef AuWriteLockFunc
15972 +#undef AuRWLockFuncs
15975 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
15977 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
15979 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
15980 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
15981 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
15983 +/* ---------------------------------------------------------------------- */
15985 +static inline void au_icntnr_init(struct au_icntnr *c)
15987 +#ifdef CONFIG_AUFS_DEBUG
15988 + c->vfs_inode.i_mode = 0;
15992 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
15994 + unsigned int gen;
15995 + struct au_iinfo *iinfo;
15997 + iinfo = au_ii(inode);
15998 + spin_lock(&iinfo->ii_genspin);
16000 + *iigen = iinfo->ii_generation;
16001 + gen = iinfo->ii_generation.ig_generation;
16002 + spin_unlock(&iinfo->ii_genspin);
16007 +/* tiny test for inode number */
16008 +/* tmpfs generation is too rough */
16009 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16011 + struct au_iinfo *iinfo;
16013 + iinfo = au_ii(inode);
16014 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16015 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16016 + && iinfo->ii_higen == h_inode->i_generation);
16019 +static inline void au_iigen_dec(struct inode *inode)
16021 + struct au_iinfo *iinfo;
16023 + iinfo = au_ii(inode);
16024 + spin_lock(&iinfo->ii_genspin);
16025 + iinfo->ii_generation.ig_generation--;
16026 + spin_unlock(&iinfo->ii_genspin);
16029 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16034 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16040 +/* ---------------------------------------------------------------------- */
16042 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16043 + aufs_bindex_t bindex)
16045 + IiMustAnyLock(inode);
16046 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16049 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16051 + IiMustAnyLock(inode);
16052 + return au_ii(inode)->ii_bstart;
16055 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16057 + IiMustAnyLock(inode);
16058 + return au_ii(inode)->ii_bend;
16061 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16063 + IiMustAnyLock(inode);
16064 + return au_ii(inode)->ii_vdir;
16067 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16069 + IiMustAnyLock(inode);
16070 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16073 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16075 + IiMustWriteLock(inode);
16076 + au_ii(inode)->ii_bstart = bindex;
16079 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16081 + IiMustWriteLock(inode);
16082 + au_ii(inode)->ii_bend = bindex;
16085 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16087 + IiMustWriteLock(inode);
16088 + au_ii(inode)->ii_vdir = vdir;
16091 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16093 + IiMustAnyLock(inode);
16094 + return au_ii(inode)->ii_hinode + bindex;
16097 +/* ---------------------------------------------------------------------- */
16099 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16102 + return pin->parent;
16106 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16108 + if (pin && pin->hdir)
16109 + return pin->hdir->hi_inode;
16113 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16116 + return pin->hdir;
16120 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16123 + pin->dentry = dentry;
16126 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16127 + unsigned char lflag)
16131 + au_fset_pin(pin->flags, DI_LOCKED);
16133 + au_fclr_pin(pin->flags, DI_LOCKED);
16137 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16140 + dput(pin->parent);
16141 + pin->parent = dget(parent);
16145 +/* ---------------------------------------------------------------------- */
16148 +#ifdef CONFIG_AUFS_HNOTIFY
16149 +struct au_hnotify_op {
16150 + void (*ctl)(struct au_hinode *hinode, int do_set);
16151 + int (*alloc)(struct au_hinode *hinode);
16154 + * if it returns true, the the caller should free hinode->hi_notify,
16155 + * otherwise ->free() frees it.
16157 + int (*free)(struct au_hinode *hinode,
16158 + struct au_hnotify *hn) __must_check;
16160 + void (*fin)(void);
16161 + int (*init)(void);
16163 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16164 + void (*fin_br)(struct au_branch *br);
16165 + int (*init_br)(struct au_branch *br, int perm);
16169 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
16170 +void au_hn_free(struct au_hinode *hinode);
16171 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
16172 +void au_hn_reset(struct inode *inode, unsigned int flags);
16173 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
16174 + struct qstr *h_child_qstr, struct inode *h_child_inode);
16175 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
16176 +int au_hnotify_init_br(struct au_branch *br, int perm);
16177 +void au_hnotify_fin_br(struct au_branch *br);
16178 +int __init au_hnotify_init(void);
16179 +void au_hnotify_fin(void);
16182 +extern const struct au_hnotify_op au_hnotify_op;
16185 +void au_hn_init(struct au_hinode *hinode)
16187 + hinode->hi_notify = NULL;
16190 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16192 + return hinode->hi_notify;
16197 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
16198 + struct inode *inode __maybe_unused)
16200 + return -EOPNOTSUPP;
16203 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16208 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
16209 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
16210 + int do_set __maybe_unused)
16211 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
16212 + unsigned int flags __maybe_unused)
16213 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
16214 + struct au_branch *br __maybe_unused,
16215 + int perm __maybe_unused)
16216 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
16217 + int perm __maybe_unused)
16218 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
16219 +AuStubInt0(__init au_hnotify_init, void)
16220 +AuStubVoid(au_hnotify_fin, void)
16221 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
16222 +#endif /* CONFIG_AUFS_HNOTIFY */
16224 +static inline void au_hn_suspend(struct au_hinode *hdir)
16226 + au_hn_ctl(hdir, /*do_set*/0);
16229 +static inline void au_hn_resume(struct au_hinode *hdir)
16231 + au_hn_ctl(hdir, /*do_set*/1);
16234 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
16236 + mutex_lock(&hdir->hi_inode->i_mutex);
16237 + au_hn_suspend(hdir);
16240 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
16241 + unsigned int sc __maybe_unused)
16243 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
16244 + au_hn_suspend(hdir);
16247 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
16249 + au_hn_resume(hdir);
16250 + mutex_unlock(&hdir->hi_inode->i_mutex);
16253 +#endif /* __KERNEL__ */
16254 +#endif /* __AUFS_INODE_H__ */
16255 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
16256 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
16257 +++ linux/fs/aufs/ioctl.c 2014-04-24 22:11:10.855269116 +0200
16260 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16262 + * This program, aufs is free software; you can redistribute it and/or modify
16263 + * it under the terms of the GNU General Public License as published by
16264 + * the Free Software Foundation; either version 2 of the License, or
16265 + * (at your option) any later version.
16267 + * This program is distributed in the hope that it will be useful,
16268 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16269 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16270 + * GNU General Public License for more details.
16272 + * You should have received a copy of the GNU General Public License
16273 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16278 + * plink-management and readdir in userspace.
16279 + * assist the pathconf(3) wrapper library.
16283 +#include <linux/compat.h>
16284 +#include <linux/file.h>
16287 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16290 + aufs_bindex_t wbi, bindex, bend;
16291 + struct file *h_file;
16292 + struct super_block *sb;
16293 + struct dentry *root;
16294 + struct au_branch *br;
16295 + struct aufs_wbr_fd wbrfd = {
16296 + .oflags = au_dir_roflags,
16299 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
16300 + | O_NOATIME | O_CLOEXEC;
16302 + AuDebugOn(wbrfd.oflags & ~valid);
16305 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
16306 + if (unlikely(err)) {
16312 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
16313 + wbrfd.oflags |= au_dir_roflags;
16314 + AuDbg("0%o\n", wbrfd.oflags);
16315 + if (unlikely(wbrfd.oflags & ~valid))
16319 + fd = get_unused_fd();
16321 + if (unlikely(fd < 0))
16324 + h_file = ERR_PTR(-EINVAL);
16327 + sb = path->dentry->d_sb;
16328 + root = sb->s_root;
16329 + aufs_read_lock(root, AuLock_IR);
16330 + bend = au_sbend(sb);
16331 + if (wbrfd.brid >= 0) {
16332 + wbi = au_br_index(sb, wbrfd.brid);
16333 + if (unlikely(wbi < 0 || wbi > bend))
16337 + h_file = ERR_PTR(-ENOENT);
16338 + br = au_sbr(sb, wbi);
16339 + if (!au_br_writable(br->br_perm)) {
16343 + bindex = wbi + 1;
16345 + for (; bindex <= bend; bindex++) {
16346 + br = au_sbr(sb, bindex);
16347 + if (au_br_writable(br->br_perm)) {
16349 + br = au_sbr(sb, wbi);
16354 + AuDbg("wbi %d\n", wbi);
16356 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
16360 + aufs_read_unlock(root, AuLock_IR);
16361 + err = PTR_ERR(h_file);
16362 + if (IS_ERR(h_file))
16365 + atomic_dec(&br->br_count); /* cf. au_h_open() */
16366 + fd_install(fd, h_file);
16368 + goto out; /* success */
16371 + put_unused_fd(fd);
16377 +/* ---------------------------------------------------------------------- */
16379 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
16384 + case AUFS_CTL_RDU:
16385 + case AUFS_CTL_RDU_INO:
16386 + err = au_rdu_ioctl(file, cmd, arg);
16389 + case AUFS_CTL_WBR_FD:
16390 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
16393 + case AUFS_CTL_IBUSY:
16394 + err = au_ibusy_ioctl(file, arg);
16398 + /* do not call the lower */
16399 + AuDbg("0x%x\n", cmd);
16407 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
16412 + case AUFS_CTL_MVDOWN:
16413 + err = au_mvdown(file->f_dentry, (void __user *)arg);
16416 + case AUFS_CTL_WBR_FD:
16417 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
16421 + /* do not call the lower */
16422 + AuDbg("0x%x\n", cmd);
16430 +#ifdef CONFIG_COMPAT
16431 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
16432 + unsigned long arg)
16437 + case AUFS_CTL_RDU:
16438 + case AUFS_CTL_RDU_INO:
16439 + err = au_rdu_compat_ioctl(file, cmd, arg);
16442 + case AUFS_CTL_IBUSY:
16443 + err = au_ibusy_compat_ioctl(file, arg);
16447 + err = aufs_ioctl_dir(file, cmd, arg);
16454 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
16455 + unsigned long arg)
16457 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
16460 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
16461 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
16462 +++ linux/fs/aufs/i_op_add.c 2014-04-24 22:11:10.851935747 +0200
16465 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16467 + * This program, aufs is free software; you can redistribute it and/or modify
16468 + * it under the terms of the GNU General Public License as published by
16469 + * the Free Software Foundation; either version 2 of the License, or
16470 + * (at your option) any later version.
16472 + * This program is distributed in the hope that it will be useful,
16473 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16474 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16475 + * GNU General Public License for more details.
16477 + * You should have received a copy of the GNU General Public License
16478 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16482 + * inode operations (add entry)
16488 + * final procedure of adding a new entry, except link(2).
16489 + * remove whiteout, instantiate, copyup the parent dir's times and size
16490 + * and update version.
16491 + * if it failed, re-create the removed whiteout.
16493 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
16494 + struct dentry *wh_dentry, struct dentry *dentry)
16497 + aufs_bindex_t bwh;
16498 + struct path h_path;
16499 + struct inode *inode, *h_dir;
16500 + struct dentry *wh;
16504 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
16505 + IMustLock(h_dir);
16506 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
16507 + bwh = au_dbwh(dentry);
16508 + h_path.dentry = wh_dentry;
16509 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
16510 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
16512 + if (unlikely(err))
16516 + inode = au_new_inode(dentry, /*must_new*/1);
16517 + if (!IS_ERR(inode)) {
16518 + d_instantiate(dentry, inode);
16519 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
16521 + if (au_ibstart(dir) == au_dbstart(dentry))
16522 + au_cpup_attr_timesizes(dir);
16523 + dir->i_version++;
16524 + return 0; /* success */
16527 + err = PTR_ERR(inode);
16532 + /* dir inode is locked */
16533 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
16534 + rerr = PTR_ERR(wh);
16535 + if (IS_ERR(wh)) {
16536 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
16537 + dentry, err, rerr);
16546 +static int au_d_may_add(struct dentry *dentry)
16551 + if (unlikely(d_unhashed(dentry)))
16553 + if (unlikely(dentry->d_inode))
16559 + * simple tests for the adding inode operations.
16560 + * following the checks in vfs, plus the parent-child relationship.
16562 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16563 + struct dentry *h_parent, int isdir)
16567 + struct dentry *h_dentry;
16568 + struct inode *h_inode;
16570 + err = -ENAMETOOLONG;
16571 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16574 + h_dentry = au_h_dptr(dentry, bindex);
16575 + h_inode = h_dentry->d_inode;
16576 + if (!dentry->d_inode) {
16578 + if (unlikely(h_inode))
16581 + /* rename(2) case */
16583 + if (unlikely(!h_inode || !h_inode->i_nlink))
16586 + h_mode = h_inode->i_mode;
16589 + if (unlikely(S_ISDIR(h_mode)))
16591 + } else if (unlikely(!S_ISDIR(h_mode))) {
16598 + /* expected parent dir is locked */
16599 + if (unlikely(h_parent != h_dentry->d_parent))
16608 + * initial procedure of adding a new entry.
16609 + * prepare writable branch and the parent dir, lock it,
16610 + * and lookup whiteout for the new entry.
16612 +static struct dentry*
16613 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
16614 + struct dentry *src_dentry, struct au_pin *pin,
16615 + struct au_wr_dir_args *wr_dir_args)
16617 + struct dentry *wh_dentry, *h_parent;
16618 + struct super_block *sb;
16619 + struct au_branch *br;
16621 + unsigned int udba;
16622 + aufs_bindex_t bcpup;
16624 + AuDbg("%pd\n", dentry);
16626 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
16628 + wh_dentry = ERR_PTR(err);
16629 + if (unlikely(err < 0))
16632 + sb = dentry->d_sb;
16633 + udba = au_opt_udba(sb);
16634 + err = au_pin(pin, dentry, bcpup, udba,
16635 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16636 + wh_dentry = ERR_PTR(err);
16637 + if (unlikely(err))
16640 + h_parent = au_pinned_h_parent(pin);
16641 + if (udba != AuOpt_UDBA_NONE
16642 + && au_dbstart(dentry) == bcpup)
16643 + err = au_may_add(dentry, bcpup, h_parent,
16644 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
16645 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16646 + err = -ENAMETOOLONG;
16647 + wh_dentry = ERR_PTR(err);
16648 + if (unlikely(err))
16651 + br = au_sbr(sb, bcpup);
16653 + struct path tmp = {
16654 + .dentry = h_parent,
16655 + .mnt = au_br_mnt(br)
16657 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
16660 + wh_dentry = NULL;
16661 + if (bcpup != au_dbwh(dentry))
16662 + goto out; /* success */
16664 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
16667 + if (IS_ERR(wh_dentry))
16670 + return wh_dentry;
16673 +/* ---------------------------------------------------------------------- */
16675 +enum { Mknod, Symlink, Creat };
16676 +struct simple_arg {
16684 + const char *symname;
16693 +static int add_simple(struct inode *dir, struct dentry *dentry,
16694 + struct simple_arg *arg)
16697 + aufs_bindex_t bstart;
16698 + unsigned char created;
16699 + struct dentry *wh_dentry, *parent;
16700 + struct inode *h_dir;
16701 + /* to reuduce stack size */
16703 + struct au_dtime dt;
16704 + struct au_pin pin;
16705 + struct path h_path;
16706 + struct au_wr_dir_args wr_dir_args;
16709 + AuDbg("%pd\n", dentry);
16713 + a = kmalloc(sizeof(*a), GFP_NOFS);
16714 + if (unlikely(!a))
16716 + a->wr_dir_args.force_btgt = -1;
16717 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
16719 + parent = dentry->d_parent; /* dir inode is locked */
16720 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16721 + if (unlikely(err))
16723 + err = au_d_may_add(dentry);
16724 + if (unlikely(err))
16726 + di_write_lock_parent(parent);
16727 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16728 + &a->pin, &a->wr_dir_args);
16729 + err = PTR_ERR(wh_dentry);
16730 + if (IS_ERR(wh_dentry))
16733 + bstart = au_dbstart(dentry);
16734 + a->h_path.dentry = au_h_dptr(dentry, bstart);
16735 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
16736 + h_dir = au_pinned_h_dir(&a->pin);
16737 + switch (arg->type) {
16739 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
16740 + arg->u.c.want_excl);
16743 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
16746 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
16754 + err = epilog(dir, bstart, wh_dentry, dentry);
16757 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
16759 + /* no delegation since it is just created */
16760 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
16763 + AuIOErr("%pd revert failure(%d, %d)\n",
16764 + dentry, err, rerr);
16767 + au_dtime_revert(&a->dt);
16770 + au_unpin(&a->pin);
16774 + di_write_unlock(parent);
16776 + if (unlikely(err)) {
16777 + au_update_dbstart(dentry);
16780 + aufs_read_unlock(dentry, AuLock_DW);
16787 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16790 + struct simple_arg arg = {
16797 + return add_simple(dir, dentry, &arg);
16800 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
16802 + struct simple_arg arg = {
16804 + .u.s.symname = symname
16806 + return add_simple(dir, dentry, &arg);
16809 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16812 + struct simple_arg arg = {
16816 + .want_excl = want_excl
16819 + return add_simple(dir, dentry, &arg);
16822 +/* ---------------------------------------------------------------------- */
16824 +struct au_link_args {
16825 + aufs_bindex_t bdst, bsrc;
16826 + struct au_pin pin;
16827 + struct path h_path;
16828 + struct dentry *src_parent, *parent;
16831 +static int au_cpup_before_link(struct dentry *src_dentry,
16832 + struct au_link_args *a)
16835 + struct dentry *h_src_dentry;
16836 + struct au_cp_generic cpg = {
16837 + .dentry = src_dentry,
16842 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
16845 + di_read_lock_parent(a->src_parent, AuLock_IR);
16846 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
16847 + if (unlikely(err))
16850 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
16851 + err = au_pin(&a->pin, src_dentry, a->bdst,
16852 + au_opt_udba(src_dentry->d_sb),
16853 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16854 + if (unlikely(err))
16857 + err = au_sio_cpup_simple(&cpg);
16858 + au_unpin(&a->pin);
16861 + di_read_unlock(a->src_parent, AuLock_IR);
16865 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
16866 + struct au_link_args *a)
16869 + unsigned char plink;
16870 + aufs_bindex_t bend;
16871 + struct dentry *h_src_dentry;
16872 + struct inode *h_inode, *inode, *delegated;
16873 + struct super_block *sb;
16874 + struct file *h_file;
16878 + sb = src_dentry->d_sb;
16879 + inode = src_dentry->d_inode;
16880 + if (au_ibstart(inode) <= a->bdst)
16881 + h_inode = au_h_iptr(inode, a->bdst);
16882 + if (!h_inode || !h_inode->i_nlink) {
16883 + /* copyup src_dentry as the name of dentry. */
16884 + bend = au_dbend(dentry);
16885 + if (bend < a->bsrc)
16886 + au_set_dbend(dentry, a->bsrc);
16887 + au_set_h_dptr(dentry, a->bsrc,
16888 + dget(au_h_dptr(src_dentry, a->bsrc)));
16889 + dget(a->h_path.dentry);
16890 + au_set_h_dptr(dentry, a->bdst, NULL);
16891 + dentry->d_inode = src_dentry->d_inode; /* tmp */
16892 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
16893 + if (IS_ERR(h_file))
16894 + err = PTR_ERR(h_file);
16896 + struct au_cp_generic cpg = {
16897 + .dentry = dentry,
16902 + .flags = AuCpup_KEEPLINO
16904 + err = au_sio_cpup_simple(&cpg);
16905 + au_h_open_post(dentry, a->bsrc, h_file);
16907 + dput(a->h_path.dentry);
16908 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
16910 + au_set_h_dptr(dentry, a->bdst,
16911 + a->h_path.dentry);
16913 + dentry->d_inode = NULL; /* restore */
16914 + au_set_h_dptr(dentry, a->bsrc, NULL);
16915 + au_set_dbend(dentry, bend);
16917 + /* the inode of src_dentry already exists on a.bdst branch */
16918 + h_src_dentry = d_find_alias(h_inode);
16919 + if (!h_src_dentry && au_plink_test(inode)) {
16921 + h_src_dentry = au_plink_lkup(inode, a->bdst);
16922 + err = PTR_ERR(h_src_dentry);
16923 + if (IS_ERR(h_src_dentry))
16926 + if (unlikely(!h_src_dentry->d_inode)) {
16927 + dput(h_src_dentry);
16928 + h_src_dentry = NULL;
16932 + if (h_src_dentry) {
16933 + delegated = NULL;
16934 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
16935 + &a->h_path, &delegated);
16936 + if (unlikely(err == -EWOULDBLOCK)) {
16937 + pr_warn("cannot retry for NFSv4 delegation"
16938 + " for an internal link\n");
16941 + dput(h_src_dentry);
16943 + AuIOErr("no dentry found for hi%lu on b%d\n",
16944 + h_inode->i_ino, a->bdst);
16949 + if (!err && !plink)
16950 + au_plink_append(inode, a->bdst, a->h_path.dentry);
16957 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16958 + struct dentry *dentry)
16961 + struct au_dtime dt;
16962 + struct au_link_args *a;
16963 + struct dentry *wh_dentry, *h_src_dentry;
16964 + struct inode *inode, *delegated;
16965 + struct super_block *sb;
16966 + struct au_wr_dir_args wr_dir_args = {
16967 + /* .force_btgt = -1, */
16968 + .flags = AuWrDir_ADD_ENTRY
16972 + inode = src_dentry->d_inode;
16973 + IMustLock(inode);
16976 + a = kzalloc(sizeof(*a), GFP_NOFS);
16977 + if (unlikely(!a))
16980 + a->parent = dentry->d_parent; /* dir inode is locked */
16981 + err = aufs_read_and_write_lock2(dentry, src_dentry,
16982 + AuLock_NOPLM | AuLock_GEN);
16983 + if (unlikely(err))
16985 + err = au_d_hashed_positive(src_dentry);
16986 + if (unlikely(err))
16988 + err = au_d_may_add(dentry);
16989 + if (unlikely(err))
16992 + a->src_parent = dget_parent(src_dentry);
16993 + wr_dir_args.force_btgt = au_ibstart(inode);
16995 + di_write_lock_parent(a->parent);
16996 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
16997 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
16999 + err = PTR_ERR(wh_dentry);
17000 + if (IS_ERR(wh_dentry))
17004 + sb = dentry->d_sb;
17005 + a->bdst = au_dbstart(dentry);
17006 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17007 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17008 + a->bsrc = au_ibstart(inode);
17009 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17010 + if (!h_src_dentry) {
17011 + a->bsrc = au_dbstart(src_dentry);
17012 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17013 + AuDebugOn(!h_src_dentry);
17014 + } else if (IS_ERR(h_src_dentry))
17017 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17018 + if (a->bdst < a->bsrc
17019 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17020 + err = au_cpup_or_link(src_dentry, dentry, a);
17022 + delegated = NULL;
17023 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17024 + &a->h_path, &delegated);
17025 + if (unlikely(err == -EWOULDBLOCK)) {
17026 + pr_warn("cannot retry for NFSv4 delegation"
17027 + " for an internal link\n");
17031 + dput(h_src_dentry);
17034 + * copyup src_dentry to the branch we process,
17035 + * and then link(2) to it.
17037 + dput(h_src_dentry);
17038 + if (a->bdst < a->bsrc
17039 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17040 + au_unpin(&a->pin);
17041 + di_write_unlock(a->parent);
17042 + err = au_cpup_before_link(src_dentry, a);
17043 + di_write_lock_parent(a->parent);
17045 + err = au_pin(&a->pin, dentry, a->bdst,
17047 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17048 + if (unlikely(err))
17052 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17054 + if (h_src_dentry && h_src_dentry->d_inode) {
17055 + delegated = NULL;
17056 + err = vfsub_link(h_src_dentry,
17057 + au_pinned_h_dir(&a->pin),
17058 + &a->h_path, &delegated);
17059 + if (unlikely(err == -EWOULDBLOCK)) {
17060 + pr_warn("cannot retry"
17061 + " for NFSv4 delegation"
17062 + " for an internal link\n");
17068 + if (unlikely(err))
17072 + a->h_path.dentry = wh_dentry;
17073 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17075 + if (unlikely(err))
17079 + dir->i_version++;
17080 + if (au_ibstart(dir) == au_dbstart(dentry))
17081 + au_cpup_attr_timesizes(dir);
17082 + inc_nlink(inode);
17083 + inode->i_ctime = dir->i_ctime;
17084 + d_instantiate(dentry, au_igrab(inode));
17085 + if (d_unhashed(a->h_path.dentry))
17086 + /* some filesystem calls d_drop() */
17088 + goto out_unpin; /* success */
17091 + /* no delegation since it is just created */
17092 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17093 + /*delegated*/NULL, /*force*/0);
17094 + if (unlikely(rerr)) {
17095 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17098 + au_dtime_revert(&dt);
17100 + au_unpin(&a->pin);
17104 + di_write_unlock(a->parent);
17105 + dput(a->src_parent);
17107 + if (unlikely(err)) {
17108 + au_update_dbstart(dentry);
17111 + aufs_read_and_write_unlock2(dentry, src_dentry);
17119 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
17122 + aufs_bindex_t bindex;
17123 + unsigned char diropq;
17124 + struct path h_path;
17125 + struct dentry *wh_dentry, *parent, *opq_dentry;
17126 + struct mutex *h_mtx;
17127 + struct super_block *sb;
17129 + struct au_pin pin;
17130 + struct au_dtime dt;
17131 + } *a; /* reduce the stack usage */
17132 + struct au_wr_dir_args wr_dir_args = {
17133 + .force_btgt = -1,
17134 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
17140 + a = kmalloc(sizeof(*a), GFP_NOFS);
17141 + if (unlikely(!a))
17144 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17145 + if (unlikely(err))
17147 + err = au_d_may_add(dentry);
17148 + if (unlikely(err))
17151 + parent = dentry->d_parent; /* dir inode is locked */
17152 + di_write_lock_parent(parent);
17153 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17154 + &a->pin, &wr_dir_args);
17155 + err = PTR_ERR(wh_dentry);
17156 + if (IS_ERR(wh_dentry))
17159 + sb = dentry->d_sb;
17160 + bindex = au_dbstart(dentry);
17161 + h_path.dentry = au_h_dptr(dentry, bindex);
17162 + h_path.mnt = au_sbr_mnt(sb, bindex);
17163 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
17164 + if (unlikely(err))
17167 + /* make the dir opaque */
17169 + h_mtx = &h_path.dentry->d_inode->i_mutex;
17171 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
17172 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17173 + opq_dentry = au_diropq_create(dentry, bindex);
17174 + mutex_unlock(h_mtx);
17175 + err = PTR_ERR(opq_dentry);
17176 + if (IS_ERR(opq_dentry))
17178 + dput(opq_dentry);
17182 + err = epilog(dir, bindex, wh_dentry, dentry);
17185 + goto out_unpin; /* success */
17190 + AuLabel(revert opq);
17191 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17192 + rerr = au_diropq_remove(dentry, bindex);
17193 + mutex_unlock(h_mtx);
17195 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
17196 + dentry, err, rerr);
17202 + AuLabel(revert dir);
17203 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
17205 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
17206 + dentry, err, rerr);
17209 + au_dtime_revert(&a->dt);
17211 + au_unpin(&a->pin);
17214 + di_write_unlock(parent);
17216 + if (unlikely(err)) {
17217 + au_update_dbstart(dentry);
17220 + aufs_read_unlock(dentry, AuLock_DW);
17226 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
17227 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
17228 +++ linux/fs/aufs/i_op.c 2014-04-24 22:11:10.851935747 +0200
17231 + * Copyright (C) 2005-2014 Junjiro R. Okajima
17233 + * This program, aufs is free software; you can redistribute it and/or modify
17234 + * it under the terms of the GNU General Public License as published by
17235 + * the Free Software Foundation; either version 2 of the License, or
17236 + * (at your option) any later version.
17238 + * This program is distributed in the hope that it will be useful,
17239 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17240 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17241 + * GNU General Public License for more details.
17243 + * You should have received a copy of the GNU General Public License
17244 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17248 + * inode operations (except add/del/rename)
17251 +#include <linux/device_cgroup.h>
17252 +#include <linux/fs_stack.h>
17253 +#include <linux/mm.h>
17254 +#include <linux/namei.h>
17255 +#include <linux/security.h>
17258 +static int h_permission(struct inode *h_inode, int mask,
17259 + struct vfsmount *h_mnt, int brperm)
17262 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
17265 + if ((write_mask && IS_IMMUTABLE(h_inode))
17266 + || ((mask & MAY_EXEC)
17267 + && S_ISREG(h_inode->i_mode)
17268 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
17269 + || !(h_inode->i_mode & S_IXUGO))))
17273 + * - skip the lower fs test in the case of write to ro branch.
17274 + * - nfs dir permission write check is optimized, but a policy for
17275 + * link/rename requires a real check.
17277 + if ((write_mask && !au_br_writable(brperm))
17278 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
17279 + && write_mask && !(mask & MAY_READ))
17280 + || !h_inode->i_op->permission) {
17281 + /* AuLabel(generic_permission); */
17282 + err = generic_permission(h_inode, mask);
17284 + /* AuLabel(h_inode->permission); */
17285 + err = h_inode->i_op->permission(h_inode, mask);
17290 + err = devcgroup_inode_permission(h_inode, mask);
17292 + err = security_inode_permission(h_inode, mask);
17296 + /* todo: do we need to call ima_path_check()? */
17297 + struct path h_path = {
17301 + err = ima_path_check(&h_path,
17302 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
17303 + IMA_COUNT_LEAVE);
17311 +static int aufs_permission(struct inode *inode, int mask)
17314 + aufs_bindex_t bindex, bend;
17315 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
17316 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
17317 + struct inode *h_inode;
17318 + struct super_block *sb;
17319 + struct au_branch *br;
17321 + /* todo: support rcu-walk? */
17322 + if (mask & MAY_NOT_BLOCK)
17325 + sb = inode->i_sb;
17326 + si_read_lock(sb, AuLock_FLUSH);
17327 + ii_read_lock_child(inode);
17329 + err = au_iigen_test(inode, au_sigen(sb));
17330 + if (unlikely(err))
17334 + if (!isdir || write_mask) {
17335 + err = au_busy_or_stale();
17336 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17337 + if (unlikely(!h_inode
17338 + || (h_inode->i_mode & S_IFMT)
17339 + != (inode->i_mode & S_IFMT)))
17343 + bindex = au_ibstart(inode);
17344 + br = au_sbr(sb, bindex);
17345 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
17348 + && !special_file(h_inode->i_mode)) {
17349 + /* test whether the upper writable branch exists */
17351 + for (; bindex >= 0; bindex--)
17352 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
17360 + /* non-write to dir */
17362 + bend = au_ibend(inode);
17363 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
17364 + h_inode = au_h_iptr(inode, bindex);
17366 + err = au_busy_or_stale();
17367 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
17370 + br = au_sbr(sb, bindex);
17371 + err = h_permission(h_inode, mask, au_br_mnt(br),
17377 + ii_read_unlock(inode);
17378 + si_read_unlock(sb);
17382 +/* ---------------------------------------------------------------------- */
17384 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
17385 + unsigned int flags)
17387 + struct dentry *ret, *parent;
17388 + struct inode *inode;
17389 + struct super_block *sb;
17390 + int err, npositive;
17394 + /* todo: support rcu-walk? */
17395 + ret = ERR_PTR(-ECHILD);
17396 + if (flags & LOOKUP_RCU)
17399 + ret = ERR_PTR(-ENAMETOOLONG);
17400 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17404 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17405 + ret = ERR_PTR(err);
17406 + if (unlikely(err))
17409 + err = au_di_init(dentry);
17410 + ret = ERR_PTR(err);
17411 + if (unlikely(err))
17415 + npositive = 0; /* suppress a warning */
17416 + parent = dentry->d_parent; /* dir inode is locked */
17417 + di_read_lock_parent(parent, AuLock_IR);
17418 + err = au_alive_dir(parent);
17420 + err = au_digen_test(parent, au_sigen(sb));
17422 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
17426 + di_read_unlock(parent, AuLock_IR);
17427 + ret = ERR_PTR(err);
17428 + if (unlikely(err < 0))
17432 + inode = au_new_inode(dentry, /*must_new*/0);
17433 + ret = (void *)inode;
17435 + if (IS_ERR(inode)) {
17440 + ret = d_splice_alias(inode, dentry);
17442 + if (unlikely(d_need_lookup(dentry))) {
17443 + spin_lock(&dentry->d_lock);
17444 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
17445 + spin_unlock(&dentry->d_lock);
17448 + if (unlikely(IS_ERR(ret) && inode)) {
17449 + ii_write_unlock(inode);
17455 + di_write_unlock(dentry);
17457 + /* verbose coding for lock class name */
17458 + if (unlikely(S_ISLNK(inode->i_mode)))
17459 + au_rw_class(&au_di(dentry)->di_rwsem,
17460 + au_lc_key + AuLcSymlink_DIINFO);
17461 + else if (unlikely(S_ISDIR(inode->i_mode)))
17462 + au_rw_class(&au_di(dentry)->di_rwsem,
17463 + au_lc_key + AuLcDir_DIINFO);
17464 + else /* likely */
17465 + au_rw_class(&au_di(dentry)->di_rwsem,
17466 + au_lc_key + AuLcNonDir_DIINFO);
17469 + si_read_unlock(sb);
17474 +/* ---------------------------------------------------------------------- */
17476 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
17477 + const unsigned char add_entry, aufs_bindex_t bcpup,
17478 + aufs_bindex_t bstart)
17481 + struct dentry *h_parent;
17482 + struct inode *h_dir;
17485 + IMustLock(parent->d_inode);
17487 + di_write_lock_parent(parent);
17490 + if (!au_h_dptr(parent, bcpup)) {
17491 + if (bstart > bcpup)
17492 + err = au_cpup_dirs(dentry, bcpup);
17493 + else if (bstart < bcpup)
17494 + err = au_cpdown_dirs(dentry, bcpup);
17498 + if (!err && add_entry) {
17499 + h_parent = au_h_dptr(parent, bcpup);
17500 + h_dir = h_parent->d_inode;
17501 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
17502 + err = au_lkup_neg(dentry, bcpup,
17503 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
17504 + /* todo: no unlock here */
17505 + mutex_unlock(&h_dir->i_mutex);
17507 + AuDbg("bcpup %d\n", bcpup);
17509 + if (!dentry->d_inode)
17510 + au_set_h_dptr(dentry, bstart, NULL);
17511 + au_update_dbrange(dentry, /*do_put_zero*/0);
17516 + di_write_unlock(parent);
17518 + err = bcpup; /* success */
17525 + * decide the branch and the parent dir where we will create a new entry.
17526 + * returns new bindex or an error.
17527 + * copyup the parent dir if needed.
17529 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
17530 + struct au_wr_dir_args *args)
17533 + unsigned int flags;
17534 + aufs_bindex_t bcpup, bstart, src_bstart;
17535 + const unsigned char add_entry
17536 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
17537 + | au_ftest_wrdir(args->flags, TMP_WHENTRY);
17538 + struct super_block *sb;
17539 + struct dentry *parent;
17540 + struct au_sbinfo *sbinfo;
17542 + sb = dentry->d_sb;
17543 + sbinfo = au_sbi(sb);
17544 + parent = dget_parent(dentry);
17545 + bstart = au_dbstart(dentry);
17547 + if (args->force_btgt < 0) {
17548 + if (src_dentry) {
17549 + src_bstart = au_dbstart(src_dentry);
17550 + if (src_bstart < bstart)
17551 + bcpup = src_bstart;
17552 + } else if (add_entry) {
17554 + if (au_ftest_wrdir(args->flags, ISDIR))
17555 + au_fset_wbr(flags, DIR);
17556 + err = AuWbrCreate(sbinfo, dentry, flags);
17560 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
17562 + err = AuWbrCopyup(sbinfo, dentry);
17564 + if (!IS_ROOT(dentry)) {
17565 + di_read_lock_parent(parent, !AuLock_IR);
17566 + err = AuWbrCopyup(sbinfo, dentry);
17567 + di_read_unlock(parent, !AuLock_IR);
17569 + err = AuWbrCopyup(sbinfo, dentry);
17572 + if (unlikely(err < 0))
17576 + bcpup = args->force_btgt;
17577 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
17580 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
17582 + if (bcpup == bstart)
17583 + goto out; /* success */
17585 + /* copyup the new parent into the branch we process */
17586 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
17588 + if (!dentry->d_inode) {
17589 + au_set_h_dptr(dentry, bstart, NULL);
17590 + au_set_dbstart(dentry, bcpup);
17591 + au_set_dbend(dentry, bcpup);
17593 + AuDebugOn(add_entry && !au_h_dptr(dentry, bcpup));
17601 +/* ---------------------------------------------------------------------- */
17603 +void au_pin_hdir_unlock(struct au_pin *p)
17606 + au_hn_imtx_unlock(p->hdir);
17609 +static int au_pin_hdir_lock(struct au_pin *p)
17617 + /* even if an error happens later, keep this lock */
17618 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
17621 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
17626 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
17627 + p->h_parent, p->br);
17633 +int au_pin_hdir_relock(struct au_pin *p)
17636 + struct inode *h_i;
17637 + struct dentry *h_d[] = {
17642 + err = au_pin_hdir_lock(p);
17643 + if (unlikely(err))
17646 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
17649 + h_i = h_d[i]->d_inode;
17651 + err = !h_i->i_nlink;
17658 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
17660 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
17661 + p->hdir->hi_inode->i_mutex.owner = task;
17665 +void au_pin_hdir_acquire_nest(struct au_pin *p)
17668 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
17669 + p->lsc_hi, 0, NULL, _RET_IP_);
17670 + au_pin_hdir_set_owner(p, current);
17674 +void au_pin_hdir_release(struct au_pin *p)
17677 + au_pin_hdir_set_owner(p, p->task);
17678 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
17682 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
17684 + if (pin && pin->parent)
17685 + return au_h_dptr(pin->parent, pin->bindex);
17689 +void au_unpin(struct au_pin *p)
17692 + au_pin_hdir_unlock(p);
17693 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
17694 + vfsub_mnt_drop_write(p->h_mnt);
17698 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17699 + di_read_unlock(p->parent, AuLock_IR);
17700 + iput(p->hdir->hi_inode);
17702 + p->parent = NULL;
17705 + /* do not clear p->task */
17708 +int au_do_pin(struct au_pin *p)
17711 + struct super_block *sb;
17712 + struct inode *h_dir;
17715 + sb = p->dentry->d_sb;
17716 + p->br = au_sbr(sb, p->bindex);
17717 + if (IS_ROOT(p->dentry)) {
17718 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17719 + p->h_mnt = au_br_mnt(p->br);
17720 + err = vfsub_mnt_want_write(p->h_mnt);
17721 + if (unlikely(err)) {
17722 + au_fclr_pin(p->flags, MNT_WRITE);
17729 + p->h_dentry = NULL;
17730 + if (p->bindex <= au_dbend(p->dentry))
17731 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
17733 + p->parent = dget_parent(p->dentry);
17734 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17735 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
17738 + p->h_parent = au_h_dptr(p->parent, p->bindex);
17739 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
17741 + h_dir = p->hdir->hi_inode;
17745 + * if DI_LOCKED is not set, then p->parent may be different
17746 + * and h_parent can be NULL.
17748 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
17750 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17751 + di_read_unlock(p->parent, AuLock_IR);
17753 + p->parent = NULL;
17757 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
17758 + p->h_mnt = au_br_mnt(p->br);
17759 + err = vfsub_mnt_want_write(p->h_mnt);
17760 + if (unlikely(err)) {
17761 + au_fclr_pin(p->flags, MNT_WRITE);
17762 + if (!au_ftest_pin(p->flags, DI_LOCKED))
17763 + di_read_unlock(p->parent, AuLock_IR);
17765 + p->parent = NULL;
17771 + err = au_pin_hdir_lock(p);
17773 + goto out; /* success */
17776 + pr_err("err %d\n", err);
17777 + err = au_busy_or_stale();
17782 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
17783 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
17784 + unsigned int udba, unsigned char flags)
17786 + p->dentry = dentry;
17788 + p->lsc_di = lsc_di;
17789 + p->lsc_hi = lsc_hi;
17790 + p->flags = flags;
17791 + p->bindex = bindex;
17793 + p->parent = NULL;
17797 + p->h_dentry = NULL;
17798 + p->h_parent = NULL;
17800 + p->task = current;
17803 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
17804 + unsigned int udba, unsigned char flags)
17806 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
17808 + return au_do_pin(pin);
17811 +/* ---------------------------------------------------------------------- */
17814 + * ->setattr() and ->getattr() are called in various cases.
17815 + * chmod, stat: dentry is revalidated.
17816 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
17818 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
17820 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
17821 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
17824 + struct inode *inode;
17825 + struct dentry *parent;
17828 + inode = dentry->d_inode;
17829 + if (au_digen_test(dentry, sigen)) {
17830 + parent = dget_parent(dentry);
17831 + di_read_lock_parent(parent, AuLock_IR);
17832 + err = au_refresh_dentry(dentry, parent);
17833 + di_read_unlock(parent, AuLock_IR);
17841 +#define AuIcpup_DID_CPUP 1
17842 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
17843 +#define au_fset_icpup(flags, name) \
17844 + do { (flags) |= AuIcpup_##name; } while (0)
17845 +#define au_fclr_icpup(flags, name) \
17846 + do { (flags) &= ~AuIcpup_##name; } while (0)
17848 +struct au_icpup_args {
17849 + unsigned char flags;
17850 + unsigned char pin_flags;
17851 + aufs_bindex_t btgt;
17852 + unsigned int udba;
17853 + struct au_pin pin;
17854 + struct path h_path;
17855 + struct inode *h_inode;
17858 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
17859 + struct au_icpup_args *a)
17863 + aufs_bindex_t bstart, ibstart;
17864 + struct dentry *hi_wh, *parent;
17865 + struct inode *inode;
17866 + struct au_wr_dir_args wr_dir_args = {
17867 + .force_btgt = -1,
17871 + bstart = au_dbstart(dentry);
17872 + inode = dentry->d_inode;
17873 + if (S_ISDIR(inode->i_mode))
17874 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
17875 + /* plink or hi_wh() case */
17876 + ibstart = au_ibstart(inode);
17877 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
17878 + wr_dir_args.force_btgt = ibstart;
17879 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17880 + if (unlikely(err < 0))
17883 + if (err != bstart)
17884 + au_fset_icpup(a->flags, DID_CPUP);
17887 + a->pin_flags = AuPin_MNT_WRITE;
17889 + if (!IS_ROOT(dentry)) {
17890 + au_fset_pin(a->pin_flags, DI_LOCKED);
17891 + parent = dget_parent(dentry);
17892 + di_write_lock_parent(parent);
17895 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
17896 + if (unlikely(err))
17899 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17900 + a->h_inode = a->h_path.dentry->d_inode;
17901 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17903 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
17904 + sz = ia->ia_size;
17905 + mutex_unlock(&a->h_inode->i_mutex);
17908 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
17909 + hi_wh = au_hi_wh(inode, a->btgt);
17911 + struct au_cp_generic cpg = {
17912 + .dentry = dentry,
17918 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
17919 + if (unlikely(err))
17921 + hi_wh = au_hi_wh(inode, a->btgt);
17922 + /* todo: revalidate hi_wh? */
17927 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
17928 + di_downgrade_lock(parent, AuLock_IR);
17932 + if (!au_ftest_icpup(a->flags, DID_CPUP))
17933 + goto out; /* success */
17935 + if (!d_unhashed(dentry)) {
17936 + struct au_cp_generic cpg = {
17937 + .dentry = dentry,
17942 + .flags = AuCpup_DTIME | AuCpup_HOPEN
17944 + err = au_sio_cpup_simple(&cpg);
17946 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17947 + } else if (!hi_wh)
17948 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
17950 + a->h_path.dentry = hi_wh; /* do not dget here */
17953 + a->h_inode = a->h_path.dentry->d_inode;
17955 + goto out; /* success */
17956 + au_unpin(&a->pin);
17959 + di_write_unlock(parent);
17964 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
17968 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
17971 + struct inode *inode, *delegated;
17972 + struct super_block *sb;
17973 + struct file *file;
17974 + struct au_icpup_args *a;
17976 + inode = dentry->d_inode;
17977 + IMustLock(inode);
17980 + a = kzalloc(sizeof(*a), GFP_NOFS);
17981 + if (unlikely(!a))
17984 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
17985 + ia->ia_valid &= ~ATTR_MODE;
17988 + sb = dentry->d_sb;
17989 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17990 + if (unlikely(err))
17993 + if (ia->ia_valid & ATTR_FILE) {
17994 + /* currently ftruncate(2) only */
17995 + AuDebugOn(!S_ISREG(inode->i_mode));
17996 + file = ia->ia_file;
17997 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
17998 + if (unlikely(err))
18000 + ia->ia_file = au_hf_top(file);
18001 + a->udba = AuOpt_UDBA_NONE;
18003 + /* fchmod() doesn't pass ia_file */
18004 + a->udba = au_opt_udba(sb);
18005 + di_write_lock_child(dentry);
18006 + /* no d_unlinked(), to set UDBA_NONE for root */
18007 + if (d_unhashed(dentry))
18008 + a->udba = AuOpt_UDBA_NONE;
18009 + if (a->udba != AuOpt_UDBA_NONE) {
18010 + AuDebugOn(IS_ROOT(dentry));
18011 + err = au_reval_for_attr(dentry, au_sigen(sb));
18012 + if (unlikely(err))
18017 + err = au_pin_and_icpup(dentry, ia, a);
18018 + if (unlikely(err < 0))
18020 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
18021 + ia->ia_file = NULL;
18022 + ia->ia_valid &= ~ATTR_FILE;
18025 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
18026 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
18027 + == (ATTR_MODE | ATTR_CTIME)) {
18028 + err = security_path_chmod(&a->h_path, ia->ia_mode);
18029 + if (unlikely(err))
18031 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
18032 + && (ia->ia_valid & ATTR_CTIME)) {
18033 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
18034 + if (unlikely(err))
18038 + if (ia->ia_valid & ATTR_SIZE) {
18041 + if (ia->ia_size < i_size_read(inode))
18043 + truncate_setsize(inode, ia->ia_size);
18046 + if (ia->ia_valid & ATTR_FILE)
18048 + mutex_unlock(&a->h_inode->i_mutex);
18049 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
18050 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18052 + delegated = NULL;
18054 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
18056 + err = break_deleg_wait(&delegated);
18064 + au_cpup_attr_changeable(inode);
18067 + mutex_unlock(&a->h_inode->i_mutex);
18068 + au_unpin(&a->pin);
18069 + if (unlikely(err))
18070 + au_update_dbstart(dentry);
18072 + di_write_unlock(dentry);
18074 + fi_write_unlock(file);
18075 + ia->ia_file = file;
18076 + ia->ia_valid |= ATTR_FILE;
18079 + si_read_unlock(sb);
18087 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
18088 + unsigned int nlink)
18092 + inode->i_mode = st->mode;
18093 + /* don't i_[ug]id_write() here */
18094 + inode->i_uid = st->uid;
18095 + inode->i_gid = st->gid;
18096 + inode->i_atime = st->atime;
18097 + inode->i_mtime = st->mtime;
18098 + inode->i_ctime = st->ctime;
18100 + au_cpup_attr_nlink(inode, /*force*/0);
18101 + if (S_ISDIR(inode->i_mode)) {
18102 + n = inode->i_nlink;
18105 + smp_mb(); /* for i_nlink */
18106 + /* 0 can happen */
18107 + set_nlink(inode, n);
18110 + spin_lock(&inode->i_lock);
18111 + inode->i_blocks = st->blocks;
18112 + i_size_write(inode, st->size);
18113 + spin_unlock(&inode->i_lock);
18116 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
18117 + struct dentry *dentry, struct kstat *st)
18120 + unsigned int mnt_flags;
18121 + aufs_bindex_t bindex;
18122 + unsigned char udba_none, positive;
18123 + struct super_block *sb, *h_sb;
18124 + struct inode *inode;
18125 + struct path h_path;
18127 + sb = dentry->d_sb;
18128 + inode = dentry->d_inode;
18129 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18130 + if (unlikely(err))
18132 + mnt_flags = au_mntflags(sb);
18133 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
18135 + /* support fstat(2) */
18136 + if (!d_unlinked(dentry) && !udba_none) {
18137 + unsigned int sigen = au_sigen(sb);
18138 + err = au_digen_test(dentry, sigen);
18140 + di_read_lock_child(dentry, AuLock_IR);
18141 + err = au_dbrange_test(dentry);
18142 + if (unlikely(err))
18145 + AuDebugOn(IS_ROOT(dentry));
18146 + di_write_lock_child(dentry);
18147 + err = au_dbrange_test(dentry);
18149 + err = au_reval_for_attr(dentry, sigen);
18150 + di_downgrade_lock(dentry, AuLock_IR);
18151 + if (unlikely(err))
18155 + di_read_lock_child(dentry, AuLock_IR);
18157 + bindex = au_ibstart(inode);
18158 + h_path.mnt = au_sbr_mnt(sb, bindex);
18159 + h_sb = h_path.mnt->mnt_sb;
18160 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
18161 + goto out_fill; /* success */
18163 + h_path.dentry = NULL;
18164 + if (au_dbstart(dentry) == bindex)
18165 + h_path.dentry = dget(au_h_dptr(dentry, bindex));
18166 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
18167 + h_path.dentry = au_plink_lkup(inode, bindex);
18168 + if (IS_ERR(h_path.dentry))
18169 + goto out_fill; /* pretending success */
18171 + /* illegally overlapped or something */
18172 + if (unlikely(!h_path.dentry))
18173 + goto out_fill; /* pretending success */
18175 + positive = !!h_path.dentry->d_inode;
18177 + err = vfs_getattr(&h_path, st);
18178 + dput(h_path.dentry);
18181 + au_refresh_iattr(inode, st,
18182 + h_path.dentry->d_inode->i_nlink);
18183 + goto out_fill; /* success */
18189 + generic_fillattr(inode, st);
18191 + di_read_unlock(dentry, AuLock_IR);
18192 + si_read_unlock(sb);
18198 +/* ---------------------------------------------------------------------- */
18200 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
18204 + struct super_block *sb;
18205 + struct dentry *h_dentry;
18208 + h_dentry = au_h_dptr(dentry, bindex);
18209 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
18212 + err = security_inode_readlink(h_dentry);
18213 + if (unlikely(err))
18216 + sb = dentry->d_sb;
18217 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
18218 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
18219 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
18221 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
18227 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
18231 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
18232 + if (unlikely(err))
18234 + err = au_d_hashed_positive(dentry);
18236 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
18237 + aufs_read_unlock(dentry, AuLock_IR);
18243 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
18246 + mm_segment_t old_fs;
18253 + buf.k = (void *)__get_free_page(GFP_NOFS);
18254 + if (unlikely(!buf.k))
18257 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
18258 + if (unlikely(err))
18261 + err = au_d_hashed_positive(dentry);
18263 + old_fs = get_fs();
18264 + set_fs(KERNEL_DS);
18265 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
18268 + aufs_read_unlock(dentry, AuLock_IR);
18272 + /* will be freed by put_link */
18273 + nd_set_link(nd, buf.k);
18274 + return NULL; /* success */
18278 + free_page((unsigned long)buf.k);
18281 + return ERR_PTR(err);
18284 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
18285 + struct nameidata *nd, void *cookie __maybe_unused)
18289 + p = nd_get_link(nd);
18290 + if (!IS_ERR_OR_NULL(p))
18291 + free_page((unsigned long)p);
18294 +/* ---------------------------------------------------------------------- */
18296 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
18299 + struct super_block *sb;
18300 + struct inode *h_inode;
18302 + sb = inode->i_sb;
18303 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
18305 + si_read_lock(sb, AuLock_FLUSH);
18306 + ii_write_lock_child(inode);
18308 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18309 + err = vfsub_update_time(h_inode, ts, flags);
18311 + ii_write_unlock(inode);
18312 + si_read_unlock(sb);
18317 +/* ---------------------------------------------------------------------- */
18319 +struct inode_operations aufs_symlink_iop = {
18320 + .permission = aufs_permission,
18321 + .setattr = aufs_setattr,
18322 + .getattr = aufs_getattr,
18324 + .readlink = aufs_readlink,
18325 + .follow_link = aufs_follow_link,
18326 + .put_link = aufs_put_link,
18328 + /* .update_time = aufs_update_time */
18331 +struct inode_operations aufs_dir_iop = {
18332 + .create = aufs_create,
18333 + .lookup = aufs_lookup,
18334 + .link = aufs_link,
18335 + .unlink = aufs_unlink,
18336 + .symlink = aufs_symlink,
18337 + .mkdir = aufs_mkdir,
18338 + .rmdir = aufs_rmdir,
18339 + .mknod = aufs_mknod,
18340 + .rename = aufs_rename,
18342 + .permission = aufs_permission,
18343 + .setattr = aufs_setattr,
18344 + .getattr = aufs_getattr,
18346 + .update_time = aufs_update_time
18347 + /* no support for atomic_open() */
18350 +struct inode_operations aufs_iop = {
18351 + .permission = aufs_permission,
18352 + .setattr = aufs_setattr,
18353 + .getattr = aufs_getattr,
18355 + .update_time = aufs_update_time
18357 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
18358 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
18359 +++ linux/fs/aufs/i_op_del.c 2014-04-24 22:11:10.855269116 +0200
18362 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18364 + * This program, aufs is free software; you can redistribute it and/or modify
18365 + * it under the terms of the GNU General Public License as published by
18366 + * the Free Software Foundation; either version 2 of the License, or
18367 + * (at your option) any later version.
18369 + * This program is distributed in the hope that it will be useful,
18370 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18371 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18372 + * GNU General Public License for more details.
18374 + * You should have received a copy of the GNU General Public License
18375 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18379 + * inode operations (del entry)
18385 + * decide if a new whiteout for @dentry is necessary or not.
18386 + * when it is necessary, prepare the parent dir for the upper branch whose
18387 + * branch index is @bcpup for creation. the actual creation of the whiteout will
18388 + * be done by caller.
18390 + * 0: wh is unnecessary
18391 + * plus: wh is necessary
18394 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
18396 + int need_wh, err;
18397 + aufs_bindex_t bstart;
18398 + struct super_block *sb;
18400 + sb = dentry->d_sb;
18401 + bstart = au_dbstart(dentry);
18402 + if (*bcpup < 0) {
18404 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
18405 + err = AuWbrCopyup(au_sbi(sb), dentry);
18407 + if (unlikely(err < 0))
18411 + AuDebugOn(bstart < *bcpup
18412 + || au_test_ro(sb, *bcpup, dentry->d_inode));
18413 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
18415 + if (*bcpup != bstart) {
18416 + err = au_cpup_dirs(dentry, *bcpup);
18417 + if (unlikely(err))
18421 + struct au_dinfo *dinfo, *tmp;
18423 + need_wh = -ENOMEM;
18424 + dinfo = au_di(dentry);
18425 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
18427 + au_di_cp(tmp, dinfo);
18428 + au_di_swap(tmp, dinfo);
18429 + /* returns the number of positive dentries */
18430 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
18431 + au_di_swap(tmp, dinfo);
18432 + au_rw_write_unlock(&tmp->di_rwsem);
18436 + AuDbg("need_wh %d\n", need_wh);
18444 + * simple tests for the del-entry operations.
18445 + * following the checks in vfs, plus the parent-child relationship.
18447 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18448 + struct dentry *h_parent, int isdir)
18452 + struct dentry *h_dentry, *h_latest;
18453 + struct inode *h_inode;
18455 + h_dentry = au_h_dptr(dentry, bindex);
18456 + h_inode = h_dentry->d_inode;
18457 + if (dentry->d_inode) {
18459 + if (unlikely(!h_inode || !h_inode->i_nlink))
18462 + h_mode = h_inode->i_mode;
18465 + if (unlikely(S_ISDIR(h_mode)))
18467 + } else if (unlikely(!S_ISDIR(h_mode))) {
18472 + /* rename(2) case */
18474 + if (unlikely(h_inode))
18479 + /* expected parent dir is locked */
18480 + if (unlikely(h_parent != h_dentry->d_parent))
18485 + * rmdir a dir may break the consistency on some filesystem.
18486 + * let's try heavy test.
18489 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
18492 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
18493 + au_sbr(dentry->d_sb, bindex));
18495 + if (IS_ERR(h_latest))
18497 + if (h_latest == h_dentry)
18506 + * decide the branch where we operate for @dentry. the branch index will be set
18507 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
18508 + * dir for reverting.
18509 + * when a new whiteout is necessary, create it.
18511 +static struct dentry*
18512 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
18513 + struct au_dtime *dt, struct au_pin *pin)
18515 + struct dentry *wh_dentry;
18516 + struct super_block *sb;
18517 + struct path h_path;
18518 + int err, need_wh;
18519 + unsigned int udba;
18520 + aufs_bindex_t bcpup;
18522 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
18523 + wh_dentry = ERR_PTR(need_wh);
18524 + if (unlikely(need_wh < 0))
18527 + sb = dentry->d_sb;
18528 + udba = au_opt_udba(sb);
18530 + err = au_pin(pin, dentry, bcpup, udba,
18531 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18532 + wh_dentry = ERR_PTR(err);
18533 + if (unlikely(err))
18536 + h_path.dentry = au_pinned_h_parent(pin);
18537 + if (udba != AuOpt_UDBA_NONE
18538 + && au_dbstart(dentry) == bcpup) {
18539 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
18540 + wh_dentry = ERR_PTR(err);
18541 + if (unlikely(err))
18545 + h_path.mnt = au_sbr_mnt(sb, bcpup);
18546 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
18547 + wh_dentry = NULL;
18549 + goto out; /* success, no need to create whiteout */
18551 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
18552 + if (IS_ERR(wh_dentry))
18555 + /* returns with the parent is locked and wh_dentry is dget-ed */
18556 + goto out; /* success */
18561 + return wh_dentry;
18565 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
18566 + * in order to be revertible and save time for removing many child whiteouts
18568 + * returns 1 when there are too many child whiteout and caller should remove
18569 + * them asynchronously. returns 0 when the number of children is enough small to
18570 + * remove now or the branch fs is a remote fs.
18571 + * otherwise return an error.
18573 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
18574 + struct au_nhash *whlist, struct inode *dir)
18576 + int rmdir_later, err, dirwh;
18577 + struct dentry *h_dentry;
18578 + struct super_block *sb;
18580 + sb = dentry->d_sb;
18581 + SiMustAnyLock(sb);
18582 + h_dentry = au_h_dptr(dentry, bindex);
18583 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
18584 + if (unlikely(err))
18587 + /* stop monitoring */
18588 + au_hn_free(au_hi(dentry->d_inode, bindex));
18590 + if (!au_test_fs_remote(h_dentry->d_sb)) {
18591 + dirwh = au_sbi(sb)->si_dirwh;
18592 + rmdir_later = (dirwh <= 1);
18593 + if (!rmdir_later)
18594 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
18597 + return rmdir_later;
18600 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
18601 + if (unlikely(err)) {
18602 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
18603 + h_dentry, bindex, err);
18613 + * final procedure for deleting a entry.
18614 + * maintain dentry and iattr.
18616 +static void epilog(struct inode *dir, struct dentry *dentry,
18617 + aufs_bindex_t bindex)
18619 + struct inode *inode;
18621 + inode = dentry->d_inode;
18623 + inode->i_ctime = dir->i_ctime;
18625 + if (au_ibstart(dir) == bindex)
18626 + au_cpup_attr_timesizes(dir);
18627 + dir->i_version++;
18631 + * when an error happened, remove the created whiteout and revert everything.
18633 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
18634 + aufs_bindex_t bwh, struct dentry *wh_dentry,
18635 + struct dentry *dentry, struct au_dtime *dt)
18638 + struct path h_path = {
18639 + .dentry = wh_dentry,
18640 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
18643 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
18645 + au_set_dbwh(dentry, bwh);
18646 + au_dtime_revert(dt);
18650 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
18654 +/* ---------------------------------------------------------------------- */
18656 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
18659 + aufs_bindex_t bwh, bindex, bstart;
18660 + struct inode *inode, *h_dir, *delegated;
18661 + struct dentry *parent, *wh_dentry;
18662 + /* to reuduce stack size */
18664 + struct au_dtime dt;
18665 + struct au_pin pin;
18666 + struct path h_path;
18672 + a = kmalloc(sizeof(*a), GFP_NOFS);
18673 + if (unlikely(!a))
18676 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18677 + if (unlikely(err))
18679 + err = au_d_hashed_positive(dentry);
18680 + if (unlikely(err))
18682 + inode = dentry->d_inode;
18683 + IMustLock(inode);
18685 + if (unlikely(S_ISDIR(inode->i_mode)))
18686 + goto out_unlock; /* possible? */
18688 + bstart = au_dbstart(dentry);
18689 + bwh = au_dbwh(dentry);
18691 + parent = dentry->d_parent; /* dir inode is locked */
18692 + di_write_lock_parent(parent);
18693 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
18695 + err = PTR_ERR(wh_dentry);
18696 + if (IS_ERR(wh_dentry))
18699 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
18700 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18701 + dget(a->h_path.dentry);
18702 + if (bindex == bstart) {
18703 + h_dir = au_pinned_h_dir(&a->pin);
18704 + delegated = NULL;
18705 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
18706 + if (unlikely(err == -EWOULDBLOCK)) {
18707 + pr_warn("cannot retry for NFSv4 delegation"
18708 + " for an internal unlink\n");
18712 + /* dir inode is locked */
18713 + h_dir = wh_dentry->d_parent->d_inode;
18714 + IMustLock(h_dir);
18719 + vfsub_drop_nlink(inode);
18720 + epilog(dir, dentry, bindex);
18722 + /* update target timestamps */
18723 + if (bindex == bstart) {
18724 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
18726 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
18728 + /* todo: this timestamp may be reverted later */
18729 + inode->i_ctime = h_dir->i_ctime;
18730 + goto out_unpin; /* success */
18737 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18744 + au_unpin(&a->pin);
18746 + dput(a->h_path.dentry);
18748 + di_write_unlock(parent);
18750 + aufs_read_unlock(dentry, AuLock_DW);
18757 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
18759 + int err, rmdir_later;
18760 + aufs_bindex_t bwh, bindex, bstart;
18761 + struct inode *inode;
18762 + struct dentry *parent, *wh_dentry, *h_dentry;
18763 + struct au_whtmp_rmdir *args;
18764 + /* to reuduce stack size */
18766 + struct au_dtime dt;
18767 + struct au_pin pin;
18773 + a = kmalloc(sizeof(*a), GFP_NOFS);
18774 + if (unlikely(!a))
18777 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18778 + if (unlikely(err))
18780 + err = au_alive_dir(dentry);
18781 + if (unlikely(err))
18783 + inode = dentry->d_inode;
18784 + IMustLock(inode);
18786 + if (unlikely(!S_ISDIR(inode->i_mode)))
18787 + goto out_unlock; /* possible? */
18790 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
18791 + if (unlikely(!args))
18794 + parent = dentry->d_parent; /* dir inode is locked */
18795 + di_write_lock_parent(parent);
18796 + err = au_test_empty(dentry, &args->whlist);
18797 + if (unlikely(err))
18800 + bstart = au_dbstart(dentry);
18801 + bwh = au_dbwh(dentry);
18803 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
18805 + err = PTR_ERR(wh_dentry);
18806 + if (IS_ERR(wh_dentry))
18809 + h_dentry = au_h_dptr(dentry, bstart);
18812 + if (bindex == bstart) {
18813 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
18815 + rmdir_later = err;
18819 + /* stop monitoring */
18820 + au_hn_free(au_hi(inode, bstart));
18822 + /* dir inode is locked */
18823 + IMustLock(wh_dentry->d_parent->d_inode);
18828 + vfsub_dead_dir(inode);
18829 + au_set_dbdiropq(dentry, -1);
18830 + epilog(dir, dentry, bindex);
18832 + if (rmdir_later) {
18833 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
18837 + goto out_unpin; /* success */
18845 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18852 + au_unpin(&a->pin);
18856 + di_write_unlock(parent);
18858 + au_whtmp_rmdir_free(args);
18860 + aufs_read_unlock(dentry, AuLock_DW);
18867 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
18868 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
18869 +++ linux/fs/aufs/i_op_ren.c 2014-04-24 22:11:10.855269116 +0200
18872 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18874 + * This program, aufs is free software; you can redistribute it and/or modify
18875 + * it under the terms of the GNU General Public License as published by
18876 + * the Free Software Foundation; either version 2 of the License, or
18877 + * (at your option) any later version.
18879 + * This program is distributed in the hope that it will be useful,
18880 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18881 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18882 + * GNU General Public License for more details.
18884 + * You should have received a copy of the GNU General Public License
18885 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18889 + * inode operation (rename entry)
18890 + * todo: this is crazy monster
18895 +enum { AuSRC, AuDST, AuSrcDst };
18896 +enum { AuPARENT, AuCHILD, AuParentChild };
18898 +#define AuRen_ISDIR 1
18899 +#define AuRen_ISSAMEDIR (1 << 1)
18900 +#define AuRen_WHSRC (1 << 2)
18901 +#define AuRen_WHDST (1 << 3)
18902 +#define AuRen_MNT_WRITE (1 << 4)
18903 +#define AuRen_DT_DSTDIR (1 << 5)
18904 +#define AuRen_DIROPQ (1 << 6)
18905 +#define AuRen_CPUP (1 << 7)
18906 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
18907 +#define au_fset_ren(flags, name) \
18908 + do { (flags) |= AuRen_##name; } while (0)
18909 +#define au_fclr_ren(flags, name) \
18910 + do { (flags) &= ~AuRen_##name; } while (0)
18912 +struct au_ren_args {
18914 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
18916 + struct inode *dir, *inode;
18917 + struct au_hinode *hdir;
18918 + struct au_dtime dt[AuParentChild];
18919 + aufs_bindex_t bstart;
18922 +#define src_dentry sd[AuSRC].dentry
18923 +#define src_dir sd[AuSRC].dir
18924 +#define src_inode sd[AuSRC].inode
18925 +#define src_h_dentry sd[AuSRC].h_dentry
18926 +#define src_parent sd[AuSRC].parent
18927 +#define src_h_parent sd[AuSRC].h_parent
18928 +#define src_wh_dentry sd[AuSRC].wh_dentry
18929 +#define src_hdir sd[AuSRC].hdir
18930 +#define src_h_dir sd[AuSRC].hdir->hi_inode
18931 +#define src_dt sd[AuSRC].dt
18932 +#define src_bstart sd[AuSRC].bstart
18934 +#define dst_dentry sd[AuDST].dentry
18935 +#define dst_dir sd[AuDST].dir
18936 +#define dst_inode sd[AuDST].inode
18937 +#define dst_h_dentry sd[AuDST].h_dentry
18938 +#define dst_parent sd[AuDST].parent
18939 +#define dst_h_parent sd[AuDST].h_parent
18940 +#define dst_wh_dentry sd[AuDST].wh_dentry
18941 +#define dst_hdir sd[AuDST].hdir
18942 +#define dst_h_dir sd[AuDST].hdir->hi_inode
18943 +#define dst_dt sd[AuDST].dt
18944 +#define dst_bstart sd[AuDST].bstart
18946 + struct dentry *h_trap;
18947 + struct au_branch *br;
18948 + struct au_hinode *src_hinode;
18949 + struct path h_path;
18950 + struct au_nhash whlist;
18951 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
18953 + unsigned int flags;
18955 + struct au_whtmp_rmdir *thargs;
18956 + struct dentry *h_dst;
18959 +/* ---------------------------------------------------------------------- */
18962 + * functions for reverting.
18963 + * when an error happened in a single rename systemcall, we should revert
18964 + * everything as if nothing happend.
18965 + * we don't need to revert the copied-up/down the parent dir since they are
18969 +#define RevertFailure(fmt, ...) do { \
18970 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
18971 + ##__VA_ARGS__, err, rerr); \
18975 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
18979 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18980 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
18981 + au_hn_imtx_unlock(a->src_hinode);
18982 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
18984 + RevertFailure("remove diropq %pd", a->src_dentry);
18987 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
18990 + struct inode *delegated;
18992 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
18993 + a->src_h_parent);
18994 + rerr = PTR_ERR(a->h_path.dentry);
18995 + if (IS_ERR(a->h_path.dentry)) {
18996 + RevertFailure("lkup one %pd", a->src_dentry);
19000 + delegated = NULL;
19001 + rerr = vfsub_rename(a->dst_h_dir,
19002 + au_h_dptr(a->src_dentry, a->btgt),
19003 + a->src_h_dir, &a->h_path, &delegated);
19004 + if (unlikely(rerr == -EWOULDBLOCK)) {
19005 + pr_warn("cannot retry for NFSv4 delegation"
19006 + " for an internal rename\n");
19009 + d_drop(a->h_path.dentry);
19010 + dput(a->h_path.dentry);
19011 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
19013 + RevertFailure("rename %pd", a->src_dentry);
19016 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
19020 + a->h_path.dentry = a->dst_h_dentry;
19021 + /* no delegation since it is just created */
19022 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL,
19024 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
19025 + au_set_dbstart(a->src_dentry, a->src_bstart);
19027 + RevertFailure("unlink %pd", a->dst_h_dentry);
19030 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
19033 + struct inode *delegated;
19035 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
19036 + a->dst_h_parent);
19037 + rerr = PTR_ERR(a->h_path.dentry);
19038 + if (IS_ERR(a->h_path.dentry)) {
19039 + RevertFailure("lkup one %pd", a->dst_dentry);
19042 + if (a->h_path.dentry->d_inode) {
19043 + d_drop(a->h_path.dentry);
19044 + dput(a->h_path.dentry);
19048 + delegated = NULL;
19049 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
19051 + if (unlikely(rerr == -EWOULDBLOCK)) {
19052 + pr_warn("cannot retry for NFSv4 delegation"
19053 + " for an internal rename\n");
19056 + d_drop(a->h_path.dentry);
19057 + dput(a->h_path.dentry);
19059 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
19061 + RevertFailure("rename %pd", a->h_dst);
19064 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
19068 + a->h_path.dentry = a->src_wh_dentry;
19069 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
19070 + au_set_dbwh(a->src_dentry, a->src_bwh);
19072 + RevertFailure("unlink %pd", a->src_wh_dentry);
19074 +#undef RevertFailure
19076 +/* ---------------------------------------------------------------------- */
19079 + * when we have to copyup the renaming entry, do it with the rename-target name
19080 + * in order to minimize the cost (the later actual rename is unnecessary).
19081 + * otherwise rename it on the target branch.
19083 +static int au_ren_or_cpup(struct au_ren_args *a)
19086 + struct dentry *d;
19087 + struct inode *delegated;
19089 + d = a->src_dentry;
19090 + if (au_dbstart(d) == a->btgt) {
19091 + a->h_path.dentry = a->dst_h_dentry;
19092 + if (au_ftest_ren(a->flags, DIROPQ)
19093 + && au_dbdiropq(d) == a->btgt)
19094 + au_fclr_ren(a->flags, DIROPQ);
19095 + AuDebugOn(au_dbstart(d) != a->btgt);
19096 + delegated = NULL;
19097 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
19098 + a->dst_h_dir, &a->h_path, &delegated);
19099 + if (unlikely(err == -EWOULDBLOCK)) {
19100 + pr_warn("cannot retry for NFSv4 delegation"
19101 + " for an internal rename\n");
19107 + if (!err && a->h_dst)
19108 + /* it will be set to dinfo later */
19114 +/* cf. aufs_rmdir() */
19115 +static int au_ren_del_whtmp(struct au_ren_args *a)
19118 + struct inode *dir;
19120 + dir = a->dst_dir;
19121 + SiMustAnyLock(dir->i_sb);
19122 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
19123 + au_sbi(dir->i_sb)->si_dirwh)
19124 + || au_test_fs_remote(a->h_dst->d_sb)) {
19125 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
19126 + if (unlikely(err))
19127 + pr_warn("failed removing whtmp dir %pd (%d), "
19128 + "ignored.\n", a->h_dst, err);
19130 + au_nhash_wh_free(&a->thargs->whlist);
19131 + a->thargs->whlist = a->whlist;
19132 + a->whlist.nh_num = 0;
19133 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
19135 + a->thargs = NULL;
19141 +/* make it 'opaque' dir. */
19142 +static int au_ren_diropq(struct au_ren_args *a)
19145 + struct dentry *diropq;
19148 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
19149 + a->src_hinode = au_hi(a->src_inode, a->btgt);
19150 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
19151 + diropq = au_diropq_create(a->src_dentry, a->btgt);
19152 + au_hn_imtx_unlock(a->src_hinode);
19153 + if (IS_ERR(diropq))
19154 + err = PTR_ERR(diropq);
19160 +static int do_rename(struct au_ren_args *a)
19163 + struct dentry *d, *h_d;
19165 + /* prepare workqueue args for asynchronous rmdir */
19166 + h_d = a->dst_h_dentry;
19167 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
19169 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
19170 + if (unlikely(!a->thargs))
19172 + a->h_dst = dget(h_d);
19175 + /* create whiteout for src_dentry */
19176 + if (au_ftest_ren(a->flags, WHSRC)) {
19177 + a->src_bwh = au_dbwh(a->src_dentry);
19178 + AuDebugOn(a->src_bwh >= 0);
19180 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
19181 + err = PTR_ERR(a->src_wh_dentry);
19182 + if (IS_ERR(a->src_wh_dentry))
19186 + /* lookup whiteout for dentry */
19187 + if (au_ftest_ren(a->flags, WHDST)) {
19188 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
19190 + err = PTR_ERR(h_d);
19193 + if (!h_d->d_inode)
19196 + a->dst_wh_dentry = h_d;
19199 + /* rename dentry to tmpwh */
19201 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
19202 + if (unlikely(err))
19205 + d = a->dst_dentry;
19206 + au_set_h_dptr(d, a->btgt, NULL);
19207 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
19208 + if (unlikely(err))
19210 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
19213 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
19215 + /* rename by vfs_rename or cpup */
19216 + d = a->dst_dentry;
19217 + if (au_ftest_ren(a->flags, ISDIR)
19218 + && (a->dst_wh_dentry
19219 + || au_dbdiropq(d) == a->btgt
19220 + /* hide the lower to keep xino */
19221 + || a->btgt < au_dbend(d)
19222 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
19223 + au_fset_ren(a->flags, DIROPQ);
19224 + err = au_ren_or_cpup(a);
19225 + if (unlikely(err))
19226 + /* leave the copied-up one */
19229 + /* make dir opaque */
19230 + if (au_ftest_ren(a->flags, DIROPQ)) {
19231 + err = au_ren_diropq(a);
19232 + if (unlikely(err))
19236 + /* update target timestamps */
19237 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
19238 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
19239 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
19240 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
19242 + /* remove whiteout for dentry */
19243 + if (a->dst_wh_dentry) {
19244 + a->h_path.dentry = a->dst_wh_dentry;
19245 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
19247 + if (unlikely(err))
19251 + /* remove whtmp */
19253 + au_ren_del_whtmp(a); /* ignore this error */
19256 + goto out_success;
19259 + if (au_ftest_ren(a->flags, DIROPQ))
19260 + au_ren_rev_diropq(err, a);
19262 + if (!au_ftest_ren(a->flags, CPUP))
19263 + au_ren_rev_rename(err, a);
19265 + au_ren_rev_cpup(err, a);
19269 + au_ren_rev_whtmp(err, a);
19271 + dput(a->dst_wh_dentry);
19272 + a->dst_wh_dentry = NULL;
19274 + if (a->src_wh_dentry)
19275 + au_ren_rev_whsrc(err, a);
19277 + dput(a->src_wh_dentry);
19278 + dput(a->dst_wh_dentry);
19282 + au_whtmp_rmdir_free(a->thargs);
19283 + a->thargs = NULL;
19289 +/* ---------------------------------------------------------------------- */
19292 + * test if @dentry dir can be rename destination or not.
19293 + * success means, it is a logically empty dir.
19295 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
19297 + return au_test_empty(dentry, whlist);
19301 + * test if @dentry dir can be rename source or not.
19302 + * if it can, return 0 and @children is filled.
19304 + * - it is a logically empty dir.
19305 + * - or, it exists on writable branch and has no children including whiteouts
19306 + * on the lower branch.
19308 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
19311 + unsigned int rdhash;
19312 + aufs_bindex_t bstart;
19314 + bstart = au_dbstart(dentry);
19315 + if (bstart != btgt) {
19316 + struct au_nhash whlist;
19318 + SiMustAnyLock(dentry->d_sb);
19319 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
19321 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
19323 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
19324 + if (unlikely(err))
19326 + err = au_test_empty(dentry, &whlist);
19327 + au_nhash_wh_free(&whlist);
19331 + if (bstart == au_dbtaildir(dentry))
19332 + return 0; /* success */
19334 + err = au_test_empty_lower(dentry);
19337 + if (err == -ENOTEMPTY) {
19338 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
19339 + " is not supported\n");
19345 +/* side effect: sets whlist and h_dentry */
19346 +static int au_ren_may_dir(struct au_ren_args *a)
19349 + unsigned int rdhash;
19350 + struct dentry *d;
19352 + d = a->dst_dentry;
19353 + SiMustAnyLock(d->d_sb);
19356 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
19357 + rdhash = au_sbi(d->d_sb)->si_rdhash;
19359 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
19360 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
19361 + if (unlikely(err))
19364 + au_set_dbstart(d, a->dst_bstart);
19365 + err = may_rename_dstdir(d, &a->whlist);
19366 + au_set_dbstart(d, a->btgt);
19368 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
19369 + if (unlikely(err))
19372 + d = a->src_dentry;
19373 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
19374 + if (au_ftest_ren(a->flags, ISDIR)) {
19375 + err = may_rename_srcdir(d, a->btgt);
19376 + if (unlikely(err)) {
19377 + au_nhash_wh_free(&a->whlist);
19378 + a->whlist.nh_num = 0;
19385 +/* ---------------------------------------------------------------------- */
19388 + * simple tests for rename.
19389 + * following the checks in vfs, plus the parent-child relationship.
19391 +static int au_may_ren(struct au_ren_args *a)
19394 + struct inode *h_inode;
19396 + if (a->src_bstart == a->btgt) {
19397 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
19398 + au_ftest_ren(a->flags, ISDIR));
19399 + if (unlikely(err))
19402 + if (unlikely(a->src_h_dentry == a->h_trap))
19407 + if (a->dst_bstart != a->btgt)
19410 + err = -ENOTEMPTY;
19411 + if (unlikely(a->dst_h_dentry == a->h_trap))
19415 + h_inode = a->dst_h_dentry->d_inode;
19416 + isdir = !!au_ftest_ren(a->flags, ISDIR);
19417 + if (!a->dst_dentry->d_inode) {
19418 + if (unlikely(h_inode))
19420 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
19423 + if (unlikely(!h_inode || !h_inode->i_nlink))
19425 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
19427 + if (unlikely(err))
19432 + if (unlikely(err == -ENOENT || err == -EEXIST))
19438 +/* ---------------------------------------------------------------------- */
19443 + * - src_dir and dir by lock_rename()
19444 + * - inode if exitsts
19447 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
19449 + * + di_write_lock2_child()
19450 + * + di_write_lock_child()
19451 + * + ii_write_lock_child()
19452 + * + di_write_lock_child2()
19453 + * + ii_write_lock_child2()
19454 + * + src_parent and parent
19455 + * + di_write_lock_parent()
19456 + * + ii_write_lock_parent()
19457 + * + di_write_lock_parent2()
19458 + * + ii_write_lock_parent2()
19459 + * + lower src_dir and dir by vfsub_lock_rename()
19460 + * + verify the every relationships between child and parent. if any
19461 + * of them failed, unlock all and return -EBUSY.
19463 +static void au_ren_unlock(struct au_ren_args *a)
19465 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
19466 + a->dst_h_parent, a->dst_hdir);
19467 + if (au_ftest_ren(a->flags, MNT_WRITE))
19468 + vfsub_mnt_drop_write(au_br_mnt(a->br));
19471 +static int au_ren_lock(struct au_ren_args *a)
19474 + unsigned int udba;
19477 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
19478 + a->src_hdir = au_hi(a->src_dir, a->btgt);
19479 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
19480 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
19482 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
19483 + if (unlikely(err))
19485 + au_fset_ren(a->flags, MNT_WRITE);
19486 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
19487 + a->dst_h_parent, a->dst_hdir);
19488 + udba = au_opt_udba(a->src_dentry->d_sb);
19489 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
19490 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
19491 + err = au_busy_or_stale();
19492 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
19493 + err = au_h_verify(a->src_h_dentry, udba,
19494 + a->src_h_parent->d_inode, a->src_h_parent,
19496 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
19497 + err = au_h_verify(a->dst_h_dentry, udba,
19498 + a->dst_h_parent->d_inode, a->dst_h_parent,
19501 + goto out; /* success */
19503 + err = au_busy_or_stale();
19504 + au_ren_unlock(a);
19510 +/* ---------------------------------------------------------------------- */
19512 +static void au_ren_refresh_dir(struct au_ren_args *a)
19514 + struct inode *dir;
19516 + dir = a->dst_dir;
19517 + dir->i_version++;
19518 + if (au_ftest_ren(a->flags, ISDIR)) {
19519 + /* is this updating defined in POSIX? */
19520 + au_cpup_attr_timesizes(a->src_inode);
19521 + au_cpup_attr_nlink(dir, /*force*/1);
19524 + if (au_ibstart(dir) == a->btgt)
19525 + au_cpup_attr_timesizes(dir);
19527 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19530 + dir = a->src_dir;
19531 + dir->i_version++;
19532 + if (au_ftest_ren(a->flags, ISDIR))
19533 + au_cpup_attr_nlink(dir, /*force*/1);
19534 + if (au_ibstart(dir) == a->btgt)
19535 + au_cpup_attr_timesizes(dir);
19538 +static void au_ren_refresh(struct au_ren_args *a)
19540 + aufs_bindex_t bend, bindex;
19541 + struct dentry *d, *h_d;
19542 + struct inode *i, *h_i;
19543 + struct super_block *sb;
19545 + d = a->dst_dentry;
19548 + /* already dget-ed by au_ren_or_cpup() */
19549 + au_set_h_dptr(d, a->btgt, a->h_dst);
19551 + i = a->dst_inode;
19553 + if (!au_ftest_ren(a->flags, ISDIR))
19554 + vfsub_drop_nlink(i);
19556 + vfsub_dead_dir(i);
19557 + au_cpup_attr_timesizes(i);
19559 + au_update_dbrange(d, /*do_put_zero*/1);
19562 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
19563 + au_set_h_dptr(d, bindex, NULL);
19564 + bend = au_dbend(d);
19565 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
19566 + au_set_h_dptr(d, bindex, NULL);
19567 + au_update_dbrange(d, /*do_put_zero*/0);
19570 + d = a->src_dentry;
19571 + au_set_dbwh(d, -1);
19572 + bend = au_dbend(d);
19573 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
19574 + h_d = au_h_dptr(d, bindex);
19576 + au_set_h_dptr(d, bindex, NULL);
19578 + au_set_dbend(d, a->btgt);
19581 + i = a->src_inode;
19582 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
19583 + return; /* success */
19585 + bend = au_ibend(i);
19586 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
19587 + h_i = au_h_iptr(i, bindex);
19589 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
19590 + /* ignore this error */
19591 + au_set_h_iptr(i, bindex, NULL, 0);
19594 + au_set_ibend(i, a->btgt);
19597 +/* ---------------------------------------------------------------------- */
19599 +/* mainly for link(2) and rename(2) */
19600 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
19602 + aufs_bindex_t bdiropq, bwh;
19603 + struct dentry *parent;
19604 + struct au_branch *br;
19606 + parent = dentry->d_parent;
19607 + IMustLock(parent->d_inode); /* dir is locked */
19609 + bdiropq = au_dbdiropq(parent);
19610 + bwh = au_dbwh(dentry);
19611 + br = au_sbr(dentry->d_sb, btgt);
19612 + if (au_br_rdonly(br)
19613 + || (0 <= bdiropq && bdiropq < btgt)
19614 + || (0 <= bwh && bwh < btgt))
19617 + AuDbg("btgt %d\n", btgt);
19621 +/* sets src_bstart, dst_bstart and btgt */
19622 +static int au_ren_wbr(struct au_ren_args *a)
19625 + struct au_wr_dir_args wr_dir_args = {
19626 + /* .force_btgt = -1, */
19627 + .flags = AuWrDir_ADD_ENTRY
19630 + a->src_bstart = au_dbstart(a->src_dentry);
19631 + a->dst_bstart = au_dbstart(a->dst_dentry);
19632 + if (au_ftest_ren(a->flags, ISDIR))
19633 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19634 + wr_dir_args.force_btgt = a->src_bstart;
19635 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
19636 + wr_dir_args.force_btgt = a->dst_bstart;
19637 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
19638 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
19644 +static void au_ren_dt(struct au_ren_args *a)
19646 + a->h_path.dentry = a->src_h_parent;
19647 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
19648 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
19649 + a->h_path.dentry = a->dst_h_parent;
19650 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
19653 + au_fclr_ren(a->flags, DT_DSTDIR);
19654 + if (!au_ftest_ren(a->flags, ISDIR))
19657 + a->h_path.dentry = a->src_h_dentry;
19658 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
19659 + if (a->dst_h_dentry->d_inode) {
19660 + au_fset_ren(a->flags, DT_DSTDIR);
19661 + a->h_path.dentry = a->dst_h_dentry;
19662 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
19666 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
19668 + struct dentry *h_d;
19669 + struct mutex *h_mtx;
19671 + au_dtime_revert(a->src_dt + AuPARENT);
19672 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
19673 + au_dtime_revert(a->dst_dt + AuPARENT);
19675 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
19676 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
19677 + h_mtx = &h_d->d_inode->i_mutex;
19678 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19679 + au_dtime_revert(a->src_dt + AuCHILD);
19680 + mutex_unlock(h_mtx);
19682 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
19683 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
19684 + h_mtx = &h_d->d_inode->i_mutex;
19685 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
19686 + au_dtime_revert(a->dst_dt + AuCHILD);
19687 + mutex_unlock(h_mtx);
19692 +/* ---------------------------------------------------------------------- */
19694 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
19695 + struct inode *_dst_dir, struct dentry *_dst_dentry)
19698 + /* reduce stack space */
19699 + struct au_ren_args *a;
19701 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
19702 + IMustLock(_src_dir);
19703 + IMustLock(_dst_dir);
19706 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
19707 + a = kzalloc(sizeof(*a), GFP_NOFS);
19708 + if (unlikely(!a))
19711 + a->src_dir = _src_dir;
19712 + a->src_dentry = _src_dentry;
19713 + a->src_inode = a->src_dentry->d_inode;
19714 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
19715 + a->dst_dir = _dst_dir;
19716 + a->dst_dentry = _dst_dentry;
19717 + a->dst_inode = a->dst_dentry->d_inode;
19718 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
19719 + if (a->dst_inode) {
19720 + IMustLock(a->dst_inode);
19721 + au_igrab(a->dst_inode);
19725 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
19726 + if (S_ISDIR(a->src_inode->i_mode)) {
19727 + au_fset_ren(a->flags, ISDIR);
19728 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
19730 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19731 + AuLock_DIR | flags);
19733 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
19735 + if (unlikely(err))
19738 + err = au_d_hashed_positive(a->src_dentry);
19739 + if (unlikely(err))
19742 + if (a->dst_inode) {
19744 + * If it is a dir, VFS unhash dst_dentry before this
19745 + * function. It means we cannot rely upon d_unhashed().
19747 + if (unlikely(!a->dst_inode->i_nlink))
19749 + if (!S_ISDIR(a->dst_inode->i_mode)) {
19750 + err = au_d_hashed_positive(a->dst_dentry);
19751 + if (unlikely(err))
19753 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
19755 + } else if (unlikely(d_unhashed(a->dst_dentry)))
19759 + * is it possible?
19760 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
19761 + * there may exist a problem somewhere else.
19764 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
19767 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
19768 + di_write_lock_parent(a->dst_parent);
19770 + /* which branch we process */
19771 + err = au_ren_wbr(a);
19772 + if (unlikely(err < 0))
19774 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
19775 + a->h_path.mnt = au_br_mnt(a->br);
19777 + /* are they available to be renamed */
19778 + err = au_ren_may_dir(a);
19779 + if (unlikely(err))
19780 + goto out_children;
19782 + /* prepare the writable parent dir on the same branch */
19783 + if (a->dst_bstart == a->btgt) {
19784 + au_fset_ren(a->flags, WHDST);
19786 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
19787 + if (unlikely(err))
19788 + goto out_children;
19791 + if (a->src_dir != a->dst_dir) {
19793 + * this temporary unlock is safe,
19794 + * because both dir->i_mutex are locked.
19796 + di_write_unlock(a->dst_parent);
19797 + di_write_lock_parent(a->src_parent);
19798 + err = au_wr_dir_need_wh(a->src_dentry,
19799 + au_ftest_ren(a->flags, ISDIR),
19801 + di_write_unlock(a->src_parent);
19802 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
19803 + au_fclr_ren(a->flags, ISSAMEDIR);
19805 + err = au_wr_dir_need_wh(a->src_dentry,
19806 + au_ftest_ren(a->flags, ISDIR),
19808 + if (unlikely(err < 0))
19809 + goto out_children;
19811 + au_fset_ren(a->flags, WHSRC);
19814 + if (a->src_bstart != a->btgt) {
19815 + struct au_pin pin;
19817 + err = au_pin(&pin, a->src_dentry, a->btgt,
19818 + au_opt_udba(a->src_dentry->d_sb),
19819 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19821 + struct au_cp_generic cpg = {
19822 + .dentry = a->src_dentry,
19824 + .bsrc = a->src_bstart,
19827 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19829 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
19830 + err = au_sio_cpup_simple(&cpg);
19833 + if (unlikely(err))
19834 + goto out_children;
19835 + a->src_bstart = a->btgt;
19836 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
19837 + au_fset_ren(a->flags, WHSRC);
19840 + /* lock them all */
19841 + err = au_ren_lock(a);
19842 + if (unlikely(err))
19843 + /* leave the copied-up one */
19844 + goto out_children;
19846 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
19847 + err = au_may_ren(a);
19848 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
19849 + err = -ENAMETOOLONG;
19850 + if (unlikely(err))
19853 + /* store timestamps to be revertible */
19857 + err = do_rename(a);
19858 + if (unlikely(err))
19861 + /* update dir attributes */
19862 + au_ren_refresh_dir(a);
19864 + /* dput/iput all lower dentries */
19865 + au_ren_refresh(a);
19867 + goto out_hdir; /* success */
19870 + au_ren_rev_dt(err, a);
19872 + au_ren_unlock(a);
19874 + au_nhash_wh_free(&a->whlist);
19875 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
19876 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
19877 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
19878 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
19882 + d_move(a->src_dentry, a->dst_dentry);
19884 + au_update_dbstart(a->dst_dentry);
19885 + if (!a->dst_inode)
19886 + d_drop(a->dst_dentry);
19888 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19889 + di_write_unlock(a->dst_parent);
19891 + di_write_unlock2(a->src_parent, a->dst_parent);
19893 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
19895 + iput(a->dst_inode);
19897 + au_whtmp_rmdir_free(a->thargs);
19903 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
19904 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
19905 +++ linux/fs/aufs/Kconfig 2014-04-24 22:11:10.835268907 +0200
19908 + tristate "Aufs (Advanced multi layered unification filesystem) support"
19910 + Aufs is a stackable unification filesystem such as Unionfs,
19911 + which unifies several directories and provides a merged single
19913 + In the early days, aufs was entirely re-designed and
19914 + re-implemented Unionfs Version 1.x series. Introducing many
19915 + original ideas, approaches and improvements, it becomes totally
19916 + different from Unionfs while keeping the basic features.
19920 + prompt "Maximum number of branches"
19921 + default AUFS_BRANCH_MAX_127
19923 + Specifies the maximum number of branches (or member directories)
19924 + in a single aufs. The larger value consumes more system
19925 + resources and has a minor impact to performance.
19926 +config AUFS_BRANCH_MAX_127
19929 + Specifies the maximum number of branches (or member directories)
19930 + in a single aufs. The larger value consumes more system
19931 + resources and has a minor impact to performance.
19932 +config AUFS_BRANCH_MAX_511
19935 + Specifies the maximum number of branches (or member directories)
19936 + in a single aufs. The larger value consumes more system
19937 + resources and has a minor impact to performance.
19938 +config AUFS_BRANCH_MAX_1023
19941 + Specifies the maximum number of branches (or member directories)
19942 + in a single aufs. The larger value consumes more system
19943 + resources and has a minor impact to performance.
19944 +config AUFS_BRANCH_MAX_32767
19947 + Specifies the maximum number of branches (or member directories)
19948 + in a single aufs. The larger value consumes more system
19949 + resources and has a minor impact to performance.
19952 +config AUFS_SBILIST
19954 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
19957 + Automatic configuration for internal use.
19958 + When aufs supports Magic SysRq or /proc, enabled automatically.
19960 +config AUFS_HNOTIFY
19961 + bool "Detect direct branch access (bypassing aufs)"
19963 + If you want to modify files on branches directly, eg. bypassing aufs,
19964 + and want aufs to detect the changes of them fully, then enable this
19965 + option and use 'udba=notify' mount option.
19966 + Currently there is only one available configuration, "fsnotify".
19967 + It will have a negative impact to the performance.
19968 + See detail in aufs.5.
19971 + prompt "method" if AUFS_HNOTIFY
19972 + default AUFS_HFSNOTIFY
19973 +config AUFS_HFSNOTIFY
19978 +config AUFS_EXPORT
19979 + bool "NFS-exportable aufs"
19980 + depends on EXPORTFS
19982 + If you want to export your mounted aufs via NFS, then enable this
19983 + option. There are several requirements for this configuration.
19984 + See detail in aufs.5.
19986 +config AUFS_INO_T_64
19988 + depends on AUFS_EXPORT
19989 + depends on 64BIT && !(ALPHA || S390)
19992 + Automatic configuration for internal use.
19993 + /* typedef unsigned long/int __kernel_ino_t */
19994 + /* alpha and s390x are int */
19997 + bool "Readdir in userspace"
19999 + Aufs has two methods to provide a merged view for a directory,
20000 + by a user-space library and by kernel-space natively. The latter
20001 + is always enabled but sometimes large and slow.
20002 + If you enable this option, install the library in aufs2-util
20003 + package, and set some environment variables for your readdir(3),
20004 + then the work will be handled in user-space which generally
20005 + shows better performance in most cases.
20006 + See detail in aufs.5.
20008 +config AUFS_SP_IATTR
20009 + bool "Respect the attributes (mtime/ctime mainly) of special files"
20011 + When you write something to a special file, some attributes of it
20012 + (mtime/ctime mainly) may be updated. Generally such updates are
20013 + less important (actually some device drivers and NFS ignore
20014 + it). But some applications (such like test program) requires
20015 + such updates. If you need these updates, then enable this
20016 + configuration which introduces some overhead.
20017 + Currently this configuration handles FIFO only.
20020 + bool "Show whiteouts"
20022 + If you want to make the whiteouts in aufs visible, then enable
20023 + this option and specify 'shwh' mount option. Although it may
20024 + sounds like philosophy or something, but in technically it
20025 + simply shows the name of whiteout with keeping its behaviour.
20027 +config AUFS_BR_RAMFS
20028 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
20030 + If you want to use ramfs as an aufs branch fs, then enable this
20031 + option. Generally tmpfs is recommended.
20032 + Aufs prohibited them to be a branch fs by default, because
20033 + initramfs becomes unusable after switch_root or something
20034 + generally. If you sets initramfs as an aufs branch and boot your
20035 + system by switch_root, you will meet a problem easily since the
20036 + files in initramfs may be inaccessible.
20037 + Unless you are going to use ramfs as an aufs branch fs without
20038 + switch_root or something, leave it N.
20040 +config AUFS_BR_FUSE
20041 + bool "Fuse fs as an aufs branch"
20042 + depends on FUSE_FS
20045 + If you want to use fuse-based userspace filesystem as an aufs
20046 + branch fs, then enable this option.
20047 + It implements the internal poll(2) operation which is
20048 + implemented by fuse only (curretnly).
20053 + Automatic configuration for internal use.
20055 +config AUFS_BR_HFSPLUS
20056 + bool "Hfsplus as an aufs branch"
20057 + depends on HFSPLUS_FS
20060 + If you want to use hfsplus fs as an aufs branch fs, then enable
20061 + this option. This option introduces a small overhead at
20062 + copying-up a file on hfsplus.
20064 +config AUFS_BDEV_LOOP
20066 + depends on BLK_DEV_LOOP
20069 + Automatic configuration for internal use.
20070 + Convert =[ym] into =y.
20073 + bool "Debug aufs"
20075 + Enable this to compile aufs internal debug code.
20076 + It will have a negative impact to the performance.
20078 +config AUFS_MAGIC_SYSRQ
20080 + depends on AUFS_DEBUG && MAGIC_SYSRQ
20083 + Automatic configuration for internal use.
20084 + When aufs supports Magic SysRq, enabled automatically.
20086 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
20087 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
20088 +++ linux/fs/aufs/loop.c 2014-04-24 22:11:10.855269116 +0200
20091 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20093 + * This program, aufs is free software; you can redistribute it and/or modify
20094 + * it under the terms of the GNU General Public License as published by
20095 + * the Free Software Foundation; either version 2 of the License, or
20096 + * (at your option) any later version.
20098 + * This program is distributed in the hope that it will be useful,
20099 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20101 + * GNU General Public License for more details.
20103 + * You should have received a copy of the GNU General Public License
20104 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20108 + * support for loopback block device as a branch
20113 +/* added into drivers/block/loop.c */
20114 +static struct file *(*backing_file_func)(struct super_block *sb);
20117 + * test if two lower dentries have overlapping branches.
20119 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
20121 + struct super_block *h_sb;
20122 + struct file *backing_file;
20124 + if (unlikely(!backing_file_func)) {
20125 + /* don't load "loop" module here */
20126 + backing_file_func = symbol_get(loop_backing_file);
20127 + if (unlikely(!backing_file_func))
20128 + /* "loop" module is not loaded */
20132 + h_sb = h_adding->d_sb;
20133 + backing_file = backing_file_func(h_sb);
20134 + if (!backing_file)
20137 + h_adding = backing_file->f_dentry;
20139 + * h_adding can be local NFS.
20140 + * in this case aufs cannot detect the loop.
20142 + if (unlikely(h_adding->d_sb == sb))
20144 + return !!au_test_subdir(h_adding, sb->s_root);
20147 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
20148 +int au_test_loopback_kthread(void)
20151 + struct task_struct *tsk = current;
20152 + char c, comm[sizeof(tsk->comm)];
20155 + if (tsk->flags & PF_KTHREAD) {
20156 + get_task_comm(comm, tsk);
20158 + ret = ('0' <= c && c <= '9'
20159 + && !strncmp(comm, "loop", 4));
20165 +/* ---------------------------------------------------------------------- */
20167 +#define au_warn_loopback_step 16
20168 +static int au_warn_loopback_nelem = au_warn_loopback_step;
20169 +static unsigned long *au_warn_loopback_array;
20171 +void au_warn_loopback(struct super_block *h_sb)
20173 + int i, new_nelem;
20174 + unsigned long *a, magic;
20175 + static DEFINE_SPINLOCK(spin);
20177 + magic = h_sb->s_magic;
20178 + spin_lock(&spin);
20179 + a = au_warn_loopback_array;
20180 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
20181 + if (a[i] == magic) {
20182 + spin_unlock(&spin);
20186 + /* h_sb is new to us, print it */
20187 + if (i < au_warn_loopback_nelem) {
20192 + /* expand the array */
20193 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
20194 + a = au_kzrealloc(au_warn_loopback_array,
20195 + au_warn_loopback_nelem * sizeof(unsigned long),
20196 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
20198 + au_warn_loopback_nelem = new_nelem;
20199 + au_warn_loopback_array = a;
20204 + spin_unlock(&spin);
20205 + AuWarn1("realloc failed, ignored\n");
20209 + spin_unlock(&spin);
20210 + pr_warn("you may want to try another patch for loopback file "
20211 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
20214 +int au_loopback_init(void)
20217 + struct super_block *sb __maybe_unused;
20219 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
20222 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
20223 + sizeof(unsigned long), GFP_NOFS);
20224 + if (unlikely(!au_warn_loopback_array))
20230 +void au_loopback_fin(void)
20232 + symbol_put(loop_backing_file);
20233 + kfree(au_warn_loopback_array);
20235 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
20236 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
20237 +++ linux/fs/aufs/loop.h 2014-04-24 22:11:10.855269116 +0200
20240 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20242 + * This program, aufs is free software; you can redistribute it and/or modify
20243 + * it under the terms of the GNU General Public License as published by
20244 + * the Free Software Foundation; either version 2 of the License, or
20245 + * (at your option) any later version.
20247 + * This program is distributed in the hope that it will be useful,
20248 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20249 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20250 + * GNU General Public License for more details.
20252 + * You should have received a copy of the GNU General Public License
20253 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20257 + * support for loopback mount as a branch
20260 +#ifndef __AUFS_LOOP_H__
20261 +#define __AUFS_LOOP_H__
20266 +struct super_block;
20268 +#ifdef CONFIG_AUFS_BDEV_LOOP
20269 +/* drivers/block/loop.c */
20270 +struct file *loop_backing_file(struct super_block *sb);
20273 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
20274 +int au_test_loopback_kthread(void);
20275 +void au_warn_loopback(struct super_block *h_sb);
20277 +int au_loopback_init(void);
20278 +void au_loopback_fin(void);
20280 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
20281 + struct dentry *h_adding)
20282 +AuStubInt0(au_test_loopback_kthread, void)
20283 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
20285 +AuStubInt0(au_loopback_init, void)
20286 +AuStubVoid(au_loopback_fin, void)
20287 +#endif /* BLK_DEV_LOOP */
20289 +#endif /* __KERNEL__ */
20290 +#endif /* __AUFS_LOOP_H__ */
20291 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
20292 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
20293 +++ linux/fs/aufs/magic.mk 2012-10-05 20:40:23.980965955 +0200
20296 +# defined in ${srctree}/fs/fuse/inode.c
20298 +ifdef CONFIG_FUSE_FS
20299 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
20302 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
20304 +ifdef CONFIG_OCFS2_FS
20305 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
20308 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
20310 +ifdef CONFIG_OCFS2_FS_O2CB
20311 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
20314 +# defined in ${srctree}/fs/cifs/cifsfs.c
20316 +ifdef CONFIG_CIFS_FS
20317 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
20320 +# defined in ${srctree}/fs/xfs/xfs_sb.h
20322 +ifdef CONFIG_XFS_FS
20323 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
20326 +# defined in ${srctree}/fs/configfs/mount.c
20328 +ifdef CONFIG_CONFIGFS_FS
20329 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
20332 +# defined in ${srctree}/fs/9p/v9fs.h
20334 +ifdef CONFIG_9P_FS
20335 +ccflags-y += -DV9FS_MAGIC=0x01021997
20338 +# defined in ${srctree}/fs/ubifs/ubifs.h
20340 +ifdef CONFIG_UBIFS_FS
20341 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
20344 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
20346 +ifdef CONFIG_HFSPLUS_FS
20347 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
20349 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
20350 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
20351 +++ linux/fs/aufs/Makefile 2014-04-24 22:11:10.845269011 +0200
20354 +include ${src}/magic.mk
20355 +ifeq (${CONFIG_AUFS_FS},m)
20356 +include ${src}/conf.mk
20358 +-include ${src}/priv_def.mk
20360 +# cf. include/linux/kernel.h
20362 +ccflags-y += -DDEBUG
20363 +# sparse requires the full pathname
20365 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
20367 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
20370 +obj-$(CONFIG_AUFS_FS) += aufs.o
20371 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
20372 + wkq.o vfsub.o dcsub.o \
20373 + cpup.o whout.o wbr_policy.o \
20374 + dinfo.o dentry.o \
20376 + finfo.o file.o f_op.o \
20378 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
20382 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
20383 +aufs-$(CONFIG_SYSFS) += sysfs.o
20384 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
20385 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
20386 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
20387 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
20388 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
20389 +aufs-$(CONFIG_AUFS_POLL) += poll.o
20390 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
20391 +aufs-$(CONFIG_AUFS_SP_IATTR) += f_op_sp.o
20392 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
20393 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
20394 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
20395 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
20396 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
20397 +++ linux/fs/aufs/module.c 2014-04-24 22:11:10.855269116 +0200
20400 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20402 + * This program, aufs is free software; you can redistribute it and/or modify
20403 + * it under the terms of the GNU General Public License as published by
20404 + * the Free Software Foundation; either version 2 of the License, or
20405 + * (at your option) any later version.
20407 + * This program is distributed in the hope that it will be useful,
20408 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20409 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20410 + * GNU General Public License for more details.
20412 + * You should have received a copy of the GNU General Public License
20413 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20417 + * module global variables and operations
20420 +#include <linux/module.h>
20421 +#include <linux/seq_file.h>
20424 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
20426 + if (new_sz <= nused)
20429 + p = krealloc(p, new_sz, gfp);
20431 + memset(p + nused, 0, new_sz - nused);
20435 +/* ---------------------------------------------------------------------- */
20440 +struct kmem_cache *au_cachep[AuCache_Last];
20441 +static int __init au_cache_init(void)
20443 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
20444 + if (au_cachep[AuCache_DINFO])
20445 + /* SLAB_DESTROY_BY_RCU */
20446 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
20447 + au_icntnr_init_once);
20448 + if (au_cachep[AuCache_ICNTNR])
20449 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
20450 + au_fi_init_once);
20451 + if (au_cachep[AuCache_FINFO])
20452 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
20453 + if (au_cachep[AuCache_VDIR])
20454 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
20455 + if (au_cachep[AuCache_DEHSTR])
20461 +static void au_cache_fin(void)
20466 + * Make sure all delayed rcu free inodes are flushed before we
20471 + /* excluding AuCache_HNOTIFY */
20472 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
20473 + for (i = 0; i < AuCache_HNOTIFY; i++)
20474 + if (au_cachep[i]) {
20475 + kmem_cache_destroy(au_cachep[i]);
20476 + au_cachep[i] = NULL;
20480 +/* ---------------------------------------------------------------------- */
20482 +int au_dir_roflags;
20484 +#ifdef CONFIG_AUFS_SBILIST
20486 + * iterate_supers_type() doesn't protect us from
20487 + * remounting (branch management)
20489 +struct au_splhead au_sbilist;
20492 +struct lock_class_key au_lc_key[AuLcKey_Last];
20495 + * functions for module interface.
20497 +MODULE_LICENSE("GPL");
20498 +/* MODULE_LICENSE("GPL v2"); */
20499 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
20500 +MODULE_DESCRIPTION(AUFS_NAME
20501 + " -- Advanced multi layered unification filesystem");
20502 +MODULE_VERSION(AUFS_VERSION);
20503 +MODULE_ALIAS_FS(AUFS_NAME);
20505 +/* this module parameter has no meaning when SYSFS is disabled */
20506 +int sysaufs_brs = 1;
20507 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
20508 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
20510 +/* ---------------------------------------------------------------------- */
20512 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
20514 +int au_seq_path(struct seq_file *seq, struct path *path)
20516 + return seq_path(seq, path, au_esc_chars);
20519 +/* ---------------------------------------------------------------------- */
20521 +static int __init aufs_init(void)
20526 + p = au_esc_chars;
20527 + for (i = 1; i <= ' '; i++)
20533 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
20535 + au_sbilist_init();
20536 + sysaufs_brs_init();
20539 + err = sysaufs_init();
20540 + if (unlikely(err))
20542 + err = au_procfs_init();
20543 + if (unlikely(err))
20544 + goto out_sysaufs;
20545 + err = au_wkq_init();
20546 + if (unlikely(err))
20548 + err = au_loopback_init();
20549 + if (unlikely(err))
20551 + err = au_hnotify_init();
20552 + if (unlikely(err))
20553 + goto out_loopback;
20554 + err = au_sysrq_init();
20555 + if (unlikely(err))
20557 + err = au_cache_init();
20558 + if (unlikely(err))
20560 + err = register_filesystem(&aufs_fs_type);
20561 + if (unlikely(err))
20563 + /* since we define pr_fmt, call printk directly */
20564 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
20565 + goto out; /* success */
20572 + au_hnotify_fin();
20574 + au_loopback_fin();
20586 +static void __exit aufs_exit(void)
20588 + unregister_filesystem(&aufs_fs_type);
20591 + au_hnotify_fin();
20592 + au_loopback_fin();
20599 +module_init(aufs_init);
20600 +module_exit(aufs_exit);
20601 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
20602 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
20603 +++ linux/fs/aufs/module.h 2014-04-24 22:11:10.855269116 +0200
20606 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20608 + * This program, aufs is free software; you can redistribute it and/or modify
20609 + * it under the terms of the GNU General Public License as published by
20610 + * the Free Software Foundation; either version 2 of the License, or
20611 + * (at your option) any later version.
20613 + * This program is distributed in the hope that it will be useful,
20614 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20615 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20616 + * GNU General Public License for more details.
20618 + * You should have received a copy of the GNU General Public License
20619 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20623 + * module initialization and module-global
20626 +#ifndef __AUFS_MODULE_H__
20627 +#define __AUFS_MODULE_H__
20631 +#include <linux/slab.h>
20636 +/* module parameters */
20637 +extern int sysaufs_brs;
20639 +/* ---------------------------------------------------------------------- */
20641 +extern int au_dir_roflags;
20644 + AuLcNonDir_FIINFO,
20645 + AuLcNonDir_DIINFO,
20646 + AuLcNonDir_IIINFO,
20652 + AuLcSymlink_DIINFO,
20653 + AuLcSymlink_IIINFO,
20657 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
20659 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
20660 +int au_seq_path(struct seq_file *seq, struct path *path);
20662 +#ifdef CONFIG_PROC_FS
20664 +int __init au_procfs_init(void);
20665 +void au_procfs_fin(void);
20667 +AuStubInt0(au_procfs_init, void);
20668 +AuStubVoid(au_procfs_fin, void);
20671 +/* ---------------------------------------------------------------------- */
20680 + AuCache_HNOTIFY, /* must be last */
20684 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
20685 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
20686 +#define AuCacheCtor(type, ctor) \
20687 + kmem_cache_create(#type, sizeof(struct type), \
20688 + __alignof__(struct type), AuCacheFlags, ctor)
20690 +extern struct kmem_cache *au_cachep[];
20692 +#define AuCacheFuncs(name, index) \
20693 +static inline struct au_##name *au_cache_alloc_##name(void) \
20694 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
20695 +static inline void au_cache_free_##name(struct au_##name *p) \
20696 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
20698 +AuCacheFuncs(dinfo, DINFO);
20699 +AuCacheFuncs(icntnr, ICNTNR);
20700 +AuCacheFuncs(finfo, FINFO);
20701 +AuCacheFuncs(vdir, VDIR);
20702 +AuCacheFuncs(vdir_dehstr, DEHSTR);
20703 +#ifdef CONFIG_AUFS_HNOTIFY
20704 +AuCacheFuncs(hnotify, HNOTIFY);
20707 +#endif /* __KERNEL__ */
20708 +#endif /* __AUFS_MODULE_H__ */
20709 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
20710 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
20711 +++ linux/fs/aufs/mvdown.c 2014-04-24 22:11:10.855269116 +0200
20714 + * Copyright (C) 2011-2014 Junjiro R. Okajima
20716 + * This program, aufs is free software; you can redistribute it and/or modify
20717 + * it under the terms of the GNU General Public License as published by
20718 + * the Free Software Foundation; either version 2 of the License, or
20719 + * (at your option) any later version.
20721 + * This program is distributed in the hope that it will be useful,
20722 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20723 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20724 + * GNU General Public License for more details.
20726 + * You should have received a copy of the GNU General Public License
20727 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20731 + * move-down, opposite of copy-up
20736 +struct au_mvd_args {
20738 + struct super_block *h_sb;
20739 + struct dentry *h_parent;
20740 + struct au_hinode *hdir;
20741 + struct inode *h_dir, *h_inode;
20742 + } info[AUFS_MVDOWN_NARRAY];
20744 + struct aufs_mvdown mvdown;
20745 + struct dentry *dentry, *parent;
20746 + struct inode *inode, *dir;
20747 + struct super_block *sb;
20748 + aufs_bindex_t bopq, bwh, bfound;
20749 + unsigned char rename_lock;
20750 + struct au_pin pin;
20753 +#define mvd_errno mvdown.au_errno
20754 +#define mvd_bsrc mvdown.a[AUFS_MVDOWN_UPPER].bindex
20755 +#define mvd_src_brid mvdown.a[AUFS_MVDOWN_UPPER].brid
20756 +#define mvd_bdst mvdown.a[AUFS_MVDOWN_LOWER].bindex
20757 +#define mvd_dst_brid mvdown.a[AUFS_MVDOWN_LOWER].brid
20759 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
20760 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
20761 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
20762 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
20763 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
20765 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
20766 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
20767 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
20768 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
20769 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
20771 +#define AU_MVD_PR(flag, ...) do { \
20773 + pr_err(__VA_ARGS__); \
20776 +/* make the parent dir on bdst */
20777 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
20782 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
20783 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
20784 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
20785 + a->mvd_h_dst_parent = NULL;
20786 + if (au_dbend(a->parent) >= a->mvd_bdst)
20787 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20788 + if (!a->mvd_h_dst_parent) {
20789 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
20790 + if (unlikely(err)) {
20791 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
20794 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
20802 +/* lock them all */
20803 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
20806 + struct dentry *h_trap;
20808 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
20809 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
20810 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
20811 + a->rename_lock = 0;
20812 + err = au_pin(&a->pin, a->dentry, a->mvd_bdst,
20813 + au_opt_udba(a->sb),
20814 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
20816 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
20817 + mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
20818 + AuLsc_I_PARENT3);
20820 + AU_MVD_PR(dmsg, "pin failed\n");
20825 + a->rename_lock = 1;
20826 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20827 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20829 + err = (h_trap != a->mvd_h_src_parent);
20831 + err = (h_trap != a->mvd_h_dst_parent);
20833 + BUG_ON(err); /* it should never happen */
20840 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
20842 + if (!a->rename_lock) {
20843 + mutex_unlock(&a->mvd_h_src_dir->i_mutex);
20844 + au_unpin(&a->pin);
20846 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
20847 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
20850 +/* copy-down the file */
20851 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
20854 + struct au_cp_generic cpg = {
20855 + .dentry = a->dentry,
20856 + .bdst = a->mvd_bdst,
20857 + .bsrc = a->mvd_bsrc,
20860 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20863 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
20864 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
20865 + au_fset_cpup(cpg.flags, OVERWRITE);
20866 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
20867 + au_fset_cpup(cpg.flags, RWDST);
20868 + err = au_sio_cpdown_simple(&cpg);
20869 + if (unlikely(err))
20870 + AU_MVD_PR(dmsg, "cpdown failed\n");
20877 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
20880 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
20883 + struct path h_path;
20884 + struct au_branch *br;
20885 + struct inode *delegated;
20887 + br = au_sbr(a->sb, a->mvd_bdst);
20888 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
20889 + err = PTR_ERR(h_path.dentry);
20890 + if (IS_ERR(h_path.dentry)) {
20891 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
20896 + if (h_path.dentry->d_inode) {
20897 + h_path.mnt = au_br_mnt(br);
20898 + delegated = NULL;
20899 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
20900 + &delegated, /*force*/0);
20901 + if (unlikely(err == -EWOULDBLOCK)) {
20902 + pr_warn("cannot retry for NFSv4 delegation"
20903 + " for an internal unlink\n");
20906 + if (unlikely(err))
20907 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
20909 + dput(h_path.dentry);
20917 + * unlink the topmost h_dentry
20918 + * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
20919 + * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
20921 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
20924 + struct path h_path;
20925 + struct inode *delegated;
20927 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
20928 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
20929 + delegated = NULL;
20930 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
20931 + if (unlikely(err == -EWOULDBLOCK)) {
20932 + pr_warn("cannot retry for NFSv4 delegation"
20933 + " for an internal unlink\n");
20936 + if (unlikely(err))
20937 + AU_MVD_PR(dmsg, "unlink failed\n");
20944 + * copy-down the file and unlink the bsrc file.
20945 + * - unlink the bdst whout if exist
20946 + * - copy-down the file (with whtmp name and rename)
20947 + * - unlink the bsrc file
20949 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
20953 + err = au_do_mkdir(dmsg, a);
20955 + err = au_do_lock(dmsg, a);
20956 + if (unlikely(err))
20960 + * do not revert the activities we made on bdst since they should be
20961 + * harmless in aufs.
20964 + err = au_do_cpdown(dmsg, a);
20966 + err = au_do_unlink_wh(dmsg, a);
20967 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
20968 + err = au_do_unlink(dmsg, a);
20969 + if (unlikely(err))
20972 + /* maintain internal array */
20973 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
20974 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
20975 + au_set_dbstart(a->dentry, a->mvd_bdst);
20976 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
20977 + au_set_ibstart(a->inode, a->mvd_bdst);
20979 + if (au_dbend(a->dentry) < a->mvd_bdst)
20980 + au_set_dbend(a->dentry, a->mvd_bdst);
20981 + if (au_ibend(a->inode) < a->mvd_bdst)
20982 + au_set_ibend(a->inode, a->mvd_bdst);
20985 + au_do_unlock(dmsg, a);
20991 +/* ---------------------------------------------------------------------- */
20993 +static int find_lower_writable(struct au_mvd_args *a)
20995 + struct super_block *sb;
20996 + aufs_bindex_t bindex, bend;
20997 + struct au_branch *br;
21000 + bindex = a->mvd_bsrc;
21001 + bend = au_sbend(sb);
21002 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) {
21003 + for (bindex++; bindex <= bend; bindex++) {
21004 + br = au_sbr(sb, bindex);
21005 + if (!au_br_rdonly(br))
21009 + for (bindex++; bindex <= bend; bindex++) {
21010 + br = au_sbr(sb, bindex);
21011 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21012 + if (au_br_rdonly(br))
21014 + |= AUFS_MVDOWN_ROLOWER_R;
21023 +/* make sure the file is idle */
21024 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
21026 + int err, plinked;
21029 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
21030 + if (au_dbstart(a->dentry) == a->mvd_bsrc
21031 + && d_count(a->dentry) == 1
21032 + && atomic_read(&a->inode->i_count) == 1
21033 + /* && a->mvd_h_src_inode->i_nlink == 1 */
21034 + && (!plinked || !au_plink_test(a->inode))
21035 + && a->inode->i_nlink == 1)
21040 + "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
21041 + a->mvd_bsrc, au_dbstart(a->dentry), d_count(a->dentry),
21042 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
21043 + a->mvd_h_src_inode->i_nlink,
21044 + plinked, plinked ? au_plink_test(a->inode) : 0);
21051 +/* make sure the parent dir is fine */
21052 +static int au_mvd_args_parent(const unsigned char dmsg,
21053 + struct au_mvd_args *a)
21056 + aufs_bindex_t bindex;
21059 + if (unlikely(au_alive_dir(a->parent))) {
21061 + AU_MVD_PR(dmsg, "parent dir is dead\n");
21065 + a->bopq = au_dbdiropq(a->parent);
21066 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
21067 + AuDbg("b%d\n", bindex);
21068 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
21069 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
21071 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
21072 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
21073 + a->bopq, a->mvd_bdst);
21081 +static int au_mvd_args_intermediate(const unsigned char dmsg,
21082 + struct au_mvd_args *a)
21085 + struct au_dinfo *dinfo, *tmp;
21087 + /* lookup the next lower positive entry */
21089 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
21090 + if (unlikely(!tmp))
21095 + dinfo = au_di(a->dentry);
21096 + au_di_cp(tmp, dinfo);
21097 + au_di_swap(tmp, dinfo);
21099 + /* returns the number of positive dentries */
21100 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
21102 + a->bwh = au_dbwh(a->dentry);
21103 + else if (err > 0)
21104 + a->bfound = au_dbstart(a->dentry);
21106 + au_di_swap(tmp, dinfo);
21107 + au_rw_write_unlock(&tmp->di_rwsem);
21109 + if (unlikely(err < 0))
21110 + AU_MVD_PR(dmsg, "failed look-up lower\n");
21113 + * here, we have these cases.
21115 + * no positive dentry under bsrc. there are more sub-cases.
21117 + * there no whiteout, we can safely move-down.
21120 + * bsrc < bwh && bwh < bdst
21121 + * there is a whiteout on RO branch. cannot proceed.
21123 + * there is a whiteout on the RW target branch. it should
21126 + * there is a whiteout somewhere unrelated branch.
21127 + * -1 < bfound && bfound <= bsrc
21130 + * found, but it is on RO branch between bsrc and bdst. cannot
21133 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
21136 + * found, after we create the file on bdst, it will be hidden.
21139 + AuDebugOn(a->bfound == -1
21141 + && a->bwh <= a->mvd_bsrc);
21142 + AuDebugOn(-1 < a->bfound
21143 + && a->bfound <= a->mvd_bsrc);
21146 + if (a->bfound == -1
21147 + && a->mvd_bsrc < a->bwh
21149 + && a->bwh < a->mvd_bdst) {
21150 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
21151 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
21152 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
21154 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
21155 + a->mvd_errno = EAU_MVDOWN_UPPER;
21156 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
21157 + a->mvd_bdst, a->bfound);
21161 + err = 0; /* success */
21168 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
21173 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21174 + && a->bfound == a->mvd_bdst)
21180 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
21183 + struct au_branch *br;
21186 + if (unlikely(S_ISDIR(a->inode->i_mode)))
21190 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
21191 + a->mvd_bsrc = au_ibstart(a->inode);
21193 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
21194 + if (unlikely(a->mvd_bsrc < 0
21195 + || (a->mvd_bsrc < au_dbstart(a->dentry)
21196 + || au_dbend(a->dentry) < a->mvd_bsrc
21197 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
21198 + || (a->mvd_bsrc < au_ibstart(a->inode)
21199 + || au_ibend(a->inode) < a->mvd_bsrc
21200 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
21201 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
21202 + AU_MVD_PR(dmsg, "no upper\n");
21206 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
21207 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
21208 + AU_MVD_PR(dmsg, "on the bottom\n");
21211 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
21212 + br = au_sbr(a->sb, a->mvd_bsrc);
21213 + err = au_br_rdonly(br);
21214 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
21215 + if (unlikely(err))
21217 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
21218 + || IS_APPEND(a->mvd_h_src_inode))) {
21220 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
21226 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
21227 + a->mvd_bdst = find_lower_writable(a);
21228 + if (unlikely(a->mvd_bdst < 0)) {
21229 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
21230 + AU_MVD_PR(dmsg, "no writable lower branch\n");
21234 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
21235 + if (unlikely(a->mvd_bdst < 0
21236 + || au_sbend(a->sb) < a->mvd_bdst)) {
21237 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
21238 + AU_MVD_PR(dmsg, "no lower brid\n");
21243 + err = au_mvd_args_busy(dmsg, a);
21245 + err = au_mvd_args_parent(dmsg, a);
21247 + err = au_mvd_args_intermediate(dmsg, a);
21249 + err = au_mvd_args_exist(dmsg, a);
21251 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
21258 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
21261 + unsigned char dmsg;
21262 + struct au_mvd_args *args;
21265 + if (unlikely(!capable(CAP_SYS_ADMIN)))
21268 + WARN_ONCE(1, "move-down is still testing...\n");
21271 + args = kmalloc(sizeof(*args), GFP_NOFS);
21272 + if (unlikely(!args))
21275 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
21277 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
21278 + if (unlikely(err)) {
21283 + AuDbg("flags 0x%x\n", args->mvdown.flags);
21284 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
21285 + args->mvdown.au_errno = 0;
21286 + args->dentry = dentry;
21287 + args->inode = dentry->d_inode;
21288 + args->sb = dentry->d_sb;
21291 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
21292 + args->parent = dget_parent(dentry);
21293 + args->dir = args->parent->d_inode;
21294 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
21295 + dput(args->parent);
21296 + if (unlikely(args->parent != dentry->d_parent)) {
21297 + AU_MVD_PR(dmsg, "parent dir is moved\n");
21301 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
21302 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
21303 + if (unlikely(err))
21306 + di_write_lock_parent(args->parent);
21307 + err = au_mvd_args(dmsg, args);
21308 + if (unlikely(err))
21311 + AuDbgDentry(dentry);
21312 + AuDbgInode(args->inode);
21313 + err = au_do_mvdown(dmsg, args);
21314 + if (unlikely(err))
21316 + AuDbgDentry(dentry);
21317 + AuDbgInode(args->inode);
21319 + au_cpup_attr_timesizes(args->dir);
21320 + au_cpup_attr_timesizes(args->inode);
21321 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
21322 + /* au_digen_dec(dentry); */
21325 + di_write_unlock(args->parent);
21326 + aufs_read_unlock(dentry, AuLock_DW);
21328 + mutex_unlock(&args->inode->i_mutex);
21330 + mutex_unlock(&args->dir->i_mutex);
21332 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
21340 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
21341 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
21342 +++ linux/fs/aufs/opts.c 2014-04-24 22:11:10.855269116 +0200
21345 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21347 + * This program, aufs is free software; you can redistribute it and/or modify
21348 + * it under the terms of the GNU General Public License as published by
21349 + * the Free Software Foundation; either version 2 of the License, or
21350 + * (at your option) any later version.
21352 + * This program is distributed in the hope that it will be useful,
21353 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21354 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21355 + * GNU General Public License for more details.
21357 + * You should have received a copy of the GNU General Public License
21358 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21362 + * mount options/flags
21365 +#include <linux/namei.h>
21366 +#include <linux/types.h> /* a distribution requires */
21367 +#include <linux/parser.h>
21370 +/* ---------------------------------------------------------------------- */
21374 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
21375 + Opt_idel, Opt_imod, Opt_ireorder,
21376 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
21377 + Opt_rdblk_def, Opt_rdhash_def,
21378 + Opt_xino, Opt_zxino, Opt_noxino,
21379 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
21380 + Opt_trunc_xino_path, Opt_itrunc_xino,
21381 + Opt_trunc_xib, Opt_notrunc_xib,
21382 + Opt_shwh, Opt_noshwh,
21383 + Opt_plink, Opt_noplink, Opt_list_plink,
21385 + Opt_dio, Opt_nodio,
21386 + /* Opt_lock, Opt_unlock, */
21387 + Opt_cmd, Opt_cmd_args,
21388 + Opt_diropq_a, Opt_diropq_w,
21389 + Opt_warn_perm, Opt_nowarn_perm,
21390 + Opt_wbr_copyup, Opt_wbr_create,
21391 + Opt_refrof, Opt_norefrof,
21392 + Opt_verbose, Opt_noverbose,
21393 + Opt_sum, Opt_nosum, Opt_wsum,
21394 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
21397 +static match_table_t options = {
21398 + {Opt_br, "br=%s"},
21399 + {Opt_br, "br:%s"},
21401 + {Opt_add, "add=%d:%s"},
21402 + {Opt_add, "add:%d:%s"},
21403 + {Opt_add, "ins=%d:%s"},
21404 + {Opt_add, "ins:%d:%s"},
21405 + {Opt_append, "append=%s"},
21406 + {Opt_append, "append:%s"},
21407 + {Opt_prepend, "prepend=%s"},
21408 + {Opt_prepend, "prepend:%s"},
21410 + {Opt_del, "del=%s"},
21411 + {Opt_del, "del:%s"},
21412 + /* {Opt_idel, "idel:%d"}, */
21413 + {Opt_mod, "mod=%s"},
21414 + {Opt_mod, "mod:%s"},
21415 + /* {Opt_imod, "imod:%d:%s"}, */
21417 + {Opt_dirwh, "dirwh=%d"},
21419 + {Opt_xino, "xino=%s"},
21420 + {Opt_noxino, "noxino"},
21421 + {Opt_trunc_xino, "trunc_xino"},
21422 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
21423 + {Opt_notrunc_xino, "notrunc_xino"},
21424 + {Opt_trunc_xino_path, "trunc_xino=%s"},
21425 + {Opt_itrunc_xino, "itrunc_xino=%d"},
21426 + /* {Opt_zxino, "zxino=%s"}, */
21427 + {Opt_trunc_xib, "trunc_xib"},
21428 + {Opt_notrunc_xib, "notrunc_xib"},
21430 +#ifdef CONFIG_PROC_FS
21431 + {Opt_plink, "plink"},
21433 + {Opt_ignore_silent, "plink"},
21436 + {Opt_noplink, "noplink"},
21438 +#ifdef CONFIG_AUFS_DEBUG
21439 + {Opt_list_plink, "list_plink"},
21442 + {Opt_udba, "udba=%s"},
21444 + {Opt_dio, "dio"},
21445 + {Opt_nodio, "nodio"},
21447 + {Opt_diropq_a, "diropq=always"},
21448 + {Opt_diropq_a, "diropq=a"},
21449 + {Opt_diropq_w, "diropq=whiteouted"},
21450 + {Opt_diropq_w, "diropq=w"},
21452 + {Opt_warn_perm, "warn_perm"},
21453 + {Opt_nowarn_perm, "nowarn_perm"},
21455 + /* keep them temporary */
21456 + {Opt_ignore_silent, "coo=%s"},
21457 + {Opt_ignore_silent, "nodlgt"},
21458 + {Opt_ignore_silent, "nodirperm1"},
21459 + {Opt_ignore_silent, "clean_plink"},
21461 +#ifdef CONFIG_AUFS_SHWH
21462 + {Opt_shwh, "shwh"},
21464 + {Opt_noshwh, "noshwh"},
21466 + {Opt_rendir, "rendir=%d"},
21468 + {Opt_refrof, "refrof"},
21469 + {Opt_norefrof, "norefrof"},
21471 + {Opt_verbose, "verbose"},
21472 + {Opt_verbose, "v"},
21473 + {Opt_noverbose, "noverbose"},
21474 + {Opt_noverbose, "quiet"},
21475 + {Opt_noverbose, "q"},
21476 + {Opt_noverbose, "silent"},
21478 + {Opt_sum, "sum"},
21479 + {Opt_nosum, "nosum"},
21480 + {Opt_wsum, "wsum"},
21482 + {Opt_rdcache, "rdcache=%d"},
21483 + {Opt_rdblk, "rdblk=%d"},
21484 + {Opt_rdblk_def, "rdblk=def"},
21485 + {Opt_rdhash, "rdhash=%d"},
21486 + {Opt_rdhash_def, "rdhash=def"},
21488 + {Opt_wbr_create, "create=%s"},
21489 + {Opt_wbr_create, "create_policy=%s"},
21490 + {Opt_wbr_copyup, "cpup=%s"},
21491 + {Opt_wbr_copyup, "copyup=%s"},
21492 + {Opt_wbr_copyup, "copyup_policy=%s"},
21494 + /* internal use for the scripts */
21495 + {Opt_ignore_silent, "si=%s"},
21497 + {Opt_br, "dirs=%s"},
21498 + {Opt_ignore, "debug=%d"},
21499 + {Opt_ignore, "delete=whiteout"},
21500 + {Opt_ignore, "delete=all"},
21501 + {Opt_ignore, "imap=%s"},
21503 + /* temporary workaround, due to old mount(8)? */
21504 + {Opt_ignore_silent, "relatime"},
21509 +/* ---------------------------------------------------------------------- */
21511 +static const char *au_parser_pattern(int val, struct match_token *token)
21513 + while (token->pattern) {
21514 + if (token->token == val)
21515 + return token->pattern;
21522 +/* ---------------------------------------------------------------------- */
21524 +static match_table_t brperm = {
21525 + {AuBrPerm_RO, AUFS_BRPERM_RO},
21526 + {AuBrPerm_RR, AUFS_BRPERM_RR},
21527 + {AuBrPerm_RW, AUFS_BRPERM_RW},
21531 +static match_table_t brattr = {
21532 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
21533 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
21534 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
21538 +#define AuBrStr_LONGEST AUFS_BRPERM_RW \
21539 + "+" AUFS_BRATTR_UNPIN \
21540 + "+" AUFS_BRWATTR_NLWH
21542 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
21549 + p = strchr(str, '+');
21552 + v = match_token(str, table, args);
21558 + pr_warn("ignored branch attribute %s\n", str);
21568 +static int noinline_for_stack br_perm_val(char *perm)
21572 + substring_t args[MAX_OPT_ARGS];
21574 + p = strchr(perm, '+');
21577 + val = match_token(perm, brperm, args);
21581 + pr_warn("ignored branch permission %s\n", perm);
21582 + val = AuBrPerm_RO;
21590 + q = strchr(p, '+');
21593 + val |= br_attr_val(p, brattr, args);
21600 + switch (val & AuBrPerm_Mask) {
21601 + case AuBrPerm_RO:
21602 + case AuBrPerm_RR:
21603 + if (unlikely(val & AuBrWAttr_NoLinkWH)) {
21604 + pr_warn("ignored branch attribute %s\n",
21605 + AUFS_BRWATTR_NLWH);
21606 + val &= ~AuBrWAttr_NoLinkWH;
21609 + case AuBrPerm_RW:
21610 + if (unlikely(val & AuBrRAttr_WH)) {
21611 + pr_warn("ignored branch attribute %s\n",
21612 + AUFS_BRRATTR_WH);
21613 + val &= ~AuBrRAttr_WH;
21622 +/* Caller should free the return value */
21623 +char *au_optstr_br_perm(int brperm)
21625 + char *p, a[sizeof(AuBrStr_LONGEST)];
21628 +#define SetPerm(str) do { \
21629 + sz = sizeof(str); \
21630 + memcpy(a, str, sz); \
21631 + p = a + sz - 1; \
21634 +#define AppendAttr(flag, str) do { \
21635 + if (brperm & flag) { \
21636 + sz = sizeof(str); \
21638 + memcpy(p, str, sz); \
21643 + switch (brperm & AuBrPerm_Mask) {
21644 + case AuBrPerm_RO:
21645 + SetPerm(AUFS_BRPERM_RO);
21647 + case AuBrPerm_RR:
21648 + SetPerm(AUFS_BRPERM_RR);
21650 + case AuBrPerm_RW:
21651 + SetPerm(AUFS_BRPERM_RW);
21657 + AppendAttr(AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN);
21658 + AppendAttr(AuBrRAttr_WH, AUFS_BRRATTR_WH);
21659 + AppendAttr(AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH);
21661 + AuDebugOn(strlen(a) >= sizeof(a));
21662 + return kstrdup(a, GFP_NOFS);
21667 +/* ---------------------------------------------------------------------- */
21669 +static match_table_t udbalevel = {
21670 + {AuOpt_UDBA_REVAL, "reval"},
21671 + {AuOpt_UDBA_NONE, "none"},
21672 +#ifdef CONFIG_AUFS_HNOTIFY
21673 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
21674 +#ifdef CONFIG_AUFS_HFSNOTIFY
21675 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
21681 +static int noinline_for_stack udba_val(char *str)
21683 + substring_t args[MAX_OPT_ARGS];
21685 + return match_token(str, udbalevel, args);
21688 +const char *au_optstr_udba(int udba)
21690 + return au_parser_pattern(udba, (void *)udbalevel);
21693 +/* ---------------------------------------------------------------------- */
21695 +static match_table_t au_wbr_create_policy = {
21696 + {AuWbrCreate_TDP, "tdp"},
21697 + {AuWbrCreate_TDP, "top-down-parent"},
21698 + {AuWbrCreate_RR, "rr"},
21699 + {AuWbrCreate_RR, "round-robin"},
21700 + {AuWbrCreate_MFS, "mfs"},
21701 + {AuWbrCreate_MFS, "most-free-space"},
21702 + {AuWbrCreate_MFSV, "mfs:%d"},
21703 + {AuWbrCreate_MFSV, "most-free-space:%d"},
21705 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
21706 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
21707 + {AuWbrCreate_PMFS, "pmfs"},
21708 + {AuWbrCreate_PMFSV, "pmfs:%d"},
21709 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
21710 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
21716 + * cf. linux/lib/parser.c and cmdline.c
21717 + * gave up calling memparse() since it uses simple_strtoull() instead of
21720 +static int noinline_for_stack
21721 +au_match_ull(substring_t *s, unsigned long long *result)
21724 + unsigned int len;
21728 + len = s->to - s->from;
21729 + if (len + 1 <= sizeof(a)) {
21730 + memcpy(a, s->from, len);
21732 + err = kstrtoull(a, 0, result);
21737 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
21738 + struct au_opt_wbr_create *create)
21741 + unsigned long long ull;
21744 + if (!au_match_ull(arg, &ull))
21745 + create->mfsrr_watermark = ull;
21747 + pr_err("bad integer in %s\n", str);
21754 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
21755 + struct au_opt_wbr_create *create)
21760 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
21761 + create->mfs_second = n;
21763 + pr_err("bad integer in %s\n", str);
21770 +static int noinline_for_stack
21771 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
21774 + substring_t args[MAX_OPT_ARGS];
21776 + err = match_token(str, au_wbr_create_policy, args);
21777 + create->wbr_create = err;
21779 + case AuWbrCreate_MFSRRV:
21780 + case AuWbrCreate_PMFSRRV:
21781 + e = au_wbr_mfs_wmark(&args[0], str, create);
21783 + e = au_wbr_mfs_sec(&args[1], str, create);
21787 + case AuWbrCreate_MFSRR:
21788 + case AuWbrCreate_PMFSRR:
21789 + e = au_wbr_mfs_wmark(&args[0], str, create);
21790 + if (unlikely(e)) {
21795 + case AuWbrCreate_MFS:
21796 + case AuWbrCreate_PMFS:
21797 + create->mfs_second = AUFS_MFS_DEF_SEC;
21799 + case AuWbrCreate_MFSV:
21800 + case AuWbrCreate_PMFSV:
21801 + e = au_wbr_mfs_sec(&args[0], str, create);
21810 +const char *au_optstr_wbr_create(int wbr_create)
21812 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
21815 +static match_table_t au_wbr_copyup_policy = {
21816 + {AuWbrCopyup_TDP, "tdp"},
21817 + {AuWbrCopyup_TDP, "top-down-parent"},
21818 + {AuWbrCopyup_BUP, "bup"},
21819 + {AuWbrCopyup_BUP, "bottom-up-parent"},
21820 + {AuWbrCopyup_BU, "bu"},
21821 + {AuWbrCopyup_BU, "bottom-up"},
21825 +static int noinline_for_stack au_wbr_copyup_val(char *str)
21827 + substring_t args[MAX_OPT_ARGS];
21829 + return match_token(str, au_wbr_copyup_policy, args);
21832 +const char *au_optstr_wbr_copyup(int wbr_copyup)
21834 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
21837 +/* ---------------------------------------------------------------------- */
21839 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
21841 +static void dump_opts(struct au_opts *opts)
21843 +#ifdef CONFIG_AUFS_DEBUG
21844 + /* reduce stack space */
21846 + struct au_opt_add *add;
21847 + struct au_opt_del *del;
21848 + struct au_opt_mod *mod;
21849 + struct au_opt_xino *xino;
21850 + struct au_opt_xino_itrunc *xino_itrunc;
21851 + struct au_opt_wbr_create *create;
21853 + struct au_opt *opt;
21856 + while (opt->type != Opt_tail) {
21857 + switch (opt->type) {
21859 + u.add = &opt->add;
21860 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
21861 + u.add->bindex, u.add->pathname, u.add->perm,
21862 + u.add->path.dentry);
21866 + u.del = &opt->del;
21867 + AuDbg("del {%s, %p}\n",
21868 + u.del->pathname, u.del->h_path.dentry);
21872 + u.mod = &opt->mod;
21873 + AuDbg("mod {%s, 0x%x, %p}\n",
21874 + u.mod->path, u.mod->perm, u.mod->h_root);
21877 + u.add = &opt->add;
21878 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
21879 + u.add->bindex, u.add->pathname, u.add->perm,
21880 + u.add->path.dentry);
21882 + case Opt_prepend:
21883 + u.add = &opt->add;
21884 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
21885 + u.add->bindex, u.add->pathname, u.add->perm,
21886 + u.add->path.dentry);
21889 + AuDbg("dirwh %d\n", opt->dirwh);
21891 + case Opt_rdcache:
21892 + AuDbg("rdcache %d\n", opt->rdcache);
21895 + AuDbg("rdblk %u\n", opt->rdblk);
21897 + case Opt_rdblk_def:
21898 + AuDbg("rdblk_def\n");
21901 + AuDbg("rdhash %u\n", opt->rdhash);
21903 + case Opt_rdhash_def:
21904 + AuDbg("rdhash_def\n");
21907 + u.xino = &opt->xino;
21908 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
21910 + case Opt_trunc_xino:
21911 + AuLabel(trunc_xino);
21913 + case Opt_notrunc_xino:
21914 + AuLabel(notrunc_xino);
21916 + case Opt_trunc_xino_path:
21917 + case Opt_itrunc_xino:
21918 + u.xino_itrunc = &opt->xino_itrunc;
21919 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
21925 + case Opt_trunc_xib:
21926 + AuLabel(trunc_xib);
21928 + case Opt_notrunc_xib:
21929 + AuLabel(notrunc_xib);
21940 + case Opt_noplink:
21941 + AuLabel(noplink);
21943 + case Opt_list_plink:
21944 + AuLabel(list_plink);
21947 + AuDbg("udba %d, %s\n",
21948 + opt->udba, au_optstr_udba(opt->udba));
21956 + case Opt_diropq_a:
21957 + AuLabel(diropq_a);
21959 + case Opt_diropq_w:
21960 + AuLabel(diropq_w);
21962 + case Opt_warn_perm:
21963 + AuLabel(warn_perm);
21965 + case Opt_nowarn_perm:
21966 + AuLabel(nowarn_perm);
21971 + case Opt_norefrof:
21972 + AuLabel(norefrof);
21974 + case Opt_verbose:
21975 + AuLabel(verbose);
21977 + case Opt_noverbose:
21978 + AuLabel(noverbose);
21989 + case Opt_wbr_create:
21990 + u.create = &opt->wbr_create;
21991 + AuDbg("create %d, %s\n", u.create->wbr_create,
21992 + au_optstr_wbr_create(u.create->wbr_create));
21993 + switch (u.create->wbr_create) {
21994 + case AuWbrCreate_MFSV:
21995 + case AuWbrCreate_PMFSV:
21996 + AuDbg("%d sec\n", u.create->mfs_second);
21998 + case AuWbrCreate_MFSRR:
21999 + AuDbg("%llu watermark\n",
22000 + u.create->mfsrr_watermark);
22002 + case AuWbrCreate_MFSRRV:
22003 + case AuWbrCreate_PMFSRRV:
22004 + AuDbg("%llu watermark, %d sec\n",
22005 + u.create->mfsrr_watermark,
22006 + u.create->mfs_second);
22010 + case Opt_wbr_copyup:
22011 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
22012 + au_optstr_wbr_copyup(opt->wbr_copyup));
22022 +void au_opts_free(struct au_opts *opts)
22024 + struct au_opt *opt;
22027 + while (opt->type != Opt_tail) {
22028 + switch (opt->type) {
22031 + case Opt_prepend:
22032 + path_put(&opt->add.path);
22036 + path_put(&opt->del.h_path);
22040 + dput(opt->mod.h_root);
22043 + fput(opt->xino.file);
22050 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
22051 + aufs_bindex_t bindex)
22054 + struct au_opt_add *add = &opt->add;
22057 + add->bindex = bindex;
22058 + add->perm = AuBrPerm_RO;
22059 + add->pathname = opt_str;
22060 + p = strchr(opt_str, '=');
22064 + add->perm = br_perm_val(p);
22067 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
22070 + add->perm = AuBrPerm_RO;
22071 + if (au_test_fs_rr(add->path.dentry->d_sb))
22072 + add->perm = AuBrPerm_RR;
22073 + else if (!bindex && !(sb_flags & MS_RDONLY))
22074 + add->perm = AuBrPerm_RW;
22076 + opt->type = Opt_add;
22079 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
22086 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
22090 + del->pathname = args[0].from;
22091 + AuDbg("del path %s\n", del->pathname);
22093 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
22094 + if (unlikely(err))
22095 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
22100 +#if 0 /* reserved for future use */
22101 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
22102 + struct au_opt_del *del, substring_t args[])
22105 + struct dentry *root;
22108 + root = sb->s_root;
22109 + aufs_read_lock(root, AuLock_FLUSH);
22110 + if (bindex < 0 || au_sbend(sb) < bindex) {
22111 + pr_err("out of bounds, %d\n", bindex);
22116 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
22117 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
22120 + aufs_read_unlock(root, !AuLock_IR);
22125 +static int noinline_for_stack
22126 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
22129 + struct path path;
22133 + mod->path = args[0].from;
22134 + p = strchr(mod->path, '=');
22135 + if (unlikely(!p)) {
22136 + pr_err("no permssion %s\n", args[0].from);
22141 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
22142 + if (unlikely(err)) {
22143 + pr_err("lookup failed %s (%d)\n", mod->path, err);
22147 + mod->perm = br_perm_val(p);
22148 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
22149 + mod->h_root = dget(path.dentry);
22156 +#if 0 /* reserved for future use */
22157 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
22158 + struct au_opt_mod *mod, substring_t args[])
22161 + struct dentry *root;
22164 + root = sb->s_root;
22165 + aufs_read_lock(root, AuLock_FLUSH);
22166 + if (bindex < 0 || au_sbend(sb) < bindex) {
22167 + pr_err("out of bounds, %d\n", bindex);
22172 + mod->perm = br_perm_val(args[1].from);
22173 + AuDbg("mod path %s, perm 0x%x, %s\n",
22174 + mod->path, mod->perm, args[1].from);
22175 + mod->h_root = dget(au_h_dptr(root, bindex));
22178 + aufs_read_unlock(root, !AuLock_IR);
22183 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
22184 + substring_t args[])
22187 + struct file *file;
22189 + file = au_xino_create(sb, args[0].from, /*silent*/0);
22190 + err = PTR_ERR(file);
22191 + if (IS_ERR(file))
22195 + if (unlikely(file->f_dentry->d_sb == sb)) {
22197 + pr_err("%s must be outside\n", args[0].from);
22202 + xino->file = file;
22203 + xino->path = args[0].from;
22209 +static int noinline_for_stack
22210 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
22211 + struct au_opt_xino_itrunc *xino_itrunc,
22212 + substring_t args[])
22215 + aufs_bindex_t bend, bindex;
22216 + struct path path;
22217 + struct dentry *root;
22219 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
22220 + if (unlikely(err)) {
22221 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
22225 + xino_itrunc->bindex = -1;
22226 + root = sb->s_root;
22227 + aufs_read_lock(root, AuLock_FLUSH);
22228 + bend = au_sbend(sb);
22229 + for (bindex = 0; bindex <= bend; bindex++) {
22230 + if (au_h_dptr(root, bindex) == path.dentry) {
22231 + xino_itrunc->bindex = bindex;
22235 + aufs_read_unlock(root, !AuLock_IR);
22238 + if (unlikely(xino_itrunc->bindex < 0)) {
22239 + pr_err("no such branch %s\n", args[0].from);
22247 +/* called without aufs lock */
22248 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
22250 + int err, n, token;
22251 + aufs_bindex_t bindex;
22252 + unsigned char skipped;
22253 + struct dentry *root;
22254 + struct au_opt *opt, *opt_tail;
22256 + /* reduce the stack space */
22258 + struct au_opt_xino_itrunc *xino_itrunc;
22259 + struct au_opt_wbr_create *create;
22262 + substring_t args[MAX_OPT_ARGS];
22266 + a = kmalloc(sizeof(*a), GFP_NOFS);
22267 + if (unlikely(!a))
22270 + root = sb->s_root;
22274 + opt_tail = opt + opts->max_opt - 1;
22275 + opt->type = Opt_tail;
22276 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
22279 + token = match_token(opt_str, options, a->args);
22283 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
22285 + err = opt_add(opt, opt_str, opts->sb_flags,
22287 + if (unlikely(!err && ++opt > opt_tail)) {
22291 + opt->type = Opt_tail;
22296 + if (unlikely(match_int(&a->args[0], &n))) {
22297 + pr_err("bad integer in %s\n", opt_str);
22301 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
22304 + opt->type = token;
22307 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
22308 + /*dummy bindex*/1);
22310 + opt->type = token;
22312 + case Opt_prepend:
22313 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
22316 + opt->type = token;
22319 + err = au_opts_parse_del(&opt->del, a->args);
22321 + opt->type = token;
22323 +#if 0 /* reserved for future use */
22325 + del->pathname = "(indexed)";
22326 + if (unlikely(match_int(&args[0], &n))) {
22327 + pr_err("bad integer in %s\n", opt_str);
22330 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
22332 + opt->type = token;
22336 + err = au_opts_parse_mod(&opt->mod, a->args);
22338 + opt->type = token;
22340 +#ifdef IMOD /* reserved for future use */
22342 + u.mod->path = "(indexed)";
22343 + if (unlikely(match_int(&a->args[0], &n))) {
22344 + pr_err("bad integer in %s\n", opt_str);
22347 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
22349 + opt->type = token;
22353 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
22355 + opt->type = token;
22358 + case Opt_trunc_xino_path:
22359 + err = au_opts_parse_xino_itrunc_path
22360 + (sb, &opt->xino_itrunc, a->args);
22362 + opt->type = token;
22365 + case Opt_itrunc_xino:
22366 + u.xino_itrunc = &opt->xino_itrunc;
22367 + if (unlikely(match_int(&a->args[0], &n))) {
22368 + pr_err("bad integer in %s\n", opt_str);
22371 + u.xino_itrunc->bindex = n;
22372 + aufs_read_lock(root, AuLock_FLUSH);
22373 + if (n < 0 || au_sbend(sb) < n) {
22374 + pr_err("out of bounds, %d\n", n);
22375 + aufs_read_unlock(root, !AuLock_IR);
22378 + aufs_read_unlock(root, !AuLock_IR);
22380 + opt->type = token;
22384 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
22387 + opt->type = token;
22390 + case Opt_rdcache:
22391 + if (unlikely(match_int(&a->args[0], &n))) {
22392 + pr_err("bad integer in %s\n", opt_str);
22395 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
22396 + pr_err("rdcache must be smaller than %d\n",
22397 + AUFS_RDCACHE_MAX);
22400 + opt->rdcache = n;
22402 + opt->type = token;
22405 + if (unlikely(match_int(&a->args[0], &n)
22407 + || n > KMALLOC_MAX_SIZE)) {
22408 + pr_err("bad integer in %s\n", opt_str);
22411 + if (unlikely(n && n < NAME_MAX)) {
22412 + pr_err("rdblk must be larger than %d\n",
22418 + opt->type = token;
22421 + if (unlikely(match_int(&a->args[0], &n)
22423 + || n * sizeof(struct hlist_head)
22424 + > KMALLOC_MAX_SIZE)) {
22425 + pr_err("bad integer in %s\n", opt_str);
22430 + opt->type = token;
22433 + case Opt_trunc_xino:
22434 + case Opt_notrunc_xino:
22436 + case Opt_trunc_xib:
22437 + case Opt_notrunc_xib:
22441 + case Opt_noplink:
22442 + case Opt_list_plink:
22445 + case Opt_diropq_a:
22446 + case Opt_diropq_w:
22447 + case Opt_warn_perm:
22448 + case Opt_nowarn_perm:
22450 + case Opt_norefrof:
22451 + case Opt_verbose:
22452 + case Opt_noverbose:
22456 + case Opt_rdblk_def:
22457 + case Opt_rdhash_def:
22459 + opt->type = token;
22463 + opt->udba = udba_val(a->args[0].from);
22464 + if (opt->udba >= 0) {
22466 + opt->type = token;
22468 + pr_err("wrong value, %s\n", opt_str);
22471 + case Opt_wbr_create:
22472 + u.create = &opt->wbr_create;
22473 + u.create->wbr_create
22474 + = au_wbr_create_val(a->args[0].from, u.create);
22475 + if (u.create->wbr_create >= 0) {
22477 + opt->type = token;
22479 + pr_err("wrong value, %s\n", opt_str);
22481 + case Opt_wbr_copyup:
22482 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
22483 + if (opt->wbr_copyup >= 0) {
22485 + opt->type = token;
22487 + pr_err("wrong value, %s\n", opt_str);
22491 + pr_warn("ignored %s\n", opt_str);
22493 + case Opt_ignore_silent:
22498 + pr_err("unknown option %s\n", opt_str);
22502 + if (!err && !skipped) {
22503 + if (unlikely(++opt > opt_tail)) {
22506 + opt->type = Opt_tail;
22509 + opt->type = Opt_tail;
22515 + if (unlikely(err))
22516 + au_opts_free(opts);
22522 +static int au_opt_wbr_create(struct super_block *sb,
22523 + struct au_opt_wbr_create *create)
22526 + struct au_sbinfo *sbinfo;
22528 + SiMustWriteLock(sb);
22530 + err = 1; /* handled */
22531 + sbinfo = au_sbi(sb);
22532 + if (sbinfo->si_wbr_create_ops->fin) {
22533 + err = sbinfo->si_wbr_create_ops->fin(sb);
22538 + sbinfo->si_wbr_create = create->wbr_create;
22539 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
22540 + switch (create->wbr_create) {
22541 + case AuWbrCreate_MFSRRV:
22542 + case AuWbrCreate_MFSRR:
22543 + case AuWbrCreate_PMFSRR:
22544 + case AuWbrCreate_PMFSRRV:
22545 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
22547 + case AuWbrCreate_MFS:
22548 + case AuWbrCreate_MFSV:
22549 + case AuWbrCreate_PMFS:
22550 + case AuWbrCreate_PMFSV:
22551 + sbinfo->si_wbr_mfs.mfs_expire
22552 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
22556 + if (sbinfo->si_wbr_create_ops->init)
22557 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
22564 + * plus: processed without an error
22565 + * zero: unprocessed
22567 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
22568 + struct au_opts *opts)
22571 + struct au_sbinfo *sbinfo;
22573 + SiMustWriteLock(sb);
22575 + err = 1; /* handled */
22576 + sbinfo = au_sbi(sb);
22577 + switch (opt->type) {
22579 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22580 + sbinfo->si_mntflags |= opt->udba;
22581 + opts->given_udba |= opt->udba;
22585 + au_opt_set(sbinfo->si_mntflags, PLINK);
22587 + case Opt_noplink:
22588 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
22589 + au_plink_put(sb, /*verbose*/1);
22590 + au_opt_clr(sbinfo->si_mntflags, PLINK);
22592 + case Opt_list_plink:
22593 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
22594 + au_plink_list(sb);
22598 + au_opt_set(sbinfo->si_mntflags, DIO);
22599 + au_fset_opts(opts->flags, REFRESH_DYAOP);
22602 + au_opt_clr(sbinfo->si_mntflags, DIO);
22603 + au_fset_opts(opts->flags, REFRESH_DYAOP);
22606 + case Opt_diropq_a:
22607 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
22609 + case Opt_diropq_w:
22610 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
22613 + case Opt_warn_perm:
22614 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
22616 + case Opt_nowarn_perm:
22617 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
22621 + au_opt_set(sbinfo->si_mntflags, REFROF);
22623 + case Opt_norefrof:
22624 + au_opt_clr(sbinfo->si_mntflags, REFROF);
22627 + case Opt_verbose:
22628 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
22630 + case Opt_noverbose:
22631 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
22635 + au_opt_set(sbinfo->si_mntflags, SUM);
22638 + au_opt_clr(sbinfo->si_mntflags, SUM);
22639 + au_opt_set(sbinfo->si_mntflags, SUM_W);
22641 + au_opt_clr(sbinfo->si_mntflags, SUM);
22642 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
22645 + case Opt_wbr_create:
22646 + err = au_opt_wbr_create(sb, &opt->wbr_create);
22648 + case Opt_wbr_copyup:
22649 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
22650 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
22654 + sbinfo->si_dirwh = opt->dirwh;
22657 + case Opt_rdcache:
22658 + sbinfo->si_rdcache
22659 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
22662 + sbinfo->si_rdblk = opt->rdblk;
22664 + case Opt_rdblk_def:
22665 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
22668 + sbinfo->si_rdhash = opt->rdhash;
22670 + case Opt_rdhash_def:
22671 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
22675 + au_opt_set(sbinfo->si_mntflags, SHWH);
22678 + au_opt_clr(sbinfo->si_mntflags, SHWH);
22681 + case Opt_trunc_xino:
22682 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
22684 + case Opt_notrunc_xino:
22685 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
22688 + case Opt_trunc_xino_path:
22689 + case Opt_itrunc_xino:
22690 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
22695 + case Opt_trunc_xib:
22696 + au_fset_opts(opts->flags, TRUNC_XIB);
22698 + case Opt_notrunc_xib:
22699 + au_fclr_opts(opts->flags, TRUNC_XIB);
22711 + * returns tri-state.
22712 + * plus: processed without an error
22713 + * zero: unprocessed
22716 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
22717 + struct au_opts *opts)
22719 + int err, do_refresh;
22722 + switch (opt->type) {
22724 + opt->add.bindex = au_sbend(sb) + 1;
22725 + if (opt->add.bindex < 0)
22726 + opt->add.bindex = 0;
22728 + case Opt_prepend:
22729 + opt->add.bindex = 0;
22730 + add: /* indented label */
22732 + err = au_br_add(sb, &opt->add,
22733 + au_ftest_opts(opts->flags, REMOUNT));
22736 + au_fset_opts(opts->flags, REFRESH);
22742 + err = au_br_del(sb, &opt->del,
22743 + au_ftest_opts(opts->flags, REMOUNT));
22746 + au_fset_opts(opts->flags, TRUNC_XIB);
22747 + au_fset_opts(opts->flags, REFRESH);
22753 + err = au_br_mod(sb, &opt->mod,
22754 + au_ftest_opts(opts->flags, REMOUNT),
22759 + au_fset_opts(opts->flags, REFRESH);
22767 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
22768 + struct au_opt_xino **opt_xino,
22769 + struct au_opts *opts)
22772 + aufs_bindex_t bend, bindex;
22773 + struct dentry *root, *parent, *h_root;
22776 + switch (opt->type) {
22778 + err = au_xino_set(sb, &opt->xino,
22779 + !!au_ftest_opts(opts->flags, REMOUNT));
22780 + if (unlikely(err))
22783 + *opt_xino = &opt->xino;
22784 + au_xino_brid_set(sb, -1);
22786 + /* safe d_parent access */
22787 + parent = opt->xino.file->f_dentry->d_parent;
22788 + root = sb->s_root;
22789 + bend = au_sbend(sb);
22790 + for (bindex = 0; bindex <= bend; bindex++) {
22791 + h_root = au_h_dptr(root, bindex);
22792 + if (h_root == parent) {
22793 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
22801 + au_xino_brid_set(sb, -1);
22802 + *opt_xino = (void *)-1;
22809 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
22810 + unsigned int pending)
22813 + aufs_bindex_t bindex, bend;
22814 + unsigned char do_plink, skip, do_free;
22815 + struct au_branch *br;
22816 + struct au_wbr *wbr;
22817 + struct dentry *root;
22818 + struct inode *dir, *h_dir;
22819 + struct au_sbinfo *sbinfo;
22820 + struct au_hinode *hdir;
22822 + SiMustAnyLock(sb);
22824 + sbinfo = au_sbi(sb);
22825 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
22827 + if (!(sb_flags & MS_RDONLY)) {
22828 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
22829 + pr_warn("first branch should be rw\n");
22830 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
22831 + pr_warn("shwh should be used with ro\n");
22834 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
22835 + && !au_opt_test(sbinfo->si_mntflags, XINO))
22836 + pr_warn("udba=*notify requires xino\n");
22839 + root = sb->s_root;
22840 + dir = root->d_inode;
22841 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
22842 + bend = au_sbend(sb);
22843 + for (bindex = 0; !err && bindex <= bend; bindex++) {
22845 + h_dir = au_h_iptr(dir, bindex);
22846 + br = au_sbr(sb, bindex);
22849 + wbr = br->br_wbr;
22851 + wbr_wh_read_lock(wbr);
22853 + if (!au_br_writable(br->br_perm)) {
22856 + || (!wbr->wbr_whbase
22857 + && !wbr->wbr_plink
22858 + && !wbr->wbr_orph));
22859 + } else if (!au_br_wh_linkable(br->br_perm)) {
22860 + /* skip = (!br->br_whbase && !br->br_orph); */
22861 + skip = (!wbr || !wbr->wbr_whbase);
22862 + if (skip && wbr) {
22864 + skip = !!wbr->wbr_plink;
22866 + skip = !wbr->wbr_plink;
22869 + /* skip = (br->br_whbase && br->br_ohph); */
22870 + skip = (wbr && wbr->wbr_whbase);
22873 + skip = !!wbr->wbr_plink;
22875 + skip = !wbr->wbr_plink;
22879 + wbr_wh_read_unlock(wbr);
22884 + hdir = au_hi(dir, bindex);
22885 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
22887 + wbr_wh_write_lock(wbr);
22888 + err = au_wh_init(br, sb);
22890 + wbr_wh_write_unlock(wbr);
22891 + au_hn_imtx_unlock(hdir);
22893 + if (!err && do_free) {
22895 + br->br_wbr = NULL;
22902 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
22905 + unsigned int tmp;
22906 + aufs_bindex_t bindex, bend;
22907 + struct au_opt *opt;
22908 + struct au_opt_xino *opt_xino, xino;
22909 + struct au_sbinfo *sbinfo;
22910 + struct au_branch *br;
22912 + SiMustWriteLock(sb);
22917 + while (err >= 0 && opt->type != Opt_tail)
22918 + err = au_opt_simple(sb, opt++, opts);
22921 + else if (unlikely(err < 0))
22924 + /* disable xino and udba temporary */
22925 + sbinfo = au_sbi(sb);
22926 + tmp = sbinfo->si_mntflags;
22927 + au_opt_clr(sbinfo->si_mntflags, XINO);
22928 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
22931 + while (err >= 0 && opt->type != Opt_tail)
22932 + err = au_opt_br(sb, opt++, opts);
22935 + else if (unlikely(err < 0))
22938 + bend = au_sbend(sb);
22939 + if (unlikely(bend < 0)) {
22941 + pr_err("no branches\n");
22945 + if (au_opt_test(tmp, XINO))
22946 + au_opt_set(sbinfo->si_mntflags, XINO);
22948 + while (!err && opt->type != Opt_tail)
22949 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
22950 + if (unlikely(err))
22953 + err = au_opts_verify(sb, sb->s_flags, tmp);
22954 + if (unlikely(err))
22957 + /* restore xino */
22958 + if (au_opt_test(tmp, XINO) && !opt_xino) {
22959 + xino.file = au_xino_def(sb);
22960 + err = PTR_ERR(xino.file);
22961 + if (IS_ERR(xino.file))
22964 + err = au_xino_set(sb, &xino, /*remount*/0);
22966 + if (unlikely(err))
22970 + /* restore udba */
22971 + tmp &= AuOptMask_UDBA;
22972 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
22973 + sbinfo->si_mntflags |= tmp;
22974 + bend = au_sbend(sb);
22975 + for (bindex = 0; bindex <= bend; bindex++) {
22976 + br = au_sbr(sb, bindex);
22977 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
22978 + if (unlikely(err))
22979 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
22981 + /* go on even if err */
22983 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
22984 + struct inode *dir = sb->s_root->d_inode;
22985 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
22992 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
22995 + struct inode *dir;
22996 + struct au_opt_xino *opt_xino;
22997 + struct au_opt *opt;
22998 + struct au_sbinfo *sbinfo;
23000 + SiMustWriteLock(sb);
23002 + dir = sb->s_root->d_inode;
23003 + sbinfo = au_sbi(sb);
23007 + while (err >= 0 && opt->type != Opt_tail) {
23008 + err = au_opt_simple(sb, opt, opts);
23010 + err = au_opt_br(sb, opt, opts);
23012 + err = au_opt_xino(sb, opt, &opt_xino, opts);
23018 + /* go on even err */
23020 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
23021 + if (unlikely(rerr && !err))
23024 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
23025 + rerr = au_xib_trunc(sb);
23026 + if (unlikely(rerr && !err))
23030 + /* will be handled by the caller */
23031 + if (!au_ftest_opts(opts->flags, REFRESH)
23032 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
23033 + au_fset_opts(opts->flags, REFRESH);
23035 + AuDbg("status 0x%x\n", opts->flags);
23039 +/* ---------------------------------------------------------------------- */
23041 +unsigned int au_opt_udba(struct super_block *sb)
23043 + return au_mntflags(sb) & AuOptMask_UDBA;
23045 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
23046 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
23047 +++ linux/fs/aufs/opts.h 2014-04-24 22:11:10.855269116 +0200
23050 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23052 + * This program, aufs is free software; you can redistribute it and/or modify
23053 + * it under the terms of the GNU General Public License as published by
23054 + * the Free Software Foundation; either version 2 of the License, or
23055 + * (at your option) any later version.
23057 + * This program is distributed in the hope that it will be useful,
23058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23060 + * GNU General Public License for more details.
23062 + * You should have received a copy of the GNU General Public License
23063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23067 + * mount options/flags
23070 +#ifndef __AUFS_OPTS_H__
23071 +#define __AUFS_OPTS_H__
23075 +#include <linux/path.h>
23078 +struct super_block;
23080 +/* ---------------------------------------------------------------------- */
23083 +#define AuOpt_XINO 1 /* external inode number bitmap
23084 + and translation table */
23085 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
23086 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
23087 +#define AuOpt_UDBA_REVAL (1 << 3)
23088 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
23089 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
23090 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
23091 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
23092 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
23093 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
23094 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
23095 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
23096 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
23097 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
23098 +#define AuOpt_DIO (1 << 14) /* direct io */
23100 +#ifndef CONFIG_AUFS_HNOTIFY
23101 +#undef AuOpt_UDBA_HNOTIFY
23102 +#define AuOpt_UDBA_HNOTIFY 0
23104 +#ifndef CONFIG_AUFS_SHWH
23106 +#define AuOpt_SHWH 0
23109 +#define AuOpt_Def (AuOpt_XINO \
23110 + | AuOpt_UDBA_REVAL \
23112 + /* | AuOpt_DIRPERM1 */ \
23113 + | AuOpt_WARN_PERM)
23114 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
23115 + | AuOpt_UDBA_REVAL \
23116 + | AuOpt_UDBA_HNOTIFY)
23118 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
23119 +#define au_opt_set(flags, name) do { \
23120 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
23121 + ((flags) |= AuOpt_##name); \
23123 +#define au_opt_set_udba(flags, name) do { \
23124 + (flags) &= ~AuOptMask_UDBA; \
23125 + ((flags) |= AuOpt_##name); \
23127 +#define au_opt_clr(flags, name) do { \
23128 + ((flags) &= ~AuOpt_##name); \
23131 +static inline unsigned int au_opts_plink(unsigned int mntflags)
23133 +#ifdef CONFIG_PROC_FS
23136 + return mntflags & ~AuOpt_PLINK;
23140 +/* ---------------------------------------------------------------------- */
23142 +/* policies to select one among multiple writable branches */
23144 + AuWbrCreate_TDP, /* top down parent */
23145 + AuWbrCreate_RR, /* round robin */
23146 + AuWbrCreate_MFS, /* most free space */
23147 + AuWbrCreate_MFSV, /* mfs with seconds */
23148 + AuWbrCreate_MFSRR, /* mfs then rr */
23149 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
23150 + AuWbrCreate_PMFS, /* parent and mfs */
23151 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
23152 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
23153 + AuWbrCreate_PMFSRRV, /* plus seconds */
23155 + AuWbrCreate_Def = AuWbrCreate_TDP
23159 + AuWbrCopyup_TDP, /* top down parent */
23160 + AuWbrCopyup_BUP, /* bottom up parent */
23161 + AuWbrCopyup_BU, /* bottom up */
23163 + AuWbrCopyup_Def = AuWbrCopyup_TDP
23166 +/* ---------------------------------------------------------------------- */
23168 +struct au_opt_add {
23169 + aufs_bindex_t bindex;
23172 + struct path path;
23175 +struct au_opt_del {
23177 + struct path h_path;
23180 +struct au_opt_mod {
23183 + struct dentry *h_root;
23186 +struct au_opt_xino {
23188 + struct file *file;
23191 +struct au_opt_xino_itrunc {
23192 + aufs_bindex_t bindex;
23195 +struct au_opt_wbr_create {
23198 + unsigned long long mfsrr_watermark;
23204 + struct au_opt_xino xino;
23205 + struct au_opt_xino_itrunc xino_itrunc;
23206 + struct au_opt_add add;
23207 + struct au_opt_del del;
23208 + struct au_opt_mod mod;
23211 + unsigned int rdblk;
23212 + unsigned int rdhash;
23214 + struct au_opt_wbr_create wbr_create;
23220 +#define AuOpts_REMOUNT 1
23221 +#define AuOpts_REFRESH (1 << 1)
23222 +#define AuOpts_TRUNC_XIB (1 << 2)
23223 +#define AuOpts_REFRESH_DYAOP (1 << 3)
23224 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
23225 +#define au_fset_opts(flags, name) \
23226 + do { (flags) |= AuOpts_##name; } while (0)
23227 +#define au_fclr_opts(flags, name) \
23228 + do { (flags) &= ~AuOpts_##name; } while (0)
23231 + struct au_opt *opt;
23234 + unsigned int given_udba;
23235 + unsigned int flags;
23236 + unsigned long sb_flags;
23239 +/* ---------------------------------------------------------------------- */
23241 +char *au_optstr_br_perm(int brperm);
23242 +const char *au_optstr_udba(int udba);
23243 +const char *au_optstr_wbr_copyup(int wbr_copyup);
23244 +const char *au_optstr_wbr_create(int wbr_create);
23246 +void au_opts_free(struct au_opts *opts);
23247 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
23248 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
23249 + unsigned int pending);
23250 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
23251 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
23253 +unsigned int au_opt_udba(struct super_block *sb);
23255 +/* ---------------------------------------------------------------------- */
23257 +#endif /* __KERNEL__ */
23258 +#endif /* __AUFS_OPTS_H__ */
23259 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
23260 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
23261 +++ linux/fs/aufs/plink.c 2014-04-24 22:11:10.855269116 +0200
23264 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23266 + * This program, aufs is free software; you can redistribute it and/or modify
23267 + * it under the terms of the GNU General Public License as published by
23268 + * the Free Software Foundation; either version 2 of the License, or
23269 + * (at your option) any later version.
23271 + * This program is distributed in the hope that it will be useful,
23272 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23273 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23274 + * GNU General Public License for more details.
23276 + * You should have received a copy of the GNU General Public License
23277 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23287 + * the pseudo-link maintenance mode.
23288 + * during a user process maintains the pseudo-links,
23289 + * prohibit adding a new plink and branch manipulation.
23293 + * For entry functions which will handle plink, and i_mutex is already held
23295 + * They cannot wait and should return an error at once.
23296 + * Callers has to check the error.
23298 + * For entry functions which will handle plink, but i_mutex is not held
23300 + * They can wait the plink maintenance mode to finish.
23302 + * They behave like F_SETLK and F_SETLKW.
23303 + * If the caller never handle plink, then both flags are unnecessary.
23306 +int au_plink_maint(struct super_block *sb, int flags)
23310 + struct au_sbinfo *sbi;
23312 + SiMustAnyLock(sb);
23315 + if (!au_opt_test(au_mntflags(sb), PLINK))
23318 + sbi = au_sbi(sb);
23319 + pid = sbi->si_plink_maint_pid;
23320 + if (!pid || pid == current->pid)
23323 + /* todo: it highly depends upon /sbin/mount.aufs */
23325 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
23326 + rcu_read_unlock();
23330 + if (au_ftest_lock(flags, NOPLMW)) {
23331 + /* if there is no i_mutex lock in VFS, we don't need to wait */
23332 + /* AuDebugOn(!lockdep_depth(current)); */
23333 + while (sbi->si_plink_maint_pid) {
23334 + si_read_unlock(sb);
23335 + /* gave up wake_up_bit() */
23336 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
23338 + if (au_ftest_lock(flags, FLUSH))
23339 + au_nwt_flush(&sbi->si_nowait);
23340 + si_noflush_read_lock(sb);
23342 + } else if (au_ftest_lock(flags, NOPLM)) {
23343 + AuDbg("ppid %d, pid %d\n", ppid, pid);
23351 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
23353 + spin_lock(&sbinfo->si_plink_maint_lock);
23354 + sbinfo->si_plink_maint_pid = 0;
23355 + spin_unlock(&sbinfo->si_plink_maint_lock);
23356 + wake_up_all(&sbinfo->si_plink_wq);
23359 +int au_plink_maint_enter(struct super_block *sb)
23362 + struct au_sbinfo *sbinfo;
23365 + sbinfo = au_sbi(sb);
23366 + /* make sure i am the only one in this fs */
23367 + si_write_lock(sb, AuLock_FLUSH);
23368 + if (au_opt_test(au_mntflags(sb), PLINK)) {
23369 + spin_lock(&sbinfo->si_plink_maint_lock);
23370 + if (!sbinfo->si_plink_maint_pid)
23371 + sbinfo->si_plink_maint_pid = current->pid;
23374 + spin_unlock(&sbinfo->si_plink_maint_lock);
23376 + si_write_unlock(sb);
23381 +/* ---------------------------------------------------------------------- */
23383 +#ifdef CONFIG_AUFS_DEBUG
23384 +void au_plink_list(struct super_block *sb)
23387 + struct au_sbinfo *sbinfo;
23388 + struct hlist_head *plink_hlist;
23389 + struct pseudo_link *plink;
23391 + SiMustAnyLock(sb);
23393 + sbinfo = au_sbi(sb);
23394 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23395 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23397 + for (i = 0; i < AuPlink_NHASH; i++) {
23398 + plink_hlist = &sbinfo->si_plink[i].head;
23400 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
23401 + AuDbg("%lu\n", plink->inode->i_ino);
23402 + rcu_read_unlock();
23407 +/* is the inode pseudo-linked? */
23408 +int au_plink_test(struct inode *inode)
23411 + struct au_sbinfo *sbinfo;
23412 + struct hlist_head *plink_hlist;
23413 + struct pseudo_link *plink;
23415 + sbinfo = au_sbi(inode->i_sb);
23416 + AuRwMustAnyLock(&sbinfo->si_rwsem);
23417 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
23418 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
23421 + i = au_plink_hash(inode->i_ino);
23422 + plink_hlist = &sbinfo->si_plink[i].head;
23424 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
23425 + if (plink->inode == inode) {
23429 + rcu_read_unlock();
23433 +/* ---------------------------------------------------------------------- */
23436 + * generate a name for plink.
23437 + * the file will be stored under AUFS_WH_PLINKDIR.
23439 +/* 20 is max digits length of ulong 64 */
23440 +#define PLINK_NAME_LEN ((20 + 1) * 2)
23442 +static int plink_name(char *name, int len, struct inode *inode,
23443 + aufs_bindex_t bindex)
23446 + struct inode *h_inode;
23448 + h_inode = au_h_iptr(inode, bindex);
23449 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
23453 +struct au_do_plink_lkup_args {
23454 + struct dentry **errp;
23455 + struct qstr *tgtname;
23456 + struct dentry *h_parent;
23457 + struct au_branch *br;
23460 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
23461 + struct dentry *h_parent,
23462 + struct au_branch *br)
23464 + struct dentry *h_dentry;
23465 + struct mutex *h_mtx;
23467 + h_mtx = &h_parent->d_inode->i_mutex;
23468 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
23469 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
23470 + mutex_unlock(h_mtx);
23474 +static void au_call_do_plink_lkup(void *args)
23476 + struct au_do_plink_lkup_args *a = args;
23477 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
23480 +/* lookup the plink-ed @inode under the branch at @bindex */
23481 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
23483 + struct dentry *h_dentry, *h_parent;
23484 + struct au_branch *br;
23485 + struct inode *h_dir;
23487 + char a[PLINK_NAME_LEN];
23488 + struct qstr tgtname = QSTR_INIT(a, 0);
23490 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
23492 + br = au_sbr(inode->i_sb, bindex);
23493 + h_parent = br->br_wbr->wbr_plink;
23494 + h_dir = h_parent->d_inode;
23495 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
23497 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
23498 + struct au_do_plink_lkup_args args = {
23499 + .errp = &h_dentry,
23500 + .tgtname = &tgtname,
23501 + .h_parent = h_parent,
23505 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
23506 + if (unlikely(wkq_err))
23507 + h_dentry = ERR_PTR(wkq_err);
23509 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
23514 +/* create a pseudo-link */
23515 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
23516 + struct dentry *h_dentry, struct au_branch *br)
23519 + struct path h_path = {
23520 + .mnt = au_br_mnt(br)
23522 + struct inode *h_dir, *delegated;
23524 + h_dir = h_parent->d_inode;
23525 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
23527 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
23528 + err = PTR_ERR(h_path.dentry);
23529 + if (IS_ERR(h_path.dentry))
23533 + /* wh.plink dir is not monitored */
23534 + /* todo: is it really safe? */
23535 + if (h_path.dentry->d_inode
23536 + && h_path.dentry->d_inode != h_dentry->d_inode) {
23537 + delegated = NULL;
23538 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
23539 + if (unlikely(err == -EWOULDBLOCK)) {
23540 + pr_warn("cannot retry for NFSv4 delegation"
23541 + " for an internal unlink\n");
23544 + dput(h_path.dentry);
23545 + h_path.dentry = NULL;
23549 + if (!err && !h_path.dentry->d_inode) {
23550 + delegated = NULL;
23551 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
23552 + if (unlikely(err == -EWOULDBLOCK)) {
23553 + pr_warn("cannot retry for NFSv4 delegation"
23554 + " for an internal link\n");
23558 + dput(h_path.dentry);
23561 + mutex_unlock(&h_dir->i_mutex);
23565 +struct do_whplink_args {
23567 + struct qstr *tgt;
23568 + struct dentry *h_parent;
23569 + struct dentry *h_dentry;
23570 + struct au_branch *br;
23573 +static void call_do_whplink(void *args)
23575 + struct do_whplink_args *a = args;
23576 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
23579 +static int whplink(struct dentry *h_dentry, struct inode *inode,
23580 + aufs_bindex_t bindex, struct au_branch *br)
23582 + int err, wkq_err;
23583 + struct au_wbr *wbr;
23584 + struct dentry *h_parent;
23585 + struct inode *h_dir;
23586 + char a[PLINK_NAME_LEN];
23587 + struct qstr tgtname = QSTR_INIT(a, 0);
23589 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
23590 + h_parent = wbr->wbr_plink;
23591 + h_dir = h_parent->d_inode;
23592 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
23594 + /* always superio. */
23595 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
23596 + struct do_whplink_args args = {
23599 + .h_parent = h_parent,
23600 + .h_dentry = h_dentry,
23603 + wkq_err = au_wkq_wait(call_do_whplink, &args);
23604 + if (unlikely(wkq_err))
23607 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
23612 +/* free a single plink */
23613 +static void do_put_plink(struct pseudo_link *plink, int do_del)
23616 + hlist_del(&plink->hlist);
23617 + iput(plink->inode);
23621 +static void do_put_plink_rcu(struct rcu_head *rcu)
23623 + struct pseudo_link *plink;
23625 + plink = container_of(rcu, struct pseudo_link, rcu);
23626 + iput(plink->inode);
23631 + * create a new pseudo-link for @h_dentry on @bindex.
23632 + * the linked inode is held in aufs @inode.
23634 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
23635 + struct dentry *h_dentry)
23637 + struct super_block *sb;
23638 + struct au_sbinfo *sbinfo;
23639 + struct hlist_head *plink_hlist;
23640 + struct pseudo_link *plink, *tmp;
23641 + struct au_sphlhead *sphl;
23642 + int found, err, cnt, i;
23644 + sb = inode->i_sb;
23645 + sbinfo = au_sbi(sb);
23646 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23647 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23649 + found = au_plink_test(inode);
23653 + i = au_plink_hash(inode->i_ino);
23654 + sphl = sbinfo->si_plink + i;
23655 + plink_hlist = &sphl->head;
23656 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
23658 + tmp->inode = au_igrab(inode);
23664 + spin_lock(&sphl->spin);
23665 + hlist_for_each_entry(plink, plink_hlist, hlist) {
23666 + if (plink->inode == inode) {
23672 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
23673 + spin_unlock(&sphl->spin);
23675 + cnt = au_sphl_count(sphl);
23676 +#define msg "unexpectedly unblanced or too many pseudo-links"
23677 + if (cnt > AUFS_PLINK_WARN)
23678 + AuWarn1(msg ", %d\n", cnt);
23680 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
23682 + do_put_plink(tmp, 0);
23687 + if (unlikely(err)) {
23688 + pr_warn("err %d, damaged pseudo link.\n", err);
23690 + au_sphl_del_rcu(&tmp->hlist, sphl);
23691 + call_rcu(&tmp->rcu, do_put_plink_rcu);
23696 +/* free all plinks */
23697 +void au_plink_put(struct super_block *sb, int verbose)
23700 + struct au_sbinfo *sbinfo;
23701 + struct hlist_head *plink_hlist;
23702 + struct hlist_node *tmp;
23703 + struct pseudo_link *plink;
23705 + SiMustWriteLock(sb);
23707 + sbinfo = au_sbi(sb);
23708 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23709 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23711 + /* no spin_lock since sbinfo is write-locked */
23713 + for (i = 0; i < AuPlink_NHASH; i++) {
23714 + plink_hlist = &sbinfo->si_plink[i].head;
23715 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
23716 + pr_warn("pseudo-link is not flushed");
23719 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
23720 + do_put_plink(plink, 0);
23721 + INIT_HLIST_HEAD(plink_hlist);
23725 +void au_plink_clean(struct super_block *sb, int verbose)
23727 + struct dentry *root;
23729 + root = sb->s_root;
23730 + aufs_write_lock(root);
23731 + if (au_opt_test(au_mntflags(sb), PLINK))
23732 + au_plink_put(sb, verbose);
23733 + aufs_write_unlock(root);
23736 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
23739 + aufs_bindex_t bstart, bend, bindex;
23742 + bstart = au_ibstart(inode);
23743 + bend = au_ibend(inode);
23744 + if (bstart >= 0) {
23745 + for (bindex = bstart; bindex <= bend; bindex++) {
23746 + if (!au_h_iptr(inode, bindex)
23747 + || au_ii_br_id(inode, bindex) != br_id)
23749 + au_set_h_iptr(inode, bindex, NULL, 0);
23754 + for (bindex = bstart; bindex <= bend; bindex++)
23755 + if (au_h_iptr(inode, bindex)) {
23765 +/* free the plinks on a branch specified by @br_id */
23766 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
23768 + struct au_sbinfo *sbinfo;
23769 + struct hlist_head *plink_hlist;
23770 + struct hlist_node *tmp;
23771 + struct pseudo_link *plink;
23772 + struct inode *inode;
23775 + SiMustWriteLock(sb);
23777 + sbinfo = au_sbi(sb);
23778 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
23779 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
23781 + /* no spin_lock since sbinfo is write-locked */
23782 + for (i = 0; i < AuPlink_NHASH; i++) {
23783 + plink_hlist = &sbinfo->si_plink[i].head;
23784 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
23785 + inode = au_igrab(plink->inode);
23786 + ii_write_lock_child(inode);
23787 + do_put = au_plink_do_half_refresh(inode, br_id);
23789 + do_put_plink(plink, 1);
23790 + ii_write_unlock(inode);
23795 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
23796 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
23797 +++ linux/fs/aufs/poll.c 2014-04-24 22:11:10.855269116 +0200
23800 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23802 + * This program, aufs is free software; you can redistribute it and/or modify
23803 + * it under the terms of the GNU General Public License as published by
23804 + * the Free Software Foundation; either version 2 of the License, or
23805 + * (at your option) any later version.
23807 + * This program is distributed in the hope that it will be useful,
23808 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23809 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23810 + * GNU General Public License for more details.
23812 + * You should have received a copy of the GNU General Public License
23813 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23818 + * There is only one filesystem which implements ->poll operation, currently.
23823 +unsigned int aufs_poll(struct file *file, poll_table *wait)
23825 + unsigned int mask;
23827 + struct file *h_file;
23828 + struct dentry *dentry;
23829 + struct super_block *sb;
23831 + /* We should pretend an error happened. */
23832 + mask = POLLERR /* | POLLIN | POLLOUT */;
23833 + dentry = file->f_dentry;
23834 + sb = dentry->d_sb;
23835 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
23836 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
23837 + if (unlikely(err))
23840 + /* it is not an error if h_file has no operation */
23841 + mask = DEFAULT_POLLMASK;
23842 + h_file = au_hf_top(file);
23843 + if (h_file->f_op->poll)
23844 + mask = h_file->f_op->poll(h_file, wait);
23846 + di_read_unlock(dentry, AuLock_IR);
23847 + fi_read_unlock(file);
23850 + si_read_unlock(sb);
23851 + AuTraceErr((int)mask);
23854 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
23855 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
23856 +++ linux/fs/aufs/procfs.c 2014-04-24 22:11:10.855269116 +0200
23859 + * Copyright (C) 2010-2014 Junjiro R. Okajima
23861 + * This program, aufs is free software; you can redistribute it and/or modify
23862 + * it under the terms of the GNU General Public License as published by
23863 + * the Free Software Foundation; either version 2 of the License, or
23864 + * (at your option) any later version.
23866 + * This program is distributed in the hope that it will be useful,
23867 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23868 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23869 + * GNU General Public License for more details.
23871 + * You should have received a copy of the GNU General Public License
23872 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23876 + * procfs interfaces
23879 +#include <linux/proc_fs.h>
23882 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
23884 + struct au_sbinfo *sbinfo;
23886 + sbinfo = file->private_data;
23888 + au_plink_maint_leave(sbinfo);
23889 + kobject_put(&sbinfo->si_kobj);
23895 +static void au_procfs_plm_write_clean(struct file *file)
23897 + struct au_sbinfo *sbinfo;
23899 + sbinfo = file->private_data;
23901 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
23904 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
23907 + struct super_block *sb;
23908 + struct au_sbinfo *sbinfo;
23911 + if (unlikely(file->private_data))
23915 + /* don't use au_sbilist_lock() here */
23916 + spin_lock(&au_sbilist.spin);
23917 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
23918 + if (id == sysaufs_si_id(sbinfo)) {
23919 + kobject_get(&sbinfo->si_kobj);
23920 + sb = sbinfo->si_sb;
23923 + spin_unlock(&au_sbilist.spin);
23926 + if (unlikely(!sb))
23929 + err = au_plink_maint_enter(sb);
23931 + /* keep kobject_get() */
23932 + file->private_data = sbinfo;
23934 + kobject_put(&sbinfo->si_kobj);
23940 + * Accept a valid "si=xxxx" only.
23941 + * Once it is accepted successfully, accept "clean" too.
23943 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
23944 + size_t count, loff_t *ppos)
23947 + unsigned long id;
23948 + /* last newline is allowed */
23949 + char buf[3 + sizeof(unsigned long) * 2 + 1];
23952 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23956 + if (unlikely(count > sizeof(buf)))
23959 + err = copy_from_user(buf, ubuf, count);
23960 + if (unlikely(err)) {
23967 + if (!strcmp("clean", buf)) {
23968 + au_procfs_plm_write_clean(file);
23969 + goto out_success;
23970 + } else if (unlikely(strncmp("si=", buf, 3)))
23973 + err = kstrtoul(buf + 3, 16, &id);
23974 + if (unlikely(err))
23977 + err = au_procfs_plm_write_si(file, id);
23978 + if (unlikely(err))
23982 + err = count; /* success */
23987 +static const struct file_operations au_procfs_plm_fop = {
23988 + .write = au_procfs_plm_write,
23989 + .release = au_procfs_plm_release,
23990 + .owner = THIS_MODULE
23993 +/* ---------------------------------------------------------------------- */
23995 +static struct proc_dir_entry *au_procfs_dir;
23997 +void au_procfs_fin(void)
23999 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
24000 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
24003 +int __init au_procfs_init(void)
24006 + struct proc_dir_entry *entry;
24009 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
24010 + if (unlikely(!au_procfs_dir))
24013 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
24014 + au_procfs_dir, &au_procfs_plm_fop);
24015 + if (unlikely(!entry))
24019 + goto out; /* success */
24023 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
24027 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
24028 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
24029 +++ linux/fs/aufs/rdu.c 2014-04-24 22:11:10.858602483 +0200
24032 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24034 + * This program, aufs is free software; you can redistribute it and/or modify
24035 + * it under the terms of the GNU General Public License as published by
24036 + * the Free Software Foundation; either version 2 of the License, or
24037 + * (at your option) any later version.
24039 + * This program is distributed in the hope that it will be useful,
24040 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24041 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24042 + * GNU General Public License for more details.
24044 + * You should have received a copy of the GNU General Public License
24045 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24049 + * readdir in userspace.
24052 +#include <linux/compat.h>
24053 +#include <linux/fs_stack.h>
24054 +#include <linux/security.h>
24057 +/* bits for struct aufs_rdu.flags */
24058 +#define AuRdu_CALLED 1
24059 +#define AuRdu_CONT (1 << 1)
24060 +#define AuRdu_FULL (1 << 2)
24061 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
24062 +#define au_fset_rdu(flags, name) \
24063 + do { (flags) |= AuRdu_##name; } while (0)
24064 +#define au_fclr_rdu(flags, name) \
24065 + do { (flags) &= ~AuRdu_##name; } while (0)
24067 +struct au_rdu_arg {
24068 + struct dir_context ctx;
24069 + struct aufs_rdu *rdu;
24070 + union au_rdu_ent_ul ent;
24071 + unsigned long end;
24073 + struct super_block *sb;
24077 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
24078 + loff_t offset, u64 h_ino, unsigned int d_type)
24081 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
24082 + struct aufs_rdu *rdu = arg->rdu;
24083 + struct au_rdu_ent ent;
24087 + au_fset_rdu(rdu->cookie.flags, CALLED);
24088 + len = au_rdu_len(nlen);
24089 + if (arg->ent.ul + len < arg->end) {
24091 + ent.bindex = rdu->cookie.bindex;
24092 + ent.type = d_type;
24094 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
24095 + ent.type = DT_UNKNOWN;
24097 + /* unnecessary to support mmap_sem since this is a dir */
24099 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
24101 + if (copy_to_user(arg->ent.e->name, name, nlen))
24103 + /* the terminating NULL */
24104 + if (__put_user(0, arg->ent.e->name + nlen))
24107 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
24108 + arg->ent.ul += len;
24112 + au_fset_rdu(rdu->cookie.flags, FULL);
24114 + rdu->tail = arg->ent;
24118 + /* AuTraceErr(err); */
24122 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
24126 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
24128 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
24129 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
24131 + if (unlikely(offset != cookie->h_pos))
24137 + au_fclr_rdu(cookie->flags, CALLED);
24139 + err = vfsub_iterate_dir(h_file, &arg->ctx);
24143 + && au_ftest_rdu(cookie->flags, CALLED)
24144 + && !au_ftest_rdu(cookie->flags, FULL));
24145 + cookie->h_pos = h_file->f_pos;
24152 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
24155 + aufs_bindex_t bend;
24156 + struct au_rdu_arg arg = {
24158 + .actor = au_diractor(au_rdu_fill)
24161 + struct dentry *dentry;
24162 + struct inode *inode;
24163 + struct file *h_file;
24164 + struct au_rdu_cookie *cookie = &rdu->cookie;
24166 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
24167 + if (unlikely(err)) {
24173 + rdu->tail = rdu->ent;
24176 + arg.ent = rdu->ent;
24177 + arg.end = arg.ent.ul;
24178 + arg.end += rdu->sz;
24181 + if (unlikely(!file->f_op->iterate))
24184 + err = security_file_permission(file, MAY_READ);
24186 + if (unlikely(err))
24189 + dentry = file->f_dentry;
24190 + inode = dentry->d_inode;
24192 + mutex_lock(&inode->i_mutex);
24194 + err = mutex_lock_killable(&inode->i_mutex);
24196 + if (unlikely(err))
24200 + arg.sb = inode->i_sb;
24201 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
24202 + if (unlikely(err))
24204 + err = au_alive_dir(dentry);
24205 + if (unlikely(err))
24207 + /* todo: reval? */
24208 + fi_read_lock(file);
24211 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
24212 + && cookie->generation != au_figen(file)))
24217 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
24219 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
24221 + bend = au_fbstart(file);
24222 + if (cookie->bindex < bend)
24223 + cookie->bindex = bend;
24224 + bend = au_fbend_dir(file);
24225 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
24226 + for (; !err && cookie->bindex <= bend;
24227 + cookie->bindex++, cookie->h_pos = 0) {
24228 + h_file = au_hf_dir(file, cookie->bindex);
24232 + au_fclr_rdu(cookie->flags, FULL);
24233 + err = au_rdu_do(h_file, &arg);
24235 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
24238 + AuDbg("rent %llu\n", rdu->rent);
24240 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
24241 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
24242 + au_fset_rdu(cookie->flags, CONT);
24243 + cookie->generation = au_figen(file);
24246 + ii_read_lock_child(inode);
24247 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
24248 + ii_read_unlock(inode);
24251 + fi_read_unlock(file);
24253 + si_read_unlock(arg.sb);
24255 + mutex_unlock(&inode->i_mutex);
24261 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
24265 + unsigned long long nent;
24266 + union au_rdu_ent_ul *u;
24267 + struct au_rdu_ent ent;
24268 + struct super_block *sb;
24271 + nent = rdu->nent;
24273 + sb = file->f_dentry->d_sb;
24274 + si_read_lock(sb, AuLock_FLUSH);
24275 + while (nent-- > 0) {
24276 + /* unnecessary to support mmap_sem since this is a dir */
24277 + err = copy_from_user(&ent, u->e, sizeof(ent));
24279 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
24280 + if (unlikely(err)) {
24286 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
24288 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
24290 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
24292 + if (unlikely(err)) {
24297 + err = __put_user(ino, &u->e->ino);
24298 + if (unlikely(err)) {
24303 + u->ul += au_rdu_len(ent.nlen);
24305 + si_read_unlock(sb);
24310 +/* ---------------------------------------------------------------------- */
24312 +static int au_rdu_verify(struct aufs_rdu *rdu)
24314 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
24315 + "%llu, b%d, 0x%x, g%u}\n",
24316 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
24318 + rdu->rent, rdu->shwh, rdu->full,
24319 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
24320 + rdu->cookie.generation);
24322 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
24326 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
24330 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
24333 + struct aufs_rdu rdu;
24334 + void __user *p = (void __user *)arg;
24336 + err = copy_from_user(&rdu, p, sizeof(rdu));
24337 + if (unlikely(err)) {
24342 + err = au_rdu_verify(&rdu);
24343 + if (unlikely(err))
24347 + case AUFS_CTL_RDU:
24348 + err = au_rdu(file, &rdu);
24349 + if (unlikely(err))
24352 + e = copy_to_user(p, &rdu, sizeof(rdu));
24353 + if (unlikely(e)) {
24358 + case AUFS_CTL_RDU_INO:
24359 + err = au_rdu_ino(file, &rdu);
24363 + /* err = -ENOTTY; */
24372 +#ifdef CONFIG_COMPAT
24373 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
24376 + struct aufs_rdu rdu;
24377 + void __user *p = compat_ptr(arg);
24379 + /* todo: get_user()? */
24380 + err = copy_from_user(&rdu, p, sizeof(rdu));
24381 + if (unlikely(err)) {
24386 + rdu.ent.e = compat_ptr(rdu.ent.ul);
24387 + err = au_rdu_verify(&rdu);
24388 + if (unlikely(err))
24392 + case AUFS_CTL_RDU:
24393 + err = au_rdu(file, &rdu);
24394 + if (unlikely(err))
24397 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
24398 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
24399 + e = copy_to_user(p, &rdu, sizeof(rdu));
24400 + if (unlikely(e)) {
24405 + case AUFS_CTL_RDU_INO:
24406 + err = au_rdu_ino(file, &rdu);
24410 + /* err = -ENOTTY; */
24419 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
24420 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
24421 +++ linux/fs/aufs/rwsem.h 2014-04-24 22:11:10.858602483 +0200
24424 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24426 + * This program, aufs is free software; you can redistribute it and/or modify
24427 + * it under the terms of the GNU General Public License as published by
24428 + * the Free Software Foundation; either version 2 of the License, or
24429 + * (at your option) any later version.
24431 + * This program is distributed in the hope that it will be useful,
24432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24434 + * GNU General Public License for more details.
24436 + * You should have received a copy of the GNU General Public License
24437 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24441 + * simple read-write semaphore wrappers
24444 +#ifndef __AUFS_RWSEM_H__
24445 +#define __AUFS_RWSEM_H__
24449 +#include "debug.h"
24452 + struct rw_semaphore rwsem;
24453 +#ifdef CONFIG_AUFS_DEBUG
24454 + /* just for debugging, not almighty counter */
24455 + atomic_t rcnt, wcnt;
24459 +#ifdef CONFIG_AUFS_DEBUG
24460 +#define AuDbgCntInit(rw) do { \
24461 + atomic_set(&(rw)->rcnt, 0); \
24462 + atomic_set(&(rw)->wcnt, 0); \
24463 + smp_mb(); /* atomic set */ \
24466 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
24467 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
24468 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
24469 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
24471 +#define AuDbgCntInit(rw) do {} while (0)
24472 +#define AuDbgRcntInc(rw) do {} while (0)
24473 +#define AuDbgRcntDec(rw) do {} while (0)
24474 +#define AuDbgWcntInc(rw) do {} while (0)
24475 +#define AuDbgWcntDec(rw) do {} while (0)
24476 +#endif /* CONFIG_AUFS_DEBUG */
24478 +/* to debug easier, do not make them inlined functions */
24479 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
24480 +/* rwsem_is_locked() is unusable */
24481 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
24482 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
24483 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
24484 + && atomic_read(&(rw)->wcnt) <= 0)
24485 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
24486 + || atomic_read(&(rw)->wcnt))
24488 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
24490 +static inline void au_rw_init(struct au_rwsem *rw)
24492 + AuDbgCntInit(rw);
24493 + init_rwsem(&rw->rwsem);
24496 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
24499 + down_write(&rw->rwsem);
24500 + AuDbgWcntInc(rw);
24503 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
24504 + unsigned int lsc)
24507 + down_write_nested(&rw->rwsem, lsc);
24508 + AuDbgWcntInc(rw);
24511 +static inline void au_rw_read_lock(struct au_rwsem *rw)
24513 + down_read(&rw->rwsem);
24514 + AuDbgRcntInc(rw);
24517 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
24519 + down_read_nested(&rw->rwsem, lsc);
24520 + AuDbgRcntInc(rw);
24523 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
24525 + AuRwMustReadLock(rw);
24526 + AuDbgRcntDec(rw);
24527 + up_read(&rw->rwsem);
24530 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
24532 + AuRwMustWriteLock(rw);
24533 + AuDbgRcntInc(rw);
24534 + AuDbgWcntDec(rw);
24535 + downgrade_write(&rw->rwsem);
24538 +static inline void au_rw_write_lock(struct au_rwsem *rw)
24540 + down_write(&rw->rwsem);
24541 + AuDbgWcntInc(rw);
24544 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
24545 + unsigned int lsc)
24547 + down_write_nested(&rw->rwsem, lsc);
24548 + AuDbgWcntInc(rw);
24551 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
24553 + AuRwMustWriteLock(rw);
24554 + AuDbgWcntDec(rw);
24555 + up_write(&rw->rwsem);
24558 +/* why is not _nested version defined */
24559 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
24561 + int ret = down_read_trylock(&rw->rwsem);
24563 + AuDbgRcntInc(rw);
24567 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
24569 + int ret = down_write_trylock(&rw->rwsem);
24571 + AuDbgWcntInc(rw);
24575 +#undef AuDbgCntInit
24576 +#undef AuDbgRcntInc
24577 +#undef AuDbgRcntDec
24578 +#undef AuDbgWcntInc
24579 +#undef AuDbgWcntDec
24581 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
24582 +static inline void prefix##_read_lock(param) \
24583 +{ au_rw_read_lock(rwsem); } \
24584 +static inline void prefix##_write_lock(param) \
24585 +{ au_rw_write_lock(rwsem); } \
24586 +static inline int prefix##_read_trylock(param) \
24587 +{ return au_rw_read_trylock(rwsem); } \
24588 +static inline int prefix##_write_trylock(param) \
24589 +{ return au_rw_write_trylock(rwsem); }
24590 +/* why is not _nested version defined */
24591 +/* static inline void prefix##_read_trylock_nested(param, lsc)
24592 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
24593 +static inline void prefix##_write_trylock_nestd(param, lsc)
24594 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
24596 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
24597 +static inline void prefix##_read_unlock(param) \
24598 +{ au_rw_read_unlock(rwsem); } \
24599 +static inline void prefix##_write_unlock(param) \
24600 +{ au_rw_write_unlock(rwsem); } \
24601 +static inline void prefix##_downgrade_lock(param) \
24602 +{ au_rw_dgrade_lock(rwsem); }
24604 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
24605 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
24606 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
24608 +#endif /* __KERNEL__ */
24609 +#endif /* __AUFS_RWSEM_H__ */
24610 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
24611 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
24612 +++ linux/fs/aufs/sbinfo.c 2014-04-24 22:11:10.858602483 +0200
24615 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24617 + * This program, aufs is free software; you can redistribute it and/or modify
24618 + * it under the terms of the GNU General Public License as published by
24619 + * the Free Software Foundation; either version 2 of the License, or
24620 + * (at your option) any later version.
24622 + * This program is distributed in the hope that it will be useful,
24623 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24624 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24625 + * GNU General Public License for more details.
24627 + * You should have received a copy of the GNU General Public License
24628 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24632 + * superblock private data
24638 + * they are necessary regardless sysfs is disabled.
24640 +void au_si_free(struct kobject *kobj)
24643 + struct au_sbinfo *sbinfo;
24644 + char *locked __maybe_unused; /* debug only */
24646 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
24647 + for (i = 0; i < AuPlink_NHASH; i++)
24648 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
24649 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
24651 + au_rw_write_lock(&sbinfo->si_rwsem);
24652 + au_br_free(sbinfo);
24653 + au_rw_write_unlock(&sbinfo->si_rwsem);
24655 + AuDebugOn(radix_tree_gang_lookup
24656 + (&sbinfo->au_si_pid.tree, (void **)&locked,
24657 + /*first_index*/PID_MAX_DEFAULT - 1,
24658 + /*max_items*/sizeof(locked)/sizeof(*locked)));
24660 + kfree(sbinfo->si_branch);
24661 + kfree(sbinfo->au_si_pid.bitmap);
24662 + mutex_destroy(&sbinfo->si_xib_mtx);
24663 + AuRwDestroy(&sbinfo->si_rwsem);
24668 +int au_si_alloc(struct super_block *sb)
24671 + struct au_sbinfo *sbinfo;
24672 + static struct lock_class_key aufs_si;
24675 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
24676 + if (unlikely(!sbinfo))
24679 + BUILD_BUG_ON(sizeof(unsigned long) !=
24680 + sizeof(*sbinfo->au_si_pid.bitmap));
24681 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
24682 + sizeof(*sbinfo->au_si_pid.bitmap),
24684 + if (unlikely(!sbinfo->au_si_pid.bitmap))
24687 + /* will be reallocated separately */
24688 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
24689 + if (unlikely(!sbinfo->si_branch))
24692 + err = sysaufs_si_init(sbinfo);
24693 + if (unlikely(err))
24696 + au_nwt_init(&sbinfo->si_nowait);
24697 + au_rw_init_wlock(&sbinfo->si_rwsem);
24698 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
24699 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
24700 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
24702 + atomic_long_set(&sbinfo->si_ninodes, 0);
24703 + atomic_long_set(&sbinfo->si_nfiles, 0);
24705 + sbinfo->si_bend = -1;
24706 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
24708 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
24709 + sbinfo->si_wbr_create = AuWbrCreate_Def;
24710 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
24711 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
24713 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
24715 + sbinfo->si_xino_jiffy = jiffies;
24716 + sbinfo->si_xino_expire
24717 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
24718 + mutex_init(&sbinfo->si_xib_mtx);
24719 + sbinfo->si_xino_brid = -1;
24720 + /* leave si_xib_last_pindex and si_xib_next_bit */
24722 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
24723 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24724 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24725 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
24727 + for (i = 0; i < AuPlink_NHASH; i++)
24728 + au_sphl_init(sbinfo->si_plink + i);
24729 + init_waitqueue_head(&sbinfo->si_plink_wq);
24730 + spin_lock_init(&sbinfo->si_plink_maint_lock);
24732 + au_sphl_init(&sbinfo->si_files);
24734 + /* leave other members for sysaufs and si_mnt. */
24735 + sbinfo->si_sb = sb;
24736 + sb->s_fs_info = sbinfo;
24738 + au_debug_sbinfo_init(sbinfo);
24739 + return 0; /* success */
24742 + kfree(sbinfo->si_branch);
24744 + kfree(sbinfo->au_si_pid.bitmap);
24751 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
24754 + struct au_branch **brp;
24756 + AuRwMustWriteLock(&sbinfo->si_rwsem);
24759 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
24760 + if (unlikely(!sz))
24761 + sz = sizeof(*brp);
24762 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
24764 + sbinfo->si_branch = brp;
24771 +/* ---------------------------------------------------------------------- */
24773 +unsigned int au_sigen_inc(struct super_block *sb)
24775 + unsigned int gen;
24777 + SiMustWriteLock(sb);
24779 + gen = ++au_sbi(sb)->si_generation;
24780 + au_update_digen(sb->s_root);
24781 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
24782 + sb->s_root->d_inode->i_version++;
24786 +aufs_bindex_t au_new_br_id(struct super_block *sb)
24788 + aufs_bindex_t br_id;
24790 + struct au_sbinfo *sbinfo;
24792 + SiMustWriteLock(sb);
24794 + sbinfo = au_sbi(sb);
24795 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
24796 + br_id = ++sbinfo->si_last_br_id;
24797 + AuDebugOn(br_id < 0);
24798 + if (br_id && au_br_index(sb, br_id) < 0)
24805 +/* ---------------------------------------------------------------------- */
24807 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
24808 +int si_read_lock(struct super_block *sb, int flags)
24813 + if (au_ftest_lock(flags, FLUSH))
24814 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24816 + si_noflush_read_lock(sb);
24817 + err = au_plink_maint(sb, flags);
24818 + if (unlikely(err))
24819 + si_read_unlock(sb);
24824 +int si_write_lock(struct super_block *sb, int flags)
24828 + if (au_ftest_lock(flags, FLUSH))
24829 + au_nwt_flush(&au_sbi(sb)->si_nowait);
24831 + si_noflush_write_lock(sb);
24832 + err = au_plink_maint(sb, flags);
24833 + if (unlikely(err))
24834 + si_write_unlock(sb);
24839 +/* dentry and super_block lock. call at entry point */
24840 +int aufs_read_lock(struct dentry *dentry, int flags)
24843 + struct super_block *sb;
24845 + sb = dentry->d_sb;
24846 + err = si_read_lock(sb, flags);
24847 + if (unlikely(err))
24850 + if (au_ftest_lock(flags, DW))
24851 + di_write_lock_child(dentry);
24853 + di_read_lock_child(dentry, flags);
24855 + if (au_ftest_lock(flags, GEN)) {
24856 + err = au_digen_test(dentry, au_sigen(sb));
24857 + AuDebugOn(!err && au_dbrange_test(dentry));
24858 + if (unlikely(err))
24859 + aufs_read_unlock(dentry, flags);
24866 +void aufs_read_unlock(struct dentry *dentry, int flags)
24868 + if (au_ftest_lock(flags, DW))
24869 + di_write_unlock(dentry);
24871 + di_read_unlock(dentry, flags);
24872 + si_read_unlock(dentry->d_sb);
24875 +void aufs_write_lock(struct dentry *dentry)
24877 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
24878 + di_write_lock_child(dentry);
24881 +void aufs_write_unlock(struct dentry *dentry)
24883 + di_write_unlock(dentry);
24884 + si_write_unlock(dentry->d_sb);
24887 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
24890 + unsigned int sigen;
24891 + struct super_block *sb;
24894 + err = si_read_lock(sb, flags);
24895 + if (unlikely(err))
24898 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
24900 + if (au_ftest_lock(flags, GEN)) {
24901 + sigen = au_sigen(sb);
24902 + err = au_digen_test(d1, sigen);
24903 + AuDebugOn(!err && au_dbrange_test(d1));
24905 + err = au_digen_test(d2, sigen);
24906 + AuDebugOn(!err && au_dbrange_test(d2));
24908 + if (unlikely(err))
24909 + aufs_read_and_write_unlock2(d1, d2);
24916 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
24918 + di_write_unlock2(d1, d2);
24919 + si_read_unlock(d1->d_sb);
24922 +/* ---------------------------------------------------------------------- */
24924 +int si_pid_test_slow(struct super_block *sb)
24929 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
24930 + rcu_read_unlock();
24932 + return (long)!!p;
24935 +void si_pid_set_slow(struct super_block *sb)
24938 + struct au_sbinfo *sbinfo;
24940 + AuDebugOn(si_pid_test_slow(sb));
24942 + sbinfo = au_sbi(sb);
24943 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
24945 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24946 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
24947 + /*any valid ptr*/sb);
24948 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24950 + radix_tree_preload_end();
24953 +void si_pid_clr_slow(struct super_block *sb)
24956 + struct au_sbinfo *sbinfo;
24958 + AuDebugOn(!si_pid_test_slow(sb));
24960 + sbinfo = au_sbi(sb);
24961 + spin_lock(&sbinfo->au_si_pid.tree_lock);
24962 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
24963 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
24965 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
24966 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
24967 +++ linux/fs/aufs/spl.h 2014-04-24 22:11:10.858602483 +0200
24970 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24972 + * This program, aufs is free software; you can redistribute it and/or modify
24973 + * it under the terms of the GNU General Public License as published by
24974 + * the Free Software Foundation; either version 2 of the License, or
24975 + * (at your option) any later version.
24977 + * This program is distributed in the hope that it will be useful,
24978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24980 + * GNU General Public License for more details.
24982 + * You should have received a copy of the GNU General Public License
24983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24987 + * simple list protected by a spinlock
24990 +#ifndef __AUFS_SPL_H__
24991 +#define __AUFS_SPL_H__
24995 +struct au_splhead {
24997 + struct list_head head;
25000 +static inline void au_spl_init(struct au_splhead *spl)
25002 + spin_lock_init(&spl->spin);
25003 + INIT_LIST_HEAD(&spl->head);
25006 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
25008 + spin_lock(&spl->spin);
25009 + list_add(list, &spl->head);
25010 + spin_unlock(&spl->spin);
25013 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
25015 + spin_lock(&spl->spin);
25017 + spin_unlock(&spl->spin);
25020 +static inline void au_spl_del_rcu(struct list_head *list,
25021 + struct au_splhead *spl)
25023 + spin_lock(&spl->spin);
25024 + list_del_rcu(list);
25025 + spin_unlock(&spl->spin);
25028 +/* ---------------------------------------------------------------------- */
25030 +struct au_sphlhead {
25032 + struct hlist_head head;
25035 +static inline void au_sphl_init(struct au_sphlhead *sphl)
25037 + spin_lock_init(&sphl->spin);
25038 + INIT_HLIST_HEAD(&sphl->head);
25041 +static inline void au_sphl_add(struct hlist_node *hlist,
25042 + struct au_sphlhead *sphl)
25044 + spin_lock(&sphl->spin);
25045 + hlist_add_head(hlist, &sphl->head);
25046 + spin_unlock(&sphl->spin);
25049 +static inline void au_sphl_del(struct hlist_node *hlist,
25050 + struct au_sphlhead *sphl)
25052 + spin_lock(&sphl->spin);
25053 + hlist_del(hlist);
25054 + spin_unlock(&sphl->spin);
25057 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
25058 + struct au_sphlhead *sphl)
25060 + spin_lock(&sphl->spin);
25061 + hlist_del_rcu(hlist);
25062 + spin_unlock(&sphl->spin);
25065 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
25067 + unsigned long cnt;
25068 + struct hlist_node *pos;
25071 + spin_lock(&sphl->spin);
25072 + hlist_for_each(pos, &sphl->head)
25074 + spin_unlock(&sphl->spin);
25078 +#endif /* __KERNEL__ */
25079 +#endif /* __AUFS_SPL_H__ */
25080 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
25081 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
25082 +++ linux/fs/aufs/super.c 2014-04-24 22:11:10.858602483 +0200
25085 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25087 + * This program, aufs is free software; you can redistribute it and/or modify
25088 + * it under the terms of the GNU General Public License as published by
25089 + * the Free Software Foundation; either version 2 of the License, or
25090 + * (at your option) any later version.
25092 + * This program is distributed in the hope that it will be useful,
25093 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25094 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25095 + * GNU General Public License for more details.
25097 + * You should have received a copy of the GNU General Public License
25098 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25102 + * mount and super_block operations
25105 +#include <linux/mm.h>
25106 +#include <linux/module.h>
25107 +#include <linux/seq_file.h>
25108 +#include <linux/statfs.h>
25109 +#include <linux/vmalloc.h>
25110 +#include <linux/writeback.h>
25114 + * super_operations
25116 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
25118 + struct au_icntnr *c;
25120 + c = au_cache_alloc_icntnr();
25122 + au_icntnr_init(c);
25123 + c->vfs_inode.i_version = 1; /* sigen(sb); */
25124 + c->iinfo.ii_hinode = NULL;
25125 + return &c->vfs_inode;
25130 +static void aufs_destroy_inode_cb(struct rcu_head *head)
25132 + struct inode *inode = container_of(head, struct inode, i_rcu);
25134 + INIT_HLIST_HEAD(&inode->i_dentry);
25135 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
25138 +static void aufs_destroy_inode(struct inode *inode)
25140 + au_iinfo_fin(inode);
25141 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
25144 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
25146 + struct inode *inode;
25149 + inode = iget_locked(sb, ino);
25150 + if (unlikely(!inode)) {
25151 + inode = ERR_PTR(-ENOMEM);
25154 + if (!(inode->i_state & I_NEW))
25157 + err = au_xigen_new(inode);
25159 + err = au_iinfo_init(inode);
25161 + inode->i_version++;
25163 + iget_failed(inode);
25164 + inode = ERR_PTR(err);
25168 + /* never return NULL */
25169 + AuDebugOn(!inode);
25170 + AuTraceErrPtr(inode);
25174 +/* lock free root dinfo */
25175 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
25178 + aufs_bindex_t bindex, bend;
25179 + struct path path;
25180 + struct au_hdentry *hdp;
25181 + struct au_branch *br;
25185 + bend = au_sbend(sb);
25186 + hdp = au_di(sb->s_root)->di_hdentry;
25187 + for (bindex = 0; !err && bindex <= bend; bindex++) {
25188 + br = au_sbr(sb, bindex);
25189 + path.mnt = au_br_mnt(br);
25190 + path.dentry = hdp[bindex].hd_dentry;
25191 + err = au_seq_path(seq, &path);
25193 + perm = au_optstr_br_perm(br->br_perm);
25195 + err = seq_printf(seq, "=%s", perm);
25202 + if (!err && bindex != bend)
25203 + err = seq_putc(seq, ':');
25209 +static void au_show_wbr_create(struct seq_file *m, int v,
25210 + struct au_sbinfo *sbinfo)
25214 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25216 + seq_puts(m, ",create=");
25217 + pat = au_optstr_wbr_create(v);
25219 + case AuWbrCreate_TDP:
25220 + case AuWbrCreate_RR:
25221 + case AuWbrCreate_MFS:
25222 + case AuWbrCreate_PMFS:
25223 + seq_puts(m, pat);
25225 + case AuWbrCreate_MFSV:
25226 + seq_printf(m, /*pat*/"mfs:%lu",
25227 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
25230 + case AuWbrCreate_PMFSV:
25231 + seq_printf(m, /*pat*/"pmfs:%lu",
25232 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
25235 + case AuWbrCreate_MFSRR:
25236 + seq_printf(m, /*pat*/"mfsrr:%llu",
25237 + sbinfo->si_wbr_mfs.mfsrr_watermark);
25239 + case AuWbrCreate_MFSRRV:
25240 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
25241 + sbinfo->si_wbr_mfs.mfsrr_watermark,
25242 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
25245 + case AuWbrCreate_PMFSRR:
25246 + seq_printf(m, /*pat*/"pmfsrr:%llu",
25247 + sbinfo->si_wbr_mfs.mfsrr_watermark);
25249 + case AuWbrCreate_PMFSRRV:
25250 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
25251 + sbinfo->si_wbr_mfs.mfsrr_watermark,
25252 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
25258 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
25260 +#ifdef CONFIG_SYSFS
25264 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
25265 + aufs_bindex_t bindex, brid;
25266 + struct qstr *name;
25268 + struct dentry *d, *h_root;
25269 + struct au_hdentry *hdp;
25271 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25274 + f = au_sbi(sb)->si_xib;
25278 + /* stop printing the default xino path on the first writable branch */
25280 + brid = au_xino_brid(sb);
25282 + bindex = au_br_index(sb, brid);
25283 + hdp = au_di(sb->s_root)->di_hdentry;
25284 + h_root = hdp[0 + bindex].hd_dentry;
25287 + name = &d->d_name;
25288 + /* safe ->d_parent because the file is unlinked */
25289 + if (d->d_parent == h_root
25290 + && name->len == len
25291 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
25294 + seq_puts(seq, ",xino=");
25295 + err = au_xino_path(seq, f);
25302 +/* seq_file will re-call me in case of too long string */
25303 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
25306 + unsigned int mnt_flags, v;
25307 + struct super_block *sb;
25308 + struct au_sbinfo *sbinfo;
25310 +#define AuBool(name, str) do { \
25311 + v = au_opt_test(mnt_flags, name); \
25312 + if (v != au_opt_test(AuOpt_Def, name)) \
25313 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
25316 +#define AuStr(name, str) do { \
25317 + v = mnt_flags & AuOptMask_##name; \
25318 + if (v != (AuOpt_Def & AuOptMask_##name)) \
25319 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
25322 +#define AuUInt(name, str, val) do { \
25323 + if (val != AUFS_##name##_DEF) \
25324 + seq_printf(m, "," #str "=%u", val); \
25327 + /* lock free root dinfo */
25328 + sb = dentry->d_sb;
25329 + si_noflush_read_lock(sb);
25330 + sbinfo = au_sbi(sb);
25331 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
25333 + mnt_flags = au_mntflags(sb);
25334 + if (au_opt_test(mnt_flags, XINO)) {
25335 + err = au_show_xino(m, sb);
25336 + if (unlikely(err))
25339 + seq_puts(m, ",noxino");
25341 + AuBool(TRUNC_XINO, trunc_xino);
25342 + AuStr(UDBA, udba);
25343 + AuBool(SHWH, shwh);
25344 + AuBool(PLINK, plink);
25345 + AuBool(DIO, dio);
25346 + /* AuBool(DIRPERM1, dirperm1); */
25347 + /* AuBool(REFROF, refrof); */
25349 + v = sbinfo->si_wbr_create;
25350 + if (v != AuWbrCreate_Def)
25351 + au_show_wbr_create(m, v, sbinfo);
25353 + v = sbinfo->si_wbr_copyup;
25354 + if (v != AuWbrCopyup_Def)
25355 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
25357 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
25358 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
25359 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
25361 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
25363 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
25364 + AuUInt(RDCACHE, rdcache, v);
25366 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
25367 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
25369 + AuBool(SUM, sum);
25370 + /* AuBool(SUM_W, wsum); */
25371 + AuBool(WARN_PERM, warn_perm);
25372 + AuBool(VERBOSE, verbose);
25375 + /* be sure to print "br:" last */
25376 + if (!sysaufs_brs) {
25377 + seq_puts(m, ",br:");
25378 + au_show_brs(m, sb);
25380 + si_read_unlock(sb);
25388 +/* ---------------------------------------------------------------------- */
25390 +/* sum mode which returns the summation for statfs(2) */
25392 +static u64 au_add_till_max(u64 a, u64 b)
25400 + return ULLONG_MAX;
25403 +static u64 au_mul_till_max(u64 a, long mul)
25411 + return ULLONG_MAX;
25414 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
25417 + long bsize, factor;
25418 + u64 blocks, bfree, bavail, files, ffree;
25419 + aufs_bindex_t bend, bindex, i;
25420 + unsigned char shared;
25421 + struct path h_path;
25422 + struct super_block *h_sb;
25425 + bsize = LONG_MAX;
25431 + bend = au_sbend(sb);
25432 + for (bindex = 0; bindex <= bend; bindex++) {
25433 + h_path.mnt = au_sbr_mnt(sb, bindex);
25434 + h_sb = h_path.mnt->mnt_sb;
25436 + for (i = 0; !shared && i < bindex; i++)
25437 + shared = (au_sbr_sb(sb, i) == h_sb);
25441 + /* sb->s_root for NFS is unreliable */
25442 + h_path.dentry = h_path.mnt->mnt_root;
25443 + err = vfs_statfs(&h_path, buf);
25444 + if (unlikely(err))
25447 + if (bsize > buf->f_bsize) {
25449 + * we will reduce bsize, so we have to expand blocks
25450 + * etc. to match them again
25452 + factor = (bsize / buf->f_bsize);
25453 + blocks = au_mul_till_max(blocks, factor);
25454 + bfree = au_mul_till_max(bfree, factor);
25455 + bavail = au_mul_till_max(bavail, factor);
25456 + bsize = buf->f_bsize;
25459 + factor = (buf->f_bsize / bsize);
25460 + blocks = au_add_till_max(blocks,
25461 + au_mul_till_max(buf->f_blocks, factor));
25462 + bfree = au_add_till_max(bfree,
25463 + au_mul_till_max(buf->f_bfree, factor));
25464 + bavail = au_add_till_max(bavail,
25465 + au_mul_till_max(buf->f_bavail, factor));
25466 + files = au_add_till_max(files, buf->f_files);
25467 + ffree = au_add_till_max(ffree, buf->f_ffree);
25470 + buf->f_bsize = bsize;
25471 + buf->f_blocks = blocks;
25472 + buf->f_bfree = bfree;
25473 + buf->f_bavail = bavail;
25474 + buf->f_files = files;
25475 + buf->f_ffree = ffree;
25476 + buf->f_frsize = 0;
25482 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
25485 + struct path h_path;
25486 + struct super_block *sb;
25488 + /* lock free root dinfo */
25489 + sb = dentry->d_sb;
25490 + si_noflush_read_lock(sb);
25491 + if (!au_opt_test(au_mntflags(sb), SUM)) {
25492 + /* sb->s_root for NFS is unreliable */
25493 + h_path.mnt = au_sbr_mnt(sb, 0);
25494 + h_path.dentry = h_path.mnt->mnt_root;
25495 + err = vfs_statfs(&h_path, buf);
25497 + err = au_statfs_sum(sb, buf);
25498 + si_read_unlock(sb);
25501 + buf->f_type = AUFS_SUPER_MAGIC;
25502 + buf->f_namelen = AUFS_MAX_NAMELEN;
25503 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
25505 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
25510 +/* ---------------------------------------------------------------------- */
25512 +static int aufs_sync_fs(struct super_block *sb, int wait)
25515 + aufs_bindex_t bend, bindex;
25516 + struct au_branch *br;
25517 + struct super_block *h_sb;
25520 + si_noflush_read_lock(sb);
25521 + bend = au_sbend(sb);
25522 + for (bindex = 0; bindex <= bend; bindex++) {
25523 + br = au_sbr(sb, bindex);
25524 + if (!au_br_writable(br->br_perm))
25527 + h_sb = au_sbr_sb(sb, bindex);
25528 + if (h_sb->s_op->sync_fs) {
25529 + e = h_sb->s_op->sync_fs(h_sb, wait);
25530 + if (unlikely(e && !err))
25532 + /* go on even if an error happens */
25535 + si_read_unlock(sb);
25540 +/* ---------------------------------------------------------------------- */
25542 +/* final actions when unmounting a file system */
25543 +static void aufs_put_super(struct super_block *sb)
25545 + struct au_sbinfo *sbinfo;
25547 + sbinfo = au_sbi(sb);
25551 + dbgaufs_si_fin(sbinfo);
25552 + kobject_put(&sbinfo->si_kobj);
25555 +/* ---------------------------------------------------------------------- */
25557 +void au_array_free(void *array)
25560 + if (!is_vmalloc_addr(array))
25567 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
25570 + unsigned long long n;
25577 + if (*hint > ULLONG_MAX / sizeof(array)) {
25578 + array = ERR_PTR(-EMFILE);
25579 + pr_err("hint %llu\n", *hint);
25583 + array = kmalloc(sizeof(array) * *hint, GFP_NOFS);
25584 + if (unlikely(!array))
25585 + array = vmalloc(sizeof(array) * *hint);
25586 + if (unlikely(!array)) {
25587 + array = ERR_PTR(-ENOMEM);
25591 + n = cb(array, *hint, arg);
25592 + AuDebugOn(n > *hint);
25599 +static unsigned long long au_iarray_cb(void *a,
25600 + unsigned long long max __maybe_unused,
25603 + unsigned long long n;
25604 + struct inode **p, *inode;
25605 + struct list_head *head;
25610 + spin_lock(&inode_sb_list_lock);
25611 + list_for_each_entry(inode, head, i_sb_list) {
25612 + if (!is_bad_inode(inode)
25613 + && au_ii(inode)->ii_bstart >= 0) {
25614 + spin_lock(&inode->i_lock);
25615 + if (atomic_read(&inode->i_count)) {
25619 + AuDebugOn(n > max);
25621 + spin_unlock(&inode->i_lock);
25624 + spin_unlock(&inode_sb_list_lock);
25629 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
25631 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
25632 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
25635 +void au_iarray_free(struct inode **a, unsigned long long max)
25637 + unsigned long long ull;
25639 + for (ull = 0; ull < max; ull++)
25641 + au_array_free(a);
25644 +/* ---------------------------------------------------------------------- */
25647 + * refresh dentry and inode at remount time.
25649 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
25650 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
25651 + struct dentry *parent)
25655 + di_write_lock_child(dentry);
25656 + di_read_lock_parent(parent, AuLock_IR);
25657 + err = au_refresh_dentry(dentry, parent);
25658 + if (!err && dir_flags)
25659 + au_hn_reset(dentry->d_inode, dir_flags);
25660 + di_read_unlock(parent, AuLock_IR);
25661 + di_write_unlock(dentry);
25666 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
25667 + struct au_sbinfo *sbinfo,
25668 + const unsigned int dir_flags)
25671 + struct dentry *parent;
25672 + struct inode *inode;
25675 + parent = dget_parent(dentry);
25676 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
25677 + inode = dentry->d_inode;
25679 + if (!S_ISDIR(inode->i_mode))
25680 + err = au_do_refresh(dentry, /*dir_flags*/0,
25683 + err = au_do_refresh(dentry, dir_flags, parent);
25684 + if (unlikely(err))
25685 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
25688 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
25689 + AuDbgDentry(dentry);
25697 +static int au_refresh_d(struct super_block *sb)
25699 + int err, i, j, ndentry, e;
25700 + unsigned int sigen;
25701 + struct au_dcsub_pages dpages;
25702 + struct au_dpage *dpage;
25703 + struct dentry **dentries, *d;
25704 + struct au_sbinfo *sbinfo;
25705 + struct dentry *root = sb->s_root;
25706 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
25708 + err = au_dpages_init(&dpages, GFP_NOFS);
25709 + if (unlikely(err))
25711 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
25712 + if (unlikely(err))
25715 + sigen = au_sigen(sb);
25716 + sbinfo = au_sbi(sb);
25717 + for (i = 0; i < dpages.ndpage; i++) {
25718 + dpage = dpages.dpages + i;
25719 + dentries = dpage->dentries;
25720 + ndentry = dpage->ndentry;
25721 + for (j = 0; j < ndentry; j++) {
25723 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
25724 + if (unlikely(e && !err))
25726 + /* go on even err */
25731 + au_dpages_free(&dpages);
25736 +static int au_refresh_i(struct super_block *sb)
25739 + unsigned int sigen;
25740 + unsigned long long max, ull;
25741 + struct inode *inode, **array;
25743 + array = au_iarray_alloc(sb, &max);
25744 + err = PTR_ERR(array);
25745 + if (IS_ERR(array))
25749 + sigen = au_sigen(sb);
25750 + for (ull = 0; ull < max; ull++) {
25751 + inode = array[ull];
25752 + if (au_iigen(inode, NULL) != sigen) {
25753 + ii_write_lock_child(inode);
25754 + e = au_refresh_hinode_self(inode);
25755 + ii_write_unlock(inode);
25756 + if (unlikely(e)) {
25757 + pr_err("error %d, i%lu\n", e, inode->i_ino);
25760 + /* go on even if err */
25765 + au_iarray_free(array, max);
25771 +static void au_remount_refresh(struct super_block *sb)
25774 + unsigned int udba;
25775 + aufs_bindex_t bindex, bend;
25776 + struct dentry *root;
25777 + struct inode *inode;
25778 + struct au_branch *br;
25780 + au_sigen_inc(sb);
25781 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
25783 + root = sb->s_root;
25784 + DiMustNoWaiters(root);
25785 + inode = root->d_inode;
25786 + IiMustNoWaiters(inode);
25788 + udba = au_opt_udba(sb);
25789 + bend = au_sbend(sb);
25790 + for (bindex = 0; bindex <= bend; bindex++) {
25791 + br = au_sbr(sb, bindex);
25792 + err = au_hnotify_reset_br(udba, br, br->br_perm);
25793 + if (unlikely(err))
25794 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25796 + /* go on even if err */
25798 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
25800 + di_write_unlock(root);
25801 + err = au_refresh_d(sb);
25802 + e = au_refresh_i(sb);
25803 + if (unlikely(e && !err))
25805 + /* aufs_write_lock() calls ..._child() */
25806 + di_write_lock_child(root);
25808 + au_cpup_attr_all(inode, /*force*/1);
25810 + if (unlikely(err))
25811 + AuIOErr("refresh failed, ignored, %d\n", err);
25814 +/* stop extra interpretation of errno in mount(8), and strange error messages */
25815 +static int cvt_err(int err)
25829 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
25832 + unsigned int mntflags;
25833 + struct au_opts opts;
25834 + struct dentry *root;
25835 + struct inode *inode;
25836 + struct au_sbinfo *sbinfo;
25839 + root = sb->s_root;
25840 + if (!data || !*data) {
25841 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25843 + di_write_lock_child(root);
25844 + err = au_opts_verify(sb, *flags, /*pending*/0);
25845 + aufs_write_unlock(root);
25851 + memset(&opts, 0, sizeof(opts));
25852 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25853 + if (unlikely(!opts.opt))
25855 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25856 + opts.flags = AuOpts_REMOUNT;
25857 + opts.sb_flags = *flags;
25859 + /* parse it before aufs lock */
25860 + err = au_opts_parse(sb, data, &opts);
25861 + if (unlikely(err))
25864 + sbinfo = au_sbi(sb);
25865 + inode = root->d_inode;
25866 + mutex_lock(&inode->i_mutex);
25867 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
25868 + if (unlikely(err))
25870 + di_write_lock_child(root);
25872 + /* au_opts_remount() may return an error */
25873 + err = au_opts_remount(sb, &opts);
25874 + au_opts_free(&opts);
25876 + if (au_ftest_opts(opts.flags, REFRESH))
25877 + au_remount_refresh(sb);
25879 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
25880 + mntflags = au_mntflags(sb);
25881 + do_dx = !!au_opt_test(mntflags, DIO);
25882 + au_dy_arefresh(do_dx);
25885 + aufs_write_unlock(root);
25888 + mutex_unlock(&inode->i_mutex);
25890 + free_page((unsigned long)opts.opt);
25892 + err = cvt_err(err);
25897 +static const struct super_operations aufs_sop = {
25898 + .alloc_inode = aufs_alloc_inode,
25899 + .destroy_inode = aufs_destroy_inode,
25900 + /* always deleting, no clearing */
25901 + .drop_inode = generic_delete_inode,
25902 + .show_options = aufs_show_options,
25903 + .statfs = aufs_statfs,
25904 + .put_super = aufs_put_super,
25905 + .sync_fs = aufs_sync_fs,
25906 + .remount_fs = aufs_remount_fs
25909 +/* ---------------------------------------------------------------------- */
25911 +static int alloc_root(struct super_block *sb)
25914 + struct inode *inode;
25915 + struct dentry *root;
25918 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
25919 + err = PTR_ERR(inode);
25920 + if (IS_ERR(inode))
25923 + inode->i_op = &aufs_dir_iop;
25924 + inode->i_fop = &aufs_dir_fop;
25925 + inode->i_mode = S_IFDIR;
25926 + set_nlink(inode, 2);
25927 + unlock_new_inode(inode);
25929 + root = d_make_root(inode);
25930 + if (unlikely(!root))
25932 + err = PTR_ERR(root);
25933 + if (IS_ERR(root))
25936 + err = au_di_init(root);
25938 + sb->s_root = root;
25939 + return 0; /* success */
25947 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
25948 + int silent __maybe_unused)
25951 + struct au_opts opts;
25952 + struct dentry *root;
25953 + struct inode *inode;
25954 + char *arg = raw_data;
25956 + if (unlikely(!arg || !*arg)) {
25958 + pr_err("no arg\n");
25963 + memset(&opts, 0, sizeof(opts));
25964 + opts.opt = (void *)__get_free_page(GFP_NOFS);
25965 + if (unlikely(!opts.opt))
25967 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
25968 + opts.sb_flags = sb->s_flags;
25970 + err = au_si_alloc(sb);
25971 + if (unlikely(err))
25974 + /* all timestamps always follow the ones on the branch */
25975 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
25976 + sb->s_op = &aufs_sop;
25977 + sb->s_d_op = &aufs_dop;
25978 + sb->s_magic = AUFS_SUPER_MAGIC;
25979 + sb->s_maxbytes = 0;
25980 + au_export_init(sb);
25982 + err = alloc_root(sb);
25983 + if (unlikely(err)) {
25984 + si_write_unlock(sb);
25987 + root = sb->s_root;
25988 + inode = root->d_inode;
25991 + * actually we can parse options regardless aufs lock here.
25992 + * but at remount time, parsing must be done before aufs lock.
25993 + * so we follow the same rule.
25995 + ii_write_lock_parent(inode);
25996 + aufs_write_unlock(root);
25997 + err = au_opts_parse(sb, arg, &opts);
25998 + if (unlikely(err))
26001 + /* lock vfs_inode first, then aufs. */
26002 + mutex_lock(&inode->i_mutex);
26003 + aufs_write_lock(root);
26004 + err = au_opts_mount(sb, &opts);
26005 + au_opts_free(&opts);
26006 + aufs_write_unlock(root);
26007 + mutex_unlock(&inode->i_mutex);
26009 + goto out_opts; /* success */
26013 + sb->s_root = NULL;
26015 + dbgaufs_si_fin(au_sbi(sb));
26016 + kobject_put(&au_sbi(sb)->si_kobj);
26017 + sb->s_fs_info = NULL;
26019 + free_page((unsigned long)opts.opt);
26022 + err = cvt_err(err);
26027 +/* ---------------------------------------------------------------------- */
26029 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
26030 + const char *dev_name __maybe_unused,
26033 + struct dentry *root;
26034 + struct super_block *sb;
26036 + /* all timestamps always follow the ones on the branch */
26037 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
26038 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
26039 + if (IS_ERR(root))
26043 + si_write_lock(sb, !AuLock_FLUSH);
26044 + sysaufs_brs_add(sb, 0);
26045 + si_write_unlock(sb);
26046 + au_sbilist_add(sb);
26052 +static void aufs_kill_sb(struct super_block *sb)
26054 + struct au_sbinfo *sbinfo;
26056 + sbinfo = au_sbi(sb);
26058 + au_sbilist_del(sb);
26059 + aufs_write_lock(sb->s_root);
26060 + if (sbinfo->si_wbr_create_ops->fin)
26061 + sbinfo->si_wbr_create_ops->fin(sb);
26062 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
26063 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
26064 + au_remount_refresh(sb);
26066 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26067 + au_plink_put(sb, /*verbose*/1);
26069 + sbinfo->si_sb = NULL;
26070 + aufs_write_unlock(sb->s_root);
26071 + au_nwt_flush(&sbinfo->si_nowait);
26073 + kill_anon_super(sb);
26076 +struct file_system_type aufs_fs_type = {
26077 + .name = AUFS_FSTYPE,
26078 + /* a race between rename and others */
26079 + .fs_flags = FS_RENAME_DOES_D_MOVE,
26080 + .mount = aufs_mount,
26081 + .kill_sb = aufs_kill_sb,
26082 + /* no need to __module_get() and module_put(). */
26083 + .owner = THIS_MODULE,
26085 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
26086 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
26087 +++ linux/fs/aufs/super.h 2014-04-24 22:11:10.858602483 +0200
26090 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26092 + * This program, aufs is free software; you can redistribute it and/or modify
26093 + * it under the terms of the GNU General Public License as published by
26094 + * the Free Software Foundation; either version 2 of the License, or
26095 + * (at your option) any later version.
26097 + * This program is distributed in the hope that it will be useful,
26098 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26099 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26100 + * GNU General Public License for more details.
26102 + * You should have received a copy of the GNU General Public License
26103 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26107 + * super_block operations
26110 +#ifndef __AUFS_SUPER_H__
26111 +#define __AUFS_SUPER_H__
26115 +#include <linux/fs.h>
26116 +#include "rwsem.h"
26120 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
26121 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
26124 +/* policies to select one among multiple writable branches */
26125 +struct au_wbr_copyup_operations {
26126 + int (*copyup)(struct dentry *dentry);
26129 +#define AuWbr_DIR 1 /* target is a dir */
26130 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
26132 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
26133 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
26134 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
26136 +struct au_wbr_create_operations {
26137 + int (*create)(struct dentry *dentry, unsigned int flags);
26138 + int (*init)(struct super_block *sb);
26139 + int (*fin)(struct super_block *sb);
26142 +struct au_wbr_mfs {
26143 + struct mutex mfs_lock; /* protect this structure */
26144 + unsigned long mfs_jiffy;
26145 + unsigned long mfs_expire;
26146 + aufs_bindex_t mfs_bindex;
26148 + unsigned long long mfsrr_bytes;
26149 + unsigned long long mfsrr_watermark;
26152 +struct pseudo_link {
26154 + struct hlist_node hlist;
26155 + struct rcu_head rcu;
26157 + struct inode *inode;
26160 +#define AuPlink_NHASH 100
26161 +static inline int au_plink_hash(ino_t ino)
26163 + return ino % AuPlink_NHASH;
26167 +struct au_sbinfo {
26168 + /* nowait tasks in the system-wide workqueue */
26169 + struct au_nowait_tasks si_nowait;
26172 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
26173 + * rwsem for au_sbinfo is necessary.
26175 + struct au_rwsem si_rwsem;
26177 + /* prevent recursive locking in deleting inode */
26179 + unsigned long *bitmap;
26180 + spinlock_t tree_lock;
26181 + struct radix_tree_root tree;
26185 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
26188 + atomic_long_t si_ninodes, si_nfiles;
26190 + /* branch management */
26191 + unsigned int si_generation;
26193 + /* see above flags */
26194 + unsigned char au_si_status;
26196 + aufs_bindex_t si_bend;
26198 + /* dirty trick to keep br_id plus */
26199 + unsigned int si_last_br_id :
26200 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
26201 + struct au_branch **si_branch;
26203 + /* policy to select a writable branch */
26204 + unsigned char si_wbr_copyup;
26205 + unsigned char si_wbr_create;
26206 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
26207 + struct au_wbr_create_operations *si_wbr_create_ops;
26209 + /* round robin */
26210 + atomic_t si_wbr_rr_next;
26212 + /* most free space */
26213 + struct au_wbr_mfs si_wbr_mfs;
26215 + /* mount flags */
26216 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
26217 + unsigned int si_mntflags;
26219 + /* external inode number (bitmap and translation table) */
26220 + au_readf_t si_xread;
26221 + au_writef_t si_xwrite;
26222 + struct file *si_xib;
26223 + struct mutex si_xib_mtx; /* protect xib members */
26224 + unsigned long *si_xib_buf;
26225 + unsigned long si_xib_last_pindex;
26226 + int si_xib_next_bit;
26227 + aufs_bindex_t si_xino_brid;
26228 + unsigned long si_xino_jiffy;
26229 + unsigned long si_xino_expire;
26230 + /* reserved for future use */
26231 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
26233 +#ifdef CONFIG_AUFS_EXPORT
26234 + /* i_generation */
26235 + struct file *si_xigen;
26236 + atomic_t si_xigen_next;
26239 + /* vdir parameters */
26240 + unsigned long si_rdcache; /* max cache time in jiffies */
26241 + unsigned int si_rdblk; /* deblk size */
26242 + unsigned int si_rdhash; /* hash size */
26245 + * If the number of whiteouts are larger than si_dirwh, leave all of
26246 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
26247 + * future fsck.aufs or kernel thread will remove them later.
26248 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
26250 + unsigned int si_dirwh;
26253 + * rename(2) a directory with all children.
26255 + /* reserved for future use */
26256 + /* int si_rendir; */
26258 + /* pseudo_link list */
26259 + struct au_sphlhead si_plink[AuPlink_NHASH];
26260 + wait_queue_head_t si_plink_wq;
26261 + spinlock_t si_plink_maint_lock;
26262 + pid_t si_plink_maint_pid;
26265 + struct au_sphlhead si_files;
26268 + * sysfs and lifetime management.
26269 + * this is not a small structure and it may be a waste of memory in case
26270 + * of sysfs is disabled, particulary when many aufs-es are mounted.
26271 + * but using sysfs is majority.
26273 + struct kobject si_kobj;
26274 +#ifdef CONFIG_DEBUG_FS
26275 + struct dentry *si_dbgaufs;
26276 + struct dentry *si_dbgaufs_plink;
26277 + struct dentry *si_dbgaufs_xib;
26278 +#ifdef CONFIG_AUFS_EXPORT
26279 + struct dentry *si_dbgaufs_xigen;
26283 +#ifdef CONFIG_AUFS_SBILIST
26284 + struct list_head si_list;
26287 + /* dirty, necessary for unmounting, sysfs and sysrq */
26288 + struct super_block *si_sb;
26291 +/* sbinfo status flags */
26293 + * set true when refresh_dirs() failed at remount time.
26294 + * then try refreshing dirs at access time again.
26295 + * if it is false, refreshing dirs at access time is unnecesary
26297 +#define AuSi_FAILED_REFRESH_DIR 1
26298 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
26299 + unsigned int flag)
26301 + AuRwMustAnyLock(&sbi->si_rwsem);
26302 + return sbi->au_si_status & flag;
26304 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
26305 +#define au_fset_si(sbinfo, name) do { \
26306 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
26307 + (sbinfo)->au_si_status |= AuSi_##name; \
26309 +#define au_fclr_si(sbinfo, name) do { \
26310 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
26311 + (sbinfo)->au_si_status &= ~AuSi_##name; \
26314 +/* ---------------------------------------------------------------------- */
26316 +/* policy to select one among writable branches */
26317 +#define AuWbrCopyup(sbinfo, ...) \
26318 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
26319 +#define AuWbrCreate(sbinfo, ...) \
26320 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
26322 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
26323 +#define AuLock_DW 1 /* write-lock dentry */
26324 +#define AuLock_IR (1 << 1) /* read-lock inode */
26325 +#define AuLock_IW (1 << 2) /* write-lock inode */
26326 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
26327 +#define AuLock_DIR (1 << 4) /* target is a dir */
26328 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
26329 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
26330 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
26331 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
26332 +#define au_fset_lock(flags, name) \
26333 + do { (flags) |= AuLock_##name; } while (0)
26334 +#define au_fclr_lock(flags, name) \
26335 + do { (flags) &= ~AuLock_##name; } while (0)
26337 +/* ---------------------------------------------------------------------- */
26340 +extern struct file_system_type aufs_fs_type;
26341 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
26342 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
26344 +void au_array_free(void *array);
26345 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
26346 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
26347 +void au_iarray_free(struct inode **a, unsigned long long max);
26350 +void au_si_free(struct kobject *kobj);
26351 +int au_si_alloc(struct super_block *sb);
26352 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
26354 +unsigned int au_sigen_inc(struct super_block *sb);
26355 +aufs_bindex_t au_new_br_id(struct super_block *sb);
26357 +int si_read_lock(struct super_block *sb, int flags);
26358 +int si_write_lock(struct super_block *sb, int flags);
26359 +int aufs_read_lock(struct dentry *dentry, int flags);
26360 +void aufs_read_unlock(struct dentry *dentry, int flags);
26361 +void aufs_write_lock(struct dentry *dentry);
26362 +void aufs_write_unlock(struct dentry *dentry);
26363 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
26364 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
26366 +int si_pid_test_slow(struct super_block *sb);
26367 +void si_pid_set_slow(struct super_block *sb);
26368 +void si_pid_clr_slow(struct super_block *sb);
26370 +/* wbr_policy.c */
26371 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
26372 +extern struct au_wbr_create_operations au_wbr_create_ops[];
26373 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
26374 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
26377 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
26379 +/* ---------------------------------------------------------------------- */
26381 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
26383 + return sb->s_fs_info;
26386 +/* ---------------------------------------------------------------------- */
26388 +#ifdef CONFIG_AUFS_EXPORT
26389 +int au_test_nfsd(void);
26390 +void au_export_init(struct super_block *sb);
26391 +void au_xigen_inc(struct inode *inode);
26392 +int au_xigen_new(struct inode *inode);
26393 +int au_xigen_set(struct super_block *sb, struct file *base);
26394 +void au_xigen_clr(struct super_block *sb);
26396 +static inline int au_busy_or_stale(void)
26398 + if (!au_test_nfsd())
26403 +AuStubInt0(au_test_nfsd, void)
26404 +AuStubVoid(au_export_init, struct super_block *sb)
26405 +AuStubVoid(au_xigen_inc, struct inode *inode)
26406 +AuStubInt0(au_xigen_new, struct inode *inode)
26407 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
26408 +AuStubVoid(au_xigen_clr, struct super_block *sb)
26409 +static inline int au_busy_or_stale(void)
26413 +#endif /* CONFIG_AUFS_EXPORT */
26415 +/* ---------------------------------------------------------------------- */
26417 +#ifdef CONFIG_AUFS_SBILIST
26419 +extern struct au_splhead au_sbilist;
26421 +static inline void au_sbilist_init(void)
26423 + au_spl_init(&au_sbilist);
26426 +static inline void au_sbilist_add(struct super_block *sb)
26428 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
26431 +static inline void au_sbilist_del(struct super_block *sb)
26433 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
26436 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
26437 +static inline void au_sbilist_lock(void)
26439 + spin_lock(&au_sbilist.spin);
26442 +static inline void au_sbilist_unlock(void)
26444 + spin_unlock(&au_sbilist.spin);
26446 +#define AuGFP_SBILIST GFP_ATOMIC
26448 +AuStubVoid(au_sbilist_lock, void)
26449 +AuStubVoid(au_sbilist_unlock, void)
26450 +#define AuGFP_SBILIST GFP_NOFS
26451 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
26453 +AuStubVoid(au_sbilist_init, void)
26454 +AuStubVoid(au_sbilist_add, struct super_block*)
26455 +AuStubVoid(au_sbilist_del, struct super_block*)
26456 +AuStubVoid(au_sbilist_lock, void)
26457 +AuStubVoid(au_sbilist_unlock, void)
26458 +#define AuGFP_SBILIST GFP_NOFS
26461 +/* ---------------------------------------------------------------------- */
26463 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
26466 + * This function is a dynamic '__init' fucntion actually,
26467 + * so the tiny check for si_rwsem is unnecessary.
26469 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
26470 +#ifdef CONFIG_DEBUG_FS
26471 + sbinfo->si_dbgaufs = NULL;
26472 + sbinfo->si_dbgaufs_plink = NULL;
26473 + sbinfo->si_dbgaufs_xib = NULL;
26474 +#ifdef CONFIG_AUFS_EXPORT
26475 + sbinfo->si_dbgaufs_xigen = NULL;
26480 +/* ---------------------------------------------------------------------- */
26482 +static inline pid_t si_pid_bit(void)
26484 + /* the origin of pid is 1, but the bitmap's is 0 */
26485 + return current->pid - 1;
26488 +static inline int si_pid_test(struct super_block *sb)
26490 + pid_t bit = si_pid_bit();
26491 + if (bit < PID_MAX_DEFAULT)
26492 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26494 + return si_pid_test_slow(sb);
26497 +static inline void si_pid_set(struct super_block *sb)
26499 + pid_t bit = si_pid_bit();
26500 + if (bit < PID_MAX_DEFAULT) {
26501 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
26502 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26505 + si_pid_set_slow(sb);
26508 +static inline void si_pid_clr(struct super_block *sb)
26510 + pid_t bit = si_pid_bit();
26511 + if (bit < PID_MAX_DEFAULT) {
26512 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
26513 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
26516 + si_pid_clr_slow(sb);
26519 +/* ---------------------------------------------------------------------- */
26521 +/* lock superblock. mainly for entry point functions */
26523 + * __si_read_lock, __si_write_lock,
26524 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
26526 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
26528 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
26529 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
26530 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
26532 +static inline void si_noflush_read_lock(struct super_block *sb)
26534 + __si_read_lock(sb);
26538 +static inline int si_noflush_read_trylock(struct super_block *sb)
26540 + int locked = __si_read_trylock(sb);
26546 +static inline void si_noflush_write_lock(struct super_block *sb)
26548 + __si_write_lock(sb);
26552 +static inline int si_noflush_write_trylock(struct super_block *sb)
26554 + int locked = __si_write_trylock(sb);
26560 +#if 0 /* unused */
26561 +static inline int si_read_trylock(struct super_block *sb, int flags)
26563 + if (au_ftest_lock(flags, FLUSH))
26564 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26565 + return si_noflush_read_trylock(sb);
26569 +static inline void si_read_unlock(struct super_block *sb)
26572 + __si_read_unlock(sb);
26575 +#if 0 /* unused */
26576 +static inline int si_write_trylock(struct super_block *sb, int flags)
26578 + if (au_ftest_lock(flags, FLUSH))
26579 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26580 + return si_noflush_write_trylock(sb);
26584 +static inline void si_write_unlock(struct super_block *sb)
26587 + __si_write_unlock(sb);
26590 +#if 0 /* unused */
26591 +static inline void si_downgrade_lock(struct super_block *sb)
26593 + __si_downgrade_lock(sb);
26597 +/* ---------------------------------------------------------------------- */
26599 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
26601 + SiMustAnyLock(sb);
26602 + return au_sbi(sb)->si_bend;
26605 +static inline unsigned int au_mntflags(struct super_block *sb)
26607 + SiMustAnyLock(sb);
26608 + return au_sbi(sb)->si_mntflags;
26611 +static inline unsigned int au_sigen(struct super_block *sb)
26613 + SiMustAnyLock(sb);
26614 + return au_sbi(sb)->si_generation;
26617 +static inline void au_ninodes_inc(struct super_block *sb)
26619 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
26622 +static inline void au_ninodes_dec(struct super_block *sb)
26624 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
26625 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
26628 +static inline void au_nfiles_inc(struct super_block *sb)
26630 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
26633 +static inline void au_nfiles_dec(struct super_block *sb)
26635 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
26636 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
26639 +static inline struct au_branch *au_sbr(struct super_block *sb,
26640 + aufs_bindex_t bindex)
26642 + SiMustAnyLock(sb);
26643 + return au_sbi(sb)->si_branch[0 + bindex];
26646 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
26648 + SiMustWriteLock(sb);
26649 + au_sbi(sb)->si_xino_brid = brid;
26652 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
26654 + SiMustAnyLock(sb);
26655 + return au_sbi(sb)->si_xino_brid;
26658 +#endif /* __KERNEL__ */
26659 +#endif /* __AUFS_SUPER_H__ */
26660 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
26661 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
26662 +++ linux/fs/aufs/sysaufs.c 2014-04-24 22:11:10.858602483 +0200
26665 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26667 + * This program, aufs is free software; you can redistribute it and/or modify
26668 + * it under the terms of the GNU General Public License as published by
26669 + * the Free Software Foundation; either version 2 of the License, or
26670 + * (at your option) any later version.
26672 + * This program is distributed in the hope that it will be useful,
26673 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26674 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26675 + * GNU General Public License for more details.
26677 + * You should have received a copy of the GNU General Public License
26678 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26682 + * sysfs interface and lifetime management
26683 + * they are necessary regardless sysfs is disabled.
26686 +#include <linux/random.h>
26689 +unsigned long sysaufs_si_mask;
26690 +struct kset *sysaufs_kset;
26692 +#define AuSiAttr(_name) { \
26693 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
26694 + .show = sysaufs_si_##_name, \
26697 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
26698 +struct attribute *sysaufs_si_attrs[] = {
26699 + &sysaufs_si_attr_xi_path.attr,
26703 +static const struct sysfs_ops au_sbi_ops = {
26704 + .show = sysaufs_si_show
26707 +static struct kobj_type au_sbi_ktype = {
26708 + .release = au_si_free,
26709 + .sysfs_ops = &au_sbi_ops,
26710 + .default_attrs = sysaufs_si_attrs
26713 +/* ---------------------------------------------------------------------- */
26715 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
26719 + sbinfo->si_kobj.kset = sysaufs_kset;
26720 + /* cf. sysaufs_name() */
26721 + err = kobject_init_and_add
26722 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
26723 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
26725 + dbgaufs_si_null(sbinfo);
26727 + err = dbgaufs_si_init(sbinfo);
26728 + if (unlikely(err))
26729 + kobject_put(&sbinfo->si_kobj);
26734 +void sysaufs_fin(void)
26737 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26738 + kset_unregister(sysaufs_kset);
26741 +int __init sysaufs_init(void)
26746 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
26747 + } while (!sysaufs_si_mask);
26750 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
26751 + if (unlikely(!sysaufs_kset))
26753 + err = PTR_ERR(sysaufs_kset);
26754 + if (IS_ERR(sysaufs_kset))
26756 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
26757 + if (unlikely(err)) {
26758 + kset_unregister(sysaufs_kset);
26762 + err = dbgaufs_init();
26763 + if (unlikely(err))
26768 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
26769 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
26770 +++ linux/fs/aufs/sysaufs.h 2014-04-24 22:11:10.858602483 +0200
26773 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26775 + * This program, aufs is free software; you can redistribute it and/or modify
26776 + * it under the terms of the GNU General Public License as published by
26777 + * the Free Software Foundation; either version 2 of the License, or
26778 + * (at your option) any later version.
26780 + * This program is distributed in the hope that it will be useful,
26781 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26782 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26783 + * GNU General Public License for more details.
26785 + * You should have received a copy of the GNU General Public License
26786 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26790 + * sysfs interface and mount lifetime management
26793 +#ifndef __SYSAUFS_H__
26794 +#define __SYSAUFS_H__
26798 +#include <linux/sysfs.h>
26799 +#include "module.h"
26801 +struct super_block;
26804 +struct sysaufs_si_attr {
26805 + struct attribute attr;
26806 + int (*show)(struct seq_file *seq, struct super_block *sb);
26809 +/* ---------------------------------------------------------------------- */
26812 +extern unsigned long sysaufs_si_mask;
26813 +extern struct kset *sysaufs_kset;
26814 +extern struct attribute *sysaufs_si_attrs[];
26815 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
26816 +int __init sysaufs_init(void);
26817 +void sysaufs_fin(void);
26819 +/* ---------------------------------------------------------------------- */
26821 +/* some people doesn't like to show a pointer in kernel */
26822 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
26824 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
26827 +#define SysaufsSiNamePrefix "si_"
26828 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
26829 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
26831 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
26832 + sysaufs_si_id(sbinfo));
26836 +#ifdef CONFIG_SYSFS
26838 +extern struct attribute_group *sysaufs_attr_group;
26840 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
26841 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26844 +void sysaufs_br_init(struct au_branch *br);
26845 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
26846 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
26848 +#define sysaufs_brs_init() do {} while (0)
26851 +#define sysaufs_attr_group NULL
26853 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
26856 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
26862 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
26863 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
26864 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
26866 +static inline void sysaufs_brs_init(void)
26871 +#endif /* CONFIG_SYSFS */
26873 +#endif /* __KERNEL__ */
26874 +#endif /* __SYSAUFS_H__ */
26875 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
26876 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
26877 +++ linux/fs/aufs/sysfs.c 2014-04-24 22:11:10.858602483 +0200
26880 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26882 + * This program, aufs is free software; you can redistribute it and/or modify
26883 + * it under the terms of the GNU General Public License as published by
26884 + * the Free Software Foundation; either version 2 of the License, or
26885 + * (at your option) any later version.
26887 + * This program is distributed in the hope that it will be useful,
26888 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26889 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26890 + * GNU General Public License for more details.
26892 + * You should have received a copy of the GNU General Public License
26893 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26897 + * sysfs interface
26900 +#include <linux/seq_file.h>
26903 +#ifdef CONFIG_AUFS_FS_MODULE
26904 +/* this entry violates the "one line per file" policy of sysfs */
26905 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
26909 + static char *conf =
26910 +/* this file is generated at compiling */
26911 +#include "conf.str"
26914 + err = snprintf(buf, PAGE_SIZE, conf);
26915 + if (unlikely(err >= PAGE_SIZE))
26920 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
26923 +static struct attribute *au_attr[] = {
26924 +#ifdef CONFIG_AUFS_FS_MODULE
26925 + &au_config_attr.attr,
26927 + NULL, /* need to NULL terminate the list of attributes */
26930 +static struct attribute_group sysaufs_attr_group_body = {
26934 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
26936 +/* ---------------------------------------------------------------------- */
26938 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
26942 + SiMustAnyLock(sb);
26945 + if (au_opt_test(au_mntflags(sb), XINO)) {
26946 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
26947 + seq_putc(seq, '\n');
26953 + * the lifetime of branch is independent from the entry under sysfs.
26954 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
26957 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
26958 + aufs_bindex_t bindex, int idx)
26961 + struct path path;
26962 + struct dentry *root;
26963 + struct au_branch *br;
26966 + AuDbg("b%d\n", bindex);
26969 + root = sb->s_root;
26970 + di_read_lock_parent(root, !AuLock_IR);
26971 + br = au_sbr(sb, bindex);
26974 + case AuBrSysfs_BR:
26975 + path.mnt = au_br_mnt(br);
26976 + path.dentry = au_h_dptr(root, bindex);
26977 + au_seq_path(seq, &path);
26978 + di_read_unlock(root, !AuLock_IR);
26979 + perm = au_optstr_br_perm(br->br_perm);
26981 + err = seq_printf(seq, "=%s\n", perm);
26988 + case AuBrSysfs_BRID:
26989 + err = seq_printf(seq, "%d\n", br->br_id);
26990 + di_read_unlock(root, !AuLock_IR);
26999 +/* ---------------------------------------------------------------------- */
27001 +static struct seq_file *au_seq(char *p, ssize_t len)
27003 + struct seq_file *seq;
27005 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
27007 + /* mutex_init(&seq.lock); */
27010 + return seq; /* success */
27013 + seq = ERR_PTR(-ENOMEM);
27017 +#define SysaufsBr_PREFIX "br"
27018 +#define SysaufsBrid_PREFIX "brid"
27020 +/* todo: file size may exceed PAGE_SIZE */
27021 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
27027 + aufs_bindex_t bend;
27028 + struct au_sbinfo *sbinfo;
27029 + struct super_block *sb;
27030 + struct seq_file *seq;
27032 + struct attribute **cattr;
27034 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
27035 + sb = sbinfo->si_sb;
27038 + * prevent a race condition between sysfs and aufs.
27039 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
27040 + * prohibits maintaining the sysfs entries.
27041 + * hew we acquire read lock after sysfs_get_active_two().
27042 + * on the other hand, the remount process may maintain the sysfs/aufs
27043 + * entries after acquiring write lock.
27044 + * it can cause a deadlock.
27045 + * simply we gave up processing read here.
27048 + if (unlikely(!si_noflush_read_trylock(sb)))
27051 + seq = au_seq(buf, PAGE_SIZE);
27052 + err = PTR_ERR(seq);
27056 + name = (void *)attr->name;
27057 + cattr = sysaufs_si_attrs;
27059 + if (!strcmp(name, (*cattr)->name)) {
27060 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
27067 + if (!strncmp(name, SysaufsBrid_PREFIX,
27068 + sizeof(SysaufsBrid_PREFIX) - 1)) {
27069 + idx = AuBrSysfs_BRID;
27070 + name += sizeof(SysaufsBrid_PREFIX) - 1;
27071 + } else if (!strncmp(name, SysaufsBr_PREFIX,
27072 + sizeof(SysaufsBr_PREFIX) - 1)) {
27073 + idx = AuBrSysfs_BR;
27074 + name += sizeof(SysaufsBr_PREFIX) - 1;
27078 + err = kstrtol(name, 10, &l);
27080 + bend = au_sbend(sb);
27082 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
27089 + err = seq->count;
27090 + /* sysfs limit */
27091 + if (unlikely(err == PAGE_SIZE))
27096 + si_read_unlock(sb);
27101 +/* ---------------------------------------------------------------------- */
27103 +void sysaufs_br_init(struct au_branch *br)
27106 + struct au_brsysfs *br_sysfs;
27107 + struct attribute *attr;
27109 + br_sysfs = br->br_sysfs;
27110 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
27111 + attr = &br_sysfs->attr;
27112 + sysfs_attr_init(attr);
27113 + attr->name = br_sysfs->name;
27114 + attr->mode = S_IRUGO;
27119 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
27121 + struct au_branch *br;
27122 + struct kobject *kobj;
27123 + struct au_brsysfs *br_sysfs;
27125 + aufs_bindex_t bend;
27127 + dbgaufs_brs_del(sb, bindex);
27129 + if (!sysaufs_brs)
27132 + kobj = &au_sbi(sb)->si_kobj;
27133 + bend = au_sbend(sb);
27134 + for (; bindex <= bend; bindex++) {
27135 + br = au_sbr(sb, bindex);
27136 + br_sysfs = br->br_sysfs;
27137 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
27138 + sysfs_remove_file(kobj, &br_sysfs->attr);
27144 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
27147 + aufs_bindex_t bend;
27148 + struct kobject *kobj;
27149 + struct au_branch *br;
27150 + struct au_brsysfs *br_sysfs;
27152 + dbgaufs_brs_add(sb, bindex);
27154 + if (!sysaufs_brs)
27157 + kobj = &au_sbi(sb)->si_kobj;
27158 + bend = au_sbend(sb);
27159 + for (; bindex <= bend; bindex++) {
27160 + br = au_sbr(sb, bindex);
27161 + br_sysfs = br->br_sysfs;
27162 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
27163 + SysaufsBr_PREFIX "%d", bindex);
27164 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
27165 + SysaufsBrid_PREFIX "%d", bindex);
27166 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
27167 + err = sysfs_create_file(kobj, &br_sysfs->attr);
27168 + if (unlikely(err))
27169 + pr_warn("failed %s under sysfs(%d)\n",
27170 + br_sysfs->name, err);
27175 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
27176 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
27177 +++ linux/fs/aufs/sysrq.c 2014-04-24 22:11:10.858602483 +0200
27180 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27182 + * This program, aufs is free software; you can redistribute it and/or modify
27183 + * it under the terms of the GNU General Public License as published by
27184 + * the Free Software Foundation; either version 2 of the License, or
27185 + * (at your option) any later version.
27187 + * This program is distributed in the hope that it will be useful,
27188 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27189 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27190 + * GNU General Public License for more details.
27192 + * You should have received a copy of the GNU General Public License
27193 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27197 + * magic sysrq hanlder
27200 +/* #include <linux/sysrq.h> */
27201 +#include <linux/writeback.h>
27204 +/* ---------------------------------------------------------------------- */
27206 +static void sysrq_sb(struct super_block *sb)
27209 + struct au_sbinfo *sbinfo;
27210 + struct file *file;
27211 + struct au_sphlhead *files;
27212 + struct au_finfo *finfo;
27214 + plevel = au_plevel;
27215 + au_plevel = KERN_WARNING;
27217 + /* since we define pr_fmt, call printk directly */
27218 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
27220 + sbinfo = au_sbi(sb);
27221 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
27222 + pr("superblock\n");
27226 + pr("root dentry\n");
27227 + au_dpri_dentry(sb->s_root);
27228 + pr("root inode\n");
27229 + au_dpri_inode(sb->s_root->d_inode);
27234 + int err, i, j, ndentry;
27235 + struct au_dcsub_pages dpages;
27236 + struct au_dpage *dpage;
27238 + err = au_dpages_init(&dpages, GFP_ATOMIC);
27239 + if (unlikely(err))
27241 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
27243 + for (i = 0; i < dpages.ndpage; i++) {
27244 + dpage = dpages.dpages + i;
27245 + ndentry = dpage->ndentry;
27246 + for (j = 0; j < ndentry; j++)
27247 + au_dpri_dentry(dpage->dentries[j]);
27249 + au_dpages_free(&dpages);
27256 + pr("isolated inode\n");
27257 + spin_lock(&inode_sb_list_lock);
27258 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
27259 + spin_lock(&i->i_lock);
27260 + if (1 || hlist_empty(&i->i_dentry))
27261 + au_dpri_inode(i);
27262 + spin_unlock(&i->i_lock);
27264 + spin_unlock(&inode_sb_list_lock);
27268 + files = &au_sbi(sb)->si_files;
27269 + spin_lock(&files->spin);
27270 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
27272 + file = finfo->fi_file;
27273 + mode = file_inode(file)->i_mode;
27274 + if (!special_file(mode) || au_special_file(mode))
27275 + au_dpri_file(file);
27277 + spin_unlock(&files->spin);
27281 + au_plevel = plevel;
27284 +/* ---------------------------------------------------------------------- */
27286 +/* module parameter */
27287 +static char *aufs_sysrq_key = "a";
27288 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
27289 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
27291 +static void au_sysrq(int key __maybe_unused)
27293 + struct au_sbinfo *sbinfo;
27296 + au_sbilist_lock();
27297 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
27298 + sysrq_sb(sbinfo->si_sb);
27299 + au_sbilist_unlock();
27303 +static struct sysrq_key_op au_sysrq_op = {
27304 + .handler = au_sysrq,
27305 + .help_msg = "Aufs",
27306 + .action_msg = "Aufs",
27307 + .enable_mask = SYSRQ_ENABLE_DUMP
27310 +/* ---------------------------------------------------------------------- */
27312 +int __init au_sysrq_init(void)
27318 + key = *aufs_sysrq_key;
27319 + if ('a' <= key && key <= 'z')
27320 + err = register_sysrq_key(key, &au_sysrq_op);
27321 + if (unlikely(err))
27322 + pr_err("err %d, sysrq=%c\n", err, key);
27326 +void au_sysrq_fin(void)
27329 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
27330 + if (unlikely(err))
27331 + pr_err("err %d (ignored)\n", err);
27333 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
27334 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
27335 +++ linux/fs/aufs/vdir.c 2014-04-24 22:11:10.858602483 +0200
27338 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27340 + * This program, aufs is free software; you can redistribute it and/or modify
27341 + * it under the terms of the GNU General Public License as published by
27342 + * the Free Software Foundation; either version 2 of the License, or
27343 + * (at your option) any later version.
27345 + * This program is distributed in the hope that it will be useful,
27346 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27347 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27348 + * GNU General Public License for more details.
27350 + * You should have received a copy of the GNU General Public License
27351 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27355 + * virtual or vertical directory
27360 +static unsigned int calc_size(int nlen)
27362 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
27365 +static int set_deblk_end(union au_vdir_deblk_p *p,
27366 + union au_vdir_deblk_p *deblk_end)
27368 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
27369 + p->de->de_str.len = 0;
27373 + return -1; /* error */
27376 +/* returns true or false */
27377 +static int is_deblk_end(union au_vdir_deblk_p *p,
27378 + union au_vdir_deblk_p *deblk_end)
27380 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
27381 + return !p->de->de_str.len;
27385 +static unsigned char *last_deblk(struct au_vdir *vdir)
27387 + return vdir->vd_deblk[vdir->vd_nblk - 1];
27390 +/* ---------------------------------------------------------------------- */
27392 +/* estimate the apropriate size for name hash table */
27393 +unsigned int au_rdhash_est(loff_t sz)
27401 + if (sz < AUFS_RDHASH_DEF)
27402 + n = AUFS_RDHASH_DEF;
27403 + /* pr_info("n %u\n", n); */
27408 + * the allocated memory has to be freed by
27409 + * au_nhash_wh_free() or au_nhash_de_free().
27411 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
27413 + struct hlist_head *head;
27416 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
27418 + nhash->nh_num = num_hash;
27419 + nhash->nh_head = head;
27420 + for (u = 0; u < num_hash; u++)
27421 + INIT_HLIST_HEAD(head++);
27422 + return 0; /* success */
27428 +static void nhash_count(struct hlist_head *head)
27432 + struct hlist_node *pos;
27435 + hlist_for_each(pos, head)
27437 + pr_info("%lu\n", n);
27441 +static void au_nhash_wh_do_free(struct hlist_head *head)
27443 + struct au_vdir_wh *pos;
27444 + struct hlist_node *node;
27446 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
27450 +static void au_nhash_de_do_free(struct hlist_head *head)
27452 + struct au_vdir_dehstr *pos;
27453 + struct hlist_node *node;
27455 + hlist_for_each_entry_safe(pos, node, head, hash)
27456 + au_cache_free_vdir_dehstr(pos);
27459 +static void au_nhash_do_free(struct au_nhash *nhash,
27460 + void (*free)(struct hlist_head *head))
27463 + struct hlist_head *head;
27465 + n = nhash->nh_num;
27469 + head = nhash->nh_head;
27470 + while (n-- > 0) {
27471 + nhash_count(head);
27474 + kfree(nhash->nh_head);
27477 +void au_nhash_wh_free(struct au_nhash *whlist)
27479 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
27482 +static void au_nhash_de_free(struct au_nhash *delist)
27484 + au_nhash_do_free(delist, au_nhash_de_do_free);
27487 +/* ---------------------------------------------------------------------- */
27489 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
27493 + unsigned int u, n;
27494 + struct hlist_head *head;
27495 + struct au_vdir_wh *pos;
27498 + n = whlist->nh_num;
27499 + head = whlist->nh_head;
27500 + for (u = 0; u < n; u++, head++)
27501 + hlist_for_each_entry(pos, head, wh_hash)
27502 + if (pos->wh_bindex == btgt && ++num > limit)
27507 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
27508 + unsigned char *name,
27509 + unsigned int len)
27512 + /* const unsigned int magic_bit = 12; */
27514 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
27519 + /* v = hash_long(v, magic_bit); */
27520 + v %= nhash->nh_num;
27521 + return nhash->nh_head + v;
27524 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
27527 + return str->len == nlen && !memcmp(str->name, name, nlen);
27530 +/* returns found or not */
27531 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
27533 + struct hlist_head *head;
27534 + struct au_vdir_wh *pos;
27535 + struct au_vdir_destr *str;
27537 + head = au_name_hash(whlist, name, nlen);
27538 + hlist_for_each_entry(pos, head, wh_hash) {
27539 + str = &pos->wh_str;
27540 + AuDbg("%.*s\n", str->len, str->name);
27541 + if (au_nhash_test_name(str, name, nlen))
27547 +/* returns found(true) or not */
27548 +static int test_known(struct au_nhash *delist, char *name, int nlen)
27550 + struct hlist_head *head;
27551 + struct au_vdir_dehstr *pos;
27552 + struct au_vdir_destr *str;
27554 + head = au_name_hash(delist, name, nlen);
27555 + hlist_for_each_entry(pos, head, hash) {
27557 + AuDbg("%.*s\n", str->len, str->name);
27558 + if (au_nhash_test_name(str, name, nlen))
27564 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
27565 + unsigned char d_type)
27567 +#ifdef CONFIG_AUFS_SHWH
27568 + wh->wh_ino = ino;
27569 + wh->wh_type = d_type;
27573 +/* ---------------------------------------------------------------------- */
27575 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
27576 + unsigned int d_type, aufs_bindex_t bindex,
27577 + unsigned char shwh)
27580 + struct au_vdir_destr *str;
27581 + struct au_vdir_wh *wh;
27583 + AuDbg("%.*s\n", nlen, name);
27584 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
27587 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
27588 + if (unlikely(!wh))
27592 + wh->wh_bindex = bindex;
27594 + au_shwh_init_wh(wh, ino, d_type);
27595 + str = &wh->wh_str;
27597 + memcpy(str->name, name, nlen);
27598 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
27605 +static int append_deblk(struct au_vdir *vdir)
27608 + unsigned long ul;
27609 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
27610 + union au_vdir_deblk_p p, deblk_end;
27611 + unsigned char **o;
27614 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
27616 + if (unlikely(!o))
27619 + vdir->vd_deblk = o;
27620 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
27622 + ul = vdir->vd_nblk++;
27623 + vdir->vd_deblk[ul] = p.deblk;
27624 + vdir->vd_last.ul = ul;
27625 + vdir->vd_last.p.deblk = p.deblk;
27626 + deblk_end.deblk = p.deblk + deblk_sz;
27627 + err = set_deblk_end(&p, &deblk_end);
27634 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
27635 + unsigned int d_type, struct au_nhash *delist)
27639 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
27640 + union au_vdir_deblk_p p, *room, deblk_end;
27641 + struct au_vdir_dehstr *dehstr;
27643 + p.deblk = last_deblk(vdir);
27644 + deblk_end.deblk = p.deblk + deblk_sz;
27645 + room = &vdir->vd_last.p;
27646 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
27647 + || !is_deblk_end(room, &deblk_end));
27649 + sz = calc_size(nlen);
27650 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
27651 + err = append_deblk(vdir);
27652 + if (unlikely(err))
27655 + p.deblk = last_deblk(vdir);
27656 + deblk_end.deblk = p.deblk + deblk_sz;
27658 + AuDebugOn(room->deblk != p.deblk);
27662 + dehstr = au_cache_alloc_vdir_dehstr();
27663 + if (unlikely(!dehstr))
27666 + dehstr->str = &room->de->de_str;
27667 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
27668 + room->de->de_ino = ino;
27669 + room->de->de_type = d_type;
27670 + room->de->de_str.len = nlen;
27671 + memcpy(room->de->de_str.name, name, nlen);
27674 + room->deblk += sz;
27675 + if (unlikely(set_deblk_end(room, &deblk_end)))
27676 + err = append_deblk(vdir);
27683 +/* ---------------------------------------------------------------------- */
27685 +void au_vdir_free(struct au_vdir *vdir)
27687 + unsigned char **deblk;
27689 + deblk = vdir->vd_deblk;
27690 + while (vdir->vd_nblk--)
27692 + kfree(vdir->vd_deblk);
27693 + au_cache_free_vdir(vdir);
27696 +static struct au_vdir *alloc_vdir(struct file *file)
27698 + struct au_vdir *vdir;
27699 + struct super_block *sb;
27702 + sb = file->f_dentry->d_sb;
27703 + SiMustAnyLock(sb);
27706 + vdir = au_cache_alloc_vdir();
27707 + if (unlikely(!vdir))
27710 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
27711 + if (unlikely(!vdir->vd_deblk))
27714 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
27715 + if (!vdir->vd_deblk_sz) {
27716 + /* estimate the apropriate size for deblk */
27717 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
27718 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
27720 + vdir->vd_nblk = 0;
27721 + vdir->vd_version = 0;
27722 + vdir->vd_jiffy = 0;
27723 + err = append_deblk(vdir);
27725 + return vdir; /* success */
27727 + kfree(vdir->vd_deblk);
27730 + au_cache_free_vdir(vdir);
27732 + vdir = ERR_PTR(err);
27736 +static int reinit_vdir(struct au_vdir *vdir)
27739 + union au_vdir_deblk_p p, deblk_end;
27741 + while (vdir->vd_nblk > 1) {
27742 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
27743 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
27746 + p.deblk = vdir->vd_deblk[0];
27747 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
27748 + err = set_deblk_end(&p, &deblk_end);
27749 + /* keep vd_dblk_sz */
27750 + vdir->vd_last.ul = 0;
27751 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
27752 + vdir->vd_version = 0;
27753 + vdir->vd_jiffy = 0;
27758 +/* ---------------------------------------------------------------------- */
27760 +#define AuFillVdir_CALLED 1
27761 +#define AuFillVdir_WHABLE (1 << 1)
27762 +#define AuFillVdir_SHWH (1 << 2)
27763 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
27764 +#define au_fset_fillvdir(flags, name) \
27765 + do { (flags) |= AuFillVdir_##name; } while (0)
27766 +#define au_fclr_fillvdir(flags, name) \
27767 + do { (flags) &= ~AuFillVdir_##name; } while (0)
27769 +#ifndef CONFIG_AUFS_SHWH
27770 +#undef AuFillVdir_SHWH
27771 +#define AuFillVdir_SHWH 0
27774 +struct fillvdir_arg {
27775 + struct dir_context ctx;
27776 + struct file *file;
27777 + struct au_vdir *vdir;
27778 + struct au_nhash delist;
27779 + struct au_nhash whlist;
27780 + aufs_bindex_t bindex;
27781 + unsigned int flags;
27785 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
27786 + loff_t offset __maybe_unused, u64 h_ino,
27787 + unsigned int d_type)
27789 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
27790 + char *name = (void *)__name;
27791 + struct super_block *sb;
27793 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
27796 + sb = arg->file->f_dentry->d_sb;
27797 + au_fset_fillvdir(arg->flags, CALLED);
27799 + if (nlen <= AUFS_WH_PFX_LEN
27800 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
27801 + if (test_known(&arg->delist, name, nlen)
27802 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
27803 + goto out; /* already exists or whiteouted */
27805 + sb = arg->file->f_dentry->d_sb;
27806 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
27808 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
27809 + d_type = DT_UNKNOWN;
27810 + arg->err = append_de(arg->vdir, name, nlen, ino,
27811 + d_type, &arg->delist);
27813 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
27814 + name += AUFS_WH_PFX_LEN;
27815 + nlen -= AUFS_WH_PFX_LEN;
27816 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
27817 + goto out; /* already whiteouted */
27820 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
27823 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
27824 + d_type = DT_UNKNOWN;
27825 + arg->err = au_nhash_append_wh
27826 + (&arg->whlist, name, nlen, ino, d_type,
27827 + arg->bindex, shwh);
27833 + arg->vdir->vd_jiffy = jiffies;
27835 + AuTraceErr(arg->err);
27839 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
27840 + struct au_nhash *whlist, struct au_nhash *delist)
27842 +#ifdef CONFIG_AUFS_SHWH
27844 + unsigned int nh, u;
27845 + struct hlist_head *head;
27846 + struct au_vdir_wh *pos;
27847 + struct hlist_node *n;
27849 + struct au_vdir_destr *destr;
27851 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
27854 + o = p = (void *)__get_free_page(GFP_NOFS);
27855 + if (unlikely(!p))
27859 + nh = whlist->nh_num;
27860 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
27861 + p += AUFS_WH_PFX_LEN;
27862 + for (u = 0; u < nh; u++) {
27863 + head = whlist->nh_head + u;
27864 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
27865 + destr = &pos->wh_str;
27866 + memcpy(p, destr->name, destr->len);
27867 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
27868 + pos->wh_ino, pos->wh_type, delist);
27869 + if (unlikely(err))
27874 + free_page((unsigned long)o);
27884 +static int au_do_read_vdir(struct fillvdir_arg *arg)
27887 + unsigned int rdhash;
27889 + aufs_bindex_t bend, bindex, bstart;
27890 + unsigned char shwh;
27891 + struct file *hf, *file;
27892 + struct super_block *sb;
27894 + file = arg->file;
27895 + sb = file->f_dentry->d_sb;
27896 + SiMustAnyLock(sb);
27898 + rdhash = au_sbi(sb)->si_rdhash;
27900 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
27901 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
27902 + if (unlikely(err))
27904 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
27905 + if (unlikely(err))
27911 + if (au_opt_test(au_mntflags(sb), SHWH)) {
27913 + au_fset_fillvdir(arg->flags, SHWH);
27915 + bstart = au_fbstart(file);
27916 + bend = au_fbend_dir(file);
27917 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
27918 + hf = au_hf_dir(file, bindex);
27922 + offset = vfsub_llseek(hf, 0, SEEK_SET);
27924 + if (unlikely(offset))
27927 + arg->bindex = bindex;
27928 + au_fclr_fillvdir(arg->flags, WHABLE);
27930 + || (bindex != bend
27931 + && au_br_whable(au_sbr_perm(sb, bindex))))
27932 + au_fset_fillvdir(arg->flags, WHABLE);
27935 + au_fclr_fillvdir(arg->flags, CALLED);
27937 + err = vfsub_iterate_dir(hf, &arg->ctx);
27940 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
27943 + * dir_relax() may be good for concurrency, but aufs should not
27944 + * use it since it will cause a lockdep problem.
27948 + if (!err && shwh)
27949 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
27951 + au_nhash_wh_free(&arg->whlist);
27954 + au_nhash_de_free(&arg->delist);
27959 +static int read_vdir(struct file *file, int may_read)
27962 + unsigned long expire;
27963 + unsigned char do_read;
27964 + struct fillvdir_arg arg = {
27966 + .actor = au_diractor(fillvdir)
27969 + struct inode *inode;
27970 + struct au_vdir *vdir, *allocated;
27973 + inode = file_inode(file);
27974 + IMustLock(inode);
27975 + SiMustAnyLock(inode->i_sb);
27977 + allocated = NULL;
27979 + expire = au_sbi(inode->i_sb)->si_rdcache;
27980 + vdir = au_ivdir(inode);
27983 + vdir = alloc_vdir(file);
27984 + err = PTR_ERR(vdir);
27985 + if (IS_ERR(vdir))
27988 + allocated = vdir;
27989 + } else if (may_read
27990 + && (inode->i_version != vdir->vd_version
27991 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
27993 + err = reinit_vdir(vdir);
27994 + if (unlikely(err))
27999 + return 0; /* success */
28003 + err = au_do_read_vdir(&arg);
28005 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
28006 + vdir->vd_version = inode->i_version;
28007 + vdir->vd_last.ul = 0;
28008 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
28010 + au_set_ivdir(inode, allocated);
28011 + } else if (allocated)
28012 + au_vdir_free(allocated);
28018 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
28021 + unsigned long ul, n;
28022 + const unsigned int deblk_sz = src->vd_deblk_sz;
28024 + AuDebugOn(tgt->vd_nblk != 1);
28027 + if (tgt->vd_nblk < src->vd_nblk) {
28028 + unsigned char **p;
28030 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
28032 + if (unlikely(!p))
28034 + tgt->vd_deblk = p;
28037 + if (tgt->vd_deblk_sz != deblk_sz) {
28038 + unsigned char *p;
28040 + tgt->vd_deblk_sz = deblk_sz;
28041 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
28042 + if (unlikely(!p))
28044 + tgt->vd_deblk[0] = p;
28046 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
28047 + tgt->vd_version = src->vd_version;
28048 + tgt->vd_jiffy = src->vd_jiffy;
28050 + n = src->vd_nblk;
28051 + for (ul = 1; ul < n; ul++) {
28052 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
28054 + if (unlikely(!tgt->vd_deblk[ul]))
28058 + tgt->vd_nblk = n;
28059 + tgt->vd_last.ul = tgt->vd_last.ul;
28060 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
28061 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
28062 + - src->vd_deblk[src->vd_last.ul];
28064 + return 0; /* success */
28067 + rerr = reinit_vdir(tgt);
28072 +int au_vdir_init(struct file *file)
28075 + struct inode *inode;
28076 + struct au_vdir *vdir_cache, *allocated;
28078 + /* test file->f_pos here instead of ctx->pos */
28079 + err = read_vdir(file, !file->f_pos);
28080 + if (unlikely(err))
28083 + allocated = NULL;
28084 + vdir_cache = au_fvdir_cache(file);
28085 + if (!vdir_cache) {
28086 + vdir_cache = alloc_vdir(file);
28087 + err = PTR_ERR(vdir_cache);
28088 + if (IS_ERR(vdir_cache))
28090 + allocated = vdir_cache;
28091 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
28092 + /* test file->f_pos here instead of ctx->pos */
28093 + err = reinit_vdir(vdir_cache);
28094 + if (unlikely(err))
28097 + return 0; /* success */
28099 + inode = file_inode(file);
28100 + err = copy_vdir(vdir_cache, au_ivdir(inode));
28102 + file->f_version = inode->i_version;
28104 + au_set_fvdir_cache(file, allocated);
28105 + } else if (allocated)
28106 + au_vdir_free(allocated);
28112 +static loff_t calc_offset(struct au_vdir *vdir)
28115 + union au_vdir_deblk_p p;
28117 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
28118 + offset = vdir->vd_last.p.deblk - p.deblk;
28119 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
28123 +/* returns true or false */
28124 +static int seek_vdir(struct file *file, struct dir_context *ctx)
28127 + unsigned int deblk_sz;
28128 + unsigned long ul, n;
28130 + union au_vdir_deblk_p p, deblk_end;
28131 + struct au_vdir *vdir_cache;
28134 + vdir_cache = au_fvdir_cache(file);
28135 + offset = calc_offset(vdir_cache);
28136 + AuDbg("offset %lld\n", offset);
28137 + if (ctx->pos == offset)
28140 + vdir_cache->vd_last.ul = 0;
28141 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
28146 + deblk_sz = vdir_cache->vd_deblk_sz;
28147 + ul = div64_u64(ctx->pos, deblk_sz);
28148 + AuDbg("ul %lu\n", ul);
28149 + if (ul >= vdir_cache->vd_nblk)
28152 + n = vdir_cache->vd_nblk;
28153 + for (; ul < n; ul++) {
28154 + p.deblk = vdir_cache->vd_deblk[ul];
28155 + deblk_end.deblk = p.deblk + deblk_sz;
28157 + offset *= deblk_sz;
28158 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
28161 + l = calc_size(p.de->de_str.len);
28165 + if (!is_deblk_end(&p, &deblk_end)) {
28167 + vdir_cache->vd_last.ul = ul;
28168 + vdir_cache->vd_last.p = p;
28175 + AuTraceErr(!valid);
28179 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
28181 + unsigned int l, deblk_sz;
28182 + union au_vdir_deblk_p deblk_end;
28183 + struct au_vdir *vdir_cache;
28184 + struct au_vdir_de *de;
28186 + vdir_cache = au_fvdir_cache(file);
28187 + if (!seek_vdir(file, ctx))
28190 + deblk_sz = vdir_cache->vd_deblk_sz;
28192 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
28193 + deblk_end.deblk += deblk_sz;
28194 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
28195 + de = vdir_cache->vd_last.p.de;
28196 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
28197 + de->de_str.len, de->de_str.name, ctx->pos,
28198 + (unsigned long)de->de_ino, de->de_type);
28199 + if (unlikely(!dir_emit(ctx, de->de_str.name,
28200 + de->de_str.len, de->de_ino,
28202 + /* todo: ignore the error caused by udba? */
28203 + /* return err; */
28207 + l = calc_size(de->de_str.len);
28208 + vdir_cache->vd_last.p.deblk += l;
28211 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
28212 + vdir_cache->vd_last.ul++;
28213 + vdir_cache->vd_last.p.deblk
28214 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
28215 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
28224 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
28225 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
28226 +++ linux/fs/aufs/vfsub.c 2014-04-24 22:11:10.861935852 +0200
28229 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28231 + * This program, aufs is free software; you can redistribute it and/or modify
28232 + * it under the terms of the GNU General Public License as published by
28233 + * the Free Software Foundation; either version 2 of the License, or
28234 + * (at your option) any later version.
28236 + * This program is distributed in the hope that it will be useful,
28237 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28238 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28239 + * GNU General Public License for more details.
28241 + * You should have received a copy of the GNU General Public License
28242 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28246 + * sub-routines for VFS
28249 +#include <linux/ima.h>
28250 +#include <linux/namei.h>
28251 +#include <linux/security.h>
28252 +#include <linux/splice.h>
28255 +int vfsub_update_h_iattr(struct path *h_path, int *did)
28259 + struct super_block *h_sb;
28261 + /* for remote fs, leave work for its getattr or d_revalidate */
28262 + /* for bad i_attr fs, handle them in aufs_getattr() */
28263 + /* still some fs may acquire i_mutex. we need to skip them */
28267 + h_sb = h_path->dentry->d_sb;
28268 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
28270 + err = vfs_getattr(h_path, &st);
28275 +/* ---------------------------------------------------------------------- */
28277 +struct file *vfsub_dentry_open(struct path *path, int flags)
28279 + struct file *file;
28281 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
28283 + if (!IS_ERR_OR_NULL(file)
28284 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
28285 + i_readcount_inc(path->dentry->d_inode);
28290 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
28292 + struct file *file;
28295 + file = filp_open(path,
28296 + oflags /* | __FMODE_NONOTIFY */,
28299 + if (IS_ERR(file))
28301 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28307 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
28311 + err = kern_path(name, flags, path);
28312 + if (!err && path->dentry->d_inode)
28313 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
28317 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
28320 + struct path path = {
28324 + /* VFS checks it too, but by WARN_ON_ONCE() */
28325 + IMustLock(parent->d_inode);
28327 + path.dentry = lookup_one_len(name, parent, len);
28328 + if (IS_ERR(path.dentry))
28330 + if (path.dentry->d_inode)
28331 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
28334 + AuTraceErrPtr(path.dentry);
28335 + return path.dentry;
28338 +void vfsub_call_lkup_one(void *args)
28340 + struct vfsub_lkup_one_args *a = args;
28341 + *a->errp = vfsub_lkup_one(a->name, a->parent);
28344 +/* ---------------------------------------------------------------------- */
28346 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
28347 + struct dentry *d2, struct au_hinode *hdir2)
28349 + struct dentry *d;
28352 + d = lock_rename(d1, d2);
28354 + au_hn_suspend(hdir1);
28355 + if (hdir1 != hdir2)
28356 + au_hn_suspend(hdir2);
28361 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
28362 + struct dentry *d2, struct au_hinode *hdir2)
28364 + au_hn_resume(hdir1);
28365 + if (hdir1 != hdir2)
28366 + au_hn_resume(hdir2);
28368 + unlock_rename(d1, d2);
28372 +/* ---------------------------------------------------------------------- */
28374 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
28377 + struct dentry *d;
28381 + d = path->dentry;
28382 + path->dentry = d->d_parent;
28383 + err = security_path_mknod(path, d, mode, 0);
28384 + path->dentry = d;
28385 + if (unlikely(err))
28388 + err = vfs_create(dir, path->dentry, mode, want_excl);
28390 + struct path tmp = *path;
28393 + vfsub_update_h_iattr(&tmp, &did);
28395 + tmp.dentry = path->dentry->d_parent;
28396 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28405 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
28408 + struct dentry *d;
28412 + d = path->dentry;
28413 + path->dentry = d->d_parent;
28414 + err = security_path_symlink(path, d, symname);
28415 + path->dentry = d;
28416 + if (unlikely(err))
28419 + err = vfs_symlink(dir, path->dentry, symname);
28421 + struct path tmp = *path;
28424 + vfsub_update_h_iattr(&tmp, &did);
28426 + tmp.dentry = path->dentry->d_parent;
28427 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28436 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
28439 + struct dentry *d;
28443 + d = path->dentry;
28444 + path->dentry = d->d_parent;
28445 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
28446 + path->dentry = d;
28447 + if (unlikely(err))
28450 + err = vfs_mknod(dir, path->dentry, mode, dev);
28452 + struct path tmp = *path;
28455 + vfsub_update_h_iattr(&tmp, &did);
28457 + tmp.dentry = path->dentry->d_parent;
28458 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28467 +static int au_test_nlink(struct inode *inode)
28469 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
28471 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
28472 + || inode->i_nlink < link_max)
28477 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
28478 + struct inode **delegated_inode)
28481 + struct dentry *d;
28485 + err = au_test_nlink(src_dentry->d_inode);
28486 + if (unlikely(err))
28489 + /* we don't call may_linkat() */
28490 + d = path->dentry;
28491 + path->dentry = d->d_parent;
28492 + err = security_path_link(src_dentry, path, d);
28493 + path->dentry = d;
28494 + if (unlikely(err))
28498 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
28501 + struct path tmp = *path;
28504 + /* fuse has different memory inode for the same inumber */
28505 + vfsub_update_h_iattr(&tmp, &did);
28507 + tmp.dentry = path->dentry->d_parent;
28508 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28509 + tmp.dentry = src_dentry;
28510 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28519 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
28520 + struct inode *dir, struct path *path,
28521 + struct inode **delegated_inode)
28524 + struct path tmp = {
28527 + struct dentry *d;
28530 + IMustLock(src_dir);
28532 + d = path->dentry;
28533 + path->dentry = d->d_parent;
28534 + tmp.dentry = src_dentry->d_parent;
28535 + err = security_path_rename(&tmp, src_dentry, path, d);
28536 + path->dentry = d;
28537 + if (unlikely(err))
28541 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
28542 + delegated_inode);
28547 + tmp.dentry = d->d_parent;
28548 + vfsub_update_h_iattr(&tmp, &did);
28550 + tmp.dentry = src_dentry;
28551 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28552 + tmp.dentry = src_dentry->d_parent;
28553 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28562 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
28565 + struct dentry *d;
28569 + d = path->dentry;
28570 + path->dentry = d->d_parent;
28571 + err = security_path_mkdir(path, d, mode);
28572 + path->dentry = d;
28573 + if (unlikely(err))
28576 + err = vfs_mkdir(dir, path->dentry, mode);
28578 + struct path tmp = *path;
28581 + vfsub_update_h_iattr(&tmp, &did);
28583 + tmp.dentry = path->dentry->d_parent;
28584 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
28593 +int vfsub_rmdir(struct inode *dir, struct path *path)
28596 + struct dentry *d;
28600 + d = path->dentry;
28601 + path->dentry = d->d_parent;
28602 + err = security_path_rmdir(path, d);
28603 + path->dentry = d;
28604 + if (unlikely(err))
28608 + err = vfs_rmdir(dir, path->dentry);
28611 + struct path tmp = {
28612 + .dentry = path->dentry->d_parent,
28616 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
28623 +/* ---------------------------------------------------------------------- */
28625 +/* todo: support mmap_sem? */
28626 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
28632 + err = vfs_read(file, ubuf, count, ppos);
28635 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28639 +/* todo: kernel_read()? */
28640 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
28644 + mm_segment_t oldfs;
28651 + oldfs = get_fs();
28652 + set_fs(KERNEL_DS);
28653 + err = vfsub_read_u(file, buf.u, count, ppos);
28658 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
28664 + err = vfs_write(file, ubuf, count, ppos);
28667 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28671 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
28674 + mm_segment_t oldfs;
28677 + const char __user *u;
28681 + oldfs = get_fs();
28682 + set_fs(KERNEL_DS);
28683 + err = vfsub_write_u(file, buf.u, count, ppos);
28688 +int vfsub_flush(struct file *file, fl_owner_t id)
28693 + if (file->f_op->flush) {
28694 + if (!au_test_nfs(file->f_dentry->d_sb))
28695 + err = file->f_op->flush(file, id);
28698 + err = file->f_op->flush(file, id);
28702 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
28708 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
28712 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
28715 + err = iterate_dir(file, ctx);
28718 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
28722 +long vfsub_splice_to(struct file *in, loff_t *ppos,
28723 + struct pipe_inode_info *pipe, size_t len,
28724 + unsigned int flags)
28729 + err = do_splice_to(in, ppos, pipe, len, flags);
28731 + file_accessed(in);
28733 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
28737 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
28738 + loff_t *ppos, size_t len, unsigned int flags)
28743 + err = do_splice_from(pipe, out, ppos, len, flags);
28746 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
28750 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
28754 + /* file can be NULL */
28756 + err = vfs_fsync(file, datasync);
28760 + AuDebugOn(!file);
28761 + path = &file->f_path;
28763 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
28768 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
28769 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
28770 + struct file *h_file)
28773 + struct inode *h_inode;
28774 + struct super_block *h_sb;
28777 + err = vfsub_truncate(h_path, length);
28781 + h_inode = h_path->dentry->d_inode;
28782 + h_sb = h_inode->i_sb;
28784 + sb_start_write(h_sb);
28786 + err = locks_verify_truncate(h_inode, h_file, length);
28788 + err = security_path_truncate(h_path);
28791 + err = do_truncate(h_path->dentry, length, attr, h_file);
28795 + sb_end_write(h_sb);
28802 +/* ---------------------------------------------------------------------- */
28804 +struct au_vfsub_mkdir_args {
28806 + struct inode *dir;
28807 + struct path *path;
28811 +static void au_call_vfsub_mkdir(void *args)
28813 + struct au_vfsub_mkdir_args *a = args;
28814 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
28817 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
28819 + int err, do_sio, wkq_err;
28821 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28823 + err = vfsub_mkdir(dir, path, mode);
28825 + struct au_vfsub_mkdir_args args = {
28831 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
28832 + if (unlikely(wkq_err))
28839 +struct au_vfsub_rmdir_args {
28841 + struct inode *dir;
28842 + struct path *path;
28845 +static void au_call_vfsub_rmdir(void *args)
28847 + struct au_vfsub_rmdir_args *a = args;
28848 + *a->errp = vfsub_rmdir(a->dir, a->path);
28851 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
28853 + int err, do_sio, wkq_err;
28855 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
28857 + err = vfsub_rmdir(dir, path);
28859 + struct au_vfsub_rmdir_args args = {
28864 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
28865 + if (unlikely(wkq_err))
28872 +/* ---------------------------------------------------------------------- */
28874 +struct notify_change_args {
28876 + struct path *path;
28877 + struct iattr *ia;
28878 + struct inode **delegated_inode;
28881 +static void call_notify_change(void *args)
28883 + struct notify_change_args *a = args;
28884 + struct inode *h_inode;
28886 + h_inode = a->path->dentry->d_inode;
28887 + IMustLock(h_inode);
28889 + *a->errp = -EPERM;
28890 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
28891 + *a->errp = notify_change(a->path->dentry, a->ia,
28892 + a->delegated_inode);
28894 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
28896 + AuTraceErr(*a->errp);
28899 +int vfsub_notify_change(struct path *path, struct iattr *ia,
28900 + struct inode **delegated_inode)
28903 + struct notify_change_args args = {
28907 + .delegated_inode = delegated_inode
28910 + call_notify_change(&args);
28915 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
28916 + struct inode **delegated_inode)
28918 + int err, wkq_err;
28919 + struct notify_change_args args = {
28923 + .delegated_inode = delegated_inode
28926 + wkq_err = au_wkq_wait(call_notify_change, &args);
28927 + if (unlikely(wkq_err))
28933 +/* ---------------------------------------------------------------------- */
28935 +struct unlink_args {
28937 + struct inode *dir;
28938 + struct path *path;
28939 + struct inode **delegated_inode;
28942 +static void call_unlink(void *args)
28944 + struct unlink_args *a = args;
28945 + struct dentry *d = a->path->dentry;
28946 + struct inode *h_inode;
28947 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
28948 + && d_count(d) == 1);
28950 + IMustLock(a->dir);
28952 + a->path->dentry = d->d_parent;
28953 + *a->errp = security_path_unlink(a->path, d);
28954 + a->path->dentry = d;
28955 + if (unlikely(*a->errp))
28958 + if (!stop_sillyrename)
28960 + h_inode = d->d_inode;
28965 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
28968 + struct path tmp = {
28969 + .dentry = d->d_parent,
28970 + .mnt = a->path->mnt
28972 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
28975 + if (!stop_sillyrename)
28980 + AuTraceErr(*a->errp);
28984 + * @dir: must be locked.
28985 + * @dentry: target dentry.
28987 +int vfsub_unlink(struct inode *dir, struct path *path,
28988 + struct inode **delegated_inode, int force)
28991 + struct unlink_args args = {
28995 + .delegated_inode = delegated_inode
28999 + call_unlink(&args);
29003 + wkq_err = au_wkq_wait(call_unlink, &args);
29004 + if (unlikely(wkq_err))
29010 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
29011 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
29012 +++ linux/fs/aufs/vfsub.h 2014-04-24 22:11:10.861935852 +0200
29015 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29017 + * This program, aufs is free software; you can redistribute it and/or modify
29018 + * it under the terms of the GNU General Public License as published by
29019 + * the Free Software Foundation; either version 2 of the License, or
29020 + * (at your option) any later version.
29022 + * This program is distributed in the hope that it will be useful,
29023 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29024 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29025 + * GNU General Public License for more details.
29027 + * You should have received a copy of the GNU General Public License
29028 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29032 + * sub-routines for VFS
29035 +#ifndef __AUFS_VFSUB_H__
29036 +#define __AUFS_VFSUB_H__
29040 +#include <linux/fs.h>
29041 +#include <linux/lglock.h>
29042 +#include <linux/mount.h>
29043 +#include "debug.h"
29045 +/* copied from linux/fs/internal.h */
29046 +/* todo: BAD approach!! */
29047 +extern void __mnt_drop_write(struct vfsmount *);
29048 +extern spinlock_t inode_sb_list_lock;
29050 +/* ---------------------------------------------------------------------- */
29052 +/* lock subclass for lower inode */
29053 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
29054 +/* reduce? gave up. */
29056 + AuLsc_I_Begin = I_MUTEX_NONDIR2, /* 4 */
29057 + AuLsc_I_PARENT, /* lower inode, parent first */
29058 + AuLsc_I_PARENT2, /* copyup dirs */
29059 + AuLsc_I_PARENT3, /* copyup wh */
29065 +/* to debug easier, do not make them inlined functions */
29066 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
29067 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
29069 +/* ---------------------------------------------------------------------- */
29071 +static inline void vfsub_drop_nlink(struct inode *inode)
29073 + AuDebugOn(!inode->i_nlink);
29074 + drop_nlink(inode);
29077 +static inline void vfsub_dead_dir(struct inode *inode)
29079 + AuDebugOn(!S_ISDIR(inode->i_mode));
29080 + inode->i_flags |= S_DEAD;
29081 + clear_nlink(inode);
29084 +static inline int vfsub_native_ro(struct inode *inode)
29086 + return (inode->i_sb->s_flags & MS_RDONLY)
29087 + || IS_RDONLY(inode)
29088 + /* || IS_APPEND(inode) */
29089 + || IS_IMMUTABLE(inode);
29092 +/* ---------------------------------------------------------------------- */
29094 +int vfsub_update_h_iattr(struct path *h_path, int *did);
29095 +struct file *vfsub_dentry_open(struct path *path, int flags);
29096 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
29097 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
29099 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
29102 +struct vfsub_lkup_one_args {
29103 + struct dentry **errp;
29104 + struct qstr *name;
29105 + struct dentry *parent;
29108 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
29109 + struct dentry *parent)
29111 + return vfsub_lookup_one_len(name->name, parent, name->len);
29114 +void vfsub_call_lkup_one(void *args);
29116 +/* ---------------------------------------------------------------------- */
29118 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
29122 + err = mnt_want_write(mnt);
29127 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
29130 + mnt_drop_write(mnt);
29134 +static inline void vfsub_mnt_drop_write_file(struct file *file)
29137 + mnt_drop_write_file(file);
29141 +/* ---------------------------------------------------------------------- */
29144 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
29145 + struct dentry *d2, struct au_hinode *hdir2);
29146 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
29147 + struct dentry *d2, struct au_hinode *hdir2);
29149 +int vfsub_create(struct inode *dir, struct path *path, int mode,
29151 +int vfsub_symlink(struct inode *dir, struct path *path,
29152 + const char *symname);
29153 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
29154 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
29155 + struct path *path, struct inode **delegated_inode);
29156 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
29157 + struct inode *hdir, struct path *path,
29158 + struct inode **delegated_inode);
29159 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
29160 +int vfsub_rmdir(struct inode *dir, struct path *path);
29162 +/* ---------------------------------------------------------------------- */
29164 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
29166 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
29168 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
29170 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
29172 +int vfsub_flush(struct file *file, fl_owner_t id);
29173 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
29175 +/* just for type-check */
29176 +static inline filldir_t au_diractor(int (*func)(struct dir_context *,
29177 + const char *, int, loff_t, u64,
29180 + return (filldir_t)func;
29184 +static inline loff_t vfsub_f_size_read(struct file *file)
29186 + return i_size_read(file_inode(file));
29189 +static inline unsigned int vfsub_file_flags(struct file *file)
29191 + unsigned int flags;
29193 + spin_lock(&file->f_lock);
29194 + flags = file->f_flags;
29195 + spin_unlock(&file->f_lock);
29200 +static inline void vfsub_file_accessed(struct file *h_file)
29202 + file_accessed(h_file);
29203 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
29206 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
29207 + struct dentry *h_dentry)
29209 + struct path h_path = {
29210 + .dentry = h_dentry,
29213 + touch_atime(&h_path);
29214 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
29217 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
29220 + return update_time(h_inode, ts, flags);
29221 + /* no vfsub_update_h_iattr() since we don't have struct path */
29224 +long vfsub_splice_to(struct file *in, loff_t *ppos,
29225 + struct pipe_inode_info *pipe, size_t len,
29226 + unsigned int flags);
29227 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
29228 + loff_t *ppos, size_t len, unsigned int flags);
29230 +static inline long vfsub_truncate(struct path *path, loff_t length)
29234 + err = vfs_truncate(path, length);
29239 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
29240 + struct file *h_file);
29241 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
29243 +/* ---------------------------------------------------------------------- */
29245 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
29250 + err = vfs_llseek(file, offset, origin);
29255 +/* ---------------------------------------------------------------------- */
29257 +/* dirty workaround for strict type of fmode_t */
29263 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
29265 + union vfsub_fmu u = {
29269 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
29274 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
29276 + union vfsub_fmu u = {
29283 +/* ---------------------------------------------------------------------- */
29285 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
29286 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
29287 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
29288 + struct inode **delegated_inode);
29289 +int vfsub_notify_change(struct path *path, struct iattr *ia,
29290 + struct inode **delegated_inode);
29291 +int vfsub_unlink(struct inode *dir, struct path *path,
29292 + struct inode **delegated_inode, int force);
29294 +#endif /* __KERNEL__ */
29295 +#endif /* __AUFS_VFSUB_H__ */
29296 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
29297 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
29298 +++ linux/fs/aufs/wbr_policy.c 2014-04-24 22:11:10.861935852 +0200
29301 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29303 + * This program, aufs is free software; you can redistribute it and/or modify
29304 + * it under the terms of the GNU General Public License as published by
29305 + * the Free Software Foundation; either version 2 of the License, or
29306 + * (at your option) any later version.
29308 + * This program is distributed in the hope that it will be useful,
29309 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29310 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29311 + * GNU General Public License for more details.
29313 + * You should have received a copy of the GNU General Public License
29314 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29318 + * policies for selecting one among multiple writable branches
29321 +#include <linux/statfs.h>
29324 +/* subset of cpup_attr() */
29325 +static noinline_for_stack
29326 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
29330 + struct inode *h_isrc;
29332 + h_isrc = h_src->d_inode;
29333 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
29334 + ia.ia_mode = h_isrc->i_mode;
29335 + ia.ia_uid = h_isrc->i_uid;
29336 + ia.ia_gid = h_isrc->i_gid;
29337 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
29338 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
29339 + /* no delegation since it is just created */
29340 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
29342 + /* is this nfs only? */
29343 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
29344 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
29345 + ia.ia_mode = h_isrc->i_mode;
29346 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
29352 +#define AuCpdown_PARENT_OPQ 1
29353 +#define AuCpdown_WHED (1 << 1)
29354 +#define AuCpdown_MADE_DIR (1 << 2)
29355 +#define AuCpdown_DIROPQ (1 << 3)
29356 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
29357 +#define au_fset_cpdown(flags, name) \
29358 + do { (flags) |= AuCpdown_##name; } while (0)
29359 +#define au_fclr_cpdown(flags, name) \
29360 + do { (flags) &= ~AuCpdown_##name; } while (0)
29362 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
29363 + unsigned int *flags)
29366 + struct dentry *opq_dentry;
29368 + opq_dentry = au_diropq_create(dentry, bdst);
29369 + err = PTR_ERR(opq_dentry);
29370 + if (IS_ERR(opq_dentry))
29372 + dput(opq_dentry);
29373 + au_fset_cpdown(*flags, DIROPQ);
29379 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
29380 + struct inode *dir, aufs_bindex_t bdst)
29383 + struct path h_path;
29384 + struct au_branch *br;
29386 + br = au_sbr(dentry->d_sb, bdst);
29387 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
29388 + err = PTR_ERR(h_path.dentry);
29389 + if (IS_ERR(h_path.dentry))
29393 + if (h_path.dentry->d_inode) {
29394 + h_path.mnt = au_br_mnt(br);
29395 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
29398 + dput(h_path.dentry);
29404 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
29405 + struct au_pin *pin,
29406 + struct dentry *h_parent, void *arg)
29409 + aufs_bindex_t bopq, bstart;
29410 + struct path h_path;
29411 + struct dentry *parent;
29412 + struct inode *h_dir, *h_inode, *inode, *dir;
29413 + unsigned int *flags = arg;
29415 + bstart = au_dbstart(dentry);
29416 + /* dentry is di-locked */
29417 + parent = dget_parent(dentry);
29418 + dir = parent->d_inode;
29419 + h_dir = h_parent->d_inode;
29420 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
29421 + IMustLock(h_dir);
29423 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
29424 + if (unlikely(err < 0))
29426 + h_path.dentry = au_h_dptr(dentry, bdst);
29427 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
29428 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
29429 + S_IRWXU | S_IRUGO | S_IXUGO);
29430 + if (unlikely(err))
29432 + au_fset_cpdown(*flags, MADE_DIR);
29434 + bopq = au_dbdiropq(dentry);
29435 + au_fclr_cpdown(*flags, WHED);
29436 + au_fclr_cpdown(*flags, DIROPQ);
29437 + if (au_dbwh(dentry) == bdst)
29438 + au_fset_cpdown(*flags, WHED);
29439 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
29440 + au_fset_cpdown(*flags, PARENT_OPQ);
29441 + h_inode = h_path.dentry->d_inode;
29442 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
29443 + if (au_ftest_cpdown(*flags, WHED)) {
29444 + err = au_cpdown_dir_opq(dentry, bdst, flags);
29445 + if (unlikely(err)) {
29446 + mutex_unlock(&h_inode->i_mutex);
29451 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
29452 + mutex_unlock(&h_inode->i_mutex);
29453 + if (unlikely(err))
29456 + if (au_ftest_cpdown(*flags, WHED)) {
29457 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
29458 + if (unlikely(err))
29462 + inode = dentry->d_inode;
29463 + if (au_ibend(inode) < bdst)
29464 + au_set_ibend(inode, bdst);
29465 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
29466 + au_hi_flags(inode, /*isdir*/1));
29467 + goto out; /* success */
29471 + if (au_ftest_cpdown(*flags, DIROPQ)) {
29472 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
29473 + rerr = au_diropq_remove(dentry, bdst);
29474 + mutex_unlock(&h_inode->i_mutex);
29475 + if (unlikely(rerr)) {
29476 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
29477 + dentry, bdst, rerr);
29483 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
29484 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
29485 + if (unlikely(rerr)) {
29486 + AuIOErr("failed removing %pd b%d (%d)\n",
29487 + dentry, bdst, rerr);
29492 + au_set_h_dptr(dentry, bdst, NULL);
29493 + if (au_dbend(dentry) == bdst)
29494 + au_update_dbend(dentry);
29500 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
29503 + unsigned int flags;
29506 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
29511 +/* ---------------------------------------------------------------------- */
29513 +/* policies for create */
29515 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
29517 + int err, i, j, ndentry;
29518 + aufs_bindex_t bopq;
29519 + struct au_dcsub_pages dpages;
29520 + struct au_dpage *dpage;
29521 + struct dentry **dentries, *parent, *d;
29523 + err = au_dpages_init(&dpages, GFP_NOFS);
29524 + if (unlikely(err))
29526 + parent = dget_parent(dentry);
29527 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
29528 + if (unlikely(err))
29532 + for (i = 0; i < dpages.ndpage; i++) {
29533 + dpage = dpages.dpages + i;
29534 + dentries = dpage->dentries;
29535 + ndentry = dpage->ndentry;
29536 + for (j = 0; j < ndentry; j++) {
29538 + di_read_lock_parent2(d, !AuLock_IR);
29539 + bopq = au_dbdiropq(d);
29540 + di_read_unlock(d, !AuLock_IR);
29541 + if (bopq >= 0 && bopq < err)
29548 + au_dpages_free(&dpages);
29553 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
29555 + for (; bindex >= 0; bindex--)
29556 + if (!au_br_rdonly(au_sbr(sb, bindex)))
29561 +/* top down parent */
29562 +static int au_wbr_create_tdp(struct dentry *dentry,
29563 + unsigned int flags __maybe_unused)
29566 + aufs_bindex_t bstart, bindex;
29567 + struct super_block *sb;
29568 + struct dentry *parent, *h_parent;
29570 + sb = dentry->d_sb;
29571 + bstart = au_dbstart(dentry);
29573 + if (!au_br_rdonly(au_sbr(sb, bstart)))
29577 + parent = dget_parent(dentry);
29578 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
29579 + h_parent = au_h_dptr(parent, bindex);
29580 + if (!h_parent || !h_parent->d_inode)
29583 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
29590 + /* bottom up here */
29591 + if (unlikely(err < 0)) {
29592 + err = au_wbr_bu(sb, bstart - 1);
29594 + err = au_wbr_nonopq(dentry, err);
29598 + AuDbg("b%d\n", err);
29602 +/* ---------------------------------------------------------------------- */
29604 +/* an exception for the policy other than tdp */
29605 +static int au_wbr_create_exp(struct dentry *dentry)
29608 + aufs_bindex_t bwh, bdiropq;
29609 + struct dentry *parent;
29612 + bwh = au_dbwh(dentry);
29613 + parent = dget_parent(dentry);
29614 + bdiropq = au_dbdiropq(parent);
29616 + if (bdiropq >= 0)
29617 + err = min(bdiropq, bwh);
29620 + AuDbg("%d\n", err);
29621 + } else if (bdiropq >= 0) {
29623 + AuDbg("%d\n", err);
29628 + err = au_wbr_nonopq(dentry, err);
29630 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
29633 + AuDbg("%d\n", err);
29637 +/* ---------------------------------------------------------------------- */
29640 +static int au_wbr_create_init_rr(struct super_block *sb)
29644 + err = au_wbr_bu(sb, au_sbend(sb));
29645 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
29648 + AuDbg("b%d\n", err);
29652 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
29656 + aufs_bindex_t bindex, bend;
29657 + struct super_block *sb;
29660 + err = au_wbr_create_exp(dentry);
29664 + sb = dentry->d_sb;
29665 + next = &au_sbi(sb)->si_wbr_rr_next;
29666 + bend = au_sbend(sb);
29668 + for (bindex = 0; bindex <= bend; bindex++) {
29669 + if (!au_ftest_wbr(flags, DIR)) {
29670 + err = atomic_dec_return(next) + 1;
29671 + /* modulo for 0 is meaningless */
29672 + if (unlikely(!err))
29673 + err = atomic_dec_return(next) + 1;
29675 + err = atomic_read(next);
29676 + AuDbg("%d\n", err);
29679 + AuDbg("%d\n", err);
29680 + if (!au_br_rdonly(au_sbr(sb, err)))
29686 + err = au_wbr_nonopq(dentry, err);
29689 + AuDbg("%d\n", err);
29693 +/* ---------------------------------------------------------------------- */
29695 +/* most free space */
29696 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
29698 + struct super_block *sb;
29699 + struct au_branch *br;
29700 + struct au_wbr_mfs *mfs;
29701 + struct dentry *h_parent;
29702 + aufs_bindex_t bindex, bend;
29704 + unsigned long long b, bavail;
29705 + struct path h_path;
29706 + /* reduce the stack usage */
29707 + struct kstatfs *st;
29709 + st = kmalloc(sizeof(*st), GFP_NOFS);
29710 + if (unlikely(!st)) {
29711 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
29716 + sb = dentry->d_sb;
29717 + mfs = &au_sbi(sb)->si_wbr_mfs;
29718 + MtxMustLock(&mfs->mfs_lock);
29719 + mfs->mfs_bindex = -EROFS;
29720 + mfs->mfsrr_bytes = 0;
29723 + bend = au_sbend(sb);
29725 + bindex = au_dbstart(parent);
29726 + bend = au_dbtaildir(parent);
29729 + for (; bindex <= bend; bindex++) {
29731 + h_parent = au_h_dptr(parent, bindex);
29732 + if (!h_parent || !h_parent->d_inode)
29735 + br = au_sbr(sb, bindex);
29736 + if (au_br_rdonly(br))
29739 + /* sb->s_root for NFS is unreliable */
29740 + h_path.mnt = au_br_mnt(br);
29741 + h_path.dentry = h_path.mnt->mnt_root;
29742 + err = vfs_statfs(&h_path, st);
29743 + if (unlikely(err)) {
29744 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
29748 + /* when the available size is equal, select the lower one */
29749 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
29750 + || sizeof(b) < sizeof(st->f_bsize));
29751 + b = st->f_bavail * st->f_bsize;
29752 + br->br_wbr->wbr_bytes = b;
29753 + if (b >= bavail) {
29755 + mfs->mfs_bindex = bindex;
29756 + mfs->mfs_jiffy = jiffies;
29760 + mfs->mfsrr_bytes = bavail;
29761 + AuDbg("b%d\n", mfs->mfs_bindex);
29765 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
29768 + struct dentry *parent;
29769 + struct super_block *sb;
29770 + struct au_wbr_mfs *mfs;
29772 + err = au_wbr_create_exp(dentry);
29776 + sb = dentry->d_sb;
29778 + if (au_ftest_wbr(flags, PARENT))
29779 + parent = dget_parent(dentry);
29780 + mfs = &au_sbi(sb)->si_wbr_mfs;
29781 + mutex_lock(&mfs->mfs_lock);
29782 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
29783 + || mfs->mfs_bindex < 0
29784 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
29785 + au_mfs(dentry, parent);
29786 + mutex_unlock(&mfs->mfs_lock);
29787 + err = mfs->mfs_bindex;
29791 + err = au_wbr_nonopq(dentry, err);
29794 + AuDbg("b%d\n", err);
29798 +static int au_wbr_create_init_mfs(struct super_block *sb)
29800 + struct au_wbr_mfs *mfs;
29802 + mfs = &au_sbi(sb)->si_wbr_mfs;
29803 + mutex_init(&mfs->mfs_lock);
29804 + mfs->mfs_jiffy = 0;
29805 + mfs->mfs_bindex = -EROFS;
29810 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
29812 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
29816 +/* ---------------------------------------------------------------------- */
29818 +/* most free space and then round robin */
29819 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
29822 + struct au_wbr_mfs *mfs;
29824 + err = au_wbr_create_mfs(dentry, flags);
29826 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
29827 + mutex_lock(&mfs->mfs_lock);
29828 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
29829 + err = au_wbr_create_rr(dentry, flags);
29830 + mutex_unlock(&mfs->mfs_lock);
29833 + AuDbg("b%d\n", err);
29837 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
29841 + au_wbr_create_init_mfs(sb); /* ignore */
29842 + err = au_wbr_create_init_rr(sb);
29847 +/* ---------------------------------------------------------------------- */
29849 +/* top down parent and most free space */
29850 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
29853 + unsigned long long b;
29854 + aufs_bindex_t bindex, bstart, bend;
29855 + struct super_block *sb;
29856 + struct dentry *parent, *h_parent;
29857 + struct au_branch *br;
29859 + err = au_wbr_create_tdp(dentry, flags);
29860 + if (unlikely(err < 0))
29862 + parent = dget_parent(dentry);
29863 + bstart = au_dbstart(parent);
29864 + bend = au_dbtaildir(parent);
29865 + if (bstart == bend)
29866 + goto out_parent; /* success */
29868 + e2 = au_wbr_create_mfs(dentry, flags);
29870 + goto out_parent; /* success */
29872 + /* when the available size is equal, select upper one */
29873 + sb = dentry->d_sb;
29874 + br = au_sbr(sb, err);
29875 + b = br->br_wbr->wbr_bytes;
29876 + AuDbg("b%d, %llu\n", err, b);
29878 + for (bindex = bstart; bindex <= bend; bindex++) {
29879 + h_parent = au_h_dptr(parent, bindex);
29880 + if (!h_parent || !h_parent->d_inode)
29883 + br = au_sbr(sb, bindex);
29884 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
29885 + b = br->br_wbr->wbr_bytes;
29887 + AuDbg("b%d, %llu\n", err, b);
29892 + err = au_wbr_nonopq(dentry, err);
29897 + AuDbg("b%d\n", err);
29901 +/* ---------------------------------------------------------------------- */
29904 + * - top down parent
29905 + * - most free space with parent
29906 + * - most free space round-robin regardless parent
29908 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
29911 + unsigned long long watermark;
29912 + struct super_block *sb;
29913 + struct au_branch *br;
29914 + struct au_wbr_mfs *mfs;
29916 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
29917 + if (unlikely(err < 0))
29920 + sb = dentry->d_sb;
29921 + br = au_sbr(sb, err);
29922 + mfs = &au_sbi(sb)->si_wbr_mfs;
29923 + mutex_lock(&mfs->mfs_lock);
29924 + watermark = mfs->mfsrr_watermark;
29925 + mutex_unlock(&mfs->mfs_lock);
29926 + if (br->br_wbr->wbr_bytes < watermark)
29927 + /* regardless the parent dir */
29928 + err = au_wbr_create_mfsrr(dentry, flags);
29931 + AuDbg("b%d\n", err);
29935 +/* ---------------------------------------------------------------------- */
29937 +/* policies for copyup */
29939 +/* top down parent */
29940 +static int au_wbr_copyup_tdp(struct dentry *dentry)
29942 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
29945 +/* bottom up parent */
29946 +static int au_wbr_copyup_bup(struct dentry *dentry)
29949 + aufs_bindex_t bindex, bstart;
29950 + struct dentry *parent, *h_parent;
29951 + struct super_block *sb;
29954 + sb = dentry->d_sb;
29955 + parent = dget_parent(dentry);
29956 + bstart = au_dbstart(parent);
29957 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
29958 + h_parent = au_h_dptr(parent, bindex);
29959 + if (!h_parent || !h_parent->d_inode)
29962 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
29969 + /* bottom up here */
29970 + if (unlikely(err < 0))
29971 + err = au_wbr_bu(sb, bstart - 1);
29973 + AuDbg("b%d\n", err);
29978 +static int au_wbr_copyup_bu(struct dentry *dentry)
29981 + aufs_bindex_t bstart;
29983 + bstart = au_dbstart(dentry);
29984 + err = au_wbr_bu(dentry->d_sb, bstart);
29985 + AuDbg("b%d\n", err);
29986 + if (err > bstart)
29987 + err = au_wbr_nonopq(dentry, err);
29989 + AuDbg("b%d\n", err);
29993 +/* ---------------------------------------------------------------------- */
29995 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
29996 + [AuWbrCopyup_TDP] = {
29997 + .copyup = au_wbr_copyup_tdp
29999 + [AuWbrCopyup_BUP] = {
30000 + .copyup = au_wbr_copyup_bup
30002 + [AuWbrCopyup_BU] = {
30003 + .copyup = au_wbr_copyup_bu
30007 +struct au_wbr_create_operations au_wbr_create_ops[] = {
30008 + [AuWbrCreate_TDP] = {
30009 + .create = au_wbr_create_tdp
30011 + [AuWbrCreate_RR] = {
30012 + .create = au_wbr_create_rr,
30013 + .init = au_wbr_create_init_rr
30015 + [AuWbrCreate_MFS] = {
30016 + .create = au_wbr_create_mfs,
30017 + .init = au_wbr_create_init_mfs,
30018 + .fin = au_wbr_create_fin_mfs
30020 + [AuWbrCreate_MFSV] = {
30021 + .create = au_wbr_create_mfs,
30022 + .init = au_wbr_create_init_mfs,
30023 + .fin = au_wbr_create_fin_mfs
30025 + [AuWbrCreate_MFSRR] = {
30026 + .create = au_wbr_create_mfsrr,
30027 + .init = au_wbr_create_init_mfsrr,
30028 + .fin = au_wbr_create_fin_mfs
30030 + [AuWbrCreate_MFSRRV] = {
30031 + .create = au_wbr_create_mfsrr,
30032 + .init = au_wbr_create_init_mfsrr,
30033 + .fin = au_wbr_create_fin_mfs
30035 + [AuWbrCreate_PMFS] = {
30036 + .create = au_wbr_create_pmfs,
30037 + .init = au_wbr_create_init_mfs,
30038 + .fin = au_wbr_create_fin_mfs
30040 + [AuWbrCreate_PMFSV] = {
30041 + .create = au_wbr_create_pmfs,
30042 + .init = au_wbr_create_init_mfs,
30043 + .fin = au_wbr_create_fin_mfs
30045 + [AuWbrCreate_PMFSRR] = {
30046 + .create = au_wbr_create_pmfsrr,
30047 + .init = au_wbr_create_init_mfsrr,
30048 + .fin = au_wbr_create_fin_mfs
30050 + [AuWbrCreate_PMFSRRV] = {
30051 + .create = au_wbr_create_pmfsrr,
30052 + .init = au_wbr_create_init_mfsrr,
30053 + .fin = au_wbr_create_fin_mfs
30056 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
30057 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
30058 +++ linux/fs/aufs/whout.c 2014-04-24 22:11:10.861935852 +0200
30061 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30063 + * This program, aufs is free software; you can redistribute it and/or modify
30064 + * it under the terms of the GNU General Public License as published by
30065 + * the Free Software Foundation; either version 2 of the License, or
30066 + * (at your option) any later version.
30068 + * This program is distributed in the hope that it will be useful,
30069 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30070 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30071 + * GNU General Public License for more details.
30073 + * You should have received a copy of the GNU General Public License
30074 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30078 + * whiteout for logical deletion and opaque directory
30083 +#define WH_MASK S_IRUGO
30086 + * If a directory contains this file, then it is opaque. We start with the
30087 + * .wh. flag so that it is blocked by lookup.
30089 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
30090 + sizeof(AUFS_WH_DIROPQ) - 1);
30093 + * generate whiteout name, which is NOT terminated by NULL.
30094 + * @name: original d_name.name
30095 + * @len: original d_name.len
30096 + * @wh: whiteout qstr
30097 + * returns zero when succeeds, otherwise error.
30098 + * succeeded value as wh->name should be freed by kfree().
30100 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
30104 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
30105 + return -ENAMETOOLONG;
30107 + wh->len = name->len + AUFS_WH_PFX_LEN;
30108 + p = kmalloc(wh->len, GFP_NOFS);
30111 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30112 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
30119 +/* ---------------------------------------------------------------------- */
30122 + * test if the @wh_name exists under @h_parent.
30123 + * @try_sio specifies the necessary of super-io.
30125 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
30126 + struct au_branch *br, int try_sio)
30129 + struct dentry *wh_dentry;
30132 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
30134 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
30135 + err = PTR_ERR(wh_dentry);
30136 + if (IS_ERR(wh_dentry))
30140 + if (!wh_dentry->d_inode)
30141 + goto out_wh; /* success */
30144 + if (S_ISREG(wh_dentry->d_inode->i_mode))
30145 + goto out_wh; /* success */
30148 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
30149 + wh_dentry, wh_dentry->d_inode->i_mode);
30158 + * test if the @h_dentry sets opaque or not.
30160 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
30163 + struct inode *h_dir;
30165 + h_dir = h_dentry->d_inode;
30166 + err = au_wh_test(h_dentry, &diropq_name, br,
30167 + au_test_h_perm_sio(h_dir, MAY_EXEC));
30172 + * returns a negative dentry whose name is unique and temporary.
30174 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
30175 + struct qstr *prefix)
30177 + struct dentry *dentry;
30179 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
30181 + /* strict atomic_t is unnecessary here */
30182 + static unsigned short cnt;
30185 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
30188 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
30189 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
30190 + dentry = ERR_PTR(-ENAMETOOLONG);
30191 + if (unlikely(qs.len > NAME_MAX))
30193 + dentry = ERR_PTR(-ENOMEM);
30194 + name = kmalloc(qs.len + 1, GFP_NOFS);
30195 + if (unlikely(!name))
30199 + /* doubly whiteout-ed */
30200 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
30201 + p = name + AUFS_WH_PFX_LEN * 2;
30202 + memcpy(p, prefix->name, prefix->len);
30203 + p += prefix->len;
30205 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
30208 + for (i = 0; i < 3; i++) {
30209 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
30210 + dentry = au_sio_lkup_one(&qs, h_parent, br);
30211 + if (IS_ERR(dentry) || !dentry->d_inode)
30215 + /* pr_warn("could not get random name\n"); */
30216 + dentry = ERR_PTR(-EEXIST);
30217 + AuDbg("%.*s\n", AuLNPair(&qs));
30221 + if (name != defname)
30224 + AuTraceErrPtr(dentry);
30229 + * rename the @h_dentry on @br to the whiteouted temporary name.
30231 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
30234 + struct path h_path = {
30235 + .mnt = au_br_mnt(br)
30237 + struct inode *h_dir, *delegated;
30238 + struct dentry *h_parent;
30240 + h_parent = h_dentry->d_parent; /* dir inode is locked */
30241 + h_dir = h_parent->d_inode;
30242 + IMustLock(h_dir);
30244 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
30245 + err = PTR_ERR(h_path.dentry);
30246 + if (IS_ERR(h_path.dentry))
30249 + /* under the same dir, no need to lock_rename() */
30250 + delegated = NULL;
30251 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
30253 + if (unlikely(err == -EWOULDBLOCK)) {
30254 + pr_warn("cannot retry for NFSv4 delegation"
30255 + " for an internal rename\n");
30258 + dput(h_path.dentry);
30265 +/* ---------------------------------------------------------------------- */
30267 + * functions for removing a whiteout
30270 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
30273 + struct inode *delegated;
30276 + * forces superio when the dir has a sticky bit.
30277 + * this may be a violation of unix fs semantics.
30279 + force = (h_dir->i_mode & S_ISVTX)
30280 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
30281 + delegated = NULL;
30282 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
30283 + if (unlikely(err == -EWOULDBLOCK)) {
30284 + pr_warn("cannot retry for NFSv4 delegation"
30285 + " for an internal unlink\n");
30291 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
30292 + struct dentry *dentry)
30296 + err = do_unlink_wh(h_dir, h_path);
30297 + if (!err && dentry)
30298 + au_set_dbwh(dentry, -1);
30303 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
30304 + struct au_branch *br)
30307 + struct path h_path = {
30308 + .mnt = au_br_mnt(br)
30312 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
30313 + if (IS_ERR(h_path.dentry))
30314 + err = PTR_ERR(h_path.dentry);
30316 + if (h_path.dentry->d_inode
30317 + && S_ISREG(h_path.dentry->d_inode->i_mode))
30318 + err = do_unlink_wh(h_parent->d_inode, &h_path);
30319 + dput(h_path.dentry);
30325 +/* ---------------------------------------------------------------------- */
30327 + * initialize/clean whiteout for a branch
30330 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
30334 + struct inode *delegated;
30336 + if (!whpath->dentry->d_inode)
30340 + err = vfsub_rmdir(h_dir, whpath);
30342 + delegated = NULL;
30343 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
30344 + if (unlikely(err == -EWOULDBLOCK)) {
30345 + pr_warn("cannot retry for NFSv4 delegation"
30346 + " for an internal unlink\n");
30350 + if (unlikely(err))
30351 + pr_warn("failed removing %pd (%d), ignored.\n",
30352 + whpath->dentry, err);
30355 +static int test_linkable(struct dentry *h_root)
30357 + struct inode *h_dir = h_root->d_inode;
30359 + if (h_dir->i_op->link)
30362 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
30363 + h_root, au_sbtype(h_root->d_sb));
30367 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
30368 +static int au_whdir(struct inode *h_dir, struct path *path)
30373 + if (!path->dentry->d_inode) {
30374 + int mode = S_IRWXU;
30376 + if (au_test_nfs(path->dentry->d_sb))
30378 + err = vfsub_mkdir(h_dir, path, mode);
30379 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
30382 + pr_err("unknown %pd exists\n", path->dentry);
30387 +struct au_wh_base {
30388 + const struct qstr *name;
30389 + struct dentry *dentry;
30392 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
30393 + struct path *h_path)
30395 + h_path->dentry = base[AuBrWh_BASE].dentry;
30396 + au_wh_clean(h_dir, h_path, /*isdir*/0);
30397 + h_path->dentry = base[AuBrWh_PLINK].dentry;
30398 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30399 + h_path->dentry = base[AuBrWh_ORPH].dentry;
30400 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30404 + * returns tri-state,
30405 + * minus: error, caller should print the mesage
30407 + * plus: error, caller should NOT print the mesage
30409 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
30410 + int do_plink, struct au_wh_base base[],
30411 + struct path *h_path)
30414 + struct inode *h_dir;
30416 + h_dir = h_root->d_inode;
30417 + h_path->dentry = base[AuBrWh_BASE].dentry;
30418 + au_wh_clean(h_dir, h_path, /*isdir*/0);
30419 + h_path->dentry = base[AuBrWh_PLINK].dentry;
30421 + err = test_linkable(h_root);
30422 + if (unlikely(err)) {
30427 + err = au_whdir(h_dir, h_path);
30428 + if (unlikely(err))
30430 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
30432 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30433 + h_path->dentry = base[AuBrWh_ORPH].dentry;
30434 + err = au_whdir(h_dir, h_path);
30435 + if (unlikely(err))
30437 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
30444 + * for the moment, aufs supports the branch filesystem which does not support
30445 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
30446 + * copyup failed. finally, such filesystem will not be used as the writable
30449 + * returns tri-state, see above.
30451 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
30452 + int do_plink, struct au_wh_base base[],
30453 + struct path *h_path)
30456 + struct inode *h_dir;
30458 + WbrWhMustWriteLock(wbr);
30460 + err = test_linkable(h_root);
30461 + if (unlikely(err)) {
30467 + * todo: should this create be done in /sbin/mount.aufs helper?
30470 + h_dir = h_root->d_inode;
30471 + if (!base[AuBrWh_BASE].dentry->d_inode) {
30472 + h_path->dentry = base[AuBrWh_BASE].dentry;
30473 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
30474 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
30477 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
30478 + if (unlikely(err))
30481 + h_path->dentry = base[AuBrWh_PLINK].dentry;
30483 + err = au_whdir(h_dir, h_path);
30484 + if (unlikely(err))
30486 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
30488 + au_wh_clean(h_dir, h_path, /*isdir*/1);
30489 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
30491 + h_path->dentry = base[AuBrWh_ORPH].dentry;
30492 + err = au_whdir(h_dir, h_path);
30493 + if (unlikely(err))
30495 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
30502 + * initialize the whiteout base file/dir for @br.
30504 +int au_wh_init(struct au_branch *br, struct super_block *sb)
30507 + const unsigned char do_plink
30508 + = !!au_opt_test(au_mntflags(sb), PLINK);
30509 + struct inode *h_dir;
30510 + struct path path = br->br_path;
30511 + struct dentry *h_root = path.dentry;
30512 + struct au_wbr *wbr = br->br_wbr;
30513 + static const struct qstr base_name[] = {
30514 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
30515 + sizeof(AUFS_BASE_NAME) - 1),
30516 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
30517 + sizeof(AUFS_PLINKDIR_NAME) - 1),
30518 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
30519 + sizeof(AUFS_ORPHDIR_NAME) - 1)
30521 + struct au_wh_base base[] = {
30522 + [AuBrWh_BASE] = {
30523 + .name = base_name + AuBrWh_BASE,
30526 + [AuBrWh_PLINK] = {
30527 + .name = base_name + AuBrWh_PLINK,
30530 + [AuBrWh_ORPH] = {
30531 + .name = base_name + AuBrWh_ORPH,
30537 + WbrWhMustWriteLock(wbr);
30539 + for (i = 0; i < AuBrWh_Last; i++) {
30540 + /* doubly whiteouted */
30541 + struct dentry *d;
30543 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
30544 + err = PTR_ERR(d);
30548 + base[i].dentry = d;
30550 + && wbr->wbr_wh[i]
30551 + && wbr->wbr_wh[i] != base[i].dentry);
30555 + for (i = 0; i < AuBrWh_Last; i++) {
30556 + dput(wbr->wbr_wh[i]);
30557 + wbr->wbr_wh[i] = NULL;
30561 + if (!au_br_writable(br->br_perm)) {
30562 + h_dir = h_root->d_inode;
30563 + au_wh_init_ro(h_dir, base, &path);
30564 + } else if (!au_br_wh_linkable(br->br_perm)) {
30565 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
30571 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
30577 + goto out; /* success */
30580 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
30581 + err, h_root, au_sbtype(h_root->d_sb));
30583 + for (i = 0; i < AuBrWh_Last; i++)
30584 + dput(base[i].dentry);
30588 +/* ---------------------------------------------------------------------- */
30590 + * whiteouts are all hard-linked usually.
30591 + * when its link count reaches a ceiling, we create a new whiteout base
30592 + * asynchronously.
30595 +struct reinit_br_wh {
30596 + struct super_block *sb;
30597 + struct au_branch *br;
30600 +static void reinit_br_wh(void *arg)
30603 + aufs_bindex_t bindex;
30604 + struct path h_path;
30605 + struct reinit_br_wh *a = arg;
30606 + struct au_wbr *wbr;
30607 + struct inode *dir, *delegated;
30608 + struct dentry *h_root;
30609 + struct au_hinode *hdir;
30612 + wbr = a->br->br_wbr;
30613 + /* big aufs lock */
30614 + si_noflush_write_lock(a->sb);
30615 + if (!au_br_writable(a->br->br_perm))
30617 + bindex = au_br_index(a->sb, a->br->br_id);
30618 + if (unlikely(bindex < 0))
30621 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
30622 + dir = a->sb->s_root->d_inode;
30623 + hdir = au_hi(dir, bindex);
30624 + h_root = au_h_dptr(a->sb->s_root, bindex);
30625 + AuDebugOn(h_root != au_br_dentry(a->br));
30627 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
30628 + wbr_wh_write_lock(wbr);
30629 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
30632 + h_path.dentry = wbr->wbr_whbase;
30633 + h_path.mnt = au_br_mnt(a->br);
30634 + delegated = NULL;
30635 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
30637 + if (unlikely(err == -EWOULDBLOCK)) {
30638 + pr_warn("cannot retry for NFSv4 delegation"
30639 + " for an internal unlink\n");
30643 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
30646 + dput(wbr->wbr_whbase);
30647 + wbr->wbr_whbase = NULL;
30649 + err = au_wh_init(a->br, a->sb);
30650 + wbr_wh_write_unlock(wbr);
30651 + au_hn_imtx_unlock(hdir);
30652 + di_read_unlock(a->sb->s_root, AuLock_IR);
30656 + atomic_dec(&wbr->wbr_wh_running);
30657 + atomic_dec(&a->br->br_count);
30658 + si_write_unlock(a->sb);
30659 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
30661 + if (unlikely(err))
30662 + AuIOErr("err %d\n", err);
30665 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
30667 + int do_dec, wkq_err;
30668 + struct reinit_br_wh *arg;
30671 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
30674 + /* ignore ENOMEM */
30675 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
30678 + * dec(wh_running), kfree(arg) and dec(br_count)
30679 + * in reinit function
30683 + atomic_inc(&br->br_count);
30684 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
30685 + if (unlikely(wkq_err)) {
30686 + atomic_dec(&br->br_wbr->wbr_wh_running);
30687 + atomic_dec(&br->br_count);
30695 + atomic_dec(&br->br_wbr->wbr_wh_running);
30698 +/* ---------------------------------------------------------------------- */
30701 + * create the whiteout @wh.
30703 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
30704 + struct dentry *wh)
30707 + struct path h_path = {
30710 + struct au_branch *br;
30711 + struct au_wbr *wbr;
30712 + struct dentry *h_parent;
30713 + struct inode *h_dir, *delegated;
30715 + h_parent = wh->d_parent; /* dir inode is locked */
30716 + h_dir = h_parent->d_inode;
30717 + IMustLock(h_dir);
30719 + br = au_sbr(sb, bindex);
30720 + h_path.mnt = au_br_mnt(br);
30721 + wbr = br->br_wbr;
30722 + wbr_wh_read_lock(wbr);
30723 + if (wbr->wbr_whbase) {
30724 + delegated = NULL;
30725 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
30726 + if (unlikely(err == -EWOULDBLOCK)) {
30727 + pr_warn("cannot retry for NFSv4 delegation"
30728 + " for an internal link\n");
30731 + if (!err || err != -EMLINK)
30734 + /* link count full. re-initialize br_whbase. */
30735 + kick_reinit_br_wh(sb, br);
30738 + /* return this error in this context */
30739 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
30742 + wbr_wh_read_unlock(wbr);
30746 +/* ---------------------------------------------------------------------- */
30749 + * create or remove the diropq.
30751 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
30752 + unsigned int flags)
30754 + struct dentry *opq_dentry, *h_dentry;
30755 + struct super_block *sb;
30756 + struct au_branch *br;
30759 + sb = dentry->d_sb;
30760 + br = au_sbr(sb, bindex);
30761 + h_dentry = au_h_dptr(dentry, bindex);
30762 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
30763 + if (IS_ERR(opq_dentry))
30766 + if (au_ftest_diropq(flags, CREATE)) {
30767 + err = link_or_create_wh(sb, bindex, opq_dentry);
30769 + au_set_dbdiropq(dentry, bindex);
30770 + goto out; /* success */
30773 + struct path tmp = {
30774 + .dentry = opq_dentry,
30775 + .mnt = au_br_mnt(br)
30777 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
30779 + au_set_dbdiropq(dentry, -1);
30781 + dput(opq_dentry);
30782 + opq_dentry = ERR_PTR(err);
30785 + return opq_dentry;
30788 +struct do_diropq_args {
30789 + struct dentry **errp;
30790 + struct dentry *dentry;
30791 + aufs_bindex_t bindex;
30792 + unsigned int flags;
30795 +static void call_do_diropq(void *args)
30797 + struct do_diropq_args *a = args;
30798 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
30801 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
30802 + unsigned int flags)
30804 + struct dentry *diropq, *h_dentry;
30806 + h_dentry = au_h_dptr(dentry, bindex);
30807 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
30808 + diropq = do_diropq(dentry, bindex, flags);
30811 + struct do_diropq_args args = {
30813 + .dentry = dentry,
30814 + .bindex = bindex,
30818 + wkq_err = au_wkq_wait(call_do_diropq, &args);
30819 + if (unlikely(wkq_err))
30820 + diropq = ERR_PTR(wkq_err);
30826 +/* ---------------------------------------------------------------------- */
30829 + * lookup whiteout dentry.
30830 + * @h_parent: lower parent dentry which must exist and be locked
30831 + * @base_name: name of dentry which will be whiteouted
30832 + * returns dentry for whiteout.
30834 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
30835 + struct au_branch *br)
30838 + struct qstr wh_name;
30839 + struct dentry *wh_dentry;
30841 + err = au_wh_name_alloc(&wh_name, base_name);
30842 + wh_dentry = ERR_PTR(err);
30844 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
30845 + kfree(wh_name.name);
30847 + return wh_dentry;
30851 + * link/create a whiteout for @dentry on @bindex.
30853 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
30854 + struct dentry *h_parent)
30856 + struct dentry *wh_dentry;
30857 + struct super_block *sb;
30860 + sb = dentry->d_sb;
30861 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
30862 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
30863 + err = link_or_create_wh(sb, bindex, wh_dentry);
30865 + au_set_dbwh(dentry, bindex);
30868 + wh_dentry = ERR_PTR(err);
30872 + return wh_dentry;
30875 +/* ---------------------------------------------------------------------- */
30877 +/* Delete all whiteouts in this directory on branch bindex. */
30878 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
30879 + aufs_bindex_t bindex, struct au_branch *br)
30882 + unsigned long ul, n;
30883 + struct qstr wh_name;
30885 + struct hlist_head *head;
30886 + struct au_vdir_wh *pos;
30887 + struct au_vdir_destr *str;
30890 + p = (void *)__get_free_page(GFP_NOFS);
30891 + wh_name.name = p;
30892 + if (unlikely(!wh_name.name))
30896 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30897 + p += AUFS_WH_PFX_LEN;
30898 + n = whlist->nh_num;
30899 + head = whlist->nh_head;
30900 + for (ul = 0; !err && ul < n; ul++, head++) {
30901 + hlist_for_each_entry(pos, head, wh_hash) {
30902 + if (pos->wh_bindex != bindex)
30905 + str = &pos->wh_str;
30906 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
30907 + memcpy(p, str->name, str->len);
30908 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
30909 + err = unlink_wh_name(h_dentry, &wh_name, br);
30914 + AuIOErr("whiteout name too long %.*s\n",
30915 + str->len, str->name);
30920 + free_page((unsigned long)wh_name.name);
30926 +struct del_wh_children_args {
30928 + struct dentry *h_dentry;
30929 + struct au_nhash *whlist;
30930 + aufs_bindex_t bindex;
30931 + struct au_branch *br;
30934 +static void call_del_wh_children(void *args)
30936 + struct del_wh_children_args *a = args;
30937 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
30940 +/* ---------------------------------------------------------------------- */
30942 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
30944 + struct au_whtmp_rmdir *whtmp;
30946 + unsigned int rdhash;
30948 + SiMustAnyLock(sb);
30950 + whtmp = kmalloc(sizeof(*whtmp), gfp);
30951 + if (unlikely(!whtmp)) {
30952 + whtmp = ERR_PTR(-ENOMEM);
30956 + whtmp->dir = NULL;
30957 + whtmp->br = NULL;
30958 + whtmp->wh_dentry = NULL;
30959 + /* no estimation for dir size */
30960 + rdhash = au_sbi(sb)->si_rdhash;
30962 + rdhash = AUFS_RDHASH_DEF;
30963 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
30964 + if (unlikely(err)) {
30966 + whtmp = ERR_PTR(err);
30973 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
30976 + atomic_dec(&whtmp->br->br_count);
30977 + dput(whtmp->wh_dentry);
30978 + iput(whtmp->dir);
30979 + au_nhash_wh_free(&whtmp->whlist);
30984 + * rmdir the whiteouted temporary named dir @h_dentry.
30985 + * @whlist: whiteouted children.
30987 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
30988 + struct dentry *wh_dentry, struct au_nhash *whlist)
30991 + struct path h_tmp;
30992 + struct inode *wh_inode, *h_dir;
30993 + struct au_branch *br;
30995 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
30996 + IMustLock(h_dir);
30998 + br = au_sbr(dir->i_sb, bindex);
30999 + wh_inode = wh_dentry->d_inode;
31000 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
31003 + * someone else might change some whiteouts while we were sleeping.
31004 + * it means this whlist may have an obsoleted entry.
31006 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
31007 + err = del_wh_children(wh_dentry, whlist, bindex, br);
31010 + struct del_wh_children_args args = {
31012 + .h_dentry = wh_dentry,
31013 + .whlist = whlist,
31014 + .bindex = bindex,
31018 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
31019 + if (unlikely(wkq_err))
31022 + mutex_unlock(&wh_inode->i_mutex);
31025 + h_tmp.dentry = wh_dentry;
31026 + h_tmp.mnt = au_br_mnt(br);
31027 + err = vfsub_rmdir(h_dir, &h_tmp);
31031 + if (au_ibstart(dir) == bindex) {
31032 + /* todo: dir->i_mutex is necessary */
31033 + au_cpup_attr_timesizes(dir);
31034 + vfsub_drop_nlink(dir);
31036 + return 0; /* success */
31039 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
31043 +static void call_rmdir_whtmp(void *args)
31046 + aufs_bindex_t bindex;
31047 + struct au_whtmp_rmdir *a = args;
31048 + struct super_block *sb;
31049 + struct dentry *h_parent;
31050 + struct inode *h_dir;
31051 + struct au_hinode *hdir;
31053 + /* rmdir by nfsd may cause deadlock with this i_mutex */
31054 + /* mutex_lock(&a->dir->i_mutex); */
31056 + sb = a->dir->i_sb;
31057 + si_read_lock(sb, !AuLock_FLUSH);
31058 + if (!au_br_writable(a->br->br_perm))
31060 + bindex = au_br_index(sb, a->br->br_id);
31061 + if (unlikely(bindex < 0))
31065 + ii_write_lock_parent(a->dir);
31066 + h_parent = dget_parent(a->wh_dentry);
31067 + h_dir = h_parent->d_inode;
31068 + hdir = au_hi(a->dir, bindex);
31069 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
31070 + if (unlikely(err))
31072 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
31073 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
31076 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
31077 + au_hn_imtx_unlock(hdir);
31078 + vfsub_mnt_drop_write(au_br_mnt(a->br));
31082 + ii_write_unlock(a->dir);
31084 + /* mutex_unlock(&a->dir->i_mutex); */
31085 + au_whtmp_rmdir_free(a);
31086 + si_read_unlock(sb);
31087 + au_nwt_done(&au_sbi(sb)->si_nowait);
31088 + if (unlikely(err))
31089 + AuIOErr("err %d\n", err);
31092 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
31093 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
31096 + struct super_block *sb;
31100 + /* all post-process will be done in do_rmdir_whtmp(). */
31102 + args->dir = au_igrab(dir);
31103 + args->br = au_sbr(sb, bindex);
31104 + atomic_inc(&args->br->br_count);
31105 + args->wh_dentry = dget(wh_dentry);
31106 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
31107 + if (unlikely(wkq_err)) {
31108 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
31109 + au_whtmp_rmdir_free(args);
31112 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
31113 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
31114 +++ linux/fs/aufs/whout.h 2014-04-24 22:11:10.861935852 +0200
31117 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31119 + * This program, aufs is free software; you can redistribute it and/or modify
31120 + * it under the terms of the GNU General Public License as published by
31121 + * the Free Software Foundation; either version 2 of the License, or
31122 + * (at your option) any later version.
31124 + * This program is distributed in the hope that it will be useful,
31125 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31126 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31127 + * GNU General Public License for more details.
31129 + * You should have received a copy of the GNU General Public License
31130 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31134 + * whiteout for logical deletion and opaque directory
31137 +#ifndef __AUFS_WHOUT_H__
31138 +#define __AUFS_WHOUT_H__
31145 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
31147 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
31148 + struct au_branch *br, int try_sio);
31149 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
31150 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31151 + struct qstr *prefix);
31152 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
31153 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
31154 + struct dentry *dentry);
31155 +int au_wh_init(struct au_branch *br, struct super_block *sb);
31157 +/* diropq flags */
31158 +#define AuDiropq_CREATE 1
31159 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
31160 +#define au_fset_diropq(flags, name) \
31161 + do { (flags) |= AuDiropq_##name; } while (0)
31162 +#define au_fclr_diropq(flags, name) \
31163 + do { (flags) &= ~AuDiropq_##name; } while (0)
31165 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
31166 + unsigned int flags);
31167 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
31168 + struct au_branch *br);
31169 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
31170 + struct dentry *h_parent);
31172 +/* real rmdir for the whiteout-ed dir */
31173 +struct au_whtmp_rmdir {
31174 + struct inode *dir;
31175 + struct au_branch *br;
31176 + struct dentry *wh_dentry;
31177 + struct au_nhash whlist;
31180 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
31181 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
31182 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
31183 + struct dentry *wh_dentry, struct au_nhash *whlist);
31184 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
31185 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
31187 +/* ---------------------------------------------------------------------- */
31189 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
31190 + aufs_bindex_t bindex)
31192 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
31195 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
31197 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
31200 +#endif /* __KERNEL__ */
31201 +#endif /* __AUFS_WHOUT_H__ */
31202 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
31203 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
31204 +++ linux/fs/aufs/wkq.c 2014-04-24 22:11:10.861935852 +0200
31207 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31209 + * This program, aufs is free software; you can redistribute it and/or modify
31210 + * it under the terms of the GNU General Public License as published by
31211 + * the Free Software Foundation; either version 2 of the License, or
31212 + * (at your option) any later version.
31214 + * This program is distributed in the hope that it will be useful,
31215 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31216 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31217 + * GNU General Public License for more details.
31219 + * You should have received a copy of the GNU General Public License
31220 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31224 + * workqueue for asynchronous/super-io operations
31225 + * todo: try new dredential scheme
31228 +#include <linux/module.h>
31231 +/* internal workqueue named AUFS_WKQ_NAME */
31233 +static struct workqueue_struct *au_wkq;
31235 +struct au_wkinfo {
31236 + struct work_struct wk;
31237 + struct kobject *kobj;
31239 + unsigned int flags; /* see wkq.h */
31241 + au_wkq_func_t func;
31244 + struct completion *comp;
31247 +/* ---------------------------------------------------------------------- */
31249 +static void wkq_func(struct work_struct *wk)
31251 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
31253 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
31254 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
31256 + wkinfo->func(wkinfo->args);
31257 + if (au_ftest_wkq(wkinfo->flags, WAIT))
31258 + complete(wkinfo->comp);
31260 + kobject_put(wkinfo->kobj);
31261 + module_put(THIS_MODULE); /* todo: ?? */
31267 + * Since struct completion is large, try allocating it dynamically.
31269 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
31270 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
31272 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
31274 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
31276 + init_completion(*comp);
31277 + wkinfo->comp = *comp;
31283 +static void au_wkq_comp_free(struct completion *comp)
31291 +#define AuWkqCompDeclare(name) \
31292 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
31293 + struct completion *comp = &_ ## name
31295 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
31297 + wkinfo->comp = *comp;
31301 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
31305 +#endif /* 4KSTACKS */
31307 +static void au_wkq_run(struct au_wkinfo *wkinfo)
31309 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
31310 + if (au_wkq_test()) {
31311 + AuWarn1("wkq from wkq, due to a dead dir by UDBA?\n");
31312 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
31315 + au_dbg_verify_kthread();
31317 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
31318 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
31319 + queue_work(au_wkq, &wkinfo->wk);
31321 + INIT_WORK(&wkinfo->wk, wkq_func);
31322 + schedule_work(&wkinfo->wk);
31327 + * Be careful. It is easy to make deadlock happen.
31328 + * processA: lock, wkq and wait
31329 + * processB: wkq and wait, lock in wkq
31332 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
31335 + AuWkqCompDeclare(comp);
31336 + struct au_wkinfo wkinfo = {
31342 + err = au_wkq_comp_alloc(&wkinfo, &comp);
31344 + au_wkq_run(&wkinfo);
31345 + /* no timeout, no interrupt */
31346 + wait_for_completion(wkinfo.comp);
31347 + au_wkq_comp_free(comp);
31348 + destroy_work_on_stack(&wkinfo.wk);
31356 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
31357 + * problem in a concurrent umounting.
31359 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
31360 + unsigned int flags)
31363 + struct au_wkinfo *wkinfo;
31365 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
31368 + * wkq_func() must free this wkinfo.
31369 + * it highly depends upon the implementation of workqueue.
31372 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
31374 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
31375 + wkinfo->flags = flags & ~AuWkq_WAIT;
31376 + wkinfo->func = func;
31377 + wkinfo->args = args;
31378 + wkinfo->comp = NULL;
31379 + kobject_get(wkinfo->kobj);
31380 + __module_get(THIS_MODULE); /* todo: ?? */
31382 + au_wkq_run(wkinfo);
31385 + au_nwt_done(&au_sbi(sb)->si_nowait);
31391 +/* ---------------------------------------------------------------------- */
31393 +void au_nwt_init(struct au_nowait_tasks *nwt)
31395 + atomic_set(&nwt->nw_len, 0);
31396 + /* smp_mb(); */ /* atomic_set */
31397 + init_waitqueue_head(&nwt->nw_wq);
31400 +void au_wkq_fin(void)
31402 + destroy_workqueue(au_wkq);
31405 +int __init au_wkq_init(void)
31410 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
31411 + if (IS_ERR(au_wkq))
31412 + err = PTR_ERR(au_wkq);
31413 + else if (!au_wkq)
31418 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
31419 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
31420 +++ linux/fs/aufs/wkq.h 2014-04-24 22:11:10.861935852 +0200
31423 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31425 + * This program, aufs is free software; you can redistribute it and/or modify
31426 + * it under the terms of the GNU General Public License as published by
31427 + * the Free Software Foundation; either version 2 of the License, or
31428 + * (at your option) any later version.
31430 + * This program is distributed in the hope that it will be useful,
31431 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31432 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31433 + * GNU General Public License for more details.
31435 + * You should have received a copy of the GNU General Public License
31436 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31440 + * workqueue for asynchronous/super-io operations
31441 + * todo: try new credentials management scheme
31444 +#ifndef __AUFS_WKQ_H__
31445 +#define __AUFS_WKQ_H__
31449 +struct super_block;
31451 +/* ---------------------------------------------------------------------- */
31454 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
31456 +struct au_nowait_tasks {
31458 + wait_queue_head_t nw_wq;
31461 +/* ---------------------------------------------------------------------- */
31463 +typedef void (*au_wkq_func_t)(void *args);
31466 +#define AuWkq_WAIT 1
31467 +#define AuWkq_NEST (1 << 1)
31468 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
31469 +#define au_fset_wkq(flags, name) \
31470 + do { (flags) |= AuWkq_##name; } while (0)
31471 +#define au_fclr_wkq(flags, name) \
31472 + do { (flags) &= ~AuWkq_##name; } while (0)
31474 +#ifndef CONFIG_AUFS_HNOTIFY
31476 +#define AuWkq_NEST 0
31480 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
31481 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
31482 + unsigned int flags);
31483 +void au_nwt_init(struct au_nowait_tasks *nwt);
31484 +int __init au_wkq_init(void);
31485 +void au_wkq_fin(void);
31487 +/* ---------------------------------------------------------------------- */
31489 +static inline int au_wkq_test(void)
31491 + return current->flags & PF_WQ_WORKER;
31494 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
31496 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
31499 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
31501 + if (atomic_dec_and_test(&nwt->nw_len))
31502 + wake_up_all(&nwt->nw_wq);
31505 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
31507 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
31511 +#endif /* __KERNEL__ */
31512 +#endif /* __AUFS_WKQ_H__ */
31513 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
31514 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
31515 +++ linux/fs/aufs/xino.c 2014-04-24 22:11:10.861935852 +0200
31518 + * Copyright (C) 2005-2014 Junjiro R. Okajima
31520 + * This program, aufs is free software; you can redistribute it and/or modify
31521 + * it under the terms of the GNU General Public License as published by
31522 + * the Free Software Foundation; either version 2 of the License, or
31523 + * (at your option) any later version.
31525 + * This program is distributed in the hope that it will be useful,
31526 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31527 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31528 + * GNU General Public License for more details.
31530 + * You should have received a copy of the GNU General Public License
31531 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31535 + * external inode number translation table and bitmap
31538 +#include <linux/seq_file.h>
31539 +#include <linux/statfs.h>
31542 +/* todo: unnecessary to support mmap_sem since kernel-space? */
31543 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
31547 + mm_segment_t oldfs;
31554 + oldfs = get_fs();
31555 + set_fs(KERNEL_DS);
31557 + /* todo: signal_pending? */
31558 + err = func(file, buf.u, size, pos);
31559 + } while (err == -EAGAIN || err == -EINTR);
31562 +#if 0 /* reserved for future use */
31564 + fsnotify_access(file->f_dentry);
31570 +/* ---------------------------------------------------------------------- */
31572 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
31573 + size_t size, loff_t *pos)
31576 + mm_segment_t oldfs;
31579 + const char __user *u;
31583 + oldfs = get_fs();
31584 + set_fs(KERNEL_DS);
31586 + /* todo: signal_pending? */
31587 + err = func(file, buf.u, size, pos);
31588 + } while (err == -EAGAIN || err == -EINTR);
31591 +#if 0 /* reserved for future use */
31593 + fsnotify_modify(file->f_dentry);
31599 +struct do_xino_fwrite_args {
31601 + au_writef_t func;
31602 + struct file *file;
31608 +static void call_do_xino_fwrite(void *args)
31610 + struct do_xino_fwrite_args *a = args;
31611 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
31614 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
31619 + /* todo: signal block and no wkq? */
31620 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
31622 + err = do_xino_fwrite(func, file, buf, size, pos);
31626 + * it breaks RLIMIT_FSIZE and normal user's limit,
31627 + * users should care about quota and real 'filesystem full.'
31630 + struct do_xino_fwrite_args args = {
31639 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
31640 + if (unlikely(wkq_err))
31647 +/* ---------------------------------------------------------------------- */
31650 + * create a new xinofile at the same place/path as @base_file.
31652 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
31654 + struct file *file;
31655 + struct dentry *base, *parent;
31656 + struct inode *dir, *delegated;
31657 + struct qstr *name;
31658 + struct path path;
31661 + base = base_file->f_dentry;
31662 + parent = base->d_parent; /* dir inode is locked */
31663 + dir = parent->d_inode;
31666 + file = ERR_PTR(-EINVAL);
31667 + name = &base->d_name;
31668 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
31669 + if (IS_ERR(path.dentry)) {
31670 + file = (void *)path.dentry;
31671 + pr_err("%pd lookup err %ld\n",
31672 + base, PTR_ERR(path.dentry));
31676 + /* no need to mnt_want_write() since we call dentry_open() later */
31677 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
31678 + if (unlikely(err)) {
31679 + file = ERR_PTR(err);
31680 + pr_err("%pd create err %d\n", base, err);
31684 + path.mnt = base_file->f_path.mnt;
31685 + file = vfsub_dentry_open(&path,
31686 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
31687 + /* | __FMODE_NONOTIFY */);
31688 + if (IS_ERR(file)) {
31689 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
31693 + delegated = NULL;
31694 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
31695 + if (unlikely(err == -EWOULDBLOCK)) {
31696 + pr_warn("cannot retry for NFSv4 delegation"
31697 + " for an internal unlink\n");
31700 + if (unlikely(err)) {
31701 + pr_err("%pd unlink err %d\n", base, err);
31706 + /* no one can touch copy_src xino */
31707 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
31708 + if (unlikely(err)) {
31709 + pr_err("%pd copy err %d\n", base, err);
31713 + goto out_dput; /* success */
31717 + file = ERR_PTR(err);
31719 + dput(path.dentry);
31724 +struct au_xino_lock_dir {
31725 + struct au_hinode *hdir;
31726 + struct dentry *parent;
31727 + struct mutex *mtx;
31730 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
31731 + struct au_xino_lock_dir *ldir)
31733 + aufs_bindex_t brid, bindex;
31735 + ldir->hdir = NULL;
31737 + brid = au_xino_brid(sb);
31739 + bindex = au_br_index(sb, brid);
31740 + if (bindex >= 0) {
31741 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
31742 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
31744 + ldir->parent = dget_parent(xino->f_dentry);
31745 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
31746 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
31750 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
31753 + au_hn_imtx_unlock(ldir->hdir);
31755 + mutex_unlock(ldir->mtx);
31756 + dput(ldir->parent);
31760 +/* ---------------------------------------------------------------------- */
31762 +/* trucate xino files asynchronously */
31764 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
31767 + unsigned long jiffy;
31769 + aufs_bindex_t bi, bend;
31770 + struct kstatfs *st;
31771 + struct au_branch *br;
31772 + struct file *new_xino, *file;
31773 + struct super_block *h_sb;
31774 + struct au_xino_lock_dir ldir;
31777 + st = kzalloc(sizeof(*st), GFP_NOFS);
31778 + if (unlikely(!st))
31782 + bend = au_sbend(sb);
31783 + if (unlikely(bindex < 0 || bend < bindex))
31785 + br = au_sbr(sb, bindex);
31786 + file = br->br_xino.xi_file;
31790 + err = vfs_statfs(&file->f_path, st);
31791 + if (unlikely(err))
31792 + AuErr1("statfs err %d, ignored\n", err);
31794 + blocks = file_inode(file)->i_blocks;
31795 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31796 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
31798 + au_xino_lock_dir(sb, file, &ldir);
31799 + /* mnt_want_write() is unnecessary here */
31800 + new_xino = au_xino_create2(file, file);
31801 + au_xino_unlock_dir(&ldir);
31802 + err = PTR_ERR(new_xino);
31803 + if (IS_ERR(new_xino)) {
31804 + pr_err("err %d, ignored\n", err);
31809 + br->br_xino.xi_file = new_xino;
31811 + h_sb = au_br_sb(br);
31812 + for (bi = 0; bi <= bend; bi++) {
31813 + if (unlikely(bi == bindex))
31815 + br = au_sbr(sb, bi);
31816 + if (au_br_sb(br) != h_sb)
31819 + fput(br->br_xino.xi_file);
31820 + br->br_xino.xi_file = new_xino;
31821 + get_file(new_xino);
31824 + err = vfs_statfs(&new_xino->f_path, st);
31826 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
31827 + bindex, (u64)file_inode(new_xino)->i_blocks,
31828 + st->f_bfree, st->f_blocks);
31829 + if (file_inode(new_xino)->i_blocks < blocks)
31830 + au_sbi(sb)->si_xino_jiffy = jiffy;
31832 + AuErr1("statfs err %d, ignored\n", err);
31840 +struct xino_do_trunc_args {
31841 + struct super_block *sb;
31842 + struct au_branch *br;
31845 +static void xino_do_trunc(void *_args)
31847 + struct xino_do_trunc_args *args = _args;
31848 + struct super_block *sb;
31849 + struct au_branch *br;
31850 + struct inode *dir;
31852 + aufs_bindex_t bindex;
31856 + dir = sb->s_root->d_inode;
31859 + si_noflush_write_lock(sb);
31860 + ii_read_lock_parent(dir);
31861 + bindex = au_br_index(sb, br->br_id);
31862 + err = au_xino_trunc(sb, bindex);
31863 + ii_read_unlock(dir);
31864 + if (unlikely(err))
31865 + pr_warn("err b%d, (%d)\n", bindex, err);
31866 + atomic_dec(&br->br_xino_running);
31867 + atomic_dec(&br->br_count);
31868 + si_write_unlock(sb);
31869 + au_nwt_done(&au_sbi(sb)->si_nowait);
31873 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
31876 + struct kstatfs st;
31877 + struct au_sbinfo *sbinfo;
31879 + /* todo: si_xino_expire and the ratio should be customizable */
31880 + sbinfo = au_sbi(sb);
31881 + if (time_before(jiffies,
31882 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
31885 + /* truncation border */
31886 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
31887 + if (unlikely(err)) {
31888 + AuErr1("statfs err %d, ignored\n", err);
31891 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
31897 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
31899 + struct xino_do_trunc_args *args;
31902 + if (!xino_trunc_test(sb, br))
31905 + if (atomic_inc_return(&br->br_xino_running) > 1)
31908 + /* lock and kfree() will be called in trunc_xino() */
31909 + args = kmalloc(sizeof(*args), GFP_NOFS);
31910 + if (unlikely(!args)) {
31911 + AuErr1("no memory\n");
31915 + atomic_inc(&br->br_count);
31918 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
31920 + return; /* success */
31922 + pr_err("wkq %d\n", wkq_err);
31923 + atomic_dec(&br->br_count);
31928 + atomic_dec(&br->br_xino_running);
31931 +/* ---------------------------------------------------------------------- */
31933 +static int au_xino_do_write(au_writef_t write, struct file *file,
31934 + ino_t h_ino, ino_t ino)
31940 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
31941 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
31944 + pos *= sizeof(ino);
31945 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
31946 + if (sz == sizeof(ino))
31947 + return 0; /* success */
31949 + AuIOErr("write failed (%zd)\n", sz);
31954 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
31955 + * at the position of @h_ino.
31956 + * even if @ino is zero, it is written to the xinofile and means no entry.
31957 + * if the size of the xino file on a specific filesystem exceeds the watermark,
31958 + * try truncating it.
31960 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
31964 + unsigned int mnt_flags;
31965 + struct au_branch *br;
31967 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
31968 + || ((loff_t)-1) > 0);
31969 + SiMustAnyLock(sb);
31971 + mnt_flags = au_mntflags(sb);
31972 + if (!au_opt_test(mnt_flags, XINO))
31975 + br = au_sbr(sb, bindex);
31976 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
31979 + if (au_opt_test(mnt_flags, TRUNC_XINO)
31980 + && au_test_fs_trunc_xino(au_br_sb(br)))
31981 + xino_try_trunc(sb, br);
31982 + return 0; /* success */
31985 + AuIOErr("write failed (%d)\n", err);
31989 +/* ---------------------------------------------------------------------- */
31991 +/* aufs inode number bitmap */
31993 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
31994 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
31998 + AuDebugOn(bit < 0 || page_bits <= bit);
31999 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
32003 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
32005 + AuDebugOn(ino < AUFS_FIRST_INO);
32006 + ino -= AUFS_FIRST_INO;
32007 + *pindex = ino / page_bits;
32008 + *bit = ino % page_bits;
32011 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
32016 + struct au_sbinfo *sbinfo;
32017 + struct file *xib;
32018 + unsigned long *p;
32020 + sbinfo = au_sbi(sb);
32021 + MtxMustLock(&sbinfo->si_xib_mtx);
32022 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
32023 + || !au_opt_test(sbinfo->si_mntflags, XINO));
32025 + if (pindex == sbinfo->si_xib_last_pindex)
32028 + xib = sbinfo->si_xib;
32029 + p = sbinfo->si_xib_buf;
32030 + pos = sbinfo->si_xib_last_pindex;
32031 + pos *= PAGE_SIZE;
32032 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
32033 + if (unlikely(sz != PAGE_SIZE))
32037 + pos *= PAGE_SIZE;
32038 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
32039 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
32041 + memset(p, 0, PAGE_SIZE);
32042 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
32044 + if (sz == PAGE_SIZE) {
32045 + sbinfo->si_xib_last_pindex = pindex;
32046 + return 0; /* success */
32050 + AuIOErr1("write failed (%zd)\n", sz);
32057 +/* ---------------------------------------------------------------------- */
32059 +static void au_xib_clear_bit(struct inode *inode)
32062 + unsigned long pindex;
32063 + struct super_block *sb;
32064 + struct au_sbinfo *sbinfo;
32066 + AuDebugOn(inode->i_nlink);
32068 + sb = inode->i_sb;
32069 + xib_calc_bit(inode->i_ino, &pindex, &bit);
32070 + AuDebugOn(page_bits <= bit);
32071 + sbinfo = au_sbi(sb);
32072 + mutex_lock(&sbinfo->si_xib_mtx);
32073 + err = xib_pindex(sb, pindex);
32075 + clear_bit(bit, sbinfo->si_xib_buf);
32076 + sbinfo->si_xib_next_bit = bit;
32078 + mutex_unlock(&sbinfo->si_xib_mtx);
32081 +/* for s_op->delete_inode() */
32082 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
32085 + unsigned int mnt_flags;
32086 + aufs_bindex_t bindex, bend, bi;
32087 + unsigned char try_trunc;
32088 + struct au_iinfo *iinfo;
32089 + struct super_block *sb;
32090 + struct au_hinode *hi;
32091 + struct inode *h_inode;
32092 + struct au_branch *br;
32093 + au_writef_t xwrite;
32095 + sb = inode->i_sb;
32096 + mnt_flags = au_mntflags(sb);
32097 + if (!au_opt_test(mnt_flags, XINO)
32098 + || inode->i_ino == AUFS_ROOT_INO)
32102 + au_xigen_inc(inode);
32103 + au_xib_clear_bit(inode);
32106 + iinfo = au_ii(inode);
32110 + bindex = iinfo->ii_bstart;
32114 + xwrite = au_sbi(sb)->si_xwrite;
32115 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
32116 + hi = iinfo->ii_hinode + bindex;
32117 + bend = iinfo->ii_bend;
32118 + for (; bindex <= bend; bindex++, hi++) {
32119 + h_inode = hi->hi_inode;
32121 + || (!unlinked && h_inode->i_nlink))
32124 + /* inode may not be revalidated */
32125 + bi = au_br_index(sb, hi->hi_id);
32129 + br = au_sbr(sb, bi);
32130 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
32131 + h_inode->i_ino, /*ino*/0);
32132 + if (!err && try_trunc
32133 + && au_test_fs_trunc_xino(au_br_sb(br)))
32134 + xino_try_trunc(sb, br);
32138 +/* get an unused inode number from bitmap */
32139 +ino_t au_xino_new_ino(struct super_block *sb)
32142 + unsigned long *p, pindex, ul, pend;
32143 + struct au_sbinfo *sbinfo;
32144 + struct file *file;
32145 + int free_bit, err;
32147 + if (!au_opt_test(au_mntflags(sb), XINO))
32148 + return iunique(sb, AUFS_FIRST_INO);
32150 + sbinfo = au_sbi(sb);
32151 + mutex_lock(&sbinfo->si_xib_mtx);
32152 + p = sbinfo->si_xib_buf;
32153 + free_bit = sbinfo->si_xib_next_bit;
32154 + if (free_bit < page_bits && !test_bit(free_bit, p))
32155 + goto out; /* success */
32156 + free_bit = find_first_zero_bit(p, page_bits);
32157 + if (free_bit < page_bits)
32158 + goto out; /* success */
32160 + pindex = sbinfo->si_xib_last_pindex;
32161 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
32162 + err = xib_pindex(sb, ul);
32163 + if (unlikely(err))
32165 + free_bit = find_first_zero_bit(p, page_bits);
32166 + if (free_bit < page_bits)
32167 + goto out; /* success */
32170 + file = sbinfo->si_xib;
32171 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
32172 + for (ul = pindex + 1; ul <= pend; ul++) {
32173 + err = xib_pindex(sb, ul);
32174 + if (unlikely(err))
32176 + free_bit = find_first_zero_bit(p, page_bits);
32177 + if (free_bit < page_bits)
32178 + goto out; /* success */
32183 + set_bit(free_bit, p);
32184 + sbinfo->si_xib_next_bit = free_bit + 1;
32185 + pindex = sbinfo->si_xib_last_pindex;
32186 + mutex_unlock(&sbinfo->si_xib_mtx);
32187 + ino = xib_calc_ino(pindex, free_bit);
32188 + AuDbg("i%lu\n", (unsigned long)ino);
32191 + mutex_unlock(&sbinfo->si_xib_mtx);
32197 + * read @ino from xinofile for the specified branch{@sb, @bindex}
32198 + * at the position of @h_ino.
32199 + * if @ino does not exist and @do_new is true, get new one.
32201 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
32207 + struct file *file;
32208 + struct au_sbinfo *sbinfo;
32211 + if (!au_opt_test(au_mntflags(sb), XINO))
32212 + return 0; /* no xino */
32215 + sbinfo = au_sbi(sb);
32217 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
32218 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
32221 + pos *= sizeof(*ino);
32223 + file = au_sbr(sb, bindex)->br_xino.xi_file;
32224 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
32225 + return 0; /* no ino */
32227 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
32228 + if (sz == sizeof(*ino))
32229 + return 0; /* success */
32232 + if (unlikely(sz >= 0)) {
32234 + AuIOErr("xino read error (%zd)\n", sz);
32240 +/* ---------------------------------------------------------------------- */
32242 +/* create and set a new xino file */
32244 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
32246 + struct file *file;
32247 + struct dentry *h_parent, *d;
32248 + struct inode *h_dir;
32252 + * at mount-time, and the xino file is the default path,
32253 + * hnotify is disabled so we have no notify events to ignore.
32254 + * when a user specified the xino, we cannot get au_hdir to be ignored.
32256 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
32257 + /* | __FMODE_NONOTIFY */,
32258 + S_IRUGO | S_IWUGO);
32259 + if (IS_ERR(file)) {
32261 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
32265 + /* keep file count */
32266 + h_parent = dget_parent(file->f_dentry);
32267 + h_dir = h_parent->d_inode;
32268 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
32269 + /* mnt_want_write() is unnecessary here */
32270 + /* no delegation since it is just created */
32271 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
32272 + mutex_unlock(&h_dir->i_mutex);
32274 + if (unlikely(err)) {
32276 + pr_err("unlink %s(%d)\n", fname, err);
32281 + d = file->f_dentry;
32282 + if (unlikely(sb == d->d_sb)) {
32284 + pr_err("%s must be outside\n", fname);
32287 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
32289 + pr_err("xino doesn't support %s(%s)\n",
32290 + fname, au_sbtype(d->d_sb));
32293 + return file; /* success */
32297 + file = ERR_PTR(err);
32302 + * find another branch who is on the same filesystem of the specified
32303 + * branch{@btgt}. search until @bend.
32305 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
32306 + aufs_bindex_t bend)
32308 + aufs_bindex_t bindex;
32309 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
32311 + for (bindex = 0; bindex < btgt; bindex++)
32312 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
32314 + for (bindex++; bindex <= bend; bindex++)
32315 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
32320 +/* ---------------------------------------------------------------------- */
32323 + * initialize the xinofile for the specified branch @br
32324 + * at the place/path where @base_file indicates.
32325 + * test whether another branch is on the same filesystem or not,
32326 + * if @do_test is true.
32328 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
32329 + struct file *base_file, int do_test)
32333 + aufs_bindex_t bend, bindex;
32334 + struct au_branch *shared_br, *b;
32335 + struct file *file;
32336 + struct super_block *tgt_sb;
32338 + shared_br = NULL;
32339 + bend = au_sbend(sb);
32341 + tgt_sb = au_br_sb(br);
32342 + for (bindex = 0; bindex <= bend; bindex++) {
32343 + b = au_sbr(sb, bindex);
32344 + if (tgt_sb == au_br_sb(b)) {
32351 + if (!shared_br || !shared_br->br_xino.xi_file) {
32352 + struct au_xino_lock_dir ldir;
32354 + au_xino_lock_dir(sb, base_file, &ldir);
32355 + /* mnt_want_write() is unnecessary here */
32356 + file = au_xino_create2(base_file, NULL);
32357 + au_xino_unlock_dir(&ldir);
32358 + err = PTR_ERR(file);
32359 + if (IS_ERR(file))
32361 + br->br_xino.xi_file = file;
32363 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
32364 + get_file(br->br_xino.xi_file);
32367 + ino = AUFS_ROOT_INO;
32368 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
32370 + if (unlikely(err)) {
32371 + fput(br->br_xino.xi_file);
32372 + br->br_xino.xi_file = NULL;
32379 +/* ---------------------------------------------------------------------- */
32381 +/* trucate a xino bitmap file */
32384 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
32388 + unsigned long pindex;
32389 + loff_t pos, pend;
32390 + struct au_sbinfo *sbinfo;
32393 + unsigned long *p;
32396 + sbinfo = au_sbi(sb);
32397 + MtxMustLock(&sbinfo->si_xib_mtx);
32398 + p = sbinfo->si_xib_buf;
32399 + func = sbinfo->si_xread;
32400 + pend = vfsub_f_size_read(file);
32402 + while (pos < pend) {
32403 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
32405 + if (unlikely(sz <= 0))
32409 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
32410 + if (unlikely(*ino < AUFS_FIRST_INO))
32413 + xib_calc_bit(*ino, &pindex, &bit);
32414 + AuDebugOn(page_bits <= bit);
32415 + err = xib_pindex(sb, pindex);
32427 +static int xib_restore(struct super_block *sb)
32430 + aufs_bindex_t bindex, bend;
32434 + page = (void *)__get_free_page(GFP_NOFS);
32435 + if (unlikely(!page))
32439 + bend = au_sbend(sb);
32440 + for (bindex = 0; !err && bindex <= bend; bindex++)
32441 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
32442 + err = do_xib_restore
32443 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
32445 + AuDbg("b%d\n", bindex);
32446 + free_page((unsigned long)page);
32452 +int au_xib_trunc(struct super_block *sb)
32457 + struct au_xino_lock_dir ldir;
32458 + struct au_sbinfo *sbinfo;
32459 + unsigned long *p;
32460 + struct file *file;
32462 + SiMustWriteLock(sb);
32465 + sbinfo = au_sbi(sb);
32466 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
32469 + file = sbinfo->si_xib;
32470 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
32473 + au_xino_lock_dir(sb, file, &ldir);
32474 + /* mnt_want_write() is unnecessary here */
32475 + file = au_xino_create2(sbinfo->si_xib, NULL);
32476 + au_xino_unlock_dir(&ldir);
32477 + err = PTR_ERR(file);
32478 + if (IS_ERR(file))
32480 + fput(sbinfo->si_xib);
32481 + sbinfo->si_xib = file;
32483 + p = sbinfo->si_xib_buf;
32484 + memset(p, 0, PAGE_SIZE);
32486 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
32487 + if (unlikely(sz != PAGE_SIZE)) {
32489 + AuIOErr("err %d\n", err);
32495 + mutex_lock(&sbinfo->si_xib_mtx);
32496 + /* mnt_want_write() is unnecessary here */
32497 + err = xib_restore(sb);
32498 + mutex_unlock(&sbinfo->si_xib_mtx);
32504 +/* ---------------------------------------------------------------------- */
32507 + * xino mount option handlers
32509 +static au_readf_t find_readf(struct file *h_file)
32511 + const struct file_operations *fop = h_file->f_op;
32514 + return fop->read;
32515 + if (fop->aio_read)
32516 + return do_sync_read;
32517 + return ERR_PTR(-ENOSYS);
32520 +static au_writef_t find_writef(struct file *h_file)
32522 + const struct file_operations *fop = h_file->f_op;
32525 + return fop->write;
32526 + if (fop->aio_write)
32527 + return do_sync_write;
32528 + return ERR_PTR(-ENOSYS);
32532 +static void xino_clear_xib(struct super_block *sb)
32534 + struct au_sbinfo *sbinfo;
32536 + SiMustWriteLock(sb);
32538 + sbinfo = au_sbi(sb);
32539 + sbinfo->si_xread = NULL;
32540 + sbinfo->si_xwrite = NULL;
32541 + if (sbinfo->si_xib)
32542 + fput(sbinfo->si_xib);
32543 + sbinfo->si_xib = NULL;
32544 + free_page((unsigned long)sbinfo->si_xib_buf);
32545 + sbinfo->si_xib_buf = NULL;
32548 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
32552 + struct au_sbinfo *sbinfo;
32553 + struct file *file;
32555 + SiMustWriteLock(sb);
32557 + sbinfo = au_sbi(sb);
32558 + file = au_xino_create2(base, sbinfo->si_xib);
32559 + err = PTR_ERR(file);
32560 + if (IS_ERR(file))
32562 + if (sbinfo->si_xib)
32563 + fput(sbinfo->si_xib);
32564 + sbinfo->si_xib = file;
32565 + sbinfo->si_xread = find_readf(file);
32566 + sbinfo->si_xwrite = find_writef(file);
32569 + if (!sbinfo->si_xib_buf)
32570 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
32571 + if (unlikely(!sbinfo->si_xib_buf))
32574 + sbinfo->si_xib_last_pindex = 0;
32575 + sbinfo->si_xib_next_bit = 0;
32576 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
32578 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
32579 + PAGE_SIZE, &pos);
32580 + if (unlikely(err != PAGE_SIZE))
32584 + goto out; /* success */
32587 + free_page((unsigned long)sbinfo->si_xib_buf);
32588 + sbinfo->si_xib_buf = NULL;
32592 + fput(sbinfo->si_xib);
32593 + sbinfo->si_xib = NULL;
32594 + sbinfo->si_xread = NULL;
32595 + sbinfo->si_xwrite = NULL;
32600 +/* xino for each branch */
32601 +static void xino_clear_br(struct super_block *sb)
32603 + aufs_bindex_t bindex, bend;
32604 + struct au_branch *br;
32606 + bend = au_sbend(sb);
32607 + for (bindex = 0; bindex <= bend; bindex++) {
32608 + br = au_sbr(sb, bindex);
32609 + if (!br || !br->br_xino.xi_file)
32612 + fput(br->br_xino.xi_file);
32613 + br->br_xino.xi_file = NULL;
32617 +static int au_xino_set_br(struct super_block *sb, struct file *base)
32621 + aufs_bindex_t bindex, bend, bshared;
32623 + struct file *old, *new;
32625 + struct au_branch *br;
32626 + struct inode *inode;
32627 + au_writef_t writef;
32629 + SiMustWriteLock(sb);
32632 + bend = au_sbend(sb);
32633 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
32634 + if (unlikely(!fpair))
32637 + inode = sb->s_root->d_inode;
32638 + ino = AUFS_ROOT_INO;
32639 + writef = au_sbi(sb)->si_xwrite;
32640 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
32641 + br = au_sbr(sb, bindex);
32642 + bshared = is_sb_shared(sb, bindex, bindex - 1);
32643 + if (bshared >= 0) {
32644 + /* shared xino */
32645 + *p = fpair[bshared];
32646 + get_file(p->new);
32651 + p->old = br->br_xino.xi_file;
32652 + p->new = au_xino_create2(base, br->br_xino.xi_file);
32653 + err = PTR_ERR(p->new);
32654 + if (IS_ERR(p->new)) {
32660 + err = au_xino_do_write(writef, p->new,
32661 + au_h_iptr(inode, bindex)->i_ino, ino);
32662 + if (unlikely(err))
32666 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
32667 + br = au_sbr(sb, bindex);
32668 + if (br->br_xino.xi_file)
32669 + fput(br->br_xino.xi_file);
32670 + get_file(p->new);
32671 + br->br_xino.xi_file = p->new;
32675 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
32685 +void au_xino_clr(struct super_block *sb)
32687 + struct au_sbinfo *sbinfo;
32689 + au_xigen_clr(sb);
32690 + xino_clear_xib(sb);
32691 + xino_clear_br(sb);
32692 + sbinfo = au_sbi(sb);
32693 + /* lvalue, do not call au_mntflags() */
32694 + au_opt_clr(sbinfo->si_mntflags, XINO);
32697 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
32700 + struct dentry *parent, *cur_parent;
32701 + struct qstr *dname, *cur_name;
32702 + struct file *cur_xino;
32703 + struct inode *dir;
32704 + struct au_sbinfo *sbinfo;
32706 + SiMustWriteLock(sb);
32709 + sbinfo = au_sbi(sb);
32710 + parent = dget_parent(xino->file->f_dentry);
32713 + dname = &xino->file->f_dentry->d_name;
32714 + cur_xino = sbinfo->si_xib;
32716 + cur_parent = dget_parent(cur_xino->f_dentry);
32717 + cur_name = &cur_xino->f_dentry->d_name;
32718 + skip = (cur_parent == parent
32719 + && dname->len == cur_name->len
32720 + && !memcmp(dname->name, cur_name->name,
32722 + dput(cur_parent);
32728 + au_opt_set(sbinfo->si_mntflags, XINO);
32729 + dir = parent->d_inode;
32730 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
32731 + /* mnt_want_write() is unnecessary here */
32732 + err = au_xino_set_xib(sb, xino->file);
32734 + err = au_xigen_set(sb, xino->file);
32736 + err = au_xino_set_br(sb, xino->file);
32737 + mutex_unlock(&dir->i_mutex);
32739 + goto out; /* success */
32742 + AuIOErr("failed creating xino(%d).\n", err);
32749 +/* ---------------------------------------------------------------------- */
32752 + * create a xinofile at the default place/path.
32754 +struct file *au_xino_def(struct super_block *sb)
32756 + struct file *file;
32758 + struct au_branch *br;
32759 + struct super_block *h_sb;
32760 + struct path path;
32761 + aufs_bindex_t bend, bindex, bwr;
32764 + bend = au_sbend(sb);
32766 + for (bindex = 0; bindex <= bend; bindex++) {
32767 + br = au_sbr(sb, bindex);
32768 + if (au_br_writable(br->br_perm)
32769 + && !au_test_fs_bad_xino(au_br_sb(br))) {
32776 + file = ERR_PTR(-ENOMEM);
32777 + page = (void *)__get_free_page(GFP_NOFS);
32778 + if (unlikely(!page))
32780 + path.mnt = au_br_mnt(br);
32781 + path.dentry = au_h_dptr(sb->s_root, bwr);
32782 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
32783 + file = (void *)p;
32784 + if (!IS_ERR(p)) {
32785 + strcat(p, "/" AUFS_XINO_FNAME);
32786 + AuDbg("%s\n", p);
32787 + file = au_xino_create(sb, p, /*silent*/0);
32788 + if (!IS_ERR(file))
32789 + au_xino_brid_set(sb, br->br_id);
32791 + free_page((unsigned long)page);
32793 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
32794 + if (IS_ERR(file))
32796 + h_sb = file->f_dentry->d_sb;
32797 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
32798 + pr_err("xino doesn't support %s(%s)\n",
32799 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
32801 + file = ERR_PTR(-EINVAL);
32803 + if (!IS_ERR(file))
32804 + au_xino_brid_set(sb, -1);
32811 +/* ---------------------------------------------------------------------- */
32813 +int au_xino_path(struct seq_file *seq, struct file *file)
32817 + err = au_seq_path(seq, &file->f_path);
32818 + if (unlikely(err < 0))
32822 +#define Deleted "\\040(deleted)"
32823 + seq->count -= sizeof(Deleted) - 1;
32824 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
32825 + sizeof(Deleted) - 1));
32831 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
32832 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
32833 +++ linux/include/uapi/linux/aufs_type.h 2014-04-24 22:11:10.935269950 +0200
32836 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32838 + * This program, aufs is free software; you can redistribute it and/or modify
32839 + * it under the terms of the GNU General Public License as published by
32840 + * the Free Software Foundation; either version 2 of the License, or
32841 + * (at your option) any later version.
32843 + * This program is distributed in the hope that it will be useful,
32844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32846 + * GNU General Public License for more details.
32848 + * You should have received a copy of the GNU General Public License
32849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32852 +#ifndef __AUFS_TYPE_H__
32853 +#define __AUFS_TYPE_H__
32855 +#define AUFS_NAME "aufs"
32859 + * define it before including all other headers.
32860 + * sched.h may use pr_* macros before defining "current", so define the
32861 + * no-current version first, and re-define later.
32863 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
32864 +#include <linux/sched.h>
32866 +#define pr_fmt(fmt) \
32867 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
32868 + (int)sizeof(current->comm), current->comm, current->pid
32870 +#include <stdint.h>
32871 +#include <sys/types.h>
32872 +#endif /* __KERNEL__ */
32874 +#include <linux/limits.h>
32876 +#define AUFS_VERSION "3.14-20140407"
32878 +/* todo? move this to linux-2.6.19/include/magic.h */
32879 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
32881 +/* ---------------------------------------------------------------------- */
32883 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
32884 +typedef int8_t aufs_bindex_t;
32885 +#define AUFS_BRANCH_MAX 127
32887 +typedef int16_t aufs_bindex_t;
32888 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
32889 +#define AUFS_BRANCH_MAX 511
32890 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
32891 +#define AUFS_BRANCH_MAX 1023
32892 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
32893 +#define AUFS_BRANCH_MAX 32767
32898 +#ifndef AUFS_BRANCH_MAX
32899 +#error unknown CONFIG_AUFS_BRANCH_MAX value
32901 +#endif /* __KERNEL__ */
32903 +/* ---------------------------------------------------------------------- */
32905 +#define AUFS_FSTYPE AUFS_NAME
32907 +#define AUFS_ROOT_INO 2
32908 +#define AUFS_FIRST_INO 11
32910 +#define AUFS_WH_PFX ".wh."
32911 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
32912 +#define AUFS_WH_TMP_LEN 4
32913 +/* a limit for rmdir/rename a dir and copyup */
32914 +#define AUFS_MAX_NAMELEN (NAME_MAX \
32915 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
32917 + - AUFS_WH_TMP_LEN) /* hex */
32918 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
32919 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
32920 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
32921 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
32922 +#define AUFS_DIRWH_DEF 3
32923 +#define AUFS_RDCACHE_DEF 10 /* seconds */
32924 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
32925 +#define AUFS_RDBLK_DEF 512 /* bytes */
32926 +#define AUFS_RDHASH_DEF 32
32927 +#define AUFS_WKQ_NAME AUFS_NAME "d"
32928 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
32929 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
32930 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
32932 +/* pseudo-link maintenace under /proc */
32933 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
32934 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
32935 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
32937 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
32938 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
32940 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
32941 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
32942 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
32944 +/* doubly whiteouted */
32945 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
32946 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
32947 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
32949 +/* branch permissions and attributes */
32950 +#define AUFS_BRPERM_RW "rw"
32951 +#define AUFS_BRPERM_RO "ro"
32952 +#define AUFS_BRPERM_RR "rr"
32953 +#define AUFS_BRRATTR_WH "wh"
32954 +#define AUFS_BRWATTR_NLWH "nolwh"
32955 +#define AUFS_BRATTR_UNPIN "unpin"
32957 +/* ---------------------------------------------------------------------- */
32961 + /* readdir in userspace */
32965 + /* pathconf wrapper */
32975 +/* borrowed from linux/include/linux/kernel.h */
32977 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
32978 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
32981 +/* borrowed from linux/include/linux/compiler-gcc3.h */
32983 +#define __aligned(x) __attribute__((aligned(x)))
32988 +#define __packed __attribute__((packed))
32992 +struct au_rdu_cookie {
32997 + uint32_t generation;
33000 +struct au_rdu_ent {
33009 +static inline int au_rdu_len(int nlen)
33011 + /* include the terminating NULL */
33012 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
33013 + sizeof(uint64_t));
33016 +union au_rdu_ent_ul {
33017 + struct au_rdu_ent __user *e;
33029 + uint64_t sz; /* AuCtl_RDU */
33030 + uint64_t nent; /* AuCtl_RDU_INO */
33032 + union au_rdu_ent_ul ent;
33033 + uint16_t verify[AufsCtlRduV_End];
33035 + /* input/output */
33039 + union au_rdu_ent_ul tail;
33040 + /* number of entries which were added in a single call */
33045 + struct au_rdu_cookie cookie;
33048 +/* ---------------------------------------------------------------------- */
33050 +struct aufs_wbr_fd {
33055 +/* ---------------------------------------------------------------------- */
33057 +struct aufs_ibusy {
33058 + uint64_t ino, h_ino;
33062 +/* ---------------------------------------------------------------------- */
33064 +/* error code for move-down */
33065 +/* the actual message strings are implemented in aufs-util.git */
33067 + EAU_MVDOWN_OPAQUE = 1,
33068 + EAU_MVDOWN_WHITEOUT,
33069 + EAU_MVDOWN_UPPER,
33070 + EAU_MVDOWN_BOTTOM,
33071 + EAU_MVDOWN_NOUPPER,
33072 + EAU_MVDOWN_NOLOWERBR,
33076 +/* flags for move-down */
33077 +#define AUFS_MVDOWN_DMSG 1
33078 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
33079 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
33080 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
33081 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
33082 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
33083 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
33084 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
33085 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
33086 +/* will be added more */
33089 + AUFS_MVDOWN_UPPER,
33090 + AUFS_MVDOWN_LOWER,
33091 + AUFS_MVDOWN_NARRAY
33094 +struct aufs_mvdown {
33099 + } a[AUFS_MVDOWN_NARRAY];
33101 + /* will be added more */
33104 +/* ---------------------------------------------------------------------- */
33106 +#define AuCtlType 'A'
33107 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
33108 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
33109 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
33110 + struct aufs_wbr_fd)
33111 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
33112 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
33113 + struct aufs_mvdown)
33115 +#endif /* __AUFS_TYPE_H__ */