doing vfs_hash_get when vnode locked

Kostik Belousov kostikbel at gmail.com
Tue Aug 5 16:51:20 UTC 2008


On Tue, Aug 05, 2008 at 12:54:26PM -0400, Rick Macklem wrote:
> 
> 
> On Tue, 5 Aug 2008, Kostik Belousov wrote:
> 
> [stuff snipped]
> >>>
> >>I need a referenced vnode (v_usecount incremented, which I thought would
> >>avoid it being recycled) when another blocked thread in the kernel has
> >No, this is a wrong assumption. Use count does not prevent the vnode
> >from being reclaimed.
> >
> What does v_usecount mean then, if it doesn't say "I have it in use, so
> you can't recycle it until I vrele() it"?
It means that the vnode memory will not be freed until vrele().

But the VOP_RECLAIM may be called any time, and it requires exclusive lock.
After vnode is reclaimed, it is reassigned to the deadfs. In particular,
VOP_RECLAIM implementation must clear v_data.

For the reclaimed vnode you still hold a reference to, you can reliably
obtain the vnode lock.

> 
> I suppose I can test for the lock and grab it, if no other thread already
> has it locked.
> 
> >Unless you held the vnode lock, it may be reclaimed. To set the
> >VI_DOOMED flag, both exclusive vnode lock and vnode interlock must be
> >held.
> >
> I don't care about VI_DOOMED nor want to set it. It is just what vget()
> checked for the case of LK_TYPE_MASK == 0 under FreeBSD7.
> 
> >If you can guarantee that the other thread does not relinquish the vnode
> >lock while curthread operates on the vnode, you may use vref() and
> >direct check on VI_DOOMED. I shall admit that this is quite perversive
> >and fragile.
> >
> I'll have to think about it but, yes, I think I can guarantee that if
> another thread holds the vnode lock then it is blocked waiting for this
> thread to complete recovery. (The only other way to do this recovery is
> without the vnode and that means I have to do a lot of coding. I'm
> pretty sure holding a v_usecount works for OpenBSD and Mac OS X. I've
> done quite a bit of testing on both and not had a problem.)

I do not know about these systems, esp. whether and how they implement
a forced unmount.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20080805/be6ae6e5/attachment.pgp


More information about the freebsd-fs mailing list