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/kern/vfs_default.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/kern/vfs_default.c')
-rw-r--r-- | sys/kern/vfs_default.c | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index e55156d..cc5603e 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -717,15 +717,7 @@ vfs_stdsync(mp, waitfor, cred, td) */ MNT_ILOCK(mp); loop: - for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); vp != NULL; vp = nvp) { - /* - * 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; - - nvp = TAILQ_NEXT(vp, v_nmntvnodes); + MNT_VNODE_FOREACH(vp, mp, nvp) { VI_LOCK(vp); if (TAILQ_EMPTY(&vp->v_dirtyblkhd)) { |