From b124f6c510c48e1ce8a71ea17a354f49c71fc9a0 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 14 Dec 2004 08:23:18 +0000 Subject: [PATCH] Move the checkdirs() function from vfs_mount.c to kern_descrip.c and call it mountcheckdirs(). --- sys/kern/kern_descrip.c | 48 +++++++++++++++++++++++++++++++++++ sys/kern/vfs_mount.c | 55 +++-------------------------------------- sys/sys/filedesc.h | 1 + 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 754a3cbe2974..28afe115f5ad 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -2256,6 +2256,54 @@ dupfdopen(struct thread *td, struct filedesc *fdp, int indx, int dfd, int mode, /* NOTREACHED */ } +/* + * Scan all active processes to see if any of them have a current + * or root directory of `olddp'. If so, replace them with the new + * mount point. + */ +void +mountcheckdirs(olddp, newdp) + struct vnode *olddp, *newdp; +{ + struct filedesc *fdp; + struct proc *p; + int nrele; + + if (vrefcnt(olddp) == 1) + return; + sx_slock(&allproc_lock); + LIST_FOREACH(p, &allproc, p_list) { + mtx_lock(&fdesc_mtx); + fdp = p->p_fd; + if (fdp == NULL) { + mtx_unlock(&fdesc_mtx); + continue; + } + nrele = 0; + FILEDESC_LOCK_FAST(fdp); + if (fdp->fd_cdir == olddp) { + vref(newdp); + fdp->fd_cdir = newdp; + nrele++; + } + if (fdp->fd_rdir == olddp) { + vref(newdp); + fdp->fd_rdir = newdp; + nrele++; + } + FILEDESC_UNLOCK_FAST(fdp); + mtx_unlock(&fdesc_mtx); + while (nrele--) + vrele(olddp); + } + sx_sunlock(&allproc_lock); + if (rootvnode == olddp) { + vrele(rootvnode); + vref(newdp); + rootvnode = newdp; + } +} + struct filedesc_to_leader * filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, struct proc *leader) { diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index acb44c886245..edd155516038 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -73,7 +73,6 @@ __FBSDID("$FreeBSD$"); #define ROOTNAME "root_device" #define VFS_MOUNTARG_SIZE_MAX (1024 * 64) -static void checkdirs(struct vnode *olddp, struct vnode *newdp); static void gets(char *cp); static int vfs_domount(struct thread *td, const char *fstype, char *fspath, int fsflags, void *fsdata); @@ -784,7 +783,7 @@ vfs_domount( vfs_event_signal(NULL, VQ_MOUNT, 0); if (VFS_ROOT(mp, &newdp, td)) panic("mount: lost mount"); - checkdirs(vp, newdp); + mountcheckdirs(vp, newdp); vput(newdp); VOP_UNLOCK(vp, 0, td); if ((mp->mnt_flag & MNT_RDONLY) == 0) @@ -802,54 +801,6 @@ vfs_domount( return (error); } -/* - * Scan all active processes to see if any of them have a current - * or root directory of `olddp'. If so, replace them with the new - * mount point. - */ -static void -checkdirs(olddp, newdp) - struct vnode *olddp, *newdp; -{ - struct filedesc *fdp; - struct proc *p; - int nrele; - - if (vrefcnt(olddp) == 1) - return; - sx_slock(&allproc_lock); - LIST_FOREACH(p, &allproc, p_list) { - mtx_lock(&fdesc_mtx); - fdp = p->p_fd; - if (fdp == NULL) { - mtx_unlock(&fdesc_mtx); - continue; - } - nrele = 0; - FILEDESC_LOCK_FAST(fdp); - if (fdp->fd_cdir == olddp) { - vref(newdp); - fdp->fd_cdir = newdp; - nrele++; - } - if (fdp->fd_rdir == olddp) { - vref(newdp); - fdp->fd_rdir = newdp; - nrele++; - } - FILEDESC_UNLOCK_FAST(fdp); - mtx_unlock(&fdesc_mtx); - while (nrele--) - vrele(olddp); - } - sx_sunlock(&allproc_lock); - if (rootvnode == olddp) { - vrele(rootvnode); - vref(newdp); - rootvnode = newdp; - } -} - /* * --------------------------------------------------------------------- * Unmount a filesystem. @@ -991,7 +942,7 @@ dounmount(mp, flags, td) */ if ((flags & MNT_FORCE) && VFS_ROOT(mp, &fsrootvp, td) == 0) { if (mp->mnt_vnodecovered != NULL) - checkdirs(fsrootvp, mp->mnt_vnodecovered); + mountcheckdirs(fsrootvp, mp->mnt_vnodecovered); if (fsrootvp == rootvnode) { vrele(rootvnode); rootvnode = NULL; @@ -1008,7 +959,7 @@ dounmount(mp, flags, td) /* Undo cdir/rdir and rootvnode changes made above. */ if ((flags & MNT_FORCE) && VFS_ROOT(mp, &fsrootvp, td) == 0) { if (mp->mnt_vnodecovered != NULL) - checkdirs(mp->mnt_vnodecovered, fsrootvp); + mountcheckdirs(mp->mnt_vnodecovered, fsrootvp); if (rootvnode == NULL) { rootvnode = fsrootvp; vref(rootvnode); diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 00e3df23758a..5726768210ea 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -172,6 +172,7 @@ struct filedesc_to_leader * filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, struct proc *leader); int getvnode(struct filedesc *fdp, int fd, struct file **fpp); +void mountcheckdirs(struct vnode *olddp, struct vnode *newdp); void setugidsafety(struct thread *td); static __inline struct file *