diff options
author | phk <phk@FreeBSD.org> | 2004-07-04 08:52:35 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2004-07-04 08:52:35 +0000 |
commit | 070a613a48a55587e5a08b240d1c6b21a8256e76 (patch) | |
tree | f28045f107d09ceda32c1e5423817652a2166121 /sys/nfsclient/nfs_vfsops.c | |
parent | f02259600de5473e6c6e64dedb982bc901b5394d (diff) | |
download | FreeBSD-src-070a613a48a55587e5a08b240d1c6b21a8256e76.zip FreeBSD-src-070a613a48a55587e5a08b240d1c6b21a8256e76.tar.gz |
When we traverse the vnodes on a mountpoint we need to look out for
our cached 'next vnode' being removed from this mountpoint. If we
find that it was recycled, we restart our traversal from the start
of the list.
Code to do that is in all local disk filesystems (and a few other
places) and looks roughly like this:
MNT_ILOCK(mp);
loop:
for (vp = TAILQ_FIRST(&mp...);
(vp = nvp) != NULL;
nvp = TAILQ_NEXT(vp,...)) {
if (vp->v_mount != mp)
goto loop;
MNT_IUNLOCK(mp);
...
MNT_ILOCK(mp);
}
MNT_IUNLOCK(mp);
The code which takes vnodes off a mountpoint looks like this:
MNT_ILOCK(vp->v_mount);
...
TAILQ_REMOVE(&vp->v_mount->mnt_nvnodelist, vp, v_nmntvnodes);
...
MNT_IUNLOCK(vp->v_mount);
...
vp->v_mount = something;
(Take a moment and try to spot the locking error before you read on.)
On a SMP system, one CPU could have removed nvp from our mountlist
but not yet gotten to assign a new value to vp->v_mount while another
CPU simultaneously get to the top of the traversal loop where it
finds that (vp->v_mount != mp) is not true despite the fact that
the vnode has indeed been removed from our mountpoint.
Fix:
Introduce the macro MNT_VNODE_FOREACH() to traverse the list of
vnodes on a mountpoint while taking into account that vnodes may
be removed from the list as we go. This saves approx 65 lines of
duplicated code.
Split the insmntque() which potentially moves a vnode from one mount
point to another into delmntque() and insmntque() which does just
what the names say.
Fix delmntque() to set vp->v_mount to NULL while holding the
mountpoint lock.
Diffstat (limited to 'sys/nfsclient/nfs_vfsops.c')
-rw-r--r-- | sys/nfsclient/nfs_vfsops.c | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/sys/nfsclient/nfs_vfsops.c b/sys/nfsclient/nfs_vfsops.c index 36941c0..411faad 100644 --- a/sys/nfsclient/nfs_vfsops.c +++ b/sys/nfsclient/nfs_vfsops.c @@ -930,7 +930,7 @@ nfs_root(struct mount *mp, struct vnode **vpp) static int nfs_sync(struct mount *mp, int waitfor, struct ucred *cred, struct thread *td) { - struct vnode *vp, *vnp; + struct vnode *vp, *nvp; int error, allerror = 0; /* @@ -938,16 +938,7 @@ nfs_sync(struct mount *mp, int waitfor, struct ucred *cred, struct thread *td) */ MNT_ILOCK(mp); loop: - for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); - vp != NULL; - vp = vnp) { - /* - * If the vnode that we are about to sync is no longer - * associated with this mount point, start over. - */ - if (vp->v_mount != mp) - goto loop; - vnp = TAILQ_NEXT(vp, v_nmntvnodes); + MNT_VNODE_FOREACH(vp, mp, nvp) { VI_LOCK(vp); MNT_IUNLOCK(mp); if (VOP_ISLOCKED(vp, NULL) || TAILQ_EMPTY(&vp->v_dirtyblkhd) || |