2 * Copyright (C) 2005-2017 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, see <http://www.gnu.org/licenses/>.
19 * lookup and dentry operations
22 #include <linux/namei.h>
25 struct au_do_lookup_args
{
31 * returns positive/negative dentry, NULL or an error.
32 * NULL means whiteout-ed or not-found.
35 au_do_lookup(struct dentry
*h_parent
, struct dentry
*dentry
,
36 aufs_bindex_t bindex
, struct qstr
*wh_name
,
37 struct au_do_lookup_args
*args
)
39 struct dentry
*h_dentry
;
40 struct inode
*h_inode
;
43 unsigned char wh_able
;
44 const unsigned char allow_neg
= !!au_ftest_lkup(args
->flags
, ALLOW_NEG
);
45 const unsigned char ignore_perm
= !!au_ftest_lkup(args
->flags
,
49 br
= au_sbr(dentry
->d_sb
, bindex
);
50 wh_able
= !!au_br_whable(br
->br_perm
);
52 wh_found
= au_wh_test(h_parent
, wh_name
, ignore_perm
);
53 h_dentry
= ERR_PTR(wh_found
);
56 if (unlikely(wh_found
< 0))
59 /* We found a whiteout */
60 /* au_set_dbbot(dentry, bindex); */
61 au_set_dbwh(dentry
, bindex
);
63 return NULL
; /* success */
67 h_dentry
= vfsub_lkup_one(&dentry
->d_name
, h_parent
);
69 h_dentry
= au_sio_lkup_one(&dentry
->d_name
, h_parent
);
70 if (IS_ERR(h_dentry
)) {
71 if (PTR_ERR(h_dentry
) == -ENAMETOOLONG
77 h_inode
= d_inode(h_dentry
);
78 if (d_is_negative(h_dentry
)) {
82 || (args
->type
&& args
->type
!= (h_inode
->i_mode
& S_IFMT
)))
85 if (au_dbbot(dentry
) <= bindex
)
86 au_set_dbbot(dentry
, bindex
);
87 if (au_dbtop(dentry
) < 0 || bindex
< au_dbtop(dentry
))
88 au_set_dbtop(dentry
, bindex
);
89 au_set_h_dptr(dentry
, bindex
, h_dentry
);
91 if (!d_is_dir(h_dentry
)
93 || (d_really_is_positive(dentry
) && !d_is_dir(dentry
)))
94 goto out
; /* success */
96 inode_lock_nested(h_inode
, AuLsc_I_CHILD
);
97 opq
= au_diropq_test(h_dentry
);
98 inode_unlock(h_inode
);
100 au_set_dbdiropq(dentry
, bindex
);
101 else if (unlikely(opq
< 0)) {
102 au_set_h_dptr(dentry
, bindex
, NULL
);
103 h_dentry
= ERR_PTR(opq
);
114 static int au_test_shwh(struct super_block
*sb
, const struct qstr
*name
)
116 if (unlikely(!au_opt_test(au_mntflags(sb
), SHWH
)
117 && !strncmp(name
->name
, AUFS_WH_PFX
, AUFS_WH_PFX_LEN
)))
123 * returns the number of lower positive dentries,
124 * otherwise an error.
125 * can be called at unlinking with @type is zero.
127 int au_lkup_dentry(struct dentry
*dentry
, aufs_bindex_t btop
,
131 aufs_bindex_t bindex
, btail
, bdiropq
;
132 unsigned char isdir
, dirperm1
;
134 struct au_do_lookup_args args
= {
137 const struct qstr
*name
= &dentry
->d_name
;
138 struct dentry
*parent
;
139 struct super_block
*sb
;
142 err
= au_test_shwh(sb
, name
);
146 err
= au_wh_name_alloc(&whname
, name
);
150 isdir
= !!d_is_dir(dentry
);
151 dirperm1
= !!au_opt_test(au_mntflags(sb
), DIRPERM1
);
154 parent
= dget_parent(dentry
);
155 btail
= au_dbtaildir(parent
);
156 for (bindex
= btop
; bindex
<= btail
; bindex
++) {
157 struct dentry
*h_parent
, *h_dentry
;
158 struct inode
*h_inode
, *h_dir
;
160 h_dentry
= au_h_dptr(dentry
, bindex
);
162 if (d_is_positive(h_dentry
))
166 h_parent
= au_h_dptr(parent
, bindex
);
167 if (!h_parent
|| !d_is_dir(h_parent
))
170 h_dir
= d_inode(h_parent
);
171 inode_lock_nested(h_dir
, AuLsc_I_PARENT
);
172 h_dentry
= au_do_lookup(h_parent
, dentry
, bindex
, &whname
,
175 err
= PTR_ERR(h_dentry
);
176 if (IS_ERR(h_dentry
))
179 au_fclr_lkup(args
.flags
, ALLOW_NEG
);
181 au_fset_lkup(args
.flags
, IGNORE_PERM
);
183 if (au_dbwh(dentry
) == bindex
)
187 if (d_is_negative(h_dentry
))
189 h_inode
= d_inode(h_dentry
);
192 args
.type
= h_inode
->i_mode
& S_IFMT
;
193 if (args
.type
!= S_IFDIR
)
196 /* the type of lower may be different */
197 bdiropq
= au_dbdiropq(dentry
);
198 if (bdiropq
>= 0 && bdiropq
<= bindex
)
205 au_update_dbtop(dentry
);
208 if (unlikely(!au_opt_test(au_mntflags(sb
), UDBA_NONE
)
209 && au_dbtop(dentry
) < 0)) {
211 AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
222 struct dentry
*au_sio_lkup_one(struct qstr
*name
, struct dentry
*parent
)
224 struct dentry
*dentry
;
227 if (!au_test_h_perm_sio(d_inode(parent
), MAY_EXEC
))
228 dentry
= vfsub_lkup_one(name
, parent
);
230 struct vfsub_lkup_one_args args
= {
236 wkq_err
= au_wkq_wait(vfsub_call_lkup_one
, &args
);
237 if (unlikely(wkq_err
))
238 dentry
= ERR_PTR(wkq_err
);
245 * lookup @dentry on @bindex which should be negative.
247 int au_lkup_neg(struct dentry
*dentry
, aufs_bindex_t bindex
, int wh
)
250 struct dentry
*parent
, *h_parent
, *h_dentry
;
251 struct au_branch
*br
;
253 parent
= dget_parent(dentry
);
254 h_parent
= au_h_dptr(parent
, bindex
);
255 br
= au_sbr(dentry
->d_sb
, bindex
);
257 h_dentry
= au_whtmp_lkup(h_parent
, br
, &dentry
->d_name
);
259 h_dentry
= au_sio_lkup_one(&dentry
->d_name
, h_parent
);
260 err
= PTR_ERR(h_dentry
);
261 if (IS_ERR(h_dentry
))
263 if (unlikely(d_is_positive(h_dentry
))) {
265 AuIOErr("%pd should be negative on b%d.\n", h_dentry
, bindex
);
271 if (bindex
< au_dbtop(dentry
))
272 au_set_dbtop(dentry
, bindex
);
273 if (au_dbbot(dentry
) < bindex
)
274 au_set_dbbot(dentry
, bindex
);
275 au_set_h_dptr(dentry
, bindex
, h_dentry
);
282 /* ---------------------------------------------------------------------- */
284 /* subset of struct inode */
287 /* unsigned int i_nlink; */
298 static void au_iattr_save(struct au_iattr
*ia
, struct inode
*h_inode
)
300 ia
->i_ino
= h_inode
->i_ino
;
301 /* ia->i_nlink = h_inode->i_nlink; */
302 ia
->i_uid
= h_inode
->i_uid
;
303 ia
->i_gid
= h_inode
->i_gid
;
304 ia
->i_version
= h_inode
->i_version
;
306 ia->i_size = h_inode->i_size;
307 ia->i_blocks = h_inode->i_blocks;
309 ia
->i_mode
= (h_inode
->i_mode
& S_IFMT
);
312 static int au_iattr_test(struct au_iattr
*ia
, struct inode
*h_inode
)
314 return ia
->i_ino
!= h_inode
->i_ino
315 /* || ia->i_nlink != h_inode->i_nlink */
316 || !uid_eq(ia
->i_uid
, h_inode
->i_uid
)
317 || !gid_eq(ia
->i_gid
, h_inode
->i_gid
)
318 || ia
->i_version
!= h_inode
->i_version
320 || ia->i_size != h_inode->i_size
321 || ia->i_blocks != h_inode->i_blocks
323 || ia
->i_mode
!= (h_inode
->i_mode
& S_IFMT
);
326 static int au_h_verify_dentry(struct dentry
*h_dentry
, struct dentry
*h_parent
,
327 struct au_branch
*br
)
331 struct inode
*h_inode
;
333 struct super_block
*h_sb
;
336 memset(&ia
, -1, sizeof(ia
));
337 h_sb
= h_dentry
->d_sb
;
339 if (d_is_positive(h_dentry
)) {
340 h_inode
= d_inode(h_dentry
);
341 au_iattr_save(&ia
, h_inode
);
342 } else if (au_test_nfs(h_sb
) || au_test_fuse(h_sb
))
343 /* nfs d_revalidate may return 0 for negative dentry */
344 /* fuse d_revalidate always return 0 for negative dentry */
347 /* main purpose is namei.c:cached_lookup() and d_revalidate */
348 h_d
= vfsub_lkup_one(&h_dentry
->d_name
, h_parent
);
354 if (unlikely(h_d
!= h_dentry
355 || d_inode(h_d
) != h_inode
356 || (h_inode
&& au_iattr_test(&ia
, h_inode
))))
357 err
= au_busy_or_stale();
365 int au_h_verify(struct dentry
*h_dentry
, unsigned int udba
, struct inode
*h_dir
,
366 struct dentry
*h_parent
, struct au_branch
*br
)
371 if (udba
== AuOpt_UDBA_REVAL
372 && !au_test_fs_remote(h_dentry
->d_sb
)) {
374 err
= (d_inode(h_dentry
->d_parent
) != h_dir
);
375 } else if (udba
!= AuOpt_UDBA_NONE
)
376 err
= au_h_verify_dentry(h_dentry
, h_parent
, br
);
381 /* ---------------------------------------------------------------------- */
383 static int au_do_refresh_hdentry(struct dentry
*dentry
, struct dentry
*parent
)
386 aufs_bindex_t new_bindex
, bindex
, bbot
, bwh
, bdiropq
;
387 struct au_hdentry tmp
, *p
, *q
;
388 struct au_dinfo
*dinfo
;
389 struct super_block
*sb
;
391 DiMustWriteLock(dentry
);
394 dinfo
= au_di(dentry
);
395 bbot
= dinfo
->di_bbot
;
397 bdiropq
= dinfo
->di_bdiropq
;
398 bindex
= dinfo
->di_btop
;
399 p
= au_hdentry(dinfo
, bindex
);
400 for (; bindex
<= bbot
; bindex
++, p
++) {
404 new_bindex
= au_br_index(sb
, p
->hd_id
);
405 if (new_bindex
== bindex
)
408 if (dinfo
->di_bwh
== bindex
)
410 if (dinfo
->di_bdiropq
== bindex
)
411 bdiropq
= new_bindex
;
412 if (new_bindex
< 0) {
418 /* swap two lower dentries, and loop again */
419 q
= au_hdentry(dinfo
, new_bindex
);
430 if (bwh
>= 0 && bwh
<= au_sbbot(sb
) && au_sbr_whable(sb
, bwh
))
433 dinfo
->di_bdiropq
= -1;
435 && bdiropq
<= au_sbbot(sb
)
436 && au_sbr_whable(sb
, bdiropq
))
437 dinfo
->di_bdiropq
= bdiropq
;
442 bbot
= au_dbbot(parent
);
444 p
= au_hdentry(dinfo
, bindex
);
445 for (; bindex
<= bbot
; bindex
++, p
++)
447 dinfo
->di_btop
= bindex
;
451 if (dinfo
->di_btop
>= 0) {
453 p
= au_hdentry(dinfo
, bindex
);
454 for (; bindex
>= 0; bindex
--, p
--)
456 dinfo
->di_bbot
= bindex
;
465 static void au_do_hide(struct dentry
*dentry
)
469 if (d_really_is_positive(dentry
)) {
470 inode
= d_inode(dentry
);
471 if (!d_is_dir(dentry
)) {
472 if (inode
->i_nlink
&& !d_unhashed(dentry
))
476 /* stop next lookup */
477 inode
->i_flags
|= S_DEAD
;
479 smp_mb(); /* necessary? */
484 static int au_hide_children(struct dentry
*parent
)
486 int err
, i
, j
, ndentry
;
487 struct au_dcsub_pages dpages
;
488 struct au_dpage
*dpage
;
489 struct dentry
*dentry
;
491 err
= au_dpages_init(&dpages
, GFP_NOFS
);
494 err
= au_dcsub_pages(&dpages
, parent
, NULL
, NULL
);
498 /* in reverse order */
499 for (i
= dpages
.ndpage
- 1; i
>= 0; i
--) {
500 dpage
= dpages
.dpages
+ i
;
501 ndentry
= dpage
->ndentry
;
502 for (j
= ndentry
- 1; j
>= 0; j
--) {
503 dentry
= dpage
->dentries
[j
];
504 if (dentry
!= parent
)
510 au_dpages_free(&dpages
);
515 static void au_hide(struct dentry
*dentry
)
520 if (d_is_dir(dentry
)) {
521 /* shrink_dcache_parent(dentry); */
522 err
= au_hide_children(dentry
);
524 AuIOErr("%pd, failed hiding children, ignored %d\n",
531 * By adding a dirty branch, a cached dentry may be affected in various ways.
533 * a dirty branch is added
534 * - on the top of layers
535 * - in the middle of layers
536 * - to the bottom of layers
538 * on the added branch there exists
541 * - a same named entry
543 * * negative --> positive
544 * * positive --> positive
545 * - type is unchanged
548 * * negative --> negative
549 * * positive --> negative (rejected by au_br_del() for non-dir case)
552 static int au_refresh_by_dinfo(struct dentry
*dentry
, struct au_dinfo
*dinfo
,
553 struct au_dinfo
*tmp
)
556 aufs_bindex_t bindex
, bbot
;
558 struct dentry
*dentry
;
564 struct au_hdentry
*hd
;
565 struct inode
*inode
, *h_inode
;
566 struct dentry
*h_dentry
;
569 AuDebugOn(dinfo
->di_btop
< 0);
571 orig_h
.dentry
= au_hdentry(dinfo
, dinfo
->di_btop
)->hd_dentry
;
573 if (d_is_positive(orig_h
.dentry
)) {
574 orig_h
.inode
= d_inode(orig_h
.dentry
);
575 orig_h
.mode
= orig_h
.inode
->i_mode
& S_IFMT
;
577 if (tmp
->di_btop
>= 0) {
578 tmp_h
.dentry
= au_hdentry(tmp
, tmp
->di_btop
)->hd_dentry
;
579 if (d_is_positive(tmp_h
.dentry
)) {
580 tmp_h
.inode
= d_inode(tmp_h
.dentry
);
581 tmp_h
.mode
= tmp_h
.inode
->i_mode
& S_IFMT
;
586 if (d_really_is_positive(dentry
))
587 inode
= d_inode(dentry
);
589 AuDbg("nagative originally\n");
595 AuDebugOn(dinfo
->di_btop
!= dinfo
->di_bbot
);
596 AuDebugOn(dinfo
->di_bdiropq
!= -1);
599 AuDbg("negative --> negative\n");
600 /* should have only one negative lower */
601 if (tmp
->di_btop
>= 0
602 && tmp
->di_btop
< dinfo
->di_btop
) {
603 AuDebugOn(tmp
->di_btop
!= tmp
->di_bbot
);
604 AuDebugOn(dinfo
->di_btop
!= dinfo
->di_bbot
);
605 au_set_h_dptr(dentry
, dinfo
->di_btop
, NULL
);
606 au_di_cp(dinfo
, tmp
);
607 hd
= au_hdentry(tmp
, tmp
->di_btop
);
608 au_set_h_dptr(dentry
, tmp
->di_btop
,
609 dget(hd
->hd_dentry
));
611 au_dbg_verify_dinode(dentry
);
613 AuDbg("negative --> positive\n");
615 * similar to the behaviour of creating with bypassing
617 * unhash it in order to force an error in the
618 * succeeding create operation.
619 * we should not set S_DEAD here.
622 /* au_di_swap(tmp, dinfo); */
623 au_dbg_verify_dinode(dentry
);
626 AuDbg("positive originally\n");
627 /* inode may be NULL */
628 AuDebugOn(inode
&& (inode
->i_mode
& S_IFMT
) != orig_h
.mode
);
630 AuDbg("positive --> negative\n");
631 /* or bypassing aufs */
633 if (tmp
->di_bwh
>= 0 && tmp
->di_bwh
<= dinfo
->di_btop
)
634 dinfo
->di_bwh
= tmp
->di_bwh
;
636 err
= au_refresh_hinode_self(inode
);
637 au_dbg_verify_dinode(dentry
);
638 } else if (orig_h
.mode
== tmp_h
.mode
) {
639 AuDbg("positive --> positive, same type\n");
640 if (!S_ISDIR(orig_h
.mode
)
641 && dinfo
->di_btop
> tmp
->di_btop
) {
643 * similar to the behaviour of removing and
648 err
= au_refresh_hinode_self(inode
);
649 au_dbg_verify_dinode(dentry
);
651 /* fill empty slots */
652 if (dinfo
->di_btop
> tmp
->di_btop
)
653 dinfo
->di_btop
= tmp
->di_btop
;
654 if (dinfo
->di_bbot
< tmp
->di_bbot
)
655 dinfo
->di_bbot
= tmp
->di_bbot
;
656 dinfo
->di_bwh
= tmp
->di_bwh
;
657 dinfo
->di_bdiropq
= tmp
->di_bdiropq
;
658 bbot
= dinfo
->di_bbot
;
659 bindex
= tmp
->di_btop
;
660 hd
= au_hdentry(tmp
, bindex
);
661 for (; bindex
<= bbot
; bindex
++, hd
++) {
662 if (au_h_dptr(dentry
, bindex
))
664 h_dentry
= hd
->hd_dentry
;
667 AuDebugOn(d_is_negative(h_dentry
));
668 h_inode
= d_inode(h_dentry
);
669 AuDebugOn(orig_h
.mode
672 au_set_h_dptr(dentry
, bindex
,
676 err
= au_refresh_hinode(inode
, dentry
);
677 au_dbg_verify_dinode(dentry
);
680 AuDbg("positive --> positive, different type\n");
681 /* similar to the behaviour of removing and creating */
684 err
= au_refresh_hinode_self(inode
);
685 au_dbg_verify_dinode(dentry
);
693 void au_refresh_dop(struct dentry
*dentry
, int force_reval
)
695 const struct dentry_operations
*dop
696 = force_reval
? &aufs_dop
: dentry
->d_sb
->s_d_op
;
697 static const unsigned int mask
698 = DCACHE_OP_REVALIDATE
| DCACHE_OP_WEAK_REVALIDATE
;
700 BUILD_BUG_ON(sizeof(mask
) != sizeof(dentry
->d_flags
));
702 if (dentry
->d_op
== dop
)
705 AuDbg("%pd\n", dentry
);
706 spin_lock(&dentry
->d_lock
);
707 if (dop
== &aufs_dop
)
708 dentry
->d_flags
|= mask
;
710 dentry
->d_flags
&= ~mask
;
712 spin_unlock(&dentry
->d_lock
);
715 int au_refresh_dentry(struct dentry
*dentry
, struct dentry
*parent
)
717 int err
, ebrange
, nbr
;
719 struct au_dinfo
*dinfo
, *tmp
;
720 struct super_block
*sb
;
723 DiMustWriteLock(dentry
);
724 AuDebugOn(IS_ROOT(dentry
));
725 AuDebugOn(d_really_is_negative(parent
));
728 sigen
= au_sigen(sb
);
729 err
= au_digen_test(parent
, sigen
);
733 nbr
= au_sbbot(sb
) + 1;
734 dinfo
= au_di(dentry
);
735 err
= au_di_realloc(dinfo
, nbr
, /*may_shrink*/0);
738 ebrange
= au_dbrange_test(dentry
);
740 ebrange
= au_do_refresh_hdentry(dentry
, parent
);
742 if (d_unhashed(dentry
) || ebrange
/* || dinfo->di_tmpfile */) {
743 AuDebugOn(au_dbtop(dentry
) < 0 && au_dbbot(dentry
) >= 0);
744 if (d_really_is_positive(dentry
)) {
745 inode
= d_inode(dentry
);
746 err
= au_refresh_hinode_self(inode
);
748 au_dbg_verify_dinode(dentry
);
750 goto out_dgen
; /* success */
754 /* temporary dinfo */
757 tmp
= au_di_alloc(sb
, AuLsc_DI_TMP
);
760 au_di_swap(tmp
, dinfo
);
761 /* returns the number of positive dentries */
763 * if current working dir is removed, it returns an error.
764 * but the dentry is legal.
766 err
= au_lkup_dentry(dentry
, /*btop*/0, AuLkup_ALLOW_NEG
);
768 au_di_swap(tmp
, dinfo
);
772 /* compare/refresh by dinfo */
774 err
= au_refresh_by_dinfo(dentry
, dinfo
, tmp
);
775 au_dbg_verify_dinode(dentry
);
778 au_di_realloc(dinfo
, nbr
, /*may_shrink*/1); /* harmless if err */
779 au_rw_write_unlock(&tmp
->di_rwsem
);
785 au_update_digen(dentry
);
787 if (unlikely(err
&& !(dentry
->d_flags
& DCACHE_NFSFS_RENAMED
))) {
788 AuIOErr("failed refreshing %pd, %d\n", dentry
, err
);
795 static int au_do_h_d_reval(struct dentry
*h_dentry
, unsigned int flags
,
796 struct dentry
*dentry
, aufs_bindex_t bindex
)
801 if (!(h_dentry
->d_flags
& DCACHE_OP_REVALIDATE
))
804 AuDbg("b%d\n", bindex
);
806 * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
807 * due to whiteout and branch permission.
809 flags
&= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN
| LOOKUP_CREATE
810 | LOOKUP_FOLLOW
| LOOKUP_EXCL
);
811 /* it may return tri-state */
812 valid
= h_dentry
->d_op
->d_revalidate(h_dentry
, flags
);
814 if (unlikely(valid
< 0))
824 /* todo: remove this */
825 static int h_d_revalidate(struct dentry
*dentry
, struct inode
*inode
,
826 unsigned int flags
, int do_udba
)
829 umode_t mode
, h_mode
;
830 aufs_bindex_t bindex
, btail
, btop
, ibs
, ibe
;
831 unsigned char plus
, unhashed
, is_root
, h_plus
, h_nfs
, tmpfile
;
832 struct inode
*h_inode
, *h_cached_inode
;
833 struct dentry
*h_dentry
;
834 struct qstr
*name
, *h_name
;
841 unhashed
= !!d_unhashed(dentry
);
842 is_root
= !!IS_ROOT(dentry
);
843 name
= &dentry
->d_name
;
844 tmpfile
= au_di(dentry
)->di_tmpfile
;
847 * Theoretically, REVAL test should be unnecessary in case of
849 * But {fs,i}notify doesn't fire some necessary events,
850 * IN_ATTRIB for atime/nlink/pageio
851 * Let's do REVAL test too.
853 if (do_udba
&& inode
) {
854 mode
= (inode
->i_mode
& S_IFMT
);
855 plus
= (inode
->i_nlink
> 0);
856 ibs
= au_ibtop(inode
);
857 ibe
= au_ibbot(inode
);
860 btop
= au_dbtop(dentry
);
862 if (inode
&& S_ISDIR(inode
->i_mode
))
863 btail
= au_dbtaildir(dentry
);
864 for (bindex
= btop
; bindex
<= btail
; bindex
++) {
865 h_dentry
= au_h_dptr(dentry
, bindex
);
869 AuDbg("b%d, %pd\n", bindex
, h_dentry
);
870 h_nfs
= !!au_test_nfs(h_dentry
->d_sb
);
871 spin_lock(&h_dentry
->d_lock
);
872 h_name
= &h_dentry
->d_name
;
876 && (unhashed
!= !!d_unhashed(h_dentry
)
878 && !au_qstreq(name
, h_name
))
881 && !(flags
& LOOKUP_OPEN
)
882 && (h_dentry
->d_flags
883 & DCACHE_NFSFS_RENAMED
)))
887 h_unhashed
= d_unhashed(h_dentry
);
888 spin_unlock(&h_dentry
->d_lock
);
889 AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
890 unhashed
, h_unhashed
, dentry
, h_dentry
);
893 spin_unlock(&h_dentry
->d_lock
);
895 err
= au_do_h_d_reval(h_dentry
, flags
, dentry
, bindex
);
897 /* do not goto err, to keep the errno */
900 /* todo: plink too? */
905 if (unlikely(!!inode
!= d_is_positive(h_dentry
)))
909 if (d_is_positive(h_dentry
))
910 h_inode
= d_inode(h_dentry
);
913 h_cached_inode
= h_inode
;
915 h_mode
= (h_inode
->i_mode
& S_IFMT
);
916 h_plus
= (h_inode
->i_nlink
> 0);
918 if (inode
&& ibs
<= bindex
&& bindex
<= ibe
)
919 h_cached_inode
= au_h_iptr(inode
, bindex
);
922 if (unlikely(plus
!= h_plus
&& !tmpfile
))
925 if (unlikely(!(h_dentry
->d_flags
& DCACHE_NFSFS_RENAMED
)
927 && !IS_ROOT(h_dentry
)
928 && unhashed
!= d_unhashed(h_dentry
)))
931 if (unlikely(mode
!= h_mode
932 || h_cached_inode
!= h_inode
))
945 /* todo: consolidate with do_refresh() and au_reval_for_attr() */
946 static int simple_reval_dpath(struct dentry
*dentry
, unsigned int sigen
)
949 struct dentry
*parent
;
951 if (!au_digen_test(dentry
, sigen
))
954 parent
= dget_parent(dentry
);
955 di_read_lock_parent(parent
, AuLock_IR
);
956 AuDebugOn(au_digen_test(parent
, sigen
));
957 au_dbg_verify_gen(parent
, sigen
);
958 err
= au_refresh_dentry(dentry
, parent
);
959 di_read_unlock(parent
, AuLock_IR
);
965 int au_reval_dpath(struct dentry
*dentry
, unsigned int sigen
)
968 struct dentry
*d
, *parent
;
970 if (!au_ftest_si(au_sbi(dentry
->d_sb
), FAILED_REFRESH_DIR
))
971 return simple_reval_dpath(dentry
, sigen
);
973 /* slow loop, keep it simple and stupid */
974 /* cf: au_cpup_dirs() */
977 while (au_digen_test(dentry
, sigen
)) {
981 parent
= dget_parent(d
);
982 if (!au_digen_test(parent
, sigen
))
988 di_write_lock_child2(d
);
990 /* someone might update our dentry while we were sleeping */
991 if (au_digen_test(d
, sigen
)) {
993 * todo: consolidate with simple_reval_dpath(),
994 * do_refresh() and au_reval_for_attr().
996 di_read_lock_parent(parent
, AuLock_IR
);
997 err
= au_refresh_dentry(d
, parent
);
998 di_read_unlock(parent
, AuLock_IR
);
1012 * if valid returns 1, otherwise 0.
1014 static int aufs_d_revalidate(struct dentry
*dentry
, unsigned int flags
)
1018 unsigned char do_udba
;
1019 struct super_block
*sb
;
1020 struct inode
*inode
;
1022 /* todo: support rcu-walk? */
1023 if (flags
& LOOKUP_RCU
)
1027 if (unlikely(!au_di(dentry
)))
1034 * i_mutex of parent dir may be held,
1035 * but we should not return 'invalid' due to busy.
1037 err
= aufs_read_lock(dentry
, AuLock_FLUSH
| AuLock_DW
| AuLock_NOPLM
);
1038 if (unlikely(err
)) {
1044 if (d_really_is_positive(dentry
))
1045 inode
= d_inode(dentry
);
1046 if (unlikely(inode
&& au_is_bad_inode(inode
))) {
1051 if (unlikely(au_dbrange_test(dentry
))) {
1057 sigen
= au_sigen(sb
);
1058 if (au_digen_test(dentry
, sigen
)) {
1059 AuDebugOn(IS_ROOT(dentry
));
1060 err
= au_reval_dpath(dentry
, sigen
);
1061 if (unlikely(err
)) {
1066 di_downgrade_lock(dentry
, AuLock_IR
);
1069 if (!(flags
& (LOOKUP_OPEN
| LOOKUP_EMPTY
))
1071 && !(inode
->i_state
&& I_LINKABLE
)
1072 && (IS_DEADDIR(inode
) || !inode
->i_nlink
)) {
1077 do_udba
= !au_opt_test(au_mntflags(sb
), UDBA_NONE
);
1078 if (do_udba
&& inode
) {
1079 aufs_bindex_t btop
= au_ibtop(inode
);
1080 struct inode
*h_inode
;
1083 h_inode
= au_h_iptr(inode
, btop
);
1084 if (h_inode
&& au_test_higen(inode
, h_inode
)) {
1091 err
= h_d_revalidate(dentry
, inode
, flags
, do_udba
);
1092 if (unlikely(!err
&& do_udba
&& au_dbtop(dentry
) < 0)) {
1094 AuDbg("both of real entry and whiteout found, %p, err %d\n",
1100 di_downgrade_lock(dentry
, AuLock_IR
);
1102 aufs_read_unlock(dentry
, AuLock_IR
);
1107 AuDbg("%pd invalid, %d\n", dentry
, valid
);
1113 static void aufs_d_release(struct dentry
*dentry
)
1115 if (au_di(dentry
)) {
1117 au_hn_di_reinit(dentry
);
1121 const struct dentry_operations aufs_dop
= {
1122 .d_revalidate
= aufs_d_revalidate
,
1123 .d_weak_revalidate
= aufs_d_revalidate
,
1124 .d_release
= aufs_d_release
1127 /* aufs_dop without d_revalidate */
1128 const struct dentry_operations aufs_dop_noreval
= {
1129 .d_release
= aufs_d_release