Subject: Re: Addition to force open to open only regular files
To: Warner Losh <firstname.lastname@example.org>
From: Jason R Thorpe <email@example.com>
Date: 11/29/2000 09:10:36
On Wed, Nov 29, 2000 at 12:04:47AM -0700, Warner Losh wrote:
> The race saved by getfh() I think causes kernel resources to be
> consumed. The getfh call locks the leaf and leaving it locked on
> return to userland seems to be dangerous to me.
What on earth are you talking about? If that were actually true, all
sorts of hell would break loose.
I suggest you actually read the code. Here, let me quote it for you:
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
SCARG(uap, fname), p);
error = namei(&nd);
vp = nd.ni_vp; <--- vnode is locked due to LOCKLEAF
memset((caddr_t)&fh, 0, sizeof(fh));
fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
error = VFS_VPTOFH(vp, &fh.fh_fid);
vput(vp); <--- unlocks the vnode
The file handle has a "generation" number in it, which is incremented when
the vnode is recycled ("stale file handle" ring a bell?), so it's safe to
return the file handle to userland with the vnode unlocked.
-- Jason R. Thorpe <firstname.lastname@example.org>