From 426da3bcfb40b0b0733f0be4dea9e7659f442368 Mon Sep 17 00:00:00 2001 From: Alfred Perlstein 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/netsmb/smb_dev.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'sys/netsmb/smb_dev.c') diff --git a/sys/netsmb/smb_dev.c b/sys/netsmb/smb_dev.c index 2a0f671762e3..c832fa8166cd 100644 --- a/sys/netsmb/smb_dev.c +++ b/sys/netsmb/smb_dev.c @@ -394,10 +394,15 @@ nsmb_getfp(struct filedesc* fdp, int fd, int flag) { struct file* fp; + FILEDESC_LOCK(fdp); if (((u_int)fd) >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL || - (fp->f_flag & flag) == 0) + (fp->f_flag & flag) == 0) { + FILEDESC_UNLOCK(fdp); return (NULL); + } + fhold(fp); + FILEDESC_UNLOCK(fdp); return (fp); } @@ -416,19 +421,25 @@ smb_dev2share(int fd, int mode, struct smb_cred *scred, if (fp == NULL) return EBADF; vp = (struct vnode*)fp->f_data; - if (vp == NULL) + if (vp == NULL) { + fdrop(fp, curthread); return EBADF; + } dev = vn_todev(vp); - if (dev == NODEV) + if (dev == NODEV) { + fdrop(fp, curthread); return EBADF; + } SMB_CHECKMINOR(dev); ssp = sdp->sd_share; - if (ssp == NULL) + if (ssp == NULL) { + fdrop(fp, curthread); return ENOTCONN; + } error = smb_share_get(ssp, LK_EXCLUSIVE, scred); - if (error) - return error; - *sspp = ssp; - return 0; + if (error == 0) + *sspp = ssp; + fdrop(fp, curthread); + return error; } -- cgit v1.3