File:  [DragonFly] / src / share / man / man9 / VOP_FSYNC.9
Revision 1.3: download - view: text, annotated - select for diffs
Fri Aug 1 17:46:25 2003 UTC (11 years ago) by dillon
Branches: MAIN
CVS tags: HEAD
Cleanup remaining tsleep priority issues.

Submitted-by: Jeroen Ruigrok/asmodai <asmodai@wxs.nl>

    1: .\" -*- nroff -*-
    2: .\"
    3: .\" Copyright (c) 1996 Doug Rabson
    4: .\"
    5: .\" All rights reserved.
    6: .\"
    7: .\" This program is free software.
    8: .\"
    9: .\" Redistribution and use in source and binary forms, with or without
   10: .\" modification, are permitted provided that the following conditions
   11: .\" are met:
   12: .\" 1. Redistributions of source code must retain the above copyright
   13: .\"    notice, this list of conditions and the following disclaimer.
   14: .\" 2. Redistributions in binary form must reproduce the above copyright
   15: .\"    notice, this list of conditions and the following disclaimer in the
   16: .\"    documentation and/or other materials provided with the distribution.
   17: .\"
   18: .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
   19: .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   20: .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   21: .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
   22: .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   23: .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   24: .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   25: .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   26: .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   27: .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   28: .\"
   29: .\" $FreeBSD: src/share/man/man9/VOP_FSYNC.9,v 1.6.2.2 2001/12/17 11:30:18 ru Exp $
   30: .\" $DragonFly: src/share/man/man9/VOP_FSYNC.9,v 1.3 2003/08/01 17:46:25 dillon Exp $
   31: .\"
   32: .Dd July 24, 1996
   33: .Os
   34: .Dt VOP_FSYNC 9
   35: .Sh NAME
   36: .Nm VOP_FSYNC
   37: .Nd flush filesystem buffers for a file
   38: .Sh SYNOPSIS
   39: .In sys/param.h
   40: .In sys/vnode.h
   41: .Ft int
   42: .Fn VOP_FSYNC "struct vnode *vp" "struct ucred *cred" "int waitfor" "struct proc *p"
   43: .Sh DESCRIPTION
   44: This call flushes any dirty filesystem buffers for the file.
   45: It is used to implement the
   46: .Xr sync 2
   47: and
   48: .Xr fsync 2
   49: system calls.
   50: .Pp
   51: Its arguments are:
   52: .Bl -tag -width waitfor
   53: .It Ar vp
   54: the vnode of the file
   55: .It Ar cred
   56: the caller's credentials
   57: .It Ar waitfor
   58: whether the function should wait for I/O to complete
   59: .It Ar p
   60: the calling process
   61: .El
   62: .Pp
   63: The argument
   64: .Fa waitfor
   65: is either
   66: .Dv MNT_WAIT
   67: or
   68: .Dv MNT_NOWAIT
   69: and specifies whether or not the function should wait for the writes
   70: to finish before returning.
   71: .Sh LOCKS
   72: The file should be locked on entry.
   73: .Sh RETURN VALUES
   74: Zero is returned if the call is successful, otherwise an appropriate
   75: error code is returned.
   76: .Sh PSEUDOCODE
   77: .Bd -literal
   78: int
   79: vop_fsync(struct vnode *vp, struct ucred *cred, int waitfor, struct proc *p)
   80: {
   81:     struct buf *bp;
   82:     struct buf *nbp;
   83:     struct timeval tv;
   84:     int s;
   85: 
   86: loop:
   87:     s = splbio();
   88:     for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
   89: 	nbp = bp->b_vnbufs.le_next;
   90: 
   91: 	/*
   92: 	 * Ignore buffers which are already being written.
   93: 	 */
   94: 	if (bp->b_flags & B_BUSY)
   95: 	    continue;
   96: 
   97: 	/*
   98: 	 * Make sure the buffer is dirty.
   99: 	 */
  100: 	if ((bp->b_flags & B_DELWRI) == 0)
  101: 	    panic("vop_fsync: not dirty");
  102: 
  103: 	vfs_bio_awrite(bp);
  104: 	splx(s);
  105: 	goto loop;
  106:     }
  107:     splx(s);
  108: 
  109:     if (waitfor == MNT_WAIT) {
  110: 	s = splbio();
  111: 	while (vp->v_numoutput) {
  112: 	    vp->v_flag |= VBWAIT;
  113: 	    tsleep((caddr_t)&vp->v_numoutput, 0, "vopfsn");
  114: 	}
  115: 	splx(s);
  116: #ifdef DIAGNOSTIC
  117: 	if (vp->v_dirtyblkhd.lh_first) {
  118: 	    vprint("vop_fsync: dirty", vp);
  119: 	    goto loop;
  120: 	}
  121: #endif
  122:     }
  123: 
  124:     /*
  125:      * Write out the on-disc version of the vnode.
  126:      */
  127:     tv = time;
  128:     return VOP_UPDATE(vp, &tv, &tv, waitfor == MNT_WAIT);
  129: }
  130: .Ed
  131: .Sh ERRORS
  132: .Bl -tag -width Er
  133: .It Bq Er ENOSPC
  134: The filesystem is full.
  135: .It Bq Er EDQUOT
  136: Quota exceeded.
  137: .El
  138: .Sh SEE ALSO
  139: .Xr vnode 9
  140: .Sh AUTHORS
  141: This man page was written by
  142: .An Doug Rabson .