xref: /freebsd/share/man/man9/VOP_FSYNC.9 (revision 0a57ea7df24d23c69c2740cf86d8bff7553555e6)
1fab63cc4SDoug Rabson.\" -*- nroff -*-
2fab63cc4SDoug Rabson.\"
3fab63cc4SDoug Rabson.\" Copyright (c) 1996 Doug Rabson
4fab63cc4SDoug Rabson.\"
5fab63cc4SDoug Rabson.\" All rights reserved.
6fab63cc4SDoug Rabson.\"
7fab63cc4SDoug Rabson.\" This program is free software.
8fab63cc4SDoug Rabson.\"
9fab63cc4SDoug Rabson.\" Redistribution and use in source and binary forms, with or without
10fab63cc4SDoug Rabson.\" modification, are permitted provided that the following conditions
11fab63cc4SDoug Rabson.\" are met:
12fab63cc4SDoug Rabson.\" 1. Redistributions of source code must retain the above copyright
13fab63cc4SDoug Rabson.\"    notice, this list of conditions and the following disclaimer.
14fab63cc4SDoug Rabson.\" 2. Redistributions in binary form must reproduce the above copyright
15fab63cc4SDoug Rabson.\"    notice, this list of conditions and the following disclaimer in the
16fab63cc4SDoug Rabson.\"    documentation and/or other materials provided with the distribution.
17fab63cc4SDoug Rabson.\"
18fab63cc4SDoug Rabson.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19fab63cc4SDoug Rabson.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20fab63cc4SDoug Rabson.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21fab63cc4SDoug Rabson.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22fab63cc4SDoug Rabson.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23fab63cc4SDoug Rabson.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24fab63cc4SDoug Rabson.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25fab63cc4SDoug Rabson.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26fab63cc4SDoug Rabson.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27fab63cc4SDoug Rabson.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28fab63cc4SDoug Rabson.\"
297f3dea24SPeter Wemm.\" $FreeBSD$
30fab63cc4SDoug Rabson.\"
31fab63cc4SDoug Rabson.Dd July 24, 1996
32fab63cc4SDoug Rabson.Os
33fab63cc4SDoug Rabson.Dt VOP_FSYNC 9
34fab63cc4SDoug Rabson.Sh NAME
35fab63cc4SDoug Rabson.Nm VOP_FSYNC
36fab63cc4SDoug Rabson.Nd flush file system buffers for a file
37fab63cc4SDoug Rabson.Sh SYNOPSIS
3832eef9aeSRuslan Ermilov.In sys/param.h
3932eef9aeSRuslan Ermilov.In sys/vnode.h
40fab63cc4SDoug Rabson.Ft int
41c2508101SAndrew R. Reiter.Fn VOP_FSYNC "struct vnode *vp" "struct ucred *cred" "int waitfor" "struct thread *td"
42fab63cc4SDoug Rabson.Sh DESCRIPTION
43fab63cc4SDoug RabsonThis call flushes any dirty file system buffers for the file.
44fab63cc4SDoug RabsonIt is used to implement the
45fab63cc4SDoug Rabson.Xr sync 2
46fab63cc4SDoug Rabsonand
47fab63cc4SDoug Rabson.Xr fsync 2
48fab63cc4SDoug Rabsonsystem calls.
49fab63cc4SDoug Rabson.Pp
50fab63cc4SDoug RabsonIts arguments are:
51fab63cc4SDoug Rabson.Bl -tag -width waitfor
520640e9e0SHiten Pandya.It Fa vp
530a57ea7dSRuslan ErmilovThe vnode of the file.
540640e9e0SHiten Pandya.It Fa cred
550a57ea7dSRuslan ErmilovThe caller's credentials.
560640e9e0SHiten Pandya.It Fa waitfor
570a57ea7dSRuslan ErmilovWhether the function should wait for I/O to complete.
58505f2a7eSAlexander LangerPossible values are:
59505f2a7eSAlexander Langer.Bl -tag -width MNT_NOWAIT
60505f2a7eSAlexander Langer.It Dv MNT_WAIT
610a57ea7dSRuslan ErmilovSynchronously wait for I/O to complete.
62505f2a7eSAlexander Langer.It Dv MNT_NOWAIT
630a57ea7dSRuslan ErmilovStart all I/O, but do not wait for it.
64505f2a7eSAlexander Langer.It Dv MNT_LAZY
650a57ea7dSRuslan ErmilovPush data not written by file system syncer.
66505f2a7eSAlexander Langer.El
670640e9e0SHiten Pandya.It Fa td
680a57ea7dSRuslan ErmilovThe calling thread.
69fab63cc4SDoug Rabson.El
70fab63cc4SDoug Rabson.Pp
71fab63cc4SDoug RabsonThe argument
72fab63cc4SDoug Rabson.Fa waitfor
73fab63cc4SDoug Rabsonis either
74fab63cc4SDoug Rabson.Dv MNT_WAIT
75fab63cc4SDoug Rabsonor
76fab63cc4SDoug Rabson.Dv MNT_NOWAIT
77fab63cc4SDoug Rabsonand specifies whether or not the function should wait for the writes
78fab63cc4SDoug Rabsonto finish before returning.
79fab63cc4SDoug Rabson.Sh LOCKS
80fab63cc4SDoug RabsonThe file should be locked on entry.
81fab63cc4SDoug Rabson.Sh RETURN VALUES
82fab63cc4SDoug RabsonZero is returned if the call is successful, otherwise an appropriate
83fab63cc4SDoug Rabsonerror code is returned.
84fab63cc4SDoug Rabson.Sh PSEUDOCODE
85fab63cc4SDoug Rabson.Bd -literal
86fab63cc4SDoug Rabsonint
87c2508101SAndrew R. Reitervop_fsync(struct vnode *vp, struct ucred *cred, int waitfor, struct thread *td)
88fab63cc4SDoug Rabson{
89fab63cc4SDoug Rabson    struct buf *bp;
90fab63cc4SDoug Rabson    struct buf *nbp;
91fab63cc4SDoug Rabson    struct timeval tv;
92fab63cc4SDoug Rabson    int s;
93fab63cc4SDoug Rabson
94fab63cc4SDoug Rabsonloop:
95fab63cc4SDoug Rabson    s = splbio();
96fab63cc4SDoug Rabson    for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
97fab63cc4SDoug Rabson	nbp = bp->b_vnbufs.le_next;
98fab63cc4SDoug Rabson
99fab63cc4SDoug Rabson	/*
100fab63cc4SDoug Rabson	 * Ignore buffers which are already being written.
101fab63cc4SDoug Rabson	 */
102fab63cc4SDoug Rabson	if (bp->b_flags & B_BUSY)
103fab63cc4SDoug Rabson	    continue;
104fab63cc4SDoug Rabson
105fab63cc4SDoug Rabson	/*
106fab63cc4SDoug Rabson	 * Make sure the buffer is dirty.
107fab63cc4SDoug Rabson	 */
108fab63cc4SDoug Rabson	if ((bp->b_flags & B_DELWRI) == 0)
109fab63cc4SDoug Rabson	    panic("vop_fsync: not dirty");
110fab63cc4SDoug Rabson
111fab63cc4SDoug Rabson	vfs_bio_awrite(bp);
112fab63cc4SDoug Rabson	splx(s);
113fab63cc4SDoug Rabson	goto loop;
114fab63cc4SDoug Rabson    }
115fab63cc4SDoug Rabson    splx(s);
116fab63cc4SDoug Rabson
117fab63cc4SDoug Rabson    if (waitfor == MNT_WAIT) {
118fab63cc4SDoug Rabson	s = splbio();
119fab63cc4SDoug Rabson	while (vp->v_numoutput) {
120fab63cc4SDoug Rabson	    vp->v_flag |= VBWAIT;
121fab63cc4SDoug Rabson	    tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "vopfsn");
122fab63cc4SDoug Rabson	}
123fab63cc4SDoug Rabson	splx(s);
124fab63cc4SDoug Rabson#ifdef DIAGNOSTIC
125fab63cc4SDoug Rabson	if (vp->v_dirtyblkhd.lh_first) {
126fab63cc4SDoug Rabson	    vprint("vop_fsync: dirty", vp);
127fab63cc4SDoug Rabson	    goto loop;
128fab63cc4SDoug Rabson	}
129fab63cc4SDoug Rabson#endif
130fab63cc4SDoug Rabson    }
131fab63cc4SDoug Rabson
132fab63cc4SDoug Rabson    /*
133fab63cc4SDoug Rabson     * Write out the on-disc version of the vnode.
134fab63cc4SDoug Rabson     */
135fab63cc4SDoug Rabson    tv = time;
136fab63cc4SDoug Rabson    return VOP_UPDATE(vp, &tv, &tv, waitfor == MNT_WAIT);
137fab63cc4SDoug Rabson}
138fab63cc4SDoug Rabson.Ed
139fab63cc4SDoug Rabson.Sh ERRORS
140eaa8b244SMike Pritchard.Bl -tag -width Er
141fab63cc4SDoug Rabson.It Bq Er ENOSPC
142fab63cc4SDoug RabsonThe file system is full.
143fab63cc4SDoug Rabson.It Bq Er EDQUOT
144fab63cc4SDoug RabsonQuota exceeded.
145fab63cc4SDoug Rabson.El
146fab63cc4SDoug Rabson.Sh SEE ALSO
147fab63cc4SDoug Rabson.Xr vnode 9
148fab63cc4SDoug Rabson.Sh AUTHORS
149aaf1f16eSPhilippe CharnierThis man page was written by
150aaf1f16eSPhilippe Charnier.An Doug Rabson .
151