Date: Sat, 17 Jun 2006 06:29:26 GMT From: Scott Long <scottl@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 99404 for review Message-ID: <200606170629.k5H6TQlo000434@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=99404 Change 99404 by scottl@scottl-wv1u on 2006/06/17 06:29:15 Provide minimal locking for ses(4). Affected files ... .. //depot/projects/scottl-camlock/src/sys/cam/scsi/scsi_ses.c#6 edit Differences ... ==== //depot/projects/scottl-camlock/src/sys/cam/scsi/scsi_ses.c#6 (text+ko) ==== @@ -43,6 +43,7 @@ #include <cam/cam_periph.h> #include <cam/cam_xpt_periph.h> #include <cam/cam_debug.h> +#include <cam/cam_sim.h> #include <cam/scsi/scsi_all.h> #include <cam/scsi/scsi_message.h> @@ -182,7 +183,7 @@ .d_close = sesclose, .d_ioctl = sesioctl, .d_name = "ses", - .d_flags = D_NEEDGIANT, + .d_flags = 0, }; static void @@ -419,14 +420,17 @@ splx(s); return (ENXIO); } + mtx_lock(periph->sim->mtx); if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) { splx(s); + mtx_unlock(periph->sim->mtx); return (error); } splx(s); if (cam_periph_acquire(periph) != CAM_REQ_CMP) { cam_periph_unlock(periph); + mtx_unlock(periph->sim->mtx); return (ENXIO); } @@ -459,6 +463,7 @@ cam_periph_release(periph); } cam_periph_unlock(periph); + mtx_unlock(periph->sim->mtx); return (error); } @@ -477,13 +482,17 @@ softc = (struct ses_softc *)periph->softc; - if ((error = cam_periph_lock(periph, PRIBIO)) != 0) + mtx_lock(periph->sim->mtx); + if ((error = cam_periph_lock(periph, PRIBIO)) != 0) { + mtx_unlock(periph->sim->mtx); return (error); + } softc->ses_flags &= ~SES_FLAG_OPEN; cam_periph_unlock(periph); cam_periph_release(periph); + mtx_unlock(periph->sim->mtx); return (0); } @@ -541,14 +550,17 @@ CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n")); + mtx_lock(periph->sim->mtx); ssc = (struct ses_softc *)periph->softc; /* * Now check to see whether we're initialized or not. */ if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) { + mtx_unlock(periph->sim->mtx); return (ENXIO); } + mtx_unlock(periph->sim->mtx); error = 0; @@ -578,22 +590,34 @@ break; case SESIOC_GETOBJMAP: + /* + * XXX Dropping the lock while copying multiple segments is + * bogus. + */ + mtx_lock(periph->sim->mtx); for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) { obj.obj_id = i; obj.subencid = ssc->ses_objmap[i].subenclosure; obj.object_type = ssc->ses_objmap[i].enctype; + mtx_unlock(periph->sim->mtx); error = copyout(&obj, uobj, sizeof (ses_object)); + mtx_lock(periph->sim->mtx); if (error) { break; } } + mtx_unlock(periph->sim->mtx); break; case SESIOC_GETENCSTAT: + mtx_lock(periph->sim->mtx); error = (*ssc->ses_vec.get_encstat)(ssc, 1); - if (error) + if (error) { + mtx_unlock(periph->sim->mtx); break; + } tmp = ssc->ses_encstat & ~ENCI_SVALID; + mtx_unlock(periph->sim->mtx); error = copyout(&tmp, addr, sizeof (ses_encstat)); ssc->ses_encstat = tmp; break; @@ -602,7 +626,9 @@ error = copyin(addr, &tmp, sizeof (ses_encstat)); if (error) break; + mtx_lock(periph->sim->mtx); error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1); + mtx_unlock(periph->sim->mtx); break; case SESIOC_GETOBJSTAT: @@ -613,7 +639,9 @@ error = EINVAL; break; } + mtx_lock(periph->sim->mtx); error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1); + mtx_unlock(periph->sim->mtx); if (error) break; error = copyout(&objs, addr, sizeof (ses_objstat)); @@ -632,7 +660,9 @@ error = EINVAL; break; } + mtx_lock(periph->sim->mtx); error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1); + mtx_unlock(periph->sim->mtx); /* * Always (for now) invalidate entry. @@ -642,11 +672,15 @@ case SESIOC_INIT: + mtx_lock(periph->sim->mtx); error = (*ssc->ses_vec.init_enc)(ssc); + mtx_unlock(periph->sim->mtx); break; default: + mtx_lock(periph->sim->mtx); error = cam_periph_ioctl(periph, cmd, arg_addr, seserror); + mtx_unlock(periph->sim->mtx); break; } return (error);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606170629.k5H6TQlo000434>