*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->FreeBSD man pages -> VOP_UNLOCK (9)              
Title
Content
Arch
Section
 

VOP_LOCK(9)

Contents


NAME    [Toc]    [Back]

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

SYNOPSIS    [Toc]    [Back]

     #include <sys/param.h>
     #include <sys/lock.h>
     #include <sys/vnode.h>

     int
     VOP_LOCK(struct vnode *vp, int flags, struct thread *td);

     int
     VOP_UNLOCK(struct vnode *vp, int flags, struct thread *td);

     int
     VOP_ISLOCKED(struct vnode *vp, struct thread *td);

     int
     vn_lock(struct vnode *vp, int flags, struct thread *td);

DESCRIPTION    [Toc]    [Back]

     These calls are used to serialize access to the file system, such as to
     prevent two writes to the same file from happening at the same time.

     The arguments are:

     vp     the vnode being locked or unlocked

     flags  One of the lock request types:

		  LK_SHARED	    Shared lock
		  LK_EXCLUSIVE	    Exclusive lock
		  LK_UPGRADE	    Shared-to-exclusive upgrade
		  LK_EXCLUPGRADE    First shared-to-exclusive upgrade
		  LK_DOWNGRADE	    Exclusive-to-shared downgrade
		  LK_RELEASE	    Release any type of lock
		  LK_DRAIN	    Wait for all lock activity to end

	    The lock type may be or'ed with these lock flags:

		  LK_NOWAIT	   Do not sleep to wait for lock
		  LK_SLEEPFAIL	   Sleep, then return failure
		  LK_CANRECURSE    Allow recursive exclusive lock
		  LK_REENABLE	   Lock is to be reenabled after drain
		  LK_NOPAUSE	   No spinloop

	    The lock type may be or'ed with these control flags:

		  LK_INTERLOCK	  Specify when the caller already has a simple
				  lock (VOP_LOCK will unlock the simple lock
				  after getting the lock)
		  LK_RETRY	  Retry until locked
		  LK_NOOBJ	  Don't create object

     td     thread context to use for the locks

     Kernel code should use vn_lock() to lock a vnode rather than calling
     VOP_LOCK() directly.

RETURN VALUES    [Toc]    [Back]

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

PSEUDOCODE    [Toc]    [Back]

     struct vopnode {
	 int von_flag;
	 /*
	  * Other file system 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    [Toc]    [Back]

      
      
     vnode(9)

AUTHORS    [Toc]    [Back]

     This man page was written by Doug Rabson.


FreeBSD 5.2.1			 July 24, 1996			 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
VOP_SETACL FreeBSD set the access control list for a vnode
VOP_GETACL FreeBSD retrieve access control list for a vnode
VOP_ACLCHECK FreeBSD check an access control list for a vnode
vaccess OpenBSD check access permissions based on vnode parameters
vaccess FreeBSD generate an access control decision using vnode parameters
vaccess_acl_posix1e FreeBSD generate a POSIX.1e ACL access control decision using vnode parameters
tt_message_arg_xval_set HP-UX serialize and set data into an existing message argument
st_sym_size Tru64 access information about the symbols in an object, and access or set symbol name demangling controls
st_is_sym_weak Tru64 access information about the symbols in an object, and access or set symbol name demangling controls
st_sym_value Tru64 access information about the symbols in an object, and access or set symbol name demangling controls
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service