Date: Sat, 4 Aug 2007 10:57:30 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: Bruce Evans <brde@optusnet.com.au> Cc: bugs@freebsd.org, fs@freebsd.org Subject: Re: msdosfs not MPSAFE Message-ID: <20070804075730.GP2738@deviant.kiev.zoral.com.ua> In-Reply-To: <20070721233613.Q3366@besplex.bde.org> References: <20070710233455.O2101@besplex.bde.org> <20070712084115.GA2200@deviant.kiev.zoral.com.ua> <20070712225324.F9515@besplex.bde.org> <20070712142127.GD2200@deviant.kiev.zoral.com.ua> <20070716195556.P12807@besplex.bde.org> <20070721063434.GI2200@deviant.kiev.zoral.com.ua> <20070721233613.Q3366@besplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--h9WqFG8zn/Mwlkpe Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jul 21, 2007 at 11:52:04PM +1000, Bruce Evans wrote: > On Sat, 21 Jul 2007, Kostik Belousov wrote: >=20 > >On Mon, Jul 16, 2007 at 08:18:14PM +1000, Bruce Evans wrote: > >>sx xlocking works, but is not quite right: > >>% /* > >>% + * XXX msdosfs_lookup() is split up because unlocking before all the > >>returns > >>% + * in the original function would be too churning. > >>% + */ > >>% +int > >>% +msdosfs_lookup(ap) > >>% + struct vop_cachedlookup_args *ap; > >>% +{ > >>% + int error; > >>% + > >>% + sx_xlock(&mbnambuf_lock); > >>% + error =3D msdosfs_lookup_locked(ap); > >>% + sx_xunlock(&mbnambuf_lock); > >>% + return (error); > >>% +} > >>% + > >>% +/* > > > >Assume that a directory A is participating in lookup() from two threads: > >thread 1 lookup the A itself; > >thread 2 lookup some entry in the A. > >Then, thread 1 would have mbnambuf_lock locked, and may wait for A' > >vnode lock; > >thread 2 shall own vnode lock for A, then locking mbnambuf_lock. > > > >I do not see what may prevent this LOR scenario from realizing, or what > >make it harmless. >=20 > Nothing I can see either. The wrapper is too global. >=20 > Next try: move locking into the inner loop in msdosfs_lookup(). Unlocking > is not as ugly as I feared. The following has only been tested at compile > time: >=20 > % Index: msdosfs_lookup.c > % =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > % RCS file: /home/ncvs/src/sys/fs/msdosfs/msdosfs_lookup.c,v > % retrieving revision 1.40 > % diff -u -2 -r1.40 msdosfs_lookup.c > % --- msdosfs_lookup.c 26 Dec 2003 17:24:37 -0000 1.40 > % +++ msdosfs_lookup.c 21 Jul 2007 13:27:37 -0000 > % @@ -54,4 +54,5 @@ > % #include <sys/bio.h> > % #include <sys/buf.h> > % +#include <sys/sx.h> > % #include <sys/vnode.h> > % #include <sys/mount.h> > % @@ -63,4 +64,6 @@ > % #include <fs/msdosfs/fat.h> > %=20 > % +extern struct sx mbnambuf_lock; > % + > % /* > % * When we search a directory the blocks containing directory entries = are > % @@ -192,4 +195,5 @@ > % */ > % tdp =3D NULL; > % + sx_xlock(&mbnambuf_lock); > % mbnambuf_init(); > % /* > % @@ -206,4 +210,5 @@ > % if (error =3D=3D E2BIG) > % break; > % + sx_xunlock(&mbnambuf_lock); > % return (error); > % } > % @@ -211,4 +216,5 @@ > % if (error) { > % brelse(bp); > % + sx_xunlock(&mbnambuf_lock); > % return (error); > % } > % @@ -240,4 +246,5 @@ > % if (dep->deName[0] =3D=3D SLOT_EMPTY) { > % brelse(bp); > % + sx_xunlock(&mbnambuf_lock); > % goto notfound; > % } > % @@ -301,4 +308,5 @@ > % dp->de_fndcnt =3D wincnt - 1; > %=20 > % + sx_xunlock(&mbnambuf_lock); > % goto found; > % } > % @@ -310,4 +318,5 @@ > % brelse(bp); > % } /* for (frcn =3D 0; ; frcn++) */ > % + sx_xunlock(&mbnambuf_lock); > %=20 > % notfound: >=20 > After moving the locking into msdosfs_conv.c and adding assertions there, > this should be a good enough fix until the mbnambuf interface is changed. > This bug is in all versions since 5.2-RELEASE. Once again, sorry for late answer. The change seems to be good. --h9WqFG8zn/Mwlkpe Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFGtDFpC3+MBN1Mb4gRAr1XAJ9hWtnFtf0kiW6EvRrLwiCrJhvKZACfVdGC 9Dp51cDM0HfDVEaDRq2rbk4= =V3NH -----END PGP SIGNATURE----- --h9WqFG8zn/Mwlkpe--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070804075730.GP2738>