Move the checkdirs() function from vfs_mount.c to kern_descrip.c and
call it mountcheckdirs().
This commit is contained in:
parent
1aeacc6d75
commit
b124f6c510
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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 *
|
||||
|
Loading…
Reference in New Issue
Block a user