Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
VOP_LOCK(9)	       FreeBSD Kernel Developer's Manual	   VOP_LOCK(9)

NAME
     VOP_LOCK, VOP_UNLOCK, VOP_ISLOCKED	-- serialize access to a vnode

SYNOPSIS
     #include <sys/vnode.h>

     int
     VOP_LOCK(struct vnode *vp);

     int
     VOP_UNLOCK(struct vnode *vp);

     int
     VOP_ISLOCKED(struct vnode *vp);

DESCRIPTION
     The arguments are:

     vp	 the vnode being locked	or unlocked

     These calls are used to serialize access to the filesystem, for instance
     to	prevent	two writes to the same file from happening at the same time.

RETURN VALUES
     Zero is returned on success, otherwise an error is	returned.

PSEUDOCODE
     struct vopnode {
	 int von_flag;
	 /*
	  * Other filesystem specific data.
	  */
	 ...;
     };
     #define VON_LOCKED	     1
     #define VON_WANTED	     2
     #define VTOVON(vp)	     ((struct vopnode *) (vp)->v_data)

     int
     vop_lock(struct vnode *vp)
     {
	 struct	vopnode* vop;

     start:
	 while (vp->v_flag & VXLOCK) {
	     vp->v_flag	|= VXWANT;
	     tsleep((caddr_t)vp, PINOD,	"voplk1", 0);
	 }
	 if (vp->v_tag == VT_NON)
	     return ENOENT;

	 vop = VTOVON(vp);
	 if (vop->von_flag & VON_LOCKED) {
	     vop->von_flag |= VON_WANTED;
	     tsleep((caddr_t) vop, PINOD, "voplk2", 0);
	     goto start;
	 }

	 vop->von_flag |= VON_LOCKED;

	 return	0;
     }

     int
     vop_unlock(struct vnode *vp)
     {
	 struct	vopnode	*vop = VTOVON(vp);

	 if ((vop->von_flag & VON_LOCKED) == 0)	{
	     panic("vop_unlock not locked");
	 }
	 vop->von_flag &= ~VON_LOCKED;
	 if (vop->von_flag & VON_WANTED) {
	     vop->von_flag &= ~VON_WANTED;
	     wakeup((caddr_t) vop);
	 }

	 return	0;
     }

     int
     vop_islocked(struct vnode *vp)
     {
	 struct	vopnode	*vop = VTOVON(vp);

	 if (vop->von_flag & VON_LOCKED)
	     return 1;
	 else
	     return 0;
     }

SEE ALSO
     vnode(9)

AUTHORS
     This man page was written by Doug Rabson.

FreeBSD	11.1			 July 24, 1996			  FreeBSD 11.1

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | PSEUDOCODE | SEE ALSO | AUTHORS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=VOP_LOCK&sektion=9&manpath=FreeBSD+2.2.1-RELEASE>

home | help