From 844237b3960bfbf49070d6371a84f67f9e3366f6 Mon Sep 17 00:00:00 2001 From: alfred Date: Sun, 13 Jan 2002 11:58:06 +0000 Subject: SMP Lock struct file, filedesc and the global file list. Seigo Tanimura (tanimura) posted the initial delta. I've polished it quite a bit reducing the need for locking and adapting it for KSE. Locks: 1 mutex in each filedesc protects all the fields. protects "struct file" initialization, while a struct file is being changed from &badfileops -> &pipeops or something the filedesc should be locked. 1 mutex in each struct file protects the refcount fields. doesn't protect anything else. the flags used for garbage collection have been moved to f_gcflag which was the FILLER short, this doesn't need locking because the garbage collection is a single threaded container. could likely be made to use a pool mutex. 1 sx lock for the global filelist. struct file * fhold(struct file *fp); /* increments reference count on a file */ struct file * fhold_locked(struct file *fp); /* like fhold but expects file to locked */ struct file * ffind_hold(struct thread *, int fd); /* finds the struct file in thread, adds one reference and returns it unlocked */ struct file * ffind_lock(struct thread *, int fd); /* ffind_hold, but returns file locked */ I still have to smp-safe the fget cruft, I'll get to that asap. --- sys/alpha/osf1/osf1_misc.c | 7 +++---- sys/alpha/osf1/osf1_mount.c | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'sys/alpha') diff --git a/sys/alpha/osf1/osf1_misc.c b/sys/alpha/osf1/osf1_misc.c index 84526e2..46b20d9 100644 --- a/sys/alpha/osf1/osf1_misc.c +++ b/sys/alpha/osf1/osf1_misc.c @@ -667,18 +667,17 @@ osf1_fstat(td, uap) struct thread *td; register struct osf1_fstat_args *uap; { - register struct filedesc *fdp; register struct file *fp; struct stat ub; struct osf1_stat oub; int error; - fdp = td->td_proc->p_fd; - if ((unsigned)SCARG(uap, fd) >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) + fp = ffind_hold(td, uap->fd); + if (fp == NULL) return (EBADF); error = fo_stat(fp, &ub, td); + fdrop(fp, td); cvtstat2osf1(&ub, &oub); if (error == 0) error = copyout((caddr_t)&oub, (caddr_t)SCARG(uap, sb), diff --git a/sys/alpha/osf1/osf1_mount.c b/sys/alpha/osf1/osf1_mount.c index 2e88b17..4244da3 100644 --- a/sys/alpha/osf1/osf1_mount.c +++ b/sys/alpha/osf1/osf1_mount.c @@ -154,7 +154,9 @@ osf1_fstatfs(td, uap) return (error); mp = ((struct vnode *)fp->f_data)->v_mount; sp = &mp->mnt_stat; - if ((error = VFS_STATFS(mp, sp, td))) + error = VFS_STATFS(mp, sp, td); + fdrop(fp, td); + if (error) return (error); sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; bsd2osf_statfs(sp, &osfs); -- cgit v1.1