2000-05-06 00:59:20 +04:00
|
|
|
/* $NetBSD: lfs_bio.c,v 1.18 2000/05/05 20:59:21 perseant Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Konrad E. Schroder <perseant@hhhh.org>.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)lfs_bio.c 8.10 (Berkeley) 6/10/95
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1996-02-10 01:28:45 +03:00
|
|
|
#include <sys/systm.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
#include <ufs/ufs/ufsmount.h>
|
1996-02-10 01:28:45 +03:00
|
|
|
#include <ufs/ufs/ufs_extern.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
#include <sys/malloc.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <ufs/lfs/lfs.h>
|
|
|
|
#include <ufs/lfs/lfs_extern.h>
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/* Macros to clear/set/test flags. */
|
|
|
|
# define SET(t, f) (t) |= (f)
|
|
|
|
# define CLR(t, f) (t) &= ~(f)
|
|
|
|
# define ISSET(t, f) ((t) & (f))
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* LFS block write function.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* No write cost accounting is done.
|
|
|
|
* This is almost certainly wrong for synchronous operations and NFS.
|
|
|
|
*/
|
|
|
|
int lfs_allclean_wakeup; /* Cleaner wakeup address. */
|
1999-03-10 03:20:00 +03:00
|
|
|
int locked_queue_count = 0; /* XXX Count of locked-down buffers. */
|
|
|
|
long locked_queue_bytes = 0L; /* XXX Total size of locked buffers. */
|
|
|
|
int lfs_writing = 0; /* Set if already kicked off a writer
|
1994-06-08 15:41:58 +04:00
|
|
|
because of buffer space */
|
1999-03-10 03:20:00 +03:00
|
|
|
extern int lfs_dostats;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* #define WRITE_THRESHHOLD ((nbuf >> 1) - 10)
|
|
|
|
* #define WAIT_THRESHHOLD (nbuf - (nbuf >> 2) - 10)
|
|
|
|
*/
|
|
|
|
#define LFS_MAX_BUFS ((nbuf >> 2) - 10)
|
|
|
|
#define LFS_WAIT_BUFS ((nbuf >> 1) - (nbuf >> 3) - 10)
|
|
|
|
/* These are new ... is LFS taking up too much memory in its buffers? */
|
1999-12-04 15:11:13 +03:00
|
|
|
#define LFS_MAX_BYTES (((bufpages >> 2) - 10) * NBPG)
|
|
|
|
#define LFS_WAIT_BYTES (((bufpages >> 1) - (bufpages >> 3) - 10) * NBPG)
|
1999-03-10 03:20:00 +03:00
|
|
|
#define LFS_BUFWAIT 2
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
1999-03-10 03:20:00 +03:00
|
|
|
*
|
|
|
|
* XXX we don't let meta-data writes run out of space because they can
|
|
|
|
* come from the segment writer. We need to make sure that there is
|
|
|
|
* enough space reserved so that there's room to write meta-data
|
|
|
|
* blocks.
|
|
|
|
*
|
|
|
|
* Also, we don't let blocks that have come to us from the cleaner
|
|
|
|
* run out of space.
|
|
|
|
*/
|
|
|
|
#define CANT_WAIT(BP,F) (IS_IFILE((BP)) || (BP)->b_lblkno<0 || ((F) & BW_CLEAN))
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
int
|
1996-02-10 01:28:45 +03:00
|
|
|
lfs_bwrite(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_bwrite_args /* {
|
|
|
|
struct buf *a_bp;
|
1996-02-10 01:28:45 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct buf *bp = ap->a_bp;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
1999-12-15 10:10:32 +03:00
|
|
|
if(VTOI(bp->b_vp)->i_lfs->lfs_ronly == 0
|
|
|
|
&& (bp->b_flags & B_ASYNC)) {
|
1999-03-10 03:20:00 +03:00
|
|
|
panic("bawrite LFS buffer");
|
1999-12-15 10:10:32 +03:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
#endif /* DIAGNOSTIC */
|
|
|
|
return lfs_bwrite_ext(bp,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine if there is enough room currently available to write db
|
|
|
|
* disk blocks. We need enough blocks for the new blocks, the current
|
|
|
|
* inode blocks, a summary block, plus potentially the ifile inode and
|
|
|
|
* the segment usage table, plus an ifile page.
|
|
|
|
*/
|
|
|
|
inline static int lfs_fits(struct lfs *fs, int db)
|
|
|
|
{
|
|
|
|
if(((db + (fs->lfs_uinodes + INOPB((fs))) /
|
|
|
|
INOPB(fs) + fsbtodb(fs, 1) + LFS_SUMMARY_SIZE / DEV_BSIZE +
|
|
|
|
fs->lfs_segtabsz)) >= fs->lfs_avail)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Also check the number of segments available for writing.
|
|
|
|
* If you don't do this here, it is possible for the *cleaner* to
|
|
|
|
* cause us to become starved of segments, by flushing the pending
|
|
|
|
* block list.
|
|
|
|
*
|
|
|
|
* XXX the old lfs_markv did not have this problem.
|
|
|
|
*/
|
|
|
|
if (fs->lfs_nclean <= MIN_FREE_SEGS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_bwrite_ext(bp, flags)
|
|
|
|
struct buf *bp;
|
|
|
|
int flags;
|
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct lfs *fs;
|
|
|
|
struct inode *ip;
|
1998-03-01 05:20:01 +03:00
|
|
|
int db, error, s;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1999-12-15 10:10:32 +03:00
|
|
|
/*
|
|
|
|
* Don't write *any* blocks if we're mounted read-only.
|
|
|
|
* In particular the cleaner can't write blocks either.
|
|
|
|
*/
|
|
|
|
if(VTOI(bp->b_vp)->i_lfs->lfs_ronly) {
|
|
|
|
bp->b_flags &= ~(B_DELWRI|B_LOCKED|B_READ|B_ERROR);
|
|
|
|
if(bp->b_flags & B_CALL)
|
|
|
|
bp->b_flags &= ~B_BUSY;
|
|
|
|
else
|
|
|
|
brelse(bp);
|
|
|
|
return EROFS;
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Set the delayed write flag and use reassignbuf to move the buffer
|
|
|
|
* from the clean list to the dirty one.
|
|
|
|
*
|
|
|
|
* Set the B_LOCKED flag and unlock the buffer, causing brelse to move
|
|
|
|
* the buffer onto the LOCKED free list. This is necessary, otherwise
|
|
|
|
* getnewbuf() would try to reclaim the buffers using bawrite, which
|
|
|
|
* isn't going to work.
|
|
|
|
*
|
|
|
|
* XXX we don't let meta-data writes run out of space because they can
|
|
|
|
* come from the segment writer. We need to make sure that there is
|
|
|
|
* enough space reserved so that there's room to write meta-data
|
|
|
|
* blocks.
|
|
|
|
*/
|
|
|
|
if (!(bp->b_flags & B_LOCKED)) {
|
|
|
|
fs = VFSTOUFS(bp->b_vp->v_mount)->um_lfs;
|
1998-03-01 05:20:01 +03:00
|
|
|
db = fragstodb(fs, numfrags(fs, bp->b_bcount));
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
if(CANT_WAIT(bp,flags)) {
|
|
|
|
if(((db + (fs->lfs_uinodes + INOPB((fs))) / INOPB(fs)
|
|
|
|
+ fsbtodb(fs, 1)
|
|
|
|
+ LFS_SUMMARY_SIZE / DEV_BSIZE
|
|
|
|
+ fs->lfs_segtabsz)) >= fs->lfs_avail)
|
|
|
|
{
|
|
|
|
printf("A");
|
|
|
|
}
|
|
|
|
if (fs->lfs_nclean <= MIN_FREE_SEGS-1)
|
|
|
|
printf("M");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
while (!lfs_fits(fs, db) && !CANT_WAIT(bp,flags)) {
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Out of space, need cleaner to run */
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
wakeup(&lfs_allclean_wakeup);
|
1998-03-01 05:20:01 +03:00
|
|
|
wakeup(&fs->lfs_nextseg);
|
1999-03-10 03:20:00 +03:00
|
|
|
error = tsleep(&fs->lfs_avail, PCATCH | PUSER, "cleaner", NULL);
|
1996-02-10 01:28:45 +03:00
|
|
|
if (error) {
|
1999-03-10 03:20:00 +03:00
|
|
|
/* printf("lfs_bwrite: error in tsleep"); */
|
1994-06-08 15:41:58 +04:00
|
|
|
brelse(bp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
ip = VTOI(bp->b_vp);
|
1999-03-26 01:26:52 +03:00
|
|
|
if (bp->b_flags & B_CALL)
|
1999-03-10 03:20:00 +03:00
|
|
|
{
|
|
|
|
if(!(ip->i_flag & IN_CLEANING))
|
|
|
|
++fs->lfs_uinodes;
|
|
|
|
ip->i_flag |= IN_CLEANING;
|
|
|
|
} else {
|
|
|
|
if(!(ip->i_flag & IN_MODIFIED))
|
|
|
|
++fs->lfs_uinodes;
|
|
|
|
ip->i_flag |= IN_CHANGE | IN_MODIFIED | IN_UPDATE;
|
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
fs->lfs_avail -= db;
|
1994-06-08 15:41:58 +04:00
|
|
|
++locked_queue_count;
|
1999-03-10 03:20:00 +03:00
|
|
|
locked_queue_bytes += bp->b_bufsize;
|
1999-11-24 02:52:40 +03:00
|
|
|
s = splbio();
|
1999-12-15 10:10:32 +03:00
|
|
|
bp->b_flags |= B_DELWRI | B_LOCKED;
|
1994-06-08 15:41:58 +04:00
|
|
|
bp->b_flags &= ~(B_READ | B_ERROR);
|
|
|
|
reassignbuf(bp, bp->b_vp);
|
|
|
|
splx(s);
|
1999-03-26 01:26:52 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1999-03-26 01:26:52 +03:00
|
|
|
if(bp->b_flags & B_CALL)
|
1999-03-10 03:20:00 +03:00
|
|
|
bp->b_flags &= ~B_BUSY;
|
|
|
|
else
|
|
|
|
brelse(bp);
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-06-01 07:00:40 +04:00
|
|
|
void lfs_flush_fs(mp, flags)
|
|
|
|
struct mount *mp;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct lfs *lfsp;
|
|
|
|
|
|
|
|
lfsp = ((struct ufsmount *)mp->mnt_data)->ufsmount_u.lfs;
|
|
|
|
if((mp->mnt_flag & MNT_RDONLY) == 0 &&
|
|
|
|
lfsp->lfs_dirops==0)
|
|
|
|
{
|
|
|
|
/* disallow dirops during flush */
|
|
|
|
lfsp->lfs_writer++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We set the queue to 0 here because we
|
|
|
|
* are about to write all the dirty
|
|
|
|
* buffers we have. If more come in
|
|
|
|
* while we're writing the segment, they
|
|
|
|
* may not get written, so we want the
|
|
|
|
* count to reflect these new writes
|
|
|
|
* after the segwrite completes.
|
|
|
|
*/
|
|
|
|
if(lfs_dostats)
|
|
|
|
++lfs_stats.flush_invoked;
|
|
|
|
lfs_segwrite(mp, flags);
|
|
|
|
|
|
|
|
/* XXX KS - allow dirops again */
|
|
|
|
if(--lfsp->lfs_writer==0)
|
|
|
|
wakeup(&lfsp->lfs_dirops);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* This routine flushes buffers out of the B_LOCKED queue when LFS has too
|
|
|
|
* many locked down. Eventually the pageout daemon will simply call LFS
|
|
|
|
* when pages need to be reclaimed. Note, we have one static count of locked
|
|
|
|
* buffers, so we can't have more than a single file system. To make this
|
|
|
|
* work for multiple file systems, put the count into the mount structure.
|
|
|
|
*/
|
|
|
|
void
|
1999-03-10 03:20:00 +03:00
|
|
|
lfs_flush(fs, flags)
|
|
|
|
struct lfs *fs;
|
|
|
|
int flags;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct mount *mp, *nmp;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
if(lfs_dostats)
|
|
|
|
++lfs_stats.write_exceeded;
|
1999-12-15 10:10:32 +03:00
|
|
|
if (lfs_writing && flags==0) {/* XXX flags */
|
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
printf("lfs_flush: not flushing because another flush is active\n");
|
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
return;
|
1999-12-15 10:10:32 +03:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_writing = 1;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock(&mountlist_slock);
|
|
|
|
for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
|
|
|
|
if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
|
|
|
|
nmp = mp->mnt_list.cqe_next;
|
|
|
|
continue;
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
if (strncmp(&mp->mnt_stat.f_fstypename[0], MOUNT_LFS, MFSNAMELEN)==0)
|
1999-06-01 07:00:40 +04:00
|
|
|
lfs_flush_fs(mp, flags);
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock(&mountlist_slock);
|
|
|
|
nmp = mp->mnt_list.cqe_next;
|
|
|
|
vfs_unbusy(mp);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_unlock(&mountlist_slock);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
lfs_countlocked(&locked_queue_count,&locked_queue_bytes);
|
|
|
|
wakeup(&locked_queue_count);
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_writing = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-03-10 03:20:00 +03:00
|
|
|
lfs_check(vp, blkno, flags)
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vnode *vp;
|
1998-03-01 05:20:01 +03:00
|
|
|
ufs_daddr_t blkno;
|
1999-03-10 03:20:00 +03:00
|
|
|
int flags;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
|
|
|
int error;
|
1999-04-12 04:36:47 +04:00
|
|
|
struct lfs *fs;
|
1999-11-06 23:33:05 +03:00
|
|
|
extern int lfs_dirvcount;
|
1999-04-12 04:36:47 +04:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
error = 0;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* If out of buffers, wait on writer */
|
1999-03-10 03:20:00 +03:00
|
|
|
/* XXX KS - if it's the Ifile, we're probably the cleaner! */
|
|
|
|
if (VTOI(vp)->i_number == LFS_IFILE_INUM)
|
|
|
|
return 0;
|
|
|
|
|
1999-04-12 04:36:47 +04:00
|
|
|
/* If dirops are active, can't flush. Wait for SET_ENDOP */
|
|
|
|
fs = VTOI(vp)->i_lfs;
|
|
|
|
if (fs->lfs_dirops)
|
|
|
|
return 0;
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
if (locked_queue_count > LFS_MAX_BUFS
|
1999-04-12 04:36:47 +04:00
|
|
|
|| locked_queue_bytes > LFS_MAX_BYTES
|
1999-11-06 23:33:05 +03:00
|
|
|
|| lfs_dirvcount > LFS_MAXDIROP
|
1999-06-01 07:00:40 +04:00
|
|
|
|| fs->lfs_diropwait > 0)
|
1999-03-10 03:20:00 +03:00
|
|
|
{
|
1999-04-12 04:36:47 +04:00
|
|
|
++fs->lfs_writer;
|
|
|
|
lfs_flush(fs, flags);
|
|
|
|
if(--fs->lfs_writer==0)
|
|
|
|
wakeup(&fs->lfs_dirops);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1999-06-01 07:00:40 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
while (locked_queue_count > LFS_WAIT_BUFS
|
|
|
|
|| locked_queue_bytes > LFS_WAIT_BYTES)
|
|
|
|
{
|
|
|
|
if(lfs_dostats)
|
|
|
|
++lfs_stats.wait_exceeded;
|
1999-12-15 10:10:32 +03:00
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
printf("lfs_check: waiting: count=%d, bytes=%ld\n",
|
|
|
|
locked_queue_count, locked_queue_bytes);
|
|
|
|
#endif
|
1999-03-10 03:20:00 +03:00
|
|
|
error = tsleep(&locked_queue_count, PCATCH | PUSER,
|
|
|
|
"buffers", hz * LFS_BUFWAIT);
|
2000-05-06 00:59:20 +04:00
|
|
|
/*
|
|
|
|
* lfs_flush might not flush all the buffers, if some of the
|
|
|
|
* inodes were locked. Try flushing again to keep us from
|
|
|
|
* blocking indefinitely.
|
|
|
|
*/
|
|
|
|
if (locked_queue_count > LFS_MAX_BUFS
|
|
|
|
|| locked_queue_bytes > LFS_MAX_BYTES)
|
|
|
|
{
|
|
|
|
++fs->lfs_writer;
|
|
|
|
lfs_flush(fs, flags);
|
|
|
|
if(--fs->lfs_writer==0)
|
|
|
|
wakeup(&fs->lfs_dirops);
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new buffer header.
|
|
|
|
*/
|
|
|
|
struct buf *
|
|
|
|
lfs_newbuf(vp, daddr, size)
|
|
|
|
struct vnode *vp;
|
|
|
|
ufs_daddr_t daddr;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
size_t nbytes;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
nbytes = roundup(size, DEV_BSIZE);
|
|
|
|
|
|
|
|
bp = malloc(sizeof(struct buf), M_SEGMENT, M_WAITOK);
|
|
|
|
bzero(bp, sizeof(struct buf));
|
|
|
|
if (nbytes)
|
|
|
|
bp->b_data = malloc(nbytes, M_SEGMENT, M_WAITOK);
|
|
|
|
if(nbytes) {
|
|
|
|
bzero(bp->b_data, nbytes);
|
|
|
|
}
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(vp==NULL)
|
|
|
|
panic("vp is NULL in lfs_newbuf");
|
|
|
|
if(bp==NULL)
|
|
|
|
panic("bp is NULL after malloc in lfs_newbuf");
|
1994-06-08 15:41:58 +04:00
|
|
|
#endif
|
1999-03-10 03:20:00 +03:00
|
|
|
s = splbio();
|
|
|
|
bgetvp(vp, bp);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
bp->b_bufsize = size;
|
|
|
|
bp->b_bcount = size;
|
|
|
|
bp->b_lblkno = daddr;
|
|
|
|
bp->b_blkno = daddr;
|
|
|
|
bp->b_error = 0;
|
|
|
|
bp->b_resid = 0;
|
|
|
|
bp->b_iodone = lfs_callback;
|
|
|
|
bp->b_flags |= B_BUSY | B_CALL | B_NOCACHE;
|
|
|
|
|
|
|
|
return (bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lfs_freebuf(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
if(bp->b_vp)
|
|
|
|
brelvp(bp);
|
|
|
|
splx(s);
|
|
|
|
if (!(bp->b_flags & B_INVAL)) { /* B_INVAL indicates a "fake" buffer */
|
|
|
|
free(bp->b_data, M_SEGMENT);
|
|
|
|
bp->b_data = NULL;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
free(bp, M_SEGMENT);
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/*
|
|
|
|
* Definitions for the buffer free lists.
|
|
|
|
*/
|
|
|
|
#define BQUEUES 4 /* number of free buffer queues */
|
|
|
|
|
|
|
|
#define BQ_LOCKED 0 /* super-blocks &c */
|
|
|
|
#define BQ_LRU 1 /* lru, useful buffers */
|
|
|
|
#define BQ_AGE 2 /* rubbish */
|
|
|
|
#define BQ_EMPTY 3 /* buffer headers with no memory */
|
|
|
|
|
|
|
|
extern TAILQ_HEAD(bqueues, buf) bufqueues[BQUEUES];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a count of buffers on the "locked" queue.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_countlocked(count, bytes)
|
|
|
|
int *count;
|
|
|
|
long *bytes;
|
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct buf *bp;
|
|
|
|
int n = 0;
|
|
|
|
long int size = 0L;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
for (bp = bufqueues[BQ_LOCKED].tqh_first; bp;
|
|
|
|
bp = bp->b_freelist.tqe_next) {
|
|
|
|
n++;
|
|
|
|
size += bp->b_bufsize;
|
|
|
|
}
|
|
|
|
*count = n;
|
|
|
|
*bytes = size;
|
|
|
|
return;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|