FreeBSD/sys/fs/ext2fs/ext2_vfsops.c
/*
 * Go through the disk queues to initiate sandbagged IO;
 * go through the inodes to write those that have been modified;
 * initiate the writing of the super block if it has been modified.
 *
 * Note: we are always called with the filesystem marked `MPBUSY'.
 */
Go through the disk queues to initiate sandbagged IO;
go through the inodes to write those that have been modified;
initiate the writing of the super block if it has been modified.

we are always called with the filesystem marked `MPBUSY'.
Go through the disk queues to initiate sandbagged IO ; go through the inodes to write those that have been modified ; initiate the writing of the super block if it has been modified . we are always called with the filesystem marked ` MPBUSY ' .
static int
ext2_sync(struct mount *mp, int waitfor)
{
	struct vnode *mvp, *vp;
	struct thread *td;
	struct inode *ip;
	struct ext2mount *ump = VFSTOEXT2(mp);
	struct m_ext2fs *fs;
	int error, allerror = 0;
	td = curthread;
	fs = ump->um_e2fs;
	if (fs->e2fs_fmod != 0 && fs->e2fs_ronly != 0) {		
		printf("fs = %s\n", fs->e2fs_fsmnt);
		panic("ext2_sync: rofs mod");
	}
loop:
	MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
		if (vp->v_type == VNON) {
			VI_UNLOCK(vp);
			continue;
		}
		ip = VTOI(vp);
		if ((ip->i_flag &
		    (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0 &&
		    (vp->v_bufobj.bo_dirty.bv_cnt == 0 ||
		    waitfor == MNT_LAZY)) {
			VI_UNLOCK(vp);
			continue;
		}
		error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK, td);
		if (error) {
			if (error == ENOENT) {
				MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
				goto loop;
			}
			continue;
		}
		if ((error = VOP_FSYNC(vp, waitfor, td)) != 0)
			allerror = error;
		VOP_UNLOCK(vp, 0);
		vrele(vp);
	}
	if (waitfor != MNT_LAZY) {
		vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
		if ((error = VOP_FSYNC(ump->um_devvp, waitfor, td)) != 0)
			allerror = error;
		VOP_UNLOCK(ump->um_devvp, 0);
	}
	if (fs->e2fs_fmod != 0) {
		fs->e2fs_fmod = 0;
		fs->e2fs->e2fs_wtime = time_second;
		if ((error = ext2_cgupdate(ump, waitfor)) != 0)
			allerror = error;
	}
	return (allerror);
}
static int ext2_sync ( struct mount * mp , int waitfor ) { struct vnode * mvp , * vp ; struct thread * td ; struct inode * ip ; struct ext2mount * ump = VFSTOEXT2 ( mp ) ; struct m_ext2fs * fs ; int error , allerror = 0 ; td = curthread ; fs = ump -> um_e2fs ; if ( fs -> e2fs_fmod != 0 && fs -> e2fs_ronly != 0 ) { printf ( " \n " , fs -> e2fs_fsmnt ) ; panic ( " " ) ; } loop : MNT_VNODE_FOREACH_ALL ( vp , mp , mvp ) { if ( vp -> v_type == VNON ) { VI_UNLOCK ( vp ) ; continue ; } ip = VTOI ( vp ) ; if ( ( ip -> i_flag & ( IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE ) ) == 0 && ( vp -> v_bufobj . bo_dirty . bv_cnt == 0 || waitfor == MNT_LAZY ) ) { VI_UNLOCK ( vp ) ; continue ; } error = vget ( vp , LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK , td ) ; if ( error ) { if ( error == ENOENT ) { MNT_VNODE_FOREACH_ALL_ABORT ( mp , mvp ) ; goto loop ; } continue ; } if ( ( error = VOP_FSYNC ( vp , waitfor , td ) ) != 0 ) allerror = error ; VOP_UNLOCK ( vp , 0 ) ; vrele ( vp ) ; } if ( waitfor != MNT_LAZY ) { vn_lock ( ump -> um_devvp , LK_EXCLUSIVE | LK_RETRY ) ; if ( ( error = VOP_FSYNC ( ump -> um_devvp , waitfor , td ) ) != 0 ) allerror = error ; VOP_UNLOCK ( ump -> um_devvp , 0 ) ; } if ( fs -> e2fs_fmod != 0 ) { fs -> e2fs_fmod = 0 ; fs -> e2fs -> e2fs_wtime = time_second ; if ( ( error = ext2_cgupdate ( ump , waitfor ) ) != 0 ) allerror = error ; } return ( allerror ) ; }
Go through the disk queues to initiate sandbagged IO;
 go through the inodes to write those that have been modified;
 initiate the writing of the super block if it has been modified.
Go through the disk queues to initiate sandbagged IO ; go through the inodes to write those that have been modified ; initiate the writing of the super block if it has been modified .
/* XXX */ /*
	 * Write back each (modified) inode.
	 */ /*
	 * Force stale filesystem control information to be flushed.
	 */ /*
	 * Write back modified superblock.
	 */