Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Feb 2006 16:40:34 +0200
From:      Kostik Belousov <kostikbel@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   [possible patch] fdescfs vop_lookup and parent vnode locking
Message-ID:  <c781d7f30602030640i31762e4bk8aa1234abc099613@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Is it correct that filesystem-specific vop_lookup is expected to
take the directory vnode (dvp) locked, and shall return with dvp locked ?
vnode_if.src specifies this behaviour as dependent on the flags in the cnp
arguments. My reading of the sources suggest that the statement in the firs=
t
sentence is true, and note from vnode_if.src applies to
sys/kern/vfs_lookup.c:lookup() procedure itself.

If it is true, the fdescfs break this rule, dropping the lock on the dvp. S=
ee
sys/fs/fdescfs/fdesc_vnops.c, line 196. As result, having fdescfs mounted,
most accesses to files on it cause warning from the lockmgr,
lockmgr: thread XXX unlocking unheld lock

I did some testing with the following patch

Index: sys/fs/fdescfs/fdesc_vnops.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: /usr/local/arch/ncvs/src/sys/fs/fdescfs/fdesc_vnops.c,v
retrieving revision 1.100
diff -u -r1.100 fdesc_vnops.c
--- sys/fs/fdescfs/fdesc_vnops.c=0910 Aug 2005 07:08:14 -0000=091.100
+++ sys/fs/fdescfs/fdesc_vnops.c=093 Feb 2006 14:35:11 -0000
@@ -193,11 +193,9 @@
 =09=09goto bad;
 =09}

-=09VOP_UNLOCK(dvp, 0, td);
 =09if (cnp->cn_namelen =3D=3D 1 && *pname =3D=3D '.') {
 =09=09*vpp =3D dvp;
 =09=09VREF(dvp);
-=09=09vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
 =09=09return (0);
 =09}

@@ -228,12 +226,12 @@
 =09if (error)
 =09=09goto bad;
 =09VTOFDESC(fvp)->fd_fd =3D fd;
-=09vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, td);
+=09if (fvp !=3D dvp)
+=09=09vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, td);
 =09*vpp =3D fvp;
 =09return (0);

 bad:
-=09vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
 =09*vpp =3D NULL;
 =09return (error);
 }


and do not see the warnings anymore. The system does not deadlock.

What do you think about the problem ?

Best regards,
Kostik Belousov



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c781d7f30602030640i31762e4bk8aa1234abc099613>