1 diff -urN linux/fs/aufs/aufs.h linux-aufs/fs/aufs/aufs.h
2 --- linux/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-aufs/fs/aufs/aufs.h 2009-03-12 16:18:04.000000000 +0100
6 + * Copyright (C) 2005-2009 Junjiro Okajima
8 + * This program, aufs is free software; you can redistribute it and/or modify
9 + * it under the terms of the GNU General Public License as published by
10 + * the Free Software Foundation; either version 2 of the License, or
11 + * (at your option) any later version.
13 + * This program is distributed in the hope that it will be useful,
14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 + * GNU General Public License for more details.
18 + * You should have received a copy of the GNU General Public License
19 + * along with this program; if not, write to the Free Software
20 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 +#include <linux/version.h>
35 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
36 +#error you got wrong version
39 +/* introduced in linux-2.6.27 */
40 +#include <linux/bug.h>
42 +#define WARN_ONCE(cond, fmt ...) WARN_ON(cond)
45 +/* ---------------------------------------------------------------------- */
65 +/* reserved for future use */
66 +/* #include "xattr.h" */
68 +#ifdef AuNoInlineForStack
69 +#undef noinline_for_stack
70 +#define noinline_for_stack /* */
73 +#endif /* __KERNEL__ */
74 +#endif /* __AUFS_H__ */
75 diff -urN linux/fs/aufs/branch.c linux-aufs/fs/aufs/branch.c
76 --- linux/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
77 +++ linux-aufs/fs/aufs/branch.c 2009-03-12 16:18:04.000000000 +0100
80 + * Copyright (C) 2005-2009 Junjiro Okajima
82 + * This program, aufs is free software; you can redistribute it and/or modify
83 + * it under the terms of the GNU General Public License as published by
84 + * the Free Software Foundation; either version 2 of the License, or
85 + * (at your option) any later version.
87 + * This program is distributed in the hope that it will be useful,
88 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
89 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90 + * GNU General Public License for more details.
92 + * You should have received a copy of the GNU General Public License
93 + * along with this program; if not, write to the Free Software
94 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
103 +#include <linux/iso_fs.h>
104 +#include <linux/loop.h>
105 +#include <linux/romfs_fs.h>
106 +#include <linux/smp_lock.h>
109 +static void au_br_do_free(struct au_branch *br)
112 + struct au_wbr *wbr;
116 + if (br->br_xino.xi_file)
117 + fput(br->br_xino.xi_file);
118 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
121 + for (i = 0; i < AuBrWh_Last; i++)
122 + dput(wbr->wbr_wh[i]);
123 + /* do not call au_br_nfs_lockdep_off() here */
124 + if (br->br_mnt && !au_test_nfs(br->br_mnt->mnt_sb))
125 + mntput(br->br_mnt);
128 + mntput(br->br_mnt);
131 + AuDebugOn(au_br_count(br));
133 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
134 + au_rwsem_destroy(&wbr->wbr_wh_rwsem);
141 + * frees all branches
143 +void au_br_free(struct au_sbinfo *sbinfo)
145 + aufs_bindex_t bmax;
146 + struct au_branch **br;
149 + bmax = sbinfo->si_bend + 1;
150 + br = sbinfo->si_branch;
152 + au_br_do_free(*br++);
156 + * find the index of a branch which is specified by @br_id.
158 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
160 + aufs_bindex_t bindex, bend;
164 + bend = au_sbend(sb);
165 + for (bindex = 0; bindex <= bend; bindex++)
166 + if (au_sbr_id(sb, bindex) == br_id)
172 + * test if the @h_sb is real-readonly.
174 +int au_test_def_rr(struct super_block *h_sb)
176 + switch (h_sb->s_magic) {
177 +#ifdef CONFIG_AUFS_RR_SQUASHFS
178 + case SQUASHFS_MAGIC_LZMA:
179 + case SQUASHFS_MAGIC:
180 + case SQUASHFS_MAGIC_LZMA_SWAP:
181 + case SQUASHFS_MAGIC_SWAP:
182 + return 1; /* real readonly */
185 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
186 + case ISOFS_SUPER_MAGIC:
190 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
195 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
205 +/* ---------------------------------------------------------------------- */
208 + * test if two hidden_dentries have overlapping branches.
210 +static int do_test_overlap(struct super_block *sb, struct dentry *h_d1,
211 + struct dentry *h_d2)
215 + LKTRTrace("%.*s, %.*s\n", AuDLNPair(h_d1), AuDLNPair(h_d2));
217 + d = au_test_subdir(h_d1, h_d2);
225 +static int test_overlap_loopback(struct super_block *sb, struct dentry *h_d1,
226 + struct dentry *h_d2)
228 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
229 + struct inode *h_inode;
230 + struct loop_device *l;
232 + LKTRTrace("%.*s, %.*s\n", AuDLNPair(h_d1), AuDLNPair(h_d2));
235 + AuDbgSb(h_d1->d_sb);
236 + AuDbgSb(h_d2->d_sb);
238 + h_inode = h_d1->d_inode;
239 + if (MAJOR(h_inode->i_sb->s_dev) != LOOP_MAJOR)
242 + l = h_inode->i_sb->s_bdev->bd_disk->private_data;
243 + h_d1 = l->lo_backing_file->f_dentry;
244 + /* h_d1 can be local NFS. in this case aufs cannot detect the loop */
247 + AuDbgSb(h_d1->d_sb);
248 + AuDbgSb(h_d2->d_sb);
249 + if (unlikely(h_d1->d_sb == sb))
251 + return do_test_overlap(sb, h_d1, h_d2);
257 +static int test_overlap(struct super_block *sb, struct dentry *h_d1,
258 + struct dentry *h_d2)
260 + LKTRTrace("d1 %.*s, d2 %.*s\n", AuDLNPair(h_d1), AuDLNPair(h_d2));
262 + if (unlikely(h_d1 == h_d2)) {
267 + return do_test_overlap(sb, h_d1, h_d2)
268 + || do_test_overlap(sb, h_d2, h_d1)
269 + || test_overlap_loopback(sb, h_d1, h_d2)
270 + || test_overlap_loopback(sb, h_d2, h_d1);
273 +/* ---------------------------------------------------------------------- */
275 +static int au_br_init_wh(struct super_block *sb, aufs_bindex_t bindex,
276 + struct au_branch *br, int new_perm,
277 + struct dentry *h_root, struct vfsmount *h_mnt)
280 + struct inode *h_dir;
281 + struct au_wbr *wbr;
283 + LKTRTrace("b%d, new_perm %d\n", bindex, new_perm);
284 + SiMustWriteLock(sb);
287 + h_dir = h_root->d_inode;
288 + old_perm = br->br_perm;
289 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
291 + wbr_wh_write_lock(wbr);
292 + br->br_perm = new_perm;
293 + err = au_wh_init(h_root, br, h_mnt, sb, bindex);
294 + br->br_perm = old_perm;
296 + wbr_wh_write_unlock(wbr);
297 + mutex_unlock(&h_dir->i_mutex);
298 + if (!err && wbr && !au_br_writable(new_perm)) {
299 + AuDebugOn(wbr->wbr_whbase);
300 + AuDebugOn(wbr->wbr_plink);
301 + AuDebugOn(wbr->wbr_tmp);
310 +/* ---------------------------------------------------------------------- */
313 + * returns a newly allocated branch. @new_nbranch is a number of branches
314 + * after adding a branch.
316 +static struct au_branch *alloc_addbr(struct super_block *sb, int new_nbranch,
319 + struct au_branch **branchp, *add_branch;
322 + struct dentry *root;
323 + struct inode *inode;
324 + struct au_hinode *hinodep;
325 + struct au_hdentry *hdentryp;
327 + LKTRTrace("new_nbranch %d\n", new_nbranch);
328 + SiMustWriteLock(sb);
330 + DiMustWriteLock(root);
331 + inode = root->d_inode;
332 + IiMustWriteLock(inode);
334 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
335 + if (unlikely(!add_branch))
337 + add_branch->br_wbr = NULL;
338 + if (au_br_writable(perm)) {
339 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
341 + if (unlikely(!add_branch->br_wbr))
345 + sz = sizeof(*branchp) * (new_nbranch - 1);
347 + sz = sizeof(*branchp);
348 + p = au_sbi(sb)->si_branch;
349 + branchp = au_kzrealloc(p, sz, sizeof(*branchp) * new_nbranch, GFP_NOFS);
350 + if (unlikely(!branchp))
352 + au_sbi(sb)->si_branch = branchp;
354 + sz = sizeof(*hdentryp) * (new_nbranch - 1);
356 + sz = sizeof(*hdentryp);
357 + p = au_di(root)->di_hdentry;
358 + hdentryp = au_kzrealloc(p, sz, sizeof(*hdentryp) * new_nbranch,
360 + if (unlikely(!hdentryp))
362 + au_di(root)->di_hdentry = hdentryp;
364 + sz = sizeof(*hinodep) * (new_nbranch - 1);
366 + sz = sizeof(*hinodep);
367 + p = au_ii(inode)->ii_hinode;
368 + hinodep = au_kzrealloc(p, sz, sizeof(*hinodep) * new_nbranch, GFP_NOFS);
369 + if (unlikely(!hinodep))
371 + au_ii(inode)->ii_hinode = hinodep;
372 + return add_branch; /* success */
375 + kfree(add_branch->br_wbr);
379 + AuTraceErr(-ENOMEM);
380 + return ERR_PTR(-ENOMEM);
384 + * test if the branch permission is legal or not.
386 +static int test_br(struct super_block *sb, struct inode *inode, int brperm,
392 + if (unlikely(au_br_writable(brperm) && IS_RDONLY(inode))) {
393 + AuErr("write permission for readonly fs or inode, %s\n", path);
401 +static int au_unsupported_fs(struct super_block *sb)
403 + return sb->s_magic == PROC_SUPER_MAGIC
405 + || sb->s_magic == SYSFS_MAGIC
407 + || !strcmp(au_sbtype(sb), "unionfs");
412 + * 0: success, the caller will add it
413 + * plus: success, it is already unified, the caller should ignore it
416 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
419 + struct dentry *root;
420 + struct inode *inode, *h_inode;
421 + aufs_bindex_t bend, bindex;
423 + LKTRTrace("%s, remo%d\n", add->path, remount);
426 + bend = au_sbend(sb);
427 + if (unlikely(bend >= 0
428 + && au_find_dbindex(root, add->nd.path.dentry) >= 0)) {
432 + AuErr("%s duplicated\n", add->path);
437 + err = -ENOSPC; /* -E2BIG; */
438 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
439 + || AUFS_BRANCH_MAX - 1 <= bend)) {
440 + AuErr("number of branches exceeded %s\n", add->path);
445 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
446 + AuErr("bad index %d\n", add->bindex);
450 + inode = add->nd.path.dentry->d_inode;
451 + AuDebugOn(!inode || !S_ISDIR(inode->i_mode));
453 + if (unlikely(!inode->i_nlink)) {
454 + AuErr("no existence %s\n", add->path);
459 + if (unlikely(inode->i_sb == sb)) {
460 + AuErr("%s must be outside\n", add->path);
464 + if (unlikely(au_test_nested(inode->i_sb))) {
465 + AuErr("nested " AUFS_NAME " %s\n", add->path);
469 + if (unlikely(au_unsupported_fs(inode->i_sb))) {
470 + AuErr("unsupported filesystem, %s\n", add->path);
474 + if (unlikely(au_test_unsupported_nfs(inode->i_sb))) {
475 + AuErr(AuNoNfsBranchMsg " %s\n", add->path);
479 + if (unlikely(au_test_unsupported_nfs4(inode->i_sb))) {
480 + AuErr(AuNoNfsv4BranchMsg " %s\n", add->path);
484 + err = test_br(sb, add->nd.path.dentry->d_inode, add->perm, add->path);
489 + return 0; /* success */
492 + for (bindex = 0; bindex <= bend; bindex++)
493 + if (unlikely(test_overlap(sb, add->nd.path.dentry,
494 + au_h_dptr(root, bindex)))) {
495 + AuErr("%s is overlapped\n", add->path);
500 + h_inode = au_h_dptr(root, 0)->d_inode;
501 + if (unlikely(au_opt_test(au_mntflags(sb), WARN_PERM)
502 + && ((h_inode->i_mode & S_IALLUGO)
503 + != (inode->i_mode & S_IALLUGO)
504 + || h_inode->i_uid != inode->i_uid
505 + || h_inode->i_gid != inode->i_gid)))
506 + AuWarn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
508 + inode->i_uid, inode->i_gid, (inode->i_mode & S_IALLUGO),
509 + h_inode->i_uid, h_inode->i_gid,
510 + (h_inode->i_mode & S_IALLUGO));
517 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
518 + int perm, struct path *path)
521 + struct au_wbr *wbr;
527 + au_rw_init_nolock(&wbr->wbr_wh_rwsem);
528 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
529 + atomic_set(&wbr->wbr_wh_running, 0);
530 + wbr->wbr_bytes = 0;
532 + err = au_br_init_wh(sb, /*bindex*/-1, br, perm,
533 + path->dentry, path->mnt);
539 +static int au_br_init(struct au_branch *br, struct super_block *sb,
540 + struct au_opt_add *add)
543 + unsigned int mnt_flags;
549 + br->br_xino.xi_file = NULL;
550 + mutex_init(&br->br_xino.xi_nondir_mtx);
551 + atomic_set(&br->br_xino_running, 0);
552 + atomic_set(&br->br_count, 0);
554 + if (au_br_writable(add->perm)) {
555 + err = au_wbr_init(br, sb, add->perm, &add->nd.path);
560 + br->br_mnt = mntget(add->nd.path.mnt);
561 + mnt_flags = au_mntflags(sb);
562 + if (au_opt_test(mnt_flags, XINO)) {
563 + err = au_xino_br(sb, br, add->nd.path.dentry->d_inode->i_ino,
564 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
565 + if (unlikely(err)) {
566 + AuDebugOn(br->br_xino.xi_file);
569 +#if 0 /* reserved for future use */
570 + } else if (au_opt_test(mnt_flags, XINODIR)) {
571 + err = au_xinodir_br(sb, br, add->nd.path.dentry->d_inode->i_ino,
573 + if (unlikely(err)) {
574 + AuDebugOn(br->br_xino.xi_file);
580 + br->br_id = au_new_br_id(sb);
581 + br->br_perm = add->perm;
582 + br->br_xino_upper = AUFS_XINO_TRUNC_INIT;
583 + sysaufs_br_init(br);
584 + br->br_generation = au_sigen(sb);
585 + /* smp_mb(); */ /* atomic_set */
592 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
595 + aufs_bindex_t bend, add_bindex;
596 + struct dentry *root, *dentry;
597 + struct au_iinfo *iinfo;
598 + struct au_sbinfo *sbinfo;
599 + struct au_dinfo *dinfo;
600 + struct inode *root_inode;
601 + unsigned long long maxb;
602 + struct au_branch **branchp, *add_branch;
603 + struct au_hdentry *hdentryp;
604 + struct au_hinode *hinodep;
606 + dentry = add->nd.path.dentry;
607 + LKTRTrace("b%d, %s, 0x%x, %.*s\n",
608 + add->bindex, add->path, add->perm, AuDLNPair(dentry));
609 + SiMustWriteLock(sb);
611 + DiMustWriteLock(root);
612 + root_inode = root->d_inode;
613 + IMustLock(root_inode);
614 + IiMustWriteLock(root_inode);
616 + err = test_add(sb, add, remount);
617 + if (unlikely(err < 0))
621 + goto out; /* success */
624 + bend = au_sbend(sb);
625 + add_branch = alloc_addbr(sb, bend + 2, add->perm);
626 + err = PTR_ERR(add_branch);
627 + if (IS_ERR(add_branch))
629 + err = au_br_init(add_branch, sb, add);
630 + if (unlikely(err)) {
631 + au_br_do_free(add_branch);
635 + add_bindex = add->bindex;
637 + sysaufs_brs_del(sb, add_bindex);
639 + sbinfo = au_sbi(sb);
640 + dinfo = au_di(root);
641 + iinfo = au_ii(root_inode);
643 + amount = bend + 1 - add_bindex;
644 + branchp = sbinfo->si_branch + add_bindex;
645 + memmove(branchp + 1, branchp, sizeof(*branchp) * amount);
646 + *branchp = add_branch;
647 + hdentryp = dinfo->di_hdentry + add_bindex;
648 + memmove(hdentryp + 1, hdentryp, sizeof(*hdentryp) * amount);
649 + au_h_dentry_init(hdentryp);
650 + hinodep = iinfo->ii_hinode + add_bindex;
651 + memmove(hinodep + 1, hinodep, sizeof(*hinodep) * amount);
652 + hinodep->hi_inode = NULL;
653 + au_hin_init(hinodep, NULL);
658 + if (unlikely(bend < 0)) {
659 + sbinfo->si_bend = 0;
660 + dinfo->di_bstart = 0;
661 + iinfo->ii_bstart = 0;
663 + au_set_h_dptr(root, add_bindex, dget(dentry));
664 + au_set_h_iptr(root_inode, add_bindex, au_igrab(dentry->d_inode), 0);
666 + sysaufs_brs_add(sb, add_bindex);
669 + au_cpup_attr_all(root_inode, /*force*/1);
671 + au_add_nlink(root_inode, dentry->d_inode);
672 + maxb = dentry->d_sb->s_maxbytes;
673 + if (sb->s_maxbytes < maxb)
674 + sb->s_maxbytes = maxb;
676 + /* safe d_parent reference */
677 + if (!au_xino_def_br(sbinfo)
678 + && add_branch->br_xino.xi_file
679 + && add_branch->br_xino.xi_file->f_dentry->d_parent == dentry)
680 + au_xino_def_br_set(add_branch, sbinfo);
687 +/* ---------------------------------------------------------------------- */
689 +#define AuVerbose(do_info, fmt, args...) do { \
691 + LKTRTrace(fmt, ##args); \
693 + AuInfo(fmt, ##args); \
697 + * test if the branch is deletable or not.
699 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
702 + int err, i, j, ndentry;
703 + struct au_dcsub_pages dpages;
704 + struct au_dpage *dpage;
706 + aufs_bindex_t bstart, bend;
707 + unsigned char verbose;
708 + struct inode *inode;
710 + LKTRTrace("b%d, gen%d\n", bindex, sigen);
711 + SiMustWriteLock(root->d_sb);
713 + err = au_dpages_init(&dpages, GFP_NOFS);
716 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
720 + verbose = !!au_opt_test(au_mntflags(root->d_sb), VERBOSE);
721 + for (i = 0; !err && i < dpages.ndpage; i++) {
722 + dpage = dpages.dpages + i;
723 + ndentry = dpage->ndentry;
724 + for (j = 0; !err && j < ndentry; j++) {
725 + d = dpage->dentries[j];
726 + AuDebugOn(!atomic_read(&d->d_count));
727 + inode = d->d_inode;
729 + if (au_digen(d) == sigen
730 + && au_iigen(inode) == sigen)
731 + di_read_lock_child(d, AuLock_IR);
733 + di_write_lock_child(d);
734 + err = au_reval_dpath(d, sigen);
736 + di_downgrade_lock(d, AuLock_IR);
738 + di_write_unlock(d);
743 + bstart = au_dbstart(d);
744 + bend = au_dbend(d);
745 + if (bstart <= bindex
747 + && au_h_dptr(d, bindex)
748 + && (!S_ISDIR(d->d_inode->i_mode)
749 + || bstart == bend)) {
751 + AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
753 + di_read_unlock(d, AuLock_IR);
758 + au_dpages_free(&dpages);
764 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
769 + aufs_bindex_t bstart, bend;
770 + unsigned char verbose;
772 + LKTRTrace("b%d, gen%d\n", bindex, sigen);
773 + SiMustWriteLock(sb);
776 + verbose = !!au_opt_test(au_mntflags(sb), VERBOSE);
777 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
778 + AuDebugOn(!atomic_read(&i->i_count));
779 + if (!list_empty(&i->i_dentry))
782 + if (au_iigen(i) == sigen)
783 + ii_read_lock_child(i);
785 + ii_write_lock_child(i);
786 + err = au_refresh_hinode_self(i);
788 + ii_downgrade_lock(i);
790 + ii_write_unlock(i);
795 + bstart = au_ibstart(i);
796 + bend = au_ibend(i);
797 + if (bstart <= bindex
799 + && au_h_iptr(i, bindex)
800 + && (!S_ISDIR(i->i_mode) || bstart == bend)) {
802 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
813 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex)
818 + LKTRTrace("b%d\n", bindex);
819 + SiMustWriteLock(root->d_sb);
820 + DiMustWriteLock(root);
821 + /* dont trust BKL */
822 + AuDebugOn(!kernel_locked());
824 + sigen = au_sigen(root->d_sb);
825 + DiMustNoWaiters(root);
826 + IiMustNoWaiters(root->d_inode);
827 + di_write_unlock(root);
828 + err = test_dentry_busy(root, bindex, sigen);
830 + err = test_inode_busy(root->d_sb, bindex, sigen);
831 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
837 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
840 + aufs_bindex_t bindex, bend, br_id;
841 + unsigned char do_wh, verbose;
842 + struct au_sbinfo *sbinfo;
843 + struct au_dinfo *dinfo;
844 + struct au_iinfo *iinfo;
845 + struct au_branch *br, **brp;
846 + struct au_wbr *wbr;
847 + struct au_hdentry *hdp;
848 + struct au_hinode *hip;
850 + LKTRTrace("%s, %.*s\n", del->path, AuDLNPair(del->h_root));
851 + SiMustWriteLock(sb);
852 + DiMustWriteLock(sb->s_root);
853 + IiMustWriteLock(sb->s_root->d_inode);
856 + bindex = au_find_dbindex(sb->s_root, del->h_root);
859 + goto out; /* success */
861 + AuErr("%s no such branch\n", del->path);
864 + LKTRTrace("bindex b%d\n", bindex);
867 + verbose = !!au_opt_test(au_mntflags(sb), VERBOSE);
868 + bend = au_sbend(sb);
869 + if (unlikely(!bend)) {
870 + AuVerbose(verbose, "no more branches left\n");
873 + br = au_sbr(sb, bindex);
874 + if (unlikely(au_br_count(br))) {
875 + AuVerbose(verbose, "%d file(s) opened\n", au_br_count(br));
880 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_tmp);
882 +#if 0 /* reserved for future use */
883 + /* remove whiteout base */
884 + err = au_br_init_wh(sb, bindex, br, AuBr_RO, del->h_root,
889 + for (i = 0; i < AuBrWh_Last; i++) {
890 + dput(wbr->wbr_wh[i]);
891 + wbr->wbr_wh[i] = NULL;
896 + err = test_children_busy(sb->s_root, bindex);
897 + if (unlikely(err)) {
905 + sysaufs_brs_del(sb, bindex);
906 + sbinfo = au_sbi(sb);
907 + dinfo = au_di(sb->s_root);
908 + iinfo = au_ii(sb->s_root->d_inode);
910 + dput(au_h_dptr(sb->s_root, bindex));
911 + au_hiput(iinfo->ii_hinode + bindex);
915 + /* todo: realloc and shrink memory? */
916 + if (bindex < bend) {
917 + const aufs_bindex_t n = bend - bindex;
919 + brp = sbinfo->si_branch + bindex;
920 + memmove(brp, brp + 1, sizeof(*brp) * n);
921 + hdp = dinfo->di_hdentry + bindex;
922 + memmove(hdp, hdp + 1, sizeof(*hdp) * n);
923 + hip = iinfo->ii_hinode + bindex;
924 + memmove(hip, hip + 1, sizeof(*hip) * n);
926 + sbinfo->si_branch[0 + bend] = NULL;
927 + dinfo->di_hdentry[0 + bend].hd_dentry = NULL;
928 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
929 + au_hin_init(iinfo->ii_hinode + bend, NULL);
935 + sysaufs_brs_add(sb, bindex);
938 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
940 + au_sub_nlink(sb->s_root->d_inode, del->h_root->d_inode);
941 + if (au_opt_test(au_mntflags(sb), PLINK))
942 + au_plink_half_refresh(sb, br_id);
944 + if (sb->s_maxbytes == del->h_root->d_sb->s_maxbytes) {
946 + sb->s_maxbytes = 0;
947 + for (bindex = 0; bindex <= bend; bindex++) {
948 + unsigned long long maxb;
949 + maxb = au_sbr_sb(sb, bindex)->s_maxbytes;
950 + if (sb->s_maxbytes < maxb)
951 + sb->s_maxbytes = maxb;
955 + if (au_xino_def_br(sbinfo) == br)
956 + au_xino_def_br_set(NULL, sbinfo);
957 + goto out; /* success */
961 + rerr = au_br_init_wh(sb, bindex, br, br->br_perm, del->h_root,
964 + AuWarn("failed re-creating base whiteout, %s. (%d)\n",
971 +static int do_need_sigen_inc(int a, int b)
973 + return au_br_whable(a) && !au_br_whable(b);
976 +static int need_sigen_inc(int old, int new)
978 + return do_need_sigen_inc(old, new)
979 + || do_need_sigen_inc(new, old);
982 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
985 + struct file *file, *hf;
988 + SiMustWriteLock(sb);
990 + /* no need file_list_lock() since sbinfo is locked */
992 + list_for_each_entry(file, &sb->s_files, f_u.fu_list) {
993 + LKTRTrace("%.*s\n", AuDLNPair(file->f_dentry));
994 + if (!au_test_aufs_file(file))
997 + fi_read_lock(file);
998 + if (!S_ISREG(file->f_dentry->d_inode->i_mode)
999 + || !(file->f_mode & FMODE_WRITE)
1000 + || au_fbstart(file) != bindex) {
1001 + FiMustNoWaiters(file);
1002 + fi_read_unlock(file);
1006 + if (unlikely(au_test_mmapped(file))) {
1008 + FiMustNoWaiters(file);
1009 + fi_read_unlock(file);
1013 + /* todo: already flushed? */
1014 + hf = au_h_fptr(file, au_fbstart(file));
1015 + hf->f_flags = au_file_roflags(hf->f_flags);
1016 + hf->f_mode &= ~FMODE_WRITE;
1017 + put_write_access(hf->f_dentry->d_inode);
1018 + FiMustNoWaiters(file);
1019 + fi_read_unlock(file);
1026 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
1030 + struct dentry *root;
1031 + aufs_bindex_t bindex;
1032 + struct au_branch *br;
1033 + struct inode *hidden_dir;
1035 + LKTRTrace("%s, %.*s, 0x%x\n",
1036 + mod->path, AuDLNPair(mod->h_root), mod->perm);
1037 + SiMustWriteLock(sb);
1038 + root = sb->s_root;
1039 + DiMustWriteLock(root);
1040 + IiMustWriteLock(root->d_inode);
1042 + bindex = au_find_dbindex(root, mod->h_root);
1045 + return 0; /* success */
1047 + AuErr("%s no such branch\n", mod->path);
1050 + LKTRTrace("bindex b%d\n", bindex);
1052 + hidden_dir = mod->h_root->d_inode;
1053 + err = test_br(sb, hidden_dir, mod->perm, mod->path);
1054 + if (unlikely(err))
1057 + br = au_sbr(sb, bindex);
1058 + if (br->br_perm == mod->perm)
1059 + return 0; /* success */
1061 + if (au_br_writable(br->br_perm)) {
1063 + /* remove whiteout base */
1064 + err = au_br_init_wh(sb, bindex, br, mod->perm, mod->h_root,
1066 + if (unlikely(err))
1068 +#else /* reserved for future use */
1069 + struct au_wbr *wbr;
1072 + for (i = 0; i < AuBrWh_Last; i++) {
1073 + dput(wbr->wbr_wh[i]);
1074 + wbr->wbr_wh[i] = NULL;
1078 + if (!au_br_writable(mod->perm)) {
1079 + /* rw --> ro, file might be mmapped */
1081 +#if 1 /* todo: test more? */
1082 + DiMustNoWaiters(root);
1083 + IiMustNoWaiters(root->d_inode);
1084 + di_write_unlock(root);
1085 + err = au_br_mod_files_ro(sb, bindex);
1086 + /* aufs_write_lock() calls ..._child() */
1087 + di_write_lock_child(root);
1090 + } else if (au_br_writable(mod->perm)) {
1093 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
1095 + struct path path = {
1096 + .mnt = br->br_mnt,
1097 + .dentry = mod->h_root
1100 + err = au_wbr_init(br, sb, mod->perm, &path);
1101 + if (unlikely(err)) {
1102 + kfree(br->br_wbr);
1103 + br->br_wbr = NULL;
1109 + *do_update |= need_sigen_inc(br->br_perm, mod->perm);
1110 + br->br_perm = mod->perm;
1117 diff -urN linux/fs/aufs/branch.h linux-aufs/fs/aufs/branch.h
1118 --- linux/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
1119 +++ linux-aufs/fs/aufs/branch.h 2009-03-12 16:18:04.000000000 +0100
1122 + * Copyright (C) 2005-2009 Junjiro Okajima
1124 + * This program, aufs is free software; you can redistribute it and/or modify
1125 + * it under the terms of the GNU General Public License as published by
1126 + * the Free Software Foundation; either version 2 of the License, or
1127 + * (at your option) any later version.
1129 + * This program is distributed in the hope that it will be useful,
1130 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1131 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1132 + * GNU General Public License for more details.
1134 + * You should have received a copy of the GNU General Public License
1135 + * along with this program; if not, write to the Free Software
1136 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1140 + * branch filesystems and xino for them
1145 +#ifndef __AUFS_BRANCH_H__
1146 +#define __AUFS_BRANCH_H__
1150 +#include <linux/fs.h>
1151 +#include <linux/mount.h>
1152 +#include <linux/sysfs.h>
1153 +#include <linux/aufs_type.h>
1157 +/* ---------------------------------------------------------------------- */
1159 +/* an entry in a xino file */
1160 +struct au_xino_entry {
1162 + /* __u32 h_gen; */ /* reserved for future use */
1165 +/* reserved for future use */
1166 +/* #define AuXino_INVALID_HGEN (-1) */
1169 +struct au_xino_file {
1170 + struct file *xi_file;
1171 + struct mutex xi_nondir_mtx;
1173 + /* reserved for future use */
1175 + struct file **xi_file;
1177 + /* array management */
1178 + unsigned long long xi_limit; /* Max xino file size */
1179 + unsigned long long xi_size; /* s_maxbytes */
1182 + unsigned long long xi_upper; /* watermark in bytes */
1183 + unsigned long long xi_step; /* to next watermark in bytes */
1186 + blkcnt_t xi_upper; /* watermark in blocks */
1187 + atomic_t xi_running;
1191 +/* members for writable branch only */
1192 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_TMP, AuBrWh_Last};
1194 + struct au_rwsem wbr_wh_rwsem;
1195 + struct dentry *wbr_wh[AuBrWh_Last];
1196 + atomic_t wbr_wh_running;
1197 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
1198 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
1199 +#define wbr_tmp wbr_wh[AuBrWh_TMP] /* temporary dir */
1202 + unsigned long long wbr_bytes;
1205 +/* protected by superblock rwsem */
1207 + struct au_xino_file br_xino;
1209 + aufs_bindex_t br_id;
1212 + struct vfsmount *br_mnt;
1213 + atomic_t br_count;
1215 + struct au_wbr *br_wbr;
1217 +#if 1 /* reserved for future use */
1218 + /* xino truncation */
1219 + blkcnt_t br_xino_upper; /* watermark in blocks */
1220 + atomic_t br_xino_running;
1223 +#ifdef CONFIG_SYSFS
1224 + /* an entry under sysfs per mount-point */
1226 + struct attribute br_attr;
1229 + au_gen_t br_generation;
1232 +/* ---------------------------------------------------------------------- */
1234 +/* branch permission and attribute */
1236 + AuBrPerm_RW, /* writable, linkable wh */
1237 + AuBrPerm_RO, /* readonly, no wh */
1238 + AuBrPerm_RR, /* natively readonly, no wh */
1240 + AuBrPerm_RWNoLinkWH, /* un-linkable whiteouts */
1243 + AuBrPerm_RRWH, /* whiteout-able */
1248 +static inline int au_br_writable(int brperm)
1250 + return brperm == AuBrPerm_RW || brperm == AuBrPerm_RWNoLinkWH;
1253 +static inline int au_br_whable(int brperm)
1255 + return brperm == AuBrPerm_RW
1256 + || brperm == AuBrPerm_ROWH
1257 + || brperm == AuBrPerm_RRWH;
1260 +#if 0 /* reserved for future use */
1261 +static inline int au_br_linkable_wh(int brperm)
1263 + return brperm == AuBrPerm_RW;
1267 +static inline int au_br_hinotifyable(int brperm)
1269 +#ifdef CONFIG_AUFS_HINOTIFY
1270 + return brperm != AuBrPerm_RR && brperm != AuBrPerm_RRWH;
1276 +/* ---------------------------------------------------------------------- */
1280 +void au_br_free(struct au_sbinfo *sinfo);
1281 +int au_test_def_rr(struct super_block *h_sb);
1282 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
1284 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
1286 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
1288 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
1292 +#define Au_LOFF_MAX ((loff_t)LLONG_MAX)
1293 +int au_xib_trunc(struct super_block *sb);
1294 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
1296 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
1298 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
1299 +struct file *au_xino_create2(struct super_block *sb, struct file *base_file,
1300 + struct file *copy_src);
1301 +ino_t au_xino_new_ino(struct super_block *sb);
1302 +int au_xino_write0(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
1304 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
1305 + struct au_xino_entry *xinoe);
1306 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
1307 + struct au_xino_entry *xinoe);
1308 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
1309 + struct file *base_file, int do_test);
1310 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
1312 +struct au_opt_xino;
1313 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
1314 +void au_xino_clr(struct super_block *sb);
1315 +struct file *au_xino_def(struct super_block *sb);
1317 +struct au_opt_xinodir;
1318 +#if 0 /* def CONFIG_AUFS_EXPORT */ /* reserved for future use */
1320 +int au_xinodir_br(struct super_block *sb, struct au_branch *br, ino_t hino,
1322 +int au_xinodir_set(struct super_block *sb, struct au_opt_xinodir *xinodir,
1326 +int au_xinodir_br(struct super_block *sb, struct au_branch *br, ino_t hino,
1333 +int au_xinodir_set(struct super_block *sb, struct au_opt_xinodir *xinodir,
1340 +/* ---------------------------------------------------------------------- */
1342 +/* todo: memory barrier? */
1343 +static inline int au_br_count(struct au_branch *br)
1345 + return atomic_read(&br->br_count);
1348 +static inline int au_br_get(struct au_branch *br)
1350 + return atomic_inc_return(&br->br_count);
1353 +static inline int au_br_put(struct au_branch *br)
1355 + return atomic_dec_return(&br->br_count);
1358 +static inline au_gen_t au_br_gen(struct au_branch *br)
1360 + return br->br_generation;
1364 + * test if the @br is readonly or not.
1366 +static inline int au_br_rdonly(struct au_branch *br)
1368 + return ((br->br_mnt->mnt_sb->s_flags & MS_RDONLY)
1369 + || !au_br_writable(br->br_perm))
1373 +/* ---------------------------------------------------------------------- */
1375 +/* Superblock to branch */
1377 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
1379 + return au_sbr(sb, bindex)->br_id;
1383 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
1385 + return au_sbr(sb, bindex)->br_mnt;
1389 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
1391 + return au_sbr_mnt(sb, bindex)->mnt_sb;
1394 +#if 0 /* reserved for future use */
1395 +static inline int au_sbr_count(struct super_block *sb, aufs_bindex_t bindex)
1397 + return au_br_count(au_sbr(sb, bindex));
1400 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
1402 + au_br_get(au_sbr(sb, bindex));
1406 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
1408 + au_br_put(au_sbr(sb, bindex));
1411 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
1413 + return au_sbr(sb, bindex)->br_perm;
1416 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
1418 + return au_br_whable(au_sbr_perm(sb, bindex));
1421 +static inline int au_br_want_write(struct au_branch *br)
1425 + AuDebugOn(!au_br_writable(br->br_perm));
1426 + err = au_mnt_want_write(br->br_mnt);
1431 +static inline void au_br_drop_write(struct au_branch *br)
1433 + AuDebugOn(!au_br_writable(br->br_perm));
1434 + au_mnt_drop_write(br->br_mnt);
1437 +static inline int au_test_trunc_xino(struct super_block *sb)
1439 + return au_test_tmpfs(sb);
1442 +/* temporary support for i#1 in cramfs */
1443 +static inline int au_test_unique_ino(struct dentry *h_dentry, ino_t h_ino)
1445 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
1446 + if (unlikely(h_dentry->d_sb->s_magic == CRAMFS_MAGIC))
1447 + return h_ino != 1;
1452 +static inline struct vfsmount *au_do_nfsmnt(struct vfsmount *h_mnt)
1454 + if (!au_test_nfs(h_mnt->mnt_sb)
1455 + && !au_test_ecryptfs(h_mnt->mnt_sb))
1460 +static inline void au_br_nfs_lockdep_off(struct super_block *sb)
1462 + if (au_test_nfs(sb))
1466 +static inline void au_br_nfs_lockdep_on(struct super_block *sb)
1468 + /* hoping this condition will be optimized... */
1469 + if (au_test_nfs(sb))
1473 +#ifdef CONFIG_AUFS_BR_NFS
1474 +static inline int au_test_unsupported_nfs(struct super_block *h_sb)
1479 +/* it doesn't mntget() */
1481 +struct vfsmount *au_nfsmnt(struct super_block *sb, aufs_bindex_t bindex)
1483 + return au_do_nfsmnt(au_sbr_mnt(sb, bindex));
1486 +#define AuNoNfsBranchMsg "dummy"
1489 +static inline int au_test_unsupported_nfs(struct super_block *h_sb)
1491 + return h_sb->s_magic == NFS_SUPER_MAGIC;
1494 +/* it doesn't mntget() */
1496 +struct vfsmount *au_nfsmnt(struct super_block *sb, aufs_bindex_t bindex)
1501 +#define AuNoNfsBranchMsg "NFS branch is not supported" \
1502 + ", try some configurations and patches included in aufs source CVS."
1504 +#endif /* CONFIG_AUFS_BR_NFS */
1506 +#ifdef CONFIG_AUFS_BR_NFS_V4
1507 +static inline int au_test_unsupported_nfs4(struct super_block *h_sb)
1512 +#define AuNoNfsv4BranchMsg "dummy"
1515 +static inline int au_test_unsupported_nfs4(struct super_block *h_sb)
1517 + return h_sb->s_magic == NFS_SUPER_MAGIC
1518 + && !strcmp(h_sb->s_type->name, "nfs4");
1521 +#define AuNoNfsv4BranchMsg "NFSv4 branch is not supported" \
1522 + ", try some configurations and patches included in aufs source CVS."
1524 +#endif /* CONFIG_AUFS_BR_NFS_v4 */
1526 +/* support atomic open */
1527 +static inline int au_test_fs_intent(struct super_block *h_sb)
1529 + return au_test_nfs4(h_sb) /*|| au_test_fuse(h_sb)*/;
1532 +/* ---------------------------------------------------------------------- */
1535 + * br_wh_read_lock, br_wh_write_lock
1536 + * br_wh_read_unlock, br_wh_write_unlock, br_wh_downgrade_lock
1538 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, wbr->wbr_wh_rwsem);
1540 +/* to debug easier, do not make them inlined functions */
1541 +#define WbrWhMustReadLock(wbr) do { \
1542 + /* SiMustAnyLock(sb); */ \
1543 + AuRwMustReadLock(&(wbr)->wbr_wh_rwsem); \
1546 +#define WbrWhMustWriteLock(wbr) do { \
1547 + /* SiMustAnyLock(sb); */ \
1548 + AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem); \
1551 +#define WbrWhMustAnyLock(br) do { \
1552 + /* SiMustAnyLock(sb); */ \
1553 + AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem); \
1556 +#endif /* __KERNEL__ */
1557 +#endif /* __AUFS_BRANCH_H__ */
1558 diff -urN linux/fs/aufs/br_fuse.c linux-aufs/fs/aufs/br_fuse.c
1559 --- linux/fs/aufs/br_fuse.c 1970-01-01 01:00:00.000000000 +0100
1560 +++ linux-aufs/fs/aufs/br_fuse.c 2009-03-12 16:18:04.000000000 +0100
1563 + * Copyright (C) 2005-2009 Junjiro Okajima
1565 + * This program, aufs is free software; you can redistribute it and/or modify
1566 + * it under the terms of the GNU General Public License as published by
1567 + * the Free Software Foundation; either version 2 of the License, or
1568 + * (at your option) any later version.
1570 + * This program is distributed in the hope that it will be useful,
1571 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1572 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1573 + * GNU General Public License for more details.
1575 + * You should have received a copy of the GNU General Public License
1576 + * along with this program; if not, write to the Free Software
1577 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1581 + * special handling for inode attributes on FUSE branch
1588 +/* h_mnt can be NULL, is it safe? */
1589 +int au_update_fuse_h_inode(struct vfsmount *h_mnt, struct dentry *h_dentry)
1594 + LKTRTrace("%.*s\n", AuDLNPair(h_dentry));
1597 + if (h_dentry->d_inode
1598 + /* && atomic_read(&h_dentry->d_inode->i_count) */
1599 + && au_test_fuse(h_dentry->d_sb)) {
1600 + err = vfsub_getattr(h_mnt, h_dentry, &st, /*dlgt*/0);
1601 + if (unlikely(err)) {
1602 + AuDbg("err %d\n", err);
1604 + AuDbgDentry(h_dentry);
1614 + * This function was born after a discussion with the FUSE developer.
1615 + * The inode attributes on a filesystem who defines i_op->getattr()
1616 + * is unreliable since such fs may not maintain the attributes at lookup.
1617 + * This function doesn't want the result of stat, instead wants the side-effect
1618 + * which refreshes the attributes.
1619 + * Hmm, there seems to be no such filesystem except fuse.
1621 +int vfsub_i_attr(struct vfsmount *mnt, struct dentry *dentry, int dlgt)
1624 + struct inode *inode;
1625 + struct inode_operations *op;
1628 + inode = dentry->d_inode;
1629 + AuDebugOn(!inode);
1633 + if (op && op->getattr && !au_test_aufs(dentry->d_sb)) {
1634 + err = security_inode_getattr(mnt, dentry);
1636 + err = op->getattr(mnt, dentry, &st);
1642 diff -urN linux/fs/aufs/br_nfs.c linux-aufs/fs/aufs/br_nfs.c
1643 --- linux/fs/aufs/br_nfs.c 1970-01-01 01:00:00.000000000 +0100
1644 +++ linux-aufs/fs/aufs/br_nfs.c 2009-03-12 16:18:04.000000000 +0100
1647 + * Copyright (C) 2005-2009 Junjiro Okajima
1649 + * This program, aufs is free software; you can redistribute it and/or modify
1650 + * it under the terms of the GNU General Public License as published by
1651 + * the Free Software Foundation; either version 2 of the License, or
1652 + * (at your option) any later version.
1654 + * This program is distributed in the hope that it will be useful,
1655 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1656 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1657 + * GNU General Public License for more details.
1659 + * You should have received a copy of the GNU General Public License
1660 + * along with this program; if not, write to the Free Software
1661 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1665 + * lookup functions for NFS branch in linux-2.6.19 and later
1672 +static struct file *au_find_h_intent(struct au_hdentry *hd, struct file *file)
1674 + struct file *h_file, *hf;
1675 + struct au_hdintent *hdi, *tmp, *do_free;
1677 + LKTRTrace("%.*s\n", AuDLNPair(hd->hd_dentry));
1681 + spin_lock(&hd->hd_lock);
1682 + list_for_each_entry_safe(hdi, tmp, hd->hd_intent_list, hdi_list) {
1683 + hf = hdi->hdi_file[AuIntent_BRANCH];
1684 + if (hdi->hdi_file[AuIntent_AUFS] == file
1685 + && hf->f_dentry == hd->hd_dentry) {
1688 + list_del(&hdi->hdi_list);
1692 + spin_unlock(&hd->hd_lock);
1698 +struct file *au_h_intent(struct dentry *dentry, aufs_bindex_t bindex,
1699 + struct file *file)
1701 + struct file *h_file;
1702 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
1704 + LKTRTrace("%.*s, b%d, f %p\n", AuDLNPair(dentry), bindex, file);
1705 + DiMustAnyLock(dentry);
1706 + AuDebugOn(bindex < au_di(dentry)->di_bstart
1707 + || bindex > au_di(dentry)->di_bend);
1710 + if (!hd->hd_intent_list || !file)
1711 + return h_file; /* success */
1713 + /* AuDebugOn(au_test_wkq(current)); */
1714 + h_file = au_find_h_intent(hd, file);
1718 +static int au_set_h_intent(struct dentry *dentry, aufs_bindex_t bindex,
1719 + struct file *file, struct file *h_file)
1722 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
1723 + struct au_hdintent *hdi;
1726 + LKTRTrace("%.*s, b%d, f %p\n", AuDLNPair(dentry), bindex, file);
1727 + /* d_revalidate() holds read_lock */
1728 + /* DiMustWriteLock(dentry); */
1729 + AuDebugOn(bindex < au_di(dentry)->di_bstart
1730 + || bindex > au_di(dentry)->di_bend
1733 + /* || au_test_wkq(current) */);
1736 + if (hd->hd_intent_list) {
1738 + hf = au_find_h_intent(hd, file);
1742 + AuWarn("freed hfile %.*s b%d left\n",
1743 + AuDLNPair(dentry), bindex);
1746 + spin_lock(&hd->hd_lock);
1747 + if (!hd->hd_intent_list) {
1748 + hd->hd_intent_list
1749 + = kmalloc(sizeof(*hd->hd_intent_list),
1751 + if (unlikely(!hd->hd_intent_list)) {
1752 + spin_unlock(&hd->hd_lock);
1755 + INIT_LIST_HEAD(hd->hd_intent_list);
1757 + spin_unlock(&hd->hd_lock);
1760 + hdi = kmalloc(sizeof(*hdi), GFP_NOFS);
1761 + if (unlikely(!hdi))
1765 + /* hdi->hdi_pid = current->pid; */
1766 + hdi->hdi_file[AuIntent_AUFS] = file;
1767 + hdi->hdi_file[AuIntent_BRANCH] = h_file;
1768 + spin_lock(&hd->hd_lock);
1769 + list_add(&hdi->hdi_list, hd->hd_intent_list);
1770 + spin_unlock(&hd->hd_lock);
1777 +int au_br_nfs_h_intent(struct file *nd_file, struct dentry *dentry,
1778 + aufs_bindex_t bindex, struct nameidata *nd)
1789 + err = au_set_h_intent(dentry, bindex, nd->intent.open.file, nd_file);
1790 + if (unlikely(err)) {
1792 + au_set_h_dptr(dentry, bindex, NULL);
1793 + /* todo: update bstart and bend? */
1801 +/* ---------------------------------------------------------------------- */
1803 +void au_hintent_put(struct au_hdentry *hd, int do_free)
1805 + struct au_hdintent *hdi, *tmp;
1808 + if (hd->hd_intent_list) {
1809 + /* no spin lock */
1810 + list_for_each_entry_safe(hdi, tmp, hd->hd_intent_list,
1812 + LKTRTrace("hdi %p\n", hdi);
1813 + hf = hdi->hdi_file[AuIntent_BRANCH];
1816 + /* list_del(&hdi->hdi_list); */
1820 + kfree(hd->hd_intent_list);
1824 +/* ---------------------------------------------------------------------- */
1826 +int au_fake_intent(/* struct au_ndsub *save, */struct nameidata *nd,
1827 + struct au_branch *br)
1831 + LKTRTrace("perm %d\n", br->br_perm);
1834 + nd->intent.open.file = NULL;
1835 + if (nd->flags & LOOKUP_OPEN) {
1836 + if (au_test_fs_intent(br->br_mnt->mnt_sb)) {
1838 + nd->intent.open.file = get_empty_filp();
1839 + if (unlikely(!nd->intent.open.file))
1843 + if (!au_br_writable(br->br_perm)) {
1844 + nd->intent.open.flags = FMODE_READ
1845 + | au_file_roflags(nd->intent.open.flags);
1846 + nd->flags &= ~LOOKUP_CREATE;
1855 +static void au_put_filp(struct file *file)
1857 +#if !defined(CONFIG_AUFS_MODULE) || defined(CONFIG_AUFS_PUT_FILP_PATCH)
1858 + if (unlikely(file))
1861 + WARN_ONCE(file, "unexpected put_fillp() call");
1865 +int au_hin_after_reval(struct nameidata *nd, struct dentry *dentry,
1866 + aufs_bindex_t bindex, struct file *file)
1870 + LKTRTrace("nd %p, %.*s, b%d, f %d\n",
1871 + nd, AuDLNPair(dentry), bindex, !!file);
1874 + if ((nd->flags & LOOKUP_OPEN)
1875 + && nd->intent.open.file
1876 + && !IS_ERR(nd->intent.open.file)) {
1877 + if (nd->intent.open.file->f_dentry) {
1878 + err = au_set_h_intent(dentry, bindex, file,
1879 + nd->intent.open.file);
1881 + nd->intent.open.file = NULL;
1883 + au_put_filp(nd->intent.open.file);
1889 +#ifdef CONFIG_AUFS_DLGT
1890 +struct au_lookup_hash_args {
1891 + struct dentry **errp;
1892 + struct qstr *name;
1893 + struct dentry *base;
1894 + struct nameidata *nd;
1897 +static void au_call_lookup_hash(void *args)
1899 + struct au_lookup_hash_args *a = args;
1900 + *a->errp = vfsub__lookup_hash(a->name, a->base, a->nd);
1903 +static struct dentry *
1904 +au_lkup_hash_dlgt(struct qstr *this, struct dentry *parent,
1905 + struct nameidata *nd, unsigned int flags)
1907 + struct dentry *dentry;
1910 + dirperm1 = au_ftest_ndx(flags, DIRPERM1);
1911 + if (!dirperm1 && !au_ftest_ndx(flags, DLGT))
1912 + dentry = vfsub__lookup_hash(this, parent, nd);
1915 + struct au_lookup_hash_args args = {
1921 + wkq_err = au_wkq_wait(au_call_lookup_hash, &args,
1922 + /*dlgt*/!dirperm1);
1923 + if (unlikely(wkq_err))
1924 + dentry = ERR_PTR(wkq_err);
1927 + AuTraceErrPtr(dentry);
1931 +static struct dentry *
1932 +au_lkup_hash_dlgt(struct qstr *this, struct dentry *parent,
1933 + struct nameidata *nd, unsigned int flags)
1935 + return vfsub__lookup_hash(this, parent, nd);
1937 +#endif /* CONFIG_AUFS_DLGT */
1939 +struct dentry *au_lkup_hash(const char *name, struct dentry *parent,
1940 + int len, struct au_ndx *ndx)
1942 + struct dentry *dentry;
1944 + unsigned long hash;
1947 + struct nameidata tmp_nd, *ndo;
1950 + LKTRTrace("%.*s/%.*s\n", AuDLNPair(parent), len, name);
1952 + /* todo: export and call __lookup_one_len() in fs/namei.c? */
1953 + dentry = ERR_PTR(-EACCES);
1956 + if (unlikely(!len))
1960 + hash = init_name_hash();
1963 + if (unlikely(c == '/' || c == '\0'))
1965 + hash = partial_name_hash(c, hash);
1967 + this.hash = end_name_hash(hash);
1972 + err = au_fake_intent(&tmp_nd, ndx->br);
1973 + dentry = ERR_PTR(err);
1974 + if (unlikely(err))
1977 + memset(&tmp_nd, 0, sizeof(tmp_nd));
1979 + tmp_nd.path.dentry = parent;
1980 + tmp_nd.path.mnt = ndx->nfsmnt;
1981 + path_get(&tmp_nd.path);
1982 + dentry = au_lkup_hash_dlgt(&this, parent, &tmp_nd, ndx->flags);
1983 + if (!IS_ERR(dentry)) {
1984 + /* why negative dentry for a new dir was unhashed? */
1985 + if (unlikely(d_unhashed(dentry)))
1987 + if (tmp_nd.intent.open.file
1988 + && tmp_nd.intent.open.file->f_dentry) {
1989 + ndx->nd_file = tmp_nd.intent.open.file;
1990 + tmp_nd.intent.open.file = NULL;
1991 + /* au_br_get(ndx->br); */
1994 + path_put(&tmp_nd.path);
1997 + au_put_filp(tmp_nd.intent.open.file);
1999 + AuTraceErrPtr(dentry);
2002 diff -urN linux/fs/aufs/br_xfs.c linux-aufs/fs/aufs/br_xfs.c
2003 --- linux/fs/aufs/br_xfs.c 1970-01-01 01:00:00.000000000 +0100
2004 +++ linux-aufs/fs/aufs/br_xfs.c 2009-03-12 16:18:04.000000000 +0100
2007 + * Copyright (C) 2005-2009 Junjiro Okajima
2009 + * This program, aufs is free software; you can redistribute it and/or modify
2010 + * it under the terms of the GNU General Public License as published by
2011 + * the Free Software Foundation; either version 2 of the License, or
2012 + * (at your option) any later version.
2014 + * This program is distributed in the hope that it will be useful,
2015 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2016 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2017 + * GNU General Public License for more details.
2019 + * You should have received a copy of the GNU General Public License
2020 + * along with this program; if not, write to the Free Software
2021 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2025 + * special handling inode attributes on XFS branch in linux-2.6.24 and later
2032 +/* h_mnt can be NULL, is it safe? */
2033 +dev_t au_h_rdev(struct inode *h_inode, struct vfsmount *h_mnt,
2034 + struct dentry *h_dentry)
2040 + LKTRTrace("hi%lu\n", h_inode->i_ino);
2042 + LKTRTrace("%.*s\n", AuDLNPair(h_dentry));
2044 + rdev = h_inode->i_rdev;
2045 + if (!rdev || !au_test_xfs(h_inode->i_sb))
2051 + h_dentry = d_find_alias(h_inode);
2052 + if (unlikely(!h_dentry))
2054 + err = PTR_ERR(h_dentry);
2055 + if (IS_ERR(h_dentry)) {
2059 + LKTRTrace("%.*s\n", AuDLNPair(h_dentry));
2063 + err = vfsub_getattr(h_mnt, h_dentry, &st, /*dlgt*/0);
2067 + goto out; /* success */
2071 + AuIOErr("failed rdev for XFS inode, hi%lu, %d\n", h_inode->i_ino, err);
2075 diff -urN linux/fs/aufs/cpup.c linux-aufs/fs/aufs/cpup.c
2076 --- linux/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
2077 +++ linux-aufs/fs/aufs/cpup.c 2009-03-12 16:18:04.000000000 +0100
2080 + * Copyright (C) 2005-2009 Junjiro Okajima
2082 + * This program, aufs is free software; you can redistribute it and/or modify
2083 + * it under the terms of the GNU General Public License as published by
2084 + * the Free Software Foundation; either version 2 of the License, or
2085 + * (at your option) any later version.
2087 + * This program is distributed in the hope that it will be useful,
2088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2090 + * GNU General Public License for more details.
2092 + * You should have received a copy of the GNU General Public License
2093 + * along with this program; if not, write to the Free Software
2094 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2098 + * copy-up functions, see wbr_policy.c for copy-down
2103 +#include <linux/fs_stack.h>
2104 +#include <linux/uaccess.h>
2107 +/* todo? violent cpup_attr_*() functions don't care inode lock */
2109 +void au_cpup_attr_timesizes(struct inode *inode)
2111 + struct inode *h_inode;
2113 + LKTRTrace("i%lu\n", inode->i_ino);
2114 + /* todo? IMustLock(inode); */
2115 + h_inode = au_h_iptr(inode, au_ibstart(inode));
2116 + AuDebugOn(!h_inode);
2117 + /* todo? IMustLock(!h_inode); */
2119 + fsstack_copy_attr_times(inode, h_inode);
2120 + vfsub_copy_inode_size(inode, h_inode);
2123 +void au_cpup_attr_nlink(struct inode *inode, int force)
2125 + struct inode *h_inode;
2126 + struct super_block *sb;
2127 + aufs_bindex_t bindex, bend;
2129 + LKTRTrace("i%lu\n", inode->i_ino);
2130 + /* todo? IMustLock(inode); */
2131 + AuDebugOn(!inode->i_mode);
2134 + bindex = au_ibstart(inode);
2135 + h_inode = au_h_iptr(inode, bindex);
2138 + && !S_ISDIR(h_inode->i_mode)
2139 + && au_opt_test(au_mntflags(sb), PLINK)
2140 + && au_plink_test(sb, inode))
2143 + inode->i_nlink = h_inode->i_nlink;
2146 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
2147 + * it may includes whplink directory.
2149 + if (S_ISDIR(h_inode->i_mode)) {
2150 + bend = au_ibend(inode);
2151 + for (bindex++; bindex <= bend; bindex++) {
2152 + h_inode = au_h_iptr(inode, bindex);
2154 + au_add_nlink(inode, h_inode);
2159 +void au_cpup_attr_changeable(struct inode *inode)
2161 + struct inode *h_inode;
2163 + LKTRTrace("i%lu\n", inode->i_ino);
2164 + /* todo? IMustLock(inode); */
2165 + h_inode = au_h_iptr(inode, au_ibstart(inode));
2166 + AuDebugOn(!h_inode);
2168 + inode->i_mode = h_inode->i_mode;
2169 + inode->i_uid = h_inode->i_uid;
2170 + inode->i_gid = h_inode->i_gid;
2171 + au_cpup_attr_timesizes(inode);
2172 + au_cpup_attr_flags(inode, h_inode);
2175 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
2177 + struct au_iinfo *iinfo = au_ii(inode);
2178 + iinfo->ii_higen = h_inode->i_generation;
2179 + iinfo->ii_hsb1 = h_inode->i_sb;
2182 +void au_cpup_attr_all(struct inode *inode, int force)
2184 + struct inode *h_inode;
2186 + LKTRTrace("i%lu\n", inode->i_ino);
2187 + /* todo? IMustLock(inode); */
2188 + h_inode = au_h_iptr(inode, au_ibstart(inode));
2189 + AuDebugOn(!h_inode);
2191 + au_cpup_attr_changeable(inode);
2192 + if (inode->i_nlink > 0)
2193 + au_cpup_attr_nlink(inode, force);
2195 + switch (inode->i_mode & S_IFMT) {
2198 + inode->i_rdev = au_h_rdev(h_inode, /*h_mnt*/NULL,
2199 + /*h_dentry*/NULL);
2201 + inode->i_blkbits = h_inode->i_blkbits;
2202 + au_cpup_igen(inode, h_inode);
2205 +/* ---------------------------------------------------------------------- */
2207 +/* Note: dt_dentry and dt_hidden_dentry are not dget/dput-ed */
2209 +/* keep the timestamps of the parent dir when cpup */
2210 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
2211 + struct dentry *h_dentry, struct au_hinode *hinode,
2212 + struct au_hinode *hdir)
2214 + struct inode *h_inode;
2216 + LKTRTrace("%.*s, hdir %d\n", AuDLNPair(dentry), !!hdir);
2217 + AuDebugOn(!dentry || !h_dentry || !h_dentry->d_inode);
2219 + dt->dt_dentry = dentry;
2220 + dt->dt_h_dentry = h_dentry;
2221 + dt->dt_hinode = hinode;
2222 + dt->dt_hdir = hdir;
2223 + h_inode = h_dentry->d_inode;
2224 + dt->dt_atime = h_inode->i_atime;
2225 + dt->dt_mtime = h_inode->i_mtime;
2229 +void au_dtime_revert(struct au_dtime *dt)
2231 + struct iattr attr;
2233 + struct au_hin_ignore ign[2];
2234 + struct vfsub_args vargs;
2236 + LKTRTrace("%.*s\n", AuDLNPair(dt->dt_dentry));
2238 + attr.ia_atime = dt->dt_atime;
2239 + attr.ia_mtime = dt->dt_mtime;
2240 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
2241 + | ATTR_ATIME | ATTR_ATIME_SET;
2243 + vfsub_args_init(&vargs, ign,
2244 + au_test_dlgt(au_mntflags(dt->dt_dentry->d_sb)), 0);
2246 + * IN_ATTRIB should be divided into
2247 + * IN_ATTRIB_ATIME, IN_ATTRIB_MTIME ...,
2248 + * and define all ORed new IN_ATTRIB macro.
2250 + vfsub_ign_hinode(&vargs, IN_ATTRIB, dt->dt_hinode);
2251 + vfsub_ign_hinode(&vargs, IN_ATTRIB, dt->dt_hdir);
2252 + err = vfsub_notify_change(dt->dt_h_dentry, &attr, &vargs);
2253 + if (unlikely(err))
2254 + AuWarn("restoring timestamps failed(%d). ignored\n", err);
2257 +/* ---------------------------------------------------------------------- */
2259 +static noinline_for_stack
2260 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
2261 + struct au_hinode *hdir, struct vfsub_args *vargs)
2264 + struct dentry *h_dst;
2266 + struct inode *h_isrc, *h_idst;
2268 + h_dst = au_h_dptr(dst, bindex);
2269 + LKTRTrace("%.*s\n", AuDLNPair(h_dst));
2270 + h_idst = h_dst->d_inode;
2271 + /* todo? IMustLock(h_idst); */
2272 + h_isrc = h_src->d_inode;
2273 + /* todo? IMustLock(h_isrc); */
2275 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID
2276 + | ATTR_ATIME | ATTR_MTIME
2277 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
2278 + ia.ia_mode = h_isrc->i_mode;
2279 + ia.ia_uid = h_isrc->i_uid;
2280 + ia.ia_gid = h_isrc->i_gid;
2281 + ia.ia_atime = h_isrc->i_atime;
2282 + ia.ia_mtime = h_isrc->i_mtime;
2283 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
2284 + au_cpup_attr_flags(h_idst, h_isrc);
2286 + vfsub_args_reinit(vargs);
2287 + vfsub_ign_hinode(vargs, IN_ATTRIB, hdir);
2288 + err = vfsub_notify_change(h_dst, &ia, vargs);
2290 + /* is this nfs only? */
2291 + if (!err && sbits && au_test_nfs(h_dst->d_sb)) {
2292 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
2293 + ia.ia_mode = h_isrc->i_mode;
2294 + vfsub_args_reinit(vargs);
2295 + vfsub_ign_hinode(vargs, IN_ATTRIB, hdir);
2296 + err = vfsub_notify_change(h_dst, &ia, vargs);
2304 + * to support a sparse file which is opened with O_APPEND,
2305 + * we need to close the file.
2307 +static noinline_for_stack
2308 +int cpup_regular(struct dentry *dentry, aufs_bindex_t bdst, aufs_bindex_t bsrc,
2309 + loff_t len, struct au_hinode *hdir, struct vfsub_args *vargs)
2312 + struct super_block *sb;
2313 + struct inode *h_inode;
2314 + enum { SRC, DST };
2316 + aufs_bindex_t bindex;
2317 + unsigned int flags;
2318 + struct dentry *dentry;
2319 + struct file *file;
2320 + void *label, *label_file;
2321 + } *h, hidden[] = {
2324 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
2327 + .label_file = &&out_src_file
2331 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
2333 + .label = &&out_src_file,
2334 + .label_file = &&out_dst_file
2338 + LKTRTrace("dentry %.*s, bdst %d, bsrc %d, len %lld\n",
2339 + AuDLNPair(dentry), bdst, bsrc, len);
2340 + AuDebugOn(bsrc <= bdst);
2342 + sb = dentry->d_sb;
2343 + AuDebugOn(au_test_ro(sb, bdst, dentry->d_inode));
2344 + /* bsrc branch can be ro/rw. */
2347 + for (i = 0; i < 2; i++, h++) {
2348 + h->dentry = au_h_dptr(dentry, h->bindex);
2349 + AuDebugOn(!h->dentry);
2350 + h_inode = h->dentry->d_inode;
2351 + AuDebugOn(!h_inode || !S_ISREG(h_inode->i_mode));
2352 + h->file = au_h_open(dentry, h->bindex, h->flags, /*file*/NULL);
2353 + err = PTR_ERR(h->file);
2354 + if (IS_ERR(h->file))
2357 + if (unlikely(!h->file->f_op))
2358 + goto *h->label_file;
2361 + /* stop updating while we copyup */
2362 + IMustLock(hidden[SRC].dentry->d_inode);
2363 + err = au_copy_file(hidden[DST].file, hidden[SRC].file, len, hdir, sb,
2367 + fput(hidden[DST].file);
2368 + au_sbr_put(sb, hidden[DST].bindex);
2370 + fput(hidden[SRC].file);
2371 + au_sbr_put(sb, hidden[SRC].bindex);
2377 +static int au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
2378 + aufs_bindex_t bsrc, loff_t len,
2379 + struct au_hinode *hdir, struct dentry *h_dst,
2380 + struct vfsub_args *vargs)
2388 + l = i_size_read(au_h_iptr(dentry->d_inode, bsrc));
2389 + if (len == -1 || l < len)
2392 + err = cpup_regular(dentry, bdst, bsrc, len, hdir, vargs);
2394 + goto out; /* success */
2396 + vfsub_args_reinit(vargs);
2397 + vfsub_ign_hinode(vargs, IN_DELETE, hdir);
2398 + rerr = vfsub_unlink(hdir->hi_inode, h_dst, vargs);
2400 + AuIOErr("failed unlinking cpup-ed %.*s(%d, %d)\n",
2401 + AuDLNPair(h_dst), err, rerr);
2410 +static int au_do_cpup_symlink(struct dentry *h_dst, struct dentry *h_src,
2411 + struct inode *h_dir, umode_t mode,
2412 + struct vfsub_args *vargs)
2416 + mm_segment_t old_fs;
2421 + sym = __getname();
2422 + if (unlikely(!sym))
2425 + old_fs = get_fs();
2426 + set_fs(KERNEL_DS);
2427 + symlen = h_src->d_inode->i_op->readlink(h_src, (char __user *)sym,
2434 + err = vfsub_symlink(h_dir, h_dst, sym, mode, vargs);
2443 +/* return with hidden dst inode is locked */
2444 +static noinline_for_stack
2445 +int cpup_entry(struct dentry *dentry, aufs_bindex_t bdst, aufs_bindex_t bsrc,
2446 + loff_t len, unsigned int flags, struct dentry *dst_parent,
2447 + struct vfsub_args *vargs)
2450 + unsigned char isdir, hinotify;
2451 + struct dentry *h_src, *h_dst, *h_parent, *gparent;
2452 + struct inode *h_inode, *h_dir;
2453 + struct au_dtime dt;
2455 + struct super_block *sb;
2456 + struct au_hinode *hgdir, *hdir;
2457 + unsigned int mnt_flags;
2458 + const int do_dt = au_ftest_cpup(flags, DTIME);
2460 + LKTRTrace("%.*s, i%lu, bdst %d, bsrc %d, len %lld, dtime %u\n",
2461 + AuDLNPair(dentry), dentry->d_inode->i_ino, bdst, bsrc, len,
2463 + sb = dentry->d_sb;
2464 + AuDebugOn(bdst >= bsrc || au_test_ro(sb, bdst, NULL));
2465 + /* bsrc branch can be ro/rw. */
2467 + h_src = au_h_dptr(dentry, bsrc);
2468 + AuDebugOn(!h_src);
2469 + h_inode = h_src->d_inode;
2470 + AuDebugOn(!h_inode);
2471 + AuDebugOn(h_inode != au_h_iptr(dentry->d_inode, bsrc));
2473 + /* stop referencing while we are creating */
2474 + h_dst = au_h_dptr(dentry, bdst);
2475 + AuDebugOn(h_dst && h_dst->d_inode);
2476 + h_parent = h_dst->d_parent; /* dir inode is locked */
2477 + h_dir = h_parent->d_inode;
2479 + AuDebugOn(h_parent != h_dst->d_parent);
2482 + mnt_flags = au_mntflags(sb);
2483 + hinotify = !!au_opt_test(mnt_flags, UDBA_INOTIFY);
2485 + hdir = au_hi(dst_parent->d_inode, bdst);
2486 + AuDebugOn(hdir->hi_inode != h_dir);
2491 + if (hinotify && !IS_ROOT(dst_parent)) {
2492 + gparent = dget_parent(dst_parent);
2493 + hgdir = au_hi(gparent->d_inode, bdst);
2494 + IMustLock(hgdir->hi_inode);
2497 + au_dtime_store(&dt, dst_parent, h_parent, hdir, hgdir);
2501 + vfsub_args_reinit(vargs);
2502 + vfsub_ign_hinode(vargs, IN_CREATE, hdir);
2503 + mode = h_inode->i_mode;
2504 + switch (mode & S_IFMT) {
2506 + /* stop updating while we are referencing */
2507 + IMustLock(h_inode);
2508 + err = au_h_create(h_dir, h_dst, mode | S_IWUSR, vargs, NULL,
2509 + au_nfsmnt(sb, bdst));
2511 + err = au_do_cpup_regular(dentry, bdst, bsrc, len,
2512 + hdir, h_dst, vargs);
2516 + err = vfsub_mkdir(h_dir, h_dst, mode, vargs);
2518 + /* setattr case: dir is not locked */
2519 + if (0 && au_ibstart(dst_parent->d_inode) == bdst)
2520 + au_cpup_attr_nlink(dst_parent->d_inode,
2522 + au_cpup_attr_nlink(dentry->d_inode, /*force*/1);
2526 + err = au_do_cpup_symlink(h_dst, h_src, h_dir, mode, vargs);
2530 + AuDebugOn(!capable(CAP_MKNOD));
2534 + err = vfsub_mknod(h_dir, h_dst, mode,
2535 + au_h_rdev(h_inode, /*h_mnt*/NULL, h_src),
2539 + AuIOErr("Unknown inode type 0%o\n", mode);
2545 + && au_opt_test_xino(mnt_flags)
2546 + && h_inode->i_nlink == 1
2547 + /* todo: unnecessary? */
2548 + /* && dentry->d_inode->i_nlink == 1 */
2550 + && !au_ftest_cpup(flags, KEEPLINO))
2551 + au_xino_write0(sb, bsrc, h_inode->i_ino, /*ino*/0);
2552 + /* ignore this error */
2555 + au_dtime_revert(&dt);
2561 + * copyup the @dentry from @bsrc to @bdst.
2562 + * the caller must set the both of hidden dentries.
2563 + * @len is for truncating when it is -1 copyup the entire file.
2565 +static int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
2566 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
2567 + struct dentry *dst_parent, struct vfsub_args *vargs)
2570 + unsigned int mnt_flags;
2571 + aufs_bindex_t old_ibstart;
2572 + unsigned char isdir, plink, hinotify;
2573 + struct au_dtime dt;
2574 + struct dentry *h_src, *h_dst, *h_parent, *gparent;
2575 + struct inode *dst_inode, *h_dir, *inode;
2576 + struct super_block *sb;
2577 + struct au_hinode *hgdir, *hdir;
2579 + LKTRTrace("%.*s, i%lu, bdst %d, bsrc %d, len %lld, flags 0x%x\n",
2580 + AuDLNPair(dentry), dentry->d_inode->i_ino, bdst, bsrc, len,
2582 + sb = dentry->d_sb;
2583 + AuDebugOn(bsrc <= bdst);
2584 + h_dst = au_h_dptr(dentry, bdst);
2585 + AuDebugOn(!h_dst || h_dst->d_inode);
2586 + h_parent = h_dst->d_parent; /* dir inode is locked */
2587 + h_dir = h_parent->d_inode;
2589 + h_src = au_h_dptr(dentry, bsrc);
2590 + AuDebugOn(!h_src || !h_src->d_inode);
2591 + inode = dentry->d_inode;
2592 + IiMustWriteLock(inode);
2594 + dst_parent = dget_parent(dentry);
2598 + mnt_flags = au_mntflags(sb);
2599 + plink = !!au_opt_test(mnt_flags, PLINK);
2600 + hinotify = !!au_opt_test(mnt_flags, UDBA_INOTIFY);
2603 + hdir = au_hi(dst_parent->d_inode, bdst);
2604 + dst_inode = au_h_iptr(inode, bdst);
2606 + if (unlikely(!plink)) {
2608 + AuIOErr("i%lu exists on a upper branch "
2609 + "but plink is disabled\n", inode->i_ino);
2613 + if (dst_inode->i_nlink) {
2614 + const int do_dt = au_ftest_cpup(flags, DTIME);
2616 + h_src = au_plink_lkup(sb, bdst, inode);
2617 + err = PTR_ERR(h_src);
2618 + if (IS_ERR(h_src))
2620 + if (unlikely(!h_src->d_inode)) {
2622 + AuIOErr("i%lu exists on a upper branch "
2623 + "but plink is broken\n", inode->i_ino);
2630 + if (hinotify && !IS_ROOT(dst_parent)) {
2631 + gparent = dget_parent(dst_parent);
2632 + hgdir = au_hi(gparent->d_inode, bdst);
2633 + IMustLock(hgdir->hi_inode);
2636 + au_dtime_store(&dt, dst_parent, h_parent, hdir,
2639 + vfsub_args_reinit(vargs);
2640 + vfsub_ign_hinode(vargs, IN_CREATE, hdir);
2641 + err = vfsub_link(h_src, h_dir, h_dst, vargs);
2643 + au_dtime_revert(&dt);
2647 + /* todo: cpup_wh_file? */
2649 + au_update_brange(inode, 1);
2652 + old_ibstart = au_ibstart(inode);
2653 + err = cpup_entry(dentry, bdst, bsrc, len, flags, dst_parent, vargs);
2654 + if (unlikely(err))
2656 + dst_inode = h_dst->d_inode;
2657 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
2659 + /* todo: test dlgt? */
2660 + err = cpup_iattr(dentry, bdst, h_src, hdir, vargs);
2661 +#if 0 /* reserved for future use */
2663 + err = cpup_xattrs(h_src, h_dst);
2665 + isdir = S_ISDIR(dst_inode->i_mode);
2667 + if (bdst < old_ibstart)
2668 + au_set_ibstart(inode, bdst);
2669 + au_set_h_iptr(inode, bdst, au_igrab(dst_inode),
2670 + au_hi_flags(inode, isdir));
2671 + mutex_unlock(&dst_inode->i_mutex);
2673 + && h_src->d_inode->i_nlink > 1
2675 + au_plink_append(sb, inode, h_dst, bdst);
2676 + goto out; /* success */
2680 + mutex_unlock(&dst_inode->i_mutex);
2682 + if (au_opt_test(mnt_flags, UDBA_INOTIFY) && !IS_ROOT(dst_parent)) {
2683 + gparent = dget_parent(dst_parent);
2684 + hgdir = au_hi(gparent->d_inode, bdst);
2687 + au_dtime_store(&dt, dst_parent, h_parent, hdir, hgdir);
2688 + vfsub_args_reinit(vargs);
2689 + vfsub_ign_hinode(vargs, IN_DELETE, hdir);
2691 + rerr = vfsub_unlink(h_dir, h_dst, vargs);
2693 + rerr = vfsub_rmdir(h_dir, h_dst, vargs);
2694 + au_dtime_revert(&dt);
2696 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
2706 +struct au_cpup_single_args {
2708 + struct dentry *dentry;
2709 + aufs_bindex_t bdst, bsrc;
2711 + unsigned int flags;
2712 + struct dentry *dst_parent;
2713 + struct vfsub_args *vargs;
2716 +static void au_call_cpup_single(void *args)
2718 + struct au_cpup_single_args *a = args;
2719 + *a->errp = au_cpup_single(a->dentry, a->bdst, a->bsrc, a->len,
2720 + a->flags, a->dst_parent, a->vargs);
2723 +int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
2724 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
2725 + struct dentry *dst_parent)
2728 + struct dentry *h_dentry;
2730 + struct au_hin_ignore ign;
2731 + struct vfsub_args vargs;
2733 + LKTRTrace("%.*s, i%lu, bdst %d, bsrc %d, len %lld, flags 0x%x\n",
2734 + AuDLNPair(dentry), dentry->d_inode->i_ino, bdst, bsrc, len,
2737 + vfsub_args_init(&vargs, &ign, au_test_dlgt(au_mntflags(dentry->d_sb)),
2738 + /*force_unlink*/0);
2739 + h_dentry = au_h_dptr(dentry, bsrc);
2740 + mode = h_dentry->d_inode->i_mode & S_IFMT;
2741 + if ((mode != S_IFCHR && mode != S_IFBLK)
2742 + || capable(CAP_MKNOD))
2743 + err = au_cpup_single(dentry, bdst, bsrc, len, flags,
2744 + dst_parent, &vargs);
2746 + struct au_cpup_single_args args = {
2753 + .dst_parent = dst_parent,
2756 + vfsub_fclr(vargs.flags, DLGT);
2757 + wkq_err = au_wkq_wait(au_call_cpup_single, &args, /*dlgt*/0);
2758 + if (unlikely(wkq_err))
2767 + * copyup the @dentry from the first active hidden branch to @bdst,
2768 + * using au_cpup_single().
2770 +static int au_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2771 + unsigned int flags, struct vfsub_args *vargs)
2774 + struct inode *inode;
2775 + aufs_bindex_t bsrc, bend;
2777 + LKTRTrace("%.*s, bdst %d, len %lld, flags 0x%x\n",
2778 + AuDLNPair(dentry), bdst, len, flags);
2779 + inode = dentry->d_inode;
2780 + AuDebugOn(!S_ISDIR(inode->i_mode) && au_dbstart(dentry) < bdst);
2782 + bend = au_dbend(dentry);
2783 + for (bsrc = bdst + 1; bsrc <= bend; bsrc++)
2784 + if (au_h_dptr(dentry, bsrc))
2786 + AuDebugOn(!au_h_dptr(dentry, bsrc));
2788 + err = au_lkup_neg(dentry, bdst);
2790 + err = au_cpup_single(dentry, bdst, bsrc, len, flags, NULL,
2793 + return 0; /* success */
2796 + au_set_h_dptr(dentry, bdst, NULL);
2797 + au_set_dbstart(dentry, bsrc);
2804 +struct au_cpup_simple_args {
2806 + struct dentry *dentry;
2807 + aufs_bindex_t bdst;
2809 + unsigned int flags;
2810 + struct vfsub_args *vargs;
2813 +static void au_call_cpup_simple(void *args)
2815 + struct au_cpup_simple_args *a = args;
2816 + *a->errp = au_cpup_simple(a->dentry, a->bdst, a->len, a->flags,
2820 +int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2821 + unsigned int flags)
2824 + unsigned char do_sio, dlgt;
2825 + struct dentry *parent;
2826 + struct inode *h_dir, *dir;
2827 + struct au_hin_ignore ign;
2828 + struct vfsub_args vargs;
2830 + LKTRTrace("%.*s, b%d, len %lld, flags 0x%x\n",
2831 + AuDLNPair(dentry), bdst, len, flags);
2833 + parent = dget_parent(dentry);
2834 + dir = parent->d_inode;
2835 + h_dir = au_h_iptr(dir, bdst);
2836 + dlgt = !!au_test_dlgt(au_mntflags(dir->i_sb));
2837 + do_sio = !!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE, dlgt);
2840 + * testing CAP_MKNOD is for generic fs,
2841 + * but CAP_FSETID is for xfs only, currently.
2843 + umode_t mode = dentry->d_inode->i_mode;
2844 + do_sio = (((mode & (S_IFCHR | S_IFBLK))
2845 + && !capable(CAP_MKNOD))
2846 + || ((mode & (S_ISUID | S_ISGID))
2847 + && !capable(CAP_FSETID)));
2849 + vfsub_args_init(&vargs, &ign, dlgt, /*force_unlink*/0);
2851 + err = au_cpup_simple(dentry, bdst, len, flags, &vargs);
2853 + struct au_cpup_simple_args args = {
2861 + vfsub_fclr(vargs.flags, DLGT);
2862 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args, /*dlgt*/0);
2863 + if (unlikely(wkq_err))
2872 +/* ---------------------------------------------------------------------- */
2874 +static int au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
2875 + struct dentry *wh_dentry, struct file *file,
2876 + loff_t len, struct vfsub_args *vargs)
2879 + struct au_dinfo *dinfo;
2880 + aufs_bindex_t bstart;
2881 + struct dentry *h_d_bdst, *h_d_bstart;
2885 + dinfo = au_di(dentry);
2886 + bstart = dinfo->di_bstart;
2887 + h_d_bdst = dinfo->di_hdentry[0 + bdst].hd_dentry;
2888 + dinfo->di_bstart = bdst;
2889 + dinfo->di_hdentry[0 + bdst].hd_dentry = wh_dentry;
2890 + h_d_bstart = dinfo->di_hdentry[0 + bstart].hd_dentry;
2892 + dinfo->di_hdentry[0 + bstart].hd_dentry
2893 + = au_h_fptr(file, au_fbstart(file))->f_dentry;
2894 + err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME,
2895 + /*h_parent*/NULL, vargs);
2896 + if (!err && file) {
2897 + err = au_reopen_nondir(file);
2898 + dinfo->di_hdentry[0 + bstart].hd_dentry = h_d_bstart;
2900 + dinfo->di_hdentry[0 + bdst].hd_dentry = h_d_bdst;
2901 + dinfo->di_bstart = bstart;
2908 + * copyup the deleted file for writing.
2910 +static int au_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2911 + struct file *file)
2914 + unsigned char dlgt;
2915 + struct dentry *parent, *h_parent, *wh_dentry;
2916 + struct super_block *sb;
2917 + unsigned int mnt_flags;
2918 + struct au_dtime dt;
2919 + struct au_hin_ignore ign;
2920 + struct vfsub_args vargs;
2921 + struct au_hinode *hgdir, *hdir;
2922 + struct au_ndx ndx = {
2928 + LKTRTrace("%.*s, bdst %d, len %llu\n", AuDLNPair(dentry), bdst, len);
2929 + AuDebugOn(S_ISDIR(dentry->d_inode->i_mode)
2930 + || (file && !(file->f_mode & FMODE_WRITE)));
2931 + DiMustWriteLock(dentry);
2933 + parent = dget_parent(dentry);
2934 + IiMustAnyLock(parent->d_inode);
2935 + h_parent = au_h_dptr(parent, bdst);
2936 + AuDebugOn(!h_parent);
2938 + sb = parent->d_sb;
2939 + mnt_flags = au_mntflags(sb);
2941 + ndx.nfsmnt = au_nfsmnt(sb, bdst);
2942 + if (au_test_dlgt(mnt_flags)) {
2944 + au_fset_ndx(ndx.flags, DLGT);
2946 + wh_dentry = au_whtmp_lkup(h_parent, &dentry->d_name, &ndx);
2947 + err = PTR_ERR(wh_dentry);
2948 + if (IS_ERR(wh_dentry))
2953 + if (au_opt_test(mnt_flags, UDBA_INOTIFY)) {
2954 + hdir = au_hi(parent->d_inode, bdst);
2955 + if (!IS_ROOT(parent)) {
2956 + struct dentry *gparent;
2957 + gparent = dget_parent(parent);
2958 + hgdir = au_hi(gparent->d_inode, bdst);
2962 + au_dtime_store(&dt, parent, h_parent, hdir, hgdir);
2963 + vfsub_args_init(&vargs, &ign, dlgt, /*force_unlink*/0);
2964 + err = au_do_cpup_wh(dentry, bdst, wh_dentry, file, len, &vargs);
2965 + if (unlikely(err))
2968 + AuDebugOn(!d_unhashed(dentry));
2969 + /* dget first to force sillyrename on nfs */
2971 + vfsub_args_reinit(&vargs);
2972 + vfsub_ign_hinode(&vargs, IN_DELETE, hdir);
2973 + err = vfsub_unlink(h_parent->d_inode, wh_dentry, &vargs);
2974 + if (unlikely(err)) {
2975 + AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
2976 + AuDLNPair(wh_dentry), err);
2979 + au_dtime_revert(&dt);
2980 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
2990 +struct au_cpup_wh_args {
2992 + struct dentry *dentry;
2993 + aufs_bindex_t bdst;
2995 + struct file *file;
2998 +static void au_call_cpup_wh(void *args)
3000 + struct au_cpup_wh_args *a = args;
3001 + *a->errp = au_cpup_wh(a->dentry, a->bdst, a->len, a->file);
3004 +int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
3005 + struct file *file)
3008 + struct dentry *parent, *h_tmp, *h_parent, *h_dentry;
3009 + struct inode *dir, *h_dir, *h_tmpdir, *h_inode;
3010 + struct au_wbr *wbr;
3013 + parent = dget_parent(dentry);
3014 + dir = parent->d_inode;
3015 + IiMustAnyLock(dir);
3019 + h_dir = au_igrab(au_h_iptr(dir, bdst));
3021 + if (!h_dir->i_nlink) {
3022 + DiMustWriteLock(parent);
3023 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
3025 + h_tmp = wbr->wbr_tmp;
3027 + h_parent = dget(au_h_dptr(parent, bdst));
3028 + au_set_h_dptr(parent, bdst, NULL);
3029 + au_set_h_dptr(parent, bdst, dget(h_tmp));
3030 + h_tmpdir = h_tmp->d_inode;
3031 + au_set_h_iptr(dir, bdst, NULL, 0);
3032 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
3034 + /* this temporary unlock is safe */
3036 + h_dentry = au_h_fptr(file, au_fbstart(file))->f_dentry;
3038 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
3039 + h_inode = h_dentry->d_inode;
3040 + IMustLock(h_inode);
3041 + mutex_unlock(&h_inode->i_mutex);
3042 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
3043 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
3046 + if (!au_test_h_perm_sio
3047 + (h_tmpdir, MAY_EXEC | MAY_WRITE,
3048 + au_test_dlgt(au_mntflags(dentry->d_sb))))
3049 + err = au_cpup_wh(dentry, bdst, len, file);
3051 + struct au_cpup_wh_args args = {
3058 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args, /*dlgt*/0);
3059 + if (unlikely(wkq_err))
3063 + /* todo: is this restore safe? */
3065 + mutex_unlock(&h_tmpdir->i_mutex);
3066 + au_set_h_iptr(dir, bdst, NULL, 0);
3067 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
3068 + au_set_h_dptr(parent, bdst, NULL);
3069 + au_set_h_dptr(parent, bdst, h_parent);
3078 +/* ---------------------------------------------------------------------- */
3081 + * generic routine for both of copy-up and copy-down.
3082 + * Although I've tried building a path by dcsub, I gave up this approach.
3083 + * Since the ancestor directory may be moved/renamed during copy.
3085 +/* cf. revalidate function in file.c */
3086 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
3087 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
3088 + struct dentry *h_parent, void *arg),
3092 + unsigned char pin_flags;
3093 + struct au_pin pin;
3094 + struct super_block *sb;
3095 + struct dentry *d, *parent, *h_parent, *real_parent;
3097 + LKTRTrace("%.*s, b%d, parent i%lu\n",
3098 + AuDLNPair(dentry), bdst, (unsigned long)parent_ino(dentry));
3099 + sb = dentry->d_sb;
3100 + AuDebugOn(au_test_ro(sb, bdst, NULL));
3102 + parent = dget_parent(dentry);
3103 + IiMustWriteLock(parent->d_inode);
3104 + if (IS_ROOT(parent))
3107 + pin_flags = AuPin_MNT_WRITE;
3108 + if (au_opt_test(au_mntflags(sb), UDBA_INOTIFY))
3109 + au_fset_pin(pin_flags, DO_GPARENT);
3110 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT3, AuLsc_I_PARENT2,
3113 + /* do not use au_dpage */
3114 + real_parent = parent;
3117 + parent = dget_parent(dentry);
3118 + h_parent = au_h_dptr(parent, bdst);
3120 + goto out; /* success */
3122 + /* find top dir which is needed to cpup */
3126 + parent = dget_parent(d);
3127 + di_read_lock_parent3(parent, !AuLock_IR);
3128 + h_parent = au_h_dptr(parent, bdst);
3129 + di_read_unlock(parent, !AuLock_IR);
3130 + } while (!h_parent);
3132 + if (d != real_parent)
3133 + di_write_lock_child3(d);
3135 + /* somebody else might create while we were sleeping */
3136 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
3137 + if (au_h_dptr(d, bdst))
3138 + au_update_dbstart(d);
3140 + au_pin_do_set_dentry(pin.pin + AuPin_PARENT, d);
3141 + err = au_do_pin(pin.pin + AuPin_PARENT,
3144 + err = cp(d, bdst, h_parent, arg);
3149 + if (d != real_parent)
3150 + di_write_unlock(d);
3151 + if (unlikely(err))
3161 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
3162 + struct dentry *h_parent, void *arg)
3166 + err = au_sio_cpup_simple(dentry, bdst, -1, AuCpup_DTIME);
3172 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
3176 + err = au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
3182 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
3185 + struct dentry *parent;
3186 + struct inode *dir;
3188 + parent = dget_parent(dentry);
3189 + dir = parent->d_inode;
3190 + LKTRTrace("%.*s, b%d, parent i%lu\n",
3191 + AuDLNPair(dentry), bdst, dir->i_ino);
3192 + DiMustReadLock(parent);
3193 + IiMustReadLock(dir);
3196 + if (au_h_iptr(dir, bdst))
3199 + di_read_unlock(parent, AuLock_IR);
3200 + di_write_lock_parent(parent);
3201 + /* someone else might change our inode while we were sleeping */
3202 + if (!au_h_iptr(dir, bdst))
3203 + err = au_cpup_dirs(dentry, bdst);
3204 + di_downgrade_lock(parent, AuLock_IR);
3211 diff -urN linux/fs/aufs/cpup.h linux-aufs/fs/aufs/cpup.h
3212 --- linux/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
3213 +++ linux-aufs/fs/aufs/cpup.h 2009-03-12 16:18:04.000000000 +0100
3216 + * Copyright (C) 2005-2009 Junjiro Okajima
3218 + * This program, aufs is free software; you can redistribute it and/or modify
3219 + * it under the terms of the GNU General Public License as published by
3220 + * the Free Software Foundation; either version 2 of the License, or
3221 + * (at your option) any later version.
3223 + * This program is distributed in the hope that it will be useful,
3224 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3225 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3226 + * GNU General Public License for more details.
3228 + * You should have received a copy of the GNU General Public License
3229 + * along with this program; if not, write to the Free Software
3230 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3234 + * copy-up/down functions
3239 +#ifndef __AUFS_CPUP_H__
3240 +#define __AUFS_CPUP_H__
3244 +#include <linux/fs.h>
3245 +#include <linux/aufs_type.h>
3247 +void au_cpup_attr_timesizes(struct inode *inode);
3248 +void au_cpup_attr_nlink(struct inode *inode, int force);
3249 +void au_cpup_attr_changeable(struct inode *inode);
3250 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
3251 +void au_cpup_attr_all(struct inode *inode, int force);
3253 +/* ---------------------------------------------------------------------- */
3256 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
3257 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
3259 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
3260 +#define au_fset_cpup(flags, name) { (flags) |= AuCpup_##name; }
3261 +#define au_fclr_cpup(flags, name) { (flags) &= ~AuCpup_##name; }
3263 +int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
3264 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
3265 + struct dentry *dst_parent);
3266 +int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
3267 + unsigned int flags);
3268 +int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
3269 + struct file *file);
3271 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
3272 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
3273 + struct dentry *h_parent, void *arg),
3275 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
3276 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
3278 +/* ---------------------------------------------------------------------- */
3280 +/* keep timestamps when copyup */
3282 + struct dentry *dt_dentry, *dt_h_dentry;
3283 + struct au_hinode *dt_hinode, *dt_hdir;
3284 + struct timespec dt_atime, dt_mtime;
3286 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
3287 + struct dentry *h_dentry, struct au_hinode *hinode,
3288 + struct au_hinode *hdir);
3289 +void au_dtime_revert(struct au_dtime *dt);
3291 +/* ---------------------------------------------------------------------- */
3293 +static inline void au_cpup_attr_flags(struct inode *inode,
3294 + struct inode *h_inode)
3296 + inode->i_flags |= h_inode->i_flags & ~(S_DEAD | S_PRIVATE);
3299 +#endif /* __KERNEL__ */
3300 +#endif /* __AUFS_CPUP_H__ */
3301 diff -urN linux/fs/aufs/dcsub.c linux-aufs/fs/aufs/dcsub.c
3302 --- linux/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
3303 +++ linux-aufs/fs/aufs/dcsub.c 2009-03-12 16:18:04.000000000 +0100
3306 + * Copyright (C) 2005-2009 Junjiro Okajima
3308 + * This program, aufs is free software; you can redistribute it and/or modify
3309 + * it under the terms of the GNU General Public License as published by
3310 + * the Free Software Foundation; either version 2 of the License, or
3311 + * (at your option) any later version.
3313 + * This program is distributed in the hope that it will be useful,
3314 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3315 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3316 + * GNU General Public License for more details.
3318 + * You should have received a copy of the GNU General Public License
3319 + * along with this program; if not, write to the Free Software
3320 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3324 + * sub-routines for dentry cache
3331 +static void au_dpage_free(struct au_dpage *dpage)
3336 + AuDebugOn(!dpage);
3338 + for (i = 0; i < dpage->ndentry; i++)
3339 + dput(dpage->dentries[i]);
3340 + free_page((unsigned long)dpage->dentries);
3343 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
3351 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
3352 + if (unlikely(!dpages->dpages))
3354 + p = (void *)__get_free_page(gfp);
3357 + dpages->dpages[0].ndentry = 0;
3358 + dpages->dpages[0].dentries = p;
3359 + dpages->ndpage = 1;
3360 + return 0; /* success */
3363 + kfree(dpages->dpages);
3369 +void au_dpages_free(struct au_dcsub_pages *dpages)
3375 + for (i = 0; i < dpages->ndpage; i++)
3376 + au_dpage_free(dpages->dpages + i);
3377 + kfree(dpages->dpages);
3380 +static int au_dpages_append(struct au_dcsub_pages *dpages,
3381 + struct dentry *dentry, gfp_t gfp)
3384 + struct au_dpage *dpage;
3387 + /* AuTraceEnter(); */
3389 + dpage = dpages->dpages + dpages->ndpage - 1;
3390 + AuDebugOn(!dpage);
3391 + sz = PAGE_SIZE / sizeof(dentry);
3392 + if (unlikely(dpage->ndentry >= sz)) {
3393 + LKTRLabel(new dpage);
3395 + sz = dpages->ndpage * sizeof(*dpages->dpages);
3396 + p = au_kzrealloc(dpages->dpages, sz,
3397 + sz + sizeof(*dpages->dpages), gfp);
3400 + dpages->dpages = p;
3401 + dpage = dpages->dpages + dpages->ndpage;
3402 + p = (void *)__get_free_page(gfp);
3405 + dpage->ndentry = 0;
3406 + dpage->dentries = p;
3410 + dpage->dentries[dpage->ndentry++] = dget(dentry);
3411 + return 0; /* success */
3414 + /* AuTraceErr(err); */
3418 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
3419 + au_dpages_test test, void *arg)
3422 + struct dentry *this_parent = root;
3423 + struct list_head *next;
3424 + struct super_block *sb = root->d_sb;
3429 + spin_lock(&dcache_lock);
3431 + next = this_parent->d_subdirs.next;
3433 + if (this_parent->d_sb == sb
3434 + && !IS_ROOT(this_parent)
3435 + && atomic_read(&this_parent->d_count)
3436 + && this_parent->d_inode
3437 + && (!test || test(this_parent, arg))) {
3438 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
3439 + if (unlikely(err))
3443 + while (next != &this_parent->d_subdirs) {
3444 + struct list_head *tmp = next;
3445 + struct dentry *dentry = list_entry(tmp, struct dentry,
3448 + if (/*d_unhashed(dentry) || */!dentry->d_inode)
3450 + if (!list_empty(&dentry->d_subdirs)) {
3451 + this_parent = dentry;
3454 + if (dentry->d_sb == sb
3455 + && atomic_read(&dentry->d_count)
3456 + && (!test || test(dentry, arg))) {
3457 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
3458 + if (unlikely(err))
3463 + if (this_parent != root) {
3464 + next = this_parent->d_u.d_child.next;
3465 + this_parent = this_parent->d_parent; /* dcache_lock is locked */
3469 + spin_unlock(&dcache_lock);
3474 + for (i = 0; i < dpages->ndpage; i++) {
3475 + if ((dpages->dpages + i)->ndentry)
3477 + i, (dpages->dpages + i)->ndentry);
3478 + j += (dpages->dpages + i)->ndentry;
3481 + AuDbg("ndpage %d, %d\n", dpages->ndpage, j);
3488 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
3489 + int do_include, au_dpages_test test, void *arg)
3496 + spin_lock(&dcache_lock);
3497 + if (do_include && (!test || test(dentry, arg))) {
3498 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
3499 + if (unlikely(err))
3502 + while (!IS_ROOT(dentry)) {
3503 + dentry = dentry->d_parent; /* dcache_lock is locked */
3504 + if (!test || test(dentry, arg)) {
3505 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
3506 + if (unlikely(err))
3512 + spin_unlock(&dcache_lock);
3518 +struct dentry *au_test_subdir(struct dentry *d1, struct dentry *d2)
3520 + struct dentry *trap, **dentries;
3522 + struct au_dcsub_pages dpages;
3523 + struct au_dpage *dpage;
3525 + LKTRTrace("%.*s, %.*s\n", AuDLNPair(d1), AuDLNPair(d2));
3527 + trap = ERR_PTR(-ENOMEM);
3528 + err = au_dpages_init(&dpages, GFP_NOFS);
3529 + if (unlikely(err))
3531 + err = au_dcsub_pages_rev(&dpages, d1, /*do_include*/1, NULL, NULL);
3532 + if (unlikely(err))
3536 + for (i = 0; !err && i < dpages.ndpage; i++) {
3537 + dpage = dpages.dpages + i;
3538 + dentries = dpage->dentries;
3539 + for (j = 0; !err && j < dpage->ndentry; j++) {
3551 + au_dpages_free(&dpages);
3553 + AuTraceErrPtr(trap);
3556 diff -urN linux/fs/aufs/dcsub.h linux-aufs/fs/aufs/dcsub.h
3557 --- linux/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
3558 +++ linux-aufs/fs/aufs/dcsub.h 2009-03-12 16:18:04.000000000 +0100
3561 + * Copyright (C) 2005-2009 Junjiro Okajima
3563 + * This program, aufs is free software; you can redistribute it and/or modify
3564 + * it under the terms of the GNU General Public License as published by
3565 + * the Free Software Foundation; either version 2 of the License, or
3566 + * (at your option) any later version.
3568 + * This program is distributed in the hope that it will be useful,
3569 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3570 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3571 + * GNU General Public License for more details.
3573 + * You should have received a copy of the GNU General Public License
3574 + * along with this program; if not, write to the Free Software
3575 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3579 + * sub-routines for dentry cache
3584 +#ifndef __AUFS_DCSUB_H__
3585 +#define __AUFS_DCSUB_H__
3589 +#include <linux/dcache.h>
3593 + struct dentry **dentries;
3596 +struct au_dcsub_pages {
3598 + struct au_dpage *dpages;
3601 +/* ---------------------------------------------------------------------- */
3603 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
3604 +void au_dpages_free(struct au_dcsub_pages *dpages);
3605 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
3606 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
3607 + au_dpages_test test, void *arg);
3608 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
3609 + int do_include, au_dpages_test test, void *arg);
3610 +struct dentry *au_test_subdir(struct dentry *d1, struct dentry *d2);
3612 +#endif /* __KERNEL__ */
3613 +#endif /* __AUFS_DCSUB_H__ */
3614 diff -urN linux/fs/aufs/debug.c linux-aufs/fs/aufs/debug.c
3615 --- linux/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
3616 +++ linux-aufs/fs/aufs/debug.c 2009-03-12 16:18:04.000000000 +0100
3619 + * Copyright (C) 2005-2009 Junjiro Okajima
3621 + * This program, aufs is free software; you can redistribute it and/or modify
3622 + * it under the terms of the GNU General Public License as published by
3623 + * the Free Software Foundation; either version 2 of the License, or
3624 + * (at your option) any later version.
3626 + * This program is distributed in the hope that it will be useful,
3627 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3628 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3629 + * GNU General Public License for more details.
3631 + * You should have received a copy of the GNU General Public License
3632 + * along with this program; if not, write to the Free Software
3633 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3637 + * debug print functions
3644 +atomic_t au_cond = ATOMIC_INIT(0);
3646 +char *au_plevel = KERN_DEBUG;
3647 +#define dpri(fmt, arg...) do { \
3649 + printk("%s" fmt, au_plevel, ##arg); \
3652 +/* ---------------------------------------------------------------------- */
3654 +void au_dpri_whlist(struct au_nhash *whlist)
3657 + struct hlist_head *head;
3658 + struct au_vdir_wh *tpos;
3659 + struct hlist_node *pos;
3661 + for (i = 0; i < AuSize_NHASH; i++) {
3662 + head = whlist->heads + i;
3663 + hlist_for_each_entry(tpos, pos, head, wh_hash)
3664 + dpri("b%d, %.*s, %d\n",
3666 + tpos->wh_str.len, tpos->wh_str.name,
3667 + tpos->wh_str.len);
3671 +void au_dpri_vdir(struct au_vdir *vdir)
3674 + union au_vdir_deblk_p p;
3677 + if (!vdir || IS_ERR(vdir)) {
3678 + dpri("err %ld\n", PTR_ERR(vdir));
3682 + dpri("nblk %d, deblk %p, last{%d, %p}, ver %lu\n",
3683 + vdir->vd_nblk, vdir->vd_deblk,
3684 + vdir->vd_last.i, vdir->vd_last.p.p, vdir->vd_version);
3685 + for (i = 0; i < vdir->vd_nblk; i++) {
3686 + p.deblk = vdir->vd_deblk[i];
3688 + dpri("[%d]: %p\n", i, o);
3692 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode,
3693 + struct dentry *wh)
3696 + int l = 0, ntfy = 0;
3698 + if (!inode || IS_ERR(inode)) {
3699 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
3703 + /* the type of i_blocks depends upon CONFIG_LSF */
3704 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
3705 + && sizeof(inode->i_blocks) != sizeof(u64));
3707 + n = (void *)wh->d_name.name;
3708 + l = wh->d_name.len;
3711 + ntfy = au_test_inotify(inode);
3712 + dpri("i%d: i%lu, %s, cnt %d, nl %u, 0%o, ntfy %d, sz %llu, blk %llu,"
3713 + " ct %lld, np %lu, st 0x%lx, f 0x%x, g %x%s%.*s\n",
3715 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
3716 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
3718 + i_size_read(inode), (unsigned long long)inode->i_blocks,
3719 + (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
3720 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
3721 + inode->i_state, inode->i_flags, inode->i_generation,
3722 + l ? ", wh " : "", l, n);
3726 +void au_dpri_inode(struct inode *inode)
3728 + struct au_iinfo *iinfo;
3729 + aufs_bindex_t bindex;
3732 + err = do_pri_inode(-1, inode, NULL);
3733 + if (err || !au_test_aufs(inode->i_sb))
3736 + iinfo = au_ii(inode);
3739 + dpri("i-1: bstart %d, bend %d, gen %d\n",
3740 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode));
3741 + if (iinfo->ii_bstart < 0)
3743 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++)
3744 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode,
3745 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
3748 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry,
3749 + struct list_head *intent)
3751 + struct dentry *wh = NULL;
3753 + if (!dentry || IS_ERR(dentry)) {
3754 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
3757 + /* do not call dget_parent() here */
3758 + dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x, intent %d\n",
3760 + AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
3761 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
3762 + atomic_read(&dentry->d_count), dentry->d_flags, !!intent);
3763 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
3764 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
3766 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
3768 + do_pri_inode(bindex, dentry->d_inode, wh);
3772 +static struct list_head *au_dbg_h_intent(struct au_dinfo *dinfo,
3773 + aufs_bindex_t bindex)
3775 +#ifdef CONFIG_AUFS_BR_NFS
3776 + return dinfo->di_hdentry[0 + bindex].hd_intent_list;
3782 +void au_dpri_dentry(struct dentry *dentry)
3784 + struct au_dinfo *dinfo;
3785 + aufs_bindex_t bindex;
3788 + err = do_pri_dentry(-1, dentry, NULL);
3789 + if (err || !au_test_aufs(dentry->d_sb))
3792 + dinfo = au_di(dentry);
3795 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
3796 + dinfo->di_bstart, dinfo->di_bend,
3797 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
3798 + if (dinfo->di_bstart < 0)
3800 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
3801 + do_pri_dentry(bindex, dinfo->di_hdentry[0 + bindex].hd_dentry,
3802 + au_dbg_h_intent(dinfo, bindex));
3805 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
3809 + if (!file || IS_ERR(file)) {
3810 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
3816 + && au_test_aufs(file->f_dentry->d_sb)
3818 + snprintf(a, sizeof(a), ", mmapped %d", au_test_mmapped(file));
3819 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, pos %llu%s\n",
3820 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
3822 + if (file->f_dentry)
3823 + do_pri_dentry(bindex, file->f_dentry, NULL);
3827 +void au_dpri_file(struct file *file)
3829 + struct au_finfo *finfo;
3830 + aufs_bindex_t bindex;
3833 + err = do_pri_file(-1, file);
3834 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
3837 + finfo = au_fi(file);
3840 + if (finfo->fi_bstart < 0)
3842 + for (bindex = finfo->fi_bstart; bindex <= finfo->fi_bend; bindex++) {
3843 + struct au_hfile *hf;
3844 + hf = finfo->fi_hfile + bindex;
3845 + do_pri_file(bindex, hf ? hf->hf_file : NULL);
3849 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
3851 + struct vfsmount *mnt;
3852 + struct super_block *sb;
3854 + if (!br || IS_ERR(br)
3855 + || !(mnt = br->br_mnt) || IS_ERR(mnt)
3856 + || !(sb = mnt->mnt_sb) || IS_ERR(sb)) {
3857 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
3861 + dpri("s%d: {perm 0x%x, cnt %d, wbr %p}, "
3862 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt(BIAS) %d, active %d, "
3864 + bindex, br->br_perm, au_br_count(br), br->br_wbr,
3865 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
3866 + sb->s_flags, sb->s_count - S_BIAS,
3867 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
3871 +void au_dpri_sb(struct super_block *sb)
3873 + struct au_sbinfo *sbinfo;
3874 + aufs_bindex_t bindex;
3876 + /* to reuduce stack size */
3878 + struct vfsmount mnt;
3879 + struct au_branch fake;
3882 + /* this function can be called from magic sysrq */
3883 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
3884 + if (unlikely(!a)) {
3885 + dpri("no memory\n");
3889 + a->mnt.mnt_sb = sb;
3890 + a->fake.br_perm = 0;
3891 + a->fake.br_mnt = &a->mnt;
3892 + a->fake.br_xino.xi_file = NULL;
3893 + atomic_set(&a->fake.br_count, 0);
3894 + smp_mb(); /* atomic_set */
3895 + err = do_pri_br(-1, &a->fake);
3897 + dpri("dev 0x%x\n", sb->s_dev);
3898 + if (err || !au_test_aufs(sb))
3901 + sbinfo = au_sbi(sb);
3904 + dpri("nw %d, gen %u, kobj %d\n",
3905 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
3906 + atomic_read(&sbinfo->si_kobj.kref.refcount));
3907 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
3908 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
3911 +/* ---------------------------------------------------------------------- */
3913 +void au_dbg_sleep(int sec)
3915 + static DECLARE_WAIT_QUEUE_HEAD(wq);
3916 + wait_event_timeout(wq, 0, sec * HZ);
3919 +void au_dbg_sleep_jiffy(int jiffy)
3921 + static DECLARE_WAIT_QUEUE_HEAD(wq);
3922 + wait_event_timeout(wq, 0, jiffy);
3925 +void au_dbg_iattr(struct iattr *ia)
3927 +#define AuBit(name) if (ia->ia_valid & ATTR_ ## name) \
3947 + dpri("ia_file %p\n", ia->ia_file);
3950 +/* ---------------------------------------------------------------------- */
3952 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo)
3954 +#ifdef ForceInotify
3955 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_INOTIFY);
3958 + au_opt_set(sbinfo->si_mntflags, DLGT);
3960 +#ifdef ForceNoPlink
3961 + au_opt_clr(sbinfo->si_mntflags, PLINK);
3964 + au_opt_clr(sbinfo->si_mntflags, XINO);
3966 +#ifdef ForceNoRefrof
3967 + au_opt_clr(sbinfo->si_mntflags, REFROF);
3970 + au_opt_set(sbinfo->si_mntflags, SHWH);
3973 +#ifdef CONFIG_AUFS_DEBUG_LOCK
3976 + for (i = 0; i < AuDbgLock_Last; i++)
3977 + au_spl_init(sbinfo->si_dbg_lock + i);
3982 +int __init au_debug_init(void)
3984 + aufs_bindex_t bindex;
3985 + struct au_vdir_destr destr;
3988 + AuDebugOn(bindex >= 0);
3991 + AuDebugOn(destr.len < NAME_MAX);
3993 +#ifdef CONFIG_4KSTACKS
3994 + AuWarn("CONFIG_4KSTACKS is defined.\n");
4001 +#if 0 /* verbose debug */
4004 + struct au_branch *br;
4005 + struct au_dinfo *di;
4006 + struct au_finfo *fi;
4007 + struct au_iinfo *ii;
4008 + struct au_hinode *hi;
4009 + struct au_sbinfo *si;
4010 + struct au_vdir_destr *destr;
4011 + struct au_vdir_de *de;
4012 + struct au_vdir_wh *wh;
4013 + struct au_vdir *vd;
4018 + "id %d, perm %d, mnt %d, count %d, "
4020 + "xup %d, xrun %d, "
4023 + offsetof(typeof(*u.br), br_xino),
4024 + offsetof(typeof(*u.br), br_id),
4025 + offsetof(typeof(*u.br), br_perm),
4026 + offsetof(typeof(*u.br), br_mnt),
4027 + offsetof(typeof(*u.br), br_count),
4028 + offsetof(typeof(*u.br), wbr),
4029 + offsetof(typeof(*u.br), br_xino_upper),
4030 + offsetof(typeof(*u.br), br_xino_running),
4031 + offsetof(typeof(*u.br), br_generation),
4032 + offsetof(typeof(*u.br), br_sabr),
4034 + pr_info("di{gen %d, rwsem %d, bstart %d, bend %d, bwh %d, "
4035 + "bdiropq %d, hdentry %d} %d\n",
4036 + offsetof(typeof(*u.di), di_generation),
4037 + offsetof(typeof(*u.di), di_rwsem),
4038 + offsetof(typeof(*u.di), di_bstart),
4039 + offsetof(typeof(*u.di), di_bend),
4040 + offsetof(typeof(*u.di), di_bwh),
4041 + offsetof(typeof(*u.di), di_bdiropq),
4042 + offsetof(typeof(*u.di), di_hdentry),
4044 + pr_info("fi{gen %d, rwsem %d, hfile %d, bstart %d, bend %d, "
4045 + "h_vm_ops %d, vdir_cach %d} %d\n",
4046 + offsetof(typeof(*u.fi), fi_generation),
4047 + offsetof(typeof(*u.fi), fi_rwsem),
4048 + offsetof(typeof(*u.fi), fi_hfile),
4049 + offsetof(typeof(*u.fi), fi_bstart),
4050 + offsetof(typeof(*u.fi), fi_bend),
4051 + offsetof(typeof(*u.fi), fi_h_vm_ops),
4052 + offsetof(typeof(*u.fi), fi_vdir_cache),
4054 + pr_info("ii{gen %d, hsb %d, "
4055 + "rwsem %d, bstart %d, bend %d, hinode %d, vdir %d} "
4057 + offsetof(typeof(*u.ii), ii_generation),
4058 + offsetof(typeof(*u.ii), ii_hsb1),
4059 + offsetof(typeof(*u.ii), ii_rwsem),
4060 + offsetof(typeof(*u.ii), ii_bstart),
4061 + offsetof(typeof(*u.ii), ii_bend),
4062 + offsetof(typeof(*u.ii), ii_hinode),
4063 + offsetof(typeof(*u.ii), ii_vdir),
4065 + pr_info("hi{inode %d, id %d, notify %d, wh %d} %d\n",
4066 + offsetof(typeof(*u.hi), hi_inode),
4067 + offsetof(typeof(*u.hi), hi_id),
4068 + offsetof(typeof(*u.hi), hi_notify),
4069 + offsetof(typeof(*u.hi), hi_whdentry),
4071 + pr_info("si{nwt %d, rwsem %d, gen %d, stat %d, "
4072 + "bend %d, last id %d, br %d, "
4073 + "cpup %d, creat %d, ops %d, ops %d, "
4076 + "xread %d, xwrite %d, xib %d, xmtx %d, buf %d, "
4077 + "xlast %d, xnext %d, "
4083 + /* "lvma_l %d, lvma %d" */
4085 + offsetof(typeof(*u.si), si_nowait),
4086 + offsetof(typeof(*u.si), si_rwsem),
4087 + offsetof(typeof(*u.si), si_generation),
4088 + offsetof(typeof(*u.si), au_si_status),
4089 + offsetof(typeof(*u.si), si_bend),
4090 + offsetof(typeof(*u.si), si_last_br_id),
4091 + offsetof(typeof(*u.si), si_branch),
4092 + offsetof(typeof(*u.si), si_wbr_copyup),
4093 + offsetof(typeof(*u.si), si_wbr_create),
4094 + offsetof(typeof(*u.si), si_wbr_copyup_ops),
4095 + offsetof(typeof(*u.si), si_wbr_create_ops),
4096 + offsetof(typeof(*u.si), si_wbr_rr_next),
4097 + offsetof(typeof(*u.si), si_wbr_mfs),
4098 + offsetof(typeof(*u.si), si_mntflags),
4099 + offsetof(typeof(*u.si), si_xread),
4100 + offsetof(typeof(*u.si), si_xwrite),
4101 + offsetof(typeof(*u.si), si_xib),
4102 + offsetof(typeof(*u.si), si_xib_mtx),
4103 + offsetof(typeof(*u.si), si_xib_buf),
4104 + offsetof(typeof(*u.si), si_xib_last_pindex),
4105 + offsetof(typeof(*u.si), si_xib_next_bit),
4106 + offsetof(typeof(*u.si), si_rdcache),
4107 + offsetof(typeof(*u.si), si_dirwh),
4108 + offsetof(typeof(*u.si), si_plink),
4109 + offsetof(typeof(*u.si), si_mnt),
4110 + offsetof(typeof(*u.si), si_sa),
4111 + /*offsetof(typeof(*u.si), si_lvma_lock),
4112 + offsetof(typeof(*u.si), si_lvma),*/
4114 + pr_info("destr{len %d, name %d} %d\n",
4115 + offsetof(typeof(*u.destr), len),
4116 + offsetof(typeof(*u.destr), name),
4117 + sizeof(*u.destr));
4118 + pr_info("de{ino %d, type %d, str %d} %d\n",
4119 + offsetof(typeof(*u.de), de_ino),
4120 + offsetof(typeof(*u.de), de_type),
4121 + offsetof(typeof(*u.de), de_str),
4123 + pr_info("wh{hash %d, bindex %d, str %d} %d\n",
4124 + offsetof(typeof(*u.wh), wh_hash),
4125 + offsetof(typeof(*u.wh), wh_bindex),
4126 + offsetof(typeof(*u.wh), wh_str),
4128 + pr_info("vd{deblk %d, nblk %d, last %d, ver %d, jiffy %d} %d\n",
4129 + offsetof(typeof(*u.vd), vd_deblk),
4130 + offsetof(typeof(*u.vd), vd_nblk),
4131 + offsetof(typeof(*u.vd), vd_last),
4132 + offsetof(typeof(*u.vd), vd_version),
4133 + offsetof(typeof(*u.vd), vd_jiffy),
4140 diff -urN linux/fs/aufs/debug.h linux-aufs/fs/aufs/debug.h
4141 --- linux/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
4142 +++ linux-aufs/fs/aufs/debug.h 2009-03-12 16:18:04.000000000 +0100
4145 + * Copyright (C) 2005-2009 Junjiro Okajima
4147 + * This program, aufs is free software; you can redistribute it and/or modify
4148 + * it under the terms of the GNU General Public License as published by
4149 + * the Free Software Foundation; either version 2 of the License, or
4150 + * (at your option) any later version.
4152 + * This program is distributed in the hope that it will be useful,
4153 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4154 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4155 + * GNU General Public License for more details.
4157 + * You should have received a copy of the GNU General Public License
4158 + * along with this program; if not, write to the Free Software
4159 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4163 + * debug print functions
4168 +#ifndef __AUFS_DEBUG_H__
4169 +#define __AUFS_DEBUG_H__
4173 +#include <linux/fs.h>
4174 +#include <linux/kd.h>
4175 +#include <linux/vt_kern.h>
4176 +#include <linux/sysrq.h>
4178 +/* to debug easier, do not make it an inlined function */
4179 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
4181 +#ifdef CONFIG_AUFS_DEBUG
4182 +/* sparse warns about pointer */
4183 +#define AuDebugOn(a) BUG_ON(!!(a))
4184 +extern atomic_t au_cond;
4185 +#define au_debug_on() atomic_inc_return(&au_cond)
4186 +#define au_debug_off() atomic_dec_return(&au_cond)
4187 +static inline int au_debug_test(void)
4189 + return atomic_read(&au_cond);
4192 +#define AuDebugOn(a) do {} while (0)
4193 +#define au_debug_on() do {} while (0)
4194 +#define au_debug_off() do {} while (0)
4195 +static inline int au_debug_test(void)
4199 +#endif /* CONFIG_AUFS_DEBUG */
4201 +/* ---------------------------------------------------------------------- */
4204 +#if defined(CONFIG_LKTR) || defined(CONFIG_LKTR_MODULE)
4205 +#include <linux/lktr.h>
4206 +#ifdef CONFIG_AUFS_DEBUG
4208 +#define LktrCond unlikely(au_debug_test() || (lktr_cond && lktr_cond()))
4211 +#define LktrCond au_debug_test()
4212 +#define LKTRDumpVma(pre, vma, suf) do {} while (0)
4213 +#define LKTRDumpStack() do {} while (0)
4214 +#define LKTRTrace(fmt, args...) do { \
4216 + AuDbg(fmt, ##args); \
4218 +#define LKTRLabel(label) LKTRTrace("%s\n", #label)
4219 +#endif /* CONFIG_LKTR */
4221 +#define AuTraceErr(e) do { \
4222 + if (unlikely((e) < 0)) \
4223 + LKTRTrace("err %d\n", (int)(e)); \
4226 +#define AuTraceErrPtr(p) do { \
4228 + LKTRTrace("err %ld\n", PTR_ERR(p)); \
4231 +#define AuTraceEnter() LKTRLabel(enter)
4233 +/* dirty macros for debug print, use with "%.*s" and caution */
4234 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
4235 +#define AuDLNPair(d) AuLNPair(&(d)->d_name)
4237 +/* ---------------------------------------------------------------------- */
4239 +#define AuDpri(lvl, fmt, arg...) \
4240 + printk(lvl AUFS_NAME " %s:%d:%s[%d]: " fmt, \
4241 + __func__, __LINE__, current->comm, current->pid, ##arg)
4242 +#define AuDbg(fmt, arg...) AuDpri(KERN_DEBUG, fmt, ##arg)
4243 +#define AuInfo(fmt, arg...) AuDpri(KERN_INFO, fmt, ##arg)
4244 +#define AuWarn(fmt, arg...) AuDpri(KERN_WARNING, fmt, ##arg)
4245 +#define AuErr(fmt, arg...) AuDpri(KERN_ERR, fmt, ##arg)
4246 +#define AuIOErr(fmt, arg...) AuErr("I/O Error, " fmt, ##arg)
4247 +#define AuIOErrWhck(fmt, arg...) AuErr("I/O Error, try whck. " fmt, ##arg)
4248 +#define AuWarn1(fmt, arg...) do { \
4249 + static unsigned char _c; \
4251 + AuWarn(fmt, ##arg); \
4254 +#define AuErr1(fmt, arg...) do { \
4255 + static unsigned char _c; \
4257 + AuErr(fmt, ##arg); \
4260 +#define AuIOErr1(fmt, arg...) do { \
4261 + static unsigned char _c; \
4263 + AuIOErr(fmt, ##arg); \
4266 +#define AuUnsupportMsg "This operation is not supported." \
4267 + " Please report this application to aufs-users ML."
4268 +#define AuUnsupport(fmt, args...) do { \
4269 + AuErr(AuUnsupportMsg "\n" fmt, ##args); \
4273 +/* ---------------------------------------------------------------------- */
4276 +#ifdef CONFIG_AUFS_DEBUG
4277 +extern char *au_plevel;
4279 +void au_dpri_whlist(struct au_nhash *whlist);
4281 +void au_dpri_vdir(struct au_vdir *vdir);
4282 +void au_dpri_inode(struct inode *inode);
4283 +void au_dpri_dentry(struct dentry *dentry);
4284 +void au_dpri_file(struct file *filp);
4285 +void au_dpri_sb(struct super_block *sb);
4286 +void au_dbg_sleep(int sec);
4287 +void au_dbg_sleep_jiffy(int jiffy);
4289 +#ifndef ATTR_TIMES_SET
4290 +#define ATTR_TIMES_SET 0
4292 +void au_dbg_iattr(struct iattr *ia);
4293 +int __init au_debug_init(void);
4294 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
4295 +#define AuDbgWhlist(w) do { \
4296 + LKTRTrace(#w "\n"); \
4297 + au_dpri_whlist(w); \
4300 +#define AuDbgVdir(v) do { \
4301 + LKTRTrace(#v "\n"); \
4302 + au_dpri_vdir(v); \
4305 +#define AuDbgInode(i) do { \
4306 + LKTRTrace(#i "\n"); \
4307 + au_dpri_inode(i); \
4310 +#define AuDbgDentry(d) do { \
4311 + LKTRTrace(#d "\n"); \
4312 + au_dpri_dentry(d); \
4315 +#define AuDbgFile(f) do { \
4316 + LKTRTrace(#f "\n"); \
4317 + au_dpri_file(f); \
4320 +#define AuDbgSb(sb) do { \
4321 + LKTRTrace(#sb "\n"); \
4325 +#define AuDbgSleep(sec) do { \
4326 + AuDbg("sleep %d sec\n", sec); \
4327 + au_dbg_sleep(sec); \
4330 +#define AuDbgSleepJiffy(jiffy) do { \
4331 + AuDbg("sleep %d jiffies\n", jiffy); \
4332 + au_dbg_sleep_jiffy(jiffy); \
4335 +#define AuDbgIAttr(ia) do { \
4336 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
4337 + au_dbg_iattr(ia); \
4340 +static inline int au_debug_init(void)
4344 +static inline void au_debug_sbinfo_init(struct au_sbinfo *sbinfo)
4348 +#define AuDbgWhlist(w) do {} while (0)
4349 +#define AuDbgVdir(v) do {} while (0)
4350 +#define AuDbgInode(i) do {} while (0)
4351 +#define AuDbgDentry(d) do {} while (0)
4352 +#define AuDbgFile(f) do {} while (0)
4353 +#define AuDbgSb(sb) do {} while (0)
4354 +#define AuDbgSleep(sec) do {} while (0)
4355 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
4356 +#define AuDbgIAttr(ia) do {} while (0)
4357 +#endif /* CONFIG_AUFS_DEBUG */
4360 +#define AuDbgSleep_UdbaRace() AuDbgSleep(DbgUdbaRace)
4362 +#define AuDbgSleep_UdbaRace() do {} while (0)
4365 +/* ---------------------------------------------------------------------- */
4367 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
4368 +int __init au_sysrq_init(void);
4369 +void au_sysrq_fin(void);
4371 +#ifdef CONFIG_HW_CONSOLE
4372 +#define au_dbg_blocked() do { \
4374 + handle_sysrq('w', vc_cons[fg_console].d->vc_tty); \
4377 +#define au_dbg_blocked() do {} while (0)
4381 +static inline int au_sysrq_init(void)
4385 +#define au_sysrq_fin() do {} while (0)
4386 +#define au_dbg_blocked() do {} while (0)
4387 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
4390 + AuDbgLock_SI_LOCKING,
4391 + AuDbgLock_SI_LOCKED,
4392 + AuDbgLock_DI_LOCKING,
4393 + AuDbgLock_DI_LOCKED,
4394 + AuDbgLock_II_LOCKING,
4395 + AuDbgLock_II_LOCKED,
4398 +#ifdef CONFIG_AUFS_DEBUG_LOCK
4399 +void au_dbg_locking_si_reg(struct super_block *sb, int flags);
4400 +void au_dbg_locking_si_unreg(struct super_block *sb, int flags);
4401 +void au_dbg_locked_si_reg(struct super_block *sb, int flags);
4402 +void au_dbg_locked_si_unreg(struct super_block *sb, int flags);
4403 +void au_dbg_locking_di_reg(struct dentry *d, int flags, unsigned int lsc);
4404 +void au_dbg_locking_di_unreg(struct dentry *d, int flags);
4405 +void au_dbg_locked_di_reg(struct dentry *d, int flags, unsigned int lsc);
4406 +void au_dbg_locked_di_unreg(struct dentry *d, int flags);
4407 +void au_dbg_locking_ii_reg(struct inode *i, int flags, unsigned int lsc);
4408 +void au_dbg_locking_ii_unreg(struct inode *i, int flags);
4409 +void au_dbg_locked_ii_reg(struct inode *i, int flags, unsigned int lsc);
4410 +void au_dbg_locked_ii_unreg(struct inode *i, int flags);
4413 +void au_dbg_locking_si_reg(struct super_block *sb, int flags)
4418 +void au_dbg_locking_si_unreg(struct super_block *sb, int flags)
4423 +void au_dbg_locked_si_reg(struct super_block *sb, int flags)
4428 +void au_dbg_locked_si_unreg(struct super_block *sb, int flags)
4434 +void au_dbg_locking_di_reg(struct dentry *d, int flags, unsigned int lsc)
4439 +void au_dbg_locking_di_unreg(struct dentry *d, int flags)
4444 +void au_dbg_locked_di_reg(struct dentry *d, int flags, unsigned int lsc)
4449 +void au_dbg_locked_di_unreg(struct dentry *d, int flags)
4454 +void au_dbg_locking_ii_reg(struct inode *i, int flags, unsigned int lsc)
4459 +void au_dbg_locking_ii_unreg(struct inode *i, int flags)
4464 +void au_dbg_locked_ii_reg(struct inode *i, int flags, unsigned int lsc)
4469 +void au_dbg_locked_ii_unreg(struct inode *i, int flags)
4473 +#endif /* CONFIG_AUFS_DEBUG_LOCK */
4475 +#endif /* __KERNEL__ */
4476 +#endif /* __AUFS_DEBUG_H__ */
4477 diff -urN linux/fs/aufs/dentry.c linux-aufs/fs/aufs/dentry.c
4478 --- linux/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
4479 +++ linux-aufs/fs/aufs/dentry.c 2009-03-12 16:18:04.000000000 +0100
4482 + * Copyright (C) 2005-2009 Junjiro Okajima
4484 + * This program, aufs is free software; you can redistribute it and/or modify
4485 + * it under the terms of the GNU General Public License as published by
4486 + * the Free Software Foundation; either version 2 of the License, or
4487 + * (at your option) any later version.
4489 + * This program is distributed in the hope that it will be useful,
4490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4492 + * GNU General Public License for more details.
4494 + * You should have received a copy of the GNU General Public License
4495 + * along with this program; if not, write to the Free Software
4496 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4500 + * lookup and dentry operations
4507 +/* ---------------------------------------------------------------------- */
4510 + * au_lkup_one() is a generic abstract entry function which calls
4511 + * lookup_one_len() or __lookup_hash() finally. it is some condisions that makes
4512 + * lookup complicated, which are nfs branch, open-intent and dlgt mode.
4515 +#if defined(CONFIG_AUFS_BR_NFS) || defined(CONFIG_AUFS_DLGT)
4516 +/* cf. lookup_one_len() in linux/fs/namei.c */
4517 +struct dentry *au_lkup_one(const char *name, struct dentry *parent, int len,
4518 + struct au_ndx *ndx)
4520 + struct dentry *dentry;
4522 + LKTRTrace("%.*s/%.*s, ndx{%d, 0x%x}\n",
4523 + AuDLNPair(parent), len, name, !!ndx->nfsmnt, ndx->flags);
4525 + ndx->nd_file = NULL;
4527 + dentry = au_lkup_one_dlgt(name, parent, len, ndx->flags);
4529 + dentry = au_lkup_hash(name, parent, len, ndx);
4531 + AuTraceErrPtr(dentry);
4534 +#endif /* CONFIG_AUFS_BR_NFS || CONFIG_AUFS_DLGT */
4536 +struct au_lkup_one_args {
4537 + struct dentry **errp;
4539 + struct dentry *parent;
4541 + struct au_ndx *ndx;
4544 +static void au_call_lkup_one(void *args)
4546 + struct au_lkup_one_args *a = args;
4547 + *a->errp = au_lkup_one(a->name, a->parent, a->len, a->ndx);
4550 +#define AuLkup_ALLOW_NEG 1
4551 +#define AuLkup_DLGT (1 << 1)
4552 +#define AuLkup_DIRPERM1 (1 << 2)
4553 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
4554 +#define au_fset_lkup(flags, name) { (flags) |= AuLkup_##name; }
4555 +#define au_fclr_lkup(flags, name) { (flags) &= ~AuLkup_##name; }
4556 +#ifndef CONFIG_AUFS_DLGT
4558 +#define AuLkup_DLGT 0
4559 +#undef AuLkup_DIRPERM1
4560 +#define AuLkup_DIRPERM1 0
4563 +struct au_do_lookup_args {
4564 + unsigned int flags;
4566 + struct nameidata *nd;
4570 + * returns positive/negative dentry, NULL or an error.
4571 + * NULL means whiteout-ed or not-found.
4573 +static /* noinline_for_stack */
4574 +struct dentry *au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
4575 + aufs_bindex_t bindex, struct qstr *wh_name,
4576 + struct au_do_lookup_args *args)
4578 + struct dentry *h_dentry;
4579 + int err, wh_found, opq;
4580 + unsigned char wh_able;
4581 + struct inode *h_dir, *h_inode, *inode;
4582 + struct qstr *name;
4583 + struct super_block *sb;
4584 + unsigned int nd_flags;
4585 + struct au_ndx ndx = {
4589 + const int allow_neg = au_ftest_lkup(args->flags, ALLOW_NEG);
4591 + LKTRTrace("%.*s/%.*s, b%d, {flags 0x%x, type 0%o, nd %d}\n",
4592 + AuDLNPair(h_parent), AuDLNPair(dentry), bindex,
4593 + args->flags, args->type, !!args->nd);
4595 + LKTRTrace("nd{0x%x}\n", args->nd->flags);
4596 + AuDebugOn(IS_ROOT(dentry));
4597 + h_dir = h_parent->d_inode;
4601 + sb = dentry->d_sb;
4602 + ndx.nfsmnt = au_nfsmnt(sb, bindex);
4603 + if (au_ftest_lkup(args->flags, DLGT))
4604 + au_fset_ndx(ndx.flags, DLGT);
4605 + if (au_ftest_lkup(args->flags, DIRPERM1))
4606 + au_fset_ndx(ndx.flags, DIRPERM1);
4607 + LKTRTrace("nfsmnt %p\n", ndx.nfsmnt);
4608 + ndx.br = au_sbr(sb, bindex);
4609 + wh_able = !!au_br_whable(ndx.br->br_perm);
4610 + name = &dentry->d_name;
4612 + wh_found = au_test_robr_wh(name, h_parent, wh_name,
4613 + /*try_sio*/0, &ndx);
4614 + h_dentry = ERR_PTR(wh_found);
4617 + if (unlikely(wh_found < 0))
4620 + /* We found a whiteout */
4621 + /* au_set_dbend(dentry, bindex); */
4622 + au_set_dbwh(dentry, bindex);
4624 + return NULL; /* success */
4626 + && au_test_nfs(h_parent->d_sb)
4627 + && (ndx.nd->flags & LOOKUP_CREATE)) {
4628 + nd_flags = ndx.nd->flags;
4629 + ndx.nd->flags &= ~(LOOKUP_OPEN | LOOKUP_CREATE);
4633 + /* do not superio. */
4634 + h_dentry = au_lkup_one(name->name, h_parent, name->len, &ndx);
4635 + if (IS_ERR(h_dentry))
4637 + AuDebugOn(d_unhashed(h_dentry));
4638 + h_inode = h_dentry->d_inode;
4642 + } else if (wh_found
4643 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
4646 + if (au_dbend(dentry) <= bindex)
4647 + au_set_dbend(dentry, bindex);
4648 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
4649 + au_set_dbstart(dentry, bindex);
4650 + au_set_h_dptr(dentry, bindex, h_dentry);
4652 + err = au_br_nfs_h_intent(ndx.nd_file, dentry, bindex, args->nd);
4653 + if (unlikely(err)) {
4654 + h_dentry = ERR_PTR(err);
4658 + inode = dentry->d_inode;
4659 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
4660 + || (inode && !S_ISDIR(inode->i_mode)))
4661 + goto out; /* success */
4663 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
4664 + opq = au_diropq_test(h_dentry, &ndx);
4665 + mutex_unlock(&h_inode->i_mutex);
4667 + au_set_dbdiropq(dentry, bindex);
4668 + else if (unlikely(opq < 0)) {
4669 + au_set_h_dptr(dentry, bindex, NULL);
4670 + h_dentry = ERR_PTR(opq);
4679 + ndx.nd->flags |= (nd_flags & (LOOKUP_OPEN | LOOKUP_CREATE));
4680 + AuTraceErrPtr(h_dentry);
4685 + * returns the number of hidden positive dentries,
4686 + * otherwise an error.
4687 + * can be called at unlinking with @type is zero.
4689 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
4690 + struct nameidata *nd)
4692 + int npositive, err;
4693 + unsigned int mnt_flags;
4694 + aufs_bindex_t bindex, btail, bdiropq;
4695 + unsigned char isdir;
4696 + struct qstr whname;
4697 + struct au_do_lookup_args args = {
4701 + const struct qstr *name = &dentry->d_name;
4702 + struct dentry *parent;
4703 + struct super_block *sb;
4704 + struct inode *inode;
4706 + LKTRTrace("%.*s, b%d, type 0%o\n", AuLNPair(name), bstart, type);
4707 + AuDebugOn(bstart < 0 || IS_ROOT(dentry));
4709 + /* dir may not be locked */
4710 + parent = dget_parent(dentry);
4712 + err = au_test_robr_shwh(dentry->d_sb, name);
4713 + if (unlikely(err))
4716 + err = au_wh_name_alloc(name->name, name->len, &whname);
4717 + if (unlikely(err))
4720 + sb = dentry->d_sb;
4721 + mnt_flags = au_mntflags(sb);
4722 + inode = dentry->d_inode;
4723 + isdir = !!(inode && S_ISDIR(inode->i_mode));
4725 + if (au_test_dlgt(mnt_flags))
4726 + au_fset_lkup(args.flags, DLGT);
4727 + if (au_test_dirperm1(mnt_flags))
4728 + au_fset_lkup(args.flags, DIRPERM1);
4730 + au_fset_lkup(args.flags, ALLOW_NEG);
4732 + btail = au_dbtaildir(parent);
4733 + for (bindex = bstart; bindex <= btail; bindex++) {
4734 + struct dentry *h_parent, *h_dentry;
4735 + struct inode *h_inode, *h_dir;
4737 + h_dentry = au_h_dptr(dentry, bindex);
4739 + if (h_dentry->d_inode)
4741 + if (type != S_IFDIR)
4745 + h_parent = au_h_dptr(parent, bindex);
4748 + h_dir = h_parent->d_inode;
4749 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
4752 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
4753 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
4755 + mutex_unlock(&h_dir->i_mutex);
4756 + err = PTR_ERR(h_dentry);
4757 + if (IS_ERR(h_dentry))
4759 + au_fclr_lkup(args.flags, ALLOW_NEG);
4761 + if (au_dbwh(dentry) >= 0)
4765 + h_inode = h_dentry->d_inode;
4770 + args.type = h_inode->i_mode & S_IFMT;
4771 + if (args.type != S_IFDIR)
4774 + /* the type of lowers may be different */
4775 + bdiropq = au_dbdiropq(dentry);
4776 + if (bdiropq >= 0 && bdiropq <= bindex)
4782 + LKTRLabel(positive);
4783 + au_update_dbstart(dentry);
4786 + if (!au_opt_test(mnt_flags, UDBA_NONE) && au_dbstart(dentry) < 0)
4787 + /* both of real entry and whiteout found */
4791 + au_wh_name_free(&whname);
4798 +struct dentry *au_sio_lkup_one(const char *name, struct dentry *parent, int len,
4799 + struct au_ndx *ndx)
4801 + struct dentry *dentry;
4804 + LKTRTrace("%.*s/%.*s\n", AuDLNPair(parent), len, name);
4806 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC,
4807 + au_ftest_ndx(ndx->flags, DLGT)))
4808 + dentry = au_lkup_one(name, parent, len, ndx);
4811 + unsigned int flags = ndx->flags;
4812 + struct au_lkup_one_args args = {
4820 + au_fclr_ndx(ndx->flags, DLGT);
4821 + au_fclr_ndx(ndx->flags, DIRPERM1);
4822 + wkq_err = au_wkq_wait(au_call_lkup_one, &args, /*dlgt*/0);
4823 + if (unlikely(wkq_err))
4824 + dentry = ERR_PTR(wkq_err);
4825 + ndx->flags = flags;
4828 + AuTraceErrPtr(dentry);
4833 + * lookup @dentry on @bindex which should be negative.
4835 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
4838 + struct dentry *parent, *h_parent, *h_dentry;
4839 + struct inode *h_dir;
4840 + struct au_ndx ndx = {
4845 + struct super_block *sb;
4846 + unsigned int mnt_flags;
4848 + LKTRTrace("%.*s, b%d\n", AuDLNPair(dentry), bindex);
4849 + /* dir may not be locked */
4850 + parent = dget_parent(dentry);
4851 + AuDebugOn(!parent || !parent->d_inode
4852 + || !S_ISDIR(parent->d_inode->i_mode));
4853 + h_parent = au_h_dptr(parent, bindex);
4854 + AuDebugOn(!h_parent);
4855 + h_dir = h_parent->d_inode;
4856 + AuDebugOn(!h_dir || !S_ISDIR(h_dir->i_mode));
4858 + sb = dentry->d_sb;
4859 + mnt_flags = au_mntflags(sb);
4860 + ndx.nfsmnt = au_nfsmnt(sb, bindex);
4861 + if (au_test_dlgt(mnt_flags))
4862 + au_fset_ndx(ndx.flags, DLGT);
4863 + if (au_test_dirperm1(mnt_flags))
4864 + au_fset_ndx(ndx.flags, DIRPERM1);
4865 + h_dentry = au_sio_lkup_one(dentry->d_name.name, h_parent,
4866 + dentry->d_name.len, &ndx);
4867 + err = PTR_ERR(h_dentry);
4868 + if (IS_ERR(h_dentry))
4870 + if (unlikely(h_dentry->d_inode)) {
4872 + AuIOErr("b%d %.*s should be negative.\n",
4873 + bindex, AuDLNPair(h_dentry));
4878 + if (bindex < au_dbstart(dentry))
4879 + au_set_dbstart(dentry, bindex);
4880 + if (au_dbend(dentry) < bindex)
4881 + au_set_dbend(dentry, bindex);
4882 + au_set_h_dptr(dentry, bindex, h_dentry);
4892 + * returns the number of found hidden positive dentries,
4893 + * otherwise an error.
4895 +int au_refresh_hdentry(struct dentry *dentry, mode_t type)
4897 + int npositive, new_sz;
4898 + struct au_dinfo *dinfo;
4899 + struct super_block *sb;
4900 + struct dentry *parent;
4901 + aufs_bindex_t bindex, parent_bend, parent_bstart, bwh, bdiropq, bend;
4902 + struct au_hdentry *p;
4905 + LKTRTrace("%.*s, type 0%o\n", AuDLNPair(dentry), type);
4906 + DiMustWriteLock(dentry);
4907 + sb = dentry->d_sb;
4908 + AuDebugOn(IS_ROOT(dentry));
4909 + sgen = au_sigen(sb);
4910 + parent = dget_parent(dentry);
4911 + AuDebugOn(au_digen(parent) != sgen
4912 + || au_iigen(parent->d_inode) != sgen);
4914 + npositive = -ENOMEM;
4915 + new_sz = sizeof(*dinfo->di_hdentry) * (au_sbend(sb) + 1);
4916 + dinfo = au_di(dentry);
4917 + p = au_kzrealloc(dinfo->di_hdentry, sizeof(*p) * (dinfo->di_bend + 1),
4918 + new_sz, GFP_NOFS);
4921 + dinfo->di_hdentry = p;
4923 + bend = dinfo->di_bend;
4924 + bwh = dinfo->di_bwh;
4925 + bdiropq = dinfo->di_bdiropq;
4926 + p += dinfo->di_bstart;
4927 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
4928 + struct dentry *hd, *hdp;
4929 + struct au_hdentry tmp, *q;
4930 + aufs_bindex_t new_bindex;
4932 + hd = p->hd_dentry;
4935 + hdp = dget_parent(hd);
4936 + if (hdp == au_h_dptr(parent, bindex)) {
4941 + new_bindex = au_find_dbindex(parent, hdp);
4943 + AuDebugOn(new_bindex == bindex);
4944 + if (dinfo->di_bwh == bindex)
4946 + if (dinfo->di_bdiropq == bindex)
4947 + bdiropq = new_bindex;
4948 + /* todo: test more? */
4949 + if (new_bindex < 0) {
4950 + au_hdput(p, /*do_free*/0);
4951 + p->hd_dentry = NULL;
4954 + /* swap two hidden dentries, and loop again */
4955 + q = dinfo->di_hdentry + new_bindex;
4959 + if (tmp.hd_dentry) {
4965 + /* todo: test more? */
4966 + dinfo->di_bwh = -1;
4967 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
4968 + dinfo->di_bwh = bwh;
4969 + dinfo->di_bdiropq = -1;
4971 + && bdiropq <= au_sbend(sb)
4972 + && au_sbr_whable(sb, bdiropq))
4973 + dinfo->di_bdiropq = bdiropq;
4974 + parent_bend = au_dbend(parent);
4975 + p = dinfo->di_hdentry;
4976 + for (bindex = 0; bindex <= parent_bend; bindex++, p++)
4977 + if (p->hd_dentry) {
4978 + dinfo->di_bstart = bindex;
4981 + p = dinfo->di_hdentry + parent_bend;
4982 + for (bindex = parent_bend; bindex >= 0; bindex--, p--)
4983 + if (p->hd_dentry) {
4984 + dinfo->di_bend = bindex;
4989 + parent_bstart = au_dbstart(parent);
4990 + if (type != S_IFDIR && dinfo->di_bstart == parent_bstart)
4991 + goto out_dgen; /* success */
4993 + npositive = au_lkup_dentry(dentry, parent_bstart, type, /*nd*/NULL);
4994 + if (npositive < 0)
4996 + if (dinfo->di_bwh >= 0 && dinfo->di_bwh <= dinfo->di_bstart)
5000 + au_update_digen(dentry);
5003 + AuTraceErr(npositive);
5007 +static int au_lock_nd(struct dentry *dentry, struct nameidata *nd)
5010 + if (nd && dentry != nd->path.dentry) {
5011 + di_read_lock_parent(nd->path.dentry, 0);
5017 +static void au_unlock_nd(int locked, struct nameidata *nd)
5020 + di_read_unlock(nd->path.dentry, 0);
5023 +/* #define TestingFuse */
5024 +static noinline_for_stack
5025 +int au_do_h_d_reval(struct dentry *dentry, aufs_bindex_t bindex,
5026 + struct nameidata *nd, struct dentry *h_dentry)
5028 + int err, valid, e;
5029 + int (*reval)(struct dentry *, struct nameidata *);
5030 + struct super_block *sb;
5031 + struct nameidata fake_nd, *p;
5033 + LKTRTrace("%.*s, b%d, nd %d\n", AuDLNPair(dentry), bindex, !!nd);
5037 + if (h_dentry->d_op)
5038 + reval = h_dentry->d_op->d_revalidate;
5042 + sb = dentry->d_sb;
5044 + memcpy(&fake_nd, nd, sizeof(*nd));
5045 + err = au_fake_intent(&fake_nd, au_sbr(sb, bindex));
5046 + if (unlikely(err)) {
5051 + p = au_fake_dm(&fake_nd, nd, sb, bindex);
5052 + AuDebugOn(IS_ERR(p));
5053 + AuDebugOn(nd && p != &fake_nd);
5054 + LKTRTrace("b%d\n", bindex);
5056 + /* it may return tri-state */
5057 + valid = reval(h_dentry, p);
5058 + if (unlikely(valid < 0))
5067 + e = au_hin_after_reval(p, dentry, bindex, nd->intent.open.file);
5068 +#ifndef TestingFuse
5069 + au_update_fuse_h_inode(p->path.mnt, h_dentry); /*ignore*/
5071 + if (unlikely(e && !err))
5074 +#ifndef TestingFuse
5076 + au_update_fuse_h_inode(NULL, h_dentry); /*ignore*/
5078 + au_fake_dm_release(p);
5085 +static noinline_for_stack
5086 +int h_d_revalidate(struct dentry *dentry, struct inode *inode,
5087 + struct nameidata *nd, int do_udba)
5090 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
5091 + unsigned char plus, locked, unhashed, is_root, h_plus;
5092 + struct super_block *sb;
5093 + struct inode *first, *h_inode, *h_cached_inode;
5094 + umode_t mode, h_mode;
5095 + struct dentry *h_dentry;
5096 + struct qstr *name;
5098 + LKTRTrace("%.*s, nd %d\n", AuDLNPair(dentry), !!nd);
5099 + AuDebugOn(inode && au_digen(dentry) != au_iigen(inode));
5102 + sb = dentry->d_sb;
5108 + unhashed = !!d_unhashed(dentry);
5109 + is_root = !!IS_ROOT(dentry);
5110 + name = &dentry->d_name;
5113 + * Theoretically, REVAL test should be unnecessary in case of INOTIFY.
5114 + * But inotify doesn't fire some necessary events,
5115 + * IN_ATTRIB for atime/nlink/pageio
5116 + * IN_DELETE for NFS dentry
5117 + * Let's do REVAL test too.
5119 + if (do_udba && inode) {
5120 + mode = (inode->i_mode & S_IFMT);
5121 + plus = (inode->i_nlink > 0);
5122 + first = au_h_iptr(inode, au_ibstart(inode));
5123 + ibs = au_ibstart(inode);
5124 + ibe = au_ibend(inode);
5127 + bstart = au_dbstart(dentry);
5129 + if (inode && S_ISDIR(inode->i_mode))
5130 + btail = au_dbtaildir(dentry);
5131 + locked = !!au_lock_nd(dentry, nd);
5132 + for (bindex = bstart; bindex <= btail; bindex++) {
5133 + h_dentry = au_h_dptr(dentry, bindex);
5137 + LKTRTrace("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
5139 + /* force re-lookup for fuse, in order to update attributes */
5140 + if (au_test_fuse(h_dentry->d_sb))
5144 + if (unlikely(do_udba
5146 + && (unhashed != !!d_unhashed(h_dentry)
5147 + || name->len != h_dentry->d_name.len
5148 + || memcmp(name->name, h_dentry->d_name.name,
5151 + LKTRTrace("unhash 0x%x 0x%x, %.*s %.*s\n",
5152 + unhashed, d_unhashed(h_dentry),
5153 + AuDLNPair(dentry), AuDLNPair(h_dentry));
5157 + err = au_do_h_d_reval(dentry, bindex, nd, h_dentry);
5158 + if (unlikely(err))
5159 + /* do not goto err, to keep the errno */
5162 + /* todo: plink too? */
5167 + h_inode = h_dentry->d_inode;
5168 + if (unlikely(!!inode != !!h_inode))
5173 + h_cached_inode = h_inode;
5175 + h_mode = (h_inode->i_mode & S_IFMT);
5176 + h_plus = (h_inode->i_nlink > 0);
5178 + if (inode && ibs <= bindex && bindex <= ibe)
5179 + h_cached_inode = au_h_iptr(inode, bindex);
5181 + LKTRTrace("{%d, 0%o, %p}, h{%d, 0%o, %p}\n",
5182 + plus, mode, h_cached_inode,
5183 + h_plus, h_mode, h_inode);
5184 + if (unlikely(plus != h_plus
5186 + || h_cached_inode != h_inode))
5194 + au_unlock_nd(locked, nd);
5197 + * judging by timestamps is meaningless since some filesystem uses
5198 + * CURRENT_TIME_SEC instead of CURRENT_TIME.
5201 + * NFS may stop IN_DELETE because of DCACHE_NFSFS_RENAMED.
5208 +static int simple_reval_dpath(struct dentry *dentry, au_gen_t sgen)
5212 + struct dentry *parent;
5213 + struct inode *inode;
5215 + LKTRTrace("%.*s, sgen %d\n", AuDLNPair(dentry), sgen);
5216 + SiMustAnyLock(dentry->d_sb);
5217 + DiMustWriteLock(dentry);
5218 + inode = dentry->d_inode;
5219 + AuDebugOn(!inode);
5221 + if (au_digen(dentry) == sgen && au_iigen(inode) == sgen)
5224 + parent = dget_parent(dentry);
5225 + di_read_lock_parent(parent, AuLock_IR);
5226 + AuDebugOn(au_digen(parent) != sgen
5227 + || au_iigen(parent->d_inode) != sgen);
5228 +#ifdef CONFIG_AUFS_DEBUG
5231 + struct au_dcsub_pages dpages;
5232 + struct au_dpage *dpage;
5233 + struct dentry **dentries;
5235 + err = au_dpages_init(&dpages, GFP_NOFS);
5237 + err = au_dcsub_pages_rev(&dpages, parent, /*do_include*/1, NULL,
5240 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
5241 + dpage = dpages.dpages + i;
5242 + dentries = dpage->dentries;
5243 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
5244 + AuDebugOn(au_digen(dentries[j]) != sgen);
5246 + au_dpages_free(&dpages);
5249 + type = (inode->i_mode & S_IFMT);
5250 + /* returns a number of positive dentries */
5251 + err = au_refresh_hdentry(dentry, type);
5253 + err = au_refresh_hinode(inode, dentry);
5254 + di_read_unlock(parent, AuLock_IR);
5260 +int au_reval_dpath(struct dentry *dentry, au_gen_t sgen)
5263 + struct dentry *d, *parent;
5264 + struct inode *inode;
5266 + LKTRTrace("%.*s, sgen %d\n", AuDLNPair(dentry), sgen);
5267 + AuDebugOn(!dentry->d_inode);
5268 + DiMustWriteLock(dentry);
5270 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIRS))
5271 + return simple_reval_dpath(dentry, sgen);
5273 + /* slow loop, keep it simple and stupid */
5274 + /* cf: au_cpup_dirs() */
5277 + while (au_digen(dentry) != sgen || au_iigen(dentry->d_inode) != sgen) {
5281 + parent = dget_parent(d);
5282 + if (au_digen(parent) == sgen
5283 + && au_iigen(parent->d_inode) == sgen)
5288 + inode = d->d_inode;
5290 + di_write_lock_child(d);
5292 + /* someone might update our dentry while we were sleeping */
5293 + if (au_digen(d) != sgen || au_iigen(d->d_inode) != sgen) {
5294 + di_read_lock_parent(parent, AuLock_IR);
5295 + /* returns a number of positive dentries */
5296 + err = au_refresh_hdentry(d, inode->i_mode & S_IFMT);
5298 + err = au_refresh_hinode(inode, d);
5299 + di_read_unlock(parent, AuLock_IR);
5303 + di_write_unlock(d);
5305 + if (unlikely(err))
5314 + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
5315 + * nfsd passes NULL as nameidata.
5317 +static int aufs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
5321 + unsigned char do_udba;
5322 + struct nameidata tmp_nd, *ndp;
5323 + struct super_block *sb;
5324 + struct inode *inode;
5326 + LKTRTrace("dentry %.*s\n", AuDLNPair(dentry));
5327 + if (nd && nd->path.dentry)
5328 + LKTRTrace("nd{%.*s, 0x%x}\n",
5329 + AuDLNPair(nd->path.dentry), nd->flags);
5331 + * dir case: AuDebugOn(dentry->d_parent != nd->dentry);
5332 + * remove failure case:AuDebugOn(!IS_ROOT(dentry)
5333 + * && d_unhashed(dentry));
5335 + AuDebugOn(!dentry->d_fsdata);
5338 + sb = dentry->d_sb;
5339 + aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW);
5340 + inode = dentry->d_inode;
5341 + sgen = au_sigen(sb);
5342 + if (au_digen(dentry) != sgen) {
5343 + AuDebugOn(IS_ROOT(dentry));
5344 +#ifdef ForceInotify
5345 + AuDbg("UDBA or digen, %.*s\n", AuDLNPair(dentry));
5348 + err = au_reval_dpath(dentry, sgen);
5349 + if (unlikely(err))
5351 + AuDebugOn(au_digen(dentry) != sgen);
5353 + if (inode && au_iigen(inode) != sgen) {
5354 + AuDebugOn(IS_ROOT(dentry));
5355 +#ifdef ForceInotify
5356 + AuDbg("UDBA or survived, %.*s\n", AuDLNPair(dentry));
5358 + err = au_refresh_hinode(inode, dentry);
5359 + if (unlikely(err))
5361 + AuDebugOn(au_iigen(inode) != sgen);
5363 + di_downgrade_lock(dentry, AuLock_IR);
5365 +#if 0 /* todo: support it? */
5366 + /* parent dir i_nlink is not updated in the case of setattr */
5367 + if (S_ISDIR(inode->i_mode)) {
5368 + mutex_lock(&inode->i_mutex);
5369 + ii_write_lock(inode);
5370 + au_cpup_attr_nlink(inode);
5371 + ii_write_unlock(inode);
5372 + mutex_unlock(&inode->i_mutex);
5376 + AuDebugOn(au_digen(dentry) != sgen);
5377 + AuDebugOn(inode && au_iigen(inode) != sgen);
5379 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
5380 + if (do_udba && inode) {
5381 + aufs_bindex_t bstart = au_ibstart(inode);
5383 + && au_test_higen(inode, au_h_iptr(inode, bstart)))
5386 + ndp = au_dup_nd(au_sbi(sb), &tmp_nd, nd);
5390 + nd->path.dentry = au_h_dptr(nd->path.dentry, bindex);
5391 + if (fake_nd->path.dentry) {
5392 + fake_nd->path.mnt = au_sbr_mnt(sb, bindex);
5393 + AuDebugOn(!fake_nd->path.mnt);
5394 + path_get(&fake_nd->path);
5399 + err = h_d_revalidate(dentry, inode, ndp, do_udba);
5400 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0))
5401 + /* both of real entry and whiteout found */
5406 + di_downgrade_lock(dentry, AuLock_IR);
5408 + au_store_fmode_exec(nd, inode);
5409 + aufs_read_unlock(dentry, AuLock_IR);
5413 + LKTRTrace("%.*s invalid\n", AuDLNPair(dentry));
5417 +static void aufs_d_release(struct dentry *dentry)
5419 + struct au_dinfo *dinfo;
5420 + aufs_bindex_t bend, bindex;
5422 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
5423 + AuDebugOn(!d_unhashed(dentry));
5425 + dinfo = dentry->d_fsdata;
5429 + /* dentry may not be revalidated */
5430 + bindex = dinfo->di_bstart;
5431 + if (bindex >= 0) {
5432 + struct au_hdentry *p;
5433 + bend = dinfo->di_bend;
5434 + AuDebugOn(bend < bindex);
5435 + p = dinfo->di_hdentry + bindex;
5436 + while (bindex++ <= bend) {
5438 + au_hdput(p, /*do_free*/1);
5442 + kfree(dinfo->di_hdentry);
5443 + au_rwsem_destroy(&dinfo->di_rwsem);
5444 + au_cache_free_dinfo(dinfo);
5445 + au_hin_di_reinit(dentry);
5448 +struct dentry_operations aufs_dop = {
5449 + .d_revalidate = aufs_d_revalidate,
5450 + .d_release = aufs_d_release,
5451 + /* never use d_delete, especially in case of nfs server */
5453 diff -urN linux/fs/aufs/dentry.h linux-aufs/fs/aufs/dentry.h
5454 --- linux/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
5455 +++ linux-aufs/fs/aufs/dentry.h 2009-03-12 16:18:04.000000000 +0100
5458 + * Copyright (C) 2005-2009 Junjiro Okajima
5460 + * This program, aufs is free software; you can redistribute it and/or modify
5461 + * it under the terms of the GNU General Public License as published by
5462 + * the Free Software Foundation; either version 2 of the License, or
5463 + * (at your option) any later version.
5465 + * This program is distributed in the hope that it will be useful,
5466 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5467 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5468 + * GNU General Public License for more details.
5470 + * You should have received a copy of the GNU General Public License
5471 + * along with this program; if not, write to the Free Software
5472 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5476 + * lookup and dentry operations
5481 +#ifndef __AUFS_DENTRY_H__
5482 +#define __AUFS_DENTRY_H__
5486 +#include <linux/fs.h>
5487 +#include <linux/namei.h>
5488 +#include <linux/aufs_type.h>
5493 +/* nameidata open_intent */
5500 +struct au_hdintent {
5501 + struct list_head hdi_list;
5502 + struct file *hdi_file[AuIntent_Last];
5505 +struct au_hdentry {
5506 + struct dentry *hd_dentry;
5508 +#ifdef CONFIG_AUFS_BR_NFS
5509 + spinlock_t hd_lock; /* intest_list */
5510 + struct list_head *hd_intent_list;
5515 + atomic_t di_generation;
5517 + struct au_rwsem di_rwsem;
5518 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
5519 + struct au_hdentry *di_hdentry;
5522 +/* nameidata extension flags */
5523 +#define AuNdx_DLGT 1
5524 +#define AuNdx_DIRPERM1 (1 << 1)
5525 +#define au_ftest_ndx(flags, name) ((flags) & AuNdx_##name)
5526 +#define au_fset_ndx(flags, name) { (flags) |= AuNdx_##name; }
5527 +#define au_fclr_ndx(flags, name) { (flags) &= ~AuNdx_##name; }
5528 +#ifndef CONFIG_AUFS_DLGT
5530 +#define AuNdx_DLGT 0
5531 +#undef AuNdx_DIRPERM1
5532 +#define AuNdx_DIRPERM1 0
5536 + struct vfsmount *nfsmnt;
5537 + unsigned int flags;
5538 + struct nameidata *nd;
5539 + struct au_branch *br;
5540 + struct file *nd_file;
5543 +/* ---------------------------------------------------------------------- */
5545 +static inline void au_do_h_dentry_init(struct au_hdentry *hdentry)
5547 + hdentry->hd_dentry = NULL;
5550 +#ifdef CONFIG_AUFS_BR_NFS
5551 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
5553 + au_do_h_dentry_init(hdentry);
5554 + spin_lock_init(&hdentry->hd_lock);
5557 +static inline void au_h_dentry_init_all(struct au_hdentry *hdentry, int n)
5560 + spin_lock_init(&hdentry[n].hd_lock);
5564 +struct file *au_h_intent(struct dentry *dentry, aufs_bindex_t bindex,
5565 + struct file *file);
5566 +int au_br_nfs_h_intent(struct file *nd_file, struct dentry *dentry,
5567 + aufs_bindex_t bindex, struct nameidata *nd);
5568 +void au_hintent_put(struct au_hdentry *hd, int do_free);
5569 +int au_fake_intent(struct nameidata *nd, struct au_branch *br);
5570 +int au_hin_after_reval(struct nameidata *nd, struct dentry *dentry,
5571 + aufs_bindex_t bindex, struct file *file);
5572 +struct dentry *au_lkup_hash(const char *name, struct dentry *parent, int len,
5573 + struct au_ndx *ndx);
5576 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
5578 + au_do_h_dentry_init(hdentry);
5581 +static inline void au_h_dentry_init_all(struct au_hdentry *hdentry, int n)
5587 +struct file *au_h_intent(struct dentry *dentry, aufs_bindex_t bindex,
5588 + struct file *file)
5590 + /* return ERR_PTR(-ENOSYS); */
5595 +int au_br_nfs_h_intent(struct file *nd_file, struct dentry *dentry,
5596 + aufs_bindex_t bindex, struct nameidata *nd)
5601 +static inline void au_hintent_put(struct au_hdentry *hd, int do_free)
5606 +static inline int au_fake_intent(struct nameidata *nd, struct au_branch *br)
5612 +int au_hin_after_reval(struct nameidata *nd, struct dentry *dentry,
5613 + aufs_bindex_t bindex, struct file *file)
5618 +#ifdef CONFIG_AUFS_DLGT
5620 +struct dentry *au_lkup_hash(const char *name, struct dentry *parent, int len,
5621 + struct au_ndx *ndx)
5623 + /* return ERR_PTR(-ENOSYS); */
5624 + return vfsub_lookup_one_len(name, parent, len);
5627 +#endif /* CONFIG_AUFS_BR_NFS */
5629 +#ifdef CONFIG_AUFS_DLGT
5631 +struct dentry *au_lkup_one_dlgt(const char *name, struct dentry *parent,
5632 + int len, unsigned int flags);
5633 +#elif defined(CONFIG_AUFS_BR_NFS)
5634 +/* regardelss kernel version */
5636 +struct dentry *au_lkup_one_dlgt(const char *name, struct dentry *parent,
5637 + int len, unsigned int flags)
5639 + return vfsub_lookup_one_len(name, parent, len);
5644 +extern struct dentry_operations aufs_dop;
5645 +#if defined(CONFIG_AUFS_BR_NFS) || defined(CONFIG_AUFS_DLGT)
5646 +struct dentry *au_lkup_one(const char *name, struct dentry *parent, int len,
5647 + struct au_ndx *ndx);
5650 +struct dentry *au_lkup_one(const char *name, struct dentry *parent, int len,
5651 + struct au_ndx *ndx)
5653 + /* todo? ndx->nd_file = NULL; */
5654 + return vfsub_lookup_one_len(name, parent, len);
5657 +struct dentry *au_sio_lkup_one(const char *name, struct dentry *parent, int len,
5658 + struct au_ndx *ndx);
5659 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
5660 + struct nameidata *nd);
5661 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex);
5662 +int au_refresh_hdentry(struct dentry *dentry, mode_t type);
5663 +int au_reval_dpath(struct dentry *dentry, au_gen_t sgen);
5666 +int au_alloc_dinfo(struct dentry *dentry);
5667 +struct au_dinfo *au_di(struct dentry *dentry);
5669 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
5670 +void di_read_unlock(struct dentry *d, int flags);
5671 +void di_downgrade_lock(struct dentry *d, int flags);
5672 +void di_write_lock(struct dentry *d, unsigned int lsc);
5673 +void di_write_unlock(struct dentry *d);
5674 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
5675 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
5676 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
5678 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
5680 +aufs_bindex_t au_dbtail(struct dentry *dentry);
5681 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
5682 +#if 0 /* reserved for future use */
5683 +aufs_bindex_t au_dbtail_generic(struct dentry *dentry);
5686 +void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex);
5687 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
5688 + struct dentry *h_dentry);
5690 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
5691 +void au_update_dbstart(struct dentry *dentry);
5692 +void au_update_dbend(struct dentry *dentry);
5693 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
5695 +/* ---------------------------------------------------------------------- */
5697 +/* todo: memory barrier? */
5698 +static inline au_gen_t au_digen(struct dentry *d)
5700 + return atomic_read(&au_di(d)->di_generation);
5703 +#ifdef CONFIG_AUFS_HINOTIFY
5704 +static inline au_gen_t au_digen_dec(struct dentry *d)
5706 + return atomic_dec_return(&au_di(d)->di_generation);
5709 +static inline void au_hin_di_reinit(struct dentry *d)
5711 + d->d_fsdata = NULL;
5714 +static inline void au_hin_di_reinit(struct dentry *d)
5718 +#endif /* CONFIG_AUFS_HINOTIFY */
5720 +/* ---------------------------------------------------------------------- */
5722 +/* lock subclass for dinfo */
5724 + AuLsc_DI_CHILD, /* child first */
5725 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hinotify */
5726 + AuLsc_DI_CHILD3, /* copyup dirs */
5734 + * di_read_lock_child, di_write_lock_child,
5735 + * di_read_lock_child2, di_write_lock_child2,
5736 + * di_read_lock_child3, di_write_lock_child3,
5737 + * di_read_lock_parent, di_write_lock_parent,
5738 + * di_read_lock_parent2, di_write_lock_parent2,
5739 + * di_read_lock_parent3, di_write_lock_parent3,
5740 + * di_read_lock_parent4, di_write_lock_parent4,
5742 +#define AuReadLockFunc(name, lsc) \
5743 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
5744 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
5746 +#define AuWriteLockFunc(name, lsc) \
5747 +static inline void di_write_lock_##name(struct dentry *d) \
5748 +{ di_write_lock(d, AuLsc_DI_##lsc); }
5750 +#define AuRWLockFuncs(name, lsc) \
5751 + AuReadLockFunc(name, lsc) \
5752 + AuWriteLockFunc(name, lsc)
5754 +AuRWLockFuncs(child, CHILD);
5755 +AuRWLockFuncs(child2, CHILD2);
5756 +AuRWLockFuncs(child3, CHILD3);
5757 +AuRWLockFuncs(parent, PARENT);
5758 +AuRWLockFuncs(parent2, PARENT2);
5759 +AuRWLockFuncs(parent3, PARENT3);
5760 +AuRWLockFuncs(parent4, PARENT4);
5762 +#undef AuReadLockFunc
5763 +#undef AuWriteLockFunc
5764 +#undef AuRWLockFuncs
5766 +/* to debug easier, do not make them inlined functions */
5767 +#define DiMustReadLock(d) do { \
5768 + SiMustAnyLock((d)->d_sb); \
5769 + AuRwMustReadLock(&au_di(d)->di_rwsem); \
5772 +#define DiMustWriteLock(d) do { \
5773 + SiMustAnyLock((d)->d_sb); \
5774 + AuRwMustWriteLock(&au_di(d)->di_rwsem); \
5777 +#define DiMustAnyLock(d) do { \
5778 + SiMustAnyLock((d)->d_sb); \
5779 + AuRwMustAnyLock(&au_di(d)->di_rwsem); \
5782 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
5784 +/* ---------------------------------------------------------------------- */
5786 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
5788 + DiMustAnyLock(dentry);
5789 + return au_di(dentry)->di_bstart;
5792 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
5794 + DiMustAnyLock(dentry);
5795 + return au_di(dentry)->di_bend;
5798 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
5800 + DiMustAnyLock(dentry);
5801 + return au_di(dentry)->di_bwh;
5804 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
5806 + DiMustAnyLock(dentry);
5807 + AuDebugOn(dentry->d_inode
5808 + && dentry->d_inode->i_mode
5809 + && !S_ISDIR(dentry->d_inode->i_mode));
5810 + return au_di(dentry)->di_bdiropq;
5813 +/* todo: hard/soft set? */
5814 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
5816 + DiMustWriteLock(dentry);
5817 + AuDebugOn(au_sbend(dentry->d_sb) < bindex);
5819 + au_di(dentry)->di_bstart = bindex;
5822 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
5824 + DiMustWriteLock(dentry);
5825 + AuDebugOn(au_sbend(dentry->d_sb) < bindex
5826 + || bindex < au_dbstart(dentry));
5827 + au_di(dentry)->di_bend = bindex;
5830 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
5832 + DiMustWriteLock(dentry);
5833 + AuDebugOn(au_sbend(dentry->d_sb) < bindex);
5834 + /* dbwh can be outside of bstart - bend range */
5835 + au_di(dentry)->di_bwh = bindex;
5838 +static inline void au_hdput(struct au_hdentry *hd, int do_free)
5840 + au_hintent_put(hd, do_free);
5841 + dput(hd->hd_dentry);
5844 +static inline void au_update_digen(struct dentry *dentry)
5846 + AuDebugOn(!dentry->d_sb);
5847 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
5848 + /* smp_mb(); */ /* atomic_set */
5851 +#endif /* __KERNEL__ */
5852 +#endif /* __AUFS_DENTRY_H__ */
5853 diff -urN linux/fs/aufs/dinfo.c linux-aufs/fs/aufs/dinfo.c
5854 --- linux/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
5855 +++ linux-aufs/fs/aufs/dinfo.c 2009-03-12 16:18:04.000000000 +0100
5858 + * Copyright (C) 2005-2009 Junjiro Okajima
5860 + * This program, aufs is free software; you can redistribute it and/or modify
5861 + * it under the terms of the GNU General Public License as published by
5862 + * the Free Software Foundation; either version 2 of the License, or
5863 + * (at your option) any later version.
5865 + * This program is distributed in the hope that it will be useful,
5866 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5867 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5868 + * GNU General Public License for more details.
5870 + * You should have received a copy of the GNU General Public License
5871 + * along with this program; if not, write to the Free Software
5872 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5876 + * dentry private data
5883 +int au_alloc_dinfo(struct dentry *dentry)
5885 + struct au_dinfo *dinfo;
5886 + struct super_block *sb;
5889 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
5890 + AuDebugOn(dentry->d_fsdata);
5892 + dinfo = au_cache_alloc_dinfo();
5894 + sb = dentry->d_sb;
5895 + nbr = au_sbend(sb) + 1;
5898 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry),
5900 + if (dinfo->di_hdentry) {
5901 + au_h_dentry_init_all(dinfo->di_hdentry, nbr);
5902 + atomic_set(&dinfo->di_generation, au_sigen(sb));
5903 + /* smp_mb(); */ /* atomic_set */
5904 + au_rw_init_wlock_nested(&dinfo->di_rwsem,
5906 + au_dbg_locked_di_reg(dentry, AuLock_DW, AuLsc_DI_CHILD);
5907 + dinfo->di_bstart = -1;
5908 + dinfo->di_bend = -1;
5909 + dinfo->di_bwh = -1;
5910 + dinfo->di_bdiropq = -1;
5912 + dentry->d_fsdata = dinfo;
5913 + dentry->d_op = &aufs_dop;
5914 + return 0; /* success */
5916 + au_cache_free_dinfo(dinfo);
5918 + AuTraceErr(-ENOMEM);
5922 +struct au_dinfo *au_di(struct dentry *dentry)
5924 + struct au_dinfo *dinfo = dentry->d_fsdata;
5926 + || !dinfo->di_hdentry
5927 + /* || au_sbi(dentry->d_sb)->si_bend < dinfo->di_bend */
5928 + || dinfo->di_bend < dinfo->di_bstart
5929 + /* dbwh can be outside of this range */
5930 + || (0 <= dinfo->di_bdiropq
5931 + && (dinfo->di_bdiropq < dinfo->di_bstart
5932 + /* || dinfo->di_bend < dinfo->di_bdiropq */))
5937 +/* ---------------------------------------------------------------------- */
5939 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
5942 + case AuLsc_DI_CHILD:
5943 + ii_write_lock_child(inode);
5945 + case AuLsc_DI_CHILD2:
5946 + ii_write_lock_child2(inode);
5948 + case AuLsc_DI_CHILD3:
5949 + ii_write_lock_child3(inode);
5951 + case AuLsc_DI_PARENT:
5952 + ii_write_lock_parent(inode);
5954 + case AuLsc_DI_PARENT2:
5955 + ii_write_lock_parent2(inode);
5957 + case AuLsc_DI_PARENT3:
5958 + ii_write_lock_parent3(inode);
5960 + case AuLsc_DI_PARENT4:
5961 + ii_write_lock_parent4(inode);
5968 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
5971 + case AuLsc_DI_CHILD:
5972 + ii_read_lock_child(inode);
5974 + case AuLsc_DI_CHILD2:
5975 + ii_read_lock_child2(inode);
5977 + case AuLsc_DI_CHILD3:
5978 + ii_read_lock_child3(inode);
5980 + case AuLsc_DI_PARENT:
5981 + ii_read_lock_parent(inode);
5983 + case AuLsc_DI_PARENT2:
5984 + ii_read_lock_parent2(inode);
5986 + case AuLsc_DI_PARENT3:
5987 + ii_read_lock_parent3(inode);
5989 + case AuLsc_DI_PARENT4:
5990 + ii_read_lock_parent4(inode);
5997 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
5999 + LKTRTrace("%.*s, %u\n", AuDLNPair(d), lsc);
6000 + SiMustAnyLock(d->d_sb);
6002 + /* todo: always nested? */
6003 + au_dbg_locking_di_reg(d, flags, lsc);
6004 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
6005 + au_dbg_locking_di_unreg(d, flags);
6006 + au_dbg_locked_di_reg(d, flags, lsc);
6008 + if (au_ftest_lock(flags, IW))
6009 + do_ii_write_lock(d->d_inode, lsc);
6010 + else if (au_ftest_lock(flags, IR))
6011 + do_ii_read_lock(d->d_inode, lsc);
6015 +void di_read_unlock(struct dentry *d, int flags)
6017 + LKTRTrace("%.*s\n", AuDLNPair(d));
6018 + SiMustAnyLock(d->d_sb);
6021 + if (au_ftest_lock(flags, IW))
6022 + ii_write_unlock(d->d_inode);
6023 + else if (au_ftest_lock(flags, IR))
6024 + ii_read_unlock(d->d_inode);
6026 + au_rw_read_unlock(&au_di(d)->di_rwsem);
6027 + au_dbg_locked_di_unreg(d, flags);
6030 +void di_downgrade_lock(struct dentry *d, int flags)
6032 + SiMustAnyLock(d->d_sb);
6034 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
6035 + if (d->d_inode && au_ftest_lock(flags, IR))
6036 + ii_downgrade_lock(d->d_inode);
6039 +void di_write_lock(struct dentry *d, unsigned int lsc)
6041 + LKTRTrace("%.*s, %u\n", AuDLNPair(d), lsc);
6042 + SiMustAnyLock(d->d_sb);
6044 + /* todo: always nested? */
6045 + au_dbg_locking_di_reg(d, AuLock_IW, lsc);
6046 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
6047 + au_dbg_locking_di_unreg(d, AuLock_IW);
6048 + au_dbg_locked_di_reg(d, AuLock_IW, lsc);
6050 + do_ii_write_lock(d->d_inode, lsc);
6053 +void di_write_unlock(struct dentry *d)
6055 + LKTRTrace("%.*s\n", AuDLNPair(d));
6056 + SiMustAnyLock(d->d_sb);
6059 + ii_write_unlock(d->d_inode);
6060 + au_rw_write_unlock(&au_di(d)->di_rwsem);
6061 + au_dbg_locked_di_unreg(d, AuLock_IW);
6064 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
6067 + AuDebugOn(d1 == d2
6068 + || d1->d_inode == d2->d_inode
6069 + || d1->d_sb != d2->d_sb);
6071 + if (isdir && au_test_subdir(d1, d2)) {
6072 + di_write_lock_child(d1);
6073 + di_write_lock_child2(d2);
6075 + /* there should be no races */
6076 + di_write_lock_child(d2);
6077 + di_write_lock_child2(d1);
6081 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
6084 + AuDebugOn(d1 == d2
6085 + || d1->d_inode == d2->d_inode
6086 + || d1->d_sb != d2->d_sb);
6088 + if (isdir && au_test_subdir(d1, d2)) {
6089 + di_write_lock_parent(d1);
6090 + di_write_lock_parent2(d2);
6092 + /* there should be no races */
6093 + di_write_lock_parent(d2);
6094 + di_write_lock_parent2(d1);
6098 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
6100 + di_write_unlock(d1);
6101 + if (d1->d_inode == d2->d_inode) {
6102 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
6103 + au_dbg_locked_di_unreg(d2, AuLock_IW);
6105 + di_write_unlock(d2);
6108 +/* ---------------------------------------------------------------------- */
6110 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
6114 + DiMustAnyLock(dentry);
6115 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
6117 + AuDebugOn(bindex < 0
6118 + /* || bindex > au_sbend(dentry->d_sb) */);
6119 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
6120 + AuDebugOn(d && (atomic_read(&d->d_count) <= 0));
6124 +aufs_bindex_t au_dbtail(struct dentry *dentry)
6126 + aufs_bindex_t bend, bwh;
6128 + bend = au_dbend(dentry);
6130 + bwh = au_dbwh(dentry);
6133 + if (0 < bwh && bwh < bend)
6139 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
6141 + aufs_bindex_t bend, bopq;
6143 + AuDebugOn(dentry->d_inode
6144 + && dentry->d_inode->i_mode
6145 + && !S_ISDIR(dentry->d_inode->i_mode));
6147 + bend = au_dbtail(dentry);
6149 + bopq = au_dbdiropq(dentry);
6150 + AuDebugOn(bend < bopq);
6151 + if (0 <= bopq && bopq < bend)
6157 +#if 0 /* reserved for future use */
6158 +aufs_bindex_t au_dbtail_generic(struct dentry *dentry)
6160 + struct inode *inode;
6162 + inode = dentry->d_inode;
6163 + if (inode && S_ISDIR(inode->i_mode))
6164 + return au_dbtaildir(dentry);
6166 + return au_dbtail(dentry);
6170 +/* ---------------------------------------------------------------------- */
6172 +void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
6174 + DiMustWriteLock(dentry);
6175 + AuDebugOn(au_sbend(dentry->d_sb) < bindex);
6176 + AuDebugOn((bindex >= 0
6177 + && (bindex < au_dbstart(dentry)
6178 + || au_dbend(dentry) < bindex))
6179 + || (dentry->d_inode
6180 + && dentry->d_inode->i_mode
6181 + && !S_ISDIR(dentry->d_inode->i_mode)));
6182 + au_di(dentry)->di_bdiropq = bindex;
6185 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
6186 + struct dentry *h_dentry)
6188 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
6189 + DiMustWriteLock(dentry);
6190 + AuDebugOn(bindex < au_di(dentry)->di_bstart
6191 + || bindex > au_di(dentry)->di_bend
6192 + || (h_dentry && atomic_read(&h_dentry->d_count) <= 0)
6193 + || (h_dentry && hd->hd_dentry)
6195 + if (hd->hd_dentry)
6196 + au_hdput(hd, /*do_free*/0);
6197 + hd->hd_dentry = h_dentry;
6200 +/* ---------------------------------------------------------------------- */
6202 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
6204 + struct au_dinfo *dinfo;
6205 + aufs_bindex_t bindex;
6206 + struct dentry *h_d;
6208 + LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), do_put_zero);
6209 + DiMustWriteLock(dentry);
6211 + dinfo = au_di(dentry);
6212 + if (!dinfo || dinfo->di_bstart < 0)
6215 + if (do_put_zero) {
6216 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend;
6218 + h_d = dinfo->di_hdentry[0 + bindex].hd_dentry;
6219 + if (h_d && !h_d->d_inode)
6220 + au_set_h_dptr(dentry, bindex, NULL);
6224 + dinfo->di_bstart = -1;
6225 + while (++dinfo->di_bstart <= dinfo->di_bend)
6226 + if (dinfo->di_hdentry[0 + dinfo->di_bstart].hd_dentry)
6228 + if (dinfo->di_bstart > dinfo->di_bend) {
6229 + dinfo->di_bstart = -1;
6230 + dinfo->di_bend = -1;
6235 + while (0 <= --dinfo->di_bend)
6236 + if (dinfo->di_hdentry[0 + dinfo->di_bend].hd_dentry)
6238 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
6241 +void au_update_dbstart(struct dentry *dentry)
6243 + aufs_bindex_t bindex,
6244 + bstart = au_dbstart(dentry),
6245 + bend = au_dbend(dentry);
6246 + struct dentry *h_dentry;
6248 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
6249 + DiMustWriteLock(dentry);
6251 + for (bindex = bstart; bindex <= bend; bindex++) {
6252 + h_dentry = au_h_dptr(dentry, bindex);
6255 + if (h_dentry->d_inode) {
6256 + au_set_dbstart(dentry, bindex);
6259 + au_set_h_dptr(dentry, bindex, NULL);
6263 +void au_update_dbend(struct dentry *dentry)
6265 + aufs_bindex_t bindex,
6266 + bstart = au_dbstart(dentry),
6267 + bend = au_dbend(dentry);
6268 + struct dentry *h_dentry;
6270 + DiMustWriteLock(dentry);
6271 + for (bindex = bend; bindex <= bstart; bindex--) {
6272 + h_dentry = au_h_dptr(dentry, bindex);
6275 + if (h_dentry->d_inode) {
6276 + au_set_dbend(dentry, bindex);
6279 + au_set_h_dptr(dentry, bindex, NULL);
6283 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
6285 + aufs_bindex_t bindex, bend;
6287 + bend = au_dbend(dentry);
6288 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
6289 + if (au_h_dptr(dentry, bindex) == h_dentry)
6293 diff -urN linux/fs/aufs/dir.c linux-aufs/fs/aufs/dir.c
6294 --- linux/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
6295 +++ linux-aufs/fs/aufs/dir.c 2009-03-12 16:18:04.000000000 +0100
6298 + * Copyright (C) 2005-2009 Junjiro Okajima
6300 + * This program, aufs is free software; you can redistribute it and/or modify
6301 + * it under the terms of the GNU General Public License as published by
6302 + * the Free Software Foundation; either version 2 of the License, or
6303 + * (at your option) any later version.
6305 + * This program is distributed in the hope that it will be useful,
6306 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6307 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6308 + * GNU General Public License for more details.
6310 + * You should have received a copy of the GNU General Public License
6311 + * along with this program; if not, write to the Free Software
6312 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6316 + * directory operations
6321 +#include <linux/fs_stack.h>
6324 +static int reopen_dir(struct file *file)
6327 + struct dentry *dentry, *h_dentry;
6328 + aufs_bindex_t bindex, btail, bstart;
6329 + struct file *h_file;
6331 + dentry = file->f_dentry;
6332 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
6333 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
6335 + /* open all hidden dirs */
6336 + bstart = au_dbstart(dentry);
6337 +#if 1 /* todo: necessary? */
6338 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
6339 + au_set_h_fptr(file, bindex, NULL);
6341 + au_set_fbstart(file, bstart);
6342 + btail = au_dbtaildir(dentry);
6343 +#if 1 /* todo: necessary? */
6344 + for (bindex = au_fbend(file); btail < bindex; bindex--)
6345 + au_set_h_fptr(file, bindex, NULL);
6347 + au_set_fbend(file, btail);
6348 + for (bindex = bstart; bindex <= btail; bindex++) {
6349 + h_dentry = au_h_dptr(dentry, bindex);
6352 + h_file = au_h_fptr(file, bindex);
6354 + AuDebugOn(h_file->f_dentry != h_dentry);
6358 + h_file = au_h_open(dentry, bindex, file->f_flags, file);
6359 + err = PTR_ERR(h_file);
6360 + if (IS_ERR(h_file))
6361 + goto out; /* close all? */
6362 + /* cpup_file_flags(h_file, file); */
6363 + au_set_h_fptr(file, bindex, h_file);
6365 + au_update_figen(file);
6366 + /* todo: necessary? */
6367 + /* file->f_ra = h_file->f_ra; */
6375 +static int do_open_dir(struct file *file, int flags)
6378 + aufs_bindex_t bindex, btail;
6379 + struct dentry *dentry, *h_dentry;
6380 + struct file *h_file;
6382 + dentry = file->f_dentry;
6383 + LKTRTrace("%.*s, 0x%x\n", AuDLNPair(dentry), flags);
6384 + AuDebugOn(!dentry->d_inode || !S_ISDIR(dentry->d_inode->i_mode));
6387 + au_set_fvdir_cache(file, NULL);
6388 + file->f_version = dentry->d_inode->i_version;
6389 + bindex = au_dbstart(dentry);
6390 + au_set_fbstart(file, bindex);
6391 + btail = au_dbtaildir(dentry);
6392 + au_set_fbend(file, btail);
6393 + for (; !err && bindex <= btail; bindex++) {
6394 + h_dentry = au_h_dptr(dentry, bindex);
6398 + h_file = au_h_open(dentry, bindex, flags, file);
6399 + if (IS_ERR(h_file)) {
6400 + err = PTR_ERR(h_file);
6403 + au_set_h_fptr(file, bindex, h_file);
6405 + au_update_figen(file);
6406 + /* todo: necessary? */
6407 + /* file->f_ra = h_file->f_ra; */
6409 + return 0; /* success */
6412 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
6413 + au_set_h_fptr(file, bindex, NULL);
6414 + au_set_fbstart(file, -1);
6415 + au_set_fbend(file, -1);
6419 +static int aufs_open_dir(struct inode *inode, struct file *file)
6421 + LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(file->f_dentry));
6423 + return au_do_open(inode, file, do_open_dir);
6426 +static int aufs_release_dir(struct inode *inode, struct file *file)
6428 + struct au_vdir *vdir_cache;
6429 + struct super_block *sb;
6431 + LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(file->f_dentry));
6433 + sb = file->f_dentry->d_sb;
6434 + si_noflush_read_lock(sb);
6435 + fi_write_lock(file);
6436 + vdir_cache = au_fvdir_cache(file);
6438 + au_vdir_free(vdir_cache);
6439 + fi_write_unlock(file);
6440 + au_finfo_fin(file);
6441 + si_read_unlock(sb);
6445 +static int fsync_dir(struct dentry *dentry, int datasync)
6448 + struct inode *inode;
6449 + struct super_block *sb;
6450 + aufs_bindex_t bend, bindex;
6452 + LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), datasync);
6453 + DiMustAnyLock(dentry);
6454 + sb = dentry->d_sb;
6455 + SiMustAnyLock(sb);
6456 + inode = dentry->d_inode;
6458 + IiMustAnyLock(inode);
6461 + bend = au_dbend(dentry);
6462 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
6463 + struct dentry *h_dentry;
6464 + struct inode *h_inode;
6465 + struct file_operations *fop;
6467 + if (au_test_ro(sb, bindex, inode))
6469 + h_dentry = au_h_dptr(dentry, bindex);
6472 + h_inode = h_dentry->d_inode;
6476 + /* no mnt_want_write() */
6477 + /* cf. fs/nsfd/vfs.c and fs/nfsd/nfs4recover.c */
6478 + /* todo: inotiry fired? */
6479 + mutex_lock(&h_inode->i_mutex);
6480 + fop = (void *)h_inode->i_fop;
6481 + err = filemap_fdatawrite(h_inode->i_mapping);
6482 + if (!err && fop && fop->fsync)
6483 + err = fop->fsync(NULL, h_dentry, datasync);
6485 + err = filemap_fdatawrite(h_inode->i_mapping);
6487 + au_update_fuse_h_inode(NULL, h_dentry); /*ignore*/
6488 + mutex_unlock(&h_inode->i_mutex);
6496 + * @file may be NULL
6498 +static int aufs_fsync_dir(struct file *file, struct dentry *dentry,
6502 + struct inode *inode;
6503 + struct file *h_file;
6504 + struct super_block *sb;
6505 + aufs_bindex_t bend, bindex;
6507 + LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), datasync);
6508 + inode = dentry->d_inode;
6512 + sb = dentry->d_sb;
6513 + si_noflush_read_lock(sb);
6515 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1,
6517 + if (unlikely(err))
6520 + di_write_lock_child(dentry);
6523 + bend = au_fbend(file);
6524 + for (bindex = au_fbstart(file); !err && bindex <= bend;
6526 + h_file = au_h_fptr(file, bindex);
6527 + if (!h_file || au_test_ro(sb, bindex, inode))
6531 + if (h_file->f_op && h_file->f_op->fsync) {
6532 + /* todo: try do_fsync() in fs/sync.c? */
6533 + mutex_lock(&h_file->f_mapping->host->i_mutex);
6534 + err = h_file->f_op->fsync
6535 + (h_file, h_file->f_dentry, datasync);
6537 + au_update_fuse_h_inode
6538 + (h_file->f_vfsmnt,
6539 + h_file->f_dentry);
6541 + mutex_unlock(&h_file->f_mapping->host->i_mutex);
6545 + err = fsync_dir(dentry, datasync);
6546 + au_cpup_attr_timesizes(inode);
6547 + di_write_unlock(dentry);
6549 + fi_write_unlock(file);
6552 + si_read_unlock(sb);
6557 +/* ---------------------------------------------------------------------- */
6559 +static int aufs_readdir(struct file *file, void *dirent, filldir_t filldir)
6562 + struct dentry *dentry;
6563 + struct inode *inode;
6564 + struct super_block *sb;
6566 + dentry = file->f_dentry;
6567 + LKTRTrace("%.*s, pos %lld\n", AuDLNPair(dentry), file->f_pos);
6568 + inode = dentry->d_inode;
6571 + sb = dentry->d_sb;
6572 + si_read_lock(sb, AuLock_FLUSH);
6573 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*locked*/1);
6574 + if (unlikely(err))
6576 + err = au_vdir_init(file);
6577 + di_downgrade_lock(dentry, AuLock_IR);
6578 + if (unlikely(err))
6581 + if (!au_test_nfsd(current)) {
6582 + err = au_vdir_fill_de(file, dirent, filldir);
6585 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
6586 + * encode_fh() and others.
6588 + struct inode *h_inode = au_h_iptr(inode, au_ibstart(inode));
6590 + di_read_unlock(dentry, AuLock_IR);
6591 + si_read_unlock(sb);
6593 + err = au_vdir_fill_de(file, dirent, filldir);
6595 + fsstack_copy_attr_atime(inode, h_inode);
6596 + fi_write_unlock(file);
6602 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
6605 + di_read_unlock(dentry, AuLock_IR);
6606 + fi_write_unlock(file);
6608 + si_read_unlock(sb);
6613 +/* ---------------------------------------------------------------------- */
6615 +#define AuTestEmpty_WHONLY 1
6616 +#define AuTestEmpty_DLGT (1 << 1)
6617 +#define AuTestEmpty_DIRPERM1 (1 << 2)
6618 +#define AuTestEmpty_CALLED (1 << 3)
6619 +#define AuTestEmpty_SHWH (1 << 4)
6620 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
6621 +#define au_fset_testempty(flags, name) { (flags) |= AuTestEmpty_##name; }
6622 +#define au_fclr_testempty(flags, name) { (flags) &= ~AuTestEmpty_##name; }
6623 +#ifndef CONFIG_AUFS_DLGT
6624 +#undef AuTestEmpty_DLGT
6625 +#define AuTestEmpty_DLGT 0
6626 +#undef AuTestEmpty_DIRPERM1
6627 +#define AuTestEmpty_DIRPERM1 0
6629 +#ifndef CONFIG_AUFS_SHWH
6630 +#undef AuTestEmpty_SHWH
6631 +#define AuTestEmpty_SHWH 0
6634 +struct test_empty_arg {
6635 + struct au_nhash *whlist;
6636 + unsigned int flags;
6638 + aufs_bindex_t bindex;
6641 +static int test_empty_cb(void *__arg, const char *__name, int namelen,
6642 + loff_t offset, u64 ino, unsigned int d_type)
6644 + struct test_empty_arg *arg = __arg;
6645 + char *name = (void *)__name;
6647 + LKTRTrace("%.*s\n", namelen, name);
6650 + au_fset_testempty(arg->flags, CALLED);
6652 + if (name[0] == '.'
6653 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
6654 + return 0; /* success */
6656 + if (namelen <= AUFS_WH_PFX_LEN
6657 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
6658 + if (au_ftest_testempty(arg->flags, WHONLY)
6659 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
6660 + arg->err = -ENOTEMPTY;
6664 + name += AUFS_WH_PFX_LEN;
6665 + namelen -= AUFS_WH_PFX_LEN;
6666 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
6667 + arg->err = au_nhash_append_wh
6668 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
6669 + au_ftest_testempty(arg->flags, SHWH));
6673 + AuTraceErr(arg->err);
6677 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
6680 + struct file *h_file;
6682 + LKTRTrace("%.*s, {%p, 0x%x, %d}\n",
6683 + AuDLNPair(dentry), arg->whlist, arg->flags, arg->bindex);
6685 + h_file = au_h_open(dentry, arg->bindex,
6686 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
6688 + err = PTR_ERR(h_file);
6689 + if (IS_ERR(h_file))
6692 + if (au_opt_test(au_mntflags(dentry->d_sb), UDBA_INOTIFY)
6693 + && !h_file->f_dentry->d_inode->i_nlink)
6696 + dlgt = au_ftest_testempty(arg->flags, DLGT);
6699 + au_fclr_testempty(arg->flags, CALLED);
6701 + err = vfsub_readdir(h_file, test_empty_cb, arg, dlgt);
6704 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
6708 + au_sbr_put(dentry->d_sb, arg->bindex);
6714 +struct do_test_empty_args {
6716 + struct dentry *dentry;
6717 + struct test_empty_arg *arg;
6720 +static void call_do_test_empty(void *args)
6722 + struct do_test_empty_args *a = args;
6723 + *a->errp = do_test_empty(a->dentry, a->arg);
6726 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
6729 + struct dentry *h_dentry;
6730 + struct inode *h_inode;
6732 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
6733 + h_dentry = au_h_dptr(dentry, arg->bindex);
6734 + AuDebugOn(!h_dentry);
6735 + h_inode = h_dentry->d_inode;
6736 + AuDebugOn(!h_inode);
6738 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
6739 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ,
6740 + au_test_dlgt(au_mntflags(dentry->d_sb)));
6741 + mutex_unlock(&h_inode->i_mutex);
6743 + err = do_test_empty(dentry, arg);
6745 + struct do_test_empty_args args = {
6750 + unsigned int flags = arg->flags;
6752 + au_fclr_testempty(arg->flags, DLGT);
6753 + au_fclr_testempty(arg->flags, DIRPERM1);
6754 + wkq_err = au_wkq_wait(call_do_test_empty, &args, /*dlgt*/0);
6755 + if (unlikely(wkq_err))
6757 + arg->flags = flags;
6764 +int au_test_empty_lower(struct dentry *dentry)
6767 + struct inode *inode;
6768 + struct test_empty_arg arg;
6769 + struct au_nhash *whlist;
6770 + aufs_bindex_t bindex, bstart, btail;
6771 + unsigned int mnt_flags;
6773 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
6774 + inode = dentry->d_inode;
6775 + AuDebugOn(!inode || !S_ISDIR(inode->i_mode));
6777 + whlist = au_nhash_new(GFP_NOFS);
6778 + err = PTR_ERR(whlist);
6779 + if (IS_ERR(whlist))
6782 + bstart = au_dbstart(dentry);
6783 + mnt_flags = au_mntflags(dentry->d_sb);
6784 + arg.whlist = whlist;
6786 + if (au_test_dlgt(mnt_flags))
6787 + au_fset_testempty(arg.flags, DLGT);
6788 + if (au_opt_test(mnt_flags, SHWH))
6789 + au_fset_testempty(arg.flags, SHWH);
6790 + arg.bindex = bstart;
6791 + err = do_test_empty(dentry, &arg);
6792 + if (unlikely(err))
6795 + au_fset_testempty(arg.flags, WHONLY);
6796 + if (au_test_dirperm1(mnt_flags))
6797 + au_fset_testempty(arg.flags, DIRPERM1);
6798 + btail = au_dbtaildir(dentry);
6799 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
6800 + struct dentry *h_dentry;
6801 + h_dentry = au_h_dptr(dentry, bindex);
6802 + if (h_dentry && h_dentry->d_inode) {
6803 + arg.bindex = bindex;
6804 + err = do_test_empty(dentry, &arg);
6809 + au_nhash_del(whlist);
6815 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
6818 + struct inode *inode;
6819 + struct test_empty_arg arg;
6820 + aufs_bindex_t bindex, btail;
6822 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
6823 + inode = dentry->d_inode;
6824 + AuDebugOn(!inode || !S_ISDIR(inode->i_mode));
6827 + arg.whlist = whlist;
6828 + arg.flags = AuTestEmpty_WHONLY;
6829 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
6830 + au_fset_testempty(arg.flags, SHWH);
6831 + btail = au_dbtaildir(dentry);
6832 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
6833 + struct dentry *h_dentry;
6834 + h_dentry = au_h_dptr(dentry, bindex);
6835 + if (h_dentry && h_dentry->d_inode) {
6836 + arg.bindex = bindex;
6837 + err = sio_test_empty(dentry, &arg);
6845 +/* ---------------------------------------------------------------------- */
6847 +struct file_operations aufs_dir_fop = {
6848 + .read = generic_read_dir,
6849 + .readdir = aufs_readdir,
6850 + /* .unlocked_ioctl = aufs_ioctl_dir, */
6851 + .open = aufs_open_dir,
6852 + .release = aufs_release_dir,
6853 + .flush = aufs_flush,
6854 + .fsync = aufs_fsync_dir,
6856 diff -urN linux/fs/aufs/dir.h linux-aufs/fs/aufs/dir.h
6857 --- linux/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
6858 +++ linux-aufs/fs/aufs/dir.h 2009-03-12 16:18:04.000000000 +0100
6861 + * Copyright (C) 2005-2009 Junjiro Okajima
6863 + * This program, aufs is free software; you can redistribute it and/or modify
6864 + * it under the terms of the GNU General Public License as published by
6865 + * the Free Software Foundation; either version 2 of the License, or
6866 + * (at your option) any later version.
6868 + * This program is distributed in the hope that it will be useful,
6869 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6870 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6871 + * GNU General Public License for more details.
6873 + * You should have received a copy of the GNU General Public License
6874 + * along with this program; if not, write to the Free Software
6875 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6879 + * directory operations
6884 +#ifndef __AUFS_DIR_H__
6885 +#define __AUFS_DIR_H__
6889 +#include <linux/fs.h>
6890 +#include <linux/aufs_type.h>
6892 +/* ---------------------------------------------------------------------- */
6894 +/* need to be faster and smaller */
6896 +/* todo: changeable? */
6897 +#define AuSize_DEBLK 512
6898 +#define AuSize_NHASH 32
6899 +#if AuSize_DEBLK < NAME_MAX || PAGE_SIZE < AuSize_DEBLK
6900 +#error invalid size AuSize_DEBLK
6903 +typedef char au_vdir_deblk_t[AuSize_DEBLK];
6906 + struct hlist_head heads[AuSize_NHASH];
6909 +struct au_vdir_destr {
6910 + unsigned char len;
6914 +struct au_vdir_dehstr {
6915 + struct hlist_node hash;
6916 + struct au_vdir_destr *str;
6919 +struct au_vdir_de {
6921 + unsigned char de_type;
6922 + /* caution: packed */
6923 + struct au_vdir_destr de_str;
6926 +struct au_vdir_wh {
6927 + struct hlist_node wh_hash;
6928 + aufs_bindex_t wh_bindex;
6929 +#ifdef CONFIG_AUFS_SHWH
6931 + unsigned char wh_type;
6932 + /* caution: packed */
6934 + struct au_vdir_destr wh_str;
6937 +union au_vdir_deblk_p {
6939 + au_vdir_deblk_t *deblk;
6940 + struct au_vdir_de *de;
6944 + au_vdir_deblk_t **vd_deblk;
6948 + union au_vdir_deblk_p p;
6951 + unsigned long vd_version;
6952 + unsigned long vd_jiffy;
6955 +/* ---------------------------------------------------------------------- */
6958 +extern struct file_operations aufs_dir_fop;
6959 +int au_test_empty_lower(struct dentry *dentry);
6960 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
6963 +struct au_nhash *au_nhash_new(gfp_t gfp);
6964 +void au_nhash_del(struct au_nhash *nhash);
6965 +void au_nhash_init(struct au_nhash *nhash);
6966 +void au_nhash_move(struct au_nhash *dst, struct au_nhash *src);
6967 +void au_nhash_fin(struct au_nhash *nhash);
6968 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
6970 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int namelen);
6971 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int namelen,
6972 + ino_t ino, unsigned int d_type, aufs_bindex_t bindex,
6973 + unsigned char shwh);
6974 +void au_vdir_free(struct au_vdir *vdir);
6975 +int au_vdir_init(struct file *file);
6976 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir);
6978 +/* ---------------------------------------------------------------------- */
6981 +void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino, unsigned char d_type)
6983 +#ifdef CONFIG_AUFS_SHWH
6985 + wh->wh_type = d_type;
6989 +static inline void au_add_nlink(struct inode *dir, struct inode *h_dir)
6991 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
6992 + dir->i_nlink += h_dir->i_nlink - 2;
6993 + if (h_dir->i_nlink < 2)
6994 + dir->i_nlink += 2;
6997 +static inline void au_sub_nlink(struct inode *dir, struct inode *h_dir)
6999 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
7000 + dir->i_nlink -= h_dir->i_nlink - 2;
7001 + if (h_dir->i_nlink < 2)
7002 + dir->i_nlink -= 2;
7005 +#endif /* __KERNEL__ */
7006 +#endif /* __AUFS_DIR_H__ */
7007 diff -urN linux/fs/aufs/dlgt.c linux-aufs/fs/aufs/dlgt.c
7008 --- linux/fs/aufs/dlgt.c 1970-01-01 01:00:00.000000000 +0100
7009 +++ linux-aufs/fs/aufs/dlgt.c 2009-03-12 16:18:04.000000000 +0100
7012 + * Copyright (C) 2005-2009 Junjiro Okajima
7014 + * This program, aufs is free software; you can redistribute it and/or modify
7015 + * it under the terms of the GNU General Public License as published by
7016 + * the Free Software Foundation; either version 2 of the License, or
7017 + * (at your option) any later version.
7019 + * This program is distributed in the hope that it will be useful,
7020 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7021 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7022 + * GNU General Public License for more details.
7024 + * You should have received a copy of the GNU General Public License
7025 + * along with this program; if not, write to the Free Software
7026 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7030 + * lookup functions in 'delegate' mode
7037 +/* ---------------------------------------------------------------------- */
7039 +struct au_lookup_one_len_args {
7040 + struct dentry **errp;
7042 + struct dentry *parent;
7046 +static void au_call_lookup_one_len(void *args)
7048 + struct au_lookup_one_len_args *a = args;
7049 + *a->errp = vfsub_lookup_one_len(a->name, a->parent, a->len);
7052 +struct dentry *au_lkup_one_dlgt(const char *name, struct dentry *parent,
7053 + int len, unsigned int flags)
7055 + struct dentry *dentry;
7058 + LKTRTrace("%.*s/%.*s, 0x%x\n", AuDLNPair(parent), len, name, flags);
7060 + dirperm1 = au_ftest_ndx(flags, DIRPERM1);
7061 + if (!dirperm1 && !au_ftest_ndx(flags, DLGT))
7062 + dentry = vfsub_lookup_one_len(name, parent, len);
7065 + struct au_lookup_one_len_args args = {
7071 + wkq_err = au_wkq_wait(au_call_lookup_one_len, &args,
7072 + /*dlgt*/!dirperm1);
7073 + if (unlikely(wkq_err))
7074 + dentry = ERR_PTR(wkq_err);
7077 + AuTraceErrPtr(dentry);
7081 +/* ---------------------------------------------------------------------- */
7083 +struct security_inode_permission_args {
7085 + struct inode *h_inode;
7087 + struct nameidata *fake_nd;
7090 +static void call_security_inode_permission(void *args)
7092 + struct security_inode_permission_args *a = args;
7093 + LKTRTrace("fsuid %d\n", current_fsuid());
7094 + *a->errp = vfsub_security_inode_permission(a->h_inode, a->mask,
7098 +int au_security_inode_permission(struct inode *h_inode, int mask,
7099 + struct nameidata *fake_nd, int dlgt)
7106 + err = vfsub_security_inode_permission(h_inode, mask, fake_nd);
7109 + struct security_inode_permission_args args = {
7111 + .h_inode = h_inode,
7113 + .fake_nd = fake_nd
7115 + wkq_err = au_wkq_wait(call_security_inode_permission, &args,
7117 + if (unlikely(wkq_err))
7124 diff -urN linux/fs/aufs/export.c linux-aufs/fs/aufs/export.c
7125 --- linux/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
7126 +++ linux-aufs/fs/aufs/export.c 2009-03-12 16:18:04.000000000 +0100
7129 + * Copyright (C) 2005-2009 Junjiro Okajima
7131 + * This program, aufs is free software; you can redistribute it and/or modify
7132 + * it under the terms of the GNU General Public License as published by
7133 + * the Free Software Foundation; either version 2 of the License, or
7134 + * (at your option) any later version.
7136 + * This program is distributed in the hope that it will be useful,
7137 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7138 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7139 + * GNU General Public License for more details.
7141 + * You should have received a copy of the GNU General Public License
7142 + * along with this program; if not, write to the Free Software
7143 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7152 +#include <linux/exportfs.h>
7153 +#include <linux/mnt_namespace.h>
7154 +#include <linux/random.h>
7155 +#include <linux/nsproxy.h>
7159 +#ifdef CONFIG_AUFS_INO_T_64
7167 +static ino_t decode_ino(__u32 *a)
7171 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
7173 +#ifdef CONFIG_AUFS_INO_T_64
7179 +static void encode_ino(__u32 *a, ino_t ino)
7185 +#ifdef CONFIG_AUFS_INO_T_64
7190 +/* NFS file handle */
7194 +#ifdef CONFIG_AUFS_INO_T_64
7195 + /* support 64bit inode number */
7209 + Fh_dir_ino = Fh_dir_ino1
7212 +static int au_test_anon(struct dentry *dentry)
7214 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
7217 +/* ---------------------------------------------------------------------- */
7218 +/* inode generation external table */
7220 +int au_xigen_inc(struct inode *inode)
7226 + struct super_block *sb;
7227 + struct au_sbinfo *sbinfo;
7229 + LKTRTrace("i%lu\n", (unsigned long)inode->i_ino);
7233 + if (unlikely(!au_opt_test_xino(au_mntflags(sb))))
7236 + pos = inode->i_ino;
7237 + pos *= sizeof(igen);
7238 + igen = inode->i_generation + 1;
7239 + sbinfo = au_sbi(sb);
7240 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
7241 + sizeof(igen), &pos);
7242 + if (sz == sizeof(igen))
7243 + goto out; /* success */
7246 + if (unlikely(sz >= 0)) {
7248 + AuIOErr("xigen error (%zd)\n", sz);
7256 +int au_xigen_new(struct inode *inode)
7261 + struct super_block *sb;
7262 + struct au_sbinfo *sbinfo;
7263 + struct file *file;
7265 + LKTRTrace("i%lu\n", inode->i_ino);
7268 + /* todo: dirty, at mount time */
7269 + if (inode->i_ino == AUFS_ROOT_INO)
7272 + if (unlikely(!au_opt_test_xino(au_mntflags(sb))))
7276 + pos = inode->i_ino;
7277 + if (unlikely(Au_LOFF_MAX / sizeof(inode->i_generation) - 1 < pos)) {
7278 + AuIOErr1("too large i%lld\n", pos);
7281 + pos *= sizeof(inode->i_generation);
7284 + sbinfo = au_sbi(sb);
7285 + file = sbinfo->si_xigen;
7288 + if (i_size_read(file->f_dentry->d_inode)
7289 + < pos + sizeof(inode->i_generation)) {
7290 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
7291 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
7292 + sizeof(inode->i_generation), &pos);
7294 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
7295 + sizeof(inode->i_generation), &pos);
7296 + if (sz == sizeof(inode->i_generation))
7297 + goto out; /* success */
7300 + if (unlikely(sz >= 0)) {
7302 + AuIOErr("xigen error (%zd)\n", sz);
7310 +int au_xigen_set(struct super_block *sb, struct file *base)
7313 + struct au_sbinfo *sbinfo;
7314 + struct file *file;
7316 + LKTRTrace("%.*s\n", AuDLNPair(base->f_dentry));
7317 + SiMustWriteLock(sb);
7319 + sbinfo = au_sbi(sb);
7320 + file = au_xino_create2(sb, base, sbinfo->si_xigen);
7321 + err = PTR_ERR(file);
7325 + if (sbinfo->si_xigen)
7326 + fput(sbinfo->si_xigen);
7327 + sbinfo->si_xigen = file;
7334 +void au_xigen_clr(struct super_block *sb)
7336 + struct au_sbinfo *sbinfo;
7338 + sbinfo = au_sbi(sb);
7339 + if (sbinfo->si_xigen) {
7340 + fput(sbinfo->si_xigen);
7341 + sbinfo->si_xigen = NULL;
7345 +/* ---------------------------------------------------------------------- */
7347 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
7350 + struct dentry *dentry, *d;
7351 + struct inode *inode;
7354 + LKTRTrace("i%lu, diri%lu\n",
7355 + (unsigned long)ino, (unsigned long)dir_ino);
7358 + inode = ilookup(sb, ino);
7362 + dentry = ERR_PTR(-ESTALE);
7363 + sigen = au_sigen(sb);
7364 + if (unlikely(is_bad_inode(inode)
7365 + || IS_DEADDIR(inode)
7366 + || sigen != au_iigen(inode)))
7370 + if (!dir_ino || S_ISDIR(inode->i_mode))
7371 + dentry = d_find_alias(inode);
7373 + spin_lock(&dcache_lock);
7374 + list_for_each_entry(d, &inode->i_dentry, d_alias)
7375 + if (!au_test_anon(d)
7376 + && d->d_parent->d_inode->i_ino == dir_ino) {
7377 + dentry = dget_locked(d);
7380 + spin_unlock(&dcache_lock);
7382 + if (unlikely(dentry && sigen != au_digen(dentry))) {
7384 + dentry = ERR_PTR(-ESTALE);
7390 + AuTraceErrPtr(dentry);
7394 +/* ---------------------------------------------------------------------- */
7398 + * when you mntput() for the return value of this function,
7399 + * you have to store it to your local var.
7400 + * ie. never mntput si_mntcache directly.
7402 +static struct vfsmount *au_do_mnt_get(struct super_block *sb)
7404 + struct mnt_namespace *ns;
7405 + struct vfsmount *pos, *mnt;
7409 + /* vfsmount_lock is not exported */
7410 + /* no get/put ?? */
7411 + AuDebugOn(!current->nsproxy);
7412 + ns = current->nsproxy->mnt_ns;
7415 + /* the order (reverse) will not be a problem */
7416 + list_for_each_entry(pos, &ns->list, mnt_list)
7417 + if (pos->mnt_sb == sb) {
7423 + return mntget(mnt);
7426 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
7427 +static struct vfsmount *au_mnt_get(struct super_block *sb)
7429 + struct au_sbinfo *sbinfo;
7430 + struct vfsmount *mnt;
7432 + sbinfo = au_sbi(sb);
7433 + spin_lock(&sbinfo->si_mntcache_lock);
7434 + if (sbinfo->si_mntcache)
7435 + mnt = mntget(sbinfo->si_mntcache);
7437 + sbinfo->si_mntcache = au_do_mnt_get(sb);
7438 + mnt = sbinfo->si_mntcache;
7440 + spin_unlock(&sbinfo->si_mntcache_lock);
7444 +static struct vfsmount *au_mnt_get(struct super_block *sb)
7446 + return au_do_mnt_get(sb);
7450 +struct au_nfsd_si_lock {
7451 + const au_gen_t sigen;
7452 + const aufs_bindex_t br_id;
7453 + unsigned char force_lock;
7456 +static aufs_bindex_t si_nfsd_read_lock(struct super_block *sb,
7457 + struct au_nfsd_si_lock *nsi_lock)
7459 + aufs_bindex_t bindex;
7461 + si_read_lock(sb, AuLock_FLUSH);
7463 + /* branch id may be wrapped around */
7464 + bindex = au_br_index(sb, nsi_lock->br_id);
7465 + LKTRTrace("b%d\n", bindex);
7466 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
7467 + goto out; /* success */
7469 + if (!nsi_lock->force_lock)
7470 + si_read_unlock(sb);
7477 +struct find_name_by_ino {
7478 + int called, found;
7485 +find_name_by_ino(void *arg, const char *name, int namelen, loff_t offset,
7486 + u64 ino, unsigned int d_type)
7488 + struct find_name_by_ino *a = arg;
7491 + if (a->ino != ino)
7494 + memcpy(a->name, name, namelen);
7495 + a->namelen = namelen;
7500 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
7501 + struct au_nfsd_si_lock *nsi_lock)
7503 + struct dentry *dentry, *parent;
7504 + struct file *file;
7505 + struct inode *dir;
7506 + struct find_name_by_ino arg;
7509 + parent = path->dentry;
7510 + LKTRTrace("%.*s, i%lu\n", AuDLNPair(parent), (unsigned long)ino);
7513 + si_read_unlock(parent->d_sb);
7515 + file = dentry_open(parent, path->mnt, au_dir_roflags, file->f_cred);
7516 + dentry = (void *)file;
7520 + dentry = ERR_PTR(-ENOMEM);
7521 + arg.name = __getname();
7522 + if (unlikely(!arg.name))
7529 + err = vfsub_readdir(file, find_name_by_ino, &arg, /*dlgt*/0);
7530 + } while (!err && !arg.found && arg.called);
7531 + dentry = ERR_PTR(err);
7532 + if (unlikely(err))
7534 + dentry = ERR_PTR(-ENOENT);
7538 + /* do not call au_lkup_one(), nor dlgt */
7539 + dir = parent->d_inode;
7540 + mutex_lock(&dir->i_mutex);
7541 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
7542 + mutex_unlock(&dir->i_mutex);
7543 + AuTraceErrPtr(dentry);
7544 + if (IS_ERR(dentry))
7546 + AuDebugOn(au_test_anon(dentry));
7547 + if (unlikely(!dentry->d_inode)) {
7549 + dentry = ERR_PTR(-ENOENT);
7553 + __putname(arg.name);
7557 + if (unlikely(nsi_lock
7558 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
7559 + if (!IS_ERR(dentry)) {
7561 + dentry = ERR_PTR(-ESTALE);
7563 + AuTraceErrPtr(dentry);
7567 +static /* noinline_for_stack */
7568 +struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
7569 + ino_t dir_ino, struct au_nfsd_si_lock *nsi_lock)
7571 + struct dentry *dentry, *parent;
7574 + LKTRTrace("i%lu, diri%lu\n",
7575 + (unsigned long)ino, (unsigned long)dir_ino);
7577 + parent = sb->s_root;
7578 + if (dir_ino != AUFS_ROOT_INO) {
7579 + parent = decode_by_ino(sb, dir_ino, 0);
7583 + if (IS_ERR(parent))
7585 + AuDebugOn(au_test_anon(parent));
7589 + path.dentry = parent;
7590 + path.mnt = au_mnt_get(sb);
7591 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
7595 + AuTraceErrPtr(dentry);
7599 +/* ---------------------------------------------------------------------- */
7601 +static int h_acceptable(void *expv, struct dentry *dentry)
7606 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
7607 + char *buf, int len, struct super_block *sb)
7615 + p = d_path(h_rootpath, buf, len);
7620 + path.mnt = h_rootpath->mnt;
7621 + path.dentry = h_parent;
7622 + p = d_path(&path, buf, len);
7625 + LKTRTrace("%s\n", p);
7628 + LKTRTrace("%p, %s, %ld\n",
7629 + p, p, (long)(p - buf));
7631 + path.mnt = au_mnt_get(sb);
7632 + path.dentry = sb->s_root;
7633 + p = d_path(&path, buf, len - strlen(p));
7638 + p[strlen(p)] = '/';
7639 + LKTRTrace("%s\n", p);
7646 +static noinline_for_stack
7647 +struct dentry *decode_by_path(struct super_block *sb, aufs_bindex_t bindex,
7648 + ino_t ino, __u32 *fh, int fh_len,
7649 + struct au_nfsd_si_lock *nsi_lock)
7651 + struct dentry *dentry, *h_parent, *root;
7652 + struct super_block *h_sb;
7653 + char *pathname, *p;
7654 + struct vfsmount *h_mnt;
7655 + struct au_branch *br;
7657 + struct nameidata nd;
7659 + LKTRTrace("b%d\n", bindex);
7660 + SiMustAnyLock(sb);
7662 + br = au_sbr(sb, bindex);
7663 + /* au_br_get(br); */
7664 + h_mnt = br->br_mnt;
7665 + h_sb = h_mnt->mnt_sb;
7666 + LKTRTrace("%s, h_decode_fh\n", au_sbtype(h_sb));
7667 + /* in linux-2.6.24, it takes struct fid * as file handle */
7668 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
7669 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
7670 + fh_len - Fh_tail, fh[Fh_h_type],
7671 + h_acceptable, /*context*/NULL);
7672 + dentry = h_parent;
7673 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
7674 + AuWarn1("%s decode_fh failed, %ld\n",
7675 + au_sbtype(h_sb), PTR_ERR(h_parent));
7679 + if (unlikely(au_test_anon(h_parent))) {
7680 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
7682 + goto out_h_parent;
7685 + dentry = ERR_PTR(-ENOMEM);
7686 + pathname = (void *)__get_free_page(GFP_NOFS);
7687 + if (unlikely(!pathname))
7688 + goto out_h_parent;
7690 + root = sb->s_root;
7691 + nd.path.mnt = h_mnt;
7692 + di_read_lock_parent(root, !AuLock_IR);
7693 + nd.path.dentry = au_h_dptr(root, bindex);
7694 + di_read_unlock(root, !AuLock_IR);
7695 + p = au_build_path(h_parent, &nd.path, pathname, PAGE_SIZE, sb);
7696 + dentry = (void *)p;
7698 + goto out_pathname;
7700 + LKTRTrace("%s\n", p);
7701 + si_read_unlock(sb);
7702 + err = vfsub_path_lookup(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &nd);
7703 + dentry = ERR_PTR(err);
7704 + if (unlikely(err))
7707 + dentry = ERR_PTR(-ENOENT);
7708 + AuDebugOn(au_test_anon(nd.path.dentry));
7709 + if (unlikely(!nd.path.dentry->d_inode))
7712 + if (ino != nd.path.dentry->d_inode->i_ino)
7713 + dentry = au_lkup_by_ino(&nd.path, ino, /*nsi_lock*/NULL);
7715 + dentry = dget(nd.path.dentry);
7718 + path_put(&nd.path);
7720 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
7721 + if (!IS_ERR(dentry)) {
7723 + dentry = ERR_PTR(-ESTALE);
7726 + free_page((unsigned long)pathname);
7730 + /* au_br_put(br); */
7731 + AuTraceErrPtr(dentry);
7735 +/* ---------------------------------------------------------------------- */
7737 +static struct dentry *
7738 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
7741 + struct dentry *dentry;
7742 + __u32 *fh = fid->raw;
7743 + ino_t ino, dir_ino;
7744 + aufs_bindex_t bindex;
7745 + struct au_nfsd_si_lock nsi_lock = {
7746 + .sigen = fh[Fh_sigen],
7747 + .br_id = fh[Fh_br_id],
7751 + LKTRTrace("%d, fh{br_id %u, sigen %u, i%u, diri%u, g%u}\n",
7752 + fh_type, fh[Fh_br_id], fh[Fh_sigen], fh[Fh_ino],
7753 + fh[Fh_dir_ino], fh[Fh_igen]);
7754 + AuDebugOn(fh_len < Fh_tail);
7756 + dentry = ERR_PTR(-ESTALE);
7757 + /* branch id may be wrapped around */
7758 + bindex = si_nfsd_read_lock(sb, &nsi_lock);
7759 + if (unlikely(bindex < 0))
7761 + nsi_lock.force_lock = 1;
7763 + /* is this inode still cached? */
7764 + ino = decode_ino(fh + Fh_ino);
7765 + AuDebugOn(ino == AUFS_ROOT_INO);
7766 + dir_ino = decode_ino(fh + Fh_dir_ino);
7767 + dentry = decode_by_ino(sb, ino, dir_ino);
7768 + if (IS_ERR(dentry))
7773 + /* is the parent dir cached? */
7774 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
7775 + if (IS_ERR(dentry))
7781 + dentry = decode_by_path(sb, bindex, ino, fh, fh_len, &nsi_lock);
7782 + if (IS_ERR(dentry))
7784 + if (unlikely(!dentry))
7785 + /* todo?: make it ESTALE */
7789 + LKTRLabel(accept);
7790 + if (dentry->d_inode->i_generation == fh[Fh_igen])
7791 + goto out_unlock; /* success */
7795 + dentry = ERR_PTR(-ESTALE);
7797 + LKTRLabel(out_unlock);
7798 + si_read_unlock(sb);
7801 + if (0 && IS_ERR(dentry))
7802 + dentry = ERR_PTR(-ESTALE);
7803 + AuTraceErrPtr(dentry);
7807 +#if 0 /* reserved for future use */
7808 +/* support subtreecheck option */
7809 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
7810 + int fh_len, int fh_type)
7812 + struct dentry *parent;
7813 + __u32 *fh = fid->raw;
7816 + dir_ino = decode_ino(fh + Fh_dir_ino);
7817 + parent = decode_by_ino(sb, dir_ino, 0);
7818 + if (IS_ERR(parent))
7821 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
7822 + dir_ino, fh, fh_len);
7825 + AuTraceErrPtr(parent);
7830 +/* ---------------------------------------------------------------------- */
7832 +static int aufs_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len,
7836 + aufs_bindex_t bindex, bend;
7837 + struct super_block *sb, *h_sb;
7838 + struct inode *inode;
7839 + struct dentry *parent, *h_parent;
7840 + struct au_branch *br;
7842 + LKTRTrace("%.*s, max %d, conn %d\n",
7843 + AuDLNPair(dentry), *max_len, connectable);
7844 + AuDebugOn(au_test_anon(dentry));
7848 + if (unlikely(*max_len <= Fh_tail)) {
7849 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
7853 + err = FILEID_ROOT;
7854 + if (IS_ROOT(dentry)) {
7855 + AuDebugOn(dentry->d_inode->i_ino != AUFS_ROOT_INO);
7861 + sb = dentry->d_sb;
7862 + aufs_read_lock(dentry, AuLock_FLUSH | AuLock_IR);
7863 + parent = dget_parent(dentry);
7864 + di_read_lock_parent(parent, !AuLock_IR);
7865 + inode = dentry->d_inode;
7866 + AuDebugOn(!inode);
7867 +#ifdef CONFIG_AUFS_DEBUG
7869 + unsigned int mnt_flags = au_mntflags(sb);
7871 + if (unlikely(!au_opt_test_xino(mnt_flags)))
7872 + AuWarn1("NFS-exporting requires xino\n");
7873 + if (unlikely(0 && !au_opt_test(mnt_flags, UDBA_INOTIFY)))
7874 + AuWarn1("udba=inotify is recommended "
7875 + "for NFS-exporting\n");
7879 + bend = au_dbtaildir(parent);
7880 + for (bindex = au_dbstart(parent); bindex <= bend; bindex++) {
7881 + h_parent = au_h_dptr(parent, bindex);
7887 + if (unlikely(!h_parent))
7889 + LKTRTrace("b%d\n", bindex);
7892 + br = au_sbr(sb, bindex);
7893 + h_sb = br->br_mnt->mnt_sb;
7894 + if (unlikely(!h_sb->s_export_op)) {
7895 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
7899 + fh[Fh_br_id] = br->br_id;
7900 + fh[Fh_sigen] = au_sigen(sb);
7901 + encode_ino(fh + Fh_ino, inode->i_ino);
7902 + encode_ino(fh + Fh_dir_ino, parent->d_inode->i_ino);
7903 + fh[Fh_igen] = inode->i_generation;
7905 + *max_len -= Fh_tail;
7906 + /* in linux-2.6.24, it takes struct fid * as file handle */
7907 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
7909 + /*connectable or subtreecheck*/0);
7910 + err = fh[Fh_h_type];
7911 + *max_len += Fh_tail;
7912 + /* todo: macros? */
7916 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
7921 + di_read_unlock(parent, !AuLock_IR);
7923 + aufs_read_unlock(dentry, AuLock_IR);
7926 + if (unlikely(err < 0))
7931 +/* ---------------------------------------------------------------------- */
7933 +static struct export_operations aufs_export_op = {
7934 + .fh_to_dentry = aufs_fh_to_dentry,
7935 + //.fh_to_parent = aufs_fh_to_parent,
7936 + .encode_fh = aufs_encode_fh
7939 +void au_export_init(struct super_block *sb)
7941 + struct au_sbinfo *sbinfo;
7945 + SiMustWriteLock(sb);
7947 + sb->s_export_op = &aufs_export_op;
7948 + sbinfo = au_sbi(sb);
7949 + sbinfo->si_xigen = NULL;
7950 + get_random_bytes(&u, sizeof(u));
7951 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
7952 + atomic_set(&sbinfo->si_xigen_next, u);
7953 + memset(&sbinfo->si_xinodir, 0, sizeof(struct path));
7955 diff -urN linux/fs/aufs/file.c linux-aufs/fs/aufs/file.c
7956 --- linux/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
7957 +++ linux-aufs/fs/aufs/file.c 2009-03-12 16:18:04.000000000 +0100
7960 + * Copyright (C) 2005-2009 Junjiro Okajima
7962 + * This program, aufs is free software; you can redistribute it and/or modify
7963 + * it under the terms of the GNU General Public License as published by
7964 + * the Free Software Foundation; either version 2 of the License, or
7965 + * (at your option) any later version.
7967 + * This program is distributed in the hope that it will be useful,
7968 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7969 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7970 + * GNU General Public License for more details.
7972 + * You should have received a copy of the GNU General Public License
7973 + * along with this program; if not, write to the Free Software
7974 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7978 + * handling file/dir, and address_space operation
7983 +#include <linux/pagemap.h>
7987 + * a dirty trick for handling FMODE_EXEC and deny_write_access().
7988 + * because FMODE_EXEC flag is not passed to f_op->open(),
7989 + * set it to file->private_data temporary.
7991 +#if !defined(CONFIG_AUFS_MODULE) || defined(CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH)
7992 +int au_store_fmode_exec(struct nameidata *nd, struct inode *inode)
8002 + && (nd->flags & LOOKUP_OPEN)
8003 + && nd->intent.open.file
8004 + && (nd->intent.open.flags & FMODE_EXEC)
8006 + && S_ISREG(inode->i_mode)) {
8007 + u.ul = nd->intent.open.flags;
8008 + nd->intent.open.file->private_data = u.p;
8017 +/* drop flags for writing */
8018 +unsigned int au_file_roflags(unsigned int flags)
8020 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
8021 + flags |= O_RDONLY | O_NOATIME;
8025 +/* common functions to regular file and dir */
8026 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
8027 + struct file *file)
8029 + struct file *h_file;
8030 + struct dentry *h_dentry;
8031 + struct inode *h_inode;
8032 + struct super_block *sb;
8033 + struct au_branch *br;
8036 + LKTRTrace("%.*s, b%d, flags 0%o, f %d\n",
8037 + AuDLNPair(dentry), bindex, flags, !!file);
8038 + h_dentry = au_h_dptr(dentry, bindex);
8039 + AuDebugOn(!h_dentry);
8040 + h_inode = h_dentry->d_inode;
8042 + /* a race condition can happen between open and unlink/rmdir */
8043 + h_file = ERR_PTR(-ENOENT);
8044 + if (unlikely((!d_unhashed(dentry) && d_unhashed(h_dentry))
8048 + sb = dentry->d_sb;
8049 + br = au_sbr(sb, bindex);
8051 + /* drop flags for writing */
8052 + if (au_test_ro(sb, bindex, dentry->d_inode))
8053 + flags = au_file_roflags(flags);
8054 + flags &= ~O_CREAT;
8057 + if (file && au_test_nfs(h_dentry->d_sb))
8058 + h_file = au_h_intent(dentry, bindex, file);
8060 + h_file = dentry_open(dget(h_dentry), mntget(br->br_mnt), flags, current_cred());
8063 + * a dirty trick for handling FMODE_EXEC and deny_write_access().
8065 + if (file && (file->f_mode & FMODE_EXEC)) {
8066 + h_file->f_mode |= FMODE_EXEC;
8067 + smp_mb(); /* flush f_mode */
8068 + err = au_deny_write_access(h_file);
8069 + if (unlikely(err)) {
8071 + h_file = ERR_PTR(err);
8074 + if (IS_ERR(h_file))
8078 + AuTraceErrPtr(h_file);
8082 +static int do_coo(struct dentry *dentry, aufs_bindex_t bstart)
8085 + aufs_bindex_t bcpup;
8086 + unsigned char pin_flags;
8087 + struct au_pin pin;
8088 + struct dentry *parent;
8089 + struct mutex *h_mtx;
8090 + struct super_block *sb;
8092 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
8093 + AuDebugOn(IS_ROOT(dentry));
8094 + DiMustWriteLock(dentry);
8096 + parent = dget_parent(dentry);
8097 + di_write_lock_parent(parent);
8098 + sb = dentry->d_sb;
8099 + err = AuWbrCopyup(au_sbi(sb), dentry);
8102 + err = 0; /* stop copyup, it is not an error */
8107 + if (!au_h_dptr(parent, bcpup)) {
8108 + err = au_cpup_dirs(dentry, bcpup);
8109 + if (unlikely(err))
8113 + di_downgrade_lock(parent, AuLock_IR);
8114 + pin_flags = AuPin_DI_LOCKED | AuPin_MNT_WRITE;
8115 + if (au_opt_test(au_mntflags(sb), UDBA_INOTIFY))
8116 + au_fset_pin(pin_flags, DO_GPARENT);
8117 + err = au_pin(&pin, dentry, bcpup, pin_flags);
8118 + if (unlikely(err))
8120 + h_mtx = &au_h_dptr(dentry, bstart)->d_inode->i_mutex;
8121 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
8122 + AuDebugOn(au_h_dptr(dentry, bcpup));
8123 + err = au_sio_cpup_simple(dentry, bcpup, -1, AuCpup_DTIME);
8125 + mutex_unlock(h_mtx);
8130 + di_downgrade_lock(parent, AuLock_IR);
8132 + di_read_unlock(parent, AuLock_IR);
8138 +int au_do_open(struct inode *inode, struct file *file,
8139 + int (*open)(struct file *file, int flags))
8142 + struct dentry *dentry;
8143 + struct super_block *sb;
8144 + aufs_bindex_t bstart;
8145 + unsigned char coo;
8147 + dentry = file->f_dentry;
8148 + LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(dentry));
8150 + sb = dentry->d_sb;
8151 + si_read_lock(sb, AuLock_FLUSH);
8153 + if (!(sb->s_flags & MS_RDONLY))
8154 + switch (au_mntflags(sb) & AuOptMask_COO) {
8155 + case AuOpt_COO_LEAF:
8156 + coo = !S_ISDIR(inode->i_mode);
8158 + case AuOpt_COO_ALL:
8162 + err = au_finfo_init(file);
8163 + if (unlikely(err))
8167 + di_read_lock_child(dentry, AuLock_IR);
8169 + di_write_lock_child(dentry);
8170 + bstart = au_dbstart(dentry);
8171 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
8172 + err = do_coo(dentry, bstart);
8174 + di_write_unlock(dentry);
8178 + di_downgrade_lock(dentry, AuLock_IR);
8181 + err = open(file, file->f_flags);
8182 + di_read_unlock(dentry, AuLock_IR);
8185 + fi_write_unlock(file);
8186 + if (unlikely(err))
8187 + au_finfo_fin(file);
8189 + si_read_unlock(sb);
8194 +int au_reopen_nondir(struct file *file)
8197 + aufs_bindex_t bstart, bindex, bend;
8198 + struct dentry *dentry;
8199 + struct file *h_file, *h_file_tmp;
8201 + dentry = file->f_dentry;
8202 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
8203 + bstart = au_dbstart(dentry);
8204 + //bstart = au_ibstart(inode);
8205 + AuDebugOn(S_ISDIR(dentry->d_inode->i_mode)
8206 + || !au_h_dptr(dentry, bstart)->d_inode);
8208 + h_file_tmp = NULL;
8209 + if (au_fbstart(file) == bstart) {
8210 + h_file = au_h_fptr(file, bstart);
8211 + if (file->f_mode == h_file->f_mode)
8212 + return 0; /* success */
8213 + h_file_tmp = h_file;
8214 + get_file(h_file_tmp);
8215 + au_set_h_fptr(file, bstart, NULL);
8217 + AuDebugOn(au_fbstart(file) < bstart
8218 + || au_fi(file)->fi_hfile[0 + bstart].hf_file);
8220 + h_file = au_h_open(dentry, bstart, file->f_flags & ~O_TRUNC, file);
8221 + err = PTR_ERR(h_file);
8222 + if (IS_ERR(h_file))
8223 + goto out; /* todo: close all? */
8225 + /* cpup_file_flags(h_file, file); */
8226 + au_set_fbstart(file, bstart);
8227 + au_set_h_fptr(file, bstart, h_file);
8228 + au_update_figen(file);
8229 + /* todo: necessary? */
8230 + /* file->f_ra = h_file->f_ra; */
8232 + /* close lower files */
8233 + bend = au_fbend(file);
8234 + for (bindex = bstart + 1; bindex <= bend; bindex++)
8235 + au_set_h_fptr(file, bindex, NULL);
8236 + au_set_fbend(file, bstart);
8245 +/* ---------------------------------------------------------------------- */
8247 +static int au_ready_to_write_wh(struct file *file, loff_t len,
8248 + aufs_bindex_t bcpup)
8251 + aufs_bindex_t old_bstart;
8252 + struct inode *inode;
8253 + struct dentry *dentry, *hi_wh, *old_h_dentry;
8254 + struct au_dinfo *dinfo;
8255 + struct super_block *sb;
8259 + dentry = file->f_dentry;
8260 + inode = dentry->d_inode;
8261 + hi_wh = au_hi_wh(inode, bcpup);
8263 + err = au_sio_cpup_wh(dentry, bcpup, len, file);
8265 + /* already copied-up after unlink */
8266 + dinfo = au_di(dentry);
8267 + old_bstart = dinfo->di_bstart;
8268 + dinfo->di_bstart = bcpup;
8269 + old_h_dentry = dinfo->di_hdentry[0 + bcpup].hd_dentry;
8270 + dinfo->di_hdentry[0 + bcpup].hd_dentry = hi_wh;
8271 + err = au_reopen_nondir(file);
8272 + dinfo->di_hdentry[0 + bcpup].hd_dentry = old_h_dentry;
8273 + dinfo->di_bstart = old_bstart;
8276 + sb = dentry->d_sb;
8277 + if (!err && inode->i_nlink > 1 && au_opt_test(au_mntflags(sb), PLINK))
8278 + au_plink_append(sb, inode, au_h_dptr(dentry, bcpup), bcpup);
8285 + * prepare the @file for writing.
8287 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
8290 + unsigned char pin_flags;
8291 + aufs_bindex_t bstart, bcpup;
8292 + struct dentry *dentry, *parent, *h_dentry;
8293 + struct inode *h_inode, *inode;
8294 + struct super_block *sb;
8296 + dentry = file->f_dentry;
8297 + LKTRTrace("%.*s, len %lld\n", AuDLNPair(dentry), len);
8298 + FiMustWriteLock(file);
8300 + sb = dentry->d_sb;
8301 + bstart = au_fbstart(file);
8302 + AuDebugOn(au_fbr(file, bstart) != au_sbr(sb, bstart));
8304 + inode = dentry->d_inode;
8305 + AuDebugOn(S_ISDIR(inode->i_mode));
8306 + LKTRTrace("rdonly %d, bstart %d\n",
8307 + au_test_ro(sb, bstart, inode), bstart);
8309 + err = au_test_ro(sb, bstart, inode);
8310 + if (!err && (au_h_fptr(file, bstart)->f_mode & FMODE_WRITE)) {
8311 + err = au_pin(pin, dentry, bstart, /*flags*/0);
8315 + /* need to cpup */
8316 + parent = dget_parent(dentry);
8317 + di_write_lock_parent(parent);
8318 + err = AuWbrCopyup(au_sbi(sb), dentry);
8320 + if (unlikely(err < 0))
8324 + if (!au_h_dptr(parent, bcpup)) {
8325 + err = au_cpup_dirs(dentry, bcpup);
8326 + if (unlikely(err))
8330 + pin_flags = AuPin_DI_LOCKED | AuPin_MNT_WRITE;
8331 + if (au_opt_test(au_mntflags(sb), UDBA_INOTIFY))
8332 + au_fset_pin(pin_flags, DO_GPARENT);
8333 + err = au_pin(pin, dentry, bcpup, pin_flags);
8334 + if (unlikely(err))
8337 + AuDebugOn(au_fbstart(file) != bstart);
8338 + h_dentry = au_h_fptr(file, bstart)->f_dentry;
8339 + h_inode = h_dentry->d_inode;
8340 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
8341 + if (d_unhashed(dentry) /* || d_unhashed(h_dentry) */
8342 + /* || !h_inode->i_nlink */) {
8343 + err = au_ready_to_write_wh(file, len, bcpup);
8344 + di_downgrade_lock(parent, AuLock_IR);
8346 + di_downgrade_lock(parent, AuLock_IR);
8347 + if (!au_h_dptr(dentry, bcpup))
8348 + err = au_sio_cpup_simple(dentry, bcpup, len,
8352 + err = au_reopen_nondir(file);
8355 + mutex_unlock(&h_inode->i_mutex);
8359 + au_pin_set_parent_lflag(pin, /*lflag*/0);
8360 + goto out_dput; /* success */
8366 + di_downgrade_lock(parent, AuLock_IR);
8368 + di_read_unlock(parent, AuLock_IR);
8376 +/* ---------------------------------------------------------------------- */
8378 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
8381 + unsigned int mnt_flags;
8382 + unsigned char pin_flags;
8383 + aufs_bindex_t bstart, new_bstart, old_bstart;
8384 + struct au_pin pin;
8385 + struct au_finfo *finfo;
8386 + struct dentry *dentry, *parent, *old_h_dentry, *hi_wh;
8387 + struct inode *inode, *dir;
8388 + struct super_block *sb;
8389 + struct au_dinfo *dinfo;
8391 + dentry = file->f_dentry;
8392 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
8393 + FiMustWriteLock(file);
8396 + finfo = au_fi(file);
8397 + inode = dentry->d_inode;
8398 + sb = dentry->d_sb;
8399 + mnt_flags = au_mntflags(sb);
8400 + pin_flags = AuPin_DI_LOCKED | AuPin_MNT_WRITE;
8401 + if (au_opt_test(mnt_flags, UDBA_INOTIFY))
8402 + au_fset_pin(pin_flags, DO_GPARENT);
8404 + bstart = au_ibstart(inode);
8405 + if (bstart == finfo->fi_bstart)
8408 + new_bstart = bstart;
8409 + parent = dget_parent(dentry);
8410 + dir = parent->d_inode;
8411 + if (au_test_ro(sb, bstart, inode)) {
8412 + di_read_lock_parent(parent, !AuLock_IR);
8413 + err = AuWbrCopyup(au_sbi(sb), dentry);
8415 + di_read_unlock(parent, !AuLock_IR);
8416 + if (unlikely(err < 0))
8420 + /* someone else might change our inode while we were sleeping */
8421 + /* todo: test more? */
8422 + if (bstart != au_ibstart(inode)) {
8427 + di_read_lock_parent(parent, AuLock_IR);
8428 + bstart = new_bstart;
8430 + hi_wh = au_hi_wh(inode, bstart);
8431 + if (au_opt_test(mnt_flags, PLINK)
8432 + && au_plink_test(sb, inode)
8433 + && !d_unhashed(dentry)) {
8434 + err = au_test_and_cpup_dirs(dentry, bstart);
8435 + if (unlikely(err))
8438 + /* always superio. */
8440 + err = au_pin(&pin, dentry, bstart, pin_flags);
8442 + err = au_sio_cpup_simple(dentry, bstart, -1,
8445 +#else /* reserved for future use */
8446 + if (!au_test_wkq(current)) {
8448 + struct cpup_pseudo_link_args args = {
8454 + wkq_err = au_wkq_wait(call_cpup_pseudo_link, &args);
8455 + if (unlikely(wkq_err))
8458 + err = cpup_pseudo_link(dentry, bstart, /*do_lock*/1);
8460 + } else if (hi_wh) {
8461 + /* already copied-up after unlink */
8462 + dinfo = au_di(dentry);
8463 + old_bstart = dinfo->di_bstart;
8464 + dinfo->di_bstart = bstart;
8465 + old_h_dentry = dinfo->di_hdentry[0 + bstart].hd_dentry;
8466 + dinfo->di_hdentry[0 + bstart].hd_dentry = hi_wh;
8467 + err = au_reopen_nondir(file);
8468 + dinfo->di_hdentry[0 + bstart].hd_dentry = old_h_dentry;
8469 + dinfo->di_bstart = old_bstart;
8474 + di_read_unlock(parent, AuLock_IR);
8483 + * after branch manipulating, refresh the file.
8485 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
8487 + int err, new_sz, need_reopen;
8488 + struct dentry *dentry;
8489 + aufs_bindex_t bend, bindex, brid;
8490 + struct au_hfile *p;
8491 + struct au_finfo *finfo;
8492 + struct super_block *sb;
8493 + struct inode *inode;
8495 + dentry = file->f_dentry;
8496 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
8497 + FiMustWriteLock(file);
8498 + DiMustAnyLock(dentry);
8499 + inode = dentry->d_inode;
8500 + IiMustAnyLock(inode);
8503 + sb = dentry->d_sb;
8504 + finfo = au_fi(file);
8505 + new_sz = sizeof(*finfo->fi_hfile) * (au_sbend(sb) + 1);
8506 + p = au_kzrealloc(finfo->fi_hfile, sizeof(*p) * (finfo->fi_bend + 1),
8507 + new_sz, GFP_NOFS);
8510 + finfo->fi_hfile = p;
8512 + p += finfo->fi_bstart;
8513 + brid = p->hf_br->br_id;
8514 + bend = finfo->fi_bend;
8515 + for (bindex = finfo->fi_bstart; bindex <= bend; bindex++, p++) {
8516 + struct au_hfile tmp, *q;
8517 + aufs_bindex_t new_bindex;
8521 + new_bindex = au_find_bindex(sb, p->hf_br);
8522 + if (new_bindex == bindex)
8524 + /* todo: test more? */
8525 + if (new_bindex < 0) {
8526 + au_set_h_fptr(file, bindex, NULL);
8530 + /* swap two hidden inode, and loop again */
8531 + q = finfo->fi_hfile + new_bindex;
8535 + if (tmp.hf_file) {
8541 + aufs_bindex_t s = finfo->fi_bstart, e = finfo->fi_bend;
8542 + finfo->fi_bstart = 0;
8543 + finfo->fi_bend = au_sbend(sb);
8544 + finfo->fi_bstart = s;
8545 + finfo->fi_bend = e;
8548 + p = finfo->fi_hfile;
8549 + if (!au_test_mmapped(file) && !d_unhashed(dentry)) {
8550 + bend = au_sbend(sb);
8551 + for (finfo->fi_bstart = 0; finfo->fi_bstart <= bend;
8552 + finfo->fi_bstart++, p++)
8554 + if (p->hf_file->f_dentry
8555 + && p->hf_file->f_dentry->d_inode)
8561 + bend = au_br_index(sb, brid);
8562 + for (finfo->fi_bstart = 0; finfo->fi_bstart < bend;
8563 + finfo->fi_bstart++, p++)
8566 + bend = au_sbend(sb);
8569 + p = finfo->fi_hfile + bend;
8570 + for (finfo->fi_bend = bend; finfo->fi_bend >= finfo->fi_bstart;
8571 + finfo->fi_bend--, p--)
8573 + if (p->hf_file->f_dentry
8574 + && p->hf_file->f_dentry->d_inode)
8579 + AuDebugOn(finfo->fi_bend < finfo->fi_bstart);
8583 + if (!au_test_mmapped(file))
8584 + err = au_file_refresh_by_inode(file, &need_reopen);
8585 + if (!err && need_reopen && !d_unhashed(dentry))
8586 + err = reopen(file);
8588 + au_update_figen(file);
8589 + return 0; /* success */
8592 + /* error, close all hidden files */
8593 + bend = au_fbend(file);
8594 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
8595 + au_set_h_fptr(file, bindex, NULL);
8602 +/* common function to regular file and dir */
8603 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
8604 + int wlock, int locked)
8607 + struct dentry *dentry;
8608 + struct super_block *sb;
8609 + aufs_bindex_t bstart;
8610 + unsigned char pseudo_link;
8611 + au_gen_t sgen, fgen;
8613 + dentry = file->f_dentry;
8614 + LKTRTrace("%.*s, w %d, l %d\n", AuDLNPair(dentry), wlock, locked);
8615 + sb = dentry->d_sb;
8616 + SiMustAnyLock(sb);
8619 + sgen = au_sigen(sb);
8620 + fi_write_lock(file);
8621 + fgen = au_figen(file);
8622 + di_write_lock_child(dentry);
8623 + bstart = au_dbstart(dentry);
8624 + pseudo_link = (bstart != au_ibstart(dentry->d_inode));
8625 + if (sgen == fgen && !pseudo_link && au_fbstart(file) == bstart) {
8627 + di_downgrade_lock(dentry, AuLock_IR);
8628 + fi_downgrade_lock(file);
8630 + goto out; /* success */
8633 + LKTRTrace("sgen %d, fgen %d\n", sgen, fgen);
8634 + if (sgen != au_digen(dentry)
8635 + || sgen != au_iigen(dentry->d_inode)) {
8637 + * d_path() and path_lookup() is a simple and good approach
8638 + * to revalidate. but si_rwsem in DEBUG_RWSEM will cause a
8639 + * deadlock. removed the code.
8641 + err = au_reval_dpath(dentry, sgen);
8642 + if (unlikely(err < 0))
8644 + AuDebugOn(au_digen(dentry) != sgen
8645 + || au_iigen(dentry->d_inode) != sgen);
8648 + err = refresh_file(file, reopen
8649 + /* , au_opt_test(au_mnt_flags(sb), REFROF) */);
8652 + di_downgrade_lock(dentry, AuLock_IR);
8653 + fi_downgrade_lock(file);
8656 + di_write_unlock(dentry);
8657 + fi_write_unlock(file);
8665 +/* ---------------------------------------------------------------------- */
8667 +/* cf. aufs_nopage() */
8668 +/* for madvise(2) */
8669 +static int aufs_readpage(struct file *file, struct page *page)
8672 + unlock_page(page);
8676 +/* they will never be called. */
8677 +#ifdef CONFIG_AUFS_DEBUG
8678 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
8679 +static int aufs_prepare_write(struct file *file, struct page *page,
8680 + unsigned from, unsigned to)
8681 +{ AuUnsupport(); return 0; }
8682 +static int aufs_commit_write(struct file *file, struct page *page,
8683 + unsigned from, unsigned to)
8684 +{ AuUnsupport(); return 0; }
8686 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
8687 + loff_t pos, unsigned len, unsigned flags,
8688 + struct page **pagep, void **fsdata)
8689 +{ AuUnsupport(); return 0; }
8690 +static int aufs_write_end(struct file *file, struct address_space *mapping,
8691 + loff_t pos, unsigned len, unsigned copied,
8692 + struct page *page, void *fsdata)
8693 +{ AuUnsupport(); return 0; }
8694 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
8695 +{ AuUnsupport(); return 0; }
8696 +static void aufs_sync_page(struct page *page)
8699 +static int aufs_set_page_dirty(struct page *page)
8700 +{ AuUnsupport(); return 0; }
8701 +static void aufs_invalidatepage(struct page *page, unsigned long offset)
8703 +static int aufs_releasepage(struct page *page, gfp_t gfp)
8704 +{ AuUnsupport(); return 0; }
8705 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
8706 + const struct iovec *iov, loff_t offset,
8707 + unsigned long nr_segs)
8708 +{ AuUnsupport(); return 0; }
8709 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
8710 +static struct page *aufs_get_xip_page(struct address_space *mapping,
8711 + sector_t offset, int create)
8712 +{ AuUnsupport(); return NULL; }
8714 +#endif /* CONFIG_AUFS_DEBUG */
8716 +struct address_space_operations aufs_aop = {
8717 + .readpage = aufs_readpage,
8718 +#ifdef CONFIG_AUFS_DEBUG
8719 + .writepage = aufs_writepage,
8720 + .sync_page = aufs_sync_page,
8721 + .set_page_dirty = aufs_set_page_dirty,
8722 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
8723 + .prepare_write = aufs_prepare_write,
8724 + .commit_write = aufs_commit_write,
8726 + .write_begin = aufs_write_begin,
8727 + .write_end = aufs_write_end,
8728 + .invalidatepage = aufs_invalidatepage,
8729 + .releasepage = aufs_releasepage,
8730 + .direct_IO = aufs_direct_IO,
8731 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
8732 + .get_xip_page = aufs_get_xip_page,
8734 +#endif /* CONFIG_AUFS_DEBUG */
8736 diff -urN linux/fs/aufs/file.h linux-aufs/fs/aufs/file.h
8737 --- linux/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
8738 +++ linux-aufs/fs/aufs/file.h 2009-03-12 16:18:04.000000000 +0100
8741 + * Copyright (C) 2005-2009 Junjiro Okajima
8743 + * This program, aufs is free software; you can redistribute it and/or modify
8744 + * it under the terms of the GNU General Public License as published by
8745 + * the Free Software Foundation; either version 2 of the License, or
8746 + * (at your option) any later version.
8748 + * This program is distributed in the hope that it will be useful,
8749 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8750 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8751 + * GNU General Public License for more details.
8753 + * You should have received a copy of the GNU General Public License
8754 + * along with this program; if not, write to the Free Software
8755 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8764 +#ifndef __AUFS_FILE_H__
8765 +#define __AUFS_FILE_H__
8769 +#include <linux/file.h>
8770 +#include <linux/fs.h>
8771 +#include <linux/mm.h>
8772 +#include <linux/aufs_type.h>
8773 +#include "dentry.h"
8777 +/* ---------------------------------------------------------------------- */
8781 + struct file *hf_file;
8782 + struct au_branch *hf_br;
8787 + atomic_t fi_generation;
8789 + struct au_rwsem fi_rwsem;
8790 + struct au_hfile *fi_hfile;
8791 + aufs_bindex_t fi_bstart, fi_bend;
8794 + struct vm_operations_struct *fi_h_vm_ops;
8795 + struct au_vdir *fi_vdir_cache;
8799 +/* ---------------------------------------------------------------------- */
8802 +extern struct address_space_operations aufs_aop;
8803 +unsigned int au_file_roflags(unsigned int flags);
8804 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
8805 + struct file *file);
8806 +int au_do_open(struct inode *inode, struct file *file,
8807 + int (*open)(struct file *file, int flags));
8808 +int au_reopen_nondir(struct file *file);
8810 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
8811 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
8812 + int wlock, int locked);
8815 +extern struct file_operations aufs_file_fop;
8816 +int aufs_flush(struct file *file, fl_owner_t id);
8819 +struct au_finfo *au_fi(struct file *file);
8820 +struct au_branch *au_fbr(struct file *file, aufs_bindex_t bindex);
8821 +struct file *au_h_fptr(struct file *file, aufs_bindex_t bindex);
8823 +void au_hfput(struct au_hfile *hf);
8824 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
8825 + struct file *h_file);
8827 +void au_finfo_fin(struct file *file);
8828 +int au_finfo_init(struct file *file);
8830 +#ifdef CONFIG_AUFS_ROBR
8832 +struct file *au_robr_safe_file(struct vm_area_struct *vma);
8833 +void au_robr_reset_file(struct vm_area_struct *vma, struct file *file);
8835 +static inline struct file *au_robr_safe_file(struct vm_area_struct *vma)
8837 + struct file *file;
8839 + file = vma->vm_file;
8840 + if (file->private_data && au_test_aufs(file->f_dentry->d_sb))
8846 +void au_robr_reset_file(struct vm_area_struct *vma, struct file *file)
8848 + vma->vm_file = file;
8849 + /* smp_mb(); */ /* flush vm_file */
8851 +#endif /* CONFIG_AUFS_ROBR */
8853 +#if 0 /* reserved for future use */
8855 +long aufs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
8856 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
8859 +/* ---------------------------------------------------------------------- */
8861 +/* todo: memory barrier? */
8862 +static inline au_gen_t au_figen(struct file *f)
8864 + return atomic_read(&au_fi(f)->fi_generation);
8867 +static inline int au_test_mmapped(struct file *f)
8869 + return !!(au_fi(f)->fi_h_vm_ops);
8872 +static inline int au_test_aufs_file(struct file *f)
8874 + return !(f->f_dentry->d_inode->i_mode
8875 + & (S_IFCHR | S_IFBLK | S_IFIFO | S_IFSOCK));
8878 +/* ---------------------------------------------------------------------- */
8880 +#if !defined(CONFIG_AUFS_MODULE) || defined(CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH)
8881 +int au_store_fmode_exec(struct nameidata *nd, struct inode *inode);
8883 +static inline int au_deny_write_access(struct file *h_file)
8885 + LKTRTrace("%.*s\n", AuDLNPair(h_file->f_dentry));
8886 + return deny_write_access(h_file);
8889 +static inline void au_allow_write_access(struct file *h_file)
8891 + allow_write_access(h_file);
8896 +static inline int au_store_fmode_exec(struct nameidata *nd, struct inode *inode)
8902 +static inline int au_deny_write_access(struct file *h_file)
8908 +static inline void au_allow_write_access(struct file *h_file)
8912 +#endif /* CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH */
8914 +/* ---------------------------------------------------------------------- */
8917 + * fi_read_lock, fi_write_lock,
8918 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
8920 +AuSimpleRwsemFuncs(fi, struct file *f, au_fi(f)->fi_rwsem);
8922 +/* to debug easier, do not make them inlined functions */
8923 +#define FiMustReadLock(f) do { \
8924 + SiMustAnyLock((f)->f_dentry->d_sb); \
8925 + AuRwMustReadLock(&au_fi(f)->fi_rwsem); \
8928 +#define FiMustWriteLock(f) do { \
8929 + SiMustAnyLock((f)->f_dentry->d_sb); \
8930 + AuRwMustWriteLock(&au_fi(f)->fi_rwsem); \
8933 +#define FiMustAnyLock(f) do { \
8934 + SiMustAnyLock((f)->f_dentry->d_sb); \
8935 + AuRwMustAnyLock(&au_fi(f)->fi_rwsem); \
8938 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
8940 +/* ---------------------------------------------------------------------- */
8942 +/* todo: hard/soft set? */
8943 +static inline aufs_bindex_t au_fbstart(struct file *file)
8945 + FiMustAnyLock(file);
8946 + return au_fi(file)->fi_bstart;
8949 +static inline aufs_bindex_t au_fbend(struct file *file)
8951 + FiMustAnyLock(file);
8952 + return au_fi(file)->fi_bend;
8955 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
8957 +#ifdef CONFIG_AUFS_EXPORT
8958 + AuRwMustAnyLock(&au_fi(file)->fi_rwsem);
8960 + FiMustAnyLock(file);
8962 + return au_fi(file)->fi_vdir_cache;
8965 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
8967 + FiMustWriteLock(file);
8968 + AuDebugOn(au_sbend(file->f_dentry->d_sb) < bindex);
8969 + au_fi(file)->fi_bstart = bindex;
8972 +static inline void au_set_fbend(struct file *file, aufs_bindex_t bindex)
8974 + FiMustWriteLock(file);
8975 + AuDebugOn(au_sbend(file->f_dentry->d_sb) < bindex
8976 + || bindex < au_fbstart(file));
8977 + au_fi(file)->fi_bend = bindex;
8980 +static inline void au_set_fvdir_cache(struct file *file,
8981 + struct au_vdir *vdir_cache)
8983 + FiMustWriteLock(file);
8984 + AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode)
8985 + || (au_fi(file)->fi_vdir_cache && vdir_cache));
8986 + au_fi(file)->fi_vdir_cache = vdir_cache;
8989 +static inline void au_update_figen(struct file *file)
8991 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
8992 + /* smp_mb(); */ /* atomic_set */
8995 +#endif /* __KERNEL__ */
8996 +#endif /* __AUFS_FILE_H__ */
8997 diff -urN linux/fs/aufs/finfo.c linux-aufs/fs/aufs/finfo.c
8998 --- linux/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
8999 +++ linux-aufs/fs/aufs/finfo.c 2009-03-12 16:18:04.000000000 +0100
9002 + * Copyright (C) 2005-2009 Junjiro Okajima
9004 + * This program, aufs is free software; you can redistribute it and/or modify
9005 + * it under the terms of the GNU General Public License as published by
9006 + * the Free Software Foundation; either version 2 of the License, or
9007 + * (at your option) any later version.
9009 + * This program is distributed in the hope that it will be useful,
9010 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9011 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9012 + * GNU General Public License for more details.
9014 + * You should have received a copy of the GNU General Public License
9015 + * along with this program; if not, write to the Free Software
9016 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9020 + * file private data
9027 +struct au_finfo *au_fi(struct file *file)
9029 + struct au_finfo *finfo = file->private_data;
9031 + || !finfo->fi_hfile
9032 + || (0 < finfo->fi_bend
9033 + && (/* au_sbi(file->f_dentry->d_sb)->si_bend
9035 + || */ finfo->fi_bend < finfo->fi_bstart)));
9039 +struct au_branch *au_fbr(struct file *file, aufs_bindex_t bindex)
9041 + struct au_finfo *finfo = au_fi(file);
9042 + struct au_hfile *hf;
9044 + FiMustAnyLock(file);
9046 + || finfo->fi_bstart < 0
9047 + || bindex < finfo->fi_bstart
9048 + || finfo->fi_bend < bindex);
9049 + hf = finfo->fi_hfile + bindex;
9050 + AuDebugOn(hf->hf_br && au_br_count(hf->hf_br) <= 0);
9054 +struct file *au_h_fptr(struct file *file, aufs_bindex_t bindex)
9056 + struct au_finfo *finfo = au_fi(file);
9057 + struct au_hfile *hf;
9059 + FiMustAnyLock(file);
9061 + || finfo->fi_bstart < 0
9062 + || bindex < finfo->fi_bstart
9063 + || finfo->fi_bend < bindex);
9064 + hf = finfo->fi_hfile + bindex;
9065 + AuDebugOn(hf->hf_file
9066 + && file_count(hf->hf_file) <= 0
9067 + && au_br_count(hf->hf_br) <= 0);
9068 + return hf->hf_file;
9071 +void au_hfput(struct au_hfile *hf)
9073 + if (hf->hf_file->f_mode & FMODE_EXEC)
9074 + au_allow_write_access(hf->hf_file);
9075 + fput(hf->hf_file);
9076 + hf->hf_file = NULL;
9077 + AuDebugOn(!hf->hf_br);
9078 + au_br_put(hf->hf_br);
9082 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
9084 + struct au_finfo *finfo = au_fi(file);
9085 + struct au_hfile *hf;
9087 + FiMustWriteLock(file);
9089 + || finfo->fi_bstart < 0
9090 + || bindex < finfo->fi_bstart
9091 + || finfo->fi_bend < bindex);
9092 + AuDebugOn(val && file_count(val) <= 0);
9093 + hf = finfo->fi_hfile + bindex;
9094 + AuDebugOn(val && hf->hf_file);
9098 + hf->hf_file = val;
9099 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
9103 +void au_finfo_fin(struct file *file)
9105 + struct au_finfo *finfo;
9106 + struct dentry *dentry;
9107 + aufs_bindex_t bindex, bend;
9109 + dentry = file->f_dentry;
9110 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
9111 + SiMustAnyLock(dentry->d_sb);
9113 + fi_write_lock(file);
9114 + bend = au_fbend(file);
9115 + bindex = au_fbstart(file);
9117 + for (; bindex <= bend; bindex++)
9118 + au_set_h_fptr(file, bindex, NULL);
9120 + finfo = au_fi(file);
9121 +#ifdef CONFIG_AUFS_DEBUG
9122 + if (finfo->fi_bstart >= 0) {
9123 + bend = au_fbend(file);
9124 + for (bindex = finfo->fi_bstart; bindex <= bend; bindex++) {
9125 + struct au_hfile *hf;
9126 + hf = finfo->fi_hfile + bindex;
9127 + AuDebugOn(hf->hf_file || hf->hf_br);
9132 + kfree(finfo->fi_hfile);
9133 + fi_write_unlock(file);
9134 + au_rwsem_destroy(&finfo->fi_rwsem);
9135 + au_cache_free_finfo(finfo);
9138 +int au_finfo_init(struct file *file)
9140 + struct au_finfo *finfo;
9141 + struct dentry *dentry;
9147 + dentry = file->f_dentry;
9148 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
9149 + AuDebugOn(!dentry->d_inode);
9151 + finfo = au_cache_alloc_finfo();
9153 + finfo->fi_hfile = kcalloc(au_sbend(dentry->d_sb) + 1,
9154 + sizeof(*finfo->fi_hfile), GFP_NOFS);
9155 + if (finfo->fi_hfile) {
9156 + au_rw_init_wlock(&finfo->fi_rwsem);
9157 + //au_dbg_lock_fi_reg(file);
9158 + finfo->fi_bstart = -1;
9159 + finfo->fi_bend = -1;
9160 + atomic_set(&finfo->fi_generation, au_digen(dentry));
9161 + /* smp_mb(); */ /* atomic_set */
9164 + * a dirty trick for handling FMODE_EXEC and
9165 + * deny_write_access().
9166 + * because FMODE_EXEC flag is not passed to
9168 + * aufs set it to file->private_data temporary in lookup
9169 + * or dentry revalidation operations.
9170 + * restore the flag to f_mode here.
9172 + u.p = file->private_data;
9173 + if (u.ul & FMODE_EXEC) {
9174 + file->f_mode |= FMODE_EXEC;
9175 + smp_mb(); /* flush f_mode */
9178 + file->private_data = finfo;
9179 + return 0; /* success */
9181 + au_cache_free_finfo(finfo);
9184 + AuTraceErr(-ENOMEM);
9187 diff -urN linux/fs/aufs/f_op.c linux-aufs/fs/aufs/f_op.c
9188 --- linux/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
9189 +++ linux-aufs/fs/aufs/f_op.c 2009-03-12 16:18:04.000000000 +0100
9192 + * Copyright (C) 2005-2009 Junjiro Okajima
9194 + * This program, aufs is free software; you can redistribute it and/or modify
9195 + * it under the terms of the GNU General Public License as published by
9196 + * the Free Software Foundation; either version 2 of the License, or
9197 + * (at your option) any later version.
9199 + * This program is distributed in the hope that it will be useful,
9200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9202 + * GNU General Public License for more details.
9204 + * You should have received a copy of the GNU General Public License
9205 + * along with this program; if not, write to the Free Software
9206 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9210 + * file and vm operations
9215 +#include <linux/fs_stack.h>
9216 +#include <linux/poll.h>
9219 +/* common function to regular file and dir */
9220 +int aufs_flush(struct file *file, fl_owner_t id)
9223 + struct dentry *dentry;
9224 + aufs_bindex_t bindex, bend;
9225 + struct file *h_file;
9227 + dentry = file->f_dentry;
9228 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
9230 + si_noflush_read_lock(dentry->d_sb);
9231 + fi_read_lock(file);
9232 + di_read_lock_child(dentry, AuLock_IW);
9235 + bend = au_fbend(file);
9236 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9237 + h_file = au_h_fptr(file, bindex);
9238 + if (h_file && h_file->f_op && h_file->f_op->flush) {
9239 + err = h_file->f_op->flush(h_file, id);
9241 + au_update_fuse_h_inode
9242 + (h_file->f_vfsmnt, h_file->f_dentry);
9246 + au_cpup_attr_timesizes(dentry->d_inode);
9248 + di_read_unlock(dentry, AuLock_IW);
9249 + fi_read_unlock(file);
9250 + si_read_unlock(dentry->d_sb);
9255 +/* ---------------------------------------------------------------------- */
9257 +static int do_open_nondir(struct file *file, int flags)
9260 + aufs_bindex_t bindex;
9261 + struct super_block *sb;
9262 + struct file *h_file;
9263 + struct dentry *dentry;
9264 + struct inode *inode;
9265 + struct au_finfo *finfo;
9267 + dentry = file->f_dentry;
9268 + LKTRTrace("%.*s, flags 0%o\n", AuDLNPair(dentry), flags);
9269 + FiMustWriteLock(file);
9270 + inode = dentry->d_inode;
9271 + AuDebugOn(!inode || S_ISDIR(inode->i_mode));
9274 + finfo = au_fi(file);
9275 + finfo->fi_h_vm_ops = NULL;
9276 + sb = dentry->d_sb;
9277 + bindex = au_dbstart(dentry);
9278 + AuDebugOn(!au_h_dptr(dentry, bindex)->d_inode);
9279 + /* O_TRUNC is processed already */
9280 + BUG_ON(au_test_ro(sb, bindex, inode) && (flags & O_TRUNC));
9282 + h_file = au_h_open(dentry, bindex, flags, file);
9283 + if (IS_ERR(h_file))
9284 + err = PTR_ERR(h_file);
9286 + au_set_fbstart(file, bindex);
9287 + au_set_fbend(file, bindex);
9288 + au_set_h_fptr(file, bindex, h_file);
9289 + au_update_figen(file);
9290 + /* todo: necessary? */
9291 + /* file->f_ra = h_file->f_ra; */
9298 +static int aufs_open_nondir(struct inode *inode, struct file *file)
9300 + LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(file->f_dentry));
9302 + return au_do_open(inode, file, do_open_nondir);
9305 +static int aufs_release_nondir(struct inode *inode, struct file *file)
9307 + struct super_block *sb = file->f_dentry->d_sb;
9309 + LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(file->f_dentry));
9311 + si_noflush_read_lock(sb);
9312 + au_finfo_fin(file);
9313 + si_read_unlock(sb);
9317 +/* ---------------------------------------------------------------------- */
9319 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
9323 + struct dentry *dentry;
9324 + struct file *h_file;
9325 + struct super_block *sb;
9326 + struct inode *h_inode;
9328 + dentry = file->f_dentry;
9329 + LKTRTrace("%.*s, cnt %zu, pos %lld\n", AuDLNPair(dentry), count, *ppos);
9331 + sb = dentry->d_sb;
9332 + si_read_lock(sb, AuLock_FLUSH);
9333 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0,
9335 + if (unlikely(err))
9338 + /* support LSM and notify */
9339 + h_file = au_h_fptr(file, au_fbstart(file));
9340 + h_inode = h_file->f_dentry->d_inode;
9341 + err = vfsub_read_u(h_file, buf, count, ppos,
9342 + au_test_dlgt(au_mntflags(sb)));
9343 + /* todo: necessary? */
9344 + /* file->f_ra = h_file->f_ra; */
9345 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
9347 + di_read_unlock(dentry, AuLock_IR);
9348 + fi_read_unlock(file);
9350 + si_read_unlock(sb);
9355 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
9356 + size_t count, loff_t *ppos)
9359 + struct dentry *dentry;
9360 + struct inode *inode;
9361 + struct super_block *sb;
9362 + unsigned int mnt_flags;
9363 + struct file *h_file;
9364 + char __user *buf = (char __user *)ubuf;
9365 + struct au_hin_ignore ign;
9366 + struct vfsub_args vargs;
9367 + aufs_bindex_t bstart;
9369 + struct au_pin pin;
9371 + dentry = file->f_dentry;
9372 + LKTRTrace("%.*s, cnt %zu, pos %lld\n", AuDLNPair(dentry), count, *ppos);
9374 + inode = dentry->d_inode;
9375 + mutex_lock(&inode->i_mutex);
9376 + sb = dentry->d_sb;
9377 + si_read_lock(sb, AuLock_FLUSH);
9378 + mnt_flags = au_mntflags(sb);
9379 + hinotify = !!au_opt_test(mnt_flags, UDBA_INOTIFY);
9380 + vfsub_args_init(&vargs, &ign, au_test_dlgt(mnt_flags), 0);
9382 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
9384 + if (unlikely(err))
9386 + err = au_ready_to_write(file, -1, &pin);
9387 + di_downgrade_lock(dentry, AuLock_IR);
9388 + if (unlikely(err))
9391 + bstart = au_fbstart(file);
9392 + h_file = au_h_fptr(file, bstart);
9395 + err = vfsub_write_u(h_file, buf, count, ppos, &vargs);
9397 + vfsub_ign_hinode(&vargs, IN_MODIFY, au_pinned_hdir(&pin));
9398 + err = vfsub_write_u(h_file, buf, count, ppos, &vargs);
9401 + au_cpup_attr_timesizes(inode);
9404 + di_read_unlock(dentry, AuLock_IR);
9405 + fi_write_unlock(file);
9407 + si_read_unlock(sb);
9408 + mutex_unlock(&inode->i_mutex);
9413 +#ifdef CONFIG_AUFS_SPLICE_PATCH
9414 +static int au_test_loopback(void)
9416 + const char c = current->comm[4];
9417 + /* true if a kernel thread named 'loop[0-9].*' accesses a file */
9418 + const int loopback = (current->mm == NULL
9419 + && '0' <= c && c <= '9'
9420 + && strncmp(current->comm, "loop", 4) == 0);
9424 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
9425 + struct pipe_inode_info *pipe, size_t len,
9426 + unsigned int flags)
9429 + struct file *h_file;
9430 + struct dentry *dentry;
9431 + struct super_block *sb;
9433 + dentry = file->f_dentry;
9434 + LKTRTrace("%.*s, pos %lld, len %zu\n", AuDLNPair(dentry), *ppos, len);
9436 + sb = dentry->d_sb;
9437 + si_read_lock(sb, AuLock_FLUSH);
9438 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0,
9440 + if (unlikely(err))
9444 + /* support LSM and notify */
9445 + h_file = au_h_fptr(file, au_fbstart(file));
9446 + if (au_test_loopback()) {
9447 + file->f_mapping = h_file->f_mapping;
9448 + smp_mb(); /* unnecessary? */
9450 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags,
9451 + au_test_dlgt(au_mntflags(sb)));
9452 + /* todo: necessasry? */
9453 + /* file->f_ra = h_file->f_ra; */
9454 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
9455 + di_read_unlock(dentry, AuLock_IR);
9456 + fi_read_unlock(file);
9459 + si_read_unlock(sb);
9465 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
9466 + size_t len, unsigned int flags)
9469 + struct dentry *dentry;
9470 + struct inode *inode, *h_inode;
9471 + struct super_block *sb;
9472 + struct file *h_file;
9473 + /* struct au_hin_ignore ign; */
9474 + struct vfsub_args vargs;
9475 + unsigned int mnt_flags;
9476 + struct au_pin pin;
9478 + dentry = file->f_dentry;
9479 + LKTRTrace("%.*s, len %zu, pos %lld\n", AuDLNPair(dentry), len, *ppos);
9481 + inode = dentry->d_inode;
9482 + mutex_lock(&inode->i_mutex);
9483 + sb = dentry->d_sb;
9484 + si_read_lock(sb, AuLock_FLUSH);
9485 + mnt_flags = au_mntflags(sb);
9486 + vfsub_args_init(&vargs, /*&ign*/NULL, au_test_dlgt(mnt_flags), 0);
9488 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
9490 + if (unlikely(err))
9492 + err = au_ready_to_write(file, -1, &pin);
9493 + di_downgrade_lock(dentry, AuLock_IR);
9494 + if (unlikely(err))
9497 + /* support LSM and notify */
9498 + /* current vfs_splice_from() doesn't fire up the inotify event */
9499 + h_file = au_h_fptr(file, au_fbstart(file));
9500 + h_inode = h_file->f_dentry->d_inode;
9501 + if (1 || !au_opt_test(mnt_flags, UDBA_INOTIFY)) {
9503 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags, &vargs);
9505 +#if 0 /* reserved for future use */
9507 + struct dentry *parent = dget_parent(dentry);
9508 + vfsub_ign_hinode(&vargs, IN_MODIFY, au_pinned_hdir(&pin));
9509 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags, &vargs);
9513 + au_cpup_attr_timesizes(inode);
9516 + di_read_unlock(dentry, AuLock_IR);
9517 + fi_write_unlock(file);
9519 + si_read_unlock(sb);
9520 + mutex_unlock(&inode->i_mutex);
9524 +#endif /* CONFIG_AUFS_SPLICE_PATCH */
9526 +/* ---------------------------------------------------------------------- */
9528 +static int aufs_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9531 + struct dentry *dentry;
9532 + struct file *file, *h_file;
9533 + struct inode *inode;
9534 + static DECLARE_WAIT_QUEUE_HEAD(wq);
9535 + struct au_finfo *finfo;
9538 + AuDebugOn(!vma || !vma->vm_file);
9539 + /* todo: non-robr mode, user vm_file as it is? */
9540 + wait_event(wq, (file = au_robr_safe_file(vma)));
9541 + AuDebugOn(!au_test_aufs(file->f_dentry->d_sb));
9542 + dentry = file->f_dentry;
9543 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
9544 + inode = dentry->d_inode;
9545 + AuDebugOn(!S_ISREG(inode->i_mode));
9547 + /* do not revalidate, no si lock */
9548 + finfo = au_fi(file);
9549 + h_file = finfo->fi_hfile[0 + finfo->fi_bstart].hf_file;
9550 + AuDebugOn(!h_file || !au_test_mmapped(file));
9551 + fi_write_lock(file);
9552 + vma->vm_file = h_file;
9553 + err = finfo->fi_h_vm_ops->fault(vma, vmf);
9554 + /* todo: necessary? */
9555 + /* file->f_ra = h_file->f_ra; */
9556 + au_robr_reset_file(vma, file);
9557 + fi_write_unlock(file);
9558 +#if 0 /* def CONFIG_SMP */
9559 + /* wake_up_nr(&wq, online_cpu - 1); */
9565 + if (!(err & VM_FAULT_ERROR)) {
9567 + struct page *page;
9569 + AuDbg("%p, %d\n", page, page_mapcount(page));
9571 + page->mapping = file->f_mapping;
9573 + file->f_mapping = h_file->f_mapping;
9574 + touch_atime(NULL, dentry);
9575 + inode->i_atime = h_file->f_dentry->d_inode->i_atime;
9582 +static struct vm_operations_struct aufs_vm_ops = {
9583 + .fault = aufs_fault,
9584 +#if 0 /* reserved for future use */
9585 + .open = aufs_vmaopen,
9586 + .close = aufs_vmaclose,
9587 + unsigned long (*nopfn)(struct vm_area_struct *area,
9588 + unsigned long address);
9589 + page_mkwrite(struct vm_area_struct *vma, struct page *page)
9593 +/* ---------------------------------------------------------------------- */
9595 +static struct vm_operations_struct *au_vm_ops(struct file *h_file,
9596 + struct vm_area_struct *vma)
9598 + struct vm_operations_struct *vm_ops;
9603 + au_br_nfs_lockdep_off(h_file->f_vfsmnt->mnt_sb);
9604 + err = h_file->f_op->mmap(h_file, vma);
9605 + au_br_nfs_lockdep_on(h_file->f_vfsmnt->mnt_sb);
9606 + vm_ops = ERR_PTR(err);
9607 + if (unlikely(err))
9609 + vm_ops = vma->vm_ops;
9610 + err = do_munmap(current->mm, vma->vm_start,
9611 + vma->vm_end - vma->vm_start);
9612 + if (unlikely(err)) {
9613 + AuIOErr("failed internal unmapping %.*s, %d\n",
9614 + AuDLNPair(h_file->f_dentry), err);
9615 + vm_ops = ERR_PTR(-EIO);
9619 + AuTraceErrPtr(vm_ops);
9623 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
9626 + unsigned char wlock, mmapped;
9627 + struct dentry *dentry;
9628 + struct super_block *sb;
9629 + struct file *h_file;
9630 + struct vm_operations_struct *vm_ops;
9632 + dentry = file->f_dentry;
9633 + LKTRTrace("%.*s, %lx, len %lu\n",
9634 + AuDLNPair(dentry), vma->vm_start,
9635 + vma->vm_end - vma->vm_start);
9636 + AuDebugOn(!S_ISREG(dentry->d_inode->i_mode));
9637 + AuDebugOn(down_write_trylock(&vma->vm_mm->mmap_sem));
9639 + mmapped = au_test_mmapped(file); /* can be harmless race condition */
9640 + wlock = !!(file->f_mode & FMODE_WRITE);
9641 + sb = dentry->d_sb;
9642 + si_read_lock(sb, AuLock_FLUSH);
9643 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, wlock | !mmapped,
9645 + if (unlikely(err))
9649 + struct au_pin pin;
9651 + err = au_ready_to_write(file, -1, &pin);
9652 + di_downgrade_lock(dentry, AuLock_IR);
9653 + if (unlikely(err))
9656 + } else if (!mmapped)
9657 + di_downgrade_lock(dentry, AuLock_IR);
9659 + h_file = au_h_fptr(file, au_fbstart(file));
9660 + if (au_test_fuse(h_file->f_dentry->d_sb)) {
9662 + * by this assignment, f_mapping will differs from aufs inode
9664 + * if someone else mixes the use of f_dentry->d_inode and
9665 + * f_mapping->host, then a problem may arise.
9667 + file->f_mapping = h_file->f_mapping;
9670 + if (0 && h_file->f_op->mmap == generic_file_mmap) {
9671 + err = generic_file_mmap(file, vma); /* instead of h_file */
9672 + if (unlikely(err))
9674 + au_fi(file)->fi_h_vm_ops = vma->vm_ops;
9678 + vm_ops = au_vm_ops(h_file, vma);
9679 + err = PTR_ERR(vm_ops);
9680 + if (IS_ERR(vm_ops))
9684 + err = generic_file_mmap(file, vma);
9685 + if (unlikely(err))
9687 + vma->vm_ops = &aufs_vm_ops;
9689 + if (!au_test_mmapped(file)) {
9690 + FiMustWriteLock(file);
9691 + au_fi(file)->fi_h_vm_ops = vm_ops;
9695 + file_accessed(h_file);
9696 + au_update_fuse_h_inode(h_file->f_vfsmnt, h_file->f_dentry); /*ignore*/
9697 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
9700 + di_read_unlock(dentry, AuLock_IR);
9701 + if (!wlock && mmapped)
9702 + fi_read_unlock(file);
9704 + fi_write_unlock(file);
9706 + si_read_unlock(sb);
9711 +/* ---------------------------------------------------------------------- */
9713 +static unsigned int aufs_poll(struct file *file, poll_table *wait)
9715 + unsigned int mask;
9716 + struct file *h_file;
9718 + struct dentry *dentry;
9719 + struct super_block *sb;
9721 + dentry = file->f_dentry;
9722 + LKTRTrace("%.*s, wait %p\n", AuDLNPair(dentry), wait);
9723 + AuDebugOn(S_ISDIR(dentry->d_inode->i_mode));
9725 + /* We should pretend an error happened. */
9726 + mask = POLLERR /* | POLLIN | POLLOUT */;
9727 + sb = dentry->d_sb;
9728 + si_read_lock(sb, AuLock_FLUSH);
9729 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0,
9731 + if (unlikely(err))
9734 + /* it is not an error of hidden_file has no operation */
9735 + mask = DEFAULT_POLLMASK;
9736 + h_file = au_h_fptr(file, au_fbstart(file));
9737 + if (h_file->f_op && h_file->f_op->poll)
9738 + mask = h_file->f_op->poll(h_file, wait);
9739 + di_read_unlock(dentry, AuLock_IR);
9740 + fi_read_unlock(file);
9743 + si_read_unlock(sb);
9744 + AuTraceErr((int)mask);
9748 +static int aufs_fsync_nondir(struct file *file, struct dentry *dentry,
9752 + struct inode *inode;
9753 + struct file *h_file;
9754 + struct super_block *sb;
9755 + struct au_pin pin;
9757 + LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), datasync);
9758 + inode = dentry->d_inode;
9760 + IMustLock(file->f_mapping->host);
9761 + if (inode != file->f_mapping->host) {
9762 + mutex_unlock(&file->f_mapping->host->i_mutex);
9763 + mutex_lock(&inode->i_mutex);
9767 + sb = dentry->d_sb;
9768 + si_read_lock(sb, AuLock_FLUSH);
9769 + err = 0; /* -EBADF; */ /* posix? */
9770 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
9772 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
9774 + if (unlikely(err))
9776 + err = au_ready_to_write(file, -1, &pin);
9777 + di_downgrade_lock(dentry, AuLock_IR);
9778 + if (unlikely(err))
9783 + h_file = au_h_fptr(file, au_fbstart(file));
9784 + if (h_file->f_op && h_file->f_op->fsync) {
9785 + struct mutex *h_mtx = &h_file->f_dentry->d_inode->i_mutex;
9787 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
9788 + err = h_file->f_op->fsync(h_file, h_file->f_dentry, datasync);
9790 + au_update_fuse_h_inode(h_file->f_vfsmnt,
9791 + h_file->f_dentry);
9792 + au_cpup_attr_timesizes(inode);
9793 + mutex_unlock(h_mtx);
9797 + di_read_unlock(dentry, AuLock_IR);
9798 + fi_write_unlock(file);
9800 + si_read_unlock(sb);
9801 + if (inode != file->f_mapping->host) {
9802 + mutex_unlock(&inode->i_mutex);
9803 + mutex_lock(&file->f_mapping->host->i_mutex);
9809 +static int aufs_fasync(int fd, struct file *file, int flag)
9812 + struct file *h_file;
9813 + struct dentry *dentry;
9814 + struct super_block *sb;
9816 + dentry = file->f_dentry;
9817 + LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), flag);
9819 + sb = dentry->d_sb;
9820 + si_read_lock(sb, AuLock_FLUSH);
9821 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0,
9823 + if (unlikely(err))
9826 + h_file = au_h_fptr(file, au_fbstart(file));
9827 + if (h_file->f_op && h_file->f_op->fasync)
9828 + err = h_file->f_op->fasync(fd, h_file, flag);
9829 + di_read_unlock(dentry, AuLock_IR);
9830 + fi_read_unlock(file);
9833 + si_read_unlock(sb);
9838 +/* ---------------------------------------------------------------------- */
9840 +struct file_operations aufs_file_fop = {
9842 + * while generic_file_llseek/_unlocked() don't use BKL,
9843 + * don't use it since it operates file->f_mapping->host.
9844 + * in aufs, it may be a real file and may confuse users by UDBA.
9846 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
9847 + /* .llseek = generic_file_llseek, */
9849 + .read = aufs_read,
9850 + .write = aufs_write,
9851 + .poll = aufs_poll,
9852 + /* .unlocked_ioctl = aufs_ioctl, */
9853 + .mmap = aufs_mmap,
9854 + .open = aufs_open_nondir,
9855 + .flush = aufs_flush,
9856 + .release = aufs_release_nondir,
9857 + .fsync = aufs_fsync_nondir,
9858 + .fasync = aufs_fasync,
9859 +#ifdef CONFIG_AUFS_SPLICE_PATCH
9860 + .splice_write = aufs_splice_write,
9861 + .splice_read = aufs_splice_read,
9864 diff -urN linux/fs/aufs/getattr.c linux-aufs/fs/aufs/getattr.c
9865 --- linux/fs/aufs/getattr.c 1970-01-01 01:00:00.000000000 +0100
9866 +++ linux-aufs/fs/aufs/getattr.c 2009-03-12 16:18:04.000000000 +0100
9869 + * Copyright (C) 2005-2009 Junjiro Okajima
9871 + * This program, aufs is free software; you can redistribute it and/or modify
9872 + * it under the terms of the GNU General Public License as published by
9873 + * the Free Software Foundation; either version 2 of the License, or
9874 + * (at your option) any later version.
9876 + * This program is distributed in the hope that it will be useful,
9877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9879 + * GNU General Public License for more details.
9881 + * You should have received a copy of the GNU General Public License
9882 + * along with this program; if not, write to the Free Software
9883 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9887 + * inode attributes on NFS/FUSE branch or HINOTIFY
9894 +static struct dentry *
9895 +au_h_dget_any(struct dentry *dentry, aufs_bindex_t *bindex)
9897 + struct dentry *h_dentry;
9898 + struct inode *inode, *h_inode;
9899 + struct super_block *sb;
9900 + aufs_bindex_t ib, db;
9902 + /* must be positive dentry */
9903 + inode = dentry->d_inode;
9904 + LKTRTrace("%.*s, i%lu\n", AuDLNPair(dentry), inode->i_ino);
9906 + sb = dentry->d_sb;
9907 + db = au_dbstart(dentry);
9908 + ib = au_ibstart(inode);
9911 + h_dentry = dget(au_h_dptr(dentry, db));
9913 + goto out; /* success */
9917 + h_inode = au_h_iptr(inode, ib);
9918 + h_dentry = d_find_alias(h_inode);
9920 + goto out; /* success */
9923 + if (au_opt_test(au_mntflags(sb), PLINK)
9924 + && au_plink_test(sb, inode)) {
9925 + h_dentry = au_plink_lkup(sb, ib, inode);
9926 + if (IS_ERR(h_dentry))
9928 + AuDebugOn(!h_dentry->d_inode);
9929 + goto out; /* success */
9933 + h_dentry = dget(au_hi_wh(inode, ib));
9936 + AuTraceErrPtr(h_dentry);
9940 +int aufs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st)
9943 + unsigned int mnt_flags;
9944 + aufs_bindex_t bindex;
9945 + unsigned char did_lock;
9946 + struct inode *inode;
9947 + struct dentry *h_dentry;
9948 + struct super_block *sb, *h_sb;
9950 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
9953 + sb = dentry->d_sb;
9954 + si_read_lock(sb, AuLock_FLUSH);
9955 + mnt_flags = au_mntflags(sb);
9956 + if (dentry != sb->s_root) {
9957 + di_read_lock_parent(dentry, AuLock_IR);
9958 + inode = dentry->d_inode;
9961 + /* todo: test bit inotify option too? */
9962 + bindex = au_ibstart(inode);
9963 + h_sb = au_sbr_sb(sb, bindex);
9964 + /* todo: fix this condition */
9965 + if ((au_opt_test(mnt_flags, PLINK) && au_plink_test(sb, inode))
9966 + /* au_iigen(inode) == au_sigen(sb) */
9967 + || (!au_test_fuse(h_sb) && !au_test_nfs(h_sb)))
9970 + h_dentry = au_h_dget_any(dentry, &bindex);
9971 + err = PTR_ERR(h_dentry);
9972 + if (IS_ERR(h_dentry))
9975 + /* lock free root dinfo */
9978 + inode = dentry->d_inode;
9979 + h_dentry = dget(au_di(dentry)->di_hdentry->hd_dentry);
9983 + if (h_dentry && h_dentry->d_inode)
9984 + err = vfsub_getattr(au_sbr_mnt(sb, bindex), h_dentry, st,
9985 + au_test_dlgt(mnt_flags));
9988 + /* todo: I don't like this approach */
9989 + au_cpup_attr_all(inode, /*force*/0);
9991 + generic_fillattr(inode, st);
9996 + di_read_unlock(dentry, AuLock_IR);
9997 + si_read_unlock(sb);
10001 diff -urN linux/fs/aufs/hinode.h linux-aufs/fs/aufs/hinode.h
10002 --- linux/fs/aufs/hinode.h 1970-01-01 01:00:00.000000000 +0100
10003 +++ linux-aufs/fs/aufs/hinode.h 2009-03-12 16:18:04.000000000 +0100
10006 + * Copyright (C) 2005-2009 Junjiro Okajima
10008 + * This program, aufs is free software; you can redistribute it and/or modify
10009 + * it under the terms of the GNU General Public License as published by
10010 + * the Free Software Foundation; either version 2 of the License, or
10011 + * (at your option) any later version.
10013 + * This program is distributed in the hope that it will be useful,
10014 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10015 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10016 + * GNU General Public License for more details.
10018 + * You should have received a copy of the GNU General Public License
10019 + * along with this program; if not, write to the Free Software
10020 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10024 + * lower (branch filesystem) inode and setting inotify
10029 +#ifndef __AUFS_HINODE_H__
10030 +#define __AUFS_HINODE_H__
10034 +#include <linux/fs.h>
10035 +#include <linux/inotify.h>
10036 +#include <linux/aufs_type.h>
10037 +#include "super.h"
10038 +#include "vfsub.h"
10040 +/* ---------------------------------------------------------------------- */
10042 +struct au_hinotify {
10043 +#ifdef CONFIG_AUFS_HINOTIFY
10044 + struct au_splhead hin_ignore;
10045 + struct inotify_watch hin_watch;
10046 + struct inode *hin_aufs_inode; /* no get/put */
10050 +struct au_hinode {
10051 + struct inode *hi_inode;
10052 + aufs_bindex_t hi_id;
10053 +#ifdef CONFIG_AUFS_HINOTIFY
10054 + struct au_hinotify *hi_notify;
10057 + /* reference to the copied-up whiteout with get/put */
10058 + struct dentry *hi_whdentry;
10061 +struct au_hin_ignore {
10062 +#ifdef CONFIG_AUFS_HINOTIFY
10063 + struct list_head ign_list;
10066 + __u32 ign_events, ign_handled;
10067 + struct au_hinode *ign_hinode;
10071 +/* ---------------------------------------------------------------------- */
10073 +#ifdef CONFIG_AUFS_HINOTIFY
10074 +/* inotify events */
10075 +static const __u32 AuInMask = (IN_MOVE | IN_DELETE | IN_CREATE
10076 + /* | IN_ACCESS */
10077 + | IN_MODIFY | IN_ATTRIB
10078 + /* | IN_DELETE_SELF | IN_MOVE_SELF */
10082 +void au_hin_init(struct au_hinode *hinode, struct au_hinotify *val)
10084 + hinode->hi_notify = val;
10088 +int au_hin_alloc(struct au_hinode *hinode, struct inode *inode,
10089 + struct inode *h_inode);
10090 +void au_hin_free(struct au_hinode *hinode);
10091 +void au_hin_ctl(struct au_hinode *hinode, const __u32 mask);
10092 +void au_reset_hinotify(struct inode *inode, unsigned int flags);
10094 +int au_hin_verify_gen(struct dentry *dentry);
10096 +int __init au_inotify_init(void);
10097 +void au_inotify_fin(void);
10099 +static inline void au_hin_suspend(struct au_hinode *hinode)
10101 + au_hin_ctl(hinode, 0);
10104 +static inline void au_hin_resume(struct au_hinode *hinode)
10106 + au_hin_ctl(hinode, AuInMask);
10112 +void au_hin_init(struct au_hinode *hinode, struct au_hinotify *val)
10118 +int au_hin_alloc(struct au_hinode *hinode, struct inode *inode,
10119 + struct inode *h_inode)
10121 + return -EOPNOTSUPP;
10124 +static inline void au_hin_free(struct au_hinode *hinode)
10129 +static inline void au_reset_hinotify(struct inode *inode, unsigned int flags)
10134 +static inline int au_hin_verify_gen(struct dentry *dentry)
10139 +static inline int au_inotify_init(void)
10144 +#define au_inotify_fin() do {} while (0)
10146 +static inline void au_hin_suspend(struct au_hinode *hinode)
10151 +static inline void au_hin_resume(struct au_hinode *hinode)
10155 +#endif /* CONFIG_AUFS_HINOTIFY */
10157 +#if defined(CONFIG_AUFS_HINOTIFY) && defined(CONFIG_AUFS_DEBUG)
10158 +static inline void au_hin_list_del(struct list_head *e)
10160 + list_del_init(e);
10163 +void au_dbg_hin_list(struct vfsub_args *vargs);
10165 +static inline void au_hin_list_del(struct list_head *e)
10170 +static inline void au_dbg_hin_list(struct vfsub_args *vargs)
10174 +#endif /* CONFIG_AUFS_DEBUG */
10176 +/* ---------------------------------------------------------------------- */
10178 +#endif /* __KERNEL__ */
10179 +#endif /* __AUFS_HINODE_H__ */
10180 diff -urN linux/fs/aufs/hin_or_dlgt.c linux-aufs/fs/aufs/hin_or_dlgt.c
10181 --- linux/fs/aufs/hin_or_dlgt.c 1970-01-01 01:00:00.000000000 +0100
10182 +++ linux-aufs/fs/aufs/hin_or_dlgt.c 2009-03-12 16:18:04.000000000 +0100
10185 + * Copyright (C) 2005-2009 Junjiro Okajima
10187 + * This program, aufs is free software; you can redistribute it and/or modify
10188 + * it under the terms of the GNU General Public License as published by
10189 + * the Free Software Foundation; either version 2 of the License, or
10190 + * (at your option) any later version.
10192 + * This program is distributed in the hope that it will be useful,
10193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10195 + * GNU General Public License for more details.
10197 + * You should have received a copy of the GNU General Public License
10198 + * along with this program; if not, write to the Free Software
10199 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10203 + * sub-routines for vfs in hinotify or dlgt mode
10208 +#include <linux/uaccess.h>
10211 +#if !defined(CONFIG_AUFS_HINOTIFY) && !defined(CONFIG_AUFS_DLGT)
10212 +#error mis-configuraion or Makefile
10215 +/* ---------------------------------------------------------------------- */
10217 +struct permission_args {
10219 + struct inode *inode;
10221 + struct nameidata *nd;
10224 +static void call_permission(void *args)
10226 + struct permission_args *a = args;
10227 + *a->errp = do_vfsub_permission(a->inode, a->mask, a->nd);
10230 +int vfsub_permission(struct inode *inode, int mask, struct nameidata *nd,
10234 + return do_vfsub_permission(inode, mask, nd);
10236 + int err, wkq_err;
10237 + struct permission_args args = {
10243 + wkq_err = au_wkq_wait(call_permission, &args, /*dlgt*/1);
10244 + if (unlikely(wkq_err))
10250 +/* ---------------------------------------------------------------------- */
10252 +struct create_args {
10254 + struct inode *dir;
10255 + struct dentry *dentry;
10257 + struct nameidata *nd;
10258 + struct vfsub_args *vargs;
10261 +static void call_create(void *args)
10263 + struct create_args *a = args;
10264 + vfsub_ignore(a->vargs);
10265 + *a->errp = do_vfsub_create(a->dir, a->dentry, a->mode, a->nd);
10266 + if (unlikely(*a->errp))
10267 + vfsub_unignore(a->vargs);
10268 + au_dbg_hin_list(a->vargs);
10271 +int vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
10272 + struct nameidata *nd, struct vfsub_args *vargs)
10275 + struct create_args args = {
10278 + .dentry = dentry,
10284 + if (!vfsub_ftest(vargs->flags, DLGT))
10285 + call_create(&args);
10288 + wkq_err = au_wkq_wait(call_create, &args, /*dlgt*/1);
10289 + if (unlikely(wkq_err))
10295 +struct symlink_args {
10297 + struct inode *dir;
10298 + struct dentry *dentry;
10299 + const char *symname;
10301 + struct vfsub_args *vargs;
10304 +static void call_symlink(void *args)
10306 + struct symlink_args *a = args;
10307 + vfsub_ignore(a->vargs);
10308 + *a->errp = do_vfsub_symlink(a->dir, a->dentry, a->symname, a->mode);
10309 + if (unlikely(*a->errp))
10310 + vfsub_unignore(a->vargs);
10311 + au_dbg_hin_list(a->vargs);
10314 +int vfsub_symlink(struct inode *dir, struct dentry *dentry, const char *symname,
10315 + int mode, struct vfsub_args *vargs)
10318 + struct symlink_args args = {
10321 + .dentry = dentry,
10322 + .symname = symname,
10327 + if (!vfsub_ftest(vargs->flags, DLGT))
10328 + call_symlink(&args);
10331 + wkq_err = au_wkq_wait(call_symlink, &args, /*dlgt*/1);
10332 + if (unlikely(wkq_err))
10338 +struct mknod_args {
10340 + struct inode *dir;
10341 + struct dentry *dentry;
10344 + struct vfsub_args *vargs;
10347 +static void call_mknod(void *args)
10349 + struct mknod_args *a = args;
10350 + vfsub_ignore(a->vargs);
10351 + *a->errp = do_vfsub_mknod(a->dir, a->dentry, a->mode, a->dev);
10352 + if (unlikely(*a->errp))
10353 + vfsub_unignore(a->vargs);
10354 + au_dbg_hin_list(a->vargs);
10357 +int vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev,
10358 + struct vfsub_args *vargs)
10361 + struct mknod_args args = {
10364 + .dentry = dentry,
10370 + if (!vfsub_ftest(vargs->flags, DLGT))
10371 + call_mknod(&args);
10374 + wkq_err = au_wkq_wait(call_mknod, &args, /*dlgt*/1);
10375 + if (unlikely(wkq_err))
10381 +struct mkdir_args {
10383 + struct inode *dir;
10384 + struct dentry *dentry;
10386 + struct vfsub_args *vargs;
10389 +static void call_mkdir(void *args)
10391 + struct mkdir_args *a = args;
10392 + vfsub_ignore(a->vargs);
10393 + *a->errp = do_vfsub_mkdir(a->dir, a->dentry, a->mode);
10394 + if (unlikely(*a->errp))
10395 + vfsub_unignore(a->vargs);
10396 + au_dbg_hin_list(a->vargs);
10399 +int vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode,
10400 + struct vfsub_args *vargs)
10403 + struct mkdir_args args = {
10406 + .dentry = dentry,
10411 + if (!vfsub_ftest(vargs->flags, DLGT))
10412 + call_mkdir(&args);
10415 + wkq_err = au_wkq_wait(call_mkdir, &args, /*dlgt*/1);
10416 + if (unlikely(wkq_err))
10422 +/* ---------------------------------------------------------------------- */
10424 +struct link_args {
10426 + struct inode *dir;
10427 + struct dentry *src_dentry, *dentry;
10428 + struct vfsub_args *vargs;
10431 +static void call_link(void *args)
10433 + struct link_args *a = args;
10434 + vfsub_ignore(a->vargs);
10435 + *a->errp = do_vfsub_link(a->src_dentry, a->dir, a->dentry);
10436 + if (unlikely(*a->errp))
10437 + vfsub_unignore(a->vargs);
10438 + au_dbg_hin_list(a->vargs);
10441 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
10442 + struct dentry *dentry, struct vfsub_args *vargs)
10445 + struct link_args args = {
10447 + .src_dentry = src_dentry,
10449 + .dentry = dentry,
10453 + if (!vfsub_ftest(vargs->flags, DLGT))
10454 + call_link(&args);
10457 + wkq_err = au_wkq_wait(call_link, &args, /*dlgt*/1);
10458 + if (unlikely(wkq_err))
10464 +struct rename_args {
10466 + struct inode *src_dir, *dir;
10467 + struct dentry *src_dentry, *dentry;
10468 + struct vfsub_args *vargs;
10471 +static void call_rename(void *args)
10473 + struct rename_args *a = args;
10474 + vfsub_ignore(a->vargs);
10475 + *a->errp = do_vfsub_rename(a->src_dir, a->src_dentry, a->dir,
10477 + if (unlikely(*a->errp))
10478 + vfsub_unignore(a->vargs);
10479 + au_dbg_hin_list(a->vargs);
10482 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
10483 + struct inode *dir, struct dentry *dentry,
10484 + struct vfsub_args *vargs)
10487 + struct rename_args args = {
10489 + .src_dir = src_dir,
10490 + .src_dentry = src_dentry,
10492 + .dentry = dentry,
10496 + if (!vfsub_ftest(vargs->flags, DLGT))
10497 + call_rename(&args);
10500 + wkq_err = au_wkq_wait(call_rename, &args, /*dlgt*/1);
10501 + if (unlikely(wkq_err))
10507 +struct rmdir_args {
10509 + struct inode *dir;
10510 + struct dentry *dentry;
10511 + struct vfsub_args *vargs;
10514 +static void call_rmdir(void *args)
10516 + struct rmdir_args *a = args;
10517 + vfsub_ignore(a->vargs);
10518 + *a->errp = do_vfsub_rmdir(a->dir, a->dentry);
10519 + if (unlikely(*a->errp))
10520 + vfsub_unignore(a->vargs);
10521 + au_dbg_hin_list(a->vargs);
10524 +int vfsub_rmdir(struct inode *dir, struct dentry *dentry,
10525 + struct vfsub_args *vargs)
10528 + struct rmdir_args args = {
10531 + .dentry = dentry,
10535 + if (!vfsub_ftest(vargs->flags, DLGT))
10536 + call_rmdir(&args);
10539 + wkq_err = au_wkq_wait(call_rmdir, &args, /*dlgt*/1);
10540 + if (unlikely(wkq_err))
10546 +/* ---------------------------------------------------------------------- */
10548 +struct read_args {
10550 + struct file *file;
10553 + char __user *ubuf;
10559 +static void call_read_k(void *args)
10561 + struct read_args *a = args;
10562 + LKTRTrace("%.*s, cnt %zu, pos %lld\n",
10563 + AuDLNPair(a->file->f_dentry), a->count, *a->ppos);
10564 + *a->errp = do_vfsub_read_k(a->file, a->kbuf, a->count, a->ppos);
10567 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
10568 + loff_t *ppos, int dlgt)
10571 + return do_vfsub_read_u(file, ubuf, count, ppos);
10574 + ssize_t err, read;
10575 + struct read_args args = {
10586 + * workaround an application bug.
10587 + * generally, read(2) or write(2) may return the value shorter
10588 + * than requested. But many applications don't support it,
10589 + * for example bash.
10592 + if (args.count > PAGE_SIZE)
10593 + args.count = PAGE_SIZE;
10594 + args.kbuf = kmalloc(args.count, GFP_NOFS);
10595 + if (unlikely(!args.kbuf))
10600 + wkq_err = au_wkq_wait(call_read_k, &args, /*dlgt*/1);
10601 + if (unlikely(wkq_err))
10603 + if (unlikely(err > 0
10604 + && copy_to_user(ubuf, args.kbuf, err))) {
10609 + else if (unlikely(err < 0))
10612 + /* do not read too much because of file i/o pointer */
10613 + if (count < args.count)
10614 + args.count = count;
10618 + smp_mb(); /* flush ubuf */
10622 + kfree(args.kbuf);
10628 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
10632 + return do_vfsub_read_k(file, kbuf, count, ppos);
10636 + struct read_args args = {
10642 + args.kbuf = kbuf;
10643 + wkq_err = au_wkq_wait(call_read_k, &args, /*dlgt*/1);
10644 + if (unlikely(wkq_err))
10650 +struct write_args {
10652 + struct file *file;
10655 + const char __user *ubuf;
10659 + struct vfsub_args *vargs;
10662 +static void call_write_k(void *args)
10664 + struct write_args *a = args;
10665 + vfsub_ignore(a->vargs);
10666 + *a->errp = do_vfsub_write_k(a->file, a->kbuf, a->count, a->ppos);
10667 + if (unlikely(*a->errp <= 0))
10668 + vfsub_unignore(a->vargs);
10669 + au_dbg_hin_list(a->vargs);
10672 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
10673 + loff_t *ppos, struct vfsub_args *vargs)
10677 + if (!vfsub_ftest(vargs->flags, DLGT)) {
10678 + vfsub_ignore(vargs);
10679 + err = do_vfsub_write_u(file, ubuf, count, ppos);
10680 + if (unlikely(err <= 0))
10681 + vfsub_unignore(vargs);
10682 + au_dbg_hin_list(vargs);
10686 + struct write_args args = {
10698 + * workaround an application bug.
10699 + * generally, read(2) or write(2) may return the value shorter
10700 + * than requested. But many applications don't support it,
10701 + * for example bash.
10704 + if (args.count > PAGE_SIZE)
10705 + args.count = PAGE_SIZE;
10706 + args.kbuf = kmalloc(args.count, GFP_NOFS);
10707 + if (unlikely(!args.kbuf))
10712 + if (unlikely(copy_from_user(args.kbuf, ubuf,
10718 + wkq_err = au_wkq_wait(call_write_k, &args, /*dlgt*/1);
10719 + if (unlikely(wkq_err))
10723 + if (count < args.count)
10724 + args.count = count;
10729 + else if (unlikely(err < 0))
10735 + kfree(args.kbuf);
10741 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
10742 + struct vfsub_args *vargs)
10745 + struct write_args args = {
10753 + args.kbuf = kbuf;
10754 + if (!vfsub_ftest(vargs->flags, DLGT))
10755 + call_write_k(&args);
10758 + wkq_err = au_wkq_wait(call_write_k, &args, /*dlgt*/1);
10759 + if (unlikely(wkq_err))
10765 +struct readdir_args {
10767 + struct file *file;
10768 + filldir_t filldir;
10772 +static void call_readdir(void *args)
10774 + struct readdir_args *a = args;
10775 + *a->errp = do_vfsub_readdir(a->file, a->filldir, a->arg);
10778 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg, int dlgt)
10781 + return do_vfsub_readdir(file, filldir, arg);
10783 + int err, wkq_err;
10784 + struct readdir_args args = {
10787 + .filldir = filldir,
10790 + wkq_err = au_wkq_wait(call_readdir, &args, /*dlgt*/1);
10791 + if (unlikely(wkq_err))
10797 +/* ---------------------------------------------------------------------- */
10799 +struct splice_to_args {
10803 + struct pipe_inode_info *pipe;
10805 + unsigned int flags;
10808 +static void call_splice_to(void *args)
10810 + struct splice_to_args *a = args;
10811 + *a->errp = do_vfsub_splice_to(a->in, a->ppos, a->pipe, a->len,
10815 +long vfsub_splice_to(struct file *in, loff_t *ppos,
10816 + struct pipe_inode_info *pipe, size_t len,
10817 + unsigned int flags, int dlgt)
10820 + return do_vfsub_splice_to(in, ppos, pipe, len, flags);
10824 + struct splice_to_args args = {
10832 + wkq_err = au_wkq_wait(call_splice_to, &args, /*dlgt*/1);
10833 + if (unlikely(wkq_err))
10839 +struct splice_from_args {
10841 + struct pipe_inode_info *pipe;
10842 + struct file *out;
10845 + unsigned int flags;
10846 + struct vfsub_args *vargs;
10849 +static void call_splice_from(void *args)
10851 + struct splice_from_args *a = args;
10852 + vfsub_ignore(a->vargs);
10853 + *a->errp = do_vfsub_splice_from(a->pipe, a->out, a->ppos, a->len,
10855 + if (unlikely(*a->errp < 0))
10856 + vfsub_unignore(a->vargs);
10857 + au_dbg_hin_list(a->vargs);
10860 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
10861 + loff_t *ppos, size_t len, unsigned int flags,
10862 + struct vfsub_args *vargs)
10865 + struct splice_from_args args = {
10875 + if (!vfsub_ftest(vargs->flags, DLGT))
10876 + call_splice_from(&args);
10879 + wkq_err = au_wkq_wait(call_splice_from, &args, /*dlgt*/1);
10880 + if (unlikely(wkq_err))
10886 +/* ---------------------------------------------------------------------- */
10888 +struct getattr_args {
10890 + struct vfsmount *mnt;
10891 + struct dentry *dentry;
10892 + struct kstat *st;
10895 +static void call_getattr(void *args)
10897 + struct getattr_args *a = args;
10898 + *a->errp = do_vfsub_getattr(a->mnt, a->dentry, a->st);
10901 +int vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st,
10905 + return do_vfsub_getattr(mnt, dentry, st);
10907 + int err, wkq_err;
10908 + struct getattr_args args = {
10911 + .dentry = dentry,
10914 + wkq_err = au_wkq_wait(call_getattr, &args, /*dlgt*/1);
10915 + if (unlikely(wkq_err))
10920 diff -urN linux/fs/aufs/hinotify.c linux-aufs/fs/aufs/hinotify.c
10921 --- linux/fs/aufs/hinotify.c 1970-01-01 01:00:00.000000000 +0100
10922 +++ linux-aufs/fs/aufs/hinotify.c 2009-03-12 16:18:04.000000000 +0100
10925 + * Copyright (C) 2005-2009 Junjiro Okajima
10927 + * This program, aufs is free software; you can redistribute it and/or modify
10928 + * it under the terms of the GNU General Public License as published by
10929 + * the Free Software Foundation; either version 2 of the License, or
10930 + * (at your option) any later version.
10932 + * This program is distributed in the hope that it will be useful,
10933 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10934 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10935 + * GNU General Public License for more details.
10937 + * You should have received a copy of the GNU General Public License
10938 + * along with this program; if not, write to the Free Software
10939 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10943 + * internal/hidden inotify handler
10952 +#define AuDbgHin(args...) AuDbg(##args)
10954 +#define AuDbgHin(args...) do {} while ()
10958 +static struct inotify_handle *in_handle;
10960 +AuCacheFuncs(hinotify, AuCache_HINOTIFY);
10962 +int au_hin_alloc(struct au_hinode *hinode, struct inode *inode,
10963 + struct inode *h_inode)
10966 + struct au_hinotify *hin;
10969 + LKTRTrace("i%lu, hi%lu\n", inode->i_ino, h_inode->i_ino);
10972 + hin = au_cache_alloc_hinotify();
10974 + AuDebugOn(hinode->hi_notify);
10975 + hinode->hi_notify = hin;
10976 + au_spl_init(&hin->hin_ignore);
10977 + hin->hin_aufs_inode = inode;
10979 + inotify_init_watch(&hin->hin_watch);
10980 + wd = inotify_add_watch(in_handle, &hin->hin_watch, h_inode,
10983 + return 0; /* success */
10986 + put_inotify_watch(&hin->hin_watch);
10987 + au_cache_free_hinotify(hin);
10988 + hinode->hi_notify = NULL;
10995 +void au_hin_free(struct au_hinode *hinode)
10998 + struct au_hinotify *hin;
11002 + hin = hinode->hi_notify;
11005 + if (atomic_read(&hin->hin_watch.count))
11006 + err = inotify_rm_watch(in_handle, &hin->hin_watch);
11007 + if (unlikely(err))
11008 + /* it means the watch is already removed */
11009 + LKTRTrace("failed inotify_rm_watch() %d\n", err);
11010 + au_cache_free_hinotify(hin);
11011 + hinode->hi_notify = NULL;
11015 +/* ---------------------------------------------------------------------- */
11017 +void au_hin_ctl(struct au_hinode *hinode, const __u32 mask)
11019 + struct inode *h_inode;
11020 + struct inotify_watch *watch;
11022 + h_inode = hinode->hi_inode;
11023 + LKTRTrace("hi%lu, sb %p, 0x%x\n", h_inode->i_ino, h_inode->i_sb, mask);
11024 + IMustLock(h_inode);
11025 + if (!hinode->hi_notify)
11028 + watch = &hinode->hi_notify->hin_watch;
11029 +#if 0 /* reserved for future use */
11032 + wd = inotify_find_update_watch(in_handle, h_inode, mask);
11034 + /* ignore an err; */
11037 + /* struct inotify_handle is hidden */
11038 + mutex_lock(&h_inode->inotify_mutex);
11039 + /* mutex_lock(&watch->ih->mutex); */
11040 + watch->mask = mask;
11041 + /* mutex_unlock(&watch->ih->mutex); */
11042 + mutex_unlock(&h_inode->inotify_mutex);
11044 + LKTRTrace("watch %p, mask %u\n", watch, watch->mask);
11047 +void au_reset_hinotify(struct inode *inode, unsigned int flags)
11049 + aufs_bindex_t bindex, bend;
11050 + struct inode *hi;
11051 + struct dentry *iwhdentry;
11053 + LKTRTrace("i%lu, 0x%x\n", inode->i_ino, flags);
11055 + bend = au_ibend(inode);
11056 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
11057 + hi = au_h_iptr(inode, bindex);
11059 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
11060 + iwhdentry = au_hi_wh(inode, bindex);
11064 + au_set_h_iptr(inode, bindex, NULL, 0);
11065 + au_set_h_iptr(inode, bindex, au_igrab(hi),
11066 + flags & ~AuHi_XINO);
11069 + /* mutex_unlock(&hi->i_mutex); */
11074 +/* ---------------------------------------------------------------------- */
11076 +void au_unpin_gp(struct au_pin *args)
11078 + struct au_pin1 *gp;
11080 + gp = au_pin_gp(args);
11083 + LKTRTrace("%.*s\n", AuDLNPair(gp->dentry));
11087 + au_do_unpin(gp, NULL);
11090 +int au_hin_verify_gen(struct dentry *dentry)
11092 + struct super_block *sb = dentry->d_sb;
11094 + struct inode *inode;
11096 + if (!au_opt_test(au_mntflags(sb), UDBA_INOTIFY))
11099 + sigen = au_sigen(dentry->d_sb);
11100 + inode = dentry->d_inode;
11101 + return au_digen(dentry) != sigen
11102 + || (inode && au_iigen(inode) != sigen);
11105 +/* ---------------------------------------------------------------------- */
11107 +/* cf. fsnotify_change() */
11108 +__u32 vfsub_events_notify_change(struct iattr *ia)
11111 + const unsigned int amtime = (ATTR_ATIME | ATTR_MTIME);
11114 + if ((ia->ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
11115 + || (ia->ia_valid & amtime) == amtime)
11116 + events |= IN_ATTRIB;
11117 + if ((ia->ia_valid & ATTR_SIZE)
11118 + || (ia->ia_valid & amtime) == ATTR_MTIME)
11119 + events |= IN_MODIFY;
11123 +void vfsub_ign_hinode(struct vfsub_args *vargs, __u32 events,
11124 + struct au_hinode *hinode)
11126 + struct au_hinotify *hin;
11127 + struct super_block *sb;
11128 + struct au_hin_ignore *ign;
11133 + hin = hinode->hi_notify;
11134 + if (!hin || !hin->hin_watch.mask)
11137 + sb = hin->hin_aufs_inode->i_sb;
11138 + AuDebugOn(!au_opt_test(au_mntflags(sb), UDBA_INOTIFY));
11140 + ign = vargs->ignore + vargs->nignore++;
11141 + ign->ign_events = events;
11142 + ign->ign_handled = 0;
11143 + ign->ign_hinode = hinode;
11146 + struct inode *h_inode;
11147 + h_inode = hinode->hi_inode;
11148 + if (!mutex_is_locked(&h_inode->i_mutex))
11149 + au_dbg_blocked();
11150 + IMustLock(h_inode);
11154 +static void au_hin_ignore(struct au_hin_ignore *ign)
11156 + struct au_hinode *hinode;
11158 + struct au_hinotify *hin;
11159 + struct inode *h_inode;
11161 + hinode = ign->ign_hinode;
11162 + events = ign->ign_events;
11163 + LKTRTrace("0x%x\n", events);
11164 + AuDebugOn(!hinode || !events);
11166 + hin = hinode->hi_notify;
11167 + h_inode = hinode->hi_inode;
11168 + if (h_inode && hin) {
11169 + LKTRTrace("hi%lu\n", h_inode->i_ino);
11171 + AuDbg("hi%lu, 0x%x\n", h_inode->i_ino, events);
11174 + au_spl_add(&ign->ign_list, &hin->hin_ignore);
11175 + /* AuDbg("list_add %p, 0x%x\n", ign, events); */
11177 +#if 1 /* todo: test dlgt */
11180 + * it may happen by this scenario.
11181 + * - a file and its parent dir exist on two branches
11182 + * - a file on the upper branch is opened
11183 + * - the parent dir and the file are removed by udba
11184 + * - the parent is re-accessed, and new dentry/inode in
11185 + * aufs is generated for it, based upon the one on the lower
11187 + * - the opened file is re-accessed, re-validated, and it may be
11188 + * re-connected to the new parent dentry
11189 + * it means the file in aufs cannot get the actual removed
11190 + * parent dir on the branch.
11192 + INIT_LIST_HEAD(&ign->ign_list);
11196 +static void au_hin_unignore(struct au_hin_ignore *ign)
11198 + struct au_hinode *hinode;
11200 + struct au_hinotify *hin;
11201 + struct inode *h_inode;
11203 + hinode = ign->ign_hinode;
11204 + events = ign->ign_events;
11205 + LKTRTrace("0x%x\n", events);
11206 + /* AuDbg("0x%x\n", events); */
11207 + AuDebugOn(!hinode || !events);
11209 + hin = hinode->hi_notify;
11210 + h_inode = hinode->hi_inode;
11211 + if (!h_inode || !hin)
11213 + LKTRTrace("hi%lu\n", h_inode->i_ino);
11215 + AuDbg("hi%lu, 0x%x\n", h_inode->i_ino, events);
11218 + spin_lock(&hin->hin_ignore.spin);
11219 + au_hin_list_del(&ign->ign_list);
11220 + spin_unlock(&hin->hin_ignore.spin);
11221 + /* AuDbg("list_del %p, 0x%x\n", ign, events); */
11224 +static int au_hin_test_ignore(u32 mask, struct au_hinotify *hin)
11228 + struct au_hin_ignore *ign, *tmp;
11229 + struct list_head *head;
11232 + head = &hin->hin_ignore.head;
11233 + spin_lock(&hin->hin_ignore.spin);
11234 + list_for_each_entry_safe(ign, tmp, head, ign_list) {
11235 + /* AuDbg("ign %p\n", ign); */
11236 + if (ign->ign_pid == current->pid) {
11237 + events = (mask & ign->ign_events);
11240 + ign->ign_handled |= events;
11241 + if (ign->ign_events == ign->ign_handled) {
11242 + list_del_init(&ign->ign_list);
11244 + AuDbg("list_del %p, 0x%x\n",
11252 + spin_unlock(&hin->hin_ignore.spin);
11254 + return do_ignore;
11257 +void vfsub_ignore(struct vfsub_args *vargs)
11260 + struct au_hin_ignore *ign;
11261 + struct super_block *sb;
11262 + struct au_hinode *hinode;
11263 + struct inode *h_inode;
11265 + n = vargs->nignore;
11269 + ign = vargs->ignore;
11270 + hinode = ign->ign_hinode;
11271 + sb = hinode->hi_notify->hin_aufs_inode->i_sb;
11272 + h_inode = hinode->hi_inode;
11273 + if (au_opt_test(au_mntflags(sb), UDBA_INOTIFY)) {
11274 + if (!mutex_is_locked(&h_inode->i_mutex))
11275 + au_dbg_blocked();
11276 + IMustLock(h_inode);
11278 + while (n-- > 0) {
11279 + ign->ign_pid = current->pid;
11280 + au_hin_ignore(ign++);
11284 +void vfsub_unignore(struct vfsub_args *vargs)
11287 + struct au_hin_ignore *ign;
11289 + n = vargs->nignore;
11293 + ign = vargs->ignore;
11295 + au_hin_unignore(ign++);
11298 +#ifdef CONFIG_AUFS_DEBUG
11299 +void au_dbg_hin_list(struct vfsub_args *vargs)
11302 + struct au_hin_ignore *ign;
11304 + n = vargs->nignore;
11308 + ign = vargs->ignore;
11309 + while (n-- > 0) {
11310 + /* AuDebugOn(!list_empty(&ign++->ign_list)); */
11311 + if (list_empty(&ign++->ign_list))
11314 + AuDbg("%d: pid %d, 0x%x\n",
11315 + n + 1, ign->ign_pid, ign->ign_events);
11316 + au_hin_unignore(ign);
11318 + au_dbg_blocked();
11323 +/* ---------------------------------------------------------------------- */
11325 +static char *in_name(u32 mask)
11327 +#ifdef CONFIG_AUFS_DEBUG
11328 +#define test_ret(flag) if (mask & flag) \
11330 + test_ret(IN_ACCESS);
11331 + test_ret(IN_MODIFY);
11332 + test_ret(IN_ATTRIB);
11333 + test_ret(IN_CLOSE_WRITE);
11334 + test_ret(IN_CLOSE_NOWRITE);
11335 + test_ret(IN_OPEN);
11336 + test_ret(IN_MOVED_FROM);
11337 + test_ret(IN_MOVED_TO);
11338 + test_ret(IN_CREATE);
11339 + test_ret(IN_DELETE);
11340 + test_ret(IN_DELETE_SELF);
11341 + test_ret(IN_MOVE_SELF);
11342 + test_ret(IN_UNMOUNT);
11343 + test_ret(IN_Q_OVERFLOW);
11344 + test_ret(IN_IGNORED);
11352 +/* ---------------------------------------------------------------------- */
11354 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
11355 + struct inode *dir)
11357 + struct dentry *dentry, *d, *parent;
11358 + struct qstr *dname;
11360 + LKTRTrace("%.*s, dir%lu\n", nlen, name, dir->i_ino);
11362 + parent = d_find_alias(dir);
11367 + spin_lock(&dcache_lock);
11368 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
11369 + LKTRTrace("%.*s\n", AuDLNPair(d));
11370 + dname = &d->d_name;
11371 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
11373 + if (!atomic_read(&d->d_count) || !d->d_fsdata) {
11374 + spin_lock(&d->d_lock);
11376 + spin_unlock(&d->d_lock);
11380 + dentry = dget(d);
11383 + spin_unlock(&dcache_lock);
11388 + lktr_set_pid(current->pid, LktrArrayPid);
11389 + AuDbgDentry(dentry);
11390 + lktr_clear_pid(current->pid, LktrArrayPid);
11392 + di_write_lock_child(dentry);
11397 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
11398 + aufs_bindex_t bindex, ino_t h_ino)
11400 + struct inode *inode;
11401 + struct au_xino_entry xinoe;
11404 + LKTRTrace("b%d, hi%lu\n", bindex, (unsigned long)h_ino);
11405 + AuDebugOn(!au_opt_test_xino(au_mntflags(sb)));
11408 + err = au_xino_read(sb, bindex, h_ino, &xinoe);
11409 + if (!err && xinoe.ino)
11410 + inode = ilookup(sb, xinoe.ino);
11413 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
11414 + AuWarn("wrong root branch\n");
11420 + ii_write_lock_child(inode);
11426 +static int hin_xino(struct inode *inode, struct inode *h_inode)
11429 + aufs_bindex_t bindex, bend, bfound, bstart;
11430 + struct inode *h_i;
11432 + LKTRTrace("i%lu, hi%lu\n", inode->i_ino, h_inode->i_ino);
11435 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
11436 + AuWarn("branch root dir was changed\n");
11441 + bend = au_ibend(inode);
11442 + bstart = au_ibstart(inode);
11443 +#if 0 /* reserved for future use */
11444 + if (bindex == bend) {
11445 + /* keep this ino in rename case */
11449 + for (bindex = bstart; bindex <= bend; bindex++) {
11450 + if (au_h_iptr(inode, bindex) == h_inode) {
11458 + for (bindex = bstart; bindex <= bend; bindex++) {
11459 + h_i = au_h_iptr(inode, bindex);
11461 + err = au_xino_write0(inode->i_sb, bindex, h_i->i_ino,
11463 + /* ignore this error */
11464 + /* bad action? */
11467 + /* children inode number will be broken */
11474 +static int hin_gen_tree(struct dentry *dentry)
11476 + int err, i, j, ndentry;
11477 + struct au_dcsub_pages dpages;
11478 + struct au_dpage *dpage;
11479 + struct dentry **dentries;
11481 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
11483 + err = au_dpages_init(&dpages, GFP_NOFS);
11484 + if (unlikely(err))
11486 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
11487 + if (unlikely(err))
11490 + for (i = 0; i < dpages.ndpage; i++) {
11491 + dpage = dpages.dpages + i;
11492 + dentries = dpage->dentries;
11493 + ndentry = dpage->ndentry;
11494 + for (j = 0; j < ndentry; j++) {
11495 + struct dentry *d;
11497 + LKTRTrace("%.*s\n", AuDLNPair(d));
11504 + /* todo: reset children xino?
11505 + cached children only? */
11506 + au_iigen_dec(d->d_inode);
11511 + au_dpages_free(&dpages);
11513 + /* discard children */
11514 + dentry_unhash(dentry);
11522 + * return 0 if processed.
11524 +static int hin_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
11525 + const unsigned int isdir)
11528 + struct dentry *d;
11529 + struct qstr *dname;
11531 + LKTRTrace("%.*s, i%lu\n", nlen, name, inode->i_ino);
11534 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
11535 + AuWarn("branch root dir was changed\n");
11541 + AuDebugOn(!name);
11542 + au_iigen_dec(inode);
11543 + spin_lock(&dcache_lock);
11544 + list_for_each_entry(d, &inode->i_dentry, d_alias) {
11545 + dname = &d->d_name;
11546 + if (dname->len != nlen
11547 + && memcmp(dname->name, name, nlen))
11550 + spin_lock(&d->d_lock);
11553 + spin_unlock(&d->d_lock);
11556 + spin_unlock(&dcache_lock);
11558 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIRS);
11559 + d = d_find_alias(inode);
11561 + au_iigen_dec(inode);
11565 + dname = &d->d_name;
11566 + if (dname->len == nlen && !memcmp(dname->name, name, nlen))
11567 + err = hin_gen_tree(d);
11576 +static int hin_gen_by_name(struct dentry *dentry, const unsigned int isdir)
11579 + struct inode *inode;
11581 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
11583 + inode = dentry->d_inode;
11584 + if (IS_ROOT(dentry)
11585 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
11587 + AuWarn("branch root dir was changed\n");
11594 + au_digen_dec(dentry);
11596 + au_iigen_dec(inode);
11598 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIRS);
11600 + err = hin_gen_tree(dentry);
11607 +static void hin_attr(struct inode *inode, struct inode *h_inode)
11609 + struct dentry *h_dentry;
11611 + LKTRTrace("i%lu, hi%lu\n", inode->i_ino, h_inode->i_ino);
11613 + if (au_h_iptr(inode, au_ibstart(inode)) != h_inode)
11616 + h_dentry = d_find_alias(h_inode);
11618 + au_update_fuse_h_inode(NULL, h_dentry);
11619 + /* ignore an error*/
11623 + au_cpup_attr_all(inode, /*force*/1);
11626 +/* ---------------------------------------------------------------------- */
11628 +/* hinotify job flags */
11629 +#define AuHinJob_XINO0 1
11630 +#define AuHinJob_GEN (1 << 1)
11631 +#define AuHinJob_DIRENT (1 << 2)
11632 +#define AuHinJob_ATTR (1 << 3)
11633 +#define AuHinJob_ISDIR (1 << 4)
11634 +#define AuHinJob_TRYXINO0 (1 << 5)
11635 +#define AuHinJob_MNTPNT (1 << 6)
11636 +#define au_ftest_hinjob(flags, name) ((flags) & AuHinJob_##name)
11637 +#define au_fset_hinjob(flags, name) { (flags) |= AuHinJob_##name; }
11638 +#define au_fclr_hinjob(flags, name) { (flags) &= ~AuHinJob_##name; }
11640 +struct hin_job_args {
11641 + unsigned int flags;
11642 + struct inode *inode, *h_inode, *dir, *h_dir;
11643 + struct dentry *dentry;
11648 +static int hin_job(struct hin_job_args *a)
11650 + const unsigned int isdir = au_ftest_hinjob(a->flags, ISDIR);
11653 + if (au_ftest_hinjob(a->flags, XINO0) && a->inode)
11654 + hin_xino(a->inode, a->h_inode);
11655 + /* ignore this error */
11657 + if (au_ftest_hinjob(a->flags, TRYXINO0)
11660 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
11661 + if (!a->h_inode->i_nlink)
11662 + hin_xino(a->inode, a->h_inode);
11663 + /* ignore this error */
11664 + mutex_unlock(&a->h_inode->i_mutex);
11667 + /* make the generation obsolete */
11668 + if (au_ftest_hinjob(a->flags, GEN)) {
11671 + err = hin_gen_by_inode(a->h_name, a->h_nlen, a->inode,
11673 + if (err && a->dentry)
11674 + hin_gen_by_name(a->dentry, isdir);
11675 + /* ignore this error */
11678 + /* make dir entries obsolete */
11679 + if (au_ftest_hinjob(a->flags, DIRENT) && a->inode) {
11680 + struct au_vdir *vdir;
11681 + IiMustWriteLock(a->inode);
11682 + vdir = au_ivdir(a->inode);
11684 + vdir->vd_jiffy = 0;
11685 + /* IMustLock(a->inode); */
11686 + /* a->inode->i_version++; */
11689 + /* update the attr */
11690 + if (au_ftest_hinjob(a->flags, ATTR) && a->inode && a->h_inode) {
11691 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
11692 + hin_attr(a->inode, a->h_inode);
11693 + mutex_unlock(&a->h_inode->i_mutex);
11696 + /* can do nothing but warn */
11697 + if (au_ftest_hinjob(a->flags, MNTPNT)
11699 + && d_mountpoint(a->dentry))
11700 + AuWarn("mount-point %.*s is removed or renamed\n",
11701 + AuDLNPair(a->dentry));
11706 +/* ---------------------------------------------------------------------- */
11708 +enum { CHILD, PARENT };
11709 +struct postproc_args {
11710 + struct inode *h_dir, *dir, *h_child_inode;
11712 + unsigned int flags[2];
11713 + unsigned int h_child_nlen;
11714 + char h_child_name[];
11717 +static void postproc(void *_args)
11719 + struct postproc_args *a = _args;
11720 + struct super_block *sb;
11721 + aufs_bindex_t bindex, bend, bfound;
11722 + unsigned char xino, try_iput;
11724 + struct inode *inode;
11726 + struct hin_job_args args;
11727 + struct dentry *dentry;
11728 + struct au_sbinfo *sbinfo;
11730 + AuDebugOn(!_args);
11731 + AuDebugOn(!a->h_dir);
11732 + AuDebugOn(!a->dir);
11733 + AuDebugOn(!a->mask);
11734 + LKTRTrace("mask 0x%x %s, i%lu, hi%lu, hci%lu\n",
11735 + a->mask, in_name(a->mask), a->dir->i_ino, a->h_dir->i_ino,
11736 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
11741 + * do not lock a->dir->i_mutex here
11742 + * because of d_revalidate() may cause a deadlock.
11746 + * just wait for the dir becoming non-busy.
11747 + * for instance, prevent NFSD lookup from "nlink == 0" message.
11748 + * but it is not guranteed.
11750 + mutex_lock(&a->dir->i_mutex);
11751 + mutex_unlock(&a->dir->i_mutex);
11754 + sb = a->dir->i_sb;
11756 + sbinfo = au_sbi(sb);
11757 + AuDebugOn(!sbinfo);
11758 + /* big aufs lock */
11759 + si_noflush_write_lock(sb);
11761 + ii_read_lock_parent(a->dir);
11763 + bend = au_ibend(a->dir);
11764 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
11765 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
11769 + ii_read_unlock(a->dir);
11770 + if (unlikely(bfound < 0))
11773 + xino = !!au_opt_test_xino(au_mntflags(sb));
11775 + if (a->h_child_inode)
11776 + h_ino = a->h_child_inode->i_ino;
11778 + if (a->h_child_nlen
11779 + && (au_ftest_hinjob(a->flags[CHILD], GEN)
11780 + || au_ftest_hinjob(a->flags[CHILD], MNTPNT)))
11781 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
11785 + inode = dentry->d_inode;
11786 + if (xino && !inode && h_ino
11787 + && (au_ftest_hinjob(a->flags[CHILD], XINO0)
11788 + || au_ftest_hinjob(a->flags[CHILD], TRYXINO0)
11789 + || au_ftest_hinjob(a->flags[CHILD], GEN)
11790 + || au_ftest_hinjob(a->flags[CHILD], ATTR))) {
11791 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
11795 + args.flags = a->flags[CHILD];
11796 + args.dentry = dentry;
11797 + args.inode = inode;
11798 + args.h_inode = a->h_child_inode;
11799 + args.dir = a->dir;
11800 + args.h_dir = a->h_dir;
11801 + args.h_name = a->h_child_name;
11802 + args.h_nlen = a->h_child_nlen;
11803 + err = hin_job(&args);
11805 + if (dentry->d_fsdata)
11806 + di_write_unlock(dentry);
11809 + if (inode && try_iput) {
11810 + ii_write_unlock(inode);
11814 + ii_write_lock_parent(a->dir);
11815 + args.flags = a->flags[PARENT];
11816 + args.dentry = NULL;
11817 + args.inode = a->dir;
11818 + args.h_inode = a->h_dir;
11820 + args.h_dir = NULL;
11821 + args.h_name = NULL;
11823 + err = hin_job(&args);
11824 + ii_write_unlock(a->dir);
11827 + au_nwt_done(&sbinfo->si_nowait);
11828 + si_write_unlock(sb);
11830 + iput(a->h_child_inode);
11836 +static void aufs_inotify(struct inotify_watch *watch, u32 wd, u32 mask,
11837 + u32 cookie, const char *h_child_name,
11838 + struct inode *h_child_inode)
11840 + struct au_hinotify *hinotify;
11841 + struct postproc_args *args;
11842 + int len, wkq_err;
11843 + unsigned char isdir, isroot, wh;
11845 + struct inode *dir;
11846 + unsigned int flags[2];
11848 + LKTRTrace("i%lu, wd %d, mask 0x%x %s, cookie 0x%x, hcname %s, hi%lu\n",
11849 + watch->inode->i_ino, wd, mask, in_name(mask), cookie,
11850 + h_child_name ? h_child_name : "",
11851 + h_child_inode ? h_child_inode->i_ino : 0);
11853 + /* if IN_UNMOUNT happens, there must be another bug */
11854 + if (mask & (IN_IGNORED | IN_UNMOUNT)) {
11855 + put_inotify_watch(watch);
11860 + if (!h_child_name || strcmp(h_child_name, AUFS_XINO_FNAME))
11861 + AuDbg("i%lu, wd %d, mask 0x%x %s, cookie 0x%x, hcname %s,"
11863 + watch->inode->i_ino, wd, mask, in_name(mask), cookie,
11864 + h_child_name ? h_child_name : "",
11865 + h_child_inode ? h_child_inode->i_ino : 0);
11868 + hinotify = container_of(watch, struct au_hinotify, hin_watch);
11869 + AuDebugOn(!hinotify || !hinotify->hin_aufs_inode);
11870 + if (au_hin_test_ignore(mask, hinotify)) {
11872 + AuDbg("ignored\n");
11876 +#if 0 /* tmp debug */
11877 + if (h_child_name && !strcmp(h_child_name, AUFS_XINO_FNAME)) {
11878 + AuDbg("i%lu, wd %d, mask 0x%x %s, cookie 0x%x, hcname %s, hi%lu\n",
11879 + watch->inode->i_ino, wd, mask, in_name(mask), cookie,
11880 + h_child_name ? h_child_name : "",
11881 + h_child_inode ? h_child_inode->i_ino : 0);
11882 + //au_dbg_blocked();
11886 + dir = igrab(hinotify->hin_aufs_inode);
11889 + isroot = (dir->i_ino == AUFS_ROOT_INO);
11892 + if (h_child_name) {
11893 + len = strlen(h_child_name);
11894 + if (!memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
11895 + h_child_name += AUFS_WH_PFX_LEN;
11896 + len -= AUFS_WH_PFX_LEN;
11902 + if (h_child_inode)
11903 + isdir = !!S_ISDIR(h_child_inode->i_mode);
11904 + flags[PARENT] = AuHinJob_ISDIR;
11905 + flags[CHILD] = 0;
11907 + flags[CHILD] = AuHinJob_ISDIR;
11908 + switch (mask & IN_ALL_EVENTS) {
11912 + if (h_child_inode) {
11914 + au_fset_hinjob(flags[CHILD], ATTR);
11916 + au_fset_hinjob(flags[PARENT], ATTR);
11919 + /* IN_MOVED_FROM is the first event in rename(2) */
11920 + case IN_MOVED_FROM:
11921 + case IN_MOVED_TO:
11922 + AuDebugOn(!h_child_name || !h_child_inode);
11923 + au_fset_hinjob(flags[CHILD], GEN);
11924 + au_fset_hinjob(flags[CHILD], ATTR);
11926 + au_fset_hinjob(flags[CHILD], XINO0);
11927 + au_fset_hinjob(flags[CHILD], MNTPNT);
11929 + au_fset_hinjob(flags[PARENT], ATTR);
11930 + au_fset_hinjob(flags[PARENT], DIRENT);
11934 + AuDebugOn(!h_child_name || !h_child_inode);
11935 + au_fset_hinjob(flags[PARENT], ATTR);
11936 + au_fset_hinjob(flags[PARENT], DIRENT);
11937 + au_fset_hinjob(flags[CHILD], GEN);
11939 + if (!isdir && h_child_inode->i_nlink > 1)
11940 + au_fset_hinjob(flags[CHILD], ATTR);
11945 + * aufs never be able to get this child inode.
11946 + * revalidation should be in d_revalidate()
11947 + * by checking i_nlink, i_generation or d_unhashed().
11949 + AuDebugOn(!h_child_name);
11950 + au_fset_hinjob(flags[PARENT], ATTR);
11951 + au_fset_hinjob(flags[PARENT], DIRENT);
11952 + au_fset_hinjob(flags[CHILD], GEN);
11953 + au_fset_hinjob(flags[CHILD], TRYXINO0);
11954 + au_fset_hinjob(flags[CHILD], MNTPNT);
11957 + case IN_DELETE_SELF:
11960 + au_fset_hinjob(flags[PARENT], GEN);
11964 + case IN_MOVE_SELF:
11967 + * when an inotify is set to an aufs inode,
11968 + * such inode can be isolated and this event can be fired
11971 + AuDebugOn(h_child_name || h_child_inode);
11972 + if (unlikely(isroot)) {
11973 + AuWarn("root branch was moved\n");
11977 + au_fset_hinjob(flags[PARENT], XINO0);
11978 + au_fset_hinjob(flags[PARENT], GEN);
11979 + au_fset_hinjob(flags[PARENT], ATTR);
11980 + au_fset_hinjob(flags[PARENT], DIRENT);
11981 + /* au_fset_hinjob(flags[PARENT], MNTPNT); */
11991 + h_child_inode = NULL;
11993 + /* iput() and kfree() will be called in postproc() */
11995 + * inotify_mutex is already acquired and kmalloc/prune_icache may lock
11996 + * iprune_mutex. strange.
11999 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
12001 + if (unlikely(!args)) {
12002 + AuErr1("no memory\n");
12006 + args->flags[PARENT] = flags[PARENT];
12007 + args->flags[CHILD] = flags[CHILD];
12008 + args->mask = mask;
12010 + args->h_dir = igrab(watch->inode);
12011 + if (h_child_inode)
12012 + h_child_inode = igrab(h_child_inode); /* can be NULL */
12013 + args->h_child_inode = h_child_inode;
12014 + args->h_child_nlen = len;
12016 + p = (void *)args;
12017 + p += sizeof(*args);
12018 + memcpy(p, h_child_name, len + 1);
12022 + wkq_err = au_wkq_nowait(postproc, args, dir->i_sb, /*dlgt*/0);
12024 + if (unlikely(wkq_err))
12025 + AuErr("wkq %d\n", wkq_err);
12028 +static void aufs_inotify_destroy(struct inotify_watch *watch)
12033 +static struct inotify_operations aufs_inotify_ops = {
12034 + .handle_event = aufs_inotify,
12035 + .destroy_watch = aufs_inotify_destroy
12038 +/* ---------------------------------------------------------------------- */
12040 +static void au_hin_destroy_cache(void)
12042 + kmem_cache_destroy(au_cachep[AuCache_HINOTIFY]);
12043 + au_cachep[AuCache_HINOTIFY] = NULL;
12046 +int __init au_inotify_init(void)
12051 + au_cachep[AuCache_HINOTIFY] = AuCache(au_hinotify);
12052 + if (au_cachep[AuCache_HINOTIFY]) {
12054 + in_handle = inotify_init(&aufs_inotify_ops);
12055 + if (IS_ERR(in_handle)) {
12056 + err = PTR_ERR(in_handle);
12057 + au_hin_destroy_cache();
12064 +void au_inotify_fin(void)
12066 + inotify_destroy(in_handle);
12067 + if (au_cachep[AuCache_HINOTIFY])
12068 + au_hin_destroy_cache();
12070 diff -urN linux/fs/aufs/iinfo.c linux-aufs/fs/aufs/iinfo.c
12071 --- linux/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
12072 +++ linux-aufs/fs/aufs/iinfo.c 2009-03-12 16:18:04.000000000 +0100
12075 + * Copyright (C) 2005-2009 Junjiro Okajima
12077 + * This program, aufs is free software; you can redistribute it and/or modify
12078 + * it under the terms of the GNU General Public License as published by
12079 + * the Free Software Foundation; either version 2 of the License, or
12080 + * (at your option) any later version.
12082 + * This program is distributed in the hope that it will be useful,
12083 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12084 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12085 + * GNU General Public License for more details.
12087 + * You should have received a copy of the GNU General Public License
12088 + * along with this program; if not, write to the Free Software
12089 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12093 + * inode private data
12100 +struct au_iinfo *au_ii(struct inode *inode)
12102 + struct au_iinfo *iinfo;
12104 + iinfo = &(container_of(inode, struct aufs_icntnr, vfs_inode)->iinfo);
12105 + /* bad_inode case */
12106 + if (unlikely(!iinfo->ii_hinode))
12108 + AuDebugOn(!iinfo->ii_hinode
12109 + /* || au_sbi(inode->i_sb)->si_bend < iinfo->ii_bend */
12110 + || iinfo->ii_bend < iinfo->ii_bstart);
12114 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
12116 + struct inode *hidden_inode;
12118 + /* lock free root dinfo/inode */
12119 + if (inode->i_ino != AUFS_ROOT_INO) {
12120 + IiMustAnyLock(inode);
12121 + AuDebugOn(bindex < 0 || au_ibend(inode) < bindex);
12123 + SiMustAnyLock(inode->i_sb);
12124 + AuDebugOn(bindex < 0 || au_sbend(inode->i_sb) < bindex);
12126 + hidden_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
12127 + AuDebugOn(hidden_inode && atomic_read(&hidden_inode->i_count) <= 0);
12128 + return hidden_inode;
12131 +aufs_bindex_t au_ii_br_id(struct inode *inode, aufs_bindex_t bindex)
12133 + IiMustAnyLock(inode);
12134 + AuDebugOn(bindex < 0
12135 + || au_ibend(inode) < bindex
12136 + || !au_ii(inode)->ii_hinode[0 + bindex].hi_inode);
12137 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
12140 +/* todo: hard/soft set? */
12141 +void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
12143 + struct au_iinfo *iinfo = au_ii(inode);
12144 + struct inode *h_inode;
12146 + IiMustWriteLock(inode);
12147 + AuDebugOn(au_sbend(inode->i_sb) < bindex);
12148 + iinfo->ii_bstart = bindex;
12149 + h_inode = iinfo->ii_hinode[bindex + 0].hi_inode;
12151 + au_cpup_igen(inode, h_inode);
12154 +unsigned int au_hi_flags(struct inode *inode, int isdir)
12156 + unsigned int flags;
12157 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
12160 + if (au_opt_test_xino(mnt_flags))
12161 + au_fset_hi(flags, XINO);
12162 + if (isdir && au_opt_test(mnt_flags, UDBA_INOTIFY))
12163 + au_fset_hi(flags, NOTIFY);
12167 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
12168 + struct inode *h_inode, unsigned int flags)
12170 + struct au_hinode *hinode;
12171 + struct inode *hi;
12172 + struct au_iinfo *iinfo = au_ii(inode);
12174 + LKTRTrace("i%lu, b%d, hi%lu, flags 0x%x\n",
12175 + inode->i_ino, bindex, h_inode ? h_inode->i_ino : 0, flags);
12176 + IiMustWriteLock(inode);
12177 + hinode = iinfo->ii_hinode + bindex;
12178 + hi = hinode->hi_inode;
12179 + AuDebugOn(bindex < au_ibstart(inode) || au_ibend(inode) < bindex);
12180 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
12181 + AuDebugOn(h_inode && hi);
12184 + au_hiput(hinode);
12185 + hinode->hi_inode = h_inode;
12188 + struct super_block *sb = inode->i_sb;
12190 + if (bindex == iinfo->ii_bstart)
12191 + au_cpup_igen(inode, h_inode);
12192 + hinode->hi_id = au_sbr_id(sb, bindex);
12193 + if (au_ftest_hi(flags, XINO)) {
12194 + struct au_xino_entry xinoe = {
12195 + .ino = inode->i_ino,
12196 + /* .h_gen = h_inode->i_generation */
12198 + err = au_xino_write(sb, bindex, h_inode->i_ino, &xinoe);
12199 + if (unlikely(err))
12200 + AuIOErr1("failed au_xino_write() %d\n", err);
12203 + if (au_ftest_hi(flags, NOTIFY)
12204 + && au_br_hinotifyable(au_sbr_perm(sb, bindex))) {
12205 + err = au_hin_alloc(hinode, inode, h_inode);
12206 + if (unlikely(err))
12207 + AuIOErr1("au_hin_alloc() %d\n", err);
12212 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
12213 + struct dentry *h_wh)
12215 + struct au_hinode *hinode;
12217 + IiMustWriteLock(inode);
12218 + hinode = au_ii(inode)->ii_hinode + bindex;
12219 + AuDebugOn(hinode->hi_whdentry);
12220 + hinode->hi_whdentry = h_wh;
12223 +void au_update_iigen(struct inode *inode)
12225 + AuDebugOn(!inode->i_sb);
12226 + atomic_set(&au_ii(inode)->ii_generation, au_sigen(inode->i_sb));
12227 + /* smp_mb(); */ /* atomic_set */
12230 +/* it may be called at remount time, too */
12231 +void au_update_brange(struct inode *inode, int do_put_zero)
12233 + struct au_iinfo *iinfo;
12235 + LKTRTrace("i%lu, %d\n", inode->i_ino, do_put_zero);
12236 + IiMustWriteLock(inode);
12238 + iinfo = au_ii(inode);
12239 + if (!iinfo || iinfo->ii_bstart < 0)
12242 + if (do_put_zero) {
12243 + aufs_bindex_t bindex;
12244 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
12246 + struct inode *h_i;
12247 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
12248 + if (h_i && !h_i->i_nlink)
12249 + au_set_h_iptr(inode, bindex, NULL, 0);
12253 + iinfo->ii_bstart = -1;
12254 + while (++iinfo->ii_bstart <= iinfo->ii_bend)
12255 + if (iinfo->ii_hinode[0 + iinfo->ii_bstart].hi_inode)
12257 + if (iinfo->ii_bstart > iinfo->ii_bend) {
12258 + iinfo->ii_bstart = -1;
12259 + iinfo->ii_bend = -1;
12263 + iinfo->ii_bend++;
12264 + while (0 <= --iinfo->ii_bend)
12265 + if (iinfo->ii_hinode[0 + iinfo->ii_bend].hi_inode)
12267 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend || iinfo->ii_bend < 0);
12270 +/* ---------------------------------------------------------------------- */
12272 +int au_iinfo_init(struct inode *inode)
12274 + struct au_iinfo *iinfo;
12275 + struct super_block *sb;
12278 + sb = inode->i_sb;
12280 + iinfo = &(container_of(inode, struct aufs_icntnr, vfs_inode)->iinfo);
12281 + AuDebugOn(iinfo->ii_hinode);
12282 + nbr = au_sbend(sb) + 1;
12285 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
12286 + if (iinfo->ii_hinode) {
12287 + for (i = 0; i < nbr; i++)
12288 + iinfo->ii_hinode[i].hi_id = -1;
12289 + atomic_set(&iinfo->ii_generation, au_sigen(sb));
12290 + /* smp_mb(); */ /* atomic_set */
12291 + au_rw_init_nolock(&iinfo->ii_rwsem);
12292 + iinfo->ii_bstart = -1;
12293 + iinfo->ii_bend = -1;
12294 + iinfo->ii_vdir = NULL;
12300 +static int au_iinfo_write0(struct super_block *sb, struct au_hinode *hinode,
12304 + aufs_bindex_t bindex;
12307 + locked = si_noflush_read_trylock(sb); /* crucio! */
12308 + bindex = au_br_index(sb, hinode->hi_id);
12310 + err = au_xino_write0(sb, bindex, hinode->hi_inode->i_ino, ino);
12311 + /* error action? */
12313 + si_read_unlock(sb);
12317 +void au_iinfo_fin(struct inode *inode)
12319 + struct au_iinfo *iinfo;
12320 + aufs_bindex_t bend;
12321 + unsigned char unlinked;
12322 + struct au_hinode *hi;
12323 + struct super_block *sb;
12326 + iinfo = au_ii(inode);
12327 + /* bad_inode case */
12331 + if (iinfo->ii_vdir)
12332 + au_vdir_free(iinfo->ii_vdir);
12334 + if (iinfo->ii_bstart >= 0) {
12335 + sb = inode->i_sb;
12336 + unlinked = !inode->i_nlink;
12339 + ino = inode->i_ino;
12340 + hi = iinfo->ii_hinode + iinfo->ii_bstart;
12341 + bend = iinfo->ii_bend;
12342 + while (iinfo->ii_bstart++ <= bend) {
12343 + if (hi->hi_inode) {
12344 + if (unlinked || !hi->hi_inode->i_nlink) {
12345 + au_iinfo_write0(sb, hi, ino);
12346 + /* ignore this error */
12355 + kfree(iinfo->ii_hinode);
12356 + au_rwsem_destroy(&iinfo->ii_rwsem);
12358 diff -urN linux/fs/aufs/inode.c linux-aufs/fs/aufs/inode.c
12359 --- linux/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
12360 +++ linux-aufs/fs/aufs/inode.c 2009-03-12 16:18:04.000000000 +0100
12363 + * Copyright (C) 2005-2009 Junjiro Okajima
12365 + * This program, aufs is free software; you can redistribute it and/or modify
12366 + * it under the terms of the GNU General Public License as published by
12367 + * the Free Software Foundation; either version 2 of the License, or
12368 + * (at your option) any later version.
12370 + * This program is distributed in the hope that it will be useful,
12371 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12372 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12373 + * GNU General Public License for more details.
12375 + * You should have received a copy of the GNU General Public License
12376 + * along with this program; if not, write to the Free Software
12377 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12381 + * inode functions
12388 +int au_refresh_hinode_self(struct inode *inode)
12390 + int err, new_sz, update;
12391 + struct inode *first;
12392 + struct au_hinode *p, *q, tmp;
12393 + struct super_block *sb;
12394 + struct au_iinfo *iinfo;
12395 + aufs_bindex_t bindex, bend, new_bindex;
12397 + LKTRTrace("i%lu\n", inode->i_ino);
12398 + IiMustWriteLock(inode);
12402 + sb = inode->i_sb;
12403 + bend = au_sbend(sb);
12404 + new_sz = sizeof(*iinfo->ii_hinode) * (bend + 1);
12405 + iinfo = au_ii(inode);
12406 + p = au_kzrealloc(iinfo->ii_hinode, sizeof(*p) * (iinfo->ii_bend + 1),
12407 + new_sz, GFP_NOFS);
12408 + if (unlikely(!p))
12411 + iinfo->ii_hinode = p;
12412 + p = iinfo->ii_hinode + iinfo->ii_bstart;
12413 + first = p->hi_inode;
12415 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
12417 + if (!p->hi_inode)
12420 + new_bindex = au_br_index(sb, p->hi_id);
12421 + if (new_bindex == bindex)
12423 + if (new_bindex < 0) {
12426 + p->hi_inode = NULL;
12430 + if (new_bindex < iinfo->ii_bstart)
12431 + iinfo->ii_bstart = new_bindex;
12432 + if (iinfo->ii_bend < new_bindex)
12433 + iinfo->ii_bend = new_bindex;
12434 + /* swap two hidden inode, and loop again */
12435 + q = iinfo->ii_hinode + new_bindex;
12439 + if (tmp.hi_inode) {
12444 + au_update_brange(inode, /*do_put_zero*/0);
12446 + if (unlikely(err))
12449 + if (1 || first != au_h_iptr(inode, iinfo->ii_bstart))
12450 + au_cpup_attr_all(inode, /*force*/0);
12451 + if (update && S_ISDIR(inode->i_mode))
12452 + inode->i_version++;
12453 + au_update_iigen(inode);
12460 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
12463 + struct inode *first;
12464 + struct au_hinode *p;
12465 + struct super_block *sb;
12466 + struct au_iinfo *iinfo;
12467 + aufs_bindex_t bindex, bend;
12468 + unsigned char isdir;
12469 + unsigned int flags;
12471 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
12472 + IiMustWriteLock(inode);
12474 + err = au_refresh_hinode_self(inode);
12475 + if (unlikely(err))
12478 + sb = dentry->d_sb;
12479 + bend = au_sbend(sb);
12480 + iinfo = au_ii(inode);
12482 + p = iinfo->ii_hinode + iinfo->ii_bstart;
12483 + first = p->hi_inode;
12484 + isdir = S_ISDIR(inode->i_mode);
12485 + flags = au_hi_flags(inode, isdir);
12486 + bend = au_dbend(dentry);
12487 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
12488 + struct inode *hi;
12489 + struct dentry *hd;
12491 + hd = au_h_dptr(dentry, bindex);
12492 + if (!hd || !hd->d_inode)
12495 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
12496 + hi = au_h_iptr(inode, bindex);
12498 + if (hi == hd->d_inode)
12504 + if (bindex < iinfo->ii_bstart)
12505 + iinfo->ii_bstart = bindex;
12506 + if (iinfo->ii_bend < bindex)
12507 + iinfo->ii_bend = bindex;
12508 + au_set_h_iptr(inode, bindex, au_igrab(hd->d_inode), flags);
12511 + au_update_brange(inode, /*do_put_zero*/0);
12513 + if (unlikely(err))
12516 + if (1 || first != au_h_iptr(inode, iinfo->ii_bstart))
12517 + au_cpup_attr_all(inode, /*force*/0);
12518 + if (update && isdir)
12519 + inode->i_version++;
12520 + au_update_iigen(inode);
12527 +static int set_inode(struct inode *inode, struct dentry *dentry)
12530 + struct dentry *h_dentry;
12531 + struct inode *h_inode;
12533 + aufs_bindex_t bindex, bstart, btail;
12534 + unsigned char isdir;
12535 + struct au_iinfo *iinfo;
12536 + unsigned int flags;
12538 + LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(dentry));
12539 + AuDebugOn(!(inode->i_state & I_NEW));
12540 + IiMustWriteLock(inode);
12541 + bstart = au_dbstart(dentry);
12542 + h_dentry = au_h_dptr(dentry, bstart);
12543 + AuDebugOn(!h_dentry);
12544 + h_inode = h_dentry->d_inode;
12545 + AuDebugOn(!h_inode);
12549 + mode = h_inode->i_mode;
12550 + switch (mode & S_IFMT) {
12552 + btail = au_dbtail(dentry);
12553 + inode->i_op = &aufs_iop;
12554 + inode->i_fop = &aufs_file_fop;
12555 + inode->i_mapping->a_ops = &aufs_aop;
12559 + btail = au_dbtaildir(dentry);
12560 + inode->i_op = &aufs_dir_iop;
12561 + inode->i_fop = &aufs_dir_fop;
12564 + btail = au_dbtail(dentry);
12565 + inode->i_op = &aufs_symlink_iop;
12566 + /* inode->i_fop = &aufs_file_fop; */
12572 + btail = au_dbtail(dentry);
12573 + inode->i_op = &aufs_iop;
12574 + init_special_inode(inode, mode,
12575 + au_h_rdev(h_inode, /*h_mnt*/NULL, h_dentry));
12578 + AuIOErr("Unknown file type 0%o\n", mode);
12583 + /* do not set inotify for whiteouted dirs (SHWH mode) */
12584 + flags = au_hi_flags(inode, isdir);
12585 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
12586 + && au_ftest_hi(flags, NOTIFY)
12587 + && dentry->d_name.len > AUFS_WH_PFX_LEN
12588 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
12589 + au_fclr_hi(flags, NOTIFY);
12590 + iinfo = au_ii(inode);
12591 + iinfo->ii_bstart = bstart;
12592 + iinfo->ii_bend = btail;
12593 + for (bindex = bstart; bindex <= btail; bindex++) {
12594 + h_dentry = au_h_dptr(dentry, bindex);
12597 + AuDebugOn(!h_dentry->d_inode);
12598 + au_set_h_iptr(inode, bindex, au_igrab(h_dentry->d_inode),
12601 + au_cpup_attr_all(inode, /*force*/1);
12608 +/* successful returns with iinfo write_locked */
12609 +/* todo: return with unlocked? */
12610 +static int reval_inode(struct inode *inode, struct dentry *dentry, int *matched)
12613 + struct inode *h_inode, *h_dinode;
12614 + aufs_bindex_t bindex, bend;
12616 + LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(dentry));
12621 + * before this function, if aufs got any iinfo lock, it must be only
12622 + * one, the parent dir.
12623 + * it can happen by UDBA and the obsoleted inode number.
12626 + if (unlikely(inode->i_ino == parent_ino(dentry)))
12629 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
12630 + /* mutex_lock_nested(&inode->i_mutex, AuLsc_I_CHILD); */
12631 + ii_write_lock_new_child(inode);
12633 + if (unlikely(IS_DEADDIR(inode)))
12637 + bend = au_ibend(inode);
12638 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
12639 + h_inode = au_h_iptr(inode, bindex);
12640 + if (h_inode && h_inode == h_dinode) {
12641 + /* && (ibs != bstart
12642 + || !au_test_higen(inode, h_inode))); */
12645 + if (au_iigen(inode) != au_digen(dentry))
12646 + err = au_refresh_hinode(inode, dentry);
12652 + if (unlikely(err))
12653 + ii_write_unlock(inode);
12654 + /* mutex_unlock(&inode->i_mutex); */
12660 +/* successful returns with iinfo write_locked */
12661 +/* todo: return with unlocked? */
12662 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
12664 + struct inode *inode, *h_inode;
12665 + struct dentry *h_dentry;
12666 + struct super_block *sb;
12669 + aufs_bindex_t bstart;
12670 + struct au_xino_entry xinoe;
12672 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
12673 + sb = dentry->d_sb;
12674 + bstart = au_dbstart(dentry);
12675 + h_dentry = au_h_dptr(dentry, bstart);
12676 + AuDebugOn(!h_dentry);
12677 + h_inode = h_dentry->d_inode;
12678 + AuDebugOn(!h_inode);
12680 + h_ino = h_inode->i_ino;
12681 + err = au_xino_read(sb, bstart, h_ino, &xinoe);
12682 + inode = ERR_PTR(err);
12683 + if (unlikely(err))
12686 + if (!xinoe.ino) {
12687 + xinoe.ino = au_xino_new_ino(sb);
12688 + if (!xinoe.ino) {
12689 + inode = ERR_PTR(-EIO);
12694 + LKTRTrace("i%lu\n", (unsigned long)xinoe.ino);
12695 + inode = au_iget_locked(sb, xinoe.ino);
12696 + err = PTR_ERR(inode);
12697 + if (IS_ERR(inode))
12700 + LKTRTrace("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
12701 + if (inode->i_state & I_NEW) {
12702 + ii_write_lock_new_child(inode);
12703 + err = set_inode(inode, dentry);
12704 + unlock_new_inode(inode);
12706 + goto out; /* success */
12707 + iget_failed(inode);
12708 + ii_write_unlock(inode);
12710 + } else if (!must_new) {
12711 + AuDebugOn(inode->i_state & I_LOCK);
12712 + err = reval_inode(inode, dentry, &match);
12714 + goto out; /* success */
12719 + if (unlikely(au_test_unique_ino(h_dentry, h_ino)))
12720 + AuWarn1("Un-notified UDBA or repeatedly renamed dir,"
12721 + " b%d, %s, %.*s, hi%lu, i%lu.\n",
12722 + bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
12723 + (unsigned long)h_ino, (unsigned long)xinoe.ino);
12725 + err = au_xino_write0(sb, bstart, h_ino, 0);
12730 + /* force noxino? */
12734 + inode = ERR_PTR(err);
12736 + AuTraceErrPtr(inode);
12740 +/* ---------------------------------------------------------------------- */
12742 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
12743 + struct inode *inode)
12747 + err = au_br_rdonly(au_sbr(sb, bindex));
12749 + /* pseudo-link after flushed may out of bounds */
12752 + && au_ibstart(inode) <= bindex
12753 + && bindex <= au_ibend(inode)) {
12755 + * permission check is unnecessary since vfsub routine
12756 + * will be called later
12758 + struct inode *hi = au_h_iptr(inode, bindex);
12760 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
12767 +int au_test_h_perm(struct inode *h_inode, int mask, int dlgt)
12769 + if (!current_fsuid())
12771 + /* todo: fake nameidata? */
12772 + return vfsub_permission(h_inode, mask, NULL, dlgt);
12775 +int au_test_h_perm_sio(struct inode *h_inode, int mask, int dlgt)
12777 + if (au_test_nfs(h_inode->i_sb)
12778 + && (mask & MAY_WRITE)
12779 + && S_ISDIR(h_inode->i_mode))
12780 + mask |= MAY_READ; /* force permission check */
12781 + return au_test_h_perm(h_inode, mask, dlgt);
12783 diff -urN linux/fs/aufs/inode.h linux-aufs/fs/aufs/inode.h
12784 --- linux/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
12785 +++ linux-aufs/fs/aufs/inode.h 2009-03-12 16:18:04.000000000 +0100
12788 + * Copyright (C) 2005-2009 Junjiro Okajima
12790 + * This program, aufs is free software; you can redistribute it and/or modify
12791 + * it under the terms of the GNU General Public License as published by
12792 + * the Free Software Foundation; either version 2 of the License, or
12793 + * (at your option) any later version.
12795 + * This program is distributed in the hope that it will be useful,
12796 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12797 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12798 + * GNU General Public License for more details.
12800 + * You should have received a copy of the GNU General Public License
12801 + * along with this program; if not, write to the Free Software
12802 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12806 + * inode operations
12811 +#ifndef __AUFS_INODE_H__
12812 +#define __AUFS_INODE_H__
12816 +#include <linux/fs.h>
12817 +#include <linux/namei.h>
12818 +#include <linux/security.h>
12819 +#include <linux/aufs_type.h>
12820 +#include "hinode.h"
12822 +#include "super.h"
12827 + atomic_t ii_generation;
12828 + struct super_block *ii_hsb1; /* no get/put */
12830 + struct au_rwsem ii_rwsem;
12831 + aufs_bindex_t ii_bstart, ii_bend;
12833 + struct au_hinode *ii_hinode;
12834 + struct au_vdir *ii_vdir;
12837 +struct aufs_icntnr {
12838 + struct au_iinfo iinfo;
12839 + struct inode vfs_inode;
12842 +/* au_pin flags */
12843 +#define AuPin_DI_LOCKED 1
12844 +#define AuPin_DO_GPARENT (1 << 1)
12845 +#define AuPin_MNT_WRITE (1 << 2)
12846 +#define AuPin_VFS_RENAME (1 << 3)
12847 +/* will be set automatically */
12848 +#define AuPin_VERIFY (1 << 4)
12849 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
12850 +#define au_fset_pin(flags, name) { (flags) |= AuPin_##name; }
12851 +#define au_fclr_pin(flags, name) { (flags) &= ~AuPin_##name; }
12855 + struct dentry *dentry;
12856 + unsigned char lsc_di, lsc_hi, flags;
12857 + aufs_bindex_t bindex;
12860 + struct dentry *parent;
12861 + struct inode *h_dir;
12864 +enum {AuPin_PARENT, AuPin_GPARENT};
12866 +#ifdef CONFIG_AUFS_HINOTIFY
12867 + struct au_pin1 pin[2];
12869 + struct au_pin1 pin[1]; /* no grand parent */
12873 +/* ---------------------------------------------------------------------- */
12876 +int au_refresh_hinode_self(struct inode *inode);
12877 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
12878 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
12879 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
12880 + struct inode *inode);
12881 +int au_test_h_perm(struct inode *h_inode, int mask, int dlgt);
12882 +int au_test_h_perm_sio(struct inode *h_inode, int mask, int dlgt);
12885 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
12887 +/* au_wr_dir flags */
12888 +#define AuWrDir_ADD_ENTRY 1
12889 +#define AuWrDir_ISDIR (1 << 1)
12890 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
12891 +#define au_fset_wrdir(flags, name) { (flags) |= AuWrDir_##name; }
12892 +#define au_fclr_wrdir(flags, name) { (flags) &= ~AuWrDir_##name; }
12894 +struct au_wr_dir_args {
12895 + aufs_bindex_t force_btgt;
12896 + unsigned char flags;
12898 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
12899 + struct au_wr_dir_args *args);
12901 +void au_pin_init(struct au_pin *args, struct dentry *dentry,
12902 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
12903 + unsigned char flags);
12904 +int au_pin(struct au_pin *args, struct dentry *dentry, aufs_bindex_t bindex,
12905 + unsigned char flags) __must_check;
12906 +int au_do_pin(struct au_pin1 *p, struct au_pin1 *gp) __must_check;
12907 +void au_do_unpin(struct au_pin1 *p, struct au_pin1 *gp);
12911 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
12912 + struct dentry *h_parent, int isdir, struct au_ndx *ndx);
12913 +int aufs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
12914 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
12915 +int aufs_create(struct inode *dir, struct dentry *dentry, int mode,
12916 + struct nameidata *nd);
12917 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
12918 + struct dentry *dentry);
12919 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
12922 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
12923 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
12924 + struct dentry *h_parent, int isdir, struct au_ndx *ndx);
12925 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
12926 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
12929 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
12930 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
12931 + struct inode *dir, struct dentry *dentry);
12933 +#ifdef CONFIG_AUFS_DLGT
12935 +int au_security_inode_permission(struct inode *h_inode, int mask,
12936 + struct nameidata *fake_nd, int dlgt);
12939 +int au_security_inode_permission(struct inode *h_inode, int mask,
12940 + struct nameidata *fake_nd, int dlgt)
12942 + return vfsub_security_inode_permission(h_inode, mask, fake_nd);
12944 +#endif /* CONFIG_AUFS_DLGT */
12946 +#ifdef CONFIG_AUFS_GETATTR
12948 +int aufs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st);
12951 +#if 0 /* reserved for future use */
12953 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
12954 + size_t sz, int flags);
12955 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
12957 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t sz);
12958 +int aufs_removexattr(struct dentry *dentry, const char *name);
12962 +struct au_iinfo *au_ii(struct inode *inode);
12963 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
12964 +aufs_bindex_t au_ii_br_id(struct inode *inode, aufs_bindex_t bindex);
12966 +void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex);
12967 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
12968 + struct dentry *h_wh);
12969 +unsigned int au_hi_flags(struct inode *inode, int isdir);
12971 +/* hinode flags */
12972 +#define AuHi_XINO 1
12973 +#define AuHi_NOTIFY (1 << 1)
12974 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
12975 +#define au_fset_hi(flags, name) { (flags) |= AuHi_##name; }
12976 +#define au_fclr_hi(flags, name) { (flags) &= ~AuHi_##name; }
12977 +#ifndef CONFIG_AUFS_HINOTIFY
12978 +#undef AuHi_NOTIFY
12979 +#define AuHi_NOTIFY 0
12982 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
12983 + struct inode *h_inode, unsigned int flags);
12985 +void au_update_iigen(struct inode *inode);
12986 +void au_update_brange(struct inode *inode, int do_put_zero);
12988 +int au_iinfo_init(struct inode *inode);
12989 +void au_iinfo_fin(struct inode *inode);
12992 +#ifdef CONFIG_AUFS_DEBUG
12993 +void au_plink_list(struct super_block *sb);
12995 +static inline void au_plink_list(struct super_block *sb)
13000 +int au_plink_test(struct super_block *sb, struct inode *inode);
13001 +struct dentry *au_plink_lkup(struct super_block *sb, aufs_bindex_t bindex,
13002 + struct inode *inode);
13003 +void au_plink_append(struct super_block *sb, struct inode *inode,
13004 + struct dentry *h_dentry, aufs_bindex_t bindex);
13005 +void au_plink_put(struct super_block *sb);
13006 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
13008 +/* ---------------------------------------------------------------------- */
13010 +/* lock subclass for iinfo */
13012 + AuLsc_II_CHILD, /* child first */
13013 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hinotify */
13014 + AuLsc_II_CHILD3, /* copyup dirs */
13015 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
13016 + AuLsc_II_PARENT2,
13017 + AuLsc_II_PARENT3,
13018 + AuLsc_II_PARENT4,
13019 + AuLsc_II_NEW_CHILD,
13023 + * ii_read_lock_child, ii_write_lock_child,
13024 + * ii_read_lock_child2, ii_write_lock_child2,
13025 + * ii_read_lock_child3, ii_write_lock_child3,
13026 + * ii_read_lock_parent, ii_write_lock_parent,
13027 + * ii_read_lock_parent2, ii_write_lock_parent2,
13028 + * ii_read_lock_parent3, ii_write_lock_parent3,
13029 + * ii_read_lock_parent4, ii_write_lock_parent4,
13030 + * ii_read_lock_new_child, ii_write_lock_new_child,
13032 +#define AuReadLockFunc(name, lsc) \
13033 +static inline void ii_read_lock_##name(struct inode *i) \
13035 + au_dbg_locking_ii_reg(i, 0, AuLsc_II_##lsc); \
13036 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
13037 + au_dbg_locking_ii_unreg(i, 0); \
13038 + au_dbg_locked_ii_reg(i, 0, AuLsc_II_##lsc); \
13041 +#define AuWriteLockFunc(name, lsc) \
13042 +static inline void ii_write_lock_##name(struct inode *i) \
13044 + au_dbg_locking_ii_reg(i, 1, AuLsc_II_##lsc); \
13045 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
13046 + au_dbg_locking_ii_unreg(i, 1); \
13047 + au_dbg_locked_ii_reg(i, 1, AuLsc_II_##lsc); \
13050 +#define AuRWLockFuncs(name, lsc) \
13051 + AuReadLockFunc(name, lsc) \
13052 + AuWriteLockFunc(name, lsc)
13054 +AuRWLockFuncs(child, CHILD);
13055 +AuRWLockFuncs(child2, CHILD2);
13056 +AuRWLockFuncs(child3, CHILD3);
13057 +AuRWLockFuncs(parent, PARENT);
13058 +AuRWLockFuncs(parent2, PARENT2);
13059 +AuRWLockFuncs(parent3, PARENT3);
13060 +AuRWLockFuncs(parent4, PARENT4);
13061 +AuRWLockFuncs(new_child, NEW_CHILD);
13063 +#undef AuReadLockFunc
13064 +#undef AuWriteLockFunc
13065 +#undef AuRWLockFuncs
13068 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
13070 +AuSimpleUnlockRwsemFuncs(ii_do, struct inode *i, au_ii(i)->ii_rwsem);
13071 +static inline void ii_read_unlock(struct inode *i)
13073 + ii_do_read_unlock(i);
13074 + au_dbg_locked_ii_unreg(i, 0);
13077 +static inline void ii_write_unlock(struct inode *i)
13079 + ii_do_write_unlock(i);
13080 + au_dbg_locked_ii_unreg(i, 0);
13083 +static inline void ii_downgrade_lock(struct inode *i)
13085 + ii_do_downgrade_lock(i);
13088 +/* to debug easier, do not make them inlined functions */
13089 +#define IiMustReadLock(i) do { \
13090 + SiMustAnyLock((i)->i_sb); \
13091 + AuRwMustReadLock(&au_ii(i)->ii_rwsem); \
13094 +#define IiMustWriteLock(i) do { \
13095 + SiMustAnyLock((i)->i_sb); \
13096 + AuRwMustWriteLock(&au_ii(i)->ii_rwsem); \
13099 +#define IiMustAnyLock(i) do { \
13100 + SiMustAnyLock((i)->i_sb); \
13101 + AuRwMustAnyLock(&au_ii(i)->ii_rwsem); \
13104 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
13106 +/* ---------------------------------------------------------------------- */
13108 +static inline struct inode *au_igrab(struct inode *inode)
13111 + AuDebugOn(!atomic_read(&inode->i_count));
13112 + atomic_inc_return(&inode->i_count);
13117 +/* ---------------------------------------------------------------------- */
13119 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
13121 + /* lock free root dinfo/inode */
13122 + if (inode->i_ino != AUFS_ROOT_INO)
13123 + IiMustAnyLock(inode);
13125 + SiMustAnyLock(inode->i_sb);
13126 + return au_ii(inode)->ii_bstart;
13129 +static inline aufs_bindex_t au_ibend(struct inode *inode)
13131 + /* lock free root dinfo/inode */
13132 + if (inode->i_ino != AUFS_ROOT_INO)
13133 + IiMustAnyLock(inode);
13135 + SiMustAnyLock(inode->i_sb);
13136 + return au_ii(inode)->ii_bend;
13139 +static inline struct au_vdir *au_ivdir(struct inode *inode)
13141 + IiMustAnyLock(inode);
13142 + AuDebugOn(!S_ISDIR(inode->i_mode));
13143 + return au_ii(inode)->ii_vdir;
13146 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
13148 + struct au_hinode *hinode;
13149 + IiMustAnyLock(inode);
13150 + hinode = au_ii(inode)->ii_hinode + bindex;
13151 + return hinode->hi_whdentry;
13154 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
13156 + IiMustWriteLock(inode);
13157 + AuDebugOn(au_sbend(inode->i_sb) < bindex || bindex < au_ibstart(inode));
13158 + au_ii(inode)->ii_bend = bindex;
13161 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
13163 + IiMustWriteLock(inode);
13164 + AuDebugOn(!S_ISDIR(inode->i_mode) || (au_ii(inode)->ii_vdir && vdir));
13165 + au_ii(inode)->ii_vdir = vdir;
13168 +static inline void au_hiput(struct au_hinode *hinode)
13170 + au_hin_free(hinode);
13171 + dput(hinode->hi_whdentry);
13172 + iput(hinode->hi_inode);
13175 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
13177 + /* todo: this lock check causes some unnecessary locks in callers. */
13178 + IiMustAnyLock(inode);
13179 + return au_ii(inode)->ii_hinode + bindex;
13182 +/* tiny test for inode number */
13183 +/* tmpfs generation is too rough */
13184 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
13186 + struct au_iinfo *iinfo;
13188 + IiMustAnyLock(inode);
13190 + iinfo = au_ii(inode);
13191 + return !(iinfo->ii_hsb1 == h_inode->i_sb
13192 + && iinfo->ii_higen == h_inode->i_generation);
13195 +static inline au_gen_t au_iigen(struct inode *inode)
13197 + return atomic_read(&au_ii(inode)->ii_generation);
13200 +#ifdef CONFIG_AUFS_HINOTIFY
13201 +static inline au_gen_t au_iigen_dec(struct inode *inode)
13203 + /* AuDbg("i%lu\n", inode->i_ino); */
13204 + return atomic_dec_return(&au_ii(inode)->ii_generation);
13208 +/* ---------------------------------------------------------------------- */
13210 +#ifdef CONFIG_AUFS_HINOTIFY
13211 +static inline struct au_pin1 *au_pin_gp(struct au_pin *args)
13213 + return args->pin + AuPin_GPARENT;
13217 +void au_unpin_gp(struct au_pin *args);
13221 +static inline struct au_pin1 *au_pin_gp(struct au_pin *args)
13226 +static inline void au_unpin_gp(struct au_pin *args)
13230 +#endif /* HINOTIFY */
13232 +static inline void au_unpin(struct au_pin *args)
13234 + au_do_unpin(args->pin + AuPin_PARENT, au_pin_gp(args));
13238 +struct au_hinode *au_do_pinned_hdir(struct au_pin1 *pin)
13240 + if (pin && pin->parent)
13241 + return au_hi(pin->parent->d_inode, pin->bindex);
13245 +struct dentry *au_do_pinned_h_parent(struct au_pin1 *pin);
13247 +static inline struct dentry *au_do_pinned_parent(struct au_pin1 *pin)
13250 + return pin->parent;
13254 +static inline struct inode *au_do_pinned_h_dir(struct au_pin1 *pin)
13257 + return pin->h_dir;
13262 +void au_pin_do_set_dentry(struct au_pin1 *pin, struct dentry *dentry)
13265 + pin->dentry = dentry;
13269 +void au_pin_do_set_parent(struct au_pin1 *pin, struct dentry *parent)
13272 + dput(pin->parent);
13273 + pin->parent = dget(parent);
13277 +static inline void au_pin_do_set_h_dir(struct au_pin1 *pin, struct inode *h_dir)
13280 + iput(pin->h_dir);
13281 + pin->h_dir = au_igrab(h_dir);
13286 +void au_pin_do_set_parent_lflag(struct au_pin1 *pin, unsigned char lflag)
13289 + /* dirty macros require brackets */
13291 + au_fset_pin(pin->flags, DI_LOCKED);
13293 + au_fclr_pin(pin->flags, DI_LOCKED);
13299 +struct au_hinode *au_pinned_hdir(struct au_pin *args)
13301 + return au_do_pinned_hdir(args->pin + AuPin_PARENT);
13305 +struct au_hinode *au_pinned_hgdir(struct au_pin *args)
13307 + return au_do_pinned_hdir(au_pin_gp(args));
13311 +struct dentry *au_pinned_h_parent(struct au_pin *args)
13313 + return au_do_pinned_h_parent(args->pin + AuPin_PARENT);
13316 +#if 0 /* reserved for future use */
13318 +struct dentry *au_pinned_h_gparent(struct au_pin *args)
13320 + return au_do_pinned_h_parent(au_pin_gp(args));
13325 +struct dentry *au_pinned_parent(struct au_pin *args)
13327 + return au_do_pinned_parent(args->pin + AuPin_PARENT);
13331 +struct dentry *au_pinned_gparent(struct au_pin *args)
13333 + return au_do_pinned_parent(au_pin_gp(args));
13337 +struct inode *au_pinned_h_dir(struct au_pin *args)
13339 + return au_do_pinned_h_dir(args->pin + AuPin_PARENT);
13343 +struct inode *au_pinned_h_gdir(struct au_pin *args)
13345 + return au_do_pinned_h_dir(au_pin_gp(args));
13348 +static inline void au_pin_set_parent(struct au_pin *args, struct dentry *d)
13350 + au_pin_do_set_parent(args->pin + AuPin_PARENT, d);
13353 +static inline void au_pin_set_gparent(struct au_pin *args, struct dentry *d)
13355 + au_pin_do_set_parent(au_pin_gp(args), d);
13358 +static inline void au_pin_set_h_dir(struct au_pin *args, struct inode *h_dir)
13360 + au_pin_do_set_h_dir(args->pin + AuPin_PARENT, h_dir);
13363 +static inline void au_pin_set_h_gdir(struct au_pin *args, struct inode *h_dir)
13365 + au_pin_do_set_h_dir(au_pin_gp(args), h_dir);
13369 +void au_pin_set_parent_lflag(struct au_pin *args, unsigned char lflag)
13371 + au_pin_do_set_parent_lflag(args->pin + AuPin_PARENT, lflag);
13375 +void au_pin_set_gparent_lflag(struct au_pin *args, unsigned char lflag)
13377 + au_pin_do_set_parent_lflag(au_pin_gp(args), lflag);
13380 +#endif /* __KERNEL__ */
13381 +#endif /* __AUFS_INODE_H__ */
13382 diff -urN linux/fs/aufs/i_op_add.c linux-aufs/fs/aufs/i_op_add.c
13383 --- linux/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
13384 +++ linux-aufs/fs/aufs/i_op_add.c 2009-03-12 16:18:04.000000000 +0100
13387 + * Copyright (C) 2005-2009 Junjiro Okajima
13389 + * This program, aufs is free software; you can redistribute it and/or modify
13390 + * it under the terms of the GNU General Public License as published by
13391 + * the Free Software Foundation; either version 2 of the License, or
13392 + * (at your option) any later version.
13394 + * This program is distributed in the hope that it will be useful,
13395 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13396 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13397 + * GNU General Public License for more details.
13399 + * You should have received a copy of the GNU General Public License
13400 + * along with this program; if not, write to the Free Software
13401 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13405 + * inode operations (add entry)
13413 + * final procedure of adding a new entry, except link(2).
13414 + * remove whiteout, instantiate, copyup the parent dir's times and size
13415 + * and update version.
13416 + * if it failed, re-create the removed whiteout.
13418 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
13419 + struct dentry *wh_dentry, struct dentry *dentry)
13422 + aufs_bindex_t bwh;
13423 + struct inode *inode, *h_dir;
13424 + struct dentry *wh;
13425 + struct au_ndx ndx;
13426 + struct super_block *sb;
13428 + LKTRTrace("wh %p, %.*s\n", wh_dentry, AuDLNPair(dentry));
13430 + sb = dentry->d_sb;
13433 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
13434 + IMustLock(h_dir);
13435 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
13436 + bwh = au_dbwh(dentry);
13437 + err = au_wh_unlink_dentry(au_hi(dir, bindex), wh_dentry, dentry,
13439 + if (unlikely(err))
13443 + inode = au_new_inode(dentry, /*must_new*/1);
13444 + if (!IS_ERR(inode)) {
13445 + d_instantiate(dentry, inode);
13446 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
13448 + /* or always cpup dir mtime? */
13449 + if (au_ibstart(dir) == au_dbstart(dentry))
13450 + au_cpup_attr_timesizes(dir);
13451 + dir->i_version++;
13452 + return 0; /* success */
13455 + err = PTR_ERR(inode);
13461 + if (au_test_dlgt(au_mntflags(sb)))
13462 + au_fset_ndx(ndx.flags, DLGT);
13463 + ndx.nfsmnt = au_nfsmnt(sb, bwh);
13465 + /* ndx.br = NULL; */
13466 + /* dir inode is locked */
13467 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent, &ndx);
13468 + rerr = PTR_ERR(wh);
13469 + if (IS_ERR(wh)) {
13470 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
13471 + AuDLNPair(dentry), err, rerr);
13482 + * simple tests for the adding inode operations.
13483 + * following the checks in vfs, plus the parent-child relationship.
13485 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
13486 + struct dentry *h_parent, int isdir, struct au_ndx *ndx)
13489 + struct dentry *h_dentry;
13490 + struct inode *h_inode;
13493 + LKTRTrace("%.*s/%.*s, b%d, dir %d\n",
13494 + AuDLNPair(h_parent), AuDLNPair(dentry), bindex, isdir);
13496 + exist = !!dentry->d_inode;
13497 + h_dentry = au_h_dptr(dentry, bindex);
13498 + h_inode = h_dentry->d_inode;
13501 + if (unlikely(h_inode))
13504 + /* rename(2) case */
13506 + if (unlikely(!h_inode || !h_inode->i_nlink))
13509 + h_mode = h_inode->i_mode;
13512 + if (unlikely(S_ISDIR(h_mode)))
13514 + } else if (unlikely(!S_ISDIR(h_mode))) {
13521 + /* expected parent dir is locked */
13522 + if (unlikely(h_parent != h_dentry->d_parent))
13526 + if (au_opt_test(au_mntflags(dentry->d_sb), UDBA_INOTIFY)) {
13527 + struct dentry *h_latest;
13528 + struct qstr *qstr = &dentry->d_name;
13531 + if (unlikely(au_test_h_perm
13532 + (h_parent->d_inode, MAY_EXEC | MAY_WRITE,
13533 + au_ftest_ndx(ndx->flags, DLGT))))
13536 + h_latest = au_sio_lkup_one(qstr->name, h_parent, qstr->len,
13538 + err = PTR_ERR(h_latest);
13539 + if (IS_ERR(h_latest))
13543 + /* fuse d_revalidate always return 0 for negative dentries */
13544 + if (h_latest == h_dentry || au_test_fuse(h_dentry->d_sb))
13554 + * initial procedure of adding a new entry.
13555 + * prepare writable branch and the parent dir, lock it,
13556 + * lookup whiteout for the new entry.
13558 +static struct dentry*
13559 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
13560 + struct dentry *src_dentry, struct au_pin *pin,
13561 + struct au_wr_dir_args *wr_dir_args)
13563 + struct dentry *wh_dentry, *h_parent;
13564 + struct super_block *sb;
13566 + unsigned int mnt_flags;
13567 + unsigned char pin_flags;
13568 + aufs_bindex_t bstart, bcpup;
13569 + struct au_ndx ndx;
13571 + LKTRTrace("%.*s, src %p\n", AuDLNPair(dentry), src_dentry);
13573 + bstart = au_dbstart(dentry);
13574 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
13576 + wh_dentry = ERR_PTR(err);
13577 + if (unlikely(err < 0))
13580 + sb = dentry->d_sb;
13581 + mnt_flags = au_mntflags(sb);
13582 + pin_flags = AuPin_DI_LOCKED | AuPin_MNT_WRITE;
13583 + if (dt && au_opt_test(mnt_flags, UDBA_INOTIFY))
13584 + au_fset_pin(pin_flags, DO_GPARENT);
13585 + err = au_pin(pin, dentry, bcpup, pin_flags);
13586 + wh_dentry = ERR_PTR(err);
13587 + if (unlikely(err))
13590 + ndx.nfsmnt = au_nfsmnt(sb, bcpup);
13592 + if (au_test_dlgt(mnt_flags))
13593 + au_fset_ndx(ndx.flags, DLGT);
13595 + /* ndx.br = NULL; */
13596 + /* ndx.nd_file = NULL; */
13598 + h_parent = au_pinned_h_parent(pin);
13599 + if (!au_opt_test(mnt_flags, UDBA_NONE) && au_dbstart(dentry) == bcpup) {
13600 + struct nameidata nd;
13602 + if (ndx.nfsmnt) {
13603 + /* todo: dirty? */
13605 + ndx.br = au_sbr(sb, bcpup);
13606 + memset(&nd, 0, sizeof(nd));
13607 + nd.flags = LOOKUP_CREATE;
13608 + nd.intent.open.flags = O_EXCL;
13610 + err = au_may_add(dentry, bcpup, h_parent,
13611 + au_ftest_wrdir(wr_dir_args->flags, ISDIR),
13613 + wh_dentry = ERR_PTR(err);
13614 + if (unlikely(err))
13621 + au_dtime_store(dt, au_pinned_parent(pin), h_parent,
13622 + au_pinned_hdir(pin), au_pinned_hgdir(pin));
13624 + wh_dentry = NULL;
13625 + if (/* bcpup != bstart || */ bcpup != au_dbwh(dentry))
13626 + goto out; /* success */
13628 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, &ndx);
13631 + if (IS_ERR(wh_dentry))
13634 + AuTraceErrPtr(wh_dentry);
13635 + return wh_dentry;
13638 +/* ---------------------------------------------------------------------- */
13640 +enum { Mknod, Symlink, Creat };
13641 +struct simple_arg {
13646 + struct nameidata *nd;
13649 + const char *symname;
13658 +static int add_simple(struct inode *dir, struct dentry *dentry,
13659 + struct simple_arg *arg)
13662 + struct dentry *h_dentry, *wh_dentry, *parent;
13663 + struct inode *h_dir;
13664 + struct au_dtime dt;
13665 + struct vfsub_args vargs;
13666 + struct super_block *sb;
13667 + aufs_bindex_t bstart;
13668 + unsigned char created;
13669 + struct au_hin_ignore ign;
13670 + struct au_pin pin;
13671 + struct au_wr_dir_args wr_dir_args = {
13672 + .force_btgt = -1,
13673 + .flags = AuWrDir_ADD_ENTRY
13676 + LKTRTrace("type %d, %.*s\n", arg->type, AuDLNPair(dentry));
13680 + parent = dentry->d_parent; /* dir inode is locked */
13681 + aufs_read_lock(dentry, AuLock_DW);
13682 + vfsub_args_init(&vargs, &ign, !!au_test_dlgt(au_mntflags(sb)), 0);
13683 + di_write_lock_parent(parent);
13684 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL, &pin,
13686 + err = PTR_ERR(wh_dentry);
13687 + if (IS_ERR(wh_dentry))
13690 + bstart = au_dbstart(dentry);
13691 + h_dentry = au_h_dptr(dentry, bstart);
13692 + h_dir = au_pinned_h_dir(&pin);
13693 + vfsub_ign_hinode(&vargs, IN_CREATE, au_pinned_hdir(&pin));
13695 + switch (arg->type) {
13697 + AuDebugOn(au_test_nfs(h_dir->i_sb) && !arg->u.c.nd);
13698 + err = au_h_create(h_dir, h_dentry, arg->u.c.mode, &vargs,
13699 + arg->u.c.nd, au_nfsmnt(sb, bstart));
13702 + err = vfsub_symlink(h_dir, h_dentry, arg->u.s.symname,
13703 + S_IALLUGO, &vargs);
13706 + err = vfsub_mknod(h_dir, h_dentry, arg->u.m.mode, arg->u.m.dev,
13714 + err = epilog(dir, bstart, wh_dentry, dentry);
13717 + if (unlikely(created && err && h_dentry->d_inode)) {
13719 + vfsub_args_reinit(&vargs);
13720 + vfsub_ign_hinode(&vargs, IN_DELETE, au_pinned_hdir(&pin));
13721 + rerr = vfsub_unlink(h_dir, h_dentry, &vargs);
13723 + AuIOErr("%.*s revert failure(%d, %d)\n",
13724 + AuDLNPair(dentry), err, rerr);
13727 + /* todo: inotify will be fired to the grand parent dir? */
13728 + au_dtime_revert(&dt);
13736 + if (unlikely(err)) {
13737 + au_update_dbstart(dentry);
13740 + di_write_unlock(parent);
13741 + aufs_read_unlock(dentry, AuLock_DW);
13743 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
13748 +int aufs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
13750 + struct simple_arg arg = {
13757 + return add_simple(dir, dentry, &arg);
13760 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
13762 + struct simple_arg arg = {
13764 + .u.s.symname = symname
13766 + return add_simple(dir, dentry, &arg);
13769 +int aufs_create(struct inode *dir, struct dentry *dentry, int mode,
13770 + struct nameidata *nd)
13772 + struct simple_arg arg = {
13779 + return add_simple(dir, dentry, &arg);
13782 +/* ---------------------------------------------------------------------- */
13784 +struct au_link_args {
13785 + unsigned int mnt_flags;
13786 + unsigned char pin_flags;
13787 + aufs_bindex_t bdst, bsrc;
13788 + struct vfsub_args vargs;
13789 + struct au_pin pin;
13790 + struct au_hin_ignore ign;
13791 + struct dentry *h_dentry;
13792 + struct dentry *src_parent, *parent;
13795 +static int au_cpup_before_link(struct dentry *src_dentry, struct inode *dir,
13796 + struct dentry *dentry, struct au_link_args *a)
13799 + const int hinotify = au_opt_test(a->mnt_flags, UDBA_INOTIFY);
13800 + struct mutex *h_mtx;
13802 + LKTRTrace("src %.*s, i%lu, dst %.*s\n",
13803 + AuDLNPair(src_dentry), dir->i_ino, AuDLNPair(dentry));
13805 + di_read_lock_parent(a->src_parent, AuLock_IR);
13806 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
13807 + if (unlikely(err))
13810 + AuDebugOn(au_dbstart(src_dentry) != a->bsrc);
13811 + h_mtx = &au_h_dptr(src_dentry, a->bsrc)->d_inode->i_mutex;
13812 + a->pin_flags = AuPin_DI_LOCKED | AuPin_MNT_WRITE;
13814 + au_fset_pin(a->pin_flags, DO_GPARENT);
13815 + err = au_pin(&a->pin, src_dentry, a->bdst, a->pin_flags);
13816 + if (unlikely(err))
13818 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13819 + /* todo: no KEEPLINO because of noplink? */
13820 + err = au_sio_cpup_simple(src_dentry, a->bdst, -1,
13821 + AuCpup_DTIME /* | AuCpup_KEEPLINO */);
13822 + mutex_unlock(h_mtx);
13823 + au_unpin(&a->pin);
13826 + di_read_unlock(a->src_parent, AuLock_IR);
13831 +static int au_cpup_or_link(struct dentry *src_dentry, struct au_link_args *a)
13834 + struct inode *h_inode;
13835 + aufs_bindex_t bstart;
13836 + struct dentry *h_src_dentry;
13839 + AuDebugOn(au_dbstart(src_dentry) != a->bsrc);
13841 + bstart = au_ibstart(src_dentry->d_inode);
13843 + if (bstart <= a->bdst)
13844 + h_inode = au_h_iptr(src_dentry->d_inode, a->bdst);
13845 + if (!h_inode || !h_inode->i_nlink) {
13846 + /* copyup src_dentry as the name of dentry. */
13847 + au_set_dbstart(src_dentry, a->bdst);
13848 + au_set_h_dptr(src_dentry, a->bdst, dget(a->h_dentry));
13849 + h_inode = au_h_dptr(src_dentry, a->bsrc)->d_inode;
13850 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
13851 + err = au_sio_cpup_single(src_dentry, a->bdst, a->bsrc, -1,
13852 + AuCpup_KEEPLINO, a->parent);
13853 + mutex_unlock(&h_inode->i_mutex);
13854 + au_set_h_dptr(src_dentry, a->bdst, NULL);
13855 + au_set_dbstart(src_dentry, a->bsrc);
13857 + /* the inode of src_dentry already exists on a.bdst branch */
13858 + h_src_dentry = d_find_alias(h_inode);
13859 + if (h_src_dentry) {
13860 + /* vfsub_args_reinit(&a->vargs); */
13861 + vfsub_ign_hinode(&a->vargs, IN_CREATE,
13862 + au_pinned_hdir(&a->pin));
13863 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
13864 + a->h_dentry, &a->vargs);
13865 + dput(h_src_dentry);
13867 + AuIOErr("no dentry found for i%lu on b%d\n",
13868 + h_inode->i_ino, a->bdst);
13874 + au_plink_append(src_dentry->d_sb, src_dentry->d_inode,
13875 + a->h_dentry, a->bdst);
13881 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
13882 + struct dentry *dentry)
13885 + struct au_dtime dt;
13886 + struct super_block *sb;
13887 + struct au_link_args *a;
13888 + struct au_wr_dir_args wr_dir_args = {
13889 + /* .force_btgt = -1, */
13890 + .flags = AuWrDir_ADD_ENTRY
13892 + struct dentry *wh_dentry, *h_src_dentry;
13893 + struct inode *inode;
13895 + LKTRTrace("src %.*s, i%lu, dst %.*s\n",
13896 + AuDLNPair(src_dentry), dir->i_ino, AuDLNPair(dentry));
13898 + inode = src_dentry->d_inode;
13899 + IMustLock(inode);
13900 + AuDebugOn(S_ISDIR(inode->i_mode));
13903 + a = kzalloc(sizeof(*a), GFP_NOFS);
13904 + if (unlikely(!a))
13907 + sb = dentry->d_sb;
13908 + a->parent = dentry->d_parent; /* dir inode is locked */
13909 + aufs_read_and_write_lock2(dentry, src_dentry, /*AuLock_FLUSH*/0);
13910 + a->src_parent = dget_parent(src_dentry);
13911 + wr_dir_args.force_btgt = au_dbstart(src_dentry);
13912 + a->mnt_flags = au_mntflags(sb);
13913 + vfsub_args_init(&a->vargs, &a->ign, au_test_dlgt(a->mnt_flags), 0);
13915 + di_write_lock_parent(a->parent);
13916 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
13917 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
13919 + err = PTR_ERR(wh_dentry);
13920 + if (IS_ERR(wh_dentry))
13924 + a->bdst = au_dbstart(dentry);
13925 + a->h_dentry = au_h_dptr(dentry, a->bdst);
13927 + /* todo: minor optimize,
13928 + their sb may be same while their bindex differs? */
13929 + a->bsrc = au_dbstart(src_dentry);
13930 + if (au_opt_test(a->mnt_flags, PLINK)) {
13931 + if (a->bdst < a->bsrc
13932 + /* && h_src_dentry->d_sb != a->h_dentry->d_sb */)
13933 + err = au_cpup_or_link(src_dentry, a);
13935 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
13936 + AuDebugOn(!h_src_dentry);
13937 + AuDebugOn(!h_src_dentry->d_inode);
13938 + vfsub_ign_hinode(&a->vargs, IN_CREATE,
13939 + au_pinned_hdir(&a->pin));
13940 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
13941 + a->h_dentry, &a->vargs);
13945 + * copyup src_dentry to the branch we process,
13946 + * and then link(2) to it.
13948 + if (a->bdst < a->bsrc
13949 + /* && h_src_dentry->d_sb != a->h_dentry->d_sb */) {
13950 + au_unpin(&a->pin);
13951 + di_write_unlock(a->parent);
13952 + err = au_cpup_before_link(src_dentry, dir, dentry, a);
13955 + = AuPin_DI_LOCKED | AuPin_MNT_WRITE;
13956 + if (au_opt_test(a->mnt_flags, UDBA_INOTIFY))
13957 + au_fset_pin(a->pin_flags, DO_GPARENT);
13958 + di_write_lock_parent(a->parent);
13959 + err = au_pin(&a->pin, dentry, a->bdst,
13961 + if (unlikely(err))
13966 + /* vfsub_args_reinit(&a->vargs); */
13967 + vfsub_ign_hinode(&a->vargs, IN_CREATE,
13968 + au_pinned_hdir(&a->pin));
13969 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
13970 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
13971 + a->h_dentry, &a->vargs);
13974 + if (unlikely(err))
13978 + err = au_wh_unlink_dentry(au_pinned_hdir(&a->pin), wh_dentry,
13979 + dentry, /*dlgt*/0);
13980 + if (unlikely(err))
13984 +#if 0 /* cannot support it */
13985 + /* fuse has different memory inode for the same inode number */
13986 + if (au_test_fuse(a->h_dentry->d_sb)) {
13988 + d_drop(a->h_dentry);
13989 + /*d_drop(h_src_dentry);
13990 + d_drop(src_dentry);*/
13991 + inc_nlink(a->inode);
13992 + a->inode->i_ctime = dir->i_ctime;
13996 + dir->i_version++;
13997 + if (au_ibstart(dir) == au_dbstart(dentry))
13998 + au_cpup_attr_timesizes(dir);
13999 + if (!d_unhashed(a->h_dentry)
14000 + /* || h_old_inode->i_nlink <= nlink */
14001 + /* || SB_NFS(h_src_dentry->d_sb) */) {
14002 + d_instantiate(dentry, au_igrab(inode));
14003 + inc_nlink(inode);
14004 + inode->i_ctime = dir->i_ctime;
14006 + /* nfs case (< 2.6.15) */
14008 + goto out_unpin; /* success */
14011 + vfsub_args_reinit(&a->vargs);
14012 + vfsub_ign_hinode(&a->vargs, IN_DELETE, au_pinned_hdir(&a->pin));
14013 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), a->h_dentry, &a->vargs);
14016 + AuIOErr("%.*s reverting failed(%d, %d)\n",
14017 + AuDLNPair(dentry), err, rerr);
14021 + au_dtime_revert(&dt);
14023 + au_unpin(&a->pin);
14027 + if (unlikely(err)) {
14028 + au_update_dbstart(dentry);
14031 + di_write_unlock(a->parent);
14032 + dput(a->src_parent);
14033 + aufs_read_and_write_unlock2(dentry, src_dentry);
14037 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
14042 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
14045 + struct dentry *h_dentry, *wh_dentry, *parent, *opq_dentry;
14046 + struct mutex *h_mtx;
14047 + struct au_dtime dt;
14048 + aufs_bindex_t bindex;
14049 + unsigned char diropq, dlgt;
14050 + unsigned int mnt_flags;
14051 + struct au_hin_ignore ign;
14052 + struct vfsub_args vargs;
14053 + struct au_pin pin;
14054 + struct au_wr_dir_args wr_dir_args = {
14055 + .force_btgt = -1,
14056 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
14059 + LKTRTrace("i%lu, %.*s, mode 0%o\n",
14060 + dir->i_ino, AuDLNPair(dentry), mode);
14063 + aufs_read_lock(dentry, AuLock_DW);
14064 + parent = dentry->d_parent; /* dir inode is locked */
14065 + mnt_flags = au_mntflags(dentry->d_sb);
14066 + dlgt = !!au_test_dlgt(mnt_flags);
14067 + vfsub_args_init(&vargs, &ign, dlgt, 0);
14069 + di_write_lock_parent(parent);
14070 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL, &pin,
14072 + err = PTR_ERR(wh_dentry);
14073 + if (IS_ERR(wh_dentry))
14076 + bindex = au_dbstart(dentry);
14077 + h_dentry = au_h_dptr(dentry, bindex);
14078 + vfsub_ign_hinode(&vargs, IN_CREATE, au_pinned_hdir(&pin));
14079 + err = vfsub_mkdir(au_pinned_h_dir(&pin), h_dentry, mode, &vargs);
14080 + if (unlikely(err))
14083 + /* make the dir opaque */
14085 + h_mtx = &h_dentry->d_inode->i_mutex;
14086 + if (wh_dentry || au_opt_test(mnt_flags, ALWAYS_DIROPQ)) {
14087 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
14088 + opq_dentry = au_diropq_create(dentry, bindex, /*dlgt*/0);
14089 + mutex_unlock(h_mtx);
14090 + err = PTR_ERR(opq_dentry);
14091 + if (IS_ERR(opq_dentry))
14093 + dput(opq_dentry);
14097 + err = epilog(dir, bindex, wh_dentry, dentry);
14100 + goto out_unlock; /* success */
14105 + LKTRLabel(revert opq);
14106 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
14107 + rerr = au_diropq_remove(dentry, bindex, dlgt);
14108 + mutex_unlock(h_mtx);
14110 + AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
14111 + AuDLNPair(dentry), err, rerr);
14117 + LKTRLabel(revert dir);
14118 + vfsub_args_reinit(&vargs);
14119 + vfsub_ign_hinode(&vargs, IN_DELETE, au_pinned_hdir(&pin));
14120 + rerr = vfsub_rmdir(au_pinned_h_dir(&pin), h_dentry, &vargs);
14122 + AuIOErr("%.*s reverting dir failed(%d, %d)\n",
14123 + AuDLNPair(dentry), err, rerr);
14127 + au_dtime_revert(&dt);
14132 + if (unlikely(err)) {
14133 + au_update_dbstart(dentry);
14136 + di_write_unlock(parent);
14137 + aufs_read_unlock(dentry, AuLock_DW);
14139 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
14143 diff -urN linux/fs/aufs/i_op.c linux-aufs/fs/aufs/i_op.c
14144 --- linux/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
14145 +++ linux-aufs/fs/aufs/i_op.c 2009-03-12 16:18:04.000000000 +0100
14148 + * Copyright (C) 2005-2009 Junjiro Okajima
14150 + * This program, aufs is free software; you can redistribute it and/or modify
14151 + * it under the terms of the GNU General Public License as published by
14152 + * the Free Software Foundation; either version 2 of the License, or
14153 + * (at your option) any later version.
14155 + * This program is distributed in the hope that it will be useful,
14156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14158 + * GNU General Public License for more details.
14160 + * You should have received a copy of the GNU General Public License
14161 + * along with this program; if not, write to the Free Software
14162 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14166 + * inode operations (except add/del/rename)
14171 +#include <linux/fs_stack.h>
14172 +#include <linux/uaccess.h>
14175 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
14176 +static int h_permission(struct inode *h_inode, int mask,
14177 + struct vfsmount *h_mnt, int brperm, int dlgt)
14179 + int err, submask;
14180 + const int write_mask = (mask & (MAY_WRITE | MAY_APPEND));
14182 + LKTRTrace("ino %lu, mask 0x%x, brperm 0x%x\n",
14183 + h_inode->i_ino, mask, brperm);
14186 + if ((write_mask && IS_IMMUTABLE(h_inode))
14187 + || ((mask & MAY_EXEC) && S_ISREG(h_inode->i_mode)
14188 + && (h_mnt->mnt_flags & MNT_NOEXEC)))
14192 + * - skip hidden fs test in the case of write to ro branch.
14193 + * - nfs dir permission write check is optimized, but a policy for
14194 + * link/rename requires a real check.
14196 + submask = mask & ~MAY_APPEND;
14197 + if ((write_mask && !au_br_writable(brperm))
14198 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
14199 + && write_mask && !(mask & MAY_READ))
14200 + || !h_inode->i_op
14201 + || !h_inode->i_op->permission) {
14202 + /* LKTRLabel(generic_permission); */
14203 + err = generic_permission(h_inode, submask, NULL);
14205 + /* LKTRLabel(h_inode->permission); */
14206 + err = h_inode->i_op->permission(h_inode, submask);
14210 +#if 1 /* todo: export? */
14212 + err = au_security_inode_permission(h_inode, mask, NULL,
14221 +static int aufs_permission(struct inode *inode, int mask)
14224 + aufs_bindex_t bindex, bend;
14225 + unsigned char dlgt;
14226 + const unsigned char isdir = S_ISDIR(inode->i_mode);
14227 + struct inode *h_inode;
14228 + struct super_block *sb;
14229 + unsigned int mnt_flags;
14230 + const int write_mask = (mask & (MAY_WRITE | MAY_APPEND));
14232 + LKTRTrace("ino %lu, mask 0x%x, isdir %d, write_mask %d\n",
14233 + inode->i_ino, mask, isdir, write_mask);
14235 + sb = inode->i_sb;
14236 + si_read_lock(sb, AuLock_FLUSH);
14237 + ii_read_lock_child(inode);
14238 + mnt_flags = au_mntflags(sb);
14239 + dlgt = !!au_test_dlgt(mnt_flags);
14241 + if (!isdir || write_mask || au_test_dirperm1(mnt_flags)) {
14242 + h_inode = au_h_iptr(inode, au_ibstart(inode));
14243 + AuDebugOn(!h_inode
14244 + || ((h_inode->i_mode & S_IFMT)
14245 + != (inode->i_mode & S_IFMT)));
14247 + bindex = au_ibstart(inode);
14248 + LKTRTrace("b%d\n", bindex);
14249 + err = h_permission(h_inode, mask, au_sbr_mnt(sb, bindex),
14250 + au_sbr_perm(sb, bindex), dlgt);
14252 + if (write_mask && !err) {
14253 + /* test whether the upper writable branch exists */
14255 + for (; bindex >= 0; bindex--)
14256 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
14264 + /* non-write to dir */
14266 + bend = au_ibend(inode);
14267 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
14268 + h_inode = au_h_iptr(inode, bindex);
14271 + AuDebugOn(!S_ISDIR(h_inode->i_mode));
14273 + LKTRTrace("b%d\n", bindex);
14274 + err = h_permission(h_inode, mask, au_sbr_mnt(sb, bindex),
14275 + au_sbr_perm(sb, bindex), dlgt);
14279 + ii_read_unlock(inode);
14280 + si_read_unlock(sb);
14282 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
14288 +static int silly_lock(struct inode *inode, struct nameidata *nd)
14291 + struct super_block *sb = inode->i_sb;
14293 + LKTRTrace("i%lu, nd %p\n", inode->i_ino, nd);
14295 + if (!nd || !nd->path.dentry) {
14296 + si_read_lock(sb, AuLock_FLUSH);
14297 + ii_read_lock_child(inode);
14298 + } else if (nd->path.dentry->d_inode != inode) {
14300 + /* lock child first, then parent */
14301 + si_read_lock(sb, AuLock_FLUSH);
14302 + ii_read_lock_child(inode);
14303 + di_read_lock_parent(nd->path.dentry, 0);
14306 + aufs_read_lock(nd->path.dentry, AuLock_FLUSH | AuLock_IR);
14311 +static void silly_unlock(int locked, struct inode *inode, struct nameidata *nd)
14313 + struct super_block *sb = inode->i_sb;
14315 + LKTRTrace("locked %d, i%lu, nd %p\n", locked, inode->i_ino, nd);
14317 + switch (locked) {
14319 + ii_read_unlock(inode);
14320 + si_read_unlock(sb);
14323 + di_read_unlock(nd->path.dentry, 0);
14324 + ii_read_unlock(inode);
14325 + si_read_unlock(sb);
14328 + aufs_read_unlock(nd->path.dentry, AuLock_IR);
14335 +static int h_permission(struct inode *h_inode, int mask,
14336 + struct nameidata *fake_nd, int brperm, int dlgt)
14338 + int err, submask;
14339 + const int write_mask = (mask & (MAY_WRITE | MAY_APPEND));
14341 + LKTRTrace("ino %lu, mask 0x%x, brperm 0x%x\n",
14342 + h_inode->i_ino, mask, brperm);
14345 + if ((write_mask && IS_IMMUTABLE(h_inode))
14346 + || ((mask & MAY_EXEC) && S_ISREG(h_inode->i_mode)
14347 + && fake_nd && fake_nd->path.mnt
14348 + && (fake_nd->path.mnt->mnt_flags & MNT_NOEXEC)))
14352 + * - skip hidden fs test in the case of write to ro branch.
14353 + * - nfs dir permission write check is optimized, but a policy for
14354 + * link/rename requires a real check.
14356 + submask = mask & ~MAY_APPEND;
14357 + if ((write_mask && !au_br_writable(brperm))
14358 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
14359 + && write_mask && !(mask & MAY_READ))
14360 + || !h_inode->i_op
14361 + || !h_inode->i_op->permission) {
14362 + /* LKTRLabel(generic_permission); */
14363 + err = generic_permission(h_inode, submask, NULL);
14365 + /* LKTRLabel(h_inode->permission); */
14366 + err = h_inode->i_op->permission(h_inode, submask, fake_nd);
14370 +#if 1 /* todo: export? */
14372 + err = au_security_inode_permission(h_inode, mask, fake_nd,
14381 +static int aufs_permission(struct inode *inode, int mask, struct nameidata *nd)
14384 + aufs_bindex_t bindex, bend;
14385 + unsigned char locked, dlgt, do_nd;
14386 + const unsigned char isdir = S_ISDIR(inode->i_mode);
14387 + struct inode *h_inode;
14388 + struct super_block *sb;
14389 + unsigned int mnt_flags;
14390 + struct path path;
14391 + const int write_mask = (mask & (MAY_WRITE | MAY_APPEND));
14393 + LKTRTrace("ino %lu, mask 0x%x, isdir %d, write_mask %d, "
14394 + "nd %d{%d, %d}\n",
14395 + inode->i_ino, mask, isdir, write_mask,
14396 + !!nd, nd ? !!nd->path.dentry : 0, nd ? !!nd->path.mnt : 0);
14398 + sb = inode->i_sb;
14399 + locked = silly_lock(inode, nd);
14400 + do_nd = (nd && locked >= 1);
14401 + mnt_flags = au_mntflags(sb);
14402 + dlgt = !!au_test_dlgt(mnt_flags);
14404 + if (!isdir || write_mask || au_test_dirperm1(mnt_flags)) {
14405 + h_inode = au_h_iptr(inode, au_ibstart(inode));
14406 + AuDebugOn(!h_inode
14407 + || ((h_inode->i_mode & S_IFMT)
14408 + != (inode->i_mode & S_IFMT)));
14410 + bindex = au_ibstart(inode);
14411 + LKTRTrace("b%d\n", bindex);
14414 + nd->path.mnt = au_sbr_mnt(sb, bindex);
14415 + nd->path.dentry = au_h_dptr(nd->path.dentry, bindex);
14416 + path_get(&nd->path);
14417 + err = h_permission(h_inode, mask, nd,
14418 + au_sbr_perm(sb, bindex), dlgt);
14419 + path_put(&nd->path);
14422 + AuDebugOn(nd && nd->path.mnt);
14423 + err = h_permission(h_inode, mask, nd,
14424 + au_sbr_perm(sb, bindex), dlgt);
14427 + if (write_mask && !err) {
14428 + /* test whether the upper writable branch exists */
14430 + for (; bindex >= 0; bindex--)
14431 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
14439 + /* non-write to dir */
14444 + path.dentry = NULL;
14447 + bend = au_ibend(inode);
14448 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
14449 + h_inode = au_h_iptr(inode, bindex);
14452 + AuDebugOn(!S_ISDIR(h_inode->i_mode));
14454 + LKTRTrace("b%d\n", bindex);
14456 + nd->path.mnt = au_sbr_mnt(sb, bindex);
14457 + nd->path.dentry = au_h_dptr(path.dentry, bindex);
14458 + path_get(&nd->path);
14459 + err = h_permission(h_inode, mask, nd,
14460 + au_sbr_perm(sb, bindex), dlgt);
14461 + path_put(&nd->path);
14463 + AuDebugOn(nd && nd->path.mnt);
14464 + err = h_permission(h_inode, mask, nd,
14465 + au_sbr_perm(sb, bindex), dlgt);
14472 + silly_unlock(locked, inode, nd);
14474 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
14478 +#endif /* KERNEL_VERSION(2, 6, 27) */
14480 +/* ---------------------------------------------------------------------- */
14482 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
14483 + struct nameidata *nd)
14485 + struct dentry *ret, *parent;
14486 + int err, npositive;
14487 + struct inode *inode, *h_inode;
14488 + struct nameidata tmp_nd, *ndp;
14489 + aufs_bindex_t bstart;
14490 + struct mutex *mtx;
14491 + struct super_block *sb;
14493 + LKTRTrace("dir %lu, %.*s, nd{0x%x}\n",
14494 + dir->i_ino, AuDLNPair(dentry), nd ? nd->flags : 0);
14495 + AuDebugOn(IS_ROOT(dentry));
14499 + si_read_lock(sb, AuLock_FLUSH);
14500 + err = au_alloc_dinfo(dentry);
14501 + ret = ERR_PTR(err);
14502 + if (unlikely(err))
14505 + /* nd can be NULL */
14506 + ndp = au_dup_nd(au_sbi(sb), &tmp_nd, nd);
14507 + parent = dentry->d_parent; /* dir inode is locked */
14508 + di_read_lock_parent(parent, AuLock_IR);
14509 + npositive = au_lkup_dentry(dentry, au_dbstart(parent), /*type*/0, ndp);
14510 + di_read_unlock(parent, AuLock_IR);
14512 + ret = ERR_PTR(err);
14513 + if (unlikely(err < 0))
14518 + bstart = au_dbstart(dentry);
14519 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
14520 + AuDebugOn(!h_inode);
14521 + if (!S_ISDIR(h_inode->i_mode)) {
14523 + * stop 'race'-ing between hardlinks under different
14526 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
14528 + inode = au_new_inode(dentry, /*must_new*/0);
14529 + mutex_unlock(mtx);
14531 + inode = au_new_inode(dentry, /*must_new*/0);
14532 + ret = (void *)inode;
14534 + if (!IS_ERR(inode)) {
14535 + ret = d_splice_alias(inode, dentry);
14536 + if (unlikely(IS_ERR(ret) && inode))
14537 + ii_write_unlock(inode);
14539 + && (nd->flags & LOOKUP_OPEN)
14540 + && nd->intent.open.file
14541 + && nd->intent.open.file->f_dentry);
14542 + au_store_fmode_exec(nd, inode);
14546 + di_write_unlock(dentry);
14548 + si_read_unlock(sb);
14549 + AuTraceErrPtr(ret);
14550 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
14555 +/* ---------------------------------------------------------------------- */
14558 + * decide the branch and the parent dir where we will create a new entry.
14559 + * returns new bindex or an error.
14560 + * copyup the parent dir if needed.
14562 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
14563 + struct au_wr_dir_args *args)
14566 + aufs_bindex_t bcpup, bstart, src_bstart;
14567 + struct super_block *sb;
14568 + struct dentry *parent;
14569 + struct au_sbinfo *sbinfo;
14570 + const int add_entry = au_ftest_wrdir(args->flags, ADD_ENTRY);
14572 + LKTRTrace("%.*s, src %p, {%d, 0x%x}\n",
14573 + AuDLNPair(dentry), src_dentry, args->force_btgt, args->flags);
14575 + sb = dentry->d_sb;
14576 + sbinfo = au_sbi(sb);
14577 + parent = dget_parent(dentry);
14578 + bstart = au_dbstart(dentry);
14580 + if (args->force_btgt < 0) {
14581 + if (src_dentry) {
14582 + src_bstart = au_dbstart(src_dentry);
14583 + if (src_bstart < bstart)
14584 + bcpup = src_bstart;
14585 + } else if (add_entry) {
14586 + err = AuWbrCreate(sbinfo, dentry,
14587 + au_ftest_wrdir(args->flags, ISDIR));
14591 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
14593 + err = AuWbrCopyup(sbinfo, dentry);
14595 + if (!IS_ROOT(dentry)) {
14596 + di_read_lock_parent(parent, !AuLock_IR);
14597 + err = AuWbrCopyup(sbinfo, dentry);
14598 + di_read_unlock(parent, !AuLock_IR);
14600 + err = AuWbrCopyup(sbinfo, dentry);
14603 + if (unlikely(err < 0))
14607 + bcpup = args->force_btgt;
14608 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
14610 + LKTRTrace("bstart %d, bcpup %d\n", bstart, bcpup);
14611 + if (bstart < bcpup)
14612 + au_update_dbrange(dentry, /*do_put_zero*/1);
14615 + if (bcpup == bstart)
14616 + goto out; /* success */
14618 + /* copyup the new parent into the branch we process */
14620 + au_update_dbstart(dentry);
14621 + IMustLock(parent->d_inode);
14622 + DiMustWriteLock(parent);
14623 + IiMustWriteLock(parent->d_inode);
14625 + di_write_lock_parent(parent);
14628 + if (!au_h_dptr(parent, bcpup)) {
14629 + if (bstart < bcpup)
14630 + err = au_cpdown_dirs(dentry, bcpup);
14632 + err = au_cpup_dirs(dentry, bcpup);
14634 + if (!err && add_entry) {
14635 + struct dentry *h_parent;
14636 + struct inode *h_dir;
14638 + h_parent = au_h_dptr(parent, bcpup);
14639 + AuDebugOn(!h_parent);
14640 + h_dir = h_parent->d_inode;
14641 + AuDebugOn(!h_dir);
14642 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
14643 + err = au_lkup_neg(dentry, bcpup);
14644 + mutex_unlock(&h_dir->i_mutex);
14645 + if (bstart < bcpup && au_dbstart(dentry) < 0) {
14646 + au_set_dbstart(dentry, 0);
14647 + au_update_dbrange(dentry, /*do_put_zero*/0);
14652 + di_write_unlock(parent);
14654 + err = bcpup; /* success */
14657 + LKTRTrace("err %d\n", err);
14662 +/* ---------------------------------------------------------------------- */
14664 +struct dentry *au_do_pinned_h_parent(struct au_pin1 *pin)
14666 + if (pin && pin->parent)
14667 + return au_h_dptr(pin->parent, pin->bindex);
14671 +void au_do_unpin(struct au_pin1 *p, struct au_pin1 *gp)
14674 + LKTRTrace("%.*s\n", AuDLNPair(p->dentry));
14675 + LKTRTrace("p{%d, %d, %d, %d, 0x%x}, gp %p\n",
14676 + p->lsc_di, p->lsc_hi, !!p->parent, !!p->h_dir, p->flags, gp);
14678 + if (au_ftest_pin(p->flags, MNT_WRITE))
14679 + au_br_drop_write(au_sbr(p->dentry->d_sb, p->bindex));
14680 + if (au_ftest_pin(p->flags, VFS_RENAME))
14681 + vfsub_unlock_rename_mutex(au_sbr_sb(p->dentry->d_sb,
14686 + mutex_unlock(&p->h_dir->i_mutex);
14688 + au_do_unpin(gp, NULL);
14689 + if (!au_ftest_pin(p->flags, DI_LOCKED))
14690 + di_read_unlock(p->parent, AuLock_IR);
14693 + p->parent = NULL;
14697 +int au_do_pin(struct au_pin1 *p, struct au_pin1 *gp)
14700 + struct dentry *h_dentry;
14702 + LKTRTrace("%.*s, %d, b%d, 0x%x\n",
14703 + AuDLNPair(p->dentry), !!gp, p->bindex, p->flags);
14704 + AuDebugOn(au_ftest_pin(p->flags, DO_GPARENT) && !gp);
14705 + /* AuDebugOn(!do_gp && gp); */
14708 + if (IS_ROOT(p->dentry)) {
14709 + if (au_ftest_pin(p->flags, VFS_RENAME))
14710 + vfsub_lock_rename_mutex(au_sbr_sb(p->dentry->d_sb,
14712 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
14713 + err = au_br_want_write(au_sbr(p->dentry->d_sb,
14715 + if (unlikely(err))
14716 + au_fclr_pin(p->flags, MNT_WRITE);
14722 + if (p->bindex <= au_dbend(p->dentry))
14723 + h_dentry = au_h_dptr(p->dentry, p->bindex);
14725 + p->parent = dget_parent(p->dentry);
14726 + if (!au_ftest_pin(p->flags, DI_LOCKED))
14727 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
14729 + DiMustAnyLock(p->parent);
14730 + AuDebugOn(!p->parent->d_inode);
14731 + p->h_dir = au_igrab(au_h_iptr(p->parent->d_inode, p->bindex));
14733 + if (unlikely(au_ftest_pin(p->flags, VERIFY) && !p->h_dir)) {
14735 + if (!au_ftest_pin(p->flags, DI_LOCKED))
14736 + di_read_unlock(p->parent, AuLock_IR);
14738 + p->parent = NULL;
14742 + if (au_ftest_pin(p->flags, DO_GPARENT)) {
14743 + gp->dentry = p->parent;
14744 + err = au_do_pin(gp, NULL);
14745 + if (unlikely(err))
14746 + gp->dentry = NULL;
14748 + if (au_ftest_pin(p->flags, VFS_RENAME))
14749 + vfsub_lock_rename_mutex(p->h_dir->i_sb);
14750 + mutex_lock_nested(&p->h_dir->i_mutex, p->lsc_hi);
14752 + /* todo: call d_revalidate() here? */
14754 + if (h_dentry && h_dentry->d_op && h_dentry->d_op->d_revalidate
14755 + && !h_dentry->d_op->d_revalidate(h_dentry, NULL))
14759 + || !au_ftest_pin(p->flags, VERIFY)
14760 + || !au_verify_parent(h_dentry, p->h_dir)) {
14761 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
14762 + err = au_br_want_write(au_sbr(p->dentry->d_sb,
14764 + if (unlikely(err))
14765 + au_fclr_pin(p->flags, MNT_WRITE);
14768 + goto out; /* success */
14773 + AuDbgDentry(p->dentry);
14774 + AuDbgDentry(h_dentry);
14775 + AuDbgDentry(p->parent);
14776 + AuDbgInode(p->h_dir);
14778 + AuDbgDentry(h_dentry->d_parent);
14780 + au_do_unpin(p, gp);
14781 + if (au_ftest_pin(p->flags, DO_GPARENT))
14782 + gp->dentry = NULL;
14789 +void au_pin_init(struct au_pin *args, struct dentry *dentry,
14790 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
14791 + unsigned char flags)
14793 + struct au_pin1 *p;
14798 + memset(args, 0, sizeof(*args));
14799 + p = args->pin + AuPin_PARENT;
14800 + p->dentry = dentry;
14801 + p->lsc_di = lsc_di;
14802 + p->lsc_hi = lsc_hi;
14803 + p->flags = flags;
14804 + p->bindex = bindex;
14805 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE))
14806 + au_fset_pin(p->flags, VERIFY);
14807 + if (!au_ftest_pin(flags, DO_GPARENT))
14811 + p = au_pin_gp(args);
14813 + p->lsc_di = lsc_di + 1; /* child first */
14814 + p->lsc_hi = lsc_hi - 1; /* parent first */
14815 + p->bindex = bindex;
14816 + p->flags = f & ~(AuPin_MNT_WRITE
14817 + | AuPin_DO_GPARENT
14818 + | AuPin_DI_LOCKED);
14822 +int au_pin(struct au_pin *args, struct dentry *dentry, aufs_bindex_t bindex,
14823 + unsigned char flags)
14825 + LKTRTrace("%.*s, b%d, 0x%x\n",
14826 + AuDLNPair(dentry), bindex, flags);
14828 + au_pin_init(args, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
14830 + return au_do_pin(args->pin + AuPin_PARENT, au_pin_gp(args));
14833 +/* ---------------------------------------------------------------------- */
14835 +struct au_icpup_args {
14836 + unsigned char isdir, hinotify, did_cpup; /* flags */
14837 + unsigned char pin_flags;
14838 + aufs_bindex_t btgt;
14839 + struct au_pin pin;
14840 + struct au_hin_ignore ign[2];
14841 + struct vfsub_args vargs;
14842 + struct dentry *h_dentry;
14843 + struct inode *h_inode;
14846 +/* todo: refine it */
14847 +static int au_lock_and_icpup(struct dentry *dentry, loff_t sz,
14848 + struct au_icpup_args *a)
14851 + aufs_bindex_t bstart;
14852 + struct super_block *sb;
14853 + struct dentry *hi_wh, *parent;
14854 + struct inode *inode;
14855 + struct au_wr_dir_args wr_dir_args = {
14856 + .force_btgt = -1,
14860 + LKTRTrace("%.*s, %lld\n", AuDLNPair(dentry), sz);
14862 + di_write_lock_child(dentry);
14863 + bstart = au_dbstart(dentry);
14864 + sb = dentry->d_sb;
14865 + inode = dentry->d_inode;
14866 + a->isdir = !!S_ISDIR(inode->i_mode);
14868 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
14869 + /* plink or hi_wh() */
14870 + if (bstart != au_ibstart(inode))
14871 + wr_dir_args.force_btgt = au_ibstart(inode);
14872 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
14873 + if (unlikely(err < 0))
14876 + a->did_cpup = (err != bstart);
14879 + /* crazy udba locks */
14880 + a->pin_flags = AuPin_MNT_WRITE;
14881 + a->hinotify = !!au_opt_test(au_mntflags(sb), UDBA_INOTIFY);
14883 + au_fset_pin(a->pin_flags, DO_GPARENT);
14885 + if (!IS_ROOT(dentry)) {
14886 + au_fset_pin(a->pin_flags, DI_LOCKED);
14887 + parent = dget_parent(dentry);
14888 + di_write_lock_parent(parent);
14890 + err = au_pin(&a->pin, dentry, a->btgt, a->pin_flags);
14891 + if (unlikely(err)) {
14893 + di_write_unlock(parent);
14898 + a->h_dentry = au_h_dptr(dentry, bstart);
14899 + a->h_inode = a->h_dentry->d_inode;
14900 + AuDebugOn(!a->h_inode);
14901 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
14902 + if (!a->did_cpup) {
14903 + au_unpin_gp(&a->pin);
14905 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
14906 + di_downgrade_lock(parent, AuLock_IR);
14909 + goto out; /* success */
14913 + if (!d_unhashed(dentry)) {
14915 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
14916 + di_downgrade_lock(parent, AuLock_IR);
14919 + err = au_sio_cpup_simple(dentry, a->btgt, sz, AuCpup_DTIME);
14921 + a->h_dentry = au_h_dptr(dentry, a->btgt);
14923 + hi_wh = au_hi_wh(inode, a->btgt);
14925 + err = au_sio_cpup_wh(dentry, a->btgt, sz,
14928 + hi_wh = au_hi_wh(inode, a->btgt);
14929 + /* todo: revalidate hi_wh? */
14932 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
14933 + di_downgrade_lock(parent, AuLock_IR);
14937 + a->h_dentry = au_h_dptr(dentry, a->btgt);
14939 + a->h_dentry = hi_wh; /* do not dget here */
14942 + mutex_unlock(&a->h_inode->i_mutex);
14943 + a->h_inode = a->h_dentry->d_inode;
14944 + AuDebugOn(!a->h_inode);
14946 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
14947 + au_unpin_gp(&a->pin);
14948 + goto out; /* success */
14951 + au_unpin(&a->pin);
14954 + di_write_unlock(dentry);
14960 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
14963 + struct inode *inode;
14964 + struct super_block *sb;
14966 + struct file *file;
14968 + struct au_icpup_args *a;
14970 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
14971 + inode = dentry->d_inode;
14972 + IMustLock(inode);
14975 + a = kzalloc(sizeof(*a), GFP_NOFS);
14976 + if (unlikely(!a))
14980 + sb = dentry->d_sb;
14981 + si_read_lock(sb, AuLock_FLUSH);
14982 + vfsub_args_init(&a->vargs, a->ign, au_test_dlgt(au_mntflags(sb)), 0);
14984 + if (ia->ia_valid & ATTR_FILE) {
14985 + /* currently ftruncate(2) only */
14986 + file = ia->ia_file;
14987 + fi_write_lock(file);
14988 + ia->ia_file = au_h_fptr(file, au_fbstart(file));
14992 + if ((ia->ia_valid & ATTR_SIZE)
14993 + && ia->ia_size < i_size_read(inode))
14994 + sz = ia->ia_size;
14995 + err = au_lock_and_icpup(dentry, sz, a);
14996 + if (unlikely(err < 0))
14998 + if (a->did_cpup) {
14999 + ia->ia_file = NULL;
15000 + ia->ia_valid &= ~ATTR_FILE;
15003 + if ((ia->ia_valid & ATTR_SIZE)
15004 + && ia->ia_size < i_size_read(inode)) {
15005 + err = vmtruncate(inode, ia->ia_size);
15006 + if (unlikely(err))
15010 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
15011 + ia->ia_valid &= ~ATTR_MODE;
15014 + if (a->hinotify) {
15015 + events = vfsub_events_notify_change(ia);
15018 + vfsub_ign_hinode(&a->vargs, events,
15019 + au_hi(inode, a->btgt));
15020 + vfsub_ign_hinode(&a->vargs, events,
15021 + au_pinned_hdir(&a->pin));
15024 + err = vfsub_notify_change(a->h_dentry, ia, &a->vargs);
15026 + au_cpup_attr_changeable(inode);
15029 + mutex_unlock(&a->h_inode->i_mutex);
15030 + au_unpin(&a->pin);
15031 + di_write_unlock(dentry);
15034 + fi_write_unlock(file);
15035 + ia->ia_file = file;
15036 + ia->ia_valid |= ATTR_FILE;
15038 + si_read_unlock(sb);
15042 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
15047 +/* ---------------------------------------------------------------------- */
15049 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
15052 + struct super_block *sb;
15053 + struct dentry *h_dentry;
15055 + LKTRTrace("%.*s, b%d, %d\n", AuDLNPair(dentry), bindex, bufsiz);
15057 + h_dentry = au_h_dptr(dentry, bindex);
15058 + if (unlikely(/* !h_dentry
15059 + || !h_dentry->d_inode
15061 + !h_dentry->d_inode->i_op
15062 + || !h_dentry->d_inode->i_op->readlink))
15065 + sb = dentry->d_sb;
15066 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
15067 + touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
15068 + au_update_fuse_h_inode(NULL, h_dentry); /*ignore*/
15069 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
15071 + return h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
15074 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
15078 + LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), bufsiz);
15080 + aufs_read_lock(dentry, AuLock_IR);
15081 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
15082 + aufs_read_unlock(dentry, AuLock_IR);
15084 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
15089 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
15093 + mm_segment_t old_fs;
15095 + LKTRTrace("%.*s, nd %.*s\n",
15096 + AuDLNPair(dentry), AuDLNPair(nd->path.dentry));
15099 + buf = __getname();
15100 + if (unlikely(!buf))
15103 + aufs_read_lock(dentry, AuLock_IR);
15104 + old_fs = get_fs();
15105 + set_fs(KERNEL_DS);
15106 + err = h_readlink(dentry, au_dbstart(dentry), (char __user *)buf,
15109 + aufs_read_unlock(dentry, AuLock_IR);
15113 + /* will be freed by put_link */
15114 + nd_set_link(nd, buf);
15115 + return NULL; /* success */
15120 + path_put(&nd->path);
15122 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
15124 + return ERR_PTR(err);
15127 +static void aufs_put_link(struct dentry *dentry, struct nameidata *nd,
15130 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
15131 + __putname(nd_get_link(nd));
15134 +/* ---------------------------------------------------------------------- */
15136 +static void aufs_truncate_range(struct inode *inode, loff_t start, loff_t end)
15141 +/* ---------------------------------------------------------------------- */
15143 +struct inode_operations aufs_symlink_iop = {
15144 + .permission = aufs_permission,
15145 + .setattr = aufs_setattr,
15146 +#ifdef CONFIG_AUFS_GETATTR
15147 + .getattr = aufs_getattr,
15150 + .readlink = aufs_readlink,
15151 + .follow_link = aufs_follow_link,
15152 + .put_link = aufs_put_link
15155 +struct inode_operations aufs_dir_iop = {
15156 + .create = aufs_create,
15157 + .lookup = aufs_lookup,
15158 + .link = aufs_link,
15159 + .unlink = aufs_unlink,
15160 + .symlink = aufs_symlink,
15161 + .mkdir = aufs_mkdir,
15162 + .rmdir = aufs_rmdir,
15163 + .mknod = aufs_mknod,
15164 + .rename = aufs_rename,
15166 + .permission = aufs_permission,
15167 + .setattr = aufs_setattr,
15168 +#ifdef CONFIG_AUFS_GETATTR
15169 + .getattr = aufs_getattr,
15172 +#if 0 /* reserved for future use */
15173 + .setxattr = aufs_setxattr,
15174 + .getxattr = aufs_getxattr,
15175 + .listxattr = aufs_listxattr,
15176 + .removexattr = aufs_removexattr
15180 +struct inode_operations aufs_iop = {
15181 + .permission = aufs_permission,
15182 + .setattr = aufs_setattr,
15183 +#ifdef CONFIG_AUFS_GETATTR
15184 + .getattr = aufs_getattr,
15187 +#if 0 /* reserved for future use */
15188 + .setxattr = aufs_setxattr,
15189 + .getxattr = aufs_getxattr,
15190 + .listxattr = aufs_listxattr,
15191 + .removexattr = aufs_removexattr,
15194 + .truncate_range = aufs_truncate_range
15196 diff -urN linux/fs/aufs/i_op_del.c linux-aufs/fs/aufs/i_op_del.c
15197 --- linux/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
15198 +++ linux-aufs/fs/aufs/i_op_del.c 2009-03-12 16:18:04.000000000 +0100
15201 + * Copyright (C) 2005-2009 Junjiro Okajima
15203 + * This program, aufs is free software; you can redistribute it and/or modify
15204 + * it under the terms of the GNU General Public License as published by
15205 + * the Free Software Foundation; either version 2 of the License, or
15206 + * (at your option) any later version.
15208 + * This program is distributed in the hope that it will be useful,
15209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15211 + * GNU General Public License for more details.
15213 + * You should have received a copy of the GNU General Public License
15214 + * along with this program; if not, write to the Free Software
15215 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15219 + * inode operations (del entry)
15227 + * 0: wh is unnecessary
15228 + * plus: wh is necessary
15231 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
15233 + int need_wh, err;
15234 + aufs_bindex_t bstart;
15235 + struct dentry *h_dentry;
15236 + struct super_block *sb;
15238 + LKTRTrace("%.*s, isdir %d, *bcpup %d\n",
15239 + AuDLNPair(dentry), isdir, *bcpup);
15240 + sb = dentry->d_sb;
15242 + bstart = au_dbstart(dentry);
15243 + LKTRTrace("bcpup %d, bstart %d\n", *bcpup, bstart);
15244 + h_dentry = au_h_dptr(dentry, bstart);
15245 + if (*bcpup < 0) {
15247 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
15248 + err = AuWbrCopyup(au_sbi(sb), dentry);
15250 + if (unlikely(err < 0))
15254 + AuDebugOn(bstart < *bcpup
15255 + || au_test_ro(sb, *bcpup, dentry->d_inode));
15256 + LKTRTrace("bcpup %d, bstart %d\n", *bcpup, bstart);
15258 + if (*bcpup != bstart) {
15259 + err = au_cpup_dirs(dentry, *bcpup);
15260 + if (unlikely(err))
15264 + aufs_bindex_t old_bend, new_bend, bdiropq = -1;
15265 + old_bend = au_dbend(dentry);
15267 + bdiropq = au_dbdiropq(dentry);
15268 + au_set_dbdiropq(dentry, -1);
15270 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0,
15274 + au_set_dbdiropq(dentry, bdiropq);
15275 + if (unlikely(err < 0))
15277 + new_bend = au_dbend(dentry);
15278 + if (!need_wh && old_bend != new_bend) {
15279 + au_set_h_dptr(dentry, new_bend, NULL);
15280 + au_set_dbend(dentry, old_bend);
15281 +#if 0 /* todo: remove this? */
15282 + } else if (!au_h_dptr(dentry, new_bend)->d_inode) {
15283 + LKTRTrace("negative\n");
15284 + au_set_h_dptr(dentry, new_bend, NULL);
15285 + au_set_dbend(dentry, old_bend);
15290 + LKTRTrace("need_wh %d\n", need_wh);
15299 + * simple tests for the removal inode operations.
15300 + * following the checks in vfs, plus the parent-child relationship.
15302 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
15303 + struct dentry *h_parent, int isdir, struct au_ndx *ndx)
15306 + struct super_block *sb;
15307 + struct dentry *h_dentry;
15308 + struct inode *h_inode;
15311 + LKTRTrace("%.*s/%.*s, b%d, dir %d\n",
15312 + AuDLNPair(h_parent), AuDLNPair(dentry), bindex, isdir);
15314 + sb = dentry->d_sb;
15315 + exist = !!dentry->d_inode;
15316 + h_dentry = au_h_dptr(dentry, bindex);
15317 + h_inode = h_dentry->d_inode;
15320 + if (unlikely(!h_inode || !h_inode->i_nlink))
15323 + h_mode = h_inode->i_mode;
15326 + if (unlikely(S_ISDIR(h_mode)))
15328 + } else if (unlikely(!S_ISDIR(h_mode))) {
15333 + /* rename(2) case */
15335 + if (unlikely(h_inode))
15340 + /* expected parent dir is locked */
15341 + if (unlikely(h_parent != h_dentry->d_parent))
15346 + * some filesystem may unlink a dir and corrupt its consistency.
15347 + * so let's try heavy test.
15349 + if (1 /*au_opt_test(au_mntflags(sb), UDBA_INOTIFY)*/) {
15350 + struct dentry *h_latest;
15351 + struct qstr *qstr = &dentry->d_name;
15354 + if (unlikely(au_test_h_perm(h_parent->d_inode,
15355 + MAY_EXEC | MAY_WRITE,
15356 + au_ftest_ndx(ndx->flags, DLGT))))
15359 + h_latest = au_sio_lkup_one(qstr->name, h_parent, qstr->len,
15362 + if (IS_ERR(h_latest))
15365 + if (h_latest == h_dentry)
15374 +static struct dentry *
15375 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
15376 + struct au_dtime *dt, struct au_pin *pin)
15378 + struct dentry *wh_dentry, *h_parent;
15379 + struct super_block *sb;
15380 + int err, need_wh;
15381 + unsigned int mnt_flags;
15382 + unsigned char pin_flags;
15383 + aufs_bindex_t bcpup;
15384 + struct au_ndx ndx;
15386 + LKTRTrace("%.*s, isdir %d\n", AuDLNPair(dentry), isdir);
15388 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
15390 + wh_dentry = ERR_PTR(err);
15391 + if (unlikely(err < 0))
15394 + sb = dentry->d_sb;
15395 + mnt_flags = au_mntflags(sb);
15397 + pin_flags = AuPin_DI_LOCKED | AuPin_MNT_WRITE;
15398 + if (au_opt_test(mnt_flags, UDBA_INOTIFY))
15399 + au_fset_pin(pin_flags, DO_GPARENT);
15400 + err = au_pin(pin, dentry, bcpup, pin_flags);
15401 + wh_dentry = ERR_PTR(err);
15402 + if (unlikely(err))
15404 + h_parent = au_pinned_h_parent(pin);
15405 + if (!au_opt_test(mnt_flags, UDBA_NONE) && au_dbstart(dentry) == bcpup) {
15406 + ndx.nfsmnt = au_nfsmnt(sb, bcpup);
15408 + if (au_test_dlgt(mnt_flags))
15409 + au_fset_ndx(ndx.flags, DLGT);
15411 + /* ndx.br = au_sbr(sb, bcpup); */
15412 + /* ndx.nd_file = NULL; */
15413 + err = au_may_del(dentry, bcpup, h_parent, isdir, &ndx);
15414 + wh_dentry = ERR_PTR(err);
15415 + if (unlikely(err))
15419 + au_dtime_store(dt, au_pinned_parent(pin), h_parent, au_pinned_hdir(pin),
15420 + au_pinned_hgdir(pin));
15421 + wh_dentry = NULL;
15423 + goto out; /* success, no need to create whiteout */
15425 + ndx.nfsmnt = au_nfsmnt(sb, bcpup);
15427 + if (au_test_dlgt(mnt_flags))
15428 + au_fset_ndx(ndx.flags, DLGT);
15430 + /* ndx.br = NULL; */
15431 + wh_dentry = au_wh_create(dentry, bcpup, h_parent, &ndx);
15432 + if (!IS_ERR(wh_dentry))
15433 + goto out; /* success */
15434 + /* returns with the parent is locked and wh_dentry is DGETed */
15439 + AuTraceErrPtr(wh_dentry);
15440 + return wh_dentry;
15443 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
15444 + struct au_nhash *whlist, struct inode *dir)
15446 + int rmdir_later, err;
15447 + struct dentry *h_dentry;
15448 + struct inode *inode, *h_inode;
15449 + struct super_block *sb;
15451 + LKTRTrace("%.*s, b%d\n", AuDLNPair(dentry), bindex);
15455 + sb = dentry->d_sb;
15456 + if (au_opt_test(au_mntflags(sb), UDBA_INOTIFY)) {
15457 + inode = dentry->d_inode;
15458 + h_inode = au_h_iptr(inode, bindex);
15459 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
15461 + h_dentry = au_h_dptr(dentry, bindex);
15462 + err = au_whtmp_ren(dir, bindex, h_dentry);
15464 + /* todo: bad approach? */
15466 + au_hin_suspend(au_hi(inode, bindex));
15467 + mutex_unlock(&h_inode->i_mutex);
15469 + if (unlikely(err))
15472 + if (!au_test_nfs(h_dentry->d_sb)) {
15473 + const int dirwh = au_sbi(sb)->si_dirwh;
15474 + rmdir_later = (dirwh <= 1);
15475 + if (!rmdir_later)
15476 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
15479 + return rmdir_later;
15482 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
15483 + if (unlikely(err)) {
15484 + AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
15485 + AuDLNPair(h_dentry), bindex, err);
15486 + /* we do not revert the inotify watch */
15495 +static void epilog(struct inode *dir, struct dentry *dentry,
15496 + aufs_bindex_t bindex)
15498 + /* todo: unnecessary? */
15500 + dentry->d_inode->i_ctime = dir->i_ctime;
15502 + if (atomic_read(&dentry->d_count) == 1) {
15503 + au_set_h_dptr(dentry, au_dbstart(dentry), NULL);
15504 + au_update_dbstart(dentry);
15506 + if (au_ibstart(dir) == bindex)
15507 + au_cpup_attr_timesizes(dir);
15508 + dir->i_version++;
15511 +/* revert flags */
15512 +#define AuRev_DLGT 1
15513 +#define au_ftest_rev(flags, name) ((flags) & AuRev_##name)
15514 +#define au_fset_rev(flags, name) { (flags) |= AuRev_##name; }
15515 +#define au_fclr_rev(flags, name) { (flags) &= ~AuRev_##name; }
15516 +#ifndef CONFIG_AUFS_DLGT
15518 +#define AuRev_DLGT 0
15521 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bwh,
15522 + struct dentry *wh_dentry, struct dentry *dentry,
15523 + struct au_dtime *dt, unsigned int flags)
15527 + rerr = au_wh_unlink_dentry(au_hi(dir, bwh), wh_dentry, dentry,
15528 + au_ftest_rev(flags, DLGT));
15530 + au_set_dbwh(dentry, bwh);
15531 + au_dtime_revert(dt);
15535 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
15536 + AuDLNPair(dentry), err, rerr);
15540 +/* ---------------------------------------------------------------------- */
15542 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
15545 + struct inode *inode, *h_dir;
15546 + struct dentry *parent, *wh_dentry, *h_dentry;
15547 + struct au_dtime dt;
15548 + aufs_bindex_t bwh, bindex, bstart;
15549 + unsigned char dlgt;
15550 + struct super_block *sb;
15551 + struct au_hin_ignore ign;
15552 + struct vfsub_args vargs;
15553 + struct au_pin pin;
15555 + LKTRTrace("i%lu, %.*s\n", dir->i_ino, AuDLNPair(dentry));
15557 + inode = dentry->d_inode;
15558 + if (unlikely(!inode))
15559 + return -ENOENT; /* possible? */
15560 + IMustLock(inode);
15562 + aufs_read_lock(dentry, AuLock_DW);
15563 + parent = dentry->d_parent; /* dir inode is locked */
15564 + di_write_lock_parent(parent);
15566 + bstart = au_dbstart(dentry);
15567 + bwh = au_dbwh(dentry);
15569 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &dt, &pin);
15570 + err = PTR_ERR(wh_dentry);
15571 + if (IS_ERR(wh_dentry))
15575 + dlgt = !!au_test_dlgt(au_mntflags(sb));
15576 + AuDebugOn(au_dbstart(dentry) != bstart);
15577 + h_dentry = au_h_dptr(dentry, bstart);
15580 + if (bindex == bstart) {
15581 + vfsub_args_init(&vargs, &ign, dlgt, 0);
15582 + vfsub_ign_hinode(&vargs, IN_DELETE, au_pinned_hdir(&pin));
15583 + h_dir = au_pinned_h_dir(&pin);
15584 + err = vfsub_unlink(h_dir, h_dentry, &vargs);
15586 + /* dir inode is locked */
15587 + AuDebugOn(!wh_dentry
15588 + || wh_dentry->d_parent != au_h_dptr(parent, bindex));
15589 + h_dir = wh_dentry->d_parent->d_inode;
15590 + IMustLock(h_dir);
15595 + drop_nlink(inode);
15596 +#if 0 /* todo: update plink? */
15597 + if (!inode->i_nlink
15598 + && au_opt_test(p->a.mnt_flags, PLINK)
15599 + && au_plink_test(sb, inode)
15600 + /* && atomic_read(&inode->i_count) == 2) */) {
15607 + * although this is not a dir,
15608 + * set it here since we need to detect the dead inode.
15610 + if (!inode->i_nlink)
15611 + inode->i_flags |= S_DEAD;
15612 + epilog(dir, dentry, bindex);
15614 + /* update target timestamps */
15615 + if (bindex == bstart) {
15616 + au_update_fuse_h_inode(NULL, h_dentry); /*ignore*/
15617 + inode->i_ctime = h_dentry->d_inode->i_ctime;
15619 + /* todo: this timestamp may be reverted later */
15620 + inode->i_ctime = h_dir->i_ctime;
15621 + goto out_unlock; /* success */
15627 + unsigned int rev_flags;
15631 + au_fset_rev(rev_flags, DLGT);
15632 + rerr = do_revert(err, dir, bwh, wh_dentry, dentry, &dt,
15643 + di_write_unlock(parent);
15644 + aufs_read_unlock(dentry, AuLock_DW);
15646 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
15651 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
15653 + int err, rmdir_later;
15654 + struct inode *inode;
15655 + struct dentry *parent, *wh_dentry, *h_dentry;
15656 + struct au_dtime dt;
15657 + aufs_bindex_t bwh, bindex, bstart;
15658 + struct au_whtmp_rmdir_args *args;
15659 + struct au_nhash *whlist;
15660 + struct super_block *sb;
15661 + unsigned int mnt_flags;
15662 + struct au_pin pin;
15664 + LKTRTrace("i%lu, %.*s\n", dir->i_ino, AuDLNPair(dentry));
15666 + inode = dentry->d_inode;
15667 + err = -ENOENT; /* possible? */
15668 + if (unlikely(!inode))
15670 + IMustLock(inode);
15672 + whlist = au_nhash_new(GFP_NOFS);
15673 + err = PTR_ERR(whlist);
15674 + if (IS_ERR(whlist))
15678 + args = kmalloc(sizeof(*args), GFP_NOFS);
15679 + if (unlikely(!args))
15682 + aufs_read_lock(dentry, AuLock_DW);
15683 + parent = dentry->d_parent; /* dir inode is locked */
15684 + di_write_lock_parent(parent);
15685 + err = au_test_empty(dentry, whlist);
15686 + if (unlikely(err))
15689 + bstart = au_dbstart(dentry);
15690 + bwh = au_dbwh(dentry);
15692 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &dt, &pin);
15693 + err = PTR_ERR(wh_dentry);
15694 + if (IS_ERR(wh_dentry))
15697 + AuDebugOn(au_dbstart(dentry) != bstart);
15698 + h_dentry = au_h_dptr(dentry, bstart);
15702 + if (bindex == bstart) {
15703 + err = renwh_and_rmdir(dentry, bstart, whlist, dir);
15705 + rmdir_later = err;
15709 + /* dir inode is locked */
15710 + AuDebugOn(!wh_dentry
15711 + || wh_dentry->d_parent != au_h_dptr(parent, bindex));
15712 + IMustLock(wh_dentry->d_parent->d_inode);
15716 + sb = dentry->d_sb;
15717 + mnt_flags = au_mntflags(sb);
15719 + if (au_opt_test(mnt_flags, UDBA_INOTIFY) && rmdir_later)
15720 + au_reset_hinotify(inode, /*flags*/0);
15721 + clear_nlink(inode);
15722 + inode->i_flags |= S_DEAD;
15723 + au_set_dbdiropq(dentry, -1);
15724 + epilog(dir, dentry, bindex);
15726 + if (rmdir_later) {
15727 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, whlist,
15732 + goto out_unlock; /* success */
15736 + LKTRLabel(revert);
15739 + unsigned int rev_flags;
15742 + if (au_test_dlgt(mnt_flags))
15743 + au_fset_rev(rev_flags, DLGT);
15744 + rerr = do_revert(err, dir, bwh, wh_dentry, dentry, &dt,
15755 + di_write_unlock(parent);
15756 + aufs_read_unlock(dentry, AuLock_DW);
15759 + au_nhash_del(whlist);
15762 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
15766 diff -urN linux/fs/aufs/i_op_ren.c linux-aufs/fs/aufs/i_op_ren.c
15767 --- linux/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
15768 +++ linux-aufs/fs/aufs/i_op_ren.c 2009-03-12 16:18:04.000000000 +0100
15771 + * Copyright (C) 2005-2009 Junjiro Okajima
15773 + * This program, aufs is free software; you can redistribute it and/or modify
15774 + * it under the terms of the GNU General Public License as published by
15775 + * the Free Software Foundation; either version 2 of the License, or
15776 + * (at your option) any later version.
15778 + * This program is distributed in the hope that it will be useful,
15779 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15780 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15781 + * GNU General Public License for more details.
15783 + * You should have received a copy of the GNU General Public License
15784 + * along with this program; if not, write to the Free Software
15785 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15789 + * inode operation (rename entry)
15790 + * todo: this is crazy monster
15797 +enum { SRC, DST };
15799 +#define AuRen_ISDIR 1
15800 +#define AuRen_ISSAMEDIR (1 << 1)
15801 +#define AuRen_WHSRC (1 << 2)
15802 +#define AuRen_WHDST (1 << 3)
15803 +#define AuRen_DLGT (1 << 4)
15804 +#define AuRen_VFSLOCK (1 << 5)
15805 +#define AuRen_PINNED (1 << 6)
15806 +#define AuRen_MNT_WRITE (1 << 7)
15807 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
15808 +#define au_fset_ren(flags, name) { (flags) |= AuRen_##name; }
15809 +#define au_fclr_ren(flags, name) { (flags) &= ~AuRen_##name; }
15810 +#ifndef CONFIG_AUFS_DLGT
15812 +#define AuRen_DLGT 0
15815 +struct au_ren_args {
15816 + /* original args */
15817 + struct dentry *src_dentry, *dentry;
15818 + struct inode *src_dir, *dir;
15820 + struct dentry *h_dentry[2], *h_parent[2], *h_trap, *h_locked[2];
15821 + /* todo: remove them */
15822 + struct dentry *parent[2], *gparent[2];
15823 + struct au_pin pin[2];
15824 + struct au_nhash whlist;
15825 + aufs_bindex_t btgt, bstart[2];
15826 + /* do_rename() only */
15827 + unsigned char need_diropq, bycpup;
15828 + struct super_block *sb;
15829 + unsigned int flags;
15830 + unsigned int mnt_flags;
15831 + struct au_ndx ndx;
15833 + /* do_rename() only */
15834 +#ifdef CONFIG_AUFS_BR_NFS
15835 + struct au_hin_ignore ign[3];
15837 + struct au_hin_ignore ign[2];
15839 + struct vfsub_args vargs;
15840 + struct au_whtmp_rmdir_args *thargs;
15841 + struct dentry *wh_dentry[2], *h_dst, *h_src;
15844 +/* ---------------------------------------------------------------------- */
15846 +#define RevertFailure(fmt, args...) do { \
15847 + AuIOErrWhck("revert failure: " fmt " (%d, %d)\n", \
15848 + ##args, err, rerr); \
15852 +static noinline_for_stack
15853 +void au_ren_rev_diropq(int err, struct au_ren_args *a)
15856 + struct mutex *h_mtx;
15858 + /* lock inode simply since inotify is not set to h_inode. */
15859 + h_mtx = &au_h_dptr(a->src_dentry, a->btgt)->d_inode->i_mutex;
15860 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15861 + rerr = au_diropq_remove(a->src_dentry, a->btgt,
15862 + au_ftest_ren(a->flags, DLGT));
15863 + mutex_unlock(h_mtx);
15865 + RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
15868 +static noinline_for_stack
15869 +void au_ren_rev_rename(int err, struct au_ren_args *a)
15872 + struct dentry *h_d;
15873 + struct qstr *name = &a->src_dentry->d_name;
15875 + h_d = au_lkup_one(name->name, a->h_parent[SRC], name->len, &a->ndx);
15876 + rerr = PTR_ERR(h_d);
15877 + if (IS_ERR(h_d)) {
15878 + RevertFailure("au_lkup_one %.*s", AuDLNPair(a->src_dentry));
15882 + AuDebugOn(h_d->d_inode);
15883 + vfsub_args_reinit(&a->vargs);
15884 + vfsub_ign_hinode(&a->vargs, IN_MOVED_FROM,
15885 + au_pinned_hdir(a->pin + DST));
15886 + vfsub_ign_hinode(&a->vargs, IN_MOVED_TO, au_pinned_hdir(a->pin + SRC));
15887 + rerr = vfsub_rename(au_pinned_h_dir(a->pin + DST),
15888 + au_h_dptr(a->src_dentry, a->btgt),
15889 + au_pinned_h_dir(a->pin + SRC), h_d, &a->vargs);
15892 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
15894 + RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
15897 +static noinline_for_stack
15898 +void au_ren_rev_cpup(int err, struct au_ren_args *a)
15902 + vfsub_args_reinit(&a->vargs);
15903 + vfsub_ign_hinode(&a->vargs, IN_DELETE, au_pinned_hdir(a->pin + DST));
15904 + rerr = vfsub_unlink(au_pinned_h_dir(a->pin + DST), a->h_dentry[DST],
15906 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
15907 + au_set_dbstart(a->src_dentry, a->bstart[SRC]);
15909 + RevertFailure("unlink %.*s", AuDLNPair(a->h_dentry[DST]));
15912 +static noinline_for_stack
15913 +void au_ren_rev_whtmp(int err, struct au_ren_args *a)
15916 + struct dentry *h_d;
15917 + struct mutex *h_mtx;
15918 + struct qstr *name = &a->dentry->d_name;
15920 + h_d = au_lkup_one(name->name, a->h_parent[DST], name->len, &a->ndx);
15921 + rerr = PTR_ERR(h_d);
15922 + if (IS_ERR(h_d)) {
15923 + RevertFailure("lookup %.*s", AuLNPair(name));
15926 + if (h_d->d_inode) {
15932 + h_mtx = &a->h_dst->d_inode->i_mutex;
15933 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15934 + au_hin_resume(au_hi(a->src_dentry->d_inode, a->btgt));
15935 + mutex_unlock(h_mtx);
15936 + vfsub_args_reinit(&a->vargs);
15937 + vfsub_ign_hinode(&a->vargs, IN_MOVED_TO | IN_MOVED_FROM,
15938 + au_pinned_hdir(a->pin + DST));
15939 + rerr = vfsub_rename(au_pinned_h_dir(a->pin + DST), a->h_dst,
15940 + au_pinned_h_dir(a->pin + DST), h_d, &a->vargs);
15944 + au_set_h_dptr(a->dentry, a->btgt, NULL);
15945 + au_set_h_dptr(a->dentry, a->btgt, dget(a->h_dst));
15947 + RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
15950 +static noinline_for_stack
15951 +void au_ren_rev_whsrc(int err, struct au_ren_args *a)
15955 + rerr = au_wh_unlink_dentry(au_pinned_hdir(a->pin + SRC),
15956 + a->wh_dentry[SRC], a->src_dentry, /*dlgt*/0);
15958 + RevertFailure("unlink %.*s", AuDLNPair(a->wh_dentry[SRC]));
15960 +#undef RevertFailure
15962 +/* ---------------------------------------------------------------------- */
15964 +static /* noinline_for_stack */
15965 +int au_ren_or_cpup(struct au_ren_args *a)
15971 + if (au_dbstart(a->src_dentry) == a->btgt) {
15972 + if (a->need_diropq && au_dbdiropq(a->src_dentry) == a->btgt)
15973 + a->need_diropq = 0;
15974 + vfsub_ign_hinode(&a->vargs, IN_MOVED_FROM,
15975 + au_pinned_hdir(a->pin + SRC));
15976 + vfsub_ign_hinode(&a->vargs, IN_MOVED_TO,
15977 + au_pinned_hdir(a->pin + DST));
15978 + /* nfs_rename() calls d_delete() */
15979 + if (au_test_nfs(au_pinned_h_dir(a->pin + DST)->i_sb)
15980 + && a->h_dentry[DST]->d_inode
15981 + && (S_ISDIR(a->h_dentry[DST]->d_inode->i_mode)
15982 + || atomic_read(&a->h_dentry[DST]->d_count) <= 2))
15983 + vfsub_ign_hinode(&a->vargs, IN_DELETE,
15984 + au_pinned_hdir(a->pin + DST));
15985 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
15986 + err = vfsub_rename(au_pinned_h_dir(a->pin + SRC),
15987 + au_h_dptr(a->src_dentry, a->btgt),
15988 + au_pinned_h_dir(a->pin + DST),
15989 + a->h_dentry[DST], &a->vargs);
15991 + struct mutex *h_mtx = &a->h_dentry[SRC]->d_inode->i_mutex;
15994 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
15995 + au_set_dbstart(a->src_dentry, a->btgt);
15996 + au_set_h_dptr(a->src_dentry, a->btgt, dget(a->h_dentry[DST]));
15997 + err = au_sio_cpup_single(a->src_dentry, a->btgt, a->bstart[SRC],
15998 + -1, !AuCpup_DTIME, a->parent[DST]);
15999 + if (unlikely(err)) {
16000 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
16001 + au_set_dbstart(a->src_dentry, a->bstart[SRC]);
16003 + mutex_unlock(h_mtx);
16009 +static /* noinline_for_stack */
16010 +int au_ren_del_whtmp(struct au_ren_args *a)
16016 + if (au_test_nfs(a->h_dst->d_sb)
16017 + || !au_nhash_test_longer_wh(&a->whlist, a->btgt,
16018 + au_sbi(a->sb)->si_dirwh)) {
16019 + err = au_whtmp_rmdir(a->dir, a->btgt, a->h_dst, &a->whlist);
16020 + if (unlikely(err))
16021 + AuWarn("failed removing whtmp dir %.*s (%d), "
16022 + "ignored.\n", AuDLNPair(a->h_dst), err);
16024 + au_whtmp_kick_rmdir(a->dir, a->btgt, a->h_dst, &a->whlist,
16027 + a->thargs = NULL;
16033 +static /* noinline_for_stack */
16034 +int au_ren_diropq(struct au_ren_args *a)
16037 + struct dentry *diropq;
16038 + struct mutex *h_mtx;
16043 + h_mtx = &au_h_dptr(a->src_dentry, a->btgt)->d_inode->i_mutex;
16044 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16045 + diropq = au_diropq_create(a->src_dentry, a->btgt,
16046 + au_ftest_ren(a->flags, DLGT));
16047 + mutex_unlock(h_mtx);
16048 + if (IS_ERR(diropq))
16049 + err = PTR_ERR(diropq);
16055 +static /* noinline_for_stack */
16056 +int do_rename(struct au_ren_args *a)
16059 + aufs_bindex_t bindex, bend;
16060 + struct dentry *h_d;
16062 + LKTRTrace("%.*s/%.*s, %.*s/%.*s, "
16063 + "hd{%p, %p}, hp{%p, %p}, wh %p, btgt %d, bstart{%d, %d}, "
16065 + AuDLNPair(a->parent[SRC]), AuDLNPair(a->src_dentry),
16066 + AuDLNPair(a->parent[DST]), AuDLNPair(a->dentry),
16067 + a->h_dentry[SRC], a->h_dentry[DST],
16068 + a->h_parent[SRC], a->h_parent[DST],
16069 + &a->whlist, a->btgt,
16070 + a->bstart[SRC], a->bstart[DST],
16073 + /* prepare workqueue args */
16074 + if (au_ftest_ren(a->flags, ISDIR) && a->h_dentry[DST]->d_inode) {
16076 + a->thargs = kmalloc(sizeof(*a->thargs), GFP_NOFS);
16077 + if (unlikely(!a->thargs))
16079 + a->h_dst = dget(a->h_dentry[DST]);
16082 + a->ndx.nfsmnt = au_nfsmnt(a->sb, a->btgt);
16083 + if (au_ftest_ren(a->flags, DLGT))
16084 + au_fset_ndx(a->ndx.flags, DLGT);
16086 + /* create whiteout for src_dentry */
16087 + if (au_ftest_ren(a->flags, WHSRC)) {
16088 + a->wh_dentry[SRC] = au_wh_create(a->src_dentry, a->btgt,
16089 + a->h_parent[SRC], &a->ndx);
16090 + err = PTR_ERR(a->wh_dentry[SRC]);
16091 + if (IS_ERR(a->wh_dentry[SRC]))
16095 + /* lookup whiteout for dentry */
16096 + if (au_ftest_ren(a->flags, WHDST)) {
16097 + h_d = au_wh_lkup(a->h_parent[DST], &a->dentry->d_name, &a->ndx);
16098 + err = PTR_ERR(h_d);
16101 + if (!h_d->d_inode)
16104 + a->wh_dentry[DST] = h_d;
16107 + /* rename dentry to tmpwh */
16109 + struct au_hinode *hinode;
16111 + AuDbgDentry(a->h_dentry[DST]);
16112 + err = au_whtmp_ren(a->dir, a->btgt, a->h_dentry[DST]);
16113 + if (unlikely(err))
16115 + AuDbgDentry(a->h_dentry[DST]);
16116 + hinode = au_hi(a->dentry->d_inode, a->btgt);
16117 + /* todo: bad approach? */
16118 + mutex_lock_nested(&hinode->hi_inode->i_mutex, AuLsc_I_CHILD);
16119 + au_hin_suspend(hinode);
16120 + mutex_unlock(&hinode->hi_inode->i_mutex);
16121 + au_set_h_dptr(a->dentry, a->btgt, NULL);
16122 + AuDbgDentry(a->h_dentry[DST]);
16123 + err = au_lkup_neg(a->dentry, a->btgt);
16124 + if (unlikely(err))
16126 + a->h_dentry[DST] = au_h_dptr(a->dentry, a->btgt);
16130 + if (a->h_dentry[DST]->d_inode && a->bstart[SRC] != a->btgt) {
16131 + struct mutex *h_mtx = &a->h_dentry[SRC]->d_inode->i_mutex;
16133 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
16134 + err = au_sio_cpup_simple(a->src_dentry, a->btgt, -1,
16136 + mutex_unlock(h_mtx);
16137 + if (unlikely(err))
16141 + /* rename by vfs_rename or cpup */
16142 + a->need_diropq = au_ftest_ren(a->flags, ISDIR)
16143 + && (a->wh_dentry[DST]
16144 + || au_dbdiropq(a->dentry) == a->btgt
16145 + /* hide the lower to keep xino */
16146 + || a->btgt < au_dbend(a->dentry)
16147 + || au_opt_test(a->mnt_flags, ALWAYS_DIROPQ));
16149 + vfsub_args_init(&a->vargs, a->ign, au_ftest_ren(a->flags, DLGT), 0);
16150 + err = au_ren_or_cpup(a);
16151 + if (unlikely(err))
16154 + /* make dir opaque */
16155 + if (a->need_diropq) {
16156 + err = au_ren_diropq(a);
16157 + if (unlikely(err))
16161 + /* update target timestamps */
16162 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
16163 + a->h_src = au_h_dptr(a->src_dentry, a->btgt);
16164 + au_update_fuse_h_inode(NULL, a->h_src); /*ignore*/
16166 + * fsstack_copy_attr_atime(a->src_dentry->d_inode, a->h_src->d_inode);
16168 + a->src_dentry->d_inode->i_ctime = a->h_src->d_inode->i_ctime;
16170 + /* remove whiteout for dentry */
16171 + if (a->wh_dentry[DST]) {
16172 + err = au_wh_unlink_dentry(au_pinned_hdir(a->pin + DST),
16173 + a->wh_dentry[DST], a->dentry,
16175 + if (unlikely(err))
16179 + /* remove whtmp */
16181 + /* ignore this error */
16182 + au_ren_del_whtmp(a);
16185 + goto out_success;
16188 + if (a->need_diropq)
16189 + au_ren_rev_diropq(err, a);
16192 + au_ren_rev_rename(err, a);
16194 + au_ren_rev_cpup(err, a);
16197 + au_ren_rev_whtmp(err, a);
16199 + dput(a->wh_dentry[DST]);
16200 + a->wh_dentry[DST] = NULL;
16202 + if (a->wh_dentry[SRC])
16203 + au_ren_rev_whsrc(err, a);
16204 + d_drop(a->src_dentry);
16205 + bend = au_dbend(a->src_dentry);
16206 + for (bindex = au_dbstart(a->src_dentry); bindex <= bend; bindex++) {
16207 + h_d = au_h_dptr(a->src_dentry, bindex);
16211 + d_drop(a->dentry);
16212 + bend = au_dbend(a->dentry);
16213 + for (bindex = au_dbstart(a->dentry); bindex <= bend; bindex++) {
16214 + h_d = au_h_dptr(a->dentry, bindex);
16218 + au_update_dbstart(a->dentry);
16220 + d_drop(a->h_dst);
16222 + dput(a->wh_dentry[SRC]);
16223 + dput(a->wh_dentry[DST]);
16227 + kfree(a->thargs);
16235 + * test if @dentry dir can be rename destination or not.
16236 + * success means, it is a logically empty dir.
16238 +static int may_rename_dstdir(struct dentry *dentry, aufs_bindex_t btgt,
16239 + struct au_nhash *whlist)
16241 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
16243 + return au_test_empty(dentry, whlist);
16247 + * test if @dentry dir can be rename source or not.
16248 + * if it can, return 0 and @children is filled.
16250 + * - or, it is a logically empty dir.
16251 + * - or, it exists on writable branch and has no children including whiteouts
16252 + * on the lower branch.
16254 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
16257 + aufs_bindex_t bstart;
16259 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
16261 + bstart = au_dbstart(dentry);
16262 + if (bstart != btgt) {
16263 + struct au_nhash *whlist;
16265 + whlist = au_nhash_new(GFP_NOFS);
16266 + err = PTR_ERR(whlist);
16267 + if (IS_ERR(whlist))
16269 + err = au_test_empty(dentry, whlist);
16270 + au_nhash_del(whlist);
16274 + if (bstart == au_dbtaildir(dentry))
16275 + return 0; /* success */
16277 + err = au_test_empty_lower(dentry);
16280 + if (/* unlikely */(err == -ENOTEMPTY)) {
16281 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
16282 + " is not supported\n");
16289 +/* mainly for link(2) and rename(2) */
16290 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
16292 + aufs_bindex_t bdiropq, bwh;
16293 + struct dentry *parent;
16295 + LKTRTrace("%.*s, b%d\n", AuDLNPair(dentry), btgt);
16296 + parent = dentry->d_parent;
16297 + IMustLock(parent->d_inode); /* dir is locked */
16299 + bdiropq = au_dbdiropq(parent);
16300 + bwh = au_dbwh(dentry);
16301 + if (au_br_rdonly(au_sbr(dentry->d_sb, btgt))
16302 + || (0 <= bdiropq && bdiropq < btgt)
16303 + || (0 <= bwh && bwh < btgt))
16306 + LKTRTrace("btgt %d\n", btgt);
16311 + * simple tests for rename.
16312 + * following the checks in vfs, plus the parent-child relationship.
16314 +static int au_may_ren(struct au_ren_args *a)
16317 + struct inode *h_inode;
16321 + if (a->bstart[SRC] == a->btgt) {
16322 + err = au_may_del(a->src_dentry, a->btgt, a->h_parent[SRC],
16323 + au_ftest_ren(a->flags, ISDIR), &a->ndx);
16324 + if (unlikely(err))
16327 + if (unlikely(a->h_dentry[SRC] == a->h_trap))
16332 + if (a->bstart[DST] != a->btgt)
16336 + h_inode = a->h_dentry[DST]->d_inode;
16337 + if (!a->dentry->d_inode) {
16338 + if (unlikely(h_inode))
16340 + err = au_may_add(a->dentry, a->btgt, a->h_parent[DST],
16341 + au_ftest_ren(a->flags, ISDIR), &a->ndx);
16343 + if (unlikely(!h_inode || !h_inode->i_nlink))
16345 + err = au_may_del(a->dentry, a->btgt, a->h_parent[DST],
16346 + au_ftest_ren(a->flags, ISDIR), &a->ndx);
16347 + if (unlikely(err))
16349 + err = -ENOTEMPTY;
16350 + if (unlikely(a->h_dentry[DST] == a->h_trap))
16356 + if (unlikely(err == -ENOENT || err == -EEXIST))
16365 + * - src_dir and dir by lock_rename()
16366 + * - inode if exitsts
16369 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
16371 + * + di_write_lock2_child()
16372 + * + di_write_lock_child()
16373 + * + ii_write_lock_child()
16374 + * + di_write_lock_child2()
16375 + * + ii_write_lock_child2()
16376 + * + src_parent and parent
16377 + * + di_write_lock_parent()
16378 + * + ii_write_lock_parent()
16379 + * + di_write_lock_parent2()
16380 + * + ii_write_lock_parent2()
16381 + * + if udab=inotify is specified, lock grand parents (crazy)
16382 + * + di_read_lock_gparent()
16383 + * + ii_read_lock_gparent()
16384 + * + di_read_lock_gparent2()
16385 + * + ii_read_lock_gparent2()
16386 + * + mutex_lock(s_vfs_rename_mutex)
16387 + * + mutex_lock_gparent()
16388 + * + mutex_lock_gparent2()
16389 + * + mutex_lock_parent()
16390 + * + mutex_lock_parent2()
16391 + * + else lower src_dir and dir by vfsub_lock_rename()
16392 + * + verify the every relations between child, parent and grand parent. if any
16393 + * of them failed, unlock all and return -EBUSY.
16395 +static void au_ren_pin_init(struct au_pin *first, struct dentry *d1,
16396 + struct au_pin *next, struct dentry *d2,
16397 + aufs_bindex_t bindex)
16401 + /* AuLsc_DI_PARENT3 is for higher gparent initially */
16402 + au_pin_init(first, d1, bindex, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
16403 + AuPin_DI_LOCKED | AuPin_DO_GPARENT);
16404 + /* AuLsc_DI_PARENT4 is for lower gparent initially */
16405 + au_pin_init(next, d2, bindex, AuLsc_DI_PARENT3, AuLsc_I_PARENT4,
16406 + AuPin_DI_LOCKED | AuPin_DO_GPARENT);
16409 +static void au_ren_fake_pin(struct au_ren_args *a)
16412 + struct au_pin1 *p;
16413 + struct inode *h_i;
16417 + /* they increment the ref counter */
16418 + for (i = 0; i < 2; i++) {
16419 + p = a->pin[i].pin + AuPin_PARENT;
16420 + au_pin_set_parent(a->pin + i, a->parent[i]);
16421 + dput(a->parent[i]);
16422 + h_i = a->h_parent[i]->d_inode;
16423 + au_pin_set_h_dir(a->pin + i, h_i);
16426 + if (!a->gparent[i]) {
16427 + au_pin_set_gparent(a->pin + i, NULL);
16428 + au_pin_set_h_gdir(a->pin + i, NULL);
16430 + au_pin_set_gparent(a->pin + i, a->gparent[i]);
16431 + dput(a->gparent[i]);
16432 + h_i = au_h_iptr(a->gparent[i]->d_inode, a->btgt);
16433 + au_pin_set_h_gdir(a->pin + i, h_i);
16440 +/* cf. i_op.c: au_do_pin() */
16441 +static int au_ren_pin4(int higher, int lower, struct au_ren_args *a)
16444 + struct au_pin *p;
16445 + struct au_pin1 *p4[4];
16446 + struct inode *h_dir;
16449 + lktr_set_pid(current->pid, LktrArrayPid);
16450 + LKTRTrace("i%lu, %.*s, i%lu, %.*s\n",
16451 + a->src_dir->i_ino, AuDLNPair(a->src_dentry),
16452 + a->dir->i_ino, AuDLNPair(a->dentry));
16453 + lktr_clear_pid(current->pid, LktrArrayPid);
16455 + LKTRTrace("%d, %d\n", higher, lower);
16458 + p = a->pin + higher;
16459 + p4[0] = au_pin_gp(p); /* highest */
16460 + p4[1] = p->pin + AuPin_PARENT;
16461 + p = a->pin + lower;
16462 + p4[2] = au_pin_gp(p);
16463 + p4[3] = p->pin + AuPin_PARENT;
16465 + if (a->gparent[higher]) {
16466 + au_pin_do_set_parent(p4[0], a->gparent[higher]);
16467 + au_pin_do_set_dentry(p4[0], a->parent[higher]);
16469 + au_pin_do_set_parent(p4[1], a->parent[higher]);
16470 + if (a->gparent[lower]) {
16471 + au_pin_do_set_parent(p4[2], a->gparent[lower]);
16472 + au_pin_do_set_dentry(p4[2], a->parent[lower]);
16474 + au_pin_do_set_parent(p4[3], a->parent[lower]);
16477 + lktr_set_pid(current->pid, LktrArrayPid);
16478 + for (i = 0; i < 4; i++)
16479 + AuDbgDentry(p4[i]->parent);
16481 + DiMustWriteLock(p4[3]->parent);
16482 + di_write_unlock(p4[1]->parent);
16483 + if (p4[2]->parent)
16484 + di_read_lock_parent2(p4[2]->parent, AuLock_IR);
16485 + di_write_lock_parent3(p4[1]->parent);
16486 + if (p4[0]->parent)
16487 + di_read_lock_parent4(p4[0]->parent, AuLock_IR);
16488 + //lktr_clear_pid(current->pid, LktrArrayPid);
16490 + vfsub_lock_rename_mutex(au_sbr_sb(a->dentry->d_sb, a->btgt));
16491 + au_fset_ren(a->flags, VFSLOCK);
16493 + lsc = AuLsc_I_PARENT;
16494 + for (i = 0; i < 4; i++, lsc++) {
16495 + if (p4[i]->parent) {
16496 + h_dir = au_h_iptr(p4[i]->parent->d_inode, a->btgt);
16497 + au_pin_do_set_h_dir(p4[i], h_dir);
16498 + mutex_lock_nested(&h_dir->i_mutex, lsc);
16506 +static struct dentry *au_ren_pin3(int higher, int lower, struct au_ren_args *a)
16508 + struct dentry *h_trap;
16509 + struct au_pin *p;
16512 + LKTRTrace("%d, %d\n", higher, lower);
16514 + p = a->pin + higher;
16515 + AuDebugOn(!au_pin_gp(p));
16516 + au_fset_pin(au_pin_gp(p)->flags, VFS_RENAME);
16517 + err = au_do_pin(p->pin + AuPin_PARENT, au_pin_gp(p));
16518 + h_trap = ERR_PTR(err);
16519 + if (unlikely(err))
16521 + p = a->pin + lower;
16522 + au_fclr_pin(p->pin[AuPin_PARENT].flags, DO_GPARENT);
16523 + err = au_do_pin(p->pin + AuPin_PARENT, NULL);
16524 + h_trap = ERR_PTR(err);
16525 + if (unlikely(err)) {
16526 + p = a->pin + higher;
16527 + au_do_unpin(p->pin + AuPin_PARENT, au_pin_gp(p));
16530 + h_trap = au_pinned_h_parent(p);
16533 + AuTraceErrPtr(h_trap);
16537 +static struct dentry *au_ren_pin(struct au_ren_args *a)
16539 + struct dentry *h_trap;
16540 + struct inode *h_gdir;
16541 + int err, i, same_gp;
16543 + //lktr_set_pid(current->pid, LktrArrayPid);
16545 + AuDebugOn(!au_opt_test(a->mnt_flags, UDBA_INOTIFY));
16547 + /* gdir is not locked */
16549 + if (!IS_ROOT(a->parent[SRC]))
16550 + a->gparent[SRC] = dget_parent(a->parent[SRC]);
16551 + if (!IS_ROOT(a->parent[DST])) {
16552 + a->gparent[DST] = dget_parent(a->parent[DST]);
16553 + same_gp = (a->gparent[SRC] == a->gparent[DST]);
16558 + * - gparent[SRC] is parent[DST]
16559 + * - parent[SRC] is gparent[DST]
16560 + * - gparent[SRC] is gparent[DST]
16561 + * - gparent[SRC] is a descendant of parent[DST]
16562 + * - parent[SRC] is an ancestor of gparent[DST]
16563 + * - not within grand parent range
16566 + h_trap = ERR_PTR(-EBUSY);
16567 + if (a->gparent[SRC] == a->parent[DST]) {
16568 + //AuDbg("here\n");
16570 + au_ren_pin_init(a->pin + DST, a->dentry, a->pin + SRC,
16571 + a->src_dentry, a->btgt);
16572 + h_trap = au_ren_pin3(DST, SRC, a);
16573 + if (!IS_ERR(h_trap)) {
16574 + h_gdir = au_pinned_h_dir(a->pin + DST);
16575 + err = au_verify_parent(a->h_parent[SRC], h_gdir);
16576 + if (unlikely(err))
16577 + h_trap = ERR_PTR(-EBUSY);
16579 + } else if (a->parent[SRC] == a->gparent[DST] || same_gp) {
16580 + //AuDbg("here\n");
16582 + au_ren_pin_init(a->pin + SRC, a->src_dentry, a->pin + DST,
16583 + a->dentry, a->btgt);
16584 + h_trap = au_ren_pin3(SRC, DST, a);
16585 + if (!IS_ERR(h_trap)) {
16587 + h_gdir = au_pinned_h_dir(a->pin + SRC);
16589 + h_gdir = au_pinned_h_gdir(a->pin + SRC);
16590 + err = au_verify_parent(a->h_parent[DST], h_gdir);
16591 + if (unlikely(err))
16592 + h_trap = ERR_PTR(-EBUSY);
16594 + } else if (a->gparent[SRC]
16595 + && (h_trap = au_test_subdir(a->gparent[SRC],
16596 + a->parent[DST]))) {
16597 + //AuDbg("here\n");
16599 + au_ren_pin_init(a->pin + DST, a->dentry, a->pin + SRC,
16600 + a->src_dentry, a->btgt);
16601 + if (a->gparent[DST]) {
16602 + err = au_ren_pin4(DST, SRC, a);
16603 + if (unlikely(err))
16604 + h_trap = ERR_PTR(err);
16606 + struct dentry *t;
16607 + t = au_ren_pin3(DST, SRC, a);
16608 + AuDebugOn(t == h_trap);
16611 + } else if (a->gparent[DST]
16612 + && (h_trap = au_test_subdir(a->gparent[DST],
16613 + a->parent[SRC]))) {
16614 + /* todo: is this really necessary? */
16615 + //AuDbg("here\n");
16617 + au_ren_pin_init(a->pin + SRC, a->src_dentry, a->pin + DST,
16618 + a->dentry, a->btgt);
16619 + if (a->gparent[SRC]) {
16620 + err = au_ren_pin4(SRC, DST, a);
16621 + if (unlikely(err))
16622 + h_trap = ERR_PTR(err);
16624 + struct dentry *t;
16625 + t = au_ren_pin3(SRC, DST, a);
16626 + AuDebugOn(t == h_trap);
16629 + } else /* if (a->gparent[DST]
16630 + && (h_trap = au_test_subdir(a->gparent[DST],
16631 + a->parent[SRC]))) */ {
16632 + //AuDbg("here\n");
16635 + if (a->gparent[DST])
16636 + h_trap = au_test_subdir(a->gparent[DST],
16638 + au_ren_pin_init(a->pin + SRC, a->src_dentry, a->pin + DST,
16639 + a->dentry, a->btgt);
16640 + err = au_ren_pin4(SRC, DST, a);
16641 + if (unlikely(err))
16642 + h_trap = ERR_PTR(err);
16644 + au_fset_ren(a->flags, PINNED);
16646 + if (!IS_ERR(h_trap)) {
16648 + for (i = 0; !err && i < 2; i++) {
16649 + h_gdir = au_pinned_h_gdir(a->pin + i);
16651 + err = au_verify_parent(a->h_parent[i], h_gdir);
16653 + if (unlikely(err)) {
16654 + h_trap = ERR_PTR(err);
16655 + //AuDbg("here\n");
16659 + dput(a->gparent[SRC]);
16660 + dput(a->gparent[DST]);
16661 + memset(a->gparent, 0, sizeof(a->gparent));
16662 + AuTraceErrPtr(h_trap);
16663 + //lktr_clear_pid(current->pid, LktrArrayPid);
16667 +static void au_ren_unlock(struct au_ren_args *a)
16673 + if (au_ftest_ren(a->flags, MNT_WRITE))
16674 + au_mnt_drop_write(au_sbr_mnt(a->dentry->d_sb, a->btgt));
16675 + if (a->h_locked[0])
16676 + vfsub_unlock_rename(a->h_locked[0], a->h_locked[1]);
16677 + if (au_ftest_ren(a->flags, PINNED)) {
16678 + au_unpin(a->pin + SRC);
16679 + au_unpin(a->pin + DST);
16680 + memset(a->gparent, 0, sizeof(a->gparent));
16682 + if (au_ftest_ren(a->flags, VFSLOCK))
16683 + vfsub_unlock_rename_mutex(au_sbr_sb(a->dentry->d_sb, a->btgt));
16684 + for (i = 0; i < 2; i++)
16685 + if (a->gparent[i]) {
16686 + di_read_unlock(a->gparent[i], AuLock_IR);
16687 + dput(a->gparent[i]);
16691 +static int au_ren_lock(struct au_ren_args *a)
16694 + const int hinotify = au_opt_test(a->mnt_flags, UDBA_INOTIFY);
16700 + || (au_ftest_ren(a->flags, ISSAMEDIR) && IS_ROOT(a->parent[SRC]))) {
16701 + au_ren_pin_init(a->pin + SRC, a->src_dentry, a->pin + DST,
16702 + a->dentry, a->btgt);
16704 + a->h_locked[0] = a->h_parent[SRC];
16705 + a->h_locked[1] = a->h_parent[DST];
16706 + a->h_trap = vfsub_lock_rename(a->h_locked[0], a->h_locked[1]);
16707 + au_ren_fake_pin(a);
16708 + } else if (au_ftest_ren(a->flags, ISSAMEDIR)
16709 + && !IS_ROOT(a->parent[SRC])) {
16710 + /* this and next block should not be compiled when
16711 + hinotify is disabled */
16712 + /* irregular/tricky rename lock */
16714 + au_ren_pin_init(a->pin + SRC, a->src_dentry, a->pin + DST,
16715 + a->dentry, a->btgt);
16716 + a->gparent[SRC] = dget_parent(a->parent[SRC]);
16717 + di_read_lock_parent2(a->gparent[SRC], AuLock_IR);
16718 + a->h_locked[0] = a->h_parent[SRC];
16719 + a->h_locked[1] = dget_parent(a->h_parent[SRC]);
16720 + a->h_trap = vfsub_lock_rename(a->h_locked[0], a->h_locked[1]);
16721 + err = au_verify_parent(a->h_parent[SRC],
16722 + a->h_locked[1]->d_inode);
16723 + dput(a->h_locked[1]);
16725 + au_ren_fake_pin(a);
16727 + /* 3 or 4 dir locks. crazy */
16729 + a->h_trap = au_ren_pin(a);
16730 + if (IS_ERR(a->h_trap))
16731 + err = PTR_ERR(a->h_trap);
16734 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
16735 + err = au_verify_parent(a->h_dentry[SRC],
16736 + a->h_parent[SRC]->d_inode);
16737 + if (!err && au_dbstart(a->dentry) == a->btgt)
16738 + err = au_verify_parent(a->h_dentry[DST],
16739 + a->h_parent[DST]->d_inode);
16741 + err = au_br_want_write(au_sbr(a->dentry->d_sb, a->btgt));
16742 + if (unlikely(err))
16744 + au_fset_ren(a->flags, MNT_WRITE);
16745 + goto out; /* success */
16751 + au_ren_unlock(a);
16757 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16758 + struct inode *dir, struct dentry *dentry)
16761 + aufs_bindex_t bend, bindex;
16762 + unsigned char do_dt_dstdir, hinotify;
16763 + struct inode *inode[2];
16764 + enum { PARENT, CHILD };
16765 + /* reduce stack space */
16767 + struct au_ren_args a;
16768 + struct au_dtime dt[2][2];
16770 + struct au_wr_dir_args wr_dir_args = {
16771 + /* .force_btgt = -1, */
16772 + .flags = AuWrDir_ADD_ENTRY
16775 + LKTRTrace("i%lu, %.*s, i%lu, %.*s\n",
16776 + src_dir->i_ino, AuDLNPair(src_dentry),
16777 + dir->i_ino, AuDLNPair(dentry));
16778 + AuDebugOn(IS_ROOT(src_dentry) || IS_ROOT(dentry));
16779 + IMustLock(src_dir);
16781 + inode[DST] = dentry->d_inode;
16782 + if (inode[DST]) {
16783 + IMustLock(inode[DST]);
16784 + au_igrab(inode[DST]);
16788 + BUILD_BUG_ON(sizeof(*p) > PAGE_SIZE);
16789 + p = kzalloc(sizeof(*p), GFP_NOFS);
16790 + if (unlikely(!p))
16794 + p->a.src_dir = src_dir;
16795 + p->a.src_dentry = src_dentry;
16797 + p->a.dentry = dentry;
16798 + p->a.sb = src_dentry->d_sb;
16799 + inode[SRC] = src_dentry->d_inode;
16801 + if (S_ISDIR(inode[SRC]->i_mode)) {
16802 + au_fset_ren(p->a.flags, ISDIR);
16803 + if (unlikely(inode[DST] && !S_ISDIR(inode[DST]->i_mode)))
16805 + aufs_read_and_write_lock2(dentry, src_dentry, AuLock_DIR);
16807 + aufs_read_and_write_lock2(dentry, src_dentry, 0);
16809 + p->a.mnt_flags = au_mntflags(p->a.sb);
16810 + if (au_test_dlgt(p->a.mnt_flags))
16811 + au_fset_ren(p->a.flags, DLGT);
16812 + p->a.parent[SRC] = src_dentry->d_parent; /* dir inode is locked */
16813 + p->a.parent[DST] = dentry->d_parent; /* dir inode is locked */
16814 + au_fset_ren(p->a.flags, ISSAMEDIR); /* temporary */
16815 + di_write_lock_parent(p->a.parent[DST]);
16817 + /* which branch we process */
16818 + p->a.bstart[SRC] = au_dbstart(src_dentry);
16819 + p->a.bstart[DST] = au_dbstart(dentry);
16820 + if (au_ftest_ren(p->a.flags, ISDIR))
16821 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
16822 + wr_dir_args.force_btgt = p->a.bstart[SRC];
16823 + if (dentry->d_inode && p->a.bstart[DST] < p->a.bstart[SRC])
16824 + wr_dir_args.force_btgt = p->a.bstart[DST];
16825 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
16826 + err = au_wr_dir(dentry, src_dentry, &wr_dir_args);
16828 + if (unlikely(err < 0))
16831 + /* are they available to be renamed */
16833 + au_nhash_init(&p->a.whlist);
16834 + if (au_ftest_ren(p->a.flags, ISDIR) && inode[DST]) {
16835 + au_set_dbstart(dentry, p->a.bstart[DST]);
16836 + err = may_rename_dstdir(dentry, p->a.btgt, &p->a.whlist);
16837 + au_set_dbstart(dentry, p->a.btgt);
16839 + p->a.h_dentry[DST] = au_h_dptr(dentry, au_dbstart(dentry));
16840 + if (unlikely(err))
16842 + /* todo: minor optimize,
16843 + their sb may be same while their bindex differs? */
16844 + p->a.h_dentry[SRC] = au_h_dptr(src_dentry, au_dbstart(src_dentry));
16845 + if (au_ftest_ren(p->a.flags, ISDIR)) {
16846 + err = may_rename_srcdir(src_dentry, p->a.btgt);
16847 + if (unlikely(err))
16848 + goto out_children;
16851 + /* prepare the writable parent dir on the same branch */
16852 + if (p->a.bstart[DST] == p->a.btgt) {
16853 + au_fset_ren(p->a.flags, WHDST);
16855 + err = au_cpup_dirs(dentry, p->a.btgt);
16856 + if (unlikely(err))
16857 + goto out_children;
16860 + if (src_dir != dir) {
16862 + * this temporary unlock is safe,
16863 + * because both dir->i_mutex are locked.
16865 + di_write_unlock(p->a.parent[DST]);
16866 + di_write_lock_parent(p->a.parent[SRC]);
16867 + err = au_wr_dir_need_wh
16868 + (src_dentry, au_ftest_ren(p->a.flags, ISDIR),
16870 + di_write_unlock(p->a.parent[SRC]);
16871 + di_write_lock2_parent(p->a.parent[SRC], p->a.parent[DST],
16873 + au_fclr_ren(p->a.flags, ISSAMEDIR);
16875 + err = au_wr_dir_need_wh
16876 + (src_dentry, au_ftest_ren(p->a.flags, ISDIR),
16878 + if (unlikely(err < 0))
16879 + goto out_children;
16881 + au_fset_ren(p->a.flags, WHSRC);
16883 + hinotify = au_opt_test(p->a.mnt_flags, UDBA_INOTIFY);
16884 + p->a.h_parent[SRC] = au_h_dptr(p->a.parent[SRC], p->a.btgt);
16885 + p->a.h_parent[DST] = au_h_dptr(p->a.parent[DST], p->a.btgt);
16886 + err = au_ren_lock(&p->a);
16887 + if (unlikely(err))
16888 + goto out_children;
16890 + if (!au_opt_test(p->a.mnt_flags, UDBA_NONE)) {
16891 + p->a.ndx.nfsmnt = au_nfsmnt(p->a.sb, p->a.btgt);
16892 + if (au_ftest_ren(p->a.flags, DLGT))
16893 + au_fset_ndx(p->a.ndx.flags, DLGT);
16894 + err = au_may_ren(&p->a);
16895 + if (unlikely(err))
16897 + memset(&p->a.ndx, 0, sizeof(p->a.ndx));
16900 + /* store timestamps to be revertible */
16901 + au_dtime_store(p->dt[PARENT] + SRC, p->a.parent[SRC],
16902 + p->a.h_parent[SRC], au_pinned_hdir(p->a.pin + SRC),
16903 + au_pinned_hgdir(p->a.pin + SRC)
16904 + /* hgdir[SRC] */);
16905 + if (!au_ftest_ren(p->a.flags, ISSAMEDIR))
16906 + au_dtime_store(p->dt[PARENT] + DST, p->a.parent[DST],
16907 + p->a.h_parent[DST],
16908 + au_pinned_hdir(p->a.pin + DST),
16909 + au_pinned_hgdir(p->a.pin + DST)
16910 + /* hgdir[DST] */);
16911 + do_dt_dstdir = 0;
16912 + if (au_ftest_ren(p->a.flags, ISDIR)) {
16913 + au_dtime_store(p->dt[CHILD] + SRC, src_dentry,
16914 + p->a.h_dentry[SRC], au_hi(inode[SRC], p->a.btgt),
16915 + au_pinned_hdir(p->a.pin + SRC));
16916 + if (p->a.h_dentry[DST]->d_inode) {
16917 + do_dt_dstdir = 1;
16918 + au_dtime_store(p->dt[CHILD] + DST, dentry,
16919 + p->a.h_dentry[DST],
16920 + au_hi(inode[DST], p->a.btgt),
16921 + au_pinned_hdir(p->a.pin + DST));
16925 + err = do_rename(&p->a);
16926 + if (unlikely(err))
16929 + /* update dir attributes */
16930 + dir->i_version++;
16931 + if (au_ftest_ren(p->a.flags, ISDIR)) {
16932 + /* is this updating defined in POSIX? */
16933 + /* mutex_lock(&inode[SRC]->i_mutex); */
16934 + au_cpup_attr_timesizes(inode[SRC]);
16935 + /* mutex_unlock(&inode[SRC]->i_mutex); */
16937 + au_cpup_attr_nlink(dir, /*force*/1);
16938 + if (inode[DST]) {
16939 + clear_nlink(inode[DST]);
16940 + au_cpup_attr_timesizes(inode[DST]);
16943 + if (au_ibstart(dir) == p->a.btgt)
16944 + au_cpup_attr_timesizes(dir);
16946 + if (!au_ftest_ren(p->a.flags, ISSAMEDIR)) {
16947 + src_dir->i_version++;
16948 + if (au_ftest_ren(p->a.flags, ISDIR))
16949 + au_cpup_attr_nlink(src_dir, /*force*/1);
16950 + if (au_ibstart(src_dir) == p->a.btgt)
16951 + au_cpup_attr_timesizes(src_dir);
16954 + /* todo: simple d_drop(src_dentry) is not enough? */
16955 + /* dput/iput all lower dentries */
16956 + au_set_dbwh(src_dentry, -1);
16957 + bend = au_dbend(src_dentry);
16958 + for (bindex = p->a.btgt + 1; bindex <= bend; bindex++) {
16959 + struct dentry *hd;
16960 + hd = au_h_dptr(src_dentry, bindex);
16962 + au_set_h_dptr(src_dentry, bindex, NULL);
16964 + au_set_dbend(src_dentry, p->a.btgt);
16966 + if (au_opt_test(p->a.mnt_flags, PLINK)
16967 + && au_plink_test(src_dentry->d_sb, inode[SRC]))
16968 + goto out_hdir; /* success */
16969 + bend = au_ibend(inode[SRC]);
16970 + for (bindex = p->a.btgt + 1; bindex <= bend; bindex++) {
16971 + struct inode *hi;
16972 + hi = au_h_iptr(inode[SRC], bindex);
16974 + au_xino_write0(p->a.sb, bindex, hi->i_ino, 0);
16975 + /* ignore this error */
16976 + au_set_h_iptr(inode[SRC], bindex, NULL, 0);
16979 + au_set_ibend(inode[SRC], p->a.btgt);
16980 + goto out_hdir; /* success */
16983 + au_dtime_revert(p->dt[PARENT] + SRC);
16984 + if (!au_ftest_ren(p->a.flags, ISSAMEDIR))
16985 + au_dtime_revert(p->dt[PARENT] + DST);
16986 + if (au_ftest_ren(p->a.flags, ISDIR) && err != -EIO) {
16987 + struct dentry *hd;
16989 + hd = p->dt[CHILD][SRC].dt_h_dentry;
16990 + mutex_lock_nested(&hd->d_inode->i_mutex, AuLsc_I_CHILD);
16991 + au_dtime_revert(p->dt[CHILD] + SRC);
16992 + mutex_unlock(&hd->d_inode->i_mutex);
16993 + if (do_dt_dstdir) {
16994 + hd = p->dt[CHILD][DST].dt_h_dentry;
16995 + mutex_lock_nested(&hd->d_inode->i_mutex, AuLsc_I_CHILD);
16996 + au_dtime_revert(p->dt[CHILD] + DST);
16997 + mutex_unlock(&hd->d_inode->i_mutex);
17001 + au_ren_unlock(&p->a);
17003 + au_nhash_fin(&p->a.whlist);
17005 + if (unlikely(err && au_ftest_ren(p->a.flags, ISDIR))) {
17006 + au_update_dbstart(dentry);
17010 + d_move(src_dentry, dentry);
17012 + && (inode[DST]->i_nlink == 1
17013 + || au_ftest_ren(p->a.flags, ISDIR)))
17014 + inode[DST]->i_flags |= S_DEAD;
17016 + if (au_ftest_ren(p->a.flags, ISSAMEDIR))
17017 + di_write_unlock(p->a.parent[DST]);
17019 + di_write_unlock2(p->a.parent[SRC], p->a.parent[DST]);
17020 + aufs_read_and_write_unlock2(dentry, src_dentry);
17024 + iput(inode[DST]);
17026 + //lktr_clear_pid(current->pid, LktrArrayPid);
17027 + if (unlikely(err == -EBUSY && au_test_nfsd(current)))
17031 diff -urN linux/fs/aufs/Makefile linux-aufs/fs/aufs/Makefile
17032 --- linux/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
17033 +++ linux-aufs/fs/aufs/Makefile 2008-10-20 03:47:24.000000000 +0200
17035 +# AUFS Makefile for the Linux 2.6.25 and later
17038 +# the environment variables are not inherited since 2.6.23
17039 +ifdef AUFS_EXTRA_CFLAGS
17040 +ccflags-y += ${AUFS_EXTRA_CFLAGS}
17043 +########################################
17045 +ifdef CONFIG_AUFS_RR_SQUASHFS
17046 +# cf. squashfs3.2-r2 and sqlzma patch.
17047 +ccflags-y += -DSQUASHFS_MAGIC=0x73717368
17048 +ccflags-y += -DSQUASHFS_MAGIC_SWAP=0x68737173
17049 +ccflags-y += -DSQUASHFS_MAGIC_LZMA=0x71736873
17050 +ccflags-y += -DSQUASHFS_MAGIC_LZMA_SWAP=0x73687371
17053 +# defined in ${srctree}/fs/fuse/inode.c
17054 +ccflags-$(CONFIG_AUFS_WORKAROUND_FUSE) += -DFUSE_SUPER_MAGIC=0x65735546
17056 +# defined in ${srctree}/fs/xfs/xfs_sb.h
17058 +ifdef CONFIG_XFS_FS
17059 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
17062 +# defined in ${srctree}/mm/shmem.c
17064 +ifdef CONFIG_TMPFS
17065 +ccflags-y += -DTMPFS_MAGIC=0x01021994
17068 +# defined in ${srctree}fs/sysfs/mount.c
17070 +ccflags-$(CONFIG_SYSFS) += -DSYSFS_MAGIC=0x62656572
17072 +ifndef EXTRAVERSION
17073 +EXTRAVERSION = $(shell echo ${KERNELVERSION} | cut -f3- -d. | cut -f2- -d-)
17075 +# for -mm tree, support the latest version only
17076 +ifneq ($(strip $(shell echo ${EXTRAVERSION} | fgrep -- mm)),)
17077 +ccflags-y += -DCONFIG_AUFS_UNIONFS22_PATCH -DCONFIG_AUFS_UNIONFS23_PATCH
17080 +-include $(dir $(lastword ${MAKEFILE_LIST}))priv.mk
17081 +#$(warning ${ccflags-y})
17083 +########################################
17085 +obj-$(CONFIG_AUFS) += aufs.o
17086 +aufs-y := module.o super.o sbinfo.o branch.o xino.o sysaufs.o opts.o \
17087 + wkq.o vfsub.o dcsub.o \
17088 + cpup.o whout.o plink.o wbr_policy.o \
17089 + dentry.o dinfo.o \
17090 + file.o f_op.o finfo.o \
17092 + inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o iinfo.o \
17095 +aufs-$(CONFIG_SYSFS) += sysfs.o
17096 +aufs-$(CONFIG_AUFS_BR_NFS) += br_nfs.o
17097 +aufs-$(CONFIG_AUFS_BR_XFS) += br_xfs.o
17098 +aufs-$(CONFIG_AUFS_WORKAROUND_FUSE) += br_fuse.o
17099 +aufs-$(CONFIG_AUFS_DLGT) += dlgt.o
17100 +aufs-$(CONFIG_AUFS_HINOTIFY) += hinotify.o
17101 +aufs-$(CONFIG_AUFS_HIN_OR_DLGT) += hin_or_dlgt.o
17102 +aufs-$(CONFIG_AUFS_GETATTR) += getattr.o
17103 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
17104 +aufs-$(CONFIG_AUFS_ROBR) += robr.o
17105 +# reserved for future use
17106 +#aufs-$(CONFIG_AUFS_XATTR) += xattr.o
17107 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
17108 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
17109 diff -urN linux/fs/aufs/misc.c linux-aufs/fs/aufs/misc.c
17110 --- linux/fs/aufs/misc.c 1970-01-01 01:00:00.000000000 +0100
17111 +++ linux-aufs/fs/aufs/misc.c 2009-03-12 16:18:04.000000000 +0100
17114 + * Copyright (C) 2005-2009 Junjiro Okajima
17116 + * This program, aufs is free software; you can redistribute it and/or modify
17117 + * it under the terms of the GNU General Public License as published by
17118 + * the Free Software Foundation; either version 2 of the License, or
17119 + * (at your option) any later version.
17121 + * This program is distributed in the hope that it will be useful,
17122 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17123 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17124 + * GNU General Public License for more details.
17126 + * You should have received a copy of the GNU General Public License
17127 + * along with this program; if not, write to the Free Software
17128 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17137 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
17141 + LKTRTrace("p %p, nused %d, sz %d\n", p, nused, new_sz);
17142 + AuDebugOn(new_sz <= 0);
17143 + if (new_sz <= nused)
17146 + q = krealloc(p, new_sz, gfp);
17148 + memset(q + nused, 0, new_sz - nused);
17152 +/* ---------------------------------------------------------------------- */
17154 +struct nameidata *au_dup_nd(struct au_sbinfo *sbinfo, struct nameidata *dst,
17155 + struct nameidata *src)
17157 + LKTRTrace("src %p\n", src);
17161 + dst->flags &= ~LOOKUP_PARENT;
17162 + if (sbinfo->si_wbr_create == AuWbrCreate_TDP) {
17163 + if ((dst->flags & LOOKUP_CREATE)
17164 + && !(dst->intent.open.flags & O_CREAT))
17165 + dst->flags &= ~LOOKUP_CREATE;
17167 + dst->flags &= ~LOOKUP_CREATE;
17168 + dst->intent.open.flags &= ~O_CREAT;
17176 +struct nameidata *au_fake_dm(struct nameidata *fake_nd, struct nameidata *nd,
17177 + struct super_block *sb, aufs_bindex_t bindex)
17179 + LKTRTrace("nd %p, b%d\n", nd, bindex);
17184 + DiMustAnyLock(nd->path.dentry);
17186 + fake_nd->path.dentry = NULL;
17187 + fake_nd->path.mnt = NULL;
17189 + if (bindex <= au_dbend(nd->path.dentry))
17190 + fake_nd->path.dentry = au_h_dptr(nd->path.dentry, bindex);
17191 + if (fake_nd->path.dentry) {
17192 + fake_nd->path.mnt = au_sbr_mnt(sb, bindex);
17193 + AuDebugOn(!fake_nd->path.mnt);
17194 + path_get(&fake_nd->path);
17196 + fake_nd = ERR_PTR(-ENOENT);
17198 + AuTraceErrPtr(fake_nd);
17202 +void au_fake_dm_release(struct nameidata *fake_nd)
17205 + path_put(&fake_nd->path);
17208 +int au_h_create(struct inode *h_dir, struct dentry *h_dentry, int mode,
17209 + struct vfsub_args *vargs, struct nameidata *nd,
17210 + struct vfsmount *nfsmnt)
17214 + LKTRTrace("hi%lu, %.*s, 0%o, nd %d, nfsmnt %d\n",
17215 + h_dir->i_ino, AuDLNPair(h_dentry), mode, !!nd, !!nfsmnt);
17219 + err = vfsub_create(h_dir, h_dentry, mode, /*nd*/NULL, vargs);
17221 + struct nameidata fake_nd;
17226 + memset(&fake_nd, 0, sizeof(fake_nd));
17227 + fake_nd.path.dentry = h_dentry;
17228 + fake_nd.path.mnt = nfsmnt;
17229 + path_get(&fake_nd.path);
17230 + fake_nd.flags = LOOKUP_CREATE;
17231 + fake_nd.intent.open.flags = O_CREAT | FMODE_READ;
17232 + fake_nd.intent.open.create_mode = mode;
17234 + err = vfsub_create(h_dir, h_dentry, mode, &fake_nd, vargs);
17235 + path_put(&fake_nd.path);
17242 +/* ---------------------------------------------------------------------- */
17244 +/* empty_zero_page is not exported on PPC before 2.6.26 */
17245 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) \
17246 + && (defined(CONFIG_PPC) || defined(CONFIG_PPC64))
17247 +static char *au_zp_alloc(void)
17249 + return (void *)get_zeroed_page(GFP_NOFS);
17252 +static void au_zp_free(char *p)
17255 + free_page((unsigned long)p);
17258 +static char *au_zp_alloc(void)
17260 + return page_address(ZERO_PAGE(0));
17263 +static void au_zp_free(char *p)
17269 +int au_copy_file(struct file *dst, struct file *src, loff_t len,
17270 + struct au_hinode *hdir, struct super_block *sb,
17271 + struct vfsub_args *vargs)
17273 + int err, all_zero, do_kfree;
17274 + unsigned long blksize;
17276 + /* reduce stack usage */
17277 + struct iattr *ia;
17279 + LKTRTrace("%.*s, %.*s\n",
17280 + AuDLNPair(dst->f_dentry), AuDLNPair(src->f_dentry));
17281 + AuDebugOn(!(dst->f_mode & FMODE_WRITE));
17282 +#ifdef CONFIG_AUFS_DEBUG
17284 + struct dentry *parent;
17285 + parent = dget_parent(dst->f_dentry);
17286 + IMustLock(parent->d_inode);
17292 + zp = au_zp_alloc();
17293 + if (unlikely(!zp))
17295 + blksize = dst->f_dentry->d_sb->s_blocksize;
17296 + if (!blksize || PAGE_SIZE < blksize)
17297 + blksize = PAGE_SIZE;
17298 + LKTRTrace("blksize %lu\n", blksize);
17299 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(*ia));
17301 + buf = kmalloc(blksize, GFP_NOFS);
17303 + buf = (void *)__get_free_page(GFP_NOFS);
17304 + if (unlikely(!buf))
17307 +#ifdef CONFIG_AUFS_DEBUG
17308 + if (len > (1 << 22))
17309 + AuWarn("copying a large file %lld\n", (long long)len);
17316 + size_t sz, rbytes, wbytes;
17319 + LKTRTrace("len %lld\n", len);
17321 + if (len < blksize)
17324 + /* support LSM and notify */
17326 + /* todo: signal_pending? */
17327 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
17328 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos,
17329 + vfsub_ftest(vargs->flags, DLGT));
17332 + if (unlikely(err < 0))
17336 + if (len >= rbytes && rbytes == blksize) {
17338 + all_zero = !memcmp(buf, zp, rbytes);
17339 +#else /* reserved for future use */
17340 + unsigned long long *ullp;
17344 + ullp = (void *)buf;
17345 + n = rbytes / sizeof(*ullp);
17347 + while (n-- > 0 && all_zero)
17348 + all_zero = !*ullp++;
17349 + p = (void *)ullp;
17350 + i *= sizeof(*ullp);
17351 + for (; all_zero && i < rbytes; i++)
17352 + all_zero = !*p++;
17360 + /* support LSM and notify */
17361 + vfsub_args_reinit(vargs);
17362 + vfsub_ign_hinode(vargs, IN_MODIFY, hdir);
17363 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos,
17366 + /* todo: signal_pending? */
17367 + if (unlikely(err == -EAGAIN || err == -EINTR))
17369 + if (unlikely(err < 0))
17377 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
17379 + if (unlikely(res < 0))
17386 + /* the last block may be a hole */
17387 + if (!err && all_zero) {
17388 + struct dentry *h_d = dst->f_dentry;
17389 + struct inode *h_i = h_d->d_inode;
17391 + LKTRLabel(last hole);
17393 + /* todo: signal_pending? */
17394 + vfsub_args_reinit(vargs);
17395 + vfsub_ign_hinode(vargs, IN_MODIFY, hdir);
17396 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos, vargs);
17397 + } while (err == -EAGAIN || err == -EINTR);
17399 + ia = (void *)buf;
17400 + ia->ia_size = dst->f_pos;
17401 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
17402 + ia->ia_file = dst;
17403 + vfsub_args_reinit(vargs);
17404 + vfsub_ign_hinode(vargs, vfsub_events_notify_change(ia),
17406 + mutex_lock_nested(&h_i->i_mutex, AuLsc_I_CHILD2);
17407 + err = vfsub_notify_change(h_d, ia, vargs);
17408 + mutex_unlock(&h_i->i_mutex);
17414 + free_page((unsigned long)buf);
17421 diff -urN linux/fs/aufs/misc.h linux-aufs/fs/aufs/misc.h
17422 --- linux/fs/aufs/misc.h 1970-01-01 01:00:00.000000000 +0100
17423 +++ linux-aufs/fs/aufs/misc.h 2009-03-12 16:18:04.000000000 +0100
17426 + * Copyright (C) 2005-2009 Junjiro Okajima
17428 + * This program, aufs is free software; you can redistribute it and/or modify
17429 + * it under the terms of the GNU General Public License as published by
17430 + * the Free Software Foundation; either version 2 of the License, or
17431 + * (at your option) any later version.
17433 + * This program is distributed in the hope that it will be useful,
17434 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17435 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17436 + * GNU General Public License for more details.
17438 + * You should have received a copy of the GNU General Public License
17439 + * along with this program; if not, write to the Free Software
17440 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17447 +#ifndef __AUFS_MISC_H__
17448 +#define __AUFS_MISC_H__
17452 +#include <linux/fs.h>
17453 +#include <linux/namei.h>
17454 +#include <linux/aufs_type.h>
17456 +/* ---------------------------------------------------------------------- */
17458 +typedef unsigned int au_gen_t;
17459 +/* see linux/include/linux/jiffies.h */
17460 +#define AuGenYounger(a, b) ((int)(b) - (int)(a) < 0)
17461 +#define AuGenOlder(a, b) AufsGenYounger(b, a)
17463 +/* ---------------------------------------------------------------------- */
17465 +struct au_splhead {
17467 + struct list_head head;
17470 +static inline void au_spl_init(struct au_splhead *spl)
17472 + spin_lock_init(&spl->spin);
17473 + INIT_LIST_HEAD(&spl->head);
17476 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
17478 + spin_lock(&spl->spin);
17479 + list_add(list, &spl->head);
17480 + spin_unlock(&spl->spin);
17483 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
17485 + spin_lock(&spl->spin);
17487 + spin_unlock(&spl->spin);
17490 +/* ---------------------------------------------------------------------- */
17493 + struct rw_semaphore rwsem;
17494 +#ifdef CONFIG_AUFS_DEBUG
17499 +#ifdef CONFIG_AUFS_DEBUG
17500 +#define AuDbgRcntInit(rw) do { \
17501 + atomic_set(&(rw)->rcnt, 0); \
17502 + smp_mb(); /* atomic set */ \
17505 +#define AuDbgRcntInc(rw) atomic_inc_return(&(rw)->rcnt)
17506 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
17508 +#define AuDbgRcntInit(rw) do {} while (0)
17509 +#define AuDbgRcntInc(rw) do {} while (0)
17510 +#define AuDbgRcntDec(rw) do {} while (0)
17511 +#endif /* CONFIG_AUFS_DEBUG */
17513 +#define au_rwsem_destroy(rw) AuDebugOn(rwsem_is_locked(&(rw)->rwsem))
17515 +static inline void au_rw_init_nolock(struct au_rwsem *rw)
17517 + AuDbgRcntInit(rw);
17518 + init_rwsem(&rw->rwsem);
17521 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
17523 + au_rw_init_nolock(rw);
17524 + down_write(&rw->rwsem);
17527 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
17528 + unsigned int lsc)
17530 + au_rw_init_nolock(rw);
17531 + down_write_nested(&rw->rwsem, lsc);
17534 +static inline void au_rw_read_lock(struct au_rwsem *rw)
17536 + down_read(&rw->rwsem);
17537 + AuDbgRcntInc(rw);
17540 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
17542 + down_read_nested(&rw->rwsem, lsc);
17543 + AuDbgRcntInc(rw);
17546 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
17548 + AuDbgRcntDec(rw);
17549 + up_read(&rw->rwsem);
17552 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
17554 + AuDbgRcntInc(rw);
17555 + downgrade_write(&rw->rwsem);
17558 +static inline void au_rw_write_lock(struct au_rwsem *rw)
17560 + down_write(&rw->rwsem);
17563 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
17564 + unsigned int lsc)
17566 + down_write_nested(&rw->rwsem, lsc);
17569 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
17571 + up_write(&rw->rwsem);
17574 +/* why is not _nested version defined */
17575 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
17577 + int ret = down_read_trylock(&rw->rwsem);
17579 + AuDbgRcntInc(rw);
17583 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
17585 + return down_write_trylock(&rw->rwsem);
17588 +#undef AuDbgRcntInit
17589 +#undef AuDbgRcntInc
17590 +#undef AuDbgRcntDec
17592 +/* to debug easier, do not make them inlined functions */
17593 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
17594 +#define AuRwMustAnyLock(rw) AuDebugOn(down_write_trylock(&(rw)->rwsem))
17595 +#ifdef CONFIG_AUFS_DEBUG
17596 +#define AuRwMustReadLock(rw) do { \
17597 + AuRwMustAnyLock(rw); \
17598 + AuDebugOn(!atomic_read(&(rw)->rcnt)); \
17601 +#define AuRwMustWriteLock(rw) do { \
17602 + AuRwMustAnyLock(rw); \
17603 + AuDebugOn(atomic_read(&(rw)->rcnt)); \
17606 +#define AuRwMustReadLock(rw) AuRwMustAnyLock(rw)
17607 +#define AuRwMustWriteLock(rw) AuRwMustAnyLock(rw)
17608 +#endif /* CONFIG_AUFS_DEBUG */
17610 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
17611 +static inline void prefix##_read_lock(param) \
17612 +{ au_rw_read_lock(&(rwsem)); } \
17613 +static inline void prefix##_write_lock(param) \
17614 +{ au_rw_write_lock(&(rwsem)); } \
17615 +static inline int prefix##_read_trylock(param) \
17616 +{ return au_rw_read_trylock(&(rwsem)); } \
17617 +static inline int prefix##_write_trylock(param) \
17618 +{ return au_rw_write_trylock(&(rwsem)); }
17619 +/* static inline void prefix##_read_trylock_nested(param, lsc)
17620 +{au_rw_read_trylock_nested(&(rwsem, lsc));}
17621 +static inline void prefix##_write_trylock_nestd(param, lsc)
17622 +{au_rw_write_trylock_nested(&(rwsem), nested);} */
17624 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
17625 +static inline void prefix##_read_unlock(param) \
17626 +{ au_rw_read_unlock(&(rwsem)); } \
17627 +static inline void prefix##_write_unlock(param) \
17628 +{ au_rw_write_unlock(&(rwsem)); } \
17629 +static inline void prefix##_downgrade_lock(param) \
17630 +{ au_rw_dgrade_lock(&(rwsem)); }
17632 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
17633 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
17634 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
17636 +/* ---------------------------------------------------------------------- */
17638 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
17640 +struct au_nd_store {
17641 + unsigned int flags;
17642 + struct path path;
17643 + struct open_intent intent;
17646 +void au_nd_store(struct au_nd_store *store, struct nameidata *nd,
17647 + struct au_sbinfo *sbinfo);
17648 +void au_nd_revert(struct au_nd_store *store, struct nameidata *nd,
17649 + struct au_sbinfo *sbinfo);
17651 +struct nameidata *au_dup_nd(struct au_sbinfo *sbinfo, struct nameidata *dst,
17652 + struct nameidata *src);
17654 +struct nameidata *au_fake_dm(struct nameidata *fake_nd, struct nameidata *nd,
17655 + struct super_block *sb, aufs_bindex_t bindex);
17656 +void au_fake_dm_release(struct nameidata *fake_nd);
17657 +struct vfsub_args;
17658 +int au_h_create(struct inode *h_dir, struct dentry *h_dentry, int mode,
17659 + struct vfsub_args *vargs, struct nameidata *nd,
17660 + struct vfsmount *nfsmnt);
17663 +int au_copy_file(struct file *dst, struct file *src, loff_t len,
17664 + struct au_hinode *hdir, struct super_block *sb,
17665 + struct vfsub_args *vargs);
17667 +#endif /* __KERNEL__ */
17668 +#endif /* __AUFS_MISC_H__ */
17669 diff -urN linux/fs/aufs/module.c linux-aufs/fs/aufs/module.c
17670 --- linux/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
17671 +++ linux-aufs/fs/aufs/module.c 2009-03-12 16:18:04.000000000 +0100
17674 + * Copyright (C) 2005-2009 Junjiro Okajima
17676 + * This program, aufs is free software; you can redistribute it and/or modify
17677 + * it under the terms of the GNU General Public License as published by
17678 + * the Free Software Foundation; either version 2 of the License, or
17679 + * (at your option) any later version.
17681 + * This program is distributed in the hope that it will be useful,
17682 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17683 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17684 + * GNU General Public License for more details.
17686 + * You should have received a copy of the GNU General Public License
17687 + * along with this program; if not, write to the Free Software
17688 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17692 + * module global variables and operations
17697 +#include <linux/module.h>
17700 +/* ---------------------------------------------------------------------- */
17705 +struct kmem_cache *au_cachep[AuCache_Last];
17706 +static int __init create_cache(void)
17708 + au_cachep[AuCache_DINFO] = AuCache(au_dinfo);
17709 + if (au_cachep[AuCache_DINFO])
17710 + au_cachep[AuCache_ICNTNR] = AuCache(aufs_icntnr);
17711 + if (au_cachep[AuCache_ICNTNR])
17712 + au_cachep[AuCache_FINFO] = AuCache(au_finfo);
17713 + if (au_cachep[AuCache_FINFO])
17714 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
17715 + if (au_cachep[AuCache_VDIR])
17716 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
17717 + if (au_cachep[AuCache_DEHSTR])
17723 +static void destroy_cache(void)
17726 + for (i = 0; i < AuCache_Last; i++)
17727 + if (au_cachep[i]) {
17728 + kmem_cache_destroy(au_cachep[i]);
17729 + au_cachep[i] = NULL;
17733 +/* ---------------------------------------------------------------------- */
17735 +char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
17736 +int au_dir_roflags;
17739 + * functions for module interface.
17741 +MODULE_LICENSE("GPL");
17742 +/* MODULE_LICENSE("GPL v2"); */
17743 +MODULE_AUTHOR("Junjiro Okajima");
17744 +MODULE_DESCRIPTION(AUFS_NAME " -- Another unionfs");
17745 +MODULE_VERSION(AUFS_VERSION);
17747 +/* it should be 'byte', but param_set_byte() prints it by "%c" */
17748 +short aufs_nwkq = AUFS_NWKQ_DEF;
17749 +MODULE_PARM_DESC(nwkq, "the number of workqueue thread, " AUFS_WKQ_NAME);
17750 +module_param_named(nwkq, aufs_nwkq, short, S_IRUGO);
17753 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
17754 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
17756 +/* ---------------------------------------------------------------------- */
17758 +static int __init aufs_init(void)
17764 +#ifdef CONFIG_AUFS_INO_T_64
17765 + BUILD_BUG_ON(sizeof(ino_t) != sizeof(long long));
17767 + BUILD_BUG_ON(sizeof(ino_t) != sizeof(int));
17770 + p = au_esc_chars;
17771 + for (i = 1; i <= ' '; i++)
17777 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
17780 + if (unlikely(aufs_nwkq <= 0))
17783 + err = sysaufs_init();
17784 + if (unlikely(err))
17786 + err = au_wkq_init();
17787 + if (unlikely(err))
17788 + goto out_sysaufs;
17789 + err = au_inotify_init();
17790 + if (unlikely(err))
17792 + err = au_sysrq_init();
17793 + if (unlikely(err))
17794 + goto out_inotify;
17796 + err = create_cache();
17797 + if (unlikely(err))
17800 + err = register_filesystem(&aufs_fs_type);
17801 + if (unlikely(err))
17803 + pr_info(AUFS_NAME " " AUFS_VERSION "\n");
17804 + return 0; /* success */
17811 + au_inotify_fin();
17821 +static void __exit aufs_exit(void)
17823 + unregister_filesystem(&aufs_fs_type);
17827 + au_inotify_fin();
17832 +module_init(aufs_init);
17833 +module_exit(aufs_exit);
17835 +/* ---------------------------------------------------------------------- */
17837 +/* fake Kconfig */
17840 +#if AUFS_BRANCH_MAX > 511 && PAGE_SIZE > 4096
17841 +#warning pagesize is larger than 4kb, \
17842 + CONFIG_AUFS_BRANCH_MAX_511 or smaller is recommended.
17845 +#ifdef CONFIG_AUFS_STAT
17846 +#ifndef CONFIG_SYSFS
17847 +#error CONFIG_AUFS_STAT requires CONFIG_SYSFS.
17849 +#endif /* CONFIG_AUFS_STAT */
17851 +#ifdef CONFIG_AUFS_SYSAUFS
17852 +#warning CONFIG_AUFS_SYSAUFS is unnecessary for linux-2.6.25 and later.
17855 +#ifdef CONFIG_AUFS_HINOTIFY
17856 +#ifndef CONFIG_INOTIFY
17857 +#error enable CONFIG_INOTIFY to use CONFIG_AUFS_HINOTIFY.
17859 +#endif /* CONFIG_AUFS_HINOTIFY */
17861 +#ifdef CONFIG_AUFS_EXPORT
17862 +#if !defined(CONFIG_EXPORTFS) && !defined(CONFIG_EXPORTFS_MODULE)
17863 +#error CONFIG_AUFS_EXPORT requires CONFIG_EXPORTFS
17865 +#if defined(CONFIG_EXPORTFS_MODULE) && defined(CONFIG_AUFS)
17866 +#error need CONFIG_EXPORTFS = y to link aufs statically with CONFIG_AUFS_EXPORT.
17868 +#endif /* CONFIG_AUFS_EXPORT */
17870 +#ifdef CONFIG_AUFS_SEC_PERM_PATCH
17871 +#ifndef CONFIG_SECURITY
17872 +#warning AUFS_SEC_PERM_PATCH is unnecessary since SECURITY is disabled.
17874 +#ifdef CONFIG_AUFS
17875 +#warning AUFS_SEC_PERM_PATCH is unnecessary since AUFS is not a module.
17879 +#ifdef CONFIG_AUFS_LHASH_PATCH
17880 +#if !defined(CONFIG_NFS_FS) && !defined(CONFIG_NFS_FS_MODULE)
17881 +#warning CONFIG_AUFS_LHASH_PATCH is unnecessary since CONFIG_NFS_FS is disabled.
17885 +#ifdef CONFIG_AUFS_PUT_FILP_PATCH
17886 +#ifndef CONFIG_NFS_V4
17887 +#warning AUFS_PUT_FILP_PATCH is unnecessary since NFS_V4 is disabled.
17889 +#ifdef CONFIG_AUFS
17890 +#warning AUFS_PUT_FILP_PATCH is unnecessary since AUFS is not a module.
17892 +#endif /* CONFIG_AUFS_PUT_FILP_PATCH */
17894 +#ifdef CONFIG_AUFS_FSYNC_SUPER_PATCH
17895 +#ifdef CONFIG_AUFS
17896 +#warning AUFS_FSYNC_SUPER_PATCH is unnecessary since AUFS is not a module.
17900 +#ifdef CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH
17901 +#ifdef CONFIG_AUFS
17902 +#warning AUFS_DENY_WRITE_ACCESS_PATCH is unnecessary since AUFS is not a module.
17906 +#ifdef CONFIG_AUFS_KSIZE_PATCH
17907 +#warning CONFIG_AUFS_KSIZE_PATCH is unnecessary for linux-2.6.22 and later.
17910 +#ifdef CONFIG_AUFS_WORKAROUND_FUSE
17911 +#if !defined(CONFIG_FUSE_FS) && !defined(CONFIG_FUSE_FS_MODULE)
17912 +#warning CONFIG_AUFS_WORKAROUND_FUSE is enabled while FUSE is disabled.
17916 +#ifdef CONFIG_AUFS_DEBUG_LOCK
17917 +#ifndef CONFIG_AUFS_MAGIC_SYSRQ
17918 +#warning CONFIG_AUFS_DEBUG_LOCK is enabled but CONFIG_AUFS_MAGIC_SYSRQ.
17922 +#ifdef CONFIG_AUFS_COMPAT
17923 +#warning CONFIG_AUFS_COMPAT will be removed in the near future.
17926 +#ifdef CONFIG_AUFS_UNIONFS23_PATCH
17927 +#ifndef CONFIG_AUFS_UNIONFS22_PATCH
17928 +#error mis-config. AUFS_UNIONFS23_PATCH is enabled but AUFS_UNIONFS22_PATCH.
17930 +#ifndef CONFIG_AUFS_SPLICE_PATCH
17931 +#error mis-config. AUFS_UNIONFS23_PATCH is enabled but AUFS_SPLICE_PATCH.
17935 +#ifdef CONFIG_DEBUG_PROVE_LOCKING
17936 +#if MAX_LOCKDEP_SUBCLASSES < AuLsc_I_End
17937 +#warning lockdep will not work since aufs uses deeper locks.
17942 diff -urN linux/fs/aufs/module.h linux-aufs/fs/aufs/module.h
17943 --- linux/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
17944 +++ linux-aufs/fs/aufs/module.h 2009-03-12 16:18:04.000000000 +0100
17947 + * Copyright (C) 2005-2009 Junjiro Okajima
17949 + * This program, aufs is free software; you can redistribute it and/or modify
17950 + * it under the terms of the GNU General Public License as published by
17951 + * the Free Software Foundation; either version 2 of the License, or
17952 + * (at your option) any later version.
17954 + * This program is distributed in the hope that it will be useful,
17955 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17956 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17957 + * GNU General Public License for more details.
17959 + * You should have received a copy of the GNU General Public License
17960 + * along with this program; if not, write to the Free Software
17961 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17965 + * module initialization and module-global
17970 +#ifndef __AUFS_MODULE_H__
17971 +#define __AUFS_MODULE_H__
17975 +/* module parameters */
17976 +extern short aufs_nwkq;
17977 +extern int sysaufs_brs;
17979 +/* ---------------------------------------------------------------------- */
17981 +extern char au_esc_chars[];
17982 +extern int au_dir_roflags;
17991 +#ifdef CONFIG_AUFS_HINOTIFY
17992 + AuCache_HINOTIFY,
17997 +extern struct kmem_cache *au_cachep[];
17999 +#define AuCacheArgs(type, sz) (type), (sz), 0, SLAB_RECLAIM_ACCOUNT, NULL
18000 +#define AuCache(type) \
18001 + kmem_cache_create(AuCacheArgs(#type, sizeof(struct type)))
18003 +/* ---------------------------------------------------------------------- */
18005 +#define AuCacheFuncs(name, index) \
18006 +static inline void *au_cache_alloc_##name(void) \
18007 +{ return kmem_cache_alloc(au_cachep[index], GFP_NOFS); } \
18008 +static inline void au_cache_free_##name(void *p) \
18009 +{ kmem_cache_free(au_cachep[index], p); }
18011 +AuCacheFuncs(dinfo, AuCache_DINFO);
18012 +AuCacheFuncs(icntnr, AuCache_ICNTNR);
18013 +AuCacheFuncs(finfo, AuCache_FINFO);
18014 +AuCacheFuncs(vdir, AuCache_VDIR);
18015 +AuCacheFuncs(dehstr, AuCache_DEHSTR);
18017 +#endif /* __KERNEL__ */
18018 +#endif /* __AUFS_MODULE_H__ */
18019 diff -urN linux/fs/aufs/opts.c linux-aufs/fs/aufs/opts.c
18020 --- linux/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
18021 +++ linux-aufs/fs/aufs/opts.c 2009-03-12 16:18:04.000000000 +0100
18024 + * Copyright (C) 2005-2009 Junjiro Okajima
18026 + * This program, aufs is free software; you can redistribute it and/or modify
18027 + * it under the terms of the GNU General Public License as published by
18028 + * the Free Software Foundation; either version 2 of the License, or
18029 + * (at your option) any later version.
18031 + * This program is distributed in the hope that it will be useful,
18032 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18033 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18034 + * GNU General Public License for more details.
18036 + * You should have received a copy of the GNU General Public License
18037 + * along with this program; if not, write to the Free Software
18038 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18042 + * mount options/flags
18047 +#include <linux/types.h> /* a distribution requires */
18048 +#include <linux/parser.h>
18051 +/* ---------------------------------------------------------------------- */
18055 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
18056 + Opt_idel, Opt_imod, Opt_ireorder,
18057 + Opt_dirwh, Opt_rdcache, Opt_deblk, Opt_nhash, Opt_rendir,
18058 + Opt_xino, Opt_zxino, Opt_noxino,
18059 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
18060 + Opt_trunc_xino_path, Opt_itrunc_xino,
18062 + Opt_trunc_xib, Opt_notrunc_xib,
18063 + Opt_dirperm1, Opt_nodirperm1,
18064 + Opt_shwh, Opt_noshwh,
18065 + Opt_plink, Opt_noplink, Opt_list_plink, Opt_clean_plink,
18067 + /* Opt_lock, Opt_unlock, */
18068 + Opt_cmd, Opt_cmd_args,
18069 + Opt_diropq_a, Opt_diropq_w,
18070 + Opt_warn_perm, Opt_nowarn_perm,
18071 + Opt_wbr_copyup, Opt_wbr_create,
18073 + Opt_dlgt, Opt_nodlgt,
18074 + Opt_refrof, Opt_norefrof,
18075 + Opt_verbose, Opt_noverbose,
18076 + Opt_sum, Opt_nosum, Opt_wsum,
18077 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
18080 +static match_table_t options = {
18081 + {Opt_br, "br=%s"},
18082 + {Opt_br, "br:%s"},
18084 + {Opt_add, "add=%d:%s"},
18085 + {Opt_add, "add:%d:%s"},
18086 + {Opt_add, "ins=%d:%s"},
18087 + {Opt_add, "ins:%d:%s"},
18088 + {Opt_append, "append=%s"},
18089 + {Opt_append, "append:%s"},
18090 + {Opt_prepend, "prepend=%s"},
18091 + {Opt_prepend, "prepend:%s"},
18093 + {Opt_del, "del=%s"},
18094 + {Opt_del, "del:%s"},
18095 + /* {Opt_idel, "idel:%d"}, */
18096 + {Opt_mod, "mod=%s"},
18097 + {Opt_mod, "mod:%s"},
18098 + {Opt_imod, "imod:%d:%s"},
18100 + {Opt_dirwh, "dirwh=%d"},
18101 + {Opt_dirwh, "dirwh:%d"},
18103 + {Opt_xino, "xino=%s"},
18104 + {Opt_xino, "xino:%s"},
18105 +#if 0 /* def CONFIG_AUFS_EXPORT */ /* reserved for futur use */
18106 + {Opt_xinodir, "xinodir=%s"},
18107 + {Opt_xinodir, "xinodir:%s"},
18109 + {Opt_noxino, "noxino"},
18110 + {Opt_trunc_xino, "trunc_xino"},
18111 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
18112 + {Opt_notrunc_xino, "notrunc_xino"},
18113 + {Opt_trunc_xino_path, "trunc_xino=%s"},
18114 + {Opt_trunc_xino_path, "trunc_xino:%s"},
18115 + {Opt_itrunc_xino, "itrunc_xino=%d"},
18116 + {Opt_itrunc_xino, "itrunc_xino:%d"},
18117 + /* {Opt_zxino, "zxino=%s"}, */
18118 + {Opt_trunc_xib, "trunc_xib"},
18119 + {Opt_notrunc_xib, "notrunc_xib"},
18121 + {Opt_plink, "plink"},
18122 + {Opt_noplink, "noplink"},
18123 +#ifdef CONFIG_AUFS_DEBUG
18124 + {Opt_list_plink, "list_plink"},
18126 + {Opt_clean_plink, "clean_plink"},
18128 + {Opt_udba, "udba=%s"},
18130 + {Opt_diropq_a, "diropq=always"},
18131 + {Opt_diropq_a, "diropq=a"},
18132 + {Opt_diropq_w, "diropq=whiteouted"},
18133 + {Opt_diropq_w, "diropq=w"},
18135 + {Opt_warn_perm, "warn_perm"},
18136 + {Opt_nowarn_perm, "nowarn_perm"},
18138 +#ifdef CONFIG_AUFS_DLGT
18139 + {Opt_dlgt, "dlgt"},
18140 + {Opt_dirperm1, "dirperm1"},
18142 + {Opt_nodlgt, "nodlgt"},
18143 + {Opt_nodirperm1, "nodirperm1"},
18145 +#ifdef CONFIG_AUFS_SHWH
18146 + {Opt_shwh, "shwh"},
18148 + {Opt_noshwh, "noshwh"},
18150 + {Opt_rendir, "rendir=%d"},
18151 + {Opt_rendir, "rendir:%d"},
18153 + {Opt_refrof, "refrof"},
18154 + {Opt_norefrof, "norefrof"},
18156 + {Opt_verbose, "verbose"},
18157 + {Opt_verbose, "v"},
18158 + {Opt_noverbose, "noverbose"},
18159 + {Opt_noverbose, "quiet"},
18160 + {Opt_noverbose, "q"},
18161 + {Opt_noverbose, "silent"},
18163 + {Opt_sum, "sum"},
18164 + {Opt_nosum, "nosum"},
18165 + {Opt_wsum, "wsum"},
18167 + {Opt_rdcache, "rdcache=%d"},
18168 + {Opt_rdcache, "rdcache:%d"},
18170 + {Opt_coo, "coo=%s"},
18172 + {Opt_wbr_create, "create=%s"},
18173 + {Opt_wbr_create, "create:%s"},
18174 + {Opt_wbr_create, "create_policy=%s"},
18175 + {Opt_wbr_create, "create_policy:%s"},
18176 + {Opt_wbr_copyup, "cpup=%s"},
18177 + {Opt_wbr_copyup, "cpup:%s"},
18178 + {Opt_wbr_copyup, "copyup=%s"},
18179 + {Opt_wbr_copyup, "copyup:%s"},
18180 + {Opt_wbr_copyup, "copyup_policy=%s"},
18181 + {Opt_wbr_copyup, "copyup_policy:%s"},
18183 + /* internal use for the scripts */
18184 + {Opt_ignore_silent, "si=%s"},
18186 +#if 0 /* reserved for future use */
18187 + {Opt_deblk, "deblk=%d"},
18188 + {Opt_deblk, "deblk:%d"},
18189 + {Opt_nhash, "nhash=%d"},
18190 + {Opt_nhash, "nhash:%d"},
18193 + {Opt_br, "dirs=%s"},
18194 + {Opt_ignore, "debug=%d"},
18195 + {Opt_ignore, "delete=whiteout"},
18196 + {Opt_ignore, "delete=all"},
18197 + {Opt_ignore, "imap=%s"},
18202 +/* ---------------------------------------------------------------------- */
18204 +static const char *au_parser_pattern(int val, struct match_token *token)
18206 + while (token->pattern) {
18207 + if (token->token == val)
18208 + return token->pattern;
18215 +/* ---------------------------------------------------------------------- */
18221 +#define NoLinkWH "nolwh"
18223 +static match_table_t brperms = {
18224 + {AuBrPerm_RR, RR},
18225 + {AuBrPerm_RO, RO},
18226 + {AuBrPerm_RW, RW},
18228 + {AuBrPerm_RRWH, RR "+" WH},
18229 + {AuBrPerm_ROWH, RO "+" WH},
18230 + {AuBrPerm_RWNoLinkWH, RW "+" NoLinkWH},
18232 + {AuBrPerm_ROWH, "nfsro"},
18233 + {AuBrPerm_RO, NULL}
18236 +static noinline_for_stack int br_perm_val(char *perm)
18239 + substring_t args[MAX_OPT_ARGS];
18241 + AuDebugOn(!perm || !*perm);
18242 + LKTRTrace("perm %s\n", perm);
18243 + val = match_token(perm, brperms, args);
18248 +const char *au_optstr_br_perm(int brperm)
18250 + return au_parser_pattern(brperm, (void *)brperms);
18253 +/* ---------------------------------------------------------------------- */
18255 +static match_table_t udbalevel = {
18256 + {AuOpt_UDBA_REVAL, "reval"},
18257 +#ifdef CONFIG_AUFS_HINOTIFY
18258 + {AuOpt_UDBA_INOTIFY, "inotify"},
18260 + {AuOpt_UDBA_NONE, "none"},
18264 +static noinline_for_stack int udba_val(char *str)
18266 + substring_t args[MAX_OPT_ARGS];
18267 + return match_token(str, udbalevel, args);
18270 +const char *au_optstr_udba(int udba)
18272 + return au_parser_pattern(udba, (void *)udbalevel);
18275 +/* ---------------------------------------------------------------------- */
18277 +static match_table_t coolevel = {
18278 + {AuOpt_COO_NONE, "none"},
18279 + {AuOpt_COO_LEAF, "leaf"},
18280 + {AuOpt_COO_ALL, "all"},
18284 +static noinline_for_stack int coo_val(char *str)
18286 + substring_t args[MAX_OPT_ARGS];
18287 + return match_token(str, coolevel, args);
18290 +const char *au_optstr_coo(int coo)
18292 + return au_parser_pattern(coo, (void *)coolevel);
18295 +/* ---------------------------------------------------------------------- */
18297 +static match_table_t au_wbr_create_policy = {
18298 + {AuWbrCreate_TDP, "tdp"},
18299 + {AuWbrCreate_TDP, "top-down-parent"},
18300 + {AuWbrCreate_RR, "rr"},
18301 + {AuWbrCreate_RR, "round-robin"},
18302 + {AuWbrCreate_MFS, "mfs"},
18303 + {AuWbrCreate_MFS, "most-free-space"},
18304 + {AuWbrCreate_MFSV, "mfs:%d"},
18305 + {AuWbrCreate_MFSV, "most-free-space:%d"},
18307 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
18308 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
18309 + {AuWbrCreate_PMFS, "pmfs"},
18310 + {AuWbrCreate_PMFSV, "pmfs:%d"},
18315 +/* cf. linux/lib/parser.c */
18316 +static int au_match_ull(substring_t *s, unsigned long long *result)
18319 + unsigned int len;
18323 + len = s->to - s->from;
18324 + if (len + 1 <= sizeof(a)) {
18325 + memcpy(a, s->from, len);
18328 + err = strict_strtoull(a, 0, result);
18331 + *result = memparse(a, &next);
18333 + if (!IS_ERR((void *)err))
18340 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
18341 + struct au_opt_wbr_create *create)
18344 + unsigned long long ull;
18347 + if (!au_match_ull(arg, &ull))
18348 + create->mfsrr_watermark = ull;
18350 + AuErr("bad integer in %s\n", str);
18358 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
18359 + struct au_opt_wbr_create *create)
18364 + if (!match_int(arg, &n) && 0 <= n)
18365 + create->mfs_second = n;
18367 + AuErr("bad integer in %s\n", str);
18375 +static noinline_for_stack
18376 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
18379 + substring_t args[MAX_OPT_ARGS];
18381 + err = match_token(str, au_wbr_create_policy, args);
18382 + create->wbr_create = err;
18384 + case AuWbrCreate_MFSRRV:
18385 + e = au_wbr_mfs_wmark(&args[0], str, create);
18387 + e = au_wbr_mfs_sec(&args[1], str, create);
18391 + case AuWbrCreate_MFSRR:
18392 + e = au_wbr_mfs_wmark(&args[0], str, create);
18393 + if (unlikely(e)) {
18398 + case AuWbrCreate_MFS:
18399 + case AuWbrCreate_PMFS:
18400 + create->mfs_second = AUFS_MFS_SECOND_DEF;
18402 + case AuWbrCreate_MFSV:
18403 + case AuWbrCreate_PMFSV:
18404 + e = au_wbr_mfs_sec(&args[0], str, create);
18413 +const char *au_optstr_wbr_create(int wbr_create)
18415 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
18418 +static match_table_t au_wbr_copyup_policy = {
18419 + {AuWbrCopyup_TDP, "tdp"},
18420 + {AuWbrCopyup_TDP, "top-down-parent"},
18421 + {AuWbrCopyup_BUP, "bup"},
18422 + {AuWbrCopyup_BUP, "bottom-up-parent"},
18423 + {AuWbrCopyup_BU, "bu"},
18424 + {AuWbrCopyup_BU, "bottom-up"},
18428 +static noinline_for_stack int au_wbr_copyup_val(char *str)
18430 + substring_t args[MAX_OPT_ARGS];
18431 + return match_token(str, au_wbr_copyup_policy, args);
18434 +const char *au_optstr_wbr_copyup(int wbr_copyup)
18436 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
18439 +/* ---------------------------------------------------------------------- */
18441 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
18443 +static void dump_opts(struct au_opts *opts)
18445 +#ifdef CONFIG_AUFS_DEBUG
18446 + /* reduce stack space */
18448 + struct au_opt_add *add;
18449 + struct au_opt_del *del;
18450 + struct au_opt_mod *mod;
18451 + struct au_opt_xino *xino;
18452 + struct au_opt_xinodir *xinodir;
18453 + struct au_opt_xino_itrunc *xino_itrunc;
18454 + struct au_opt_wbr_create *create;
18456 + struct au_opt *opt;
18461 + while (/* opt < opts_tail && */ opt->type != Opt_tail) {
18462 + switch (opt->type) {
18464 + u.add = &opt->add;
18465 + LKTRTrace("add {b%d, %s, 0x%x, %p}\n",
18466 + u.add->bindex, u.add->path, u.add->perm,
18467 + u.add->nd.path.dentry);
18471 + u.del = &opt->del;
18472 + LKTRTrace("del {%s, %p}\n", u.del->path, u.del->h_root);
18476 + u.mod = &opt->mod;
18477 + LKTRTrace("mod {%s, 0x%x, %p}\n",
18478 + u.mod->path, u.mod->perm, u.mod->h_root);
18481 + u.add = &opt->add;
18482 + LKTRTrace("append {b%d, %s, 0x%x, %p}\n",
18483 + u.add->bindex, u.add->path, u.add->perm,
18484 + u.add->nd.path.dentry);
18486 + case Opt_prepend:
18487 + u.add = &opt->add;
18488 + LKTRTrace("prepend {b%d, %s, 0x%x, %p}\n",
18489 + u.add->bindex, u.add->path, u.add->perm,
18490 + u.add->nd.path.dentry);
18493 + LKTRTrace("dirwh %d\n", opt->dirwh);
18495 + case Opt_rdcache:
18496 + LKTRTrace("rdcache %d\n", opt->rdcache);
18499 + u.xino = &opt->xino;
18500 + LKTRTrace("xino {%s %.*s}\n",
18502 + AuDLNPair(u.xino->file->f_dentry));
18504 + case Opt_xinodir:
18505 + u.xinodir = &opt->xinodir;
18506 + LKTRTrace("xinodir {%s %.*s}\n",
18508 + AuDLNPair(u.xinodir->path.dentry));
18510 + case Opt_trunc_xino:
18511 + LKTRLabel(trunc_xino);
18513 + case Opt_notrunc_xino:
18514 + LKTRLabel(notrunc_xino);
18516 + case Opt_trunc_xino_path:
18517 + case Opt_itrunc_xino:
18518 + u.xino_itrunc = &opt->xino_itrunc;
18519 + LKTRTrace("trunc_xino %d\n", u.xino_itrunc->bindex);
18523 + LKTRLabel(noxino);
18525 + case Opt_trunc_xib:
18526 + LKTRLabel(trunc_xib);
18528 + case Opt_notrunc_xib:
18529 + LKTRLabel(notrunc_xib);
18531 + case Opt_dirperm1:
18532 + LKTRLabel(dirperm1);
18534 + case Opt_nodirperm1:
18535 + LKTRLabel(nodirperm1);
18541 + LKTRLabel(noshwh);
18544 + LKTRLabel(plink);
18546 + case Opt_noplink:
18547 + LKTRLabel(noplink);
18549 + case Opt_list_plink:
18550 + LKTRLabel(list_plink);
18552 + case Opt_clean_plink:
18553 + LKTRLabel(clean_plink);
18556 + LKTRTrace("udba %d, %s\n",
18557 + opt->udba, au_optstr_udba(opt->udba));
18559 + case Opt_diropq_a:
18560 + LKTRLabel(diropq_a);
18562 + case Opt_diropq_w:
18563 + LKTRLabel(diropq_w);
18565 + case Opt_warn_perm:
18566 + LKTRLabel(warn_perm);
18568 + case Opt_nowarn_perm:
18569 + LKTRLabel(nowarn_perm);
18575 + LKTRLabel(nodlgt);
18578 + LKTRLabel(refrof);
18580 + case Opt_norefrof:
18581 + LKTRLabel(norefrof);
18583 + case Opt_verbose:
18584 + LKTRLabel(verbose);
18586 + case Opt_noverbose:
18587 + LKTRLabel(noverbose);
18593 + LKTRLabel(nosum);
18599 + LKTRTrace("coo %d, %s\n",
18600 + opt->coo, au_optstr_coo(opt->coo));
18602 + case Opt_wbr_create:
18603 + u.create = &opt->wbr_create;
18604 + LKTRTrace("create %d, %s\n", u.create->wbr_create,
18605 + au_optstr_wbr_create(u.create->wbr_create));
18606 + switch (u.create->wbr_create) {
18607 + case AuWbrCreate_MFSV:
18608 + case AuWbrCreate_PMFSV:
18609 + LKTRTrace("%d sec\n", u.create->mfs_second);
18611 + case AuWbrCreate_MFSRR:
18612 + LKTRTrace("%llu watermark\n",
18613 + u.create->mfsrr_watermark);
18615 + case AuWbrCreate_MFSRRV:
18616 + LKTRTrace("%llu watermark, %d sec\n",
18617 + u.create->mfsrr_watermark,
18618 + u.create->mfs_second);
18622 + case Opt_wbr_copyup:
18623 + LKTRTrace("copyup %d, %s\n", opt->wbr_copyup,
18624 + au_optstr_wbr_copyup(opt->wbr_copyup));
18634 +void au_opts_free(struct au_opts *opts)
18636 + struct au_opt *opt;
18641 + while (opt->type != Opt_tail) {
18642 + switch (opt->type) {
18645 + case Opt_prepend:
18646 + path_put(&opt->add.nd.path);
18650 + dput(opt->del.h_root);
18654 + dput(opt->mod.h_root);
18657 + fput(opt->xino.file);
18659 + case Opt_xinodir:
18660 + path_put(&opt->xinodir.path);
18667 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
18668 + struct super_block *sb, aufs_bindex_t bindex)
18671 + struct au_opt_add *add = &opt->add;
18674 + LKTRTrace("%s, b%d\n", opt_str, bindex);
18676 + add->bindex = bindex;
18677 + add->perm = AuBrPerm_Last;
18678 + add->path = opt_str;
18679 + p = strchr(opt_str, '=');
18683 + add->perm = br_perm_val(p);
18686 + /* LSM may detect it */
18687 + /* do not superio. */
18688 + err = vfsub_path_lookup(add->path, lkup_dirflags, &add->nd);
18690 + if (!p /* && add->perm == AuBrPerm_Last */) {
18691 + add->perm = AuBrPerm_RO;
18692 + if (au_test_def_rr(add->nd.path.dentry->d_sb))
18693 + add->perm = AuBrPerm_RR;
18694 + if (!bindex && !(sb_flags & MS_RDONLY))
18695 + add->perm = AuBrPerm_RW;
18696 +#ifdef CONFIG_AUFS_COMPAT
18697 + add->perm = AuBrPerm_RW;
18700 + opt->type = Opt_add;
18703 + AuErr("lookup failed %s (%d)\n", add->path, err);
18711 +/* called without aufs lock */
18712 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
18714 + int err, n, token;
18715 + struct dentry *root;
18716 + struct au_opt *opt, *opt_tail;
18717 + char *opt_str, *p;
18718 + aufs_bindex_t bindex, bend;
18719 + unsigned char skipped;
18721 + struct au_opt_del *del;
18722 + struct au_opt_mod *mod;
18723 + struct au_opt_xino *xino;
18724 + struct au_opt_xinodir *xinodir;
18725 + struct au_opt_xino_itrunc *xino_itrunc;
18726 + struct au_opt_wbr_create *create;
18728 + struct file *file;
18729 + /* reduce the stack space */
18731 + substring_t args[MAX_OPT_ARGS];
18732 + struct nameidata nd;
18735 + LKTRTrace("%s, nopts %d\n", str, opts->max_opt);
18738 + a = kmalloc(sizeof(*a), GFP_NOFS);
18739 + if (unlikely(!a))
18742 + root = sb->s_root;
18746 + opt_tail = opt + opts->max_opt - 1;
18747 + opt->type = Opt_tail;
18748 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
18750 + token = match_token(opt_str, options, a->args);
18751 + LKTRTrace("%s, token %d, a->args[0]{%p, %p}\n",
18752 + opt_str, token, a->args[0].from, a->args[0].to);
18758 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
18760 + err = opt_add(opt, opt_str, opts->sb_flags, sb,
18762 + if (unlikely(!err && ++opt > opt_tail)) {
18766 + opt->type = Opt_tail;
18771 + if (unlikely(match_int(&a->args[0], &n))) {
18772 + AuErr("bad integer in %s\n", opt_str);
18776 + err = opt_add(opt, a->args[1].from, opts->sb_flags, sb,
18780 + err = opt_add(opt, a->args[0].from, opts->sb_flags, sb,
18781 + /*dummy bindex*/1);
18783 + opt->type = token;
18785 + case Opt_prepend:
18786 + err = opt_add(opt, a->args[0].from, opts->sb_flags, sb,
18789 + opt->type = token;
18792 + u.del = &opt->del;
18793 + u.del->path = a->args[0].from;
18794 + LKTRTrace("del path %s\n", u.del->path);
18795 + /* LSM may detect it */
18796 + /* do not superio. */
18797 + err = vfsub_path_lookup(u.del->path, lkup_dirflags,
18799 + if (unlikely(err)) {
18800 + AuErr("lookup failed %s (%d)\n",
18801 + u.del->path, err);
18804 + u.del->h_root = dget(a->nd.path.dentry);
18805 + path_put(&a->nd.path);
18806 + opt->type = token;
18808 +#if 0 /* reserved for future use */
18810 + u.del = &opt->del;
18811 + u.del->path = "(indexed)";
18812 + if (unlikely(match_int(&a->args[0], &n))) {
18813 + AuErr("bad integer in %s\n", opt_str);
18817 + aufs_read_lock(root, AuLock_FLUSH);
18818 + if (bindex < 0 || au_sbend(sb) < bindex) {
18819 + AuErr("out of bounds, %d\n", bindex);
18820 + aufs_read_unlock(root, !AuLock_IR);
18824 + u.del->h_root = dget(au_h_dptr(root, bindex));
18825 + opt->type = token;
18826 + aufs_read_unlock(root, !AuLock_IR);
18830 + u.mod = &opt->mod;
18831 + u.mod->path = a->args[0].from;
18832 + p = strchr(u.mod->path, '=');
18833 + if (unlikely(!p)) {
18834 + AuErr("no permssion %s\n", opt_str);
18838 + u.mod->perm = br_perm_val(p);
18839 + LKTRTrace("mod path %s, perm 0x%x, %s\n",
18840 + u.mod->path, u.mod->perm, p);
18841 + /* LSM may detect it */
18842 + /* do not superio. */
18843 + err = vfsub_path_lookup(u.mod->path, lkup_dirflags,
18845 + if (unlikely(err)) {
18846 + AuErr("lookup failed %s (%d)\n",
18847 + u.mod->path, err);
18850 + u.mod->h_root = dget(a->nd.path.dentry);
18851 + path_put(&a->nd.path);
18852 + opt->type = token;
18854 +#ifdef IMOD /* reserved for future use */
18856 + u.mod = &opt->mod;
18857 + u.mod->path = "(indexed)";
18858 + if (unlikely(match_int(&a->args[0], &n))) {
18859 + AuErr("bad integer in %s\n", opt_str);
18863 + aufs_read_lock(root, AuLock_FLUSH);
18864 + if (bindex < 0 || au_sbend(sb) < bindex) {
18865 + AuErr("out of bounds, %d\n", bindex);
18866 + aufs_read_unlock(root, !AuLock_IR);
18869 + u.mod->perm = br_perm_val(a->args[1].from);
18870 + LKTRTrace("mod path %s, perm 0x%x, %s\n",
18871 + u.mod->path, u.mod->perm, a->args[1].from);
18873 + u.mod->h_root = dget(au_h_dptr(root, bindex));
18874 + opt->type = token;
18875 + aufs_read_unlock(root, !AuLock_IR);
18879 + u.xino = &opt->xino;
18880 + file = au_xino_create(sb, a->args[0].from, /*silent*/0);
18881 + err = PTR_ERR(file);
18882 + if (IS_ERR(file))
18885 + if (unlikely(file->f_dentry->d_sb == sb)) {
18887 + AuErr("%s must be outside\n", a->args[0].from);
18891 + u.xino->file = file;
18892 + u.xino->path = a->args[0].from;
18893 + opt->type = token;
18896 +#if 0 /* def CONFIG_AUFS_EXPORT */ /* reserved for futur use */
18897 + case Opt_xinodir:
18898 + u.xinodir = &opt->xinodir;
18899 + u.xinodir->name = a->args[0].from;
18900 + err = vfsub_path_lookup(u.xinodir->name, lkup_dirflags,
18902 + if (unlikely(err)) {
18903 + AuErr("lookup failed %s (%d)\n",
18904 + u.xinodir->name, err);
18907 + u.xinodir->path = a->nd.path;
18908 + /* do not path_put() */
18909 + opt->type = token;
18913 + case Opt_trunc_xino_path:
18914 + u.xino_itrunc = &opt->xino_itrunc;
18915 + p = a->args[0].from;
18916 + LKTRTrace("trunc_xino path %s\n", p);
18917 + /* LSM may detect it */
18918 + /* do not superio. */
18919 + err = vfsub_path_lookup(p, lkup_dirflags, &a->nd);
18920 + if (unlikely(err)) {
18921 + AuErr("lookup failed %s (%d)\n", p , err);
18924 + u.xino_itrunc->bindex = -1;
18925 + aufs_read_lock(root, AuLock_FLUSH);
18926 + bend = au_sbend(sb);
18927 + for (bindex = 0; bindex <= bend; bindex++) {
18928 + if (au_h_dptr(root, bindex)
18929 + == a->nd.path.dentry) {
18930 + u.xino_itrunc->bindex = bindex;
18934 + aufs_read_unlock(root, !AuLock_IR);
18935 + path_put(&a->nd.path);
18936 + if (unlikely(u.xino_itrunc->bindex < 0)) {
18937 + AuErr("no such branch %s\n", p);
18941 + opt->type = token;
18944 + case Opt_itrunc_xino:
18945 + u.xino_itrunc = &opt->xino_itrunc;
18946 + if (unlikely(match_int(&a->args[0], &n))) {
18947 + AuErr("bad integer in %s\n", opt_str);
18950 + u.xino_itrunc->bindex = n;
18951 + aufs_read_lock(root, AuLock_FLUSH);
18952 + if (n < 0 || au_sbend(sb) < n) {
18953 + AuErr("out of bounds, %d\n", n);
18954 + aufs_read_unlock(root, !AuLock_IR);
18957 + aufs_read_unlock(root, !AuLock_IR);
18959 + opt->type = token;
18963 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
18966 + opt->type = token;
18969 + case Opt_rdcache:
18970 + if (unlikely(match_int(&a->args[0], &opt->rdcache)))
18973 + opt->type = token;
18977 + if (opts->sb_flags & MS_RDONLY) {
18979 + opt->type = token;
18981 + AuErr("shwh requires ro\n");
18984 + case Opt_trunc_xino:
18985 + case Opt_notrunc_xino:
18987 + case Opt_trunc_xib:
18988 + case Opt_notrunc_xib:
18989 + case Opt_dirperm1:
18990 + case Opt_nodirperm1:
18993 + case Opt_noplink:
18994 + case Opt_list_plink:
18995 + case Opt_clean_plink:
18996 + case Opt_diropq_a:
18997 + case Opt_diropq_w:
18998 + case Opt_warn_perm:
18999 + case Opt_nowarn_perm:
19003 + case Opt_norefrof:
19004 + case Opt_verbose:
19005 + case Opt_noverbose:
19010 + opt->type = token;
19014 + opt->udba = udba_val(a->args[0].from);
19015 + if (opt->udba >= 0) {
19017 + opt->type = token;
19019 + AuErr("wrong value, %s\n", opt_str);
19022 + case Opt_wbr_create:
19023 + u.create = &opt->wbr_create;
19024 + u.create->wbr_create
19025 + = au_wbr_create_val(a->args[0].from, u.create);
19026 + if (u.create->wbr_create >= 0) {
19028 + opt->type = token;
19030 + AuErr("wrong value, %s\n", opt_str);
19032 + case Opt_wbr_copyup:
19033 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
19034 + if (opt->wbr_copyup >= 0) {
19036 + opt->type = token;
19038 + AuErr("wrong value, %s\n", opt_str);
19042 + opt->coo = coo_val(a->args[0].from);
19043 + if (opt->coo >= 0) {
19044 + if (opt->coo == AuOpt_COO_NONE
19045 + || !(opts->sb_flags & MS_RDONLY)) {
19047 + opt->type = token;
19049 + AuErr("bad %s for readonly mount\n",
19052 + AuErr("wrong value, %s\n", opt_str);
19056 +#ifndef CONFIG_AUFS_COMPAT
19057 + AuWarn("ignored %s\n", opt_str);
19059 + case Opt_ignore_silent:
19064 + AuErr("unknown option %s\n", opt_str);
19068 + if (!err && !skipped) {
19069 + if (unlikely(++opt > opt_tail)) {
19072 + opt->type = Opt_tail;
19075 + opt->type = Opt_tail;
19081 + if (unlikely(err))
19082 + au_opts_free(opts);
19091 + * plus: processed without an error
19092 + * zero: unprocessed
19094 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
19095 + struct au_opts *opts)
19098 + struct au_sbinfo *sbinfo;
19099 + struct au_opt_wbr_create *create;
19103 + err = 1; /* handled */
19104 + sbinfo = au_sbi(sb);
19105 + switch (opt->type) {
19107 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
19108 + sbinfo->si_mntflags |= opt->udba;
19109 + opts->given_udba |= opt->udba;
19113 + au_opt_set(sbinfo->si_mntflags, PLINK);
19115 + case Opt_noplink:
19116 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
19117 + au_plink_put(sb);
19118 + au_opt_clr(sbinfo->si_mntflags, PLINK);
19120 + case Opt_list_plink:
19121 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
19122 + au_plink_list(sb);
19124 + case Opt_clean_plink:
19125 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
19126 + au_plink_put(sb);
19129 + case Opt_diropq_a:
19130 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
19132 + case Opt_diropq_w:
19133 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
19137 + au_opt_set(sbinfo->si_mntflags, DLGT);
19140 + au_opt_clr(sbinfo->si_mntflags, DLGT);
19143 + case Opt_warn_perm:
19144 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
19146 + case Opt_nowarn_perm:
19147 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
19151 + au_opt_set(sbinfo->si_mntflags, REFROF);
19153 + case Opt_norefrof:
19154 + /* au_opt_set(sbinfo->si_mntflags, COO_LEAF); */
19155 + au_opt_clr(sbinfo->si_mntflags, REFROF);
19158 + case Opt_verbose:
19159 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
19161 + case Opt_noverbose:
19162 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
19166 + au_opt_set(sbinfo->si_mntflags, SUM);
19169 + au_opt_clr(sbinfo->si_mntflags, SUM);
19170 + au_opt_set(sbinfo->si_mntflags, SUM_W);
19172 + au_opt_clr(sbinfo->si_mntflags, SUM);
19173 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
19176 + case Opt_wbr_create:
19177 + create = &opt->wbr_create;
19178 + if (sbinfo->si_wbr_create_ops->fin) {
19179 + err = sbinfo->si_wbr_create_ops->fin(sb);
19183 + sbinfo->si_wbr_create = create->wbr_create;
19184 + sbinfo->si_wbr_create_ops
19185 + = au_wbr_create_ops + create->wbr_create;
19186 + switch (create->wbr_create) {
19187 + case AuWbrCreate_MFSRRV:
19188 + case AuWbrCreate_MFSRR:
19189 + sbinfo->si_wbr_mfs.mfsrr_watermark
19190 + = create->mfsrr_watermark;
19192 + case AuWbrCreate_MFS:
19193 + case AuWbrCreate_MFSV:
19194 + case AuWbrCreate_PMFS:
19195 + case AuWbrCreate_PMFSV:
19196 + sbinfo->si_wbr_mfs.mfs_expire = create->mfs_second * HZ;
19199 + if (sbinfo->si_wbr_create_ops->init)
19200 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
19202 + case Opt_wbr_copyup:
19203 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
19204 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
19208 + sbinfo->si_mntflags &= ~AuOptMask_COO;
19209 + sbinfo->si_mntflags |= opt->coo;
19213 + sbinfo->si_dirwh = opt->dirwh;
19216 + case Opt_rdcache:
19217 + sbinfo->si_rdcache = opt->rdcache * HZ;
19220 + case Opt_trunc_xino:
19221 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
19223 + case Opt_notrunc_xino:
19224 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
19227 + case Opt_dirperm1:
19228 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
19230 + case Opt_nodirperm1:
19231 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
19235 + au_opt_set(sbinfo->si_mntflags, SHWH);
19238 + au_opt_clr(sbinfo->si_mntflags, SHWH);
19241 + case Opt_trunc_xino_path:
19242 + case Opt_itrunc_xino:
19243 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
19248 + case Opt_trunc_xib:
19249 + au_fset_opts(opts->flags, TRUNC_XIB);
19251 + case Opt_notrunc_xib:
19252 + au_fclr_opts(opts->flags, TRUNC_XIB);
19265 + * returns tri-state.
19266 + * plus: processed without an error
19267 + * zero: unprocessed
19270 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
19271 + struct au_opts *opts)
19273 + int err, do_refresh;
19278 + switch (opt->type) {
19280 + opt->add.bindex = au_sbend(sb) + 1;
19281 + if (opt->add.bindex < 0)
19282 + opt->add.bindex = 0;
19284 + case Opt_prepend:
19285 + opt->add.bindex = 0;
19288 + err = au_br_add(sb, &opt->add,
19289 + au_ftest_opts(opts->flags, REMOUNT));
19292 + au_fset_opts(opts->flags, REFRESH_DIR);
19293 + if (au_br_whable(opt->add.perm))
19294 + au_fset_opts(opts->flags, REFRESH_NONDIR);
19300 + err = au_br_del(sb, &opt->del,
19301 + au_ftest_opts(opts->flags, REMOUNT));
19304 + au_fset_opts(opts->flags, TRUNC_XIB);
19305 + au_fset_opts(opts->flags, REFRESH_DIR);
19306 + au_fset_opts(opts->flags, REFRESH_NONDIR);
19312 + err = au_br_mod(sb, &opt->mod,
19313 + au_ftest_opts(opts->flags, REMOUNT),
19317 + if (do_refresh) {
19318 + au_fset_opts(opts->flags, REFRESH_DIR);
19319 + au_fset_opts(opts->flags, REFRESH_NONDIR);
19329 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
19330 + struct au_opt_xino **opt_xino,
19331 + struct au_opt_xinodir **opt_xinodir,
19332 + struct au_opts *opts)
19335 + const int remount = !!au_ftest_opts(opts->flags, REMOUNT);
19340 + switch (opt->type) {
19342 + err = au_xino_set(sb, &opt->xino, remount);
19344 + *opt_xino = &opt->xino;
19346 +#if 0 /* def CONFIG_AUFS_EXPORT */ /* reserved for futur use */
19347 + case Opt_xinodir:
19348 + err = au_xinodir_set(sb, &opt->xinodir, remount);
19350 + *opt_xinodir = &opt->xinodir;
19355 + *opt_xino = (void *)-1;
19363 +int verify_opts(struct super_block *sb, unsigned long sb_flags,
19364 + unsigned int pending, int remount)
19367 + aufs_bindex_t bindex, bend;
19368 + unsigned char do_plink, skip, do_free;
19369 + struct au_branch *br;
19370 + struct au_wbr *wbr;
19371 + struct dentry *root;
19372 + struct inode *dir, *h_dir;
19373 + unsigned int mnt_flags;
19376 + mnt_flags = au_mntflags(sb);
19377 + AuDebugOn(!(mnt_flags & AuOptMask_COO));
19378 + AuDebugOn(!(mnt_flags & AuOptMask_UDBA));
19380 + if (!(sb_flags & MS_RDONLY)) {
19381 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
19382 + AuWarn("first branch should be rw\n");
19383 + if (unlikely(au_opt_test(mnt_flags, SHWH)))
19384 + AuWarn("shwh should be used with ro\n");
19385 + } else if (unlikely(!au_opt_test(mnt_flags, COO_NONE))) {
19386 + AuWarn("resetting coo for readonly mount\n");
19387 + au_opt_set_coo(au_sbi(sb)->si_mntflags, COO_NONE);
19390 + if (unlikely(au_opt_test((mnt_flags | pending), UDBA_INOTIFY)
19391 + && !au_opt_test_xino(mnt_flags)))
19392 + AuWarn("udba=inotify requires xino\n");
19395 + root = sb->s_root;
19396 + dir = sb->s_root->d_inode;
19397 + do_plink = !!au_opt_test(mnt_flags, PLINK);
19398 + bend = au_sbend(sb);
19399 + for (bindex = 0; !err && bindex <= bend; bindex++) {
19401 + h_dir = au_h_iptr(dir, bindex);
19402 + br = au_sbr(sb, bindex);
19404 + wbr = br->br_wbr;
19406 + wbr_wh_read_lock(wbr);
19407 + switch (br->br_perm) {
19408 + case AuBrPerm_RR:
19409 + case AuBrPerm_RO:
19410 + case AuBrPerm_RRWH:
19411 + case AuBrPerm_ROWH:
19414 + || (!wbr->wbr_whbase
19415 + && !wbr->wbr_plink
19416 + && !wbr->wbr_tmp));
19419 + case AuBrPerm_RWNoLinkWH:
19420 + /* skip = (!br->br_whbase && !br->br_tmp); */
19421 + skip = (!wbr || !wbr->wbr_whbase);
19422 + if (skip && wbr) {
19424 + skip = !!wbr->wbr_plink;
19426 + skip = !wbr->wbr_plink;
19430 + case AuBrPerm_RW:
19431 + /* skip = (br->br_whbase && br->br_tmp); */
19432 + skip = (wbr && wbr->wbr_whbase);
19435 + skip = !!wbr->wbr_plink;
19437 + skip = !wbr->wbr_plink;
19445 + wbr_wh_read_unlock(wbr);
19450 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
19452 + wbr_wh_write_lock(wbr);
19453 + err = au_wh_init(au_h_dptr(root, bindex), br, br->br_mnt, sb,
19456 + wbr_wh_write_unlock(wbr);
19457 + mutex_unlock(&h_dir->i_mutex);
19459 + if (!err && do_free) {
19461 + br->br_wbr = NULL;
19469 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
19472 + struct inode *dir;
19473 + struct au_opt *opt;
19474 + struct au_opt_xino *opt_xino, xino;
19475 + struct au_opt_xinodir *opt_xinodir;
19476 + aufs_bindex_t bend;
19477 + struct au_sbinfo *sbinfo;
19478 + unsigned int tmp;
19479 + struct au_branch *br;
19482 + SiMustWriteLock(sb);
19483 + DiMustWriteLock(sb->s_root);
19484 + dir = sb->s_root->d_inode;
19485 + IiMustWriteLock(dir);
19489 + opt_xinodir = NULL;
19491 + while (err >= 0 && opt->type != Opt_tail)
19492 + err = au_opt_simple(sb, opt++, opts);
19495 + else if (unlikely(err < 0))
19498 + /* disable xino, xinodir, hinotify, dlgt temporary */
19499 + sbinfo = au_sbi(sb);
19500 + tmp = sbinfo->si_mntflags;
19501 + au_opt_clr(sbinfo->si_mntflags, XINO);
19502 + au_opt_clr(sbinfo->si_mntflags, XINODIR);
19503 + au_opt_clr(sbinfo->si_mntflags, DLGT);
19504 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
19507 + while (err >= 0 && opt->type != Opt_tail)
19508 + err = au_opt_br(sb, opt++, opts);
19511 + else if (unlikely(err < 0))
19514 + bend = au_sbend(sb);
19515 + if (unlikely(bend < 0)) {
19517 + AuErr("no branches\n");
19521 + if (au_opt_test(tmp, XINO))
19522 + au_opt_set(sbinfo->si_mntflags, XINO);
19523 + else if (au_opt_test(tmp, XINODIR))
19524 + au_opt_set(sbinfo->si_mntflags, XINODIR);
19526 + while (!err && opt->type != Opt_tail)
19527 + err = au_opt_xino(sb, opt++, &opt_xino, &opt_xinodir, opts);
19528 + if (unlikely(err))
19531 + /* todo: test this error case? */
19532 + err = verify_opts(sb, sb->s_flags, tmp, /*remount*/0);
19533 + if (unlikely(err))
19536 + /* enable xino */
19537 + if (au_opt_test(tmp, XINO) && !opt_xino) {
19538 + xino.file = au_xino_def(sb);
19539 + err = PTR_ERR(xino.file);
19540 + if (IS_ERR(xino.file))
19543 + br = au_xino_def_br(sbinfo);
19544 + err = au_xino_set(sb, &xino, /*remount*/0);
19546 + if (unlikely(err))
19548 + au_xino_def_br_set(br, sbinfo);
19551 + /* restore hinotify */
19552 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
19553 + sbinfo->si_mntflags |= (tmp & AuOptMask_UDBA);
19554 + if (au_opt_test(tmp, UDBA_INOTIFY))
19555 + au_reset_hinotify(dir, au_hi_flags(dir, 1) & ~AuHi_XINO);
19557 + /* restore dlgt */
19558 + if (au_opt_test(tmp, DLGT))
19559 + au_opt_set(sbinfo->si_mntflags, DLGT);
19566 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
19569 + struct inode *dir;
19570 + struct au_opt_xino *opt_xino;
19571 + struct au_opt_xinodir *opt_xinodir;
19572 + struct au_opt *opt;
19573 + unsigned char dlgt;
19574 + struct au_sbinfo *sbinfo;
19577 + SiMustWriteLock(sb);
19578 + DiMustWriteLock(sb->s_root);
19579 + dir = sb->s_root->d_inode;
19580 + IiMustWriteLock(dir);
19581 + sbinfo = au_sbi(sb);
19584 + dlgt = !!au_opt_test(sbinfo->si_mntflags, DLGT);
19586 + opt_xinodir = NULL;
19588 + while (err >= 0 && opt->type != Opt_tail) {
19589 + err = au_opt_simple(sb, opt, opts);
19591 + /* disable it temporary */
19592 + dlgt = !!au_opt_test(sbinfo->si_mntflags, DLGT);
19593 + au_opt_clr(sbinfo->si_mntflags, DLGT);
19596 + err = au_opt_br(sb, opt, opts);
19598 + err = au_opt_xino(sb, opt, &opt_xino, &opt_xinodir,
19603 + au_opt_set(sbinfo->si_mntflags, DLGT);
19610 + /* go on even err */
19612 + /* todo: test this error case? */
19613 + au_opt_clr(sbinfo->si_mntflags, DLGT);
19614 + rerr = verify_opts(sb, opts->sb_flags, sbinfo->si_mntflags,
19616 + if (unlikely(dlgt))
19617 + au_opt_set(sbinfo->si_mntflags, DLGT);
19618 + if (unlikely(rerr && !err))
19621 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
19622 + rerr = au_xib_trunc(sb);
19623 + if (unlikely(rerr && !err))
19627 + /* they are handled by the caller */
19628 + if (!au_ftest_opts(opts->flags, REFRESH_DIR)
19629 + && (opts->given_udba || au_opt_test_xino(sbinfo->si_mntflags)))
19630 + au_fset_opts(opts->flags, REFRESH_DIR);
19632 + LKTRTrace("status 0x%x\n", opts->flags);
19636 diff -urN linux/fs/aufs/opts.h linux-aufs/fs/aufs/opts.h
19637 --- linux/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
19638 +++ linux-aufs/fs/aufs/opts.h 2009-03-12 16:18:04.000000000 +0100
19641 + * Copyright (C) 2005-2009 Junjiro Okajima
19643 + * This program, aufs is free software; you can redistribute it and/or modify
19644 + * it under the terms of the GNU General Public License as published by
19645 + * the Free Software Foundation; either version 2 of the License, or
19646 + * (at your option) any later version.
19648 + * This program is distributed in the hope that it will be useful,
19649 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19650 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19651 + * GNU General Public License for more details.
19653 + * You should have received a copy of the GNU General Public License
19654 + * along with this program; if not, write to the Free Software
19655 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19659 + * mount options/flags
19664 +#ifndef __AUFS_OPTS_H__
19665 +#define __AUFS_OPTS_H__
19669 +#include <linux/fs.h>
19670 +#include <linux/namei.h>
19671 +#include <linux/aufs_type.h>
19674 +/* ---------------------------------------------------------------------- */
19677 +/* external inode number bitmap and translation table */
19678 +#define AuOpt_XINO 1
19679 +#define AuOpt_XINODIR (1 << 1)
19680 +#define AuOpt_TRUNC_XINO (1 << 2)
19681 +#define AuOpt_UDBA_NONE (1 << 3) /* users direct branch access */
19682 +#define AuOpt_UDBA_REVAL (1 << 4)
19683 +#define AuOpt_UDBA_INOTIFY (1 << 5)
19684 +#define AuOpt_SHWH (1 << 6)
19685 +#define AuOpt_PLINK (1 << 7)
19686 +#define AuOpt_WARN_PERM (1 << 8)
19687 +#define AuOpt_DIRPERM1 (1 << 9)
19688 +#define AuOpt_DLGT (1 << 10)
19689 +#define AuOpt_COO_NONE (1 << 11) /* copyup on open */
19690 +#define AuOpt_COO_LEAF (1 << 12)
19691 +#define AuOpt_COO_ALL (1 << 13)
19692 +#define AuOpt_ALWAYS_DIROPQ (1 << 14)
19693 +#define AuOpt_REFROF (1 << 15)
19694 +#define AuOpt_VERBOSE (1 << 16)
19695 +#define AuOpt_SUM (1 << 17)
19696 +#define AuOpt_SUM_W (1 << 18) /* unimplemented */
19698 +#if 1 /* ndef CONFIG_AUFS_EXPORT */ /* reserved for future use */
19699 +#undef AuOpt_XINODIR
19700 +#define AuOpt_XINODIR 0
19702 +#ifndef CONFIG_AUFS_HINOTIFY
19703 +#undef AuOpt_UDBA_INOTIFY
19704 +#define AuOpt_UDBA_INOTIFY 0
19706 +#ifndef CONFIG_AUFS_SHWH
19708 +#define AuOpt_SHWH 0
19710 +#ifndef CONFIG_AUFS_DLGT
19711 +#undef AuOpt_DIRPERM1
19712 +#define AuOpt_DIRPERM1 0
19714 +#define AuOpt_DLGT 0
19717 +/* policies to select one among multiple writable branches */
19719 + AuWbrCreate_TDP, /* top down parent */
19720 + AuWbrCreate_RR, /* round robin */
19721 + AuWbrCreate_MFS, /* most free space */
19722 + AuWbrCreate_MFSV, /* mfs with seconds */
19723 + AuWbrCreate_MFSRR, /* mfs then rr */
19724 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
19725 + AuWbrCreate_PMFS, /* parent and mfs */
19726 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
19728 + AuWbrCreate_Def = AuWbrCreate_TDP
19732 + AuWbrCopyup_TDP, /* top down parent */
19733 + AuWbrCopyup_BUP, /* bottom up parent */
19734 + AuWbrCopyup_BU, /* bottom up */
19736 + AuWbrCopyup_Def = AuWbrCopyup_TDP
19739 +#define AuOptMask_COO (AuOpt_COO_NONE \
19740 + | AuOpt_COO_LEAF \
19742 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
19743 + | AuOpt_UDBA_REVAL \
19744 + | AuOpt_UDBA_INOTIFY)
19746 +#ifdef CONFIG_AUFS_COMPAT
19747 +#define AuOpt_DefExtra1 AuOpt_ALWAYS_DIROPQ
19749 +#define AuOpt_DefExtra1 0
19752 +#define AuOpt_Def (AuOpt_XINO \
19753 + | AuOpt_UDBA_REVAL \
19754 + | AuOpt_WARN_PERM \
19755 + | AuOpt_COO_NONE \
19757 + | AuOpt_DefExtra1)
19759 +/* ---------------------------------------------------------------------- */
19761 +struct au_opt_add {
19762 + aufs_bindex_t bindex;
19765 + struct nameidata nd;
19768 +struct au_opt_del {
19770 + struct dentry *h_root;
19773 +struct au_opt_mod {
19776 + struct dentry *h_root;
19779 +struct au_opt_xino {
19781 + struct file *file;
19784 +struct au_opt_xinodir {
19786 + struct path path;
19789 +struct au_opt_xino_itrunc {
19790 + aufs_bindex_t bindex;
19793 +struct au_opt_xino_trunc_v {
19794 + unsigned long long upper;
19798 +struct au_opt_wbr_create {
19801 + unsigned long long mfsrr_watermark;
19807 + struct au_opt_xino xino;
19808 + struct au_opt_xinodir xinodir;
19809 + struct au_opt_xino_itrunc xino_itrunc;
19810 + struct au_opt_add add;
19811 + struct au_opt_del del;
19812 + struct au_opt_mod mod;
19819 + struct au_opt_wbr_create wbr_create;
19825 +#define AuOpts_REMOUNT 1
19826 +#define AuOpts_REFRESH_DIR (1 << 1)
19827 +#define AuOpts_REFRESH_NONDIR (1 << 2)
19828 +#define AuOpts_TRUNC_XIB (1 << 3)
19829 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
19830 +#define au_fset_opts(flags, name) { (flags) |= AuOpts_##name; }
19831 +#define au_fclr_opts(flags, name) { (flags) &= ~AuOpts_##name; }
19834 + struct au_opt *opt;
19837 + unsigned int given_udba;
19838 + unsigned int flags;
19839 + unsigned long sb_flags;
19842 +/* ---------------------------------------------------------------------- */
19844 +const char *au_optstr_br_perm(int brperm);
19845 +const char *au_optstr_udba(int udba);
19846 +const char *au_optstr_coo(int coo);
19847 +const char *au_optstr_wbr_copyup(int wbr_copyup);
19848 +const char *au_optstr_wbr_create(int wbr_create);
19850 +void au_opts_free(struct au_opts *opts);
19851 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
19852 +int verify_opts(struct super_block *sb, unsigned long sb_flags,
19853 + unsigned int pending, int remount);
19854 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
19855 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
19857 +/* ---------------------------------------------------------------------- */
19859 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
19861 +static inline int au_opt_test_xino(unsigned int flags)
19863 + return flags & (AuOpt_XINO | AuOpt_XINODIR);
19866 +#define au_opt_set(flags, name) do { \
19867 + BUILD_BUG_ON(AuOpt_##name & (AuOptMask_COO | AuOptMask_UDBA)); \
19868 + ((flags) |= AuOpt_##name); \
19871 +#define au_opt_set_coo(flags, name) do { \
19872 + (flags) &= ~AuOptMask_COO; \
19873 + ((flags) |= AuOpt_##name); \
19876 +#define au_opt_set_udba(flags, name) do { \
19877 + (flags) &= ~AuOptMask_UDBA; \
19878 + ((flags) |= AuOpt_##name); \
19881 +#define au_opt_clr(flags, name) { ((flags) &= ~AuOpt_##name); }
19883 +static inline int au_test_dlgt(unsigned int flags)
19885 + return au_opt_test(flags, DLGT) && !au_test_wkq(current);
19888 +static inline int au_test_dirperm1(unsigned int flags)
19890 + return au_opt_test(flags, DIRPERM1) && !au_test_wkq(current);
19893 +#endif /* __KERNEL__ */
19894 +#endif /* __AUFS_OPTS_H__ */
19895 diff -urN linux/fs/aufs/plink.c linux-aufs/fs/aufs/plink.c
19896 --- linux/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
19897 +++ linux-aufs/fs/aufs/plink.c 2009-03-12 16:18:04.000000000 +0100
19900 + * Copyright (C) 2005-2009 Junjiro Okajima
19902 + * This program, aufs is free software; you can redistribute it and/or modify
19903 + * it under the terms of the GNU General Public License as published by
19904 + * the Free Software Foundation; either version 2 of the License, or
19905 + * (at your option) any later version.
19907 + * This program is distributed in the hope that it will be useful,
19908 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19909 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19910 + * GNU General Public License for more details.
19912 + * You should have received a copy of the GNU General Public License
19913 + * along with this program; if not, write to the Free Software
19914 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19925 +struct pseudo_link {
19926 + struct list_head list;
19927 + struct inode *inode;
19930 +#ifdef CONFIG_AUFS_DEBUG
19931 +void au_plink_list(struct super_block *sb)
19933 + struct au_sbinfo *sbinfo;
19934 + struct list_head *plink_list;
19935 + struct pseudo_link *plink;
19938 + SiMustAnyLock(sb);
19939 + sbinfo = au_sbi(sb);
19940 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
19942 + plink_list = &sbinfo->si_plink.head;
19943 + spin_lock(&sbinfo->si_plink.spin);
19944 + list_for_each_entry(plink, plink_list, list)
19945 + AuDbg("%lu\n", plink->inode->i_ino);
19946 + spin_unlock(&sbinfo->si_plink.spin);
19950 +int au_plink_test(struct super_block *sb, struct inode *inode)
19953 + struct au_sbinfo *sbinfo;
19954 + struct list_head *plink_list;
19955 + struct pseudo_link *plink;
19957 + LKTRTrace("i%lu\n", inode->i_ino);
19958 + SiMustAnyLock(sb);
19959 + sbinfo = au_sbi(sb);
19960 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
19963 + plink_list = &sbinfo->si_plink.head;
19964 + spin_lock(&sbinfo->si_plink.spin);
19965 + list_for_each_entry(plink, plink_list, list)
19966 + if (plink->inode == inode) {
19970 + spin_unlock(&sbinfo->si_plink.spin);
19974 +/* 20 is max digits length of ulong 64 */
19975 +#define PLINK_NAME_LEN ((20 + 1) * 2)
19977 +static int plink_name(char *name, int len, struct inode *inode,
19978 + aufs_bindex_t bindex)
19981 + struct inode *h_inode;
19983 + LKTRTrace("i%lu, b%d\n", inode->i_ino, bindex);
19984 + AuDebugOn(len != PLINK_NAME_LEN);
19985 + h_inode = au_h_iptr(inode, bindex);
19986 + AuDebugOn(!h_inode);
19987 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
19988 + AuDebugOn(rlen >= len);
19992 +struct dentry *au_plink_lkup(struct super_block *sb, aufs_bindex_t bindex,
19993 + struct inode *inode)
19995 + struct dentry *h_dentry, *h_parent;
19996 + struct au_branch *br;
19997 + struct au_wbr *wbr;
19998 + struct inode *h_dir;
19999 + char tgtname[PLINK_NAME_LEN];
20001 + struct au_ndx ndx = {
20007 + LKTRTrace("b%d, i%lu\n", bindex, inode->i_ino);
20008 + br = au_sbr(sb, bindex);
20009 + wbr = br->br_wbr;
20011 + h_parent = wbr->wbr_plink;
20012 + AuDebugOn(!h_parent);
20013 + h_dir = h_parent->d_inode;
20014 + AuDebugOn(!h_dir);
20016 + len = plink_name(tgtname, sizeof(tgtname), inode, bindex);
20018 + /* always superio. */
20019 + ndx.nfsmnt = au_do_nfsmnt(br->br_mnt);
20020 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
20021 + h_dentry = au_sio_lkup_one(tgtname, h_parent, len, &ndx);
20022 + mutex_unlock(&h_dir->i_mutex);
20026 +static int do_whplink(char *tgt, int len, struct dentry *h_parent,
20027 + struct dentry *h_dentry, struct vfsmount *nfsmnt,
20028 + struct super_block *sb)
20031 + struct dentry *h_tgt;
20032 + struct inode *h_dir;
20033 + struct vfsub_args vargs;
20034 + struct au_ndx ndx = {
20035 + .nfsmnt = nfsmnt,
20043 + dlgt = !!au_test_dlgt(au_mntflags(sb));
20045 + au_fset_ndx(ndx.flags, DLGT);
20046 + h_tgt = au_lkup_one(tgt, h_parent, len, &ndx);
20047 + err = PTR_ERR(h_tgt);
20048 + if (IS_ERR(h_tgt))
20052 + vfsub_args_init(&vargs, NULL, dlgt, 0);
20053 + /* wh.plink dir is not monitored */
20054 + h_dir = h_parent->d_inode;
20055 + if (h_tgt->d_inode && h_tgt->d_inode != h_dentry->d_inode)
20056 + err = vfsub_unlink(h_dir, h_tgt, &vargs);
20057 + if (!err && !h_tgt->d_inode) {
20058 + err = vfsub_link(h_dentry, h_dir, h_tgt, &vargs);
20059 + /* todo: unnecessary? */
20060 + /* inc_nlink(inode); */
20069 +struct do_whplink_args {
20073 + struct dentry *h_parent;
20074 + struct dentry *h_dentry;
20075 + struct vfsmount *nfsmnt;
20076 + struct super_block *sb;
20079 +static void call_do_whplink(void *args)
20081 + struct do_whplink_args *a = args;
20082 + *a->errp = do_whplink(a->tgt, a->len, a->h_parent, a->h_dentry,
20083 + a->nfsmnt, a->sb);
20086 +static int whplink(struct dentry *h_dentry, struct inode *inode,
20087 + aufs_bindex_t bindex, struct super_block *sb)
20089 + int err, len, wkq_err;
20090 + struct au_branch *br;
20091 + struct au_wbr *wbr;
20092 + struct dentry *h_parent;
20093 + struct inode *h_dir;
20094 + char tgtname[PLINK_NAME_LEN];
20096 + LKTRTrace("%.*s\n", AuDLNPair(h_dentry));
20097 + br = au_sbr(inode->i_sb, bindex);
20098 + wbr = br->br_wbr;
20100 + h_parent = wbr->wbr_plink;
20101 + AuDebugOn(!h_parent);
20102 + h_dir = h_parent->d_inode;
20103 + AuDebugOn(!h_dir);
20105 + len = plink_name(tgtname, sizeof(tgtname), inode, bindex);
20107 + /* always superio. */
20108 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
20109 + if (!au_test_wkq(current)) {
20110 + struct do_whplink_args args = {
20114 + .h_parent = h_parent,
20115 + .h_dentry = h_dentry,
20116 + .nfsmnt = au_do_nfsmnt(br->br_mnt),
20119 + wkq_err = au_wkq_wait(call_do_whplink, &args, /*dlgt*/0);
20120 + if (unlikely(wkq_err))
20123 + err = do_whplink(tgtname, len, h_parent, h_dentry,
20124 + au_do_nfsmnt(br->br_mnt), sb);
20125 + mutex_unlock(&h_dir->i_mutex);
20131 +static void do_put_plink(struct pseudo_link *plink, int do_del)
20135 + iput(plink->inode);
20137 + list_del(&plink->list);
20141 +void au_plink_append(struct super_block *sb, struct inode *inode,
20142 + struct dentry *h_dentry, aufs_bindex_t bindex)
20144 + struct au_sbinfo *sbinfo;
20145 + struct list_head *plink_list;
20146 + struct pseudo_link *plink;
20147 + int found, err, cnt;
20149 + LKTRTrace("i%lu\n", inode->i_ino);
20150 + SiMustAnyLock(sb);
20151 + sbinfo = au_sbi(sb);
20152 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
20156 + plink_list = &sbinfo->si_plink.head;
20157 + spin_lock(&sbinfo->si_plink.spin);
20158 + list_for_each_entry(plink, plink_list, list) {
20160 + if (plink->inode == inode) {
20169 + plink = kmalloc(sizeof(*plink), GFP_ATOMIC);
20171 + plink->inode = au_igrab(inode);
20172 + list_add(&plink->list, plink_list);
20177 + spin_unlock(&sbinfo->si_plink.spin);
20179 +#if 0 /* todo: test here */
20181 + return; /* success */
20185 + err = whplink(h_dentry, inode, bindex, sb);
20187 + if (unlikely(cnt > AUFS_PLINK_WARN))
20188 + AuWarn1("unexpectedly many pseudo links, %d\n", cnt);
20189 + if (unlikely(err)) {
20190 + AuWarn("err %d, damaged pseudo link. ignored.\n", err);
20191 + if (!found && plink)
20192 + do_put_plink(plink, /*do_del*/1);
20196 +void au_plink_put(struct super_block *sb)
20198 + struct au_sbinfo *sbinfo;
20199 + struct list_head *plink_list;
20200 + struct pseudo_link *plink, *tmp;
20203 + SiMustWriteLock(sb);
20204 + sbinfo = au_sbi(sb);
20205 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
20207 + plink_list = &sbinfo->si_plink.head;
20208 + /* spin_lock(&sbinfo->si_plink.spin); */
20209 + list_for_each_entry_safe(plink, tmp, plink_list, list)
20210 + do_put_plink(plink, 0);
20211 + INIT_LIST_HEAD(plink_list);
20212 + /* spin_unlock(&sbinfo->si_plink.head); */
20215 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
20217 + struct au_sbinfo *sbinfo;
20218 + struct list_head *plink_list;
20219 + struct pseudo_link *plink, *tmp;
20220 + struct inode *inode;
20221 + aufs_bindex_t bstart, bend, bindex;
20225 + SiMustWriteLock(sb);
20226 + sbinfo = au_sbi(sb);
20227 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
20229 + plink_list = &sbinfo->si_plink.head;
20230 + /* spin_lock(&sbinfo->si_plink.spin); */
20231 + list_for_each_entry_safe(plink, tmp, plink_list, list) {
20233 + inode = au_igrab(plink->inode);
20234 + ii_write_lock_child(inode);
20235 + bstart = au_ibstart(inode);
20236 + bend = au_ibend(inode);
20237 + if (bstart >= 0) {
20238 + for (bindex = bstart; bindex <= bend; bindex++) {
20239 + if (!au_h_iptr(inode, bindex)
20240 + || au_ii_br_id(inode, bindex) != br_id)
20242 + au_set_h_iptr(inode, bindex, NULL, 0);
20247 + do_put_plink(plink, 1);
20250 + for (bindex = bstart; bindex <= bend; bindex++)
20251 + if (au_h_iptr(inode, bindex)) {
20256 + do_put_plink(plink, 1);
20258 + ii_write_unlock(inode);
20261 + /* spin_unlock(&sbinfo->si_plink.spin); */
20263 diff -urN linux/fs/aufs/robr.c linux-aufs/fs/aufs/robr.c
20264 --- linux/fs/aufs/robr.c 1970-01-01 01:00:00.000000000 +0100
20265 +++ linux-aufs/fs/aufs/robr.c 2009-03-12 16:18:04.000000000 +0100
20268 + * Copyright (C) 2005-2009 Junjiro Okajima
20270 + * This program, aufs is free software; you can redistribute it and/or modify
20271 + * it under the terms of the GNU General Public License as published by
20272 + * the Free Software Foundation; either version 2 of the License, or
20273 + * (at your option) any later version.
20275 + * This program is distributed in the hope that it will be useful,
20276 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20277 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20278 + * GNU General Public License for more details.
20280 + * You should have received a copy of the GNU General Public License
20281 + * along with this program; if not, write to the Free Software
20282 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20286 + * 'robr', aufs as readonly branch of another aufs
20293 +/* ---------------------------------------------------------------------- */
20295 +int au_test_robr_wh(struct qstr *name, struct dentry *h_parent,
20296 + struct qstr *wh_name, int try_sio, struct au_ndx *ndx)
20298 + if (strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
20299 + return au_wh_test(h_parent, wh_name, try_sio, ndx);
20303 +int au_test_robr_shwh(struct super_block *sb, const struct qstr *name)
20308 +/* ---------------------------------------------------------------------- */
20310 +struct au_robr_lvma {
20311 + struct list_head list;
20312 + struct vm_area_struct *vma;
20315 +struct file *au_robr_safe_file(struct vm_area_struct *vma)
20317 + struct file *file = vma->vm_file;
20318 + struct super_block *sb = file->f_dentry->d_sb;
20319 + struct au_robr_lvma *lvma, *entry;
20320 + struct au_sbinfo *sbinfo;
20321 + struct list_head *head;
20322 + unsigned char found, warn;
20326 + if (!file->private_data || !au_test_aufs(sb))
20331 + sbinfo = au_sbi(sb);
20332 + head = &sbinfo->si_lvma.head;
20333 + spin_lock(&sbinfo->si_lvma.spin);
20334 + list_for_each_entry(entry, head, list) {
20335 + found = (entry->vma == vma);
20336 + if (unlikely(found))
20340 + lvma = kmalloc(sizeof(*lvma), GFP_ATOMIC);
20343 + list_add(&lvma->list, head);
20350 + spin_unlock(&sbinfo->si_lvma.spin);
20352 + if (unlikely(warn))
20353 + AuWarn1("no memory for lvma\n");
20357 +void au_robr_reset_file(struct vm_area_struct *vma, struct file *file)
20359 + struct super_block *sb = file->f_dentry->d_sb;
20360 + struct au_robr_lvma *entry, *found;
20361 + struct au_sbinfo *sbinfo;
20362 + struct list_head *head;
20365 + AuDebugOn(!au_test_aufs(sb));
20367 + vma->vm_file = file;
20368 + /* smp_mb(); */ /* flush vm_file */
20371 + sbinfo = au_sbi(sb);
20372 + head = &sbinfo->si_lvma.head;
20373 + spin_lock(&sbinfo->si_lvma.spin);
20374 + list_for_each_entry(entry, head, list)
20375 + if (entry->vma == vma) {
20379 + AuDebugOn(!found);
20380 + list_del(&found->list);
20381 + spin_unlock(&sbinfo->si_lvma.spin);
20384 diff -urN linux/fs/aufs/sbinfo.c linux-aufs/fs/aufs/sbinfo.c
20385 --- linux/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
20386 +++ linux-aufs/fs/aufs/sbinfo.c 2009-03-12 16:18:04.000000000 +0100
20389 + * Copyright (C) 2005-2009 Junjiro Okajima
20391 + * This program, aufs is free software; you can redistribute it and/or modify
20392 + * it under the terms of the GNU General Public License as published by
20393 + * the Free Software Foundation; either version 2 of the License, or
20394 + * (at your option) any later version.
20396 + * This program is distributed in the hope that it will be useful,
20397 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20398 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20399 + * GNU General Public License for more details.
20401 + * You should have received a copy of the GNU General Public License
20402 + * along with this program; if not, write to the Free Software
20403 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20407 + * superblock private data
20412 +#include <linux/smp_lock.h>
20416 + * they are necessary regardless sysfs is disabled.
20418 +void au_si_free(struct kobject *kobj)
20420 + struct au_sbinfo *sbinfo;
20421 + struct super_block *sb;
20423 + LKTRTrace("kobj %p\n", kobj);
20424 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
20425 + LKTRTrace("sbinfo %p\n", sbinfo);
20426 + AuDebugOn(!list_empty(&sbinfo->si_plink.head));
20428 + sb = sbinfo->si_sb;
20429 + si_write_lock(sb);
20431 + au_br_free(sbinfo);
20432 + kfree(sbinfo->si_branch);
20433 + au_export_put(sbinfo);
20434 + mutex_destroy(&sbinfo->si_xib_mtx);
20435 + si_write_unlock(sb);
20436 + au_rwsem_destroy(&sbinfo->si_rwsem);
20441 +int au_si_alloc(struct super_block *sb)
20444 + struct au_sbinfo *sbinfo;
20449 + sbinfo = kmalloc(sizeof(*sbinfo), GFP_NOFS);
20450 + if (unlikely(!sbinfo))
20452 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
20453 + if (unlikely(!sbinfo->si_branch))
20456 + memset(&sbinfo->si_kobj, 0, sizeof(sbinfo->si_kobj));
20457 + err = sysaufs_si_init(sbinfo);
20458 + if (unlikely(err))
20461 + au_rw_init_wlock(&sbinfo->si_rwsem);
20462 + //au_dbg_locked_si_reg(sb, 1);
20463 + sbinfo->si_generation = 0;
20464 + sbinfo->au_si_status = 0;
20465 + sbinfo->si_bend = -1;
20466 + sbinfo->si_last_br_id = 0;
20468 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
20469 + sbinfo->si_wbr_create = AuWbrCreate_Def;
20470 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + AuWbrCopyup_Def;
20471 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + AuWbrCreate_Def;
20473 + sbinfo->si_mntflags = AuOpt_Def;
20475 + sbinfo->si_xread = NULL;
20476 + sbinfo->si_xwrite = NULL;
20477 + sbinfo->si_xib = NULL;
20478 + mutex_init(&sbinfo->si_xib_mtx);
20479 + sbinfo->si_xib_buf = NULL;
20480 + au_xino_def_br_set(NULL, sbinfo);
20481 + /* leave si_xib_last_pindex and si_xib_next_bit */
20483 + au_nwt_init(&sbinfo->si_nowait);
20485 + sbinfo->si_rdcache = AUFS_RDCACHE_DEF * HZ;
20486 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
20488 + au_spl_init(&sbinfo->si_plink);
20490 + au_robr_lvma_init(sbinfo);
20492 + /* leave other members for sysaufs and si_mnt. */
20493 + sbinfo->si_sb = sb;
20495 + sb->s_fs_info = sbinfo;
20497 + au_debug_sbinfo_init(sbinfo);
20498 + return 0; /* success */
20501 + kfree(sbinfo->si_branch);
20509 +/* ---------------------------------------------------------------------- */
20511 +struct au_branch *au_sbr(struct super_block *sb, aufs_bindex_t bindex)
20513 + struct au_branch *br;
20515 + SiMustAnyLock(sb);
20516 + AuDebugOn(bindex < 0 || au_sbend(sb) < bindex);
20517 + br = au_sbi(sb)->si_branch[0 + bindex];
20522 +au_gen_t au_sigen_inc(struct super_block *sb)
20526 + SiMustWriteLock(sb);
20527 + gen = ++au_sbi(sb)->si_generation;
20528 + au_update_digen(sb->s_root);
20529 + au_update_iigen(sb->s_root->d_inode);
20530 + sb->s_root->d_inode->i_version++;
20534 +int au_find_bindex(struct super_block *sb, struct au_branch *br)
20536 + aufs_bindex_t bindex, bend;
20538 + bend = au_sbend(sb);
20539 + for (bindex = 0; bindex <= bend; bindex++)
20540 + if (au_sbr(sb, bindex) == br)
20545 +/* ---------------------------------------------------------------------- */
20547 +/* dentry and super_block lock. call at entry point */
20548 +void aufs_read_lock(struct dentry *dentry, int flags)
20550 + si_read_lock(dentry->d_sb, flags);
20551 + if (au_ftest_lock(flags, DW))
20552 + di_write_lock_child(dentry);
20554 + di_read_lock_child(dentry, flags);
20557 +void aufs_read_unlock(struct dentry *dentry, int flags)
20559 + if (au_ftest_lock(flags, DW))
20560 + di_write_unlock(dentry);
20562 + di_read_unlock(dentry, flags);
20563 + si_read_unlock(dentry->d_sb);
20566 +void aufs_write_lock(struct dentry *dentry)
20568 + si_write_lock(dentry->d_sb);
20569 + di_write_lock_child(dentry);
20572 +void aufs_write_unlock(struct dentry *dentry)
20574 + di_write_unlock(dentry);
20575 + si_write_unlock(dentry->d_sb);
20578 +void aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
20580 + AuDebugOn(d1 == d2 || d1->d_sb != d2->d_sb);
20581 + si_read_lock(d1->d_sb, flags);
20582 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
20585 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
20587 + AuDebugOn(d1 == d2 || d1->d_sb != d2->d_sb);
20588 + di_write_unlock2(d1, d2);
20589 + si_read_unlock(d1->d_sb);
20592 +/* ---------------------------------------------------------------------- */
20594 +aufs_bindex_t au_new_br_id(struct super_block *sb)
20596 + aufs_bindex_t br_id;
20597 + struct au_sbinfo *sbinfo;
20600 + SiMustWriteLock(sb);
20602 + sbinfo = au_sbi(sb);
20604 + br_id = ++sbinfo->si_last_br_id;
20605 + if (br_id && au_br_index(sb, br_id) < 0)
20609 diff -urN linux/fs/aufs/super.c linux-aufs/fs/aufs/super.c
20610 --- linux/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
20611 +++ linux-aufs/fs/aufs/super.c 2009-03-12 16:18:04.000000000 +0100
20614 + * Copyright (C) 2005-2009 Junjiro Okajima
20616 + * This program, aufs is free software; you can redistribute it and/or modify
20617 + * it under the terms of the GNU General Public License as published by
20618 + * the Free Software Foundation; either version 2 of the License, or
20619 + * (at your option) any later version.
20621 + * This program is distributed in the hope that it will be useful,
20622 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20623 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20624 + * GNU General Public License for more details.
20626 + * You should have received a copy of the GNU General Public License
20627 + * along with this program; if not, write to the Free Software
20628 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20632 + * mount and super_block operations
20637 +#include <linux/module.h>
20638 +#include <linux/buffer_head.h>
20639 +#include <linux/seq_file.h>
20640 +#include <linux/smp_lock.h>
20641 +#include <linux/statfs.h>
20646 + * super_operations
20648 +static struct inode *aufs_alloc_inode(struct super_block *sb)
20650 + struct aufs_icntnr *c;
20654 + c = au_cache_alloc_icntnr();
20656 + inode_init_once(&c->vfs_inode);
20657 + c->vfs_inode.i_version = 1; /* sigen(sb); */
20658 + c->iinfo.ii_hinode = NULL;
20659 + return &c->vfs_inode;
20664 +static void aufs_destroy_inode(struct inode *inode)
20668 + LKTRTrace("i%lu\n", inode->i_ino);
20670 + if (!inode->i_nlink || IS_DEADDIR(inode)) {
20671 + /* todo: move this lock into xigen_inc() */
20672 + /* in nowait task or remount, sbi is write-locked */
20673 + struct super_block *sb = inode->i_sb;
20674 + const int locked = si_noflush_read_trylock(sb);
20676 + err = au_xigen_inc(inode);
20677 + if (unlikely(err))
20678 + AuWarn1("failed resetting i_generation, %d\n", err);
20680 + si_read_unlock(sb);
20683 + au_iinfo_fin(inode);
20684 + au_cache_free_icntnr(container_of(inode, struct aufs_icntnr,
20688 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
20690 + struct inode *inode;
20693 + LKTRTrace("i%lu\n", (unsigned long)ino);
20695 + inode = iget_locked(sb, ino);
20696 + if (unlikely(!inode)) {
20697 + inode = ERR_PTR(-ENOMEM);
20700 + AuDebugOn(IS_ERR(inode));
20701 + if (!(inode->i_state & I_NEW))
20704 + err = au_xigen_new(inode);
20706 + err = au_iinfo_init(inode);
20708 + inode->i_version++;
20710 + iget_failed(inode);
20711 + inode = ERR_PTR(err);
20715 + /* never return NULL */
20716 + AuDebugOn(!inode);
20717 + AuTraceErrPtr(inode);
20721 +/* lock free root dinfo */
20722 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
20725 + aufs_bindex_t bindex, bend;
20726 + struct path path;
20727 + struct au_hdentry *hd;
20732 + bend = au_sbend(sb);
20733 + hd = au_di(sb->s_root)->di_hdentry;
20734 + for (bindex = 0; !err && bindex <= bend; bindex++) {
20735 + path.mnt = au_sbr_mnt(sb, bindex);
20736 + path.dentry = hd[bindex].hd_dentry;
20737 + err = seq_path(seq, &path, au_esc_chars);
20739 + const char *p = au_optstr_br_perm(au_sbr_perm(sb,
20741 + err = seq_printf(seq, "=%s", p);
20743 + if (!err && bindex != bend)
20744 + err = seq_putc(seq, ':');
20751 +static void au_show_wbr_create(struct seq_file *m, int v,
20752 + struct au_sbinfo *sbinfo)
20756 + AuDebugOn(v == AuWbrCreate_Def);
20758 + seq_printf(m, ",create=");
20759 + pat = au_optstr_wbr_create(v);
20761 + case AuWbrCreate_TDP:
20762 + case AuWbrCreate_RR:
20763 + case AuWbrCreate_MFS:
20764 + case AuWbrCreate_PMFS:
20765 + seq_printf(m, pat);
20767 + case AuWbrCreate_MFSV:
20768 + seq_printf(m, /*pat*/"mfs:%lu",
20769 + sbinfo->si_wbr_mfs.mfs_expire / HZ);
20771 + case AuWbrCreate_PMFSV:
20772 + seq_printf(m, /*pat*/"pmfs:%lu",
20773 + sbinfo->si_wbr_mfs.mfs_expire / HZ);
20775 + case AuWbrCreate_MFSRR:
20776 + seq_printf(m, /*pat*/"mfsrr:%llu",
20777 + sbinfo->si_wbr_mfs.mfsrr_watermark);
20779 + case AuWbrCreate_MFSRRV:
20780 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
20781 + sbinfo->si_wbr_mfs.mfsrr_watermark,
20782 + sbinfo->si_wbr_mfs.mfs_expire / HZ);
20787 +/* seq_file will re-call me in case of too long string */
20788 +static int aufs_show_options(struct seq_file *m, struct vfsmount *mnt)
20791 + unsigned int mnt_flags, v;
20792 + struct path path;
20793 + struct super_block *sb;
20794 + struct au_sbinfo *sbinfo;
20795 + struct file *xino;
20799 + sb = mnt->mnt_sb;
20800 + /* lock free root dinfo */
20801 + si_noflush_read_lock(sb);
20802 + sbinfo = au_sbi(sb);
20803 + seq_printf(m, ",si=%lx", au_si_mask ^ (unsigned long)sbinfo);
20804 + mnt_flags = au_mntflags(sb);
20805 + if (au_opt_test(mnt_flags, XINO)) {
20806 + seq_puts(m, ",xino=");
20807 + xino = sbinfo->si_xib;
20808 + path.mnt = xino->f_vfsmnt;
20809 + path.dentry = xino->f_dentry;
20810 + err = seq_path(m, &path, au_esc_chars);
20811 + if (unlikely(err <= 0))
20814 +#define Deleted "\\040(deleted)"
20815 + m->count -= sizeof(Deleted) - 1;
20816 + AuDebugOn(memcmp(m->buf + m->count, Deleted,
20817 + sizeof(Deleted) - 1));
20819 +#ifdef CONFIG_AUFS_EXPORT /* reserved for future use */
20820 + } else if (au_opt_test(mnt_flags, XINODIR)) {
20821 + seq_puts(m, ",xinodir=");
20822 + seq_path(m, &sbinfo->si_xinodir, au_esc_chars);
20825 + seq_puts(m, ",noxino");
20827 +#define AuBool(name, str) do { \
20828 + v = au_opt_test(mnt_flags, name); \
20829 + if (v != au_opt_test(AuOpt_Def, name)) \
20830 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
20833 +#define AuStr(name, str) do { \
20834 + v = mnt_flags & AuOptMask_##name; \
20835 + if (v != (AuOpt_Def & AuOptMask_##name)) \
20836 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
20839 +#ifdef CONFIG_AUFS_COMPAT
20840 +#define AuStr_BrOpt "dirs="
20842 +#define AuStr_BrOpt "br:"
20845 + AuBool(TRUNC_XINO, trunc_xino);
20846 + AuBool(DIRPERM1, dirperm1);
20847 + AuBool(SHWH, shwh);
20848 + AuBool(PLINK, plink);
20849 + AuStr(UDBA, udba);
20851 + v = sbinfo->si_wbr_create;
20852 + if (v != AuWbrCreate_Def)
20853 + au_show_wbr_create(m, v, sbinfo);
20855 + v = sbinfo->si_wbr_copyup;
20856 + if (v != AuWbrCopyup_Def)
20857 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
20859 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
20860 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
20861 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
20862 + AuBool(REFROF, refrof);
20863 + AuBool(DLGT, dlgt);
20864 + AuBool(WARN_PERM, warn_perm);
20865 + AuBool(VERBOSE, verbose);
20866 + AuBool(SUM, sum);
20867 + /* AuBool(SUM_W, wsum); */
20869 + n = sbinfo->si_dirwh;
20870 + if (n != AUFS_DIRWH_DEF)
20871 + seq_printf(m, ",dirwh=%d", n);
20872 + n = sbinfo->si_rdcache / HZ;
20873 + if (n != AUFS_RDCACHE_DEF)
20874 + seq_printf(m, ",rdcache=%d", n);
20879 + if (!sysaufs_brs) {
20880 + seq_puts(m, "," AuStr_BrOpt);
20881 + au_show_brs(m, sb);
20883 + si_read_unlock(sb);
20888 +#undef AuStr_BrOpt
20891 +static u64 au_add_till_max(u64 a, u64 b)
20899 + return ULLONG_MAX;
20902 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf, int dlgt)
20905 + aufs_bindex_t bend, bindex, i;
20906 + unsigned char shared;
20907 + u64 blocks, bfree, bavail, files, ffree;
20908 + struct super_block *h_sb;
20919 + bend = au_sbend(sb);
20920 + for (bindex = bend; bindex >= 0; bindex--) {
20921 + h_sb = au_sbr_sb(sb, bindex);
20923 + for (i = bindex + 1; !shared && i <= bend; i++)
20924 + shared = au_sbr_sb(sb, i) == h_sb;
20928 + err = vfsub_statfs(h_sb->s_root, buf, dlgt);
20929 + if (unlikely(err))
20932 + blocks = au_add_till_max(blocks, buf->f_blocks);
20933 + bfree = au_add_till_max(bfree, buf->f_bfree);
20934 + bavail = au_add_till_max(bavail, buf->f_bavail);
20935 + files = au_add_till_max(files, buf->f_files);
20936 + ffree = au_add_till_max(ffree, buf->f_ffree);
20939 + buf->f_blocks = blocks;
20940 + buf->f_bfree = bfree;
20941 + buf->f_bavail = bavail;
20942 + buf->f_files = files;
20943 + buf->f_ffree = ffree;
20950 +/* todo: in case of round-robin policy, return the sum of all rw branches? */
20951 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
20954 + unsigned int mnt_flags;
20955 + unsigned char dlgt;
20956 + struct super_block *sb;
20960 + /* lock free root dinfo */
20961 + sb = dentry->d_sb;
20962 + si_noflush_read_lock(sb);
20963 + mnt_flags = au_mntflags(sb);
20964 + dlgt = !!au_test_dlgt(mnt_flags);
20965 + if (!au_opt_test(mnt_flags, SUM))
20966 + err = vfsub_statfs(au_sbr_sb(sb, 0)->s_root, buf, dlgt);
20968 + err = au_statfs_sum(sb, buf, dlgt);
20969 + si_read_unlock(sb);
20971 + buf->f_type = AUFS_SUPER_MAGIC;
20972 + buf->f_namelen -= AUFS_WH_PFX_LEN;
20973 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
20975 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
20981 +static void au_fsync_br(struct super_block *sb)
20983 +#ifdef CONFIG_AUFS_FSYNC_SUPER_PATCH
20984 + aufs_bindex_t bend, bindex;
20986 + struct au_branch *br;
20987 + struct super_block *h_sb;
20991 + si_write_lock(sb);
20992 + bend = au_sbend(sb);
20993 + for (bindex = 0; bindex < bend; bindex++) {
20994 + br = au_sbr(sb, bindex);
20995 + brperm = br->br_perm;
20996 + if (brperm == AuBrPerm_RR || brperm == AuBrPerm_RRWH)
20998 + h_sb = br->br_mnt->mnt_sb;
20999 + if (bdev_read_only(h_sb->s_bdev))
21003 + down_write(&h_sb->s_umount);
21004 + shrink_dcache_sb(h_sb);
21005 + fsync_super(h_sb);
21006 + up_write(&h_sb->s_umount);
21009 + si_write_unlock(sb);
21013 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
21014 +/* this IS NOT for super_operations */
21015 +static void aufs_umount_begin(struct super_block *arg)
21016 +#define AuUmountBeginSb(arg) (arg)
21018 +/* this IS for super_operations */
21019 +static void aufs_umount_begin(struct vfsmount *arg, int flags)
21020 +#define AuUmountBeginSb(arg) ((arg)->mnt_sb)
21023 + struct super_block *sb = AuUmountBeginSb(arg);
21024 + struct au_sbinfo *sbinfo;
21027 + /* dont trust BKL */
21028 + AuDebugOn(!kernel_locked());
21030 + sbinfo = au_sbi(sb);
21036 + si_write_lock(sb);
21037 + if (au_opt_test(au_mntflags(sb), PLINK))
21038 + au_plink_put(sb);
21039 + au_mnt_reset(sbinfo);
21040 +#if 0 /* reserved for future use */
21041 + if (sbinfo->si_wbr_create_ops->fin)
21042 + sbinfo->si_wbr_create_ops->fin(sb);
21044 + si_write_unlock(sb);
21047 +/* final actions when unmounting a file system */
21048 +static void aufs_put_super(struct super_block *sb)
21050 + struct au_sbinfo *sbinfo;
21054 + sbinfo = au_sbi(sb);
21057 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
21058 + aufs_umount_begin(sb);
21060 + kobject_put(&sbinfo->si_kobj);
21063 +/* ---------------------------------------------------------------------- */
21066 + * refresh dentry and inode at remount time.
21068 +static int do_refresh(struct dentry *dentry, mode_t type,
21069 + unsigned int dir_flags)
21072 + struct dentry *parent;
21073 + struct inode *inode;
21075 + LKTRTrace("%.*s, 0%o\n", AuDLNPair(dentry), type);
21076 + inode = dentry->d_inode;
21077 + AuDebugOn(!inode);
21079 + di_write_lock_child(dentry);
21080 + parent = dget_parent(dentry);
21081 + di_read_lock_parent(parent, AuLock_IR);
21082 + /* returns a number of positive dentries */
21083 + err = au_refresh_hdentry(dentry, type);
21085 + err = au_refresh_hinode(inode, dentry);
21086 + if (!err && type == S_IFDIR)
21087 + au_reset_hinotify(inode, dir_flags);
21089 + if (unlikely(err))
21090 + AuErr("unrecoverable error %d, %.*s\n", err, AuDLNPair(dentry));
21091 + di_read_unlock(parent, AuLock_IR);
21093 + di_write_unlock(dentry);
21099 +static int test_dir(struct dentry *dentry, void *arg)
21101 + return S_ISDIR(dentry->d_inode->i_mode);
21104 +/* todo: merge with refresh_nondir()? */
21105 +static int refresh_dir(struct dentry *root, au_gen_t sgen)
21107 + int err, i, j, ndentry, e;
21108 + struct au_dcsub_pages dpages;
21109 + struct au_dpage *dpage;
21110 + struct dentry **dentries;
21111 + struct inode *inode;
21112 + const unsigned int flags = au_hi_flags(root->d_inode, /*isdir*/1);
21114 + LKTRTrace("sgen %d\n", sgen);
21115 + SiMustWriteLock(root->d_sb);
21116 + /* dont trust BKL */
21117 + AuDebugOn(au_digen(root) != sgen || !kernel_locked());
21120 + list_for_each_entry(inode, &root->d_sb->s_inodes, i_sb_list)
21121 + if (S_ISDIR(inode->i_mode) && au_iigen(inode) != sgen) {
21122 + ii_write_lock_child(inode);
21123 + e = au_refresh_hinode_self(inode);
21124 + ii_write_unlock(inode);
21125 + if (unlikely(e)) {
21126 + LKTRTrace("e %d, i%lu\n", e, inode->i_ino);
21129 + /* go on even if err */
21133 + e = au_dpages_init(&dpages, GFP_NOFS);
21134 + if (unlikely(e)) {
21139 + e = au_dcsub_pages(&dpages, root, test_dir, NULL);
21140 + if (unlikely(e)) {
21146 + for (i = 0; !e && i < dpages.ndpage; i++) {
21147 + dpage = dpages.dpages + i;
21148 + dentries = dpage->dentries;
21149 + ndentry = dpage->ndentry;
21150 + for (j = 0; !e && j < ndentry; j++) {
21151 + struct dentry *d;
21153 +#ifdef CONFIG_AUFS_DEBUG
21155 + struct dentry *parent;
21156 + parent = dget_parent(d);
21157 + AuDebugOn(!S_ISDIR(d->d_inode->i_mode)
21159 + || au_digen(parent) != sgen);
21163 + if (au_digen(d) != sgen) {
21164 + e = do_refresh(d, S_IFDIR, flags);
21165 + if (unlikely(e && !err))
21167 + /* break on err */
21173 + au_dpages_free(&dpages);
21179 +static int test_nondir(struct dentry *dentry, void *arg)
21181 + return !S_ISDIR(dentry->d_inode->i_mode);
21184 +static int refresh_nondir(struct dentry *root, au_gen_t sgen, int do_dentry)
21186 + int err, i, j, ndentry, e;
21187 + struct au_dcsub_pages dpages;
21188 + struct au_dpage *dpage;
21189 + struct dentry **dentries;
21190 + struct inode *inode;
21192 + LKTRTrace("sgen %d\n", sgen);
21193 + SiMustWriteLock(root->d_sb);
21194 + /* dont trust BKL */
21195 + AuDebugOn(au_digen(root) != sgen || !kernel_locked());
21198 + list_for_each_entry(inode, &root->d_sb->s_inodes, i_sb_list)
21199 + if (!S_ISDIR(inode->i_mode) && au_iigen(inode) != sgen) {
21200 + ii_write_lock_child(inode);
21201 + e = au_refresh_hinode_self(inode);
21202 + ii_write_unlock(inode);
21203 + if (unlikely(e)) {
21204 + LKTRTrace("e %d, i%lu\n", e, inode->i_ino);
21207 + /* go on even if err */
21214 + e = au_dpages_init(&dpages, GFP_NOFS);
21215 + if (unlikely(e)) {
21220 + e = au_dcsub_pages(&dpages, root, test_nondir, NULL);
21221 + if (unlikely(e)) {
21227 + for (i = 0; i < dpages.ndpage; i++) {
21228 + dpage = dpages.dpages + i;
21229 + dentries = dpage->dentries;
21230 + ndentry = dpage->ndentry;
21231 + for (j = 0; j < ndentry; j++) {
21232 + struct dentry *d;
21234 +#ifdef CONFIG_AUFS_DEBUG
21236 + struct dentry *parent;
21237 + parent = dget_parent(d);
21238 + AuDebugOn(S_ISDIR(d->d_inode->i_mode)
21239 + || au_digen(parent) != sgen);
21243 + inode = d->d_inode;
21244 + if (inode && au_digen(d) != sgen) {
21245 + e = do_refresh(d, inode->i_mode & S_IFMT, 0);
21246 + if (unlikely(e && !err))
21248 + /* go on even err */
21254 + au_dpages_free(&dpages);
21260 +/* stop extra interpretation of errno in mount(8), and strange error messages */
21261 +static int cvt_err(int err)
21275 +/* protected by s_umount */
21276 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
21280 + struct dentry *root;
21281 + struct inode *inode;
21282 + struct au_opts opts;
21283 + struct au_sbinfo *sbinfo;
21284 + unsigned char dlgt;
21286 + LKTRTrace("flags 0x%x, data %s, len %lu\n",
21287 + *flags, data ? data : "NULL",
21288 + (unsigned long)(data ? strlen(data) : 0));
21293 + root = sb->s_root;
21294 + if (!data || !*data) {
21295 + aufs_write_lock(root);
21296 + err = verify_opts(sb, *flags, /*pending*/0, /*remount*/1);
21297 + aufs_write_unlock(root);
21298 + goto out; /* success */
21302 + memset(&opts, 0, sizeof(opts));
21303 + opts.opt = (void *)__get_free_page(GFP_NOFS);
21304 + if (unlikely(!opts.opt))
21306 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
21307 + opts.flags = AuOpts_REMOUNT;
21308 + opts.sb_flags = *flags;
21310 + /* parse it before aufs lock */
21311 + err = au_opts_parse(sb, data, &opts);
21312 + if (unlikely(err))
21315 + sbinfo = au_sbi(sb);
21316 + inode = root->d_inode;
21317 + mutex_lock(&inode->i_mutex);
21318 + aufs_write_lock(root);
21320 + /* au_do_opts() may return an error */
21321 + err = au_opts_remount(sb, &opts);
21322 + au_opts_free(&opts);
21324 + if (au_ftest_opts(opts.flags, REFRESH_DIR)
21325 + || au_ftest_opts(opts.flags, REFRESH_NONDIR)) {
21326 + dlgt = !!au_opt_test(sbinfo->si_mntflags, DLGT);
21327 + au_opt_clr(sbinfo->si_mntflags, DLGT);
21328 + au_sigen_inc(sb);
21329 + au_reset_hinotify(inode, au_hi_flags(inode, /*isdir*/1));
21330 + sigen = au_sigen(sb);
21331 + au_fclr_si(sbinfo, FAILED_REFRESH_DIRS);
21333 + DiMustNoWaiters(root);
21334 + IiMustNoWaiters(root->d_inode);
21335 + di_write_unlock(root);
21337 + rerr = refresh_dir(root, sigen);
21338 + if (unlikely(rerr)) {
21339 + au_fset_si(sbinfo, FAILED_REFRESH_DIRS);
21340 + AuWarn("Refreshing directories failed, ignores (%d)\n",
21344 + if (au_ftest_opts(opts.flags, REFRESH_NONDIR)) {
21345 + rerr = refresh_nondir(root, sigen, !rerr);
21346 + if (unlikely(rerr))
21347 + AuWarn("Refreshing non-directories failed,"
21348 + " ignores (%d)\n", rerr);
21351 + /* aufs_write_lock() calls ..._child() */
21352 + di_write_lock_child(root);
21354 + au_cpup_attr_all(inode, /*force*/1);
21356 + au_opt_set(sbinfo->si_mntflags, DLGT);
21359 + aufs_write_unlock(root);
21360 + mutex_unlock(&inode->i_mutex);
21363 + free_page((unsigned long)opts.opt);
21365 + err = cvt_err(err);
21370 +static struct super_operations aufs_sop = {
21371 + .alloc_inode = aufs_alloc_inode,
21372 + .destroy_inode = aufs_destroy_inode,
21373 + .drop_inode = generic_delete_inode,
21375 + .show_options = aufs_show_options,
21376 + .statfs = aufs_statfs,
21378 + .put_super = aufs_put_super,
21379 + .remount_fs = aufs_remount_fs,
21380 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
21381 + .umount_begin = aufs_umount_begin
21385 +/* ---------------------------------------------------------------------- */
21387 +static int alloc_root(struct super_block *sb)
21390 + struct inode *inode;
21391 + struct dentry *root;
21396 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
21397 + err = PTR_ERR(inode);
21398 + if (IS_ERR(inode))
21400 + inode->i_op = &aufs_dir_iop;
21401 + inode->i_fop = &aufs_dir_fop;
21402 + inode->i_mode = S_IFDIR;
21403 + unlock_new_inode(inode);
21404 + root = d_alloc_root(inode);
21405 + if (unlikely(!root))
21407 + err = PTR_ERR(root);
21408 + if (IS_ERR(root))
21411 + err = au_alloc_dinfo(root);
21413 + sb->s_root = root;
21414 + return 0; /* success */
21417 + goto out; /* do not iput */
21420 + iget_failed(inode);
21428 +static int aufs_fill_super(struct super_block *sb, void *raw_data, int silent)
21431 + struct dentry *root;
21432 + struct inode *inode;
21433 + struct au_opts opts;
21434 + char *arg = raw_data;
21436 + if (unlikely(!arg || !*arg)) {
21438 + AuErr("no arg\n");
21441 + LKTRTrace("%s, silent %d\n", arg, silent);
21444 + memset(&opts, 0, sizeof(opts));
21445 + opts.opt = (void *)__get_free_page(GFP_NOFS);
21446 + if (unlikely(!opts.opt))
21448 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
21449 + opts.sb_flags = sb->s_flags;
21451 + err = au_si_alloc(sb);
21452 + if (unlikely(err))
21454 + SiMustWriteLock(sb);
21456 + /* all timestamps always follow the ones on the branch */
21457 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
21458 + sb->s_op = &aufs_sop;
21459 + sb->s_magic = AUFS_SUPER_MAGIC;
21460 + au_export_init(sb);
21462 + err = alloc_root(sb);
21463 + if (unlikely(err)) {
21464 + AuDebugOn(sb->s_root);
21465 + si_write_unlock(sb);
21468 + root = sb->s_root;
21469 + DiMustWriteLock(root);
21470 + inode = root->d_inode;
21471 + inode->i_nlink = 2;
21474 + * actually we can parse options regardless aufs lock here.
21475 + * but at remount time, parsing must be done before aufs lock.
21476 + * so we follow the same rule.
21478 + ii_write_lock_parent(inode);
21479 + au_dbg_locked_si_reg(sb, 1);
21480 + aufs_write_unlock(root);
21481 + err = au_opts_parse(sb, arg, &opts);
21482 + if (unlikely(err))
21485 + /* lock vfs_inode first, then aufs. */
21486 + mutex_lock(&inode->i_mutex);
21487 + inode->i_op = &aufs_dir_iop;
21488 + inode->i_fop = &aufs_dir_fop;
21489 + aufs_write_lock(root);
21491 + sb->s_maxbytes = 0;
21492 + err = au_opts_mount(sb, &opts);
21493 + au_opts_free(&opts);
21494 + if (unlikely(err))
21496 + AuDebugOn(!sb->s_maxbytes);
21498 + aufs_write_unlock(root);
21499 + mutex_unlock(&inode->i_mutex);
21500 + goto out_opts; /* success */
21503 + aufs_write_unlock(root);
21504 + mutex_unlock(&inode->i_mutex);
21507 + sb->s_root = NULL;
21509 + kobject_put(&au_sbi(sb)->si_kobj);
21510 + sb->s_fs_info = NULL;
21512 + free_page((unsigned long)opts.opt);
21515 + err = cvt_err(err);
21520 +/* ---------------------------------------------------------------------- */
21522 +static int aufs_get_sb(struct file_system_type *fs_type, int flags,
21523 + const char *dev_name, void *raw_data,
21524 + struct vfsmount *mnt)
21527 + struct super_block *sb;
21529 + /* all timestamps always follow the ones on the branch */
21530 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
21531 + err = get_sb_nodev(fs_type, flags, raw_data, aufs_fill_super, mnt);
21533 + sb = mnt->mnt_sb;
21534 + au_mnt_init(au_sbi(sb), mnt);
21535 + si_write_lock(sb);
21536 + sysaufs_brs_add(sb, 0);
21537 + si_write_unlock(sb);
21542 +struct file_system_type aufs_fs_type = {
21543 + .name = AUFS_FSTYPE,
21545 + FS_RENAME_DOES_D_MOVE /* a race between rename and others*/
21546 + | FS_REVAL_DOT, /* for NFS branch and udba */
21547 + .get_sb = aufs_get_sb,
21548 + .kill_sb = generic_shutdown_super,
21549 + /* no need to __module_get() and module_put(). */
21550 + .owner = THIS_MODULE,
21552 diff -urN linux/fs/aufs/super.h linux-aufs/fs/aufs/super.h
21553 --- linux/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
21554 +++ linux-aufs/fs/aufs/super.h 2009-03-12 16:18:04.000000000 +0100
21557 + * Copyright (C) 2005-2009 Junjiro Okajima
21559 + * This program, aufs is free software; you can redistribute it and/or modify
21560 + * it under the terms of the GNU General Public License as published by
21561 + * the Free Software Foundation; either version 2 of the License, or
21562 + * (at your option) any later version.
21564 + * This program is distributed in the hope that it will be useful,
21565 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21566 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21567 + * GNU General Public License for more details.
21569 + * You should have received a copy of the GNU General Public License
21570 + * along with this program; if not, write to the Free Software
21571 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21575 + * super_block operations
21580 +#ifndef __AUFS_SUPER_H__
21581 +#define __AUFS_SUPER_H__
21585 +#include <linux/fs.h>
21586 +#include <linux/cramfs_fs.h>
21587 +#include <linux/kobject.h>
21588 +#include <linux/magic.h>
21589 +#include <linux/mount.h>
21590 +#include <linux/aufs_type.h>
21594 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
21595 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
21598 +struct au_wbr_copyup_operations {
21599 + int (*copyup)(struct dentry *dentry);
21602 +struct au_wbr_create_operations {
21603 + int (*create)(struct dentry *dentry, int isdir);
21604 + int (*init)(struct super_block *sb);
21605 + int (*fin)(struct super_block *sb);
21608 +struct au_wbr_mfs {
21609 + struct mutex mfs_lock; /* protect this structure */
21610 + unsigned long mfs_jiffy;
21611 + unsigned long mfs_expire;
21612 + aufs_bindex_t mfs_bindex;
21614 + unsigned long long mfsrr_bytes;
21615 + unsigned long long mfsrr_watermark;
21618 +/* sbinfo status flags */
21620 + * set true when refresh_dirs() failed at remount time.
21621 + * then try refreshing dirs at access time again.
21622 + * if it is false, refreshing dirs at access time is unnecesary
21624 +#define AuSi_FAILED_REFRESH_DIRS 1
21625 +#define au_ftest_si(sbinfo, name) ((sbinfo)->au_si_status & AuSi_##name)
21626 +#define au_fset_si(sbinfo, name) \
21627 + { (sbinfo)->au_si_status |= AuSi_##name; }
21628 +#define au_fclr_si(sbinfo, name) \
21629 + { (sbinfo)->au_si_status &= ~AuSi_##name; }
21632 +struct au_sbinfo {
21633 + /* nowait tasks in the system-wide workqueue */
21634 + struct au_nowait_tasks si_nowait;
21636 + struct au_rwsem si_rwsem;
21638 + /* branch management */
21639 + au_gen_t si_generation;
21641 + /* see above flags */
21642 + unsigned char au_si_status;
21644 + aufs_bindex_t si_bend;
21645 + aufs_bindex_t si_last_br_id;
21646 + struct au_branch **si_branch;
21648 + /* policy to select a writable branch */
21649 + unsigned char si_wbr_copyup;
21650 + unsigned char si_wbr_create;
21651 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
21652 + struct au_wbr_create_operations *si_wbr_create_ops;
21654 + /* round robin */
21655 + atomic_t si_wbr_rr_next;
21657 + /* most free space */
21658 + struct au_wbr_mfs si_wbr_mfs;
21660 + /* mount flags */
21661 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
21662 + unsigned int si_mntflags;
21664 + /* external inode number (bitmap and translation table) */
21665 + au_readf_t si_xread;
21666 + au_writef_t si_xwrite;
21667 + struct file *si_xib;
21668 + struct mutex si_xib_mtx; /* protect xib members */
21669 + unsigned long *si_xib_buf;
21670 + unsigned long si_xib_last_pindex;
21671 + int si_xib_next_bit;
21672 + /* reserved for future use */
21673 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
21675 +#ifdef CONFIG_AUFS_HINOTIFY
21676 + struct au_branch *si_xino_def_br;
21679 +#ifdef CONFIG_AUFS_EXPORT
21680 + /* i_generation */
21681 + struct file *si_xigen;
21682 + atomic_t si_xigen_next;
21685 + /* readdir cache time, max, in HZ */
21686 + unsigned long si_rdcache;
21689 + * If the number of whiteouts are larger than si_dirwh, leave all of
21690 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
21691 + * future fsck.aufs or kernel thread will remove them later.
21692 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
21694 + unsigned int si_dirwh;
21697 + * rename(2) a directory with all children.
21699 + /* reserved for future use */
21700 + /* int si_rendir; */
21702 + /* pseudo_link list */ /* todo: dirty? */
21703 + struct au_splhead si_plink;
21705 +#if defined(CONFIG_AUFS_EXPORT) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
21706 + /* dirty, for export, async ops, and sysfs */
21707 + spinlock_t si_mntcache_lock;
21708 + struct vfsmount *si_mntcache; /* no get/put */
21712 + * sysfs and lifetime management.
21713 + * this is not a small structure and it may be a waste of memory in case
21714 + * of sysfs is disabled, particulary when many aufs-es are mounted.
21716 + struct kobject si_kobj;
21718 +#ifdef CONFIG_AUFS_ROBR
21719 + /* locked vma list for mmap() */ /* todo: dirty? */
21720 + struct au_splhead si_lvma;
21723 +#ifdef CONFIG_AUFS_EXPORT /* reserved for future use */
21724 + struct path si_xinodir;
21727 + /* dirty, necessary for unmounting, sysfs and sysrq */
21728 + struct super_block *si_sb;
21730 +#ifdef CONFIG_AUFS_DEBUG_LOCK
21731 + struct au_splhead si_dbg_lock[AuDbgLock_Last];
21735 +/* ---------------------------------------------------------------------- */
21737 +/* policy to select one among writable branches */
21738 +#define AuWbrCopyup(sbinfo, args...) \
21739 + ((sbinfo)->si_wbr_copyup_ops->copyup(args))
21740 +#define AuWbrCreate(sbinfo, args...) \
21741 + ((sbinfo)->si_wbr_create_ops->create(args))
21743 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
21744 +#define AuLock_DW 1 /* write-lock dentry */
21745 +#define AuLock_IR (1 << 1) /* read-lock inode */
21746 +#define AuLock_IW (1 << 2) /* write-lock inode */
21747 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
21748 +#define AuLock_DIR (1 << 4) /* target is a dir */
21749 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
21750 +#define au_fset_lock(flags, name) { (flags) |= AuLock_##name; }
21751 +#define au_fclr_lock(flags, name) { (flags) &= ~AuLock_##name; }
21753 +/* ---------------------------------------------------------------------- */
21756 +extern struct file_system_type aufs_fs_type;
21757 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
21760 +void au_si_free(struct kobject *kobj);
21761 +int au_si_alloc(struct super_block *sb);
21762 +struct au_branch *au_sbr(struct super_block *sb, aufs_bindex_t bindex);
21763 +au_gen_t au_sigen_inc(struct super_block *sb);
21764 +int au_find_bindex(struct super_block *sb, struct au_branch *br);
21766 +void aufs_read_lock(struct dentry *dentry, int flags);
21767 +void aufs_read_unlock(struct dentry *dentry, int flags);
21768 +void aufs_write_lock(struct dentry *dentry);
21769 +void aufs_write_unlock(struct dentry *dentry);
21770 +void aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int isdir);
21771 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
21773 +aufs_bindex_t au_new_br_id(struct super_block *sb);
21775 +/* wbr_policy.c */
21776 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
21777 +extern struct au_wbr_create_operations au_wbr_create_ops[];
21778 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
21780 +/* ---------------------------------------------------------------------- */
21782 +#if defined(CONFIG_AUFS_EXPORT) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
21783 +static inline void au_mnt_init(struct au_sbinfo *sbinfo, struct vfsmount *mnt)
21785 + spin_lock_init(&sbinfo->si_mntcache_lock);
21786 + sbinfo->si_mntcache = mnt;
21789 +static inline void au_mnt_reset(struct au_sbinfo *sbinfo)
21791 + spin_lock(&sbinfo->si_mntcache_lock);
21792 + sbinfo->si_mntcache = NULL;
21793 + spin_unlock(&sbinfo->si_mntcache_lock);
21796 +static inline void au_mnt_init(struct au_sbinfo *sbinfo, struct vfsmount *mnt)
21801 +static inline void au_mnt_reset(struct au_sbinfo *sbinfo)
21805 +#endif /* EXPORT && < 2.6.26 */
21807 +/* ---------------------------------------------------------------------- */
21809 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
21810 +static inline int au_mnt_want_write(struct vfsmount *h_mnt)
21812 + return mnt_want_write(h_mnt);
21815 +static inline void au_mnt_drop_write(struct vfsmount *h_mnt)
21817 + mnt_drop_write(h_mnt);
21820 +static inline int au_mnt_want_write(struct vfsmount *h_mnt)
21825 +static inline void au_mnt_drop_write(struct vfsmount *h_mnt)
21831 +/* ---------------------------------------------------------------------- */
21833 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
21835 + return sb->s_fs_info;
21838 +static inline const char *au_sbtype(struct super_block *sb)
21840 + return sb->s_type->name;
21843 +static inline int au_test_aufs(struct super_block *sb)
21845 + return sb->s_magic == AUFS_SUPER_MAGIC;
21848 +static inline int au_test_nfs(struct super_block *sb)
21850 +#ifdef CONFIG_AUFS_BR_NFS
21851 + return sb->s_magic == NFS_SUPER_MAGIC;
21857 +static inline int au_test_nfs4(struct super_block *sb)
21859 +#ifdef CONFIG_AUFS_BR_NFS_V4
21860 + return au_test_nfs(sb) && !strcmp(sb->s_type->name, "nfs4");
21866 +static inline int au_test_fuse(struct super_block *sb)
21868 +#ifdef CONFIG_AUFS_WORKAROUND_FUSE
21869 + return sb->s_magic == FUSE_SUPER_MAGIC;
21875 +static inline int au_test_xfs(struct super_block *sb)
21877 +#ifdef CONFIG_AUFS_BR_XFS
21878 + return sb->s_magic == XFS_SB_MAGIC;
21884 +static inline int au_test_tmpfs(struct super_block *sb)
21886 +#ifdef CONFIG_TMPFS
21887 + return sb->s_magic == TMPFS_MAGIC;
21893 +static inline int au_test_ecryptfs(struct super_block *sb)
21895 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
21896 + /* why don't they use s_magic? */
21897 + return !strcmp(sb->s_type->name, "ecryptfs");
21903 +/* ---------------------------------------------------------------------- */
21905 +#ifdef CONFIG_AUFS_HINOTIFY
21906 +static inline void au_xino_def_br_set(struct au_branch *br,
21907 + struct au_sbinfo *sbinfo)
21909 + sbinfo->si_xino_def_br = br;
21912 +static inline struct au_branch *au_xino_def_br(struct au_sbinfo *sbinfo)
21914 + return sbinfo->si_xino_def_br;
21917 +static inline void au_xino_def_br_set(struct au_branch *br,
21918 + struct au_sbinfo *sbinfo)
21923 +static inline struct au_branch *au_xino_def_br(struct au_sbinfo *sbinfo)
21929 +/* ---------------------------------------------------------------------- */
21931 +#ifdef CONFIG_AUFS_EXPORT
21932 +void au_export_init(struct super_block *sb);
21934 +static inline int au_test_nfsd(struct task_struct *tsk)
21936 + return !tsk->mm && !strcmp(tsk->comm, "nfsd");
21939 +static inline void au_export_put(struct au_sbinfo *sbinfo)
21941 + path_put(&sbinfo->si_xinodir);
21944 +int au_xigen_inc(struct inode *inode);
21945 +int au_xigen_new(struct inode *inode);
21946 +int au_xigen_set(struct super_block *sb, struct file *base);
21947 +void au_xigen_clr(struct super_block *sb);
21949 +static inline void au_export_init(struct super_block *sb)
21954 +static inline int au_test_nfsd(struct task_struct *tsk)
21959 +static inline void au_export_put(struct au_sbinfo *sbinfo)
21964 +static inline int au_xigen_inc(struct inode *inode)
21969 +static inline int au_xigen_new(struct inode *inode)
21974 +static inline int au_xigen_set(struct super_block *sb, struct file *base)
21979 +static inline void au_xigen_clr(struct super_block *sb)
21983 +#endif /* CONFIG_AUFS_EXPORT */
21985 +#ifdef CONFIG_AUFS_ROBR
21986 +static inline int au_test_nested(struct super_block *h_sb)
21991 +static inline void au_robr_lvma_init(struct au_sbinfo *sbinfo)
21993 + au_spl_init(&sbinfo->si_lvma);
21996 +static inline int au_test_nested(struct super_block *h_sb)
21999 + if (unlikely(au_test_aufs(h_sb))) {
22006 +static inline void au_robr_lvma_init(struct au_sbinfo *sbinfo)
22010 +#endif /* CONFIG_AUFS_ROBR */
22012 +/* ---------------------------------------------------------------------- */
22014 +/* lock superblock. mainly for entry point functions */
22016 + * si_do_noflush_read_lock, si_do_noflush_write_lock,
22017 + * si_do_read_unlock, si_do_write_unlock, si_do_downgrade_lock
22019 +AuSimpleLockRwsemFuncs(si_do_noflush, struct super_block *sb,
22020 + au_sbi(sb)->si_rwsem);
22021 +AuSimpleUnlockRwsemFuncs(si_do, struct super_block *sb, au_sbi(sb)->si_rwsem);
22023 +static inline void si_noflush_read_lock(struct super_block *sb)
22025 + au_dbg_locking_si_reg(sb, 0);
22026 + si_do_noflush_read_lock(sb);
22027 + au_dbg_locking_si_unreg(sb, 0);
22028 + au_dbg_locked_si_reg(sb, 0);
22031 +static inline void si_noflush_write_lock(struct super_block *sb)
22033 + au_dbg_locking_si_reg(sb, 1);
22034 + si_do_noflush_write_lock(sb);
22035 + au_dbg_locking_si_unreg(sb, 1);
22036 + au_dbg_locked_si_reg(sb, 1);
22039 +static inline int si_noflush_read_trylock(struct super_block *sb)
22043 + au_dbg_locking_si_reg(sb, 0);
22044 + locked = si_do_noflush_read_trylock(sb);
22045 + au_dbg_locking_si_unreg(sb, 0);
22047 + au_dbg_locked_si_reg(sb, 0);
22051 +static inline int si_noflush_write_trylock(struct super_block *sb)
22055 + au_dbg_locking_si_reg(sb, 1);
22056 + locked = si_do_noflush_write_trylock(sb);
22057 + au_dbg_locking_si_unreg(sb, 1);
22059 + au_dbg_locked_si_reg(sb, 1);
22063 +static inline void si_read_unlock(struct super_block *sb)
22065 + si_do_read_unlock(sb);
22066 + au_dbg_locked_si_unreg(sb, 0);
22069 +static inline void si_write_unlock(struct super_block *sb)
22071 + si_do_write_unlock(sb);
22072 + au_dbg_locked_si_unreg(sb, 1);
22075 +static inline void si_downgrade_lock(struct super_block *sb)
22077 + si_do_downgrade_lock(sb);
22080 +static inline void si_read_lock(struct super_block *sb, int flags)
22082 + if (/* !au_test_nfsd(current) && */au_ftest_lock(flags, FLUSH))
22083 + au_nwt_flush(&au_sbi(sb)->si_nowait);
22084 + si_noflush_read_lock(sb);
22087 +static inline void si_write_lock(struct super_block *sb)
22089 + //WARN_ON(au_test_nfsd(current));
22090 + au_nwt_flush(&au_sbi(sb)->si_nowait);
22091 + si_noflush_write_lock(sb);
22094 +static inline int si_read_trylock(struct super_block *sb, int flags)
22096 + if (/* !au_test_nfsd(current) && */au_ftest_lock(flags, FLUSH))
22097 + au_nwt_flush(&au_sbi(sb)->si_nowait);
22098 + return si_noflush_read_trylock(sb);
22101 +static inline int si_write_trylock(struct super_block *sb, int flags)
22103 + if (/* !au_test_nfsd(current) && */au_ftest_lock(flags, FLUSH))
22104 + au_nwt_flush(&au_sbi(sb)->si_nowait);
22105 + return si_noflush_write_trylock(sb);
22108 +/* to debug easier, do not make them inlined functions */
22109 +#define SiMustReadLock(sb) AuRwMustReadLock(&au_sbi(sb)->si_rwsem)
22110 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
22111 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
22113 +/* ---------------------------------------------------------------------- */
22115 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
22117 + SiMustAnyLock(sb);
22118 + return au_sbi(sb)->si_bend;
22121 +static inline unsigned int au_mntflags(struct super_block *sb)
22123 + SiMustAnyLock(sb);
22124 + return au_sbi(sb)->si_mntflags;
22127 +static inline au_gen_t au_sigen(struct super_block *sb)
22129 + SiMustAnyLock(sb);
22130 + return au_sbi(sb)->si_generation;
22133 +#endif /* __KERNEL__ */
22134 +#endif /* __AUFS_SUPER_H__ */
22135 diff -urN linux/fs/aufs/sysaufs.c linux-aufs/fs/aufs/sysaufs.c
22136 --- linux/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
22137 +++ linux-aufs/fs/aufs/sysaufs.c 2009-03-12 16:18:04.000000000 +0100
22140 + * Copyright (C) 2005-2009 Junjiro Okajima
22142 + * This program, aufs is free software; you can redistribute it and/or modify
22143 + * it under the terms of the GNU General Public License as published by
22144 + * the Free Software Foundation; either version 2 of the License, or
22145 + * (at your option) any later version.
22147 + * This program is distributed in the hope that it will be useful,
22148 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22149 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22150 + * GNU General Public License for more details.
22152 + * You should have received a copy of the GNU General Public License
22153 + * along with this program; if not, write to the Free Software
22154 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22158 + * sysfs interface and lifetime management
22159 + * they are necessary regardless sysfs is disabled.
22164 +#include <linux/fs.h>
22165 +#include <linux/module.h>
22166 +#include <linux/random.h>
22167 +#include <linux/sysfs.h>
22170 +/* ---------------------------------------------------------------------- */
22172 +unsigned long au_si_mask;
22174 +/* ---------------------------------------------------------------------- */
22176 +struct kset *au_kset;
22178 +#define AuSbiAttr(_name) { \
22179 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
22180 + .show = sysaufs_sbi_##_name, \
22183 +static struct au_sbi_attr au_sbi_attr_xino = AuSbiAttr(xino);
22184 +#ifdef CONFIG_AUFS_EXPORT
22185 +static struct au_sbi_attr au_sbi_attr_xigen = AuSbiAttr(xigen);
22187 +struct attribute *au_sbi_attrs[] = {
22188 + &au_sbi_attr_xino.attr,
22189 +#ifdef CONFIG_AUFS_EXPORT
22190 + &au_sbi_attr_xigen.attr,
22195 +static struct sysfs_ops au_sbi_ops = {
22196 + .show = sysaufs_sbi_show
22199 +static struct kobj_type au_sbi_ktype = {
22200 + .release = au_si_free,
22201 + .sysfs_ops = &au_sbi_ops,
22202 + .default_attrs = au_sbi_attrs
22205 +/* ---------------------------------------------------------------------- */
22207 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
22211 + sbinfo->si_kobj.kset = au_kset;
22212 + /* some people doesn't like to show a pointer in kernel */
22213 + err = kobject_init_and_add(&sbinfo->si_kobj, &au_sbi_ktype,
22214 + NULL/*&au_kset->kobj*/,
22215 + SysaufsSb_PREFIX "%lx",
22216 + au_si_mask ^ (unsigned long)sbinfo);
22222 +/* ---------------------------------------------------------------------- */
22224 +void sysaufs_fin(void)
22226 + sysfs_remove_group(&au_kset->kobj, au_attr_group);
22227 + kset_unregister(au_kset);
22230 +int __init sysaufs_init(void)
22234 + get_random_bytes(&au_si_mask, sizeof(au_si_mask));
22236 + au_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
22237 + err = PTR_ERR(au_kset);
22238 + if (IS_ERR(au_kset))
22240 + err = sysfs_create_group(&au_kset->kobj, au_attr_group);
22241 + if (unlikely(err))
22242 + kset_unregister(au_kset);
22248 diff -urN linux/fs/aufs/sysaufs.h linux-aufs/fs/aufs/sysaufs.h
22249 --- linux/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
22250 +++ linux-aufs/fs/aufs/sysaufs.h 2009-03-12 16:18:04.000000000 +0100
22253 + * Copyright (C) 2005-2009 Junjiro Okajima
22255 + * This program, aufs is free software; you can redistribute it and/or modify
22256 + * it under the terms of the GNU General Public License as published by
22257 + * the Free Software Foundation; either version 2 of the License, or
22258 + * (at your option) any later version.
22260 + * This program is distributed in the hope that it will be useful,
22261 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22262 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22263 + * GNU General Public License for more details.
22265 + * You should have received a copy of the GNU General Public License
22266 + * along with this program; if not, write to the Free Software
22267 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22271 + * sysfs interface and lifetime management
22276 +#ifndef __SYSAUFS_H__
22277 +#define __SYSAUFS_H__
22281 +#include <linux/fs.h>
22282 +#include <linux/sysfs.h>
22283 +#include "module.h"
22284 +#include "super.h"
22286 +#define SysaufsSb_PREFIX "si_" /* followed by %p */
22288 +struct au_sbi_attr {
22289 + struct attribute attr;
22290 + int (*show)(struct seq_file *seq, struct super_block *sb);
22293 +/* ---------------------------------------------------------------------- */
22296 +extern unsigned long au_si_mask;
22297 +extern struct kset *au_kset;
22298 +extern struct attribute *au_sbi_attrs[];
22299 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
22300 +int __init sysaufs_init(void);
22301 +void sysaufs_fin(void);
22303 +/* ---------------------------------------------------------------------- */
22306 +#ifdef CONFIG_SYSFS
22308 +extern struct attribute_group *au_attr_group;
22309 +extern struct kobj_type *au_ktype;
22311 +int sysaufs_sbi_xino(struct seq_file *seq, struct super_block *sb);
22312 +#ifdef CONFIG_AUFS_EXPORT
22313 +int sysaufs_sbi_xigen(struct seq_file *seq, struct super_block *sb);
22315 +int sysaufs_sbi_mntpnt1(struct seq_file *seq, struct super_block *sb);
22316 +ssize_t sysaufs_sbi_show(struct kobject *kobj, struct attribute *attr,
22319 +void sysaufs_br_init(struct au_branch *br);
22320 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
22321 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
22323 +#define au_attr_group NULL
22324 +#define au_ktype NULL
22327 +int sysaufs_sbi_xino(struct seq_file *seq, struct super_block *sb)
22332 +#ifdef CONFIG_AUFS_EXPORT
22334 +int sysaufs_sbi_xigen(struct seq_file *seq, struct super_block *sb)
22341 +int sysaufs_sbi_mntpnt1(struct seq_file *seq, struct super_block *sb)
22347 +ssize_t sysaufs_sbi_show(struct kobject *kobj, struct attribute *attr,
22353 +static inline void sysaufs_br_init(struct au_branch *br)
22358 +static inline void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
22363 +static inline void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
22367 +#endif /* CONFIG_SYSFS */
22369 +#endif /* __KERNEL__ */
22370 +#endif /* __SYSAUFS_H__ */
22371 diff -urN linux/fs/aufs/sysfs.c linux-aufs/fs/aufs/sysfs.c
22372 --- linux/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
22373 +++ linux-aufs/fs/aufs/sysfs.c 2009-03-12 16:18:04.000000000 +0100
22376 + * Copyright (C) 2005-2009 Junjiro Okajima
22378 + * This program, aufs is free software; you can redistribute it and/or modify
22379 + * it under the terms of the GNU General Public License as published by
22380 + * the Free Software Foundation; either version 2 of the License, or
22381 + * (at your option) any later version.
22383 + * This program is distributed in the hope that it will be useful,
22384 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22385 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22386 + * GNU General Public License for more details.
22388 + * You should have received a copy of the GNU General Public License
22389 + * along with this program; if not, write to the Free Software
22390 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22394 + * sysfs interface
22399 +#include <linux/fs.h>
22400 +#include <linux/module.h>
22401 +#include <linux/seq_file.h>
22402 +#include <linux/sysfs.h>
22406 +#ifdef CONFIG_AUFS_LOCAL
22407 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
22410 +#define conf_bool(name) "CONFIG_AUFS_" #name "=y\n"
22411 + static const char opt[] =
22412 +#ifdef CONFIG_AUFS
22413 + "CONFIG_AUFS=y\n"
22415 + "CONFIG_AUFS=m\n"
22417 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
22418 + conf_bool(BRANCH_MAX_127)
22419 +#elif defined(CONFIG_AUFS_BRANCH_MAX_511)
22420 + conf_bool(BRANCH_MAX_511)
22421 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
22422 + conf_bool(BRANCH_MAX_1023)
22423 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
22424 + conf_bool(BRANCH_MAX_32767)
22426 +#ifdef CONFIG_AUFS_STAT
22429 +#ifdef CONFIG_AUFS_HINOTIFY
22430 + conf_bool(HINOTIFY)
22432 +#ifdef CONFIG_AUFS_EXPORT
22433 + conf_bool(EXPORT)
22435 +#ifdef CONFIG_AUFS_INO_T_64
22436 + conf_bool(INO_T_64)
22438 +#ifdef CONFIG_AUFS_ROBR
22441 +#ifdef CONFIG_AUFS_DLGT
22444 +#ifdef CONFIG_AUFS_HIN_OR_DLGT
22445 + conf_bool(HIN_OR_DLGT)
22447 +#ifdef CONFIG_AUFS_SHWH
22450 +#ifdef CONFIG_AUFS_RR_SQUASHFS
22451 + conf_bool(RR_SQUASHFS)
22453 +#ifdef CONFIG_AUFS_SEC_PERM_PATCH
22454 + conf_bool(SEC_PERM_PATCH)
22456 +#ifdef CONFIG_AUFS_SPLICE_PATCH
22457 + conf_bool(SPLICE_PATCH)
22459 +#ifdef CONFIG_AUFS_LHASH_PATCH
22460 + conf_bool(LHASH_PATCH)
22462 +#ifdef CONFIG_AUFS_PUT_FILP_PATCH
22463 + conf_bool(PUT_FILP_PATCH)
22465 +#ifdef CONFIG_AUFS_BR_NFS
22466 + conf_bool(BR_NFS)
22468 +#ifdef CONFIG_AUFS_BR_NFS_V4
22469 + conf_bool(BR_NFS_V4)
22471 +#ifdef CONFIG_AUFS_BR_XFS
22472 + conf_bool(BR_XFS)
22474 +#ifdef CONFIG_AUFS_FSYNC_SUPER_PATCH
22475 + conf_bool(FSYNC_SUPER_PATCH)
22477 +#ifdef CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH
22478 + conf_bool(DENY_WRITE_ACCESS_PATCH)
22480 +#ifdef CONFIG_AUFS_KSIZE_PATCH
22481 + conf_bool(KSIZE_PATCH)
22483 +#ifdef CONFIG_AUFS_WORKAROUND_FUSE
22484 + conf_bool(WORKAROUND_FUSE)
22486 +#ifdef CONFIG_AUFS_GETATTR
22487 + conf_bool(GETATTR)
22489 +#ifdef CONFIG_AUFS_DEBUG
22492 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
22493 + conf_bool(MAGIC_SYSRQ)
22495 +#ifdef CONFIG_AUFS_DEBUG_LOCK
22496 + conf_bool(DEBUG_LOCK)
22498 +#ifdef CONFIG_AUFS_COMPAT
22499 + conf_bool(COMPAT)
22501 +#ifdef CONFIG_AUFS_UNIONFS22_PATCH
22502 + conf_bool(UNIONFS22_PATCH)
22504 +#ifdef CONFIG_AUFS_UNIONFS23_PATCH
22505 + conf_bool(UNIONFS23_PATCH)
22511 + const char *end = buf + PAGE_SIZE;
22513 + p += snprintf(p, end - p, "%s", opt);
22514 +#ifdef DbgUdbaRace
22516 + p += snprintf(p, end - p, "DbgUdbaRace=%d\n", DbgUdbaRace);
22524 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
22527 +#ifdef CONFIG_AUFS_STAT
22528 +static ssize_t stat_show(struct kobject *kobj, struct kobj_attribute *attr,
22532 + const char *end = buf + PAGE_SIZE;
22535 + p += snprintf(p, end - p, "wkq max_busy:");
22536 + for (i = 0; p < end && i < aufs_nwkq; i++)
22537 + p += snprintf(p, end - p, " %u", au_wkq[i].max_busy);
22539 + p += snprintf(p, end - p, ", %u(generic)\n",
22540 + au_wkq[aufs_nwkq].max_busy);
22548 +static struct kobj_attribute au_stat_attr = __ATTR_RO(stat);
22551 +#ifdef CONFIG_AUFS_DEBUG
22552 +static ssize_t debug_show(struct kobject *kobj, struct kobj_attribute *attr,
22555 + return sprintf(buf, "%d\n", au_debug_test());
22558 +static ssize_t debug_store(struct kobject *kobj, struct kobj_attribute *attr,
22559 + const char *buf, size_t sz)
22561 + LKTRTrace("%.*s\n", (unsigned int)sz, buf);
22563 + if (unlikely(!sz || (*buf != '0' && *buf != '1')))
22564 + return -EOPNOTSUPP;
22568 + else if (*buf == '1')
22573 +static struct kobj_attribute au_debug_attr = __ATTR(debug, S_IRUGO | S_IWUSR,
22574 + debug_show, debug_store);
22577 +static struct attribute *au_attr[] = {
22578 +#ifdef CONFIG_AUFS_LOCAL
22579 + &au_config_attr.attr,
22581 +#ifdef CONFIG_AUFS_STAT
22582 + &au_stat_attr.attr,
22584 +#ifdef CONFIG_AUFS_DEBUG
22585 + &au_debug_attr.attr,
22587 + NULL, /* need to NULL terminate the list of attributes */
22590 +static struct attribute_group au_attr_group_body = {
22594 +struct attribute_group *au_attr_group = &au_attr_group_body;
22596 +/* ---------------------------------------------------------------------- */
22599 + * they are copied from linux/lib/kobject.c,
22600 + * and will be exported in the future.
22602 +static ssize_t au_attr_show(struct kobject *kobj, struct attribute *attr,
22605 + struct kobj_attribute *kattr;
22606 + ssize_t ret = -EIO;
22608 + kattr = container_of(attr, struct kobj_attribute, attr);
22610 + ret = kattr->show(kobj, kattr, buf);
22614 +#ifdef CONFIG_AUFS_DEBUG
22615 +static ssize_t au_attr_store(struct kobject *kobj, struct attribute *attr,
22616 + const char *buf, size_t count)
22618 + struct kobj_attribute *kattr;
22619 + ssize_t ret = -EIO;
22621 + kattr = container_of(attr, struct kobj_attribute, attr);
22622 + if (kattr->store)
22623 + ret = kattr->store(kobj, kattr, buf, count);
22628 +static struct sysfs_ops sysaufs_ops = {
22629 + .show = au_attr_show,
22630 +#ifdef CONFIG_AUFS_DEBUG
22631 + .store = au_attr_store
22635 +static struct kobj_type au_ktype_body = {
22636 + .sysfs_ops = &sysaufs_ops
22638 +struct kobj_type *au_ktype = &au_ktype_body;
22640 +/* ---------------------------------------------------------------------- */
22642 +static noinline_for_stack
22643 +int sysaufs_sbi_xi(struct seq_file *seq, struct file *xf, int dlgt,
22648 + struct path path;
22650 + err = vfsub_getattr(xf->f_vfsmnt, xf->f_dentry, &st, dlgt);
22652 + seq_printf(seq, "%llux%lu %lld",
22653 + st.blocks, st.blksize, (long long)st.size);
22654 + if (print_path) {
22655 + path.dentry = xf->f_dentry;
22656 + path.mnt = xf->f_vfsmnt;
22657 + seq_putc(seq, ' ');
22658 + seq_path(seq, &path, au_esc_chars);
22660 + seq_putc(seq, '\n');
22662 + seq_printf(seq, "err %d\n", err);
22668 +int sysaufs_sbi_xino(struct seq_file *seq, struct super_block *sb)
22671 + unsigned int mnt_flags;
22672 + aufs_bindex_t bend, bindex;
22673 + unsigned char dlgt, xinodir;
22675 + struct path path;
22676 + struct au_sbinfo *sbinfo;
22681 + sbinfo = au_sbi(sb);
22682 + mnt_flags = au_mntflags(sb);
22683 + xinodir = !!au_opt_test(mnt_flags, XINODIR);
22684 + if (!au_opt_test_xino(mnt_flags)) {
22685 +#ifdef CONFIG_AUFS_DEBUG
22686 + AuDebugOn(sbinfo->si_xib);
22687 + bend = au_sbend(sb);
22688 + for (bindex = 0; bindex <= bend; bindex++)
22689 + AuDebugOn(au_sbr(sb, bindex)->br_xino.xi_file);
22692 + goto out; /* success */
22695 + dlgt = !!au_test_dlgt(mnt_flags);
22696 + err = sysaufs_sbi_xi(seq, sbinfo->si_xib, dlgt, xinodir);
22698 + bend = au_sbend(sb);
22699 + for (bindex = 0; !err && bindex <= bend; bindex++) {
22700 + xf = au_sbr(sb, bindex)->br_xino.xi_file;
22703 + seq_printf(seq, "%d: ", bindex);
22704 + err = vfsub_getattr(xf->f_vfsmnt, xf->f_dentry, &st, dlgt);
22706 + seq_printf(seq, "%ld, %llux%lu %lld",
22707 + (long)file_count(xf), st.blocks, st.blksize,
22708 + (long long)st.size);
22710 + path.dentry = xf->f_dentry;
22711 + path.mnt = xf->f_vfsmnt;
22712 + seq_putc(seq, ' ');
22713 + seq_path(seq, &path, au_esc_chars);
22715 + seq_putc(seq, '\n');
22717 + seq_printf(seq, "err %d\n", err);
22725 +#ifdef CONFIG_AUFS_EXPORT
22726 +int sysaufs_sbi_xigen(struct seq_file *seq, struct super_block *sb)
22729 + unsigned int mnt_flags;
22730 + struct au_sbinfo *sbinfo;
22735 + sbinfo = au_sbi(sb);
22736 + mnt_flags = au_mntflags(sb);
22737 + if (au_opt_test_xino(mnt_flags))
22738 + err = sysaufs_sbi_xi(seq, sbinfo->si_xigen,
22739 + !!au_opt_test(mnt_flags, DLGT),
22740 + !!au_opt_test(mnt_flags, XINODIR));
22748 + * the lifetime of branch is independent from the entry under sysfs.
22749 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
22752 +#define SysaufsBr_PREFIX "br"
22753 +static int sysaufs_sbi_br(struct seq_file *seq, struct super_block *sb,
22754 + aufs_bindex_t bindex)
22757 + struct dentry *root;
22758 + struct au_branch *br;
22759 + struct path path;
22761 + LKTRTrace("b%d\n", bindex);
22764 + if (unlikely(au_sbend(sb) < bindex))
22768 + root = sb->s_root;
22769 + di_read_lock_parent(root, !AuLock_IR);
22770 + br = au_sbr(sb, bindex);
22771 + path.mnt = br->br_mnt;
22772 + path.dentry = au_h_dptr(root, bindex);
22773 + seq_path(seq, &path, au_esc_chars);
22774 + di_read_unlock(root, !AuLock_IR);
22775 + seq_printf(seq, "=%s\n", au_optstr_br_perm(br->br_perm));
22782 +/* ---------------------------------------------------------------------- */
22784 +static struct seq_file *au_seq(char *p, ssize_t len)
22786 + struct seq_file *seq;
22788 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
22790 + /* todo: necessary? */
22791 + /* mutex_init(&seq.lock); */
22794 + return seq; /* success */
22797 + seq = ERR_PTR(-ENOMEM);
22798 + AuTraceErrPtr(seq);
22802 +/* todo: file size may exceed PAGE_SIZE */
22803 +ssize_t sysaufs_sbi_show(struct kobject *kobj, struct attribute *attr,
22808 + struct au_sbinfo *sbinfo;
22809 + struct super_block *sb;
22810 + struct seq_file *seq;
22812 + struct attribute **cattr;
22814 + LKTRTrace("%s/%s\n", kobject_name(kobj), attr->name);
22816 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
22817 + sb = sbinfo->si_sb;
22818 + si_noflush_read_lock(sb);
22820 + seq = au_seq(buf, PAGE_SIZE);
22821 + err = PTR_ERR(seq);
22825 + name = (void *)attr->name;
22826 + cattr = au_sbi_attrs;
22828 + if (!strcmp(name, (*cattr)->name)) {
22829 + err = container_of(*cattr, struct au_sbi_attr, attr)
22836 + if (!strncmp(name, SysaufsBr_PREFIX, sizeof(SysaufsBr_PREFIX) - 1)) {
22837 + name += sizeof(SysaufsBr_PREFIX) - 1;
22838 + err = strict_strtol(name, 10, &l);
22840 + err = sysaufs_sbi_br(seq, sb, (aufs_bindex_t)l);
22847 + err = seq->count;
22848 + /* sysfs limit */
22849 + if (unlikely(err == PAGE_SIZE))
22854 + si_read_unlock(sb);
22859 +/* ---------------------------------------------------------------------- */
22861 +void sysaufs_br_init(struct au_branch *br)
22863 + br->br_attr.name = br->br_name;
22864 + br->br_attr.mode = S_IRUGO;
22865 + br->br_attr.owner = THIS_MODULE;
22868 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
22870 + struct au_sbinfo *sbinfo;
22871 + aufs_bindex_t bend;
22873 + LKTRTrace("b%d\n", bindex);
22875 + if (!sysaufs_brs)
22878 + sbinfo = au_sbi(sb);
22879 + bend = au_sbend(sb);
22880 + for (; bindex <= bend; bindex++)
22881 + sysfs_remove_file(&sbinfo->si_kobj,
22882 + &au_sbr(sb, bindex)->br_attr);
22885 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
22888 + struct kobject *kobj;
22889 + aufs_bindex_t bend;
22890 + struct au_branch *br;
22892 + LKTRTrace("b%d\n", bindex);
22894 + if (!sysaufs_brs)
22897 + kobj = &au_sbi(sb)->si_kobj;
22898 + bend = au_sbend(sb);
22899 + for (; bindex <= bend; bindex++) {
22900 + br = au_sbr(sb, bindex);
22901 + snprintf(br->br_name, sizeof(br->br_name),
22902 + SysaufsBr_PREFIX "%d", bindex);
22903 + err = sysfs_create_file(kobj, &br->br_attr);
22904 + if (unlikely(err))
22905 + AuWarn("failed %s under sysfs(%d)\n", br->br_name, err);
22908 diff -urN linux/fs/aufs/sysrq.c linux-aufs/fs/aufs/sysrq.c
22909 --- linux/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
22910 +++ linux-aufs/fs/aufs/sysrq.c 2009-03-12 16:18:04.000000000 +0100
22913 + * Copyright (C) 2005-2009 Junjiro Okajima
22915 + * This program, aufs is free software; you can redistribute it and/or modify
22916 + * it under the terms of the GNU General Public License as published by
22917 + * the Free Software Foundation; either version 2 of the License, or
22918 + * (at your option) any later version.
22920 + * This program is distributed in the hope that it will be useful,
22921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22923 + * GNU General Public License for more details.
22925 + * You should have received a copy of the GNU General Public License
22926 + * along with this program; if not, write to the Free Software
22927 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22931 + * magic sysrq hanlder
22936 +#include <linux/fs.h>
22937 +#include <linux/module.h>
22938 +#include <linux/moduleparam.h>
22939 +/* #include <linux/sysrq.h> */
22942 +#ifdef CONFIG_AUFS_DEBUG_LOCK
22943 +struct au_dbg_lock {
22944 + struct list_head list;
22946 + struct super_block *sb;
22947 + struct dentry *dentry;
22948 + struct inode *inode;
22952 + unsigned int lsc;
22956 +static void au_dbg_reg(struct au_splhead *spl, void *any, int flags,
22957 + unsigned int lsc)
22959 + struct au_dbg_lock *p = kmalloc(sizeof(*p), GFP_NOFS);
22963 + p->flags = flags;
22965 + p->pid = current->pid;
22966 + spin_lock(&spl->spin);
22967 + list_add(&p->list, &spl->head);
22968 + spin_unlock(&spl->spin);
22973 +static void au_dbg_unreg(struct au_splhead *spl, void *any, int flags)
22975 + struct au_dbg_lock *p, *tmp, *found;
22976 + struct list_head *head = &spl->head;
22977 + const pid_t pid = current->pid;
22980 + spin_lock(&spl->spin);
22981 + list_for_each_entry_safe(p, tmp, head, list)
22982 + if (p->any == any && p->pid == pid) {
22983 + list_del(&p->list);
22987 + spin_unlock(&spl->spin);
22992 +/* ---------------------------------------------------------------------- */
22994 +void au_dbg_locking_si_reg(struct super_block *sb, int flags)
22996 + au_dbg_reg(au_sbi(sb)->si_dbg_lock + AuDbgLock_SI_LOCKING, sb, flags,
23000 +void au_dbg_locking_si_unreg(struct super_block *sb, int flags)
23002 + au_dbg_unreg(au_sbi(sb)->si_dbg_lock + AuDbgLock_SI_LOCKING, sb, flags);
23005 +void au_dbg_locked_si_reg(struct super_block *sb, int flags)
23007 + au_dbg_reg(au_sbi(sb)->si_dbg_lock + AuDbgLock_SI_LOCKED, sb, flags,
23011 +void au_dbg_locked_si_unreg(struct super_block *sb, int flags)
23013 + au_dbg_unreg(au_sbi(sb)->si_dbg_lock + AuDbgLock_SI_LOCKED, sb, flags);
23016 +void au_dbg_locking_di_reg(struct dentry *d, int flags, unsigned int lsc)
23018 + au_dbg_reg(au_sbi(d->d_sb)->si_dbg_lock + AuDbgLock_DI_LOCKING, d,
23022 +void au_dbg_locking_di_unreg(struct dentry *d, int flags)
23024 + au_dbg_unreg(au_sbi(d->d_sb)->si_dbg_lock + AuDbgLock_DI_LOCKING, d,
23028 +void au_dbg_locked_di_reg(struct dentry *d, int flags, unsigned int lsc)
23030 + au_dbg_reg(au_sbi(d->d_sb)->si_dbg_lock + AuDbgLock_DI_LOCKED, d, flags,
23034 +void au_dbg_locked_di_unreg(struct dentry *d, int flags)
23036 + au_dbg_unreg(au_sbi(d->d_sb)->si_dbg_lock + AuDbgLock_DI_LOCKED, d,
23040 +void au_dbg_locking_ii_reg(struct inode *i, int flags, unsigned int lsc)
23042 + au_dbg_reg(au_sbi(i->i_sb)->si_dbg_lock + AuDbgLock_II_LOCKING, i,
23046 +void au_dbg_locking_ii_unreg(struct inode *i, int flags)
23048 + au_dbg_unreg(au_sbi(i->i_sb)->si_dbg_lock + AuDbgLock_II_LOCKING, i,
23052 +void au_dbg_locked_ii_reg(struct inode *i, int flags, unsigned int lsc)
23054 + au_dbg_reg(au_sbi(i->i_sb)->si_dbg_lock + AuDbgLock_II_LOCKED, i, flags,
23058 +void au_dbg_locked_ii_unreg(struct inode *i, int flags)
23060 + au_dbg_unreg(au_sbi(i->i_sb)->si_dbg_lock + AuDbgLock_II_LOCKED, i,
23063 +#endif /* CONFIG_AUFS_DEBUG_LOCK */
23065 +/* ---------------------------------------------------------------------- */
23067 +static void sysrq_sb(struct super_block *sb)
23071 + struct au_sbinfo *sbinfo;
23072 + struct file *file;
23074 + plevel = au_plevel;
23075 + au_plevel = KERN_WARNING;
23078 + sbinfo = au_sbi(sb);
23079 + pr_warning("si=%lx\n", au_si_mask ^ (unsigned long)sbinfo);
23080 + pr_warning(AUFS_NAME ": superblock\n");
23082 + pr_warning(AUFS_NAME ": root dentry\n");
23083 + au_dpri_dentry(sb->s_root);
23084 + pr_warning(AUFS_NAME ": root inode\n");
23085 + au_dpri_inode(sb->s_root->d_inode);
23086 + pr_warning(AUFS_NAME ": isolated inode\n");
23087 + list_for_each_entry(i, &sb->s_inodes, i_sb_list)
23088 + if (list_empty(&i->i_dentry))
23089 + au_dpri_inode(i);
23090 + pr_warning(AUFS_NAME ": files\n");
23091 + list_for_each_entry(file, &sb->s_files, f_u.fu_list)
23092 + if (au_test_aufs_file(file))
23093 + au_dpri_file(file);
23095 +#ifdef CONFIG_AUFS_DEBUG_LOCK
23097 + struct au_dbg_lock *p;
23098 + struct list_head *head;
23100 + pr_warning(AUFS_NAME ": locking si\n");
23101 + head = &sbinfo->si_dbg_lock[AuDbgLock_SI_LOCKING].head;
23102 + list_for_each_entry(p, head, list)
23103 + pr_warning("pid: %d, 0x%x\n", p->pid, p->flags);
23104 + pr_warning(AUFS_NAME ": locked si\n");
23105 + head = &sbinfo->si_dbg_lock[AuDbgLock_SI_LOCKED].head;
23106 + list_for_each_entry(p, head, list)
23107 + pr_warning("pid: %d, 0x%x\n", p->pid, p->flags);
23108 + pr_warning(AUFS_NAME ": locking di\n");
23109 + head = &sbinfo->si_dbg_lock[AuDbgLock_DI_LOCKING].head;
23110 + list_for_each_entry(p, head, list) {
23111 + pr_warning("pid: %d, 0x%x, %d\n",
23112 + p->pid, p->flags, p->lsc);
23113 + au_dpri_dentry(p->dentry);
23115 + pr_warning(AUFS_NAME ": locked di\n");
23116 + head = &sbinfo->si_dbg_lock[AuDbgLock_DI_LOCKED].head;
23117 + list_for_each_entry(p, head, list) {
23118 + pr_warning("pid: %d, 0x%x, %d\n",
23119 + p->pid, p->flags, p->lsc);
23120 + au_dpri_dentry(p->dentry);
23122 + pr_warning(AUFS_NAME ": locking ii\n");
23123 + head = &sbinfo->si_dbg_lock[AuDbgLock_II_LOCKING].head;
23124 + list_for_each_entry(p, head, list) {
23125 + pr_warning("pid: %d, %d\n", p->pid, p->lsc);
23126 + au_dpri_inode(p->inode);
23128 + pr_warning(AUFS_NAME ": locked ii\n");
23129 + head = &sbinfo->si_dbg_lock[AuDbgLock_II_LOCKED].head;
23130 + list_for_each_entry(p, head, list) {
23131 + pr_warning("pid: %d, %d\n", p->pid, p->lsc);
23132 + au_dpri_inode(p->inode);
23137 + au_plevel = plevel;
23141 +/* ---------------------------------------------------------------------- */
23143 +/* module parameter */
23144 +static char *aufs_sysrq_key = "a";
23145 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
23146 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
23148 +static void au_sysrq(int key, struct tty_struct *tty)
23150 + struct kobject *kobj;
23151 + struct au_sbinfo *sbinfo;
23153 + /* spin_lock(&au_kset->list_lock); */
23154 + list_for_each_entry(kobj, &au_kset->list, entry) {
23155 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
23156 + sysrq_sb(sbinfo->si_sb);
23158 + /* spin_unlock(&au_kset->list_lock); */
23161 +static struct sysrq_key_op au_sysrq_op = {
23162 + .handler = au_sysrq,
23163 + .help_msg = "Aufs",
23164 + .action_msg = "Aufs",
23165 + /* todo: test mask? */
23166 + .enable_mask = SYSRQ_ENABLE_DUMP
23169 +/* ---------------------------------------------------------------------- */
23171 +int __init au_sysrq_init(void)
23177 + key = *aufs_sysrq_key;
23178 + if ('a' <= key && key <= 'z')
23179 + err = register_sysrq_key(key, &au_sysrq_op);
23180 + if (unlikely(err))
23181 + AuErr("err %d, sysrq=%c\n", err, key);
23185 +void au_sysrq_fin(void)
23188 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
23189 + if (unlikely(err))
23190 + AuErr("err %d (ignored)\n", err);
23192 diff -urN linux/fs/aufs/vdir.c linux-aufs/fs/aufs/vdir.c
23193 --- linux/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
23194 +++ linux-aufs/fs/aufs/vdir.c 2009-03-12 16:18:04.000000000 +0100
23197 + * Copyright (C) 2005-2009 Junjiro Okajima
23199 + * This program, aufs is free software; you can redistribute it and/or modify
23200 + * it under the terms of the GNU General Public License as published by
23201 + * the Free Software Foundation; either version 2 of the License, or
23202 + * (at your option) any later version.
23204 + * This program is distributed in the hope that it will be useful,
23205 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23206 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23207 + * GNU General Public License for more details.
23209 + * You should have received a copy of the GNU General Public License
23210 + * along with this program; if not, write to the Free Software
23211 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23215 + * virtual or vertical directory
23222 +static int calc_size(int namelen)
23226 + sz = sizeof(struct au_vdir_de) + namelen;
23227 + if (sizeof(ino_t) == sizeof(long)) {
23228 + const int mask = sizeof(ino_t) - 1;
23230 + sz += sizeof(ino_t);
23235 + AuDebugOn(sz % sizeof(ino_t));
23239 +static int set_deblk_end(union au_vdir_deblk_p *p,
23240 + union au_vdir_deblk_p *deblk_end)
23242 + if (calc_size(0) <= deblk_end->p - p->p) {
23243 + p->de->de_str.len = 0;
23247 + return -1; /* error */
23250 +/* returns true or false */
23251 +static int is_deblk_end(union au_vdir_deblk_p *p,
23252 + union au_vdir_deblk_p *deblk_end)
23254 + if (calc_size(0) <= deblk_end->p - p->p)
23255 + return !p->de->de_str.len;
23259 +static au_vdir_deblk_t *last_deblk(struct au_vdir *vdir)
23261 + return vdir->vd_deblk[vdir->vd_nblk - 1];
23264 +void au_nhash_init(struct au_nhash *nhash)
23267 + for (i = 0; i < AuSize_NHASH; i++)
23268 + INIT_HLIST_HEAD(nhash->heads + i);
23271 +struct au_nhash *au_nhash_new(gfp_t gfp)
23273 + struct au_nhash *nhash;
23275 + nhash = kmalloc(sizeof(*nhash), gfp);
23277 + au_nhash_init(nhash);
23280 + return ERR_PTR(-ENOMEM);
23283 +void au_nhash_del(struct au_nhash *nhash)
23285 + au_nhash_fin(nhash);
23289 +void au_nhash_move(struct au_nhash *dst, struct au_nhash *src)
23296 + for (i = 0; i < AuSize_NHASH; i++) {
23297 + struct hlist_head *h;
23298 + h = dst->heads + i;
23300 + h->first->pprev = &h->first;
23301 + INIT_HLIST_HEAD(src->heads + i);
23306 +/* ---------------------------------------------------------------------- */
23308 +void au_nhash_fin(struct au_nhash *whlist)
23311 + struct hlist_head *head;
23312 + struct au_vdir_wh *tpos;
23313 + struct hlist_node *pos, *n;
23317 + for (i = 0; i < AuSize_NHASH; i++) {
23318 + head = whlist->heads + i;
23319 + hlist_for_each_entry_safe(tpos, pos, n, head, wh_hash) {
23320 + /* hlist_del(pos); */
23326 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
23330 + struct hlist_head *head;
23331 + struct au_vdir_wh *tpos;
23332 + struct hlist_node *pos;
23334 + LKTRTrace("limit %d\n", limit);
23337 + for (i = 0; i < AuSize_NHASH; i++) {
23338 + head = whlist->heads + i;
23339 + hlist_for_each_entry(tpos, pos, head, wh_hash)
23340 + if (tpos->wh_bindex == btgt && ++n > limit)
23346 +static unsigned int au_name_hash(const unsigned char *name, unsigned int len)
23348 + return full_name_hash(name, len) % AuSize_NHASH;
23351 +/* returns found(true) or not */
23352 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int namelen)
23354 + struct hlist_head *head;
23355 + struct au_vdir_wh *tpos;
23356 + struct hlist_node *pos;
23357 + struct au_vdir_destr *str;
23359 + LKTRTrace("%.*s\n", namelen, name);
23361 + head = whlist->heads + au_name_hash(name, namelen);
23362 + hlist_for_each_entry(tpos, pos, head, wh_hash) {
23363 + str = &tpos->wh_str;
23364 + LKTRTrace("%.*s\n", str->len, str->name);
23365 + if (str->len == namelen && !memcmp(str->name, name, namelen))
23371 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int namelen,
23372 + ino_t ino, unsigned int d_type, aufs_bindex_t bindex,
23373 + unsigned char shwh)
23376 + struct au_vdir_destr *str;
23377 + struct au_vdir_wh *wh;
23379 + LKTRTrace("%.*s\n", namelen, name);
23382 + wh = kmalloc(sizeof(*wh) + namelen, GFP_NOFS);
23383 + if (unlikely(!wh))
23386 + wh->wh_bindex = bindex;
23388 + au_shwh_init_wh(wh, ino, d_type);
23389 + str = &wh->wh_str;
23390 + str->len = namelen;
23391 + memcpy(str->name, name, namelen);
23392 + hlist_add_head(&wh->wh_hash,
23393 + whlist->heads + au_name_hash(name, namelen));
23401 +/* ---------------------------------------------------------------------- */
23403 +void au_vdir_free(struct au_vdir *vdir)
23405 + au_vdir_deblk_t **deblk;
23409 + deblk = vdir->vd_deblk;
23410 + while (vdir->vd_nblk--) {
23414 + kfree(vdir->vd_deblk);
23415 + au_cache_free_vdir(vdir);
23418 +static int append_deblk(struct au_vdir *vdir)
23421 + au_vdir_deblk_t **o;
23422 + union au_vdir_deblk_p p, deblk_end;
23427 + sz = sizeof(*o) * vdir->vd_nblk;
23428 + o = au_kzrealloc(vdir->vd_deblk, sz, sz + sizeof(*o), GFP_NOFS);
23429 + if (unlikely(!o))
23431 + vdir->vd_deblk = o;
23432 + p.deblk = kmalloc(sizeof(*p.deblk), GFP_NOFS);
23434 + i = vdir->vd_nblk++;
23435 + vdir->vd_deblk[i] = p.deblk;
23436 + vdir->vd_last.i = i;
23437 + vdir->vd_last.p.p = p.p;
23438 + deblk_end.deblk = p.deblk + 1;
23439 + err = set_deblk_end(&p, &deblk_end);
23448 +static struct au_vdir *alloc_vdir(void)
23450 + struct au_vdir *vdir;
23456 + vdir = au_cache_alloc_vdir();
23457 + if (unlikely(!vdir))
23459 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
23460 + if (unlikely(!vdir->vd_deblk))
23463 + vdir->vd_nblk = 0;
23464 + vdir->vd_version = 0;
23465 + vdir->vd_jiffy = 0;
23466 + err = append_deblk(vdir);
23468 + return vdir; /* success */
23470 + kfree(vdir->vd_deblk);
23473 + au_cache_free_vdir(vdir);
23475 + vdir = ERR_PTR(err);
23476 + AuTraceErrPtr(vdir);
23480 +static int reinit_vdir(struct au_vdir *vdir)
23483 + union au_vdir_deblk_p p, deblk_end;
23487 + while (vdir->vd_nblk > 1) {
23488 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
23489 + vdir->vd_deblk[vdir->vd_nblk - 1] = NULL;
23492 + p.deblk = vdir->vd_deblk[0];
23493 + deblk_end.deblk = p.deblk + 1;
23494 + err = set_deblk_end(&p, &deblk_end);
23496 + vdir->vd_version = 0;
23497 + vdir->vd_jiffy = 0;
23498 + vdir->vd_last.i = 0;
23499 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
23504 +/* ---------------------------------------------------------------------- */
23506 +static void free_dehlist(struct au_nhash *dehlist)
23509 + struct hlist_head *head;
23510 + struct au_vdir_dehstr *tpos;
23511 + struct hlist_node *pos, *n;
23515 + for (i = 0; i < AuSize_NHASH; i++) {
23516 + head = dehlist->heads + i;
23517 + hlist_for_each_entry_safe(tpos, pos, n, head, hash) {
23518 + /* hlist_del(pos); */
23519 + au_cache_free_dehstr(tpos);
23524 +/* returns found(true) or not */
23525 +static int test_known(struct au_nhash *delist, char *name, int namelen)
23527 + struct hlist_head *head;
23528 + struct au_vdir_dehstr *tpos;
23529 + struct hlist_node *pos;
23530 + struct au_vdir_destr *str;
23532 + LKTRTrace("%.*s\n", namelen, name);
23534 + head = delist->heads + au_name_hash(name, namelen);
23535 + hlist_for_each_entry(tpos, pos, head, hash) {
23537 + LKTRTrace("%.*s\n", str->len, str->name);
23538 + if (str->len == namelen && !memcmp(str->name, name, namelen))
23545 +static int append_de(struct au_vdir *vdir, char *name, int namelen, ino_t ino,
23546 + unsigned int d_type, struct au_nhash *delist)
23549 + union au_vdir_deblk_p p, *room, deblk_end;
23550 + struct au_vdir_dehstr *dehstr;
23552 + LKTRTrace("%.*s %d, i%lu, dt%u\n",
23553 + namelen, name, namelen, (unsigned long)ino, d_type);
23555 + p.deblk = last_deblk(vdir);
23556 + deblk_end.deblk = p.deblk + 1;
23557 + room = &vdir->vd_last.p;
23558 + AuDebugOn(room->p < p.p || deblk_end.p <= room->p
23559 + || !is_deblk_end(room, &deblk_end));
23561 + sz = calc_size(namelen);
23562 + if (unlikely(sz > deblk_end.p - room->p)) {
23563 + err = append_deblk(vdir);
23564 + if (unlikely(err))
23566 + p.deblk = last_deblk(vdir);
23567 + deblk_end.deblk = p.deblk + 1;
23569 + AuDebugOn(room->p != p.p);
23573 + dehstr = au_cache_alloc_dehstr();
23574 + if (unlikely(!dehstr))
23576 + dehstr->str = &room->de->de_str;
23577 + hlist_add_head(&dehstr->hash,
23578 + delist->heads + au_name_hash(name, namelen));
23580 + room->de->de_ino = ino;
23581 + room->de->de_type = d_type;
23582 + room->de->de_str.len = namelen;
23583 + memcpy(room->de->de_str.name, name, namelen);
23587 + if (unlikely(set_deblk_end(room, &deblk_end)))
23588 + err = append_deblk(vdir);
23596 +/* ---------------------------------------------------------------------- */
23598 +static int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
23599 + unsigned int d_type, ino_t *ino)
23602 + struct au_xino_entry xinoe;
23603 + struct mutex *mtx;
23604 + const int isdir = (d_type == DT_DIR);
23606 + /* prevent hardlinks from race condition */
23609 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
23612 + err = au_xino_read(sb, bindex, h_ino, &xinoe);
23613 + if (unlikely(err))
23616 + if (!xinoe.ino) {
23618 + xinoe.ino = au_xino_new_ino(sb);
23619 + if (unlikely(!xinoe.ino))
23622 +#if 0 /* reserved for future use */
23623 + struct inode *h_inode;
23624 + xinoe.h_gen = AuXino_INVALID_HGEN;
23625 + h_inode = ilookup(au_sbr_sb(sb, bindex), h_ino);
23627 + if (!is_bad_inode(h_inode)) {
23628 + xinoe.h_gen = h_inode->i_generation;
23629 + WARN_ON(xinoe.h_gen == AuXino_INVALID_HGEN);
23634 + err = au_xino_write(sb, bindex, h_ino, &xinoe);
23635 + if (unlikely(err))
23639 + *ino = xinoe.ino;
23643 + mutex_unlock(mtx);
23648 +static int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
23649 + unsigned int d_type, ino_t *ino)
23651 +#ifdef CONFIG_AUFS_SHWH
23652 + return au_ino(sb, bindex, h_ino, d_type, ino);
23658 +#define AuFillVdir_CALLED 1
23659 +#define AuFillVdir_SHWH (1 << 1)
23660 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
23661 +#define au_fset_fillvdir(flags, name) { (flags) |= AuFillVdir_##name; }
23662 +#define au_fclr_fillvdir(flags, name) { (flags) &= ~AuFillVdir_##name; }
23663 +#ifndef CONFIG_AUFS_SHWH
23664 +#undef AuFillVdir_SHWH
23665 +#define AuFillVdir_SHWH 0
23668 +struct fillvdir_arg {
23669 + struct file *file;
23670 + struct au_vdir *vdir;
23671 + struct au_nhash *delist;
23672 + struct au_nhash *whlist;
23673 + aufs_bindex_t bindex;
23674 + unsigned int flags;
23678 +static int fillvdir(void *__arg, const char *__name, int namelen, loff_t offset,
23679 + u64 h_ino, unsigned int d_type)
23681 + struct fillvdir_arg *arg = __arg;
23682 + char *name = (void *)__name;
23683 + aufs_bindex_t bindex, bend;
23684 + struct super_block *sb;
23687 + LKTRTrace("%.*s, namelen %d, i%llu, dt%u\n",
23688 + namelen, name, namelen, (unsigned long long)h_ino, d_type);
23690 + sb = arg->file->f_dentry->d_sb;
23691 + bend = arg->bindex;
23693 + au_fset_fillvdir(arg->flags, CALLED);
23695 + if (namelen <= AUFS_WH_PFX_LEN
23696 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
23697 + for (bindex = 0; bindex < bend; bindex++)
23698 + if (test_known(arg->delist + bindex, name, namelen)
23699 + || au_nhash_test_known_wh(arg->whlist + bindex,
23701 + goto out; /* already exists or whiteouted */
23703 + ino = 1; /* why does gcc warns? */
23704 + arg->err = au_ino(sb, bend, h_ino, d_type, &ino);
23706 + arg->err = append_de(arg->vdir, name, namelen, ino,
23707 + d_type, arg->delist + bend);
23709 + name += AUFS_WH_PFX_LEN;
23710 + namelen -= AUFS_WH_PFX_LEN;
23711 + for (bindex = 0; bindex < bend; bindex++)
23712 + if (au_nhash_test_known_wh(arg->whlist + bend, name,
23714 + goto out; /* already whiteouted */
23716 + ino = 1; /* dummy */
23717 + if (au_ftest_fillvdir(arg->flags, SHWH))
23718 + arg->err = au_wh_ino(sb, bend, h_ino, d_type, &ino);
23720 + arg->err = au_nhash_append_wh
23721 + (arg->whlist + bend, name, namelen, ino, d_type,
23722 + bend, au_ftest_fillvdir(arg->flags, SHWH));
23727 + arg->vdir->vd_jiffy = jiffies;
23729 + AuTraceErr(arg->err);
23733 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
23734 + aufs_bindex_t bstart, aufs_bindex_t bend,
23735 + struct au_nhash *_whlist, struct au_nhash *_delist)
23737 +#ifdef CONFIG_AUFS_SHWH
23739 + struct hlist_head *head;
23740 + struct au_vdir_wh *tpos;
23741 + struct hlist_node *pos, *n;
23743 + struct au_nhash *whlist, *delist;
23744 + struct au_vdir_destr *destr;
23745 + aufs_bindex_t bindex;
23748 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
23751 + o = p = __getname();
23752 + if (unlikely(!p))
23756 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
23757 + p += AUFS_WH_PFX_LEN;
23758 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
23759 + whlist = _whlist + bindex;
23760 + delist = _delist + bindex;
23762 + for (i = 0; i < AuSize_NHASH; i++) {
23763 + head = whlist->heads + i;
23764 + hlist_for_each_entry_safe(tpos, pos, n, head, wh_hash) {
23765 + destr = &tpos->wh_str;
23766 + memcpy(p, destr->name, destr->len);
23767 + err = append_de(vdir, o,
23768 + destr->len + AUFS_WH_PFX_LEN,
23769 + tpos->wh_ino, tpos->wh_type,
23771 + if (unlikely(err))
23787 +static int au_do_read_vdir(struct fillvdir_arg *arg)
23790 + unsigned int mnt_flags;
23792 + aufs_bindex_t bend, bindex, bstart;
23793 + unsigned char dlgt, shwh;
23794 + struct super_block *sb;
23800 + bend = au_fbend(arg->file);
23801 + arg->delist = kmalloc(sizeof(*arg->delist) * (bend + 1), GFP_NOFS);
23802 + if (unlikely(!arg->delist))
23804 + arg->whlist = kmalloc(sizeof(*arg->whlist) * (bend + 1), GFP_NOFS);
23805 + if (unlikely(!arg->whlist))
23808 + for (bindex = 0; bindex <= bend; bindex++) {
23809 + au_nhash_init(arg->delist + bindex);
23810 + au_nhash_init(arg->whlist + bindex);
23813 + sb = arg->file->f_dentry->d_sb;
23814 + mnt_flags = au_mntflags(sb);
23815 + dlgt = !!au_test_dlgt(mnt_flags);
23818 + if (au_opt_test(mnt_flags, SHWH)) {
23820 + au_fset_fillvdir(arg->flags, SHWH);
23822 + bstart = au_fbstart(arg->file);
23823 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
23824 + hf = au_h_fptr(arg->file, bindex);
23828 + offset = vfsub_llseek(hf, 0, SEEK_SET);
23830 + if (unlikely(offset))
23832 + arg->bindex = bindex;
23835 + au_fclr_fillvdir(arg->flags, CALLED);
23837 + err = vfsub_readdir(hf, fillvdir, arg, dlgt);
23840 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
23843 + if (!err && shwh)
23844 + err = au_handle_shwh(sb, arg->vdir, bstart, bend, arg->whlist,
23847 + for (bindex = bstart; bindex <= bend; bindex++) {
23848 + free_dehlist(arg->delist + bindex);
23849 + au_nhash_fin(arg->whlist + bindex);
23851 + kfree(arg->whlist);
23854 + kfree(arg->delist);
23860 +static int read_vdir(struct file *file, int may_read)
23863 + unsigned long expire;
23864 + struct fillvdir_arg arg;
23865 + unsigned char do_read;
23866 + struct dentry *dentry;
23867 + struct inode *inode;
23868 + struct au_vdir *vdir, *allocated;
23869 + struct super_block *sb;
23871 + dentry = file->f_dentry;
23872 + LKTRTrace("%.*s, may %d\n", AuDLNPair(dentry), may_read);
23873 + FiMustWriteLock(file);
23874 + inode = dentry->d_inode;
23875 + IMustLock(inode);
23876 + IiMustWriteLock(inode);
23877 + AuDebugOn(!S_ISDIR(inode->i_mode));
23880 + allocated = NULL;
23882 + sb = inode->i_sb;
23883 + expire = au_sbi(sb)->si_rdcache;
23884 + vdir = au_ivdir(inode);
23886 + AuDebugOn(au_fvdir_cache(file));
23888 + vdir = alloc_vdir();
23889 + err = PTR_ERR(vdir);
23890 + if (IS_ERR(vdir))
23893 + allocated = vdir;
23894 + } else if (may_read
23895 + && (inode->i_version != vdir->vd_version
23896 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
23897 + LKTRTrace("iver %llu, vdver %lu, exp %lu\n",
23898 + (unsigned long long)inode->i_version,
23899 + vdir->vd_version, vdir->vd_jiffy + expire);
23901 + err = reinit_vdir(vdir);
23902 + if (unlikely(err))
23907 + return 0; /* success */
23911 + err = au_do_read_vdir(&arg);
23913 + /* todo: necessary? */
23914 + /* file->f_pos = 0; */
23915 + vdir->vd_version = inode->i_version;
23916 + vdir->vd_last.i = 0;
23917 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
23919 + au_set_ivdir(inode, allocated);
23920 + } else if (allocated)
23921 + au_vdir_free(allocated);
23928 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
23930 + int err, i, rerr, n;
23933 + AuDebugOn(tgt->vd_nblk != 1);
23936 + if (tgt->vd_nblk < src->vd_nblk) {
23937 + au_vdir_deblk_t **p;
23938 + p = au_kzrealloc(tgt->vd_deblk, sizeof(*p) * tgt->vd_nblk,
23939 + sizeof(*p) * src->vd_nblk, GFP_NOFS);
23940 + if (unlikely(!p))
23942 + tgt->vd_deblk = p;
23945 + tgt->vd_nblk = src->vd_nblk;
23946 + n = src->vd_nblk;
23947 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], AuSize_DEBLK);
23948 + /* tgt->vd_last.i = 0; */
23949 + /* tgt->vd_last.p.deblk = tgt->vd_deblk[0]; */
23950 + tgt->vd_version = src->vd_version;
23951 + tgt->vd_jiffy = src->vd_jiffy;
23953 + for (i = 1; i < n; i++) {
23954 + tgt->vd_deblk[i] = kmalloc(AuSize_DEBLK, GFP_NOFS);
23955 + if (tgt->vd_deblk[i])
23956 + memcpy(tgt->vd_deblk[i], src->vd_deblk[i],
23962 + return 0; /* success */
23965 + rerr = reinit_vdir(tgt);
23971 +int au_vdir_init(struct file *file)
23974 + struct dentry *dentry;
23975 + struct inode *inode;
23976 + struct au_vdir *vdir_cache, *allocated;
23978 + dentry = file->f_dentry;
23979 + LKTRTrace("%.*s, pos %lld\n", AuDLNPair(dentry), file->f_pos);
23980 + FiMustWriteLock(file);
23981 + inode = dentry->d_inode;
23982 + IiMustWriteLock(inode);
23983 + AuDebugOn(!S_ISDIR(inode->i_mode));
23985 + err = read_vdir(file, !file->f_pos);
23986 + if (unlikely(err))
23989 + allocated = NULL;
23990 + vdir_cache = au_fvdir_cache(file);
23991 + if (!vdir_cache) {
23992 + vdir_cache = alloc_vdir();
23993 + err = PTR_ERR(vdir_cache);
23994 + if (IS_ERR(vdir_cache))
23996 + allocated = vdir_cache;
23997 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
23998 + err = reinit_vdir(vdir_cache);
23999 + if (unlikely(err))
24002 + return 0; /* success */
24004 + err = copy_vdir(vdir_cache, au_ivdir(inode));
24006 + file->f_version = inode->i_version;
24008 + au_set_fvdir_cache(file, allocated);
24009 + } else if (allocated)
24010 + au_vdir_free(allocated);
24017 +static loff_t calc_offset(struct au_vdir *vdir)
24020 + union au_vdir_deblk_p p;
24022 + p.deblk = vdir->vd_deblk[vdir->vd_last.i];
24023 + offset = vdir->vd_last.p.p - p.p;
24024 + offset += sizeof(*p.deblk) * vdir->vd_last.i;
24028 +/* returns true or false */
24029 +static int seek_vdir(struct file *file)
24032 + struct dentry *dentry;
24033 + struct au_vdir *vdir_cache;
24035 + union au_vdir_deblk_p p, deblk_end;
24037 + dentry = file->f_dentry;
24038 + LKTRTrace("%.*s, pos %lld\n", AuDLNPair(dentry), file->f_pos);
24039 + vdir_cache = au_fvdir_cache(file);
24040 + AuDebugOn(!vdir_cache);
24043 + offset = calc_offset(vdir_cache);
24044 + LKTRTrace("offset %lld\n", offset);
24045 + if (file->f_pos == offset)
24048 + vdir_cache->vd_last.i = 0;
24049 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
24050 + if (!file->f_pos)
24054 + i = file->f_pos / AuSize_DEBLK;
24055 + LKTRTrace("i %d\n", i);
24056 + if (i >= vdir_cache->vd_nblk)
24059 + n = vdir_cache->vd_nblk;
24060 + for (; i < n; i++) {
24061 + p.deblk = vdir_cache->vd_deblk[i];
24062 + deblk_end.deblk = p.deblk + 1;
24064 + offset *= AuSize_DEBLK;
24065 + while (!is_deblk_end(&p, &deblk_end) && offset < file->f_pos) {
24067 + l = calc_size(p.de->de_str.len);
24071 + if (!is_deblk_end(&p, &deblk_end)) {
24073 + vdir_cache->vd_last.i = i;
24074 + vdir_cache->vd_last.p = p;
24081 + AuTraceErr(!valid);
24085 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir)
24088 + struct dentry *dentry;
24089 + struct au_vdir *vdir_cache;
24090 + struct au_vdir_de *de;
24091 + union au_vdir_deblk_p deblk_end;
24093 + dentry = file->f_dentry;
24094 + LKTRTrace("%.*s, pos %lld\n", AuDLNPair(dentry), file->f_pos);
24095 + vdir_cache = au_fvdir_cache(file);
24096 + AuDebugOn(!vdir_cache);
24098 + if (!seek_vdir(file))
24103 + = vdir_cache->vd_deblk[vdir_cache->vd_last.i] + 1;
24104 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
24105 + de = vdir_cache->vd_last.p.de;
24106 + LKTRTrace("%.*s, off%lld, i%lu, dt%d\n",
24107 + de->de_str.len, de->de_str.name,
24108 + file->f_pos, (unsigned long)de->de_ino,
24110 + err = filldir(dirent, de->de_str.name, de->de_str.len,
24111 + file->f_pos, de->de_ino, de->de_type);
24112 + if (unlikely(err)) {
24114 + /* todo: ignore the error caused by udba? */
24115 + /* return err; */
24119 + l = calc_size(de->de_str.len);
24120 + vdir_cache->vd_last.p.p += l;
24121 + file->f_pos += l;
24123 + if (vdir_cache->vd_last.i < vdir_cache->vd_nblk - 1) {
24124 + vdir_cache->vd_last.i++;
24125 + vdir_cache->vd_last.p.deblk
24126 + = vdir_cache->vd_deblk[vdir_cache->vd_last.i];
24127 + file->f_pos = sizeof(*vdir_cache->vd_last.p.deblk)
24128 + * vdir_cache->vd_last.i;
24137 diff -urN linux/fs/aufs/vfsub.c linux-aufs/fs/aufs/vfsub.c
24138 --- linux/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
24139 +++ linux-aufs/fs/aufs/vfsub.c 2009-03-12 16:18:04.000000000 +0100
24142 + * Copyright (C) 2005-2009 Junjiro Okajima
24144 + * This program, aufs is free software; you can redistribute it and/or modify
24145 + * it under the terms of the GNU General Public License as published by
24146 + * the Free Software Foundation; either version 2 of the License, or
24147 + * (at your option) any later version.
24149 + * This program is distributed in the hope that it will be useful,
24150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24152 + * GNU General Public License for more details.
24154 + * You should have received a copy of the GNU General Public License
24155 + * along with this program; if not, write to the Free Software
24156 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24160 + * sub-routines for VFS
24165 +#include <linux/uaccess.h>
24168 +/* ---------------------------------------------------------------------- */
24170 +void vfsub_args_init(struct vfsub_args *vargs, struct au_hin_ignore *ign,
24171 + int dlgt, int force_unlink)
24173 + do_vfsub_args_reinit(vargs, ign);
24174 + vargs->flags = 0;
24176 + vfsub_fset(vargs->flags, DLGT);
24177 + if (force_unlink)
24178 + vfsub_fset(vargs->flags, FORCE_UNLINK);
24181 +/* ---------------------------------------------------------------------- */
24183 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
24185 + struct file *err;
24187 + LKTRTrace("%s\n", path);
24190 + err = filp_open(path, oflags, mode);
24192 + if (!IS_ERR(err))
24193 + au_update_fuse_h_inode(err->f_vfsmnt, err->f_dentry); /*ignore*/
24197 +int vfsub_path_lookup(const char *name, unsigned int flags,
24198 + struct nameidata *nd)
24202 + LKTRTrace("%s\n", name);
24204 + /* lockdep_off(); */
24205 + err = path_lookup(name, flags, nd);
24206 + /* lockdep_on(); */
24208 + au_update_fuse_h_inode(nd->path.mnt, nd->path.dentry);
24213 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
24216 + struct dentry *d;
24218 + LKTRTrace("%.*s/%.*s\n", AuDLNPair(parent), len, name);
24219 + IMustLock(parent->d_inode);
24221 + d = lookup_one_len(name, parent, len);
24223 + au_update_fuse_h_inode(NULL, d); /*ignore*/
24227 +#ifdef CONFIG_AUFS_LHASH_PATCH
24228 +struct dentry *vfsub__lookup_hash(struct qstr *name, struct dentry *parent,
24229 + struct nameidata *nd)
24231 + struct dentry *d;
24233 + LKTRTrace("%.*s/%.*s, nd %d\n",
24234 + AuDLNPair(parent), AuLNPair(name), !!nd);
24236 + LKTRTrace("nd{0x%x}\n", nd->flags);
24237 + IMustLock(parent->d_inode);
24239 + d = __lookup_hash(name, parent, nd);
24241 + au_update_fuse_h_inode(NULL, d); /*ignore*/
24246 +/* ---------------------------------------------------------------------- */
24248 +int do_vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
24249 + struct nameidata *nd)
24252 + struct vfsmount *mnt;
24254 + LKTRTrace("i%lu, %.*s, 0x%x\n", dir->i_ino, AuDLNPair(dentry), mode);
24257 + err = vfs_create(dir, dentry, mode, nd);
24261 + mnt = nd->path.mnt;
24262 + /* dir inode is locked */
24263 + au_update_fuse_h_inode(mnt, dentry->d_parent); /*ignore*/
24264 + au_update_fuse_h_inode(mnt, dentry); /*ignore*/
24269 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
24270 +#define VfsubSymlinkArgs dir, dentry, symname
24272 +#define VfsubSymlinkArgs dir, dentry, symname, mode
24275 +int do_vfsub_symlink(struct inode *dir, struct dentry *dentry,
24276 + const char *symname, int mode)
24280 + LKTRTrace("i%lu, %.*s, %s, 0x%x\n",
24281 + dir->i_ino, AuDLNPair(dentry), symname, mode);
24284 + err = vfs_symlink(VfsubSymlinkArgs);
24286 + /* dir inode is locked */
24287 + au_update_fuse_h_inode(NULL, dentry->d_parent); /*ignore*/
24288 + au_update_fuse_h_inode(NULL, dentry); /*ignore*/
24293 +int do_vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode,
24298 + LKTRTrace("i%lu, %.*s, 0x%x\n", dir->i_ino, AuDLNPair(dentry), mode);
24301 + err = vfs_mknod(dir, dentry, mode, dev);
24303 + /* dir inode is locked */
24304 + au_update_fuse_h_inode(NULL, dentry->d_parent); /*ignore*/
24305 + au_update_fuse_h_inode(NULL, dentry); /*ignore*/
24310 +int do_vfsub_link(struct dentry *src_dentry, struct inode *dir,
24311 + struct dentry *dentry)
24315 + LKTRTrace("%.*s, i%lu, %.*s\n",
24316 + AuDLNPair(src_dentry), dir->i_ino, AuDLNPair(dentry));
24320 + err = vfs_link(src_dentry, dir, dentry);
24323 + LKTRTrace("src_i %p, dst_i %p\n",
24324 + src_dentry->d_inode, dentry->d_inode);
24325 + /* fuse has different memory inode for the same inumber */
24326 + au_update_fuse_h_inode(NULL, src_dentry); /*ignore*/
24327 + /* dir inode is locked */
24328 + au_update_fuse_h_inode(NULL, dentry->d_parent); /*ignore*/
24329 + au_update_fuse_h_inode(NULL, dentry); /*ignore*/
24334 +int do_vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
24335 + struct inode *dir, struct dentry *dentry)
24339 + LKTRTrace("i%lu, %.*s, i%lu, %.*s\n",
24340 + src_dir->i_ino, AuDLNPair(src_dentry),
24341 + dir->i_ino, AuDLNPair(dentry));
24343 + IMustLock(src_dir);
24344 + AuDebugOn(src_dir != dir && !vfsub_is_rename_mutex_locked(dir->i_sb));
24347 + err = vfs_rename(src_dir, src_dentry, dir, dentry);
24350 + /* dir inode is locked */
24351 + au_update_fuse_h_inode(NULL, dentry->d_parent); /*ignore*/
24352 + au_update_fuse_h_inode(NULL, src_dentry->d_parent); /*ignore*/
24353 + au_update_fuse_h_inode(NULL, src_dentry); /*ignore*/
24358 +int do_vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode)
24362 + LKTRTrace("i%lu, %.*s, 0x%x\n", dir->i_ino, AuDLNPair(dentry), mode);
24365 + err = vfs_mkdir(dir, dentry, mode);
24367 + /* dir inode is locked */
24368 + au_update_fuse_h_inode(NULL, dentry->d_parent); /*ignore*/
24369 + au_update_fuse_h_inode(NULL, dentry); /*ignore*/
24374 +int do_vfsub_rmdir(struct inode *dir, struct dentry *dentry)
24378 + LKTRTrace("i%lu, %.*s\n", dir->i_ino, AuDLNPair(dentry));
24382 + err = vfs_rmdir(dir, dentry);
24384 + /* dir inode is locked */
24386 + au_update_fuse_h_inode(NULL, dentry->d_parent); /*ignore*/
24390 +int do_vfsub_unlink(struct inode *dir, struct dentry *dentry)
24394 + LKTRTrace("i%lu, %.*s\n", dir->i_ino, AuDLNPair(dentry));
24397 + /* vfs_unlink() locks inode */
24399 + err = vfs_unlink(dir, dentry);
24401 + /* dir inode is locked */
24403 + au_update_fuse_h_inode(NULL, dentry->d_parent); /*ignore*/
24407 +/* ---------------------------------------------------------------------- */
24409 +ssize_t do_vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
24414 + LKTRTrace("%.*s, cnt %zu, pos %lld\n",
24415 + AuDLNPair(file->f_dentry), count, *ppos);
24417 + /* todo: always off, regardless nfs branch? */
24418 + au_br_nfs_lockdep_off(file->f_vfsmnt->mnt_sb);
24419 + err = vfs_read(file, ubuf, count, ppos);
24420 + au_br_nfs_lockdep_on(file->f_vfsmnt->mnt_sb);
24422 + au_update_fuse_h_inode(file->f_vfsmnt, file->f_dentry);
24427 +/* todo: kernel_read()? */
24428 +ssize_t do_vfsub_read_k(struct file *file, void *kbuf, size_t count,
24432 + mm_segment_t oldfs;
24434 + oldfs = get_fs();
24435 + set_fs(KERNEL_DS);
24436 + err = do_vfsub_read_u(file, (char __user *)kbuf, count, ppos);
24441 +ssize_t do_vfsub_write_u(struct file *file, const char __user *ubuf,
24442 + size_t count, loff_t *ppos)
24446 + LKTRTrace("%.*s, cnt %zu, pos %lld\n",
24447 + AuDLNPair(file->f_dentry), count, *ppos);
24450 + err = vfs_write(file, ubuf, count, ppos);
24453 + au_update_fuse_h_inode(file->f_vfsmnt, file->f_dentry);
24458 +ssize_t do_vfsub_write_k(struct file *file, void *kbuf, size_t count,
24462 + mm_segment_t oldfs;
24464 + oldfs = get_fs();
24465 + set_fs(KERNEL_DS);
24466 + err = do_vfsub_write_u(file, (const char __user *)kbuf, count, ppos);
24471 +int do_vfsub_readdir(struct file *file, filldir_t filldir, void *arg)
24475 + LKTRTrace("%.*s\n", AuDLNPair(file->f_dentry));
24478 + err = vfs_readdir(file, filldir, arg);
24481 + au_update_fuse_h_inode(file->f_vfsmnt, file->f_dentry);
24486 +#ifdef CONFIG_AUFS_SPLICE_PATCH
24487 +long do_vfsub_splice_to(struct file *in, loff_t *ppos,
24488 + struct pipe_inode_info *pipe, size_t len,
24489 + unsigned int flags)
24493 + LKTRTrace("%.*s, pos %lld, len %zu, 0x%x\n",
24494 + AuDLNPair(in->f_dentry), *ppos, len, flags);
24497 + err = vfs_splice_to(in, ppos, pipe, len, flags);
24500 + au_update_fuse_h_inode(in->f_vfsmnt, in->f_dentry); /*ignore*/
24504 +long do_vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
24505 + loff_t *ppos, size_t len, unsigned int flags)
24509 + LKTRTrace("%.*s, pos %lld, len %zu, 0x%x\n",
24510 + AuDLNPair(out->f_dentry), *ppos, len, flags);
24513 + err = vfs_splice_from(pipe, out, ppos, len, flags);
24516 + au_update_fuse_h_inode(out->f_vfsmnt, out->f_dentry); /*ignore*/
24521 +/* ---------------------------------------------------------------------- */
24523 +struct au_vfsub_mkdir_args {
24525 + struct inode *dir;
24526 + struct dentry *dentry;
24528 + struct vfsub_args *vargs;
24531 +static void au_call_vfsub_mkdir(void *args)
24533 + struct au_vfsub_mkdir_args *a = args;
24534 + *a->errp = vfsub_mkdir(a->dir, a->dentry, a->mode, a->vargs);
24537 +int vfsub_sio_mkdir(struct au_hinode *hdir, struct dentry *dentry, int mode,
24540 + int err, do_sio, wkq_err;
24541 + struct inode *dir = hdir->hi_inode;
24542 + struct au_hin_ignore ign;
24543 + struct vfsub_args vargs;
24545 + LKTRTrace("i%lu, %.*s\n", dir->i_ino, AuDLNPair(dentry));
24547 + vfsub_args_init(&vargs, &ign, dlgt, /*force_unlink*/0);
24548 + vfsub_ign_hinode(&vargs, IN_CREATE, hdir);
24549 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE, dlgt);
24551 + err = vfsub_mkdir(dir, dentry, mode, &vargs);
24553 + struct au_vfsub_mkdir_args args = {
24556 + .dentry = dentry,
24560 + vfsub_fclr(vargs.flags, DLGT);
24561 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args, /*dlgt*/0);
24562 + if (unlikely(wkq_err))
24570 +struct au_vfsub_rmdir_args {
24572 + struct inode *dir;
24573 + struct dentry *dentry;
24574 + struct vfsub_args *vargs;
24577 +static void au_call_vfsub_rmdir(void *args)
24579 + struct au_vfsub_rmdir_args *a = args;
24580 + *a->errp = vfsub_rmdir(a->dir, a->dentry, a->vargs);
24583 +int vfsub_sio_rmdir(struct au_hinode *hdir, struct dentry *dentry, int dlgt)
24585 + int err, do_sio, wkq_err;
24586 + struct inode *dir = hdir->hi_inode;
24587 + struct au_hin_ignore ign;
24588 + struct vfsub_args vargs;
24590 + LKTRTrace("i%lu, %.*s\n", dir->i_ino, AuDLNPair(dentry));
24592 + vfsub_args_init(&vargs, &ign, dlgt, /*force_unlink*/0);
24593 + vfsub_ign_hinode(&vargs, IN_DELETE, hdir);
24594 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE, dlgt);
24596 + err = vfsub_rmdir(dir, dentry, &vargs);
24598 + struct au_vfsub_rmdir_args args = {
24601 + .dentry = dentry,
24604 + vfsub_fclr(vargs.flags, DLGT);
24605 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args, /*dlgt*/0);
24606 + if (unlikely(wkq_err))
24614 +/* ---------------------------------------------------------------------- */
24616 +struct notify_change_args {
24618 + struct dentry *h_dentry;
24619 + struct iattr *ia;
24620 + struct vfsub_args *vargs;
24623 +static void call_notify_change(void *args)
24625 + struct notify_change_args *a = args;
24626 + struct inode *h_inode;
24628 + LKTRTrace("%.*s, ia_valid 0x%x\n",
24629 + AuDLNPair(a->h_dentry), a->ia->ia_valid);
24630 + h_inode = a->h_dentry->d_inode;
24631 + IMustLock(h_inode);
24633 + *a->errp = -EPERM;
24634 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
24635 + vfsub_ignore(a->vargs);
24637 + *a->errp = notify_change(a->h_dentry, a->ia);
24640 + au_update_fuse_h_inode(NULL, a->h_dentry); /*ignore*/
24642 + vfsub_unignore(a->vargs);
24643 + au_dbg_hin_list(a->vargs);
24645 + AuTraceErr(*a->errp);
24648 +#ifdef CONFIG_AUFS_DLGT
24649 +static void vfsub_notify_change_dlgt(struct notify_change_args *args,
24650 + unsigned int flags)
24652 + if (!vfsub_ftest(flags, DLGT))
24653 + call_notify_change(args);
24656 + wkq_err = au_wkq_wait(call_notify_change, args, /*dlgt*/1);
24657 + if (unlikely(wkq_err))
24658 + *args->errp = wkq_err;
24662 +static void vfsub_notify_change_dlgt(struct notify_change_args *args,
24663 + unsigned int flags)
24665 + call_notify_change(args);
24669 +int vfsub_notify_change(struct dentry *dentry, struct iattr *ia,
24670 + struct vfsub_args *vargs)
24673 + struct notify_change_args args = {
24675 + .h_dentry = dentry,
24680 + vfsub_notify_change_dlgt(&args, vargs->flags);
24686 +int vfsub_sio_notify_change(struct au_hinode *hdir, struct dentry *dentry,
24687 + struct iattr *ia)
24689 + int err, wkq_err;
24690 + struct au_hin_ignore ign;
24691 + struct vfsub_args vargs;
24693 + struct notify_change_args args = {
24695 + .h_dentry = dentry,
24700 + LKTRTrace("%.*s, 0x%x\n", AuDLNPair(dentry), ia->ia_valid);
24702 + vfsub_args_init(&vargs, &ign, /*dlgt*/0, /*force_unlink*/0);
24703 + events = vfsub_events_notify_change(ia);
24705 + vfsub_ign_hinode(&vargs, events, hdir);
24706 + wkq_err = au_wkq_wait(call_notify_change, &args, /*dlgt*/0);
24707 + if (unlikely(wkq_err))
24714 +/* ---------------------------------------------------------------------- */
24716 +struct unlink_args {
24718 + struct inode *dir;
24719 + struct dentry *dentry;
24720 + struct vfsub_args *vargs;
24723 +static void call_unlink(void *args)
24725 + struct unlink_args *a = args;
24726 + struct inode *h_inode;
24727 + const int stop_sillyrename = (au_test_nfs(a->dentry->d_sb)
24728 + && atomic_read(&a->dentry->d_count) == 1);
24730 + LKTRTrace("%.*s, stop_silly %d, cnt %d\n",
24731 + AuDLNPair(a->dentry), stop_sillyrename,
24732 + atomic_read(&a->dentry->d_count));
24734 + if (!stop_sillyrename)
24736 + h_inode = a->dentry->d_inode;
24738 + atomic_inc_return(&h_inode->i_count);
24739 + vfsub_ignore(a->vargs);
24740 + *a->errp = do_vfsub_unlink(a->dir, a->dentry);
24741 + if (unlikely(*a->errp || (a->dentry->d_flags & DCACHE_NFSFS_RENAMED)))
24742 + vfsub_unignore(a->vargs);
24743 + au_dbg_hin_list(a->vargs);
24744 + if (!stop_sillyrename)
24749 + AuTraceErr(*a->errp);
24753 + * @dir: must be locked.
24754 + * @dentry: target dentry.
24756 +int vfsub_unlink(struct inode *dir, struct dentry *dentry,
24757 + struct vfsub_args *vargs)
24760 + struct unlink_args args = {
24763 + .dentry = dentry,
24767 + if (!vfsub_ftest(vargs->flags, DLGT)
24768 + && !vfsub_ftest(vargs->flags, FORCE_UNLINK))
24769 + call_unlink(&args);
24772 + wkq_err = au_wkq_wait(call_unlink, &args,
24773 + vfsub_ftest(vargs->flags, DLGT));
24774 + if (unlikely(wkq_err))
24781 +/* ---------------------------------------------------------------------- */
24783 +struct statfs_args {
24786 + struct kstatfs *buf;
24789 +static void call_statfs(void *args)
24791 + struct statfs_args *a = args;
24792 + *a->errp = vfs_statfs(a->arg, a->buf);
24795 +#ifdef CONFIG_AUFS_DLGT
24796 +static void vfsub_statfs_dlgt(struct statfs_args *args, int dlgt)
24799 + call_statfs(args);
24802 + wkq_err = au_wkq_wait(call_statfs, args, /*dlgt*/1);
24803 + if (unlikely(wkq_err))
24804 + *args->errp = wkq_err;
24808 +static void vfsub_statfs_dlgt(struct statfs_args *args, int dlgt)
24810 + call_statfs(args);
24814 +int vfsub_statfs(void *arg, struct kstatfs *buf, int dlgt)
24817 + struct statfs_args args = {
24823 + vfsub_statfs_dlgt(&args, dlgt);
24827 diff -urN linux/fs/aufs/vfsub.h linux-aufs/fs/aufs/vfsub.h
24828 --- linux/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
24829 +++ linux-aufs/fs/aufs/vfsub.h 2009-03-12 16:18:04.000000000 +0100
24832 + * Copyright (C) 2005-2009 Junjiro Okajima
24834 + * This program, aufs is free software; you can redistribute it and/or modify
24835 + * it under the terms of the GNU General Public License as published by
24836 + * the Free Software Foundation; either version 2 of the License, or
24837 + * (at your option) any later version.
24839 + * This program is distributed in the hope that it will be useful,
24840 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24841 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24842 + * GNU General Public License for more details.
24844 + * You should have received a copy of the GNU General Public License
24845 + * along with this program; if not, write to the Free Software
24846 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24850 + * sub-routines for VFS
24855 +#ifndef __AUFS_VFSUB_H__
24856 +#define __AUFS_VFSUB_H__
24860 +#include <linux/fs.h>
24861 +#include <linux/fs_stack.h>
24862 +#include <linux/inotify.h>
24863 +#include <linux/namei.h>
24864 +#include <linux/security.h>
24865 +#include <linux/splice.h>
24867 +/* ---------------------------------------------------------------------- */
24870 +#define Vfsub_DLGT 1 /* operation with delegation */
24871 +#define Vfsub_FORCE_UNLINK (1 << 1) /* force unlinking */
24872 +#define vfsub_ftest(flags, name) ((flags) & Vfsub_##name)
24873 +#define vfsub_fset(flags, name) { (flags) |= Vfsub_##name; }
24874 +#define vfsub_fclr(flags, name) { (flags) &= ~Vfsub_##name; }
24875 +#ifndef CONFIG_AUFS_DLGT
24877 +#define Vfsub_DLGT 0
24880 +struct au_hin_ignore;
24881 +struct vfsub_args {
24882 +#ifdef CONFIG_AUFS_HINOTIFY
24883 + /* inotify events to be ignored */
24885 + struct au_hin_ignore *ignore;
24888 + unsigned int flags;
24892 +#ifdef CONFIG_AUFS_HINOTIFY
24894 +void do_vfsub_args_reinit(struct vfsub_args *vargs, struct au_hin_ignore *ign)
24896 + vargs->nignore = 0;
24897 + vargs->ignore = ign;
24900 +static inline void vfsub_args_reinit(struct vfsub_args *vargs)
24902 + vargs->nignore = 0;
24905 +__u32 vfsub_events_notify_change(struct iattr *ia);
24906 +void vfsub_ign_hinode(struct vfsub_args *vargs, __u32 events,
24907 + struct au_hinode *hinode);
24908 +void vfsub_ignore(struct vfsub_args *vargs);
24909 +void vfsub_unignore(struct vfsub_args *vargs);
24912 +void do_vfsub_args_reinit(struct vfsub_args *vargs, struct au_hin_ignore *ign)
24917 +static inline void vfsub_args_reinit(struct vfsub_args *vargs)
24922 +static inline __u32 vfsub_events_notify_change(struct iattr *ia)
24927 +static inline void vfsub_ign_hinode(struct vfsub_args *vargs, __u32 events,
24928 + struct au_hinode *hinode)
24933 +static inline void vfsub_ignore(struct vfsub_args *vargs)
24938 +static inline void vfsub_unignore(struct vfsub_args *vargs)
24942 +#endif /* CONFIG_AUFS_HINOTIFY */
24944 +void vfsub_args_init(struct vfsub_args *vargs, struct au_hin_ignore *ign,
24945 + int dlgt, int force_unlink);
24947 +/* ---------------------------------------------------------------------- */
24949 +/* inotify_inode_watched() is not exported */
24950 +static inline int au_test_inotify(struct inode *inode)
24952 +#ifdef CONFIG_INOTIFY
24953 + return !list_empty(&inode->inotify_watches);
24958 +/* ---------------------------------------------------------------------- */
24960 +/* lock subclass for hidden inode */
24961 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
24962 +/* reduce? gave up. */
24964 + AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
24965 + AuLsc_I_PARENT, /* hidden inode, parent first */
24966 + AuLsc_I_PARENT2, /* copyup dirs */
24967 + AuLsc_I_PARENT3, /* rename with hinotify */
24968 + AuLsc_I_PARENT4, /* ditto */
24974 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
24976 +static inline void vfsub_lock_rename_mutex(struct super_block *sb)
24979 + mutex_lock(&sb->s_vfs_rename_mutex);
24983 +static inline void vfsub_unlock_rename_mutex(struct super_block *sb)
24986 + mutex_unlock(&sb->s_vfs_rename_mutex);
24990 +static inline int vfsub_is_rename_mutex_locked(struct super_block *sb)
24995 + res = mutex_is_locked(&sb->s_vfs_rename_mutex);
25002 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct dentry *d2)
25004 + struct dentry *d;
25007 + d = lock_rename(d1, d2);
25012 +static inline void vfsub_unlock_rename(struct dentry *d1, struct dentry *d2)
25015 + unlock_rename(d1, d2);
25019 +static inline int au_verify_parent(struct dentry *dentry, struct inode *dir)
25022 + return /* !dir->i_nlink || */ dentry->d_parent->d_inode != dir;
25025 +/* ---------------------------------------------------------------------- */
25027 +#ifdef CONFIG_AUFS_WORKAROUND_FUSE
25029 +int au_update_fuse_h_inode(struct vfsmount *h_mnt, struct dentry *h_dentry);
25032 +int au_update_fuse_h_inode(struct vfsmount *h_mnt, struct dentry *h_dentry)
25038 +#ifdef CONFIG_AUFS_BR_XFS
25040 +dev_t au_h_rdev(struct inode *h_inode, struct vfsmount *h_mnt,
25041 + struct dentry *h_dentry);
25044 +dev_t au_h_rdev(struct inode *h_inode, struct vfsmount *h_mnt,
25045 + struct dentry *h_dentry)
25047 + return h_inode->i_rdev;
25051 +/* simple abstractions, for future use */
25053 +int do_vfsub_permission(struct inode *inode, int mask, struct nameidata *nd)
25055 + LKTRTrace("i%lu, mask 0x%x, nd %d\n", inode->i_ino, mask, !!nd);
25056 + IMustLock(inode);
25057 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
25058 + return inode_permission(inode, mask);
25060 + return permission(inode, mask, nd);
25065 +int vfsub_security_inode_permission(struct inode *inode, int mask,
25066 + struct nameidata *nd)
25068 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
25069 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC | MAY_APPEND;
25070 + return security_inode_permission(inode, mask);
25072 + return security_inode_permission(inode, mask, nd);
25076 +/* ---------------------------------------------------------------------- */
25078 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
25079 +int vfsub_path_lookup(const char *name, unsigned int flags,
25080 + struct nameidata *nd);
25081 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
25084 +#ifdef CONFIG_AUFS_LHASH_PATCH
25085 +struct dentry *vfsub__lookup_hash(struct qstr *name, struct dentry *parent,
25086 + struct nameidata *nd);
25089 +/* ---------------------------------------------------------------------- */
25091 +int do_vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
25092 + struct nameidata *nd);
25093 +int do_vfsub_symlink(struct inode *dir, struct dentry *dentry,
25094 + const char *symname, int mode);
25095 +int do_vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode,
25097 +int do_vfsub_link(struct dentry *src_dentry, struct inode *dir,
25098 + struct dentry *dentry);
25099 +int do_vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
25100 + struct inode *dir, struct dentry *dentry);
25101 +int do_vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode);
25102 +int do_vfsub_rmdir(struct inode *dir, struct dentry *dentry);
25103 +int do_vfsub_unlink(struct inode *dir, struct dentry *dentry);
25105 +/* ---------------------------------------------------------------------- */
25107 +ssize_t do_vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
25109 +/* todo: kernel_read()? */
25110 +ssize_t do_vfsub_read_k(struct file *file, void *kbuf, size_t count,
25112 +ssize_t do_vfsub_write_u(struct file *file, const char __user *ubuf,
25113 + size_t count, loff_t *ppos);
25114 +ssize_t do_vfsub_write_k(struct file *file, void *kbuf, size_t count,
25116 +int do_vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
25118 +/* ---------------------------------------------------------------------- */
25120 +#ifndef CONFIG_AUFS_UNIONFS22_PATCH
25121 +static inline void vfsub_copy_inode_size(struct inode *inode,
25122 + struct inode *h_inode)
25124 + spin_lock(&inode->i_lock);
25125 + fsstack_copy_inode_size(inode, h_inode);
25126 + spin_unlock(&inode->i_lock);
25129 +static inline void vfsub_copy_inode_size(struct inode *inode,
25130 + struct inode *h_inode)
25132 + fsstack_copy_inode_size(inode, h_inode);
25136 +#ifndef CONFIG_AUFS_UNIONFS23_PATCH
25137 +#define vfs_splice_to do_splice_to
25138 +#define vfs_splice_from do_splice_from
25141 +#ifdef CONFIG_AUFS_SPLICE_PATCH
25142 +long do_vfsub_splice_to(struct file *in, loff_t *ppos,
25143 + struct pipe_inode_info *pipe, size_t len,
25144 + unsigned int flags);
25145 +long do_vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
25146 + loff_t *ppos, size_t len, unsigned int flags);
25149 +long do_vfsub_splice_to(struct file *in, loff_t *ppos,
25150 + struct pipe_inode_info *pipe, size_t len,
25151 + unsigned int flags)
25157 +long do_vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
25158 + loff_t *ppos, size_t len, unsigned int flags)
25162 +#endif /* CONFIG_AUFS_SPLICE_PATCH */
25164 +/* ---------------------------------------------------------------------- */
25166 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
25170 + LKTRTrace("%.*s\n", AuDLNPair(file->f_dentry));
25173 + err = vfs_llseek(file, offset, origin);
25178 +static inline int do_vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry,
25179 + struct kstat *st)
25181 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
25182 + return vfs_getattr(mnt, dentry, st);
25185 +/* ---------------------------------------------------------------------- */
25187 +#ifdef CONFIG_AUFS_HIN_OR_DLGT
25188 +/* hin_or_dlgt.c */
25189 +int vfsub_permission(struct inode *inode, int mask, struct nameidata *nd,
25192 +int vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
25193 + struct nameidata *nd, struct vfsub_args *vargs);
25194 +int vfsub_symlink(struct inode *dir, struct dentry *dentry, const char *symname,
25195 + int mode, struct vfsub_args *vargs);
25196 +int vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev,
25197 + struct vfsub_args *vargs);
25198 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
25199 + struct dentry *dentry, struct vfsub_args *vargs);
25200 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
25201 + struct inode *dir, struct dentry *dentry,
25202 + struct vfsub_args *vargs);
25203 +int vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode,
25204 + struct vfsub_args *vargs);
25205 +int vfsub_rmdir(struct inode *dir, struct dentry *dentry,
25206 + struct vfsub_args *vargs);
25208 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
25209 + loff_t *ppos, int dlgt);
25210 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
25212 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
25213 + loff_t *ppos, struct vfsub_args *vargs);
25214 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
25215 + struct vfsub_args *vargs);
25216 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg, int dlgt);
25217 +long vfsub_splice_to(struct file *in, loff_t *ppos,
25218 + struct pipe_inode_info *pipe, size_t len,
25219 + unsigned int flags, int dlgt);
25220 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
25221 + loff_t *ppos, size_t len, unsigned int flags,
25222 + struct vfsub_args *vargs);
25224 +int vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st,
25229 +int vfsub_permission(struct inode *inode, int mask, struct nameidata *nd,
25232 + return do_vfsub_permission(inode, mask, nd);
25236 +int vfsub_create(struct inode *dir, struct dentry *dentry, int mode,
25237 + struct nameidata *nd, struct vfsub_args *vargs)
25239 + return do_vfsub_create(dir, dentry, mode, nd);
25243 +int vfsub_symlink(struct inode *dir, struct dentry *dentry, const char *symname,
25244 + int mode, struct vfsub_args *vargs)
25246 + return do_vfsub_symlink(dir, dentry, symname, mode);
25250 +int vfsub_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev,
25251 + struct vfsub_args *vargs)
25253 + return do_vfsub_mknod(dir, dentry, mode, dev);
25257 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
25258 + struct dentry *dentry, struct vfsub_args *vargs)
25260 + return do_vfsub_link(src_dentry, dir, dentry);
25264 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
25265 + struct inode *dir, struct dentry *dentry,
25266 + struct vfsub_args *vargs)
25268 + return do_vfsub_rename(src_dir, src_dentry, dir, dentry);
25272 +int vfsub_mkdir(struct inode *dir, struct dentry *dentry, int mode,
25273 + struct vfsub_args *vargs)
25275 + return do_vfsub_mkdir(dir, dentry, mode);
25279 +int vfsub_rmdir(struct inode *dir, struct dentry *dentry,
25280 + struct vfsub_args *vargs)
25282 + return do_vfsub_rmdir(dir, dentry);
25286 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
25287 + loff_t *ppos, int dlgt)
25289 + return do_vfsub_read_u(file, ubuf, count, ppos);
25293 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
25296 + return do_vfsub_read_k(file, kbuf, count, ppos);
25300 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
25301 + loff_t *ppos, struct vfsub_args *vargs)
25303 + return do_vfsub_write_u(file, ubuf, count, ppos);
25307 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos,
25308 + struct vfsub_args *vargs)
25310 + return do_vfsub_write_k(file, kbuf, count, ppos);
25314 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg, int dlgt)
25316 + return do_vfsub_readdir(file, filldir, arg);
25320 +long vfsub_splice_to(struct file *in, loff_t *ppos,
25321 + struct pipe_inode_info *pipe, size_t len,
25322 + unsigned int flags, int dlgt)
25324 + return do_vfsub_splice_to(in, ppos, pipe, len, flags);
25328 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
25329 + loff_t *ppos, size_t len, unsigned int flags,
25330 + struct vfsub_args *vargs)
25332 + return do_vfsub_splice_from(pipe, out, ppos, len, flags);
25336 +int vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st,
25339 + return do_vfsub_getattr(mnt, dentry, st);
25341 +#endif /* HIN_OR_DLGT */
25343 +/* ---------------------------------------------------------------------- */
25345 +int vfsub_sio_mkdir(struct au_hinode *hdir, struct dentry *dentry, int mode,
25347 +int vfsub_sio_rmdir(struct au_hinode *hdir, struct dentry *dentry, int dlgt);
25348 +int vfsub_sio_notify_change(struct au_hinode *hdir, struct dentry *dentry,
25349 + struct iattr *ia);
25351 +/* ---------------------------------------------------------------------- */
25353 +int vfsub_notify_change(struct dentry *dentry, struct iattr *ia,
25354 + struct vfsub_args *vargs);
25355 +int vfsub_unlink(struct inode *dir, struct dentry *dentry,
25356 + struct vfsub_args *vargs);
25357 +int vfsub_statfs(void *arg, struct kstatfs *buf, int dlgt);
25359 +#endif /* __KERNEL__ */
25360 +#endif /* __AUFS_VFSUB_H__ */
25361 diff -urN linux/fs/aufs/wbr_policy.c linux-aufs/fs/aufs/wbr_policy.c
25362 --- linux/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
25363 +++ linux-aufs/fs/aufs/wbr_policy.c 2009-03-12 16:18:04.000000000 +0100
25366 + * Copyright (C) 2005-2009 Junjiro Okajima
25368 + * This program, aufs is free software; you can redistribute it and/or modify
25369 + * it under the terms of the GNU General Public License as published by
25370 + * the Free Software Foundation; either version 2 of the License, or
25371 + * (at your option) any later version.
25373 + * This program is distributed in the hope that it will be useful,
25374 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25375 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25376 + * GNU General Public License for more details.
25378 + * You should have received a copy of the GNU General Public License
25379 + * along with this program; if not, write to the Free Software
25380 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25384 + * policies for selecting one among multiple writable branches
25389 +#include <linux/statfs.h>
25392 +static int au_cpdown_attr(struct au_hinode *hdir, struct dentry *h_dst,
25393 + struct dentry *h_src)
25397 + struct inode *h_idst, *h_isrc;
25399 + LKTRTrace("%.*s\n", AuDLNPair(h_dst));
25400 + h_idst = h_dst->d_inode;
25401 + /* todo? IMustLock(h_idst); */
25402 + h_isrc = h_src->d_inode;
25403 + /* todo? IMustLock(h_isrc); */
25405 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
25406 + ia.ia_mode = h_isrc->i_mode;
25407 + ia.ia_uid = h_isrc->i_uid;
25408 + ia.ia_gid = h_isrc->i_gid;
25409 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
25410 + au_cpup_attr_flags(h_idst, h_isrc);
25411 + err = vfsub_sio_notify_change(hdir, h_dst, &ia);
25413 + /* is this nfs only? */
25414 + if (!err && sbits && au_test_nfs(h_dst->d_sb)) {
25415 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
25416 + ia.ia_mode = h_isrc->i_mode;
25417 + err = vfsub_sio_notify_change(hdir, h_dst, &ia);
25424 +struct au_cpdown_dir_args {
25425 + struct dentry *parent;
25426 + unsigned int parent_opq; /* bit-flags */
25429 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
25430 + struct dentry *h_parent, void *arg)
25433 + struct au_cpdown_dir_args *args = arg;
25434 + aufs_bindex_t bend, bopq, bstart;
25435 + unsigned char parent_opq, whed, dlgt, do_opq, made_dir, diropq;
25436 + struct dentry *h_dentry, *opq_dentry, *wh_dentry, *parent;
25437 + struct inode *h_dir, *h_inode, *inode, *dir;
25439 + LKTRTrace("%.*s, b%d\n", AuDLNPair(dentry), bdst);
25440 + bstart = au_dbstart(dentry);
25441 + AuDebugOn(bstart <= bdst
25442 + && bdst <= au_dbend(dentry)
25443 + && au_h_dptr(dentry, bdst));
25444 + AuDebugOn(!h_parent);
25445 + /* todo: safe? */
25446 + parent = dget_parent(dentry);
25447 + dir = parent->d_inode;
25449 + h_dir = h_parent->d_inode;
25450 + AuDebugOn(!h_dir);
25451 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
25452 + IMustLock(h_dir);
25454 + err = au_lkup_neg(dentry, bdst);
25455 + if (unlikely(err < 0))
25457 + h_dentry = au_h_dptr(dentry, bdst);
25458 + dlgt = !!au_test_dlgt(au_mntflags(dentry->d_sb));
25459 + err = vfsub_sio_mkdir(au_hi(dir, bdst), h_dentry,
25460 + S_IRWXU | S_IRUGO | S_IXUGO, dlgt);
25461 + if (unlikely(err))
25465 + bend = au_dbend(dentry);
25466 + bopq = au_dbdiropq(dentry);
25467 + whed = (au_dbwh(dentry) == bdst);
25468 + if (!args->parent_opq)
25469 + args->parent_opq |= (bopq <= bdst);
25470 + parent_opq = (args->parent_opq && args->parent == dentry);
25473 + h_inode = h_dentry->d_inode;
25474 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
25475 + if (whed || (parent_opq && do_opq)) {
25476 + opq_dentry = au_diropq_create(dentry, bdst, dlgt);
25477 + err = PTR_ERR(opq_dentry);
25478 + if (IS_ERR(opq_dentry)) {
25479 + mutex_unlock(&h_inode->i_mutex);
25482 + dput(opq_dentry);
25486 + err = au_cpdown_attr(au_hi(dir, bdst), h_dentry,
25487 + au_h_dptr(dentry, bstart));
25488 + mutex_unlock(&h_inode->i_mutex);
25489 + if (unlikely(err))
25492 + wh_dentry = NULL;
25494 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, /*ndx*/NULL);
25495 + err = PTR_ERR(wh_dentry);
25496 + if (IS_ERR(wh_dentry))
25499 + if (wh_dentry->d_inode)
25500 + err = au_wh_unlink_dentry(au_hi(dir, bdst), wh_dentry,
25503 + if (unlikely(err))
25507 + inode = dentry->d_inode;
25508 + if (au_ibend(inode) < bdst)
25509 + au_set_ibend(inode, bdst);
25510 + au_set_h_iptr(inode, bdst, au_igrab(h_inode), au_hi_flags(inode, 1));
25511 + goto out; /* success */
25516 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
25517 + rerr = au_diropq_remove(dentry, bdst, dlgt);
25518 + mutex_unlock(&h_inode->i_mutex);
25519 + if (unlikely(rerr)) {
25520 + AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
25521 + AuDLNPair(dentry), bdst, rerr);
25528 + rerr = vfsub_sio_rmdir(au_hi(dir, bdst), h_dentry, dlgt);
25529 + if (unlikely(rerr)) {
25530 + AuIOErr("failed removing %.*s b%d (%d)\n",
25531 + AuDLNPair(dentry), bdst, rerr);
25536 + au_set_h_dptr(dentry, bdst, NULL);
25537 + if (au_dbend(dentry) == bdst)
25538 + au_update_dbend(dentry);
25544 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
25547 + struct au_cpdown_dir_args args = {
25548 + .parent = dget_parent(dentry),
25552 + LKTRTrace("%.*s, b%d\n", AuDLNPair(dentry), bdst);
25554 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &args);
25555 + dput(args.parent);
25561 +/* ---------------------------------------------------------------------- */
25563 +/* policies for create */
25565 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
25567 + for (; bindex >= 0; bindex--)
25568 + if (!au_br_rdonly(au_sbr(sb, bindex)))
25573 +/* top down parent */
25574 +static int au_wbr_create_tdp(struct dentry *dentry, int isdir)
25577 + struct super_block *sb;
25578 + aufs_bindex_t bstart, bindex;
25579 + unsigned char dirperm1;
25580 + struct dentry *parent, *h_parent;
25581 + struct inode *h_dir;
25583 + LKTRTrace("%.*s, dir %d\n", AuDLNPair(dentry), isdir);
25585 + sb = dentry->d_sb;
25586 + dirperm1 = !!au_test_dirperm1(au_mntflags(sb));
25587 + bstart = au_dbstart(dentry);
25588 + AuDebugOn(bstart < 0);
25590 + /* todo: can 'err' be an illegal? */
25591 + if (/* err >= 0 && */ !au_br_rdonly(au_sbr(sb, bstart)))
25595 + parent = dget_parent(dentry);
25596 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
25597 + h_parent = au_h_dptr(parent, bindex);
25600 + h_dir = h_parent->d_inode;
25604 + if (!au_br_rdonly(au_sbr(sb, bindex))
25606 + || au_test_h_perm(h_dir, MAY_WRITE | MAY_EXEC,
25614 + /* bottom up here */
25615 + if (unlikely(err < 0))
25616 + err = au_wbr_bu(sb, bstart - 1);
25619 + LKTRTrace("b%d\n", err);
25623 +/* ---------------------------------------------------------------------- */
25625 +/* an exception for the policy other than tdp */
25626 +static int au_wbr_create_exp(struct dentry *dentry)
25629 + struct dentry *parent;
25630 + aufs_bindex_t bwh, bdiropq;
25632 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
25635 + bwh = au_dbwh(dentry);
25636 + parent = dget_parent(dentry);
25637 + bdiropq = au_dbdiropq(parent);
25639 + if (bdiropq >= 0)
25640 + err = min(bdiropq, bwh);
25643 + LKTRTrace("%d\n", err);
25644 + } else if (bdiropq >= 0) {
25646 + LKTRTrace("%d\n", err);
25650 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
25653 + LKTRTrace("%d\n", err);
25657 +/* ---------------------------------------------------------------------- */
25660 +static int au_wbr_create_init_rr(struct super_block *sb)
25664 + err = au_wbr_bu(sb, au_sbend(sb));
25665 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
25667 + LKTRTrace("b%d\n", err);
25671 +static int au_wbr_create_rr(struct dentry *dentry, int isdir)
25674 + struct super_block *sb;
25677 + aufs_bindex_t bindex, bend;
25679 + LKTRTrace("%.*s, dir %d\n", AuDLNPair(dentry), isdir);
25681 + sb = dentry->d_sb;
25683 + err = au_wbr_create_exp(dentry);
25687 + next = &au_sbi(sb)->si_wbr_rr_next;
25688 + bend = au_sbend(sb);
25690 + for (bindex = 0; bindex <= bend; bindex++) {
25692 + err = atomic_dec_return(next) + 1;
25693 + /* modulo for 0 is meaningless */
25694 + if (unlikely(!err))
25695 + err = atomic_dec_return(next) + 1;
25697 + err = atomic_read(next);
25698 + LKTRTrace("%d\n", err);
25701 + LKTRTrace("%d\n", err);
25702 + if (!au_br_rdonly(au_sbr(sb, err)))
25708 + LKTRTrace("%d\n", err);
25712 +/* ---------------------------------------------------------------------- */
25714 +/* most free space */
25715 +static void *au_wbr_statfs_arg(struct au_branch *br, struct super_block *sb,
25716 + aufs_bindex_t bindex)
25718 + struct super_block *h_sb;
25720 + h_sb = br->br_mnt->mnt_sb;
25722 + if (!au_test_nfs(h_sb))
25723 + return h_sb->s_root;
25725 + /* sigh,,, why nfs s_root has wrong inode? */
25726 + return au_di(sb->s_root)->di_hdentry[0 + bindex].hd_dentry;
25729 +static void au_mfs(struct dentry *dentry)
25731 + struct super_block *sb;
25732 + aufs_bindex_t bindex, bend;
25733 + unsigned char dlgt;
25735 + struct kstatfs st;
25736 + unsigned long long b, bavail;
25738 + struct au_branch *br;
25739 + struct au_wbr_mfs *mfs;
25741 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
25744 + sb = dentry->d_sb;
25745 + mfs = &au_sbi(sb)->si_wbr_mfs;
25746 + mfs->mfs_bindex = -EROFS;
25747 + mfs->mfsrr_bytes = 0;
25748 + dlgt = !!au_test_dlgt(au_mntflags(sb));
25749 + bend = au_sbend(sb);
25750 + for (bindex = 0; bindex <= bend; bindex++) {
25751 + br = au_sbr(sb, bindex);
25752 + if (au_br_rdonly(br))
25754 + AuDebugOn(!br->br_wbr);
25755 + arg = au_wbr_statfs_arg(br, sb, bindex);
25759 + err = vfsub_statfs(arg, &st, dlgt);
25760 + LKTRTrace("b%d, %d, %llu\n",
25761 + bindex, err, (unsigned long long)st.f_bavail);
25762 + if (unlikely(err)) {
25763 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
25767 + /* when the available size is equal, select lower one */
25768 + b = st.f_bavail * st.f_bsize;
25769 + br->br_wbr->wbr_bytes = b;
25770 + if (b >= bavail) {
25772 + mfs->mfs_bindex = bindex;
25773 + mfs->mfs_jiffy = jiffies;
25777 + mfs->mfsrr_bytes = bavail;
25778 + LKTRTrace("b%d\n", mfs->mfs_bindex);
25781 +static int au_wbr_create_mfs(struct dentry *dentry, int isdir)
25784 + struct super_block *sb;
25785 + struct au_wbr_mfs *mfs;
25787 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
25789 + sb = dentry->d_sb;
25790 + err = au_wbr_create_exp(dentry);
25794 + mfs = &au_sbi(sb)->si_wbr_mfs;
25795 + mutex_lock(&mfs->mfs_lock);
25796 + if (unlikely(time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
25797 + || mfs->mfs_bindex < 0
25798 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex))))
25800 + mutex_unlock(&mfs->mfs_lock);
25801 + err = mfs->mfs_bindex;
25804 + LKTRTrace("b%d\n", err);
25808 +static int au_wbr_create_init_mfs(struct super_block *sb)
25810 + struct au_wbr_mfs *mfs;
25812 + mfs = &au_sbi(sb)->si_wbr_mfs;
25813 + LKTRTrace("expire %lu\n", mfs->mfs_expire);
25815 + mutex_init(&mfs->mfs_lock);
25816 + mfs->mfs_jiffy = 0;
25817 + mfs->mfs_bindex = -EROFS;
25822 +static int au_wbr_create_fin_mfs(struct super_block *sb)
25825 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
25829 +/* ---------------------------------------------------------------------- */
25831 +/* most free space and then round robin */
25832 +static int au_wbr_create_mfsrr(struct dentry *dentry, int isdir)
25835 + struct au_wbr_mfs *mfs;
25837 + LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), isdir);
25839 + err = au_wbr_create_mfs(dentry, isdir);
25841 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
25842 + LKTRTrace("%llu bytes, %llu wmark\n",
25843 + mfs->mfsrr_bytes, mfs->mfsrr_watermark);
25844 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
25845 + err = au_wbr_create_rr(dentry, isdir);
25848 + LKTRTrace("b%d\n", err);
25852 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
25856 + au_wbr_create_init_mfs(sb); /* ignore */
25857 + err = au_wbr_create_init_rr(sb);
25863 +/* ---------------------------------------------------------------------- */
25865 +/* top down parent and most free space */
25866 +static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
25869 + struct super_block *sb;
25870 + struct dentry *parent, *h_parent;
25871 + aufs_bindex_t bindex, bstart, bend;
25872 + unsigned char dirperm1;
25873 + struct au_branch *br;
25874 + unsigned long long b;
25875 + struct inode *h_dir;
25877 + LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), isdir);
25879 + err = au_wbr_create_tdp(dentry, isdir);
25880 + if (unlikely(err < 0))
25882 + parent = dget_parent(dentry);
25883 + bstart = au_dbstart(parent);
25884 + bend = au_dbtaildir(parent);
25885 + if (bstart == bend)
25886 + goto out_parent; /* success */
25888 + e2 = au_wbr_create_mfs(dentry, isdir);
25890 + goto out_parent; /* success */
25892 + /* when the available size is equal, select upper one */
25893 + sb = dentry->d_sb;
25894 + br = au_sbr(sb, err);
25895 + AuDebugOn(!br->br_wbr);
25896 + dirperm1 = !!au_test_dirperm1(au_mntflags(sb));
25897 + b = br->br_wbr->wbr_bytes;
25898 + LKTRTrace("b%d, %llu\n", err, b);
25901 + for (bindex = bstart; bindex <= bend; bindex++) {
25902 + h_parent = au_h_dptr(parent, bindex);
25905 + h_dir = h_parent->d_inode;
25909 + br = au_sbr(sb, bindex);
25910 + if (!au_br_rdonly(br)
25911 + && au_test_h_perm(h_dir, MAY_WRITE | MAY_EXEC,
25913 + && br->br_wbr->wbr_bytes > b) {
25914 + b = br->br_wbr->wbr_bytes;
25916 + LKTRTrace("b%d, %llu\n", err, b);
25922 + for (bindex = bstart; bindex <= bend; bindex++) {
25923 + h_parent = au_h_dptr(parent, bindex);
25924 + if (!h_parent || !h_parent->d_inode)
25927 + br = au_sbr(sb, bindex);
25928 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
25929 + b = br->br_wbr->wbr_bytes;
25931 + LKTRTrace("b%d, %llu\n", err, b);
25938 + LKTRTrace("b%d\n", err);
25942 +/* ---------------------------------------------------------------------- */
25944 +/* policies for copyup */
25946 +/* top down parent */
25947 +static int au_wbr_copyup_tdp(struct dentry *dentry)
25949 + return au_wbr_create_tdp(dentry, /*isdir, anything is ok*/0);
25952 +/* bottom up parent */
25953 +static int au_wbr_copyup_bup(struct dentry *dentry)
25956 + struct dentry *parent, *h_parent;
25957 + aufs_bindex_t bindex, bstart;
25958 + unsigned char dirperm1;
25959 + struct super_block *sb;
25960 + struct inode *h_dir;
25962 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
25965 + sb = dentry->d_sb;
25966 + dirperm1 = !!au_test_dirperm1(au_mntflags(sb));
25967 + parent = dget_parent(dentry);
25968 + bstart = au_dbstart(parent);
25969 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
25970 + h_parent = au_h_dptr(parent, bindex);
25973 + h_dir = h_parent->d_inode;
25977 + if (!au_br_rdonly(au_sbr(sb, bindex))
25979 + || au_test_h_perm(h_dir, MAY_WRITE | MAY_EXEC,
25987 + /* bottom up here */
25988 + if (unlikely(err < 0))
25989 + err = au_wbr_bu(sb, bstart - 1);
25991 + LKTRTrace("b%d\n", err);
25996 +static int au_wbr_copyup_bu(struct dentry *dentry)
26000 + LKTRTrace("%.*s\n", AuDLNPair(dentry));
26002 + err = au_wbr_bu(dentry->d_sb, au_dbstart(dentry));
26004 + LKTRTrace("b%d\n", err);
26008 +/* ---------------------------------------------------------------------- */
26010 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
26011 + [AuWbrCopyup_TDP] = {
26012 + .copyup = au_wbr_copyup_tdp
26014 + [AuWbrCopyup_BUP] = {
26015 + .copyup = au_wbr_copyup_bup
26017 + [AuWbrCopyup_BU] = {
26018 + .copyup = au_wbr_copyup_bu
26022 +struct au_wbr_create_operations au_wbr_create_ops[] = {
26023 + [AuWbrCreate_TDP] = {
26024 + .create = au_wbr_create_tdp
26026 + [AuWbrCreate_RR] = {
26027 + .create = au_wbr_create_rr,
26028 + .init = au_wbr_create_init_rr
26030 + [AuWbrCreate_MFS] = {
26031 + .create = au_wbr_create_mfs,
26032 + .init = au_wbr_create_init_mfs,
26033 + .fin = au_wbr_create_fin_mfs
26035 + [AuWbrCreate_MFSV] = {
26036 + .create = au_wbr_create_mfs,
26037 + .init = au_wbr_create_init_mfs,
26038 + .fin = au_wbr_create_fin_mfs
26040 + [AuWbrCreate_MFSRR] = {
26041 + .create = au_wbr_create_mfsrr,
26042 + .init = au_wbr_create_init_mfsrr,
26043 + .fin = au_wbr_create_fin_mfs
26045 + [AuWbrCreate_MFSRRV] = {
26046 + .create = au_wbr_create_mfsrr,
26047 + .init = au_wbr_create_init_mfsrr,
26048 + .fin = au_wbr_create_fin_mfs
26050 + [AuWbrCreate_PMFS] = {
26051 + .create = au_wbr_create_pmfs,
26052 + .init = au_wbr_create_init_mfs,
26053 + .fin = au_wbr_create_fin_mfs
26055 + [AuWbrCreate_PMFSV] = {
26056 + .create = au_wbr_create_pmfs,
26057 + .init = au_wbr_create_init_mfs,
26058 + .fin = au_wbr_create_fin_mfs
26061 diff -urN linux/fs/aufs/whout.c linux-aufs/fs/aufs/whout.c
26062 --- linux/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
26063 +++ linux-aufs/fs/aufs/whout.c 2009-03-12 16:18:04.000000000 +0100
26066 + * Copyright (C) 2005-2009 Junjiro Okajima
26068 + * This program, aufs is free software; you can redistribute it and/or modify
26069 + * it under the terms of the GNU General Public License as published by
26070 + * the Free Software Foundation; either version 2 of the License, or
26071 + * (at your option) any later version.
26073 + * This program is distributed in the hope that it will be useful,
26074 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26075 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26076 + * GNU General Public License for more details.
26078 + * You should have received a copy of the GNU General Public License
26079 + * along with this program; if not, write to the Free Software
26080 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26084 + * whiteout for logical deletion and opaque directory
26089 +#include <linux/fs.h>
26090 +#include <linux/namei.h>
26093 +#define WH_MASK S_IRUGO
26095 +/* If a directory contains this file, then it is opaque. We start with the
26096 + * .wh. flag so that it is blocked by lookup.
26098 +static struct qstr diropq_name = {
26099 + .name = AUFS_WH_DIROPQ,
26100 + .len = sizeof(AUFS_WH_DIROPQ) - 1
26104 + * generate whiteout name, which is NOT terminated by NULL.
26105 + * @name: original d_name.name
26106 + * @len: original d_name.len
26107 + * @wh: whiteout qstr
26108 + * returns zero when succeeds, otherwise error.
26109 + * succeeded value as wh->name should be freed by au_wh_name_free().
26111 +int au_wh_name_alloc(const char *name, int len, struct qstr *wh)
26115 + AuDebugOn(!name || !len || !wh);
26117 + if (unlikely(len > PATH_MAX - AUFS_WH_PFX_LEN))
26118 + return -ENAMETOOLONG;
26120 + wh->len = len + AUFS_WH_PFX_LEN;
26121 + p = kmalloc(wh->len, GFP_NOFS);
26124 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
26125 + memcpy(p + AUFS_WH_PFX_LEN, name, len);
26132 +void au_wh_name_free(struct qstr *wh)
26134 + AuDebugOn(!wh || !wh->name);
26138 +/* ---------------------------------------------------------------------- */
26141 + * test if the @wh_name exists under @h_parent.
26142 + * @try_sio specifies the necessary of super-io.
26144 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio,
26145 + struct au_ndx *ndx)
26148 + struct dentry *wh_dentry;
26149 + struct inode *h_dir;
26150 + unsigned int flags;
26152 + LKTRTrace("%.*s/%.*s, ndx{%p, 0x%x}\n", AuDLNPair(h_parent),
26153 + wh_name->len, wh_name->name, ndx->nfsmnt, ndx->flags);
26154 + h_dir = h_parent->d_inode;
26155 + AuDebugOn(!S_ISDIR(h_dir->i_mode));
26158 + if (ndx && ndx->nd) {
26159 + flags = ndx->nd->flags;
26160 + ndx->nd->flags &= ~(LOOKUP_OPEN | LOOKUP_CREATE);
26164 + wh_dentry = au_lkup_one(wh_name->name, h_parent,
26165 + wh_name->len, ndx);
26167 + wh_dentry = au_sio_lkup_one(wh_name->name, h_parent,
26168 + wh_name->len, ndx);
26170 + ndx->nd->flags = flags;
26171 + err = PTR_ERR(wh_dentry);
26172 + if (IS_ERR(wh_dentry))
26176 + if (!wh_dentry->d_inode)
26177 + goto out_wh; /* success */
26180 + if (S_ISREG(wh_dentry->d_inode->i_mode))
26181 + goto out_wh; /* success */
26184 + AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
26185 + AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
26195 + * test if the @h_dentry sets opaque or not.
26197 +int au_diropq_test(struct dentry *h_dentry, struct au_ndx *ndx)
26199 + int err, try_sio;
26200 + struct inode *h_dir;
26202 + LKTRTrace("dentry %.*s\n", AuDLNPair(h_dentry));
26203 + h_dir = h_dentry->d_inode;
26204 + AuDebugOn(!S_ISDIR(h_dir->i_mode));
26206 + try_sio = au_test_h_perm_sio(h_dir, MAY_EXEC,
26207 + au_ftest_ndx(ndx->flags, DLGT));
26208 + err = au_wh_test(h_dentry, &diropq_name, try_sio, ndx);
26214 + * returns a negative dentry whose name is unique and temporary.
26216 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct qstr *prefix,
26217 + struct au_ndx *ndx)
26220 + struct dentry *dentry;
26222 + char defname[AUFS_WH_PFX_LEN * 2 + DNAME_INLINE_LEN_MIN + 1
26223 + + HEX_LEN + 1], *name, *p;
26224 + static unsigned char cnt;
26226 + LKTRTrace("hp %.*s, prefix %.*s\n",
26227 + AuDLNPair(h_parent), prefix->len, prefix->name);
26228 + AuDebugOn(!h_parent->d_inode);
26231 + len = sizeof(defname) - DNAME_INLINE_LEN_MIN + prefix->len - 1;
26232 + if (unlikely(prefix->len > DNAME_INLINE_LEN_MIN)) {
26233 + dentry = ERR_PTR(-ENAMETOOLONG);
26234 + if (unlikely(len >= PATH_MAX))
26236 + dentry = ERR_PTR(-ENOMEM);
26237 + name = kmalloc(len + 1, GFP_NOFS);
26238 + if (unlikely(!name))
26242 + /* doubly whiteout-ed */
26243 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
26244 + p = name + AUFS_WH_PFX_LEN * 2;
26245 + memcpy(p, prefix->name, prefix->len);
26246 + p += prefix->len;
26248 + AuDebugOn(name + len + 1 - p <= HEX_LEN);
26250 + for (i = 0; i < 3; i++) {
26251 + sprintf(p, "%.*d", HEX_LEN, cnt++);
26252 + dentry = au_sio_lkup_one(name, h_parent, len, ndx);
26253 + if (IS_ERR(dentry) || !dentry->d_inode)
26257 + /* AuWarn("could not get random name\n"); */
26258 + dentry = ERR_PTR(-EEXIST);
26259 + AuDbg("%.*s\n", len, name);
26263 + if (name != defname)
26266 + AuTraceErrPtr(dentry);
26272 + * rename the @dentry of @bindex to the whiteouted temporary name.
26274 +int au_whtmp_ren(struct inode *dir, aufs_bindex_t bindex,
26275 + struct dentry *h_dentry)
26278 + struct inode *h_dir;
26279 + struct dentry *h_parent, *tmp_dentry;
26280 + struct super_block *sb;
26281 + unsigned int mnt_flags;
26282 + struct au_hin_ignore ign;
26283 + struct vfsub_args vargs;
26284 + struct au_ndx ndx = {
26290 + LKTRTrace("%.*s\n", AuDLNPair(h_dentry));
26291 + AuDebugOn(!h_dentry->d_inode);
26292 + h_parent = h_dentry->d_parent; /* dir inode is locked */
26293 + h_dir = h_parent->d_inode;
26294 + IMustLock(h_dir);
26297 + mnt_flags = au_mntflags(sb);
26298 + dlgt = !!au_test_dlgt(mnt_flags);
26300 + au_fset_ndx(ndx.flags, DLGT);
26301 + ndx.nfsmnt = au_nfsmnt(sb, bindex);
26302 + tmp_dentry = au_whtmp_lkup(h_parent, &h_dentry->d_name, &ndx);
26303 + err = PTR_ERR(tmp_dentry);
26304 + if (IS_ERR(tmp_dentry))
26307 + /* under the same dir, no need to lock_rename() */
26308 + vfsub_args_init(&vargs, &ign, dlgt, 0);
26309 + AuDebugOn(!S_ISDIR(h_dentry->d_inode->i_mode));
26310 + vfsub_ign_hinode(&vargs, IN_MOVED_FROM | IN_MOVED_TO,
26311 + au_hi(dir, bindex));
26312 + err = vfsub_rename(h_dir, h_dentry, h_dir, tmp_dentry, &vargs);
26314 + dput(tmp_dentry);
26321 +/* ---------------------------------------------------------------------- */
26323 +static int do_unlink_wh(struct au_hinode *hdir, struct inode *h_dir,
26324 + struct dentry *wh_dentry, const int dlgt)
26327 + struct au_hin_ignore ign;
26328 + struct vfsub_args vargs;
26330 + AuDebugOn(hdir && h_dir);
26331 + AuDebugOn(!hdir && !h_dir);
26333 + h_dir = hdir->hi_inode;
26334 + LKTRTrace("hi%lu, wh %.*s\n", h_dir->i_ino, AuDLNPair(wh_dentry));
26335 + AuDebugOn(!wh_dentry->d_inode || !S_ISREG(wh_dentry->d_inode->i_mode));
26338 + * forces superio when the dir has a sticky bit.
26339 + * this may be a violation of unix fs semantics.
26341 + vfsub_args_init(&vargs, &ign, dlgt,
26342 + (h_dir->i_mode & S_ISVTX)
26343 + && wh_dentry->d_inode->i_uid != current_fsuid());
26344 + vfsub_ign_hinode(&vargs, IN_DELETE, hdir);
26345 + err = vfsub_unlink(h_dir, wh_dentry, &vargs);
26350 +int au_wh_unlink_dentry(struct au_hinode *hdir, struct dentry *wh_dentry,
26351 + struct dentry *dentry, int dlgt)
26355 + LKTRTrace("i%lu, wh %.*s, d %p\n",
26356 + hdir->hi_inode->i_ino, AuDLNPair(wh_dentry), dentry);
26357 + AuDebugOn((dentry && au_dbwh(dentry) < 0)
26358 + || !wh_dentry->d_inode
26359 + || !S_ISREG(wh_dentry->d_inode->i_mode));
26361 + err = do_unlink_wh(hdir, /*h_dir*/NULL, wh_dentry, dlgt);
26362 + if (!err && dentry)
26363 + au_set_dbwh(dentry, -1);
26369 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
26370 + struct au_ndx *ndx)
26373 + struct dentry *wh_dentry;
26375 + LKTRTrace("%.*s/%.*s\n", AuDLNPair(h_parent), AuLNPair(wh));
26377 + /* au_test_h_perm() is already done */
26378 + wh_dentry = au_lkup_one(wh->name, h_parent, wh->len, ndx);
26379 + if (IS_ERR(wh_dentry))
26380 + err = PTR_ERR(wh_dentry);
26383 + if (wh_dentry->d_inode && S_ISREG(wh_dentry->d_inode->i_mode))
26384 + err = do_unlink_wh(/*hdir*/NULL, h_parent->d_inode,
26386 + au_ftest_ndx(ndx->flags, DLGT));
26394 +/* ---------------------------------------------------------------------- */
26396 +static void clean_wh(struct inode *h_dir, struct path *whpath,
26397 + struct au_hinode *hdir, struct vfsub_args *vargs)
26403 + if (!whpath->dentry->d_inode)
26406 + err = au_mnt_want_write(whpath->mnt);
26408 + vfsub_args_reinit(vargs);
26409 + vfsub_ign_hinode(vargs, IN_DELETE, hdir);
26410 + err = vfsub_unlink(h_dir, whpath->dentry, vargs);
26411 + au_mnt_drop_write(whpath->mnt);
26413 + if (unlikely(err))
26414 + AuWarn("failed unlink %.*s (%d), ignored.\n",
26415 + AuDLNPair(whpath->dentry), err);
26418 +static void au_whdir_clean(struct inode *h_dir, struct path *whpath,
26419 + struct au_hinode *hdir, struct vfsub_args *vargs)
26425 + if (!whpath->dentry->d_inode)
26428 + err = au_mnt_want_write(whpath->mnt);
26430 + vfsub_args_reinit(vargs);
26431 + vfsub_ign_hinode(vargs, IN_DELETE, hdir);
26432 + err = vfsub_rmdir(h_dir, whpath->dentry, vargs);
26433 + au_mnt_drop_write(whpath->mnt);
26435 + if (unlikely(err))
26436 + AuWarn("failed rmdir %.*s (%d), ignored.\n",
26437 + AuDLNPair(whpath->dentry), err);
26440 +static int test_linkable(struct inode *h_dir)
26442 + if (h_dir->i_op && h_dir->i_op->link)
26447 +/* todo: should this mkdir be done in /sbin/mount.aufs script? */
26448 +static int au_whdir(struct inode *h_dir, struct path *path,
26449 + struct au_hinode *hdir, struct vfsub_args *vargs)
26454 + if (!path->dentry->d_inode) {
26455 + int mode = S_IRWXU;
26456 + if (au_test_nfs(path->dentry->d_sb))
26458 + err = au_mnt_want_write(path->mnt);
26460 + vfsub_args_reinit(vargs);
26461 + vfsub_ign_hinode(vargs, IN_CREATE, hdir);
26462 + err = vfsub_mkdir(h_dir, path->dentry, mode, vargs);
26463 + au_mnt_drop_write(path->mnt);
26465 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
26468 + AuErr("unknown %.*s exists\n", AuDLNPair(path->dentry));
26474 + * initialize the whiteout base file/dir for @br.
26476 +int au_wh_init(struct dentry *h_root, struct au_branch *br,
26477 + struct vfsmount *h_mnt, struct super_block *sb,
26478 + aufs_bindex_t bindex)
26481 + const unsigned int mnt_flags = au_mntflags(sb);
26482 + const unsigned char do_plink = !!au_opt_test(mnt_flags, PLINK),
26483 + do_hinotify = au_opt_test(mnt_flags, UDBA_INOTIFY);
26484 + struct path path = {
26487 + struct au_hin_ignore ign;
26488 + struct vfsub_args vargs;
26489 + struct inode *h_dir;
26490 + struct au_hinode *hdir;
26491 + struct au_wbr *wbr = br->br_wbr;
26492 + struct vfsmount *nfsmnt = au_do_nfsmnt(h_mnt);
26493 + static const struct qstr base_name[] = {
26494 + [AuBrWh_BASE] = {
26495 + .name = AUFS_BASE_NAME,
26496 + .len = sizeof(AUFS_BASE_NAME) - 1
26498 + [AuBrWh_PLINK] = {
26499 + .name = AUFS_PLINKDIR_NAME,
26500 + .len = sizeof(AUFS_PLINKDIR_NAME) - 1
26503 + .name = AUFS_TMPDIR_NAME,
26504 + .len = sizeof(AUFS_TMPDIR_NAME) - 1
26508 + const struct qstr *name;
26509 + struct dentry *dentry;
26511 + [AuBrWh_BASE] = {
26512 + .name = base_name + AuBrWh_BASE,
26515 + [AuBrWh_PLINK] = {
26516 + .name = base_name + AuBrWh_PLINK,
26520 + .name = base_name + AuBrWh_TMP,
26524 + struct au_ndx ndx = {
26525 + .nfsmnt = nfsmnt,
26526 + .flags = 0, /* always no dlgt */
26531 + LKTRTrace("nfsmnt %p\n", nfsmnt);
26532 + WbrWhMustWriteLock(wbr);
26533 + SiMustWriteLock(sb);
26534 + h_dir = h_root->d_inode;
26536 + for (i = 0; i < AuBrWh_Last; i++) {
26537 + /* doubly whiteouted */
26538 + struct dentry *d;
26539 + d = au_wh_lkup(h_root, (void *)base[i].name, &ndx);
26540 + err = PTR_ERR(d);
26543 + base[i].dentry = d;
26544 + if (!au_test_ecryptfs(d->d_sb))
26546 + && wbr->wbr_wh[i]
26547 + && wbr->wbr_wh[i] != base[i].dentry);
26549 + /* ecryptfs problem?: it returns different dentry */
26551 + && wbr->wbr_wh[i]
26552 + && !!wbr->wbr_wh[i] != !!base[i].dentry);
26556 + for (i = 0; i < AuBrWh_Last; i++) {
26557 + dput(wbr->wbr_wh[i]);
26558 + wbr->wbr_wh[i] = NULL;
26563 + if (bindex >= 0 && do_hinotify)
26564 + hdir = au_hi(sb->s_root->d_inode, bindex);
26565 + vfsub_args_init(&vargs, &ign, au_test_dlgt(mnt_flags), 0);
26567 + switch (br->br_perm) {
26568 + case AuBrPerm_RR:
26569 + case AuBrPerm_RO:
26570 + case AuBrPerm_RRWH:
26571 + case AuBrPerm_ROWH:
26572 + path.dentry = base[AuBrWh_BASE].dentry;
26573 + clean_wh(h_dir, &path, hdir, &vargs);
26574 + path.dentry = base[AuBrWh_PLINK].dentry;
26575 + au_whdir_clean(h_dir, &path, hdir, &vargs);
26576 + path.dentry = base[AuBrWh_TMP].dentry;
26577 + au_whdir_clean(h_dir, &path, hdir, &vargs);
26580 + case AuBrPerm_RWNoLinkWH:
26581 + path.dentry = base[AuBrWh_BASE].dentry;
26582 + clean_wh(h_dir, &path, hdir, &vargs);
26583 + path.dentry = base[AuBrWh_PLINK].dentry;
26585 + err = test_linkable(h_dir);
26586 + if (unlikely(err))
26589 + err = au_whdir(h_dir, &path, hdir, &vargs);
26590 + if (unlikely(err))
26592 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
26594 + au_whdir_clean(h_dir, &path, hdir, &vargs);
26595 + path.dentry = base[AuBrWh_TMP].dentry;
26596 + err = au_whdir(h_dir, &path, hdir, &vargs);
26597 + if (unlikely(err))
26599 + wbr->wbr_tmp = dget(base[AuBrWh_TMP].dentry);
26602 + case AuBrPerm_RW:
26604 + * for the moment, aufs supports the branch filesystem
26605 + * which does not support link(2).
26606 + * testing on FAT which does not support i_op->setattr() fully
26607 + * either, copyup failed.
26608 + * finally, such filesystem will not be used as the writable
26611 + err = test_linkable(h_dir);
26612 + if (unlikely(err))
26617 + * todo: should this create be done
26618 + * in /sbin/mount.aufs script?
26620 + if (!base[AuBrWh_BASE].dentry->d_inode) {
26621 + err = au_mnt_want_write(h_mnt);
26623 + vfsub_args_reinit(&vargs);
26624 + vfsub_ign_hinode(&vargs, IN_CREATE, hdir);
26625 + err = au_h_create
26626 + (h_dir, base[AuBrWh_BASE].dentry,
26627 + WH_MASK, &vargs, /*nd*/NULL, nfsmnt);
26628 + au_mnt_drop_write(h_mnt);
26630 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
26633 + AuErr("unknown %.*s/%.*s exists\n",
26634 + AuDLNPair(h_root),
26635 + AuDLNPair(base[AuBrWh_BASE].dentry));
26636 + if (unlikely(err))
26639 + path.dentry = base[AuBrWh_PLINK].dentry;
26641 + err = au_whdir(h_dir, &path, hdir, &vargs);
26642 + if (unlikely(err))
26644 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
26646 + au_whdir_clean(h_dir, &path, hdir, &vargs);
26647 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
26649 + path.dentry = base[AuBrWh_TMP].dentry;
26650 + err = au_whdir(h_dir, &path, hdir, &vargs);
26651 + if (unlikely(err))
26653 + wbr->wbr_tmp = dget(base[AuBrWh_TMP].dentry);
26661 + for (i = 0; i < AuBrWh_Last; i++)
26662 + dput(base[i].dentry);
26666 + AuErr("%.*s doesn't support link(2), use noplink and rw+nolwh\n",
26667 + AuDLNPair(h_root));
26670 + AuErr("an error(%d) on the writable branch %.*s(%s)\n",
26671 + err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
26675 +struct reinit_br_wh {
26676 + struct super_block *sb;
26677 + struct au_branch *br;
26680 +static void reinit_br_wh(void *arg)
26683 + struct reinit_br_wh *a = arg;
26684 + struct au_wbr *wbr;
26685 + struct inode *h_dir, *dir;
26686 + struct dentry *h_root;
26687 + aufs_bindex_t bindex;
26688 + struct au_hin_ignore ign;
26689 + struct vfsub_args vargs;
26692 + AuDebugOn(current_fsuid());
26695 + wbr = a->br->br_wbr;
26696 + /* big aufs lock */
26697 + si_noflush_write_lock(a->sb);
26698 + if (!au_br_writable(a->br->br_perm))
26700 + bindex = au_br_index(a->sb, a->br->br_id);
26701 + if (unlikely(bindex < 0))
26705 + AuDebugOn(!wbr->wbr_whbase || !wbr->wbr_whbase->d_inode);
26707 + dir = a->sb->s_root->d_inode;
26708 + ii_read_lock_parent(dir);
26709 + h_root = dget_parent(wbr->wbr_whbase);
26710 + h_dir = h_root->d_inode;
26711 + AuDebugOn(!h_dir->i_op || !h_dir->i_op->link);
26712 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
26713 + wbr_wh_write_lock(wbr);
26714 + if (!au_verify_parent(wbr->wbr_whbase, h_dir)) {
26715 + err = au_br_want_write(a->br);
26717 + vfsub_args_init(&vargs, &ign, /*dlgt*/0, 0);
26718 + vfsub_ign_hinode(&vargs, IN_DELETE, au_hi(dir, bindex));
26719 + err = vfsub_unlink(h_dir, wbr->wbr_whbase, &vargs);
26720 + au_br_drop_write(a->br);
26723 + AuWarn("%.*s is moved, ignored\n", AuDLNPair(wbr->wbr_whbase));
26726 + dput(wbr->wbr_whbase);
26727 + wbr->wbr_whbase = NULL;
26729 + err = au_wh_init(h_root, a->br, a->br->br_mnt, a->sb, bindex);
26730 + wbr_wh_write_unlock(wbr);
26731 + mutex_unlock(&h_dir->i_mutex);
26733 + ii_read_unlock(dir);
26737 + atomic_dec_return(&wbr->wbr_wh_running);
26738 + au_br_put(a->br);
26739 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
26740 + si_write_unlock(a->sb);
26742 + if (unlikely(err))
26743 + AuIOErr("err %d\n", err);
26746 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
26748 + int do_dec, wkq_err;
26749 + struct reinit_br_wh *arg;
26752 + AuDebugOn(!br->br_wbr);
26755 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
26758 + /* ignore ENOMEM */
26759 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
26762 + * dec(wh_running), kfree(arg) and au_br_put()
26763 + * in reinit function
26768 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*dlgt*/0);
26769 + if (unlikely(wkq_err)) {
26770 + atomic_dec_return(&br->br_wbr->wbr_wh_running);
26779 + atomic_dec_return(&br->br_wbr->wbr_wh_running);
26783 + * create the whiteout @wh.
26785 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
26786 + struct dentry *wh, struct inode *dir)
26789 + struct au_branch *br;
26790 + struct au_wbr *wbr;
26791 + struct dentry *h_parent;
26792 + struct inode *h_dir;
26793 + struct au_hin_ignore ign;
26794 + struct vfsub_args vargs;
26796 + LKTRTrace("%.*s\n", AuDLNPair(wh));
26797 + h_parent = wh->d_parent; /* dir inode is locked */
26798 + h_dir = h_parent->d_inode;
26799 + IMustLock(h_dir);
26800 + br = au_sbr(sb, bindex);
26801 + wbr = br->br_wbr;
26804 + dlgt = !!au_test_dlgt(au_mntflags(sb));
26805 + wbr_wh_read_lock(wbr);
26806 + if (wbr->wbr_whbase) {
26807 + vfsub_args_init(&vargs, &ign, dlgt, 0);
26809 + vfsub_ign_hinode(&vargs, IN_CREATE, au_hi(dir, bindex));
26810 + err = vfsub_link(wbr->wbr_whbase, h_dir, wh, &vargs);
26811 + if (!err || err != -EMLINK)
26814 + /* link count full. re-initialize br_whbase. */
26815 + kick_reinit_br_wh(sb, br);
26818 + /* return this error in this context */
26819 + vfsub_args_init(&vargs, &ign, dlgt, 0);
26821 + vfsub_ign_hinode(&vargs, IN_CREATE, au_hi(dir, bindex));
26822 + err = au_h_create(h_dir, wh, WH_MASK, &vargs, /*nd*/NULL,
26823 + au_do_nfsmnt(br->br_mnt));
26826 + wbr_wh_read_unlock(wbr);
26831 +/* ---------------------------------------------------------------------- */
26834 + * create or remove the diropq.
26836 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
26837 + unsigned int flags)
26839 + struct dentry *opq_dentry, *h_dentry;
26840 + struct inode *h_dir;
26842 + struct super_block *sb;
26843 + struct au_ndx ndx = {
26849 + LKTRTrace("%.*s, bindex %d, flags 0x%x\n",
26850 + AuDLNPair(dentry), bindex, flags);
26851 + h_dentry = au_h_dptr(dentry, bindex);
26852 + AuDebugOn(!h_dentry);
26853 + h_dir = h_dentry->d_inode;
26854 + AuDebugOn(!h_dir || !S_ISDIR(h_dir->i_mode));
26856 + /* already checked by au_test_h_perm(). */
26857 + sb = dentry->d_sb;
26858 + ndx.nfsmnt = au_nfsmnt(sb, bindex);
26860 + if (au_ftest_diropq(flags, DLGT)) {
26862 + au_fset_ndx(ndx.flags, DLGT);
26864 + opq_dentry = au_lkup_one(diropq_name.name, h_dentry, diropq_name.len,
26866 + if (IS_ERR(opq_dentry))
26869 + if (au_ftest_diropq(flags, CREATE)) {
26870 + AuDebugOn(opq_dentry->d_inode);
26871 + err = link_or_create_wh(dentry->d_sb, bindex, opq_dentry,
26872 + dentry->d_inode);
26874 + au_set_dbdiropq(dentry, bindex);
26875 + goto out; /* success */
26878 + AuDebugOn(/* !S_ISDIR(dentry->d_inode->i_mode)
26879 + * || */!opq_dentry->d_inode);
26880 + err = do_unlink_wh(au_hi(dentry->d_inode, bindex),
26881 + /*h_dir*/NULL, opq_dentry, dlgt);
26883 + au_set_dbdiropq(dentry, -1);
26885 + dput(opq_dentry);
26886 + opq_dentry = ERR_PTR(err);
26889 + AuTraceErrPtr(opq_dentry);
26890 + return opq_dentry;
26893 +struct do_diropq_args {
26894 + struct dentry **errp;
26895 + struct dentry *dentry;
26896 + aufs_bindex_t bindex;
26897 + unsigned int flags;
26900 +static void call_do_diropq(void *args)
26902 + struct do_diropq_args *a = args;
26903 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
26906 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
26907 + unsigned int flags)
26909 + struct dentry *diropq, *h_dentry;
26911 + LKTRTrace("%.*s, bindex %d, flags 0x%x\n",
26912 + AuDLNPair(dentry), bindex, flags);
26914 + h_dentry = au_h_dptr(dentry, bindex);
26915 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE,
26916 + au_ftest_diropq(flags, DLGT)))
26917 + diropq = do_diropq(dentry, bindex, flags);
26920 + struct do_diropq_args args = {
26922 + .dentry = dentry,
26923 + .bindex = bindex,
26926 + wkq_err = au_wkq_wait(call_do_diropq, &args, /*dlgt*/0);
26927 + if (unlikely(wkq_err))
26928 + diropq = ERR_PTR(wkq_err);
26931 + AuTraceErrPtr(diropq);
26935 +/* ---------------------------------------------------------------------- */
26938 + * lookup whiteout dentry.
26939 + * @h_parent: hidden parent dentry which must exist and be locked
26940 + * @base_name: name of dentry which will be whiteouted
26941 + * returns dentry for whiteout.
26943 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
26944 + struct au_ndx *ndx)
26947 + struct qstr wh_name;
26948 + struct dentry *wh_dentry;
26950 + LKTRTrace("%.*s/%.*s\n", AuDLNPair(h_parent), AuLNPair(base_name));
26952 + err = au_wh_name_alloc(base_name->name, base_name->len, &wh_name);
26953 + wh_dentry = ERR_PTR(err);
26955 + /* do not superio. */
26956 + wh_dentry = au_lkup_one(wh_name.name, h_parent,
26957 + wh_name.len, ndx);
26958 + au_wh_name_free(&wh_name);
26960 + AuTraceErrPtr(wh_dentry);
26961 + return wh_dentry;
26965 + * link/create a whiteout for @dentry on @bindex.
26967 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
26968 + struct dentry *h_parent, struct au_ndx *ndx)
26970 + struct dentry *wh_dentry;
26971 + struct inode *dir;
26973 + struct super_block *sb;
26975 + LKTRTrace("%.*s/%.*s on b%d\n", AuDLNPair(h_parent),
26976 + AuDLNPair(dentry), bindex);
26978 + sb = dentry->d_sb;
26979 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, ndx);
26980 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
26981 + dir = dentry->d_parent->d_inode; /* dir is locked */
26983 + err = link_or_create_wh(sb, bindex, wh_dentry, dir);
26985 + au_set_dbwh(dentry, bindex);
26988 + wh_dentry = ERR_PTR(err);
26992 + AuTraceErrPtr(wh_dentry);
26993 + return wh_dentry;
26996 +/* ---------------------------------------------------------------------- */
26998 +/* Delete all whiteouts in this directory on branch bindex. */
26999 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
27000 + aufs_bindex_t bindex, struct au_ndx *ndx)
27003 + struct qstr wh_name;
27005 + struct inode *h_inode;
27006 + struct hlist_head *head;
27007 + struct au_vdir_wh *tpos;
27008 + struct hlist_node *pos;
27009 + struct au_vdir_destr *str;
27011 + LKTRTrace("%.*s\n", AuDLNPair(h_dentry));
27012 + h_inode = h_dentry->d_inode;
27013 + AuDebugOn(IS_RDONLY(h_inode));
27017 + wh_name.name = p;
27018 + if (unlikely(!wh_name.name))
27020 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
27021 + p += AUFS_WH_PFX_LEN;
27023 + /* already checked by au_test_h_perm(). */
27025 + for (i = 0; !err && i < AuSize_NHASH; i++) {
27026 + head = whlist->heads + i;
27027 + hlist_for_each_entry(tpos, pos, head, wh_hash) {
27028 + if (tpos->wh_bindex != bindex)
27030 + str = &tpos->wh_str;
27031 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
27032 + memcpy(p, str->name, str->len);
27033 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
27034 + err = unlink_wh_name(h_dentry, &wh_name, ndx);
27039 + AuIOErr("whiteout name too long %.*s\n",
27040 + str->len, str->name);
27045 + __putname(wh_name.name);
27052 +struct del_wh_children_args {
27054 + struct dentry *h_dentry;
27055 + struct au_nhash *whlist;
27056 + aufs_bindex_t bindex;
27057 + struct au_ndx *ndx;
27060 +static void call_del_wh_children(void *args)
27062 + struct del_wh_children_args *a = args;
27063 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->ndx);
27066 +/* ---------------------------------------------------------------------- */
27069 + * rmdir the whiteouted temporary named dir @h_dentry.
27070 + * @whlist: whiteouted children.
27072 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
27073 + struct dentry *wh_dentry, struct au_nhash *whlist)
27076 + struct inode *wh_inode, *h_dir;
27077 + struct super_block *sb;
27078 + unsigned int mnt_flags;
27079 + struct au_hin_ignore ign;
27080 + struct vfsub_args vargs;
27081 + struct au_ndx ndx = {
27087 + LKTRTrace("i%lu, %.*s, b%d\n",
27088 + dir->i_ino, AuDLNPair(wh_dentry), bindex);
27089 + /* IMustLock(dir); */
27090 + IiMustAnyLock(dir);
27091 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
27092 + IMustLock(h_dir);
27095 + mnt_flags = au_mntflags(sb);
27096 + dlgt = !!au_test_dlgt(mnt_flags);
27098 + au_fset_ndx(ndx.flags, DLGT);
27099 + ndx.nfsmnt = au_nfsmnt(sb, bindex);
27100 + wh_inode = wh_dentry->d_inode;
27101 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
27104 + * someone else might change some whiteouts while we were sleeping.
27105 + * it means this whlist may have an obsoleted entry.
27107 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE, dlgt))
27108 + err = del_wh_children(wh_dentry, whlist, bindex, &ndx);
27112 + unsigned int flags = ndx.flags;
27113 + struct del_wh_children_args args = {
27115 + .h_dentry = wh_dentry,
27116 + .whlist = whlist,
27117 + .bindex = bindex,
27122 + wkq_err = au_wkq_wait(call_del_wh_children, &args, /*dlgt*/0);
27123 + if (unlikely(wkq_err))
27125 + ndx.flags = flags;
27127 + mutex_unlock(&wh_inode->i_mutex);
27130 + vfsub_args_init(&vargs, &ign, dlgt, 0);
27131 + vfsub_ign_hinode(&vargs, IN_DELETE, au_hi(dir, bindex));
27132 + err = vfsub_rmdir(h_dir, wh_dentry, &vargs);
27133 + /* d_drop(h_dentry); */
27137 + if (au_ibstart(dir) == bindex) {
27138 + au_cpup_attr_timesizes(dir);
27139 + /* au_cpup_attr_nlink(dir); */
27142 + return 0; /* success */
27145 + AuWarn("failed removing %.*s(%d), ignored\n",
27146 + AuDLNPair(wh_dentry), err);
27150 +static void au_whtmp_rmdir_free_args(struct au_whtmp_rmdir_args *args)
27152 + au_nhash_fin(&args->whlist);
27153 + dput(args->wh_dentry);
27158 +static void call_rmdir_whtmp(void *args)
27161 + struct au_whtmp_rmdir_args *a = args;
27162 + struct super_block *sb;
27163 + struct dentry *h_parent;
27164 + struct inode *h_dir;
27166 + LKTRTrace("%.*s, b%d, dir i%lu\n",
27167 + AuDLNPair(a->wh_dentry), a->bindex, a->dir->i_ino);
27169 + /* rmdir by nfsd may cause deadlock with this i_mutex */
27170 + /* mutex_lock(&a->dir->i_mutex); */
27171 + sb = a->dir->i_sb;
27172 + si_noflush_read_lock(sb);
27173 + err = au_test_ro(sb, a->bindex, NULL);
27174 + if (unlikely(err))
27178 + ii_write_lock_parent(a->dir);
27179 + h_parent = dget_parent(a->wh_dentry);
27180 + h_dir = h_parent->d_inode;
27181 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
27182 + if (!au_verify_parent(a->wh_dentry, h_dir)) {
27183 + err = au_br_want_write(au_sbr(sb, a->bindex));
27185 + err = au_whtmp_rmdir(a->dir, a->bindex, a->wh_dentry,
27187 + au_br_drop_write(au_sbr(sb, a->bindex));
27190 + mutex_unlock(&h_dir->i_mutex);
27192 + ii_write_unlock(a->dir);
27195 + /* mutex_unlock(&a->dir->i_mutex); */
27196 + au_nwt_done(&au_sbi(sb)->si_nowait);
27197 + si_read_unlock(sb);
27198 + au_whtmp_rmdir_free_args(a);
27199 + if (unlikely(err))
27200 + AuIOErr("err %d\n", err);
27203 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
27204 + struct dentry *wh_dentry, struct au_nhash *whlist,
27205 + struct au_whtmp_rmdir_args *args)
27209 + LKTRTrace("%.*s\n", AuDLNPair(wh_dentry));
27212 + /* all post-process will be done in do_rmdir_whtmp(). */
27213 + args->dir = au_igrab(dir);
27214 + args->bindex = bindex;
27215 + args->wh_dentry = dget(wh_dentry);
27216 + au_nhash_init(&args->whlist);
27217 + au_nhash_move(&args->whlist, whlist);
27218 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, dir->i_sb, /*dlgt*/0);
27219 + if (unlikely(wkq_err)) {
27220 + AuWarn("rmdir error %.*s (%d), ignored\n",
27221 + AuDLNPair(wh_dentry), wkq_err);
27222 + au_whtmp_rmdir_free_args(args);
27225 diff -urN linux/fs/aufs/whout.h linux-aufs/fs/aufs/whout.h
27226 --- linux/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
27227 +++ linux-aufs/fs/aufs/whout.h 2009-03-12 16:18:04.000000000 +0100
27230 + * Copyright (C) 2005-2009 Junjiro Okajima
27232 + * This program, aufs is free software; you can redistribute it and/or modify
27233 + * it under the terms of the GNU General Public License as published by
27234 + * the Free Software Foundation; either version 2 of the License, or
27235 + * (at your option) any later version.
27237 + * This program is distributed in the hope that it will be useful,
27238 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27239 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27240 + * GNU General Public License for more details.
27242 + * You should have received a copy of the GNU General Public License
27243 + * along with this program; if not, write to the Free Software
27244 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27248 + * whiteout for logical deletion and opaque directory
27253 +#ifndef __AUFS_WHOUT_H__
27254 +#define __AUFS_WHOUT_H__
27258 +#include <linux/fs.h>
27259 +#include <linux/aufs_type.h>
27262 +#include "super.h"
27264 +int au_wh_name_alloc(const char *name, int len, struct qstr *wh);
27265 +void au_wh_name_free(struct qstr *wh);
27268 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio,
27269 + struct au_ndx *ndx);
27270 +int au_diropq_test(struct dentry *h_dentry, struct au_ndx *ndx);
27272 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct qstr *prefix,
27273 + struct au_ndx *ndx);
27274 +int au_whtmp_ren(struct inode *dir, aufs_bindex_t bindex,
27275 + struct dentry *h_dentry);
27276 +int au_wh_unlink_dentry(struct au_hinode *dir, struct dentry *wh_dentry,
27277 + struct dentry *dentry, int dlgt);
27280 +int au_wh_init(struct dentry *h_parent, struct au_branch *br,
27281 + struct vfsmount *nfsmnt, struct super_block *sb,
27282 + aufs_bindex_t bindex);
27284 +/* diropq flags */
27285 +#define AuDiropq_CREATE 1
27286 +#define AuDiropq_DLGT (1 << 1)
27287 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
27288 +#define au_fset_diropq(flags, name) { (flags) |= AuDiropq_##name; }
27289 +#define au_fclr_diropq(flags, name) { (flags) &= ~AuDiropq_##name; }
27290 +#ifndef CONFIG_AUFS_DLGT
27291 +#undef AuDiropq_DLGT
27292 +#define AuDiropq_DLGT 0
27295 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
27296 + unsigned int flags);
27298 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
27299 + struct au_ndx *ndx);
27300 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
27301 + struct dentry *h_parent, struct au_ndx *ndx);
27303 +/* real rmdir the whiteout-ed dir */
27304 +struct au_whtmp_rmdir_args {
27305 + struct inode *dir;
27306 + aufs_bindex_t bindex;
27307 + struct dentry *wh_dentry;
27308 + struct au_nhash whlist;
27312 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
27313 + struct dentry *wh_dentry, struct au_nhash *whlist);
27314 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
27315 + struct dentry *wh_dentry, struct au_nhash *whlist,
27316 + struct au_whtmp_rmdir_args *args);
27318 +/* ---------------------------------------------------------------------- */
27321 +struct dentry *au_diropq_create(struct dentry *dentry, aufs_bindex_t bindex,
27324 + unsigned int flags = AuDiropq_CREATE;
27326 + au_fset_diropq(flags, DLGT);
27327 + return au_diropq_sio(dentry, bindex, flags);
27331 +int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex, int dlgt)
27333 + unsigned int flags = !AuDiropq_CREATE;
27335 + au_fset_diropq(flags, DLGT);
27336 + return PTR_ERR(au_diropq_sio(dentry, bindex, flags));
27339 +/* ---------------------------------------------------------------------- */
27341 +#ifdef CONFIG_AUFS_ROBR
27343 +int au_test_robr_wh(struct qstr *name, struct dentry *h_parent,
27344 + struct qstr *wh_name, int try_sio, struct au_ndx *ndx);
27345 +int au_test_robr_shwh(struct super_block *sb, const struct qstr *name);
27348 +int au_test_robr_wh(struct qstr *name, struct dentry *h_parent,
27349 + struct qstr *wh_name, int try_sio, struct au_ndx *ndx)
27351 + return au_wh_test(h_parent, wh_name, try_sio, ndx);
27355 +int au_test_robr_shwh(struct super_block *sb, const struct qstr *name)
27357 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
27358 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
27362 +#endif /* CONFIG_AUFS_ROBR */
27364 +#endif /* __KERNEL__ */
27365 +#endif /* __AUFS_WHOUT_H__ */
27366 diff -urN linux/fs/aufs/wkq.c linux-aufs/fs/aufs/wkq.c
27367 --- linux/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
27368 +++ linux-aufs/fs/aufs/wkq.c 2009-03-12 16:18:04.000000000 +0100
27371 + * Copyright (C) 2005-2009 Junjiro Okajima
27373 + * This program, aufs is free software; you can redistribute it and/or modify
27374 + * it under the terms of the GNU General Public License as published by
27375 + * the Free Software Foundation; either version 2 of the License, or
27376 + * (at your option) any later version.
27378 + * This program is distributed in the hope that it will be useful,
27379 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27380 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27381 + * GNU General Public License for more details.
27383 + * You should have received a copy of the GNU General Public License
27384 + * along with this program; if not, write to the Free Software
27385 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27389 + * workqueue for asynchronous/super-io/delegated operations
27394 +#include <linux/module.h>
27397 +struct au_wkq *au_wkq;
27400 +#ifdef CONFIG_AUFS_DLGT
27401 + struct cred *cred;
27402 +#if 0 /* reserved for future use */
27403 + unsigned keep_capabilities:1;
27404 + struct user_struct *user;
27405 + struct fs_struct *fs;
27406 + struct nsproxy *nsproxy;
27411 +struct au_wkinfo {
27412 + struct work_struct wk;
27413 + struct super_block *sb;
27415 + unsigned int flags;
27416 + struct au_cred cred;
27418 + au_wkq_func_t func;
27422 + struct completion *comp;
27425 +/* ---------------------------------------------------------------------- */
27427 +#ifdef CONFIG_AUFS_DLGT
27428 +static void cred_store(struct au_cred *cred)
27430 + cred = get_current_cred();
27433 +static void cred_revert(struct au_cred *cred)
27435 + AuDebugOn(!au_test_wkq(current));
27436 + revert_creds(cred);
27439 +static void cred_switch(struct au_cred *old, struct au_cred *new)
27442 + cred_revert(new);
27445 +static void dlgt_cred_store(unsigned int flags, struct au_wkinfo *wkinfo)
27447 + if (au_ftest_wkq(flags, DLGT))
27448 + cred_store(&wkinfo->cred);
27451 +static void dlgt_func(struct au_wkinfo *wkinfo)
27453 + if (!au_ftest_wkq(wkinfo->flags, DLGT))
27454 + wkinfo->func(wkinfo->args);
27456 + struct au_cred cred;
27457 + cred_switch(&cred, &wkinfo->cred);
27458 + wkinfo->func(wkinfo->args);
27459 + cred_revert(&cred);
27463 +static void dlgt_cred_store(unsigned int flags, struct au_wkinfo *wkinfo)
27468 +static void dlgt_func(struct au_wkinfo *wkinfo)
27470 + wkinfo->func(wkinfo->args);
27472 +#endif /* CONFIG_AUFS_DLGT */
27474 +/* ---------------------------------------------------------------------- */
27476 +static void update_busy(struct au_wkq *wkq, struct au_wkinfo *wkinfo)
27478 +#ifdef CONFIG_AUFS_STAT
27479 + unsigned int new, old;
27482 + new = atomic_read(wkinfo->busyp);
27483 + old = wkq->max_busy;
27486 + } while (cmpxchg(&wkq->max_busy, old, new) == old);
27490 +static int enqueue(struct au_wkq *wkq, struct au_wkinfo *wkinfo)
27494 + wkinfo->busyp = &wkq->busy;
27495 + update_busy(wkq, wkinfo);
27496 + if (au_ftest_wkq(wkinfo->flags, WAIT))
27497 + return !queue_work(wkq->q, &wkinfo->wk);
27499 + return !schedule_work(&wkinfo->wk);
27502 +static void do_wkq(struct au_wkinfo *wkinfo)
27504 + unsigned int idle, n;
27510 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
27513 + for (i = 0; i < aufs_nwkq; i++) {
27514 + n = atomic_inc_return(&au_wkq[i].busy);
27515 + if (n == 1 && !enqueue(au_wkq + i, wkinfo))
27516 + return; /* success */
27522 + atomic_dec_return(&au_wkq[i].busy);
27525 + idle_idx = aufs_nwkq;
27527 + atomic_inc_return(&au_wkq[idle_idx].busy);
27528 + if (!enqueue(au_wkq + idle_idx, wkinfo))
27529 + return; /* success */
27531 + /* impossible? */
27532 + AuWarn1("failed to queue_work()\n");
27537 +static void wkq_func(struct work_struct *wk)
27539 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
27541 + LKTRTrace("wkinfo{0x%x, %p, %p, %p}\n",
27542 + wkinfo->flags, wkinfo->func, wkinfo->busyp, wkinfo->comp);
27544 + dlgt_func(wkinfo);
27545 + atomic_dec_return(wkinfo->busyp);
27546 + if (au_ftest_wkq(wkinfo->flags, WAIT))
27547 + complete(wkinfo->comp);
27549 + kobject_put(&au_sbi(wkinfo->sb)->si_kobj);
27550 + module_put(THIS_MODULE);
27555 +#if defined(CONFIG_4KSTACKS) || defined(Test4KSTACKS)
27556 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
27558 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
27560 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
27562 + init_completion(*comp);
27563 + wkinfo->comp = *comp;
27569 +static void au_wkq_comp_free(struct completion *comp)
27577 +#define AuWkqCompDeclare(name) \
27578 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
27579 + struct completion *comp = &_ ## name
27581 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
27583 + wkinfo->comp = *comp;
27587 +static void au_wkq_comp_free(struct completion *comp)
27591 +#endif /* 4KSTACKS */
27593 +static void au_wkq_run(struct au_wkinfo *wkinfo)
27595 +#if 1 /* tmp debug */
27596 + if (au_test_wkq(current))
27597 + au_dbg_blocked();
27599 + AuDebugOn(au_test_wkq(current));
27601 + INIT_WORK(&wkinfo->wk, wkq_func);
27602 + dlgt_cred_store(wkinfo->flags, wkinfo);
27606 +int au_wkq_wait(au_wkq_func_t func, void *args, int dlgt)
27609 + AuWkqCompDeclare(comp);
27610 + struct au_wkinfo wkinfo = {
27611 + .flags = AuWkq_WAIT,
27616 + LKTRTrace("dlgt %d\n", dlgt);
27618 + err = au_wkq_comp_alloc(&wkinfo, &comp);
27621 + au_fset_wkq(wkinfo.flags, DLGT);
27622 + au_wkq_run(&wkinfo);
27623 + /* no timeout, no interrupt */
27624 + wait_for_completion(wkinfo.comp);
27625 + au_wkq_comp_free(comp);
27633 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
27637 + struct au_wkinfo *wkinfo;
27639 + LKTRTrace("dlgt %d\n", dlgt);
27642 + atomic_inc_return(&au_sbi(sb)->si_nowait.nw_len);
27645 + * wkq_func() must free this wkinfo.
27646 + * it highly depends upon the implementation of workqueue.
27649 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
27652 + wkinfo->flags = !AuWkq_WAIT;
27653 + wkinfo->func = func;
27654 + wkinfo->args = args;
27655 + wkinfo->comp = NULL;
27657 + au_fset_wkq(wkinfo->flags, DLGT);
27658 + kobject_get(&au_sbi(sb)->si_kobj);
27659 + __module_get(THIS_MODULE);
27661 + au_wkq_run(wkinfo);
27664 + atomic_dec_return(&au_sbi(sb)->si_nowait.nw_len);
27671 +/* ---------------------------------------------------------------------- */
27673 +void au_wkq_fin(void)
27679 + for (i = 0; i < aufs_nwkq; i++)
27680 + if (au_wkq[i].q && !IS_ERR(au_wkq[i].q))
27681 + destroy_workqueue(au_wkq[i].q);
27685 +int __init au_wkq_init(void)
27688 + struct au_wkq *nowaitq;
27690 + LKTRTrace("%d\n", aufs_nwkq);
27692 + /* '+1' is for accounting of nowait queue */
27694 + au_wkq = kcalloc(aufs_nwkq + 1, sizeof(*au_wkq), GFP_NOFS);
27695 + if (unlikely(!au_wkq))
27699 + for (i = 0; i < aufs_nwkq; i++) {
27700 + au_wkq[i].q = create_singlethread_workqueue(AUFS_WKQ_NAME);
27701 + if (au_wkq[i].q && !IS_ERR(au_wkq[i].q)) {
27702 + atomic_set(&au_wkq[i].busy, 0);
27703 + au_wkq_max_busy_init(au_wkq + i);
27707 + err = PTR_ERR(au_wkq[i].q);
27712 + /* nowait accounting */
27713 + nowaitq = au_wkq + aufs_nwkq;
27714 + atomic_set(&nowaitq->busy, 0);
27715 + au_wkq_max_busy_init(nowaitq);
27716 + nowaitq->q = NULL;
27717 + /* smp_mb(); */ /* atomic_set */
27723 diff -urN linux/fs/aufs/wkq.h linux-aufs/fs/aufs/wkq.h
27724 --- linux/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
27725 +++ linux-aufs/fs/aufs/wkq.h 2009-03-12 16:18:04.000000000 +0100
27728 + * Copyright (C) 2005-2009 Junjiro Okajima
27730 + * This program, aufs is free software; you can redistribute it and/or modify
27731 + * it under the terms of the GNU General Public License as published by
27732 + * the Free Software Foundation; either version 2 of the License, or
27733 + * (at your option) any later version.
27735 + * This program is distributed in the hope that it will be useful,
27736 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27737 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27738 + * GNU General Public License for more details.
27740 + * You should have received a copy of the GNU General Public License
27741 + * along with this program; if not, write to the Free Software
27742 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27746 + * workqueue for asynchronous/super-io/delegated operations
27751 +#ifndef __AUFS_WKQ_H__
27752 +#define __AUFS_WKQ_H__
27756 +#include <linux/fs.h>
27757 +#include <linux/sched.h>
27758 +#include <linux/workqueue.h>
27759 +#include <linux/aufs_type.h>
27761 +/* ---------------------------------------------------------------------- */
27763 +/* internal workqueue named AUFS_WKQ_NAME */
27765 + struct workqueue_struct *q;
27771 +#ifdef CONFIG_AUFS_STAT
27772 + unsigned int max_busy;
27777 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
27779 +struct au_nowait_tasks {
27781 + wait_queue_head_t nw_wq;
27784 +/* ---------------------------------------------------------------------- */
27786 +extern struct au_wkq *au_wkq;
27787 +typedef void (*au_wkq_func_t)(void *args);
27790 +#define AuWkq_WAIT 1
27791 +#define AuWkq_DLGT (1 << 1)
27792 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
27793 +#define au_fset_wkq(flags, name) { (flags) |= AuWkq_##name; }
27794 +#define au_fclr_wkq(flags, name) { (flags) &= ~AuWkq_##name; }
27795 +#ifndef CONFIG_AUFS_DLGT
27797 +#define AuWkq_DLGT 0
27800 +int au_wkq_wait(au_wkq_func_t func, void *args, int dlgt);
27801 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
27803 +int __init au_wkq_init(void);
27804 +void au_wkq_fin(void);
27806 +/* ---------------------------------------------------------------------- */
27808 +static inline int au_test_nowait_wkq(struct task_struct *tsk)
27810 + static const char *p = "events";
27811 + return !tsk->mm && !strncmp(tsk->comm, p, strlen(p));
27814 +static inline int au_test_wkq(struct task_struct *tsk)
27816 + return !tsk->mm && !strcmp(tsk->comm, AUFS_WKQ_NAME);
27817 +#if 0 /* reserved for future use, per-cpu workqueue */
27819 + && !memcmp(tsk->comm, AUFS_WKQ_NAME "/",
27820 + sizeof(AUFS_WKQ_NAME));
27824 +static inline void au_wkq_max_busy_init(struct au_wkq *wkq)
27826 +#ifdef CONFIG_AUFS_STAT
27827 + wkq->max_busy = 0;
27831 +/* todo: memory barrier? */
27832 +static inline void au_nwt_init(struct au_nowait_tasks *nwt)
27834 + atomic_set(&nwt->nw_len, 0);
27835 + smp_mb(); /* atomic_set */
27836 + init_waitqueue_head(&nwt->nw_wq);
27839 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
27843 + if (!atomic_dec_return(&nwt->nw_len))
27844 + wake_up_all(&nwt->nw_wq);
27847 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
27849 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
27853 +#endif /* __KERNEL__ */
27854 +#endif /* __AUFS_WKQ_H__ */
27855 diff -urN linux/fs/aufs/xino.c linux-aufs/fs/aufs/xino.c
27856 --- linux/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
27857 +++ linux-aufs/fs/aufs/xino.c 2009-03-12 16:18:04.000000000 +0100
27860 + * Copyright (C) 2005-2009 Junjiro Okajima
27862 + * This program, aufs is free software; you can redistribute it and/or modify
27863 + * it under the terms of the GNU General Public License as published by
27864 + * the Free Software Foundation; either version 2 of the License, or
27865 + * (at your option) any later version.
27867 + * This program is distributed in the hope that it will be useful,
27868 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27869 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27870 + * GNU General Public License for more details.
27872 + * You should have received a copy of the GNU General Public License
27873 + * along with this program; if not, write to the Free Software
27874 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27878 + * external inode number translation table and bitmap
27883 +#include <linux/uaccess.h>
27886 +/* ---------------------------------------------------------------------- */
27888 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
27892 + mm_segment_t oldfs;
27894 + LKTRTrace("%.*s, sz %zu, *pos %lld\n",
27895 + AuDLNPair(file->f_dentry), size, *pos);
27897 + oldfs = get_fs();
27898 + set_fs(KERNEL_DS);
27900 + /* todo: signal_pending? */
27901 + err = func(file, (char __user *)buf, size, pos);
27902 + } while (err == -EAGAIN || err == -EINTR);
27905 +#if 0 /* reserved for future use */
27907 + fsnotify_access(file->f_dentry);
27914 +/* ---------------------------------------------------------------------- */
27916 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *buf,
27917 + size_t size, loff_t *pos)
27920 + mm_segment_t oldfs;
27923 + oldfs = get_fs();
27924 + set_fs(KERNEL_DS);
27926 + /* todo: signal_pending? */
27927 + err = func(file, (const char __user *)buf, size, pos);
27928 + } while (err == -EAGAIN || err == -EINTR);
27933 + au_update_fuse_h_inode(file->f_vfsmnt, file->f_dentry);
27936 +#if 0 /* reserved for future use */
27938 + fsnotify_modify(file->f_dentry);
27945 +struct do_xino_fwrite_args {
27947 + au_writef_t func;
27948 + struct file *file;
27954 +static void call_do_xino_fwrite(void *args)
27956 + struct do_xino_fwrite_args *a = args;
27957 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
27960 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
27965 + LKTRTrace("%.*s, sz %zu, *pos %lld\n",
27966 + AuDLNPair(file->f_dentry), size, *pos);
27968 + /* todo: signal block and no wkq? */
27970 + * it breaks RLIMIT_FSIZE and normal user's limit,
27971 + * users should care about quota and real 'filesystem full.'
27973 + if (!au_test_wkq(current)) {
27975 + struct do_xino_fwrite_args args = {
27983 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args, /*dlgt*/0);
27984 + if (unlikely(wkq_err))
27987 + err = do_xino_fwrite(func, file, buf, size, pos);
27993 +/* ---------------------------------------------------------------------- */
27995 +struct xino_do_trunc_args {
27996 + struct super_block *sb;
27997 + struct au_branch *br;
28000 +static void xino_do_trunc(void *_args)
28002 + struct xino_do_trunc_args *args = _args;
28003 + struct super_block *sb;
28004 + aufs_bindex_t bindex;
28006 + struct file *file;
28007 + struct inode *dir;
28008 + struct au_sbinfo *sbinfo;
28012 + dir = sb->s_root->d_inode;
28013 + si_noflush_write_lock(sb);
28014 + ii_read_lock_parent(dir);
28015 + bindex = au_br_index(sb, args->br->br_id);
28016 + AuDebugOn(bindex < 0);
28017 + err = au_xino_trunc(sb, bindex);
28018 + if (unlikely(err))
28021 + file = args->br->br_xino.xi_file;
28022 + au_update_fuse_h_inode(args->br->br_mnt, file->f_dentry); /*ignore*/
28023 + if (file->f_dentry->d_inode->i_blocks >= args->br->br_xino_upper)
28024 + args->br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
28027 + ii_read_unlock(dir);
28028 + if (unlikely(err))
28029 + AuWarn("err b%d, (%d)\n", bindex, err);
28030 + atomic_dec_return(&args->br->br_xino_running);
28031 + au_br_put(args->br);
28032 + sbinfo = au_sbi(sb);
28033 + au_nwt_done(&sbinfo->si_nowait);
28034 + si_write_unlock(sb);
28038 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
28040 + struct xino_do_trunc_args *args;
28041 + struct au_sbinfo *sbinfo;
28042 + struct file *file = br->br_xino.xi_file;
28045 + au_update_fuse_h_inode(br->br_mnt, file->f_dentry); /*ignore*/
28046 + if (file->f_dentry->d_inode->i_blocks < br->br_xino_upper)
28048 + if (atomic_inc_return(&br->br_xino_running) > 1)
28051 + /* lock and kfree() will be called in trunc_xino() */
28052 + args = kmalloc(sizeof(*args), GFP_NOFS);
28053 + if (unlikely(!args)) {
28054 + AuErr1("no memory\n");
28058 + sbinfo = au_sbi(sb);
28062 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*dlgt*/0);
28064 + return; /* success */
28066 + AuErr("wkq %d\n", wkq_err);
28072 + atomic_dec_return(&br->br_xino_running);
28075 +/* ---------------------------------------------------------------------- */
28077 +static int au_xino_do_write(au_writef_t write, struct file *file,
28078 + ino_t h_ino, struct au_xino_entry *xinoe)
28086 + if (unlikely(Au_LOFF_MAX / sizeof(*xinoe) - 1 < pos)) {
28087 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
28090 + pos *= sizeof(*xinoe);
28091 + sz = xino_fwrite(write, file, xinoe, sizeof(*xinoe), &pos);
28092 + if (sz == sizeof(*xinoe))
28093 + return 0; /* success */
28095 + AuIOErr("write failed (%zd)\n", sz);
28100 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
28101 + * at the position of @_ino.
28102 + * when @ino is zero, it is written to the xinofile and means no entry.
28104 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
28105 + struct au_xino_entry *xinoe)
28108 + struct file *file;
28109 + struct au_branch *br;
28110 + unsigned int mnt_flags;
28112 + LKTRTrace("b%d, hi%lu, i%lu\n",
28113 + bindex, (unsigned long)h_ino, (unsigned long)xinoe->ino);
28114 + BUILD_BUG_ON(sizeof(long long) != sizeof(Au_LOFF_MAX)
28115 + || ((loff_t)-1) > 0);
28117 + mnt_flags = au_mntflags(sb);
28118 + if (!au_opt_test_xino(mnt_flags))
28121 + br = au_sbr(sb, bindex);
28122 + file = br->br_xino.xi_file;
28123 + AuDebugOn(!file);
28125 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, h_ino, xinoe);
28127 + if (au_opt_test(mnt_flags, TRUNC_XINO)
28128 + && au_test_trunc_xino(br->br_mnt->mnt_sb))
28129 + xino_try_trunc(sb, br);
28130 + return 0; /* success */
28133 + AuIOErr("write failed (%d)\n", err);
28137 +/* ---------------------------------------------------------------------- */
28139 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
28140 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
28144 + AuDebugOn(bit < 0 || page_bits <= bit);
28145 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
28149 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
28151 + AuDebugOn(ino < AUFS_FIRST_INO);
28152 + ino -= AUFS_FIRST_INO;
28153 + *pindex = ino / page_bits;
28154 + *bit = ino % page_bits;
28157 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
28160 + struct au_sbinfo *sbinfo;
28163 + struct file *xib;
28164 + unsigned long *p;
28166 + LKTRTrace("pindex %lu\n", pindex);
28167 + sbinfo = au_sbi(sb);
28168 + MtxMustLock(&sbinfo->si_xib_mtx);
28169 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
28170 + || !au_opt_test_xino(sbinfo->si_mntflags));
28172 + if (pindex == sbinfo->si_xib_last_pindex)
28175 + xib = sbinfo->si_xib;
28176 + p = sbinfo->si_xib_buf;
28177 + pos = sbinfo->si_xib_last_pindex;
28178 + pos *= PAGE_SIZE;
28179 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
28180 + if (unlikely(sz != PAGE_SIZE))
28184 + pos *= PAGE_SIZE;
28185 + if (i_size_read(xib->f_dentry->d_inode) >= pos + PAGE_SIZE)
28186 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
28188 + memset(p, 0, PAGE_SIZE);
28189 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
28191 + if (sz == PAGE_SIZE) {
28192 + sbinfo->si_xib_last_pindex = pindex;
28193 + return 0; /* success */
28197 + AuIOErr1("write failed (%zd)\n", sz);
28205 +/* ---------------------------------------------------------------------- */
28207 +int au_xino_write0(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
28211 + unsigned long pindex;
28212 + struct au_sbinfo *sbinfo;
28213 + struct au_xino_entry xinoe = {
28217 + LKTRTrace("b%d, hi%lu, i%lu\n",
28218 + bindex, (unsigned long)h_ino, (unsigned long)ino);
28220 + if (!au_opt_test_xino(au_mntflags(sb)))
28224 + sbinfo = au_sbi(sb);
28226 + AuDebugOn(ino < AUFS_FIRST_INO);
28227 + xib_calc_bit(ino, &pindex, &bit);
28228 + AuDebugOn(page_bits <= bit);
28229 + mutex_lock(&sbinfo->si_xib_mtx);
28230 + err = xib_pindex(sb, pindex);
28232 + clear_bit(bit, sbinfo->si_xib_buf);
28233 + sbinfo->si_xib_next_bit = bit;
28235 + mutex_unlock(&sbinfo->si_xib_mtx);
28239 + err = au_xino_write(sb, bindex, h_ino, &xinoe);
28243 +ino_t au_xino_new_ino(struct super_block *sb)
28246 + struct au_sbinfo *sbinfo;
28247 + int free_bit, err;
28248 + unsigned long *p, pindex, ul, pend;
28249 + struct file *file;
28253 + if (!au_opt_test_xino(au_mntflags(sb)))
28254 + return iunique(sb, AUFS_FIRST_INO);
28256 + sbinfo = au_sbi(sb);
28257 + mutex_lock(&sbinfo->si_xib_mtx);
28258 + p = sbinfo->si_xib_buf;
28259 + free_bit = sbinfo->si_xib_next_bit;
28260 + if (free_bit < page_bits && !test_bit(free_bit, p))
28261 + goto out; /* success */
28262 + free_bit = find_first_zero_bit(p, page_bits);
28263 + if (free_bit < page_bits)
28264 + goto out; /* success */
28266 + pindex = sbinfo->si_xib_last_pindex;
28267 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
28268 + err = xib_pindex(sb, ul);
28269 + if (unlikely(err))
28271 + free_bit = find_first_zero_bit(p, page_bits);
28272 + if (free_bit < page_bits)
28273 + goto out; /* success */
28276 + file = sbinfo->si_xib;
28277 + pend = i_size_read(file->f_dentry->d_inode) / PAGE_SIZE;
28278 + for (ul = pindex + 1; ul <= pend; ul++) {
28279 + err = xib_pindex(sb, ul);
28280 + if (unlikely(err))
28282 + free_bit = find_first_zero_bit(p, page_bits);
28283 + if (free_bit < page_bits)
28284 + goto out; /* success */
28289 + set_bit(free_bit, p);
28290 + sbinfo->si_xib_next_bit++;
28291 + pindex = sbinfo->si_xib_last_pindex;
28292 + mutex_unlock(&sbinfo->si_xib_mtx);
28293 + ino = xib_calc_ino(pindex, free_bit);
28294 + LKTRTrace("i%lu\n", (unsigned long)ino);
28297 + mutex_unlock(&sbinfo->si_xib_mtx);
28298 + LKTRTrace("i0\n");
28303 + * read @ino from xinofile for the specified branch{@sb, @bindex}
28304 + * at the position of @h_ino.
28305 + * if @ino does not exist and @do_new is true, get new one.
28307 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
28308 + struct au_xino_entry *xinoe)
28311 + struct file *file;
28314 + struct au_sbinfo *sbinfo;
28316 + LKTRTrace("b%d, hi%lu\n", bindex, (unsigned long)h_ino);
28319 + if (!au_opt_test_xino(au_mntflags(sb)))
28320 + return 0; /* no ino */
28323 + sbinfo = au_sbi(sb);
28325 + if (unlikely(Au_LOFF_MAX / sizeof(*xinoe) - 1 < pos)) {
28326 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
28329 + pos *= sizeof(*xinoe);
28331 + file = au_sbr(sb, bindex)->br_xino.xi_file;
28332 + AuDebugOn(!file);
28333 + if (i_size_read(file->f_dentry->d_inode) < pos + sizeof(*xinoe))
28334 + return 0; /* no ino */
28336 + sz = xino_fread(sbinfo->si_xread, file, xinoe, sizeof(*xinoe), &pos);
28337 + if (sz == sizeof(*xinoe))
28338 + return 0; /* success */
28341 + if (unlikely(sz >= 0)) {
28343 + AuIOErr("xino read error (%zd)\n", sz);
28350 +/* ---------------------------------------------------------------------- */
28352 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
28354 + struct file *file;
28356 + struct dentry *h_parent;
28357 + struct inode *h_dir;
28358 + struct vfsub_args vargs;
28360 + LKTRTrace("%s\n", fname);
28363 + * at mount-time, and the xino file is the default path,
28364 + * hinotify is disabled so we have no inotify events to ignore.
28365 + * when a user specified the xino, we cannot get au_hdir to be ignored.
28367 + vfsub_args_init(&vargs, /*ign*/NULL, /*dlgt*/0, 0);
28368 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE,
28369 + S_IRUGO | S_IWUGO);
28370 + if (IS_ERR(file)) {
28372 + AuErr("open %s(%ld)\n", fname, PTR_ERR(file));
28376 + /* keep file count */
28377 + h_parent = dget_parent(file->f_dentry);
28378 + h_dir = h_parent->d_inode;
28379 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
28380 + /* mnt_want_write() is unnecessary here */
28381 + err = vfsub_unlink(h_dir, file->f_dentry, &vargs);
28382 + mutex_unlock(&h_dir->i_mutex);
28384 + if (unlikely(err)) {
28386 + AuErr("unlink %s(%d)\n", fname, err);
28390 + if (sb != file->f_dentry->d_sb)
28391 + return file; /* success */
28394 + AuErr("%s must be outside\n", fname);
28399 + file = ERR_PTR(err);
28404 + * find another branch who is on the same filesystem of the specified
28405 + * branch{@btgt}. search until @bend.
28407 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
28408 + aufs_bindex_t bend)
28410 + aufs_bindex_t bindex;
28411 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
28413 + for (bindex = 0; bindex < btgt; bindex++)
28414 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
28416 + for (bindex++; bindex <= bend; bindex++)
28417 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
28423 + * create a new xinofile at the same place/path as @base_file.
28425 +struct file *au_xino_create2(struct super_block *sb, struct file *base_file,
28426 + struct file *copy_src)
28428 + struct file *file;
28430 + struct dentry *base, *dentry, *parent;
28431 + struct inode *dir, *inode;
28432 + struct qstr *name;
28433 + struct au_hinode *hdir;
28434 + struct au_branch *br;
28435 + aufs_bindex_t bindex;
28436 + struct au_hin_ignore ign;
28437 + struct vfsub_args vargs;
28438 + struct au_ndx ndx = {
28445 + base = base_file->f_dentry;
28446 + LKTRTrace("%.*s\n", AuDLNPair(base));
28447 + parent = base->d_parent; /* dir inode is locked */
28448 + dir = parent->d_inode;
28451 + file = ERR_PTR(-EINVAL);
28452 + if (unlikely(au_test_nfs(parent->d_sb)
28453 + || au_test_ecryptfs(parent->d_sb)))
28456 + /* do not superio, nor NFS. */
28457 + name = &base->d_name;
28458 + dentry = au_lkup_one(name->name, parent, name->len, &ndx);
28459 + if (IS_ERR(dentry)) {
28460 + file = (void *)dentry;
28461 + AuErr("%.*s lookup err %ld\n", AuLNPair(name), PTR_ERR(dentry));
28466 + br = au_xino_def_br(au_sbi(sb));
28468 + bindex = au_find_bindex(sb, br);
28470 + hdir = au_hi(sb->s_root->d_inode, bindex);
28472 + vfsub_args_init(&vargs, &ign, 0, 0);
28473 + vfsub_ign_hinode(&vargs, IN_CREATE, hdir);
28474 + /* no need to mnt_want_write() since we call dentry_open() later */
28475 + err = vfsub_create(dir, dentry, S_IRUGO | S_IWUGO, NULL, &vargs);
28476 + if (unlikely(err)) {
28477 + file = ERR_PTR(err);
28478 + AuErr("%.*s create err %d\n", AuLNPair(name), err);
28481 + file = dentry_open(dget(dentry), mntget(base_file->f_vfsmnt),
28482 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, base_file->f_cred);
28483 + if (IS_ERR(file)) {
28484 + AuErr("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
28487 + vfsub_args_reinit(&vargs);
28488 + vfsub_ign_hinode(&vargs, IN_DELETE, hdir);
28489 + err = vfsub_unlink(dir, dentry, &vargs);
28490 + if (unlikely(err)) {
28491 + AuErr("%.*s unlink err %d\n", AuLNPair(name), err);
28496 + inode = copy_src->f_dentry->d_inode;
28497 + err = au_copy_file(file, copy_src, i_size_read(inode),
28498 + hdir, sb, &vargs);
28499 + if (unlikely(err)) {
28500 + AuErr("%.*s copy err %d\n", AuLNPair(name), err);
28504 + goto out_dput; /* success */
28508 + file = ERR_PTR(err);
28512 + AuTraceErrPtr(file);
28516 +/* ---------------------------------------------------------------------- */
28519 + * initialize the xinofile for the specified branch{@sb, @bindex}
28520 + * at the place/path where @base_file indicates.
28521 + * test whether another branch is on the same filesystem or not,
28522 + * if @do_test is true.
28524 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
28525 + struct file *base_file, int do_test)
28528 + struct au_branch *shared_br;
28529 + aufs_bindex_t bshared, bend, bindex;
28530 + unsigned char do_create;
28531 + struct inode *dir;
28532 + struct au_xino_entry xinoe;
28533 + struct dentry *parent;
28534 + struct file *file;
28535 + struct super_block *tgt_sb;
28537 + LKTRTrace("base_file %p, do_test %d\n", base_file, do_test);
28538 + SiMustWriteLock(sb);
28539 + AuDebugOn(!au_opt_test_xino(au_mntflags(sb)));
28540 + AuDebugOn(br->br_xino.xi_file);
28544 + shared_br = NULL;
28545 + bend = au_sbend(sb);
28547 + tgt_sb = br->br_mnt->mnt_sb;
28548 + for (bindex = 0; bindex <= bend; bindex++)
28549 + if (tgt_sb == au_sbr_sb(sb, bindex)) {
28550 + bshared = bindex;
28554 + if (bshared >= 0) {
28555 + shared_br = au_sbr(sb, bshared);
28556 + do_create = !shared_br->br_xino.xi_file;
28560 + parent = dget_parent(base_file->f_dentry);
28561 + dir = parent->d_inode;
28562 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
28563 + /* mnt_want_write() is unnecessary here */
28564 + file = au_xino_create2(sb, base_file, NULL);
28565 + mutex_unlock(&dir->i_mutex);
28567 + err = PTR_ERR(file);
28568 + if (IS_ERR(file))
28570 + br->br_xino.xi_file = file;
28572 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
28573 + get_file(br->br_xino.xi_file);
28576 + xinoe.ino = AUFS_ROOT_INO;
28577 +#if 0 /* reserved for future use */
28578 + xinoe.h_gen = h_inode->i_generation;
28579 + WARN_ON(xinoe.h_gen == AuXino_INVALID_HGEN);
28581 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
28584 + return 0; /* success */
28593 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
28596 + struct au_sbinfo *sbinfo;
28598 + loff_t pos, pend;
28600 + struct au_xino_entry *xinoe;
28601 + unsigned long pindex;
28604 + SiMustWriteLock(sb);
28607 + sbinfo = au_sbi(sb);
28608 + func = sbinfo->si_xread;
28609 + pend = i_size_read(file->f_dentry->d_inode);
28610 +#ifdef CONFIG_AUFS_DEBUG
28611 + if (unlikely(pend > (1 << 22)))
28612 + AuWarn("testing a large xino file %lld\n", (long long)pend);
28615 + while (pos < pend) {
28616 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
28618 + if (unlikely(sz <= 0))
28622 + for (xinoe = page; sz > 0; xinoe++, sz -= sizeof(xinoe)) {
28623 + if (unlikely(xinoe->ino < AUFS_FIRST_INO))
28626 + xib_calc_bit(xinoe->ino, &pindex, &bit);
28627 + AuDebugOn(page_bits <= bit);
28628 + err = xib_pindex(sb, pindex);
28630 + set_bit(bit, sbinfo->si_xib_buf);
28641 +static int xib_restore(struct super_block *sb)
28644 + aufs_bindex_t bindex, bend;
28650 + page = (void *)__get_free_page(GFP_NOFS);
28651 + if (unlikely(!page))
28655 + bend = au_sbend(sb);
28656 + for (bindex = 0; !err && bindex <= bend; bindex++)
28657 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
28658 + err = do_xib_restore
28659 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
28661 + LKTRTrace("b%d\n", bindex);
28662 + free_page((unsigned long)page);
28669 +int au_xib_trunc(struct super_block *sb)
28672 + unsigned int mnt_flags;
28675 + struct au_sbinfo *sbinfo;
28676 + unsigned long *p;
28677 + struct dentry *parent;
28678 + struct inode *dir;
28679 + struct file *file;
28682 + SiMustWriteLock(sb);
28685 + mnt_flags = au_mntflags(sb);
28686 + if (!au_opt_test_xino(mnt_flags))
28689 + sbinfo = au_sbi(sb);
28690 + if (i_size_read(sbinfo->si_xib->f_dentry->d_inode) <= PAGE_SIZE)
28692 + parent = dget_parent(sbinfo->si_xib->f_dentry);
28693 + dir = parent->d_inode;
28694 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
28695 + /* mnt_want_write() is unnecessary here */
28696 + file = au_xino_create2(sb, sbinfo->si_xib, NULL);
28697 + mutex_unlock(&dir->i_mutex);
28699 + err = PTR_ERR(file);
28700 + if (IS_ERR(file))
28702 + fput(sbinfo->si_xib);
28703 + sbinfo->si_xib = file;
28705 + p = sbinfo->si_xib_buf;
28706 + memset(p, 0, PAGE_SIZE);
28708 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
28709 + if (unlikely(sz != PAGE_SIZE)) {
28711 + AuIOErr("err %d\n", err);
28717 + if (au_opt_test_xino(mnt_flags)) {
28718 + mutex_lock(&sbinfo->si_xib_mtx);
28719 + /* mnt_want_write() is unnecessary here */
28720 + err = xib_restore(sb);
28721 + mutex_unlock(&sbinfo->si_xib_mtx);
28722 +#if 0 /* reserved for future use */
28724 + /* is it really safe? */
28725 + /* dont trust BKL */
28726 + AuDebugOn(!kernel_locked());
28727 + ino = AUFS_FIRST_INO;
28728 + list_for_each_entry(inode, &sb->s_inodes, i_sb_list)
28729 + if (ino < inode->i_ino)
28730 + ino = inode->i_ino;
28732 + /* make iunique to return larger than active max inode number */
28733 + iunique(sb, ino);
28743 +/* ---------------------------------------------------------------------- */
28746 + * xino mount option handlers
28748 +static au_readf_t find_readf(struct file *h_file)
28750 + const struct file_operations *fop = h_file->f_op;
28754 + return fop->read;
28755 + if (fop->aio_read)
28756 + return do_sync_read;
28758 + return ERR_PTR(-ENOSYS);
28761 +static au_writef_t find_writef(struct file *h_file)
28763 + const struct file_operations *fop = h_file->f_op;
28767 + return fop->write;
28768 + if (fop->aio_write)
28769 + return do_sync_write;
28771 + return ERR_PTR(-ENOSYS);
28775 +static void xino_clear_xib(struct super_block *sb)
28777 + struct au_sbinfo *sbinfo;
28780 + SiMustWriteLock(sb);
28782 + sbinfo = au_sbi(sb);
28783 + sbinfo->si_xread = NULL;
28784 + sbinfo->si_xwrite = NULL;
28785 + if (sbinfo->si_xib)
28786 + fput(sbinfo->si_xib);
28787 + sbinfo->si_xib = NULL;
28788 + free_page((unsigned long)sbinfo->si_xib_buf);
28789 + sbinfo->si_xib_buf = NULL;
28792 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
28795 + struct au_sbinfo *sbinfo;
28796 + struct file *file;
28799 + LKTRTrace("%.*s\n", AuDLNPair(base->f_dentry));
28800 + SiMustWriteLock(sb);
28802 + sbinfo = au_sbi(sb);
28803 + file = au_xino_create2(sb, base, sbinfo->si_xib);
28804 + err = PTR_ERR(file);
28805 + if (IS_ERR(file))
28807 + if (sbinfo->si_xib)
28808 + fput(sbinfo->si_xib);
28809 + sbinfo->si_xib = file;
28810 + sbinfo->si_xread = find_readf(file);
28811 + AuDebugOn(IS_ERR(sbinfo->si_xread));
28812 + sbinfo->si_xwrite = find_writef(file);
28813 + AuDebugOn(IS_ERR(sbinfo->si_xwrite));
28816 + if (!sbinfo->si_xib_buf)
28817 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
28818 + if (unlikely(!sbinfo->si_xib_buf))
28821 + sbinfo->si_xib_last_pindex = 0;
28822 + sbinfo->si_xib_next_bit = 0;
28824 + /* no need to lock for i_size_read() */
28825 + if (i_size_read(file->f_dentry->d_inode) < PAGE_SIZE) {
28827 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
28828 + PAGE_SIZE, &pos);
28829 + if (unlikely(err != PAGE_SIZE))
28833 + goto out; /* success */
28836 + free_page((unsigned long)sbinfo->si_xib_buf);
28837 + sbinfo->si_xib_buf = NULL;
28841 + fput(sbinfo->si_xib);
28842 + sbinfo->si_xib = NULL;
28843 + sbinfo->si_xread = NULL;
28844 + sbinfo->si_xwrite = NULL;
28850 +/* xino for each branch */
28851 +static void xino_clear_br(struct super_block *sb)
28853 + aufs_bindex_t bindex, bend;
28854 + struct au_branch *br;
28857 + SiMustWriteLock(sb);
28859 + bend = au_sbend(sb);
28860 + for (bindex = 0; bindex <= bend; bindex++) {
28861 + br = au_sbr(sb, bindex);
28862 + if (!br || !br->br_xino.xi_file)
28865 + fput(br->br_xino.xi_file);
28866 + br->br_xino.xi_file = NULL;
28870 +static int au_xino_set_br(struct super_block *sb, struct file *base)
28873 + aufs_bindex_t bindex, bend, bshared;
28875 + struct file *old, *new;
28877 + struct au_branch *br;
28878 + struct au_xino_entry xinoe;
28879 + struct inode *inode;
28880 + au_writef_t writef;
28882 + LKTRTrace("%.*s\n", AuDLNPair(base->f_dentry));
28883 + SiMustWriteLock(sb);
28886 + bend = au_sbend(sb);
28887 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
28888 + if (unlikely(!fpair))
28891 + inode = sb->s_root->d_inode;
28892 + xinoe.ino = AUFS_ROOT_INO;
28893 + writef = au_sbi(sb)->si_xwrite;
28894 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
28895 + br = au_sbr(sb, bindex);
28896 + bshared = is_sb_shared(sb, bindex, bindex - 1);
28897 + if (bshared >= 0) {
28898 + /* shared xino */
28899 + *p = fpair[bshared];
28900 + get_file(p->new);
28905 + p->old = br->br_xino.xi_file;
28906 + p->new = au_xino_create2(sb, base, br->br_xino.xi_file);
28907 + err = PTR_ERR(p->new);
28908 + if (IS_ERR(p->new)) {
28914 + err = au_xino_do_write(writef, p->new,
28915 + au_h_iptr(inode, bindex)->i_ino, &xinoe);
28916 + if (unlikely(err))
28920 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
28921 + br = au_sbr(sb, bindex);
28922 + AuDebugOn(p->old != br->br_xino.xi_file);
28923 + if (br->br_xino.xi_file)
28924 + fput(br->br_xino.xi_file);
28925 + get_file(p->new);
28926 + br->br_xino.xi_file = p->new;
28930 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
28941 +void au_xino_clr(struct super_block *sb)
28943 + struct au_sbinfo *sbinfo;
28946 + SiMustWriteLock(sb);
28948 + au_xigen_clr(sb);
28949 + xino_clear_xib(sb);
28950 + xino_clear_br(sb);
28951 + sbinfo = au_sbi(sb);
28952 + /* lvalue, do not call au_mntflags() */
28953 + au_opt_clr(sbinfo->si_mntflags, XINO);
28954 + au_xino_def_br_set(NULL, sbinfo);
28957 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
28960 + struct dentry *parent, *cur_parent;
28961 + struct qstr *dname, *cur_name;
28962 + struct file *cur_xino;
28963 + struct inode *dir;
28964 + struct au_sbinfo *sbinfo;
28966 + LKTRTrace("remount %d\n", remount);
28967 + SiMustWriteLock(sb);
28970 + sbinfo = au_sbi(sb);
28971 + parent = dget_parent(xino->file->f_dentry);
28974 + dname = &xino->file->f_dentry->d_name;
28975 + cur_xino = sbinfo->si_xib;
28977 + cur_parent = dget_parent(cur_xino->f_dentry);
28978 + cur_name = &cur_xino->f_dentry->d_name;
28979 + skip = (cur_parent == parent
28980 + && dname->len == cur_name->len
28981 + && !memcmp(dname->name, cur_name->name,
28983 + dput(cur_parent);
28989 + au_opt_set(sbinfo->si_mntflags, XINO);
28990 + au_xino_def_br_set(NULL, sbinfo);
28991 + dir = parent->d_inode;
28992 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
28993 + /* mnt_want_write() is unnecessary here */
28994 + err = au_xino_set_xib(sb, xino->file);
28996 + err = au_xigen_set(sb, xino->file);
28998 + err = au_xino_set_br(sb, xino->file);
28999 + mutex_unlock(&dir->i_mutex);
29001 + goto out; /* success */
29004 + AuIOErr("failed creating xino(%d).\n", err);
29012 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
29015 + struct au_branch *br;
29016 + struct file *new_xino;
29017 + struct super_block *h_sb;
29018 + aufs_bindex_t bi, bend;
29019 + struct dentry *parent;
29020 + struct inode *dir;
29022 + LKTRTrace("b%d\n", bindex);
29023 + SiMustWriteLock(sb);
29026 + bend = au_sbend(sb);
29027 + if (unlikely(bindex < 0 || bend < bindex))
29029 + br = au_sbr(sb, bindex);
29030 + if (!br->br_xino.xi_file)
29033 + parent = dget_parent(br->br_xino.xi_file->f_dentry);
29034 + dir = parent->d_inode;
29035 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
29036 + /* mnt_want_write() is unnecessary here */
29037 + new_xino = au_xino_create2(sb, br->br_xino.xi_file,
29038 + br->br_xino.xi_file);
29039 + mutex_unlock(&dir->i_mutex);
29041 + err = PTR_ERR(new_xino);
29042 + if (IS_ERR(new_xino))
29045 + fput(br->br_xino.xi_file);
29046 + br->br_xino.xi_file = new_xino;
29048 + h_sb = br->br_mnt->mnt_sb;
29049 + for (bi = 0; bi <= bend; bi++) {
29050 + if (unlikely(bi == bindex))
29052 + br = au_sbr(sb, bi);
29053 + if (br->br_mnt->mnt_sb != h_sb)
29056 + fput(br->br_xino.xi_file);
29057 + br->br_xino.xi_file = new_xino;
29058 + get_file(new_xino);
29066 +/* ---------------------------------------------------------------------- */
29069 + * create a xinofile at the default place/path.
29071 +struct file *au_xino_def(struct super_block *sb)
29073 + struct file *file;
29074 + aufs_bindex_t bend, bindex, bwr;
29076 + struct path path;
29077 + struct au_branch *br;
29081 + bend = au_sbend(sb);
29083 + for (bindex = 0; bindex <= bend; bindex++) {
29084 + br = au_sbr(sb, bindex);
29085 + if (au_br_writable(br->br_perm)
29086 + && !au_test_nfs(br->br_mnt->mnt_sb)
29087 + && !au_test_ecryptfs(br->br_mnt->mnt_sb)) {
29094 + file = ERR_PTR(-ENOMEM);
29095 + page = __getname();
29096 + if (unlikely(!page))
29098 + path.mnt = au_sbr_mnt(sb, bwr);
29099 + path.dentry = au_h_dptr(sb->s_root, bwr);
29100 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
29101 + file = (void *)p;
29102 + if (!IS_ERR(p)) {
29103 + strcat(p, "/" AUFS_XINO_FNAME);
29104 + LKTRTrace("%s\n", p);
29105 + file = au_xino_create(sb, p, /*silent*/0);
29106 + if (!IS_ERR(file))
29107 + au_xino_def_br_set(au_sbr(sb, bwr), au_sbi(sb));
29111 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
29112 + if (unlikely(au_test_nfs(file->f_dentry->d_sb)
29113 + || au_test_ecryptfs(file->f_dentry->d_sb))) {
29114 + AuErr("xino or noxino option is required "
29115 + "since %s is NFS\n", AUFS_XINO_DEFPATH);
29117 + file = ERR_PTR(-EINVAL);
29119 + if (!IS_ERR(file))
29120 + au_xino_def_br_set(NULL, au_sbi(sb));
29124 + AuTraceErrPtr(file);
29127 diff -urN linux/fs/Kconfig linux-aufs/fs/Kconfig
29128 --- linux/fs/Kconfig 2009-01-05 11:42:15.000000000 +0100
29129 +++ linux-aufs/fs/Kconfig 2009-03-12 17:02:25.753047602 +0100
29130 @@ -1022,6 +1022,350 @@
29132 If you say Y here, you can turn on debugging output from Unionfs.
29135 + tristate "Another unionfs"
29137 + Aufs is a stackable unification filesystem such as Unionfs,
29138 + which unifies several directories and provides a merged single
29140 + In the early days, aufs was entirely re-designed and
29141 + re-implemented Unionfs Version 1.x series. After many original
29142 + ideas, approaches and improvements, it becomes totally
29143 + different from Unionfs while keeping the basic features.
29144 + See Unionfs for the basic features.
29147 +comment "These options are for "#UTS_RELEASE
29150 + prompt "Maximum number of branches"
29151 + default AUFS_BRANCH_MAX_127
29153 + Specifies the maximum number of branches (or member directories) in a
29154 + single aufs. The larger value consumes more system resources and has
29155 + an impact to performance.
29156 +config AUFS_BRANCH_MAX_127
29159 + Specifies the maximum number of branches (or member directories) in a
29160 + single aufs. The larger value consumes more system resources and has
29161 + an impact to performance.
29162 +config AUFS_BRANCH_MAX_511
29165 + Specifies the maximum number of branches (or member directories) in a
29166 + single aufs. The larger value consumes more system resources and has
29167 + an impact to performance.
29168 +config AUFS_BRANCH_MAX_1023
29171 + Specifies the maximum number of branches (or member directories) in a
29172 + single aufs. The larger value consumes more system resources and has
29173 + an impact to performance.
29174 +# 128kb is available for kmalloc?
29175 +config AUFS_BRANCH_MAX_32767
29178 + Specifies the maximum number of branches (or member directories) in a
29179 + single aufs. The larger value consumes more system resources and has
29180 + an impact to performance.
29184 + bool "Use <sysfs>/fs/aufs/stat"
29187 + Shows some statistic data via <sysfs>/fs/aufs/stat.
29188 + See detail in aufs.5.
29190 +comment "SYSFS and AUFS_STAT are disabled"
29191 + depends on SYSFS = n
29193 +config AUFS_HINOTIFY
29194 + bool "Use inotify to detect actions on a branch"
29195 + depends on INOTIFY
29197 + If you want to modify files on branches directly, eg. bypassing aufs,
29198 + and want aufs to detect the changes of them fully, then enable this
29199 + option and use 'udba=inotify' mount option.
29200 + It will have a negative impact to the performance.
29201 + See detail in aufs.5.
29203 +comment "INOTIFY and AUFS_HINOTIFY are disabled"
29204 + depends on INOTIFY = n
29206 +config AUFS_EXPORT
29207 + bool "NFS-exportable aufs"
29208 + depends on (AUFS = y && EXPORTFS = y) || (AUFS = m && EXPORTFS)
29210 + If you want to export your mounted aufs, then enable this
29211 + option. There are several requirements for this configuration.
29212 + See detail in aufs.5.
29214 +comment "EXPORTFS and AUFS_EXPORT are disabled"
29215 + depends on EXPORTFS = n
29217 +comment "AUFS_EXPORT is disabled since EXPORTFS is a module but AUFS"
29218 + depends on EXPORTFS = m && AUFS = y
29220 +# automatic configuration for internal use
29221 +config AUFS_INO_T_64
29222 + bool # never appear on the menu
29223 + # typedef unsigned long/int __kernel_ino_t
29224 + # alpha and s390x are int
29225 + depends on 64BIT && !(ALPHA || S390)
29229 + bool "Aufs as an readonly branch of another aufs mount"
29231 + If you want make your aufs to be a part of another aufs, then
29232 + enable this option. In other words, you can specify your aufs
29233 + path in 'br:' mount option for another aufs, but cannot
29234 + specify 'rw' as the branch permission.
29235 + It will have a negative impact to the performance.
29236 + See detail in aufs.5.
29239 + bool "Delegate the internal branch access the kernel thread"
29241 + If you want aufs to delegate
29242 + the internal access to the branches which is made by aufs, to
29243 + the kernel thread, in order to hide the access issued by your
29244 + application from your LSM or something or make your
29245 + application to be traced strictly by the task I/O accounting,
29246 + then enable this option and use 'dlgt' mount option.
29247 + It will have a negative impact to the performance.
29248 + See detail in aufs.5.
29250 +# automatic configuration for internal use
29251 +config AUFS_HIN_OR_DLGT
29252 + bool # never appear on the menu
29253 + depends on AUFS_HINOTIFY || AUFS_DLGT
29256 + Automatic configuration for internal use.
29259 + bool "Show whiteouts"
29261 + If you want to make the whiteouts in aufs visible, then enable
29262 + this option and specify 'shwh' mount option. Although it may
29263 + sounds like philosophy or something, but in technically it
29264 + simply shows the name of whiteout with keeping its behaviour.
29266 +# this is not in mainstream kernel
29267 +config AUFS_RR_SQUASHFS
29268 + bool "Make squashfs branch RR (real readonly) by default"
29271 + If you use squashfs or LZMA patched squashfs as an aufs branch
29272 + and want to set '=rr' to it by default, then enable this
29274 + 'rr' stands for real readonly and it optimizes some aspects of
29276 + See detail in aufs.5.
29278 +config AUFS_SEC_PERM_PATCH
29279 + bool "sec_perm-2.6.24.patch was applied or not"
29280 + depends on AUFS = m
29281 + depends on SECURITY
29283 + If you build aufs as a module and enabled CONFIG_SECURITY,
29284 + then you need to apply the patch
29285 + 'CVS_TREE/aufs/patch/sec_perm-2.6.24.patch' to your kernel
29286 + source, and enable this configuration.
29287 + The sec_perm-2.6.24.patch exports a kernel function
29288 + security_inode_permission() to modules.
29290 +comment "SECURITY and AUFS_SEC_PERM_PATCH are disabled"
29291 + depends on SECURITY = n
29293 +config AUFS_SPLICE_PATCH
29294 + bool "splice.patch for sendfile(2) and splice(2)"
29296 + If you use 'loopback mount' on a fs-image file, or use
29297 + splice(2) or sendfile(2) systemcall in aufs, then you need to
29298 + apply the patch 'CVS_TREE/aufs/patch/splice.patch' to your
29299 + kernel source, and enable this configuration.
29300 + The splice.patch makes the kernel function do_splice_to/from()
29301 + global and exports them to modules.
29303 +config AUFS_LHASH_PATCH
29304 + bool "lhash.patch for NFS branch"
29305 + depends on NFS_FS
29307 + If you use mounted NFS as an aufs branch filesystem, then you
29308 + need to apply the patch 'CVS_TREE/aufs/patch/lhash.patch' (or
29309 + lhash-2.6.22.patch for linux-2.6.22 and later) to your kernel
29310 + source, and enable this configuration.
29311 + The patch file makes the kernel function __lookup_hash() global
29312 + and exports it to modules.
29314 +comment "NFS_FS and AUFS_LHASH_PATCH are disabled"
29315 + depends on NFS_FS = n
29317 +config AUFS_PUT_FILP_PATCH
29318 + bool "put_filp.patch for 'atomic open'"
29319 + depends on AUFS = m && NFS_V4
29321 + If you build aufs as a module and use a filesystem which
29322 + operates 'atomic open' (for instance NFSv4) as an aufs branch
29323 + filesystem, then you need to apply the patch
29324 + 'CVS_TREE/aufs/patch/put_filp.patch' to your kernel source,
29325 + and enable this configuration.
29326 + The put_filp.patch exports a kernel function put_filp() to
29329 +comment "NFS_V4 and AUFS_PUT_FILP_PATCH are disabled"
29330 + depends on NFS_V4 = n
29332 +# automatic configuration for internal use
29333 +config AUFS_BR_NFS
29334 + bool # never appear on the menu
29335 + depends on NFS_FS
29336 + depends on AUFS_LHASH_PATCH
29339 + Automatic configuration for internal use.
29340 + When aufs supports NFS branch, enabled automatically.
29342 +config AUFS_BR_NFS_V4
29343 + bool # never appear on the menu
29344 + depends on NFS_V4 && AUFS_BR_NFS
29345 + depends on AUFS = y || (AUFS = m && AUFS_PUT_FILP_PATCH)
29348 + Automatic configuration for internal use.
29349 + When aufs supports a branch filesystem which operates
29350 + 'atomic_open', for instance NFSv4, this configuration is enabled
29353 +config AUFS_BR_XFS
29354 + bool # never appear on the menu
29355 + depends on XFS_FS
29358 + Automatic configuration for internal use.
29359 + When aufs supports XFS branch, enabled automatically.
29361 +config AUFS_FSYNC_SUPER_PATCH
29362 + bool "fsync_super-2.6.xx.patch was applied or not"
29363 + depends on AUFS = m
29365 + If you build aufs as a module and want to flush everything for
29366 + branch filesystems which are not marked as 'rr' nor 'rr+wh' at
29367 + umount or remount time, then you need to apply the patch
29368 + 'CVS_TREE/aufs/patch/fsync_super-2.6.16.patch' or
29369 + '...-2.6.19.patch' to your kernel source, and enable this
29371 + It may be helpful at shutdown time in case of your aufs is a
29372 + root filesystem. But this behaviour will not guarantee the
29373 + consistency of branch filesystems. To guarantee it, try the
29374 + approach described in the aufs manual, and do not forget
29375 + installing auplink script.
29376 + The fsync_super-2.6.xx.patch does nothing but exports a kernel
29377 + function fsync_super() to modules.
29379 +config AUFS_DENY_WRITE_ACCESS_PATCH
29380 + bool "deny_write_access.patch was applied or not"
29381 + depends on AUFS = m
29383 + A security enhancement to deny writing to a running executable
29384 + which exists on an aufs branch filesystem and executed through
29385 + aufs. If you applied
29386 + 'CVS_TREE/aufs/patch/deny_write_access.patch' to your kernel
29387 + and you are compiling aufs as a module, then enable this
29389 + The write_deny_access.patch does nothing but export the
29392 +config AUFS_WORKAROUND_FUSE
29393 + bool "Special handling for FUSE-based filesystem"
29394 + depends on FUSE_FS
29396 + A FUSE-based filesystem may not initialize its inode
29397 + attributes and the FUSE developer thinks the inode attributes
29398 + in a positive dentry which is returned by VFS lookup operation
29399 + are not reliable.
29400 + If you use a FUSE-based filesystem as an aufs branch, and it
29401 + customizes the inode attribute on it without overriding
29402 + fuse_lowlevel_ops.lookup, probably you need to enable this
29404 + If you enable this configuration, aufs calls getattr operation
29405 + in every lookup and revalidate operation for the FUSE-based
29406 + filesystem branch.
29407 + It will have a negative impact to the performance even if you do
29408 + not use a FUSE-based filesystem branch.
29410 +# automatic configuration for internal use
29411 +config AUFS_GETATTR
29412 + bool # never appear on the menu
29413 + depends on AUFS_HINOTIFY || AUFS_WORKAROUND_FUSE || AUFS_BR_NFS
29416 + Automatic configuration for internal use.
29419 + bool "Debug aufs"
29422 + Enable this to compile aufs internal debug code.
29423 + It will have a negative impact to the performance.
29425 +# automatic configuration for internal use
29426 +config AUFS_MAGIC_SYSRQ
29427 + bool # never appear on the menu
29428 + depends on AUFS_DEBUG && MAGIC_SYSRQ
29431 + Automatic configuration for internal use.
29432 + When aufs supports Magic SysRq, enabled automatically.
29434 +config AUFS_DEBUG_LOCK
29435 + bool "Show lock status in Magic SysRq"
29436 + depends on AUFS_MAGIC_SYSRQ
29438 + For developers only. Sometimes it is useful when a deadlock
29439 + occurs in aufs. Trace every aufs lock acquire and release, and
29440 + print them when Magic SysRq-<AUFS> key is pressed.
29441 + It will have a huge negative impact to the performance.
29443 +config AUFS_COMPAT
29444 + bool "Compatibility with Unionfs (obsolete)"
29446 + This makes aufs compatible with unionfs-style mount options and some
29448 + The dirs= mount option and =nfsro branch permission flag are always
29449 + interpreted as br: mount option and =ro flag respectively. The
29450 + 'debug', 'delete' and 'imap' mount options are ignored.
29451 + If you disable this option, you will get,
29452 + - aufs issues a warning about the ignored mount options
29453 + - the default branch permission flag is set. RW for the first branch,
29454 + and RO for the rests.
29455 + - the name of a internal file which represents the directory is
29456 + 'opaque', becomes '.wh..wh..opq'
29457 + - the 'diropq=w' mount option is set by default
29459 +config AUFS_UNIONFS22_PATCH
29460 + bool "Unionfs-2.2 or later patch is applied or not (obsolete)"
29462 + Unionfs version 2.2 (and later) patch introduces some changes in VFS
29463 + layer which has an impact to aufs. If you have applied such
29464 + patch to your kernel, you need to enable this configuration even
29465 + if you disabled CONFIG_UNIONFS.
29467 +config AUFS_UNIONFS23_PATCH
29468 + bool "Unionfs-2.3 or later patch is applied or not (obsolete)"
29469 + select AUFS_SPLICE_PATCH
29470 + select AUFS_UNIONFS22_PATCH
29472 + Unionfs version 2.3 (and later) patch introduces some changes in VFS
29473 + layer which has an impact to aufs. If you have applied such
29474 + patch to your kernel, you need to enable this configuration even
29475 + if you disabled CONFIG_UNIONFS.
29480 menu "Miscellaneous filesystems"
29481 diff -urN linux/fs/Makefile linux-aufs/fs/Makefile
29482 --- linux/fs/Makefile 2009-03-12 11:25:26.000000000 +0100
29483 +++ linux-aufs/fs/Makefile 2009-03-12 17:03:22.897115295 +0100
29484 @@ -125,3 +125,4 @@
29485 obj-$(CONFIG_BTRFS_FS) += btrfs/
29486 obj-$(CONFIG_GFS2_FS) += gfs2/
29487 obj-$(CONFIG_EXOFS_FS) += exofs/
29488 +obj-$(CONFIG_AUFS) += aufs/
29489 diff -urN linux/include/linux/aufs_type.h linux-aufs/include/linux/aufs_type.h
29490 --- linux/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
29491 +++ linux-aufs/include/linux/aufs_type.h 2009-03-12 16:18:04.000000000 +0100
29494 + * Copyright (C) 2005-2009 Junjiro Okajima
29496 + * This program, aufs is free software; you can redistribute it and/or modify
29497 + * it under the terms of the GNU General Public License as published by
29498 + * the Free Software Foundation; either version 2 of the License, or
29499 + * (at your option) any later version.
29501 + * This program is distributed in the hope that it will be useful,
29502 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29503 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29504 + * GNU General Public License for more details.
29506 + * You should have received a copy of the GNU General Public License
29507 + * along with this program; if not, write to the Free Software
29508 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29513 +#include <linux/ioctl.h>
29515 +#ifndef __AUFS_TYPE_H__
29516 +#define __AUFS_TYPE_H__
29518 +#define AUFS_VERSION "20090126"
29520 +/* move this to linux-2.6.19/include/magic.h */
29521 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
29523 +/* ---------------------------------------------------------------------- */
29525 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
29526 +/* some environments treat 'char' as 'unsigned char' by default */
29527 +typedef signed char aufs_bindex_t;
29528 +#define AUFS_BRANCH_MAX 127
29530 +typedef short aufs_bindex_t;
29531 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
29532 +#define AUFS_BRANCH_MAX 511
29533 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
29534 +#define AUFS_BRANCH_MAX 1023
29535 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
29536 +#define AUFS_BRANCH_MAX 32767
29538 +#error unknown CONFIG_AUFS_BRANCH_MAX value
29542 +#define AUFS_NAME "aufs"
29543 +#define AUFS_FSTYPE AUFS_NAME
29545 +#define AUFS_ROOT_INO 2
29546 +#define AUFS_FIRST_INO 11
29548 +#define AUFS_WH_PFX ".wh."
29549 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
29550 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
29551 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
29552 +#define AUFS_XINO_TRUNC_INIT 64 /* blocks */
29553 +#define AUFS_XINO_TRUNC_STEP 4 /* blocks */
29554 +#define AUFS_DIRWH_DEF 3
29555 +#define AUFS_RDCACHE_DEF 10 /* seconds */
29556 +#define AUFS_WKQ_NAME AUFS_NAME "d"
29557 +#define AUFS_NWKQ_DEF 4
29558 +#define AUFS_MFS_SECOND_DEF 30 /* seconds */
29559 +#define AUFS_PLINK_WARN 100 /* number of plinks */
29561 +#ifdef CONFIG_AUFS_COMPAT
29562 +#define AUFS_DIROPQ_NAME "__dir_opaque"
29564 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
29566 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
29568 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
29569 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
29570 +#define AUFS_TMPDIR_NAME AUFS_WH_PFX ".tmp"
29572 +/* doubly whiteouted */
29573 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
29574 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
29575 +#define AUFS_WH_TMPDIR AUFS_WH_PFX AUFS_TMPDIR_NAME
29577 +/* ---------------------------------------------------------------------- */
29580 +#if 0 /* reserved for future use */
29586 + AuCtl_DIROPQ_GET, AuCtl_DIROPQ_SET,
29590 + /* unimplmented */
29591 + AuCtl_REFRESH, AuCtl_REFRESHV,
29592 + AuCtl_FLUSH_PLINK,
29599 + aufs_bindex_t bsrc, bdst;
29603 +#define AuCtlType 'A'
29604 +#define AUFS_CTL_DIROPQ_GET _IO(AuCtlType, AuCtl_DIROPQ_GET)
29605 +#define AUFS_CTL_DIROPQ_SET _IOW(AuCtlType, AuCtl_DIROPQ_SET, aufs_bindex_t)
29606 +#define AUFS_CTL_MOVE \
29607 + _IOW(AuCtlType, AuCtl_MVDOWN, aufs_bindex_t)
29608 +#define AUFS_CTL_MVDOWN \
29609 + _IOWR(AuCtlType, AuCtl_MVDOWN, struct aufs_ctl)
29611 +#define AUFS_CTL_REFRESH _IO(AuCtlType, AuCtl_REFRESH)
29612 +#define AUFS_CTL_REFRESHV _IO(AuCtlType, AuCtl_REFRESHV)
29613 +#define AUFS_CTL_FLUSH_PLINK _IOR(AuCtlType, AuCtl_FLUSH_PLINK)
29614 +#define AUFS_CTL_CPUP _IOWR(AuCtlType, AuCtl_CPUP, struct aufs_ctl)
29615 +#define AUFS_CTL_CPDOWN \
29616 + _IOWR(AuCtlType, AuCtl_CPDOWN, struct aufs_ctl_cp)
29619 +#endif /* __AUFS_TYPE_H__ */