2 * Copyright (C) 2005-2012 Junjiro R. Okajima
4 * This program, aufs is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * lookup and dentry operations
23 #include <linux/namei.h>
26 static void au_h_nd(struct nameidata *h_nd, struct nameidata *nd)
32 * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
33 * due to whiteout and branch permission.
35 h_nd->flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
36 | LOOKUP_FOLLOW | LOOKUP_EXCL);
38 h_nd->intent.open.file = NULL;
40 memset(h_nd, 0, sizeof(*h_nd));
43 struct au_lkup_one_args {
46 struct dentry *h_parent;
51 struct dentry *au_lkup_one(struct qstr *name, struct dentry *h_parent,
52 struct au_branch *br, struct nameidata *nd)
54 struct dentry *h_dentry;
56 struct nameidata h_nd;
58 if (au_test_fs_null_nd(h_parent->d_sb))
59 return vfsub_lookup_one_len(name->name, h_parent, name->len);
62 h_nd.path.dentry = h_parent;
63 h_nd.path.mnt = br->br_mnt;
65 err = vfsub_name_hash(name->name, &h_nd.last, name->len);
66 h_dentry = ERR_PTR(err);
69 h_dentry = vfsub_lookup_hash(&h_nd);
73 AuTraceErrPtr(h_dentry);
77 static void au_call_lkup_one(void *args)
79 struct au_lkup_one_args *a = args;
80 *a->errp = au_lkup_one(a->name, a->h_parent, a->br, a->nd);
83 #define AuLkup_ALLOW_NEG 1
84 #define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
85 #define au_fset_lkup(flags, name) \
86 do { (flags) |= AuLkup_##name; } while (0)
87 #define au_fclr_lkup(flags, name) \
88 do { (flags) &= ~AuLkup_##name; } while (0)
90 struct au_do_lookup_args {
97 * returns positive/negative dentry, NULL or an error.
98 * NULL means whiteout-ed or not-found.
100 static struct dentry*
101 au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
102 aufs_bindex_t bindex, struct qstr *wh_name,
103 struct au_do_lookup_args *args)
105 struct dentry *h_dentry;
106 struct inode *h_inode, *inode;
107 struct au_branch *br;
109 unsigned char wh_able;
110 const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
113 br = au_sbr(dentry->d_sb, bindex);
114 wh_able = !!au_br_whable(br->br_perm);
116 wh_found = au_wh_test(h_parent, wh_name, br, /*try_sio*/0);
117 h_dentry = ERR_PTR(wh_found);
120 if (unlikely(wh_found < 0))
123 /* We found a whiteout */
124 /* au_set_dbend(dentry, bindex); */
125 au_set_dbwh(dentry, bindex);
127 return NULL; /* success */
130 h_dentry = au_lkup_one(&dentry->d_name, h_parent, br, args->nd);
131 if (IS_ERR(h_dentry))
134 h_inode = h_dentry->d_inode;
139 || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
142 if (au_dbend(dentry) <= bindex)
143 au_set_dbend(dentry, bindex);
144 if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
145 au_set_dbstart(dentry, bindex);
146 au_set_h_dptr(dentry, bindex, h_dentry);
148 inode = dentry->d_inode;
149 if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
150 || (inode && !S_ISDIR(inode->i_mode)))
151 goto out; /* success */
153 mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
154 opq = au_diropq_test(h_dentry, br);
155 mutex_unlock(&h_inode->i_mutex);
157 au_set_dbdiropq(dentry, bindex);
158 else if (unlikely(opq < 0)) {
159 au_set_h_dptr(dentry, bindex, NULL);
160 h_dentry = ERR_PTR(opq);
171 static int au_test_shwh(struct super_block *sb, const struct qstr *name)
173 if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
174 && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
180 * returns the number of lower positive dentries,
181 * otherwise an error.
182 * can be called at unlinking with @type is zero.
184 int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type,
185 struct nameidata *nd)
188 aufs_bindex_t bindex, btail, bdiropq;
191 struct au_do_lookup_args args = {
196 const struct qstr *name = &dentry->d_name;
197 struct dentry *parent;
200 err = au_test_shwh(dentry->d_sb, name);
204 err = au_wh_name_alloc(&whname, name);
208 inode = dentry->d_inode;
209 isdir = !!(inode && S_ISDIR(inode->i_mode));
211 au_fset_lkup(args.flags, ALLOW_NEG);
214 parent = dget_parent(dentry);
215 btail = au_dbtaildir(parent);
216 for (bindex = bstart; bindex <= btail; bindex++) {
217 struct dentry *h_parent, *h_dentry;
218 struct inode *h_inode, *h_dir;
220 h_dentry = au_h_dptr(dentry, bindex);
222 if (h_dentry->d_inode)
228 h_parent = au_h_dptr(parent, bindex);
231 h_dir = h_parent->d_inode;
232 if (!h_dir || !S_ISDIR(h_dir->i_mode))
235 mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
236 h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
238 mutex_unlock(&h_dir->i_mutex);
239 err = PTR_ERR(h_dentry);
240 if (IS_ERR(h_dentry))
242 au_fclr_lkup(args.flags, ALLOW_NEG);
244 if (au_dbwh(dentry) >= 0)
248 h_inode = h_dentry->d_inode;
253 args.type = h_inode->i_mode & S_IFMT;
254 if (args.type != S_IFDIR)
257 /* the type of lower may be different */
258 bdiropq = au_dbdiropq(dentry);
259 if (bdiropq >= 0 && bdiropq <= bindex)
266 au_update_dbstart(dentry);
269 if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
270 && au_dbstart(dentry) < 0)) {
272 AuIOErr("both of real entry and whiteout found, %.*s, err %d\n",
273 AuDLNPair(dentry), err);
283 struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent,
284 struct au_branch *br)
286 struct dentry *dentry;
289 if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
290 dentry = au_lkup_one(name, parent, br, /*nd*/NULL);
292 struct au_lkup_one_args args = {
300 wkq_err = au_wkq_wait(au_call_lkup_one, &args);
301 if (unlikely(wkq_err))
302 dentry = ERR_PTR(wkq_err);
309 * lookup @dentry on @bindex which should be negative.
311 int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex)
314 struct dentry *parent, *h_parent, *h_dentry;
316 parent = dget_parent(dentry);
317 h_parent = au_h_dptr(parent, bindex);
318 h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent,
319 au_sbr(dentry->d_sb, bindex));
320 err = PTR_ERR(h_dentry);
321 if (IS_ERR(h_dentry))
323 if (unlikely(h_dentry->d_inode)) {
325 AuIOErr("%.*s should be negative on b%d.\n",
326 AuDLNPair(h_dentry), bindex);
332 if (bindex < au_dbstart(dentry))
333 au_set_dbstart(dentry, bindex);
334 if (au_dbend(dentry) < bindex)
335 au_set_dbend(dentry, bindex);
336 au_set_h_dptr(dentry, bindex, h_dentry);
343 /* ---------------------------------------------------------------------- */
345 /* subset of struct inode */
348 /* unsigned int i_nlink; */
359 static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
361 ia->i_ino = h_inode->i_ino;
362 /* ia->i_nlink = h_inode->i_nlink; */
363 ia->i_uid = h_inode->i_uid;
364 ia->i_gid = h_inode->i_gid;
365 ia->i_version = h_inode->i_version;
367 ia->i_size = h_inode->i_size;
368 ia->i_blocks = h_inode->i_blocks;
370 ia->i_mode = (h_inode->i_mode & S_IFMT);
373 static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
375 return ia->i_ino != h_inode->i_ino
376 /* || ia->i_nlink != h_inode->i_nlink */
377 || ia->i_uid != h_inode->i_uid
378 || ia->i_gid != h_inode->i_gid
379 || ia->i_version != h_inode->i_version
381 || ia->i_size != h_inode->i_size
382 || ia->i_blocks != h_inode->i_blocks
384 || ia->i_mode != (h_inode->i_mode & S_IFMT);
387 static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
388 struct au_branch *br)
392 struct inode *h_inode;
394 struct super_block *h_sb;
397 memset(&ia, -1, sizeof(ia));
398 h_sb = h_dentry->d_sb;
399 h_inode = h_dentry->d_inode;
401 au_iattr_save(&ia, h_inode);
402 else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
403 /* nfs d_revalidate may return 0 for negative dentry */
404 /* fuse d_revalidate always return 0 for negative dentry */
407 /* main purpose is namei.c:cached_lookup() and d_revalidate */
408 h_d = au_lkup_one(&h_dentry->d_name, h_parent, br, /*nd*/NULL);
414 if (unlikely(h_d != h_dentry
415 || h_d->d_inode != h_inode
416 || (h_inode && au_iattr_test(&ia, h_inode))))
417 err = au_busy_or_stale();
425 int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
426 struct dentry *h_parent, struct au_branch *br)
431 if (udba == AuOpt_UDBA_REVAL
432 && !au_test_fs_remote(h_dentry->d_sb)) {
434 err = (h_dentry->d_parent->d_inode != h_dir);
435 } else if (udba != AuOpt_UDBA_NONE)
436 err = au_h_verify_dentry(h_dentry, h_parent, br);
441 /* ---------------------------------------------------------------------- */
443 static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
446 aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
447 struct au_hdentry tmp, *p, *q;
448 struct au_dinfo *dinfo;
449 struct super_block *sb;
451 DiMustWriteLock(dentry);
454 dinfo = au_di(dentry);
455 bend = dinfo->di_bend;
457 bdiropq = dinfo->di_bdiropq;
458 p = dinfo->di_hdentry + dinfo->di_bstart;
459 for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
463 new_bindex = au_br_index(sb, p->hd_id);
464 if (new_bindex == bindex)
467 if (dinfo->di_bwh == bindex)
469 if (dinfo->di_bdiropq == bindex)
470 bdiropq = new_bindex;
471 if (new_bindex < 0) {
477 /* swap two lower dentries, and loop again */
478 q = dinfo->di_hdentry + new_bindex;
489 if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
492 dinfo->di_bdiropq = -1;
494 && bdiropq <= au_sbend(sb)
495 && au_sbr_whable(sb, bdiropq))
496 dinfo->di_bdiropq = bdiropq;
499 dinfo->di_bstart = -1;
501 bend = au_dbend(parent);
502 p = dinfo->di_hdentry;
503 for (bindex = 0; bindex <= bend; bindex++, p++)
505 dinfo->di_bstart = bindex;
509 if (dinfo->di_bstart >= 0) {
510 p = dinfo->di_hdentry + bend;
511 for (bindex = bend; bindex >= 0; bindex--, p--)
513 dinfo->di_bend = bindex;
522 static void au_do_hide(struct dentry *dentry)
526 inode = dentry->d_inode;
528 if (!S_ISDIR(inode->i_mode)) {
529 if (inode->i_nlink && !d_unhashed(dentry))
533 /* stop next lookup */
534 inode->i_flags |= S_DEAD;
536 smp_mb(); /* necessary? */
541 static int au_hide_children(struct dentry *parent)
543 int err, i, j, ndentry;
544 struct au_dcsub_pages dpages;
545 struct au_dpage *dpage;
546 struct dentry *dentry;
548 err = au_dpages_init(&dpages, GFP_NOFS);
551 err = au_dcsub_pages(&dpages, parent, NULL, NULL);
555 /* in reverse order */
556 for (i = dpages.ndpage - 1; i >= 0; i--) {
557 dpage = dpages.dpages + i;
558 ndentry = dpage->ndentry;
559 for (j = ndentry - 1; j >= 0; j--) {
560 dentry = dpage->dentries[j];
561 if (dentry != parent)
567 au_dpages_free(&dpages);
572 static void au_hide(struct dentry *dentry)
578 inode = dentry->d_inode;
579 if (inode && S_ISDIR(inode->i_mode)) {
580 /* shrink_dcache_parent(dentry); */
581 err = au_hide_children(dentry);
583 AuIOErr("%.*s, failed hiding children, ignored %d\n",
584 AuDLNPair(dentry), err);
590 * By adding a dirty branch, a cached dentry may be affected in various ways.
592 * a dirty branch is added
593 * - on the top of layers
594 * - in the middle of layers
595 * - to the bottom of layers
597 * on the added branch there exists
600 * - a same named entry
602 * * negative --> positive
603 * * positive --> positive
604 * - type is unchanged
607 * * negative --> negative
608 * * positive --> negative (rejected by au_br_del() for non-dir case)
611 static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
612 struct au_dinfo *tmp)
615 aufs_bindex_t bindex, bend;
617 struct dentry *dentry;
621 struct au_hdentry *hd;
622 struct inode *inode, *h_inode;
623 struct dentry *h_dentry;
626 AuDebugOn(dinfo->di_bstart < 0);
627 orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
628 orig_h.inode = orig_h.dentry->d_inode;
631 orig_h.mode = orig_h.inode->i_mode & S_IFMT;
632 memset(&tmp_h, 0, sizeof(tmp_h));
633 if (tmp->di_bstart >= 0) {
634 tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
635 tmp_h.inode = tmp_h.dentry->d_inode;
637 tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
640 inode = dentry->d_inode;
642 AuDbg("nagative originally\n");
648 AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
649 AuDebugOn(dinfo->di_bdiropq != -1);
652 AuDbg("negative --> negative\n");
653 /* should have only one negative lower */
654 if (tmp->di_bstart >= 0
655 && tmp->di_bstart < dinfo->di_bstart) {
656 AuDebugOn(tmp->di_bstart != tmp->di_bend);
657 AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
658 au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
659 au_di_cp(dinfo, tmp);
660 hd = tmp->di_hdentry + tmp->di_bstart;
661 au_set_h_dptr(dentry, tmp->di_bstart,
662 dget(hd->hd_dentry));
664 au_dbg_verify_dinode(dentry);
666 AuDbg("negative --> positive\n");
668 * similar to the behaviour of creating with bypassing
670 * unhash it in order to force an error in the
671 * succeeding create operation.
672 * we should not set S_DEAD here.
675 /* au_di_swap(tmp, dinfo); */
676 au_dbg_verify_dinode(dentry);
679 AuDbg("positive originally\n");
680 /* inode may be NULL */
681 AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
683 AuDbg("positive --> negative\n");
684 /* or bypassing aufs */
686 if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
687 dinfo->di_bwh = tmp->di_bwh;
689 err = au_refresh_hinode_self(inode);
690 au_dbg_verify_dinode(dentry);
691 } else if (orig_h.mode == tmp_h.mode) {
692 AuDbg("positive --> positive, same type\n");
693 if (!S_ISDIR(orig_h.mode)
694 && dinfo->di_bstart > tmp->di_bstart) {
696 * similar to the behaviour of removing and
701 err = au_refresh_hinode_self(inode);
702 au_dbg_verify_dinode(dentry);
704 /* fill empty slots */
705 if (dinfo->di_bstart > tmp->di_bstart)
706 dinfo->di_bstart = tmp->di_bstart;
707 if (dinfo->di_bend < tmp->di_bend)
708 dinfo->di_bend = tmp->di_bend;
709 dinfo->di_bwh = tmp->di_bwh;
710 dinfo->di_bdiropq = tmp->di_bdiropq;
711 hd = tmp->di_hdentry;
712 bend = dinfo->di_bend;
713 for (bindex = tmp->di_bstart; bindex <= bend;
715 if (au_h_dptr(dentry, bindex))
717 h_dentry = hd[bindex].hd_dentry;
720 h_inode = h_dentry->d_inode;
722 AuDebugOn(orig_h.mode
725 au_set_h_dptr(dentry, bindex,
728 err = au_refresh_hinode(inode, dentry);
729 au_dbg_verify_dinode(dentry);
732 AuDbg("positive --> positive, different type\n");
733 /* similar to the behaviour of removing and creating */
736 err = au_refresh_hinode_self(inode);
737 au_dbg_verify_dinode(dentry);
745 int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
749 struct au_dinfo *dinfo, *tmp;
750 struct super_block *sb;
753 DiMustWriteLock(dentry);
754 AuDebugOn(IS_ROOT(dentry));
755 AuDebugOn(!parent->d_inode);
758 inode = dentry->d_inode;
759 sigen = au_sigen(sb);
760 err = au_digen_test(parent, sigen);
764 dinfo = au_di(dentry);
765 err = au_di_realloc(dinfo, au_sbend(sb) + 1);
768 ebrange = au_dbrange_test(dentry);
770 ebrange = au_do_refresh_hdentry(dentry, parent);
772 if (d_unhashed(dentry) || ebrange) {
773 AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
775 err = au_refresh_hinode_self(inode);
776 au_dbg_verify_dinode(dentry);
778 goto out_dgen; /* success */
782 /* temporary dinfo */
785 tmp = au_di_alloc(sb, AuLsc_DI_TMP);
788 au_di_swap(tmp, dinfo);
789 /* returns the number of positive dentries */
791 * if current working dir is removed, it returns an error.
792 * but the dentry is legal.
794 err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0, /*nd*/NULL);
796 au_di_swap(tmp, dinfo);
800 /* compare/refresh by dinfo */
802 err = au_refresh_by_dinfo(dentry, dinfo, tmp);
803 au_dbg_verify_dinode(dentry);
806 au_rw_write_unlock(&tmp->di_rwsem);
812 au_update_digen(dentry);
814 if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
815 AuIOErr("failed refreshing %.*s, %d\n",
816 AuDLNPair(dentry), err);
823 static noinline_for_stack
824 int au_do_h_d_reval(struct dentry *h_dentry, struct nameidata *nd,
825 struct dentry *dentry, aufs_bindex_t bindex)
828 int (*reval)(struct dentry *, struct nameidata *);
831 if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
833 reval = h_dentry->d_op->d_revalidate;
835 AuDbg("b%d\n", bindex);
836 if (au_test_fs_null_nd(h_dentry->d_sb))
837 /* it may return tri-state */
838 valid = reval(h_dentry, NULL);
840 struct nameidata h_nd;
842 struct dentry *parent;
845 parent = nd->path.dentry;
846 locked = (nd && nd->path.dentry != dentry);
848 di_read_lock_parent(parent, AuLock_IR);
849 BUG_ON(bindex > au_dbend(parent));
850 h_nd.path.dentry = au_h_dptr(parent, bindex);
851 BUG_ON(!h_nd.path.dentry);
852 h_nd.path.mnt = au_sbr(parent->d_sb, bindex)->br_mnt;
853 path_get(&h_nd.path);
854 valid = reval(h_dentry, &h_nd);
855 path_put(&h_nd.path);
857 di_read_unlock(parent, AuLock_IR);
860 if (unlikely(valid < 0))
870 /* todo: remove this */
871 static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
872 struct nameidata *nd, int do_udba)
875 umode_t mode, h_mode;
876 aufs_bindex_t bindex, btail, bstart, ibs, ibe;
877 unsigned char plus, unhashed, is_root, h_plus;
878 struct inode *h_inode, *h_cached_inode;
879 struct dentry *h_dentry;
880 struct qstr *name, *h_name;
887 unhashed = !!d_unhashed(dentry);
888 is_root = !!IS_ROOT(dentry);
889 name = &dentry->d_name;
892 * Theoretically, REVAL test should be unnecessary in case of
894 * But {fs,i}notify doesn't fire some necessary events,
895 * IN_ATTRIB for atime/nlink/pageio
896 * IN_DELETE for NFS dentry
897 * Let's do REVAL test too.
899 if (do_udba && inode) {
900 mode = (inode->i_mode & S_IFMT);
901 plus = (inode->i_nlink > 0);
902 ibs = au_ibstart(inode);
903 ibe = au_ibend(inode);
906 bstart = au_dbstart(dentry);
908 if (inode && S_ISDIR(inode->i_mode))
909 btail = au_dbtaildir(dentry);
910 for (bindex = bstart; bindex <= btail; bindex++) {
911 h_dentry = au_h_dptr(dentry, bindex);
915 AuDbg("b%d, %.*s\n", bindex, AuDLNPair(h_dentry));
916 spin_lock(&h_dentry->d_lock);
917 h_name = &h_dentry->d_name;
920 && (unhashed != !!d_unhashed(h_dentry)
921 || name->len != h_name->len
922 || memcmp(name->name, h_name->name, name->len))
924 AuDbg("unhash 0x%x 0x%x, %.*s %.*s\n",
925 unhashed, d_unhashed(h_dentry),
926 AuDLNPair(dentry), AuDLNPair(h_dentry));
927 spin_unlock(&h_dentry->d_lock);
930 spin_unlock(&h_dentry->d_lock);
932 err = au_do_h_d_reval(h_dentry, nd, dentry, bindex);
934 /* do not goto err, to keep the errno */
937 /* todo: plink too? */
942 h_inode = h_dentry->d_inode;
943 if (unlikely(!!inode != !!h_inode))
948 h_cached_inode = h_inode;
950 h_mode = (h_inode->i_mode & S_IFMT);
951 h_plus = (h_inode->i_nlink > 0);
953 if (inode && ibs <= bindex && bindex <= ibe)
954 h_cached_inode = au_h_iptr(inode, bindex);
956 if (unlikely(plus != h_plus
958 || h_cached_inode != h_inode))
970 /* todo: consolidate with do_refresh() and au_reval_for_attr() */
971 static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
974 struct dentry *parent;
976 if (!au_digen_test(dentry, sigen))
979 parent = dget_parent(dentry);
980 di_read_lock_parent(parent, AuLock_IR);
981 AuDebugOn(au_digen_test(parent, sigen));
982 au_dbg_verify_gen(parent, sigen);
983 err = au_refresh_dentry(dentry, parent);
984 di_read_unlock(parent, AuLock_IR);
990 int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
993 struct dentry *d, *parent;
996 if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
997 return simple_reval_dpath(dentry, sigen);
999 /* slow loop, keep it simple and stupid */
1000 /* cf: au_cpup_dirs() */
1003 while (au_digen_test(dentry, sigen)) {
1007 parent = dget_parent(d);
1008 if (!au_digen_test(parent, sigen))
1015 di_write_lock_child2(d);
1017 /* someone might update our dentry while we were sleeping */
1018 if (au_digen_test(d, sigen)) {
1020 * todo: consolidate with simple_reval_dpath(),
1021 * do_refresh() and au_reval_for_attr().
1023 di_read_lock_parent(parent, AuLock_IR);
1024 err = au_refresh_dentry(d, parent);
1025 di_read_unlock(parent, AuLock_IR);
1039 * if valid returns 1, otherwise 0.
1041 static int aufs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
1045 unsigned char do_udba;
1046 struct super_block *sb;
1047 struct inode *inode;
1049 /* todo: support rcu-walk? */
1050 if (nd && (nd->flags & LOOKUP_RCU))
1054 if (unlikely(!au_di(dentry)))
1057 inode = dentry->d_inode;
1058 if (inode && is_bad_inode(inode))
1065 * i_mutex of parent dir may be held,
1066 * but we should not return 'invalid' due to busy.
1068 err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
1069 if (unlikely(err)) {
1074 if (unlikely(au_dbrange_test(dentry))) {
1080 sigen = au_sigen(sb);
1081 if (au_digen_test(dentry, sigen)) {
1082 AuDebugOn(IS_ROOT(dentry));
1083 err = au_reval_dpath(dentry, sigen);
1084 if (unlikely(err)) {
1089 di_downgrade_lock(dentry, AuLock_IR);
1092 if (inode && (IS_DEADDIR(inode) || !inode->i_nlink))
1095 do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
1096 if (do_udba && inode) {
1097 aufs_bindex_t bstart = au_ibstart(inode);
1098 struct inode *h_inode;
1101 h_inode = au_h_iptr(inode, bstart);
1102 if (h_inode && au_test_higen(inode, h_inode))
1107 err = h_d_revalidate(dentry, inode, nd, do_udba);
1108 if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
1110 AuDbg("both of real entry and whiteout found, %.*s, err %d\n",
1111 AuDLNPair(dentry), err);
1116 di_downgrade_lock(dentry, AuLock_IR);
1118 aufs_read_unlock(dentry, AuLock_IR);
1123 AuDbg("%.*s invalid, %d\n", AuDLNPair(dentry), valid);
1129 static void aufs_d_release(struct dentry *dentry)
1131 if (au_di(dentry)) {
1133 au_hn_di_reinit(dentry);
1137 const struct dentry_operations aufs_dop = {
1138 .d_revalidate = aufs_d_revalidate,
1139 .d_release = aufs_d_release