1 diff -urN linux-2.6.30.org/Documentation/ABI/testing/debugfs-aufs linux-2.6.30/Documentation/ABI/testing/debugfs-aufs
2 --- linux-2.6.30.org/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.30/Documentation/ABI/testing/debugfs-aufs 2009-07-21 08:54:18.000000000 +0200
5 +What: /debug/aufs/si_<id>/
7 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
9 + Under /debug/aufs, a directory named si_<id> is created
10 + per aufs mount, where <id> is a unique id generated
13 +What: /debug/aufs/si_<id>/xib
15 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
17 + It shows the consumed blocks by xib (External Inode Number
18 + Bitmap), its block size and file size.
19 + When the aufs mount option 'noxino' is specified, it
20 + will be empty. About XINO files, see
21 + Documentation/filesystems/aufs/aufs.5 in detail.
23 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
25 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
27 + It shows the consumed blocks by xino (External Inode Number
28 + Translation Table), its link count, block size and file
30 + When the aufs mount option 'noxino' is specified, it
31 + will be empty. About XINO files, see
32 + Documentation/filesystems/aufs/aufs.5 in detail.
34 +What: /debug/aufs/si_<id>/xigen
36 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
38 + It shows the consumed blocks by xigen (External Inode
39 + Generation Table), its block size and file size.
40 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
42 + When the aufs mount option 'noxino' is specified, it
43 + will be empty. About XINO files, see
44 + Documentation/filesystems/aufs/aufs.5 in detail.
45 diff -urN linux-2.6.30.org/Documentation/ABI/testing/sysfs-aufs linux-2.6.30/Documentation/ABI/testing/sysfs-aufs
46 --- linux-2.6.30.org/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
47 +++ linux-2.6.30/Documentation/ABI/testing/sysfs-aufs 2009-07-21 08:54:18.000000000 +0200
49 +What: /sys/fs/aufs/si_<id>/
51 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
53 + Under /sys/fs/aufs, a directory named si_<id> is created
54 + per aufs mount, where <id> is a unique id generated
57 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
59 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
61 + It shows the abolute path of a member directory (which
62 + is called branch) in aufs, and its permission.
64 +What: /sys/fs/aufs/si_<id>/xi_path
66 +Contact: J. R. Okajima <hooanon05@yahoo.co.jp>
68 + It shows the abolute path of XINO (External Inode Number
69 + Bitmap, Translation Table and Generation Table) file
70 + even if it is the default path.
71 + When the aufs mount option 'noxino' is specified, it
72 + will be empty. About XINO files, see
73 + Documentation/filesystems/aufs/aufs.5 in detail.
74 diff -urN linux-2.6.30.org/fs/aufs/aufs.h linux-2.6.30/fs/aufs/aufs.h
75 --- linux-2.6.30.org/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
76 +++ linux-2.6.30/fs/aufs/aufs.h 2009-07-21 08:54:18.000000000 +0200
79 + * Copyright (C) 2005-2009 Junjiro R. Okajima
81 + * This program, aufs is free software; you can redistribute it and/or modify
82 + * it under the terms of the GNU General Public License as published by
83 + * the Free Software Foundation; either version 2 of the License, or
84 + * (at your option) any later version.
86 + * This program is distributed in the hope that it will be useful,
87 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
88 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89 + * GNU General Public License for more details.
91 + * You should have received a copy of the GNU General Public License
92 + * along with this program; if not, write to the Free Software
93 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
110 +#include "dbgaufs.h"
122 +#include "sysaufs.h"
127 +#endif /* __KERNEL__ */
128 +#endif /* __AUFS_H__ */
129 diff -urN linux-2.6.30.org/fs/aufs/branch.c linux-2.6.30/fs/aufs/branch.c
130 --- linux-2.6.30.org/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
131 +++ linux-2.6.30/fs/aufs/branch.c 2009-07-21 08:54:18.000000000 +0200
134 + * Copyright (C) 2005-2009 Junjiro R. Okajima
136 + * This program, aufs is free software; you can redistribute it and/or modify
137 + * it under the terms of the GNU General Public License as published by
138 + * the Free Software Foundation; either version 2 of the License, or
139 + * (at your option) any later version.
141 + * This program is distributed in the hope that it will be useful,
142 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
143 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144 + * GNU General Public License for more details.
146 + * You should have received a copy of the GNU General Public License
147 + * along with this program; if not, write to the Free Software
148 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
152 + * branch management
155 +#include <linux/file.h>
159 + * free a single branch
161 +static void au_br_do_free(struct au_branch *br)
164 + struct au_wbr *wbr;
166 + if (br->br_xino.xi_file)
167 + fput(br->br_xino.xi_file);
168 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
170 + AuDebugOn(atomic_read(&br->br_count));
174 + for (i = 0; i < AuBrWh_Last; i++)
175 + dput(wbr->wbr_wh[i]);
176 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
177 + AuRwDestroy(&wbr->wbr_wh_rwsem);
180 + /* some filesystems acquire extra lock */
182 + mntput(br->br_mnt);
190 + * frees all branches
192 +void au_br_free(struct au_sbinfo *sbinfo)
194 + aufs_bindex_t bmax;
195 + struct au_branch **br;
197 + AuRwMustWriteLock(&sbinfo->si_rwsem);
199 + bmax = sbinfo->si_bend + 1;
200 + br = sbinfo->si_branch;
202 + au_br_do_free(*br++);
206 + * find the index of a branch which is specified by @br_id.
208 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
210 + aufs_bindex_t bindex, bend;
212 + bend = au_sbend(sb);
213 + for (bindex = 0; bindex <= bend; bindex++)
214 + if (au_sbr_id(sb, bindex) == br_id)
219 +/* ---------------------------------------------------------------------- */
225 +static int test_overlap(struct super_block *sb, struct dentry *h_d1,
226 + struct dentry *h_d2)
228 + if (unlikely(h_d1 == h_d2))
230 + return !!au_test_subdir(h_d1, h_d2)
231 + || !!au_test_subdir(h_d2, h_d1)
232 + || au_test_loopback_overlap(sb, h_d1, h_d2)
233 + || au_test_loopback_overlap(sb, h_d2, h_d1);
237 + * returns a newly allocated branch. @new_nbranch is a number of branches
238 + * after adding a branch.
240 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
243 + struct au_branch *add_branch;
244 + struct dentry *root;
247 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
248 + if (unlikely(!add_branch))
251 + add_branch->br_wbr = NULL;
252 + if (au_br_writable(perm)) {
253 + /* may be freed separately at changing the branch permission */
254 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
256 + if (unlikely(!add_branch->br_wbr))
260 + if (unlikely(au_sbr_realloc(au_sbi(sb), new_nbranch)
261 + || au_di_realloc(au_di(root), new_nbranch)
262 + || au_ii_realloc(au_ii(root->d_inode), new_nbranch)))
264 + return add_branch; /* success */
267 + kfree(add_branch->br_wbr);
271 + return ERR_PTR(-ENOMEM);
275 + * test if the branch permission is legal or not.
277 +static int test_br(struct inode *inode, int brperm, char *path)
282 + if (unlikely(au_br_writable(brperm) && IS_RDONLY(inode))) {
283 + AuErr("write permission for readonly mount or inode, %s\n",
293 + * 0: success, the caller will add it
294 + * plus: success, it is already unified, the caller should ignore it
297 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
300 + aufs_bindex_t bend, bindex;
301 + struct dentry *root;
302 + struct inode *inode, *h_inode;
305 + bend = au_sbend(sb);
306 + if (unlikely(bend >= 0
307 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
311 + AuErr("%s duplicated\n", add->pathname);
316 + err = -ENOSPC; /* -E2BIG; */
317 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
318 + || AUFS_BRANCH_MAX - 1 <= bend)) {
319 + AuErr("number of branches exceeded %s\n", add->pathname);
324 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
325 + AuErr("bad index %d\n", add->bindex);
329 + inode = add->path.dentry->d_inode;
331 + if (unlikely(!inode->i_nlink)) {
332 + AuErr("no existence %s\n", add->pathname);
337 + if (unlikely(inode->i_sb == sb)) {
338 + AuErr("%s must be outside\n", add->pathname);
342 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
343 + AuErr("unsupported filesystem, %s (%s)\n",
344 + add->pathname, au_sbtype(inode->i_sb));
348 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
353 + return 0; /* success */
356 + for (bindex = 0; bindex <= bend; bindex++)
357 + if (unlikely(test_overlap(sb, add->path.dentry,
358 + au_h_dptr(root, bindex)))) {
359 + AuErr("%s is overlapped\n", add->pathname);
364 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
365 + h_inode = au_h_dptr(root, 0)->d_inode;
366 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
367 + || h_inode->i_uid != inode->i_uid
368 + || h_inode->i_gid != inode->i_gid)
369 + AuWarn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
371 + inode->i_uid, inode->i_gid,
372 + (inode->i_mode & S_IALLUGO),
373 + h_inode->i_uid, h_inode->i_gid,
374 + (h_inode->i_mode & S_IALLUGO));
382 + * initialize or clean the whiteouts for an adding branch
384 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
385 + int new_perm, struct dentry *h_root)
388 + aufs_bindex_t bindex;
389 + struct mutex *h_mtx;
390 + struct au_wbr *wbr;
391 + struct au_hinode *hdir;
394 + old_perm = br->br_perm;
395 + br->br_perm = new_perm;
398 + bindex = au_br_index(sb, br->br_id);
400 + hdir = au_hi(sb->s_root->d_inode, bindex);
401 + au_hin_imtx_lock_nested(hdir, AuLsc_I_PARENT);
403 + h_mtx = &h_root->d_inode->i_mutex;
404 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
407 + err = au_wh_init(h_root, br, sb);
409 + wbr_wh_write_lock(wbr);
410 + err = au_wh_init(h_root, br, sb);
411 + wbr_wh_write_unlock(wbr);
414 + au_hin_imtx_unlock(hdir);
416 + mutex_unlock(h_mtx);
417 + br->br_perm = old_perm;
419 + if (!err && wbr && !au_br_writable(new_perm)) {
427 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
428 + int perm, struct path *path)
431 + struct au_wbr *wbr;
434 + au_rw_init(&wbr->wbr_wh_rwsem);
435 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
436 + atomic_set(&wbr->wbr_wh_running, 0);
437 + wbr->wbr_bytes = 0;
439 + err = au_br_init_wh(sb, br, perm, path->dentry);
444 +/* intialize a new branch */
445 +static int au_br_init(struct au_branch *br, struct super_block *sb,
446 + struct au_opt_add *add)
451 + memset(&br->br_xino, 0, sizeof(br->br_xino));
452 + mutex_init(&br->br_xino.xi_nondir_mtx);
453 + br->br_perm = add->perm;
454 + br->br_mnt = add->path.mnt; /* set first, mntget() later */
455 + atomic_set(&br->br_count, 0);
456 + br->br_xino_upper = AUFS_XINO_TRUNC_INIT;
457 + atomic_set(&br->br_xino_running, 0);
458 + br->br_id = au_new_br_id(sb);
460 + if (au_br_writable(add->perm)) {
461 + err = au_wbr_init(br, sb, add->perm, &add->path);
466 + if (au_opt_test(au_mntflags(sb), XINO)) {
467 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
468 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
469 + if (unlikely(err)) {
470 + AuDebugOn(br->br_xino.xi_file);
475 + sysaufs_br_init(br);
476 + mntget(add->path.mnt);
482 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
483 + struct au_branch *br, aufs_bindex_t bend,
484 + aufs_bindex_t amount)
486 + struct au_branch **brp;
488 + AuRwMustWriteLock(&sbinfo->si_rwsem);
490 + brp = sbinfo->si_branch + bindex;
491 + memmove(brp + 1, brp, sizeof(*brp) * amount);
494 + if (unlikely(bend < 0))
495 + sbinfo->si_bend = 0;
498 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
499 + aufs_bindex_t bend, aufs_bindex_t amount)
501 + struct au_hdentry *hdp;
503 + hdp = dinfo->di_hdentry + bindex;
504 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
505 + au_h_dentry_init(hdp);
507 + if (unlikely(bend < 0))
508 + dinfo->di_bstart = 0;
511 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
512 + aufs_bindex_t bend, aufs_bindex_t amount)
514 + struct au_hinode *hip;
516 + hip = iinfo->ii_hinode + bindex;
517 + memmove(hip + 1, hip, sizeof(*hip) * amount);
518 + hip->hi_inode = NULL;
519 + au_hin_init(hip, NULL);
521 + if (unlikely(bend < 0))
522 + iinfo->ii_bstart = 0;
525 +static void au_br_do_add(struct super_block *sb, struct dentry *h_dentry,
526 + struct au_branch *br, aufs_bindex_t bindex)
528 + struct dentry *root;
529 + struct inode *root_inode;
530 + aufs_bindex_t bend, amount;
533 + root_inode = root->d_inode;
534 + au_plink_block_maintain(sb);
535 + bend = au_sbend(sb);
536 + amount = bend + 1 - bindex;
537 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
538 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
539 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
540 + au_set_h_dptr(root, bindex, dget(h_dentry));
541 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
545 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
548 + unsigned long long maxb;
549 + aufs_bindex_t bend, add_bindex;
550 + struct dentry *root, *h_dentry;
551 + struct inode *root_inode;
552 + struct au_branch *add_branch;
555 + root_inode = root->d_inode;
556 + IMustLock(root_inode);
557 + err = test_add(sb, add, remount);
558 + if (unlikely(err < 0))
562 + goto out; /* success */
565 + bend = au_sbend(sb);
566 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
567 + err = PTR_ERR(add_branch);
568 + if (IS_ERR(add_branch))
571 + err = au_br_init(add_branch, sb, add);
572 + if (unlikely(err)) {
573 + au_br_do_free(add_branch);
577 + add_bindex = add->bindex;
578 + h_dentry = add->path.dentry;
580 + au_br_do_add(sb, h_dentry, add_branch, add_bindex);
582 + sysaufs_brs_del(sb, add_bindex);
583 + au_br_do_add(sb, h_dentry, add_branch, add_bindex);
584 + sysaufs_brs_add(sb, add_bindex);
588 + au_cpup_attr_all(root_inode, /*force*/1);
590 + au_add_nlink(root_inode, h_dentry->d_inode);
591 + maxb = h_dentry->d_sb->s_maxbytes;
592 + if (sb->s_maxbytes < maxb)
593 + sb->s_maxbytes = maxb;
596 + * this test/set prevents aufs from handling unnecesary inotify events
597 + * of xino files, in a case of re-adding a writable branch which was
598 + * once detached from aufs.
600 + if (au_xino_brid(sb) < 0
601 + && au_br_writable(add_branch->br_perm)
602 + && !au_test_fs_bad_xino(h_dentry->d_sb)
603 + && add_branch->br_xino.xi_file
604 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
605 + au_xino_brid_set(sb, add_branch->br_id);
611 +/* ---------------------------------------------------------------------- */
617 +/* to show the line number, do not make it inlined function */
618 +#define AuVerbose(do_info, fmt, args...) do { \
620 + AuInfo(fmt, ##args); \
624 + * test if the branch is deletable or not.
626 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
627 + unsigned int sigen)
629 + int err, i, j, ndentry;
630 + aufs_bindex_t bstart, bend;
631 + unsigned char verbose;
632 + struct au_dcsub_pages dpages;
633 + struct au_dpage *dpage;
635 + struct inode *inode;
637 + err = au_dpages_init(&dpages, GFP_NOFS);
640 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
644 + verbose = !!au_opt_test(au_mntflags(root->d_sb), VERBOSE);
645 + for (i = 0; !err && i < dpages.ndpage; i++) {
646 + dpage = dpages.dpages + i;
647 + ndentry = dpage->ndentry;
648 + for (j = 0; !err && j < ndentry; j++) {
649 + d = dpage->dentries[j];
650 + AuDebugOn(!atomic_read(&d->d_count));
651 + inode = d->d_inode;
652 + if (au_digen(d) == sigen && au_iigen(inode) == sigen)
653 + di_read_lock_child(d, AuLock_IR);
655 + di_write_lock_child(d);
656 + err = au_reval_dpath(d, sigen);
658 + di_downgrade_lock(d, AuLock_IR);
660 + di_write_unlock(d);
665 + bstart = au_dbstart(d);
666 + bend = au_dbend(d);
667 + if (bstart <= bindex
669 + && au_h_dptr(d, bindex)
670 + && (!S_ISDIR(inode->i_mode) || bstart == bend)) {
672 + AuVerbose(verbose, "busy %.*s\n", AuDLNPair(d));
674 + di_read_unlock(d, AuLock_IR);
679 + au_dpages_free(&dpages);
684 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
685 + unsigned int sigen)
689 + aufs_bindex_t bstart, bend;
690 + unsigned char verbose;
693 + verbose = !!au_opt_test(au_mntflags(sb), VERBOSE);
694 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
695 + AuDebugOn(!atomic_read(&i->i_count));
696 + if (!list_empty(&i->i_dentry))
699 + if (au_iigen(i) == sigen)
700 + ii_read_lock_child(i);
702 + ii_write_lock_child(i);
703 + err = au_refresh_hinode_self(i, /*do_attr*/1);
705 + ii_downgrade_lock(i);
707 + ii_write_unlock(i);
712 + bstart = au_ibstart(i);
713 + bend = au_ibend(i);
714 + if (bstart <= bindex
716 + && au_h_iptr(i, bindex)
717 + && (!S_ISDIR(i->i_mode) || bstart == bend)) {
719 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
729 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex)
732 + unsigned int sigen;
734 + sigen = au_sigen(root->d_sb);
735 + DiMustNoWaiters(root);
736 + IiMustNoWaiters(root->d_inode);
737 + di_write_unlock(root);
738 + err = test_dentry_busy(root, bindex, sigen);
740 + err = test_inode_busy(root->d_sb, bindex, sigen);
741 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
746 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
747 + const aufs_bindex_t bindex,
748 + const aufs_bindex_t bend)
750 + struct au_branch **brp, **p;
752 + AuRwMustWriteLock(&sbinfo->si_rwsem);
754 + brp = sbinfo->si_branch + bindex;
756 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
757 + sbinfo->si_branch[0 + bend] = NULL;
760 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, GFP_NOFS);
762 + sbinfo->si_branch = p;
765 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
766 + const aufs_bindex_t bend)
768 + struct au_hdentry *hdp, *p;
770 + hdp = dinfo->di_hdentry + bindex;
772 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bend - bindex));
773 + dinfo->di_hdentry[0 + bend].hd_dentry = NULL;
776 + p = krealloc(dinfo->di_hdentry, sizeof(*p) * bend, GFP_NOFS);
778 + dinfo->di_hdentry = p;
781 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
782 + const aufs_bindex_t bend)
784 + struct au_hinode *hip, *p;
786 + hip = iinfo->ii_hinode + bindex;
788 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
789 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
790 + au_hin_init(iinfo->ii_hinode + bend, NULL);
793 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, GFP_NOFS);
795 + iinfo->ii_hinode = p;
798 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
799 + struct au_branch *br)
801 + aufs_bindex_t bend;
802 + struct au_sbinfo *sbinfo;
803 + struct dentry *root;
804 + struct inode *inode;
806 + SiMustWriteLock(sb);
809 + inode = root->d_inode;
810 + au_plink_block_maintain(sb);
811 + sbinfo = au_sbi(sb);
812 + bend = sbinfo->si_bend;
814 + dput(au_h_dptr(root, bindex));
815 + au_hiput(au_hi(inode, bindex));
818 + au_br_do_del_brp(sbinfo, bindex, bend);
819 + au_br_do_del_hdp(au_di(root), bindex, bend);
820 + au_br_do_del_hip(au_ii(inode), bindex, bend);
823 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
826 + unsigned int mnt_flags;
827 + aufs_bindex_t bindex, bend, br_id;
828 + unsigned char do_wh, verbose;
829 + struct au_branch *br;
830 + struct au_wbr *wbr;
833 + bindex = au_find_dbindex(sb->s_root, del->h_path.dentry);
836 + goto out; /* success */
838 + AuErr("%s no such branch\n", del->pathname);
841 + AuDbg("bindex b%d\n", bindex);
844 + mnt_flags = au_mntflags(sb);
845 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
846 + bend = au_sbend(sb);
847 + if (unlikely(!bend)) {
848 + AuVerbose(verbose, "no more branches left\n");
851 + br = au_sbr(sb, bindex);
852 + i = atomic_read(&br->br_count);
854 + AuVerbose(verbose, "%d file(s) opened\n", i);
859 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
861 + for (i = 0; i < AuBrWh_Last; i++) {
862 + dput(wbr->wbr_wh[i]);
863 + wbr->wbr_wh[i] = NULL;
867 + err = test_children_busy(sb->s_root, bindex);
868 + if (unlikely(err)) {
877 + au_br_do_del(sb, bindex, br);
879 + sysaufs_brs_del(sb, bindex);
880 + au_br_do_del(sb, bindex, br);
881 + sysaufs_brs_add(sb, bindex);
885 + au_cpup_attr_all(sb->s_root->d_inode, /*force*/1);
887 + au_sub_nlink(sb->s_root->d_inode, del->h_path.dentry->d_inode);
888 + if (au_opt_test(mnt_flags, PLINK))
889 + au_plink_half_refresh(sb, br_id);
891 + if (sb->s_maxbytes == del->h_path.dentry->d_sb->s_maxbytes) {
893 + sb->s_maxbytes = 0;
894 + for (bindex = 0; bindex <= bend; bindex++) {
895 + unsigned long long maxb;
897 + maxb = au_sbr_sb(sb, bindex)->s_maxbytes;
898 + if (sb->s_maxbytes < maxb)
899 + sb->s_maxbytes = maxb;
903 + if (au_xino_brid(sb) == br->br_id)
904 + au_xino_brid_set(sb, -1);
905 + goto out; /* success */
909 + rerr = au_br_init_wh(sb, br, br->br_perm, del->h_path.dentry);
911 + AuWarn("failed re-creating base whiteout, %s. (%d)\n",
912 + del->pathname, rerr);
917 +/* ---------------------------------------------------------------------- */
920 + * change a branch permission
923 +static void au_warn_ima(void)
926 + AuWarn("RW -> RO makes IMA to produce wrong message");
930 +static int do_need_sigen_inc(int a, int b)
932 + return au_br_whable(a) && !au_br_whable(b);
935 +static int need_sigen_inc(int old, int new)
937 + return do_need_sigen_inc(old, new)
938 + || do_need_sigen_inc(new, old);
941 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
944 + unsigned long n, ul, bytes, files;
945 + aufs_bindex_t bstart;
946 + struct file *file, *hf, **a;
947 + const int step_bytes = 1024, /* memory allocation unit */
948 + step_files = step_bytes / sizeof(*a);
952 + bytes = step_bytes;
953 + files = step_files;
954 + a = kmalloc(bytes, GFP_NOFS);
958 + /* no need file_list_lock() since sbinfo is locked? defered? */
959 + list_for_each_entry(file, &sb->s_files, f_u.fu_list) {
960 + if (special_file(file->f_dentry->d_inode->i_mode))
963 + AuDbg("%.*s\n", AuDLNPair(file->f_dentry));
964 + fi_read_lock(file);
965 + if (unlikely(au_test_mmapped(file))) {
967 + FiMustNoWaiters(file);
968 + fi_read_unlock(file);
972 + bstart = au_fbstart(file);
973 + if (!S_ISREG(file->f_dentry->d_inode->i_mode)
974 + || !(file->f_mode & FMODE_WRITE)
975 + || bstart != bindex) {
976 + FiMustNoWaiters(file);
977 + fi_read_unlock(file);
981 + hf = au_h_fptr(file, bstart);
982 + FiMustNoWaiters(file);
983 + fi_read_unlock(file);
991 + bytes += step_bytes;
992 + files += step_files;
993 + p = krealloc(a, bytes, GFP_NOFS);
1005 + for (ul = 0; ul < n; ul++) {
1006 + /* todo: already flushed? */
1007 + /* cf. fs/super.c:mark_files_ro() */
1009 + hf->f_mode &= ~FMODE_WRITE;
1010 + if (!file_check_writeable(hf)) {
1011 + file_release_write(hf);
1012 + mnt_drop_write(hf->f_vfsmnt);
1022 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
1026 + aufs_bindex_t bindex;
1027 + struct dentry *root;
1028 + struct au_branch *br;
1030 + root = sb->s_root;
1031 + au_plink_block_maintain(sb);
1032 + bindex = au_find_dbindex(root, mod->h_root);
1035 + return 0; /* success */
1037 + AuErr("%s no such branch\n", mod->path);
1040 + AuDbg("bindex b%d\n", bindex);
1042 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
1043 + if (unlikely(err))
1046 + br = au_sbr(sb, bindex);
1047 + if (br->br_perm == mod->perm)
1048 + return 0; /* success */
1050 + if (au_br_writable(br->br_perm)) {
1051 + /* remove whiteout base */
1052 + err = au_br_init_wh(sb, br, mod->perm, mod->h_root);
1053 + if (unlikely(err))
1056 + if (!au_br_writable(mod->perm)) {
1057 + /* rw --> ro, file might be mmapped */
1058 + DiMustNoWaiters(root);
1059 + IiMustNoWaiters(root->d_inode);
1060 + di_write_unlock(root);
1061 + err = au_br_mod_files_ro(sb, bindex);
1062 + /* aufs_write_lock() calls ..._child() */
1063 + di_write_lock_child(root);
1065 + if (unlikely(err)) {
1067 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
1070 + rerr = au_br_init_wh
1071 + (sb, br, br->br_perm,
1073 + if (unlikely(rerr)) {
1074 + AuIOErr("nested error %d (%d)\n",
1076 + br->br_perm = mod->perm;
1080 + } else if (au_br_writable(mod->perm)) {
1083 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
1085 + struct path path = {
1086 + .mnt = br->br_mnt,
1087 + .dentry = mod->h_root
1090 + err = au_wbr_init(br, sb, mod->perm, &path);
1091 + if (unlikely(err)) {
1092 + kfree(br->br_wbr);
1093 + br->br_wbr = NULL;
1099 + *do_update |= need_sigen_inc(br->br_perm, mod->perm);
1100 + br->br_perm = mod->perm;
1106 diff -urN linux-2.6.30.org/fs/aufs/branch.h linux-2.6.30/fs/aufs/branch.h
1107 --- linux-2.6.30.org/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
1108 +++ linux-2.6.30/fs/aufs/branch.h 2009-07-21 08:54:18.000000000 +0200
1111 + * Copyright (C) 2005-2009 Junjiro R. Okajima
1113 + * This program, aufs is free software; you can redistribute it and/or modify
1114 + * it under the terms of the GNU General Public License as published by
1115 + * the Free Software Foundation; either version 2 of the License, or
1116 + * (at your option) any later version.
1118 + * This program is distributed in the hope that it will be useful,
1119 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1120 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1121 + * GNU General Public License for more details.
1123 + * You should have received a copy of the GNU General Public License
1124 + * along with this program; if not, write to the Free Software
1125 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1129 + * branch filesystems and xino for them
1132 +#ifndef __AUFS_BRANCH_H__
1133 +#define __AUFS_BRANCH_H__
1137 +#include <linux/fs.h>
1138 +#include <linux/mount.h>
1139 +#include <linux/aufs_type.h>
1143 +/* ---------------------------------------------------------------------- */
1146 +struct au_xino_file {
1147 + struct file *xi_file;
1148 + struct mutex xi_nondir_mtx;
1150 + /* todo: make xino files an array to support huge inode number */
1152 +#ifdef CONFIG_DEBUG_FS
1153 + struct dentry *xi_dbgaufs;
1157 +/* members for writable branch only */
1158 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
1160 + struct au_rwsem wbr_wh_rwsem;
1161 + struct dentry *wbr_wh[AuBrWh_Last];
1162 + atomic_t wbr_wh_running;
1163 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
1164 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
1165 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
1168 + unsigned long long wbr_bytes;
1171 +/* protected by superblock rwsem */
1173 + struct au_xino_file br_xino;
1175 + aufs_bindex_t br_id;
1178 + struct vfsmount *br_mnt;
1179 + atomic_t br_count;
1181 + struct au_wbr *br_wbr;
1183 + /* xino truncation */
1184 + blkcnt_t br_xino_upper; /* watermark in blocks */
1185 + atomic_t br_xino_running;
1187 +#ifdef CONFIG_SYSFS
1188 + /* an entry under sysfs per mount-point */
1190 + struct attribute br_attr;
1194 +/* ---------------------------------------------------------------------- */
1196 +/* branch permission and attribute */
1198 + AuBrPerm_RW, /* writable, linkable wh */
1199 + AuBrPerm_RO, /* readonly, no wh */
1200 + AuBrPerm_RR, /* natively readonly, no wh */
1202 + AuBrPerm_RWNoLinkWH, /* un-linkable whiteouts */
1204 + AuBrPerm_ROWH, /* whiteout-able */
1205 + AuBrPerm_RRWH, /* whiteout-able */
1210 +static inline int au_br_writable(int brperm)
1212 + return brperm == AuBrPerm_RW || brperm == AuBrPerm_RWNoLinkWH;
1215 +static inline int au_br_whable(int brperm)
1217 + return brperm == AuBrPerm_RW
1218 + || brperm == AuBrPerm_ROWH
1219 + || brperm == AuBrPerm_RRWH;
1222 +static inline int au_br_rdonly(struct au_branch *br)
1224 + return ((br->br_mnt->mnt_sb->s_flags & MS_RDONLY)
1225 + || !au_br_writable(br->br_perm))
1229 +static inline int au_br_hinotifyable(int brperm __maybe_unused)
1231 +#ifdef CONFIG_AUFS_HINOTIFY
1232 + return brperm != AuBrPerm_RR && brperm != AuBrPerm_RRWH;
1238 +/* ---------------------------------------------------------------------- */
1242 +void au_br_free(struct au_sbinfo *sinfo);
1243 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
1245 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
1247 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
1249 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
1253 +static const loff_t au_loff_max = LLONG_MAX;
1255 +int au_xib_trunc(struct super_block *sb);
1256 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
1258 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
1260 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
1261 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
1262 +ino_t au_xino_new_ino(struct super_block *sb);
1263 +int au_xino_write0(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
1265 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
1267 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
1269 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
1270 + struct file *base_file, int do_test);
1271 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
1273 +struct au_opt_xino;
1274 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
1275 +void au_xino_clr(struct super_block *sb);
1276 +struct file *au_xino_def(struct super_block *sb);
1277 +int au_xino_path(struct seq_file *seq, struct file *file);
1279 +/* ---------------------------------------------------------------------- */
1281 +/* Superblock to branch */
1283 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
1285 + return au_sbr(sb, bindex)->br_id;
1289 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
1291 + return au_sbr(sb, bindex)->br_mnt;
1295 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
1297 + return au_sbr_mnt(sb, bindex)->mnt_sb;
1300 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
1302 + atomic_dec_return(&au_sbr(sb, bindex)->br_count);
1305 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
1307 + return au_sbr(sb, bindex)->br_perm;
1310 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
1312 + return au_br_whable(au_sbr_perm(sb, bindex));
1315 +/* ---------------------------------------------------------------------- */
1318 + * wbr_wh_read_lock, wbr_wh_write_lock
1319 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
1321 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
1323 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
1324 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
1325 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
1327 +#endif /* __KERNEL__ */
1328 +#endif /* __AUFS_BRANCH_H__ */
1329 diff -urN linux-2.6.30.org/fs/aufs/cpup.c linux-2.6.30/fs/aufs/cpup.c
1330 --- linux-2.6.30.org/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
1331 +++ linux-2.6.30/fs/aufs/cpup.c 2009-07-21 08:54:18.000000000 +0200
1334 + * Copyright (C) 2005-2009 Junjiro R. Okajima
1336 + * This program, aufs is free software; you can redistribute it and/or modify
1337 + * it under the terms of the GNU General Public License as published by
1338 + * the Free Software Foundation; either version 2 of the License, or
1339 + * (at your option) any later version.
1341 + * This program is distributed in the hope that it will be useful,
1342 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1343 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1344 + * GNU General Public License for more details.
1346 + * You should have received a copy of the GNU General Public License
1347 + * along with this program; if not, write to the Free Software
1348 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1352 + * copy-up functions, see wbr_policy.c for copy-down
1355 +#include <linux/file.h>
1356 +#include <linux/fs_stack.h>
1357 +#include <linux/mm.h>
1358 +#include <linux/uaccess.h>
1361 +void au_cpup_attr_flags(struct inode *dst, struct inode *src)
1363 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
1364 + | S_NOATIME | S_NOCMTIME;
1366 + dst->i_flags |= src->i_flags & ~mask;
1367 + if (au_test_fs_notime(dst->i_sb))
1368 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
1371 +void au_cpup_attr_timesizes(struct inode *inode)
1373 + struct inode *h_inode;
1375 + h_inode = au_h_iptr(inode, au_ibstart(inode));
1376 + fsstack_copy_attr_times(inode, h_inode);
1377 + vfsub_copy_inode_size(inode, h_inode);
1380 +void au_cpup_attr_nlink(struct inode *inode, int force)
1382 + struct inode *h_inode;
1383 + struct super_block *sb;
1384 + aufs_bindex_t bindex, bend;
1387 + bindex = au_ibstart(inode);
1388 + h_inode = au_h_iptr(inode, bindex);
1390 + && !S_ISDIR(h_inode->i_mode)
1391 + && au_opt_test(au_mntflags(sb), PLINK)
1392 + && au_plink_test(inode))
1395 + inode->i_nlink = h_inode->i_nlink;
1398 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
1399 + * it may includes whplink directory.
1401 + if (S_ISDIR(h_inode->i_mode)) {
1402 + bend = au_ibend(inode);
1403 + for (bindex++; bindex <= bend; bindex++) {
1404 + h_inode = au_h_iptr(inode, bindex);
1406 + au_add_nlink(inode, h_inode);
1411 +void au_cpup_attr_changeable(struct inode *inode)
1413 + struct inode *h_inode;
1415 + h_inode = au_h_iptr(inode, au_ibstart(inode));
1416 + inode->i_mode = h_inode->i_mode;
1417 + inode->i_uid = h_inode->i_uid;
1418 + inode->i_gid = h_inode->i_gid;
1419 + au_cpup_attr_timesizes(inode);
1420 + au_cpup_attr_flags(inode, h_inode);
1423 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
1425 + struct au_iinfo *iinfo = au_ii(inode);
1427 + iinfo->ii_higen = h_inode->i_generation;
1428 + iinfo->ii_hsb1 = h_inode->i_sb;
1431 +void au_cpup_attr_all(struct inode *inode, int force)
1433 + struct inode *h_inode;
1435 + h_inode = au_h_iptr(inode, au_ibstart(inode));
1436 + au_cpup_attr_changeable(inode);
1437 + if (inode->i_nlink > 0)
1438 + au_cpup_attr_nlink(inode, force);
1439 + inode->i_rdev = h_inode->i_rdev;
1440 + inode->i_blkbits = h_inode->i_blkbits;
1441 + au_cpup_igen(inode, h_inode);
1444 +/* ---------------------------------------------------------------------- */
1446 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
1448 +/* keep the timestamps of the parent dir when cpup */
1449 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
1450 + struct path *h_path)
1452 + struct inode *h_inode;
1454 + dt->dt_dentry = dentry;
1455 + dt->dt_h_path = *h_path;
1456 + h_inode = h_path->dentry->d_inode;
1457 + dt->dt_atime = h_inode->i_atime;
1458 + dt->dt_mtime = h_inode->i_mtime;
1462 +void au_dtime_revert(struct au_dtime *dt)
1464 + struct iattr attr;
1467 + attr.ia_atime = dt->dt_atime;
1468 + attr.ia_mtime = dt->dt_mtime;
1469 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
1470 + | ATTR_ATIME | ATTR_ATIME_SET;
1472 + err = vfsub_notify_change(&dt->dt_h_path, &attr);
1473 + if (unlikely(err))
1474 + AuWarn("restoring timestamps failed(%d). ignored\n", err);
1477 +/* ---------------------------------------------------------------------- */
1479 +static noinline_for_stack
1480 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src)
1484 + struct path h_path;
1485 + struct inode *h_isrc;
1487 + h_path.dentry = au_h_dptr(dst, bindex);
1488 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
1489 + h_isrc = h_src->d_inode;
1490 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID
1491 + | ATTR_ATIME | ATTR_MTIME
1492 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
1493 + ia.ia_mode = h_isrc->i_mode;
1494 + ia.ia_uid = h_isrc->i_uid;
1495 + ia.ia_gid = h_isrc->i_gid;
1496 + ia.ia_atime = h_isrc->i_atime;
1497 + ia.ia_mtime = h_isrc->i_mtime;
1498 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
1499 + au_cpup_attr_flags(h_path.dentry->d_inode, h_isrc);
1500 + err = vfsub_notify_change(&h_path, &ia);
1502 + /* is this nfs only? */
1503 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
1504 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
1505 + ia.ia_mode = h_isrc->i_mode;
1506 + err = vfsub_notify_change(&h_path, &ia);
1512 +/* ---------------------------------------------------------------------- */
1514 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
1515 + char *buf, unsigned long blksize)
1518 + size_t sz, rbytes, wbytes;
1519 + unsigned char all_zero;
1521 + struct mutex *h_mtx;
1522 + /* reduce stack usage */
1525 + zp = page_address(ZERO_PAGE(0));
1526 + if (unlikely(!zp))
1527 + return -ENOMEM; /* possible? */
1532 + AuDbg("len %lld\n", len);
1534 + if (len < blksize)
1538 + /* todo: signal_pending? */
1539 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
1540 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
1543 + if (unlikely(err < 0))
1547 + if (len >= rbytes && rbytes == blksize)
1548 + all_zero = !memcmp(buf, zp, rbytes);
1555 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
1557 + /* todo: signal_pending? */
1558 + if (unlikely(err == -EAGAIN || err == -EINTR))
1560 + if (unlikely(err < 0))
1569 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
1571 + if (unlikely(res < 0))
1578 + /* the last block may be a hole */
1579 + if (!err && all_zero) {
1580 + AuLabel(last hole);
1583 + if (au_test_nfs(dst->f_dentry->d_sb)) {
1584 + /* nfs requires this step to make last hole */
1585 + /* is this only nfs? */
1587 + /* todo: signal_pending? */
1588 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
1589 + } while (err == -EAGAIN || err == -EINTR);
1596 + ia->ia_size = dst->f_pos;
1597 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
1598 + ia->ia_file = dst;
1599 + h_mtx = &dst->f_dentry->d_inode->i_mutex;
1600 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
1601 + err = vfsub_notify_change(&dst->f_path, ia);
1602 + mutex_unlock(h_mtx);
1609 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
1612 + unsigned long blksize;
1613 + unsigned char do_kfree;
1617 + blksize = dst->f_dentry->d_sb->s_blocksize;
1618 + if (!blksize || PAGE_SIZE < blksize)
1619 + blksize = PAGE_SIZE;
1620 + AuDbg("blksize %lu\n", blksize);
1621 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
1623 + buf = kmalloc(blksize, GFP_NOFS);
1625 + buf = (void *)__get_free_page(GFP_NOFS);
1626 + if (unlikely(!buf))
1629 + if (len > (1 << 22))
1630 + AuDbg("copying a large file %lld\n", (long long)len);
1634 + err = au_do_copy_file(dst, src, len, buf, blksize);
1638 + free_page((unsigned long)buf);
1645 + * to support a sparse file which is opened with O_APPEND,
1646 + * we need to close the file.
1648 +static int au_cp_regular(struct dentry *dentry, aufs_bindex_t bdst,
1649 + aufs_bindex_t bsrc, loff_t len)
1652 + enum { SRC, DST };
1654 + aufs_bindex_t bindex;
1655 + unsigned int flags;
1656 + struct dentry *dentry;
1657 + struct file *file;
1658 + void *label, *label_file;
1662 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
1665 + .label_file = &&out_src
1669 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
1671 + .label = &&out_src,
1672 + .label_file = &&out_dst
1675 + struct super_block *sb;
1677 + /* bsrc branch can be ro/rw. */
1678 + sb = dentry->d_sb;
1680 + for (i = 0; i < 2; i++, f++) {
1681 + f->dentry = au_h_dptr(dentry, f->bindex);
1682 + f->file = au_h_open(dentry, f->bindex, f->flags, /*file*/NULL);
1683 + err = PTR_ERR(f->file);
1684 + if (IS_ERR(f->file))
1687 + if (unlikely(!f->file->f_op))
1688 + goto *f->label_file;
1691 + /* try stopping to update while we copyup */
1692 + IMustLock(file[SRC].dentry->d_inode);
1693 + err = au_copy_file(file[DST].file, file[SRC].file, len);
1696 + fput(file[DST].file);
1697 + au_sbr_put(sb, file[DST].bindex);
1699 + fput(file[SRC].file);
1700 + au_sbr_put(sb, file[SRC].bindex);
1705 +static int au_do_cpup_regular(struct dentry *dentry, aufs_bindex_t bdst,
1706 + aufs_bindex_t bsrc, loff_t len,
1707 + struct inode *h_dir, struct path *h_path)
1713 + l = i_size_read(au_h_iptr(dentry->d_inode, bsrc));
1714 + if (len == -1 || l < len)
1717 + err = au_cp_regular(dentry, bdst, bsrc, len);
1719 + goto out; /* success */
1721 + rerr = vfsub_unlink(h_dir, h_path, /*force*/0);
1723 + AuIOErr("failed unlinking cpup-ed %.*s(%d, %d)\n",
1724 + AuDLNPair(h_path->dentry), err, rerr);
1732 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
1733 + struct inode *h_dir)
1736 + mm_segment_t old_fs;
1740 + if (unlikely(!h_src->d_inode->i_op->readlink))
1744 + sym = __getname();
1745 + if (unlikely(!sym))
1748 + old_fs = get_fs();
1749 + set_fs(KERNEL_DS);
1750 + symlen = h_src->d_inode->i_op->readlink(h_src, (char __user *)sym,
1757 + err = vfsub_symlink(h_dir, h_path, sym);
1765 +/* return with the lower dst inode is locked */
1766 +static noinline_for_stack
1767 +int cpup_entry(struct dentry *dentry, aufs_bindex_t bdst,
1768 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
1769 + struct dentry *dst_parent)
1773 + unsigned int mnt_flags;
1774 + unsigned char isdir;
1775 + const unsigned char do_dt = !!au_ftest_cpup(flags, DTIME);
1776 + struct au_dtime dt;
1777 + struct path h_path;
1778 + struct dentry *h_src, *h_dst, *h_parent;
1779 + struct inode *h_inode, *h_dir;
1780 + struct super_block *sb;
1782 + /* bsrc branch can be ro/rw. */
1783 + h_src = au_h_dptr(dentry, bsrc);
1784 + h_inode = h_src->d_inode;
1785 + AuDebugOn(h_inode != au_h_iptr(dentry->d_inode, bsrc));
1787 + /* try stopping to be referenced while we are creating */
1788 + h_dst = au_h_dptr(dentry, bdst);
1789 + h_parent = h_dst->d_parent; /* dir inode is locked */
1790 + h_dir = h_parent->d_inode;
1792 + AuDebugOn(h_parent != h_dst->d_parent);
1794 + sb = dentry->d_sb;
1795 + h_path.mnt = au_sbr_mnt(sb, bdst);
1797 + h_path.dentry = h_parent;
1798 + au_dtime_store(&dt, dst_parent, &h_path);
1800 + h_path.dentry = h_dst;
1803 + mode = h_inode->i_mode;
1804 + switch (mode & S_IFMT) {
1806 + /* try stopping to update while we are referencing */
1807 + IMustLock(h_inode);
1808 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR);
1810 + err = au_do_cpup_regular
1811 + (dentry, bdst, bsrc, len,
1812 + au_h_iptr(dst_parent->d_inode, bdst), &h_path);
1816 + err = vfsub_mkdir(h_dir, &h_path, mode);
1819 + * strange behaviour from the users view,
1820 + * particularry setattr case
1822 + if (au_ibstart(dst_parent->d_inode) == bdst)
1823 + au_cpup_attr_nlink(dst_parent->d_inode,
1825 + au_cpup_attr_nlink(dentry->d_inode, /*force*/1);
1829 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
1833 + AuDebugOn(!capable(CAP_MKNOD));
1837 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
1840 + AuIOErr("Unknown inode type 0%o\n", mode);
1844 + mnt_flags = au_mntflags(sb);
1845 + if (!au_opt_test(mnt_flags, UDBA_NONE)
1847 + && au_opt_test(mnt_flags, XINO)
1848 + && h_inode->i_nlink == 1
1849 + /* todo: unnecessary? */
1850 + /* && dentry->d_inode->i_nlink == 1 */
1852 + && !au_ftest_cpup(flags, KEEPLINO))
1853 + au_xino_write0(sb, bsrc, h_inode->i_ino, /*ino*/0);
1854 + /* ignore this error */
1857 + au_dtime_revert(&dt);
1862 + * copyup the @dentry from @bsrc to @bdst.
1863 + * the caller must set the both of lower dentries.
1864 + * @len is for truncating when it is -1 copyup the entire file.
1865 + * in link/rename cases, @dst_parent may be different from the real one.
1867 +static int au_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
1868 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
1869 + struct dentry *dst_parent)
1872 + aufs_bindex_t old_ibstart;
1873 + unsigned char isdir, plink;
1874 + struct au_dtime dt;
1875 + struct path h_path;
1876 + struct dentry *h_src, *h_dst, *h_parent;
1877 + struct inode *dst_inode, *h_dir, *inode;
1878 + struct super_block *sb;
1880 + AuDebugOn(bsrc <= bdst);
1882 + sb = dentry->d_sb;
1883 + h_path.mnt = au_sbr_mnt(sb, bdst);
1884 + h_dst = au_h_dptr(dentry, bdst);
1885 + h_parent = h_dst->d_parent; /* dir inode is locked */
1886 + h_dir = h_parent->d_inode;
1889 + h_src = au_h_dptr(dentry, bsrc);
1890 + inode = dentry->d_inode;
1893 + dst_parent = dget_parent(dentry);
1897 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
1898 + dst_inode = au_h_iptr(inode, bdst);
1900 + if (unlikely(!plink)) {
1902 + AuIOErr("i%lu exists on a upper branch "
1903 + "but plink is disabled\n", inode->i_ino);
1907 + if (dst_inode->i_nlink) {
1908 + const int do_dt = au_ftest_cpup(flags, DTIME);
1910 + h_src = au_plink_lkup(inode, bdst);
1911 + err = PTR_ERR(h_src);
1912 + if (IS_ERR(h_src))
1914 + if (unlikely(!h_src->d_inode)) {
1916 + AuIOErr("i%lu exists on a upper branch "
1917 + "but plink is broken\n", inode->i_ino);
1923 + h_path.dentry = h_parent;
1924 + au_dtime_store(&dt, dst_parent, &h_path);
1926 + h_path.dentry = h_dst;
1927 + err = vfsub_link(h_src, h_dir, &h_path);
1929 + au_dtime_revert(&dt);
1933 + /* todo: cpup_wh_file? */
1935 + au_update_brange(inode, 1);
1938 + old_ibstart = au_ibstart(inode);
1939 + err = cpup_entry(dentry, bdst, bsrc, len, flags, dst_parent);
1940 + if (unlikely(err))
1942 + dst_inode = h_dst->d_inode;
1943 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
1945 + err = cpup_iattr(dentry, bdst, h_src);
1946 + isdir = S_ISDIR(dst_inode->i_mode);
1948 + if (bdst < old_ibstart)
1949 + au_set_ibstart(inode, bdst);
1950 + au_set_h_iptr(inode, bdst, au_igrab(dst_inode),
1951 + au_hi_flags(inode, isdir));
1952 + mutex_unlock(&dst_inode->i_mutex);
1954 + && h_src->d_inode->i_nlink > 1
1956 + au_plink_append(inode, bdst, h_dst);
1957 + goto out; /* success */
1961 + h_path.dentry = h_parent;
1962 + mutex_unlock(&dst_inode->i_mutex);
1963 + au_dtime_store(&dt, dst_parent, &h_path);
1964 + h_path.dentry = h_dst;
1966 + rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
1968 + rerr = vfsub_rmdir(h_dir, &h_path);
1969 + au_dtime_revert(&dt);
1971 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
1980 +struct au_cpup_single_args {
1982 + struct dentry *dentry;
1983 + aufs_bindex_t bdst, bsrc;
1985 + unsigned int flags;
1986 + struct dentry *dst_parent;
1989 +static void au_call_cpup_single(void *args)
1991 + struct au_cpup_single_args *a = args;
1992 + *a->errp = au_cpup_single(a->dentry, a->bdst, a->bsrc, a->len,
1993 + a->flags, a->dst_parent);
1996 +int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
1997 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
1998 + struct dentry *dst_parent)
2002 + struct dentry *h_dentry;
2004 + h_dentry = au_h_dptr(dentry, bsrc);
2005 + mode = h_dentry->d_inode->i_mode & S_IFMT;
2006 + if ((mode != S_IFCHR && mode != S_IFBLK)
2007 + || capable(CAP_MKNOD))
2008 + err = au_cpup_single(dentry, bdst, bsrc, len, flags,
2011 + struct au_cpup_single_args args = {
2018 + .dst_parent = dst_parent
2020 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
2021 + if (unlikely(wkq_err))
2029 + * copyup the @dentry from the first active lower branch to @bdst,
2030 + * using au_cpup_single().
2032 +static int au_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2033 + unsigned int flags)
2036 + aufs_bindex_t bsrc, bend;
2038 + bend = au_dbend(dentry);
2039 + for (bsrc = bdst + 1; bsrc <= bend; bsrc++)
2040 + if (au_h_dptr(dentry, bsrc))
2043 + err = au_lkup_neg(dentry, bdst);
2045 + err = au_cpup_single(dentry, bdst, bsrc, len, flags, NULL);
2047 + return 0; /* success */
2050 + au_set_h_dptr(dentry, bdst, NULL);
2051 + au_set_dbstart(dentry, bsrc);
2057 +struct au_cpup_simple_args {
2059 + struct dentry *dentry;
2060 + aufs_bindex_t bdst;
2062 + unsigned int flags;
2065 +static void au_call_cpup_simple(void *args)
2067 + struct au_cpup_simple_args *a = args;
2068 + *a->errp = au_cpup_simple(a->dentry, a->bdst, a->len, a->flags);
2071 +int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2072 + unsigned int flags)
2075 + unsigned char do_sio;
2076 + struct dentry *parent;
2077 + struct inode *h_dir;
2079 + parent = dget_parent(dentry);
2080 + h_dir = au_h_iptr(parent->d_inode, bdst);
2081 + do_sio = !!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE);
2084 + * testing CAP_MKNOD is for generic fs,
2085 + * but CAP_FSETID is for xfs only, currently.
2087 + umode_t mode = dentry->d_inode->i_mode;
2088 + do_sio = (((mode & (S_IFCHR | S_IFBLK))
2089 + && !capable(CAP_MKNOD))
2090 + || ((mode & (S_ISUID | S_ISGID))
2091 + && !capable(CAP_FSETID)));
2094 + err = au_cpup_simple(dentry, bdst, len, flags);
2096 + struct au_cpup_simple_args args = {
2103 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
2104 + if (unlikely(wkq_err))
2112 +/* ---------------------------------------------------------------------- */
2115 + * copyup the deleted file for writing.
2117 +static int au_do_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst,
2118 + struct dentry *wh_dentry, struct file *file,
2122 + aufs_bindex_t bstart;
2123 + struct au_dinfo *dinfo;
2124 + struct dentry *h_d_dst, *h_d_start;
2126 + dinfo = au_di(dentry);
2127 + bstart = dinfo->di_bstart;
2128 + h_d_dst = dinfo->di_hdentry[0 + bdst].hd_dentry;
2129 + dinfo->di_bstart = bdst;
2130 + dinfo->di_hdentry[0 + bdst].hd_dentry = wh_dentry;
2131 + h_d_start = dinfo->di_hdentry[0 + bstart].hd_dentry;
2133 + dinfo->di_hdentry[0 + bstart].hd_dentry
2134 + = au_h_fptr(file, au_fbstart(file))->f_dentry;
2135 + err = au_cpup_single(dentry, bdst, bstart, len, !AuCpup_DTIME,
2136 + /*h_parent*/NULL);
2137 + if (!err && file) {
2138 + err = au_reopen_nondir(file);
2139 + dinfo->di_hdentry[0 + bstart].hd_dentry = h_d_start;
2141 + dinfo->di_hdentry[0 + bdst].hd_dentry = h_d_dst;
2142 + dinfo->di_bstart = bstart;
2147 +static int au_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2148 + struct file *file)
2151 + struct au_dtime dt;
2152 + struct dentry *parent, *h_parent, *wh_dentry;
2153 + struct au_branch *br;
2154 + struct path h_path;
2156 + br = au_sbr(dentry->d_sb, bdst);
2157 + parent = dget_parent(dentry);
2158 + h_parent = au_h_dptr(parent, bdst);
2159 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
2160 + err = PTR_ERR(wh_dentry);
2161 + if (IS_ERR(wh_dentry))
2164 + h_path.dentry = h_parent;
2165 + h_path.mnt = br->br_mnt;
2166 + au_dtime_store(&dt, parent, &h_path);
2167 + err = au_do_cpup_wh(dentry, bdst, wh_dentry, file, len);
2168 + if (unlikely(err))
2172 + h_path.dentry = wh_dentry;
2173 + err = vfsub_unlink(h_parent->d_inode, &h_path, /*force*/0);
2174 + if (unlikely(err)) {
2175 + AuIOErr("failed remove copied-up tmp file %.*s(%d)\n",
2176 + AuDLNPair(wh_dentry), err);
2179 + au_dtime_revert(&dt);
2180 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
2189 +struct au_cpup_wh_args {
2191 + struct dentry *dentry;
2192 + aufs_bindex_t bdst;
2194 + struct file *file;
2197 +static void au_call_cpup_wh(void *args)
2199 + struct au_cpup_wh_args *a = args;
2200 + *a->errp = au_cpup_wh(a->dentry, a->bdst, a->len, a->file);
2203 +int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2204 + struct file *file)
2207 + struct dentry *parent, *h_orph, *h_parent, *h_dentry;
2208 + struct inode *dir, *h_dir, *h_tmpdir, *h_inode;
2209 + struct au_wbr *wbr;
2211 + parent = dget_parent(dentry);
2212 + dir = parent->d_inode;
2215 + h_dir = au_igrab(au_h_iptr(dir, bdst));
2217 + if (!h_dir->i_nlink) {
2218 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
2219 + h_orph = wbr->wbr_orph;
2221 + h_parent = dget(au_h_dptr(parent, bdst));
2222 + au_set_h_dptr(parent, bdst, NULL);
2223 + au_set_h_dptr(parent, bdst, dget(h_orph));
2224 + h_tmpdir = h_orph->d_inode;
2225 + au_set_h_iptr(dir, bdst, NULL, 0);
2226 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
2228 + /* this temporary unlock is safe */
2230 + h_dentry = au_h_fptr(file, au_fbstart(file))->f_dentry;
2232 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
2233 + h_inode = h_dentry->d_inode;
2234 + IMustLock(h_inode);
2235 + mutex_unlock(&h_inode->i_mutex);
2236 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
2237 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
2240 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE))
2241 + err = au_cpup_wh(dentry, bdst, len, file);
2243 + struct au_cpup_wh_args args = {
2250 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
2251 + if (unlikely(wkq_err))
2256 + mutex_unlock(&h_tmpdir->i_mutex);
2257 + au_set_h_iptr(dir, bdst, NULL, 0);
2258 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
2259 + au_set_h_dptr(parent, bdst, NULL);
2260 + au_set_h_dptr(parent, bdst, h_parent);
2268 +/* ---------------------------------------------------------------------- */
2271 + * generic routine for both of copy-up and copy-down.
2273 +/* cf. revalidate function in file.c */
2274 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
2275 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
2276 + struct dentry *h_parent, void *arg),
2280 + struct au_pin pin;
2281 + struct dentry *d, *parent, *h_parent, *real_parent;
2284 + parent = dget_parent(dentry);
2285 + if (IS_ROOT(parent))
2288 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
2289 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
2291 + /* do not use au_dpage */
2292 + real_parent = parent;
2295 + parent = dget_parent(dentry);
2296 + h_parent = au_h_dptr(parent, bdst);
2298 + goto out; /* success */
2300 + /* find top dir which is necessary to cpup */
2304 + parent = dget_parent(d);
2305 + di_read_lock_parent3(parent, !AuLock_IR);
2306 + h_parent = au_h_dptr(parent, bdst);
2307 + di_read_unlock(parent, !AuLock_IR);
2308 + } while (!h_parent);
2310 + if (d != real_parent)
2311 + di_write_lock_child3(d);
2313 + /* somebody else might create while we were sleeping */
2314 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
2315 + if (au_h_dptr(d, bdst))
2316 + au_update_dbstart(d);
2318 + au_pin_set_dentry(&pin, d);
2319 + err = au_do_pin(&pin);
2321 + err = cp(d, bdst, h_parent, arg);
2326 + if (d != real_parent)
2327 + di_write_unlock(d);
2328 + if (unlikely(err))
2337 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
2338 + struct dentry *h_parent __maybe_unused ,
2339 + void *arg __maybe_unused)
2341 + return au_sio_cpup_simple(dentry, bdst, -1, AuCpup_DTIME);
2344 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
2346 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
2349 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
2352 + struct dentry *parent;
2353 + struct inode *dir;
2355 + parent = dget_parent(dentry);
2356 + dir = parent->d_inode;
2358 + if (au_h_iptr(dir, bdst))
2361 + di_read_unlock(parent, AuLock_IR);
2362 + di_write_lock_parent(parent);
2363 + /* someone else might change our inode while we were sleeping */
2364 + if (!au_h_iptr(dir, bdst))
2365 + err = au_cpup_dirs(dentry, bdst);
2366 + di_downgrade_lock(parent, AuLock_IR);
2372 diff -urN linux-2.6.30.org/fs/aufs/cpup.h linux-2.6.30/fs/aufs/cpup.h
2373 --- linux-2.6.30.org/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
2374 +++ linux-2.6.30/fs/aufs/cpup.h 2009-07-21 08:54:18.000000000 +0200
2377 + * Copyright (C) 2005-2009 Junjiro R. Okajima
2379 + * This program, aufs is free software; you can redistribute it and/or modify
2380 + * it under the terms of the GNU General Public License as published by
2381 + * the Free Software Foundation; either version 2 of the License, or
2382 + * (at your option) any later version.
2384 + * This program is distributed in the hope that it will be useful,
2385 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2386 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2387 + * GNU General Public License for more details.
2389 + * You should have received a copy of the GNU General Public License
2390 + * along with this program; if not, write to the Free Software
2391 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2395 + * copy-up/down functions
2398 +#ifndef __AUFS_CPUP_H__
2399 +#define __AUFS_CPUP_H__
2403 +#include <linux/path.h>
2404 +#include <linux/time.h>
2405 +#include <linux/aufs_type.h>
2410 +void au_cpup_attr_flags(struct inode *dst, struct inode *src);
2411 +void au_cpup_attr_timesizes(struct inode *inode);
2412 +void au_cpup_attr_nlink(struct inode *inode, int force);
2413 +void au_cpup_attr_changeable(struct inode *inode);
2414 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
2415 +void au_cpup_attr_all(struct inode *inode, int force);
2417 +/* ---------------------------------------------------------------------- */
2420 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
2421 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
2423 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
2424 +#define au_fset_cpup(flags, name) { (flags) |= AuCpup_##name; }
2425 +#define au_fclr_cpup(flags, name) { (flags) &= ~AuCpup_##name; }
2427 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
2428 +int au_sio_cpup_single(struct dentry *dentry, aufs_bindex_t bdst,
2429 + aufs_bindex_t bsrc, loff_t len, unsigned int flags,
2430 + struct dentry *dst_parent);
2431 +int au_sio_cpup_simple(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2432 + unsigned int flags);
2433 +int au_sio_cpup_wh(struct dentry *dentry, aufs_bindex_t bdst, loff_t len,
2434 + struct file *file);
2436 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
2437 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
2438 + struct dentry *h_parent, void *arg),
2440 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
2441 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
2443 +/* ---------------------------------------------------------------------- */
2445 +/* keep timestamps when copyup */
2447 + struct dentry *dt_dentry;
2448 + struct path dt_h_path;
2449 + struct timespec dt_atime, dt_mtime;
2451 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
2452 + struct path *h_path);
2453 +void au_dtime_revert(struct au_dtime *dt);
2455 +#endif /* __KERNEL__ */
2456 +#endif /* __AUFS_CPUP_H__ */
2457 diff -urN linux-2.6.30.org/fs/aufs/dbgaufs.c linux-2.6.30/fs/aufs/dbgaufs.c
2458 --- linux-2.6.30.org/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
2459 +++ linux-2.6.30/fs/aufs/dbgaufs.c 2009-07-21 08:54:18.000000000 +0200
2462 + * Copyright (C) 2005-2009 Junjiro R. Okajima
2464 + * This program, aufs is free software; you can redistribute it and/or modify
2465 + * it under the terms of the GNU General Public License as published by
2466 + * the Free Software Foundation; either version 2 of the License, or
2467 + * (at your option) any later version.
2469 + * This program is distributed in the hope that it will be useful,
2470 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2471 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2472 + * GNU General Public License for more details.
2474 + * You should have received a copy of the GNU General Public License
2475 + * along with this program; if not, write to the Free Software
2476 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2480 + * debugfs interface
2483 +#include <linux/debugfs.h>
2486 +#ifndef CONFIG_SYSFS
2487 +#error DEBUG_FS depends upon SYSFS
2490 +static struct dentry *dbgaufs;
2491 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
2493 +/* 20 is max digits length of ulong 64 */
2494 +struct dbgaufs_arg {
2500 + * common function for all XINO files
2502 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
2503 + struct file *file)
2505 + kfree(file->private_data);
2509 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
2513 + struct dbgaufs_arg *p;
2516 + p = kmalloc(sizeof(*p), GFP_NOFS);
2522 + file->private_data = p;
2526 + err = vfs_getattr(xf->f_vfsmnt, xf->f_dentry, &st);
2530 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
2531 + (long)file_count(xf), st.blocks, st.blksize,
2532 + (long long)st.size);
2534 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
2535 + st.blocks, st.blksize,
2536 + (long long)st.size);
2537 + AuDebugOn(p->n >= sizeof(p->a));
2539 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
2548 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
2549 + size_t count, loff_t *ppos)
2551 + struct dbgaufs_arg *p;
2553 + p = file->private_data;
2554 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
2557 +/* ---------------------------------------------------------------------- */
2559 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
2562 + struct au_sbinfo *sbinfo;
2563 + struct super_block *sb;
2565 + sbinfo = inode->i_private;
2566 + sb = sbinfo->si_sb;
2567 + si_noflush_read_lock(sb);
2568 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
2569 + si_read_unlock(sb);
2573 +static const struct file_operations dbgaufs_xib_fop = {
2574 + .open = dbgaufs_xib_open,
2575 + .release = dbgaufs_xi_release,
2576 + .read = dbgaufs_xi_read
2579 +/* ---------------------------------------------------------------------- */
2581 +#define DbgaufsXi_PREFIX "xi"
2583 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
2587 + struct au_sbinfo *sbinfo;
2588 + struct super_block *sb;
2590 + struct qstr *name;
2594 + name = &file->f_dentry->d_name;
2595 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
2596 + || memcmp(name->name, DbgaufsXi_PREFIX,
2597 + sizeof(DbgaufsXi_PREFIX) - 1)))
2599 + err = strict_strtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
2600 + if (unlikely(err))
2603 + sbinfo = inode->i_private;
2604 + sb = sbinfo->si_sb;
2605 + si_noflush_read_lock(sb);
2606 + if (l <= au_sbend(sb)) {
2607 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
2608 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
2611 + si_read_unlock(sb);
2617 +static const struct file_operations dbgaufs_xino_fop = {
2618 + .open = dbgaufs_xino_open,
2619 + .release = dbgaufs_xi_release,
2620 + .read = dbgaufs_xi_read
2623 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
2625 + aufs_bindex_t bend;
2626 + struct au_branch *br;
2627 + struct au_xino_file *xi;
2629 + if (!au_sbi(sb)->si_dbgaufs)
2632 + bend = au_sbend(sb);
2633 + for (; bindex <= bend; bindex++) {
2634 + br = au_sbr(sb, bindex);
2635 + xi = &br->br_xino;
2636 + if (xi->xi_dbgaufs) {
2637 + debugfs_remove(xi->xi_dbgaufs);
2638 + xi->xi_dbgaufs = NULL;
2643 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
2645 + struct au_sbinfo *sbinfo;
2646 + struct dentry *parent;
2647 + struct au_branch *br;
2648 + struct au_xino_file *xi;
2649 + aufs_bindex_t bend;
2650 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
2652 + sbinfo = au_sbi(sb);
2653 + parent = sbinfo->si_dbgaufs;
2657 + bend = au_sbend(sb);
2658 + for (; bindex <= bend; bindex++) {
2659 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
2660 + br = au_sbr(sb, bindex);
2661 + xi = &br->br_xino;
2662 + AuDebugOn(xi->xi_dbgaufs);
2663 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
2664 + sbinfo, &dbgaufs_xino_fop);
2665 + /* ignore an error */
2666 + if (unlikely(!xi->xi_dbgaufs))
2667 + AuWarn1("failed %s under debugfs\n", name);
2671 +/* ---------------------------------------------------------------------- */
2673 +#ifdef CONFIG_AUFS_EXPORT
2674 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
2677 + struct au_sbinfo *sbinfo;
2678 + struct super_block *sb;
2680 + sbinfo = inode->i_private;
2681 + sb = sbinfo->si_sb;
2682 + si_noflush_read_lock(sb);
2683 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
2684 + si_read_unlock(sb);
2688 +static const struct file_operations dbgaufs_xigen_fop = {
2689 + .open = dbgaufs_xigen_open,
2690 + .release = dbgaufs_xi_release,
2691 + .read = dbgaufs_xi_read
2694 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
2699 + * This function is a dynamic '__init' fucntion actually,
2700 + * so the tiny check for si_rwsem is unnecessary.
2702 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
2705 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
2706 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
2707 + &dbgaufs_xigen_fop);
2708 + if (sbinfo->si_dbgaufs_xigen)
2714 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
2718 +#endif /* CONFIG_AUFS_EXPORT */
2720 +/* ---------------------------------------------------------------------- */
2722 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
2725 + * This function is a dynamic '__init' fucntion actually,
2726 + * so the tiny check for si_rwsem is unnecessary.
2728 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
2730 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
2731 + sbinfo->si_dbgaufs = NULL;
2732 + kobject_put(&sbinfo->si_kobj);
2735 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
2738 + char name[SysaufsSiNameLen];
2741 + * This function is a dynamic '__init' fucntion actually,
2742 + * so the tiny check for si_rwsem is unnecessary.
2744 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
2748 + AuErr1("/debug/aufs is uninitialized\n");
2753 + sysaufs_name(sbinfo, name);
2754 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
2755 + if (unlikely(!sbinfo->si_dbgaufs))
2757 + kobject_get(&sbinfo->si_kobj);
2759 + sbinfo->si_dbgaufs_xib = debugfs_create_file
2760 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
2761 + &dbgaufs_xib_fop);
2762 + if (unlikely(!sbinfo->si_dbgaufs_xib))
2765 + err = dbgaufs_xigen_init(sbinfo);
2767 + goto out; /* success */
2770 + dbgaufs_si_fin(sbinfo);
2775 +/* ---------------------------------------------------------------------- */
2777 +void dbgaufs_fin(void)
2779 + debugfs_remove(dbgaufs);
2782 +int __init dbgaufs_init(void)
2787 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
2792 diff -urN linux-2.6.30.org/fs/aufs/dbgaufs.h linux-2.6.30/fs/aufs/dbgaufs.h
2793 --- linux-2.6.30.org/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
2794 +++ linux-2.6.30/fs/aufs/dbgaufs.h 2009-07-21 08:54:19.000000000 +0200
2797 + * Copyright (C) 2005-2009 Junjiro R. Okajima
2799 + * This program, aufs is free software; you can redistribute it and/or modify
2800 + * it under the terms of the GNU General Public License as published by
2801 + * the Free Software Foundation; either version 2 of the License, or
2802 + * (at your option) any later version.
2804 + * This program is distributed in the hope that it will be useful,
2805 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2806 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2807 + * GNU General Public License for more details.
2809 + * You should have received a copy of the GNU General Public License
2810 + * along with this program; if not, write to the Free Software
2811 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2815 + * debugfs interface
2818 +#ifndef __DBGAUFS_H__
2819 +#define __DBGAUFS_H__
2823 +#include <linux/init.h>
2824 +#include <linux/aufs_type.h>
2826 +struct super_block;
2829 +#ifdef CONFIG_DEBUG_FS
2831 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
2832 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
2833 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
2834 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
2835 +void dbgaufs_fin(void);
2836 +int __init dbgaufs_init(void);
2841 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
2847 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
2853 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
2859 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
2864 +#define dbgaufs_fin() do {} while (0)
2867 +int __init dbgaufs_init(void)
2871 +#endif /* CONFIG_DEBUG_FS */
2873 +#endif /* __KERNEL__ */
2874 +#endif /* __DBGAUFS_H__ */
2875 diff -urN linux-2.6.30.org/fs/aufs/dcsub.c linux-2.6.30/fs/aufs/dcsub.c
2876 --- linux-2.6.30.org/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
2877 +++ linux-2.6.30/fs/aufs/dcsub.c 2009-07-21 08:54:19.000000000 +0200
2880 + * Copyright (C) 2005-2009 Junjiro R. Okajima
2882 + * This program, aufs is free software; you can redistribute it and/or modify
2883 + * it under the terms of the GNU General Public License as published by
2884 + * the Free Software Foundation; either version 2 of the License, or
2885 + * (at your option) any later version.
2887 + * This program is distributed in the hope that it will be useful,
2888 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2889 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2890 + * GNU General Public License for more details.
2892 + * You should have received a copy of the GNU General Public License
2893 + * along with this program; if not, write to the Free Software
2894 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2898 + * sub-routines for dentry cache
2903 +static void au_dpage_free(struct au_dpage *dpage)
2906 + struct dentry **p;
2908 + p = dpage->dentries;
2909 + for (i = 0; i < dpage->ndentry; i++)
2911 + free_page((unsigned long)dpage->dentries);
2914 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
2920 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
2921 + if (unlikely(!dpages->dpages))
2924 + p = (void *)__get_free_page(gfp);
2928 + dpages->dpages[0].ndentry = 0;
2929 + dpages->dpages[0].dentries = p;
2930 + dpages->ndpage = 1;
2931 + return 0; /* success */
2934 + kfree(dpages->dpages);
2939 +void au_dpages_free(struct au_dcsub_pages *dpages)
2942 + struct au_dpage *p;
2944 + p = dpages->dpages;
2945 + for (i = 0; i < dpages->ndpage; i++)
2946 + au_dpage_free(p++);
2947 + kfree(dpages->dpages);
2950 +static int au_dpages_append(struct au_dcsub_pages *dpages,
2951 + struct dentry *dentry, gfp_t gfp)
2954 + struct au_dpage *dpage;
2957 + dpage = dpages->dpages + dpages->ndpage - 1;
2958 + sz = PAGE_SIZE / sizeof(dentry);
2959 + if (unlikely(dpage->ndentry >= sz)) {
2960 + AuLabel(new dpage);
2962 + sz = dpages->ndpage * sizeof(*dpages->dpages);
2963 + p = au_kzrealloc(dpages->dpages, sz,
2964 + sz + sizeof(*dpages->dpages), gfp);
2968 + dpages->dpages = p;
2969 + dpage = dpages->dpages + dpages->ndpage;
2970 + p = (void *)__get_free_page(gfp);
2974 + dpage->ndentry = 0;
2975 + dpage->dentries = p;
2979 + dpage->dentries[dpage->ndentry++] = dget(dentry);
2980 + return 0; /* success */
2986 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
2987 + au_dpages_test test, void *arg)
2990 + struct dentry *this_parent = root;
2991 + struct list_head *next;
2992 + struct super_block *sb = root->d_sb;
2995 + spin_lock(&dcache_lock);
2997 + next = this_parent->d_subdirs.next;
2999 + if (this_parent->d_sb == sb
3000 + && !IS_ROOT(this_parent)
3001 + && atomic_read(&this_parent->d_count)
3002 + && this_parent->d_inode
3003 + && (!test || test(this_parent, arg))) {
3004 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
3005 + if (unlikely(err))
3009 + while (next != &this_parent->d_subdirs) {
3010 + struct list_head *tmp = next;
3011 + struct dentry *dentry = list_entry(tmp, struct dentry,
3014 + if (/*d_unhashed(dentry) || */!dentry->d_inode)
3016 + if (!list_empty(&dentry->d_subdirs)) {
3017 + this_parent = dentry;
3020 + if (dentry->d_sb == sb
3021 + && atomic_read(&dentry->d_count)
3022 + && (!test || test(dentry, arg))) {
3023 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
3024 + if (unlikely(err))
3029 + if (this_parent != root) {
3030 + next = this_parent->d_u.d_child.next;
3031 + this_parent = this_parent->d_parent; /* dcache_lock is locked */
3035 + spin_unlock(&dcache_lock);
3039 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
3040 + int do_include, au_dpages_test test, void *arg)
3045 + spin_lock(&dcache_lock);
3046 + if (do_include && (!test || test(dentry, arg))) {
3047 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
3048 + if (unlikely(err))
3051 + while (!IS_ROOT(dentry)) {
3052 + dentry = dentry->d_parent; /* dcache_lock is locked */
3053 + if (!test || test(dentry, arg)) {
3054 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
3055 + if (unlikely(err))
3061 + spin_unlock(&dcache_lock);
3066 +struct dentry *au_test_subdir(struct dentry *d1, struct dentry *d2)
3068 + struct dentry *trap, **dentries;
3070 + struct au_dcsub_pages dpages;
3071 + struct au_dpage *dpage;
3073 + trap = ERR_PTR(-ENOMEM);
3074 + err = au_dpages_init(&dpages, GFP_NOFS);
3075 + if (unlikely(err))
3077 + err = au_dcsub_pages_rev(&dpages, d1, /*do_include*/1, NULL, NULL);
3078 + if (unlikely(err))
3082 + for (i = 0; !err && i < dpages.ndpage; i++) {
3083 + dpage = dpages.dpages + i;
3084 + dentries = dpage->dentries;
3085 + for (j = 0; !err && j < dpage->ndentry; j++) {
3098 + au_dpages_free(&dpages);
3102 diff -urN linux-2.6.30.org/fs/aufs/dcsub.h linux-2.6.30/fs/aufs/dcsub.h
3103 --- linux-2.6.30.org/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
3104 +++ linux-2.6.30/fs/aufs/dcsub.h 2009-07-21 08:54:19.000000000 +0200
3107 + * Copyright (C) 2005-2009 Junjiro R. Okajima
3109 + * This program, aufs is free software; you can redistribute it and/or modify
3110 + * it under the terms of the GNU General Public License as published by
3111 + * the Free Software Foundation; either version 2 of the License, or
3112 + * (at your option) any later version.
3114 + * This program is distributed in the hope that it will be useful,
3115 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3117 + * GNU General Public License for more details.
3119 + * You should have received a copy of the GNU General Public License
3120 + * along with this program; if not, write to the Free Software
3121 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3125 + * sub-routines for dentry cache
3128 +#ifndef __AUFS_DCSUB_H__
3129 +#define __AUFS_DCSUB_H__
3133 +#include <linux/types.h>
3139 + struct dentry **dentries;
3142 +struct au_dcsub_pages {
3144 + struct au_dpage *dpages;
3147 +/* ---------------------------------------------------------------------- */
3149 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
3150 +void au_dpages_free(struct au_dcsub_pages *dpages);
3151 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
3152 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
3153 + au_dpages_test test, void *arg);
3154 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
3155 + int do_include, au_dpages_test test, void *arg);
3156 +struct dentry *au_test_subdir(struct dentry *d1, struct dentry *d2);
3158 +#endif /* __KERNEL__ */
3159 +#endif /* __AUFS_DCSUB_H__ */
3160 diff -urN linux-2.6.30.org/fs/aufs/debug.c linux-2.6.30/fs/aufs/debug.c
3161 --- linux-2.6.30.org/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
3162 +++ linux-2.6.30/fs/aufs/debug.c 2009-07-21 08:54:19.000000000 +0200
3165 + * Copyright (C) 2005-2009 Junjiro R. Okajima
3167 + * This program, aufs is free software; you can redistribute it and/or modify
3168 + * it under the terms of the GNU General Public License as published by
3169 + * the Free Software Foundation; either version 2 of the License, or
3170 + * (at your option) any later version.
3172 + * This program is distributed in the hope that it will be useful,
3173 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3174 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3175 + * GNU General Public License for more details.
3177 + * You should have received a copy of the GNU General Public License
3178 + * along with this program; if not, write to the Free Software
3179 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3183 + * debug print functions
3186 +#include <linux/module.h>
3187 +#include <linux/vt_kern.h>
3191 +MODULE_PARM_DESC(debug, "debug print");
3192 +module_param_named(debug, aufs_debug, int, S_IRUGO | S_IWUSR | S_IWGRP);
3194 +char *au_plevel = KERN_DEBUG;
3195 +#define dpri(fmt, arg...) do { \
3196 + if (au_debug_test()) \
3197 + printk("%s" fmt, au_plevel, ##arg); \
3200 +/* ---------------------------------------------------------------------- */
3202 +void au_dpri_whlist(struct au_nhash *whlist)
3204 + unsigned long ul, n;
3205 + struct hlist_head *head;
3206 + struct au_vdir_wh *tpos;
3207 + struct hlist_node *pos;
3209 + n = whlist->nh_num;
3210 + head = whlist->nh_head;
3211 + for (ul = 0; ul < n; ul++) {
3212 + hlist_for_each_entry(tpos, pos, head, wh_hash)
3213 + dpri("b%d, %.*s, %d\n",
3215 + tpos->wh_str.len, tpos->wh_str.name,
3216 + tpos->wh_str.len);
3221 +void au_dpri_vdir(struct au_vdir *vdir)
3224 + union au_vdir_deblk_p p;
3227 + if (!vdir || IS_ERR(vdir)) {
3228 + dpri("err %ld\n", PTR_ERR(vdir));
3232 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
3233 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
3234 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
3235 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
3236 + p.deblk = vdir->vd_deblk[ul];
3238 + dpri("[%lu]: %p\n", ul, o);
3242 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode,
3243 + struct dentry *wh)
3248 + if (!inode || IS_ERR(inode)) {
3249 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
3253 + /* the type of i_blocks depends upon CONFIG_LSF */
3254 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
3255 + && sizeof(inode->i_blocks) != sizeof(u64));
3257 + n = (void *)wh->d_name.name;
3258 + l = wh->d_name.len;
3261 + dpri("i%d: i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
3262 + " ct %lld, np %lu, st 0x%lx, f 0x%x, g %x%s%.*s\n",
3264 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
3265 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
3266 + i_size_read(inode), (unsigned long long)inode->i_blocks,
3267 + (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
3268 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
3269 + inode->i_state, inode->i_flags, inode->i_generation,
3270 + l ? ", wh " : "", l, n);
3274 +void au_dpri_inode(struct inode *inode)
3276 + struct au_iinfo *iinfo;
3277 + aufs_bindex_t bindex;
3280 + err = do_pri_inode(-1, inode, NULL);
3281 + if (err || !au_test_aufs(inode->i_sb))
3284 + iinfo = au_ii(inode);
3287 + dpri("i-1: bstart %d, bend %d, gen %d\n",
3288 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode));
3289 + if (iinfo->ii_bstart < 0)
3291 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++)
3292 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode,
3293 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
3296 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
3298 + struct dentry *wh = NULL;
3300 + if (!dentry || IS_ERR(dentry)) {
3301 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
3304 + /* do not call dget_parent() here */
3305 + dpri("d%d: %.*s?/%.*s, %s, cnt %d, flags 0x%x\n",
3307 + AuDLNPair(dentry->d_parent), AuDLNPair(dentry),
3308 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
3309 + atomic_read(&dentry->d_count), dentry->d_flags);
3310 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
3311 + struct au_iinfo *iinfo = au_ii(dentry->d_inode);
3313 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
3315 + do_pri_inode(bindex, dentry->d_inode, wh);
3319 +void au_dpri_dentry(struct dentry *dentry)
3321 + struct au_dinfo *dinfo;
3322 + aufs_bindex_t bindex;
3325 + err = do_pri_dentry(-1, dentry);
3326 + if (err || !au_test_aufs(dentry->d_sb))
3329 + dinfo = au_di(dentry);
3332 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d\n",
3333 + dinfo->di_bstart, dinfo->di_bend,
3334 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry));
3335 + if (dinfo->di_bstart < 0)
3337 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
3338 + do_pri_dentry(bindex, dinfo->di_hdentry[0 + bindex].hd_dentry);
3341 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
3345 + if (!file || IS_ERR(file)) {
3346 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
3352 + && au_test_aufs(file->f_dentry->d_sb)
3354 + snprintf(a, sizeof(a), ", mmapped %d", au_test_mmapped(file));
3355 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, pos %llu%s\n",
3356 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
3358 + if (file->f_dentry)
3359 + do_pri_dentry(bindex, file->f_dentry);
3363 +void au_dpri_file(struct file *file)
3365 + struct au_finfo *finfo;
3366 + aufs_bindex_t bindex;
3369 + err = do_pri_file(-1, file);
3370 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
3373 + finfo = au_fi(file);
3376 + if (finfo->fi_bstart < 0)
3378 + for (bindex = finfo->fi_bstart; bindex <= finfo->fi_bend; bindex++) {
3379 + struct au_hfile *hf;
3381 + hf = finfo->fi_hfile + bindex;
3382 + do_pri_file(bindex, hf ? hf->hf_file : NULL);
3386 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
3388 + struct vfsmount *mnt;
3389 + struct super_block *sb;
3391 + if (!br || IS_ERR(br))
3394 + if (!mnt || IS_ERR(mnt))
3397 + if (!sb || IS_ERR(sb))
3400 + dpri("s%d: {perm 0x%x, cnt %d, wbr %p}, "
3401 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt(BIAS) %d, active %d, "
3403 + bindex, br->br_perm, atomic_read(&br->br_count), br->br_wbr,
3404 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
3405 + sb->s_flags, sb->s_count - S_BIAS,
3406 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
3410 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
3414 +void au_dpri_sb(struct super_block *sb)
3416 + struct au_sbinfo *sbinfo;
3417 + aufs_bindex_t bindex;
3419 + /* to reuduce stack size */
3421 + struct vfsmount mnt;
3422 + struct au_branch fake;
3425 + /* this function can be called from magic sysrq */
3426 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
3427 + if (unlikely(!a)) {
3428 + dpri("no memory\n");
3432 + a->mnt.mnt_sb = sb;
3433 + a->fake.br_perm = 0;
3434 + a->fake.br_mnt = &a->mnt;
3435 + a->fake.br_xino.xi_file = NULL;
3436 + atomic_set(&a->fake.br_count, 0);
3437 + smp_mb(); /* atomic_set */
3438 + err = do_pri_br(-1, &a->fake);
3440 + dpri("dev 0x%x\n", sb->s_dev);
3441 + if (err || !au_test_aufs(sb))
3444 + sbinfo = au_sbi(sb);
3447 + dpri("nw %d, gen %u, kobj %d\n",
3448 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
3449 + atomic_read(&sbinfo->si_kobj.kref.refcount));
3450 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
3451 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
3454 +/* ---------------------------------------------------------------------- */
3456 +void au_dbg_sleep_jiffy(int jiffy)
3459 + jiffy = schedule_timeout_uninterruptible(jiffy);
3462 +void au_dbg_iattr(struct iattr *ia)
3464 +#define AuBit(name) if (ia->ia_valid & ATTR_ ## name) \
3484 + dpri("ia_file %p\n", ia->ia_file);
3487 +/* ---------------------------------------------------------------------- */
3489 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
3491 + struct dentry *parent;
3493 + parent = dget_parent(dentry);
3494 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode)
3495 + || IS_ROOT(dentry)
3496 + || au_digen(parent) != sigen);
3500 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
3502 + struct dentry *parent;
3504 + parent = dget_parent(dentry);
3505 + AuDebugOn(S_ISDIR(dentry->d_inode->i_mode)
3506 + || au_digen(parent) != sigen);
3510 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
3513 + struct au_dcsub_pages dpages;
3514 + struct au_dpage *dpage;
3515 + struct dentry **dentries;
3517 + err = au_dpages_init(&dpages, GFP_NOFS);
3519 + err = au_dcsub_pages_rev(&dpages, parent, /*do_include*/1, NULL, NULL);
3521 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
3522 + dpage = dpages.dpages + i;
3523 + dentries = dpage->dentries;
3524 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
3525 + AuDebugOn(au_digen(dentries[j]) != sigen);
3527 + au_dpages_free(&dpages);
3530 +void au_dbg_verify_hf(struct au_finfo *finfo)
3532 + struct au_hfile *hf;
3533 + aufs_bindex_t bend, bindex;
3535 + if (finfo->fi_bstart >= 0) {
3536 + bend = finfo->fi_bend;
3537 + for (bindex = finfo->fi_bstart; bindex <= bend; bindex++) {
3538 + hf = finfo->fi_hfile + bindex;
3539 + AuDebugOn(hf->hf_file || hf->hf_br);
3544 +void au_dbg_verify_kthread(void)
3546 + if (au_test_wkq(current)) {
3552 +/* ---------------------------------------------------------------------- */
3554 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
3556 +#ifdef AuForceNoPlink
3557 + au_opt_clr(sbinfo->si_mntflags, PLINK);
3559 +#ifdef AuForceNoXino
3560 + au_opt_clr(sbinfo->si_mntflags, XINO);
3562 +#ifdef AuForceNoRefrof
3563 + au_opt_clr(sbinfo->si_mntflags, REFROF);
3565 +#ifdef AuForceHinotify
3566 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HINOTIFY);
3570 +int __init au_debug_init(void)
3572 + aufs_bindex_t bindex;
3573 + struct au_vdir_destr destr;
3576 + AuDebugOn(bindex >= 0);
3579 + AuDebugOn(destr.len < NAME_MAX);
3581 +#ifdef CONFIG_4KSTACKS
3582 + AuWarn("CONFIG_4KSTACKS is defined.\n");
3585 +#ifdef AuForceNoBrs
3591 diff -urN linux-2.6.30.org/fs/aufs/debug.h linux-2.6.30/fs/aufs/debug.h
3592 --- linux-2.6.30.org/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
3593 +++ linux-2.6.30/fs/aufs/debug.h 2009-07-21 08:54:19.000000000 +0200
3596 + * Copyright (C) 2005-2009 Junjiro R. Okajima
3598 + * This program, aufs is free software; you can redistribute it and/or modify
3599 + * it under the terms of the GNU General Public License as published by
3600 + * the Free Software Foundation; either version 2 of the License, or
3601 + * (at your option) any later version.
3603 + * This program is distributed in the hope that it will be useful,
3604 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3605 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3606 + * GNU General Public License for more details.
3608 + * You should have received a copy of the GNU General Public License
3609 + * along with this program; if not, write to the Free Software
3610 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3614 + * debug print functions
3617 +#ifndef __AUFS_DEBUG_H__
3618 +#define __AUFS_DEBUG_H__
3622 +#include <linux/bug.h>
3623 +/* #include <linux/err.h> */
3624 +/* #include <linux/init.h> */
3625 +/* #include <linux/kernel.h> */
3626 +#include <linux/delay.h>
3627 +/* #include <linux/kd.h> */
3628 +/* #include <linux/vt_kern.h> */
3629 +#include <linux/sysrq.h>
3630 +#include <linux/aufs_type.h>
3632 +#ifdef CONFIG_AUFS_DEBUG
3633 +#define AuDebugOn(a) BUG_ON(a)
3635 +/* module parameter */
3636 +extern int aufs_debug;
3637 +static inline void au_debug(int n)
3643 +static inline int au_debug_test(void)
3645 + return aufs_debug;
3648 +#define AuDebugOn(a) do {} while (0)
3649 +#define au_debug() do {} while (0)
3650 +static inline int au_debug_test(void)
3654 +#endif /* CONFIG_AUFS_DEBUG */
3656 +/* ---------------------------------------------------------------------- */
3660 +#define AuDpri(lvl, fmt, arg...) \
3661 + printk(lvl AUFS_NAME " %s:%d:%s[%d]: " fmt, \
3662 + __func__, __LINE__, current->comm, current->pid, ##arg)
3663 +#define AuDbg(fmt, arg...) do { \
3664 + if (au_debug_test()) \
3665 + AuDpri(KERN_DEBUG, fmt, ##arg); \
3667 +#define AuLabel(l) AuDbg(#l "\n")
3668 +#define AuInfo(fmt, arg...) AuDpri(KERN_INFO, fmt, ##arg)
3669 +#define AuWarn(fmt, arg...) AuDpri(KERN_WARNING, fmt, ##arg)
3670 +#define AuErr(fmt, arg...) AuDpri(KERN_ERR, fmt, ##arg)
3671 +#define AuIOErr(fmt, arg...) AuErr("I/O Error, " fmt, ##arg)
3672 +#define AuWarn1(fmt, arg...) do { \
3673 + static unsigned char _c; \
3675 + AuWarn(fmt, ##arg); \
3678 +#define AuErr1(fmt, arg...) do { \
3679 + static unsigned char _c; \
3681 + AuErr(fmt, ##arg); \
3684 +#define AuIOErr1(fmt, arg...) do { \
3685 + static unsigned char _c; \
3687 + AuIOErr(fmt, ##arg); \
3690 +#define AuUnsupportMsg "This operation is not supported." \
3691 + " Please report this application to aufs-users ML."
3692 +#define AuUnsupport(fmt, args...) do { \
3693 + AuErr(AuUnsupportMsg "\n" fmt, ##args); \
3697 +#define AuTraceErr(e) do { \
3698 + if (unlikely((e) < 0)) \
3699 + AuDbg("err %d\n", (int)(e)); \
3702 +#define AuTraceErrPtr(p) do { \
3704 + AuDbg("err %ld\n", PTR_ERR(p)); \
3707 +/* dirty macros for debug print, use with "%.*s" and caution */
3708 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
3709 +#define AuDLNPair(d) AuLNPair(&(d)->d_name)
3711 +/* ---------------------------------------------------------------------- */
3716 +#ifdef CONFIG_AUFS_DEBUG
3717 +extern char *au_plevel;
3719 +void au_dpri_whlist(struct au_nhash *whlist);
3721 +void au_dpri_vdir(struct au_vdir *vdir);
3723 +void au_dpri_inode(struct inode *inode);
3724 +void au_dpri_dentry(struct dentry *dentry);
3726 +void au_dpri_file(struct file *filp);
3727 +struct super_block;
3728 +void au_dpri_sb(struct super_block *sb);
3730 +void au_dbg_sleep_jiffy(int jiffy);
3732 +void au_dbg_iattr(struct iattr *ia);
3734 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
3735 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
3736 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
3737 +void au_dbg_verify_hf(struct au_finfo *finfo);
3738 +void au_dbg_verify_kthread(void);
3740 +int __init au_debug_init(void);
3741 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
3742 +#define AuDbgWhlist(w) do { \
3744 + au_dpri_whlist(w); \
3747 +#define AuDbgVdir(v) do { \
3749 + au_dpri_vdir(v); \
3752 +#define AuDbgInode(i) do { \
3754 + au_dpri_inode(i); \
3757 +#define AuDbgDentry(d) do { \
3759 + au_dpri_dentry(d); \
3762 +#define AuDbgFile(f) do { \
3764 + au_dpri_file(f); \
3767 +#define AuDbgSb(sb) do { \
3768 + AuDbg(#sb "\n"); \
3772 +#define AuDbgSleep(sec) do { \
3773 + AuDbg("sleep %d sec\n", sec); \
3777 +#define AuDbgSleepJiffy(jiffy) do { \
3778 + AuDbg("sleep %d jiffies\n", jiffy); \
3779 + au_dbg_sleep_jiffy(jiffy); \
3782 +#define AuDbgIAttr(ia) do { \
3783 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
3784 + au_dbg_iattr(ia); \
3787 +static inline void au_dbg_verify_dir_parent(struct dentry *dentry,
3788 + unsigned int sigen)
3792 +static inline void au_dbg_verify_nondir_parent(struct dentry *dentry,
3793 + unsigned int sigen)
3797 +static inline void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
3801 +static inline void au_dbg_verify_hf(struct au_finfo *finfo)
3805 +static inline void au_dbg_verify_kthread(void)
3810 +static inline int au_debug_init(void)
3814 +static inline void au_debug_sbinfo_init(struct au_sbinfo *sbinfo)
3818 +#define AuDbgWhlist(w) do {} while (0)
3819 +#define AuDbgVdir(v) do {} while (0)
3820 +#define AuDbgInode(i) do {} while (0)
3821 +#define AuDbgDentry(d) do {} while (0)
3822 +#define AuDbgFile(f) do {} while (0)
3823 +#define AuDbgSb(sb) do {} while (0)
3824 +#define AuDbgSleep(sec) do {} while (0)
3825 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
3826 +#define AuDbgIAttr(ia) do {} while (0)
3827 +#endif /* CONFIG_AUFS_DEBUG */
3829 +/* ---------------------------------------------------------------------- */
3831 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
3832 +int __init au_sysrq_init(void);
3833 +void au_sysrq_fin(void);
3835 +#ifdef CONFIG_HW_CONSOLE
3836 +#define au_dbg_blocked() do { \
3838 + handle_sysrq('w', vc_cons[fg_console].d->vc_tty); \
3841 +#define au_dbg_blocked() do {} while (0)
3845 +static inline int au_sysrq_init(void)
3849 +#define au_sysrq_fin() do {} while (0)
3850 +#define au_dbg_blocked() do {} while (0)
3851 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
3853 +#endif /* __KERNEL__ */
3854 +#endif /* __AUFS_DEBUG_H__ */
3855 diff -urN linux-2.6.30.org/fs/aufs/dentry.c linux-2.6.30/fs/aufs/dentry.c
3856 --- linux-2.6.30.org/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
3857 +++ linux-2.6.30/fs/aufs/dentry.c 2009-07-21 08:54:19.000000000 +0200
3860 + * Copyright (C) 2005-2009 Junjiro R. Okajima
3862 + * This program, aufs is free software; you can redistribute it and/or modify
3863 + * it under the terms of the GNU General Public License as published by
3864 + * the Free Software Foundation; either version 2 of the License, or
3865 + * (at your option) any later version.
3867 + * This program is distributed in the hope that it will be useful,
3868 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3869 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3870 + * GNU General Public License for more details.
3872 + * You should have received a copy of the GNU General Public License
3873 + * along with this program; if not, write to the Free Software
3874 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3878 + * lookup and dentry operations
3881 +#include <linux/namei.h>
3884 +static void au_h_nd(struct nameidata *h_nd, struct nameidata *nd)
3890 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
3891 + * due to whiteout and branch permission.
3893 + h_nd->flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
3895 + /* unnecessary? */
3896 + h_nd->intent.open.file = NULL;
3898 + memset(h_nd, 0, sizeof(*h_nd));
3901 +struct au_lkup_one_args {
3902 + struct dentry **errp;
3903 + struct qstr *name;
3904 + struct dentry *h_parent;
3905 + struct au_branch *br;
3906 + struct nameidata *nd;
3909 +struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
3910 + struct au_branch *br, struct nameidata *nd)
3912 + struct dentry *h_dentry;
3914 + struct nameidata h_nd;
3916 + if (au_test_fs_null_nd(h_parent->d_sb))
3917 + return vfsub_lookup_one_len(name->name, h_parent, name->len);
3919 + au_h_nd(&h_nd, nd);
3920 + h_nd.path.dentry = h_parent;
3921 + h_nd.path.mnt = br->br_mnt;
3923 + err = __lookup_one_len(name->name, &h_nd.last, NULL, name->len);
3924 + h_dentry = ERR_PTR(err);
3926 + path_get(&h_nd.path);
3927 + h_dentry = vfsub_lookup_hash(&h_nd);
3928 + path_put(&h_nd.path);
3934 +static void au_call_lkup_one(void *args)
3936 + struct au_lkup_one_args *a = args;
3937 + *a->errp = au_lkup_one(a->name, a->h_parent, a->br, a->nd);
3940 +#define AuLkup_ALLOW_NEG 1
3941 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
3942 +#define au_fset_lkup(flags, name) { (flags) |= AuLkup_##name; }
3943 +#define au_fclr_lkup(flags, name) { (flags) &= ~AuLkup_##name; }
3945 +struct au_do_lookup_args {
3946 + unsigned int flags;
3948 + struct nameidata *nd;
3952 + * returns positive/negative dentry, NULL or an error.
3953 + * NULL means whiteout-ed or not-found.
3955 +static struct dentry*
3956 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
3957 + aufs_bindex_t bindex, struct qstr *wh_name,
3958 + struct au_do_lookup_args *args)
3960 + struct dentry *h_dentry;
3961 + struct inode *h_inode, *inode;
3962 + struct qstr *name;
3963 + struct au_branch *br;
3964 + int wh_found, opq;
3965 + unsigned char wh_able;
3966 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
3968 + name = &dentry->d_name;
3970 + br = au_sbr(dentry->d_sb, bindex);
3971 + wh_able = !!au_br_whable(br->br_perm);
3973 + wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
3974 + h_dentry = ERR_PTR(wh_found);
3977 + if (unlikely(wh_found < 0))
3980 + /* We found a whiteout */
3981 + /* au_set_dbend(dentry, bindex); */
3982 + au_set_dbwh(dentry, bindex);
3984 + return NULL; /* success */
3987 + h_dentry = au_lkup_one(name, h_parent, br, args->nd);
3988 + if (IS_ERR(h_dentry))
3991 + h_inode = h_dentry->d_inode;
3995 + } else if (wh_found
3996 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
3999 + if (au_dbend(dentry) <= bindex)
4000 + au_set_dbend(dentry, bindex);
4001 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
4002 + au_set_dbstart(dentry, bindex);
4003 + au_set_h_dptr(dentry, bindex, h_dentry);
4005 + inode = dentry->d_inode;
4006 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
4007 + || (inode && !S_ISDIR(inode->i_mode)))
4008 + goto out; /* success */
4010 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
4011 + opq = au_diropq_test(h_dentry, br);
4012 + mutex_unlock(&h_inode->i_mutex);
4014 + au_set_dbdiropq(dentry, bindex);
4015 + else if (unlikely(opq < 0)) {
4016 + au_set_h_dptr(dentry, bindex, NULL);
4017 + h_dentry = ERR_PTR(opq);
4028 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
4030 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
4031 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
4037 + * returns the number of lower positive dentries,
4038 + * otherwise an error.
4039 + * can be called at unlinking with @type is zero.
4041 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
4042 + struct nameidata *nd)
4044 + int npositive, err;
4045 + aufs_bindex_t bindex, btail, bdiropq;
4046 + unsigned char isdir;
4047 + struct qstr whname;
4048 + struct au_do_lookup_args args = {
4053 + const struct qstr *name = &dentry->d_name;
4054 + struct dentry *parent;
4055 + struct inode *inode;
4057 + parent = dget_parent(dentry);
4058 + err = au_test_shwh(dentry->d_sb, name);
4059 + if (unlikely(err))
4062 + err = au_wh_name_alloc(&whname, name);
4063 + if (unlikely(err))
4066 + inode = dentry->d_inode;
4067 + isdir = !!(inode && S_ISDIR(inode->i_mode));
4069 + au_fset_lkup(args.flags, ALLOW_NEG);
4072 + btail = au_dbtaildir(parent);
4073 + for (bindex = bstart; bindex <= btail; bindex++) {
4074 + struct dentry *h_parent, *h_dentry;
4075 + struct inode *h_inode, *h_dir;
4077 + h_dentry = au_h_dptr(dentry, bindex);
4079 + if (h_dentry->d_inode)
4081 + if (type != S_IFDIR)
4085 + h_parent = au_h_dptr(parent, bindex);
4088 + h_dir = h_parent->d_inode;
4089 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
4092 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
4093 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
4095 + mutex_unlock(&h_dir->i_mutex);
4096 + err = PTR_ERR(h_dentry);
4097 + if (IS_ERR(h_dentry))
4099 + au_fclr_lkup(args.flags, ALLOW_NEG);
4101 + if (au_dbwh(dentry) >= 0)
4105 + h_inode = h_dentry->d_inode;
4110 + args.type = h_inode->i_mode & S_IFMT;
4111 + if (args.type != S_IFDIR)
4114 + /* the type of lower may be different */
4115 + bdiropq = au_dbdiropq(dentry);
4116 + if (bdiropq >= 0 && bdiropq <= bindex)
4122 + AuLabel(positive);
4123 + au_update_dbstart(dentry);
4126 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
4127 + && au_dbstart(dentry) < 0))
4128 + /* both of real entry and whiteout found */
4132 + kfree(whname.name);
4138 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
4139 + struct au_branch *br)
4141 + struct dentry *dentry;
4144 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
4145 + dentry = au_lkup_one(name, parent, br, /*nd*/NULL);
4147 + struct au_lkup_one_args args = {
4150 + .h_parent = parent,
4155 + wkq_err = au_wkq_wait(au_call_lkup_one, &args);
4156 + if (unlikely(wkq_err))
4157 + dentry = ERR_PTR(wkq_err);
4164 + * lookup @dentry on @bindex which should be negative.
4166 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
4169 + struct dentry *parent, *h_parent, *h_dentry;
4170 + struct qstr *name;
4172 + name = &dentry->d_name;
4173 + parent = dget_parent(dentry);
4174 + h_parent = au_h_dptr(parent, bindex);
4175 + h_dentry = au_sio_lkup_one(name, h_parent,
4176 + au_sbr(dentry->d_sb, bindex));
4177 + err = PTR_ERR(h_dentry);
4178 + if (IS_ERR(h_dentry))
4180 + if (unlikely(h_dentry->d_inode)) {
4182 + AuIOErr("b%d %.*s should be negative.\n",
4183 + bindex, AuDLNPair(h_dentry));
4188 + if (bindex < au_dbstart(dentry))
4189 + au_set_dbstart(dentry, bindex);
4190 + if (au_dbend(dentry) < bindex)
4191 + au_set_dbend(dentry, bindex);
4192 + au_set_h_dptr(dentry, bindex, h_dentry);
4200 +/* ---------------------------------------------------------------------- */
4202 +/* subset of struct inode */
4204 + unsigned long i_ino;
4205 + /* unsigned int i_nlink; */
4211 + blkcnt_t i_blocks;
4216 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
4218 + ia->i_ino = h_inode->i_ino;
4219 + /* ia->i_nlink = h_inode->i_nlink; */
4220 + ia->i_uid = h_inode->i_uid;
4221 + ia->i_gid = h_inode->i_gid;
4222 + ia->i_version = h_inode->i_version;
4224 + ia->i_size = h_inode->i_size;
4225 + ia->i_blocks = h_inode->i_blocks;
4227 + ia->i_mode = (h_inode->i_mode & S_IFMT);
4230 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
4232 + return ia->i_ino != h_inode->i_ino
4233 + /* || ia->i_nlink != h_inode->i_nlink */
4234 + || ia->i_uid != h_inode->i_uid
4235 + || ia->i_gid != h_inode->i_gid
4236 + || ia->i_version != h_inode->i_version
4238 + || ia->i_size != h_inode->i_size
4239 + || ia->i_blocks != h_inode->i_blocks
4241 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
4244 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
4245 + struct au_branch *br)
4248 + struct au_iattr ia;
4249 + struct inode *h_inode;
4250 + struct dentry *h_d;
4251 + struct super_block *h_sb;
4254 + memset(&ia, -1, sizeof(ia));
4255 + h_sb = h_dentry->d_sb;
4256 + h_inode = h_dentry->d_inode;
4258 + au_iattr_save(&ia, h_inode);
4259 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
4260 + /* nfs d_revalidate may return 0 for negative dentry */
4261 + /* fuse d_revalidate always return 0 for negative dentry */
4264 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
4265 + h_d = au_lkup_one(&h_dentry->d_name, h_parent, br, /*nd*/NULL);
4266 + err = PTR_ERR(h_d);
4271 + if (unlikely(h_d != h_dentry
4272 + || h_d->d_inode != h_inode
4273 + || (h_inode && au_iattr_test(&ia, h_inode))))
4274 + err = au_busy_or_stale();
4282 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
4283 + struct dentry *h_parent, struct au_branch *br)
4288 + if (udba == AuOpt_UDBA_REVAL) {
4290 + err = (h_dentry->d_parent->d_inode != h_dir);
4291 + } else if (udba == AuOpt_UDBA_HINOTIFY)
4292 + err = au_h_verify_dentry(h_dentry, h_parent, br);
4297 +/* ---------------------------------------------------------------------- */
4299 +static void au_do_refresh_hdentry(struct au_hdentry *p, struct au_dinfo *dinfo,
4300 + struct dentry *parent)
4302 + struct dentry *h_d, *h_dp;
4303 + struct au_hdentry tmp, *q;
4304 + struct super_block *sb;
4305 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
4307 + bend = dinfo->di_bend;
4308 + bwh = dinfo->di_bwh;
4309 + bdiropq = dinfo->di_bdiropq;
4310 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
4311 + h_d = p->hd_dentry;
4315 + h_dp = dget_parent(h_d);
4316 + if (h_dp == au_h_dptr(parent, bindex)) {
4321 + new_bindex = au_find_dbindex(parent, h_dp);
4323 + if (dinfo->di_bwh == bindex)
4325 + if (dinfo->di_bdiropq == bindex)
4326 + bdiropq = new_bindex;
4327 + if (new_bindex < 0) {
4329 + p->hd_dentry = NULL;
4333 + /* swap two lower dentries, and loop again */
4334 + q = dinfo->di_hdentry + new_bindex;
4338 + if (tmp.hd_dentry) {
4344 + sb = parent->d_sb;
4345 + dinfo->di_bwh = -1;
4346 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
4347 + dinfo->di_bwh = bwh;
4349 + dinfo->di_bdiropq = -1;
4351 + && bdiropq <= au_sbend(sb)
4352 + && au_sbr_whable(sb, bdiropq))
4353 + dinfo->di_bdiropq = bdiropq;
4355 + bend = au_dbend(parent);
4356 + p = dinfo->di_hdentry;
4357 + for (bindex = 0; bindex <= bend; bindex++, p++)
4358 + if (p->hd_dentry) {
4359 + dinfo->di_bstart = bindex;
4363 + p = dinfo->di_hdentry + bend;
4364 + for (bindex = bend; bindex >= 0; bindex--, p--)
4365 + if (p->hd_dentry) {
4366 + dinfo->di_bend = bindex;
4372 + * returns the number of found lower positive dentries,
4373 + * otherwise an error.
4375 +int au_refresh_hdentry(struct dentry *dentry, mode_t type)
4377 + int npositive, err;
4378 + unsigned int sigen;
4379 + aufs_bindex_t bstart;
4380 + struct au_dinfo *dinfo;
4381 + struct super_block *sb;
4382 + struct dentry *parent;
4384 + sb = dentry->d_sb;
4385 + AuDebugOn(IS_ROOT(dentry));
4386 + sigen = au_sigen(sb);
4387 + parent = dget_parent(dentry);
4388 + AuDebugOn(au_digen(parent) != sigen
4389 + || au_iigen(parent->d_inode) != sigen);
4391 + dinfo = au_di(dentry);
4392 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
4394 + if (unlikely(err))
4396 + au_do_refresh_hdentry(dinfo->di_hdentry + dinfo->di_bstart, dinfo,
4400 + bstart = au_dbstart(parent);
4401 + if (type != S_IFDIR && dinfo->di_bstart == bstart)
4402 + goto out_dgen; /* success */
4404 + npositive = au_lkup_dentry(dentry, bstart, type, /*nd*/NULL);
4405 + if (npositive < 0)
4407 + if (dinfo->di_bwh >= 0 && dinfo->di_bwh <= dinfo->di_bstart)
4411 + au_update_digen(dentry);
4414 + AuTraceErr(npositive);
4418 +static noinline_for_stack
4419 +int au_do_h_d_reval(struct dentry *h_dentry, struct nameidata *nd,
4420 + struct dentry *dentry, aufs_bindex_t bindex)
4423 + int (*reval)(struct dentry *, struct nameidata *);
4427 + if (h_dentry->d_op)
4428 + reval = h_dentry->d_op->d_revalidate;
4432 + AuDbg("b%d\n", bindex);
4433 + if (au_test_fs_null_nd(h_dentry->d_sb))
4434 + /* it may return tri-state */
4435 + valid = reval(h_dentry, NULL);
4437 + struct nameidata h_nd;
4439 + struct dentry *parent;
4441 + au_h_nd(&h_nd, nd);
4442 + parent = nd->path.dentry;
4443 + locked = (nd && nd->path.dentry != dentry);
4445 + di_read_lock_parent(parent, AuLock_IR);
4446 + BUG_ON(bindex > au_dbend(parent));
4447 + h_nd.path.dentry = au_h_dptr(parent, bindex);
4448 + BUG_ON(!h_nd.path.dentry);
4449 + h_nd.path.mnt = au_sbr(parent->d_sb, bindex)->br_mnt;
4450 + path_get(&h_nd.path);
4451 + valid = reval(h_dentry, &h_nd);
4452 + path_put(&h_nd.path);
4454 + di_read_unlock(parent, AuLock_IR);
4457 + if (unlikely(valid < 0))
4467 +/* todo: remove this */
4468 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
4469 + struct nameidata *nd, int do_udba)
4472 + umode_t mode, h_mode;
4473 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
4474 + unsigned char plus, unhashed, is_root, h_plus;
4475 + struct inode *first, *h_inode, *h_cached_inode;
4476 + struct dentry *h_dentry;
4477 + struct qstr *name, *h_name;
4485 + unhashed = !!d_unhashed(dentry);
4486 + is_root = !!IS_ROOT(dentry);
4487 + name = &dentry->d_name;
4490 + * Theoretically, REVAL test should be unnecessary in case of INOTIFY.
4491 + * But inotify doesn't fire some necessary events,
4492 + * IN_ATTRIB for atime/nlink/pageio
4493 + * IN_DELETE for NFS dentry
4494 + * Let's do REVAL test too.
4496 + if (do_udba && inode) {
4497 + mode = (inode->i_mode & S_IFMT);
4498 + plus = (inode->i_nlink > 0);
4499 + first = au_h_iptr(inode, au_ibstart(inode));
4500 + ibs = au_ibstart(inode);
4501 + ibe = au_ibend(inode);
4504 + bstart = au_dbstart(dentry);
4506 + if (inode && S_ISDIR(inode->i_mode))
4507 + btail = au_dbtaildir(dentry);
4508 + for (bindex = bstart; bindex <= btail; bindex++) {
4509 + h_dentry = au_h_dptr(dentry, bindex);
4513 + AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
4514 + h_name = &h_dentry->d_name;
4515 + if (unlikely(do_udba
4517 + && (unhashed != !!d_unhashed(h_dentry)
4518 + || name->len != h_name->len
4519 + || memcmp(name->name, h_name->name, name->len))
4521 + AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
4522 + unhashed, d_unhashed(h_dentry),
4523 + AuDLNPair(dentry), AuDLNPair(h_dentry));
4527 + err = au_do_h_d_reval(h_dentry, nd, dentry, bindex);
4528 + if (unlikely(err))
4529 + /* do not goto err, to keep the errno */
4532 + /* todo: plink too? */
4537 + h_inode = h_dentry->d_inode;
4538 + if (unlikely(!!inode != !!h_inode))
4543 + h_cached_inode = h_inode;
4545 + h_mode = (h_inode->i_mode & S_IFMT);
4546 + h_plus = (h_inode->i_nlink > 0);
4548 + if (inode && ibs <= bindex && bindex <= ibe)
4549 + h_cached_inode = au_h_iptr(inode, bindex);
4551 + if (unlikely(plus != h_plus
4553 + || h_cached_inode != h_inode))
4565 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
4568 + struct dentry *parent;
4569 + struct inode *inode;
4571 + inode = dentry->d_inode;
4572 + if (au_digen(dentry) == sigen && au_iigen(inode) == sigen)
4575 + parent = dget_parent(dentry);
4576 + di_read_lock_parent(parent, AuLock_IR);
4577 + AuDebugOn(au_digen(parent) != sigen
4578 + || au_iigen(parent->d_inode) != sigen);
4579 + au_dbg_verify_gen(parent, sigen);
4581 + /* returns a number of positive dentries */
4582 + err = au_refresh_hdentry(dentry, inode->i_mode & S_IFMT);
4584 + err = au_refresh_hinode(inode, dentry);
4586 + di_read_unlock(parent, AuLock_IR);
4591 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
4594 + struct dentry *d, *parent;
4595 + struct inode *inode;
4597 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIRS))
4598 + return simple_reval_dpath(dentry, sigen);
4600 + /* slow loop, keep it simple and stupid */
4601 + /* cf: au_cpup_dirs() */
4604 + while (au_digen(dentry) != sigen
4605 + || au_iigen(dentry->d_inode) != sigen) {
4609 + parent = dget_parent(d);
4610 + if (au_digen(parent) == sigen
4611 + && au_iigen(parent->d_inode) == sigen)
4616 + inode = d->d_inode;
4618 + di_write_lock_child(d);
4620 + /* someone might update our dentry while we were sleeping */
4621 + if (au_digen(d) != sigen || au_iigen(d->d_inode) != sigen) {
4622 + di_read_lock_parent(parent, AuLock_IR);
4623 + /* returns a number of positive dentries */
4624 + err = au_refresh_hdentry(d, inode->i_mode & S_IFMT);
4626 + err = au_refresh_hinode(inode, d);
4627 + di_read_unlock(parent, AuLock_IR);
4631 + di_write_unlock(d);
4633 + if (unlikely(err))
4641 + * if valid returns 1, otherwise 0.
4643 +static int aufs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
4646 + unsigned int sigen;
4647 + unsigned char do_udba;
4648 + struct super_block *sb;
4649 + struct inode *inode;
4652 + sb = dentry->d_sb;
4653 + inode = dentry->d_inode;
4654 + aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW);
4655 + sigen = au_sigen(sb);
4656 + if (au_digen(dentry) != sigen) {
4657 + AuDebugOn(IS_ROOT(dentry));
4659 + err = au_reval_dpath(dentry, sigen);
4660 + if (unlikely(err))
4662 + AuDebugOn(au_digen(dentry) != sigen);
4664 + if (inode && au_iigen(inode) != sigen) {
4665 + AuDebugOn(IS_ROOT(dentry));
4666 + err = au_refresh_hinode(inode, dentry);
4667 + if (unlikely(err))
4669 + AuDebugOn(au_iigen(inode) != sigen);
4671 + di_downgrade_lock(dentry, AuLock_IR);
4673 + AuDebugOn(au_digen(dentry) != sigen);
4674 + AuDebugOn(inode && au_iigen(inode) != sigen);
4676 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
4677 + if (do_udba && inode) {
4678 + aufs_bindex_t bstart = au_ibstart(inode);
4681 + && au_test_higen(inode, au_h_iptr(inode, bstart)))
4685 + err = h_d_revalidate(dentry, inode, nd, do_udba);
4686 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0))
4687 + /* both of real entry and whiteout found */
4692 + di_downgrade_lock(dentry, AuLock_IR);
4694 + au_store_oflag(nd, inode);
4695 + aufs_read_unlock(dentry, AuLock_IR);
4699 + AuDbg("%.*s invalid\n", AuDLNPair(dentry));
4703 +static void aufs_d_release(struct dentry *dentry)
4705 + struct au_dinfo *dinfo;
4706 + aufs_bindex_t bend, bindex;
4708 + dinfo = dentry->d_fsdata;
4712 + /* dentry may not be revalidated */
4713 + bindex = dinfo->di_bstart;
4714 + if (bindex >= 0) {
4715 + struct au_hdentry *p;
4717 + bend = dinfo->di_bend;
4718 + p = dinfo->di_hdentry + bindex;
4719 + while (bindex++ <= bend) {
4725 + kfree(dinfo->di_hdentry);
4726 + AuRwDestroy(&dinfo->di_rwsem);
4727 + au_cache_free_dinfo(dinfo);
4728 + au_hin_di_reinit(dentry);
4731 +struct dentry_operations aufs_dop = {
4732 + .d_revalidate = aufs_d_revalidate,
4733 + .d_release = aufs_d_release
4735 diff -urN linux-2.6.30.org/fs/aufs/dentry.h linux-2.6.30/fs/aufs/dentry.h
4736 --- linux-2.6.30.org/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
4737 +++ linux-2.6.30/fs/aufs/dentry.h 2009-07-21 08:54:19.000000000 +0200
4740 + * Copyright (C) 2005-2009 Junjiro R. Okajima
4742 + * This program, aufs is free software; you can redistribute it and/or modify
4743 + * it under the terms of the GNU General Public License as published by
4744 + * the Free Software Foundation; either version 2 of the License, or
4745 + * (at your option) any later version.
4747 + * This program is distributed in the hope that it will be useful,
4748 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4749 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4750 + * GNU General Public License for more details.
4752 + * You should have received a copy of the GNU General Public License
4753 + * along with this program; if not, write to the Free Software
4754 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4758 + * lookup and dentry operations
4761 +#ifndef __AUFS_DENTRY_H__
4762 +#define __AUFS_DENTRY_H__
4766 +#include <linux/dcache.h>
4767 +#include <linux/aufs_type.h>
4770 +/* make a single member structure for future use */
4771 +/* todo: remove this structure */
4772 +struct au_hdentry {
4773 + struct dentry *hd_dentry;
4777 + atomic_t di_generation;
4779 + struct au_rwsem di_rwsem;
4780 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
4781 + struct au_hdentry *di_hdentry;
4784 +/* ---------------------------------------------------------------------- */
4787 +extern struct dentry_operations aufs_dop;
4789 +struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
4790 + struct au_branch *br, struct nameidata *nd);
4791 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
4792 + struct au_branch *br);
4793 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
4794 + struct dentry *h_parent, struct au_branch *br);
4796 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
4797 + struct nameidata *nd);
4798 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex);
4799 +int au_refresh_hdentry(struct dentry *dentry, mode_t type);
4800 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
4803 +int au_alloc_dinfo(struct dentry *dentry);
4804 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
4806 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
4807 +void di_read_unlock(struct dentry *d, int flags);
4808 +void di_downgrade_lock(struct dentry *d, int flags);
4809 +void di_write_lock(struct dentry *d, unsigned int lsc);
4810 +void di_write_unlock(struct dentry *d);
4811 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
4812 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
4813 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
4815 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
4816 +aufs_bindex_t au_dbtail(struct dentry *dentry);
4817 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
4819 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
4820 + struct dentry *h_dentry);
4821 +void au_update_digen(struct dentry *dentry);
4822 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
4823 +void au_update_dbstart(struct dentry *dentry);
4824 +void au_update_dbend(struct dentry *dentry);
4825 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
4827 +/* ---------------------------------------------------------------------- */
4829 +static inline struct au_dinfo *au_di(struct dentry *dentry)
4831 + return dentry->d_fsdata;
4834 +/* ---------------------------------------------------------------------- */
4836 +/* lock subclass for dinfo */
4838 + AuLsc_DI_CHILD, /* child first */
4839 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hinotify */
4840 + AuLsc_DI_CHILD3, /* copyup dirs */
4847 + * di_read_lock_child, di_write_lock_child,
4848 + * di_read_lock_child2, di_write_lock_child2,
4849 + * di_read_lock_child3, di_write_lock_child3,
4850 + * di_read_lock_parent, di_write_lock_parent,
4851 + * di_read_lock_parent2, di_write_lock_parent2,
4852 + * di_read_lock_parent3, di_write_lock_parent3,
4854 +#define AuReadLockFunc(name, lsc) \
4855 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
4856 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
4858 +#define AuWriteLockFunc(name, lsc) \
4859 +static inline void di_write_lock_##name(struct dentry *d) \
4860 +{ di_write_lock(d, AuLsc_DI_##lsc); }
4862 +#define AuRWLockFuncs(name, lsc) \
4863 + AuReadLockFunc(name, lsc) \
4864 + AuWriteLockFunc(name, lsc)
4866 +AuRWLockFuncs(child, CHILD);
4867 +AuRWLockFuncs(child2, CHILD2);
4868 +AuRWLockFuncs(child3, CHILD3);
4869 +AuRWLockFuncs(parent, PARENT);
4870 +AuRWLockFuncs(parent2, PARENT2);
4871 +AuRWLockFuncs(parent3, PARENT3);
4873 +#undef AuReadLockFunc
4874 +#undef AuWriteLockFunc
4875 +#undef AuRWLockFuncs
4877 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
4878 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
4879 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
4881 +/* ---------------------------------------------------------------------- */
4883 +/* todo: memory barrier? */
4884 +static inline unsigned int au_digen(struct dentry *d)
4886 + return atomic_read(&au_di(d)->di_generation);
4889 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
4891 + hdentry->hd_dentry = NULL;
4894 +static inline void au_hdput(struct au_hdentry *hd)
4896 + dput(hd->hd_dentry);
4899 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
4901 + return au_di(dentry)->di_bstart;
4904 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
4906 + return au_di(dentry)->di_bend;
4909 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
4911 + return au_di(dentry)->di_bwh;
4914 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
4916 + return au_di(dentry)->di_bdiropq;
4919 +/* todo: hard/soft set? */
4920 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
4922 + au_di(dentry)->di_bstart = bindex;
4925 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
4927 + au_di(dentry)->di_bend = bindex;
4930 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
4932 + /* dbwh can be outside of bstart - bend range */
4933 + au_di(dentry)->di_bwh = bindex;
4936 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
4938 + au_di(dentry)->di_bdiropq = bindex;
4941 +/* ---------------------------------------------------------------------- */
4943 +#ifdef CONFIG_AUFS_HINOTIFY
4944 +static inline void au_digen_dec(struct dentry *d)
4946 + atomic_dec_return(&au_di(d)->di_generation);
4949 +static inline void au_hin_di_reinit(struct dentry *dentry)
4951 + dentry->d_fsdata = NULL;
4954 +static inline void au_hin_di_reinit(struct dentry *dentry __maybe_unused)
4958 +#endif /* CONFIG_AUFS_HINOTIFY */
4960 +#endif /* __KERNEL__ */
4961 +#endif /* __AUFS_DENTRY_H__ */
4962 diff -urN linux-2.6.30.org/fs/aufs/dinfo.c linux-2.6.30/fs/aufs/dinfo.c
4963 --- linux-2.6.30.org/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
4964 +++ linux-2.6.30/fs/aufs/dinfo.c 2009-07-21 08:54:19.000000000 +0200
4967 + * Copyright (C) 2005-2009 Junjiro R. Okajima
4969 + * This program, aufs is free software; you can redistribute it and/or modify
4970 + * it under the terms of the GNU General Public License as published by
4971 + * the Free Software Foundation; either version 2 of the License, or
4972 + * (at your option) any later version.
4974 + * This program is distributed in the hope that it will be useful,
4975 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4976 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4977 + * GNU General Public License for more details.
4979 + * You should have received a copy of the GNU General Public License
4980 + * along with this program; if not, write to the Free Software
4981 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4985 + * dentry private data
4990 +int au_alloc_dinfo(struct dentry *dentry)
4992 + struct au_dinfo *dinfo;
4993 + struct super_block *sb;
4996 + dinfo = au_cache_alloc_dinfo();
4997 + if (unlikely(!dinfo))
5000 + sb = dentry->d_sb;
5001 + nbr = au_sbend(sb) + 1;
5004 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
5005 + if (unlikely(!dinfo->di_hdentry))
5008 + atomic_set(&dinfo->di_generation, au_sigen(sb));
5009 + /* smp_mb(); */ /* atomic_set */
5010 + au_rw_init_wlock_nested(&dinfo->di_rwsem, AuLsc_DI_CHILD);
5011 + dinfo->di_bstart = -1;
5012 + dinfo->di_bend = -1;
5013 + dinfo->di_bwh = -1;
5014 + dinfo->di_bdiropq = -1;
5016 + dentry->d_fsdata = dinfo;
5017 + dentry->d_op = &aufs_dop;
5018 + return 0; /* success */
5021 + au_cache_free_dinfo(dinfo);
5026 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
5029 + struct au_hdentry *hdp;
5032 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
5034 + sz = sizeof(*hdp);
5035 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
5037 + dinfo->di_hdentry = hdp;
5044 +/* ---------------------------------------------------------------------- */
5046 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
5049 + case AuLsc_DI_CHILD:
5050 + ii_write_lock_child(inode);
5052 + case AuLsc_DI_CHILD2:
5053 + ii_write_lock_child2(inode);
5055 + case AuLsc_DI_CHILD3:
5056 + ii_write_lock_child3(inode);
5058 + case AuLsc_DI_PARENT:
5059 + ii_write_lock_parent(inode);
5061 + case AuLsc_DI_PARENT2:
5062 + ii_write_lock_parent2(inode);
5064 + case AuLsc_DI_PARENT3:
5065 + ii_write_lock_parent3(inode);
5072 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
5075 + case AuLsc_DI_CHILD:
5076 + ii_read_lock_child(inode);
5078 + case AuLsc_DI_CHILD2:
5079 + ii_read_lock_child2(inode);
5081 + case AuLsc_DI_CHILD3:
5082 + ii_read_lock_child3(inode);
5084 + case AuLsc_DI_PARENT:
5085 + ii_read_lock_parent(inode);
5087 + case AuLsc_DI_PARENT2:
5088 + ii_read_lock_parent2(inode);
5090 + case AuLsc_DI_PARENT3:
5091 + ii_read_lock_parent3(inode);
5098 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
5100 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
5102 + if (au_ftest_lock(flags, IW))
5103 + do_ii_write_lock(d->d_inode, lsc);
5104 + else if (au_ftest_lock(flags, IR))
5105 + do_ii_read_lock(d->d_inode, lsc);
5109 +void di_read_unlock(struct dentry *d, int flags)
5112 + if (au_ftest_lock(flags, IW))
5113 + ii_write_unlock(d->d_inode);
5114 + else if (au_ftest_lock(flags, IR))
5115 + ii_read_unlock(d->d_inode);
5117 + au_rw_read_unlock(&au_di(d)->di_rwsem);
5120 +void di_downgrade_lock(struct dentry *d, int flags)
5122 + if (d->d_inode && au_ftest_lock(flags, IR))
5123 + ii_downgrade_lock(d->d_inode);
5124 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
5127 +void di_write_lock(struct dentry *d, unsigned int lsc)
5129 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
5131 + do_ii_write_lock(d->d_inode, lsc);
5134 +void di_write_unlock(struct dentry *d)
5137 + ii_write_unlock(d->d_inode);
5138 + au_rw_write_unlock(&au_di(d)->di_rwsem);
5141 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
5143 + AuDebugOn(d1 == d2
5144 + || d1->d_inode == d2->d_inode
5145 + || d1->d_sb != d2->d_sb);
5147 + if (isdir && au_test_subdir(d1, d2)) {
5148 + di_write_lock_child(d1);
5149 + di_write_lock_child2(d2);
5151 + /* there should be no races */
5152 + di_write_lock_child(d2);
5153 + di_write_lock_child2(d1);
5157 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
5159 + AuDebugOn(d1 == d2
5160 + || d1->d_inode == d2->d_inode
5161 + || d1->d_sb != d2->d_sb);
5163 + if (isdir && au_test_subdir(d1, d2)) {
5164 + di_write_lock_parent(d1);
5165 + di_write_lock_parent2(d2);
5167 + /* there should be no races */
5168 + di_write_lock_parent(d2);
5169 + di_write_lock_parent2(d1);
5173 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
5175 + di_write_unlock(d1);
5176 + if (d1->d_inode == d2->d_inode)
5177 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
5179 + di_write_unlock(d2);
5182 +/* ---------------------------------------------------------------------- */
5184 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
5188 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
5190 + AuDebugOn(bindex < 0);
5191 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
5192 + AuDebugOn(d && (atomic_read(&d->d_count) <= 0));
5196 +aufs_bindex_t au_dbtail(struct dentry *dentry)
5198 + aufs_bindex_t bend, bwh;
5200 + bend = au_dbend(dentry);
5202 + bwh = au_dbwh(dentry);
5205 + if (0 < bwh && bwh < bend)
5211 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
5213 + aufs_bindex_t bend, bopq;
5215 + bend = au_dbtail(dentry);
5217 + bopq = au_dbdiropq(dentry);
5218 + if (0 <= bopq && bopq < bend)
5224 +/* ---------------------------------------------------------------------- */
5226 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
5227 + struct dentry *h_dentry)
5229 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
5231 + if (hd->hd_dentry)
5233 + hd->hd_dentry = h_dentry;
5236 +void au_update_digen(struct dentry *dentry)
5238 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
5239 + /* smp_mb(); */ /* atomic_set */
5242 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
5244 + struct au_dinfo *dinfo;
5245 + struct dentry *h_d;
5247 + dinfo = au_di(dentry);
5248 + if (!dinfo || dinfo->di_bstart < 0)
5251 + if (do_put_zero) {
5252 + aufs_bindex_t bindex, bend;
5254 + bend = dinfo->di_bend;
5255 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
5256 + h_d = dinfo->di_hdentry[0 + bindex].hd_dentry;
5257 + if (h_d && !h_d->d_inode)
5258 + au_set_h_dptr(dentry, bindex, NULL);
5262 + dinfo->di_bstart = -1;
5263 + while (++dinfo->di_bstart <= dinfo->di_bend)
5264 + if (dinfo->di_hdentry[0 + dinfo->di_bstart].hd_dentry)
5266 + if (dinfo->di_bstart > dinfo->di_bend) {
5267 + dinfo->di_bstart = -1;
5268 + dinfo->di_bend = -1;
5273 + while (0 <= --dinfo->di_bend)
5274 + if (dinfo->di_hdentry[0 + dinfo->di_bend].hd_dentry)
5276 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
5279 +void au_update_dbstart(struct dentry *dentry)
5281 + aufs_bindex_t bindex, bend;
5282 + struct dentry *h_dentry;
5284 + bend = au_dbend(dentry);
5285 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
5286 + h_dentry = au_h_dptr(dentry, bindex);
5289 + if (h_dentry->d_inode) {
5290 + au_set_dbstart(dentry, bindex);
5293 + au_set_h_dptr(dentry, bindex, NULL);
5297 +void au_update_dbend(struct dentry *dentry)
5299 + aufs_bindex_t bindex, bstart;
5300 + struct dentry *h_dentry;
5302 + bstart = au_dbstart(dentry);
5303 + for (bindex = au_dbend(dentry); bindex <= bstart; bindex--) {
5304 + h_dentry = au_h_dptr(dentry, bindex);
5307 + if (h_dentry->d_inode) {
5308 + au_set_dbend(dentry, bindex);
5311 + au_set_h_dptr(dentry, bindex, NULL);
5315 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
5317 + aufs_bindex_t bindex, bend;
5319 + bend = au_dbend(dentry);
5320 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
5321 + if (au_h_dptr(dentry, bindex) == h_dentry)
5325 diff -urN linux-2.6.30.org/fs/aufs/dir.c linux-2.6.30/fs/aufs/dir.c
5326 --- linux-2.6.30.org/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
5327 +++ linux-2.6.30/fs/aufs/dir.c 2009-07-21 08:54:19.000000000 +0200
5330 + * Copyright (C) 2005-2009 Junjiro R. Okajima
5332 + * This program, aufs is free software; you can redistribute it and/or modify
5333 + * it under the terms of the GNU General Public License as published by
5334 + * the Free Software Foundation; either version 2 of the License, or
5335 + * (at your option) any later version.
5337 + * This program is distributed in the hope that it will be useful,
5338 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5339 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5340 + * GNU General Public License for more details.
5342 + * You should have received a copy of the GNU General Public License
5343 + * along with this program; if not, write to the Free Software
5344 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5348 + * directory operations
5351 +#include <linux/file.h>
5352 +#include <linux/fs_stack.h>
5355 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
5357 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
5359 + dir->i_nlink += h_dir->i_nlink - 2;
5360 + if (h_dir->i_nlink < 2)
5361 + dir->i_nlink += 2;
5364 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
5366 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
5368 + dir->i_nlink -= h_dir->i_nlink - 2;
5369 + if (h_dir->i_nlink < 2)
5370 + dir->i_nlink -= 2;
5373 +/* ---------------------------------------------------------------------- */
5375 +static int reopen_dir(struct file *file)
5378 + unsigned int flags;
5379 + aufs_bindex_t bindex, btail, bstart;
5380 + struct dentry *dentry, *h_dentry;
5381 + struct file *h_file;
5383 + /* open all lower dirs */
5384 + dentry = file->f_dentry;
5385 + bstart = au_dbstart(dentry);
5386 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
5387 + au_set_h_fptr(file, bindex, NULL);
5388 + au_set_fbstart(file, bstart);
5390 + btail = au_dbtaildir(dentry);
5391 + for (bindex = au_fbend(file); btail < bindex; bindex--)
5392 + au_set_h_fptr(file, bindex, NULL);
5393 + au_set_fbend(file, btail);
5395 + flags = file->f_flags;
5396 + for (bindex = bstart; bindex <= btail; bindex++) {
5397 + h_dentry = au_h_dptr(dentry, bindex);
5400 + h_file = au_h_fptr(file, bindex);
5404 + h_file = au_h_open(dentry, bindex, flags, file);
5405 + err = PTR_ERR(h_file);
5406 + if (IS_ERR(h_file))
5407 + goto out; /* close all? */
5408 + au_set_h_fptr(file, bindex, h_file);
5410 + au_update_figen(file);
5411 + /* todo: necessary? */
5412 + /* file->f_ra = h_file->f_ra; */
5419 +static int do_open_dir(struct file *file, int flags)
5422 + aufs_bindex_t bindex, btail;
5423 + struct dentry *dentry, *h_dentry;
5424 + struct file *h_file;
5427 + dentry = file->f_dentry;
5428 + au_set_fvdir_cache(file, NULL);
5429 + au_fi(file)->fi_maintain_plink = 0;
5430 + file->f_version = dentry->d_inode->i_version;
5431 + bindex = au_dbstart(dentry);
5432 + au_set_fbstart(file, bindex);
5433 + btail = au_dbtaildir(dentry);
5434 + au_set_fbend(file, btail);
5435 + for (; !err && bindex <= btail; bindex++) {
5436 + h_dentry = au_h_dptr(dentry, bindex);
5440 + h_file = au_h_open(dentry, bindex, flags, file);
5441 + if (IS_ERR(h_file)) {
5442 + err = PTR_ERR(h_file);
5445 + au_set_h_fptr(file, bindex, h_file);
5447 + au_update_figen(file);
5448 + /* todo: necessary? */
5449 + /* file->f_ra = h_file->f_ra; */
5451 + return 0; /* success */
5454 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
5455 + au_set_h_fptr(file, bindex, NULL);
5456 + au_set_fbstart(file, -1);
5457 + au_set_fbend(file, -1);
5461 +static int aufs_open_dir(struct inode *inode __maybe_unused,
5462 + struct file *file)
5464 + return au_do_open(file, do_open_dir);
5467 +static int aufs_release_dir(struct inode *inode __maybe_unused,
5468 + struct file *file)
5470 + struct au_vdir *vdir_cache;
5471 + struct super_block *sb;
5472 + struct au_sbinfo *sbinfo;
5474 + sb = file->f_dentry->d_sb;
5475 + si_noflush_read_lock(sb);
5476 + fi_write_lock(file);
5477 + vdir_cache = au_fvdir_cache(file);
5479 + au_vdir_free(vdir_cache);
5480 + if (au_fi(file)->fi_maintain_plink) {
5481 + sbinfo = au_sbi(sb);
5482 + /* clear the flag without write-lock */
5483 + sbinfo->au_si_status &= ~AuSi_MAINTAIN_PLINK;
5484 + wake_up_all(&sbinfo->si_plink_wq);
5486 + fi_write_unlock(file);
5487 + au_finfo_fin(file);
5488 + si_read_unlock(sb);
5492 +/* ---------------------------------------------------------------------- */
5494 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
5497 + aufs_bindex_t bend, bindex;
5498 + struct inode *inode;
5499 + struct super_block *sb;
5502 + sb = dentry->d_sb;
5503 + inode = dentry->d_inode;
5505 + bend = au_dbend(dentry);
5506 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
5507 + struct path h_path;
5508 + struct inode *h_inode;
5510 + if (au_test_ro(sb, bindex, inode))
5512 + h_path.dentry = au_h_dptr(dentry, bindex);
5513 + if (!h_path.dentry)
5515 + h_inode = h_path.dentry->d_inode;
5519 + /* no mnt_want_write() */
5520 + /* cf. fs/nsfd/vfs.c and fs/nfsd/nfs4recover.c */
5521 + /* todo: inotiry fired? */
5522 + h_path.mnt = au_sbr_mnt(sb, bindex);
5523 + mutex_lock(&h_inode->i_mutex);
5524 + err = filemap_fdatawrite(h_inode->i_mapping);
5525 + AuDebugOn(!h_inode->i_fop);
5526 + if (!err && h_inode->i_fop->fsync)
5527 + err = h_inode->i_fop->fsync(NULL, h_path.dentry,
5530 + err = filemap_fdatawrite(h_inode->i_mapping);
5532 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
5533 + mutex_unlock(&h_inode->i_mutex);
5539 +static int au_do_fsync_dir(struct file *file, int datasync)
5542 + aufs_bindex_t bend, bindex;
5543 + struct file *h_file;
5544 + struct super_block *sb;
5545 + struct inode *inode;
5546 + struct mutex *h_mtx;
5548 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
5549 + if (unlikely(err))
5552 + sb = file->f_dentry->d_sb;
5553 + inode = file->f_dentry->d_inode;
5554 + bend = au_fbend(file);
5555 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
5556 + h_file = au_h_fptr(file, bindex);
5557 + if (!h_file || au_test_ro(sb, bindex, inode))
5560 + err = vfs_fsync(h_file, h_file->f_dentry, datasync);
5562 + h_mtx = &h_file->f_dentry->d_inode->i_mutex;
5563 + mutex_lock(h_mtx);
5564 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
5566 + mutex_unlock(h_mtx);
5575 + * @file may be NULL
5577 +static int aufs_fsync_dir(struct file *file, struct dentry *dentry,
5581 + struct super_block *sb;
5583 + IMustLock(dentry->d_inode);
5586 + sb = dentry->d_sb;
5587 + si_noflush_read_lock(sb);
5589 + err = au_do_fsync_dir(file, datasync);
5591 + di_write_lock_child(dentry);
5592 + err = au_do_fsync_dir_no_file(dentry, datasync);
5594 + au_cpup_attr_timesizes(dentry->d_inode);
5595 + di_write_unlock(dentry);
5597 + fi_write_unlock(file);
5599 + si_read_unlock(sb);
5603 +/* ---------------------------------------------------------------------- */
5605 +static int aufs_readdir(struct file *file, void *dirent, filldir_t filldir)
5608 + struct dentry *dentry;
5609 + struct inode *inode;
5610 + struct super_block *sb;
5612 + dentry = file->f_dentry;
5613 + inode = dentry->d_inode;
5616 + sb = dentry->d_sb;
5617 + si_read_lock(sb, AuLock_FLUSH);
5618 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
5619 + if (unlikely(err))
5621 + err = au_vdir_init(file);
5622 + di_downgrade_lock(dentry, AuLock_IR);
5623 + if (unlikely(err))
5626 + if (!au_test_nfsd(current)) {
5627 + err = au_vdir_fill_de(file, dirent, filldir);
5628 + fsstack_copy_attr_atime(inode,
5629 + au_h_iptr(inode, au_ibstart(inode)));
5632 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
5633 + * encode_fh() and others.
5635 + struct inode *h_inode = au_h_iptr(inode, au_ibstart(inode));
5637 + di_read_unlock(dentry, AuLock_IR);
5638 + si_read_unlock(sb);
5640 + err = au_vdir_fill_de(file, dirent, filldir);
5642 + fsstack_copy_attr_atime(inode, h_inode);
5643 + fi_write_unlock(file);
5650 + di_read_unlock(dentry, AuLock_IR);
5651 + fi_write_unlock(file);
5653 + si_read_unlock(sb);
5657 +/* ---------------------------------------------------------------------- */
5659 +#define AuTestEmpty_WHONLY 1
5660 +#define AuTestEmpty_CALLED (1 << 1)
5661 +#define AuTestEmpty_SHWH (1 << 2)
5662 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
5663 +#define au_fset_testempty(flags, name) { (flags) |= AuTestEmpty_##name; }
5664 +#define au_fclr_testempty(flags, name) { (flags) &= ~AuTestEmpty_##name; }
5666 +#ifndef CONFIG_AUFS_SHWH
5667 +#undef AuTestEmpty_SHWH
5668 +#define AuTestEmpty_SHWH 0
5671 +struct test_empty_arg {
5672 + struct au_nhash whlist;
5673 + unsigned int flags;
5675 + aufs_bindex_t bindex;
5678 +static int test_empty_cb(void *__arg, const char *__name, int namelen,
5679 + loff_t offset __maybe_unused, u64 ino,
5680 + unsigned int d_type)
5682 + struct test_empty_arg *arg = __arg;
5683 + char *name = (void *)__name;
5686 + au_fset_testempty(arg->flags, CALLED);
5688 + if (name[0] == '.'
5689 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
5690 + goto out; /* success */
5692 + if (namelen <= AUFS_WH_PFX_LEN
5693 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
5694 + if (au_ftest_testempty(arg->flags, WHONLY)
5695 + && !au_nhash_test_known_wh(&arg->whlist, name, namelen))
5696 + arg->err = -ENOTEMPTY;
5700 + name += AUFS_WH_PFX_LEN;
5701 + namelen -= AUFS_WH_PFX_LEN;
5702 + if (!au_nhash_test_known_wh(&arg->whlist, name, namelen))
5703 + arg->err = au_nhash_append_wh
5704 + (&arg->whlist, name, namelen, ino, d_type, arg->bindex,
5705 + au_ftest_testempty(arg->flags, SHWH));
5709 + AuTraceErr(arg->err);
5713 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
5716 + struct file *h_file;
5718 + h_file = au_h_open(dentry, arg->bindex,
5719 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
5721 + err = PTR_ERR(h_file);
5722 + if (IS_ERR(h_file))
5726 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
5727 + && !h_file->f_dentry->d_inode->i_nlink)
5732 + au_fclr_testempty(arg->flags, CALLED);
5734 + err = vfsub_readdir(h_file, test_empty_cb, arg);
5737 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
5741 + au_sbr_put(dentry->d_sb, arg->bindex);
5746 +struct do_test_empty_args {
5748 + struct dentry *dentry;
5749 + struct test_empty_arg *arg;
5752 +static void call_do_test_empty(void *args)
5754 + struct do_test_empty_args *a = args;
5755 + *a->errp = do_test_empty(a->dentry, a->arg);
5758 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
5761 + struct dentry *h_dentry;
5762 + struct inode *h_inode;
5764 + h_dentry = au_h_dptr(dentry, arg->bindex);
5765 + h_inode = h_dentry->d_inode;
5766 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
5767 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
5768 + mutex_unlock(&h_inode->i_mutex);
5770 + err = do_test_empty(dentry, arg);
5772 + struct do_test_empty_args args = {
5777 + unsigned int flags = arg->flags;
5779 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
5780 + if (unlikely(wkq_err))
5782 + arg->flags = flags;
5788 +int au_test_empty_lower(struct dentry *dentry)
5791 + aufs_bindex_t bindex, bstart, btail;
5792 + struct test_empty_arg arg;
5794 + SiMustAnyLock(dentry->d_sb);
5796 + err = au_nhash_alloc(&arg.whlist, au_sbi(dentry->d_sb)->si_rdhash,
5798 + if (unlikely(err))
5801 + bstart = au_dbstart(dentry);
5803 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
5804 + au_fset_testempty(arg.flags, SHWH);
5805 + arg.bindex = bstart;
5806 + err = do_test_empty(dentry, &arg);
5807 + if (unlikely(err))
5810 + au_fset_testempty(arg.flags, WHONLY);
5811 + btail = au_dbtaildir(dentry);
5812 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
5813 + struct dentry *h_dentry;
5815 + h_dentry = au_h_dptr(dentry, bindex);
5816 + if (h_dentry && h_dentry->d_inode) {
5817 + arg.bindex = bindex;
5818 + err = do_test_empty(dentry, &arg);
5823 + au_nhash_wh_free(&arg.whlist);
5828 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
5831 + struct test_empty_arg arg;
5832 + aufs_bindex_t bindex, btail;
5835 + arg.whlist = *whlist;
5836 + arg.flags = AuTestEmpty_WHONLY;
5837 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
5838 + au_fset_testempty(arg.flags, SHWH);
5839 + btail = au_dbtaildir(dentry);
5840 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
5841 + struct dentry *h_dentry;
5843 + h_dentry = au_h_dptr(dentry, bindex);
5844 + if (h_dentry && h_dentry->d_inode) {
5845 + arg.bindex = bindex;
5846 + err = sio_test_empty(dentry, &arg);
5853 +/* ---------------------------------------------------------------------- */
5855 +const struct file_operations aufs_dir_fop = {
5856 + .read = generic_read_dir,
5857 + .readdir = aufs_readdir,
5858 + .unlocked_ioctl = aufs_ioctl_dir,
5859 + .open = aufs_open_dir,
5860 + .release = aufs_release_dir,
5861 + .flush = aufs_flush,
5862 + .fsync = aufs_fsync_dir
5864 diff -urN linux-2.6.30.org/fs/aufs/dir.h linux-2.6.30/fs/aufs/dir.h
5865 --- linux-2.6.30.org/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
5866 +++ linux-2.6.30/fs/aufs/dir.h 2009-07-21 08:54:19.000000000 +0200
5869 + * Copyright (C) 2005-2009 Junjiro R. Okajima
5871 + * This program, aufs is free software; you can redistribute it and/or modify
5872 + * it under the terms of the GNU General Public License as published by
5873 + * the Free Software Foundation; either version 2 of the License, or
5874 + * (at your option) any later version.
5876 + * This program is distributed in the hope that it will be useful,
5877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5879 + * GNU General Public License for more details.
5881 + * You should have received a copy of the GNU General Public License
5882 + * along with this program; if not, write to the Free Software
5883 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5887 + * directory operations
5890 +#ifndef __AUFS_DIR_H__
5891 +#define __AUFS_DIR_H__
5895 +#include <linux/fs.h>
5896 +#include <linux/aufs_type.h>
5898 +/* ---------------------------------------------------------------------- */
5900 +/* need to be faster and smaller */
5903 + unsigned int nh_num;
5904 + struct hlist_head *nh_head;
5907 +struct au_vdir_destr {
5908 + unsigned char len;
5909 + unsigned char name[0];
5912 +struct au_vdir_dehstr {
5913 + struct hlist_node hash;
5914 + struct au_vdir_destr *str;
5917 +struct au_vdir_de {
5919 + unsigned char de_type;
5920 + /* caution: packed */
5921 + struct au_vdir_destr de_str;
5924 +struct au_vdir_wh {
5925 + struct hlist_node wh_hash;
5926 +#ifdef CONFIG_AUFS_SHWH
5928 + aufs_bindex_t wh_bindex;
5929 + unsigned char wh_type;
5931 + aufs_bindex_t wh_bindex;
5933 + /* caution: packed */
5934 + struct au_vdir_destr wh_str;
5937 +union au_vdir_deblk_p {
5938 + unsigned char *deblk;
5939 + struct au_vdir_de *de;
5943 + unsigned char **vd_deblk;
5944 + unsigned long vd_nblk;
5947 + union au_vdir_deblk_p p;
5950 + unsigned long vd_version;
5951 + unsigned int vd_deblk_sz;
5952 + unsigned long vd_jiffy;
5955 +/* ---------------------------------------------------------------------- */
5958 +extern const struct file_operations aufs_dir_fop;
5959 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
5960 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
5961 +int au_test_empty_lower(struct dentry *dentry);
5962 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
5965 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
5966 +void au_nhash_wh_free(struct au_nhash *whlist);
5967 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
5969 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
5970 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
5971 + unsigned int d_type, aufs_bindex_t bindex,
5972 + unsigned char shwh);
5973 +void au_vdir_free(struct au_vdir *vdir);
5974 +int au_vdir_init(struct file *file);
5975 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir);
5978 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
5980 +#endif /* __KERNEL__ */
5981 +#endif /* __AUFS_DIR_H__ */
5982 diff -urN linux-2.6.30.org/fs/aufs/export.c linux-2.6.30/fs/aufs/export.c
5983 --- linux-2.6.30.org/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
5984 +++ linux-2.6.30/fs/aufs/export.c 2009-07-21 08:54:19.000000000 +0200
5987 + * Copyright (C) 2005-2009 Junjiro R. Okajima
5989 + * This program, aufs is free software; you can redistribute it and/or modify
5990 + * it under the terms of the GNU General Public License as published by
5991 + * the Free Software Foundation; either version 2 of the License, or
5992 + * (at your option) any later version.
5994 + * This program is distributed in the hope that it will be useful,
5995 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5996 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5997 + * GNU General Public License for more details.
5999 + * You should have received a copy of the GNU General Public License
6000 + * along with this program; if not, write to the Free Software
6001 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6008 +#include <linux/exportfs.h>
6009 +#include <linux/file.h>
6010 +#include <linux/mnt_namespace.h>
6011 +#include <linux/namei.h>
6012 +#include <linux/random.h>
6016 +#ifdef CONFIG_AUFS_INO_T_64
6024 +static ino_t decode_ino(__u32 *a)
6028 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
6030 +#ifdef CONFIG_AUFS_INO_T_64
6036 +static void encode_ino(__u32 *a, ino_t ino)
6042 +#ifdef CONFIG_AUFS_INO_T_64
6047 +/* NFS file handle */
6051 +#ifdef CONFIG_AUFS_INO_T_64
6052 + /* support 64bit inode number */
6066 + Fh_dir_ino = Fh_dir_ino1
6069 +static int au_test_anon(struct dentry *dentry)
6071 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
6074 +/* ---------------------------------------------------------------------- */
6075 +/* inode generation external table */
6077 +int au_xigen_inc(struct inode *inode)
6083 + struct super_block *sb;
6084 + struct au_sbinfo *sbinfo;
6088 + sbinfo = au_sbi(sb);
6090 + * temporary workaround for escaping from SiMustAnyLock() in
6091 + * au_mntflags(), since this function is called from au_iinfo_fin().
6093 + if (unlikely(!au_opt_test(sbinfo->si_mntflags, XINO)))
6096 + pos = inode->i_ino;
6097 + pos *= sizeof(igen);
6098 + igen = inode->i_generation + 1;
6099 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
6100 + sizeof(igen), &pos);
6101 + if (sz == sizeof(igen))
6102 + goto out; /* success */
6105 + if (unlikely(sz >= 0)) {
6107 + AuIOErr("xigen error (%zd)\n", sz);
6114 +int au_xigen_new(struct inode *inode)
6119 + struct super_block *sb;
6120 + struct au_sbinfo *sbinfo;
6121 + struct file *file;
6124 + /* todo: dirty, at mount time */
6125 + if (inode->i_ino == AUFS_ROOT_INO)
6128 + SiMustAnyLock(sb);
6129 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
6133 + pos = inode->i_ino;
6134 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
6135 + AuIOErr1("too large i%lld\n", pos);
6138 + pos *= sizeof(inode->i_generation);
6141 + sbinfo = au_sbi(sb);
6142 + file = sbinfo->si_xigen;
6145 + if (i_size_read(file->f_dentry->d_inode)
6146 + < pos + sizeof(inode->i_generation)) {
6147 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
6148 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
6149 + sizeof(inode->i_generation), &pos);
6151 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
6152 + sizeof(inode->i_generation), &pos);
6153 + if (sz == sizeof(inode->i_generation))
6154 + goto out; /* success */
6157 + if (unlikely(sz >= 0)) {
6159 + AuIOErr("xigen error (%zd)\n", sz);
6166 +int au_xigen_set(struct super_block *sb, struct file *base)
6169 + struct au_sbinfo *sbinfo;
6170 + struct file *file;
6172 + SiMustWriteLock(sb);
6174 + sbinfo = au_sbi(sb);
6175 + file = au_xino_create2(base, sbinfo->si_xigen);
6176 + err = PTR_ERR(file);
6180 + if (sbinfo->si_xigen)
6181 + fput(sbinfo->si_xigen);
6182 + sbinfo->si_xigen = file;
6188 +void au_xigen_clr(struct super_block *sb)
6190 + struct au_sbinfo *sbinfo;
6192 + SiMustWriteLock(sb);
6194 + sbinfo = au_sbi(sb);
6195 + if (sbinfo->si_xigen) {
6196 + fput(sbinfo->si_xigen);
6197 + sbinfo->si_xigen = NULL;
6201 +/* ---------------------------------------------------------------------- */
6203 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
6206 + struct dentry *dentry, *d;
6207 + struct inode *inode;
6208 + unsigned int sigen;
6211 + inode = ilookup(sb, ino);
6215 + dentry = ERR_PTR(-ESTALE);
6216 + sigen = au_sigen(sb);
6217 + if (unlikely(is_bad_inode(inode)
6218 + || IS_DEADDIR(inode)
6219 + || sigen != au_iigen(inode)))
6223 + if (!dir_ino || S_ISDIR(inode->i_mode))
6224 + dentry = d_find_alias(inode);
6226 + spin_lock(&dcache_lock);
6227 + list_for_each_entry(d, &inode->i_dentry, d_alias)
6228 + if (!au_test_anon(d)
6229 + && d->d_parent->d_inode->i_ino == dir_ino) {
6230 + dentry = dget_locked(d);
6233 + spin_unlock(&dcache_lock);
6235 + if (unlikely(dentry && sigen != au_digen(dentry))) {
6237 + dentry = ERR_PTR(-ESTALE);
6246 +/* ---------------------------------------------------------------------- */
6249 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
6250 +static struct vfsmount *au_mnt_get(struct super_block *sb)
6252 + struct mnt_namespace *ns;
6253 + struct vfsmount *pos, *mnt;
6255 + spin_lock(&vfsmount_lock);
6256 + /* no get/put ?? */
6257 + AuDebugOn(!current->nsproxy);
6258 + ns = current->nsproxy->mnt_ns;
6261 + /* the order (reverse) will not be a problem */
6262 + list_for_each_entry(pos, &ns->list, mnt_list)
6263 + if (pos->mnt_sb == sb) {
6264 + mnt = mntget(pos);
6267 + spin_unlock(&vfsmount_lock);
6273 +struct au_nfsd_si_lock {
6274 + const unsigned int sigen;
6275 + const aufs_bindex_t br_id;
6276 + unsigned char force_lock;
6279 +static aufs_bindex_t si_nfsd_read_lock(struct super_block *sb,
6280 + struct au_nfsd_si_lock *nsi_lock)
6282 + aufs_bindex_t bindex;
6284 + si_read_lock(sb, AuLock_FLUSH);
6286 + /* branch id may be wrapped around */
6287 + bindex = au_br_index(sb, nsi_lock->br_id);
6288 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
6289 + goto out; /* success */
6291 + if (!nsi_lock->force_lock)
6292 + si_read_unlock(sb);
6299 +struct find_name_by_ino {
6300 + int called, found;
6307 +find_name_by_ino(void *arg, const char *name, int namelen, loff_t offset,
6308 + u64 ino, unsigned int d_type)
6310 + struct find_name_by_ino *a = arg;
6313 + if (a->ino != ino)
6316 + memcpy(a->name, name, namelen);
6317 + a->namelen = namelen;
6322 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
6323 + struct au_nfsd_si_lock *nsi_lock)
6325 + struct dentry *dentry, *parent;
6326 + struct file *file;
6327 + struct inode *dir;
6328 + struct find_name_by_ino arg;
6331 + parent = path->dentry;
6333 + si_read_unlock(parent->d_sb);
6335 + file = dentry_open(parent, path->mnt, au_dir_roflags, current_cred());
6336 + dentry = (void *)file;
6340 + dentry = ERR_PTR(-ENOMEM);
6341 + arg.name = __getname();
6342 + if (unlikely(!arg.name))
6349 + err = vfsub_readdir(file, find_name_by_ino, &arg);
6350 + } while (!err && !arg.found && arg.called);
6351 + dentry = ERR_PTR(err);
6352 + if (unlikely(err))
6354 + dentry = ERR_PTR(-ENOENT);
6358 + /* do not call au_lkup_one() */
6359 + dir = parent->d_inode;
6360 + mutex_lock(&dir->i_mutex);
6361 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
6362 + mutex_unlock(&dir->i_mutex);
6363 + AuTraceErrPtr(dentry);
6364 + if (IS_ERR(dentry))
6366 + AuDebugOn(au_test_anon(dentry));
6367 + if (unlikely(!dentry->d_inode)) {
6369 + dentry = ERR_PTR(-ENOENT);
6373 + __putname(arg.name);
6377 + if (unlikely(nsi_lock
6378 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
6379 + if (!IS_ERR(dentry)) {
6381 + dentry = ERR_PTR(-ESTALE);
6383 + AuTraceErrPtr(dentry);
6387 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
6389 + struct au_nfsd_si_lock *nsi_lock)
6391 + struct dentry *dentry;
6394 + if (dir_ino != AUFS_ROOT_INO) {
6395 + path.dentry = decode_by_ino(sb, dir_ino, 0);
6396 + dentry = path.dentry;
6397 + if (!path.dentry || IS_ERR(path.dentry))
6399 + AuDebugOn(au_test_anon(path.dentry));
6401 + path.dentry = dget(sb->s_root);
6403 + path.mnt = au_mnt_get(sb);
6404 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
6408 + AuTraceErrPtr(dentry);
6412 +/* ---------------------------------------------------------------------- */
6414 +static int h_acceptable(void *expv, struct dentry *dentry)
6419 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
6420 + char *buf, int len, struct super_block *sb)
6426 + p = d_path(h_rootpath, buf, len);
6431 + path.mnt = h_rootpath->mnt;
6432 + path.dentry = h_parent;
6433 + p = d_path(&path, buf, len);
6439 + path.mnt = au_mnt_get(sb);
6440 + path.dentry = sb->s_root;
6441 + p = d_path(&path, buf, len - strlen(p));
6446 + p[strlen(p)] = '/';
6454 +struct dentry *decode_by_path(struct super_block *sb, aufs_bindex_t bindex,
6455 + ino_t ino, __u32 *fh, int fh_len,
6456 + struct au_nfsd_si_lock *nsi_lock)
6458 + struct dentry *dentry, *h_parent, *root;
6459 + struct super_block *h_sb;
6460 + char *pathname, *p;
6461 + struct vfsmount *h_mnt;
6462 + struct au_branch *br;
6466 + br = au_sbr(sb, bindex);
6467 + /* au_br_get(br); */
6468 + h_mnt = br->br_mnt;
6469 + h_sb = h_mnt->mnt_sb;
6470 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
6471 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
6472 + fh_len - Fh_tail, fh[Fh_h_type],
6473 + h_acceptable, /*context*/NULL);
6474 + dentry = h_parent;
6475 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
6476 + AuWarn1("%s decode_fh failed, %ld\n",
6477 + au_sbtype(h_sb), PTR_ERR(h_parent));
6481 + if (unlikely(au_test_anon(h_parent))) {
6482 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
6484 + goto out_h_parent;
6487 + dentry = ERR_PTR(-ENOMEM);
6488 + pathname = (void *)__get_free_page(GFP_NOFS);
6489 + if (unlikely(!pathname))
6490 + goto out_h_parent;
6492 + root = sb->s_root;
6494 + di_read_lock_parent(root, !AuLock_IR);
6495 + path.dentry = au_h_dptr(root, bindex);
6496 + di_read_unlock(root, !AuLock_IR);
6497 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
6498 + dentry = (void *)p;
6500 + goto out_pathname;
6502 + si_read_unlock(sb);
6503 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
6504 + dentry = ERR_PTR(err);
6505 + if (unlikely(err))
6508 + dentry = ERR_PTR(-ENOENT);
6509 + AuDebugOn(au_test_anon(path.dentry));
6510 + if (unlikely(!path.dentry->d_inode))
6513 + if (ino != path.dentry->d_inode->i_ino)
6514 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
6516 + dentry = dget(path.dentry);
6521 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
6522 + if (!IS_ERR(dentry)) {
6524 + dentry = ERR_PTR(-ESTALE);
6527 + free_page((unsigned long)pathname);
6531 + /* au_br_put(br); */
6532 + AuTraceErrPtr(dentry);
6536 +/* ---------------------------------------------------------------------- */
6538 +static struct dentry *
6539 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
6542 + struct dentry *dentry;
6543 + __u32 *fh = fid->raw;
6544 + ino_t ino, dir_ino;
6545 + aufs_bindex_t bindex;
6546 + struct au_nfsd_si_lock nsi_lock = {
6547 + .sigen = fh[Fh_sigen],
6548 + .br_id = fh[Fh_br_id],
6552 + AuDebugOn(fh_len < Fh_tail);
6554 + dentry = ERR_PTR(-ESTALE);
6555 + /* branch id may be wrapped around */
6556 + bindex = si_nfsd_read_lock(sb, &nsi_lock);
6557 + if (unlikely(bindex < 0))
6559 + nsi_lock.force_lock = 1;
6561 + /* is this inode still cached? */
6562 + ino = decode_ino(fh + Fh_ino);
6563 + AuDebugOn(ino == AUFS_ROOT_INO);
6564 + dir_ino = decode_ino(fh + Fh_dir_ino);
6565 + dentry = decode_by_ino(sb, ino, dir_ino);
6566 + if (IS_ERR(dentry))
6571 + /* is the parent dir cached? */
6572 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
6573 + if (IS_ERR(dentry))
6579 + dentry = decode_by_path(sb, bindex, ino, fh, fh_len, &nsi_lock);
6580 + if (IS_ERR(dentry))
6582 + if (unlikely(!dentry))
6583 + /* todo?: make it ESTALE */
6587 + if (dentry->d_inode->i_generation == fh[Fh_igen])
6588 + goto out_unlock; /* success */
6591 + dentry = ERR_PTR(-ESTALE);
6593 + si_read_unlock(sb);
6595 + AuTraceErrPtr(dentry);
6599 +#if 0 /* reserved for future use */
6600 +/* support subtreecheck option */
6601 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
6602 + int fh_len, int fh_type)
6604 + struct dentry *parent;
6605 + __u32 *fh = fid->raw;
6608 + dir_ino = decode_ino(fh + Fh_dir_ino);
6609 + parent = decode_by_ino(sb, dir_ino, 0);
6610 + if (IS_ERR(parent))
6613 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
6614 + dir_ino, fh, fh_len);
6617 + AuTraceErrPtr(parent);
6622 +/* ---------------------------------------------------------------------- */
6624 +static int aufs_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len,
6628 + aufs_bindex_t bindex, bend;
6629 + struct super_block *sb, *h_sb;
6630 + struct inode *inode;
6631 + struct dentry *parent, *h_parent;
6632 + struct au_branch *br;
6634 + AuDebugOn(au_test_anon(dentry));
6638 + if (unlikely(*max_len <= Fh_tail)) {
6639 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
6643 + err = FILEID_ROOT;
6644 + if (IS_ROOT(dentry)) {
6645 + AuDebugOn(dentry->d_inode->i_ino != AUFS_ROOT_INO);
6651 + sb = dentry->d_sb;
6652 + aufs_read_lock(dentry, AuLock_FLUSH | AuLock_IR);
6653 + parent = dget_parent(dentry);
6654 + di_read_lock_parent(parent, !AuLock_IR);
6655 + inode = dentry->d_inode;
6656 + AuDebugOn(!inode);
6657 +#ifdef CONFIG_AUFS_DEBUG
6658 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
6659 + AuWarn1("NFS-exporting requires xino\n");
6662 + bend = au_dbtaildir(parent);
6663 + for (bindex = au_dbstart(parent); bindex <= bend; bindex++) {
6664 + h_parent = au_h_dptr(parent, bindex);
6670 + if (unlikely(!h_parent))
6674 + br = au_sbr(sb, bindex);
6675 + h_sb = br->br_mnt->mnt_sb;
6676 + if (unlikely(!h_sb->s_export_op)) {
6677 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
6681 + fh[Fh_br_id] = br->br_id;
6682 + fh[Fh_sigen] = au_sigen(sb);
6683 + encode_ino(fh + Fh_ino, inode->i_ino);
6684 + encode_ino(fh + Fh_dir_ino, parent->d_inode->i_ino);
6685 + fh[Fh_igen] = inode->i_generation;
6687 + *max_len -= Fh_tail;
6688 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
6690 + /*connectable or subtreecheck*/0);
6691 + err = fh[Fh_h_type];
6692 + *max_len += Fh_tail;
6693 + /* todo: macros? */
6697 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
6702 + di_read_unlock(parent, !AuLock_IR);
6704 + aufs_read_unlock(dentry, AuLock_IR);
6706 + if (unlikely(err < 0))
6711 +/* ---------------------------------------------------------------------- */
6713 +static struct export_operations aufs_export_op = {
6714 + .fh_to_dentry = aufs_fh_to_dentry,
6715 + /* .fh_to_parent = aufs_fh_to_parent, */
6716 + .encode_fh = aufs_encode_fh
6719 +void au_export_init(struct super_block *sb)
6721 + struct au_sbinfo *sbinfo;
6724 + sb->s_export_op = &aufs_export_op;
6725 + sbinfo = au_sbi(sb);
6726 + sbinfo->si_xigen = NULL;
6727 + get_random_bytes(&u, sizeof(u));
6728 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
6729 + atomic_set(&sbinfo->si_xigen_next, u);
6731 diff -urN linux-2.6.30.org/fs/aufs/file.c linux-2.6.30/fs/aufs/file.c
6732 --- linux-2.6.30.org/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
6733 +++ linux-2.6.30/fs/aufs/file.c 2009-07-21 08:54:19.000000000 +0200
6736 + * Copyright (C) 2005-2009 Junjiro R. Okajima
6738 + * This program, aufs is free software; you can redistribute it and/or modify
6739 + * it under the terms of the GNU General Public License as published by
6740 + * the Free Software Foundation; either version 2 of the License, or
6741 + * (at your option) any later version.
6743 + * This program is distributed in the hope that it will be useful,
6744 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6746 + * GNU General Public License for more details.
6748 + * You should have received a copy of the GNU General Public License
6749 + * along with this program; if not, write to the Free Software
6750 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6754 + * handling file/dir, and address_space operation
6757 +#include <linux/file.h>
6758 +#include <linux/fsnotify.h>
6759 +#include <linux/namei.h>
6760 +#include <linux/pagemap.h>
6764 + * a dirty trick for handling deny_write_access().
6765 + * because FMODE_EXEC flag is not passed to f_op->open(),
6766 + * set it to file->private_data temporary.
6768 +void au_store_oflag(struct nameidata *nd, struct inode *inode)
6771 + /* && !(nd->flags & LOOKUP_CONTINUE) */
6772 + && (nd->flags & LOOKUP_OPEN)
6773 + && (nd->intent.open.flags & vfsub_fmode_to_uint(FMODE_EXEC))
6775 + && S_ISREG(inode->i_mode)) {
6776 + /* suppress a warning in lp64 */
6777 + unsigned long flags = nd->intent.open.flags;
6778 + nd->intent.open.file->private_data = (void *)flags;
6783 +/* drop flags for writing */
6784 +unsigned int au_file_roflags(unsigned int flags)
6786 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
6787 + flags |= O_RDONLY | O_NOATIME;
6791 +/* common functions to regular file and dir */
6792 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
6793 + struct file *file)
6795 + struct file *h_file;
6796 + struct dentry *h_dentry;
6797 + struct inode *h_inode;
6798 + struct super_block *sb;
6799 + struct au_branch *br;
6802 + /* a race condition can happen between open and unlink/rmdir */
6803 + h_file = ERR_PTR(-ENOENT);
6804 + h_dentry = au_h_dptr(dentry, bindex);
6805 + if (au_test_nfsd(current) && !h_dentry)
6807 + h_inode = h_dentry->d_inode;
6808 + if (au_test_nfsd(current) && !h_inode)
6810 + if (unlikely((!d_unhashed(dentry) && d_unhashed(h_dentry))
6814 + sb = dentry->d_sb;
6815 + br = au_sbr(sb, bindex);
6816 + h_file = ERR_PTR(-EACCES);
6817 + if (file && (file->f_mode & FMODE_EXEC)
6818 + && (br->br_mnt->mnt_flags & MNT_NOEXEC))
6821 + /* drop flags for writing */
6822 + if (au_test_ro(sb, bindex, dentry->d_inode))
6823 + flags = au_file_roflags(flags);
6824 + flags &= ~O_CREAT;
6825 + atomic_inc(&br->br_count);
6826 + h_file = dentry_open(dget(h_dentry), mntget(br->br_mnt), flags,
6828 + if (IS_ERR(h_file))
6831 + if (file && (file->f_mode & FMODE_EXEC)) {
6832 + h_file->f_mode |= FMODE_EXEC;
6833 + err = deny_write_access(h_file);
6834 + if (unlikely(err)) {
6836 + h_file = ERR_PTR(err);
6840 + fsnotify_open(h_dentry);
6841 + goto out; /* success */
6844 + atomic_dec(&br->br_count);
6849 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags))
6852 + struct dentry *dentry;
6853 + struct super_block *sb;
6855 + dentry = file->f_dentry;
6856 + sb = dentry->d_sb;
6857 + si_read_lock(sb, AuLock_FLUSH);
6858 + err = au_finfo_init(file);
6859 + if (unlikely(err))
6862 + di_read_lock_child(dentry, AuLock_IR);
6863 + err = open(file, file->f_flags);
6864 + di_read_unlock(dentry, AuLock_IR);
6866 + fi_write_unlock(file);
6867 + if (unlikely(err))
6868 + au_finfo_fin(file);
6870 + si_read_unlock(sb);
6874 +int au_reopen_nondir(struct file *file)
6877 + aufs_bindex_t bstart, bindex, bend;
6878 + struct dentry *dentry;
6879 + struct file *h_file, *h_file_tmp;
6881 + dentry = file->f_dentry;
6882 + bstart = au_dbstart(dentry);
6883 + h_file_tmp = NULL;
6884 + if (au_fbstart(file) == bstart) {
6885 + h_file = au_h_fptr(file, bstart);
6886 + if (file->f_mode == h_file->f_mode)
6887 + return 0; /* success */
6888 + h_file_tmp = h_file;
6889 + get_file(h_file_tmp);
6890 + au_set_h_fptr(file, bstart, NULL);
6892 + AuDebugOn(au_fbstart(file) < bstart
6893 + || au_fi(file)->fi_hfile[0 + bstart].hf_file);
6895 + h_file = au_h_open(dentry, bstart, file->f_flags & ~O_TRUNC, file);
6896 + err = PTR_ERR(h_file);
6897 + if (IS_ERR(h_file))
6898 + goto out; /* todo: close all? */
6901 + au_set_fbstart(file, bstart);
6902 + au_set_h_fptr(file, bstart, h_file);
6903 + au_update_figen(file);
6904 + /* todo: necessary? */
6905 + /* file->f_ra = h_file->f_ra; */
6907 + /* close lower files */
6908 + bend = au_fbend(file);
6909 + for (bindex = bstart + 1; bindex <= bend; bindex++)
6910 + au_set_h_fptr(file, bindex, NULL);
6911 + au_set_fbend(file, bstart);
6919 +/* ---------------------------------------------------------------------- */
6921 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
6922 + struct dentry *hi_wh)
6925 + aufs_bindex_t bstart;
6926 + struct au_dinfo *dinfo;
6927 + struct dentry *h_dentry;
6929 + dinfo = au_di(file->f_dentry);
6930 + bstart = dinfo->di_bstart;
6931 + dinfo->di_bstart = btgt;
6932 + h_dentry = dinfo->di_hdentry[0 + btgt].hd_dentry;
6933 + dinfo->di_hdentry[0 + btgt].hd_dentry = hi_wh;
6934 + err = au_reopen_nondir(file);
6935 + dinfo->di_hdentry[0 + btgt].hd_dentry = h_dentry;
6936 + dinfo->di_bstart = bstart;
6941 +static int au_ready_to_write_wh(struct file *file, loff_t len,
6942 + aufs_bindex_t bcpup)
6945 + struct inode *inode;
6946 + struct dentry *dentry, *hi_wh;
6947 + struct super_block *sb;
6949 + dentry = file->f_dentry;
6950 + inode = dentry->d_inode;
6951 + hi_wh = au_hi_wh(inode, bcpup);
6953 + err = au_sio_cpup_wh(dentry, bcpup, len, file);
6955 + /* already copied-up after unlink */
6956 + err = au_reopen_wh(file, bcpup, hi_wh);
6958 + sb = dentry->d_sb;
6959 + if (!err && inode->i_nlink > 1 && au_opt_test(au_mntflags(sb), PLINK))
6960 + au_plink_append(inode, bcpup, au_h_dptr(dentry, bcpup));
6966 + * prepare the @file for writing.
6968 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
6971 + aufs_bindex_t bstart, bcpup;
6972 + struct dentry *dentry, *parent, *h_dentry;
6973 + struct inode *h_inode, *inode;
6974 + struct super_block *sb;
6976 + dentry = file->f_dentry;
6977 + sb = dentry->d_sb;
6978 + bstart = au_fbstart(file);
6979 + inode = dentry->d_inode;
6980 + err = au_test_ro(sb, bstart, inode);
6981 + if (!err && (au_h_fptr(file, bstart)->f_mode & FMODE_WRITE)) {
6982 + err = au_pin(pin, dentry, bstart, AuOpt_UDBA_NONE, /*flags*/0);
6986 + /* need to cpup */
6987 + parent = dget_parent(dentry);
6988 + di_write_lock_parent(parent);
6989 + err = AuWbrCopyup(au_sbi(sb), dentry);
6991 + if (unlikely(err < 0))
6995 + if (!au_h_dptr(parent, bcpup)) {
6996 + err = au_cpup_dirs(dentry, bcpup);
6997 + if (unlikely(err))
7001 + err = au_pin(pin, dentry, bcpup, AuOpt_UDBA_NONE,
7002 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
7003 + if (unlikely(err))
7006 + h_dentry = au_h_fptr(file, bstart)->f_dentry;
7007 + h_inode = h_dentry->d_inode;
7008 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7009 + if (d_unhashed(dentry) /* || d_unhashed(h_dentry) */
7010 + /* || !h_inode->i_nlink */) {
7011 + err = au_ready_to_write_wh(file, len, bcpup);
7012 + di_downgrade_lock(parent, AuLock_IR);
7014 + di_downgrade_lock(parent, AuLock_IR);
7015 + if (!au_h_dptr(dentry, bcpup))
7016 + err = au_sio_cpup_simple(dentry, bcpup, len,
7019 + err = au_reopen_nondir(file);
7021 + mutex_unlock(&h_inode->i_mutex);
7024 + au_pin_set_parent_lflag(pin, /*lflag*/0);
7025 + goto out_dput; /* success */
7031 + di_downgrade_lock(parent, AuLock_IR);
7033 + di_read_unlock(parent, AuLock_IR);
7040 +/* ---------------------------------------------------------------------- */
7042 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
7045 + aufs_bindex_t bstart;
7046 + struct au_pin pin;
7047 + struct au_finfo *finfo;
7048 + struct dentry *dentry, *parent, *hi_wh;
7049 + struct inode *inode;
7050 + struct super_block *sb;
7053 + finfo = au_fi(file);
7054 + dentry = file->f_dentry;
7055 + sb = dentry->d_sb;
7056 + inode = dentry->d_inode;
7057 + bstart = au_ibstart(inode);
7058 + if (bstart == finfo->fi_bstart)
7061 + parent = dget_parent(dentry);
7062 + if (au_test_ro(sb, bstart, inode)) {
7063 + di_read_lock_parent(parent, !AuLock_IR);
7064 + err = AuWbrCopyup(au_sbi(sb), dentry);
7066 + di_read_unlock(parent, !AuLock_IR);
7067 + if (unlikely(err < 0))
7072 + di_read_lock_parent(parent, AuLock_IR);
7073 + hi_wh = au_hi_wh(inode, bstart);
7074 + if (au_opt_test(au_mntflags(sb), PLINK)
7075 + && au_plink_test(inode)
7076 + && !d_unhashed(dentry)) {
7077 + err = au_test_and_cpup_dirs(dentry, bstart);
7078 + if (unlikely(err))
7081 + /* always superio. */
7082 + err = au_pin(&pin, dentry, bstart, AuOpt_UDBA_NONE,
7083 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
7085 + err = au_sio_cpup_simple(dentry, bstart, -1,
7088 + } else if (hi_wh) {
7089 + /* already copied-up after unlink */
7090 + err = au_reopen_wh(file, bstart, hi_wh);
7095 + di_read_unlock(parent, AuLock_IR);
7102 +static void au_do_refresh_file(struct file *file)
7104 + aufs_bindex_t bindex, bend, new_bindex, brid;
7105 + struct au_hfile *p, tmp, *q;
7106 + struct au_finfo *finfo;
7107 + struct super_block *sb;
7109 + sb = file->f_dentry->d_sb;
7110 + finfo = au_fi(file);
7111 + p = finfo->fi_hfile + finfo->fi_bstart;
7112 + brid = p->hf_br->br_id;
7113 + bend = finfo->fi_bend;
7114 + for (bindex = finfo->fi_bstart; bindex <= bend; bindex++, p++) {
7118 + new_bindex = au_br_index(sb, p->hf_br->br_id);
7119 + if (new_bindex == bindex)
7121 + if (new_bindex < 0) {
7122 + au_set_h_fptr(file, bindex, NULL);
7126 + /* swap two lower inode, and loop again */
7127 + q = finfo->fi_hfile + new_bindex;
7131 + if (tmp.hf_file) {
7137 + p = finfo->fi_hfile;
7138 + if (!au_test_mmapped(file) && !d_unhashed(file->f_dentry)) {
7139 + bend = au_sbend(sb);
7140 + for (finfo->fi_bstart = 0; finfo->fi_bstart <= bend;
7141 + finfo->fi_bstart++, p++)
7143 + if (p->hf_file->f_dentry
7144 + && p->hf_file->f_dentry->d_inode)
7147 + au_hfput(p, file);
7150 + bend = au_br_index(sb, brid);
7151 + for (finfo->fi_bstart = 0; finfo->fi_bstart < bend;
7152 + finfo->fi_bstart++, p++)
7154 + au_hfput(p, file);
7155 + bend = au_sbend(sb);
7158 + p = finfo->fi_hfile + bend;
7159 + for (finfo->fi_bend = bend; finfo->fi_bend >= finfo->fi_bstart;
7160 + finfo->fi_bend--, p--)
7162 + if (p->hf_file->f_dentry
7163 + && p->hf_file->f_dentry->d_inode)
7166 + au_hfput(p, file);
7168 + AuDebugOn(finfo->fi_bend < finfo->fi_bstart);
7172 + * after branch manipulating, refresh the file.
7174 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
7176 + int err, need_reopen;
7177 + struct dentry *dentry;
7178 + aufs_bindex_t bend, bindex;
7180 + dentry = file->f_dentry;
7181 + err = au_fi_realloc(au_fi(file), au_sbend(dentry->d_sb) + 1);
7182 + if (unlikely(err))
7184 + au_do_refresh_file(file);
7188 + if (!au_test_mmapped(file))
7189 + err = au_file_refresh_by_inode(file, &need_reopen);
7190 + if (!err && need_reopen && !d_unhashed(dentry))
7191 + err = reopen(file);
7193 + au_update_figen(file);
7194 + return 0; /* success */
7197 + /* error, close all lower files */
7198 + bend = au_fbend(file);
7199 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
7200 + au_set_h_fptr(file, bindex, NULL);
7206 +/* common function to regular file and dir */
7207 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
7211 + unsigned int sigen, figen;
7212 + aufs_bindex_t bstart;
7213 + unsigned char pseudo_link;
7214 + struct dentry *dentry;
7217 + dentry = file->f_dentry;
7218 + sigen = au_sigen(dentry->d_sb);
7219 + fi_write_lock(file);
7220 + figen = au_figen(file);
7221 + di_write_lock_child(dentry);
7222 + bstart = au_dbstart(dentry);
7223 + pseudo_link = (bstart != au_ibstart(dentry->d_inode));
7224 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
7226 + di_downgrade_lock(dentry, AuLock_IR);
7227 + fi_downgrade_lock(file);
7229 + goto out; /* success */
7232 + AuDbg("sigen %d, figen %d\n", sigen, figen);
7233 + if (sigen != au_digen(dentry)
7234 + || sigen != au_iigen(dentry->d_inode)) {
7235 + err = au_reval_dpath(dentry, sigen);
7236 + if (unlikely(err < 0))
7238 + AuDebugOn(au_digen(dentry) != sigen
7239 + || au_iigen(dentry->d_inode) != sigen);
7242 + err = refresh_file(file, reopen);
7245 + di_downgrade_lock(dentry, AuLock_IR);
7246 + fi_downgrade_lock(file);
7249 + di_write_unlock(dentry);
7250 + fi_write_unlock(file);
7257 +/* ---------------------------------------------------------------------- */
7259 +/* cf. aufs_nopage() */
7260 +/* for madvise(2) */
7261 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
7263 + unlock_page(page);
7267 +/* they will never be called. */
7268 +#ifdef CONFIG_AUFS_DEBUG
7269 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
7270 + loff_t pos, unsigned len, unsigned flags,
7271 + struct page **pagep, void **fsdata)
7272 +{ AuUnsupport(); return 0; }
7273 +static int aufs_write_end(struct file *file, struct address_space *mapping,
7274 + loff_t pos, unsigned len, unsigned copied,
7275 + struct page *page, void *fsdata)
7276 +{ AuUnsupport(); return 0; }
7277 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
7278 +{ AuUnsupport(); return 0; }
7279 +static void aufs_sync_page(struct page *page)
7282 +static int aufs_set_page_dirty(struct page *page)
7283 +{ AuUnsupport(); return 0; }
7284 +static void aufs_invalidatepage(struct page *page, unsigned long offset)
7286 +static int aufs_releasepage(struct page *page, gfp_t gfp)
7287 +{ AuUnsupport(); return 0; }
7288 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
7289 + const struct iovec *iov, loff_t offset,
7290 + unsigned long nr_segs)
7291 +{ AuUnsupport(); return 0; }
7292 +#endif /* CONFIG_AUFS_DEBUG */
7294 +struct address_space_operations aufs_aop = {
7295 + .readpage = aufs_readpage,
7296 +#ifdef CONFIG_AUFS_DEBUG
7297 + .writepage = aufs_writepage,
7298 + .sync_page = aufs_sync_page,
7299 + .set_page_dirty = aufs_set_page_dirty,
7300 + .write_begin = aufs_write_begin,
7301 + .write_end = aufs_write_end,
7302 + .invalidatepage = aufs_invalidatepage,
7303 + .releasepage = aufs_releasepage,
7304 + .direct_IO = aufs_direct_IO,
7305 +#endif /* CONFIG_AUFS_DEBUG */
7307 diff -urN linux-2.6.30.org/fs/aufs/file.h linux-2.6.30/fs/aufs/file.h
7308 --- linux-2.6.30.org/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
7309 +++ linux-2.6.30/fs/aufs/file.h 2009-07-21 08:54:19.000000000 +0200
7312 + * Copyright (C) 2005-2009 Junjiro R. Okajima
7314 + * This program, aufs is free software; you can redistribute it and/or modify
7315 + * it under the terms of the GNU General Public License as published by
7316 + * the Free Software Foundation; either version 2 of the License, or
7317 + * (at your option) any later version.
7319 + * This program is distributed in the hope that it will be useful,
7320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7322 + * GNU General Public License for more details.
7324 + * You should have received a copy of the GNU General Public License
7325 + * along with this program; if not, write to the Free Software
7326 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7333 +#ifndef __AUFS_FILE_H__
7334 +#define __AUFS_FILE_H__
7338 +#include <linux/fs.h>
7339 +#include <linux/poll.h>
7340 +#include <linux/aufs_type.h>
7345 + struct file *hf_file;
7346 + struct au_branch *hf_br;
7351 + atomic_t fi_generation;
7353 + struct au_rwsem fi_rwsem;
7354 + struct au_hfile *fi_hfile;
7355 + aufs_bindex_t fi_bstart, fi_bend;
7358 + /* non-dir only */
7360 + struct vm_operations_struct *fi_h_vm_ops;
7361 + struct vm_operations_struct *fi_vm_ops;
7366 + struct au_vdir *fi_vdir_cache;
7367 + int fi_maintain_plink;
7372 +/* ---------------------------------------------------------------------- */
7375 +extern struct address_space_operations aufs_aop;
7376 +void au_store_oflag(struct nameidata *nd, struct inode *inode);
7377 +unsigned int au_file_roflags(unsigned int flags);
7378 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
7379 + struct file *file);
7380 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags));
7381 +int au_reopen_nondir(struct file *file);
7383 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
7384 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
7388 +#ifdef CONFIG_AUFS_POLL
7389 +unsigned int aufs_poll(struct file *file, poll_table *wait);
7393 +extern const struct file_operations aufs_file_fop;
7394 +int aufs_flush(struct file *file, fl_owner_t id);
7397 +void au_hfput(struct au_hfile *hf, struct file *file);
7398 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
7399 + struct file *h_file);
7401 +void au_update_figen(struct file *file);
7403 +void au_finfo_fin(struct file *file);
7404 +int au_finfo_init(struct file *file);
7405 +int au_fi_realloc(struct au_finfo *finfo, int nbr);
7407 +/* ---------------------------------------------------------------------- */
7409 +static inline struct au_finfo *au_fi(struct file *file)
7411 + return file->private_data;
7414 +/* ---------------------------------------------------------------------- */
7417 + * fi_read_lock, fi_write_lock,
7418 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
7420 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
7422 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
7423 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
7424 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
7426 +/* ---------------------------------------------------------------------- */
7428 +/* todo: hard/soft set? */
7429 +static inline aufs_bindex_t au_fbstart(struct file *file)
7431 + return au_fi(file)->fi_bstart;
7434 +static inline aufs_bindex_t au_fbend(struct file *file)
7436 + return au_fi(file)->fi_bend;
7439 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
7441 + return au_fi(file)->fi_vdir_cache;
7444 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
7446 + au_fi(file)->fi_bstart = bindex;
7449 +static inline void au_set_fbend(struct file *file, aufs_bindex_t bindex)
7451 + au_fi(file)->fi_bend = bindex;
7454 +static inline void au_set_fvdir_cache(struct file *file,
7455 + struct au_vdir *vdir_cache)
7457 + au_fi(file)->fi_vdir_cache = vdir_cache;
7460 +static inline struct file *au_h_fptr(struct file *file, aufs_bindex_t bindex)
7462 + return au_fi(file)->fi_hfile[0 + bindex].hf_file;
7465 +/* todo: memory barrier? */
7466 +static inline unsigned int au_figen(struct file *f)
7468 + return atomic_read(&au_fi(f)->fi_generation);
7471 +static inline int au_test_mmapped(struct file *f)
7473 + return !!(au_fi(f)->fi_h_vm_ops);
7476 +#endif /* __KERNEL__ */
7477 +#endif /* __AUFS_FILE_H__ */
7478 diff -urN linux-2.6.30.org/fs/aufs/finfo.c linux-2.6.30/fs/aufs/finfo.c
7479 --- linux-2.6.30.org/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
7480 +++ linux-2.6.30/fs/aufs/finfo.c 2009-07-21 08:54:19.000000000 +0200
7483 + * Copyright (C) 2005-2009 Junjiro R. Okajima
7485 + * This program, aufs is free software; you can redistribute it and/or modify
7486 + * it under the terms of the GNU General Public License as published by
7487 + * the Free Software Foundation; either version 2 of the License, or
7488 + * (at your option) any later version.
7490 + * This program is distributed in the hope that it will be useful,
7491 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7492 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7493 + * GNU General Public License for more details.
7495 + * You should have received a copy of the GNU General Public License
7496 + * along with this program; if not, write to the Free Software
7497 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7501 + * file private data
7504 +#include <linux/file.h>
7507 +void au_hfput(struct au_hfile *hf, struct file *file)
7509 + if (file->f_mode & FMODE_EXEC)
7510 + allow_write_access(hf->hf_file);
7511 + fput(hf->hf_file);
7512 + hf->hf_file = NULL;
7513 + atomic_dec_return(&hf->hf_br->br_count);
7517 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
7519 + struct au_finfo *finfo = au_fi(file);
7520 + struct au_hfile *hf;
7522 + hf = finfo->fi_hfile + bindex;
7524 + au_hfput(hf, file);
7526 + hf->hf_file = val;
7527 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
7531 +void au_update_figen(struct file *file)
7533 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
7534 + /* smp_mb(); */ /* atomic_set */
7537 +/* ---------------------------------------------------------------------- */
7539 +void au_finfo_fin(struct file *file)
7541 + struct au_finfo *finfo;
7542 + aufs_bindex_t bindex, bend;
7544 + fi_write_lock(file);
7545 + bend = au_fbend(file);
7546 + bindex = au_fbstart(file);
7549 + * calls fput() instead of filp_close(),
7550 + * since no dnotify or lock for the lower file.
7552 + for (; bindex <= bend; bindex++)
7553 + au_set_h_fptr(file, bindex, NULL);
7555 + finfo = au_fi(file);
7556 + au_dbg_verify_hf(finfo);
7557 + kfree(finfo->fi_hfile);
7558 + fi_write_unlock(file);
7559 + AuRwDestroy(&finfo->fi_rwsem);
7560 + au_cache_free_finfo(finfo);
7563 +int au_finfo_init(struct file *file)
7565 + struct au_finfo *finfo;
7566 + struct dentry *dentry;
7569 + dentry = file->f_dentry;
7570 + finfo = au_cache_alloc_finfo();
7571 + if (unlikely(!finfo))
7574 + finfo->fi_hfile = kcalloc(au_sbend(dentry->d_sb) + 1,
7575 + sizeof(*finfo->fi_hfile), GFP_NOFS);
7576 + if (unlikely(!finfo->fi_hfile))
7579 + au_rw_init_wlock(&finfo->fi_rwsem);
7580 + finfo->fi_bstart = -1;
7581 + finfo->fi_bend = -1;
7582 + atomic_set(&finfo->fi_generation, au_digen(dentry));
7583 + /* smp_mb(); */ /* atomic_set */
7585 + /* cf. au_store_oflag() */
7586 + /* suppress a warning in lp64 */
7587 + ul = (unsigned long)file->private_data;
7588 + file->f_mode |= (vfsub_uint_to_fmode(ul) & FMODE_EXEC);
7589 + file->private_data = finfo;
7590 + return 0; /* success */
7593 + au_cache_free_finfo(finfo);
7598 +int au_fi_realloc(struct au_finfo *finfo, int nbr)
7601 + struct au_hfile *hfp;
7604 + sz = sizeof(*hfp) * (finfo->fi_bend + 1);
7606 + sz = sizeof(*hfp);
7607 + hfp = au_kzrealloc(finfo->fi_hfile, sz, sizeof(*hfp) * nbr, GFP_NOFS);
7609 + finfo->fi_hfile = hfp;
7615 diff -urN linux-2.6.30.org/fs/aufs/f_op.c linux-2.6.30/fs/aufs/f_op.c
7616 --- linux-2.6.30.org/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
7617 +++ linux-2.6.30/fs/aufs/f_op.c 2009-07-21 08:54:19.000000000 +0200
7620 + * Copyright (C) 2005-2009 Junjiro R. Okajima
7622 + * This program, aufs is free software; you can redistribute it and/or modify
7623 + * it under the terms of the GNU General Public License as published by
7624 + * the Free Software Foundation; either version 2 of the License, or
7625 + * (at your option) any later version.
7627 + * This program is distributed in the hope that it will be useful,
7628 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7629 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7630 + * GNU General Public License for more details.
7632 + * You should have received a copy of the GNU General Public License
7633 + * along with this program; if not, write to the Free Software
7634 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7638 + * file and vm operations
7641 +#include <linux/file.h>
7642 +#include <linux/fs_stack.h>
7643 +#include <linux/mm.h>
7644 +#include <linux/security.h>
7647 +/* common function to regular file and dir */
7648 +int aufs_flush(struct file *file, fl_owner_t id)
7651 + aufs_bindex_t bindex, bend;
7652 + struct dentry *dentry;
7653 + struct file *h_file;
7655 + dentry = file->f_dentry;
7656 + si_noflush_read_lock(dentry->d_sb);
7657 + fi_read_lock(file);
7658 + di_read_lock_child(dentry, AuLock_IW);
7661 + bend = au_fbend(file);
7662 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
7663 + h_file = au_h_fptr(file, bindex);
7664 + if (!h_file || !h_file->f_op || !h_file->f_op->flush)
7667 + err = h_file->f_op->flush(h_file, id);
7669 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
7672 + au_cpup_attr_timesizes(dentry->d_inode);
7674 + di_read_unlock(dentry, AuLock_IW);
7675 + fi_read_unlock(file);
7676 + si_read_unlock(dentry->d_sb);
7680 +/* ---------------------------------------------------------------------- */
7682 +static int do_open_nondir(struct file *file, int flags)
7685 + aufs_bindex_t bindex;
7686 + struct file *h_file;
7687 + struct dentry *dentry;
7688 + struct au_finfo *finfo;
7691 + dentry = file->f_dentry;
7692 + finfo = au_fi(file);
7693 + finfo->fi_h_vm_ops = NULL;
7694 + finfo->fi_vm_ops = NULL;
7695 + bindex = au_dbstart(dentry);
7696 + /* O_TRUNC is processed already */
7697 + BUG_ON(au_test_ro(dentry->d_sb, bindex, dentry->d_inode)
7698 + && (flags & O_TRUNC));
7700 + h_file = au_h_open(dentry, bindex, flags, file);
7701 + if (IS_ERR(h_file))
7702 + err = PTR_ERR(h_file);
7704 + au_set_fbstart(file, bindex);
7705 + au_set_fbend(file, bindex);
7706 + au_set_h_fptr(file, bindex, h_file);
7707 + au_update_figen(file);
7708 + /* todo: necessary? */
7709 + /* file->f_ra = h_file->f_ra; */
7714 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
7715 + struct file *file)
7717 + return au_do_open(file, do_open_nondir);
7720 +static int aufs_release_nondir(struct inode *inode __maybe_unused,
7721 + struct file *file)
7723 + struct super_block *sb = file->f_dentry->d_sb;
7725 + si_noflush_read_lock(sb);
7726 + kfree(au_fi(file)->fi_vm_ops);
7727 + au_finfo_fin(file);
7728 + si_read_unlock(sb);
7732 +/* ---------------------------------------------------------------------- */
7734 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
7738 + struct dentry *dentry;
7739 + struct file *h_file;
7740 + struct super_block *sb;
7742 + dentry = file->f_dentry;
7743 + sb = dentry->d_sb;
7744 + si_read_lock(sb, AuLock_FLUSH);
7745 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
7746 + if (unlikely(err))
7749 + h_file = au_h_fptr(file, au_fbstart(file));
7750 + err = vfsub_read_u(h_file, buf, count, ppos);
7751 + /* todo: necessary? */
7752 + /* file->f_ra = h_file->f_ra; */
7753 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
7755 + di_read_unlock(dentry, AuLock_IR);
7756 + fi_read_unlock(file);
7758 + si_read_unlock(sb);
7762 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
7763 + size_t count, loff_t *ppos)
7766 + aufs_bindex_t bstart;
7767 + struct au_pin pin;
7768 + struct dentry *dentry;
7769 + struct inode *inode;
7770 + struct super_block *sb;
7771 + struct file *h_file;
7772 + char __user *buf = (char __user *)ubuf;
7774 + dentry = file->f_dentry;
7775 + sb = dentry->d_sb;
7776 + inode = dentry->d_inode;
7777 + mutex_lock(&inode->i_mutex);
7778 + si_read_lock(sb, AuLock_FLUSH);
7780 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
7781 + if (unlikely(err))
7784 + err = au_ready_to_write(file, -1, &pin);
7785 + di_downgrade_lock(dentry, AuLock_IR);
7786 + if (unlikely(err))
7789 + bstart = au_fbstart(file);
7790 + h_file = au_h_fptr(file, bstart);
7792 + err = vfsub_write_u(h_file, buf, count, ppos);
7793 + au_cpup_attr_timesizes(inode);
7794 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
7797 + di_read_unlock(dentry, AuLock_IR);
7798 + fi_write_unlock(file);
7800 + si_read_unlock(sb);
7801 + mutex_unlock(&inode->i_mutex);
7805 +static ssize_t aufs_aio_read(struct kiocb *kio, const struct iovec *iov,
7806 + unsigned long nv, loff_t pos)
7809 + struct file *file, *h_file;
7810 + struct dentry *dentry;
7811 + struct super_block *sb;
7813 + file = kio->ki_filp;
7814 + dentry = file->f_dentry;
7815 + sb = dentry->d_sb;
7816 + si_read_lock(sb, AuLock_FLUSH);
7817 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
7818 + if (unlikely(err))
7822 + h_file = au_h_fptr(file, au_fbstart(file));
7823 + if (h_file->f_op && h_file->f_op->aio_read) {
7824 + err = security_file_permission(h_file, MAY_READ);
7825 + if (unlikely(err))
7827 + if (!is_sync_kiocb(kio)) {
7831 + kio->ki_filp = h_file;
7832 + err = h_file->f_op->aio_read(kio, iov, nv, pos);
7833 + /* todo: necessary? */
7834 + /* file->f_ra = h_file->f_ra; */
7835 + fsstack_copy_attr_atime(dentry->d_inode,
7836 + h_file->f_dentry->d_inode);
7838 + /* currently there is no such fs */
7839 + WARN_ON_ONCE(h_file->f_op && h_file->f_op->read);
7842 + di_read_unlock(dentry, AuLock_IR);
7843 + fi_read_unlock(file);
7845 + si_read_unlock(sb);
7849 +static ssize_t aufs_aio_write(struct kiocb *kio, const struct iovec *iov,
7850 + unsigned long nv, loff_t pos)
7853 + aufs_bindex_t bstart;
7854 + struct au_pin pin;
7855 + struct dentry *dentry;
7856 + struct inode *inode;
7857 + struct super_block *sb;
7858 + struct file *file, *h_file;
7860 + file = kio->ki_filp;
7861 + dentry = file->f_dentry;
7862 + sb = dentry->d_sb;
7863 + inode = dentry->d_inode;
7864 + mutex_lock(&inode->i_mutex);
7865 + si_read_lock(sb, AuLock_FLUSH);
7867 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
7868 + if (unlikely(err))
7871 + err = au_ready_to_write(file, -1, &pin);
7872 + di_downgrade_lock(dentry, AuLock_IR);
7873 + if (unlikely(err))
7877 + bstart = au_fbstart(file);
7878 + h_file = au_h_fptr(file, bstart);
7880 + if (h_file->f_op && h_file->f_op->aio_write) {
7881 + err = security_file_permission(h_file, MAY_WRITE);
7882 + if (unlikely(err))
7884 + if (!is_sync_kiocb(kio)) {
7888 + kio->ki_filp = h_file;
7889 + err = h_file->f_op->aio_write(kio, iov, nv, pos);
7890 + au_cpup_attr_timesizes(inode);
7891 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
7893 + /* currently there is no such fs */
7894 + WARN_ON_ONCE(h_file->f_op && h_file->f_op->write);
7897 + di_read_unlock(dentry, AuLock_IR);
7898 + fi_write_unlock(file);
7900 + si_read_unlock(sb);
7901 + mutex_unlock(&inode->i_mutex);
7905 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
7906 + struct pipe_inode_info *pipe, size_t len,
7907 + unsigned int flags)
7910 + struct file *h_file;
7911 + struct dentry *dentry;
7912 + struct super_block *sb;
7914 + dentry = file->f_dentry;
7915 + sb = dentry->d_sb;
7916 + si_read_lock(sb, AuLock_FLUSH);
7917 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
7918 + if (unlikely(err))
7922 + h_file = au_h_fptr(file, au_fbstart(file));
7923 + if (au_test_loopback_kthread()) {
7924 + file->f_mapping = h_file->f_mapping;
7925 + smp_mb(); /* unnecessary? */
7927 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
7928 + /* todo: necessasry? */
7929 + /* file->f_ra = h_file->f_ra; */
7930 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
7932 + di_read_unlock(dentry, AuLock_IR);
7933 + fi_read_unlock(file);
7936 + si_read_unlock(sb);
7941 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
7942 + size_t len, unsigned int flags)
7945 + struct au_pin pin;
7946 + struct dentry *dentry;
7947 + struct inode *inode;
7948 + struct super_block *sb;
7949 + struct file *h_file;
7951 + dentry = file->f_dentry;
7952 + inode = dentry->d_inode;
7953 + mutex_lock(&inode->i_mutex);
7954 + sb = dentry->d_sb;
7955 + si_read_lock(sb, AuLock_FLUSH);
7957 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
7958 + if (unlikely(err))
7961 + err = au_ready_to_write(file, -1, &pin);
7962 + di_downgrade_lock(dentry, AuLock_IR);
7963 + if (unlikely(err))
7966 + h_file = au_h_fptr(file, au_fbstart(file));
7968 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
7969 + au_cpup_attr_timesizes(inode);
7970 + inode->i_mode = h_file->f_dentry->d_inode->i_mode;
7973 + di_read_unlock(dentry, AuLock_IR);
7974 + fi_write_unlock(file);
7976 + si_read_unlock(sb);
7977 + mutex_unlock(&inode->i_mutex);
7981 +/* ---------------------------------------------------------------------- */
7983 +static struct file *au_safe_file(struct vm_area_struct *vma)
7985 + struct file *file;
7987 + file = vma->vm_file;
7988 + if (file->private_data && au_test_aufs(file->f_dentry->d_sb))
7993 +static void au_reset_file(struct vm_area_struct *vma, struct file *file)
7995 + vma->vm_file = file;
7996 + /* smp_mb(); */ /* flush vm_file */
7999 +static int aufs_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8002 + static DECLARE_WAIT_QUEUE_HEAD(wq);
8003 + struct file *file, *h_file;
8004 + struct au_finfo *finfo;
8006 + /* todo: non-robr mode, user vm_file as it is? */
8007 + wait_event(wq, (file = au_safe_file(vma)));
8009 + /* do not revalidate, no si lock */
8010 + finfo = au_fi(file);
8011 + h_file = finfo->fi_hfile[0 + finfo->fi_bstart].hf_file;
8012 + AuDebugOn(!h_file || !au_test_mmapped(file));
8014 + fi_write_lock(file);
8015 + vma->vm_file = h_file;
8016 + err = finfo->fi_h_vm_ops->fault(vma, vmf);
8017 + /* todo: necessary? */
8018 + /* file->f_ra = h_file->f_ra; */
8019 + au_reset_file(vma, file);
8020 + fi_write_unlock(file);
8021 +#if 0 /* def CONFIG_SMP */
8022 + /* wake_up_nr(&wq, online_cpu - 1); */
8031 +static int aufs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
8034 + static DECLARE_WAIT_QUEUE_HEAD(wq);
8035 + struct file *file, *h_file;
8036 + struct au_finfo *finfo;
8038 + wait_event(wq, (file = au_safe_file(vma)));
8040 + finfo = au_fi(file);
8041 + h_file = finfo->fi_hfile[0 + finfo->fi_bstart].hf_file;
8042 + AuDebugOn(!h_file || !au_test_mmapped(file));
8044 + fi_write_lock(file);
8045 + vma->vm_file = h_file;
8046 + err = finfo->fi_h_vm_ops->page_mkwrite(vma, vmf);
8047 + au_reset_file(vma, file);
8048 + fi_write_unlock(file);
8054 +static void aufs_vm_close(struct vm_area_struct *vma)
8056 + static DECLARE_WAIT_QUEUE_HEAD(wq);
8057 + struct file *file, *h_file;
8058 + struct au_finfo *finfo;
8060 + wait_event(wq, (file = au_safe_file(vma)));
8062 + finfo = au_fi(file);
8063 + h_file = finfo->fi_hfile[0 + finfo->fi_bstart].hf_file;
8064 + AuDebugOn(!h_file || !au_test_mmapped(file));
8066 + fi_write_lock(file);
8067 + vma->vm_file = h_file;
8068 + finfo->fi_h_vm_ops->close(vma);
8069 + au_reset_file(vma, file);
8070 + fi_write_unlock(file);
8074 +static struct vm_operations_struct aufs_vm_ops = {
8075 + /* .close and .page_mkwrite are not set by default */
8076 + .fault = aufs_fault,
8079 +/* ---------------------------------------------------------------------- */
8081 +static struct vm_operations_struct *au_vm_ops(struct file *h_file,
8082 + struct vm_area_struct *vma)
8084 + struct vm_operations_struct *vm_ops;
8087 + vm_ops = ERR_PTR(-ENODEV);
8088 + if (!h_file->f_op || !h_file->f_op->mmap)
8091 + err = h_file->f_op->mmap(h_file, vma);
8092 + vm_ops = ERR_PTR(err);
8093 + if (unlikely(err))
8096 + vm_ops = vma->vm_ops;
8097 + err = do_munmap(current->mm, vma->vm_start,
8098 + vma->vm_end - vma->vm_start);
8099 + if (unlikely(err)) {
8100 + AuIOErr("failed internal unmapping %.*s, %d\n",
8101 + AuDLNPair(h_file->f_dentry), err);
8102 + vm_ops = ERR_PTR(-EIO);
8109 +static int au_custom_vm_ops(struct au_finfo *finfo, struct vm_area_struct *vma)
8112 + struct vm_operations_struct *h_ops;
8115 + h_ops = finfo->fi_h_vm_ops;
8116 + AuDebugOn(!h_ops);
8117 + if ((!h_ops->page_mkwrite && !h_ops->close)
8118 + || finfo->fi_vm_ops)
8122 + finfo->fi_vm_ops = kmemdup(&aufs_vm_ops, sizeof(aufs_vm_ops), GFP_NOFS);
8123 + if (unlikely(!finfo->fi_vm_ops))
8127 + if (h_ops->page_mkwrite)
8128 + finfo->fi_vm_ops->page_mkwrite = aufs_page_mkwrite;
8130 + finfo->fi_vm_ops->close = aufs_vm_close;
8132 + vma->vm_ops = finfo->fi_vm_ops;
8138 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
8141 + unsigned char wlock, mmapped;
8142 + struct dentry *dentry;
8143 + struct super_block *sb;
8144 + struct file *h_file;
8145 + struct vm_operations_struct *vm_ops;
8147 + dentry = file->f_dentry;
8148 + mmapped = !!au_test_mmapped(file); /* can be harmless race condition */
8149 + wlock = !!(file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
8150 + sb = dentry->d_sb;
8151 + si_read_lock(sb, AuLock_FLUSH);
8152 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, wlock | !mmapped);
8153 + if (unlikely(err))
8157 + struct au_pin pin;
8159 + err = au_ready_to_write(file, -1, &pin);
8160 + di_downgrade_lock(dentry, AuLock_IR);
8161 + if (unlikely(err))
8164 + } else if (!mmapped)
8165 + di_downgrade_lock(dentry, AuLock_IR);
8167 + h_file = au_h_fptr(file, au_fbstart(file));
8168 + if (au_test_fs_bad_mapping(h_file->f_dentry->d_sb)) {
8170 + * by this assignment, f_mapping will differs from aufs inode
8172 + * if someone else mixes the use of f_dentry->d_inode and
8173 + * f_mapping->host, then a problem may arise.
8175 + file->f_mapping = h_file->f_mapping;
8180 + vm_ops = au_vm_ops(h_file, vma);
8181 + err = PTR_ERR(vm_ops);
8182 + if (IS_ERR(vm_ops))
8187 + * unnecessary to handle MAP_DENYWRITE and deny_write_access()?
8188 + * currently MAP_DENYWRITE from userspace is ignored, but elf loader
8189 + * sets it. when FMODE_EXEC is set (by open_exec() or sys_uselib()),
8190 + * both of the aufs file and the lower file is deny_write_access()-ed.
8191 + * finally I hope we can skip handlling MAP_DENYWRITE here.
8193 + err = generic_file_mmap(file, vma);
8194 + if (unlikely(err))
8197 + vma->vm_ops = &aufs_vm_ops;
8199 + if (!au_test_mmapped(file))
8200 + au_fi(file)->fi_h_vm_ops = vm_ops;
8202 + err = au_custom_vm_ops(au_fi(file), vma);
8203 + if (unlikely(err))
8206 + vfsub_file_accessed(h_file);
8207 + fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
8210 + di_read_unlock(dentry, AuLock_IR);
8211 + if (!wlock && mmapped)
8212 + fi_read_unlock(file);
8214 + fi_write_unlock(file);
8216 + si_read_unlock(sb);
8220 +/* ---------------------------------------------------------------------- */
8222 +static int aufs_fsync_nondir(struct file *file, struct dentry *dentry,
8226 + struct au_pin pin;
8227 + struct inode *inode;
8228 + struct file *h_file;
8229 + struct super_block *sb;
8231 + inode = dentry->d_inode;
8232 + IMustLock(file->f_mapping->host);
8233 + if (inode != file->f_mapping->host) {
8234 + mutex_unlock(&file->f_mapping->host->i_mutex);
8235 + mutex_lock(&inode->i_mutex);
8239 + sb = dentry->d_sb;
8240 + si_read_lock(sb, AuLock_FLUSH);
8242 + err = 0; /* -EBADF; */ /* posix? */
8243 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
8245 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
8246 + if (unlikely(err))
8249 + err = au_ready_to_write(file, -1, &pin);
8250 + di_downgrade_lock(dentry, AuLock_IR);
8251 + if (unlikely(err))
8256 + h_file = au_h_fptr(file, au_fbstart(file));
8257 + if (h_file->f_op && h_file->f_op->fsync) {
8258 + struct dentry *h_d;
8259 + struct mutex *h_mtx;
8262 + * no filemap_fdatawrite() since aufs file has no its own
8263 + * mapping, but dir.
8265 + h_d = h_file->f_dentry;
8266 + h_mtx = &h_d->d_inode->i_mutex;
8267 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
8268 + err = h_file->f_op->fsync(h_file, h_d, datasync);
8270 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
8272 + au_cpup_attr_timesizes(inode);
8273 + mutex_unlock(h_mtx);
8277 + di_read_unlock(dentry, AuLock_IR);
8278 + fi_write_unlock(file);
8280 + si_read_unlock(sb);
8281 + if (inode != file->f_mapping->host) {
8282 + mutex_unlock(&inode->i_mutex);
8283 + mutex_lock(&file->f_mapping->host->i_mutex);
8288 +/* no one supports this operation, currently */
8290 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
8293 + struct au_pin pin;
8294 + struct dentry *dentry;
8295 + struct inode *inode;
8296 + struct file *file, *h_file;
8297 + struct super_block *sb;
8299 + file = kio->ki_filp;
8300 + dentry = file->f_dentry;
8301 + inode = dentry->d_inode;
8302 + mutex_lock(&inode->i_mutex);
8304 + sb = dentry->d_sb;
8305 + si_read_lock(sb, AuLock_FLUSH);
8307 + err = 0; /* -EBADF; */ /* posix? */
8308 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
8310 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
8311 + if (unlikely(err))
8314 + err = au_ready_to_write(file, -1, &pin);
8315 + di_downgrade_lock(dentry, AuLock_IR);
8316 + if (unlikely(err))
8321 + h_file = au_h_fptr(file, au_fbstart(file));
8322 + if (h_file->f_op && h_file->f_op->aio_fsync) {
8323 + struct dentry *h_d;
8324 + struct mutex *h_mtx;
8326 + h_d = h_file->f_dentry;
8327 + h_mtx = &h_d->d_inode->i_mutex;
8328 + if (!is_sync_kiocb(kio)) {
8332 + kio->ki_filp = h_file;
8333 + err = h_file->f_op->aio_fsync(kio, datasync);
8334 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
8336 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
8338 + au_cpup_attr_timesizes(inode);
8339 + mutex_unlock(h_mtx);
8343 + di_read_unlock(dentry, AuLock_IR);
8344 + fi_write_unlock(file);
8346 + si_read_unlock(sb);
8347 + mutex_unlock(&inode->i_mutex);
8352 +static int aufs_fasync(int fd, struct file *file, int flag)
8355 + struct file *h_file;
8356 + struct dentry *dentry;
8357 + struct super_block *sb;
8359 + dentry = file->f_dentry;
8360 + sb = dentry->d_sb;
8361 + si_read_lock(sb, AuLock_FLUSH);
8362 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
8363 + if (unlikely(err))
8366 + h_file = au_h_fptr(file, au_fbstart(file));
8367 + if (h_file->f_op && h_file->f_op->fasync)
8368 + err = h_file->f_op->fasync(fd, h_file, flag);
8370 + di_read_unlock(dentry, AuLock_IR);
8371 + fi_read_unlock(file);
8374 + si_read_unlock(sb);
8378 +/* ---------------------------------------------------------------------- */
8380 +/* no one supports this operation, currently */
8382 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
8383 + size_t len, loff_t *pos , int more)
8388 +/* ---------------------------------------------------------------------- */
8390 +const struct file_operations aufs_file_fop = {
8392 + * while generic_file_llseek/_unlocked() don't use BKL,
8393 + * don't use it since it operates file->f_mapping->host.
8394 + * in aufs, it may be a real file and may confuse users by UDBA.
8396 + /* .llseek = generic_file_llseek, */
8398 + .read = aufs_read,
8399 + .write = aufs_write,
8400 + .aio_read = aufs_aio_read,
8401 + .aio_write = aufs_aio_write,
8402 +#ifdef CONFIG_AUFS_POLL
8403 + .poll = aufs_poll,
8405 + .mmap = aufs_mmap,
8406 + .open = aufs_open_nondir,
8407 + .flush = aufs_flush,
8408 + .release = aufs_release_nondir,
8409 + .fsync = aufs_fsync_nondir,
8410 + /* .aio_fsync = aufs_aio_fsync_nondir, */
8411 + .fasync = aufs_fasync,
8412 + /* .sendpage = aufs_sendpage, */
8413 + .splice_write = aufs_splice_write,
8414 + .splice_read = aufs_splice_read,
8416 + .aio_splice_write = aufs_aio_splice_write,
8417 + .aio_splice_read = aufs_aio_splice_read
8420 diff -urN linux-2.6.30.org/fs/aufs/fstype.h linux-2.6.30/fs/aufs/fstype.h
8421 --- linux-2.6.30.org/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
8422 +++ linux-2.6.30/fs/aufs/fstype.h 2009-07-21 08:54:19.000000000 +0200
8425 + * Copyright (C) 2005-2009 Junjiro R. Okajima
8427 + * This program, aufs is free software; you can redistribute it and/or modify
8428 + * it under the terms of the GNU General Public License as published by
8429 + * the Free Software Foundation; either version 2 of the License, or
8430 + * (at your option) any later version.
8432 + * This program is distributed in the hope that it will be useful,
8433 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8434 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8435 + * GNU General Public License for more details.
8437 + * You should have received a copy of the GNU General Public License
8438 + * along with this program; if not, write to the Free Software
8439 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8443 + * judging filesystem type
8446 +#ifndef __AUFS_FSTYPE_H__
8447 +#define __AUFS_FSTYPE_H__
8451 +#include <linux/cramfs_fs.h>
8452 +#include <linux/fs.h>
8453 +#include <linux/magic.h>
8454 +#include <linux/romfs_fs.h>
8455 +#include <linux/aufs_type.h>
8457 +static inline int au_test_aufs(struct super_block *sb)
8459 + return sb->s_magic == AUFS_SUPER_MAGIC;
8462 +static inline const char *au_sbtype(struct super_block *sb)
8464 + return sb->s_type->name;
8467 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
8469 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
8470 + return sb->s_magic == ROMFS_MAGIC;
8476 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
8478 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
8479 + return sb->s_magic == ISOFS_SUPER_MAGIC;
8485 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
8487 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
8488 + return sb->s_magic == CRAMFS_MAGIC;
8493 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
8495 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
8496 + return sb->s_magic == NFS_SUPER_MAGIC;
8502 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
8504 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
8505 + return sb->s_magic == FUSE_SUPER_MAGIC;
8511 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
8513 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
8514 + return sb->s_magic == XFS_SB_MAGIC;
8520 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
8522 +#ifdef CONFIG_TMPFS
8523 + return sb->s_magic == TMPFS_MAGIC;
8529 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
8531 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
8532 + return !strcmp(au_sbtype(sb), "ecryptfs");
8538 +static inline int au_test_smbfs(struct super_block *sb __maybe_unused)
8540 +#if defined(CONFIG_SMB_FS) || defined(CONFIG_SMB_FS_MODULE)
8541 + return sb->s_magic == SMB_SUPER_MAGIC;
8547 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
8549 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
8550 + return sb->s_magic == OCFS2_SUPER_MAGIC;
8556 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
8558 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
8559 + return sb->s_magic == DLMFS_MAGIC;
8565 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
8567 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
8568 + return sb->s_magic == CODA_SUPER_MAGIC;
8574 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
8576 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
8577 + return sb->s_magic == V9FS_MAGIC;
8583 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
8585 +#if defined(CONFIG_EXT4DEV_FS) || defined(CONFIG_EXT4DEV_FS_MODULE)
8586 + return sb->s_magic == EXT4_SUPER_MAGIC;
8592 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
8594 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
8595 + return !strcmp(au_sbtype(sb), "sysv");
8601 +static inline int au_test_ramfs(struct super_block *sb)
8603 + return sb->s_magic == RAMFS_MAGIC;
8606 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
8608 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
8609 + return sb->s_magic == UBIFS_SUPER_MAGIC;
8615 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
8617 +#ifdef CONFIG_PROC_FS
8618 + return sb->s_magic == PROC_SUPER_MAGIC;
8624 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
8626 +#ifdef CONFIG_SYSFS
8627 + return sb->s_magic == SYSFS_MAGIC;
8633 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
8635 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
8636 + return sb->s_magic == CONFIGFS_MAGIC;
8642 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
8644 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
8645 + return sb->s_magic == MINIX3_SUPER_MAGIC
8646 + || sb->s_magic == MINIX2_SUPER_MAGIC
8647 + || sb->s_magic == MINIX2_SUPER_MAGIC2
8648 + || sb->s_magic == MINIX_SUPER_MAGIC
8649 + || sb->s_magic == MINIX_SUPER_MAGIC2;
8655 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
8657 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
8658 + return sb->s_magic == CIFS_MAGIC_NUMBER;
8664 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
8666 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
8667 + return sb->s_magic == MSDOS_SUPER_MAGIC;
8673 +static inline int au_test_msdos(struct super_block *sb)
8675 + return au_test_fat(sb);
8678 +static inline int au_test_vfat(struct super_block *sb)
8680 + return au_test_fat(sb);
8683 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
8685 +#ifdef CONFIG_SECURITYFS
8686 + return sb->s_magic == SECURITYFS_MAGIC;
8692 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
8694 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
8695 + return sb->s_magic == SQUASHFS_MAGIC;
8701 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
8703 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
8704 + return sb->s_magic == BTRFS_SUPER_MAGIC;
8710 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
8712 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
8713 + return sb->s_magic == XENFS_SUPER_MAGIC;
8719 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
8721 +#ifdef CONFIG_DEBUG_FS
8722 + return sb->s_magic == DEBUGFS_MAGIC;
8728 +/* ---------------------------------------------------------------------- */
8730 + * they can't be an aufs branch.
8732 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
8735 +#ifndef CONFIG_AUFS_BR_RAMFS
8736 + au_test_ramfs(sb) ||
8738 + au_test_procfs(sb)
8739 + || au_test_sysfs(sb)
8740 + || au_test_configfs(sb)
8741 + || au_test_debugfs(sb)
8742 + || au_test_securityfs(sb)
8743 + || au_test_xenfs(sb)
8744 + /* || !strcmp(au_sbtype(sb), "unionfs") */
8745 + || au_test_aufs(sb); /* will be supported in next version */
8749 + * If the filesystem supports NFS-export, then it has to support NULL as
8750 + * a nameidata parameter for ->create(), ->lookup() and ->d_revalidate().
8751 + * We can apply this principle when we handle a lower filesystem.
8753 +static inline int au_test_fs_null_nd(struct super_block *sb)
8755 + return !!sb->s_export_op;
8758 +static inline int au_test_fs_remote(struct super_block *sb)
8760 + return !au_test_tmpfs(sb)
8761 +#ifdef CONFIG_AUFS_BR_RAMFS
8762 + && !au_test_ramfs(sb)
8764 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
8767 +/* ---------------------------------------------------------------------- */
8770 + * Note: these functions (below) are created after reading ->getattr() in all
8771 + * filesystems under linux/fs. it means we have to do so in every update...
8775 + * some filesystems require getattr to refresh the inode attributes before
8777 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
8778 + * and leave the work for d_revalidate()
8780 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
8782 + return au_test_nfs(sb)
8783 + || au_test_fuse(sb)
8784 + /* || au_test_smbfs(sb) */ /* untested */
8785 + /* || au_test_ocfs2(sb) */ /* untested */
8786 + /* || au_test_btrfs(sb) */ /* untested */
8787 + /* || au_test_coda(sb) */ /* untested */
8788 + /* || au_test_v9fs(sb) */ /* untested */
8793 + * filesystems which don't maintain i_size or i_blocks.
8795 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
8797 + return au_test_xfs(sb)
8798 + /* || au_test_ext4(sb) */ /* untested */
8799 + /* || au_test_ocfs2(sb) */ /* untested */
8800 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
8801 + /* || au_test_sysv(sb) */ /* untested */
8802 + /* || au_test_ubifs(sb) */ /* untested */
8803 + /* || au_test_minix(sb) */ /* untested */
8808 + * filesystems which don't store the correct value in some of their inode
8811 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
8813 + return au_test_fs_bad_iattr_size(sb)
8814 + /* || au_test_cifs(sb) */ /* untested */
8815 + || au_test_fat(sb)
8816 + || au_test_msdos(sb)
8817 + || au_test_vfat(sb);
8820 +/* they don't check i_nlink in link(2) */
8821 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
8823 + return au_test_tmpfs(sb)
8824 +#ifdef CONFIG_AUFS_BR_RAMFS
8825 + || au_test_ramfs(sb)
8827 + || au_test_ubifs(sb);
8831 + * filesystems which sets S_NOATIME and S_NOCMTIME.
8833 +static inline int au_test_fs_notime(struct super_block *sb)
8835 + return au_test_nfs(sb)
8836 + || au_test_fuse(sb)
8837 + || au_test_ubifs(sb)
8838 + /* || au_test_cifs(sb) */ /* untested */
8843 + * filesystems which requires replacing i_mapping.
8845 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
8847 + return au_test_fuse(sb)
8848 + || au_test_ubifs(sb);
8851 +/* temporary support for i#1 in cramfs */
8852 +static inline int au_test_fs_unique_ino(struct inode *inode)
8854 + if (au_test_cramfs(inode->i_sb))
8855 + return inode->i_ino != 1;
8859 +/* ---------------------------------------------------------------------- */
8862 + * the filesystem where the xino files placed must support i/o after unlink and
8863 + * maintain i_size and i_blocks.
8865 +static inline int au_test_fs_bad_xino(struct super_block *sb)
8867 + return au_test_fs_remote(sb)
8868 + || au_test_fs_bad_iattr_size(sb)
8869 +#ifdef CONFIG_AUFS_BR_RAMFS
8870 + || !(au_test_ramfs(sb) || au_test_fs_null_nd(sb))
8872 + || !au_test_fs_null_nd(sb) /* to keep xino code simple */
8874 + /* don't want unnecessary work for xino */
8875 + || au_test_aufs(sb)
8876 + || au_test_ecryptfs(sb);
8879 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
8881 + return au_test_tmpfs(sb)
8882 + || au_test_ramfs(sb);
8886 + * test if the @sb is real-readonly.
8888 +static inline int au_test_fs_rr(struct super_block *sb)
8890 + return au_test_squashfs(sb)
8891 + || au_test_iso9660(sb)
8892 + || au_test_cramfs(sb)
8893 + || au_test_romfs(sb);
8896 +#endif /* __KERNEL__ */
8897 +#endif /* __AUFS_FSTYPE_H__ */
8898 diff -urN linux-2.6.30.org/fs/aufs/hinotify.c linux-2.6.30/fs/aufs/hinotify.c
8899 --- linux-2.6.30.org/fs/aufs/hinotify.c 1970-01-01 01:00:00.000000000 +0100
8900 +++ linux-2.6.30/fs/aufs/hinotify.c 2009-07-21 08:54:19.000000000 +0200
8903 + * Copyright (C) 2005-2009 Junjiro R. Okajima
8905 + * This program, aufs is free software; you can redistribute it and/or modify
8906 + * it under the terms of the GNU General Public License as published by
8907 + * the Free Software Foundation; either version 2 of the License, or
8908 + * (at your option) any later version.
8910 + * This program is distributed in the hope that it will be useful,
8911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8913 + * GNU General Public License for more details.
8915 + * You should have received a copy of the GNU General Public License
8916 + * along with this program; if not, write to the Free Software
8917 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8921 + * inotify for the lower directories
8926 +static const __u32 AuHinMask = (IN_MOVE | IN_DELETE | IN_CREATE);
8927 +static struct inotify_handle *au_hin_handle;
8929 +AuCacheFuncs(hinotify, HINOTIFY);
8931 +int au_hin_alloc(struct au_hinode *hinode, struct inode *inode,
8932 + struct inode *h_inode)
8935 + struct au_hinotify *hin;
8939 + hin = au_cache_alloc_hinotify();
8941 + AuDebugOn(hinode->hi_notify);
8942 + hinode->hi_notify = hin;
8943 + hin->hin_aufs_inode = inode;
8945 + inotify_init_watch(&hin->hin_watch);
8946 + wd = inotify_add_watch(au_hin_handle, &hin->hin_watch, h_inode,
8949 + return 0; /* success */
8952 + put_inotify_watch(&hin->hin_watch);
8953 + au_cache_free_hinotify(hin);
8954 + hinode->hi_notify = NULL;
8960 +void au_hin_free(struct au_hinode *hinode)
8963 + struct au_hinotify *hin;
8965 + hin = hinode->hi_notify;
8968 + if (atomic_read(&hin->hin_watch.count))
8969 + err = inotify_rm_watch(au_hin_handle, &hin->hin_watch);
8970 + if (unlikely(err))
8971 + /* it means the watch is already removed */
8972 + AuWarn("failed inotify_rm_watch() %d\n", err);
8973 + au_cache_free_hinotify(hin);
8974 + hinode->hi_notify = NULL;
8978 +/* ---------------------------------------------------------------------- */
8980 +void au_hin_ctl(struct au_hinode *hinode, int do_set)
8982 + struct inode *h_inode;
8983 + struct inotify_watch *watch;
8985 + if (!hinode->hi_notify)
8988 + h_inode = hinode->hi_inode;
8989 + IMustLock(h_inode);
8991 + /* todo: try inotify_find_update_watch()? */
8992 + watch = &hinode->hi_notify->hin_watch;
8993 + mutex_lock(&h_inode->inotify_mutex);
8994 + /* mutex_lock(&watch->ih->mutex); */
8996 + AuDebugOn(watch->mask & AuHinMask);
8997 + watch->mask |= AuHinMask;
8999 + AuDebugOn(!(watch->mask & AuHinMask));
9000 + watch->mask &= ~AuHinMask;
9002 + /* mutex_unlock(&watch->ih->mutex); */
9003 + mutex_unlock(&h_inode->inotify_mutex);
9006 +void au_reset_hinotify(struct inode *inode, unsigned int flags)
9008 + aufs_bindex_t bindex, bend;
9010 + struct dentry *iwhdentry;
9012 + bend = au_ibend(inode);
9013 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
9014 + hi = au_h_iptr(inode, bindex);
9018 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
9019 + iwhdentry = au_hi_wh(inode, bindex);
9023 + au_set_h_iptr(inode, bindex, NULL, 0);
9024 + au_set_h_iptr(inode, bindex, au_igrab(hi),
9025 + flags & ~AuHi_XINO);
9028 + /* mutex_unlock(&hi->i_mutex); */
9032 +/* ---------------------------------------------------------------------- */
9034 +static int hin_xino(struct inode *inode, struct inode *h_inode)
9037 + aufs_bindex_t bindex, bend, bfound, bstart;
9038 + struct inode *h_i;
9041 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
9042 + AuWarn("branch root dir was changed\n");
9047 + bend = au_ibend(inode);
9048 + bstart = au_ibstart(inode);
9049 +#if 0 /* reserved for future use */
9050 + if (bindex == bend) {
9051 + /* keep this ino in rename case */
9055 + for (bindex = bstart; bindex <= bend; bindex++) {
9056 + if (au_h_iptr(inode, bindex) == h_inode) {
9064 + for (bindex = bstart; bindex <= bend; bindex++) {
9065 + h_i = au_h_iptr(inode, bindex);
9069 + err = au_xino_write0(inode->i_sb, bindex, h_i->i_ino, 0);
9070 + /* ignore this error */
9074 + /* children inode number will be broken */
9081 +static int hin_gen_tree(struct dentry *dentry)
9083 + int err, i, j, ndentry;
9084 + struct au_dcsub_pages dpages;
9085 + struct au_dpage *dpage;
9086 + struct dentry **dentries;
9088 + err = au_dpages_init(&dpages, GFP_NOFS);
9089 + if (unlikely(err))
9091 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
9092 + if (unlikely(err))
9095 + for (i = 0; i < dpages.ndpage; i++) {
9096 + dpage = dpages.dpages + i;
9097 + dentries = dpage->dentries;
9098 + ndentry = dpage->ndentry;
9099 + for (j = 0; j < ndentry; j++) {
9109 + /* todo: reset children xino?
9110 + cached children only? */
9111 + au_iigen_dec(d->d_inode);
9116 + au_dpages_free(&dpages);
9118 + /* discard children */
9119 + dentry_unhash(dentry);
9126 + * return 0 if processed.
9128 +static int hin_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
9129 + const unsigned int isdir)
9133 + struct qstr *dname;
9136 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
9137 + AuWarn("branch root dir was changed\n");
9144 + au_iigen_dec(inode);
9145 + spin_lock(&dcache_lock);
9146 + list_for_each_entry(d, &inode->i_dentry, d_alias) {
9147 + dname = &d->d_name;
9148 + if (dname->len != nlen
9149 + && memcmp(dname->name, name, nlen))
9152 + spin_lock(&d->d_lock);
9155 + spin_unlock(&d->d_lock);
9158 + spin_unlock(&dcache_lock);
9160 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIRS);
9161 + d = d_find_alias(inode);
9163 + au_iigen_dec(inode);
9167 + dname = &d->d_name;
9168 + if (dname->len == nlen && !memcmp(dname->name, name, nlen))
9169 + err = hin_gen_tree(d);
9178 +static int hin_gen_by_name(struct dentry *dentry, const unsigned int isdir)
9181 + struct inode *inode;
9183 + inode = dentry->d_inode;
9184 + if (IS_ROOT(dentry)
9185 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
9187 + AuWarn("branch root dir was changed\n");
9194 + au_digen_dec(dentry);
9196 + au_iigen_dec(inode);
9198 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIRS);
9200 + err = hin_gen_tree(dentry);
9207 +/* ---------------------------------------------------------------------- */
9209 +/* hinotify job flags */
9210 +#define AuHinJob_XINO0 1
9211 +#define AuHinJob_GEN (1 << 1)
9212 +#define AuHinJob_DIRENT (1 << 2)
9213 +#define AuHinJob_ISDIR (1 << 3)
9214 +#define AuHinJob_TRYXINO0 (1 << 4)
9215 +#define AuHinJob_MNTPNT (1 << 5)
9216 +#define au_ftest_hinjob(flags, name) ((flags) & AuHinJob_##name)
9217 +#define au_fset_hinjob(flags, name) { (flags) |= AuHinJob_##name; }
9218 +#define au_fclr_hinjob(flags, name) { (flags) &= ~AuHinJob_##name; }
9220 +struct hin_job_args {
9221 + unsigned int flags;
9222 + struct inode *inode, *h_inode, *dir, *h_dir;
9223 + struct dentry *dentry;
9228 +static int hin_job(struct hin_job_args *a)
9230 + const unsigned int isdir = au_ftest_hinjob(a->flags, ISDIR);
9233 + if (au_ftest_hinjob(a->flags, XINO0) && a->inode)
9234 + hin_xino(a->inode, a->h_inode); /* ignore this error */
9236 + if (au_ftest_hinjob(a->flags, TRYXINO0)
9239 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
9240 + if (!a->h_inode->i_nlink)
9241 + hin_xino(a->inode, a->h_inode); /* ignore this error */
9242 + mutex_unlock(&a->h_inode->i_mutex);
9245 + /* make the generation obsolete */
9246 + if (au_ftest_hinjob(a->flags, GEN)) {
9249 + err = hin_gen_by_inode(a->h_name, a->h_nlen, a->inode,
9251 + if (err && a->dentry)
9252 + hin_gen_by_name(a->dentry, isdir);
9253 + /* ignore this error */
9256 + /* make dir entries obsolete */
9257 + if (au_ftest_hinjob(a->flags, DIRENT) && a->inode) {
9258 + struct au_vdir *vdir;
9260 + vdir = au_ivdir(a->inode);
9262 + vdir->vd_jiffy = 0;
9263 + /* IMustLock(a->inode); */
9264 + /* a->inode->i_version++; */
9267 + /* can do nothing but warn */
9268 + if (au_ftest_hinjob(a->flags, MNTPNT)
9270 + && d_mountpoint(a->dentry))
9271 + AuWarn("mount-point %.*s is removed or renamed\n",
9272 + AuDLNPair(a->dentry));
9277 +/* ---------------------------------------------------------------------- */
9279 +static char *in_name(u32 mask)
9281 +#ifdef CONFIG_AUFS_DEBUG
9282 +#define test_ret(flag) if (mask & flag) \
9284 + test_ret(IN_ACCESS);
9285 + test_ret(IN_MODIFY);
9286 + test_ret(IN_ATTRIB);
9287 + test_ret(IN_CLOSE_WRITE);
9288 + test_ret(IN_CLOSE_NOWRITE);
9289 + test_ret(IN_OPEN);
9290 + test_ret(IN_MOVED_FROM);
9291 + test_ret(IN_MOVED_TO);
9292 + test_ret(IN_CREATE);
9293 + test_ret(IN_DELETE);
9294 + test_ret(IN_DELETE_SELF);
9295 + test_ret(IN_MOVE_SELF);
9296 + test_ret(IN_UNMOUNT);
9297 + test_ret(IN_Q_OVERFLOW);
9298 + test_ret(IN_IGNORED);
9306 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
9307 + struct inode *dir)
9309 + struct dentry *dentry, *d, *parent;
9310 + struct qstr *dname;
9312 + parent = d_find_alias(dir);
9317 + spin_lock(&dcache_lock);
9318 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
9319 + /* AuDbg("%.*s\n", AuDLNPair(d)); */
9320 + dname = &d->d_name;
9321 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
9323 + if (!atomic_read(&d->d_count) || !d->d_fsdata) {
9324 + spin_lock(&d->d_lock);
9326 + spin_unlock(&d->d_lock);
9333 + spin_unlock(&dcache_lock);
9337 + di_write_lock_child(dentry);
9342 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
9343 + aufs_bindex_t bindex, ino_t h_ino)
9345 + struct inode *inode;
9350 + err = au_xino_read(sb, bindex, h_ino, &ino);
9352 + inode = ilookup(sb, ino);
9356 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
9357 + AuWarn("wrong root branch\n");
9363 + ii_write_lock_child(inode);
9369 +enum { CHILD, PARENT };
9370 +struct postproc_args {
9371 + struct inode *h_dir, *dir, *h_child_inode;
9373 + unsigned int flags[2];
9374 + unsigned int h_child_nlen;
9375 + char h_child_name[];
9378 +static void postproc(void *_args)
9380 + struct postproc_args *a = _args;
9381 + struct super_block *sb;
9382 + aufs_bindex_t bindex, bend, bfound;
9383 + unsigned char xino, try_iput;
9385 + struct inode *inode;
9387 + struct hin_job_args args;
9388 + struct dentry *dentry;
9389 + struct au_sbinfo *sbinfo;
9391 + AuDebugOn(!_args);
9392 + AuDebugOn(!a->h_dir);
9393 + AuDebugOn(!a->dir);
9394 + AuDebugOn(!a->mask);
9395 + AuDbg("mask 0x%x %s, i%lu, hi%lu, hci%lu\n",
9396 + a->mask, in_name(a->mask), a->dir->i_ino, a->h_dir->i_ino,
9397 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
9402 + * do not lock a->dir->i_mutex here
9403 + * because of d_revalidate() may cause a deadlock.
9405 + sb = a->dir->i_sb;
9407 + sbinfo = au_sbi(sb);
9408 + AuDebugOn(!sbinfo);
9409 + /* big aufs lock */
9410 + si_noflush_write_lock(sb);
9412 + ii_read_lock_parent(a->dir);
9414 + bend = au_ibend(a->dir);
9415 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
9416 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
9420 + ii_read_unlock(a->dir);
9421 + if (unlikely(bfound < 0))
9424 + xino = !!au_opt_test(au_mntflags(sb), XINO);
9426 + if (a->h_child_inode)
9427 + h_ino = a->h_child_inode->i_ino;
9429 + if (a->h_child_nlen
9430 + && (au_ftest_hinjob(a->flags[CHILD], GEN)
9431 + || au_ftest_hinjob(a->flags[CHILD], MNTPNT)))
9432 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
9436 + inode = dentry->d_inode;
9437 + if (xino && !inode && h_ino
9438 + && (au_ftest_hinjob(a->flags[CHILD], XINO0)
9439 + || au_ftest_hinjob(a->flags[CHILD], TRYXINO0)
9440 + || au_ftest_hinjob(a->flags[CHILD], GEN))) {
9441 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
9445 + args.flags = a->flags[CHILD];
9446 + args.dentry = dentry;
9447 + args.inode = inode;
9448 + args.h_inode = a->h_child_inode;
9449 + args.dir = a->dir;
9450 + args.h_dir = a->h_dir;
9451 + args.h_name = a->h_child_name;
9452 + args.h_nlen = a->h_child_nlen;
9453 + err = hin_job(&args);
9455 + if (dentry->d_fsdata)
9456 + di_write_unlock(dentry);
9459 + if (inode && try_iput) {
9460 + ii_write_unlock(inode);
9464 + ii_write_lock_parent(a->dir);
9465 + args.flags = a->flags[PARENT];
9466 + args.dentry = NULL;
9467 + args.inode = a->dir;
9468 + args.h_inode = a->h_dir;
9470 + args.h_dir = NULL;
9471 + args.h_name = NULL;
9473 + err = hin_job(&args);
9474 + ii_write_unlock(a->dir);
9477 + au_nwt_done(&sbinfo->si_nowait);
9478 + si_write_unlock(sb);
9480 + iput(a->h_child_inode);
9486 +/* ---------------------------------------------------------------------- */
9488 +static void aufs_inotify(struct inotify_watch *watch, u32 wd __maybe_unused,
9489 + u32 mask, u32 cookie __maybe_unused,
9490 + const char *h_child_name, struct inode *h_child_inode)
9492 + struct au_hinotify *hinotify;
9493 + struct postproc_args *args;
9495 + unsigned char isdir, isroot, wh;
9497 + struct inode *dir;
9498 + unsigned int flags[2];
9500 + /* if IN_UNMOUNT happens, there must be another bug */
9501 + AuDebugOn(mask & IN_UNMOUNT);
9502 + if (mask & (IN_IGNORED | IN_UNMOUNT)) {
9503 + put_inotify_watch(watch);
9506 +#ifdef AuDbgHinotify
9508 + if (1 || !h_child_name || strcmp(h_child_name, AUFS_XINO_FNAME)) {
9509 + AuDbg("i%lu, wd %d, mask 0x%x %s, cookie 0x%x, hcname %s,"
9511 + watch->inode->i_ino, wd, mask, in_name(mask), cookie,
9512 + h_child_name ? h_child_name : "",
9513 + h_child_inode ? h_child_inode->i_ino : 0);
9519 + hinotify = container_of(watch, struct au_hinotify, hin_watch);
9520 + AuDebugOn(!hinotify || !hinotify->hin_aufs_inode);
9521 + dir = igrab(hinotify->hin_aufs_inode);
9525 + isroot = (dir->i_ino == AUFS_ROOT_INO);
9528 + if (h_child_name) {
9529 + len = strlen(h_child_name);
9530 + if (!memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9531 + h_child_name += AUFS_WH_PFX_LEN;
9532 + len -= AUFS_WH_PFX_LEN;
9538 + if (h_child_inode)
9539 + isdir = !!S_ISDIR(h_child_inode->i_mode);
9540 + flags[PARENT] = AuHinJob_ISDIR;
9543 + flags[CHILD] = AuHinJob_ISDIR;
9544 + switch (mask & IN_ALL_EVENTS) {
9545 + case IN_MOVED_FROM:
9547 + AuDebugOn(!h_child_name || !h_child_inode);
9548 + au_fset_hinjob(flags[CHILD], GEN);
9549 + au_fset_hinjob(flags[CHILD], XINO0);
9550 + au_fset_hinjob(flags[CHILD], MNTPNT);
9551 + au_fset_hinjob(flags[PARENT], DIRENT);
9555 + AuDebugOn(!h_child_name || !h_child_inode);
9556 + au_fset_hinjob(flags[PARENT], DIRENT);
9557 + au_fset_hinjob(flags[CHILD], GEN);
9562 + * aufs never be able to get this child inode.
9563 + * revalidation should be in d_revalidate()
9564 + * by checking i_nlink, i_generation or d_unhashed().
9566 + AuDebugOn(!h_child_name);
9567 + au_fset_hinjob(flags[PARENT], DIRENT);
9568 + au_fset_hinjob(flags[CHILD], GEN);
9569 + au_fset_hinjob(flags[CHILD], TRYXINO0);
9570 + au_fset_hinjob(flags[CHILD], MNTPNT);
9578 + h_child_inode = NULL;
9580 + /* iput() and kfree() will be called in postproc() */
9582 + * inotify_mutex is already acquired and kmalloc/prune_icache may lock
9583 + * iprune_mutex. strange.
9586 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
9588 + if (unlikely(!args)) {
9589 + AuErr1("no memory\n");
9593 + args->flags[PARENT] = flags[PARENT];
9594 + args->flags[CHILD] = flags[CHILD];
9595 + args->mask = mask;
9597 + args->h_dir = igrab(watch->inode);
9598 + if (h_child_inode)
9599 + h_child_inode = igrab(h_child_inode); /* can be NULL */
9600 + args->h_child_inode = h_child_inode;
9601 + args->h_child_nlen = len;
9604 + p += sizeof(*args);
9605 + memcpy(p, h_child_name, len + 1);
9609 + wkq_err = au_wkq_nowait(postproc, args, dir->i_sb);
9611 + if (unlikely(wkq_err))
9612 + AuErr("wkq %d\n", wkq_err);
9615 +static void aufs_inotify_destroy(struct inotify_watch *watch __maybe_unused)
9620 +static struct inotify_operations aufs_inotify_ops = {
9621 + .handle_event = aufs_inotify,
9622 + .destroy_watch = aufs_inotify_destroy
9625 +/* ---------------------------------------------------------------------- */
9627 +static void au_hin_destroy_cache(void)
9629 + kmem_cache_destroy(au_cachep[AuCache_HINOTIFY]);
9630 + au_cachep[AuCache_HINOTIFY] = NULL;
9633 +int __init au_hinotify_init(void)
9638 + au_cachep[AuCache_HINOTIFY] = AuCache(au_hinotify);
9639 + if (au_cachep[AuCache_HINOTIFY]) {
9641 + au_hin_handle = inotify_init(&aufs_inotify_ops);
9642 + if (IS_ERR(au_hin_handle)) {
9643 + err = PTR_ERR(au_hin_handle);
9644 + au_hin_destroy_cache();
9651 +void au_hinotify_fin(void)
9653 + inotify_destroy(au_hin_handle);
9654 + if (au_cachep[AuCache_HINOTIFY])
9655 + au_hin_destroy_cache();
9657 diff -urN linux-2.6.30.org/fs/aufs/iinfo.c linux-2.6.30/fs/aufs/iinfo.c
9658 --- linux-2.6.30.org/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
9659 +++ linux-2.6.30/fs/aufs/iinfo.c 2009-07-21 08:54:19.000000000 +0200
9662 + * Copyright (C) 2005-2009 Junjiro R. Okajima
9664 + * This program, aufs is free software; you can redistribute it and/or modify
9665 + * it under the terms of the GNU General Public License as published by
9666 + * the Free Software Foundation; either version 2 of the License, or
9667 + * (at your option) any later version.
9669 + * This program is distributed in the hope that it will be useful,
9670 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9671 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9672 + * GNU General Public License for more details.
9674 + * You should have received a copy of the GNU General Public License
9675 + * along with this program; if not, write to the Free Software
9676 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9680 + * inode private data
9685 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
9687 + struct inode *h_inode;
9689 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
9690 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
9694 +/* todo: hard/soft set? */
9695 +void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
9697 + struct au_iinfo *iinfo = au_ii(inode);
9698 + struct inode *h_inode;
9700 + iinfo->ii_bstart = bindex;
9701 + h_inode = iinfo->ii_hinode[bindex + 0].hi_inode;
9703 + au_cpup_igen(inode, h_inode);
9706 +void au_hiput(struct au_hinode *hinode)
9708 + au_hin_free(hinode);
9709 + dput(hinode->hi_whdentry);
9710 + iput(hinode->hi_inode);
9713 +unsigned int au_hi_flags(struct inode *inode, int isdir)
9715 + unsigned int flags;
9716 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
9719 + if (au_opt_test(mnt_flags, XINO))
9720 + au_fset_hi(flags, XINO);
9721 + if (isdir && au_opt_test(mnt_flags, UDBA_HINOTIFY))
9722 + au_fset_hi(flags, HINOTIFY);
9726 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
9727 + struct inode *h_inode, unsigned int flags)
9729 + struct au_hinode *hinode;
9731 + struct au_iinfo *iinfo = au_ii(inode);
9733 + hinode = iinfo->ii_hinode + bindex;
9734 + hi = hinode->hi_inode;
9735 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
9736 + AuDebugOn(h_inode && hi);
9740 + hinode->hi_inode = h_inode;
9743 + struct super_block *sb = inode->i_sb;
9744 + struct au_branch *br;
9746 + if (bindex == iinfo->ii_bstart)
9747 + au_cpup_igen(inode, h_inode);
9748 + br = au_sbr(sb, bindex);
9749 + hinode->hi_id = br->br_id;
9750 + if (au_ftest_hi(flags, XINO)) {
9751 + err = au_xino_write(sb, bindex, h_inode->i_ino,
9753 + if (unlikely(err))
9754 + AuIOErr1("failed au_xino_write() %d\n", err);
9757 + if (au_ftest_hi(flags, HINOTIFY)
9758 + && au_br_hinotifyable(br->br_perm)) {
9759 + err = au_hin_alloc(hinode, inode, h_inode);
9760 + if (unlikely(err))
9761 + AuIOErr1("au_hin_alloc() %d\n", err);
9766 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
9767 + struct dentry *h_wh)
9769 + struct au_hinode *hinode;
9771 + hinode = au_ii(inode)->ii_hinode + bindex;
9772 + AuDebugOn(hinode->hi_whdentry);
9773 + hinode->hi_whdentry = h_wh;
9776 +void au_update_iigen(struct inode *inode)
9778 + atomic_set(&au_ii(inode)->ii_generation, au_sigen(inode->i_sb));
9779 + /* smp_mb(); */ /* atomic_set */
9782 +/* it may be called at remount time, too */
9783 +void au_update_brange(struct inode *inode, int do_put_zero)
9785 + struct au_iinfo *iinfo;
9787 + iinfo = au_ii(inode);
9788 + if (!iinfo || iinfo->ii_bstart < 0)
9791 + if (do_put_zero) {
9792 + aufs_bindex_t bindex;
9794 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
9796 + struct inode *h_i;
9798 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
9799 + if (h_i && !h_i->i_nlink)
9800 + au_set_h_iptr(inode, bindex, NULL, 0);
9804 + iinfo->ii_bstart = -1;
9805 + while (++iinfo->ii_bstart <= iinfo->ii_bend)
9806 + if (iinfo->ii_hinode[0 + iinfo->ii_bstart].hi_inode)
9808 + if (iinfo->ii_bstart > iinfo->ii_bend) {
9809 + iinfo->ii_bstart = -1;
9810 + iinfo->ii_bend = -1;
9815 + while (0 <= --iinfo->ii_bend)
9816 + if (iinfo->ii_hinode[0 + iinfo->ii_bend].hi_inode)
9818 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend || iinfo->ii_bend < 0);
9821 +/* ---------------------------------------------------------------------- */
9823 +int au_iinfo_init(struct inode *inode)
9825 + struct au_iinfo *iinfo;
9826 + struct super_block *sb;
9830 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
9831 + nbr = au_sbend(sb) + 1;
9832 + if (unlikely(nbr <= 0))
9834 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
9835 + if (iinfo->ii_hinode) {
9836 + for (i = 0; i < nbr; i++)
9837 + iinfo->ii_hinode[i].hi_id = -1;
9839 + atomic_set(&iinfo->ii_generation, au_sigen(sb));
9840 + /* smp_mb(); */ /* atomic_set */
9841 + au_rw_init(&iinfo->ii_rwsem);
9842 + iinfo->ii_bstart = -1;
9843 + iinfo->ii_bend = -1;
9844 + iinfo->ii_vdir = NULL;
9850 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
9853 + struct au_hinode *hip;
9856 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
9858 + sz = sizeof(*hip);
9859 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
9861 + iinfo->ii_hinode = hip;
9868 +static int au_iinfo_write0(struct super_block *sb, struct au_hinode *hinode,
9872 + aufs_bindex_t bindex;
9873 + unsigned char locked;
9876 + locked = !!si_noflush_read_trylock(sb);
9877 + bindex = au_br_index(sb, hinode->hi_id);
9879 + err = au_xino_write0(sb, bindex, hinode->hi_inode->i_ino, ino);
9880 + /* error action? */
9882 + si_read_unlock(sb);
9886 +void au_iinfo_fin(struct inode *inode)
9889 + aufs_bindex_t bend;
9890 + unsigned char unlinked = !inode->i_nlink;
9891 + struct au_iinfo *iinfo;
9892 + struct au_hinode *hi;
9893 + struct super_block *sb;
9896 + int err = au_xigen_inc(inode);
9897 + if (unlikely(err))
9898 + AuWarn1("failed resetting i_generation, %d\n", err);
9901 + iinfo = au_ii(inode);
9902 + /* bad_inode case */
9906 + if (iinfo->ii_vdir)
9907 + au_vdir_free(iinfo->ii_vdir);
9909 + if (iinfo->ii_bstart >= 0) {
9913 + ino = inode->i_ino;
9914 + hi = iinfo->ii_hinode + iinfo->ii_bstart;
9915 + bend = iinfo->ii_bend;
9916 + while (iinfo->ii_bstart++ <= bend) {
9917 + if (hi->hi_inode) {
9918 + if (unlinked || !hi->hi_inode->i_nlink) {
9919 + au_iinfo_write0(sb, hi, ino);
9920 + /* ignore this error */
9929 + kfree(iinfo->ii_hinode);
9930 + AuRwDestroy(&iinfo->ii_rwsem);
9932 diff -urN linux-2.6.30.org/fs/aufs/inode.c linux-2.6.30/fs/aufs/inode.c
9933 --- linux-2.6.30.org/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
9934 +++ linux-2.6.30/fs/aufs/inode.c 2009-07-21 08:54:19.000000000 +0200
9937 + * Copyright (C) 2005-2009 Junjiro R. Okajima
9939 + * This program, aufs is free software; you can redistribute it and/or modify
9940 + * it under the terms of the GNU General Public License as published by
9941 + * the Free Software Foundation; either version 2 of the License, or
9942 + * (at your option) any later version.
9944 + * This program is distributed in the hope that it will be useful,
9945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9947 + * GNU General Public License for more details.
9949 + * You should have received a copy of the GNU General Public License
9950 + * along with this program; if not, write to the Free Software
9951 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9960 +struct inode *au_igrab(struct inode *inode)
9963 + AuDebugOn(!atomic_read(&inode->i_count));
9964 + atomic_inc_return(&inode->i_count);
9969 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
9971 + au_cpup_attr_all(inode, /*force*/0);
9972 + au_update_iigen(inode);
9974 + inode->i_version++;
9977 +int au_refresh_hinode_self(struct inode *inode, int do_attr)
9980 + aufs_bindex_t bindex, new_bindex;
9981 + unsigned char update;
9982 + struct inode *first;
9983 + struct au_hinode *p, *q, tmp;
9984 + struct super_block *sb;
9985 + struct au_iinfo *iinfo;
9989 + iinfo = au_ii(inode);
9990 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
9991 + if (unlikely(err))
9994 + p = iinfo->ii_hinode + iinfo->ii_bstart;
9995 + first = p->hi_inode;
9997 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
10002 + new_bindex = au_br_index(sb, p->hi_id);
10003 + if (new_bindex == bindex)
10006 + if (new_bindex < 0) {
10009 + p->hi_inode = NULL;
10013 + if (new_bindex < iinfo->ii_bstart)
10014 + iinfo->ii_bstart = new_bindex;
10015 + if (iinfo->ii_bend < new_bindex)
10016 + iinfo->ii_bend = new_bindex;
10017 + /* swap two lower inode, and loop again */
10018 + q = iinfo->ii_hinode + new_bindex;
10022 + if (tmp.hi_inode) {
10027 + au_update_brange(inode, /*do_put_zero*/0);
10029 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
10035 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
10038 + unsigned int flags;
10039 + aufs_bindex_t bindex, bend;
10040 + unsigned char isdir;
10041 + struct inode *first;
10042 + struct au_hinode *p;
10043 + struct au_iinfo *iinfo;
10045 + err = au_refresh_hinode_self(inode, /*do_attr*/0);
10046 + if (unlikely(err))
10050 + iinfo = au_ii(inode);
10051 + p = iinfo->ii_hinode + iinfo->ii_bstart;
10052 + first = p->hi_inode;
10053 + isdir = S_ISDIR(inode->i_mode);
10054 + flags = au_hi_flags(inode, isdir);
10055 + bend = au_dbend(dentry);
10056 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
10057 + struct inode *h_i;
10058 + struct dentry *h_d;
10060 + h_d = au_h_dptr(dentry, bindex);
10061 + if (!h_d || !h_d->d_inode)
10064 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
10065 + h_i = au_h_iptr(inode, bindex);
10067 + if (h_i == h_d->d_inode)
10073 + if (bindex < iinfo->ii_bstart)
10074 + iinfo->ii_bstart = bindex;
10075 + if (iinfo->ii_bend < bindex)
10076 + iinfo->ii_bend = bindex;
10077 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
10080 + au_update_brange(inode, /*do_put_zero*/0);
10082 + if (unlikely(err))
10085 + au_refresh_hinode_attr(inode, update && isdir);
10091 +static int set_inode(struct inode *inode, struct dentry *dentry)
10094 + unsigned int flags;
10096 + aufs_bindex_t bindex, bstart, btail;
10097 + unsigned char isdir;
10098 + struct dentry *h_dentry;
10099 + struct inode *h_inode;
10100 + struct au_iinfo *iinfo;
10104 + bstart = au_dbstart(dentry);
10105 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
10106 + mode = h_inode->i_mode;
10107 + switch (mode & S_IFMT) {
10109 + btail = au_dbtail(dentry);
10110 + inode->i_op = &aufs_iop;
10111 + inode->i_fop = &aufs_file_fop;
10112 + inode->i_mapping->a_ops = &aufs_aop;
10116 + btail = au_dbtaildir(dentry);
10117 + inode->i_op = &aufs_dir_iop;
10118 + inode->i_fop = &aufs_dir_fop;
10121 + btail = au_dbtail(dentry);
10122 + inode->i_op = &aufs_symlink_iop;
10128 + btail = au_dbtail(dentry);
10129 + inode->i_op = &aufs_iop;
10130 + init_special_inode(inode, mode, h_inode->i_rdev);
10133 + AuIOErr("Unknown file type 0%o\n", mode);
10138 + /* do not set inotify for whiteouted dirs (SHWH mode) */
10139 + flags = au_hi_flags(inode, isdir);
10140 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
10141 + && au_ftest_hi(flags, HINOTIFY)
10142 + && dentry->d_name.len > AUFS_WH_PFX_LEN
10143 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
10144 + au_fclr_hi(flags, HINOTIFY);
10145 + iinfo = au_ii(inode);
10146 + iinfo->ii_bstart = bstart;
10147 + iinfo->ii_bend = btail;
10148 + for (bindex = bstart; bindex <= btail; bindex++) {
10149 + h_dentry = au_h_dptr(dentry, bindex);
10151 + au_set_h_iptr(inode, bindex,
10152 + au_igrab(h_dentry->d_inode), flags);
10154 + au_cpup_attr_all(inode, /*force*/1);
10160 +/* successful returns with iinfo write_locked */
10161 +static int reval_inode(struct inode *inode, struct dentry *dentry, int *matched)
10164 + aufs_bindex_t bindex, bend;
10165 + struct inode *h_inode, *h_dinode;
10170 + * before this function, if aufs got any iinfo lock, it must be only
10171 + * one, the parent dir.
10172 + * it can happen by UDBA and the obsoleted inode number.
10175 + if (unlikely(inode->i_ino == parent_ino(dentry)))
10179 + ii_write_lock_new_child(inode);
10180 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
10181 + bend = au_ibend(inode);
10182 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
10183 + h_inode = au_h_iptr(inode, bindex);
10184 + if (h_inode && h_inode == h_dinode) {
10187 + if (au_iigen(inode) != au_digen(dentry))
10188 + err = au_refresh_hinode(inode, dentry);
10193 + if (unlikely(err))
10194 + ii_write_unlock(inode);
10199 +/* successful returns with iinfo write_locked */
10200 +/* todo: return with unlocked? */
10201 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
10203 + struct inode *inode;
10204 + struct dentry *h_dentry;
10205 + struct super_block *sb;
10206 + ino_t h_ino, ino;
10208 + aufs_bindex_t bstart;
10210 + sb = dentry->d_sb;
10211 + bstart = au_dbstart(dentry);
10212 + h_dentry = au_h_dptr(dentry, bstart);
10213 + h_ino = h_dentry->d_inode->i_ino;
10214 + err = au_xino_read(sb, bstart, h_ino, &ino);
10215 + inode = ERR_PTR(err);
10216 + if (unlikely(err))
10220 + ino = au_xino_new_ino(sb);
10221 + if (unlikely(!ino)) {
10222 + inode = ERR_PTR(-EIO);
10227 + AuDbg("i%lu\n", (unsigned long)ino);
10228 + inode = au_iget_locked(sb, ino);
10229 + err = PTR_ERR(inode);
10230 + if (IS_ERR(inode))
10233 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
10234 + if (inode->i_state & I_NEW) {
10235 + ii_write_lock_new_child(inode);
10236 + err = set_inode(inode, dentry);
10237 + unlock_new_inode(inode);
10239 + goto out; /* success */
10241 + iget_failed(inode);
10242 + ii_write_unlock(inode);
10244 + } else if (!must_new) {
10245 + err = reval_inode(inode, dentry, &match);
10247 + goto out; /* success */
10252 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
10253 + AuWarn1("Un-notified UDBA or repeatedly renamed dir,"
10254 + " b%d, %s, %.*s, hi%lu, i%lu.\n",
10255 + bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
10256 + (unsigned long)h_ino, (unsigned long)ino);
10258 + err = au_xino_write0(sb, bstart, h_ino, 0);
10266 + inode = ERR_PTR(err);
10271 +/* ---------------------------------------------------------------------- */
10273 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
10274 + struct inode *inode)
10278 + err = au_br_rdonly(au_sbr(sb, bindex));
10280 + /* pseudo-link after flushed may happen out of bounds */
10283 + && au_ibstart(inode) <= bindex
10284 + && bindex <= au_ibend(inode)) {
10286 + * permission check is unnecessary since vfsub routine
10287 + * will be called later
10289 + struct inode *hi = au_h_iptr(inode, bindex);
10291 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
10297 +int au_test_h_perm(struct inode *h_inode, int mask)
10299 + if (!current_fsuid())
10301 + return inode_permission(h_inode, mask);
10304 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
10306 + if (au_test_nfs(h_inode->i_sb)
10307 + && (mask & MAY_WRITE)
10308 + && S_ISDIR(h_inode->i_mode))
10309 + mask |= MAY_READ; /* force permission check */
10310 + return au_test_h_perm(h_inode, mask);
10312 diff -urN linux-2.6.30.org/fs/aufs/inode.h linux-2.6.30/fs/aufs/inode.h
10313 --- linux-2.6.30.org/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
10314 +++ linux-2.6.30/fs/aufs/inode.h 2009-07-21 08:54:19.000000000 +0200
10317 + * Copyright (C) 2005-2009 Junjiro R. Okajima
10319 + * This program, aufs is free software; you can redistribute it and/or modify
10320 + * it under the terms of the GNU General Public License as published by
10321 + * the Free Software Foundation; either version 2 of the License, or
10322 + * (at your option) any later version.
10324 + * This program is distributed in the hope that it will be useful,
10325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10327 + * GNU General Public License for more details.
10329 + * You should have received a copy of the GNU General Public License
10330 + * along with this program; if not, write to the Free Software
10331 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10335 + * inode operations
10338 +#ifndef __AUFS_INODE_H__
10339 +#define __AUFS_INODE_H__
10343 +#include <linux/fs.h>
10344 +#include <linux/inotify.h>
10345 +#include <linux/aufs_type.h>
10346 +#include "rwsem.h"
10350 +struct au_hinotify {
10351 +#ifdef CONFIG_AUFS_HINOTIFY
10352 + struct inotify_watch hin_watch;
10353 + struct inode *hin_aufs_inode; /* no get/put */
10357 +struct au_hinode {
10358 + struct inode *hi_inode;
10359 + aufs_bindex_t hi_id;
10360 +#ifdef CONFIG_AUFS_HINOTIFY
10361 + struct au_hinotify *hi_notify;
10364 + /* reference to the copied-up whiteout with get/put */
10365 + struct dentry *hi_whdentry;
10370 + atomic_t ii_generation;
10371 + struct super_block *ii_hsb1; /* no get/put */
10373 + struct au_rwsem ii_rwsem;
10374 + aufs_bindex_t ii_bstart, ii_bend;
10376 + struct au_hinode *ii_hinode;
10377 + struct au_vdir *ii_vdir;
10380 +struct au_icntnr {
10381 + struct au_iinfo iinfo;
10382 + struct inode vfs_inode;
10385 +/* au_pin flags */
10386 +#define AuPin_DI_LOCKED 1
10387 +#define AuPin_MNT_WRITE (1 << 1)
10388 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
10389 +#define au_fset_pin(flags, name) { (flags) |= AuPin_##name; }
10390 +#define au_fclr_pin(flags, name) { (flags) &= ~AuPin_##name; }
10394 + struct dentry *dentry;
10395 + unsigned int udba;
10396 + unsigned char lsc_di, lsc_hi, flags;
10397 + aufs_bindex_t bindex;
10400 + struct dentry *parent;
10401 + struct au_hinode *hdir;
10402 + struct vfsmount *h_mnt;
10405 +/* ---------------------------------------------------------------------- */
10407 +static inline struct au_iinfo *au_ii(struct inode *inode)
10409 + struct au_iinfo *iinfo;
10411 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
10412 + if (iinfo->ii_hinode)
10414 + return NULL; /* debugging bad_inode case */
10417 +/* ---------------------------------------------------------------------- */
10420 +struct inode *au_igrab(struct inode *inode);
10421 +int au_refresh_hinode_self(struct inode *inode, int do_attr);
10422 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
10423 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
10424 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
10425 + struct inode *inode);
10426 +int au_test_h_perm(struct inode *h_inode, int mask);
10427 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
10430 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
10432 +/* au_wr_dir flags */
10433 +#define AuWrDir_ADD_ENTRY 1
10434 +#define AuWrDir_ISDIR (1 << 1)
10435 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
10436 +#define au_fset_wrdir(flags, name) { (flags) |= AuWrDir_##name; }
10437 +#define au_fclr_wrdir(flags, name) { (flags) &= ~AuWrDir_##name; }
10439 +struct au_wr_dir_args {
10440 + aufs_bindex_t force_btgt;
10441 + unsigned char flags;
10443 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
10444 + struct au_wr_dir_args *args);
10446 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
10447 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
10448 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
10449 + unsigned int udba, unsigned char flags);
10450 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
10451 + unsigned int udba, unsigned char flags) __must_check;
10452 +int au_do_pin(struct au_pin *pin) __must_check;
10453 +void au_unpin(struct au_pin *pin);
10456 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
10457 + struct dentry *h_parent, int isdir);
10458 +int aufs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
10459 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
10460 +int aufs_create(struct inode *dir, struct dentry *dentry, int mode,
10461 + struct nameidata *nd);
10462 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
10463 + struct dentry *dentry);
10464 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
10467 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
10468 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
10469 + struct dentry *h_parent, int isdir);
10470 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
10471 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
10474 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
10475 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
10476 + struct inode *dir, struct dentry *dentry);
10479 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
10480 +void au_hiput(struct au_hinode *hinode);
10481 +void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex);
10482 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
10483 + struct dentry *h_wh);
10484 +unsigned int au_hi_flags(struct inode *inode, int isdir);
10486 +/* hinode flags */
10487 +#define AuHi_XINO 1
10488 +#define AuHi_HINOTIFY (1 << 1)
10489 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
10490 +#define au_fset_hi(flags, name) { (flags) |= AuHi_##name; }
10491 +#define au_fclr_hi(flags, name) { (flags) &= ~AuHi_##name; }
10493 +#ifndef CONFIG_AUFS_HINOTIFY
10494 +#undef AuHi_HINOTIFY
10495 +#define AuHi_HINOTIFY 0
10498 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
10499 + struct inode *h_inode, unsigned int flags);
10501 +void au_update_iigen(struct inode *inode);
10502 +void au_update_brange(struct inode *inode, int do_put_zero);
10504 +int au_iinfo_init(struct inode *inode);
10505 +void au_iinfo_fin(struct inode *inode);
10506 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
10509 +void au_plink_block_maintain(struct super_block *sb);
10510 +#ifdef CONFIG_AUFS_DEBUG
10511 +void au_plink_list(struct super_block *sb);
10513 +static inline void au_plink_list(struct super_block *sb)
10518 +int au_plink_test(struct inode *inode);
10519 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
10520 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
10521 + struct dentry *h_dentry);
10522 +void au_plink_put(struct super_block *sb);
10523 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
10525 +/* ---------------------------------------------------------------------- */
10527 +/* lock subclass for iinfo */
10529 + AuLsc_II_CHILD, /* child first */
10530 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hinotify */
10531 + AuLsc_II_CHILD3, /* copyup dirs */
10532 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
10533 + AuLsc_II_PARENT2,
10534 + AuLsc_II_PARENT3, /* copyup dirs */
10535 + AuLsc_II_NEW_CHILD
10539 + * ii_read_lock_child, ii_write_lock_child,
10540 + * ii_read_lock_child2, ii_write_lock_child2,
10541 + * ii_read_lock_child3, ii_write_lock_child3,
10542 + * ii_read_lock_parent, ii_write_lock_parent,
10543 + * ii_read_lock_parent2, ii_write_lock_parent2,
10544 + * ii_read_lock_parent3, ii_write_lock_parent3,
10545 + * ii_read_lock_new_child, ii_write_lock_new_child,
10547 +#define AuReadLockFunc(name, lsc) \
10548 +static inline void ii_read_lock_##name(struct inode *i) \
10550 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
10553 +#define AuWriteLockFunc(name, lsc) \
10554 +static inline void ii_write_lock_##name(struct inode *i) \
10556 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
10559 +#define AuRWLockFuncs(name, lsc) \
10560 + AuReadLockFunc(name, lsc) \
10561 + AuWriteLockFunc(name, lsc)
10563 +AuRWLockFuncs(child, CHILD);
10564 +AuRWLockFuncs(child2, CHILD2);
10565 +AuRWLockFuncs(child3, CHILD3);
10566 +AuRWLockFuncs(parent, PARENT);
10567 +AuRWLockFuncs(parent2, PARENT2);
10568 +AuRWLockFuncs(parent3, PARENT3);
10569 +AuRWLockFuncs(new_child, NEW_CHILD);
10571 +#undef AuReadLockFunc
10572 +#undef AuWriteLockFunc
10573 +#undef AuRWLockFuncs
10576 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
10578 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
10580 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
10581 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
10582 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
10584 +/* ---------------------------------------------------------------------- */
10586 +static inline unsigned int au_iigen(struct inode *inode)
10588 + return atomic_read(&au_ii(inode)->ii_generation);
10591 +/* tiny test for inode number */
10592 +/* tmpfs generation is too rough */
10593 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
10595 + struct au_iinfo *iinfo;
10597 + iinfo = au_ii(inode);
10598 + return !(iinfo->ii_hsb1 == h_inode->i_sb
10599 + && iinfo->ii_higen == h_inode->i_generation);
10602 +/* ---------------------------------------------------------------------- */
10604 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
10605 + aufs_bindex_t bindex)
10607 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
10610 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
10612 + return au_ii(inode)->ii_bstart;
10615 +static inline aufs_bindex_t au_ibend(struct inode *inode)
10617 + return au_ii(inode)->ii_bend;
10620 +static inline struct au_vdir *au_ivdir(struct inode *inode)
10622 + return au_ii(inode)->ii_vdir;
10625 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
10627 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
10630 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
10632 + au_ii(inode)->ii_bend = bindex;
10635 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
10637 + au_ii(inode)->ii_vdir = vdir;
10640 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
10642 + return au_ii(inode)->ii_hinode + bindex;
10645 +/* ---------------------------------------------------------------------- */
10647 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
10650 + return pin->parent;
10654 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
10656 + if (pin && pin->hdir)
10657 + return pin->hdir->hi_inode;
10661 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
10664 + return pin->hdir;
10668 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
10671 + pin->dentry = dentry;
10674 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
10675 + unsigned char lflag)
10678 + /* dirty macros require brackets */
10680 + au_fset_pin(pin->flags, DI_LOCKED);
10682 + au_fclr_pin(pin->flags, DI_LOCKED);
10687 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
10690 + dput(pin->parent);
10691 + pin->parent = dget(parent);
10695 +/* ---------------------------------------------------------------------- */
10697 +#ifdef CONFIG_AUFS_HINOTIFY
10699 +int au_hin_alloc(struct au_hinode *hinode, struct inode *inode,
10700 + struct inode *h_inode);
10701 +void au_hin_free(struct au_hinode *hinode);
10702 +void au_hin_ctl(struct au_hinode *hinode, int do_set);
10703 +void au_reset_hinotify(struct inode *inode, unsigned int flags);
10705 +int __init au_hinotify_init(void);
10706 +void au_hinotify_fin(void);
10709 +void au_hin_init(struct au_hinode *hinode, struct au_hinotify *val)
10711 + hinode->hi_notify = val;
10714 +static inline void au_iigen_dec(struct inode *inode)
10716 + atomic_dec_return(&au_ii(inode)->ii_generation);
10721 +int au_hin_alloc(struct au_hinode *hinode __maybe_unused,
10722 + struct inode *inode __maybe_unused,
10723 + struct inode *h_inode __maybe_unused)
10725 + return -EOPNOTSUPP;
10728 +static inline void au_hin_free(struct au_hinode *hinode __maybe_unused)
10733 +static inline void au_hin_ctl(struct au_hinode *hinode __maybe_unused,
10734 + int do_set __maybe_unused)
10739 +static inline void au_reset_hinotify(struct inode *inode __maybe_unused,
10740 + unsigned int flags __maybe_unused)
10745 +static inline int au_hinotify_init(void)
10750 +#define au_hinotify_fin() do {} while (0)
10753 +void au_hin_init(struct au_hinode *hinode __maybe_unused,
10754 + struct au_hinotify *val __maybe_unused)
10758 +#endif /* CONFIG_AUFS_HINOTIFY */
10760 +static inline void au_hin_suspend(struct au_hinode *hdir)
10762 + au_hin_ctl(hdir, /*do_set*/0);
10765 +static inline void au_hin_resume(struct au_hinode *hdir)
10767 + au_hin_ctl(hdir, /*do_set*/1);
10770 +static inline void au_hin_imtx_lock(struct au_hinode *hdir)
10772 + mutex_lock(&hdir->hi_inode->i_mutex);
10773 + au_hin_suspend(hdir);
10776 +static inline void au_hin_imtx_lock_nested(struct au_hinode *hdir,
10777 + unsigned int sc __maybe_unused)
10779 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
10780 + au_hin_suspend(hdir);
10783 +static inline void au_hin_imtx_unlock(struct au_hinode *hdir)
10785 + au_hin_resume(hdir);
10786 + mutex_unlock(&hdir->hi_inode->i_mutex);
10789 +#endif /* __KERNEL__ */
10790 +#endif /* __AUFS_INODE_H__ */
10791 diff -urN linux-2.6.30.org/fs/aufs/ioctl.c linux-2.6.30/fs/aufs/ioctl.c
10792 --- linux-2.6.30.org/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
10793 +++ linux-2.6.30/fs/aufs/ioctl.c 2009-07-21 08:54:19.000000000 +0200
10796 + * Copyright (C) 2005-2009 Junjiro R. Okajima
10798 + * This program, aufs is free software; you can redistribute it and/or modify
10799 + * it under the terms of the GNU General Public License as published by
10800 + * the Free Software Foundation; either version 2 of the License, or
10801 + * (at your option) any later version.
10803 + * This program is distributed in the hope that it will be useful,
10804 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10805 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10806 + * GNU General Public License for more details.
10808 + * You should have received a copy of the GNU General Public License
10809 + * along with this program; if not, write to the Free Software
10810 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10815 + * currently plink-management only.
10818 +#include <linux/uaccess.h>
10821 +long aufs_ioctl_dir(struct file *file, unsigned int cmd,
10822 + unsigned long arg __maybe_unused)
10825 + struct super_block *sb;
10826 + struct au_sbinfo *sbinfo;
10829 + if (!capable(CAP_SYS_ADMIN))
10833 + sb = file->f_dentry->d_sb;
10834 + sbinfo = au_sbi(sb);
10836 + case AUFS_CTL_PLINK_MAINT:
10838 + * pseudo-link maintenance mode,
10839 + * cleared by aufs_release_dir()
10841 + si_write_lock(sb);
10842 + if (!au_ftest_si(sbinfo, MAINTAIN_PLINK)) {
10843 + au_fset_si(sbinfo, MAINTAIN_PLINK);
10844 + au_fi(file)->fi_maintain_plink = 1;
10847 + si_write_unlock(sb);
10849 + case AUFS_CTL_PLINK_CLEAN:
10850 + aufs_write_lock(sb->s_root);
10851 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
10852 + au_plink_put(sb);
10853 + aufs_write_unlock(sb->s_root);
10862 diff -urN linux-2.6.30.org/fs/aufs/i_op_add.c linux-2.6.30/fs/aufs/i_op_add.c
10863 --- linux-2.6.30.org/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
10864 +++ linux-2.6.30/fs/aufs/i_op_add.c 2009-07-21 08:54:19.000000000 +0200
10867 + * Copyright (C) 2005-2009 Junjiro R. Okajima
10869 + * This program, aufs is free software; you can redistribute it and/or modify
10870 + * it under the terms of the GNU General Public License as published by
10871 + * the Free Software Foundation; either version 2 of the License, or
10872 + * (at your option) any later version.
10874 + * This program is distributed in the hope that it will be useful,
10875 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10876 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10877 + * GNU General Public License for more details.
10879 + * You should have received a copy of the GNU General Public License
10880 + * along with this program; if not, write to the Free Software
10881 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10885 + * inode operations (add entry)
10891 + * final procedure of adding a new entry, except link(2).
10892 + * remove whiteout, instantiate, copyup the parent dir's times and size
10893 + * and update version.
10894 + * if it failed, re-create the removed whiteout.
10896 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
10897 + struct dentry *wh_dentry, struct dentry *dentry)
10900 + aufs_bindex_t bwh;
10901 + struct path h_path;
10902 + struct inode *inode, *h_dir;
10903 + struct dentry *wh;
10907 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
10908 + IMustLock(h_dir);
10909 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
10910 + bwh = au_dbwh(dentry);
10911 + h_path.dentry = wh_dentry;
10912 + h_path.mnt = au_sbr_mnt(dir->i_sb, bindex);
10913 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
10915 + if (unlikely(err))
10919 + inode = au_new_inode(dentry, /*must_new*/1);
10920 + if (!IS_ERR(inode)) {
10921 + d_instantiate(dentry, inode);
10922 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
10924 + if (au_ibstart(dir) == au_dbstart(dentry))
10925 + au_cpup_attr_timesizes(dir);
10926 + dir->i_version++;
10927 + return 0; /* success */
10930 + err = PTR_ERR(inode);
10935 + /* dir inode is locked */
10936 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
10937 + rerr = PTR_ERR(wh);
10938 + if (IS_ERR(wh)) {
10939 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
10940 + AuDLNPair(dentry), err, rerr);
10950 + * simple tests for the adding inode operations.
10951 + * following the checks in vfs, plus the parent-child relationship.
10953 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
10954 + struct dentry *h_parent, int isdir)
10958 + struct dentry *h_dentry;
10959 + struct inode *h_inode;
10961 + h_dentry = au_h_dptr(dentry, bindex);
10962 + h_inode = h_dentry->d_inode;
10963 + if (!dentry->d_inode) {
10965 + if (unlikely(h_inode))
10968 + /* rename(2) case */
10970 + if (unlikely(!h_inode || !h_inode->i_nlink))
10973 + h_mode = h_inode->i_mode;
10976 + if (unlikely(S_ISDIR(h_mode)))
10978 + } else if (unlikely(!S_ISDIR(h_mode))) {
10985 + /* expected parent dir is locked */
10986 + if (unlikely(h_parent != h_dentry->d_parent))
10995 + * initial procedure of adding a new entry.
10996 + * prepare writable branch and the parent dir, lock it,
10997 + * and lookup whiteout for the new entry.
10999 +static struct dentry*
11000 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
11001 + struct dentry *src_dentry, struct au_pin *pin,
11002 + struct au_wr_dir_args *wr_dir_args)
11004 + struct dentry *wh_dentry, *h_parent;
11005 + struct super_block *sb;
11006 + struct au_branch *br;
11008 + unsigned int udba;
11009 + aufs_bindex_t bcpup;
11011 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
11013 + wh_dentry = ERR_PTR(err);
11014 + if (unlikely(err < 0))
11017 + sb = dentry->d_sb;
11018 + udba = au_opt_udba(sb);
11019 + err = au_pin(pin, dentry, bcpup, udba,
11020 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11021 + wh_dentry = ERR_PTR(err);
11022 + if (unlikely(err))
11025 + h_parent = au_pinned_h_parent(pin);
11026 + if (udba != AuOpt_UDBA_NONE
11027 + && au_dbstart(dentry) == bcpup) {
11028 + err = au_may_add(dentry, bcpup, h_parent,
11029 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
11030 + wh_dentry = ERR_PTR(err);
11031 + if (unlikely(err))
11035 + br = au_sbr(sb, bcpup);
11037 + struct path tmp = {
11038 + .dentry = h_parent,
11039 + .mnt = br->br_mnt
11041 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
11044 + wh_dentry = NULL;
11045 + if (bcpup != au_dbwh(dentry))
11046 + goto out; /* success */
11048 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
11051 + if (IS_ERR(wh_dentry))
11054 + return wh_dentry;
11057 +/* ---------------------------------------------------------------------- */
11059 +enum { Mknod, Symlink, Creat };
11060 +struct simple_arg {
11065 + struct nameidata *nd;
11068 + const char *symname;
11077 +static int add_simple(struct inode *dir, struct dentry *dentry,
11078 + struct simple_arg *arg)
11081 + aufs_bindex_t bstart;
11082 + unsigned char created;
11083 + struct au_dtime dt;
11084 + struct au_pin pin;
11085 + struct path h_path;
11086 + struct dentry *wh_dentry, *parent;
11087 + struct inode *h_dir;
11088 + struct au_wr_dir_args wr_dir_args = {
11089 + .force_btgt = -1,
11090 + .flags = AuWrDir_ADD_ENTRY
11095 + parent = dentry->d_parent; /* dir inode is locked */
11096 + aufs_read_lock(dentry, AuLock_DW);
11097 + di_write_lock_parent(parent);
11098 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL, &pin,
11100 + err = PTR_ERR(wh_dentry);
11101 + if (IS_ERR(wh_dentry))
11104 + bstart = au_dbstart(dentry);
11105 + h_path.dentry = au_h_dptr(dentry, bstart);
11106 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
11107 + h_dir = au_pinned_h_dir(&pin);
11108 + switch (arg->type) {
11110 + err = vfsub_create(h_dir, &h_path, arg->u.c.mode);
11113 + err = vfsub_symlink(h_dir, &h_path, arg->u.s.symname);
11116 + err = vfsub_mknod(h_dir, &h_path, arg->u.m.mode, arg->u.m.dev);
11123 + err = epilog(dir, bstart, wh_dentry, dentry);
11126 + if (unlikely(created && err && h_path.dentry->d_inode)) {
11128 + rerr = vfsub_unlink(h_dir, &h_path, /*force*/0);
11130 + AuIOErr("%.*s revert failure(%d, %d)\n",
11131 + AuDLNPair(dentry), err, rerr);
11134 + au_dtime_revert(&dt);
11142 + if (unlikely(err)) {
11143 + au_update_dbstart(dentry);
11146 + di_write_unlock(parent);
11147 + aufs_read_unlock(dentry, AuLock_DW);
11151 +int aufs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
11153 + struct simple_arg arg = {
11160 + return add_simple(dir, dentry, &arg);
11163 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
11165 + struct simple_arg arg = {
11167 + .u.s.symname = symname
11169 + return add_simple(dir, dentry, &arg);
11172 +int aufs_create(struct inode *dir, struct dentry *dentry, int mode,
11173 + struct nameidata *nd)
11175 + struct simple_arg arg = {
11182 + return add_simple(dir, dentry, &arg);
11185 +/* ---------------------------------------------------------------------- */
11187 +struct au_link_args {
11188 + aufs_bindex_t bdst, bsrc;
11189 + struct au_pin pin;
11190 + struct path h_path;
11191 + struct dentry *src_parent, *parent;
11194 +static int au_cpup_before_link(struct dentry *src_dentry,
11195 + struct au_link_args *a)
11198 + struct dentry *h_src_dentry;
11199 + struct mutex *h_mtx;
11201 + di_read_lock_parent(a->src_parent, AuLock_IR);
11202 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
11203 + if (unlikely(err))
11206 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
11207 + h_mtx = &h_src_dentry->d_inode->i_mutex;
11208 + err = au_pin(&a->pin, src_dentry, a->bdst,
11209 + au_opt_udba(src_dentry->d_sb),
11210 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11211 + if (unlikely(err))
11213 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
11214 + err = au_sio_cpup_simple(src_dentry, a->bdst, -1,
11215 + AuCpup_DTIME /* | AuCpup_KEEPLINO */);
11216 + mutex_unlock(h_mtx);
11217 + au_unpin(&a->pin);
11220 + di_read_unlock(a->src_parent, AuLock_IR);
11224 +static int au_cpup_or_link(struct dentry *src_dentry, struct au_link_args *a)
11227 + unsigned char plink;
11228 + struct inode *h_inode, *inode;
11229 + struct dentry *h_src_dentry;
11230 + struct super_block *sb;
11234 + sb = src_dentry->d_sb;
11235 + inode = src_dentry->d_inode;
11236 + if (au_ibstart(inode) <= a->bdst)
11237 + h_inode = au_h_iptr(inode, a->bdst);
11238 + if (!h_inode || !h_inode->i_nlink) {
11239 + /* copyup src_dentry as the name of dentry. */
11240 + au_set_dbstart(src_dentry, a->bdst);
11241 + au_set_h_dptr(src_dentry, a->bdst, dget(a->h_path.dentry));
11242 + h_inode = au_h_dptr(src_dentry, a->bsrc)->d_inode;
11243 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
11244 + err = au_sio_cpup_single(src_dentry, a->bdst, a->bsrc, -1,
11245 + AuCpup_KEEPLINO, a->parent);
11246 + mutex_unlock(&h_inode->i_mutex);
11247 + au_set_h_dptr(src_dentry, a->bdst, NULL);
11248 + au_set_dbstart(src_dentry, a->bsrc);
11250 + /* the inode of src_dentry already exists on a.bdst branch */
11251 + h_src_dentry = d_find_alias(h_inode);
11252 + if (!h_src_dentry && au_plink_test(inode)) {
11254 + h_src_dentry = au_plink_lkup(inode, a->bdst);
11255 + err = PTR_ERR(h_src_dentry);
11256 + if (IS_ERR(h_src_dentry))
11259 + if (unlikely(!h_src_dentry->d_inode)) {
11260 + dput(h_src_dentry);
11261 + h_src_dentry = NULL;
11265 + if (h_src_dentry) {
11266 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
11268 + dput(h_src_dentry);
11270 + AuIOErr("no dentry found for hi%lu on b%d\n",
11271 + h_inode->i_ino, a->bdst);
11276 + if (!err && !plink)
11277 + au_plink_append(inode, a->bdst, a->h_path.dentry);
11283 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
11284 + struct dentry *dentry)
11287 + struct au_dtime dt;
11288 + struct au_link_args *a;
11289 + struct dentry *wh_dentry, *h_src_dentry;
11290 + struct inode *inode;
11291 + struct super_block *sb;
11292 + struct au_wr_dir_args wr_dir_args = {
11293 + /* .force_btgt = -1, */
11294 + .flags = AuWrDir_ADD_ENTRY
11298 + inode = src_dentry->d_inode;
11299 + IMustLock(inode);
11302 + if (unlikely(!inode->i_nlink))
11306 + a = kzalloc(sizeof(*a), GFP_NOFS);
11307 + if (unlikely(!a))
11310 + a->parent = dentry->d_parent; /* dir inode is locked */
11311 + aufs_read_and_write_lock2(dentry, src_dentry, /*AuLock_FLUSH*/0);
11312 + a->src_parent = dget_parent(src_dentry);
11313 + wr_dir_args.force_btgt = au_dbstart(src_dentry);
11315 + di_write_lock_parent(a->parent);
11316 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
11317 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
11319 + err = PTR_ERR(wh_dentry);
11320 + if (IS_ERR(wh_dentry))
11324 + sb = dentry->d_sb;
11325 + a->bdst = au_dbstart(dentry);
11326 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
11327 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
11328 + a->bsrc = au_dbstart(src_dentry);
11329 + if (au_opt_test(au_mntflags(sb), PLINK)) {
11330 + if (a->bdst < a->bsrc
11331 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
11332 + err = au_cpup_or_link(src_dentry, a);
11334 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
11335 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
11340 + * copyup src_dentry to the branch we process,
11341 + * and then link(2) to it.
11343 + if (a->bdst < a->bsrc
11344 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
11345 + au_unpin(&a->pin);
11346 + di_write_unlock(a->parent);
11347 + err = au_cpup_before_link(src_dentry, a);
11349 + di_write_lock_parent(a->parent);
11350 + err = au_pin(&a->pin, dentry, a->bdst,
11352 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11353 + if (unlikely(err))
11358 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
11359 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
11363 + if (unlikely(err))
11367 + a->h_path.dentry = wh_dentry;
11368 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
11370 + if (unlikely(err))
11374 + dir->i_version++;
11375 + if (au_ibstart(dir) == au_dbstart(dentry))
11376 + au_cpup_attr_timesizes(dir);
11377 + inc_nlink(inode);
11378 + inode->i_ctime = dir->i_ctime;
11379 + if (!d_unhashed(a->h_path.dentry))
11380 + d_instantiate(dentry, au_igrab(inode));
11382 + /* some filesystem calls d_drop() */
11384 + goto out_unpin; /* success */
11387 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, /*force*/0);
11390 + AuIOErr("%.*s reverting failed(%d, %d)\n",
11391 + AuDLNPair(dentry), err, rerr);
11395 + au_dtime_revert(&dt);
11397 + au_unpin(&a->pin);
11401 + if (unlikely(err)) {
11402 + au_update_dbstart(dentry);
11405 + di_write_unlock(a->parent);
11406 + dput(a->src_parent);
11407 + aufs_read_and_write_unlock2(dentry, src_dentry);
11413 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
11416 + aufs_bindex_t bindex;
11417 + unsigned char diropq;
11418 + struct au_pin pin;
11419 + struct path h_path;
11420 + struct dentry *wh_dentry, *parent, *opq_dentry;
11421 + struct mutex *h_mtx;
11422 + struct super_block *sb;
11423 + struct au_dtime dt;
11424 + struct au_wr_dir_args wr_dir_args = {
11425 + .force_btgt = -1,
11426 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
11431 + aufs_read_lock(dentry, AuLock_DW);
11432 + parent = dentry->d_parent; /* dir inode is locked */
11433 + di_write_lock_parent(parent);
11434 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, /*src_dentry*/NULL, &pin,
11436 + err = PTR_ERR(wh_dentry);
11437 + if (IS_ERR(wh_dentry))
11440 + sb = dentry->d_sb;
11441 + bindex = au_dbstart(dentry);
11442 + h_path.dentry = au_h_dptr(dentry, bindex);
11443 + h_path.mnt = au_sbr_mnt(sb, bindex);
11444 + err = vfsub_mkdir(au_pinned_h_dir(&pin), &h_path, mode);
11445 + if (unlikely(err))
11448 + /* make the dir opaque */
11450 + h_mtx = &h_path.dentry->d_inode->i_mutex;
11452 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
11453 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
11454 + opq_dentry = au_diropq_create(dentry, bindex);
11455 + mutex_unlock(h_mtx);
11456 + err = PTR_ERR(opq_dentry);
11457 + if (IS_ERR(opq_dentry))
11459 + dput(opq_dentry);
11463 + err = epilog(dir, bindex, wh_dentry, dentry);
11466 + goto out_unlock; /* success */
11471 + AuLabel(revert opq);
11472 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
11473 + rerr = au_diropq_remove(dentry, bindex);
11474 + mutex_unlock(h_mtx);
11476 + AuIOErr("%.*s reverting diropq failed(%d, %d)\n",
11477 + AuDLNPair(dentry), err, rerr);
11483 + AuLabel(revert dir);
11484 + rerr = vfsub_rmdir(au_pinned_h_dir(&pin), &h_path);
11486 + AuIOErr("%.*s reverting dir failed(%d, %d)\n",
11487 + AuDLNPair(dentry), err, rerr);
11491 + au_dtime_revert(&dt);
11496 + if (unlikely(err)) {
11497 + au_update_dbstart(dentry);
11500 + di_write_unlock(parent);
11501 + aufs_read_unlock(dentry, AuLock_DW);
11504 diff -urN linux-2.6.30.org/fs/aufs/i_op.c linux-2.6.30/fs/aufs/i_op.c
11505 --- linux-2.6.30.org/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
11506 +++ linux-2.6.30/fs/aufs/i_op.c 2009-07-21 08:54:19.000000000 +0200
11509 + * Copyright (C) 2005-2009 Junjiro R. Okajima
11511 + * This program, aufs is free software; you can redistribute it and/or modify
11512 + * it under the terms of the GNU General Public License as published by
11513 + * the Free Software Foundation; either version 2 of the License, or
11514 + * (at your option) any later version.
11516 + * This program is distributed in the hope that it will be useful,
11517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11519 + * GNU General Public License for more details.
11521 + * You should have received a copy of the GNU General Public License
11522 + * along with this program; if not, write to the Free Software
11523 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11527 + * inode operations (except add/del/rename)
11530 +#include <linux/device_cgroup.h>
11531 +#include <linux/fs_stack.h>
11532 +#include <linux/mm.h>
11533 +#include <linux/namei.h>
11534 +#include <linux/security.h>
11535 +#include <linux/uaccess.h>
11538 +static int h_permission(struct inode *h_inode, int mask,
11539 + struct vfsmount *h_mnt, int brperm)
11542 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
11545 + if ((write_mask && IS_IMMUTABLE(h_inode))
11546 + || ((mask & MAY_EXEC)
11547 + && S_ISREG(h_inode->i_mode)
11548 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
11549 + || !(h_inode->i_mode & S_IXUGO))))
11553 + * - skip the lower fs test in the case of write to ro branch.
11554 + * - nfs dir permission write check is optimized, but a policy for
11555 + * link/rename requires a real check.
11557 + if ((write_mask && !au_br_writable(brperm))
11558 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
11559 + && write_mask && !(mask & MAY_READ))
11560 + || !h_inode->i_op->permission) {
11561 + /* AuLabel(generic_permission); */
11562 + err = generic_permission(h_inode, mask, NULL);
11564 + /* AuLabel(h_inode->permission); */
11565 + err = h_inode->i_op->permission(h_inode, mask);
11570 + err = devcgroup_inode_permission(h_inode, mask);
11572 + err = security_inode_permission
11573 + (h_inode, mask & (MAY_READ | MAY_WRITE | MAY_EXEC
11580 +static int aufs_permission(struct inode *inode, int mask)
11583 + aufs_bindex_t bindex, bend;
11584 + const unsigned char isdir = !!S_ISDIR(inode->i_mode);
11585 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
11586 + struct inode *h_inode;
11587 + struct super_block *sb;
11588 + struct au_branch *br;
11590 + sb = inode->i_sb;
11591 + si_read_lock(sb, AuLock_FLUSH);
11592 + ii_read_lock_child(inode);
11594 + if (!isdir || write_mask) {
11595 + h_inode = au_h_iptr(inode, au_ibstart(inode));
11596 + AuDebugOn(!h_inode
11597 + || ((h_inode->i_mode & S_IFMT)
11598 + != (inode->i_mode & S_IFMT)));
11600 + bindex = au_ibstart(inode);
11601 + br = au_sbr(sb, bindex);
11602 + err = h_permission(h_inode, mask, br->br_mnt, br->br_perm);
11604 + if (write_mask && !err) {
11605 + /* test whether the upper writable branch exists */
11607 + for (; bindex >= 0; bindex--)
11608 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
11616 + /* non-write to dir */
11618 + bend = au_ibend(inode);
11619 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
11620 + h_inode = au_h_iptr(inode, bindex);
11622 + AuDebugOn(!S_ISDIR(h_inode->i_mode));
11623 + br = au_sbr(sb, bindex);
11624 + err = h_permission(h_inode, mask, br->br_mnt,
11630 + ii_read_unlock(inode);
11631 + si_read_unlock(sb);
11635 +/* ---------------------------------------------------------------------- */
11637 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
11638 + struct nameidata *nd)
11640 + struct dentry *ret, *parent;
11641 + struct inode *inode, *h_inode;
11642 + struct mutex *mtx;
11643 + struct super_block *sb;
11644 + int err, npositive;
11645 + aufs_bindex_t bstart;
11647 + /* temporary workaround for a bug in NFSD readdir */
11648 + if (!au_test_nfsd(current))
11651 + WARN_ONCE(!mutex_is_locked(&dir->i_mutex),
11652 + "a known problem of NFSD readdir since 2.6.28\n");
11655 + si_read_lock(sb, AuLock_FLUSH);
11656 + err = au_alloc_dinfo(dentry);
11657 + ret = ERR_PTR(err);
11658 + if (unlikely(err))
11661 + parent = dentry->d_parent; /* dir inode is locked */
11662 + di_read_lock_parent(parent, AuLock_IR);
11663 + npositive = au_lkup_dentry(dentry, au_dbstart(parent), /*type*/0, nd);
11664 + di_read_unlock(parent, AuLock_IR);
11666 + ret = ERR_PTR(err);
11667 + if (unlikely(err < 0))
11672 + bstart = au_dbstart(dentry);
11673 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
11674 + if (!S_ISDIR(h_inode->i_mode)) {
11676 + * stop 'race'-ing between hardlinks under different
11679 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
11681 + inode = au_new_inode(dentry, /*must_new*/0);
11682 + mutex_unlock(mtx);
11684 + inode = au_new_inode(dentry, /*must_new*/0);
11685 + ret = (void *)inode;
11687 + if (IS_ERR(inode))
11690 + ret = d_splice_alias(inode, dentry);
11691 + if (unlikely(IS_ERR(ret) && inode))
11692 + ii_write_unlock(inode);
11693 + au_store_oflag(nd, inode);
11696 + di_write_unlock(dentry);
11698 + si_read_unlock(sb);
11702 +/* ---------------------------------------------------------------------- */
11704 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
11705 + const unsigned char add_entry, aufs_bindex_t bcpup,
11706 + aufs_bindex_t bstart)
11709 + struct dentry *h_parent;
11710 + struct inode *h_dir;
11713 + au_update_dbstart(dentry);
11714 + IMustLock(parent->d_inode);
11716 + di_write_lock_parent(parent);
11719 + if (!au_h_dptr(parent, bcpup)) {
11720 + if (bstart < bcpup)
11721 + err = au_cpdown_dirs(dentry, bcpup);
11723 + err = au_cpup_dirs(dentry, bcpup);
11725 + if (!err && add_entry) {
11726 + h_parent = au_h_dptr(parent, bcpup);
11727 + h_dir = h_parent->d_inode;
11728 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
11729 + err = au_lkup_neg(dentry, bcpup);
11730 + /* todo: no unlock here */
11731 + mutex_unlock(&h_dir->i_mutex);
11732 + if (bstart < bcpup && au_dbstart(dentry) < 0) {
11733 + au_set_dbstart(dentry, 0);
11734 + au_update_dbrange(dentry, /*do_put_zero*/0);
11739 + di_write_unlock(parent);
11741 + err = bcpup; /* success */
11747 + * decide the branch and the parent dir where we will create a new entry.
11748 + * returns new bindex or an error.
11749 + * copyup the parent dir if needed.
11751 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
11752 + struct au_wr_dir_args *args)
11755 + aufs_bindex_t bcpup, bstart, src_bstart;
11756 + const unsigned char add_entry = !!au_ftest_wrdir(args->flags,
11758 + struct super_block *sb;
11759 + struct dentry *parent;
11760 + struct au_sbinfo *sbinfo;
11762 + sb = dentry->d_sb;
11763 + sbinfo = au_sbi(sb);
11764 + parent = dget_parent(dentry);
11765 + bstart = au_dbstart(dentry);
11767 + if (args->force_btgt < 0) {
11768 + if (src_dentry) {
11769 + src_bstart = au_dbstart(src_dentry);
11770 + if (src_bstart < bstart)
11771 + bcpup = src_bstart;
11772 + } else if (add_entry) {
11773 + err = AuWbrCreate(sbinfo, dentry,
11774 + au_ftest_wrdir(args->flags, ISDIR));
11778 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
11780 + err = AuWbrCopyup(sbinfo, dentry);
11782 + if (!IS_ROOT(dentry)) {
11783 + di_read_lock_parent(parent, !AuLock_IR);
11784 + err = AuWbrCopyup(sbinfo, dentry);
11785 + di_read_unlock(parent, !AuLock_IR);
11787 + err = AuWbrCopyup(sbinfo, dentry);
11790 + if (unlikely(err < 0))
11794 + bcpup = args->force_btgt;
11795 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
11797 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
11798 + if (bstart < bcpup)
11799 + au_update_dbrange(dentry, /*do_put_zero*/1);
11802 + if (bcpup == bstart)
11803 + goto out; /* success */
11805 + /* copyup the new parent into the branch we process */
11806 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
11813 +/* ---------------------------------------------------------------------- */
11815 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
11817 + if (pin && pin->parent)
11818 + return au_h_dptr(pin->parent, pin->bindex);
11822 +void au_unpin(struct au_pin *p)
11824 + if (au_ftest_pin(p->flags, MNT_WRITE))
11825 + mnt_drop_write(p->h_mnt);
11829 + au_hin_imtx_unlock(p->hdir);
11830 + if (!au_ftest_pin(p->flags, DI_LOCKED))
11831 + di_read_unlock(p->parent, AuLock_IR);
11832 + iput(p->hdir->hi_inode);
11834 + p->parent = NULL;
11839 +int au_do_pin(struct au_pin *p)
11842 + struct super_block *sb;
11843 + struct dentry *h_dentry, *h_parent;
11844 + struct au_branch *br;
11845 + struct inode *h_dir;
11848 + sb = p->dentry->d_sb;
11849 + br = au_sbr(sb, p->bindex);
11850 + if (IS_ROOT(p->dentry)) {
11851 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
11852 + p->h_mnt = br->br_mnt;
11853 + err = mnt_want_write(p->h_mnt);
11854 + if (unlikely(err)) {
11855 + au_fclr_pin(p->flags, MNT_WRITE);
11863 + if (p->bindex <= au_dbend(p->dentry))
11864 + h_dentry = au_h_dptr(p->dentry, p->bindex);
11866 + p->parent = dget_parent(p->dentry);
11867 + if (!au_ftest_pin(p->flags, DI_LOCKED))
11868 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
11871 + h_parent = au_h_dptr(p->parent, p->bindex);
11872 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
11874 + h_dir = p->hdir->hi_inode;
11877 + if (unlikely(!p->hdir || !h_dir)) {
11878 + if (!au_ftest_pin(p->flags, DI_LOCKED))
11879 + di_read_unlock(p->parent, AuLock_IR);
11881 + p->parent = NULL;
11886 + au_hin_imtx_lock_nested(p->hdir, p->lsc_hi);
11889 + err = au_h_verify(h_dentry, p->udba, h_dir, h_parent, br);
11890 + if (unlikely(err)) {
11891 + au_fclr_pin(p->flags, MNT_WRITE);
11896 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
11897 + p->h_mnt = br->br_mnt;
11898 + err = mnt_want_write(p->h_mnt);
11899 + if (unlikely(err)) {
11900 + au_fclr_pin(p->flags, MNT_WRITE);
11904 + goto out; /* success */
11909 + AuErr("err %d\n", err);
11910 + err = au_busy_or_stale();
11915 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
11916 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
11917 + unsigned int udba, unsigned char flags)
11919 + p->dentry = dentry;
11921 + p->lsc_di = lsc_di;
11922 + p->lsc_hi = lsc_hi;
11923 + p->flags = flags;
11924 + p->bindex = bindex;
11926 + p->parent = NULL;
11931 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
11932 + unsigned int udba, unsigned char flags)
11934 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
11936 + return au_do_pin(pin);
11939 +/* ---------------------------------------------------------------------- */
11941 +#define AuIcpup_DID_CPUP 1
11942 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
11943 +#define au_fset_icpup(flags, name) { (flags) |= AuIcpup_##name; }
11944 +#define au_fclr_icpup(flags, name) { (flags) &= ~AuIcpup_##name; }
11946 +struct au_icpup_args {
11947 + unsigned char flags;
11948 + unsigned char pin_flags;
11949 + aufs_bindex_t btgt;
11950 + struct au_pin pin;
11951 + struct path h_path;
11952 + struct inode *h_inode;
11955 +static int au_lock_and_icpup(struct dentry *dentry, struct iattr *ia,
11956 + struct au_icpup_args *a)
11959 + unsigned int udba;
11961 + aufs_bindex_t bstart;
11962 + struct dentry *hi_wh, *parent;
11963 + struct inode *inode;
11964 + struct au_wr_dir_args wr_dir_args = {
11965 + .force_btgt = -1,
11969 + di_write_lock_child(dentry);
11970 + bstart = au_dbstart(dentry);
11971 + inode = dentry->d_inode;
11972 + if (S_ISDIR(inode->i_mode))
11973 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
11974 + /* plink or hi_wh() case */
11975 + if (bstart != au_ibstart(inode))
11976 + wr_dir_args.force_btgt = au_ibstart(inode);
11977 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
11978 + if (unlikely(err < 0))
11981 + if (err != bstart)
11982 + au_fset_icpup(a->flags, DID_CPUP);
11985 + a->pin_flags = AuPin_MNT_WRITE;
11987 + if (!IS_ROOT(dentry)) {
11988 + au_fset_pin(a->pin_flags, DI_LOCKED);
11989 + parent = dget_parent(dentry);
11990 + di_write_lock_parent(parent);
11993 + udba = au_opt_udba(dentry->d_sb);
11994 + if (d_unhashed(dentry) || (ia->ia_valid & ATTR_FILE))
11995 + udba = AuOpt_UDBA_NONE;
11996 + err = au_pin(&a->pin, dentry, a->btgt, udba, a->pin_flags);
11997 + if (unlikely(err)) {
11999 + di_write_unlock(parent);
12004 + a->h_path.dentry = au_h_dptr(dentry, bstart);
12005 + a->h_inode = a->h_path.dentry->d_inode;
12006 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
12008 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
12009 + sz = ia->ia_size;
12012 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unhashed(dentry)) {
12013 + hi_wh = au_hi_wh(inode, a->btgt);
12015 + err = au_sio_cpup_wh(dentry, a->btgt, sz, /*file*/NULL);
12016 + if (unlikely(err))
12018 + hi_wh = au_hi_wh(inode, a->btgt);
12019 + /* todo: revalidate hi_wh? */
12024 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
12025 + di_downgrade_lock(parent, AuLock_IR);
12028 + if (!au_ftest_icpup(a->flags, DID_CPUP))
12029 + goto out; /* success */
12031 + if (!d_unhashed(dentry)) {
12032 + err = au_sio_cpup_simple(dentry, a->btgt, sz, AuCpup_DTIME);
12034 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
12035 + } else if (!hi_wh)
12036 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
12038 + a->h_path.dentry = hi_wh; /* do not dget here */
12041 + mutex_unlock(&a->h_inode->i_mutex);
12042 + a->h_inode = a->h_path.dentry->d_inode;
12044 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
12045 + goto out; /* success */
12048 + au_unpin(&a->pin);
12051 + di_write_unlock(dentry);
12056 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
12059 + struct inode *inode;
12060 + struct super_block *sb;
12061 + struct file *file;
12062 + struct au_icpup_args *a;
12065 + a = kzalloc(sizeof(*a), GFP_NOFS);
12066 + if (unlikely(!a))
12069 + inode = dentry->d_inode;
12070 + IMustLock(inode);
12071 + sb = dentry->d_sb;
12072 + si_read_lock(sb, AuLock_FLUSH);
12075 + if (ia->ia_valid & ATTR_FILE) {
12076 + /* currently ftruncate(2) only */
12077 + file = ia->ia_file;
12078 + fi_write_lock(file);
12079 + ia->ia_file = au_h_fptr(file, au_fbstart(file));
12082 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
12083 + ia->ia_valid &= ~ATTR_MODE;
12085 + err = au_lock_and_icpup(dentry, ia, a);
12086 + if (unlikely(err < 0))
12088 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
12089 + ia->ia_file = NULL;
12090 + ia->ia_valid &= ~ATTR_FILE;
12093 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
12094 + if (ia->ia_valid & ATTR_SIZE) {
12097 + if (ia->ia_size < i_size_read(inode)) {
12099 + err = vmtruncate(inode, ia->ia_size);
12100 + if (unlikely(err))
12105 + if (ia->ia_valid & ATTR_FILE)
12107 + mutex_unlock(&a->h_inode->i_mutex);
12108 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
12109 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
12111 + err = vfsub_notify_change(&a->h_path, ia);
12113 + au_cpup_attr_changeable(inode);
12116 + mutex_unlock(&a->h_inode->i_mutex);
12117 + au_unpin(&a->pin);
12118 + di_write_unlock(dentry);
12121 + fi_write_unlock(file);
12122 + ia->ia_file = file;
12123 + ia->ia_valid |= ATTR_FILE;
12125 + si_read_unlock(sb);
12131 +static int au_getattr_lock_reval(struct dentry *dentry, unsigned int sigen)
12134 + struct inode *inode;
12135 + struct dentry *parent;
12138 + inode = dentry->d_inode;
12139 + di_write_lock_child(dentry);
12140 + if (au_digen(dentry) != sigen || au_iigen(inode) != sigen) {
12141 + parent = dget_parent(dentry);
12142 + di_read_lock_parent(parent, AuLock_IR);
12143 + /* returns a number of positive dentries */
12144 + err = au_refresh_hdentry(dentry, inode->i_mode & S_IFMT);
12146 + err = au_refresh_hinode(inode, dentry);
12147 + di_read_unlock(parent, AuLock_IR);
12149 + if (unlikely(!err))
12152 + di_downgrade_lock(dentry, AuLock_IR);
12153 + if (unlikely(err))
12154 + di_read_unlock(dentry, AuLock_IR);
12159 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
12160 + unsigned int nlink)
12162 + inode->i_mode = st->mode;
12163 + inode->i_uid = st->uid;
12164 + inode->i_gid = st->gid;
12165 + inode->i_atime = st->atime;
12166 + inode->i_mtime = st->mtime;
12167 + inode->i_ctime = st->ctime;
12169 + au_cpup_attr_nlink(inode, /*force*/0);
12170 + if (S_ISDIR(inode->i_mode)) {
12171 + inode->i_nlink -= nlink;
12172 + inode->i_nlink += st->nlink;
12175 + spin_lock(&inode->i_lock);
12176 + inode->i_blocks = st->blocks;
12177 + i_size_write(inode, st->size);
12178 + spin_unlock(&inode->i_lock);
12181 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
12182 + struct dentry *dentry, struct kstat *st)
12185 + unsigned int mnt_flags;
12186 + aufs_bindex_t bindex;
12187 + unsigned char udba_none, positive, did_lock;
12188 + struct super_block *sb, *h_sb;
12189 + struct inode *inode;
12190 + struct vfsmount *h_mnt;
12191 + struct dentry *h_dentry;
12195 + sb = dentry->d_sb;
12196 + inode = dentry->d_inode;
12197 + si_read_lock(sb, AuLock_FLUSH);
12198 + if (IS_ROOT(dentry)) {
12199 + /* lock free root dinfo */
12200 + h_dentry = dget(au_di(dentry)->di_hdentry->hd_dentry);
12201 + h_mnt = au_sbr_mnt(sb, 0);
12205 + mnt_flags = au_mntflags(sb);
12206 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
12208 + /* support fstat(2) */
12209 + if (!d_unhashed(dentry) && !udba_none) {
12210 + unsigned int sigen = au_sigen(sb);
12211 + if (au_digen(dentry) == sigen && au_iigen(inode) == sigen)
12212 + di_read_lock_child(dentry, AuLock_IR);
12214 + err = au_getattr_lock_reval(dentry, sigen);
12215 + if (unlikely(err))
12219 + di_read_lock_child(dentry, AuLock_IR);
12222 + bindex = au_ibstart(inode);
12223 + h_mnt = au_sbr_mnt(sb, bindex);
12224 + h_sb = h_mnt->mnt_sb;
12225 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
12226 + goto out_fill; /* success */
12229 + if (au_dbstart(dentry) == bindex)
12230 + h_dentry = dget(au_h_dptr(dentry, bindex));
12231 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
12232 + h_dentry = au_plink_lkup(inode, bindex);
12233 + if (IS_ERR(h_dentry))
12234 + goto out_fill; /* pretending success */
12236 + /* illegally overlapped or something */
12237 + if (unlikely(!h_dentry))
12238 + goto out_fill; /* pretending success */
12241 + positive = !!h_dentry->d_inode;
12243 + err = vfs_getattr(h_mnt, h_dentry, st);
12247 + au_refresh_iattr(inode, st, h_dentry->d_inode->i_nlink);
12248 + goto out_fill; /* success */
12253 + generic_fillattr(inode, st);
12256 + di_read_unlock(dentry, AuLock_IR);
12257 + si_read_unlock(sb);
12261 +/* ---------------------------------------------------------------------- */
12263 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
12267 + struct super_block *sb;
12268 + struct dentry *h_dentry;
12271 + h_dentry = au_h_dptr(dentry, bindex);
12272 + if (unlikely(/* !h_dentry
12273 + || !h_dentry->d_inode
12274 + || !h_dentry->d_inode->i_op
12275 + || */ !h_dentry->d_inode->i_op->readlink))
12278 + err = security_inode_readlink(h_dentry);
12279 + if (unlikely(err))
12282 + sb = dentry->d_sb;
12283 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
12284 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
12285 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
12287 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
12293 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
12297 + aufs_read_lock(dentry, AuLock_IR);
12298 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
12299 + aufs_read_unlock(dentry, AuLock_IR);
12304 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
12308 + mm_segment_t old_fs;
12311 + buf = __getname();
12312 + if (unlikely(!buf))
12315 + aufs_read_lock(dentry, AuLock_IR);
12316 + old_fs = get_fs();
12317 + set_fs(KERNEL_DS);
12318 + err = h_readlink(dentry, au_dbstart(dentry), (char __user *)buf,
12321 + aufs_read_unlock(dentry, AuLock_IR);
12325 + /* will be freed by put_link */
12326 + nd_set_link(nd, buf);
12327 + return NULL; /* success */
12332 + path_put(&nd->path);
12334 + return ERR_PTR(err);
12337 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
12338 + struct nameidata *nd, void *cookie __maybe_unused)
12340 + __putname(nd_get_link(nd));
12343 +/* ---------------------------------------------------------------------- */
12345 +static void aufs_truncate_range(struct inode *inode __maybe_unused,
12346 + loff_t start __maybe_unused,
12347 + loff_t end __maybe_unused)
12352 +/* ---------------------------------------------------------------------- */
12354 +struct inode_operations aufs_symlink_iop = {
12355 + .permission = aufs_permission,
12356 + .setattr = aufs_setattr,
12357 + .getattr = aufs_getattr,
12358 + .readlink = aufs_readlink,
12359 + .follow_link = aufs_follow_link,
12360 + .put_link = aufs_put_link
12363 +struct inode_operations aufs_dir_iop = {
12364 + .create = aufs_create,
12365 + .lookup = aufs_lookup,
12366 + .link = aufs_link,
12367 + .unlink = aufs_unlink,
12368 + .symlink = aufs_symlink,
12369 + .mkdir = aufs_mkdir,
12370 + .rmdir = aufs_rmdir,
12371 + .mknod = aufs_mknod,
12372 + .rename = aufs_rename,
12374 + .permission = aufs_permission,
12375 + .setattr = aufs_setattr,
12376 + .getattr = aufs_getattr
12379 +struct inode_operations aufs_iop = {
12380 + .permission = aufs_permission,
12381 + .setattr = aufs_setattr,
12382 + .getattr = aufs_getattr,
12383 + .truncate_range = aufs_truncate_range
12385 diff -urN linux-2.6.30.org/fs/aufs/i_op_del.c linux-2.6.30/fs/aufs/i_op_del.c
12386 --- linux-2.6.30.org/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
12387 +++ linux-2.6.30/fs/aufs/i_op_del.c 2009-07-21 08:54:19.000000000 +0200
12390 + * Copyright (C) 2005-2009 Junjiro R. Okajima
12392 + * This program, aufs is free software; you can redistribute it and/or modify
12393 + * it under the terms of the GNU General Public License as published by
12394 + * the Free Software Foundation; either version 2 of the License, or
12395 + * (at your option) any later version.
12397 + * This program is distributed in the hope that it will be useful,
12398 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12399 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12400 + * GNU General Public License for more details.
12402 + * You should have received a copy of the GNU General Public License
12403 + * along with this program; if not, write to the Free Software
12404 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12408 + * inode operations (del entry)
12414 + * decide if a new whiteout for @dentry is necessary or not.
12415 + * when it is necessary, prepare the parent dir for the upper branch whose
12416 + * branch index is @bcpup for creation. the actual creation of the whiteout will
12417 + * be done by caller.
12419 + * 0: wh is unnecessary
12420 + * plus: wh is necessary
12423 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
12425 + int need_wh, err;
12426 + aufs_bindex_t bstart;
12427 + struct super_block *sb;
12429 + sb = dentry->d_sb;
12430 + bstart = au_dbstart(dentry);
12431 + if (*bcpup < 0) {
12433 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
12434 + err = AuWbrCopyup(au_sbi(sb), dentry);
12436 + if (unlikely(err < 0))
12440 + AuDebugOn(bstart < *bcpup
12441 + || au_test_ro(sb, *bcpup, dentry->d_inode));
12442 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
12444 + if (*bcpup != bstart) {
12445 + err = au_cpup_dirs(dentry, *bcpup);
12446 + if (unlikely(err))
12450 + aufs_bindex_t old_bend, new_bend, bdiropq = -1;
12452 + old_bend = au_dbend(dentry);
12454 + bdiropq = au_dbdiropq(dentry);
12455 + au_set_dbdiropq(dentry, -1);
12457 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0,
12461 + au_set_dbdiropq(dentry, bdiropq);
12462 + if (unlikely(err < 0))
12464 + new_bend = au_dbend(dentry);
12465 + if (!need_wh && old_bend != new_bend) {
12466 + au_set_h_dptr(dentry, new_bend, NULL);
12467 + au_set_dbend(dentry, old_bend);
12470 + AuDbg("need_wh %d\n", need_wh);
12478 + * simple tests for the del-entry operations.
12479 + * following the checks in vfs, plus the parent-child relationship.
12481 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
12482 + struct dentry *h_parent, int isdir)
12486 + struct dentry *h_dentry, *h_latest;
12487 + struct inode *h_inode;
12489 + h_dentry = au_h_dptr(dentry, bindex);
12490 + h_inode = h_dentry->d_inode;
12491 + if (dentry->d_inode) {
12493 + if (unlikely(!h_inode || !h_inode->i_nlink))
12496 + h_mode = h_inode->i_mode;
12499 + if (unlikely(S_ISDIR(h_mode)))
12501 + } else if (unlikely(!S_ISDIR(h_mode))) {
12506 + /* rename(2) case */
12508 + if (unlikely(h_inode))
12513 + /* expected parent dir is locked */
12514 + if (unlikely(h_parent != h_dentry->d_parent))
12519 + * rmdir a dir may break the consistency on some filesystem.
12520 + * let's try heavy test.
12523 + if (unlikely(au_test_h_perm(h_parent->d_inode, MAY_EXEC | MAY_WRITE)))
12526 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent,
12527 + au_sbr(dentry->d_sb, bindex));
12529 + if (IS_ERR(h_latest))
12531 + if (h_latest == h_dentry)
12540 + * decide the branch where we operate for @dentry. the branch index will be set
12541 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
12542 + * dir for reverting.
12543 + * when a new whiteout is necessary, create it.
12545 +static struct dentry*
12546 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
12547 + struct au_dtime *dt, struct au_pin *pin)
12549 + struct dentry *wh_dentry;
12550 + struct super_block *sb;
12551 + struct path h_path;
12552 + int err, need_wh;
12553 + unsigned int udba;
12554 + aufs_bindex_t bcpup;
12556 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
12557 + wh_dentry = ERR_PTR(need_wh);
12558 + if (unlikely(need_wh < 0))
12561 + sb = dentry->d_sb;
12562 + udba = au_opt_udba(sb);
12564 + err = au_pin(pin, dentry, bcpup, udba,
12565 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12566 + wh_dentry = ERR_PTR(err);
12567 + if (unlikely(err))
12570 + h_path.dentry = au_pinned_h_parent(pin);
12571 + if (udba != AuOpt_UDBA_NONE
12572 + && au_dbstart(dentry) == bcpup) {
12573 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
12574 + wh_dentry = ERR_PTR(err);
12575 + if (unlikely(err))
12579 + h_path.mnt = au_sbr_mnt(sb, bcpup);
12580 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
12581 + wh_dentry = NULL;
12583 + goto out; /* success, no need to create whiteout */
12585 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
12586 + if (!IS_ERR(wh_dentry))
12587 + goto out; /* success */
12588 + /* returns with the parent is locked and wh_dentry is dget-ed */
12593 + return wh_dentry;
12597 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
12598 + * in order to be revertible and save time for removing many child whiteouts
12600 + * returns 1 when there are too many child whiteout and caller should remove
12601 + * them asynchronously. returns 0 when the number of children is enough small to
12602 + * remove now or the branch fs is a remote fs.
12603 + * otherwise return an error.
12605 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
12606 + struct au_nhash *whlist, struct inode *dir)
12608 + int rmdir_later, err, dirwh;
12609 + struct dentry *h_dentry;
12610 + struct super_block *sb;
12612 + sb = dentry->d_sb;
12613 + SiMustAnyLock(sb);
12614 + h_dentry = au_h_dptr(dentry, bindex);
12615 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
12616 + if (unlikely(err))
12619 + /* stop monitoring */
12620 + au_hin_free(au_hi(dentry->d_inode, bindex));
12622 + if (!au_test_fs_remote(h_dentry->d_sb)) {
12623 + dirwh = au_sbi(sb)->si_dirwh;
12624 + rmdir_later = (dirwh <= 1);
12625 + if (!rmdir_later)
12626 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
12629 + return rmdir_later;
12632 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
12633 + if (unlikely(err)) {
12634 + AuIOErr("rmdir %.*s, b%d failed, %d. ignored\n",
12635 + AuDLNPair(h_dentry), bindex, err);
12644 + * final procedure for deleting a entry.
12645 + * maintain dentry and iattr.
12647 +static void epilog(struct inode *dir, struct dentry *dentry,
12648 + aufs_bindex_t bindex)
12650 + struct inode *inode;
12652 + inode = dentry->d_inode;
12654 + inode->i_ctime = dir->i_ctime;
12656 + if (atomic_read(&dentry->d_count) == 1) {
12657 + au_set_h_dptr(dentry, au_dbstart(dentry), NULL);
12658 + au_update_dbstart(dentry);
12660 + if (au_ibstart(dir) == bindex)
12661 + au_cpup_attr_timesizes(dir);
12662 + dir->i_version++;
12666 + * when an error happened, remove the created whiteout and revert everything.
12668 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bwh,
12669 + struct dentry *wh_dentry, struct dentry *dentry,
12670 + struct au_dtime *dt)
12673 + struct path h_path = {
12674 + .dentry = wh_dentry,
12675 + .mnt = au_sbr_mnt(dir->i_sb, bwh)
12678 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bwh), &h_path, dentry);
12680 + au_set_dbwh(dentry, bwh);
12681 + au_dtime_revert(dt);
12685 + AuIOErr("%.*s reverting whiteout failed(%d, %d)\n",
12686 + AuDLNPair(dentry), err, rerr);
12690 +/* ---------------------------------------------------------------------- */
12692 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
12695 + aufs_bindex_t bwh, bindex, bstart;
12696 + struct au_dtime dt;
12697 + struct au_pin pin;
12698 + struct path h_path;
12699 + struct inode *inode, *h_dir;
12700 + struct dentry *parent, *wh_dentry;
12703 + inode = dentry->d_inode;
12704 + if (unlikely(!inode))
12705 + return -ENOENT; /* possible? */
12706 + IMustLock(inode);
12708 + aufs_read_lock(dentry, AuLock_DW);
12709 + parent = dentry->d_parent; /* dir inode is locked */
12710 + di_write_lock_parent(parent);
12712 + bstart = au_dbstart(dentry);
12713 + bwh = au_dbwh(dentry);
12715 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &dt, &pin);
12716 + err = PTR_ERR(wh_dentry);
12717 + if (IS_ERR(wh_dentry))
12720 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
12721 + h_path.dentry = au_h_dptr(dentry, bstart);
12722 + dget(h_path.dentry);
12723 + if (bindex == bstart) {
12724 + h_dir = au_pinned_h_dir(&pin);
12725 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
12727 + /* dir inode is locked */
12728 + h_dir = wh_dentry->d_parent->d_inode;
12729 + IMustLock(h_dir);
12734 + drop_nlink(inode);
12735 + epilog(dir, dentry, bindex);
12737 + /* update target timestamps */
12738 + if (bindex == bstart) {
12739 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
12740 + inode->i_ctime = h_path.dentry->d_inode->i_ctime;
12742 + /* todo: this timestamp may be reverted later */
12743 + inode->i_ctime = h_dir->i_ctime;
12744 + goto out_unlock; /* success */
12751 + rerr = do_revert(err, dir, bwh, wh_dentry, dentry, &dt);
12759 + dput(h_path.dentry);
12761 + di_write_unlock(parent);
12762 + aufs_read_unlock(dentry, AuLock_DW);
12766 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
12768 + int err, rmdir_later;
12769 + aufs_bindex_t bwh, bindex, bstart;
12770 + struct au_dtime dt;
12771 + struct au_pin pin;
12772 + struct inode *inode;
12773 + struct dentry *parent, *wh_dentry, *h_dentry;
12774 + struct au_whtmp_rmdir *args;
12777 + inode = dentry->d_inode;
12778 + err = -ENOENT; /* possible? */
12779 + if (unlikely(!inode))
12781 + IMustLock(inode);
12783 + aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
12785 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
12786 + if (unlikely(!args))
12789 + parent = dentry->d_parent; /* dir inode is locked */
12790 + di_write_lock_parent(parent);
12791 + err = au_test_empty(dentry, &args->whlist);
12792 + if (unlikely(err))
12795 + bstart = au_dbstart(dentry);
12796 + bwh = au_dbwh(dentry);
12798 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &dt, &pin);
12799 + err = PTR_ERR(wh_dentry);
12800 + if (IS_ERR(wh_dentry))
12803 + h_dentry = au_h_dptr(dentry, bstart);
12806 + if (bindex == bstart) {
12807 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
12809 + rmdir_later = err;
12813 + /* stop monitoring */
12814 + au_hin_free(au_hi(inode, bstart));
12816 + /* dir inode is locked */
12817 + IMustLock(wh_dentry->d_parent->d_inode);
12822 + clear_nlink(inode);
12823 + au_set_dbdiropq(dentry, -1);
12824 + epilog(dir, dentry, bindex);
12826 + if (rmdir_later) {
12827 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
12831 + goto out_unpin; /* success */
12839 + rerr = do_revert(err, dir, bwh, wh_dentry, dentry, &dt);
12849 + di_write_unlock(parent);
12851 + au_whtmp_rmdir_free(args);
12853 + aufs_read_unlock(dentry, AuLock_DW);
12857 diff -urN linux-2.6.30.org/fs/aufs/i_op_ren.c linux-2.6.30/fs/aufs/i_op_ren.c
12858 --- linux-2.6.30.org/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
12859 +++ linux-2.6.30/fs/aufs/i_op_ren.c 2009-07-21 08:54:19.000000000 +0200
12862 + * Copyright (C) 2005-2009 Junjiro R. Okajima
12864 + * This program, aufs is free software; you can redistribute it and/or modify
12865 + * it under the terms of the GNU General Public License as published by
12866 + * the Free Software Foundation; either version 2 of the License, or
12867 + * (at your option) any later version.
12869 + * This program is distributed in the hope that it will be useful,
12870 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12871 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12872 + * GNU General Public License for more details.
12874 + * You should have received a copy of the GNU General Public License
12875 + * along with this program; if not, write to the Free Software
12876 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12880 + * inode operation (rename entry)
12881 + * todo: this is crazy monster
12886 +enum { AuSRC, AuDST, AuSrcDst };
12887 +enum { AuPARENT, AuCHILD, AuParentChild };
12889 +#define AuRen_ISDIR 1
12890 +#define AuRen_ISSAMEDIR (1 << 1)
12891 +#define AuRen_WHSRC (1 << 2)
12892 +#define AuRen_WHDST (1 << 3)
12893 +#define AuRen_MNT_WRITE (1 << 4)
12894 +#define AuRen_DT_DSTDIR (1 << 5)
12895 +#define AuRen_DIROPQ (1 << 6)
12896 +#define AuRen_CPUP (1 << 7)
12897 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
12898 +#define au_fset_ren(flags, name) { (flags) |= AuRen_##name; }
12899 +#define au_fclr_ren(flags, name) { (flags) &= ~AuRen_##name; }
12901 +struct au_ren_args {
12903 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
12905 + struct inode *dir, *inode;
12906 + struct au_hinode *hdir;
12907 + struct au_dtime dt[AuParentChild];
12908 + aufs_bindex_t bstart;
12911 +#define src_dentry sd[AuSRC].dentry
12912 +#define src_dir sd[AuSRC].dir
12913 +#define src_inode sd[AuSRC].inode
12914 +#define src_h_dentry sd[AuSRC].h_dentry
12915 +#define src_parent sd[AuSRC].parent
12916 +#define src_h_parent sd[AuSRC].h_parent
12917 +#define src_wh_dentry sd[AuSRC].wh_dentry
12918 +#define src_hdir sd[AuSRC].hdir
12919 +#define src_h_dir sd[AuSRC].hdir->hi_inode
12920 +#define src_dt sd[AuSRC].dt
12921 +#define src_bstart sd[AuSRC].bstart
12923 +#define dst_dentry sd[AuDST].dentry
12924 +#define dst_dir sd[AuDST].dir
12925 +#define dst_inode sd[AuDST].inode
12926 +#define dst_h_dentry sd[AuDST].h_dentry
12927 +#define dst_parent sd[AuDST].parent
12928 +#define dst_h_parent sd[AuDST].h_parent
12929 +#define dst_wh_dentry sd[AuDST].wh_dentry
12930 +#define dst_hdir sd[AuDST].hdir
12931 +#define dst_h_dir sd[AuDST].hdir->hi_inode
12932 +#define dst_dt sd[AuDST].dt
12933 +#define dst_bstart sd[AuDST].bstart
12935 + struct dentry *h_trap;
12936 + struct au_branch *br;
12937 + struct au_hinode *src_hinode;
12938 + struct path h_path;
12939 + struct au_nhash whlist;
12940 + aufs_bindex_t btgt;
12942 + unsigned int flags;
12944 + struct au_whtmp_rmdir *thargs;
12945 + struct dentry *h_dst;
12948 +/* ---------------------------------------------------------------------- */
12951 + * functions for reverting.
12952 + * when an error happened in a single rename systemcall, we should revert
12953 + * everything as if nothing happend.
12954 + * we don't need to revert the copied-up/down the parent dir since they are
12958 +#define RevertFailure(fmt, args...) do { \
12959 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
12960 + ##args, err, rerr); \
12964 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
12968 + au_hin_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
12969 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
12970 + au_hin_imtx_unlock(a->src_hinode);
12972 + RevertFailure("remove diropq %.*s", AuDLNPair(a->src_dentry));
12976 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
12980 + a->h_path.dentry = au_lkup_one(&a->src_dentry->d_name, a->src_h_parent,
12981 + a->br, /*nd*/NULL);
12982 + rerr = PTR_ERR(a->h_path.dentry);
12983 + if (IS_ERR(a->h_path.dentry)) {
12984 + RevertFailure("au_lkup_one %.*s", AuDLNPair(a->src_dentry));
12988 + rerr = vfsub_rename(a->dst_h_dir,
12989 + au_h_dptr(a->src_dentry, a->btgt),
12990 + a->src_h_dir, &a->h_path);
12991 + d_drop(a->h_path.dentry);
12992 + dput(a->h_path.dentry);
12993 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
12995 + RevertFailure("rename %.*s", AuDLNPair(a->src_dentry));
12998 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
13002 + a->h_path.dentry = a->dst_h_dentry;
13003 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*force*/0);
13004 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
13005 + au_set_dbstart(a->src_dentry, a->src_bstart);
13007 + RevertFailure("unlink %.*s", AuDLNPair(a->dst_h_dentry));
13011 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
13015 + a->h_path.dentry = au_lkup_one(&a->dst_dentry->d_name, a->dst_h_parent,
13016 + a->br, /*nd*/NULL);
13017 + rerr = PTR_ERR(a->h_path.dentry);
13018 + if (IS_ERR(a->h_path.dentry)) {
13019 + RevertFailure("lookup %.*s", AuDLNPair(a->dst_dentry));
13022 + if (a->h_path.dentry->d_inode) {
13023 + d_drop(a->h_path.dentry);
13024 + dput(a->h_path.dentry);
13028 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path);
13029 + d_drop(a->h_path.dentry);
13030 + dput(a->h_path.dentry);
13032 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
13033 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
13035 + RevertFailure("rename %.*s", AuDLNPair(a->h_dst));
13038 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
13042 + a->h_path.dentry = a->src_wh_dentry;
13043 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
13045 + RevertFailure("unlink %.*s", AuDLNPair(a->src_wh_dentry));
13048 +static void au_ren_rev_drop(struct au_ren_args *a)
13050 + struct dentry *d, *h_d;
13052 + aufs_bindex_t bend, bindex;
13054 + for (i = 0; i < AuSrcDst; i++) {
13055 + d = a->sd[i].dentry;
13057 + bend = au_dbend(d);
13058 + for (bindex = au_dbstart(d); bindex <= bend; bindex++) {
13059 + h_d = au_h_dptr(d, bindex);
13065 + au_update_dbstart(a->dst_dentry);
13067 + d_drop(a->h_dst);
13069 +#undef RevertFailure
13071 +/* ---------------------------------------------------------------------- */
13074 + * when we have to copyup the renaming entry, do it with the rename-target name
13075 + * in order to minimize the cost (the later actual rename is unnecessary).
13076 + * otherwise rename it on the target branch.
13078 +static int au_ren_or_cpup(struct au_ren_args *a)
13081 + struct dentry *d;
13083 + d = a->src_dentry;
13084 + if (au_dbstart(d) == a->btgt) {
13085 + a->h_path.dentry = a->dst_h_dentry;
13086 + if (au_ftest_ren(a->flags, DIROPQ)
13087 + && au_dbdiropq(d) == a->btgt)
13088 + au_fclr_ren(a->flags, DIROPQ);
13089 + AuDebugOn(au_dbstart(d) != a->btgt);
13090 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
13091 + a->dst_h_dir, &a->h_path);
13093 + struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
13095 + au_fset_ren(a->flags, CPUP);
13096 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13097 + au_set_dbstart(d, a->btgt);
13098 + au_set_h_dptr(d, a->btgt, dget(a->dst_h_dentry));
13099 + err = au_sio_cpup_single(d, a->btgt, a->src_bstart, -1,
13100 + !AuCpup_DTIME, a->dst_parent);
13101 + if (unlikely(err)) {
13102 + au_set_h_dptr(d, a->btgt, NULL);
13103 + au_set_dbstart(d, a->src_bstart);
13105 + mutex_unlock(h_mtx);
13111 +/* cf. aufs_rmdir() */
13112 +static int au_ren_del_whtmp(struct au_ren_args *a)
13115 + struct inode *dir;
13117 + dir = a->dst_dir;
13118 + SiMustAnyLock(dir->i_sb);
13119 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
13120 + au_sbi(dir->i_sb)->si_dirwh)
13121 + || au_test_fs_remote(a->h_dst->d_sb)) {
13122 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
13123 + if (unlikely(err))
13124 + AuWarn("failed removing whtmp dir %.*s (%d), "
13125 + "ignored.\n", AuDLNPair(a->h_dst), err);
13127 + au_nhash_wh_free(&a->thargs->whlist);
13128 + a->thargs->whlist = a->whlist;
13129 + a->whlist.nh_num = 0;
13130 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
13132 + a->thargs = NULL;
13138 +/* make it 'opaque' dir. */
13139 +static int au_ren_diropq(struct au_ren_args *a)
13142 + struct dentry *diropq;
13145 + a->src_hinode = au_hi(a->src_inode, a->btgt);
13146 + au_hin_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
13147 + diropq = au_diropq_create(a->src_dentry, a->btgt);
13148 + au_hin_imtx_unlock(a->src_hinode);
13149 + if (IS_ERR(diropq))
13150 + err = PTR_ERR(diropq);
13156 +static int do_rename(struct au_ren_args *a)
13159 + struct dentry *d, *h_d;
13161 + /* prepare workqueue args for asynchronous rmdir */
13162 + h_d = a->dst_h_dentry;
13163 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
13165 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
13166 + if (unlikely(!a->thargs))
13168 + a->h_dst = dget(h_d);
13171 + /* create whiteout for src_dentry */
13172 + if (au_ftest_ren(a->flags, WHSRC)) {
13174 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
13175 + err = PTR_ERR(a->src_wh_dentry);
13176 + if (IS_ERR(a->src_wh_dentry))
13180 + /* lookup whiteout for dentry */
13181 + if (au_ftest_ren(a->flags, WHDST)) {
13182 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
13184 + err = PTR_ERR(h_d);
13187 + if (!h_d->d_inode)
13190 + a->dst_wh_dentry = h_d;
13193 + /* rename dentry to tmpwh */
13195 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
13196 + if (unlikely(err))
13199 + d = a->dst_dentry;
13200 + au_set_h_dptr(d, a->btgt, NULL);
13201 + err = au_lkup_neg(d, a->btgt);
13202 + if (unlikely(err))
13204 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
13208 + if (a->dst_h_dentry->d_inode && a->src_bstart != a->btgt) {
13209 + struct mutex *h_mtx = &a->src_h_dentry->d_inode->i_mutex;
13211 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13212 + err = au_sio_cpup_simple(a->src_dentry, a->btgt, -1,
13214 + mutex_unlock(h_mtx);
13215 + if (unlikely(err))
13219 + /* rename by vfs_rename or cpup */
13220 + d = a->dst_dentry;
13221 + if (au_ftest_ren(a->flags, ISDIR)
13222 + && (a->dst_wh_dentry
13223 + || au_dbdiropq(d) == a->btgt
13224 + /* hide the lower to keep xino */
13225 + || a->btgt < au_dbend(d)
13226 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
13227 + au_fset_ren(a->flags, DIROPQ);
13228 + err = au_ren_or_cpup(a);
13229 + if (unlikely(err))
13230 + /* leave the copied-up one */
13233 + /* make dir opaque */
13234 + if (au_ftest_ren(a->flags, DIROPQ)) {
13235 + err = au_ren_diropq(a);
13236 + if (unlikely(err))
13240 + /* update target timestamps */
13241 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
13242 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
13243 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
13244 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
13246 + /* remove whiteout for dentry */
13247 + if (a->dst_wh_dentry) {
13248 + a->h_path.dentry = a->dst_wh_dentry;
13249 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
13251 + if (unlikely(err))
13255 + /* remove whtmp */
13257 + au_ren_del_whtmp(a); /* ignore this error */
13260 + goto out_success;
13263 + if (au_ftest_ren(a->flags, DIROPQ))
13264 + au_ren_rev_diropq(err, a);
13266 + if (!au_ftest_ren(a->flags, CPUP))
13267 + au_ren_rev_rename(err, a);
13269 + au_ren_rev_cpup(err, a);
13272 + au_ren_rev_whtmp(err, a);
13274 + dput(a->dst_wh_dentry);
13275 + a->dst_wh_dentry = NULL;
13277 + if (a->src_wh_dentry)
13278 + au_ren_rev_whsrc(err, a);
13279 + au_ren_rev_drop(a);
13281 + dput(a->src_wh_dentry);
13282 + dput(a->dst_wh_dentry);
13286 + au_whtmp_rmdir_free(a->thargs);
13287 + a->thargs = NULL;
13293 +/* ---------------------------------------------------------------------- */
13296 + * test if @dentry dir can be rename destination or not.
13297 + * success means, it is a logically empty dir.
13299 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
13301 + return au_test_empty(dentry, whlist);
13305 + * test if @dentry dir can be rename source or not.
13306 + * if it can, return 0 and @children is filled.
13308 + * - it is a logically empty dir.
13309 + * - or, it exists on writable branch and has no children including whiteouts
13310 + * on the lower branch.
13312 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
13315 + aufs_bindex_t bstart;
13317 + bstart = au_dbstart(dentry);
13318 + if (bstart != btgt) {
13319 + struct au_nhash whlist;
13321 + SiMustAnyLock(dentry->d_sb);
13322 + err = au_nhash_alloc(&whlist, au_sbi(dentry->d_sb)->si_rdhash,
13324 + if (unlikely(err))
13326 + err = au_test_empty(dentry, &whlist);
13327 + au_nhash_wh_free(&whlist);
13331 + if (bstart == au_dbtaildir(dentry))
13332 + return 0; /* success */
13334 + err = au_test_empty_lower(dentry);
13337 + if (err == -ENOTEMPTY) {
13338 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
13339 + " is not supported\n");
13345 +/* side effect: sets whlist and h_dentry */
13346 +static int au_ren_may_dir(struct au_ren_args *a)
13349 + struct dentry *d;
13351 + d = a->dst_dentry;
13352 + SiMustAnyLock(d->d_sb);
13353 + err = au_nhash_alloc(&a->whlist, au_sbi(d->d_sb)->si_rdhash, GFP_NOFS);
13354 + if (unlikely(err))
13358 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
13359 + au_set_dbstart(d, a->dst_bstart);
13360 + err = may_rename_dstdir(d, &a->whlist);
13361 + au_set_dbstart(d, a->btgt);
13363 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
13364 + if (unlikely(err))
13367 + d = a->src_dentry;
13368 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
13369 + if (au_ftest_ren(a->flags, ISDIR)) {
13370 + err = may_rename_srcdir(d, a->btgt);
13371 + if (unlikely(err)) {
13372 + au_nhash_wh_free(&a->whlist);
13373 + a->whlist.nh_num = 0;
13380 +/* ---------------------------------------------------------------------- */
13383 + * simple tests for rename.
13384 + * following the checks in vfs, plus the parent-child relationship.
13386 +static int au_may_ren(struct au_ren_args *a)
13389 + struct inode *h_inode;
13391 + if (a->src_bstart == a->btgt) {
13392 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
13393 + au_ftest_ren(a->flags, ISDIR));
13394 + if (unlikely(err))
13397 + if (unlikely(a->src_h_dentry == a->h_trap))
13402 + if (a->dst_bstart != a->btgt)
13406 + h_inode = a->dst_h_dentry->d_inode;
13407 + isdir = !!au_ftest_ren(a->flags, ISDIR);
13408 + if (!a->dst_dentry->d_inode) {
13409 + if (unlikely(h_inode))
13411 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
13414 + if (unlikely(!h_inode || !h_inode->i_nlink))
13416 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
13418 + if (unlikely(err))
13420 + err = -ENOTEMPTY;
13421 + if (unlikely(a->dst_h_dentry == a->h_trap))
13427 + if (unlikely(err == -ENOENT || err == -EEXIST))
13432 +/* ---------------------------------------------------------------------- */
13437 + * - src_dir and dir by lock_rename()
13438 + * - inode if exitsts
13441 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
13443 + * + di_write_lock2_child()
13444 + * + di_write_lock_child()
13445 + * + ii_write_lock_child()
13446 + * + di_write_lock_child2()
13447 + * + ii_write_lock_child2()
13448 + * + src_parent and parent
13449 + * + di_write_lock_parent()
13450 + * + ii_write_lock_parent()
13451 + * + di_write_lock_parent2()
13452 + * + ii_write_lock_parent2()
13453 + * + lower src_dir and dir by vfsub_lock_rename()
13454 + * + verify the every relationships between child and parent. if any
13455 + * of them failed, unlock all and return -EBUSY.
13457 +static void au_ren_unlock(struct au_ren_args *a)
13459 + struct super_block *sb;
13461 + sb = a->dst_dentry->d_sb;
13462 + if (au_ftest_ren(a->flags, MNT_WRITE))
13463 + mnt_drop_write(a->br->br_mnt);
13464 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
13465 + a->dst_h_parent, a->dst_hdir);
13468 +static int au_ren_lock(struct au_ren_args *a)
13471 + unsigned int udba;
13474 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
13475 + a->src_hdir = au_hi(a->src_dir, a->btgt);
13476 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
13477 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
13478 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
13479 + a->dst_h_parent, a->dst_hdir);
13480 + udba = au_opt_udba(a->src_dentry->d_sb);
13481 + if (au_dbstart(a->src_dentry) == a->btgt)
13482 + err = au_h_verify(a->src_h_dentry, udba,
13483 + a->src_h_parent->d_inode, a->src_h_parent,
13485 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
13486 + err = au_h_verify(a->dst_h_dentry, udba,
13487 + a->dst_h_parent->d_inode, a->dst_h_parent,
13490 + err = mnt_want_write(a->br->br_mnt);
13491 + if (unlikely(err))
13493 + au_fset_ren(a->flags, MNT_WRITE);
13494 + goto out; /* success */
13497 + err = au_busy_or_stale();
13500 + au_ren_unlock(a);
13505 +/* ---------------------------------------------------------------------- */
13507 +static void au_ren_refresh_dir(struct au_ren_args *a)
13509 + struct inode *dir;
13511 + dir = a->dst_dir;
13512 + dir->i_version++;
13513 + if (au_ftest_ren(a->flags, ISDIR)) {
13514 + /* is this updating defined in POSIX? */
13515 + au_cpup_attr_timesizes(a->src_inode);
13516 + au_cpup_attr_nlink(dir, /*force*/1);
13517 + if (a->dst_inode) {
13518 + clear_nlink(a->dst_inode);
13519 + au_cpup_attr_timesizes(a->dst_inode);
13522 + if (au_ibstart(dir) == a->btgt)
13523 + au_cpup_attr_timesizes(dir);
13525 + if (au_ftest_ren(a->flags, ISSAMEDIR))
13528 + dir = a->src_dir;
13529 + dir->i_version++;
13530 + if (au_ftest_ren(a->flags, ISDIR))
13531 + au_cpup_attr_nlink(dir, /*force*/1);
13532 + if (au_ibstart(dir) == a->btgt)
13533 + au_cpup_attr_timesizes(dir);
13536 +static void au_ren_refresh(struct au_ren_args *a)
13538 + aufs_bindex_t bend, bindex;
13539 + struct dentry *d, *h_d;
13540 + struct inode *i, *h_i;
13541 + struct super_block *sb;
13543 + d = a->src_dentry;
13544 + au_set_dbwh(d, -1);
13545 + bend = au_dbend(d);
13546 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
13547 + h_d = au_h_dptr(d, bindex);
13549 + au_set_h_dptr(d, bindex, NULL);
13551 + au_set_dbend(d, a->btgt);
13554 + i = a->src_inode;
13555 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
13556 + return; /* success */
13558 + bend = au_ibend(i);
13559 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
13560 + h_i = au_h_iptr(i, bindex);
13562 + au_xino_write0(sb, bindex, h_i->i_ino, 0);
13563 + /* ignore this error */
13564 + au_set_h_iptr(i, bindex, NULL, 0);
13567 + au_set_ibend(i, a->btgt);
13570 +/* ---------------------------------------------------------------------- */
13572 +/* mainly for link(2) and rename(2) */
13573 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
13575 + aufs_bindex_t bdiropq, bwh;
13576 + struct dentry *parent;
13577 + struct au_branch *br;
13579 + parent = dentry->d_parent;
13580 + IMustLock(parent->d_inode); /* dir is locked */
13582 + bdiropq = au_dbdiropq(parent);
13583 + bwh = au_dbwh(dentry);
13584 + br = au_sbr(dentry->d_sb, btgt);
13585 + if (au_br_rdonly(br)
13586 + || (0 <= bdiropq && bdiropq < btgt)
13587 + || (0 <= bwh && bwh < btgt))
13590 + AuDbg("btgt %d\n", btgt);
13594 +/* sets src_bstart, dst_bstart and btgt */
13595 +static int au_ren_wbr(struct au_ren_args *a)
13598 + struct au_wr_dir_args wr_dir_args = {
13599 + /* .force_btgt = -1, */
13600 + .flags = AuWrDir_ADD_ENTRY
13603 + a->src_bstart = au_dbstart(a->src_dentry);
13604 + a->dst_bstart = au_dbstart(a->dst_dentry);
13605 + if (au_ftest_ren(a->flags, ISDIR))
13606 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
13607 + wr_dir_args.force_btgt = a->src_bstart;
13608 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
13609 + wr_dir_args.force_btgt = a->dst_bstart;
13610 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
13611 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
13617 +static void au_ren_dt(struct au_ren_args *a)
13619 + a->h_path.dentry = a->src_h_parent;
13620 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
13621 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
13622 + a->h_path.dentry = a->dst_h_parent;
13623 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
13626 + au_fclr_ren(a->flags, DT_DSTDIR);
13627 + if (!au_ftest_ren(a->flags, ISDIR))
13630 + a->h_path.dentry = a->src_h_dentry;
13631 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
13632 + if (a->dst_h_dentry->d_inode) {
13633 + au_fset_ren(a->flags, DT_DSTDIR);
13634 + a->h_path.dentry = a->dst_h_dentry;
13635 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
13639 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
13641 + struct dentry *h_d;
13642 + struct mutex *h_mtx;
13644 + au_dtime_revert(a->src_dt + AuPARENT);
13645 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
13646 + au_dtime_revert(a->dst_dt + AuPARENT);
13648 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
13649 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
13650 + h_mtx = &h_d->d_inode->i_mutex;
13651 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13652 + au_dtime_revert(a->src_dt + AuCHILD);
13653 + mutex_unlock(h_mtx);
13655 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
13656 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
13657 + h_mtx = &h_d->d_inode->i_mutex;
13658 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13659 + au_dtime_revert(a->dst_dt + AuCHILD);
13660 + mutex_unlock(h_mtx);
13665 +/* ---------------------------------------------------------------------- */
13667 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
13668 + struct inode *_dst_dir, struct dentry *_dst_dentry)
13671 + /* reduce stack space */
13672 + struct au_ren_args *a;
13674 + IMustLock(_src_dir);
13675 + IMustLock(_dst_dir);
13678 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
13679 + a = kzalloc(sizeof(*a), GFP_NOFS);
13680 + if (unlikely(!a))
13683 + a->src_dir = _src_dir;
13684 + a->src_dentry = _src_dentry;
13685 + a->src_inode = a->src_dentry->d_inode;
13686 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
13687 + a->dst_dir = _dst_dir;
13688 + a->dst_dentry = _dst_dentry;
13689 + a->dst_inode = a->dst_dentry->d_inode;
13690 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
13691 + if (a->dst_inode) {
13692 + IMustLock(a->dst_inode);
13693 + au_igrab(a->dst_inode);
13697 + if (S_ISDIR(a->src_inode->i_mode)) {
13698 + au_fset_ren(a->flags, ISDIR);
13699 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
13701 + aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
13702 + AuLock_DIR | AuLock_FLUSH);
13704 + aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
13707 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
13708 + di_write_lock_parent(a->dst_parent);
13710 + /* which branch we process */
13711 + err = au_ren_wbr(a);
13712 + if (unlikely(err < 0))
13714 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
13715 + a->h_path.mnt = a->br->br_mnt;
13717 + /* are they available to be renamed */
13718 + err = au_ren_may_dir(a);
13719 + if (unlikely(err))
13722 + /* prepare the writable parent dir on the same branch */
13723 + if (a->dst_bstart == a->btgt) {
13724 + au_fset_ren(a->flags, WHDST);
13726 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
13727 + if (unlikely(err))
13728 + goto out_children;
13731 + if (a->src_dir != a->dst_dir) {
13733 + * this temporary unlock is safe,
13734 + * because both dir->i_mutex are locked.
13736 + di_write_unlock(a->dst_parent);
13737 + di_write_lock_parent(a->src_parent);
13738 + err = au_wr_dir_need_wh(a->src_dentry,
13739 + au_ftest_ren(a->flags, ISDIR),
13741 + di_write_unlock(a->src_parent);
13742 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
13743 + au_fclr_ren(a->flags, ISSAMEDIR);
13745 + err = au_wr_dir_need_wh(a->src_dentry,
13746 + au_ftest_ren(a->flags, ISDIR),
13748 + if (unlikely(err < 0))
13749 + goto out_children;
13751 + au_fset_ren(a->flags, WHSRC);
13753 + /* lock them all */
13754 + err = au_ren_lock(a);
13755 + if (unlikely(err))
13756 + goto out_children;
13758 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE)) {
13759 + err = au_may_ren(a);
13760 + if (unlikely(err))
13764 + /* store timestamps to be revertible */
13768 + err = do_rename(a);
13769 + if (unlikely(err))
13772 + /* update dir attributes */
13773 + au_ren_refresh_dir(a);
13775 + /* dput/iput all lower dentries */
13776 + au_ren_refresh(a);
13778 + goto out_hdir; /* success */
13781 + au_ren_rev_dt(err, a);
13783 + au_ren_unlock(a);
13785 + au_nhash_wh_free(&a->whlist);
13787 + if (unlikely(err && au_ftest_ren(a->flags, ISDIR))) {
13788 + au_update_dbstart(a->dst_dentry);
13789 + d_drop(a->dst_dentry);
13792 + d_move(a->src_dentry, a->dst_dentry);
13793 + if (au_ftest_ren(a->flags, ISSAMEDIR))
13794 + di_write_unlock(a->dst_parent);
13796 + di_write_unlock2(a->src_parent, a->dst_parent);
13797 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
13799 + iput(a->dst_inode);
13801 + au_whtmp_rmdir_free(a->thargs);
13806 diff -urN linux-2.6.30.org/fs/aufs/Kconfig linux-2.6.30/fs/aufs/Kconfig
13807 --- linux-2.6.30.org/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
13808 +++ linux-2.6.30/fs/aufs/Kconfig 2009-07-21 08:54:18.000000000 +0200
13811 + tristate "Aufs (Advanced multi layered unification filesystem) support"
13812 + depends on EXPERIMENTAL
13814 + Aufs is a stackable unification filesystem such as Unionfs,
13815 + which unifies several directories and provides a merged single
13817 + In the early days, aufs was entirely re-designed and
13818 + re-implemented Unionfs Version 1.x series. Introducing many
13819 + original ideas, approaches and improvements, it becomes totally
13820 + different from Unionfs while keeping the basic features.
13824 + prompt "Maximum number of branches"
13825 + default AUFS_BRANCH_MAX_127
13827 + Specifies the maximum number of branches (or member directories)
13828 + in a single aufs. The larger value consumes more system
13829 + resources and has a minor impact to performance.
13830 +config AUFS_BRANCH_MAX_127
13833 + Specifies the maximum number of branches (or member directories)
13834 + in a single aufs. The larger value consumes more system
13835 + resources and has a minor impact to performance.
13836 +config AUFS_BRANCH_MAX_511
13839 + Specifies the maximum number of branches (or member directories)
13840 + in a single aufs. The larger value consumes more system
13841 + resources and has a minor impact to performance.
13842 +config AUFS_BRANCH_MAX_1023
13845 + Specifies the maximum number of branches (or member directories)
13846 + in a single aufs. The larger value consumes more system
13847 + resources and has a minor impact to performance.
13848 +config AUFS_BRANCH_MAX_32767
13851 + Specifies the maximum number of branches (or member directories)
13852 + in a single aufs. The larger value consumes more system
13853 + resources and has a minor impact to performance.
13856 +config AUFS_HINOTIFY
13857 + bool "Use inotify to detect actions on a branch"
13858 + depends on INOTIFY
13860 + If you want to modify files on branches directly, eg. bypassing aufs,
13861 + and want aufs to detect the changes of them fully, then enable this
13862 + option and use 'udba=inotify' mount option.
13863 + It will have a negative impact to the performance.
13864 + See detail in aufs.5.
13866 +config AUFS_EXPORT
13867 + bool "NFS-exportable aufs"
13868 + depends on (AUFS_FS = y && EXPORTFS = y) || (AUFS_FS = m && EXPORTFS)
13870 + If you want to export your mounted aufs via NFS, then enable this
13871 + option. There are several requirements for this configuration.
13872 + See detail in aufs.5.
13875 + bool "Show whiteouts"
13877 + If you want to make the whiteouts in aufs visible, then enable
13878 + this option and specify 'shwh' mount option. Although it may
13879 + sounds like philosophy or something, but in technically it
13880 + simply shows the name of whiteout with keeping its behaviour.
13882 +config AUFS_BR_RAMFS
13883 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
13885 + If you want to use ramfs as an aufs branch fs, then enable this
13886 + option. Generally tmpfs is recommended.
13887 + Aufs prohibited them to be a branch fs by default, because
13888 + initramfs becomes unusable after switch_root or something
13889 + generally. If you sets initramfs as an aufs branch and boot your
13890 + system by switch_root, you will meet a problem easily since the
13891 + files in initramfs may be inaccessible.
13892 + Unless you are going to use ramfs as an aufs branch fs without
13893 + switch_root or something, leave it N.
13895 +config AUFS_BR_FUSE
13896 + bool "Fuse fs as an aufs branch"
13897 + depends on FUSE_FS
13900 + If you want to use fuse-based userspace filesystem as an aufs
13901 + branch fs, then enable this option.
13902 + It implements the internal poll(2) operation which is
13903 + implemented by fuse only (curretnly).
13906 + bool "Debug aufs"
13908 + Enable this to compile aufs internal debug code.
13909 + It will have a negative impact to the performance.
13911 +config AUFS_MAGIC_SYSRQ
13913 + depends on AUFS_DEBUG && MAGIC_SYSRQ
13916 + Automatic configuration for internal use.
13917 + When aufs supports Magic SysRq, enabled automatically.
13919 +config AUFS_BDEV_LOOP
13921 + depends on BLK_DEV_LOOP
13924 + Automatic configuration for internal use.
13925 + Convert =[ym] into =y.
13927 +config AUFS_INO_T_64
13929 + depends on AUFS_EXPORT
13930 + depends on 64BIT && !(ALPHA || S390)
13933 + Automatic configuration for internal use.
13934 + /* typedef unsigned long/int __kernel_ino_t */
13935 + /* alpha and s390x are int */
13940 + Automatic configuration for internal use.
13942 diff -urN linux-2.6.30.org/fs/aufs/loop.c linux-2.6.30/fs/aufs/loop.c
13943 --- linux-2.6.30.org/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
13944 +++ linux-2.6.30/fs/aufs/loop.c 2009-07-21 08:54:19.000000000 +0200
13947 + * Copyright (C) 2005-2009 Junjiro R. Okajima
13949 + * This program, aufs is free software; you can redistribute it and/or modify
13950 + * it under the terms of the GNU General Public License as published by
13951 + * the Free Software Foundation; either version 2 of the License, or
13952 + * (at your option) any later version.
13954 + * This program is distributed in the hope that it will be useful,
13955 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13956 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13957 + * GNU General Public License for more details.
13959 + * You should have received a copy of the GNU General Public License
13960 + * along with this program; if not, write to the Free Software
13961 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13965 + * support for loopback block device as a branch
13968 +#include <linux/loop.h>
13972 + * test if two lower dentries have overlapping branches.
13974 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_d1,
13975 + struct dentry *h_d2)
13977 + struct inode *h_inode;
13978 + struct loop_device *l;
13980 + h_inode = h_d1->d_inode;
13981 + if (MAJOR(h_inode->i_sb->s_dev) != LOOP_MAJOR)
13984 + l = h_inode->i_sb->s_bdev->bd_disk->private_data;
13985 + h_d1 = l->lo_backing_file->f_dentry;
13986 + /* h_d1 can be local NFS. in this case aufs cannot detect the loop */
13987 + if (unlikely(h_d1->d_sb == sb))
13989 + return !!au_test_subdir(h_d1, h_d2);
13992 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
13993 +int au_test_loopback_kthread(void)
13995 + const char c = current->comm[4];
13997 + return current->mm == NULL
13998 + && '0' <= c && c <= '9'
13999 + && strncmp(current->comm, "loop", 4) == 0;
14001 diff -urN linux-2.6.30.org/fs/aufs/loop.h linux-2.6.30/fs/aufs/loop.h
14002 --- linux-2.6.30.org/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
14003 +++ linux-2.6.30/fs/aufs/loop.h 2009-07-21 08:54:19.000000000 +0200
14006 + * Copyright (C) 2005-2009 Junjiro R. Okajima
14008 + * This program, aufs is free software; you can redistribute it and/or modify
14009 + * it under the terms of the GNU General Public License as published by
14010 + * the Free Software Foundation; either version 2 of the License, or
14011 + * (at your option) any later version.
14013 + * This program is distributed in the hope that it will be useful,
14014 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14015 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14016 + * GNU General Public License for more details.
14018 + * You should have received a copy of the GNU General Public License
14019 + * along with this program; if not, write to the Free Software
14020 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14024 + * support for loopback mount as a branch
14027 +#ifndef __AUFS_LOOP_H__
14028 +#define __AUFS_LOOP_H__
14033 +struct super_block;
14035 +#ifdef CONFIG_AUFS_BDEV_LOOP
14037 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_d1,
14038 + struct dentry *h_d2);
14039 +int au_test_loopback_kthread(void);
14042 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_d1,
14043 + struct dentry *h_d2)
14048 +static inline int au_test_loopback_kthread(void)
14052 +#endif /* BLK_DEV_LOOP */
14054 +#endif /* __KERNEL__ */
14055 +#endif /* __AUFS_LOOP_H__ */
14056 diff -urN linux-2.6.30.org/fs/aufs/magic.mk linux-2.6.30/fs/aufs/magic.mk
14057 --- linux-2.6.30.org/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
14058 +++ linux-2.6.30/fs/aufs/magic.mk 2009-07-21 08:54:19.000000000 +0200
14061 +# defined in ${srctree}/fs/fuse/inode.c
14063 +ifdef CONFIG_FUSE_FS
14064 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
14067 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
14069 +ifdef CONFIG_OCFS2_FS
14070 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
14073 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
14075 +ifdef CONFIG_OCFS2_FS_O2CB
14076 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
14079 +# defined in ${srctree}/fs/ramfs/inode.c
14081 +ccflags-y += -DRAMFS_MAGIC=0x858458f6
14083 +# defined in ${srctree}/fs/cifs/cifsfs.c
14085 +ifdef CONFIG_CIFS_FS
14086 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
14089 +# defined in ${srctree}/fs/xfs/xfs_sb.h
14091 +ifdef CONFIG_XFS_FS
14092 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
14095 +# defined in ${srctree}/fs/configfs/mount.c
14097 +ifdef CONFIG_CONFIGFS_FS
14098 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
14101 +# defined in ${srctree}/fs/9p/v9fs.h
14103 +ifdef CONFIG_9P_FS
14104 +ccflags-y += -DV9FS_MAGIC=0x01021997
14107 +# defined in ${srctree}/fs/ubifs/ubifs.h
14109 +ifdef CONFIG_UBIFS_FS
14110 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
14112 diff -urN linux-2.6.30.org/fs/aufs/Makefile linux-2.6.30/fs/aufs/Makefile
14113 --- linux-2.6.30.org/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
14114 +++ linux-2.6.30/fs/aufs/Makefile 2009-07-21 08:54:18.000000000 +0200
14117 +include ${src}/magic.mk
14118 +-include ${src}/priv_def.mk
14120 +obj-$(CONFIG_AUFS_FS) += aufs.o
14121 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
14122 + wkq.o vfsub.o dcsub.o \
14123 + cpup.o whout.o plink.o wbr_policy.o \
14124 + dinfo.o dentry.o \
14125 + finfo.o file.o f_op.o \
14127 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
14131 +aufs-$(CONFIG_SYSFS) += sysfs.o
14132 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
14133 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
14134 +aufs-$(CONFIG_AUFS_HINOTIFY) += hinotify.o
14135 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
14136 +aufs-$(CONFIG_AUFS_POLL) += poll.o
14137 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
14138 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
14139 diff -urN linux-2.6.30.org/fs/aufs/module.c linux-2.6.30/fs/aufs/module.c
14140 --- linux-2.6.30.org/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
14141 +++ linux-2.6.30/fs/aufs/module.c 2009-07-21 08:54:19.000000000 +0200
14144 + * Copyright (C) 2005-2009 Junjiro R. Okajima
14146 + * This program, aufs is free software; you can redistribute it and/or modify
14147 + * it under the terms of the GNU General Public License as published by
14148 + * the Free Software Foundation; either version 2 of the License, or
14149 + * (at your option) any later version.
14151 + * This program is distributed in the hope that it will be useful,
14152 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14153 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14154 + * GNU General Public License for more details.
14156 + * You should have received a copy of the GNU General Public License
14157 + * along with this program; if not, write to the Free Software
14158 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14162 + * module global variables and operations
14165 +#include <linux/module.h>
14166 +#include <linux/seq_file.h>
14169 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
14171 + if (new_sz <= nused)
14174 + p = krealloc(p, new_sz, gfp);
14176 + memset(p + nused, 0, new_sz - nused);
14180 +/* ---------------------------------------------------------------------- */
14185 +struct kmem_cache *au_cachep[AuCache_Last];
14186 +static int __init au_cache_init(void)
14188 + au_cachep[AuCache_DINFO] = AuCache(au_dinfo);
14189 + if (au_cachep[AuCache_DINFO])
14190 + au_cachep[AuCache_ICNTNR] = AuCache(au_icntnr);
14191 + if (au_cachep[AuCache_ICNTNR])
14192 + au_cachep[AuCache_FINFO] = AuCache(au_finfo);
14193 + if (au_cachep[AuCache_FINFO])
14194 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
14195 + if (au_cachep[AuCache_VDIR])
14196 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
14197 + if (au_cachep[AuCache_DEHSTR])
14203 +static void au_cache_fin(void)
14206 + for (i = 0; i < AuCache_Last; i++)
14207 + if (au_cachep[i]) {
14208 + kmem_cache_destroy(au_cachep[i]);
14209 + au_cachep[i] = NULL;
14213 +/* ---------------------------------------------------------------------- */
14215 +int au_dir_roflags;
14218 + * functions for module interface.
14220 +MODULE_LICENSE("GPL");
14221 +/* MODULE_LICENSE("GPL v2"); */
14222 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
14223 +MODULE_DESCRIPTION(AUFS_NAME
14224 + " -- Advanced multi layered unification filesystem");
14225 +MODULE_VERSION(AUFS_VERSION);
14227 +/* it should be 'byte', but param_set_byte() prints it by "%c" */
14228 +short aufs_nwkq = AUFS_NWKQ_DEF;
14229 +MODULE_PARM_DESC(nwkq, "the number of workqueue thread, " AUFS_WKQ_NAME);
14230 +module_param_named(nwkq, aufs_nwkq, short, S_IRUGO);
14232 +/* this module parameter has no meaning when SYSFS is disabled */
14233 +int sysaufs_brs = 1;
14234 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
14235 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
14237 +/* ---------------------------------------------------------------------- */
14239 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
14241 +int au_seq_path(struct seq_file *seq, struct path *path)
14243 + return seq_path(seq, path, au_esc_chars);
14246 +/* ---------------------------------------------------------------------- */
14248 +static int __init aufs_init(void)
14253 + p = au_esc_chars;
14254 + for (i = 1; i <= ' '; i++)
14260 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
14262 + sysaufs_brs_init();
14266 + if (unlikely(aufs_nwkq <= 0))
14269 + err = sysaufs_init();
14270 + if (unlikely(err))
14272 + err = au_wkq_init();
14273 + if (unlikely(err))
14274 + goto out_sysaufs;
14275 + err = au_hinotify_init();
14276 + if (unlikely(err))
14278 + err = au_sysrq_init();
14279 + if (unlikely(err))
14281 + err = au_cache_init();
14282 + if (unlikely(err))
14284 + err = register_filesystem(&aufs_fs_type);
14285 + if (unlikely(err))
14287 + pr_info(AUFS_NAME " " AUFS_VERSION "\n");
14288 + goto out; /* success */
14295 + au_hinotify_fin();
14304 +static void __exit aufs_exit(void)
14306 + unregister_filesystem(&aufs_fs_type);
14309 + au_hinotify_fin();
14314 +module_init(aufs_init);
14315 +module_exit(aufs_exit);
14316 diff -urN linux-2.6.30.org/fs/aufs/module.h linux-2.6.30/fs/aufs/module.h
14317 --- linux-2.6.30.org/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
14318 +++ linux-2.6.30/fs/aufs/module.h 2009-07-21 08:54:19.000000000 +0200
14321 + * Copyright (C) 2005-2009 Junjiro R. Okajima
14323 + * This program, aufs is free software; you can redistribute it and/or modify
14324 + * it under the terms of the GNU General Public License as published by
14325 + * the Free Software Foundation; either version 2 of the License, or
14326 + * (at your option) any later version.
14328 + * This program is distributed in the hope that it will be useful,
14329 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14330 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14331 + * GNU General Public License for more details.
14333 + * You should have received a copy of the GNU General Public License
14334 + * along with this program; if not, write to the Free Software
14335 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14339 + * module initialization and module-global
14342 +#ifndef __AUFS_MODULE_H__
14343 +#define __AUFS_MODULE_H__
14347 +#include <linux/slab.h>
14352 +/* module parameters */
14353 +extern short aufs_nwkq;
14354 +extern int sysaufs_brs;
14356 +/* ---------------------------------------------------------------------- */
14358 +extern int au_dir_roflags;
14360 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
14361 +int au_seq_path(struct seq_file *seq, struct path *path);
14363 +/* ---------------------------------------------------------------------- */
14372 +#ifdef CONFIG_AUFS_HINOTIFY
14373 + AuCache_HINOTIFY,
14378 +#define AuCache(type) KMEM_CACHE(type, SLAB_RECLAIM_ACCOUNT)
14380 +extern struct kmem_cache *au_cachep[];
14382 +#define AuCacheFuncs(name, index) \
14383 +static inline void *au_cache_alloc_##name(void) \
14384 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
14385 +static inline void au_cache_free_##name(void *p) \
14386 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
14388 +AuCacheFuncs(dinfo, DINFO);
14389 +AuCacheFuncs(icntnr, ICNTNR);
14390 +AuCacheFuncs(finfo, FINFO);
14391 +AuCacheFuncs(vdir, VDIR);
14392 +AuCacheFuncs(dehstr, DEHSTR);
14394 +/* ---------------------------------------------------------------------- */
14396 +#endif /* __KERNEL__ */
14397 +#endif /* __AUFS_MODULE_H__ */
14398 diff -urN linux-2.6.30.org/fs/aufs/opts.c linux-2.6.30/fs/aufs/opts.c
14399 --- linux-2.6.30.org/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
14400 +++ linux-2.6.30/fs/aufs/opts.c 2009-07-21 08:54:19.000000000 +0200
14403 + * Copyright (C) 2005-2009 Junjiro R. Okajima
14405 + * This program, aufs is free software; you can redistribute it and/or modify
14406 + * it under the terms of the GNU General Public License as published by
14407 + * the Free Software Foundation; either version 2 of the License, or
14408 + * (at your option) any later version.
14410 + * This program is distributed in the hope that it will be useful,
14411 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14412 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14413 + * GNU General Public License for more details.
14415 + * You should have received a copy of the GNU General Public License
14416 + * along with this program; if not, write to the Free Software
14417 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14421 + * mount options/flags
14424 +#include <linux/file.h>
14425 +#include <linux/namei.h>
14426 +#include <linux/types.h> /* a distribution requires */
14427 +#include <linux/parser.h>
14430 +/* ---------------------------------------------------------------------- */
14434 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
14435 + Opt_idel, Opt_imod, Opt_ireorder,
14436 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
14437 + Opt_rdblk_def, Opt_rdhash_def,
14438 + Opt_xino, Opt_zxino, Opt_noxino,
14439 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
14440 + Opt_trunc_xino_path, Opt_itrunc_xino,
14441 + Opt_trunc_xib, Opt_notrunc_xib,
14442 + Opt_shwh, Opt_noshwh,
14443 + Opt_plink, Opt_noplink, Opt_list_plink,
14445 + /* Opt_lock, Opt_unlock, */
14446 + Opt_cmd, Opt_cmd_args,
14447 + Opt_diropq_a, Opt_diropq_w,
14448 + Opt_warn_perm, Opt_nowarn_perm,
14449 + Opt_wbr_copyup, Opt_wbr_create,
14450 + Opt_refrof, Opt_norefrof,
14451 + Opt_verbose, Opt_noverbose,
14452 + Opt_sum, Opt_nosum, Opt_wsum,
14453 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
14456 +static match_table_t options = {
14457 + {Opt_br, "br=%s"},
14458 + {Opt_br, "br:%s"},
14460 + {Opt_add, "add=%d:%s"},
14461 + {Opt_add, "add:%d:%s"},
14462 + {Opt_add, "ins=%d:%s"},
14463 + {Opt_add, "ins:%d:%s"},
14464 + {Opt_append, "append=%s"},
14465 + {Opt_append, "append:%s"},
14466 + {Opt_prepend, "prepend=%s"},
14467 + {Opt_prepend, "prepend:%s"},
14469 + {Opt_del, "del=%s"},
14470 + {Opt_del, "del:%s"},
14471 + /* {Opt_idel, "idel:%d"}, */
14472 + {Opt_mod, "mod=%s"},
14473 + {Opt_mod, "mod:%s"},
14474 + /* {Opt_imod, "imod:%d:%s"}, */
14476 + {Opt_dirwh, "dirwh=%d"},
14478 + {Opt_xino, "xino=%s"},
14479 + {Opt_noxino, "noxino"},
14480 + {Opt_trunc_xino, "trunc_xino"},
14481 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
14482 + {Opt_notrunc_xino, "notrunc_xino"},
14483 + {Opt_trunc_xino_path, "trunc_xino=%s"},
14484 + {Opt_itrunc_xino, "itrunc_xino=%d"},
14485 + /* {Opt_zxino, "zxino=%s"}, */
14486 + {Opt_trunc_xib, "trunc_xib"},
14487 + {Opt_notrunc_xib, "notrunc_xib"},
14489 + {Opt_plink, "plink"},
14490 + {Opt_noplink, "noplink"},
14491 +#ifdef CONFIG_AUFS_DEBUG
14492 + {Opt_list_plink, "list_plink"},
14495 + {Opt_udba, "udba=%s"},
14497 + {Opt_diropq_a, "diropq=always"},
14498 + {Opt_diropq_a, "diropq=a"},
14499 + {Opt_diropq_w, "diropq=whiteouted"},
14500 + {Opt_diropq_w, "diropq=w"},
14502 + {Opt_warn_perm, "warn_perm"},
14503 + {Opt_nowarn_perm, "nowarn_perm"},
14505 + /* keep them temporary */
14506 + {Opt_ignore_silent, "coo=%s"},
14507 + {Opt_ignore_silent, "nodlgt"},
14508 + {Opt_ignore_silent, "nodirperm1"},
14509 + {Opt_ignore_silent, "clean_plink"},
14511 +#ifdef CONFIG_AUFS_SHWH
14512 + {Opt_shwh, "shwh"},
14514 + {Opt_noshwh, "noshwh"},
14516 + {Opt_rendir, "rendir=%d"},
14518 + {Opt_refrof, "refrof"},
14519 + {Opt_norefrof, "norefrof"},
14521 + {Opt_verbose, "verbose"},
14522 + {Opt_verbose, "v"},
14523 + {Opt_noverbose, "noverbose"},
14524 + {Opt_noverbose, "quiet"},
14525 + {Opt_noverbose, "q"},
14526 + {Opt_noverbose, "silent"},
14528 + {Opt_sum, "sum"},
14529 + {Opt_nosum, "nosum"},
14530 + {Opt_wsum, "wsum"},
14532 + {Opt_rdcache, "rdcache=%d"},
14533 + {Opt_rdblk, "rdblk=%d"},
14534 + {Opt_rdblk_def, "rdblk=def"},
14535 + {Opt_rdhash, "rdhash=%d"},
14536 + {Opt_rdhash_def, "rdhash=def"},
14538 + {Opt_wbr_create, "create=%s"},
14539 + {Opt_wbr_create, "create_policy=%s"},
14540 + {Opt_wbr_copyup, "cpup=%s"},
14541 + {Opt_wbr_copyup, "copyup=%s"},
14542 + {Opt_wbr_copyup, "copyup_policy=%s"},
14544 + /* internal use for the scripts */
14545 + {Opt_ignore_silent, "si=%s"},
14547 + {Opt_br, "dirs=%s"},
14548 + {Opt_ignore, "debug=%d"},
14549 + {Opt_ignore, "delete=whiteout"},
14550 + {Opt_ignore, "delete=all"},
14551 + {Opt_ignore, "imap=%s"},
14556 +/* ---------------------------------------------------------------------- */
14558 +static const char *au_parser_pattern(int val, struct match_token *token)
14560 + while (token->pattern) {
14561 + if (token->token == val)
14562 + return token->pattern;
14569 +/* ---------------------------------------------------------------------- */
14571 +static match_table_t brperms = {
14572 + {AuBrPerm_RO, AUFS_BRPERM_RO},
14573 + {AuBrPerm_RR, AUFS_BRPERM_RR},
14574 + {AuBrPerm_RW, AUFS_BRPERM_RW},
14576 + {AuBrPerm_ROWH, AUFS_BRPERM_ROWH},
14577 + {AuBrPerm_RRWH, AUFS_BRPERM_RRWH},
14578 + {AuBrPerm_RWNoLinkWH, AUFS_BRPERM_RWNLWH},
14580 + {AuBrPerm_ROWH, "nfsro"},
14581 + {AuBrPerm_RO, NULL}
14584 +static int br_perm_val(char *perm)
14587 + substring_t args[MAX_OPT_ARGS];
14589 + val = match_token(perm, brperms, args);
14593 +const char *au_optstr_br_perm(int brperm)
14595 + return au_parser_pattern(brperm, (void *)brperms);
14598 +/* ---------------------------------------------------------------------- */
14600 +static match_table_t udbalevel = {
14601 + {AuOpt_UDBA_REVAL, "reval"},
14602 + {AuOpt_UDBA_NONE, "none"},
14603 +#ifdef CONFIG_AUFS_HINOTIFY
14604 + {AuOpt_UDBA_HINOTIFY, "inotify"},
14609 +static int udba_val(char *str)
14611 + substring_t args[MAX_OPT_ARGS];
14613 + return match_token(str, udbalevel, args);
14616 +const char *au_optstr_udba(int udba)
14618 + return au_parser_pattern(udba, (void *)udbalevel);
14621 +/* ---------------------------------------------------------------------- */
14623 +static match_table_t au_wbr_create_policy = {
14624 + {AuWbrCreate_TDP, "tdp"},
14625 + {AuWbrCreate_TDP, "top-down-parent"},
14626 + {AuWbrCreate_RR, "rr"},
14627 + {AuWbrCreate_RR, "round-robin"},
14628 + {AuWbrCreate_MFS, "mfs"},
14629 + {AuWbrCreate_MFS, "most-free-space"},
14630 + {AuWbrCreate_MFSV, "mfs:%d"},
14631 + {AuWbrCreate_MFSV, "most-free-space:%d"},
14633 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
14634 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
14635 + {AuWbrCreate_PMFS, "pmfs"},
14636 + {AuWbrCreate_PMFSV, "pmfs:%d"},
14642 + * cf. linux/lib/parser.c and cmdline.c
14643 + * gave up calling memparse() since it uses simple_strtoull() instead of
14646 +static int au_match_ull(substring_t *s, unsigned long long *result)
14649 + unsigned int len;
14653 + len = s->to - s->from;
14654 + if (len + 1 <= sizeof(a)) {
14655 + memcpy(a, s->from, len);
14657 + err = strict_strtoull(a, 0, result);
14662 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
14663 + struct au_opt_wbr_create *create)
14666 + unsigned long long ull;
14669 + if (!au_match_ull(arg, &ull))
14670 + create->mfsrr_watermark = ull;
14672 + AuErr("bad integer in %s\n", str);
14679 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
14680 + struct au_opt_wbr_create *create)
14685 + if (!match_int(arg, &n) && 0 <= n)
14686 + create->mfs_second = n;
14688 + AuErr("bad integer in %s\n", str);
14695 +static int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
14698 + substring_t args[MAX_OPT_ARGS];
14700 + err = match_token(str, au_wbr_create_policy, args);
14701 + create->wbr_create = err;
14703 + case AuWbrCreate_MFSRRV:
14704 + e = au_wbr_mfs_wmark(&args[0], str, create);
14706 + e = au_wbr_mfs_sec(&args[1], str, create);
14710 + case AuWbrCreate_MFSRR:
14711 + e = au_wbr_mfs_wmark(&args[0], str, create);
14712 + if (unlikely(e)) {
14717 + case AuWbrCreate_MFS:
14718 + case AuWbrCreate_PMFS:
14719 + create->mfs_second = AUFS_MFS_SECOND_DEF;
14721 + case AuWbrCreate_MFSV:
14722 + case AuWbrCreate_PMFSV:
14723 + e = au_wbr_mfs_sec(&args[0], str, create);
14732 +const char *au_optstr_wbr_create(int wbr_create)
14734 + return au_parser_pattern(wbr_create, (void *)au_wbr_create_policy);
14737 +static match_table_t au_wbr_copyup_policy = {
14738 + {AuWbrCopyup_TDP, "tdp"},
14739 + {AuWbrCopyup_TDP, "top-down-parent"},
14740 + {AuWbrCopyup_BUP, "bup"},
14741 + {AuWbrCopyup_BUP, "bottom-up-parent"},
14742 + {AuWbrCopyup_BU, "bu"},
14743 + {AuWbrCopyup_BU, "bottom-up"},
14747 +static int au_wbr_copyup_val(char *str)
14749 + substring_t args[MAX_OPT_ARGS];
14751 + return match_token(str, au_wbr_copyup_policy, args);
14754 +const char *au_optstr_wbr_copyup(int wbr_copyup)
14756 + return au_parser_pattern(wbr_copyup, (void *)au_wbr_copyup_policy);
14759 +/* ---------------------------------------------------------------------- */
14761 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
14763 +static void dump_opts(struct au_opts *opts)
14765 +#ifdef CONFIG_AUFS_DEBUG
14766 + /* reduce stack space */
14768 + struct au_opt_add *add;
14769 + struct au_opt_del *del;
14770 + struct au_opt_mod *mod;
14771 + struct au_opt_xino *xino;
14772 + struct au_opt_xino_itrunc *xino_itrunc;
14773 + struct au_opt_wbr_create *create;
14775 + struct au_opt *opt;
14778 + while (opt->type != Opt_tail) {
14779 + switch (opt->type) {
14781 + u.add = &opt->add;
14782 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
14783 + u.add->bindex, u.add->pathname, u.add->perm,
14784 + u.add->path.dentry);
14788 + u.del = &opt->del;
14789 + AuDbg("del {%s, %p}\n",
14790 + u.del->pathname, u.del->h_path.dentry);
14794 + u.mod = &opt->mod;
14795 + AuDbg("mod {%s, 0x%x, %p}\n",
14796 + u.mod->path, u.mod->perm, u.mod->h_root);
14799 + u.add = &opt->add;
14800 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
14801 + u.add->bindex, u.add->pathname, u.add->perm,
14802 + u.add->path.dentry);
14804 + case Opt_prepend:
14805 + u.add = &opt->add;
14806 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
14807 + u.add->bindex, u.add->pathname, u.add->perm,
14808 + u.add->path.dentry);
14811 + AuDbg("dirwh %d\n", opt->dirwh);
14813 + case Opt_rdcache:
14814 + AuDbg("rdcache %d\n", opt->rdcache);
14817 + AuDbg("rdblk %u\n", opt->rdblk);
14819 + case Opt_rdblk_def:
14820 + AuDbg("rdblk_def\n");
14823 + AuDbg("rdhash %u\n", opt->rdhash);
14825 + case Opt_rdhash_def:
14826 + AuDbg("rdhash_def\n");
14829 + u.xino = &opt->xino;
14830 + AuDbg("xino {%s %.*s}\n",
14832 + AuDLNPair(u.xino->file->f_dentry));
14834 + case Opt_trunc_xino:
14835 + AuLabel(trunc_xino);
14837 + case Opt_notrunc_xino:
14838 + AuLabel(notrunc_xino);
14840 + case Opt_trunc_xino_path:
14841 + case Opt_itrunc_xino:
14842 + u.xino_itrunc = &opt->xino_itrunc;
14843 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
14849 + case Opt_trunc_xib:
14850 + AuLabel(trunc_xib);
14852 + case Opt_notrunc_xib:
14853 + AuLabel(notrunc_xib);
14864 + case Opt_noplink:
14865 + AuLabel(noplink);
14867 + case Opt_list_plink:
14868 + AuLabel(list_plink);
14871 + AuDbg("udba %d, %s\n",
14872 + opt->udba, au_optstr_udba(opt->udba));
14874 + case Opt_diropq_a:
14875 + AuLabel(diropq_a);
14877 + case Opt_diropq_w:
14878 + AuLabel(diropq_w);
14880 + case Opt_warn_perm:
14881 + AuLabel(warn_perm);
14883 + case Opt_nowarn_perm:
14884 + AuLabel(nowarn_perm);
14889 + case Opt_norefrof:
14890 + AuLabel(norefrof);
14892 + case Opt_verbose:
14893 + AuLabel(verbose);
14895 + case Opt_noverbose:
14896 + AuLabel(noverbose);
14907 + case Opt_wbr_create:
14908 + u.create = &opt->wbr_create;
14909 + AuDbg("create %d, %s\n", u.create->wbr_create,
14910 + au_optstr_wbr_create(u.create->wbr_create));
14911 + switch (u.create->wbr_create) {
14912 + case AuWbrCreate_MFSV:
14913 + case AuWbrCreate_PMFSV:
14914 + AuDbg("%d sec\n", u.create->mfs_second);
14916 + case AuWbrCreate_MFSRR:
14917 + AuDbg("%llu watermark\n",
14918 + u.create->mfsrr_watermark);
14920 + case AuWbrCreate_MFSRRV:
14921 + AuDbg("%llu watermark, %d sec\n",
14922 + u.create->mfsrr_watermark,
14923 + u.create->mfs_second);
14927 + case Opt_wbr_copyup:
14928 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
14929 + au_optstr_wbr_copyup(opt->wbr_copyup));
14939 +void au_opts_free(struct au_opts *opts)
14941 + struct au_opt *opt;
14944 + while (opt->type != Opt_tail) {
14945 + switch (opt->type) {
14948 + case Opt_prepend:
14949 + path_put(&opt->add.path);
14953 + path_put(&opt->del.h_path);
14957 + dput(opt->mod.h_root);
14960 + fput(opt->xino.file);
14967 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
14968 + aufs_bindex_t bindex)
14971 + struct au_opt_add *add = &opt->add;
14974 + add->bindex = bindex;
14975 + add->perm = AuBrPerm_Last;
14976 + add->pathname = opt_str;
14977 + p = strchr(opt_str, '=');
14981 + add->perm = br_perm_val(p);
14984 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
14987 + add->perm = AuBrPerm_RO;
14988 + if (au_test_fs_rr(add->path.dentry->d_sb))
14989 + add->perm = AuBrPerm_RR;
14990 + else if (!bindex && !(sb_flags & MS_RDONLY))
14991 + add->perm = AuBrPerm_RW;
14993 + opt->type = Opt_add;
14996 + AuErr("lookup failed %s (%d)\n", add->pathname, err);
15003 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
15007 + del->pathname = args[0].from;
15008 + AuDbg("del path %s\n", del->pathname);
15010 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
15011 + if (unlikely(err))
15012 + AuErr("lookup failed %s (%d)\n", del->pathname, err);
15017 +#if 0 /* reserved for future use */
15018 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
15019 + struct au_opt_del *del, substring_t args[])
15022 + struct dentry *root;
15025 + root = sb->s_root;
15026 + aufs_read_lock(root, AuLock_FLUSH);
15027 + if (bindex < 0 || au_sbend(sb) < bindex) {
15028 + AuErr("out of bounds, %d\n", bindex);
15033 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
15034 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
15037 + aufs_read_unlock(root, !AuLock_IR);
15042 +static int au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
15045 + struct path path;
15049 + mod->path = args[0].from;
15050 + p = strchr(mod->path, '=');
15051 + if (unlikely(!p)) {
15052 + AuErr("no permssion %s\n", args[0].from);
15057 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
15058 + if (unlikely(err)) {
15059 + AuErr("lookup failed %s (%d)\n", mod->path, err);
15063 + mod->perm = br_perm_val(p);
15064 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
15065 + mod->h_root = dget(path.dentry);
15072 +#if 0 /* reserved for future use */
15073 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
15074 + struct au_opt_mod *mod, substring_t args[])
15077 + struct dentry *root;
15080 + root = sb->s_root;
15081 + aufs_read_lock(root, AuLock_FLUSH);
15082 + if (bindex < 0 || au_sbend(sb) < bindex) {
15083 + AuErr("out of bounds, %d\n", bindex);
15088 + mod->perm = br_perm_val(args[1].from);
15089 + AuDbg("mod path %s, perm 0x%x, %s\n",
15090 + mod->path, mod->perm, args[1].from);
15091 + mod->h_root = dget(au_h_dptr(root, bindex));
15094 + aufs_read_unlock(root, !AuLock_IR);
15099 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
15100 + substring_t args[])
15103 + struct file *file;
15105 + file = au_xino_create(sb, args[0].from, /*silent*/0);
15106 + err = PTR_ERR(file);
15107 + if (IS_ERR(file))
15111 + if (unlikely(file->f_dentry->d_sb == sb)) {
15113 + AuErr("%s must be outside\n", args[0].from);
15118 + xino->file = file;
15119 + xino->path = args[0].from;
15126 +int au_opts_parse_xino_itrunc_path(struct super_block *sb,
15127 + struct au_opt_xino_itrunc *xino_itrunc,
15128 + substring_t args[])
15131 + aufs_bindex_t bend, bindex;
15132 + struct path path;
15133 + struct dentry *root;
15135 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
15136 + if (unlikely(err)) {
15137 + AuErr("lookup failed %s (%d)\n", args[0].from, err);
15141 + xino_itrunc->bindex = -1;
15142 + root = sb->s_root;
15143 + aufs_read_lock(root, AuLock_FLUSH);
15144 + bend = au_sbend(sb);
15145 + for (bindex = 0; bindex <= bend; bindex++) {
15146 + if (au_h_dptr(root, bindex) == path.dentry) {
15147 + xino_itrunc->bindex = bindex;
15151 + aufs_read_unlock(root, !AuLock_IR);
15154 + if (unlikely(xino_itrunc->bindex < 0)) {
15155 + AuErr("no such branch %s\n", args[0].from);
15163 +/* called without aufs lock */
15164 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
15166 + int err, n, token;
15167 + aufs_bindex_t bindex;
15168 + unsigned char skipped;
15169 + struct dentry *root;
15170 + struct au_opt *opt, *opt_tail;
15172 + /* reduce the stack space */
15174 + struct au_opt_xino_itrunc *xino_itrunc;
15175 + struct au_opt_wbr_create *create;
15178 + substring_t args[MAX_OPT_ARGS];
15182 + a = kmalloc(sizeof(*a), GFP_NOFS);
15183 + if (unlikely(!a))
15186 + root = sb->s_root;
15190 + opt_tail = opt + opts->max_opt - 1;
15191 + opt->type = Opt_tail;
15192 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
15195 + token = match_token(opt_str, options, a->args);
15199 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
15201 + err = opt_add(opt, opt_str, opts->sb_flags,
15203 + if (unlikely(!err && ++opt > opt_tail)) {
15207 + opt->type = Opt_tail;
15212 + if (unlikely(match_int(&a->args[0], &n))) {
15213 + AuErr("bad integer in %s\n", opt_str);
15217 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
15220 + opt->type = token;
15223 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
15224 + /*dummy bindex*/1);
15226 + opt->type = token;
15228 + case Opt_prepend:
15229 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
15232 + opt->type = token;
15235 + err = au_opts_parse_del(&opt->del, a->args);
15237 + opt->type = token;
15239 +#if 0 /* reserved for future use */
15241 + del->pathname = "(indexed)";
15242 + if (unlikely(match_int(&args[0], &n))) {
15243 + AuErr("bad integer in %s\n", opt_str);
15246 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
15248 + opt->type = token;
15252 + err = au_opts_parse_mod(&opt->mod, a->args);
15254 + opt->type = token;
15256 +#ifdef IMOD /* reserved for future use */
15258 + u.mod->path = "(indexed)";
15259 + if (unlikely(match_int(&a->args[0], &n))) {
15260 + AuErr("bad integer in %s\n", opt_str);
15263 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
15265 + opt->type = token;
15269 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
15271 + opt->type = token;
15274 + case Opt_trunc_xino_path:
15275 + err = au_opts_parse_xino_itrunc_path
15276 + (sb, &opt->xino_itrunc, a->args);
15278 + opt->type = token;
15281 + case Opt_itrunc_xino:
15282 + u.xino_itrunc = &opt->xino_itrunc;
15283 + if (unlikely(match_int(&a->args[0], &n))) {
15284 + AuErr("bad integer in %s\n", opt_str);
15287 + u.xino_itrunc->bindex = n;
15288 + aufs_read_lock(root, AuLock_FLUSH);
15289 + if (n < 0 || au_sbend(sb) < n) {
15290 + AuErr("out of bounds, %d\n", n);
15291 + aufs_read_unlock(root, !AuLock_IR);
15294 + aufs_read_unlock(root, !AuLock_IR);
15296 + opt->type = token;
15300 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
15303 + opt->type = token;
15306 + case Opt_rdcache:
15307 + if (unlikely(match_int(&a->args[0], &opt->rdcache)))
15310 + opt->type = token;
15313 + if (unlikely(match_int(&a->args[0], &n)
15315 + || n > KMALLOC_MAX_SIZE)) {
15316 + AuErr("bad integer in %s\n", opt_str);
15319 + if (unlikely(n < NAME_MAX)) {
15320 + AuErr("rdblk must be larger than %d\n",
15326 + opt->type = token;
15329 + if (unlikely(match_int(&a->args[0], &n)
15331 + || n * sizeof(struct hlist_head)
15332 + > KMALLOC_MAX_SIZE)) {
15333 + AuErr("bad integer in %s\n", opt_str);
15338 + opt->type = token;
15341 + case Opt_trunc_xino:
15342 + case Opt_notrunc_xino:
15344 + case Opt_trunc_xib:
15345 + case Opt_notrunc_xib:
15349 + case Opt_noplink:
15350 + case Opt_list_plink:
15351 + case Opt_diropq_a:
15352 + case Opt_diropq_w:
15353 + case Opt_warn_perm:
15354 + case Opt_nowarn_perm:
15356 + case Opt_norefrof:
15357 + case Opt_verbose:
15358 + case Opt_noverbose:
15362 + case Opt_rdblk_def:
15363 + case Opt_rdhash_def:
15365 + opt->type = token;
15369 + opt->udba = udba_val(a->args[0].from);
15370 + if (opt->udba >= 0) {
15372 + opt->type = token;
15374 + AuErr("wrong value, %s\n", opt_str);
15377 + case Opt_wbr_create:
15378 + u.create = &opt->wbr_create;
15379 + u.create->wbr_create
15380 + = au_wbr_create_val(a->args[0].from, u.create);
15381 + if (u.create->wbr_create >= 0) {
15383 + opt->type = token;
15385 + AuErr("wrong value, %s\n", opt_str);
15387 + case Opt_wbr_copyup:
15388 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
15389 + if (opt->wbr_copyup >= 0) {
15391 + opt->type = token;
15393 + AuErr("wrong value, %s\n", opt_str);
15397 + AuWarn("ignored %s\n", opt_str);
15399 + case Opt_ignore_silent:
15404 + AuErr("unknown option %s\n", opt_str);
15408 + if (!err && !skipped) {
15409 + if (unlikely(++opt > opt_tail)) {
15412 + opt->type = Opt_tail;
15415 + opt->type = Opt_tail;
15421 + if (unlikely(err))
15422 + au_opts_free(opts);
15428 +static int au_opt_wbr_create(struct super_block *sb,
15429 + struct au_opt_wbr_create *create)
15432 + struct au_sbinfo *sbinfo;
15434 + SiMustWriteLock(sb);
15436 + err = 1; /* handled */
15437 + sbinfo = au_sbi(sb);
15438 + if (sbinfo->si_wbr_create_ops->fin) {
15439 + err = sbinfo->si_wbr_create_ops->fin(sb);
15444 + sbinfo->si_wbr_create = create->wbr_create;
15445 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
15446 + switch (create->wbr_create) {
15447 + case AuWbrCreate_MFSRRV:
15448 + case AuWbrCreate_MFSRR:
15449 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
15451 + case AuWbrCreate_MFS:
15452 + case AuWbrCreate_MFSV:
15453 + case AuWbrCreate_PMFS:
15454 + case AuWbrCreate_PMFSV:
15455 + sbinfo->si_wbr_mfs.mfs_expire = create->mfs_second * HZ;
15459 + if (sbinfo->si_wbr_create_ops->init)
15460 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
15467 + * plus: processed without an error
15468 + * zero: unprocessed
15470 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
15471 + struct au_opts *opts)
15474 + struct au_sbinfo *sbinfo;
15476 + SiMustWriteLock(sb);
15478 + err = 1; /* handled */
15479 + sbinfo = au_sbi(sb);
15480 + switch (opt->type) {
15482 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
15483 + sbinfo->si_mntflags |= opt->udba;
15484 + opts->given_udba |= opt->udba;
15488 + au_opt_set(sbinfo->si_mntflags, PLINK);
15490 + case Opt_noplink:
15491 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
15492 + au_plink_put(sb);
15493 + au_opt_clr(sbinfo->si_mntflags, PLINK);
15495 + case Opt_list_plink:
15496 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
15497 + au_plink_list(sb);
15500 + case Opt_diropq_a:
15501 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
15503 + case Opt_diropq_w:
15504 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
15507 + case Opt_warn_perm:
15508 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
15510 + case Opt_nowarn_perm:
15511 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
15515 + au_opt_set(sbinfo->si_mntflags, REFROF);
15517 + case Opt_norefrof:
15518 + au_opt_clr(sbinfo->si_mntflags, REFROF);
15521 + case Opt_verbose:
15522 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
15524 + case Opt_noverbose:
15525 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
15529 + au_opt_set(sbinfo->si_mntflags, SUM);
15532 + au_opt_clr(sbinfo->si_mntflags, SUM);
15533 + au_opt_set(sbinfo->si_mntflags, SUM_W);
15535 + au_opt_clr(sbinfo->si_mntflags, SUM);
15536 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
15539 + case Opt_wbr_create:
15540 + err = au_opt_wbr_create(sb, &opt->wbr_create);
15542 + case Opt_wbr_copyup:
15543 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
15544 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
15548 + sbinfo->si_dirwh = opt->dirwh;
15551 + case Opt_rdcache:
15552 + sbinfo->si_rdcache = opt->rdcache * HZ;
15555 + sbinfo->si_rdblk = opt->rdblk;
15557 + case Opt_rdblk_def:
15558 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
15561 + sbinfo->si_rdhash = opt->rdhash;
15563 + case Opt_rdhash_def:
15564 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
15568 + au_opt_set(sbinfo->si_mntflags, SHWH);
15571 + au_opt_clr(sbinfo->si_mntflags, SHWH);
15574 + case Opt_trunc_xino:
15575 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
15577 + case Opt_notrunc_xino:
15578 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
15581 + case Opt_trunc_xino_path:
15582 + case Opt_itrunc_xino:
15583 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
15588 + case Opt_trunc_xib:
15589 + au_fset_opts(opts->flags, TRUNC_XIB);
15591 + case Opt_notrunc_xib:
15592 + au_fclr_opts(opts->flags, TRUNC_XIB);
15604 + * returns tri-state.
15605 + * plus: processed without an error
15606 + * zero: unprocessed
15609 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
15610 + struct au_opts *opts)
15612 + int err, do_refresh;
15615 + switch (opt->type) {
15617 + opt->add.bindex = au_sbend(sb) + 1;
15618 + if (opt->add.bindex < 0)
15619 + opt->add.bindex = 0;
15621 + case Opt_prepend:
15622 + opt->add.bindex = 0;
15625 + err = au_br_add(sb, &opt->add,
15626 + au_ftest_opts(opts->flags, REMOUNT));
15629 + au_fset_opts(opts->flags, REFRESH_DIR);
15630 + if (au_br_whable(opt->add.perm))
15631 + au_fset_opts(opts->flags, REFRESH_NONDIR);
15637 + err = au_br_del(sb, &opt->del,
15638 + au_ftest_opts(opts->flags, REMOUNT));
15641 + au_fset_opts(opts->flags, TRUNC_XIB);
15642 + au_fset_opts(opts->flags, REFRESH_DIR);
15643 + au_fset_opts(opts->flags, REFRESH_NONDIR);
15649 + err = au_br_mod(sb, &opt->mod,
15650 + au_ftest_opts(opts->flags, REMOUNT),
15654 + if (do_refresh) {
15655 + au_fset_opts(opts->flags, REFRESH_DIR);
15656 + au_fset_opts(opts->flags, REFRESH_NONDIR);
15665 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
15666 + struct au_opt_xino **opt_xino,
15667 + struct au_opts *opts)
15670 + aufs_bindex_t bend, bindex;
15671 + struct dentry *root, *parent, *h_root;
15674 + switch (opt->type) {
15676 + err = au_xino_set(sb, &opt->xino,
15677 + !!au_ftest_opts(opts->flags, REMOUNT));
15678 + if (unlikely(err))
15681 + *opt_xino = &opt->xino;
15682 + au_xino_brid_set(sb, -1);
15684 + /* safe d_parent access */
15685 + parent = opt->xino.file->f_dentry->d_parent;
15686 + root = sb->s_root;
15687 + bend = au_sbend(sb);
15688 + for (bindex = 0; bindex <= bend; bindex++) {
15689 + h_root = au_h_dptr(root, bindex);
15690 + if (h_root == parent) {
15691 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
15699 + au_xino_brid_set(sb, -1);
15700 + *opt_xino = (void *)-1;
15707 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
15708 + unsigned int pending)
15711 + aufs_bindex_t bindex, bend;
15712 + unsigned char do_plink, skip, do_free;
15713 + struct au_branch *br;
15714 + struct au_wbr *wbr;
15715 + struct dentry *root;
15716 + struct inode *dir, *h_dir;
15717 + struct au_sbinfo *sbinfo;
15718 + struct au_hinode *hdir;
15720 + SiMustAnyLock(sb);
15722 + sbinfo = au_sbi(sb);
15723 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
15725 + if (!(sb_flags & MS_RDONLY)) {
15726 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
15727 + AuWarn("first branch should be rw\n");
15728 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
15729 + AuWarn("shwh should be used with ro\n");
15732 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HINOTIFY)
15733 + && !au_opt_test(sbinfo->si_mntflags, XINO))
15734 + AuWarn("udba=inotify requires xino\n");
15737 + root = sb->s_root;
15738 + dir = sb->s_root->d_inode;
15739 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
15740 + bend = au_sbend(sb);
15741 + for (bindex = 0; !err && bindex <= bend; bindex++) {
15743 + h_dir = au_h_iptr(dir, bindex);
15744 + br = au_sbr(sb, bindex);
15747 + wbr = br->br_wbr;
15749 + wbr_wh_read_lock(wbr);
15751 + switch (br->br_perm) {
15752 + case AuBrPerm_RO:
15753 + case AuBrPerm_ROWH:
15754 + case AuBrPerm_RR:
15755 + case AuBrPerm_RRWH:
15758 + || (!wbr->wbr_whbase
15759 + && !wbr->wbr_plink
15760 + && !wbr->wbr_orph));
15763 + case AuBrPerm_RWNoLinkWH:
15764 + /* skip = (!br->br_whbase && !br->br_orph); */
15765 + skip = (!wbr || !wbr->wbr_whbase);
15766 + if (skip && wbr) {
15768 + skip = !!wbr->wbr_plink;
15770 + skip = !wbr->wbr_plink;
15774 + case AuBrPerm_RW:
15775 + /* skip = (br->br_whbase && br->br_ohph); */
15776 + skip = (wbr && wbr->wbr_whbase);
15779 + skip = !!wbr->wbr_plink;
15781 + skip = !wbr->wbr_plink;
15789 + wbr_wh_read_unlock(wbr);
15794 + hdir = au_hi(dir, bindex);
15795 + au_hin_imtx_lock_nested(hdir, AuLsc_I_PARENT);
15797 + wbr_wh_write_lock(wbr);
15798 + err = au_wh_init(au_h_dptr(root, bindex), br, sb);
15800 + wbr_wh_write_unlock(wbr);
15801 + au_hin_imtx_unlock(hdir);
15803 + if (!err && do_free) {
15805 + br->br_wbr = NULL;
15812 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
15815 + unsigned int tmp;
15816 + aufs_bindex_t bend;
15817 + struct au_opt *opt;
15818 + struct au_opt_xino *opt_xino, xino;
15819 + struct au_sbinfo *sbinfo;
15821 + SiMustWriteLock(sb);
15826 + while (err >= 0 && opt->type != Opt_tail)
15827 + err = au_opt_simple(sb, opt++, opts);
15830 + else if (unlikely(err < 0))
15833 + /* disable xino and udba temporary */
15834 + sbinfo = au_sbi(sb);
15835 + tmp = sbinfo->si_mntflags;
15836 + au_opt_clr(sbinfo->si_mntflags, XINO);
15837 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
15840 + while (err >= 0 && opt->type != Opt_tail)
15841 + err = au_opt_br(sb, opt++, opts);
15844 + else if (unlikely(err < 0))
15847 + bend = au_sbend(sb);
15848 + if (unlikely(bend < 0)) {
15850 + AuErr("no branches\n");
15854 + if (au_opt_test(tmp, XINO))
15855 + au_opt_set(sbinfo->si_mntflags, XINO);
15857 + while (!err && opt->type != Opt_tail)
15858 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
15859 + if (unlikely(err))
15862 + err = au_opts_verify(sb, sb->s_flags, tmp);
15863 + if (unlikely(err))
15866 + /* restore xino */
15867 + if (au_opt_test(tmp, XINO) && !opt_xino) {
15868 + xino.file = au_xino_def(sb);
15869 + err = PTR_ERR(xino.file);
15870 + if (IS_ERR(xino.file))
15873 + err = au_xino_set(sb, &xino, /*remount*/0);
15875 + if (unlikely(err))
15879 + /* restore udba */
15880 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
15881 + sbinfo->si_mntflags |= (tmp & AuOptMask_UDBA);
15882 + if (au_opt_test(tmp, UDBA_HINOTIFY)) {
15883 + struct inode *dir = sb->s_root->d_inode;
15884 + au_reset_hinotify(dir,
15885 + au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
15892 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
15895 + struct inode *dir;
15896 + struct au_opt_xino *opt_xino;
15897 + struct au_opt *opt;
15898 + struct au_sbinfo *sbinfo;
15900 + SiMustWriteLock(sb);
15902 + dir = sb->s_root->d_inode;
15903 + sbinfo = au_sbi(sb);
15907 + while (err >= 0 && opt->type != Opt_tail) {
15908 + err = au_opt_simple(sb, opt, opts);
15910 + err = au_opt_br(sb, opt, opts);
15912 + err = au_opt_xino(sb, opt, &opt_xino, opts);
15918 + /* go on even err */
15920 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
15921 + if (unlikely(rerr && !err))
15924 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
15925 + rerr = au_xib_trunc(sb);
15926 + if (unlikely(rerr && !err))
15930 + /* will be handled by the caller */
15931 + if (!au_ftest_opts(opts->flags, REFRESH_DIR)
15932 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
15933 + au_fset_opts(opts->flags, REFRESH_DIR);
15935 + AuDbg("status 0x%x\n", opts->flags);
15939 +/* ---------------------------------------------------------------------- */
15941 +unsigned int au_opt_udba(struct super_block *sb)
15943 + return au_mntflags(sb) & AuOptMask_UDBA;
15945 diff -urN linux-2.6.30.org/fs/aufs/opts.h linux-2.6.30/fs/aufs/opts.h
15946 --- linux-2.6.30.org/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
15947 +++ linux-2.6.30/fs/aufs/opts.h 2009-07-21 08:54:19.000000000 +0200
15950 + * Copyright (C) 2005-2009 Junjiro R. Okajima
15952 + * This program, aufs is free software; you can redistribute it and/or modify
15953 + * it under the terms of the GNU General Public License as published by
15954 + * the Free Software Foundation; either version 2 of the License, or
15955 + * (at your option) any later version.
15957 + * This program is distributed in the hope that it will be useful,
15958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15960 + * GNU General Public License for more details.
15962 + * You should have received a copy of the GNU General Public License
15963 + * along with this program; if not, write to the Free Software
15964 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15968 + * mount options/flags
15971 +#ifndef __AUFS_OPTS_H__
15972 +#define __AUFS_OPTS_H__
15976 +#include <linux/path.h>
15977 +#include <linux/aufs_type.h>
15980 +struct super_block;
15982 +/* ---------------------------------------------------------------------- */
15985 +#define AuOpt_XINO 1 /* external inode number bitmap
15986 + and translation table */
15987 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
15988 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
15989 +#define AuOpt_UDBA_REVAL (1 << 3)
15990 +#define AuOpt_UDBA_HINOTIFY (1 << 4)
15991 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
15992 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
15993 +#define AuOpt_DIRPERM1 (1 << 7) /* unimplemented */
15994 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
15995 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
15996 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
15997 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
15998 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
15999 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
16001 +#ifndef CONFIG_AUFS_HINOTIFY
16002 +#undef AuOpt_UDBA_HINOTIFY
16003 +#define AuOpt_UDBA_HINOTIFY 0
16005 +#ifndef CONFIG_AUFS_SHWH
16007 +#define AuOpt_SHWH 0
16010 +#define AuOpt_Def (AuOpt_XINO \
16011 + | AuOpt_UDBA_REVAL \
16013 + /* | AuOpt_DIRPERM1 */ \
16014 + | AuOpt_WARN_PERM)
16015 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
16016 + | AuOpt_UDBA_REVAL \
16017 + | AuOpt_UDBA_HINOTIFY)
16019 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
16020 +#define au_opt_set(flags, name) do { \
16021 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
16022 + ((flags) |= AuOpt_##name); \
16024 +#define au_opt_set_udba(flags, name) do { \
16025 + (flags) &= ~AuOptMask_UDBA; \
16026 + ((flags) |= AuOpt_##name); \
16028 +#define au_opt_clr(flags, name) { ((flags) &= ~AuOpt_##name); }
16030 +/* ---------------------------------------------------------------------- */
16032 +/* policies to select one among multiple writable branches */
16034 + AuWbrCreate_TDP, /* top down parent */
16035 + AuWbrCreate_RR, /* round robin */
16036 + AuWbrCreate_MFS, /* most free space */
16037 + AuWbrCreate_MFSV, /* mfs with seconds */
16038 + AuWbrCreate_MFSRR, /* mfs then rr */
16039 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
16040 + AuWbrCreate_PMFS, /* parent and mfs */
16041 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
16043 + AuWbrCreate_Def = AuWbrCreate_TDP
16047 + AuWbrCopyup_TDP, /* top down parent */
16048 + AuWbrCopyup_BUP, /* bottom up parent */
16049 + AuWbrCopyup_BU, /* bottom up */
16051 + AuWbrCopyup_Def = AuWbrCopyup_TDP
16054 +/* ---------------------------------------------------------------------- */
16056 +struct au_opt_add {
16057 + aufs_bindex_t bindex;
16060 + struct path path;
16063 +struct au_opt_del {
16065 + struct path h_path;
16068 +struct au_opt_mod {
16071 + struct dentry *h_root;
16074 +struct au_opt_xino {
16076 + struct file *file;
16079 +struct au_opt_xino_itrunc {
16080 + aufs_bindex_t bindex;
16083 +struct au_opt_wbr_create {
16086 + unsigned long long mfsrr_watermark;
16092 + struct au_opt_xino xino;
16093 + struct au_opt_xino_itrunc xino_itrunc;
16094 + struct au_opt_add add;
16095 + struct au_opt_del del;
16096 + struct au_opt_mod mod;
16099 + unsigned int rdblk;
16100 + unsigned int rdhash;
16102 + struct au_opt_wbr_create wbr_create;
16108 +#define AuOpts_REMOUNT 1
16109 +#define AuOpts_REFRESH_DIR (1 << 1)
16110 +#define AuOpts_REFRESH_NONDIR (1 << 2)
16111 +#define AuOpts_TRUNC_XIB (1 << 3)
16112 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
16113 +#define au_fset_opts(flags, name) { (flags) |= AuOpts_##name; }
16114 +#define au_fclr_opts(flags, name) { (flags) &= ~AuOpts_##name; }
16117 + struct au_opt *opt;
16120 + unsigned int given_udba;
16121 + unsigned int flags;
16122 + unsigned long sb_flags;
16125 +/* ---------------------------------------------------------------------- */
16127 +const char *au_optstr_br_perm(int brperm);
16128 +const char *au_optstr_udba(int udba);
16129 +const char *au_optstr_wbr_copyup(int wbr_copyup);
16130 +const char *au_optstr_wbr_create(int wbr_create);
16132 +void au_opts_free(struct au_opts *opts);
16133 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
16134 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
16135 + unsigned int pending);
16136 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
16137 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
16139 +unsigned int au_opt_udba(struct super_block *sb);
16141 +/* ---------------------------------------------------------------------- */
16143 +#endif /* __KERNEL__ */
16144 +#endif /* __AUFS_OPTS_H__ */
16145 diff -urN linux-2.6.30.org/fs/aufs/plink.c linux-2.6.30/fs/aufs/plink.c
16146 --- linux-2.6.30.org/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
16147 +++ linux-2.6.30/fs/aufs/plink.c 2009-07-21 08:54:19.000000000 +0200
16150 + * Copyright (C) 2005-2009 Junjiro R. Okajima
16152 + * This program, aufs is free software; you can redistribute it and/or modify
16153 + * it under the terms of the GNU General Public License as published by
16154 + * the Free Software Foundation; either version 2 of the License, or
16155 + * (at your option) any later version.
16157 + * This program is distributed in the hope that it will be useful,
16158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16160 + * GNU General Public License for more details.
16162 + * You should have received a copy of the GNU General Public License
16163 + * along with this program; if not, write to the Free Software
16164 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16174 + * during a user process maintains the pseudo-links,
16175 + * prohibit adding a new plink and branch manipulation.
16177 +void au_plink_block_maintain(struct super_block *sb)
16179 + struct au_sbinfo *sbi = au_sbi(sb);
16181 + SiMustAnyLock(sb);
16183 + /* gave up wake_up_bit() */
16184 + wait_event(sbi->si_plink_wq, !au_ftest_si(sbi, MAINTAIN_PLINK));
16187 +/* ---------------------------------------------------------------------- */
16189 +struct pseudo_link {
16190 + struct list_head list;
16191 + struct inode *inode;
16194 +#ifdef CONFIG_AUFS_DEBUG
16195 +void au_plink_list(struct super_block *sb)
16197 + struct au_sbinfo *sbinfo;
16198 + struct list_head *plink_list;
16199 + struct pseudo_link *plink;
16201 + SiMustAnyLock(sb);
16203 + sbinfo = au_sbi(sb);
16204 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
16206 + plink_list = &sbinfo->si_plink.head;
16207 + spin_lock(&sbinfo->si_plink.spin);
16208 + list_for_each_entry(plink, plink_list, list)
16209 + AuDbg("%lu\n", plink->inode->i_ino);
16210 + spin_unlock(&sbinfo->si_plink.spin);
16214 +/* is the inode pseudo-linked? */
16215 +int au_plink_test(struct inode *inode)
16218 + struct au_sbinfo *sbinfo;
16219 + struct list_head *plink_list;
16220 + struct pseudo_link *plink;
16222 + sbinfo = au_sbi(inode->i_sb);
16223 + AuRwMustAnyLock(&sbinfo->si_rwsem);
16224 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
16227 + plink_list = &sbinfo->si_plink.head;
16228 + spin_lock(&sbinfo->si_plink.spin);
16229 + list_for_each_entry(plink, plink_list, list)
16230 + if (plink->inode == inode) {
16234 + spin_unlock(&sbinfo->si_plink.spin);
16238 +/* ---------------------------------------------------------------------- */
16241 + * generate a name for plink.
16242 + * the file will be stored under AUFS_WH_PLINKDIR.
16244 +/* 20 is max digits length of ulong 64 */
16245 +#define PLINK_NAME_LEN ((20 + 1) * 2)
16247 +static int plink_name(char *name, int len, struct inode *inode,
16248 + aufs_bindex_t bindex)
16251 + struct inode *h_inode;
16253 + h_inode = au_h_iptr(inode, bindex);
16254 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
16258 +/* lookup the plink-ed @inode under the branch at @bindex */
16259 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
16261 + struct dentry *h_dentry, *h_parent;
16262 + struct au_branch *br;
16263 + struct inode *h_dir;
16264 + char a[PLINK_NAME_LEN];
16265 + struct qstr tgtname = {
16269 + br = au_sbr(inode->i_sb, bindex);
16270 + h_parent = br->br_wbr->wbr_plink;
16271 + h_dir = h_parent->d_inode;
16272 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
16274 + /* always superio. */
16275 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
16276 + h_dentry = au_sio_lkup_one(&tgtname, h_parent, br);
16277 + mutex_unlock(&h_dir->i_mutex);
16281 +/* create a pseudo-link */
16282 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
16283 + struct dentry *h_dentry, struct au_branch *br)
16286 + struct path h_path = {
16287 + .mnt = br->br_mnt
16289 + struct inode *h_dir;
16291 + h_dir = h_parent->d_inode;
16293 + h_path.dentry = au_lkup_one(tgt, h_parent, br, /*nd*/NULL);
16294 + err = PTR_ERR(h_path.dentry);
16295 + if (IS_ERR(h_path.dentry))
16299 + /* wh.plink dir is not monitored */
16300 + if (h_path.dentry->d_inode
16301 + && h_path.dentry->d_inode != h_dentry->d_inode) {
16302 + err = vfsub_unlink(h_dir, &h_path, /*force*/0);
16303 + dput(h_path.dentry);
16304 + h_path.dentry = NULL;
16308 + if (!err && !h_path.dentry->d_inode)
16309 + err = vfsub_link(h_dentry, h_dir, &h_path);
16310 + dput(h_path.dentry);
16316 +struct do_whplink_args {
16318 + struct qstr *tgt;
16319 + struct dentry *h_parent;
16320 + struct dentry *h_dentry;
16321 + struct au_branch *br;
16324 +static void call_do_whplink(void *args)
16326 + struct do_whplink_args *a = args;
16327 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
16330 +static int whplink(struct dentry *h_dentry, struct inode *inode,
16331 + aufs_bindex_t bindex, struct au_branch *br)
16333 + int err, wkq_err;
16334 + struct au_wbr *wbr;
16335 + struct dentry *h_parent;
16336 + struct inode *h_dir;
16337 + char a[PLINK_NAME_LEN];
16338 + struct qstr tgtname = {
16342 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
16343 + h_parent = wbr->wbr_plink;
16344 + h_dir = h_parent->d_inode;
16345 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
16347 + /* always superio. */
16348 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
16349 + if (!au_test_wkq(current)) {
16350 + struct do_whplink_args args = {
16353 + .h_parent = h_parent,
16354 + .h_dentry = h_dentry,
16357 + wkq_err = au_wkq_wait(call_do_whplink, &args);
16358 + if (unlikely(wkq_err))
16361 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
16362 + mutex_unlock(&h_dir->i_mutex);
16367 +/* free a single plink */
16368 +static void do_put_plink(struct pseudo_link *plink, int do_del)
16370 + iput(plink->inode);
16372 + list_del(&plink->list);
16377 + * create a new pseudo-link for @h_dentry on @bindex.
16378 + * the linked inode is held in aufs @inode.
16380 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16381 + struct dentry *h_dentry)
16383 + struct super_block *sb;
16384 + struct au_sbinfo *sbinfo;
16385 + struct list_head *plink_list;
16386 + struct pseudo_link *plink;
16387 + int found, err, cnt;
16389 + sb = inode->i_sb;
16390 + sbinfo = au_sbi(sb);
16391 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
16396 + plink_list = &sbinfo->si_plink.head;
16397 + spin_lock(&sbinfo->si_plink.spin);
16398 + list_for_each_entry(plink, plink_list, list) {
16400 + if (plink->inode == inode) {
16406 + spin_unlock(&sbinfo->si_plink.spin);
16412 + plink = kmalloc(sizeof(*plink), GFP_ATOMIC);
16414 + plink->inode = au_igrab(inode);
16415 + list_add(&plink->list, plink_list);
16420 + spin_unlock(&sbinfo->si_plink.spin);
16423 + au_plink_block_maintain(sb);
16424 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
16427 + if (unlikely(cnt > AUFS_PLINK_WARN))
16428 + AuWarn1("unexpectedly many pseudo links, %d\n", cnt);
16429 + if (unlikely(err)) {
16430 + AuWarn("err %d, damaged pseudo link.\n", err);
16431 + if (!found && plink)
16432 + do_put_plink(plink, /*do_del*/1);
16436 +/* free all plinks */
16437 +void au_plink_put(struct super_block *sb)
16439 + struct au_sbinfo *sbinfo;
16440 + struct list_head *plink_list;
16441 + struct pseudo_link *plink, *tmp;
16443 + SiMustWriteLock(sb);
16445 + sbinfo = au_sbi(sb);
16446 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
16448 + plink_list = &sbinfo->si_plink.head;
16449 + /* no spin_lock since sbinfo is write-locked */
16450 + list_for_each_entry_safe(plink, tmp, plink_list, list)
16451 + do_put_plink(plink, 0);
16452 + INIT_LIST_HEAD(plink_list);
16455 +/* free the plinks on a branch specified by @br_id */
16456 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
16458 + struct au_sbinfo *sbinfo;
16459 + struct list_head *plink_list;
16460 + struct pseudo_link *plink, *tmp;
16461 + struct inode *inode;
16462 + aufs_bindex_t bstart, bend, bindex;
16463 + unsigned char do_put;
16465 + SiMustWriteLock(sb);
16467 + sbinfo = au_sbi(sb);
16468 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
16470 + plink_list = &sbinfo->si_plink.head;
16471 + /* no spin_lock since sbinfo is write-locked */
16472 + list_for_each_entry_safe(plink, tmp, plink_list, list) {
16474 + inode = au_igrab(plink->inode);
16475 + ii_write_lock_child(inode);
16476 + bstart = au_ibstart(inode);
16477 + bend = au_ibend(inode);
16478 + if (bstart >= 0) {
16479 + for (bindex = bstart; bindex <= bend; bindex++) {
16480 + if (!au_h_iptr(inode, bindex)
16481 + || au_ii_br_id(inode, bindex) != br_id)
16483 + au_set_h_iptr(inode, bindex, NULL, 0);
16488 + do_put_plink(plink, 1);
16491 + for (bindex = bstart; bindex <= bend; bindex++)
16492 + if (au_h_iptr(inode, bindex)) {
16497 + do_put_plink(plink, 1);
16499 + ii_write_unlock(inode);
16503 diff -urN linux-2.6.30.org/fs/aufs/poll.c linux-2.6.30/fs/aufs/poll.c
16504 --- linux-2.6.30.org/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
16505 +++ linux-2.6.30/fs/aufs/poll.c 2009-07-21 08:54:19.000000000 +0200
16508 + * Copyright (C) 2005-2009 Junjiro R. Okajima
16510 + * This program, aufs is free software; you can redistribute it and/or modify
16511 + * it under the terms of the GNU General Public License as published by
16512 + * the Free Software Foundation; either version 2 of the License, or
16513 + * (at your option) any later version.
16515 + * This program is distributed in the hope that it will be useful,
16516 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16517 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16518 + * GNU General Public License for more details.
16520 + * You should have received a copy of the GNU General Public License
16521 + * along with this program; if not, write to the Free Software
16522 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16527 + * There is only one filesystem which implements ->poll operation, currently.
16532 +unsigned int aufs_poll(struct file *file, poll_table *wait)
16534 + unsigned int mask;
16536 + struct file *h_file;
16537 + struct dentry *dentry;
16538 + struct super_block *sb;
16540 + /* We should pretend an error happened. */
16541 + mask = POLLERR /* | POLLIN | POLLOUT */;
16542 + dentry = file->f_dentry;
16543 + sb = dentry->d_sb;
16544 + si_read_lock(sb, AuLock_FLUSH);
16545 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
16546 + if (unlikely(err))
16549 + /* it is not an error if h_file has no operation */
16550 + mask = DEFAULT_POLLMASK;
16551 + h_file = au_h_fptr(file, au_fbstart(file));
16552 + if (h_file->f_op && h_file->f_op->poll)
16553 + mask = h_file->f_op->poll(h_file, wait);
16555 + di_read_unlock(dentry, AuLock_IR);
16556 + fi_read_unlock(file);
16559 + si_read_unlock(sb);
16560 + AuTraceErr((int)mask);
16563 diff -urN linux-2.6.30.org/fs/aufs/rwsem.h linux-2.6.30/fs/aufs/rwsem.h
16564 --- linux-2.6.30.org/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
16565 +++ linux-2.6.30/fs/aufs/rwsem.h 2009-07-21 08:54:19.000000000 +0200
16568 + * Copyright (C) 2005-2009 Junjiro R. Okajima
16570 + * This program, aufs is free software; you can redistribute it and/or modify
16571 + * it under the terms of the GNU General Public License as published by
16572 + * the Free Software Foundation; either version 2 of the License, or
16573 + * (at your option) any later version.
16575 + * This program is distributed in the hope that it will be useful,
16576 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16577 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16578 + * GNU General Public License for more details.
16580 + * You should have received a copy of the GNU General Public License
16581 + * along with this program; if not, write to the Free Software
16582 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16586 + * simple read-write semaphore wrappers
16589 +#ifndef __AUFS_RWSEM_H__
16590 +#define __AUFS_RWSEM_H__
16594 +#include <linux/rwsem.h>
16597 + struct rw_semaphore rwsem;
16598 +#ifdef CONFIG_AUFS_DEBUG
16599 + /* just for debugging, not almighty counter */
16600 + atomic_t rcnt, wcnt;
16604 +#ifdef CONFIG_AUFS_DEBUG
16605 +#define AuDbgCntInit(rw) do { \
16606 + atomic_set(&(rw)->rcnt, 0); \
16607 + atomic_set(&(rw)->wcnt, 0); \
16608 + smp_mb(); /* atomic set */ \
16611 +#define AuDbgRcntInc(rw) atomic_inc_return(&(rw)->rcnt)
16612 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
16613 +#define AuDbgWcntInc(rw) WARN_ON(atomic_inc_return(&(rw)->wcnt) > 1)
16614 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
16616 +#define AuDbgCntInit(rw) do {} while (0)
16617 +#define AuDbgRcntInc(rw) do {} while (0)
16618 +#define AuDbgRcntDec(rw) do {} while (0)
16619 +#define AuDbgWcntInc(rw) do {} while (0)
16620 +#define AuDbgWcntDec(rw) do {} while (0)
16621 +#endif /* CONFIG_AUFS_DEBUG */
16623 +/* to debug easier, do not make them inlined functions */
16624 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
16625 +/* rwsem_is_locked() is unusable */
16626 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
16627 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
16628 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
16629 + && atomic_read(&(rw)->wcnt) <= 0)
16630 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
16631 + || atomic_read(&(rw)->wcnt))
16633 +static inline void au_rw_init(struct au_rwsem *rw)
16635 + AuDbgCntInit(rw);
16636 + init_rwsem(&rw->rwsem);
16639 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
16642 + down_write(&rw->rwsem);
16643 + AuDbgWcntInc(rw);
16646 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
16647 + unsigned int lsc)
16650 + down_write_nested(&rw->rwsem, lsc);
16651 + AuDbgWcntInc(rw);
16654 +static inline void au_rw_read_lock(struct au_rwsem *rw)
16656 + down_read(&rw->rwsem);
16657 + AuDbgRcntInc(rw);
16660 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
16662 + down_read_nested(&rw->rwsem, lsc);
16663 + AuDbgRcntInc(rw);
16666 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
16668 + AuRwMustReadLock(rw);
16669 + AuDbgRcntDec(rw);
16670 + up_read(&rw->rwsem);
16673 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
16675 + AuRwMustWriteLock(rw);
16676 + AuDbgRcntInc(rw);
16677 + AuDbgWcntDec(rw);
16678 + downgrade_write(&rw->rwsem);
16681 +static inline void au_rw_write_lock(struct au_rwsem *rw)
16683 + down_write(&rw->rwsem);
16684 + AuDbgWcntInc(rw);
16687 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
16688 + unsigned int lsc)
16690 + down_write_nested(&rw->rwsem, lsc);
16691 + AuDbgWcntInc(rw);
16694 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
16696 + AuRwMustWriteLock(rw);
16697 + AuDbgWcntDec(rw);
16698 + up_write(&rw->rwsem);
16701 +/* why is not _nested version defined */
16702 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
16704 + int ret = down_read_trylock(&rw->rwsem);
16706 + AuDbgRcntInc(rw);
16710 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
16712 + int ret = down_write_trylock(&rw->rwsem);
16714 + AuDbgWcntInc(rw);
16718 +#undef AuDbgCntInit
16719 +#undef AuDbgRcntInc
16720 +#undef AuDbgRcntDec
16721 +#undef AuDbgWcntInc
16722 +#undef AuDbgWcntDec
16724 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
16725 +static inline void prefix##_read_lock(param) \
16726 +{ au_rw_read_lock(rwsem); } \
16727 +static inline void prefix##_write_lock(param) \
16728 +{ au_rw_write_lock(rwsem); } \
16729 +static inline int prefix##_read_trylock(param) \
16730 +{ return au_rw_read_trylock(rwsem); } \
16731 +static inline int prefix##_write_trylock(param) \
16732 +{ return au_rw_write_trylock(rwsem); }
16733 +/* why is not _nested version defined */
16734 +/* static inline void prefix##_read_trylock_nested(param, lsc)
16735 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
16736 +static inline void prefix##_write_trylock_nestd(param, lsc)
16737 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
16739 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
16740 +static inline void prefix##_read_unlock(param) \
16741 +{ au_rw_read_unlock(rwsem); } \
16742 +static inline void prefix##_write_unlock(param) \
16743 +{ au_rw_write_unlock(rwsem); } \
16744 +static inline void prefix##_downgrade_lock(param) \
16745 +{ au_rw_dgrade_lock(rwsem); }
16747 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
16748 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
16749 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
16751 +#endif /* __KERNEL__ */
16752 +#endif /* __AUFS_RWSEM_H__ */
16753 diff -urN linux-2.6.30.org/fs/aufs/sbinfo.c linux-2.6.30/fs/aufs/sbinfo.c
16754 --- linux-2.6.30.org/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
16755 +++ linux-2.6.30/fs/aufs/sbinfo.c 2009-07-21 08:54:19.000000000 +0200
16758 + * Copyright (C) 2005-2009 Junjiro R. Okajima
16760 + * This program, aufs is free software; you can redistribute it and/or modify
16761 + * it under the terms of the GNU General Public License as published by
16762 + * the Free Software Foundation; either version 2 of the License, or
16763 + * (at your option) any later version.
16765 + * This program is distributed in the hope that it will be useful,
16766 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16767 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16768 + * GNU General Public License for more details.
16770 + * You should have received a copy of the GNU General Public License
16771 + * along with this program; if not, write to the Free Software
16772 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16776 + * superblock private data
16782 + * they are necessary regardless sysfs is disabled.
16784 +void au_si_free(struct kobject *kobj)
16786 + struct au_sbinfo *sbinfo;
16787 + struct super_block *sb;
16789 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
16790 + AuDebugOn(!list_empty(&sbinfo->si_plink.head));
16792 + sb = sbinfo->si_sb;
16793 + si_write_lock(sb);
16795 + au_br_free(sbinfo);
16796 + kfree(sbinfo->si_branch);
16797 + mutex_destroy(&sbinfo->si_xib_mtx);
16798 + si_write_unlock(sb);
16799 + AuRwDestroy(&sbinfo->si_rwsem);
16804 +int au_si_alloc(struct super_block *sb)
16807 + struct au_sbinfo *sbinfo;
16810 + sbinfo = kmalloc(sizeof(*sbinfo), GFP_NOFS);
16811 + if (unlikely(!sbinfo))
16814 + /* will be reallocated separately */
16815 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
16816 + if (unlikely(!sbinfo->si_branch))
16819 + memset(&sbinfo->si_kobj, 0, sizeof(sbinfo->si_kobj));
16820 + err = sysaufs_si_init(sbinfo);
16821 + if (unlikely(err))
16824 + au_nwt_init(&sbinfo->si_nowait);
16825 + au_rw_init_wlock(&sbinfo->si_rwsem);
16826 + sbinfo->si_generation = 0;
16827 + sbinfo->au_si_status = 0;
16828 + sbinfo->si_bend = -1;
16829 + sbinfo->si_last_br_id = 0;
16831 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
16832 + sbinfo->si_wbr_create = AuWbrCreate_Def;
16833 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + AuWbrCopyup_Def;
16834 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + AuWbrCreate_Def;
16836 + sbinfo->si_mntflags = AuOpt_Def;
16838 + sbinfo->si_xread = NULL;
16839 + sbinfo->si_xwrite = NULL;
16840 + sbinfo->si_xib = NULL;
16841 + mutex_init(&sbinfo->si_xib_mtx);
16842 + sbinfo->si_xib_buf = NULL;
16843 + sbinfo->si_xino_brid = -1;
16844 + /* leave si_xib_last_pindex and si_xib_next_bit */
16846 + sbinfo->si_rdcache = AUFS_RDCACHE_DEF * HZ;
16847 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
16848 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
16849 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
16851 + au_spl_init(&sbinfo->si_plink);
16852 + init_waitqueue_head(&sbinfo->si_plink_wq);
16854 + /* leave other members for sysaufs and si_mnt. */
16855 + sbinfo->si_sb = sb;
16856 + sb->s_fs_info = sbinfo;
16857 + au_debug_sbinfo_init(sbinfo);
16858 + return 0; /* success */
16861 + kfree(sbinfo->si_branch);
16868 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
16871 + struct au_branch **brp;
16873 + AuRwMustWriteLock(&sbinfo->si_rwsem);
16876 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
16877 + if (unlikely(!sz))
16878 + sz = sizeof(*brp);
16879 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
16881 + sbinfo->si_branch = brp;
16888 +/* ---------------------------------------------------------------------- */
16890 +unsigned int au_sigen_inc(struct super_block *sb)
16892 + unsigned int gen;
16894 + SiMustWriteLock(sb);
16896 + gen = ++au_sbi(sb)->si_generation;
16897 + au_update_digen(sb->s_root);
16898 + au_update_iigen(sb->s_root->d_inode);
16899 + sb->s_root->d_inode->i_version++;
16903 +aufs_bindex_t au_new_br_id(struct super_block *sb)
16905 + aufs_bindex_t br_id;
16907 + struct au_sbinfo *sbinfo;
16909 + SiMustWriteLock(sb);
16911 + sbinfo = au_sbi(sb);
16912 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
16913 + br_id = ++sbinfo->si_last_br_id;
16914 + if (br_id && au_br_index(sb, br_id) < 0)
16921 +/* ---------------------------------------------------------------------- */
16923 +/* dentry and super_block lock. call at entry point */
16924 +void aufs_read_lock(struct dentry *dentry, int flags)
16926 + si_read_lock(dentry->d_sb, flags);
16927 + if (au_ftest_lock(flags, DW))
16928 + di_write_lock_child(dentry);
16930 + di_read_lock_child(dentry, flags);
16933 +void aufs_read_unlock(struct dentry *dentry, int flags)
16935 + if (au_ftest_lock(flags, DW))
16936 + di_write_unlock(dentry);
16938 + di_read_unlock(dentry, flags);
16939 + si_read_unlock(dentry->d_sb);
16942 +void aufs_write_lock(struct dentry *dentry)
16944 + si_write_lock(dentry->d_sb);
16945 + di_write_lock_child(dentry);
16948 +void aufs_write_unlock(struct dentry *dentry)
16950 + di_write_unlock(dentry);
16951 + si_write_unlock(dentry->d_sb);
16954 +void aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
16956 + si_read_lock(d1->d_sb, flags);
16957 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
16960 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
16962 + di_write_unlock2(d1, d2);
16963 + si_read_unlock(d1->d_sb);
16965 diff -urN linux-2.6.30.org/fs/aufs/spl.h linux-2.6.30/fs/aufs/spl.h
16966 --- linux-2.6.30.org/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
16967 +++ linux-2.6.30/fs/aufs/spl.h 2009-07-21 08:54:19.000000000 +0200
16970 + * Copyright (C) 2005-2009 Junjiro R. Okajima
16972 + * This program, aufs is free software; you can redistribute it and/or modify
16973 + * it under the terms of the GNU General Public License as published by
16974 + * the Free Software Foundation; either version 2 of the License, or
16975 + * (at your option) any later version.
16977 + * This program is distributed in the hope that it will be useful,
16978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16980 + * GNU General Public License for more details.
16982 + * You should have received a copy of the GNU General Public License
16983 + * along with this program; if not, write to the Free Software
16984 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16988 + * simple list protected by a spinlock
16991 +#ifndef __AUFS_SPL_H__
16992 +#define __AUFS_SPL_H__
16996 +#include <linux/spinlock.h>
16997 +#include <linux/list.h>
16999 +struct au_splhead {
17001 + struct list_head head;
17004 +static inline void au_spl_init(struct au_splhead *spl)
17006 + spin_lock_init(&spl->spin);
17007 + INIT_LIST_HEAD(&spl->head);
17010 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
17012 + spin_lock(&spl->spin);
17013 + list_add(list, &spl->head);
17014 + spin_unlock(&spl->spin);
17017 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
17019 + spin_lock(&spl->spin);
17021 + spin_unlock(&spl->spin);
17024 +#endif /* __KERNEL__ */
17025 +#endif /* __AUFS_SPL_H__ */
17026 diff -urN linux-2.6.30.org/fs/aufs/super.c linux-2.6.30/fs/aufs/super.c
17027 --- linux-2.6.30.org/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
17028 +++ linux-2.6.30/fs/aufs/super.c 2009-07-21 08:54:19.000000000 +0200
17031 + * Copyright (C) 2005-2009 Junjiro R. Okajima
17033 + * This program, aufs is free software; you can redistribute it and/or modify
17034 + * it under the terms of the GNU General Public License as published by
17035 + * the Free Software Foundation; either version 2 of the License, or
17036 + * (at your option) any later version.
17038 + * This program is distributed in the hope that it will be useful,
17039 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17040 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17041 + * GNU General Public License for more details.
17043 + * You should have received a copy of the GNU General Public License
17044 + * along with this program; if not, write to the Free Software
17045 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17049 + * mount and super_block operations
17052 +#include <linux/buffer_head.h>
17053 +#include <linux/module.h>
17054 +#include <linux/seq_file.h>
17055 +#include <linux/statfs.h>
17059 + * super_operations
17061 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
17063 + struct au_icntnr *c;
17065 + c = au_cache_alloc_icntnr();
17067 + inode_init_once(&c->vfs_inode);
17068 + c->vfs_inode.i_version = 1; /* sigen(sb); */
17069 + c->iinfo.ii_hinode = NULL;
17070 + return &c->vfs_inode;
17075 +static void aufs_destroy_inode(struct inode *inode)
17077 + au_iinfo_fin(inode);
17078 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
17081 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
17083 + struct inode *inode;
17086 + inode = iget_locked(sb, ino);
17087 + if (unlikely(!inode)) {
17088 + inode = ERR_PTR(-ENOMEM);
17091 + if (!(inode->i_state & I_NEW))
17094 + err = au_xigen_new(inode);
17096 + err = au_iinfo_init(inode);
17098 + inode->i_version++;
17100 + iget_failed(inode);
17101 + inode = ERR_PTR(err);
17105 + /* never return NULL */
17106 + AuDebugOn(!inode);
17107 + AuTraceErrPtr(inode);
17111 +/* lock free root dinfo */
17112 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
17115 + aufs_bindex_t bindex, bend;
17116 + struct path path;
17117 + struct au_hdentry *hd;
17118 + struct au_branch *br;
17121 + bend = au_sbend(sb);
17122 + hd = au_di(sb->s_root)->di_hdentry;
17123 + for (bindex = 0; !err && bindex <= bend; bindex++) {
17124 + br = au_sbr(sb, bindex);
17125 + path.mnt = br->br_mnt;
17126 + path.dentry = hd[bindex].hd_dentry;
17127 + err = au_seq_path(seq, &path);
17129 + err = seq_printf(seq, "=%s",
17130 + au_optstr_br_perm(br->br_perm));
17131 + if (!err && bindex != bend)
17132 + err = seq_putc(seq, ':');
17138 +static void au_show_wbr_create(struct seq_file *m, int v,
17139 + struct au_sbinfo *sbinfo)
17143 + AuRwMustAnyLock(&sbinfo->si_rwsem);
17145 + seq_printf(m, ",create=");
17146 + pat = au_optstr_wbr_create(v);
17148 + case AuWbrCreate_TDP:
17149 + case AuWbrCreate_RR:
17150 + case AuWbrCreate_MFS:
17151 + case AuWbrCreate_PMFS:
17152 + seq_printf(m, pat);
17154 + case AuWbrCreate_MFSV:
17155 + seq_printf(m, /*pat*/"mfs:%lu",
17156 + sbinfo->si_wbr_mfs.mfs_expire / HZ);
17158 + case AuWbrCreate_PMFSV:
17159 + seq_printf(m, /*pat*/"pmfs:%lu",
17160 + sbinfo->si_wbr_mfs.mfs_expire / HZ);
17162 + case AuWbrCreate_MFSRR:
17163 + seq_printf(m, /*pat*/"mfsrr:%llu",
17164 + sbinfo->si_wbr_mfs.mfsrr_watermark);
17166 + case AuWbrCreate_MFSRRV:
17167 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
17168 + sbinfo->si_wbr_mfs.mfsrr_watermark,
17169 + sbinfo->si_wbr_mfs.mfs_expire / HZ);
17174 +static int au_show_xino(struct seq_file *seq, struct vfsmount *mnt)
17176 +#ifdef CONFIG_SYSFS
17180 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
17181 + aufs_bindex_t bindex, brid;
17182 + struct super_block *sb;
17183 + struct qstr *name;
17185 + struct dentry *d, *h_root;
17187 + AuRwMustAnyLock(&sbinfo->si_rwsem);
17190 + sb = mnt->mnt_sb;
17191 + f = au_sbi(sb)->si_xib;
17195 + /* stop printing the default xino path on the first writable branch */
17197 + brid = au_xino_brid(sb);
17199 + bindex = au_br_index(sb, brid);
17200 + h_root = au_di(sb->s_root)->di_hdentry[0 + bindex].hd_dentry;
17203 + name = &d->d_name;
17204 + /* safe ->d_parent because the file is unlinked */
17205 + if (d->d_parent == h_root
17206 + && name->len == len
17207 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
17210 + seq_puts(seq, ",xino=");
17211 + err = au_xino_path(seq, f);
17218 +/* seq_file will re-call me in case of too long string */
17219 +static int aufs_show_options(struct seq_file *m, struct vfsmount *mnt)
17222 + unsigned int mnt_flags, v;
17223 + struct super_block *sb;
17224 + struct au_sbinfo *sbinfo;
17226 +#define AuBool(name, str) do { \
17227 + v = au_opt_test(mnt_flags, name); \
17228 + if (v != au_opt_test(AuOpt_Def, name)) \
17229 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
17232 +#define AuStr(name, str) do { \
17233 + v = mnt_flags & AuOptMask_##name; \
17234 + if (v != (AuOpt_Def & AuOptMask_##name)) \
17235 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
17238 +#define AuUInt(name, str, val) do { \
17239 + if (val != AUFS_##name##_DEF) \
17240 + seq_printf(m, "," #str "=%u", val); \
17243 + /* lock free root dinfo */
17244 + sb = mnt->mnt_sb;
17245 + si_noflush_read_lock(sb);
17246 + sbinfo = au_sbi(sb);
17247 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
17249 + mnt_flags = au_mntflags(sb);
17250 + if (au_opt_test(mnt_flags, XINO)) {
17251 + err = au_show_xino(m, mnt);
17252 + if (unlikely(err))
17255 + seq_puts(m, ",noxino");
17257 + AuBool(TRUNC_XINO, trunc_xino);
17258 + AuStr(UDBA, udba);
17259 + AuBool(SHWH, shwh);
17260 + AuBool(PLINK, plink);
17261 + /* AuBool(DIRPERM1, dirperm1); */
17262 + /* AuBool(REFROF, refrof); */
17264 + v = sbinfo->si_wbr_create;
17265 + if (v != AuWbrCreate_Def)
17266 + au_show_wbr_create(m, v, sbinfo);
17268 + v = sbinfo->si_wbr_copyup;
17269 + if (v != AuWbrCopyup_Def)
17270 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
17272 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
17273 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
17274 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
17276 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
17278 + n = sbinfo->si_rdcache / HZ;
17279 + AuUInt(RDCACHE, rdcache, n);
17281 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
17282 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
17284 + AuBool(SUM, sum);
17285 + /* AuBool(SUM_W, wsum); */
17286 + AuBool(WARN_PERM, warn_perm);
17287 + AuBool(VERBOSE, verbose);
17290 + /* be sure to print "br:" last */
17291 + if (!sysaufs_brs) {
17292 + seq_puts(m, ",br:");
17293 + au_show_brs(m, sb);
17295 + si_read_unlock(sb);
17303 +/* ---------------------------------------------------------------------- */
17305 +/* sum mode which returns the summation for statfs(2) */
17307 +static u64 au_add_till_max(u64 a, u64 b)
17315 + return ULLONG_MAX;
17318 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
17321 + u64 blocks, bfree, bavail, files, ffree;
17322 + aufs_bindex_t bend, bindex, i;
17323 + unsigned char shared;
17324 + struct vfsmount *h_mnt;
17325 + struct super_block *h_sb;
17334 + bend = au_sbend(sb);
17335 + for (bindex = bend; bindex >= 0; bindex--) {
17336 + h_mnt = au_sbr_mnt(sb, bindex);
17337 + h_sb = h_mnt->mnt_sb;
17339 + for (i = bindex + 1; !shared && i <= bend; i++)
17340 + shared = (au_sbr_sb(sb, i) == h_sb);
17344 + /* sb->s_root for NFS is unreliable */
17345 + err = vfs_statfs(h_mnt->mnt_root, buf);
17346 + if (unlikely(err))
17349 + blocks = au_add_till_max(blocks, buf->f_blocks);
17350 + bfree = au_add_till_max(bfree, buf->f_bfree);
17351 + bavail = au_add_till_max(bavail, buf->f_bavail);
17352 + files = au_add_till_max(files, buf->f_files);
17353 + ffree = au_add_till_max(ffree, buf->f_ffree);
17356 + buf->f_blocks = blocks;
17357 + buf->f_bfree = bfree;
17358 + buf->f_bavail = bavail;
17359 + buf->f_files = files;
17360 + buf->f_ffree = ffree;
17366 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
17369 + struct super_block *sb;
17371 + /* lock free root dinfo */
17372 + sb = dentry->d_sb;
17373 + si_noflush_read_lock(sb);
17374 + if (!au_opt_test(au_mntflags(sb), SUM))
17375 + /* sb->s_root for NFS is unreliable */
17376 + err = vfs_statfs(au_sbr_mnt(sb, 0)->mnt_root, buf);
17378 + err = au_statfs_sum(sb, buf);
17379 + si_read_unlock(sb);
17382 + buf->f_type = AUFS_SUPER_MAGIC;
17383 + buf->f_namelen -= AUFS_WH_PFX_LEN;
17384 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
17386 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
17391 +/* ---------------------------------------------------------------------- */
17393 +/* try flushing the lower fs at aufs remount/unmount time */
17395 +static void au_fsync_br(struct super_block *sb)
17397 + aufs_bindex_t bend, bindex;
17399 + struct au_branch *br;
17400 + struct super_block *h_sb;
17402 + bend = au_sbend(sb);
17403 + for (bindex = 0; bindex < bend; bindex++) {
17404 + br = au_sbr(sb, bindex);
17405 + brperm = br->br_perm;
17406 + if (brperm == AuBrPerm_RR || brperm == AuBrPerm_RRWH)
17408 + h_sb = br->br_mnt->mnt_sb;
17409 + if (bdev_read_only(h_sb->s_bdev))
17413 + down_write(&h_sb->s_umount);
17414 + shrink_dcache_sb(h_sb);
17415 + fsync_super(h_sb);
17416 + up_write(&h_sb->s_umount);
17422 + * this IS NOT for super_operations.
17423 + * I guess it will be reverted someday.
17425 +static void aufs_umount_begin(struct super_block *sb)
17427 + struct au_sbinfo *sbinfo;
17429 + sbinfo = au_sbi(sb);
17433 + si_write_lock(sb);
17435 + if (au_opt_test(au_mntflags(sb), PLINK))
17436 + au_plink_put(sb);
17437 + if (sbinfo->si_wbr_create_ops->fin)
17438 + sbinfo->si_wbr_create_ops->fin(sb);
17439 + si_write_unlock(sb);
17442 +/* final actions when unmounting a file system */
17443 +static void aufs_put_super(struct super_block *sb)
17445 + struct au_sbinfo *sbinfo;
17447 + sbinfo = au_sbi(sb);
17451 + aufs_umount_begin(sb);
17452 + dbgaufs_si_fin(sbinfo);
17453 + kobject_put(&sbinfo->si_kobj);
17456 +/* ---------------------------------------------------------------------- */
17459 + * refresh dentry and inode at remount time.
17461 +static int do_refresh(struct dentry *dentry, mode_t type,
17462 + unsigned int dir_flags)
17465 + struct dentry *parent;
17467 + di_write_lock_child(dentry);
17468 + parent = dget_parent(dentry);
17469 + di_read_lock_parent(parent, AuLock_IR);
17471 + /* returns the number of positive dentries */
17472 + err = au_refresh_hdentry(dentry, type);
17474 + struct inode *inode = dentry->d_inode;
17475 + err = au_refresh_hinode(inode, dentry);
17476 + if (!err && type == S_IFDIR)
17477 + au_reset_hinotify(inode, dir_flags);
17479 + if (unlikely(err))
17480 + AuErr("unrecoverable error %d, %.*s\n", err, AuDLNPair(dentry));
17482 + di_read_unlock(parent, AuLock_IR);
17484 + di_write_unlock(dentry);
17489 +static int test_dir(struct dentry *dentry, void *arg __maybe_unused)
17491 + return S_ISDIR(dentry->d_inode->i_mode);
17494 +/* gave up consolidating with refresh_nondir() */
17495 +static int refresh_dir(struct dentry *root, unsigned int sigen)
17497 + int err, i, j, ndentry, e;
17498 + struct au_dcsub_pages dpages;
17499 + struct au_dpage *dpage;
17500 + struct dentry **dentries;
17501 + struct inode *inode;
17502 + const unsigned int flags = au_hi_flags(root->d_inode, /*isdir*/1);
17505 + list_for_each_entry(inode, &root->d_sb->s_inodes, i_sb_list)
17506 + if (S_ISDIR(inode->i_mode) && au_iigen(inode) != sigen) {
17507 + ii_write_lock_child(inode);
17508 + e = au_refresh_hinode_self(inode, /*do_attr*/1);
17509 + ii_write_unlock(inode);
17510 + if (unlikely(e)) {
17511 + AuDbg("e %d, i%lu\n", e, inode->i_ino);
17514 + /* go on even if err */
17518 + e = au_dpages_init(&dpages, GFP_NOFS);
17519 + if (unlikely(e)) {
17524 + e = au_dcsub_pages(&dpages, root, test_dir, NULL);
17525 + if (unlikely(e)) {
17531 + for (i = 0; !e && i < dpages.ndpage; i++) {
17532 + dpage = dpages.dpages + i;
17533 + dentries = dpage->dentries;
17534 + ndentry = dpage->ndentry;
17535 + for (j = 0; !e && j < ndentry; j++) {
17536 + struct dentry *d;
17539 + au_dbg_verify_dir_parent(d, sigen);
17540 + if (au_digen(d) != sigen) {
17541 + e = do_refresh(d, S_IFDIR, flags);
17542 + if (unlikely(e && !err))
17544 + /* break on err */
17550 + au_dpages_free(&dpages);
17555 +static int test_nondir(struct dentry *dentry, void *arg __maybe_unused)
17557 + return !S_ISDIR(dentry->d_inode->i_mode);
17560 +static int refresh_nondir(struct dentry *root, unsigned int sigen,
17563 + int err, i, j, ndentry, e;
17564 + struct au_dcsub_pages dpages;
17565 + struct au_dpage *dpage;
17566 + struct dentry **dentries;
17567 + struct inode *inode;
17570 + list_for_each_entry(inode, &root->d_sb->s_inodes, i_sb_list)
17571 + if (!S_ISDIR(inode->i_mode) && au_iigen(inode) != sigen) {
17572 + ii_write_lock_child(inode);
17573 + e = au_refresh_hinode_self(inode, /*do_attr*/1);
17574 + ii_write_unlock(inode);
17575 + if (unlikely(e)) {
17576 + AuDbg("e %d, i%lu\n", e, inode->i_ino);
17579 + /* go on even if err */
17586 + e = au_dpages_init(&dpages, GFP_NOFS);
17587 + if (unlikely(e)) {
17592 + e = au_dcsub_pages(&dpages, root, test_nondir, NULL);
17593 + if (unlikely(e)) {
17599 + for (i = 0; i < dpages.ndpage; i++) {
17600 + dpage = dpages.dpages + i;
17601 + dentries = dpage->dentries;
17602 + ndentry = dpage->ndentry;
17603 + for (j = 0; j < ndentry; j++) {
17604 + struct dentry *d;
17607 + au_dbg_verify_nondir_parent(d, sigen);
17608 + inode = d->d_inode;
17609 + if (inode && au_digen(d) != sigen) {
17610 + e = do_refresh(d, inode->i_mode & S_IFMT,
17612 + if (unlikely(e && !err))
17614 + /* go on even err */
17620 + au_dpages_free(&dpages);
17625 +static void au_remount_refresh(struct super_block *sb, unsigned int flags)
17628 + unsigned int sigen;
17629 + struct au_sbinfo *sbinfo;
17630 + struct dentry *root;
17631 + struct inode *inode;
17633 + au_sigen_inc(sb);
17634 + sigen = au_sigen(sb);
17635 + sbinfo = au_sbi(sb);
17636 + au_fclr_si(sbinfo, FAILED_REFRESH_DIRS);
17638 + root = sb->s_root;
17639 + DiMustNoWaiters(root);
17640 + inode = root->d_inode;
17641 + IiMustNoWaiters(inode);
17642 + au_reset_hinotify(inode, au_hi_flags(inode, /*isdir*/1));
17643 + di_write_unlock(root);
17645 + err = refresh_dir(root, sigen);
17646 + if (unlikely(err)) {
17647 + au_fset_si(sbinfo, FAILED_REFRESH_DIRS);
17648 + AuWarn("Refreshing directories failed, ignored (%d)\n", err);
17651 + if (au_ftest_opts(flags, REFRESH_NONDIR)) {
17652 + err = refresh_nondir(root, sigen, !err);
17653 + if (unlikely(err))
17654 + AuWarn("Refreshing non-directories failed, ignored"
17658 + /* aufs_write_lock() calls ..._child() */
17659 + di_write_lock_child(root);
17660 + au_cpup_attr_all(root->d_inode, /*force*/1);
17663 +/* stop extra interpretation of errno in mount(8), and strange error messages */
17664 +static int cvt_err(int err)
17678 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
17681 + struct au_opts opts;
17682 + struct dentry *root;
17683 + struct inode *inode;
17684 + struct au_sbinfo *sbinfo;
17687 + root = sb->s_root;
17688 + if (!data || !*data) {
17689 + aufs_write_lock(root);
17690 + err = au_opts_verify(sb, *flags, /*pending*/0);
17693 + aufs_write_unlock(root);
17698 + memset(&opts, 0, sizeof(opts));
17699 + opts.opt = (void *)__get_free_page(GFP_NOFS);
17700 + if (unlikely(!opts.opt))
17702 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
17703 + opts.flags = AuOpts_REMOUNT;
17704 + opts.sb_flags = *flags;
17706 + /* parse it before aufs lock */
17707 + err = au_opts_parse(sb, data, &opts);
17708 + if (unlikely(err))
17711 + sbinfo = au_sbi(sb);
17712 + inode = root->d_inode;
17713 + mutex_lock(&inode->i_mutex);
17714 + aufs_write_lock(root);
17717 + /* au_opts_remount() may return an error */
17718 + err = au_opts_remount(sb, &opts);
17719 + au_opts_free(&opts);
17721 + if (au_ftest_opts(opts.flags, REFRESH_DIR)
17722 + || au_ftest_opts(opts.flags, REFRESH_NONDIR))
17723 + au_remount_refresh(sb, opts.flags);
17725 + aufs_write_unlock(root);
17726 + mutex_unlock(&inode->i_mutex);
17729 + free_page((unsigned long)opts.opt);
17731 + err = cvt_err(err);
17736 +static struct super_operations aufs_sop = {
17737 + .alloc_inode = aufs_alloc_inode,
17738 + .destroy_inode = aufs_destroy_inode,
17739 + .drop_inode = generic_delete_inode,
17740 + .show_options = aufs_show_options,
17741 + .statfs = aufs_statfs,
17742 + .put_super = aufs_put_super,
17743 + .remount_fs = aufs_remount_fs
17746 +/* ---------------------------------------------------------------------- */
17748 +static int alloc_root(struct super_block *sb)
17751 + struct inode *inode;
17752 + struct dentry *root;
17755 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
17756 + err = PTR_ERR(inode);
17757 + if (IS_ERR(inode))
17760 + inode->i_op = &aufs_dir_iop;
17761 + inode->i_fop = &aufs_dir_fop;
17762 + inode->i_mode = S_IFDIR;
17763 + inode->i_nlink = 2;
17764 + unlock_new_inode(inode);
17766 + root = d_alloc_root(inode);
17767 + if (unlikely(!root))
17769 + err = PTR_ERR(root);
17770 + if (IS_ERR(root))
17773 + err = au_alloc_dinfo(root);
17775 + sb->s_root = root;
17776 + return 0; /* success */
17779 + goto out; /* do not iput */
17782 + iget_failed(inode);
17789 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
17790 + int silent __maybe_unused)
17793 + struct au_opts opts;
17794 + struct dentry *root;
17795 + struct inode *inode;
17796 + char *arg = raw_data;
17798 + if (unlikely(!arg || !*arg)) {
17800 + AuErr("no arg\n");
17805 + memset(&opts, 0, sizeof(opts));
17806 + opts.opt = (void *)__get_free_page(GFP_NOFS);
17807 + if (unlikely(!opts.opt))
17809 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
17810 + opts.sb_flags = sb->s_flags;
17812 + err = au_si_alloc(sb);
17813 + if (unlikely(err))
17816 + /* all timestamps always follow the ones on the branch */
17817 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
17818 + sb->s_op = &aufs_sop;
17819 + sb->s_magic = AUFS_SUPER_MAGIC;
17820 + sb->s_maxbytes = 0;
17821 + au_export_init(sb);
17823 + err = alloc_root(sb);
17824 + if (unlikely(err)) {
17825 + si_write_unlock(sb);
17828 + root = sb->s_root;
17829 + inode = root->d_inode;
17832 + * actually we can parse options regardless aufs lock here.
17833 + * but at remount time, parsing must be done before aufs lock.
17834 + * so we follow the same rule.
17836 + ii_write_lock_parent(inode);
17837 + aufs_write_unlock(root);
17838 + err = au_opts_parse(sb, arg, &opts);
17839 + if (unlikely(err))
17842 + /* lock vfs_inode first, then aufs. */
17843 + mutex_lock(&inode->i_mutex);
17844 + inode->i_op = &aufs_dir_iop;
17845 + inode->i_fop = &aufs_dir_fop;
17846 + aufs_write_lock(root);
17847 + err = au_opts_mount(sb, &opts);
17848 + au_opts_free(&opts);
17849 + if (unlikely(err))
17851 + aufs_write_unlock(root);
17852 + mutex_unlock(&inode->i_mutex);
17853 + goto out_opts; /* success */
17856 + aufs_write_unlock(root);
17857 + mutex_unlock(&inode->i_mutex);
17860 + sb->s_root = NULL;
17862 + kobject_put(&au_sbi(sb)->si_kobj);
17863 + sb->s_fs_info = NULL;
17865 + free_page((unsigned long)opts.opt);
17868 + err = cvt_err(err);
17873 +/* ---------------------------------------------------------------------- */
17875 +static int aufs_get_sb(struct file_system_type *fs_type, int flags,
17876 + const char *dev_name __maybe_unused, void *raw_data,
17877 + struct vfsmount *mnt)
17880 + struct super_block *sb;
17882 + /* all timestamps always follow the ones on the branch */
17883 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
17884 + err = get_sb_nodev(fs_type, flags, raw_data, aufs_fill_super, mnt);
17886 + sb = mnt->mnt_sb;
17887 + si_write_lock(sb);
17888 + sysaufs_brs_add(sb, 0);
17889 + si_write_unlock(sb);
17894 +struct file_system_type aufs_fs_type = {
17895 + .name = AUFS_FSTYPE,
17897 + FS_RENAME_DOES_D_MOVE /* a race between rename and others */
17898 + | FS_REVAL_DOT, /* for NFS branch and udba */
17899 + .get_sb = aufs_get_sb,
17900 + .kill_sb = generic_shutdown_super,
17901 + /* no need to __module_get() and module_put(). */
17902 + .owner = THIS_MODULE,
17904 diff -urN linux-2.6.30.org/fs/aufs/super.h linux-2.6.30/fs/aufs/super.h
17905 --- linux-2.6.30.org/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
17906 +++ linux-2.6.30/fs/aufs/super.h 2009-07-21 08:54:19.000000000 +0200
17909 + * Copyright (C) 2005-2009 Junjiro R. Okajima
17911 + * This program, aufs is free software; you can redistribute it and/or modify
17912 + * it under the terms of the GNU General Public License as published by
17913 + * the Free Software Foundation; either version 2 of the License, or
17914 + * (at your option) any later version.
17916 + * This program is distributed in the hope that it will be useful,
17917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17919 + * GNU General Public License for more details.
17921 + * You should have received a copy of the GNU General Public License
17922 + * along with this program; if not, write to the Free Software
17923 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17927 + * super_block operations
17930 +#ifndef __AUFS_SUPER_H__
17931 +#define __AUFS_SUPER_H__
17935 +#include <linux/fs.h>
17936 +#include <linux/aufs_type.h>
17937 +#include "rwsem.h"
17941 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
17942 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
17945 +/* policies to select one among multiple writable branches */
17946 +struct au_wbr_copyup_operations {
17947 + int (*copyup)(struct dentry *dentry);
17950 +struct au_wbr_create_operations {
17951 + int (*create)(struct dentry *dentry, int isdir);
17952 + int (*init)(struct super_block *sb);
17953 + int (*fin)(struct super_block *sb);
17956 +struct au_wbr_mfs {
17957 + struct mutex mfs_lock; /* protect this structure */
17958 + unsigned long mfs_jiffy;
17959 + unsigned long mfs_expire;
17960 + aufs_bindex_t mfs_bindex;
17962 + unsigned long long mfsrr_bytes;
17963 + unsigned long long mfsrr_watermark;
17967 +struct au_sbinfo {
17968 + /* nowait tasks in the system-wide workqueue */
17969 + struct au_nowait_tasks si_nowait;
17971 + struct au_rwsem si_rwsem;
17973 + /* branch management */
17974 + unsigned int si_generation;
17976 + /* see above flags */
17977 + unsigned char au_si_status;
17979 + aufs_bindex_t si_bend;
17980 + aufs_bindex_t si_last_br_id;
17981 + struct au_branch **si_branch;
17983 + /* policy to select a writable branch */
17984 + unsigned char si_wbr_copyup;
17985 + unsigned char si_wbr_create;
17986 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
17987 + struct au_wbr_create_operations *si_wbr_create_ops;
17989 + /* round robin */
17990 + atomic_t si_wbr_rr_next;
17992 + /* most free space */
17993 + struct au_wbr_mfs si_wbr_mfs;
17995 + /* mount flags */
17996 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
17997 + unsigned int si_mntflags;
17999 + /* external inode number (bitmap and translation table) */
18000 + au_readf_t si_xread;
18001 + au_writef_t si_xwrite;
18002 + struct file *si_xib;
18003 + struct mutex si_xib_mtx; /* protect xib members */
18004 + unsigned long *si_xib_buf;
18005 + unsigned long si_xib_last_pindex;
18006 + int si_xib_next_bit;
18007 + aufs_bindex_t si_xino_brid;
18008 + /* reserved for future use */
18009 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
18011 +#ifdef CONFIG_AUFS_EXPORT
18012 + /* i_generation */
18013 + struct file *si_xigen;
18014 + atomic_t si_xigen_next;
18017 + /* vdir parameters */
18018 + unsigned long si_rdcache; /* max cache time in HZ */
18019 + unsigned int si_rdblk; /* deblk size */
18020 + unsigned int si_rdhash; /* hash size */
18023 + * If the number of whiteouts are larger than si_dirwh, leave all of
18024 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
18025 + * future fsck.aufs or kernel thread will remove them later.
18026 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
18028 + unsigned int si_dirwh;
18031 + * rename(2) a directory with all children.
18033 + /* reserved for future use */
18034 + /* int si_rendir; */
18036 + /* pseudo_link list */
18037 + struct au_splhead si_plink;
18038 + wait_queue_head_t si_plink_wq;
18041 + * sysfs and lifetime management.
18042 + * this is not a small structure and it may be a waste of memory in case
18043 + * of sysfs is disabled, particulary when many aufs-es are mounted.
18044 + * but using sysfs is majority.
18046 + struct kobject si_kobj;
18047 +#ifdef CONFIG_DEBUG_FS
18048 + struct dentry *si_dbgaufs, *si_dbgaufs_xib;
18049 +#ifdef CONFIG_AUFS_EXPORT
18050 + struct dentry *si_dbgaufs_xigen;
18054 + /* dirty, necessary for unmounting, sysfs and sysrq */
18055 + struct super_block *si_sb;
18058 +/* sbinfo status flags */
18060 + * set true when refresh_dirs() failed at remount time.
18061 + * then try refreshing dirs at access time again.
18062 + * if it is false, refreshing dirs at access time is unnecesary
18064 +#define AuSi_FAILED_REFRESH_DIRS 1
18065 +#define AuSi_MAINTAIN_PLINK (1 << 1) /* ioctl */
18066 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
18067 + unsigned int flag)
18069 + AuRwMustAnyLock(&sbi->si_rwsem);
18070 + return sbi->au_si_status & flag;
18072 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
18073 +#define au_fset_si(sbinfo, name) do { \
18074 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
18075 + (sbinfo)->au_si_status |= AuSi_##name; \
18077 +#define au_fclr_si(sbinfo, name) do { \
18078 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
18079 + (sbinfo)->au_si_status &= ~AuSi_##name; \
18082 +/* ---------------------------------------------------------------------- */
18084 +/* policy to select one among writable branches */
18085 +#define AuWbrCopyup(sbinfo, args...) \
18086 + ((sbinfo)->si_wbr_copyup_ops->copyup(args))
18087 +#define AuWbrCreate(sbinfo, args...) \
18088 + ((sbinfo)->si_wbr_create_ops->create(args))
18090 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
18091 +#define AuLock_DW 1 /* write-lock dentry */
18092 +#define AuLock_IR (1 << 1) /* read-lock inode */
18093 +#define AuLock_IW (1 << 2) /* write-lock inode */
18094 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
18095 +#define AuLock_DIR (1 << 4) /* target is a dir */
18096 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
18097 +#define au_fset_lock(flags, name) { (flags) |= AuLock_##name; }
18098 +#define au_fclr_lock(flags, name) { (flags) &= ~AuLock_##name; }
18100 +/* ---------------------------------------------------------------------- */
18103 +extern struct file_system_type aufs_fs_type;
18104 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
18107 +void au_si_free(struct kobject *kobj);
18108 +int au_si_alloc(struct super_block *sb);
18109 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
18111 +unsigned int au_sigen_inc(struct super_block *sb);
18112 +aufs_bindex_t au_new_br_id(struct super_block *sb);
18114 +void aufs_read_lock(struct dentry *dentry, int flags);
18115 +void aufs_read_unlock(struct dentry *dentry, int flags);
18116 +void aufs_write_lock(struct dentry *dentry);
18117 +void aufs_write_unlock(struct dentry *dentry);
18118 +void aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int isdir);
18119 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
18121 +/* wbr_policy.c */
18122 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
18123 +extern struct au_wbr_create_operations au_wbr_create_ops[];
18124 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
18126 +/* ---------------------------------------------------------------------- */
18128 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
18130 + return sb->s_fs_info;
18133 +/* ---------------------------------------------------------------------- */
18135 +#ifdef CONFIG_AUFS_EXPORT
18136 +void au_export_init(struct super_block *sb);
18138 +static inline int au_test_nfsd(struct task_struct *tsk)
18140 + return !tsk->mm && !strcmp(tsk->comm, "nfsd");
18143 +int au_xigen_inc(struct inode *inode);
18144 +int au_xigen_new(struct inode *inode);
18145 +int au_xigen_set(struct super_block *sb, struct file *base);
18146 +void au_xigen_clr(struct super_block *sb);
18148 +static inline int au_busy_or_stale(void)
18150 + if (!au_test_nfsd(current))
18155 +static inline void au_export_init(struct super_block *sb)
18160 +static inline int au_test_nfsd(struct task_struct *tsk)
18165 +static inline int au_xigen_inc(struct inode *inode)
18170 +static inline int au_xigen_new(struct inode *inode)
18175 +static inline int au_xigen_set(struct super_block *sb, struct file *base)
18180 +static inline void au_xigen_clr(struct super_block *sb)
18185 +static inline int au_busy_or_stale(void)
18189 +#endif /* CONFIG_AUFS_EXPORT */
18191 +/* ---------------------------------------------------------------------- */
18193 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
18196 + * This function is a dynamic '__init' fucntion actually,
18197 + * so the tiny check for si_rwsem is unnecessary.
18199 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
18200 +#ifdef CONFIG_DEBUG_FS
18201 + sbinfo->si_dbgaufs = NULL;
18202 + sbinfo->si_dbgaufs_xib = NULL;
18203 +#ifdef CONFIG_AUFS_EXPORT
18204 + sbinfo->si_dbgaufs_xigen = NULL;
18209 +/* ---------------------------------------------------------------------- */
18211 +/* lock superblock. mainly for entry point functions */
18213 + * si_noflush_read_lock, si_noflush_write_lock,
18214 + * si_read_unlock, si_write_unlock, si_downgrade_lock
18216 +AuSimpleLockRwsemFuncs(si_noflush, struct super_block *sb,
18217 + &au_sbi(sb)->si_rwsem);
18218 +AuSimpleUnlockRwsemFuncs(si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
18220 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
18221 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
18222 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
18224 +static inline void si_read_lock(struct super_block *sb, int flags)
18226 + if (au_ftest_lock(flags, FLUSH))
18227 + au_nwt_flush(&au_sbi(sb)->si_nowait);
18228 + si_noflush_read_lock(sb);
18231 +static inline void si_write_lock(struct super_block *sb)
18233 + au_nwt_flush(&au_sbi(sb)->si_nowait);
18234 + si_noflush_write_lock(sb);
18237 +static inline int si_read_trylock(struct super_block *sb, int flags)
18239 + if (au_ftest_lock(flags, FLUSH))
18240 + au_nwt_flush(&au_sbi(sb)->si_nowait);
18241 + return si_noflush_read_trylock(sb);
18244 +static inline int si_write_trylock(struct super_block *sb, int flags)
18246 + if (au_ftest_lock(flags, FLUSH))
18247 + au_nwt_flush(&au_sbi(sb)->si_nowait);
18248 + return si_noflush_write_trylock(sb);
18251 +/* ---------------------------------------------------------------------- */
18253 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
18255 + SiMustAnyLock(sb);
18256 + return au_sbi(sb)->si_bend;
18259 +static inline unsigned int au_mntflags(struct super_block *sb)
18261 + SiMustAnyLock(sb);
18262 + return au_sbi(sb)->si_mntflags;
18265 +static inline unsigned int au_sigen(struct super_block *sb)
18267 + SiMustAnyLock(sb);
18268 + return au_sbi(sb)->si_generation;
18271 +static inline struct au_branch *au_sbr(struct super_block *sb,
18272 + aufs_bindex_t bindex)
18274 + SiMustAnyLock(sb);
18275 + return au_sbi(sb)->si_branch[0 + bindex];
18278 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
18280 + SiMustWriteLock(sb);
18281 + au_sbi(sb)->si_xino_brid = brid;
18284 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
18286 + SiMustAnyLock(sb);
18287 + return au_sbi(sb)->si_xino_brid;
18290 +#endif /* __KERNEL__ */
18291 +#endif /* __AUFS_SUPER_H__ */
18292 diff -urN linux-2.6.30.org/fs/aufs/sysaufs.c linux-2.6.30/fs/aufs/sysaufs.c
18293 --- linux-2.6.30.org/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
18294 +++ linux-2.6.30/fs/aufs/sysaufs.c 2009-07-21 08:54:19.000000000 +0200
18297 + * Copyright (C) 2005-2009 Junjiro R. Okajima
18299 + * This program, aufs is free software; you can redistribute it and/or modify
18300 + * it under the terms of the GNU General Public License as published by
18301 + * the Free Software Foundation; either version 2 of the License, or
18302 + * (at your option) any later version.
18304 + * This program is distributed in the hope that it will be useful,
18305 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18306 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18307 + * GNU General Public License for more details.
18309 + * You should have received a copy of the GNU General Public License
18310 + * along with this program; if not, write to the Free Software
18311 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18315 + * sysfs interface and lifetime management
18316 + * they are necessary regardless sysfs is disabled.
18319 +#include <linux/fs.h>
18320 +#include <linux/random.h>
18321 +#include <linux/sysfs.h>
18324 +unsigned long sysaufs_si_mask;
18325 +struct kset *sysaufs_ket;
18327 +#define AuSiAttr(_name) { \
18328 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
18329 + .show = sysaufs_si_##_name, \
18332 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
18333 +struct attribute *sysaufs_si_attrs[] = {
18334 + &sysaufs_si_attr_xi_path.attr,
18338 +static struct sysfs_ops au_sbi_ops = {
18339 + .show = sysaufs_si_show
18342 +static struct kobj_type au_sbi_ktype = {
18343 + .release = au_si_free,
18344 + .sysfs_ops = &au_sbi_ops,
18345 + .default_attrs = sysaufs_si_attrs
18348 +/* ---------------------------------------------------------------------- */
18350 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
18354 + sbinfo->si_kobj.kset = sysaufs_ket;
18355 + /* cf. sysaufs_name() */
18356 + err = kobject_init_and_add
18357 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_ket->kobj*/NULL,
18358 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
18360 + dbgaufs_si_null(sbinfo);
18362 + err = dbgaufs_si_init(sbinfo);
18363 + if (unlikely(err))
18364 + kobject_put(&sbinfo->si_kobj);
18369 +void sysaufs_fin(void)
18372 + sysfs_remove_group(&sysaufs_ket->kobj, sysaufs_attr_group);
18373 + kset_unregister(sysaufs_ket);
18376 +int __init sysaufs_init(void)
18381 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
18382 + } while (!sysaufs_si_mask);
18384 + sysaufs_ket = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
18385 + err = PTR_ERR(sysaufs_ket);
18386 + if (IS_ERR(sysaufs_ket))
18388 + err = sysfs_create_group(&sysaufs_ket->kobj, sysaufs_attr_group);
18389 + if (unlikely(err)) {
18390 + kset_unregister(sysaufs_ket);
18394 + err = dbgaufs_init();
18395 + if (unlikely(err))
18400 diff -urN linux-2.6.30.org/fs/aufs/sysaufs.h linux-2.6.30/fs/aufs/sysaufs.h
18401 --- linux-2.6.30.org/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
18402 +++ linux-2.6.30/fs/aufs/sysaufs.h 2009-07-21 08:54:19.000000000 +0200
18405 + * Copyright (C) 2005-2009 Junjiro R. Okajima
18407 + * This program, aufs is free software; you can redistribute it and/or modify
18408 + * it under the terms of the GNU General Public License as published by
18409 + * the Free Software Foundation; either version 2 of the License, or
18410 + * (at your option) any later version.
18412 + * This program is distributed in the hope that it will be useful,
18413 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18414 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18415 + * GNU General Public License for more details.
18417 + * You should have received a copy of the GNU General Public License
18418 + * along with this program; if not, write to the Free Software
18419 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18423 + * sysfs interface and mount lifetime management
18426 +#ifndef __SYSAUFS_H__
18427 +#define __SYSAUFS_H__
18431 +#include <linux/sysfs.h>
18432 +#include <linux/aufs_type.h>
18433 +#include "module.h"
18435 +struct super_block;
18438 +struct sysaufs_si_attr {
18439 + struct attribute attr;
18440 + int (*show)(struct seq_file *seq, struct super_block *sb);
18443 +/* ---------------------------------------------------------------------- */
18446 +extern unsigned long sysaufs_si_mask;
18447 +extern struct kset *sysaufs_ket;
18448 +extern struct attribute *sysaufs_si_attrs[];
18449 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
18450 +int __init sysaufs_init(void);
18451 +void sysaufs_fin(void);
18453 +/* ---------------------------------------------------------------------- */
18455 +/* some people doesn't like to show a pointer in kernel */
18456 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
18458 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
18461 +#define SysaufsSiNamePrefix "si_"
18462 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
18463 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
18465 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
18466 + sysaufs_si_id(sbinfo));
18470 +#ifdef CONFIG_SYSFS
18472 +extern struct attribute_group *sysaufs_attr_group;
18474 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
18475 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
18478 +void sysaufs_br_init(struct au_branch *br);
18479 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
18480 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
18482 +#define sysaufs_brs_init() do {} while (0)
18485 +#define sysaufs_attr_group NULL
18488 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
18494 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
18500 +static inline void sysaufs_br_init(struct au_branch *br)
18505 +static inline void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
18510 +static inline void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
18515 +static inline void sysaufs_brs_init(void)
18520 +#endif /* CONFIG_SYSFS */
18522 +#endif /* __KERNEL__ */
18523 +#endif /* __SYSAUFS_H__ */
18524 diff -urN linux-2.6.30.org/fs/aufs/sysfs.c linux-2.6.30/fs/aufs/sysfs.c
18525 --- linux-2.6.30.org/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
18526 +++ linux-2.6.30/fs/aufs/sysfs.c 2009-07-21 08:54:19.000000000 +0200
18529 + * Copyright (C) 2005-2009 Junjiro R. Okajima
18531 + * This program, aufs is free software; you can redistribute it and/or modify
18532 + * it under the terms of the GNU General Public License as published by
18533 + * the Free Software Foundation; either version 2 of the License, or
18534 + * (at your option) any later version.
18536 + * This program is distributed in the hope that it will be useful,
18537 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18538 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18539 + * GNU General Public License for more details.
18541 + * You should have received a copy of the GNU General Public License
18542 + * along with this program; if not, write to the Free Software
18543 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18547 + * sysfs interface
18550 +#include <linux/fs.h>
18551 +#include <linux/module.h>
18552 +#include <linux/seq_file.h>
18553 +#include <linux/sysfs.h>
18556 +static struct attribute *au_attr[] = {
18557 + NULL, /* need to NULL terminate the list of attributes */
18560 +static struct attribute_group sysaufs_attr_group_body = {
18564 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
18566 +/* ---------------------------------------------------------------------- */
18568 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
18572 + SiMustAnyLock(sb);
18575 + if (au_opt_test(au_mntflags(sb), XINO)) {
18576 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
18577 + seq_putc(seq, '\n');
18583 + * the lifetime of branch is independent from the entry under sysfs.
18584 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
18587 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
18588 + aufs_bindex_t bindex)
18590 + struct path path;
18591 + struct dentry *root;
18592 + struct au_branch *br;
18594 + AuDbg("b%d\n", bindex);
18596 + root = sb->s_root;
18597 + di_read_lock_parent(root, !AuLock_IR);
18598 + br = au_sbr(sb, bindex);
18599 + path.mnt = br->br_mnt;
18600 + path.dentry = au_h_dptr(root, bindex);
18601 + au_seq_path(seq, &path);
18602 + di_read_unlock(root, !AuLock_IR);
18603 + seq_printf(seq, "=%s\n", au_optstr_br_perm(br->br_perm));
18607 +/* ---------------------------------------------------------------------- */
18609 +static struct seq_file *au_seq(char *p, ssize_t len)
18611 + struct seq_file *seq;
18613 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
18615 + /* mutex_init(&seq.lock); */
18618 + return seq; /* success */
18621 + seq = ERR_PTR(-ENOMEM);
18625 +#define SysaufsBr_PREFIX "br"
18627 +/* todo: file size may exceed PAGE_SIZE */
18628 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
18633 + aufs_bindex_t bend;
18634 + struct au_sbinfo *sbinfo;
18635 + struct super_block *sb;
18636 + struct seq_file *seq;
18638 + struct attribute **cattr;
18640 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
18641 + sb = sbinfo->si_sb;
18642 + si_noflush_read_lock(sb);
18644 + seq = au_seq(buf, PAGE_SIZE);
18645 + err = PTR_ERR(seq);
18649 + name = (void *)attr->name;
18650 + cattr = sysaufs_si_attrs;
18652 + if (!strcmp(name, (*cattr)->name)) {
18653 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
18660 + bend = au_sbend(sb);
18661 + if (!strncmp(name, SysaufsBr_PREFIX, sizeof(SysaufsBr_PREFIX) - 1)) {
18662 + name += sizeof(SysaufsBr_PREFIX) - 1;
18663 + err = strict_strtol(name, 10, &l);
18666 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l);
18676 + err = seq->count;
18677 + /* sysfs limit */
18678 + if (unlikely(err == PAGE_SIZE))
18683 + si_read_unlock(sb);
18687 +/* ---------------------------------------------------------------------- */
18689 +void sysaufs_br_init(struct au_branch *br)
18691 + br->br_attr.name = br->br_name;
18692 + br->br_attr.mode = S_IRUGO;
18693 + br->br_attr.owner = THIS_MODULE;
18696 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
18698 + struct au_branch *br;
18699 + struct kobject *kobj;
18700 + aufs_bindex_t bend;
18702 + dbgaufs_brs_del(sb, bindex);
18704 + if (!sysaufs_brs)
18707 + kobj = &au_sbi(sb)->si_kobj;
18708 + bend = au_sbend(sb);
18709 + for (; bindex <= bend; bindex++) {
18710 + br = au_sbr(sb, bindex);
18711 + sysfs_remove_file(kobj, &br->br_attr);
18715 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
18718 + aufs_bindex_t bend;
18719 + struct kobject *kobj;
18720 + struct au_branch *br;
18722 + dbgaufs_brs_add(sb, bindex);
18724 + if (!sysaufs_brs)
18727 + kobj = &au_sbi(sb)->si_kobj;
18728 + bend = au_sbend(sb);
18729 + for (; bindex <= bend; bindex++) {
18730 + br = au_sbr(sb, bindex);
18731 + snprintf(br->br_name, sizeof(br->br_name), SysaufsBr_PREFIX
18733 + err = sysfs_create_file(kobj, &br->br_attr);
18734 + if (unlikely(err))
18735 + AuWarn("failed %s under sysfs(%d)\n", br->br_name, err);
18738 diff -urN linux-2.6.30.org/fs/aufs/sysrq.c linux-2.6.30/fs/aufs/sysrq.c
18739 --- linux-2.6.30.org/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
18740 +++ linux-2.6.30/fs/aufs/sysrq.c 2009-07-21 08:54:19.000000000 +0200
18743 + * Copyright (C) 2005-2009 Junjiro R. Okajima
18745 + * This program, aufs is free software; you can redistribute it and/or modify
18746 + * it under the terms of the GNU General Public License as published by
18747 + * the Free Software Foundation; either version 2 of the License, or
18748 + * (at your option) any later version.
18750 + * This program is distributed in the hope that it will be useful,
18751 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18752 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18753 + * GNU General Public License for more details.
18755 + * You should have received a copy of the GNU General Public License
18756 + * along with this program; if not, write to the Free Software
18757 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18761 + * magic sysrq hanlder
18764 +#include <linux/fs.h>
18765 +#include <linux/module.h>
18766 +#include <linux/moduleparam.h>
18767 +/* #include <linux/sysrq.h> */
18770 +/* ---------------------------------------------------------------------- */
18772 +static void sysrq_sb(struct super_block *sb)
18775 + struct au_sbinfo *sbinfo;
18776 + struct file *file;
18778 + plevel = au_plevel;
18779 + au_plevel = KERN_WARNING;
18782 + sbinfo = au_sbi(sb);
18783 + pr_warning("si=%lx\n", sysaufs_si_id(sbinfo));
18784 + pr_warning(AUFS_NAME ": superblock\n");
18786 + pr_warning(AUFS_NAME ": root dentry\n");
18787 + au_dpri_dentry(sb->s_root);
18788 + pr_warning(AUFS_NAME ": root inode\n");
18789 + au_dpri_inode(sb->s_root->d_inode);
18792 + pr_warning(AUFS_NAME ": isolated inode\n");
18793 + list_for_each_entry(i, &sb->s_inodes, i_sb_list)
18794 + if (list_empty(&i->i_dentry))
18795 + au_dpri_inode(i);
18797 + pr_warning(AUFS_NAME ": files\n");
18798 + list_for_each_entry(file, &sb->s_files, f_u.fu_list)
18799 + if (!special_file(file->f_dentry->d_inode->i_mode))
18800 + au_dpri_file(file);
18802 + au_plevel = plevel;
18806 +/* ---------------------------------------------------------------------- */
18808 +/* module parameter */
18809 +static char *aufs_sysrq_key = "a";
18810 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
18811 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
18813 +static void au_sysrq(int key __maybe_unused,
18814 + struct tty_struct *tty __maybe_unused)
18816 + struct kobject *kobj;
18817 + struct au_sbinfo *sbinfo;
18819 + /* spin_lock(&sysaufs_ket->list_lock); */
18820 + list_for_each_entry(kobj, &sysaufs_ket->list, entry) {
18821 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
18822 + sysrq_sb(sbinfo->si_sb);
18824 + /* spin_unlock(&sysaufs_ket->list_lock); */
18827 +static struct sysrq_key_op au_sysrq_op = {
18828 + .handler = au_sysrq,
18829 + .help_msg = "Aufs",
18830 + .action_msg = "Aufs",
18831 + .enable_mask = SYSRQ_ENABLE_DUMP
18834 +/* ---------------------------------------------------------------------- */
18836 +int __init au_sysrq_init(void)
18842 + key = *aufs_sysrq_key;
18843 + if ('a' <= key && key <= 'z')
18844 + err = register_sysrq_key(key, &au_sysrq_op);
18845 + if (unlikely(err))
18846 + AuErr("err %d, sysrq=%c\n", err, key);
18850 +void au_sysrq_fin(void)
18853 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
18854 + if (unlikely(err))
18855 + AuErr("err %d (ignored)\n", err);
18857 diff -urN linux-2.6.30.org/fs/aufs/vdir.c linux-2.6.30/fs/aufs/vdir.c
18858 --- linux-2.6.30.org/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
18859 +++ linux-2.6.30/fs/aufs/vdir.c 2009-07-21 08:54:19.000000000 +0200
18862 + * Copyright (C) 2005-2009 Junjiro R. Okajima
18864 + * This program, aufs is free software; you can redistribute it and/or modify
18865 + * it under the terms of the GNU General Public License as published by
18866 + * the Free Software Foundation; either version 2 of the License, or
18867 + * (at your option) any later version.
18869 + * This program is distributed in the hope that it will be useful,
18870 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18871 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18872 + * GNU General Public License for more details.
18874 + * You should have received a copy of the GNU General Public License
18875 + * along with this program; if not, write to the Free Software
18876 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18880 + * virtual or vertical directory
18883 +#include <linux/hash.h>
18886 +static unsigned int calc_size(int nlen)
18888 + BUILD_BUG_ON(sizeof(ino_t) != sizeof(long));
18889 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
18892 +static int set_deblk_end(union au_vdir_deblk_p *p,
18893 + union au_vdir_deblk_p *deblk_end)
18895 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
18896 + p->de->de_str.len = 0;
18900 + return -1; /* error */
18903 +/* returns true or false */
18904 +static int is_deblk_end(union au_vdir_deblk_p *p,
18905 + union au_vdir_deblk_p *deblk_end)
18907 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
18908 + return !p->de->de_str.len;
18912 +static unsigned char *last_deblk(struct au_vdir *vdir)
18914 + return vdir->vd_deblk[vdir->vd_nblk - 1];
18917 +/* ---------------------------------------------------------------------- */
18920 + * the allocated memory has to be freed by
18921 + * au_nhash_wh_free() or au_nhash_de_free().
18923 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
18925 + struct hlist_head *head;
18928 + head = kmalloc(sizeof(*nhash->nh_head) * num_hash, gfp);
18930 + nhash->nh_num = num_hash;
18931 + nhash->nh_head = head;
18932 + for (u = 0; u < num_hash; u++)
18933 + INIT_HLIST_HEAD(head++);
18934 + return 0; /* success */
18940 +static void nhash_count(struct hlist_head *head)
18944 + struct hlist_node *pos;
18947 + hlist_for_each(pos, head)
18949 + AuInfo("%lu\n", n);
18953 +static void au_nhash_wh_do_free(struct hlist_head *head)
18955 + struct au_vdir_wh *tpos;
18956 + struct hlist_node *pos, *node;
18958 + hlist_for_each_entry_safe(tpos, pos, node, head, wh_hash) {
18959 + /* hlist_del(pos); */
18964 +static void au_nhash_de_do_free(struct hlist_head *head)
18966 + struct au_vdir_dehstr *tpos;
18967 + struct hlist_node *pos, *node;
18969 + hlist_for_each_entry_safe(tpos, pos, node, head, hash) {
18970 + /* hlist_del(pos); */
18971 + au_cache_free_dehstr(tpos);
18975 +static void au_nhash_do_free(struct au_nhash *nhash,
18976 + void (*free)(struct hlist_head *head))
18978 + unsigned int u, n;
18979 + struct hlist_head *head;
18981 + n = nhash->nh_num;
18982 + head = nhash->nh_head;
18983 + for (u = 0; u < n; u++) {
18984 + nhash_count(head);
18987 + kfree(nhash->nh_head);
18990 +void au_nhash_wh_free(struct au_nhash *whlist)
18992 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
18995 +static void au_nhash_de_free(struct au_nhash *delist)
18997 + au_nhash_do_free(delist, au_nhash_de_do_free);
19000 +/* ---------------------------------------------------------------------- */
19002 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
19006 + unsigned int u, n;
19007 + struct hlist_head *head;
19008 + struct au_vdir_wh *tpos;
19009 + struct hlist_node *pos;
19012 + n = whlist->nh_num;
19013 + head = whlist->nh_head;
19014 + for (u = 0; u < n; u++) {
19015 + hlist_for_each_entry(tpos, pos, head, wh_hash)
19016 + if (tpos->wh_bindex == btgt && ++num > limit)
19023 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
19024 + unsigned char *name,
19025 + unsigned int len)
19028 + /* const unsigned int magic_bit = 12; */
19033 + /* v = hash_long(v, magic_bit); */
19034 + v %= nhash->nh_num;
19035 + return nhash->nh_head + v;
19038 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
19041 + return str->len == nlen && !memcmp(str->name, name, nlen);
19044 +/* returns found or not */
19045 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
19047 + struct hlist_head *head;
19048 + struct au_vdir_wh *tpos;
19049 + struct hlist_node *pos;
19050 + struct au_vdir_destr *str;
19052 + head = au_name_hash(whlist, name, nlen);
19053 + hlist_for_each_entry(tpos, pos, head, wh_hash) {
19054 + str = &tpos->wh_str;
19055 + AuDbg("%.*s\n", str->len, str->name);
19056 + if (au_nhash_test_name(str, name, nlen))
19062 +/* returns found(true) or not */
19063 +static int test_known(struct au_nhash *delist, char *name, int nlen)
19065 + struct hlist_head *head;
19066 + struct au_vdir_dehstr *tpos;
19067 + struct hlist_node *pos;
19068 + struct au_vdir_destr *str;
19070 + head = au_name_hash(delist, name, nlen);
19071 + hlist_for_each_entry(tpos, pos, head, hash) {
19073 + AuDbg("%.*s\n", str->len, str->name);
19074 + if (au_nhash_test_name(str, name, nlen))
19080 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
19081 + unsigned char d_type)
19083 +#ifdef CONFIG_AUFS_SHWH
19084 + wh->wh_ino = ino;
19085 + wh->wh_type = d_type;
19089 +/* ---------------------------------------------------------------------- */
19091 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
19092 + unsigned int d_type, aufs_bindex_t bindex,
19093 + unsigned char shwh)
19096 + struct au_vdir_destr *str;
19097 + struct au_vdir_wh *wh;
19099 + AuDbg("%.*s\n", nlen, name);
19101 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
19102 + if (unlikely(!wh))
19106 + wh->wh_bindex = bindex;
19108 + au_shwh_init_wh(wh, ino, d_type);
19109 + str = &wh->wh_str;
19111 + memcpy(str->name, name, nlen);
19112 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
19119 +static int append_deblk(struct au_vdir *vdir)
19122 + unsigned long ul;
19123 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
19124 + union au_vdir_deblk_p p, deblk_end;
19125 + unsigned char **o;
19128 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
19130 + if (unlikely(!o))
19133 + vdir->vd_deblk = o;
19134 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
19136 + ul = vdir->vd_nblk++;
19137 + vdir->vd_deblk[ul] = p.deblk;
19138 + vdir->vd_last.ul = ul;
19139 + vdir->vd_last.p.deblk = p.deblk;
19140 + deblk_end.deblk = p.deblk + deblk_sz;
19141 + err = set_deblk_end(&p, &deblk_end);
19148 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
19149 + unsigned int d_type, struct au_nhash *delist)
19153 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
19154 + union au_vdir_deblk_p p, *room, deblk_end;
19155 + struct au_vdir_dehstr *dehstr;
19157 + p.deblk = last_deblk(vdir);
19158 + deblk_end.deblk = p.deblk + deblk_sz;
19159 + room = &vdir->vd_last.p;
19160 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
19161 + || !is_deblk_end(room, &deblk_end));
19163 + sz = calc_size(nlen);
19164 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
19165 + err = append_deblk(vdir);
19166 + if (unlikely(err))
19169 + p.deblk = last_deblk(vdir);
19170 + deblk_end.deblk = p.deblk + deblk_sz;
19172 + AuDebugOn(room->deblk != p.deblk);
19176 + dehstr = au_cache_alloc_dehstr();
19177 + if (unlikely(!dehstr))
19180 + dehstr->str = &room->de->de_str;
19181 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
19182 + room->de->de_ino = ino;
19183 + room->de->de_type = d_type;
19184 + room->de->de_str.len = nlen;
19185 + memcpy(room->de->de_str.name, name, nlen);
19188 + room->deblk += sz;
19189 + if (unlikely(set_deblk_end(room, &deblk_end)))
19190 + err = append_deblk(vdir);
19197 +/* ---------------------------------------------------------------------- */
19199 +void au_vdir_free(struct au_vdir *vdir)
19201 + unsigned char **deblk;
19203 + deblk = vdir->vd_deblk;
19204 + while (vdir->vd_nblk--)
19206 + kfree(vdir->vd_deblk);
19207 + au_cache_free_vdir(vdir);
19210 +static struct au_vdir *alloc_vdir(struct super_block *sb)
19212 + struct au_vdir *vdir;
19215 + SiMustAnyLock(sb);
19218 + vdir = au_cache_alloc_vdir();
19219 + if (unlikely(!vdir))
19222 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
19223 + if (unlikely(!vdir->vd_deblk))
19226 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
19227 + vdir->vd_nblk = 0;
19228 + vdir->vd_version = 0;
19229 + vdir->vd_jiffy = 0;
19230 + err = append_deblk(vdir);
19232 + return vdir; /* success */
19234 + kfree(vdir->vd_deblk);
19237 + au_cache_free_vdir(vdir);
19239 + vdir = ERR_PTR(err);
19243 +static int reinit_vdir(struct au_vdir *vdir)
19246 + union au_vdir_deblk_p p, deblk_end;
19248 + while (vdir->vd_nblk > 1) {
19249 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
19250 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
19253 + p.deblk = vdir->vd_deblk[0];
19254 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
19255 + err = set_deblk_end(&p, &deblk_end);
19256 + /* keep vd_dblk_sz */
19257 + vdir->vd_last.ul = 0;
19258 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
19259 + vdir->vd_version = 0;
19260 + vdir->vd_jiffy = 0;
19265 +/* ---------------------------------------------------------------------- */
19267 +static int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19268 + unsigned int d_type, ino_t *ino)
19271 + struct mutex *mtx;
19272 + const int isdir = (d_type == DT_DIR);
19274 + /* prevent hardlinks from race condition */
19277 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
19280 + err = au_xino_read(sb, bindex, h_ino, ino);
19281 + if (unlikely(err))
19286 + *ino = au_xino_new_ino(sb);
19287 + if (unlikely(!*ino))
19289 + err = au_xino_write(sb, bindex, h_ino, *ino);
19290 + if (unlikely(err))
19296 + mutex_unlock(mtx);
19300 +static int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19301 + unsigned int d_type, ino_t *ino)
19303 +#ifdef CONFIG_AUFS_SHWH
19304 + return au_ino(sb, bindex, h_ino, d_type, ino);
19310 +#define AuFillVdir_CALLED 1
19311 +#define AuFillVdir_WHABLE (1 << 1)
19312 +#define AuFillVdir_SHWH (1 << 2)
19313 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
19314 +#define au_fset_fillvdir(flags, name) { (flags) |= AuFillVdir_##name; }
19315 +#define au_fclr_fillvdir(flags, name) { (flags) &= ~AuFillVdir_##name; }
19317 +#ifndef CONFIG_AUFS_SHWH
19318 +#undef AuFillVdir_SHWH
19319 +#define AuFillVdir_SHWH 0
19322 +struct fillvdir_arg {
19323 + struct file *file;
19324 + struct au_vdir *vdir;
19325 + struct au_nhash delist;
19326 + struct au_nhash whlist;
19327 + aufs_bindex_t bindex;
19328 + unsigned int flags;
19332 +static int fillvdir(void *__arg, const char *__name, int nlen,
19333 + loff_t offset __maybe_unused, u64 h_ino,
19334 + unsigned int d_type)
19336 + struct fillvdir_arg *arg = __arg;
19337 + char *name = (void *)__name;
19338 + struct super_block *sb;
19340 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
19343 + sb = arg->file->f_dentry->d_sb;
19344 + au_fset_fillvdir(arg->flags, CALLED);
19346 + if (nlen <= AUFS_WH_PFX_LEN
19347 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
19348 + if (test_known(&arg->delist, name, nlen)
19349 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
19350 + goto out; /* already exists or whiteouted */
19352 + sb = arg->file->f_dentry->d_sb;
19353 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
19355 + arg->err = append_de(arg->vdir, name, nlen, ino,
19356 + d_type, &arg->delist);
19357 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
19358 + name += AUFS_WH_PFX_LEN;
19359 + nlen -= AUFS_WH_PFX_LEN;
19360 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
19361 + goto out; /* already whiteouted */
19364 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
19367 + arg->err = au_nhash_append_wh
19368 + (&arg->whlist, name, nlen, ino, d_type,
19369 + arg->bindex, shwh);
19374 + arg->vdir->vd_jiffy = jiffies;
19376 + AuTraceErr(arg->err);
19380 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
19381 + struct au_nhash *whlist, struct au_nhash *delist)
19383 +#ifdef CONFIG_AUFS_SHWH
19385 + unsigned int nh, u;
19386 + struct hlist_head *head;
19387 + struct au_vdir_wh *tpos;
19388 + struct hlist_node *pos, *n;
19390 + struct au_vdir_destr *destr;
19392 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
19395 + o = p = __getname();
19396 + if (unlikely(!p))
19400 + nh = whlist->nh_num;
19401 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
19402 + p += AUFS_WH_PFX_LEN;
19403 + for (u = 0; u < nh; u++) {
19404 + head = whlist->nh_head + u;
19405 + hlist_for_each_entry_safe(tpos, pos, n, head, wh_hash) {
19406 + destr = &tpos->wh_str;
19407 + memcpy(p, destr->name, destr->len);
19408 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
19409 + tpos->wh_ino, tpos->wh_type, delist);
19410 + if (unlikely(err))
19425 +static int au_do_read_vdir(struct fillvdir_arg *arg)
19428 + unsigned int rdhash;
19430 + aufs_bindex_t bend, bindex, bstart;
19431 + unsigned char shwh;
19432 + struct file *hf, *file;
19433 + struct super_block *sb;
19435 + file = arg->file;
19436 + sb = file->f_dentry->d_sb;
19437 + SiMustAnyLock(sb);
19439 + rdhash = au_sbi(sb)->si_rdhash;
19440 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
19441 + if (unlikely(err))
19443 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
19444 + if (unlikely(err))
19450 + if (au_opt_test(au_mntflags(sb), SHWH)) {
19452 + au_fset_fillvdir(arg->flags, SHWH);
19454 + bstart = au_fbstart(file);
19455 + bend = au_fbend(file);
19456 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
19457 + hf = au_h_fptr(file, bindex);
19461 + offset = vfsub_llseek(hf, 0, SEEK_SET);
19463 + if (unlikely(offset))
19466 + arg->bindex = bindex;
19467 + au_fclr_fillvdir(arg->flags, WHABLE);
19469 + || (bindex != bend
19470 + && au_br_whable(au_sbr_perm(sb, bindex))))
19471 + au_fset_fillvdir(arg->flags, WHABLE);
19474 + au_fclr_fillvdir(arg->flags, CALLED);
19476 + err = vfsub_readdir(hf, fillvdir, arg);
19479 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
19482 + if (!err && shwh)
19483 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
19485 + au_nhash_wh_free(&arg->whlist);
19488 + au_nhash_de_free(&arg->delist);
19493 +static int read_vdir(struct file *file, int may_read)
19496 + unsigned long expire;
19497 + unsigned char do_read;
19498 + struct fillvdir_arg arg;
19499 + struct inode *inode;
19500 + struct au_vdir *vdir, *allocated;
19503 + inode = file->f_dentry->d_inode;
19504 + IMustLock(inode);
19505 + SiMustAnyLock(inode->i_sb);
19507 + allocated = NULL;
19509 + expire = au_sbi(inode->i_sb)->si_rdcache;
19510 + vdir = au_ivdir(inode);
19513 + vdir = alloc_vdir(inode->i_sb);
19514 + err = PTR_ERR(vdir);
19515 + if (IS_ERR(vdir))
19518 + allocated = vdir;
19519 + } else if (may_read
19520 + && (inode->i_version != vdir->vd_version
19521 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
19523 + err = reinit_vdir(vdir);
19524 + if (unlikely(err))
19529 + return 0; /* success */
19533 + err = au_do_read_vdir(&arg);
19535 + /* file->f_pos = 0; */
19536 + vdir->vd_version = inode->i_version;
19537 + vdir->vd_last.ul = 0;
19538 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
19540 + au_set_ivdir(inode, allocated);
19541 + } else if (allocated)
19542 + au_vdir_free(allocated);
19548 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
19551 + unsigned long ul, n;
19552 + const unsigned int deblk_sz = src->vd_deblk_sz;
19554 + AuDebugOn(tgt->vd_nblk != 1);
19557 + if (tgt->vd_nblk < src->vd_nblk) {
19558 + unsigned char **p;
19560 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
19562 + if (unlikely(!p))
19564 + tgt->vd_deblk = p;
19567 + tgt->vd_nblk = src->vd_nblk;
19568 + tgt->vd_deblk_sz = deblk_sz;
19569 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
19570 + /* tgt->vd_last.i = 0; */
19571 + /* tgt->vd_last.p.deblk = tgt->vd_deblk[0]; */
19572 + tgt->vd_version = src->vd_version;
19573 + tgt->vd_jiffy = src->vd_jiffy;
19575 + n = src->vd_nblk;
19576 + for (ul = 1; ul < n; ul++) {
19577 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
19579 + if (unlikely(!tgt->vd_deblk[ul]))
19583 + return 0; /* success */
19586 + rerr = reinit_vdir(tgt);
19591 +int au_vdir_init(struct file *file)
19594 + struct inode *inode;
19595 + struct au_vdir *vdir_cache, *allocated;
19597 + err = read_vdir(file, !file->f_pos);
19598 + if (unlikely(err))
19601 + allocated = NULL;
19602 + vdir_cache = au_fvdir_cache(file);
19603 + if (!vdir_cache) {
19604 + vdir_cache = alloc_vdir(file->f_dentry->d_sb);
19605 + err = PTR_ERR(vdir_cache);
19606 + if (IS_ERR(vdir_cache))
19608 + allocated = vdir_cache;
19609 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
19610 + err = reinit_vdir(vdir_cache);
19611 + if (unlikely(err))
19614 + return 0; /* success */
19616 + inode = file->f_dentry->d_inode;
19617 + err = copy_vdir(vdir_cache, au_ivdir(inode));
19619 + file->f_version = inode->i_version;
19621 + au_set_fvdir_cache(file, allocated);
19622 + } else if (allocated)
19623 + au_vdir_free(allocated);
19629 +static loff_t calc_offset(struct au_vdir *vdir)
19632 + union au_vdir_deblk_p p;
19634 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
19635 + offset = vdir->vd_last.p.deblk - p.deblk;
19636 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
19640 +/* returns true or false */
19641 +static int seek_vdir(struct file *file)
19644 + unsigned int deblk_sz;
19645 + unsigned long ul, n;
19647 + union au_vdir_deblk_p p, deblk_end;
19648 + struct au_vdir *vdir_cache;
19651 + vdir_cache = au_fvdir_cache(file);
19652 + offset = calc_offset(vdir_cache);
19653 + AuDbg("offset %lld\n", offset);
19654 + if (file->f_pos == offset)
19657 + vdir_cache->vd_last.ul = 0;
19658 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
19659 + if (!file->f_pos)
19663 + deblk_sz = vdir_cache->vd_deblk_sz;
19664 + ul = div64_u64(file->f_pos, deblk_sz);
19665 + AuDbg("ul %lu\n", ul);
19666 + if (ul >= vdir_cache->vd_nblk)
19669 + n = vdir_cache->vd_nblk;
19670 + for (; ul < n; ul++) {
19671 + p.deblk = vdir_cache->vd_deblk[ul];
19672 + deblk_end.deblk = p.deblk + deblk_sz;
19674 + offset *= deblk_sz;
19675 + while (!is_deblk_end(&p, &deblk_end) && offset < file->f_pos) {
19678 + l = calc_size(p.de->de_str.len);
19682 + if (!is_deblk_end(&p, &deblk_end)) {
19684 + vdir_cache->vd_last.ul = ul;
19685 + vdir_cache->vd_last.p = p;
19692 + AuTraceErr(!valid);
19696 +int au_vdir_fill_de(struct file *file, void *dirent, filldir_t filldir)
19699 + unsigned int l, deblk_sz;
19700 + union au_vdir_deblk_p deblk_end;
19701 + struct au_vdir *vdir_cache;
19702 + struct au_vdir_de *de;
19704 + vdir_cache = au_fvdir_cache(file);
19705 + if (!seek_vdir(file))
19708 + deblk_sz = vdir_cache->vd_deblk_sz;
19710 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
19711 + deblk_end.deblk += deblk_sz;
19712 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
19713 + de = vdir_cache->vd_last.p.de;
19714 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
19715 + de->de_str.len, de->de_str.name, file->f_pos,
19716 + (unsigned long)de->de_ino, de->de_type);
19717 + err = filldir(dirent, de->de_str.name, de->de_str.len,
19718 + file->f_pos, de->de_ino, de->de_type);
19719 + if (unlikely(err)) {
19721 + /* todo: ignore the error caused by udba? */
19722 + /* return err; */
19726 + l = calc_size(de->de_str.len);
19727 + vdir_cache->vd_last.p.deblk += l;
19728 + file->f_pos += l;
19730 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
19731 + vdir_cache->vd_last.ul++;
19732 + vdir_cache->vd_last.p.deblk
19733 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
19734 + file->f_pos = deblk_sz * vdir_cache->vd_last.ul;
19743 diff -urN linux-2.6.30.org/fs/aufs/vfsub.c linux-2.6.30/fs/aufs/vfsub.c
19744 --- linux-2.6.30.org/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
19745 +++ linux-2.6.30/fs/aufs/vfsub.c 2009-07-21 08:54:19.000000000 +0200
19748 + * Copyright (C) 2005-2009 Junjiro R. Okajima
19750 + * This program, aufs is free software; you can redistribute it and/or modify
19751 + * it under the terms of the GNU General Public License as published by
19752 + * the Free Software Foundation; either version 2 of the License, or
19753 + * (at your option) any later version.
19755 + * This program is distributed in the hope that it will be useful,
19756 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19757 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19758 + * GNU General Public License for more details.
19760 + * You should have received a copy of the GNU General Public License
19761 + * along with this program; if not, write to the Free Software
19762 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19766 + * sub-routines for VFS
19769 +#include <linux/namei.h>
19770 +#include <linux/security.h>
19771 +#include <linux/splice.h>
19772 +#include <linux/uaccess.h>
19775 +int vfsub_update_h_iattr(struct path *h_path, int *did)
19779 + struct super_block *h_sb;
19781 + /* for remote fs, leave work for its getattr or d_revalidate */
19782 + /* for bad i_attr fs, handle them in aufs_getattr() */
19783 + /* still some fs may acquire i_mutex. we need to skip them */
19787 + h_sb = h_path->dentry->d_sb;
19788 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
19790 + err = vfs_getattr(h_path->mnt, h_path->dentry, &st);
19795 +/* ---------------------------------------------------------------------- */
19797 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
19799 + struct file *file;
19802 + file = filp_open(path, oflags, mode);
19804 + if (IS_ERR(file))
19806 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
19812 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
19816 + /* lockdep_off(); */
19817 + err = kern_path(name, flags, path);
19818 + /* lockdep_on(); */
19819 + if (!err && path->dentry->d_inode)
19820 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
19824 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
19827 + struct path path = {
19831 + IMustLock(parent->d_inode);
19833 + path.dentry = lookup_one_len(name, parent, len);
19834 + if (IS_ERR(path.dentry))
19836 + if (path.dentry->d_inode)
19837 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
19840 + return path.dentry;
19843 +struct dentry *vfsub_lookup_hash(struct nameidata *nd)
19845 + struct path path = {
19846 + .mnt = nd->path.mnt
19849 + IMustLock(nd->path.dentry->d_inode);
19851 + path.dentry = lookup_hash(nd);
19852 + if (!IS_ERR(path.dentry) && path.dentry->d_inode)
19853 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
19855 + return path.dentry;
19858 +/* ---------------------------------------------------------------------- */
19860 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
19861 + struct dentry *d2, struct au_hinode *hdir2)
19863 + struct dentry *d;
19866 + d = lock_rename(d1, d2);
19868 + au_hin_suspend(hdir1);
19869 + if (hdir1 != hdir2)
19870 + au_hin_suspend(hdir2);
19875 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
19876 + struct dentry *d2, struct au_hinode *hdir2)
19878 + au_hin_resume(hdir1);
19879 + if (hdir1 != hdir2)
19880 + au_hin_resume(hdir2);
19882 + unlock_rename(d1, d2);
19886 +/* ---------------------------------------------------------------------- */
19888 +int vfsub_create(struct inode *dir, struct path *path, int mode)
19891 + struct dentry *d;
19895 + d = path->dentry;
19896 + path->dentry = d->d_parent;
19897 + err = security_path_mknod(path, path->dentry, mode, 0);
19898 + path->dentry = d;
19899 + if (unlikely(err))
19902 + if (au_test_fs_null_nd(dir->i_sb))
19903 + err = vfs_create(dir, path->dentry, mode, NULL);
19905 + struct nameidata h_nd;
19907 + memset(&h_nd, 0, sizeof(h_nd));
19908 + h_nd.flags = LOOKUP_CREATE;
19909 + h_nd.intent.open.flags = O_CREAT
19910 + | vfsub_fmode_to_uint(FMODE_READ);
19911 + h_nd.intent.open.create_mode = mode;
19912 + h_nd.path.dentry = path->dentry->d_parent;
19913 + h_nd.path.mnt = path->mnt;
19914 + path_get(&h_nd.path);
19915 + err = vfs_create(dir, path->dentry, mode, &h_nd);
19916 + path_put(&h_nd.path);
19920 + struct path tmp = *path;
19923 + vfsub_update_h_iattr(&tmp, &did);
19925 + tmp.dentry = path->dentry->d_parent;
19926 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
19935 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
19938 + struct dentry *d;
19942 + d = path->dentry;
19943 + path->dentry = d->d_parent;
19944 + err = security_path_symlink(path, path->dentry, symname);
19945 + path->dentry = d;
19946 + if (unlikely(err))
19949 + err = vfs_symlink(dir, path->dentry, symname);
19951 + struct path tmp = *path;
19954 + vfsub_update_h_iattr(&tmp, &did);
19956 + tmp.dentry = path->dentry->d_parent;
19957 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
19966 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
19969 + struct dentry *d;
19973 + d = path->dentry;
19974 + path->dentry = d->d_parent;
19975 + err = security_path_mknod(path, path->dentry, mode, dev);
19976 + path->dentry = d;
19977 + if (unlikely(err))
19980 + err = vfs_mknod(dir, path->dentry, mode, dev);
19982 + struct path tmp = *path;
19985 + vfsub_update_h_iattr(&tmp, &did);
19987 + tmp.dentry = path->dentry->d_parent;
19988 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
19997 +static int au_test_nlink(struct inode *inode)
19999 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
20001 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
20002 + || inode->i_nlink < link_max)
20007 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path)
20010 + struct dentry *d;
20014 + err = au_test_nlink(src_dentry->d_inode);
20015 + if (unlikely(err))
20018 + d = path->dentry;
20019 + path->dentry = d->d_parent;
20020 + err = security_path_link(src_dentry, path, path->dentry);
20021 + path->dentry = d;
20022 + if (unlikely(err))
20026 + err = vfs_link(src_dentry, dir, path->dentry);
20029 + struct path tmp = *path;
20032 + /* fuse has different memory inode for the same inumber */
20033 + vfsub_update_h_iattr(&tmp, &did);
20035 + tmp.dentry = path->dentry->d_parent;
20036 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
20037 + tmp.dentry = src_dentry;
20038 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
20047 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
20048 + struct inode *dir, struct path *path)
20051 + struct path tmp = {
20054 + struct dentry *d;
20057 + IMustLock(src_dir);
20059 + d = path->dentry;
20060 + path->dentry = d->d_parent;
20061 + tmp.dentry = src_dentry->d_parent;
20062 + err = security_path_rename(&tmp, src_dentry, path, path->dentry);
20063 + path->dentry = d;
20064 + if (unlikely(err))
20068 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry);
20073 + tmp.dentry = d->d_parent;
20074 + vfsub_update_h_iattr(&tmp, &did);
20076 + tmp.dentry = src_dentry;
20077 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
20078 + tmp.dentry = src_dentry->d_parent;
20079 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
20088 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
20091 + struct dentry *d;
20095 + d = path->dentry;
20096 + path->dentry = d->d_parent;
20097 + err = security_path_mkdir(path, path->dentry, mode);
20098 + path->dentry = d;
20099 + if (unlikely(err))
20102 + err = vfs_mkdir(dir, path->dentry, mode);
20104 + struct path tmp = *path;
20107 + vfsub_update_h_iattr(&tmp, &did);
20109 + tmp.dentry = path->dentry->d_parent;
20110 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
20119 +int vfsub_rmdir(struct inode *dir, struct path *path)
20122 + struct dentry *d;
20126 + d = path->dentry;
20127 + path->dentry = d->d_parent;
20128 + err = security_path_rmdir(path, path->dentry);
20129 + path->dentry = d;
20130 + if (unlikely(err))
20134 + err = vfs_rmdir(dir, path->dentry);
20137 + struct path tmp = {
20138 + .dentry = path->dentry->d_parent,
20142 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
20149 +/* ---------------------------------------------------------------------- */
20151 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
20156 + err = vfs_read(file, ubuf, count, ppos);
20158 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
20162 +/* todo: kernel_read()? */
20163 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
20167 + mm_segment_t oldfs;
20169 + oldfs = get_fs();
20170 + set_fs(KERNEL_DS);
20171 + err = vfsub_read_u(file, (char __user *)kbuf, count, ppos);
20176 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
20182 + err = vfs_write(file, ubuf, count, ppos);
20185 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
20189 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
20192 + mm_segment_t oldfs;
20194 + oldfs = get_fs();
20195 + set_fs(KERNEL_DS);
20196 + err = vfsub_write_u(file, (const char __user *)kbuf, count, ppos);
20201 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg)
20206 + err = vfs_readdir(file, filldir, arg);
20209 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
20213 +long vfsub_splice_to(struct file *in, loff_t *ppos,
20214 + struct pipe_inode_info *pipe, size_t len,
20215 + unsigned int flags)
20220 + err = do_splice_to(in, ppos, pipe, len, flags);
20223 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
20227 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
20228 + loff_t *ppos, size_t len, unsigned int flags)
20233 + err = do_splice_from(pipe, out, ppos, len, flags);
20236 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
20240 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
20241 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
20242 + struct file *h_file)
20245 + struct inode *h_inode;
20247 + h_inode = h_path->dentry->d_inode;
20249 + err = mnt_want_write(h_path->mnt);
20252 + err = inode_permission(h_inode, MAY_WRITE);
20255 + err = get_write_access(h_inode);
20258 + err = break_lease(h_inode, vfsub_fmode_to_uint(FMODE_WRITE));
20263 + err = locks_verify_truncate(h_inode, h_file, length);
20265 + err = security_path_truncate(h_path, length, attr);
20268 + err = do_truncate(h_path->dentry, length, attr, h_file);
20274 + put_write_access(h_inode);
20277 + mnt_drop_write(h_path->mnt);
20282 +/* ---------------------------------------------------------------------- */
20284 +struct au_vfsub_mkdir_args {
20286 + struct inode *dir;
20287 + struct path *path;
20291 +static void au_call_vfsub_mkdir(void *args)
20293 + struct au_vfsub_mkdir_args *a = args;
20294 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
20297 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
20299 + int err, do_sio, wkq_err;
20301 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
20303 + err = vfsub_mkdir(dir, path, mode);
20305 + struct au_vfsub_mkdir_args args = {
20311 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
20312 + if (unlikely(wkq_err))
20319 +struct au_vfsub_rmdir_args {
20321 + struct inode *dir;
20322 + struct path *path;
20325 +static void au_call_vfsub_rmdir(void *args)
20327 + struct au_vfsub_rmdir_args *a = args;
20328 + *a->errp = vfsub_rmdir(a->dir, a->path);
20331 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
20333 + int err, do_sio, wkq_err;
20335 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
20337 + err = vfsub_rmdir(dir, path);
20339 + struct au_vfsub_rmdir_args args = {
20344 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
20345 + if (unlikely(wkq_err))
20352 +/* ---------------------------------------------------------------------- */
20354 +struct notify_change_args {
20356 + struct path *path;
20357 + struct iattr *ia;
20360 +static void call_notify_change(void *args)
20362 + struct notify_change_args *a = args;
20363 + struct inode *h_inode;
20365 + h_inode = a->path->dentry->d_inode;
20366 + IMustLock(h_inode);
20368 + *a->errp = -EPERM;
20369 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
20371 + *a->errp = notify_change(a->path->dentry, a->ia);
20374 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
20376 + AuTraceErr(*a->errp);
20379 +int vfsub_notify_change(struct path *path, struct iattr *ia)
20382 + struct notify_change_args args = {
20388 + call_notify_change(&args);
20393 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia)
20395 + int err, wkq_err;
20396 + struct notify_change_args args = {
20402 + wkq_err = au_wkq_wait(call_notify_change, &args);
20403 + if (unlikely(wkq_err))
20409 +/* ---------------------------------------------------------------------- */
20411 +struct unlink_args {
20413 + struct inode *dir;
20414 + struct path *path;
20417 +static void call_unlink(void *args)
20419 + struct unlink_args *a = args;
20420 + struct dentry *d = a->path->dentry;
20421 + struct inode *h_inode;
20422 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
20423 + && atomic_read(&d->d_count) == 1);
20425 + IMustLock(a->dir);
20427 + a->path->dentry = d->d_parent;
20428 + *a->errp = security_path_unlink(a->path, d);
20429 + a->path->dentry = d;
20430 + if (unlikely(*a->errp))
20433 + if (!stop_sillyrename)
20435 + h_inode = d->d_inode;
20437 + atomic_inc(&h_inode->i_count);
20440 + *a->errp = vfs_unlink(a->dir, d);
20443 + struct path tmp = {
20444 + .dentry = d->d_parent,
20445 + .mnt = a->path->mnt
20447 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
20450 + if (!stop_sillyrename)
20455 + AuTraceErr(*a->errp);
20459 + * @dir: must be locked.
20460 + * @dentry: target dentry.
20462 +int vfsub_unlink(struct inode *dir, struct path *path, int force)
20465 + struct unlink_args args = {
20472 + call_unlink(&args);
20476 + wkq_err = au_wkq_wait(call_unlink, &args);
20477 + if (unlikely(wkq_err))
20483 diff -urN linux-2.6.30.org/fs/aufs/vfsub.h linux-2.6.30/fs/aufs/vfsub.h
20484 --- linux-2.6.30.org/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
20485 +++ linux-2.6.30/fs/aufs/vfsub.h 2009-07-21 08:54:19.000000000 +0200
20488 + * Copyright (C) 2005-2009 Junjiro R. Okajima
20490 + * This program, aufs is free software; you can redistribute it and/or modify
20491 + * it under the terms of the GNU General Public License as published by
20492 + * the Free Software Foundation; either version 2 of the License, or
20493 + * (at your option) any later version.
20495 + * This program is distributed in the hope that it will be useful,
20496 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20497 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20498 + * GNU General Public License for more details.
20500 + * You should have received a copy of the GNU General Public License
20501 + * along with this program; if not, write to the Free Software
20502 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20506 + * sub-routines for VFS
20509 +#ifndef __AUFS_VFSUB_H__
20510 +#define __AUFS_VFSUB_H__
20514 +#include <linux/fs.h>
20515 +#include <linux/fs_stack.h>
20517 +/* ---------------------------------------------------------------------- */
20519 +/* lock subclass for lower inode */
20520 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
20521 +/* reduce? gave up. */
20523 + AuLsc_I_Begin = I_MUTEX_QUOTA, /* 4 */
20524 + AuLsc_I_PARENT, /* lower inode, parent first */
20525 + AuLsc_I_PARENT2, /* copyup dirs */
20526 + AuLsc_I_PARENT3, /* copyup wh */
20532 +/* to debug easier, do not make them inlined functions */
20533 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
20534 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
20536 +/* ---------------------------------------------------------------------- */
20538 +static inline void vfsub_copy_inode_size(struct inode *inode,
20539 + struct inode *h_inode)
20541 + spin_lock(&inode->i_lock);
20542 + fsstack_copy_inode_size(inode, h_inode);
20543 + spin_unlock(&inode->i_lock);
20546 +int vfsub_update_h_iattr(struct path *h_path, int *did);
20547 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
20548 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
20549 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
20551 +struct dentry *vfsub_lookup_hash(struct nameidata *nd);
20553 +/* ---------------------------------------------------------------------- */
20556 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
20557 + struct dentry *d2, struct au_hinode *hdir2);
20558 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
20559 + struct dentry *d2, struct au_hinode *hdir2);
20561 +int vfsub_create(struct inode *dir, struct path *path, int mode);
20562 +int vfsub_symlink(struct inode *dir, struct path *path,
20563 + const char *symname);
20564 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
20565 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
20566 + struct path *path);
20567 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
20568 + struct inode *hdir, struct path *path);
20569 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
20570 +int vfsub_rmdir(struct inode *dir, struct path *path);
20572 +/* ---------------------------------------------------------------------- */
20574 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
20576 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
20578 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
20580 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
20582 +int vfsub_readdir(struct file *file, filldir_t filldir, void *arg);
20584 +static inline void vfsub_file_accessed(struct file *h_file)
20586 + file_accessed(h_file);
20587 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
20590 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
20591 + struct dentry *h_dentry)
20593 + struct path h_path = {
20594 + .dentry = h_dentry,
20597 + touch_atime(h_mnt, h_dentry);
20598 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
20601 +long vfsub_splice_to(struct file *in, loff_t *ppos,
20602 + struct pipe_inode_info *pipe, size_t len,
20603 + unsigned int flags);
20604 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
20605 + loff_t *ppos, size_t len, unsigned int flags);
20606 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
20607 + struct file *h_file);
20609 +/* ---------------------------------------------------------------------- */
20611 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
20616 + err = vfs_llseek(file, offset, origin);
20621 +/* ---------------------------------------------------------------------- */
20623 +/* dirty workaround for strict type of fmode_t */
20629 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
20631 + union vfsub_fmu u = {
20635 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
20640 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
20642 + union vfsub_fmu u = {
20649 +/* ---------------------------------------------------------------------- */
20651 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
20652 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
20653 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia);
20654 +int vfsub_notify_change(struct path *path, struct iattr *ia);
20655 +int vfsub_unlink(struct inode *dir, struct path *path, int force);
20657 +#endif /* __KERNEL__ */
20658 +#endif /* __AUFS_VFSUB_H__ */
20659 diff -urN linux-2.6.30.org/fs/aufs/wbr_policy.c linux-2.6.30/fs/aufs/wbr_policy.c
20660 --- linux-2.6.30.org/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
20661 +++ linux-2.6.30/fs/aufs/wbr_policy.c 2009-07-21 08:54:19.000000000 +0200
20664 + * Copyright (C) 2005-2009 Junjiro R. Okajima
20666 + * This program, aufs is free software; you can redistribute it and/or modify
20667 + * it under the terms of the GNU General Public License as published by
20668 + * the Free Software Foundation; either version 2 of the License, or
20669 + * (at your option) any later version.
20671 + * This program is distributed in the hope that it will be useful,
20672 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20673 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20674 + * GNU General Public License for more details.
20676 + * You should have received a copy of the GNU General Public License
20677 + * along with this program; if not, write to the Free Software
20678 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20682 + * policies for selecting one among multiple writable branches
20685 +#include <linux/statfs.h>
20688 +/* subset of cpup_attr() */
20689 +static noinline_for_stack
20690 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
20694 + struct inode *h_isrc;
20696 + h_isrc = h_src->d_inode;
20697 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
20698 + ia.ia_mode = h_isrc->i_mode;
20699 + ia.ia_uid = h_isrc->i_uid;
20700 + ia.ia_gid = h_isrc->i_gid;
20701 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
20702 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc);
20703 + err = vfsub_sio_notify_change(h_path, &ia);
20705 + /* is this nfs only? */
20706 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
20707 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
20708 + ia.ia_mode = h_isrc->i_mode;
20709 + err = vfsub_sio_notify_change(h_path, &ia);
20715 +#define AuCpdown_PARENT_OPQ 1
20716 +#define AuCpdown_WHED (1 << 1)
20717 +#define AuCpdown_MADE_DIR (1 << 2)
20718 +#define AuCpdown_DIROPQ (1 << 3)
20719 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
20720 +#define au_fset_cpdown(flags, name) { (flags) |= AuCpdown_##name; }
20721 +#define au_fclr_cpdown(flags, name) { (flags) &= ~AuCpdown_##name; }
20723 +struct au_cpdown_dir_args {
20724 + struct dentry *parent;
20725 + unsigned int flags;
20728 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
20729 + struct au_cpdown_dir_args *a)
20732 + struct dentry *opq_dentry;
20734 + opq_dentry = au_diropq_create(dentry, bdst);
20735 + err = PTR_ERR(opq_dentry);
20736 + if (IS_ERR(opq_dentry))
20738 + dput(opq_dentry);
20739 + au_fset_cpdown(a->flags, DIROPQ);
20745 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
20746 + struct inode *dir, aufs_bindex_t bdst)
20749 + struct path h_path;
20750 + struct au_branch *br;
20752 + br = au_sbr(dentry->d_sb, bdst);
20753 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20754 + err = PTR_ERR(h_path.dentry);
20755 + if (IS_ERR(h_path.dentry))
20759 + if (h_path.dentry->d_inode) {
20760 + h_path.mnt = br->br_mnt;
20761 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
20764 + dput(h_path.dentry);
20770 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
20771 + struct dentry *h_parent, void *arg)
20774 + aufs_bindex_t bend, bopq, bstart;
20775 + unsigned char parent_opq;
20776 + struct path h_path;
20777 + struct dentry *parent;
20778 + struct inode *h_dir, *h_inode, *inode, *dir;
20779 + struct au_cpdown_dir_args *args = arg;
20781 + bstart = au_dbstart(dentry);
20782 + /* dentry is di-locked */
20783 + parent = dget_parent(dentry);
20784 + dir = parent->d_inode;
20785 + h_dir = h_parent->d_inode;
20786 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
20787 + IMustLock(h_dir);
20789 + err = au_lkup_neg(dentry, bdst);
20790 + if (unlikely(err < 0))
20792 + h_path.dentry = au_h_dptr(dentry, bdst);
20793 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
20794 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
20795 + S_IRWXU | S_IRUGO | S_IXUGO);
20796 + if (unlikely(err))
20798 + au_fset_cpdown(args->flags, MADE_DIR);
20800 + bend = au_dbend(dentry);
20801 + bopq = au_dbdiropq(dentry);
20802 + au_fclr_cpdown(args->flags, WHED);
20803 + au_fclr_cpdown(args->flags, DIROPQ);
20804 + if (au_dbwh(dentry) == bdst)
20805 + au_fset_cpdown(args->flags, WHED);
20806 + if (!au_ftest_cpdown(args->flags, PARENT_OPQ) && bopq <= bdst)
20807 + au_fset_cpdown(args->flags, PARENT_OPQ);
20808 + parent_opq = (au_ftest_cpdown(args->flags, PARENT_OPQ)
20809 + && args->parent == dentry);
20810 + h_inode = h_path.dentry->d_inode;
20811 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
20812 + if (au_ftest_cpdown(args->flags, WHED)) {
20813 + err = au_cpdown_dir_opq(dentry, bdst, args);
20814 + if (unlikely(err)) {
20815 + mutex_unlock(&h_inode->i_mutex);
20820 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
20821 + mutex_unlock(&h_inode->i_mutex);
20822 + if (unlikely(err))
20825 + if (au_ftest_cpdown(args->flags, WHED)) {
20826 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
20827 + if (unlikely(err))
20831 + inode = dentry->d_inode;
20832 + if (au_ibend(inode) < bdst)
20833 + au_set_ibend(inode, bdst);
20834 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
20835 + au_hi_flags(inode, /*isdir*/1));
20836 + goto out; /* success */
20840 + if (au_ftest_cpdown(args->flags, DIROPQ)) {
20841 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
20842 + rerr = au_diropq_remove(dentry, bdst);
20843 + mutex_unlock(&h_inode->i_mutex);
20844 + if (unlikely(rerr)) {
20845 + AuIOErr("failed removing diropq for %.*s b%d (%d)\n",
20846 + AuDLNPair(dentry), bdst, rerr);
20852 + if (au_ftest_cpdown(args->flags, MADE_DIR)) {
20853 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
20854 + if (unlikely(rerr)) {
20855 + AuIOErr("failed removing %.*s b%d (%d)\n",
20856 + AuDLNPair(dentry), bdst, rerr);
20861 + au_set_h_dptr(dentry, bdst, NULL);
20862 + if (au_dbend(dentry) == bdst)
20863 + au_update_dbend(dentry);
20869 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
20872 + struct au_cpdown_dir_args args = {
20873 + .parent = dget_parent(dentry),
20877 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &args);
20878 + dput(args.parent);
20883 +/* ---------------------------------------------------------------------- */
20885 +/* policies for create */
20887 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
20889 + for (; bindex >= 0; bindex--)
20890 + if (!au_br_rdonly(au_sbr(sb, bindex)))
20895 +/* top down parent */
20896 +static int au_wbr_create_tdp(struct dentry *dentry, int isdir __maybe_unused)
20899 + aufs_bindex_t bstart, bindex;
20900 + struct super_block *sb;
20901 + struct dentry *parent, *h_parent;
20903 + sb = dentry->d_sb;
20904 + bstart = au_dbstart(dentry);
20906 + if (!au_br_rdonly(au_sbr(sb, bstart)))
20910 + parent = dget_parent(dentry);
20911 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
20912 + h_parent = au_h_dptr(parent, bindex);
20913 + if (!h_parent || !h_parent->d_inode)
20916 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20923 + /* bottom up here */
20924 + if (unlikely(err < 0))
20925 + err = au_wbr_bu(sb, bstart - 1);
20928 + AuDbg("b%d\n", err);
20932 +/* ---------------------------------------------------------------------- */
20934 +/* an exception for the policy other than tdp */
20935 +static int au_wbr_create_exp(struct dentry *dentry)
20938 + aufs_bindex_t bwh, bdiropq;
20939 + struct dentry *parent;
20942 + bwh = au_dbwh(dentry);
20943 + parent = dget_parent(dentry);
20944 + bdiropq = au_dbdiropq(parent);
20946 + if (bdiropq >= 0)
20947 + err = min(bdiropq, bwh);
20950 + AuDbg("%d\n", err);
20951 + } else if (bdiropq >= 0) {
20953 + AuDbg("%d\n", err);
20957 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
20960 + AuDbg("%d\n", err);
20964 +/* ---------------------------------------------------------------------- */
20967 +static int au_wbr_create_init_rr(struct super_block *sb)
20971 + err = au_wbr_bu(sb, au_sbend(sb));
20972 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
20975 + AuDbg("b%d\n", err);
20979 +static int au_wbr_create_rr(struct dentry *dentry, int isdir)
20983 + aufs_bindex_t bindex, bend;
20984 + struct super_block *sb;
20987 + err = au_wbr_create_exp(dentry);
20991 + sb = dentry->d_sb;
20992 + next = &au_sbi(sb)->si_wbr_rr_next;
20993 + bend = au_sbend(sb);
20995 + for (bindex = 0; bindex <= bend; bindex++) {
20997 + err = atomic_dec_return(next) + 1;
20998 + /* modulo for 0 is meaningless */
20999 + if (unlikely(!err))
21000 + err = atomic_dec_return(next) + 1;
21002 + err = atomic_read(next);
21003 + AuDbg("%d\n", err);
21006 + AuDbg("%d\n", err);
21007 + if (!au_br_rdonly(au_sbr(sb, err)))
21013 + AuDbg("%d\n", err);
21017 +/* ---------------------------------------------------------------------- */
21019 +/* most free space */
21020 +static void au_mfs(struct dentry *dentry)
21022 + struct super_block *sb;
21023 + struct au_branch *br;
21024 + struct au_wbr_mfs *mfs;
21025 + aufs_bindex_t bindex, bend;
21027 + unsigned long long b, bavail;
21028 + /* reduce the stack usage */
21029 + struct kstatfs *st;
21031 + st = kmalloc(sizeof(*st), GFP_NOFS);
21032 + if (unlikely(!st)) {
21033 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
21038 + sb = dentry->d_sb;
21039 + mfs = &au_sbi(sb)->si_wbr_mfs;
21040 + MtxMustLock(&mfs->mfs_lock);
21041 + mfs->mfs_bindex = -EROFS;
21042 + mfs->mfsrr_bytes = 0;
21043 + bend = au_sbend(sb);
21044 + for (bindex = 0; bindex <= bend; bindex++) {
21045 + br = au_sbr(sb, bindex);
21046 + if (au_br_rdonly(br))
21049 + /* sb->s_root for NFS is unreliable */
21050 + err = vfs_statfs(br->br_mnt->mnt_root, st);
21051 + if (unlikely(err)) {
21052 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
21056 + /* when the available size is equal, select the lower one */
21057 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
21058 + || sizeof(b) < sizeof(st->f_bsize));
21059 + b = st->f_bavail * st->f_bsize;
21060 + br->br_wbr->wbr_bytes = b;
21061 + if (b >= bavail) {
21063 + mfs->mfs_bindex = bindex;
21064 + mfs->mfs_jiffy = jiffies;
21068 + mfs->mfsrr_bytes = bavail;
21069 + AuDbg("b%d\n", mfs->mfs_bindex);
21073 +static int au_wbr_create_mfs(struct dentry *dentry, int isdir __maybe_unused)
21076 + struct super_block *sb;
21077 + struct au_wbr_mfs *mfs;
21079 + err = au_wbr_create_exp(dentry);
21083 + sb = dentry->d_sb;
21084 + mfs = &au_sbi(sb)->si_wbr_mfs;
21085 + mutex_lock(&mfs->mfs_lock);
21086 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
21087 + || mfs->mfs_bindex < 0
21088 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
21090 + mutex_unlock(&mfs->mfs_lock);
21091 + err = mfs->mfs_bindex;
21094 + AuDbg("b%d\n", err);
21098 +static int au_wbr_create_init_mfs(struct super_block *sb)
21100 + struct au_wbr_mfs *mfs;
21102 + mfs = &au_sbi(sb)->si_wbr_mfs;
21103 + mutex_init(&mfs->mfs_lock);
21104 + mfs->mfs_jiffy = 0;
21105 + mfs->mfs_bindex = -EROFS;
21110 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
21112 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
21116 +/* ---------------------------------------------------------------------- */
21118 +/* most free space and then round robin */
21119 +static int au_wbr_create_mfsrr(struct dentry *dentry, int isdir)
21122 + struct au_wbr_mfs *mfs;
21124 + err = au_wbr_create_mfs(dentry, isdir);
21126 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
21127 + mutex_lock(&mfs->mfs_lock);
21128 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
21129 + err = au_wbr_create_rr(dentry, isdir);
21130 + mutex_unlock(&mfs->mfs_lock);
21133 + AuDbg("b%d\n", err);
21137 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
21141 + au_wbr_create_init_mfs(sb); /* ignore */
21142 + err = au_wbr_create_init_rr(sb);
21147 +/* ---------------------------------------------------------------------- */
21149 +/* top down parent and most free space */
21150 +static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
21153 + unsigned long long b;
21154 + aufs_bindex_t bindex, bstart, bend;
21155 + struct super_block *sb;
21156 + struct dentry *parent, *h_parent;
21157 + struct au_branch *br;
21159 + err = au_wbr_create_tdp(dentry, isdir);
21160 + if (unlikely(err < 0))
21162 + parent = dget_parent(dentry);
21163 + bstart = au_dbstart(parent);
21164 + bend = au_dbtaildir(parent);
21165 + if (bstart == bend)
21166 + goto out_parent; /* success */
21168 + e2 = au_wbr_create_mfs(dentry, isdir);
21170 + goto out_parent; /* success */
21172 + /* when the available size is equal, select upper one */
21173 + sb = dentry->d_sb;
21174 + br = au_sbr(sb, err);
21175 + b = br->br_wbr->wbr_bytes;
21176 + AuDbg("b%d, %llu\n", err, b);
21178 + for (bindex = bstart; bindex <= bend; bindex++) {
21179 + h_parent = au_h_dptr(parent, bindex);
21180 + if (!h_parent || !h_parent->d_inode)
21183 + br = au_sbr(sb, bindex);
21184 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
21185 + b = br->br_wbr->wbr_bytes;
21187 + AuDbg("b%d, %llu\n", err, b);
21194 + AuDbg("b%d\n", err);
21198 +/* ---------------------------------------------------------------------- */
21200 +/* policies for copyup */
21202 +/* top down parent */
21203 +static int au_wbr_copyup_tdp(struct dentry *dentry)
21205 + return au_wbr_create_tdp(dentry, /*isdir, anything is ok*/0);
21208 +/* bottom up parent */
21209 +static int au_wbr_copyup_bup(struct dentry *dentry)
21212 + aufs_bindex_t bindex, bstart;
21213 + struct dentry *parent, *h_parent;
21214 + struct super_block *sb;
21217 + sb = dentry->d_sb;
21218 + parent = dget_parent(dentry);
21219 + bstart = au_dbstart(parent);
21220 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
21221 + h_parent = au_h_dptr(parent, bindex);
21222 + if (!h_parent || !h_parent->d_inode)
21225 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21232 + /* bottom up here */
21233 + if (unlikely(err < 0))
21234 + err = au_wbr_bu(sb, bstart - 1);
21236 + AuDbg("b%d\n", err);
21241 +static int au_wbr_copyup_bu(struct dentry *dentry)
21245 + err = au_wbr_bu(dentry->d_sb, au_dbstart(dentry));
21247 + AuDbg("b%d\n", err);
21251 +/* ---------------------------------------------------------------------- */
21253 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
21254 + [AuWbrCopyup_TDP] = {
21255 + .copyup = au_wbr_copyup_tdp
21257 + [AuWbrCopyup_BUP] = {
21258 + .copyup = au_wbr_copyup_bup
21260 + [AuWbrCopyup_BU] = {
21261 + .copyup = au_wbr_copyup_bu
21265 +struct au_wbr_create_operations au_wbr_create_ops[] = {
21266 + [AuWbrCreate_TDP] = {
21267 + .create = au_wbr_create_tdp
21269 + [AuWbrCreate_RR] = {
21270 + .create = au_wbr_create_rr,
21271 + .init = au_wbr_create_init_rr
21273 + [AuWbrCreate_MFS] = {
21274 + .create = au_wbr_create_mfs,
21275 + .init = au_wbr_create_init_mfs,
21276 + .fin = au_wbr_create_fin_mfs
21278 + [AuWbrCreate_MFSV] = {
21279 + .create = au_wbr_create_mfs,
21280 + .init = au_wbr_create_init_mfs,
21281 + .fin = au_wbr_create_fin_mfs
21283 + [AuWbrCreate_MFSRR] = {
21284 + .create = au_wbr_create_mfsrr,
21285 + .init = au_wbr_create_init_mfsrr,
21286 + .fin = au_wbr_create_fin_mfs
21288 + [AuWbrCreate_MFSRRV] = {
21289 + .create = au_wbr_create_mfsrr,
21290 + .init = au_wbr_create_init_mfsrr,
21291 + .fin = au_wbr_create_fin_mfs
21293 + [AuWbrCreate_PMFS] = {
21294 + .create = au_wbr_create_pmfs,
21295 + .init = au_wbr_create_init_mfs,
21296 + .fin = au_wbr_create_fin_mfs
21298 + [AuWbrCreate_PMFSV] = {
21299 + .create = au_wbr_create_pmfs,
21300 + .init = au_wbr_create_init_mfs,
21301 + .fin = au_wbr_create_fin_mfs
21304 diff -urN linux-2.6.30.org/fs/aufs/whout.c linux-2.6.30/fs/aufs/whout.c
21305 --- linux-2.6.30.org/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
21306 +++ linux-2.6.30/fs/aufs/whout.c 2009-07-21 08:54:19.000000000 +0200
21309 + * Copyright (C) 2005-2009 Junjiro R. Okajima
21311 + * This program, aufs is free software; you can redistribute it and/or modify
21312 + * it under the terms of the GNU General Public License as published by
21313 + * the Free Software Foundation; either version 2 of the License, or
21314 + * (at your option) any later version.
21316 + * This program is distributed in the hope that it will be useful,
21317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21319 + * GNU General Public License for more details.
21321 + * You should have received a copy of the GNU General Public License
21322 + * along with this program; if not, write to the Free Software
21323 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21327 + * whiteout for logical deletion and opaque directory
21330 +#include <linux/fs.h>
21333 +#define WH_MASK S_IRUGO
21336 + * If a directory contains this file, then it is opaque. We start with the
21337 + * .wh. flag so that it is blocked by lookup.
21339 +static struct qstr diropq_name = {
21340 + .name = AUFS_WH_DIROPQ,
21341 + .len = sizeof(AUFS_WH_DIROPQ) - 1
21345 + * generate whiteout name, which is NOT terminated by NULL.
21346 + * @name: original d_name.name
21347 + * @len: original d_name.len
21348 + * @wh: whiteout qstr
21349 + * returns zero when succeeds, otherwise error.
21350 + * succeeded value as wh->name should be freed by kfree().
21352 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
21356 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
21357 + return -ENAMETOOLONG;
21359 + wh->len = name->len + AUFS_WH_PFX_LEN;
21360 + p = kmalloc(wh->len, GFP_NOFS);
21363 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
21364 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
21371 +/* ---------------------------------------------------------------------- */
21374 + * test if the @wh_name exists under @h_parent.
21375 + * @try_sio specifies the necessary of super-io.
21377 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
21378 + struct au_branch *br, int try_sio)
21381 + struct dentry *wh_dentry;
21382 + struct inode *h_dir;
21384 + h_dir = h_parent->d_inode;
21386 + wh_dentry = au_lkup_one(wh_name, h_parent, br, /*nd*/NULL);
21388 + wh_dentry = au_sio_lkup_one(wh_name, h_parent, br);
21389 + err = PTR_ERR(wh_dentry);
21390 + if (IS_ERR(wh_dentry))
21394 + if (!wh_dentry->d_inode)
21395 + goto out_wh; /* success */
21398 + if (S_ISREG(wh_dentry->d_inode->i_mode))
21399 + goto out_wh; /* success */
21402 + AuIOErr("%.*s Invalid whiteout entry type 0%o.\n",
21403 + AuDLNPair(wh_dentry), wh_dentry->d_inode->i_mode);
21412 + * test if the @h_dentry sets opaque or not.
21414 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br)
21417 + struct inode *h_dir;
21419 + h_dir = h_dentry->d_inode;
21420 + err = au_wh_test(h_dentry, &diropq_name, br,
21421 + au_test_h_perm_sio(h_dir, MAY_EXEC));
21426 + * returns a negative dentry whose name is unique and temporary.
21428 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
21429 + struct qstr *prefix)
21432 + struct dentry *dentry;
21434 + char defname[AUFS_WH_PFX_LEN * 2 + DNAME_INLINE_LEN_MIN + 1
21435 + + HEX_LEN + 1], *name, *p;
21436 + static unsigned short cnt;
21440 + qs.len = sizeof(defname) - DNAME_INLINE_LEN_MIN + prefix->len - 1;
21441 + if (unlikely(prefix->len > DNAME_INLINE_LEN_MIN)) {
21442 + dentry = ERR_PTR(-ENAMETOOLONG);
21443 + if (unlikely(qs.len >= PATH_MAX))
21445 + dentry = ERR_PTR(-ENOMEM);
21446 + name = kmalloc(qs.len + 1, GFP_NOFS);
21447 + if (unlikely(!name))
21451 + /* doubly whiteout-ed */
21452 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
21453 + p = name + AUFS_WH_PFX_LEN * 2;
21454 + memcpy(p, prefix->name, prefix->len);
21455 + p += prefix->len;
21457 + AuDebugOn(name + qs.len + 1 - p <= HEX_LEN);
21460 + for (i = 0; i < 3; i++) {
21461 + sprintf(p, "%.*d", HEX_LEN, cnt++);
21462 + dentry = au_sio_lkup_one(&qs, h_parent, br);
21463 + if (IS_ERR(dentry) || !dentry->d_inode)
21467 + /* AuWarn("could not get random name\n"); */
21468 + dentry = ERR_PTR(-EEXIST);
21469 + AuDbg("%.*s\n", AuLNPair(&qs));
21473 + if (name != defname)
21481 + * rename the @h_dentry on @br to the whiteouted temporary name.
21483 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
21486 + struct path h_path = {
21487 + .mnt = br->br_mnt
21489 + struct inode *h_dir;
21490 + struct dentry *h_parent;
21492 + h_parent = h_dentry->d_parent; /* dir inode is locked */
21493 + h_dir = h_parent->d_inode;
21494 + IMustLock(h_dir);
21496 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
21497 + err = PTR_ERR(h_path.dentry);
21498 + if (IS_ERR(h_path.dentry))
21501 + /* under the same dir, no need to lock_rename() */
21502 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path);
21504 + dput(h_path.dentry);
21510 +/* ---------------------------------------------------------------------- */
21512 + * functions for removing a whiteout
21515 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
21520 + * forces superio when the dir has a sticky bit.
21521 + * this may be a violation of unix fs semantics.
21523 + force = (h_dir->i_mode & S_ISVTX)
21524 + && h_path->dentry->d_inode->i_uid != current_fsuid();
21525 + return vfsub_unlink(h_dir, h_path, force);
21528 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
21529 + struct dentry *dentry)
21533 + err = do_unlink_wh(h_dir, h_path);
21534 + if (!err && dentry)
21535 + au_set_dbwh(dentry, -1);
21540 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
21541 + struct au_branch *br)
21544 + struct path h_path = {
21545 + .mnt = br->br_mnt
21549 + h_path.dentry = au_lkup_one(wh, h_parent, br, /*nd*/NULL);
21550 + if (IS_ERR(h_path.dentry))
21551 + err = PTR_ERR(h_path.dentry);
21553 + if (h_path.dentry->d_inode
21554 + && S_ISREG(h_path.dentry->d_inode->i_mode))
21555 + err = do_unlink_wh(h_parent->d_inode, &h_path);
21556 + dput(h_path.dentry);
21562 +/* ---------------------------------------------------------------------- */
21564 + * initialize/clean whiteout for a branch
21567 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
21572 + if (!whpath->dentry->d_inode)
21575 + err = mnt_want_write(whpath->mnt);
21578 + err = vfsub_rmdir(h_dir, whpath);
21580 + err = vfsub_unlink(h_dir, whpath, /*force*/0);
21581 + mnt_drop_write(whpath->mnt);
21583 + if (unlikely(err))
21584 + AuWarn("failed removing %.*s (%d), ignored.\n",
21585 + AuDLNPair(whpath->dentry), err);
21588 +static int test_linkable(struct dentry *h_root)
21590 + struct inode *h_dir = h_root->d_inode;
21592 + if (h_dir->i_op->link)
21595 + AuErr("%.*s (%s) doesn't support link(2), use noplink and rw+nolwh\n",
21596 + AuDLNPair(h_root), au_sbtype(h_root->d_sb));
21600 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
21601 +static int au_whdir(struct inode *h_dir, struct path *path)
21606 + if (!path->dentry->d_inode) {
21607 + int mode = S_IRWXU;
21609 + if (au_test_nfs(path->dentry->d_sb))
21611 + err = mnt_want_write(path->mnt);
21613 + err = vfsub_mkdir(h_dir, path, mode);
21614 + mnt_drop_write(path->mnt);
21616 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
21619 + AuErr("unknown %.*s exists\n", AuDLNPair(path->dentry));
21624 +struct au_wh_base {
21625 + const struct qstr *name;
21626 + struct dentry *dentry;
21629 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
21630 + struct path *h_path)
21632 + h_path->dentry = base[AuBrWh_BASE].dentry;
21633 + au_wh_clean(h_dir, h_path, /*isdir*/0);
21634 + h_path->dentry = base[AuBrWh_PLINK].dentry;
21635 + au_wh_clean(h_dir, h_path, /*isdir*/1);
21636 + h_path->dentry = base[AuBrWh_ORPH].dentry;
21637 + au_wh_clean(h_dir, h_path, /*isdir*/1);
21641 + * returns tri-state,
21642 + * minus: error, caller should print the mesage
21644 + * plus: error, caller should NOT print the mesage
21646 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
21647 + int do_plink, struct au_wh_base base[],
21648 + struct path *h_path)
21651 + struct inode *h_dir;
21653 + h_dir = h_root->d_inode;
21654 + h_path->dentry = base[AuBrWh_BASE].dentry;
21655 + au_wh_clean(h_dir, h_path, /*isdir*/0);
21656 + h_path->dentry = base[AuBrWh_PLINK].dentry;
21658 + err = test_linkable(h_root);
21659 + if (unlikely(err)) {
21664 + err = au_whdir(h_dir, h_path);
21665 + if (unlikely(err))
21667 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
21669 + au_wh_clean(h_dir, h_path, /*isdir*/1);
21670 + h_path->dentry = base[AuBrWh_ORPH].dentry;
21671 + err = au_whdir(h_dir, h_path);
21672 + if (unlikely(err))
21674 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
21681 + * for the moment, aufs supports the branch filesystem which does not support
21682 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
21683 + * copyup failed. finally, such filesystem will not be used as the writable
21686 + * returns tri-state, see above.
21688 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
21689 + int do_plink, struct au_wh_base base[],
21690 + struct path *h_path)
21693 + struct inode *h_dir;
21695 + err = test_linkable(h_root);
21696 + if (unlikely(err)) {
21702 + * todo: should this create be done in /sbin/mount.aufs helper?
21705 + h_dir = h_root->d_inode;
21706 + if (!base[AuBrWh_BASE].dentry->d_inode) {
21707 + err = mnt_want_write(h_path->mnt);
21709 + h_path->dentry = base[AuBrWh_BASE].dentry;
21710 + err = vfsub_create(h_dir, h_path, WH_MASK);
21711 + mnt_drop_write(h_path->mnt);
21713 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
21716 + AuErr("unknown %.*s/%.*s exists\n",
21717 + AuDLNPair(h_root), AuDLNPair(base[AuBrWh_BASE].dentry));
21718 + if (unlikely(err))
21721 + h_path->dentry = base[AuBrWh_PLINK].dentry;
21723 + err = au_whdir(h_dir, h_path);
21724 + if (unlikely(err))
21726 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
21728 + au_wh_clean(h_dir, h_path, /*isdir*/1);
21729 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
21731 + h_path->dentry = base[AuBrWh_ORPH].dentry;
21732 + err = au_whdir(h_dir, h_path);
21733 + if (unlikely(err))
21735 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
21742 + * initialize the whiteout base file/dir for @br.
21744 +int au_wh_init(struct dentry *h_root, struct au_branch *br,
21745 + struct super_block *sb)
21748 + const unsigned char do_plink
21749 + = !!au_opt_test(au_mntflags(sb), PLINK);
21750 + struct path path = {
21751 + .mnt = br->br_mnt
21753 + struct inode *h_dir;
21754 + struct au_wbr *wbr = br->br_wbr;
21755 + static const struct qstr base_name[] = {
21756 + [AuBrWh_BASE] = {
21757 + .name = AUFS_BASE_NAME,
21758 + .len = sizeof(AUFS_BASE_NAME) - 1
21760 + [AuBrWh_PLINK] = {
21761 + .name = AUFS_PLINKDIR_NAME,
21762 + .len = sizeof(AUFS_PLINKDIR_NAME) - 1
21764 + [AuBrWh_ORPH] = {
21765 + .name = AUFS_ORPHDIR_NAME,
21766 + .len = sizeof(AUFS_ORPHDIR_NAME) - 1
21769 + struct au_wh_base base[] = {
21770 + [AuBrWh_BASE] = {
21771 + .name = base_name + AuBrWh_BASE,
21774 + [AuBrWh_PLINK] = {
21775 + .name = base_name + AuBrWh_PLINK,
21778 + [AuBrWh_ORPH] = {
21779 + .name = base_name + AuBrWh_ORPH,
21785 + h_dir = h_root->d_inode;
21786 + for (i = 0; i < AuBrWh_Last; i++) {
21787 + /* doubly whiteouted */
21788 + struct dentry *d;
21790 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
21791 + err = PTR_ERR(d);
21795 + base[i].dentry = d;
21797 + && wbr->wbr_wh[i]
21798 + && wbr->wbr_wh[i] != base[i].dentry);
21802 + for (i = 0; i < AuBrWh_Last; i++) {
21803 + dput(wbr->wbr_wh[i]);
21804 + wbr->wbr_wh[i] = NULL;
21809 + switch (br->br_perm) {
21810 + case AuBrPerm_RO:
21811 + case AuBrPerm_ROWH:
21812 + case AuBrPerm_RR:
21813 + case AuBrPerm_RRWH:
21814 + au_wh_init_ro(h_dir, base, &path);
21817 + case AuBrPerm_RWNoLinkWH:
21818 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
21825 + case AuBrPerm_RW:
21826 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
21836 + goto out; /* success */
21839 + AuErr("an error(%d) on the writable branch %.*s(%s)\n",
21840 + err, AuDLNPair(h_root), au_sbtype(h_root->d_sb));
21842 + for (i = 0; i < AuBrWh_Last; i++)
21843 + dput(base[i].dentry);
21847 +/* ---------------------------------------------------------------------- */
21849 + * whiteouts are all hard-linked usually.
21850 + * when its link count reaches a ceiling, we create a new whiteout base
21851 + * asynchronously.
21854 +struct reinit_br_wh {
21855 + struct super_block *sb;
21856 + struct au_branch *br;
21859 +static void reinit_br_wh(void *arg)
21862 + aufs_bindex_t bindex;
21863 + struct path h_path;
21864 + struct reinit_br_wh *a = arg;
21865 + struct au_wbr *wbr;
21866 + struct inode *dir;
21867 + struct dentry *h_root;
21868 + struct au_hinode *hdir;
21871 + wbr = a->br->br_wbr;
21872 + /* big aufs lock */
21873 + si_noflush_write_lock(a->sb);
21874 + if (!au_br_writable(a->br->br_perm))
21876 + bindex = au_br_index(a->sb, a->br->br_id);
21877 + if (unlikely(bindex < 0))
21880 + dir = a->sb->s_root->d_inode;
21881 + /* ii_read_lock_parent(dir); */
21882 + hdir = au_hi(dir, bindex);
21883 + h_root = au_h_dptr(a->sb->s_root, bindex);
21885 + au_hin_imtx_lock_nested(hdir, AuLsc_I_PARENT);
21886 + wbr_wh_write_lock(wbr);
21887 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
21890 + err = mnt_want_write(a->br->br_mnt);
21892 + h_path.dentry = wbr->wbr_whbase;
21893 + h_path.mnt = a->br->br_mnt;
21894 + err = vfsub_unlink(hdir->hi_inode, &h_path, /*force*/0);
21895 + mnt_drop_write(a->br->br_mnt);
21898 + AuWarn("%.*s is moved, ignored\n", AuDLNPair(wbr->wbr_whbase));
21901 + dput(wbr->wbr_whbase);
21902 + wbr->wbr_whbase = NULL;
21904 + err = au_wh_init(h_root, a->br, a->sb);
21905 + wbr_wh_write_unlock(wbr);
21906 + au_hin_imtx_unlock(hdir);
21907 + /* ii_read_unlock(dir); */
21911 + atomic_dec(&wbr->wbr_wh_running);
21912 + atomic_dec(&a->br->br_count);
21913 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
21914 + si_write_unlock(a->sb);
21916 + if (unlikely(err))
21917 + AuIOErr("err %d\n", err);
21920 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
21922 + int do_dec, wkq_err;
21923 + struct reinit_br_wh *arg;
21926 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
21929 + /* ignore ENOMEM */
21930 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
21933 + * dec(wh_running), kfree(arg) and dec(br_count)
21934 + * in reinit function
21938 + atomic_inc(&br->br_count);
21939 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb);
21940 + if (unlikely(wkq_err)) {
21941 + atomic_dec(&br->br_wbr->wbr_wh_running);
21942 + atomic_dec(&br->br_count);
21950 + atomic_dec(&br->br_wbr->wbr_wh_running);
21953 +/* ---------------------------------------------------------------------- */
21956 + * create the whiteout @wh.
21958 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
21959 + struct dentry *wh)
21962 + struct path h_path = {
21965 + struct au_branch *br;
21966 + struct au_wbr *wbr;
21967 + struct dentry *h_parent;
21968 + struct inode *h_dir;
21970 + h_parent = wh->d_parent; /* dir inode is locked */
21971 + h_dir = h_parent->d_inode;
21972 + IMustLock(h_dir);
21974 + br = au_sbr(sb, bindex);
21975 + h_path.mnt = br->br_mnt;
21976 + wbr = br->br_wbr;
21977 + wbr_wh_read_lock(wbr);
21978 + if (wbr->wbr_whbase) {
21979 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path);
21980 + if (!err || err != -EMLINK)
21983 + /* link count full. re-initialize br_whbase. */
21984 + kick_reinit_br_wh(sb, br);
21987 + /* return this error in this context */
21988 + err = vfsub_create(h_dir, &h_path, WH_MASK);
21991 + wbr_wh_read_unlock(wbr);
21995 +/* ---------------------------------------------------------------------- */
21998 + * create or remove the diropq.
22000 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
22001 + unsigned int flags)
22003 + struct dentry *opq_dentry, *h_dentry;
22004 + struct super_block *sb;
22005 + struct au_branch *br;
22008 + sb = dentry->d_sb;
22009 + br = au_sbr(sb, bindex);
22010 + h_dentry = au_h_dptr(dentry, bindex);
22011 + opq_dentry = au_lkup_one(&diropq_name, h_dentry, br, /*nd*/NULL);
22012 + if (IS_ERR(opq_dentry))
22015 + if (au_ftest_diropq(flags, CREATE)) {
22016 + err = link_or_create_wh(sb, bindex, opq_dentry);
22018 + au_set_dbdiropq(dentry, bindex);
22019 + goto out; /* success */
22022 + struct path tmp = {
22023 + .dentry = opq_dentry,
22024 + .mnt = br->br_mnt
22026 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
22028 + au_set_dbdiropq(dentry, -1);
22030 + dput(opq_dentry);
22031 + opq_dentry = ERR_PTR(err);
22034 + return opq_dentry;
22037 +struct do_diropq_args {
22038 + struct dentry **errp;
22039 + struct dentry *dentry;
22040 + aufs_bindex_t bindex;
22041 + unsigned int flags;
22044 +static void call_do_diropq(void *args)
22046 + struct do_diropq_args *a = args;
22047 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
22050 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
22051 + unsigned int flags)
22053 + struct dentry *diropq, *h_dentry;
22055 + h_dentry = au_h_dptr(dentry, bindex);
22056 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
22057 + diropq = do_diropq(dentry, bindex, flags);
22060 + struct do_diropq_args args = {
22062 + .dentry = dentry,
22063 + .bindex = bindex,
22067 + wkq_err = au_wkq_wait(call_do_diropq, &args);
22068 + if (unlikely(wkq_err))
22069 + diropq = ERR_PTR(wkq_err);
22075 +/* ---------------------------------------------------------------------- */
22078 + * lookup whiteout dentry.
22079 + * @h_parent: lower parent dentry which must exist and be locked
22080 + * @base_name: name of dentry which will be whiteouted
22081 + * returns dentry for whiteout.
22083 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
22084 + struct au_branch *br)
22087 + struct qstr wh_name;
22088 + struct dentry *wh_dentry;
22090 + err = au_wh_name_alloc(&wh_name, base_name);
22091 + wh_dentry = ERR_PTR(err);
22093 + wh_dentry = au_lkup_one(&wh_name, h_parent, br, /*nd*/NULL);
22094 + kfree(wh_name.name);
22096 + return wh_dentry;
22100 + * link/create a whiteout for @dentry on @bindex.
22102 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
22103 + struct dentry *h_parent)
22105 + struct dentry *wh_dentry;
22106 + struct super_block *sb;
22109 + sb = dentry->d_sb;
22110 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
22111 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
22112 + err = link_or_create_wh(sb, bindex, wh_dentry);
22114 + au_set_dbwh(dentry, bindex);
22117 + wh_dentry = ERR_PTR(err);
22121 + return wh_dentry;
22124 +/* ---------------------------------------------------------------------- */
22126 +/* Delete all whiteouts in this directory on branch bindex. */
22127 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
22128 + aufs_bindex_t bindex, struct au_branch *br)
22131 + unsigned long ul, n;
22132 + struct qstr wh_name;
22134 + struct hlist_head *head;
22135 + struct au_vdir_wh *tpos;
22136 + struct hlist_node *pos;
22137 + struct au_vdir_destr *str;
22141 + wh_name.name = p;
22142 + if (unlikely(!wh_name.name))
22146 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
22147 + p += AUFS_WH_PFX_LEN;
22148 + n = whlist->nh_num;
22149 + head = whlist->nh_head;
22150 + for (ul = 0; !err && ul < n; ul++, head++) {
22151 + hlist_for_each_entry(tpos, pos, head, wh_hash) {
22152 + if (tpos->wh_bindex != bindex)
22155 + str = &tpos->wh_str;
22156 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
22157 + memcpy(p, str->name, str->len);
22158 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
22159 + err = unlink_wh_name(h_dentry, &wh_name, br);
22164 + AuIOErr("whiteout name too long %.*s\n",
22165 + str->len, str->name);
22170 + __putname(wh_name.name);
22176 +struct del_wh_children_args {
22178 + struct dentry *h_dentry;
22179 + struct au_nhash whlist;
22180 + aufs_bindex_t bindex;
22181 + struct au_branch *br;
22184 +static void call_del_wh_children(void *args)
22186 + struct del_wh_children_args *a = args;
22187 + *a->errp = del_wh_children(a->h_dentry, &a->whlist, a->bindex, a->br);
22190 +/* ---------------------------------------------------------------------- */
22192 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
22194 + struct au_whtmp_rmdir *whtmp;
22197 + SiMustAnyLock(sb);
22199 + whtmp = kmalloc(sizeof(*whtmp), gfp);
22200 + if (unlikely(!whtmp)) {
22201 + whtmp = ERR_PTR(-ENOMEM);
22205 + whtmp->dir = NULL;
22206 + whtmp->wh_dentry = NULL;
22207 + err = au_nhash_alloc(&whtmp->whlist, au_sbi(sb)->si_rdhash, gfp);
22209 + return whtmp; /* success */
22212 + whtmp = ERR_PTR(err);
22218 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
22220 + dput(whtmp->wh_dentry);
22221 + iput(whtmp->dir);
22222 + au_nhash_wh_free(&whtmp->whlist);
22227 + * rmdir the whiteouted temporary named dir @h_dentry.
22228 + * @whlist: whiteouted children.
22230 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
22231 + struct dentry *wh_dentry, struct au_nhash *whlist)
22234 + struct path h_tmp;
22235 + struct inode *wh_inode, *h_dir;
22236 + struct au_branch *br;
22238 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
22239 + IMustLock(h_dir);
22241 + br = au_sbr(dir->i_sb, bindex);
22242 + wh_inode = wh_dentry->d_inode;
22243 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
22246 + * someone else might change some whiteouts while we were sleeping.
22247 + * it means this whlist may have an obsoleted entry.
22249 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
22250 + err = del_wh_children(wh_dentry, whlist, bindex, br);
22253 + struct del_wh_children_args args = {
22255 + .h_dentry = wh_dentry,
22256 + .whlist = *whlist,
22257 + .bindex = bindex,
22261 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
22262 + if (unlikely(wkq_err))
22265 + mutex_unlock(&wh_inode->i_mutex);
22268 + h_tmp.dentry = wh_dentry;
22269 + h_tmp.mnt = br->br_mnt;
22270 + err = vfsub_rmdir(h_dir, &h_tmp);
22271 + /* d_drop(h_dentry); */
22275 + if (au_ibstart(dir) == bindex) {
22276 + au_cpup_attr_timesizes(dir);
22279 + return 0; /* success */
22282 + AuWarn("failed removing %.*s(%d), ignored\n",
22283 + AuDLNPair(wh_dentry), err);
22287 +static void call_rmdir_whtmp(void *args)
22290 + struct au_whtmp_rmdir *a = args;
22291 + struct super_block *sb;
22292 + struct dentry *h_parent;
22293 + struct inode *h_dir;
22294 + struct au_branch *br;
22295 + struct au_hinode *hdir;
22297 + /* rmdir by nfsd may cause deadlock with this i_mutex */
22298 + /* mutex_lock(&a->dir->i_mutex); */
22299 + sb = a->dir->i_sb;
22300 + si_noflush_read_lock(sb);
22301 + err = au_test_ro(sb, a->bindex, NULL);
22302 + if (unlikely(err))
22306 + br = au_sbr(sb, a->bindex);
22307 + ii_write_lock_parent(a->dir);
22308 + h_parent = dget_parent(a->wh_dentry);
22309 + h_dir = h_parent->d_inode;
22310 + hdir = au_hi(a->dir, a->bindex);
22311 + au_hin_imtx_lock_nested(hdir, AuLsc_I_PARENT);
22312 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent, br);
22314 + err = mnt_want_write(br->br_mnt);
22316 + err = au_whtmp_rmdir(a->dir, a->bindex, a->wh_dentry,
22318 + mnt_drop_write(br->br_mnt);
22321 + au_hin_imtx_unlock(hdir);
22323 + ii_write_unlock(a->dir);
22326 + /* mutex_unlock(&a->dir->i_mutex); */
22327 + au_nwt_done(&au_sbi(sb)->si_nowait);
22328 + si_read_unlock(sb);
22329 + au_whtmp_rmdir_free(a);
22330 + if (unlikely(err))
22331 + AuIOErr("err %d\n", err);
22334 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
22335 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
22341 + /* all post-process will be done in do_rmdir_whtmp(). */
22342 + args->dir = au_igrab(dir);
22343 + args->bindex = bindex;
22344 + args->wh_dentry = dget(wh_dentry);
22345 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, dir->i_sb);
22346 + if (unlikely(wkq_err)) {
22347 + AuWarn("rmdir error %.*s (%d), ignored\n",
22348 + AuDLNPair(wh_dentry), wkq_err);
22349 + au_whtmp_rmdir_free(args);
22352 diff -urN linux-2.6.30.org/fs/aufs/whout.h linux-2.6.30/fs/aufs/whout.h
22353 --- linux-2.6.30.org/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
22354 +++ linux-2.6.30/fs/aufs/whout.h 2009-07-21 08:54:19.000000000 +0200
22357 + * Copyright (C) 2005-2009 Junjiro R. Okajima
22359 + * This program, aufs is free software; you can redistribute it and/or modify
22360 + * it under the terms of the GNU General Public License as published by
22361 + * the Free Software Foundation; either version 2 of the License, or
22362 + * (at your option) any later version.
22364 + * This program is distributed in the hope that it will be useful,
22365 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22366 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22367 + * GNU General Public License for more details.
22369 + * You should have received a copy of the GNU General Public License
22370 + * along with this program; if not, write to the Free Software
22371 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22375 + * whiteout for logical deletion and opaque directory
22378 +#ifndef __AUFS_WHOUT_H__
22379 +#define __AUFS_WHOUT_H__
22383 +#include <linux/aufs_type.h>
22387 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
22389 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name,
22390 + struct au_branch *br, int try_sio);
22391 +int au_diropq_test(struct dentry *h_dentry, struct au_branch *br);
22392 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
22393 + struct qstr *prefix);
22394 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
22395 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
22396 + struct dentry *dentry);
22397 +int au_wh_init(struct dentry *h_parent, struct au_branch *br,
22398 + struct super_block *sb);
22400 +/* diropq flags */
22401 +#define AuDiropq_CREATE 1
22402 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
22403 +#define au_fset_diropq(flags, name) { (flags) |= AuDiropq_##name; }
22404 +#define au_fclr_diropq(flags, name) { (flags) &= ~AuDiropq_##name; }
22406 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
22407 + unsigned int flags);
22408 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
22409 + struct au_branch *br);
22410 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
22411 + struct dentry *h_parent);
22413 +/* real rmdir for the whiteout-ed dir */
22414 +struct au_whtmp_rmdir {
22415 + struct inode *dir;
22416 + aufs_bindex_t bindex;
22417 + struct dentry *wh_dentry;
22418 + struct au_nhash whlist;
22421 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
22422 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
22423 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
22424 + struct dentry *wh_dentry, struct au_nhash *whlist);
22425 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
22426 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
22428 +/* ---------------------------------------------------------------------- */
22430 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
22431 + aufs_bindex_t bindex)
22433 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
22436 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
22438 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
22441 +#endif /* __KERNEL__ */
22442 +#endif /* __AUFS_WHOUT_H__ */
22443 diff -urN linux-2.6.30.org/fs/aufs/wkq.c linux-2.6.30/fs/aufs/wkq.c
22444 --- linux-2.6.30.org/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
22445 +++ linux-2.6.30/fs/aufs/wkq.c 2009-07-21 08:54:19.000000000 +0200
22448 + * Copyright (C) 2005-2009 Junjiro R. Okajima
22450 + * This program, aufs is free software; you can redistribute it and/or modify
22451 + * it under the terms of the GNU General Public License as published by
22452 + * the Free Software Foundation; either version 2 of the License, or
22453 + * (at your option) any later version.
22455 + * This program is distributed in the hope that it will be useful,
22456 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22457 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22458 + * GNU General Public License for more details.
22460 + * You should have received a copy of the GNU General Public License
22461 + * along with this program; if not, write to the Free Software
22462 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22466 + * workqueue for asynchronous/super-io operations
22467 + * todo: try new dredential scheme
22470 +#include <linux/module.h>
22473 +/* internal workqueue named AUFS_WKQ_NAME */
22474 +static struct au_wkq {
22475 + struct workqueue_struct *q;
22481 +struct au_wkinfo {
22482 + struct work_struct wk;
22483 + struct super_block *sb;
22485 + unsigned int flags; /* see wkq.h */
22487 + au_wkq_func_t func;
22491 + struct completion *comp;
22494 +/* ---------------------------------------------------------------------- */
22496 +static int enqueue(struct au_wkq *wkq, struct au_wkinfo *wkinfo)
22498 + wkinfo->busyp = &wkq->busy;
22499 + if (au_ftest_wkq(wkinfo->flags, WAIT))
22500 + return !queue_work(wkq->q, &wkinfo->wk);
22502 + return !schedule_work(&wkinfo->wk);
22505 +static void do_wkq(struct au_wkinfo *wkinfo)
22507 + unsigned int idle, n;
22511 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
22514 + for (i = 0; i < aufs_nwkq; i++) {
22515 + n = atomic_inc_return(&au_wkq[i].busy);
22516 + if (n == 1 && !enqueue(au_wkq + i, wkinfo))
22517 + return; /* success */
22523 + atomic_dec(&au_wkq[i].busy);
22526 + idle_idx = aufs_nwkq;
22528 + atomic_inc(&au_wkq[idle_idx].busy);
22529 + if (!enqueue(au_wkq + idle_idx, wkinfo))
22530 + return; /* success */
22532 + /* impossible? */
22533 + AuWarn1("failed to queue_work()\n");
22538 +static void wkq_func(struct work_struct *wk)
22540 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
22542 + wkinfo->func(wkinfo->args);
22543 + atomic_dec_return(wkinfo->busyp);
22544 + if (au_ftest_wkq(wkinfo->flags, WAIT))
22545 + complete(wkinfo->comp);
22547 + kobject_put(&au_sbi(wkinfo->sb)->si_kobj);
22548 + module_put(THIS_MODULE);
22554 + * Since struct completion is large, try allocating it dynamically.
22556 +#if defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS)
22557 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
22559 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
22561 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
22563 + init_completion(*comp);
22564 + wkinfo->comp = *comp;
22570 +static void au_wkq_comp_free(struct completion *comp)
22578 +#define AuWkqCompDeclare(name) \
22579 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
22580 + struct completion *comp = &_ ## name
22582 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
22584 + wkinfo->comp = *comp;
22588 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
22592 +#endif /* 4KSTACKS */
22594 +static void au_wkq_run(struct au_wkinfo *wkinfo)
22596 + au_dbg_verify_kthread();
22597 + INIT_WORK(&wkinfo->wk, wkq_func);
22601 +int au_wkq_wait(au_wkq_func_t func, void *args)
22604 + AuWkqCompDeclare(comp);
22605 + struct au_wkinfo wkinfo = {
22606 + .flags = AuWkq_WAIT,
22611 + err = au_wkq_comp_alloc(&wkinfo, &comp);
22613 + au_wkq_run(&wkinfo);
22614 + /* no timeout, no interrupt */
22615 + wait_for_completion(wkinfo.comp);
22616 + au_wkq_comp_free(comp);
22623 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb)
22626 + struct au_wkinfo *wkinfo;
22628 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
22631 + * wkq_func() must free this wkinfo.
22632 + * it highly depends upon the implementation of workqueue.
22635 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
22638 + wkinfo->flags = !AuWkq_WAIT;
22639 + wkinfo->func = func;
22640 + wkinfo->args = args;
22641 + wkinfo->comp = NULL;
22642 + kobject_get(&au_sbi(sb)->si_kobj);
22643 + __module_get(THIS_MODULE);
22645 + au_wkq_run(wkinfo);
22648 + atomic_dec(&au_sbi(sb)->si_nowait.nw_len);
22654 +/* ---------------------------------------------------------------------- */
22656 +void au_nwt_init(struct au_nowait_tasks *nwt)
22658 + atomic_set(&nwt->nw_len, 0);
22659 + /* smp_mb();*/ /* atomic_set */
22660 + init_waitqueue_head(&nwt->nw_wq);
22663 +void au_wkq_fin(void)
22667 + for (i = 0; i < aufs_nwkq; i++)
22668 + if (au_wkq[i].q && !IS_ERR(au_wkq[i].q))
22669 + destroy_workqueue(au_wkq[i].q);
22673 +int __init au_wkq_init(void)
22676 + struct au_wkq *nowaitq;
22678 + /* '+1' is for accounting of nowait queue */
22680 + au_wkq = kcalloc(aufs_nwkq + 1, sizeof(*au_wkq), GFP_NOFS);
22681 + if (unlikely(!au_wkq))
22685 + for (i = 0; i < aufs_nwkq; i++) {
22686 + au_wkq[i].q = create_singlethread_workqueue(AUFS_WKQ_NAME);
22687 + if (au_wkq[i].q && !IS_ERR(au_wkq[i].q)) {
22688 + atomic_set(&au_wkq[i].busy, 0);
22692 + err = PTR_ERR(au_wkq[i].q);
22697 + /* nowait accounting */
22698 + nowaitq = au_wkq + aufs_nwkq;
22699 + atomic_set(&nowaitq->busy, 0);
22700 + nowaitq->q = NULL;
22701 + /* smp_mb(); */ /* atomic_set */
22706 diff -urN linux-2.6.30.org/fs/aufs/wkq.h linux-2.6.30/fs/aufs/wkq.h
22707 --- linux-2.6.30.org/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
22708 +++ linux-2.6.30/fs/aufs/wkq.h 2009-07-21 08:54:19.000000000 +0200
22711 + * Copyright (C) 2005-2009 Junjiro R. Okajima
22713 + * This program, aufs is free software; you can redistribute it and/or modify
22714 + * it under the terms of the GNU General Public License as published by
22715 + * the Free Software Foundation; either version 2 of the License, or
22716 + * (at your option) any later version.
22718 + * This program is distributed in the hope that it will be useful,
22719 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22720 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22721 + * GNU General Public License for more details.
22723 + * You should have received a copy of the GNU General Public License
22724 + * along with this program; if not, write to the Free Software
22725 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22729 + * workqueue for asynchronous/super-io operations
22730 + * todo: try new credentials management scheme
22733 +#ifndef __AUFS_WKQ_H__
22734 +#define __AUFS_WKQ_H__
22738 +#include <linux/sched.h>
22739 +#include <linux/wait.h>
22740 +#include <linux/aufs_type.h>
22742 +struct super_block;
22744 +/* ---------------------------------------------------------------------- */
22747 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
22749 +struct au_nowait_tasks {
22751 + wait_queue_head_t nw_wq;
22754 +/* ---------------------------------------------------------------------- */
22756 +typedef void (*au_wkq_func_t)(void *args);
22759 +#define AuWkq_WAIT 1
22760 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
22761 +#define au_fset_wkq(flags, name) { (flags) |= AuWkq_##name; }
22762 +#define au_fclr_wkq(flags, name) { (flags) &= ~AuWkq_##name; }
22765 +int au_wkq_wait(au_wkq_func_t func, void *args);
22766 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb);
22767 +void au_nwt_init(struct au_nowait_tasks *nwt);
22768 +int __init au_wkq_init(void);
22769 +void au_wkq_fin(void);
22771 +/* ---------------------------------------------------------------------- */
22773 +static inline int au_test_wkq(struct task_struct *tsk)
22775 + return !tsk->mm && !strcmp(tsk->comm, AUFS_WKQ_NAME);
22778 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
22780 + if (!atomic_dec_return(&nwt->nw_len))
22781 + wake_up_all(&nwt->nw_wq);
22784 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
22786 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
22790 +#endif /* __KERNEL__ */
22791 +#endif /* __AUFS_WKQ_H__ */
22792 diff -urN linux-2.6.30.org/fs/aufs/xino.c linux-2.6.30/fs/aufs/xino.c
22793 --- linux-2.6.30.org/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
22794 +++ linux-2.6.30/fs/aufs/xino.c 2009-07-21 08:54:19.000000000 +0200
22797 + * Copyright (C) 2005-2009 Junjiro R. Okajima
22799 + * This program, aufs is free software; you can redistribute it and/or modify
22800 + * it under the terms of the GNU General Public License as published by
22801 + * the Free Software Foundation; either version 2 of the License, or
22802 + * (at your option) any later version.
22804 + * This program is distributed in the hope that it will be useful,
22805 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22806 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22807 + * GNU General Public License for more details.
22809 + * You should have received a copy of the GNU General Public License
22810 + * along with this program; if not, write to the Free Software
22811 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22815 + * external inode number translation table and bitmap
22818 +#include <linux/file.h>
22819 +#include <linux/seq_file.h>
22820 +#include <linux/uaccess.h>
22823 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
22827 + mm_segment_t oldfs;
22829 + oldfs = get_fs();
22830 + set_fs(KERNEL_DS);
22832 + /* todo: signal_pending? */
22833 + err = func(file, (char __user *)buf, size, pos);
22834 + } while (err == -EAGAIN || err == -EINTR);
22837 +#if 0 /* reserved for future use */
22839 + fsnotify_access(file->f_dentry);
22845 +/* ---------------------------------------------------------------------- */
22847 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *buf,
22848 + size_t size, loff_t *pos)
22851 + mm_segment_t oldfs;
22853 + oldfs = get_fs();
22854 + set_fs(KERNEL_DS);
22857 + /* todo: signal_pending? */
22858 + err = func(file, (const char __user *)buf, size, pos);
22859 + } while (err == -EAGAIN || err == -EINTR);
22863 +#if 0 /* reserved for future use */
22865 + fsnotify_modify(file->f_dentry);
22871 +struct do_xino_fwrite_args {
22873 + au_writef_t func;
22874 + struct file *file;
22880 +static void call_do_xino_fwrite(void *args)
22882 + struct do_xino_fwrite_args *a = args;
22883 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
22886 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
22891 + /* todo: signal block and no wkq? */
22892 + /* todo: new credential scheme */
22894 + * it breaks RLIMIT_FSIZE and normal user's limit,
22895 + * users should care about quota and real 'filesystem full.'
22897 + if (!au_test_wkq(current)) {
22899 + struct do_xino_fwrite_args args = {
22908 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
22909 + if (unlikely(wkq_err))
22912 + err = do_xino_fwrite(func, file, buf, size, pos);
22917 +/* ---------------------------------------------------------------------- */
22920 + * create a new xinofile at the same place/path as @base_file.
22922 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
22924 + struct file *file;
22925 + struct dentry *base, *dentry, *parent;
22926 + struct inode *dir;
22927 + struct qstr *name;
22930 + base = base_file->f_dentry;
22931 + parent = base->d_parent; /* dir inode is locked */
22932 + dir = parent->d_inode;
22935 + file = ERR_PTR(-EINVAL);
22936 + name = &base->d_name;
22937 + dentry = vfsub_lookup_one_len(name->name, parent, name->len);
22938 + if (IS_ERR(dentry)) {
22939 + file = (void *)dentry;
22940 + AuErr("%.*s lookup err %ld\n", AuLNPair(name), PTR_ERR(dentry));
22944 + /* no need to mnt_want_write() since we call dentry_open() later */
22945 + err = vfs_create(dir, dentry, S_IRUGO | S_IWUGO, NULL);
22946 + if (unlikely(err)) {
22947 + file = ERR_PTR(err);
22948 + AuErr("%.*s create err %d\n", AuLNPair(name), err);
22952 + file = dentry_open(dget(dentry), mntget(base_file->f_vfsmnt),
22953 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE,
22955 + if (IS_ERR(file)) {
22956 + AuErr("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
22960 + err = vfsub_unlink(dir, &file->f_path, /*force*/0);
22961 + if (unlikely(err)) {
22962 + AuErr("%.*s unlink err %d\n", AuLNPair(name), err);
22967 + /* no one can touch copy_src xino */
22968 + err = au_copy_file(file, copy_src,
22969 + i_size_read(copy_src->f_dentry->d_inode));
22970 + if (unlikely(err)) {
22971 + AuErr("%.*s copy err %d\n", AuLNPair(name), err);
22975 + goto out_dput; /* success */
22979 + file = ERR_PTR(err);
22986 +struct au_xino_lock_dir {
22987 + struct au_hinode *hdir;
22988 + struct dentry *parent;
22989 + struct mutex *mtx;
22992 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
22993 + struct au_xino_lock_dir *ldir)
22995 + aufs_bindex_t brid, bindex;
22997 + ldir->hdir = NULL;
22999 + brid = au_xino_brid(sb);
23001 + bindex = au_br_index(sb, brid);
23002 + if (bindex >= 0) {
23003 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
23004 + au_hin_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
23006 + ldir->parent = dget_parent(xino->f_dentry);
23007 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
23008 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
23012 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
23015 + au_hin_imtx_unlock(ldir->hdir);
23017 + mutex_unlock(ldir->mtx);
23018 + dput(ldir->parent);
23022 +/* ---------------------------------------------------------------------- */
23024 +/* trucate xino files asynchronously */
23026 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
23029 + aufs_bindex_t bi, bend;
23030 + struct au_branch *br;
23031 + struct file *new_xino, *file;
23032 + struct super_block *h_sb;
23033 + struct au_xino_lock_dir ldir;
23036 + bend = au_sbend(sb);
23037 + if (unlikely(bindex < 0 || bend < bindex))
23039 + br = au_sbr(sb, bindex);
23040 + file = br->br_xino.xi_file;
23044 + au_xino_lock_dir(sb, file, &ldir);
23045 + /* mnt_want_write() is unnecessary here */
23046 + new_xino = au_xino_create2(file, file);
23047 + au_xino_unlock_dir(&ldir);
23048 + err = PTR_ERR(new_xino);
23049 + if (IS_ERR(new_xino))
23053 + br->br_xino.xi_file = new_xino;
23055 + h_sb = br->br_mnt->mnt_sb;
23056 + for (bi = 0; bi <= bend; bi++) {
23057 + if (unlikely(bi == bindex))
23059 + br = au_sbr(sb, bi);
23060 + if (br->br_mnt->mnt_sb != h_sb)
23063 + fput(br->br_xino.xi_file);
23064 + br->br_xino.xi_file = new_xino;
23065 + get_file(new_xino);
23072 +struct xino_do_trunc_args {
23073 + struct super_block *sb;
23074 + struct au_branch *br;
23077 +static void xino_do_trunc(void *_args)
23079 + struct xino_do_trunc_args *args = _args;
23080 + struct super_block *sb;
23081 + struct au_branch *br;
23082 + struct inode *dir;
23084 + aufs_bindex_t bindex;
23088 + dir = sb->s_root->d_inode;
23091 + si_noflush_write_lock(sb);
23092 + ii_read_lock_parent(dir);
23093 + bindex = au_br_index(sb, br->br_id);
23094 + err = au_xino_trunc(sb, bindex);
23096 + && br->br_xino.xi_file->f_dentry->d_inode->i_blocks
23097 + >= br->br_xino_upper)
23098 + br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
23100 + ii_read_unlock(dir);
23101 + if (unlikely(err))
23102 + AuWarn("err b%d, (%d)\n", bindex, err);
23103 + atomic_dec(&br->br_xino_running);
23104 + atomic_dec(&br->br_count);
23105 + au_nwt_done(&au_sbi(sb)->si_nowait);
23106 + si_write_unlock(sb);
23110 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
23112 + struct xino_do_trunc_args *args;
23115 + if (br->br_xino.xi_file->f_dentry->d_inode->i_blocks
23116 + < br->br_xino_upper)
23119 + if (atomic_inc_return(&br->br_xino_running) > 1)
23122 + /* lock and kfree() will be called in trunc_xino() */
23123 + args = kmalloc(sizeof(*args), GFP_NOFS);
23124 + if (unlikely(!args)) {
23125 + AuErr1("no memory\n");
23129 + atomic_inc_return(&br->br_count);
23132 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb);
23134 + return; /* success */
23136 + AuErr("wkq %d\n", wkq_err);
23137 + atomic_dec_return(&br->br_count);
23142 + atomic_dec_return(&br->br_xino_running);
23145 +/* ---------------------------------------------------------------------- */
23147 +static int au_xino_do_write(au_writef_t write, struct file *file,
23148 + ino_t h_ino, ino_t ino)
23154 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
23155 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
23158 + pos *= sizeof(ino);
23159 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
23160 + if (sz == sizeof(ino))
23161 + return 0; /* success */
23163 + AuIOErr("write failed (%zd)\n", sz);
23168 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
23169 + * at the position of @h_ino.
23170 + * even if @ino is zero, it is written to the xinofile and means no entry.
23171 + * if the size of the xino file on a specific filesystem exceeds the watermark,
23172 + * try truncating it.
23174 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
23178 + unsigned int mnt_flags;
23179 + struct au_branch *br;
23181 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
23182 + || ((loff_t)-1) > 0);
23183 + SiMustAnyLock(sb);
23185 + mnt_flags = au_mntflags(sb);
23186 + if (!au_opt_test(mnt_flags, XINO))
23189 + br = au_sbr(sb, bindex);
23190 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
23193 + if (au_opt_test(mnt_flags, TRUNC_XINO)
23194 + && au_test_fs_trunc_xino(br->br_mnt->mnt_sb))
23195 + xino_try_trunc(sb, br);
23196 + return 0; /* success */
23199 + AuIOErr("write failed (%d)\n", err);
23203 +/* ---------------------------------------------------------------------- */
23205 +/* aufs inode number bitmap */
23207 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
23208 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
23212 + AuDebugOn(bit < 0 || page_bits <= bit);
23213 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
23217 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
23219 + AuDebugOn(ino < AUFS_FIRST_INO);
23220 + ino -= AUFS_FIRST_INO;
23221 + *pindex = ino / page_bits;
23222 + *bit = ino % page_bits;
23225 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
23230 + struct au_sbinfo *sbinfo;
23231 + struct file *xib;
23232 + unsigned long *p;
23234 + sbinfo = au_sbi(sb);
23235 + MtxMustLock(&sbinfo->si_xib_mtx);
23236 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
23237 + || !au_opt_test(sbinfo->si_mntflags, XINO));
23239 + if (pindex == sbinfo->si_xib_last_pindex)
23242 + xib = sbinfo->si_xib;
23243 + p = sbinfo->si_xib_buf;
23244 + pos = sbinfo->si_xib_last_pindex;
23245 + pos *= PAGE_SIZE;
23246 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
23247 + if (unlikely(sz != PAGE_SIZE))
23251 + pos *= PAGE_SIZE;
23252 + if (i_size_read(xib->f_dentry->d_inode) >= pos + PAGE_SIZE)
23253 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
23255 + memset(p, 0, PAGE_SIZE);
23256 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
23258 + if (sz == PAGE_SIZE) {
23259 + sbinfo->si_xib_last_pindex = pindex;
23260 + return 0; /* success */
23264 + AuIOErr1("write failed (%zd)\n", sz);
23271 +/* ---------------------------------------------------------------------- */
23273 +int au_xino_write0(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
23277 + unsigned long pindex;
23278 + struct au_sbinfo *sbinfo;
23280 + if (!au_opt_test(au_mntflags(sb), XINO))
23285 + sbinfo = au_sbi(sb);
23286 + xib_calc_bit(ino, &pindex, &bit);
23287 + AuDebugOn(page_bits <= bit);
23288 + mutex_lock(&sbinfo->si_xib_mtx);
23289 + err = xib_pindex(sb, pindex);
23291 + clear_bit(bit, sbinfo->si_xib_buf);
23292 + sbinfo->si_xib_next_bit = bit;
23294 + mutex_unlock(&sbinfo->si_xib_mtx);
23298 + err = au_xino_write(sb, bindex, h_ino, 0);
23302 +/* get an unused inode number from bitmap */
23303 +ino_t au_xino_new_ino(struct super_block *sb)
23306 + unsigned long *p, pindex, ul, pend;
23307 + struct au_sbinfo *sbinfo;
23308 + struct file *file;
23309 + int free_bit, err;
23311 + if (!au_opt_test(au_mntflags(sb), XINO))
23312 + return iunique(sb, AUFS_FIRST_INO);
23314 + sbinfo = au_sbi(sb);
23315 + mutex_lock(&sbinfo->si_xib_mtx);
23316 + p = sbinfo->si_xib_buf;
23317 + free_bit = sbinfo->si_xib_next_bit;
23318 + if (free_bit < page_bits && !test_bit(free_bit, p))
23319 + goto out; /* success */
23320 + free_bit = find_first_zero_bit(p, page_bits);
23321 + if (free_bit < page_bits)
23322 + goto out; /* success */
23324 + pindex = sbinfo->si_xib_last_pindex;
23325 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
23326 + err = xib_pindex(sb, ul);
23327 + if (unlikely(err))
23329 + free_bit = find_first_zero_bit(p, page_bits);
23330 + if (free_bit < page_bits)
23331 + goto out; /* success */
23334 + file = sbinfo->si_xib;
23335 + pend = i_size_read(file->f_dentry->d_inode) / PAGE_SIZE;
23336 + for (ul = pindex + 1; ul <= pend; ul++) {
23337 + err = xib_pindex(sb, ul);
23338 + if (unlikely(err))
23340 + free_bit = find_first_zero_bit(p, page_bits);
23341 + if (free_bit < page_bits)
23342 + goto out; /* success */
23347 + set_bit(free_bit, p);
23348 + sbinfo->si_xib_next_bit++;
23349 + pindex = sbinfo->si_xib_last_pindex;
23350 + mutex_unlock(&sbinfo->si_xib_mtx);
23351 + ino = xib_calc_ino(pindex, free_bit);
23352 + AuDbg("i%lu\n", (unsigned long)ino);
23355 + mutex_unlock(&sbinfo->si_xib_mtx);
23361 + * read @ino from xinofile for the specified branch{@sb, @bindex}
23362 + * at the position of @h_ino.
23363 + * if @ino does not exist and @do_new is true, get new one.
23365 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
23371 + struct file *file;
23372 + struct au_sbinfo *sbinfo;
23375 + if (!au_opt_test(au_mntflags(sb), XINO))
23376 + return 0; /* no xino */
23379 + sbinfo = au_sbi(sb);
23381 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
23382 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
23385 + pos *= sizeof(*ino);
23387 + file = au_sbr(sb, bindex)->br_xino.xi_file;
23388 + if (i_size_read(file->f_dentry->d_inode) < pos + sizeof(*ino))
23389 + return 0; /* no ino */
23391 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
23392 + if (sz == sizeof(*ino))
23393 + return 0; /* success */
23396 + if (unlikely(sz >= 0)) {
23398 + AuIOErr("xino read error (%zd)\n", sz);
23404 +/* ---------------------------------------------------------------------- */
23406 +/* create and set a new xino file */
23408 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
23410 + struct file *file;
23411 + struct dentry *h_parent, *d;
23412 + struct inode *h_dir;
23416 + * at mount-time, and the xino file is the default path,
23417 + * hinotify is disabled so we have no inotify events to ignore.
23418 + * when a user specified the xino, we cannot get au_hdir to be ignored.
23420 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE,
23421 + S_IRUGO | S_IWUGO);
23422 + if (IS_ERR(file)) {
23424 + AuErr("open %s(%ld)\n", fname, PTR_ERR(file));
23428 + /* keep file count */
23429 + h_parent = dget_parent(file->f_dentry);
23430 + h_dir = h_parent->d_inode;
23431 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
23432 + /* mnt_want_write() is unnecessary here */
23433 + err = vfsub_unlink(h_dir, &file->f_path, /*force*/0);
23434 + mutex_unlock(&h_dir->i_mutex);
23436 + if (unlikely(err)) {
23438 + AuErr("unlink %s(%d)\n", fname, err);
23443 + d = file->f_dentry;
23444 + if (unlikely(sb == d->d_sb)) {
23446 + AuErr("%s must be outside\n", fname);
23449 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
23451 + AuErr("xino doesn't support %s(%s)\n",
23452 + fname, au_sbtype(d->d_sb));
23455 + return file; /* success */
23459 + file = ERR_PTR(err);
23464 + * find another branch who is on the same filesystem of the specified
23465 + * branch{@btgt}. search until @bend.
23467 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
23468 + aufs_bindex_t bend)
23470 + aufs_bindex_t bindex;
23471 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
23473 + for (bindex = 0; bindex < btgt; bindex++)
23474 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
23476 + for (bindex++; bindex <= bend; bindex++)
23477 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
23482 +/* ---------------------------------------------------------------------- */
23485 + * initialize the xinofile for the specified branch @br
23486 + * at the place/path where @base_file indicates.
23487 + * test whether another branch is on the same filesystem or not,
23488 + * if @do_test is true.
23490 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
23491 + struct file *base_file, int do_test)
23495 + aufs_bindex_t bend, bindex;
23496 + struct au_branch *shared_br, *b;
23497 + struct file *file;
23498 + struct super_block *tgt_sb;
23500 + shared_br = NULL;
23501 + bend = au_sbend(sb);
23503 + tgt_sb = br->br_mnt->mnt_sb;
23504 + for (bindex = 0; bindex <= bend; bindex++) {
23505 + b = au_sbr(sb, bindex);
23506 + if (tgt_sb == b->br_mnt->mnt_sb) {
23513 + if (!shared_br || !shared_br->br_xino.xi_file) {
23514 + struct au_xino_lock_dir ldir;
23516 + au_xino_lock_dir(sb, base_file, &ldir);
23517 + /* mnt_want_write() is unnecessary here */
23518 + file = au_xino_create2(base_file, NULL);
23519 + au_xino_unlock_dir(&ldir);
23520 + err = PTR_ERR(file);
23521 + if (IS_ERR(file))
23523 + br->br_xino.xi_file = file;
23525 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
23526 + get_file(br->br_xino.xi_file);
23529 + ino = AUFS_ROOT_INO;
23530 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
23533 + return 0; /* success */
23540 +/* ---------------------------------------------------------------------- */
23542 +/* trucate a xino bitmap file */
23545 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
23549 + unsigned long pindex;
23550 + loff_t pos, pend;
23551 + struct au_sbinfo *sbinfo;
23554 + unsigned long *p;
23557 + sbinfo = au_sbi(sb);
23558 + MtxMustLock(&sbinfo->si_xib_mtx);
23559 + p = sbinfo->si_xib_buf;
23560 + func = sbinfo->si_xread;
23561 + pend = i_size_read(file->f_dentry->d_inode);
23563 + while (pos < pend) {
23564 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
23566 + if (unlikely(sz <= 0))
23570 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
23571 + if (unlikely(*ino < AUFS_FIRST_INO))
23574 + xib_calc_bit(*ino, &pindex, &bit);
23575 + AuDebugOn(page_bits <= bit);
23576 + err = xib_pindex(sb, pindex);
23588 +static int xib_restore(struct super_block *sb)
23591 + aufs_bindex_t bindex, bend;
23595 + page = (void *)__get_free_page(GFP_NOFS);
23596 + if (unlikely(!page))
23600 + bend = au_sbend(sb);
23601 + for (bindex = 0; !err && bindex <= bend; bindex++)
23602 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
23603 + err = do_xib_restore
23604 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
23606 + AuDbg("b%d\n", bindex);
23607 + free_page((unsigned long)page);
23613 +int au_xib_trunc(struct super_block *sb)
23618 + struct au_xino_lock_dir ldir;
23619 + struct au_sbinfo *sbinfo;
23620 + unsigned long *p;
23621 + struct file *file;
23623 + SiMustWriteLock(sb);
23626 + sbinfo = au_sbi(sb);
23627 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
23630 + file = sbinfo->si_xib;
23631 + if (i_size_read(file->f_dentry->d_inode) <= PAGE_SIZE)
23634 + au_xino_lock_dir(sb, file, &ldir);
23635 + /* mnt_want_write() is unnecessary here */
23636 + file = au_xino_create2(sbinfo->si_xib, NULL);
23637 + au_xino_unlock_dir(&ldir);
23638 + err = PTR_ERR(file);
23639 + if (IS_ERR(file))
23641 + fput(sbinfo->si_xib);
23642 + sbinfo->si_xib = file;
23644 + p = sbinfo->si_xib_buf;
23645 + memset(p, 0, PAGE_SIZE);
23647 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
23648 + if (unlikely(sz != PAGE_SIZE)) {
23650 + AuIOErr("err %d\n", err);
23656 + mutex_lock(&sbinfo->si_xib_mtx);
23657 + /* mnt_want_write() is unnecessary here */
23658 + err = xib_restore(sb);
23659 + mutex_unlock(&sbinfo->si_xib_mtx);
23665 +/* ---------------------------------------------------------------------- */
23668 + * xino mount option handlers
23670 +static au_readf_t find_readf(struct file *h_file)
23672 + const struct file_operations *fop = h_file->f_op;
23676 + return fop->read;
23677 + if (fop->aio_read)
23678 + return do_sync_read;
23680 + return ERR_PTR(-ENOSYS);
23683 +static au_writef_t find_writef(struct file *h_file)
23685 + const struct file_operations *fop = h_file->f_op;
23689 + return fop->write;
23690 + if (fop->aio_write)
23691 + return do_sync_write;
23693 + return ERR_PTR(-ENOSYS);
23697 +static void xino_clear_xib(struct super_block *sb)
23699 + struct au_sbinfo *sbinfo;
23701 + SiMustWriteLock(sb);
23703 + sbinfo = au_sbi(sb);
23704 + sbinfo->si_xread = NULL;
23705 + sbinfo->si_xwrite = NULL;
23706 + if (sbinfo->si_xib)
23707 + fput(sbinfo->si_xib);
23708 + sbinfo->si_xib = NULL;
23709 + free_page((unsigned long)sbinfo->si_xib_buf);
23710 + sbinfo->si_xib_buf = NULL;
23713 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
23717 + struct au_sbinfo *sbinfo;
23718 + struct file *file;
23720 + SiMustWriteLock(sb);
23722 + sbinfo = au_sbi(sb);
23723 + file = au_xino_create2(base, sbinfo->si_xib);
23724 + err = PTR_ERR(file);
23725 + if (IS_ERR(file))
23727 + if (sbinfo->si_xib)
23728 + fput(sbinfo->si_xib);
23729 + sbinfo->si_xib = file;
23730 + sbinfo->si_xread = find_readf(file);
23731 + sbinfo->si_xwrite = find_writef(file);
23734 + if (!sbinfo->si_xib_buf)
23735 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
23736 + if (unlikely(!sbinfo->si_xib_buf))
23739 + sbinfo->si_xib_last_pindex = 0;
23740 + sbinfo->si_xib_next_bit = 0;
23741 + if (i_size_read(file->f_dentry->d_inode) < PAGE_SIZE) {
23743 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
23744 + PAGE_SIZE, &pos);
23745 + if (unlikely(err != PAGE_SIZE))
23749 + goto out; /* success */
23752 + free_page((unsigned long)sbinfo->si_xib_buf);
23753 + sbinfo->si_xib_buf = NULL;
23757 + fput(sbinfo->si_xib);
23758 + sbinfo->si_xib = NULL;
23759 + sbinfo->si_xread = NULL;
23760 + sbinfo->si_xwrite = NULL;
23765 +/* xino for each branch */
23766 +static void xino_clear_br(struct super_block *sb)
23768 + aufs_bindex_t bindex, bend;
23769 + struct au_branch *br;
23771 + bend = au_sbend(sb);
23772 + for (bindex = 0; bindex <= bend; bindex++) {
23773 + br = au_sbr(sb, bindex);
23774 + if (!br || !br->br_xino.xi_file)
23777 + fput(br->br_xino.xi_file);
23778 + br->br_xino.xi_file = NULL;
23782 +static int au_xino_set_br(struct super_block *sb, struct file *base)
23786 + aufs_bindex_t bindex, bend, bshared;
23788 + struct file *old, *new;
23790 + struct au_branch *br;
23791 + struct inode *inode;
23792 + au_writef_t writef;
23794 + SiMustWriteLock(sb);
23797 + bend = au_sbend(sb);
23798 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
23799 + if (unlikely(!fpair))
23802 + inode = sb->s_root->d_inode;
23803 + ino = AUFS_ROOT_INO;
23804 + writef = au_sbi(sb)->si_xwrite;
23805 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
23806 + br = au_sbr(sb, bindex);
23807 + bshared = is_sb_shared(sb, bindex, bindex - 1);
23808 + if (bshared >= 0) {
23809 + /* shared xino */
23810 + *p = fpair[bshared];
23811 + get_file(p->new);
23816 + p->old = br->br_xino.xi_file;
23817 + p->new = au_xino_create2(base, br->br_xino.xi_file);
23818 + err = PTR_ERR(p->new);
23819 + if (IS_ERR(p->new)) {
23825 + err = au_xino_do_write(writef, p->new,
23826 + au_h_iptr(inode, bindex)->i_ino, ino);
23827 + if (unlikely(err))
23831 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
23832 + br = au_sbr(sb, bindex);
23833 + if (br->br_xino.xi_file)
23834 + fput(br->br_xino.xi_file);
23835 + get_file(p->new);
23836 + br->br_xino.xi_file = p->new;
23840 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
23850 +void au_xino_clr(struct super_block *sb)
23852 + struct au_sbinfo *sbinfo;
23854 + au_xigen_clr(sb);
23855 + xino_clear_xib(sb);
23856 + xino_clear_br(sb);
23857 + sbinfo = au_sbi(sb);
23858 + /* lvalue, do not call au_mntflags() */
23859 + au_opt_clr(sbinfo->si_mntflags, XINO);
23862 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
23865 + struct dentry *parent, *cur_parent;
23866 + struct qstr *dname, *cur_name;
23867 + struct file *cur_xino;
23868 + struct inode *dir;
23869 + struct au_sbinfo *sbinfo;
23871 + SiMustWriteLock(sb);
23874 + sbinfo = au_sbi(sb);
23875 + parent = dget_parent(xino->file->f_dentry);
23878 + dname = &xino->file->f_dentry->d_name;
23879 + cur_xino = sbinfo->si_xib;
23881 + cur_parent = dget_parent(cur_xino->f_dentry);
23882 + cur_name = &cur_xino->f_dentry->d_name;
23883 + skip = (cur_parent == parent
23884 + && dname->len == cur_name->len
23885 + && !memcmp(dname->name, cur_name->name,
23887 + dput(cur_parent);
23893 + au_opt_set(sbinfo->si_mntflags, XINO);
23894 + dir = parent->d_inode;
23895 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
23896 + /* mnt_want_write() is unnecessary here */
23897 + err = au_xino_set_xib(sb, xino->file);
23899 + err = au_xigen_set(sb, xino->file);
23901 + err = au_xino_set_br(sb, xino->file);
23902 + mutex_unlock(&dir->i_mutex);
23904 + goto out; /* success */
23907 + AuIOErr("failed creating xino(%d).\n", err);
23914 +/* ---------------------------------------------------------------------- */
23917 + * create a xinofile at the default place/path.
23919 +struct file *au_xino_def(struct super_block *sb)
23921 + struct file *file;
23923 + struct au_branch *br;
23924 + struct super_block *h_sb;
23925 + struct path path;
23926 + aufs_bindex_t bend, bindex, bwr;
23929 + bend = au_sbend(sb);
23931 + for (bindex = 0; bindex <= bend; bindex++) {
23932 + br = au_sbr(sb, bindex);
23933 + if (au_br_writable(br->br_perm)
23934 + && !au_test_fs_bad_xino(br->br_mnt->mnt_sb)) {
23941 + file = ERR_PTR(-ENOMEM);
23942 + page = __getname();
23943 + if (unlikely(!page))
23945 + path.mnt = br->br_mnt;
23946 + path.dentry = au_h_dptr(sb->s_root, bwr);
23947 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
23948 + file = (void *)p;
23949 + if (!IS_ERR(p)) {
23950 + strcat(p, "/" AUFS_XINO_FNAME);
23951 + AuDbg("%s\n", p);
23952 + file = au_xino_create(sb, p, /*silent*/0);
23953 + if (!IS_ERR(file))
23954 + au_xino_brid_set(sb, br->br_id);
23958 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
23959 + if (IS_ERR(file))
23961 + h_sb = file->f_dentry->d_sb;
23962 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
23963 + AuErr("xino doesn't support %s(%s)\n",
23964 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
23966 + file = ERR_PTR(-EINVAL);
23968 + if (!IS_ERR(file))
23969 + au_xino_brid_set(sb, -1);
23976 +/* ---------------------------------------------------------------------- */
23978 +int au_xino_path(struct seq_file *seq, struct file *file)
23982 + err = au_seq_path(seq, &file->f_path);
23983 + if (unlikely(err < 0))
23987 +#define Deleted "\\040(deleted)"
23988 + seq->count -= sizeof(Deleted) - 1;
23989 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
23990 + sizeof(Deleted) - 1));
23996 diff -urN linux-2.6.30.org/fs/Kconfig linux-2.6.30/fs/Kconfig
23997 --- linux-2.6.30.org/fs/Kconfig 2009-06-10 05:05:27.000000000 +0200
23998 +++ linux-2.6.30/fs/Kconfig 2009-07-21 09:13:25.176633466 +0200
23999 @@ -176,6 +176,7 @@
24000 source "fs/sysv/Kconfig"
24001 source "fs/ufs/Kconfig"
24002 source "fs/exofs/Kconfig"
24003 +source "fs/aufs/Kconfig"
24006 tristate "NILFS2 file system support (EXPERIMENTAL)"
24007 diff -urN linux-2.6.30.org/fs/Makefile linux-2.6.30/fs/Makefile
24008 --- linux-2.6.30.org/fs/Makefile 2009-06-10 05:05:27.000000000 +0200
24009 +++ linux-2.6.30/fs/Makefile 2009-07-21 09:13:25.184549275 +0200
24010 @@ -124,3 +124,4 @@
24011 obj-$(CONFIG_BTRFS_FS) += btrfs/
24012 obj-$(CONFIG_GFS2_FS) += gfs2/
24013 obj-$(CONFIG_EXOFS_FS) += exofs/
24014 +obj-$(CONFIG_AUFS_FS) += aufs/
24015 diff -urN linux-2.6.30.org/fs/namei.c linux-2.6.30/fs/namei.c
24016 --- linux-2.6.30.org/fs/namei.c 2009-06-10 05:05:27.000000000 +0200
24017 +++ linux-2.6.30/fs/namei.c 2009-07-21 09:13:29.146633618 +0200
24018 @@ -337,6 +337,7 @@
24022 +EXPORT_SYMBOL(deny_write_access);
24025 * path_get - get a reference to a path
24026 @@ -1200,7 +1201,7 @@
24027 * needs parent already locked. Doesn't follow mounts.
24030 -static struct dentry *lookup_hash(struct nameidata *nd)
24031 +struct dentry *lookup_hash(struct nameidata *nd)
24035 @@ -1209,8 +1210,9 @@
24036 return ERR_PTR(err);
24037 return __lookup_hash(&nd->last, nd->path.dentry, nd);
24039 +EXPORT_SYMBOL(lookup_hash);
24041 -static int __lookup_one_len(const char *name, struct qstr *this,
24042 +int __lookup_one_len(const char *name, struct qstr *this,
24043 struct dentry *base, int len)
24045 unsigned long hash;
24046 @@ -1231,6 +1233,7 @@
24047 this->hash = end_name_hash(hash);
24050 +EXPORT_SYMBOL(__lookup_one_len);
24053 * lookup_one_len - filesystem helper to lookup single pathname component
24054 diff -urN linux-2.6.30.org/fs/namespace.c linux-2.6.30/fs/namespace.c
24055 --- linux-2.6.30.org/fs/namespace.c 2009-06-10 05:05:27.000000000 +0200
24056 +++ linux-2.6.30/fs/namespace.c 2009-07-21 09:13:29.166633410 +0200
24059 /* spinlock for vfsmount related operations, inplace of dcache_lock */
24060 __cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
24061 +EXPORT_SYMBOL(vfsmount_lock);
24064 static DEFINE_IDA(mnt_id_ida);
24065 diff -urN linux-2.6.30.org/fs/open.c linux-2.6.30/fs/open.c
24066 --- linux-2.6.30.org/fs/open.c 2009-06-10 05:05:27.000000000 +0200
24067 +++ linux-2.6.30/fs/open.c 2009-07-21 09:13:29.183798348 +0200
24068 @@ -221,6 +221,7 @@
24069 mutex_unlock(&dentry->d_inode->i_mutex);
24072 +EXPORT_SYMBOL(do_truncate);
24074 static long do_sys_truncate(const char __user *pathname, loff_t length)
24076 diff -urN linux-2.6.30.org/fs/splice.c linux-2.6.30/fs/splice.c
24077 --- linux-2.6.30.org/fs/splice.c 2009-06-10 05:05:27.000000000 +0200
24078 +++ linux-2.6.30/fs/splice.c 2009-07-21 09:13:29.216632034 +0200
24079 @@ -905,8 +905,8 @@
24081 * Attempt to initiate a splice from pipe to file.
24083 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
24084 - loff_t *ppos, size_t len, unsigned int flags)
24085 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
24086 + loff_t *ppos, size_t len, unsigned int flags)
24090 @@ -925,13 +925,14 @@
24092 return out->f_op->splice_write(pipe, out, ppos, len, flags);
24094 +EXPORT_SYMBOL(do_splice_from);
24097 * Attempt to initiate a splice from a file to a pipe.
24099 -static long do_splice_to(struct file *in, loff_t *ppos,
24100 - struct pipe_inode_info *pipe, size_t len,
24101 - unsigned int flags)
24102 +long do_splice_to(struct file *in, loff_t *ppos,
24103 + struct pipe_inode_info *pipe, size_t len,
24104 + unsigned int flags)
24108 @@ -947,6 +948,7 @@
24110 return in->f_op->splice_read(in, ppos, pipe, len, flags);
24112 +EXPORT_SYMBOL(do_splice_to);
24115 * splice_direct_to_actor - splices data directly between two non-pipes
24116 diff -urN linux-2.6.30.org/include/linux/aufs_type.h linux-2.6.30/include/linux/aufs_type.h
24117 --- linux-2.6.30.org/include/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
24118 +++ linux-2.6.30/include/linux/aufs_type.h 2009-07-21 08:54:19.000000000 +0200
24121 + * Copyright (C) 2005-2009 Junjiro R. Okajima
24123 + * This program, aufs is free software; you can redistribute it and/or modify
24124 + * it under the terms of the GNU General Public License as published by
24125 + * the Free Software Foundation; either version 2 of the License, or
24126 + * (at your option) any later version.
24128 + * This program is distributed in the hope that it will be useful,
24129 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24130 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24131 + * GNU General Public License for more details.
24133 + * You should have received a copy of the GNU General Public License
24134 + * along with this program; if not, write to the Free Software
24135 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24138 +#ifndef __AUFS_TYPE_H__
24139 +#define __AUFS_TYPE_H__
24141 +#include <linux/ioctl.h>
24143 +#define AUFS_VERSION "2-standalone.tree-30-20090720"
24145 +/* todo? move this to linux-2.6.19/include/magic.h */
24146 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
24148 +/* ---------------------------------------------------------------------- */
24150 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
24151 +/* some environments treat 'char' as 'unsigned char' by default */
24152 +typedef signed char aufs_bindex_t;
24153 +#define AUFS_BRANCH_MAX 127
24155 +typedef short aufs_bindex_t;
24156 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
24157 +#define AUFS_BRANCH_MAX 511
24158 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
24159 +#define AUFS_BRANCH_MAX 1023
24160 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
24161 +#define AUFS_BRANCH_MAX 32767
24166 +#ifndef AUFS_BRANCH_MAX
24167 +#error unknown CONFIG_AUFS_BRANCH_MAX value
24169 +#endif /* __KERNEL__ */
24171 +/* ---------------------------------------------------------------------- */
24173 +#define AUFS_NAME "aufs"
24174 +#define AUFS_FSTYPE AUFS_NAME
24176 +#define AUFS_ROOT_INO 2
24177 +#define AUFS_FIRST_INO 11
24179 +#define AUFS_WH_PFX ".wh."
24180 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
24181 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
24182 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
24183 +#define AUFS_XINO_TRUNC_INIT 64 /* blocks */
24184 +#define AUFS_XINO_TRUNC_STEP 4 /* blocks */
24185 +#define AUFS_DIRWH_DEF 3
24186 +#define AUFS_RDCACHE_DEF 10 /* seconds */
24187 +#define AUFS_RDBLK_DEF 512 /* bytes */
24188 +#define AUFS_RDHASH_DEF 32
24189 +#define AUFS_WKQ_NAME AUFS_NAME "d"
24190 +#define AUFS_NWKQ_DEF 4
24191 +#define AUFS_MFS_SECOND_DEF 30 /* seconds */
24192 +#define AUFS_PLINK_WARN 100 /* number of plinks */
24194 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
24195 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
24197 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
24198 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
24199 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
24201 +/* doubly whiteouted */
24202 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
24203 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
24204 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
24206 +/* branch permission */
24207 +#define AUFS_BRPERM_RW "rw"
24208 +#define AUFS_BRPERM_RO "ro"
24209 +#define AUFS_BRPERM_RR "rr"
24210 +#define AUFS_BRPERM_WH "wh"
24211 +#define AUFS_BRPERM_NLWH "nolwh"
24212 +#define AUFS_BRPERM_ROWH AUFS_BRPERM_RO "+" AUFS_BRPERM_WH
24213 +#define AUFS_BRPERM_RRWH AUFS_BRPERM_RR "+" AUFS_BRPERM_WH
24214 +#define AUFS_BRPERM_RWNLWH AUFS_BRPERM_RW "+" AUFS_BRPERM_NLWH
24216 +/* ---------------------------------------------------------------------- */
24220 + AuCtl_PLINK_MAINT,
24221 + AuCtl_PLINK_CLEAN
24224 +#define AuCtlType 'A'
24225 +#define AUFS_CTL_PLINK_MAINT _IO(AuCtlType, AuCtl_PLINK_MAINT)
24226 +#define AUFS_CTL_PLINK_CLEAN _IO(AuCtlType, AuCtl_PLINK_CLEAN)
24228 +#endif /* __AUFS_TYPE_H__ */
24229 diff -urN linux-2.6.30.org/include/linux/Kbuild linux-2.6.30/include/linux/Kbuild
24230 --- linux-2.6.30.org/include/linux/Kbuild 2009-06-10 05:05:27.000000000 +0200
24231 +++ linux-2.6.30/include/linux/Kbuild 2009-07-21 09:13:25.239966985 +0200
24233 header-y += atmsap.h
24234 header-y += atmsvc.h
24235 header-y += atm_zatm.h
24236 +header-y += aufs_type.h
24237 header-y += auto_fs4.h
24239 header-y += b1lli.h
24240 diff -urN linux-2.6.30.org/include/linux/namei.h linux-2.6.30/include/linux/namei.h
24241 --- linux-2.6.30.org/include/linux/namei.h 2009-06-10 05:05:27.000000000 +0200
24242 +++ linux-2.6.30/include/linux/namei.h 2009-07-21 09:13:29.216632034 +0200
24244 extern struct file *nameidata_to_filp(struct nameidata *nd, int flags);
24245 extern void release_open_intent(struct nameidata *);
24247 +extern struct dentry *lookup_hash(struct nameidata *nd);
24248 +extern int __lookup_one_len(const char *name, struct qstr *this,
24249 + struct dentry *base, int len);
24250 extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
24251 extern struct dentry *lookup_one_noperm(const char *, struct dentry *);
24253 diff -urN linux-2.6.30.org/include/linux/splice.h linux-2.6.30/include/linux/splice.h
24254 --- linux-2.6.30.org/include/linux/splice.h 2009-06-10 05:05:27.000000000 +0200
24255 +++ linux-2.6.30/include/linux/splice.h 2009-07-21 09:13:29.234192642 +0200
24257 extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *,
24258 splice_direct_actor *);
24260 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
24261 + loff_t *ppos, size_t len, unsigned int flags);
24262 +extern long do_splice_to(struct file *in, loff_t *ppos,
24263 + struct pipe_inode_info *pipe, size_t len,
24264 + unsigned int flags);
24267 diff -urN linux-2.6.30.org/security/device_cgroup.c linux-2.6.30/security/device_cgroup.c
24268 --- linux-2.6.30.org/security/device_cgroup.c 2009-06-10 05:05:27.000000000 +0200
24269 +++ linux-2.6.30/security/device_cgroup.c 2009-07-21 09:13:29.234192642 +0200
24270 @@ -512,6 +512,7 @@
24274 +EXPORT_SYMBOL(devcgroup_inode_permission);
24276 int devcgroup_inode_mknod(int mode, dev_t dev)
24278 diff -urN linux-2.6.30.org/security/security.c linux-2.6.30/security/security.c
24279 --- linux-2.6.30.org/security/security.c 2009-06-10 05:05:27.000000000 +0200
24280 +++ linux-2.6.30/security/security.c 2009-07-21 09:13:29.234192642 +0200
24281 @@ -389,6 +389,7 @@
24283 return security_ops->path_mkdir(path, dentry, mode);
24285 +EXPORT_SYMBOL(security_path_mkdir);
24287 int security_path_rmdir(struct path *path, struct dentry *dentry)
24289 @@ -396,6 +397,7 @@
24291 return security_ops->path_rmdir(path, dentry);
24293 +EXPORT_SYMBOL(security_path_rmdir);
24295 int security_path_unlink(struct path *path, struct dentry *dentry)
24297 @@ -403,6 +405,7 @@
24299 return security_ops->path_unlink(path, dentry);
24301 +EXPORT_SYMBOL(security_path_unlink);
24303 int security_path_symlink(struct path *path, struct dentry *dentry,
24304 const char *old_name)
24305 @@ -411,6 +414,7 @@
24307 return security_ops->path_symlink(path, dentry, old_name);
24309 +EXPORT_SYMBOL(security_path_symlink);
24311 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
24312 struct dentry *new_dentry)
24313 @@ -419,6 +423,7 @@
24315 return security_ops->path_link(old_dentry, new_dir, new_dentry);
24317 +EXPORT_SYMBOL(security_path_link);
24319 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
24320 struct path *new_dir, struct dentry *new_dentry)
24321 @@ -429,6 +434,7 @@
24322 return security_ops->path_rename(old_dir, old_dentry, new_dir,
24325 +EXPORT_SYMBOL(security_path_rename);
24327 int security_path_truncate(struct path *path, loff_t length,
24328 unsigned int time_attrs)
24329 @@ -437,6 +443,7 @@
24331 return security_ops->path_truncate(path, length, time_attrs);
24333 +EXPORT_SYMBOL(security_path_truncate);
24336 int security_inode_create(struct inode *dir, struct dentry *dentry, int mode)
24337 @@ -508,6 +515,7 @@
24339 return security_ops->inode_readlink(dentry);
24341 +EXPORT_SYMBOL(security_inode_readlink);
24343 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
24345 @@ -522,6 +530,7 @@
24347 return security_ops->inode_permission(inode, mask);
24349 +EXPORT_SYMBOL(security_inode_permission);
24351 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
24353 @@ -622,6 +631,7 @@
24355 return security_ops->file_permission(file, mask);
24357 +EXPORT_SYMBOL(security_file_permission);
24359 int security_file_alloc(struct file *file)