2001-01-09 08:05:35 +03:00
|
|
|
/* $NetBSD: lfs_segment.c,v 1.67 2001/01/09 05:05:35 joff Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/*-
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
|
1999-03-10 03:20:00 +03:00
|
|
|
* 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_segment.c 8.10 (Berkeley) 6/10/95
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
|
1999-03-26 00:39:18 +03:00
|
|
|
#define ivndebug(vp,str) printf("ino %d: %s\n",VTOI(vp)->i_number,(str))
|
|
|
|
|
2000-11-30 18:59:47 +03:00
|
|
|
#if defined(_KERNEL) && !defined(_LKM)
|
1999-09-04 02:48:51 +04:00
|
|
|
#include "opt_ddb.h"
|
2000-11-30 18:59:47 +03:00
|
|
|
#endif
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
#include <miscfs/fifofs/fifo.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
#include <ufs/ufs/dir.h>
|
|
|
|
#include <ufs/ufs/ufsmount.h>
|
|
|
|
#include <ufs/ufs/ufs_extern.h>
|
|
|
|
|
|
|
|
#include <ufs/lfs/lfs.h>
|
|
|
|
#include <ufs/lfs/lfs_extern.h>
|
|
|
|
|
|
|
|
extern int count_lock_queue __P((void));
|
1998-03-01 05:20:01 +03:00
|
|
|
extern struct simplelock vnode_free_list_slock; /* XXX */
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine if it's OK to start a partial in this segment, or if we need
|
|
|
|
* to go on to a new segment.
|
|
|
|
*/
|
|
|
|
#define LFS_PARTIAL_FITS(fs) \
|
|
|
|
((fs)->lfs_dbpseg - ((fs)->lfs_offset - (fs)->lfs_curseg) > \
|
|
|
|
1 << (fs)->lfs_fsbtodb)
|
|
|
|
|
|
|
|
void lfs_callback __P((struct buf *));
|
1999-03-10 03:20:00 +03:00
|
|
|
int lfs_gather __P((struct lfs *, struct segment *,
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vnode *, int (*) __P((struct lfs *, struct buf *))));
|
|
|
|
int lfs_gatherblock __P((struct segment *, struct buf *, int *));
|
1998-03-01 05:20:01 +03:00
|
|
|
void lfs_iset __P((struct inode *, ufs_daddr_t, time_t));
|
1999-03-10 03:20:00 +03:00
|
|
|
int lfs_match_fake __P((struct lfs *, struct buf *));
|
1994-06-08 15:41:58 +04:00
|
|
|
int lfs_match_data __P((struct lfs *, struct buf *));
|
|
|
|
int lfs_match_dindir __P((struct lfs *, struct buf *));
|
|
|
|
int lfs_match_indir __P((struct lfs *, struct buf *));
|
|
|
|
int lfs_match_tindir __P((struct lfs *, struct buf *));
|
|
|
|
void lfs_newseg __P((struct lfs *));
|
2000-03-30 16:41:09 +04:00
|
|
|
void lfs_shellsort __P((struct buf **, ufs_daddr_t *, int));
|
1994-06-08 15:41:58 +04:00
|
|
|
void lfs_supercallback __P((struct buf *));
|
|
|
|
void lfs_updatemeta __P((struct segment *));
|
|
|
|
int lfs_vref __P((struct vnode *));
|
|
|
|
void lfs_vunref __P((struct vnode *));
|
|
|
|
void lfs_writefile __P((struct lfs *, struct segment *, struct vnode *));
|
|
|
|
int lfs_writeinode __P((struct lfs *, struct segment *, struct inode *));
|
|
|
|
int lfs_writeseg __P((struct lfs *, struct segment *));
|
1999-03-10 03:20:00 +03:00
|
|
|
void lfs_writesuper __P((struct lfs *, daddr_t));
|
|
|
|
int lfs_writevnodes __P((struct lfs *fs, struct mount *mp,
|
1994-06-08 15:41:58 +04:00
|
|
|
struct segment *sp, int dirops));
|
|
|
|
|
|
|
|
int lfs_allclean_wakeup; /* Cleaner wakeup address. */
|
1999-03-10 03:20:00 +03:00
|
|
|
int lfs_writeindir = 1; /* whether to flush indir on non-ckp */
|
1999-04-12 04:11:01 +04:00
|
|
|
int lfs_clean_vnhead = 0; /* Allow freeing to head of vn list */
|
1999-11-06 23:33:05 +03:00
|
|
|
int lfs_dirvcount = 0; /* # active dirops */
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
/* Statistics Counters */
|
1999-03-10 03:20:00 +03:00
|
|
|
int lfs_dostats = 1;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct lfs_stats lfs_stats;
|
|
|
|
|
2000-11-17 22:14:41 +03:00
|
|
|
extern int locked_queue_count;
|
|
|
|
extern long locked_queue_bytes;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* op values to lfs_writevnodes */
|
1999-03-10 03:20:00 +03:00
|
|
|
#define VN_REG 0
|
1994-06-08 15:41:58 +04:00
|
|
|
#define VN_DIROP 1
|
|
|
|
#define VN_EMPTY 2
|
1999-03-10 03:20:00 +03:00
|
|
|
#define VN_CLEAN 3
|
|
|
|
|
|
|
|
#define LFS_MAX_ACTIVE 10
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX KS - Set modification time on the Ifile, so the cleaner can
|
|
|
|
* read the fs mod time off of it. We don't set IN_UPDATE here,
|
|
|
|
* since we don't really need this to be flushed to disk (and in any
|
|
|
|
* case that wouldn't happen to the Ifile until we checkpoint).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_imtime(fs)
|
|
|
|
struct lfs *fs;
|
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
struct inode *ip;
|
|
|
|
|
|
|
|
TIMEVAL_TO_TIMESPEC(&time, &ts);
|
|
|
|
ip = VTOI(fs->lfs_ivnode);
|
|
|
|
ip->i_ffs_mtime = ts.tv_sec;
|
|
|
|
ip->i_ffs_mtimensec = ts.tv_nsec;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ifile and meta data blocks are not marked busy, so segment writes MUST be
|
|
|
|
* single threaded. Currently, there are two paths into lfs_segwrite, sync()
|
|
|
|
* and getnewbuf(). They both mark the file system busy. Lfs_vflush()
|
|
|
|
* explicitly marks the file system busy. So lfs_segwrite is safe. I think.
|
|
|
|
*/
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
#define SET_FLUSHING(fs,vp) (fs)->lfs_flushvp = (vp)
|
|
|
|
#define IS_FLUSHING(fs,vp) ((fs)->lfs_flushvp == (vp))
|
|
|
|
#define CLR_FLUSHING(fs,vp) (fs)->lfs_flushvp = NULL
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
int
|
|
|
|
lfs_vflush(vp)
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
struct inode *ip;
|
|
|
|
struct lfs *fs;
|
|
|
|
struct segment *sp;
|
2000-01-15 00:38:46 +03:00
|
|
|
struct buf *bp, *nbp, *tbp, *tnbp;
|
1999-09-04 02:48:51 +04:00
|
|
|
int error, s;
|
1999-03-26 01:26:52 +03:00
|
|
|
|
1999-03-30 20:03:16 +04:00
|
|
|
ip = VTOI(vp);
|
|
|
|
fs = VFSTOUFS(vp->v_mount)->um_lfs;
|
|
|
|
|
1999-03-26 01:26:52 +03:00
|
|
|
if(ip->i_flag & IN_CLEANING) {
|
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
ivndebug(vp,"vflush/in_cleaning");
|
|
|
|
#endif
|
2000-07-06 02:25:43 +04:00
|
|
|
LFS_CLR_UINO(ip, IN_CLEANING);
|
|
|
|
LFS_SET_UINO(ip, IN_MODIFIED);
|
|
|
|
|
2000-01-15 00:38:46 +03:00
|
|
|
/*
|
|
|
|
* Toss any cleaning buffers that have real counterparts
|
|
|
|
* to avoid losing new data
|
|
|
|
*/
|
|
|
|
s = splbio();
|
|
|
|
for(bp=vp->v_dirtyblkhd.lh_first; bp; bp=nbp) {
|
|
|
|
nbp = bp->b_vnbufs.le_next;
|
|
|
|
if(bp->b_flags & B_CALL) {
|
|
|
|
for(tbp=vp->v_dirtyblkhd.lh_first; tbp;
|
|
|
|
tbp=tnbp)
|
|
|
|
{
|
|
|
|
tnbp = tbp->b_vnbufs.le_next;
|
|
|
|
if(tbp->b_vp == bp->b_vp
|
|
|
|
&& tbp->b_lblkno == bp->b_lblkno
|
|
|
|
&& tbp != bp)
|
|
|
|
{
|
2000-11-17 22:14:41 +03:00
|
|
|
fs->lfs_avail += btodb(bp->b_bcount);
|
|
|
|
wakeup(&fs->lfs_avail);
|
2000-01-15 00:38:46 +03:00
|
|
|
lfs_freebuf(bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
1999-03-26 01:26:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the node is being written, wait until that is done */
|
|
|
|
if(WRITEINPROG(vp)) {
|
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
ivndebug(vp,"vflush/writeinprog");
|
|
|
|
#endif
|
|
|
|
tsleep(vp, PRIBIO+1, "lfs_vw", 0);
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/* Protect against VXLOCK deadlock in vinvalbuf() */
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_seglock(fs, SEGM_SYNC);
|
1999-09-04 02:48:51 +04:00
|
|
|
|
|
|
|
/* If we're supposed to flush a freed inode, just toss it */
|
|
|
|
/* XXX - seglock, so these buffers can't be gathered, right? */
|
|
|
|
if(ip->i_ffs_mode == 0) {
|
|
|
|
printf("lfs_vflush: ino %d is freed, not flushing\n",
|
|
|
|
ip->i_number);
|
|
|
|
s = splbio();
|
|
|
|
for(bp=vp->v_dirtyblkhd.lh_first; bp; bp=nbp) {
|
|
|
|
nbp = bp->b_vnbufs.le_next;
|
2000-11-17 22:14:41 +03:00
|
|
|
if (bp->b_flags & B_DELWRI) { /* XXX always true? */
|
|
|
|
fs->lfs_avail += btodb(bp->b_bcount);
|
|
|
|
wakeup(&fs->lfs_avail);
|
|
|
|
}
|
1999-09-04 02:48:51 +04:00
|
|
|
/* Copied from lfs_writeseg */
|
|
|
|
if (bp->b_flags & B_CALL) {
|
|
|
|
/* if B_CALL, it was created with newbuf */
|
|
|
|
lfs_freebuf(bp);
|
|
|
|
} else {
|
|
|
|
bremfree(bp);
|
2000-11-17 22:14:41 +03:00
|
|
|
LFS_UNLOCK_BUF(bp);
|
1999-09-04 02:48:51 +04:00
|
|
|
bp->b_flags &= ~(B_ERROR | B_READ | B_DELWRI |
|
2000-11-17 22:14:41 +03:00
|
|
|
B_GATHERED);
|
1999-09-04 02:48:51 +04:00
|
|
|
bp->b_flags |= B_DONE;
|
|
|
|
reassignbuf(bp, vp);
|
|
|
|
brelse(bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
2000-07-06 02:25:43 +04:00
|
|
|
LFS_CLR_UINO(ip, IN_CLEANING);
|
|
|
|
LFS_CLR_UINO(ip, IN_MODIFIED | IN_ACCESSED);
|
2000-05-31 05:40:01 +04:00
|
|
|
ip->i_flag &= ~IN_ALLMOD;
|
1999-09-04 02:48:51 +04:00
|
|
|
printf("lfs_vflush: done not flushing ino %d\n",
|
|
|
|
ip->i_number);
|
|
|
|
lfs_segunlock(fs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
SET_FLUSHING(fs,vp);
|
|
|
|
if (fs->lfs_nactive > LFS_MAX_ACTIVE) {
|
|
|
|
error = lfs_segwrite(vp->v_mount, SEGM_SYNC|SEGM_CKP);
|
|
|
|
CLR_FLUSHING(fs,vp);
|
|
|
|
lfs_segunlock(fs);
|
|
|
|
return error;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
sp = fs->lfs_sp;
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
if (vp->v_dirtyblkhd.lh_first == NULL) {
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_writevnodes(fs, vp->v_mount, sp, VN_EMPTY);
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
} else if((ip->i_flag & IN_CLEANING) &&
|
|
|
|
(fs->lfs_sp->seg_flags & SEGM_CLEAN)) {
|
1999-03-26 01:26:52 +03:00
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
ivndebug(vp,"vflush/clean");
|
|
|
|
#endif
|
|
|
|
lfs_writevnodes(fs, vp->v_mount, sp, VN_CLEAN);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
else if(lfs_dostats) {
|
2000-05-31 05:40:01 +04:00
|
|
|
if(vp->v_dirtyblkhd.lh_first || (VTOI(vp)->i_flag & IN_ALLMOD))
|
1999-03-10 03:20:00 +03:00
|
|
|
++lfs_stats.vflush_invoked;
|
|
|
|
#ifdef DEBUG_LFS
|
1999-03-26 01:26:52 +03:00
|
|
|
ivndebug(vp,"vflush");
|
1999-03-10 03:20:00 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-03-26 01:26:52 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
1999-03-30 01:51:38 +04:00
|
|
|
/* XXX KS This actually can happen right now, though it shouldn't(?) */
|
1999-03-26 01:26:52 +03:00
|
|
|
if(vp->v_flag & VDIROP) {
|
1999-03-30 01:51:38 +04:00
|
|
|
printf("lfs_vflush: flushing VDIROP, this shouldn\'t be\n");
|
|
|
|
/* panic("VDIROP being flushed...this can\'t happen"); */
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1999-03-26 01:26:52 +03:00
|
|
|
if(vp->v_usecount<0) {
|
2000-11-27 11:39:39 +03:00
|
|
|
printf("usecount=%d\n",vp->v_usecount);
|
1999-03-26 01:26:52 +03:00
|
|
|
panic("lfs_vflush: usecount<0");
|
|
|
|
}
|
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
if (vp->v_dirtyblkhd.lh_first != NULL)
|
|
|
|
lfs_writefile(fs, sp, vp);
|
|
|
|
} while (lfs_writeinode(fs, sp, ip));
|
|
|
|
} while (lfs_writeseg(fs, sp) && ip->i_number == LFS_IFILE_INUM);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
if(lfs_dostats) {
|
|
|
|
++lfs_stats.nwrites;
|
|
|
|
if (sp->seg_flags & SEGM_SYNC)
|
|
|
|
++lfs_stats.nsync_writes;
|
|
|
|
if (sp->seg_flags & SEGM_CKP)
|
|
|
|
++lfs_stats.ncheckpoints;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_segunlock(fs);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
CLR_FLUSHING(fs,vp);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-03-26 00:39:18 +03:00
|
|
|
#ifdef DEBUG_LFS_VERBOSE
|
|
|
|
# define vndebug(vp,str) if(VTOI(vp)->i_flag & IN_CLEANING) printf("not writing ino %d because %s (op %d)\n",VTOI(vp)->i_number,(str),op)
|
|
|
|
#else
|
|
|
|
# define vndebug(vp,str)
|
|
|
|
#endif
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
int
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_writevnodes(fs, mp, sp, op)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct mount *mp;
|
|
|
|
struct segment *sp;
|
|
|
|
int op;
|
|
|
|
{
|
|
|
|
struct inode *ip;
|
|
|
|
struct vnode *vp;
|
1999-03-26 01:38:28 +03:00
|
|
|
int inodes_written=0, only_cleaning;
|
2000-05-06 00:59:20 +04:00
|
|
|
int needs_unlock;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifndef LFS_NO_BACKVP_HACK
|
|
|
|
/* BEGIN HACK */
|
1998-05-08 22:31:13 +04:00
|
|
|
#define VN_OFFSET (((caddr_t)&vp->v_mntvnodes.le_next) - (caddr_t)vp)
|
|
|
|
#define BACK_VP(VP) ((struct vnode *)(((caddr_t)VP->v_mntvnodes.le_prev) - VN_OFFSET))
|
|
|
|
#define BEG_OF_VLIST ((struct vnode *)(((caddr_t)&mp->mnt_vnodelist.lh_first) - VN_OFFSET))
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
/* Find last vnode. */
|
|
|
|
loop: for (vp = mp->mnt_vnodelist.lh_first;
|
1998-03-01 05:20:01 +03:00
|
|
|
vp && vp->v_mntvnodes.le_next != NULL;
|
|
|
|
vp = vp->v_mntvnodes.le_next);
|
|
|
|
for (; vp && vp != BEG_OF_VLIST; vp = BACK_VP(vp)) {
|
1999-03-10 03:20:00 +03:00
|
|
|
#else
|
|
|
|
loop:
|
1994-06-08 15:41:58 +04:00
|
|
|
for (vp = mp->mnt_vnodelist.lh_first;
|
|
|
|
vp != NULL;
|
|
|
|
vp = vp->v_mntvnodes.le_next) {
|
1999-03-10 03:20:00 +03:00
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* If the vnode that we are about to sync is no longer
|
|
|
|
* associated with this mount point, start over.
|
|
|
|
*/
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
if (vp->v_mount != mp) {
|
|
|
|
printf("lfs_writevnodes: starting over\n");
|
1994-06-08 15:41:58 +04:00
|
|
|
goto loop;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
ip = VTOI(vp);
|
|
|
|
if ((op == VN_DIROP && !(vp->v_flag & VDIROP)) ||
|
|
|
|
(op != VN_DIROP && op != VN_CLEAN && (vp->v_flag & VDIROP))) {
|
|
|
|
vndebug(vp,"dirop");
|
1994-06-08 15:41:58 +04:00
|
|
|
continue;
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (op == VN_EMPTY && vp->v_dirtyblkhd.lh_first) {
|
|
|
|
vndebug(vp,"empty");
|
1994-06-08 15:41:58 +04:00
|
|
|
continue;
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vp->v_type == VNON) {
|
|
|
|
continue;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
if(op == VN_CLEAN && ip->i_number != LFS_IFILE_INUM
|
2000-01-15 00:38:46 +03:00
|
|
|
&& vp != fs->lfs_flushvp
|
1999-03-10 03:20:00 +03:00
|
|
|
&& !(ip->i_flag & IN_CLEANING)) {
|
|
|
|
vndebug(vp,"cleaning");
|
1994-06-08 15:41:58 +04:00
|
|
|
continue;
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
if (lfs_vref(vp)) {
|
|
|
|
vndebug(vp,"vref");
|
1994-06-08 15:41:58 +04:00
|
|
|
continue;
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
|
2000-05-06 00:59:20 +04:00
|
|
|
needs_unlock = 0;
|
2000-06-28 00:57:11 +04:00
|
|
|
if (VOP_ISLOCKED(vp)) {
|
2000-05-06 00:59:20 +04:00
|
|
|
if (vp != fs->lfs_ivnode &&
|
|
|
|
vp->v_lock.lk_lockholder != curproc->p_pid) {
|
|
|
|
#ifdef DEBUG_LFS
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
printf("lfs_writevnodes: not writing ino %d,"
|
|
|
|
" locked by pid %d\n",
|
|
|
|
VTOI(vp)->i_number,
|
|
|
|
vp->v_lock.lk_lockholder);
|
2000-05-06 00:59:20 +04:00
|
|
|
#endif
|
2000-05-10 20:47:01 +04:00
|
|
|
lfs_vunref(vp);
|
2000-05-06 00:59:20 +04:00
|
|
|
continue;
|
|
|
|
}
|
2000-05-27 04:19:52 +04:00
|
|
|
} else if (vp != fs->lfs_ivnode) {
|
2000-05-06 00:59:20 +04:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
needs_unlock = 1;
|
|
|
|
}
|
|
|
|
|
1999-03-30 20:11:43 +04:00
|
|
|
only_cleaning = 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
2000-07-05 02:30:37 +04:00
|
|
|
* Write the inode/file if dirty and it's not the IFILE.
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
2000-05-31 05:40:01 +04:00
|
|
|
if ((ip->i_flag & IN_ALLMOD) ||
|
2000-05-31 07:37:34 +04:00
|
|
|
(vp->v_dirtyblkhd.lh_first != NULL))
|
1999-03-10 03:20:00 +03:00
|
|
|
{
|
2000-05-31 05:40:01 +04:00
|
|
|
only_cleaning = ((ip->i_flag & IN_ALLMOD)==IN_CLEANING);
|
1999-03-26 01:38:28 +03:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
if(ip->i_number != LFS_IFILE_INUM
|
|
|
|
&& vp->v_dirtyblkhd.lh_first != NULL)
|
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_writefile(fs, sp, vp);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
if(vp->v_dirtyblkhd.lh_first != NULL) {
|
|
|
|
if(WRITEINPROG(vp)) {
|
|
|
|
#ifdef DEBUG_LFS
|
1999-03-26 00:39:18 +03:00
|
|
|
ivndebug(vp,"writevnodes/write2");
|
1999-03-10 03:20:00 +03:00
|
|
|
#endif
|
2000-05-31 05:40:01 +04:00
|
|
|
} else if(!(ip->i_flag & IN_ALLMOD)) {
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
printf("<%d>",ip->i_number);
|
|
|
|
#endif
|
2000-07-06 02:25:43 +04:00
|
|
|
LFS_SET_UINO(ip, IN_MODIFIED);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
(void) lfs_writeinode(fs, sp, ip);
|
1999-03-10 03:20:00 +03:00
|
|
|
inodes_written++;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
2000-06-28 00:57:11 +04:00
|
|
|
if (needs_unlock)
|
|
|
|
VOP_UNLOCK(vp, 0);
|
2000-05-06 00:59:20 +04:00
|
|
|
|
2000-06-28 00:57:11 +04:00
|
|
|
if (lfs_clean_vnhead && only_cleaning)
|
1999-03-26 01:38:28 +03:00
|
|
|
lfs_vunref_head(vp);
|
|
|
|
else
|
|
|
|
lfs_vunref(vp);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
return inodes_written;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_segwrite(mp, flags)
|
|
|
|
struct mount *mp;
|
|
|
|
int flags; /* Do a checkpoint. */
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
struct inode *ip;
|
|
|
|
struct lfs *fs;
|
|
|
|
struct segment *sp;
|
|
|
|
struct vnode *vp;
|
|
|
|
SEGUSE *segusep;
|
1998-03-01 05:20:01 +03:00
|
|
|
ufs_daddr_t ibno;
|
2000-11-12 10:58:36 +03:00
|
|
|
int do_ckp, did_ckp, error, i;
|
1999-03-10 03:20:00 +03:00
|
|
|
int writer_set = 0;
|
2000-11-12 10:58:36 +03:00
|
|
|
int dirty;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
fs = VFSTOUFS(mp)->um_lfs;
|
|
|
|
|
2000-07-03 05:45:46 +04:00
|
|
|
if (fs->lfs_ronly)
|
|
|
|
return EROFS;
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
lfs_imtime(fs);
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
|
2000-11-12 10:58:36 +03:00
|
|
|
/* printf("lfs_segwrite: ifile flags are 0x%lx\n",
|
|
|
|
(long)(VTOI(fs->lfs_ivnode)->i_flag)); */
|
|
|
|
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
#if 0
|
1999-03-10 03:20:00 +03:00
|
|
|
/*
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
* If we are not the cleaner, and there is no space available,
|
|
|
|
* wait until cleaner writes.
|
1999-03-10 03:20:00 +03:00
|
|
|
*/
|
2000-11-12 10:58:36 +03:00
|
|
|
if(!(flags & SEGM_CLEAN) && !(fs->lfs_seglock && fs->lfs_sp &&
|
|
|
|
(fs->lfs_sp->seg_flags & SEGM_CLEAN)))
|
1999-03-10 03:20:00 +03:00
|
|
|
{
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
while (fs->lfs_avail <= 0) {
|
2000-11-12 10:58:36 +03:00
|
|
|
LFS_CLEANERINFO(cip, fs, bp);
|
|
|
|
LFS_SYNC_CLEANERINFO(cip, fs, bp, 0);
|
|
|
|
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
wakeup(&lfs_allclean_wakeup);
|
|
|
|
wakeup(&fs->lfs_nextseg);
|
|
|
|
error = tsleep(&fs->lfs_avail, PRIBIO + 1, "lfs_av2",
|
|
|
|
0);
|
|
|
|
if (error) {
|
|
|
|
return (error);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Allocate a segment structure and enough space to hold pointers to
|
|
|
|
* the maximum possible number of buffers which can be described in a
|
|
|
|
* single summary block.
|
|
|
|
*/
|
1999-03-10 03:20:00 +03:00
|
|
|
do_ckp = (flags & SEGM_CKP) || fs->lfs_nactive > LFS_MAX_ACTIVE;
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_seglock(fs, flags | (do_ckp ? SEGM_CKP : 0));
|
|
|
|
sp = fs->lfs_sp;
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/*
|
1999-03-26 00:39:18 +03:00
|
|
|
* If lfs_flushvp is non-NULL, we are called from lfs_vflush,
|
|
|
|
* in which case we have to flush *all* buffers off of this vnode.
|
1999-12-04 00:47:44 +03:00
|
|
|
* We don't care about other nodes, but write any non-dirop nodes
|
|
|
|
* anyway in anticipation of another getnewvnode().
|
|
|
|
*
|
|
|
|
* If we're cleaning we only write cleaning and ifile blocks, and
|
|
|
|
* no dirops, since otherwise we'd risk corruption in a crash.
|
1999-03-10 03:20:00 +03:00
|
|
|
*/
|
2000-01-15 00:38:46 +03:00
|
|
|
if(sp->seg_flags & SEGM_CLEAN)
|
1999-03-10 03:20:00 +03:00
|
|
|
lfs_writevnodes(fs, mp, sp, VN_CLEAN);
|
|
|
|
else {
|
|
|
|
lfs_writevnodes(fs, mp, sp, VN_REG);
|
2000-01-15 00:38:46 +03:00
|
|
|
if(!fs->lfs_dirops || !fs->lfs_flushvp) {
|
|
|
|
while(fs->lfs_dirops)
|
|
|
|
if((error = tsleep(&fs->lfs_writer, PRIBIO + 1,
|
|
|
|
"lfs writer", 0)))
|
|
|
|
{
|
|
|
|
free(sp->bpp, M_SEGMENT);
|
|
|
|
free(sp, M_SEGMENT);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
fs->lfs_writer++;
|
|
|
|
writer_set=1;
|
|
|
|
lfs_writevnodes(fs, mp, sp, VN_DIROP);
|
|
|
|
((SEGSUM *)(sp->segsum))->ss_flags &= ~(SS_CONT);
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are doing a checkpoint, mark everything since the
|
|
|
|
* last checkpoint as no longer ACTIVE.
|
|
|
|
*/
|
1999-03-10 03:20:00 +03:00
|
|
|
if (do_ckp) {
|
1994-06-08 15:41:58 +04:00
|
|
|
for (ibno = fs->lfs_cleansz + fs->lfs_segtabsz;
|
|
|
|
--ibno >= fs->lfs_cleansz; ) {
|
2000-11-12 10:58:36 +03:00
|
|
|
dirty = 0;
|
1999-03-10 03:20:00 +03:00
|
|
|
if (bread(fs->lfs_ivnode, ibno, fs->lfs_bsize, NOCRED, &bp))
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
panic("lfs_segwrite: ifile read");
|
1994-06-08 15:41:58 +04:00
|
|
|
segusep = (SEGUSE *)bp->b_data;
|
2000-11-12 10:58:36 +03:00
|
|
|
for (i = fs->lfs_sepb; i--; segusep++) {
|
|
|
|
if (segusep->su_flags & SEGUSE_ACTIVE) {
|
|
|
|
segusep->su_flags &= ~SEGUSE_ACTIVE;
|
|
|
|
++dirty;
|
|
|
|
}
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/* But the current segment is still ACTIVE */
|
2000-06-28 00:00:03 +04:00
|
|
|
segusep = (SEGUSE *)bp->b_data;
|
|
|
|
if (datosn(fs, fs->lfs_curseg) / fs->lfs_sepb ==
|
2000-11-12 10:58:36 +03:00
|
|
|
(ibno-fs->lfs_cleansz)) {
|
2000-06-28 00:00:03 +04:00
|
|
|
segusep[datosn(fs, fs->lfs_curseg) %
|
|
|
|
fs->lfs_sepb].su_flags |= SEGUSE_ACTIVE;
|
2000-11-12 10:58:36 +03:00
|
|
|
--dirty;
|
|
|
|
}
|
|
|
|
if (dirty)
|
|
|
|
error = VOP_BWRITE(bp); /* Ifile */
|
|
|
|
else
|
|
|
|
brelse(bp);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
2000-11-12 10:58:36 +03:00
|
|
|
|
|
|
|
did_ckp = 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
if (do_ckp || fs->lfs_doifile) {
|
2000-11-27 06:33:57 +03:00
|
|
|
do {
|
|
|
|
vp = fs->lfs_ivnode;
|
2000-07-05 02:30:37 +04:00
|
|
|
|
2000-11-27 06:33:57 +03:00
|
|
|
vget(vp, LK_EXCLUSIVE | LK_CANRECURSE | LK_RETRY);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
2000-11-27 06:33:57 +03:00
|
|
|
ip = VTOI(vp);
|
|
|
|
if (vp->v_dirtyblkhd.lh_first != NULL)
|
|
|
|
lfs_writefile(fs, sp, vp);
|
|
|
|
if (ip->i_flag & IN_ALLMOD)
|
|
|
|
++did_ckp;
|
|
|
|
(void) lfs_writeinode(fs, sp, ip);
|
|
|
|
|
|
|
|
vput(vp);
|
|
|
|
} while (lfs_writeseg(fs, sp) && do_ckp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
2000-11-12 10:58:36 +03:00
|
|
|
/* The ifile should now be all clear */
|
|
|
|
LFS_CLR_UINO(ip, IN_ALLMOD);
|
1999-03-10 03:20:00 +03:00
|
|
|
} else {
|
1994-06-08 15:41:58 +04:00
|
|
|
(void) lfs_writeseg(fs, sp);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
1999-03-10 03:20:00 +03:00
|
|
|
* If the I/O count is non-zero, sleep until it reaches zero.
|
|
|
|
* At the moment, the user's process hangs around so we can
|
|
|
|
* sleep.
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
fs->lfs_doifile = 0;
|
1999-03-10 03:20:00 +03:00
|
|
|
if(writer_set && --fs->lfs_writer==0)
|
|
|
|
wakeup(&fs->lfs_dirops);
|
2000-11-12 10:58:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we didn't write the Ifile, we didn't really do anything.
|
|
|
|
* That means that (1) there is a checkpoint on disk and (2)
|
|
|
|
* nothing has changed since it was written.
|
|
|
|
*
|
|
|
|
* Take the flags off of the segment so that lfs_segunlock
|
|
|
|
* doesn't have to write the superblock either.
|
|
|
|
*/
|
|
|
|
if (did_ckp == 0) {
|
|
|
|
sp->seg_flags &= ~(SEGM_SYNC|SEGM_CKP);
|
|
|
|
/* if(do_ckp) printf("lfs_segwrite: no checkpoint\n"); */
|
|
|
|
}
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
if(lfs_dostats) {
|
|
|
|
++lfs_stats.nwrites;
|
|
|
|
if (sp->seg_flags & SEGM_SYNC)
|
|
|
|
++lfs_stats.nsync_writes;
|
|
|
|
if (sp->seg_flags & SEGM_CKP)
|
|
|
|
++lfs_stats.ncheckpoints;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_segunlock(fs);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the dirty blocks associated with a vnode.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_writefile(fs, sp, vp)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct segment *sp;
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
struct finfo *fip;
|
|
|
|
IFILE *ifp;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
if (sp->seg_bytes_left < fs->lfs_bsize ||
|
|
|
|
sp->sum_bytes_left < sizeof(struct finfo))
|
|
|
|
(void) lfs_writeseg(fs, sp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
sp->sum_bytes_left -= sizeof(struct finfo) - sizeof(ufs_daddr_t);
|
1994-06-08 15:41:58 +04:00
|
|
|
++((SEGSUM *)(sp->segsum))->ss_nfinfo;
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
if(vp->v_flag & VDIROP)
|
|
|
|
((SEGSUM *)(sp->segsum))->ss_flags |= (SS_DIROP|SS_CONT);
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
fip = sp->fip;
|
|
|
|
fip->fi_nblocks = 0;
|
|
|
|
fip->fi_ino = VTOI(vp)->i_number;
|
|
|
|
LFS_IENTRY(ifp, fs, fip->fi_ino, bp);
|
|
|
|
fip->fi_version = ifp->if_version;
|
|
|
|
brelse(bp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
2000-01-15 00:38:46 +03:00
|
|
|
if(sp->seg_flags & SEGM_CLEAN)
|
|
|
|
{
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_fake);
|
|
|
|
/*
|
|
|
|
* For a file being flushed, we need to write *all* blocks.
|
|
|
|
* This means writing the cleaning blocks first, and then
|
|
|
|
* immediately following with any non-cleaning blocks.
|
|
|
|
* The same is true of the Ifile since checkpoints assume
|
|
|
|
* that all valid Ifile blocks are written.
|
|
|
|
*/
|
|
|
|
if(IS_FLUSHING(fs,vp) || VTOI(vp)->i_number == LFS_IFILE_INUM)
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_data);
|
|
|
|
} else
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_data);
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* It may not be necessary to write the meta-data blocks at this point,
|
|
|
|
* as the roll-forward recovery code should be able to reconstruct the
|
|
|
|
* list.
|
1999-03-10 03:20:00 +03:00
|
|
|
*
|
|
|
|
* We have to write them anyway, though, under two conditions: (1) the
|
|
|
|
* vnode is being flushed (for reuse by vinvalbuf); or (2) we are
|
|
|
|
* checkpointing.
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
1999-03-10 03:20:00 +03:00
|
|
|
if(lfs_writeindir
|
|
|
|
|| IS_FLUSHING(fs,vp)
|
|
|
|
|| (sp->seg_flags & SEGM_CKP))
|
|
|
|
{
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_indir);
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_dindir);
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_tindir);
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
fip = sp->fip;
|
|
|
|
if (fip->fi_nblocks != 0) {
|
1999-03-10 03:20:00 +03:00
|
|
|
sp->fip = (FINFO*)((caddr_t)fip + sizeof(struct finfo) +
|
|
|
|
sizeof(ufs_daddr_t) * (fip->fi_nblocks-1));
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->start_lbp = &sp->fip->fi_blocks[0];
|
|
|
|
} else {
|
1999-03-10 03:20:00 +03:00
|
|
|
sp->sum_bytes_left += sizeof(FINFO) - sizeof(ufs_daddr_t);
|
1994-06-08 15:41:58 +04:00
|
|
|
--((SEGSUM *)(sp->segsum))->ss_nfinfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_writeinode(fs, sp, ip)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct segment *sp;
|
|
|
|
struct inode *ip;
|
|
|
|
{
|
|
|
|
struct buf *bp, *ibp;
|
2000-07-03 05:45:46 +04:00
|
|
|
struct dinode *cdp;
|
1994-06-08 15:41:58 +04:00
|
|
|
IFILE *ifp;
|
|
|
|
SEGUSE *sup;
|
1998-03-01 05:20:01 +03:00
|
|
|
ufs_daddr_t daddr;
|
2000-07-03 05:45:46 +04:00
|
|
|
daddr_t *daddrp;
|
1994-06-08 15:41:58 +04:00
|
|
|
ino_t ino;
|
|
|
|
int error, i, ndx;
|
|
|
|
int redo_ifile = 0;
|
1996-09-02 03:47:48 +04:00
|
|
|
struct timespec ts;
|
1999-04-12 04:04:21 +04:00
|
|
|
int gotblk=0;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
2000-05-31 05:40:01 +04:00
|
|
|
if (!(ip->i_flag & IN_ALLMOD))
|
1994-06-08 15:41:58 +04:00
|
|
|
return(0);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Allocate a new inode block if necessary. */
|
1999-06-16 02:25:41 +04:00
|
|
|
if ((ip->i_number != LFS_IFILE_INUM || sp->idp==NULL) && sp->ibp == NULL) {
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Allocate a new segment if necessary. */
|
|
|
|
if (sp->seg_bytes_left < fs->lfs_bsize ||
|
1998-03-01 05:20:01 +03:00
|
|
|
sp->sum_bytes_left < sizeof(ufs_daddr_t))
|
1994-06-08 15:41:58 +04:00
|
|
|
(void) lfs_writeseg(fs, sp);
|
|
|
|
|
|
|
|
/* Get next inode block. */
|
|
|
|
daddr = fs->lfs_offset;
|
|
|
|
fs->lfs_offset += fsbtodb(fs, 1);
|
|
|
|
sp->ibp = *sp->cbpp++ =
|
1999-04-12 04:04:21 +04:00
|
|
|
getblk(VTOI(fs->lfs_ivnode)->i_devvp, daddr, fs->lfs_bsize, 0, 0);
|
|
|
|
gotblk++;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Zero out inode numbers */
|
|
|
|
for (i = 0; i < INOPB(fs); ++i)
|
|
|
|
((struct dinode *)sp->ibp->b_data)[i].di_inumber = 0;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
++sp->start_bpp;
|
|
|
|
fs->lfs_avail -= fsbtodb(fs, 1);
|
|
|
|
/* Set remaining space counters. */
|
|
|
|
sp->seg_bytes_left -= fs->lfs_bsize;
|
1998-03-01 05:20:01 +03:00
|
|
|
sp->sum_bytes_left -= sizeof(ufs_daddr_t);
|
|
|
|
ndx = LFS_SUMMARY_SIZE / sizeof(ufs_daddr_t) -
|
1999-03-10 03:20:00 +03:00
|
|
|
sp->ninodes / INOPB(fs) - 1;
|
1998-03-01 05:20:01 +03:00
|
|
|
((ufs_daddr_t *)(sp->segsum))[ndx] = daddr;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-06-16 02:25:41 +04:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Update the inode times and copy the inode onto the inode page. */
|
1997-06-13 12:59:51 +04:00
|
|
|
TIMEVAL_TO_TIMESPEC(&time, &ts);
|
1999-03-10 03:20:00 +03:00
|
|
|
LFS_ITIMES(ip, &ts, &ts, &ts);
|
1999-03-26 00:39:18 +03:00
|
|
|
|
1999-06-16 02:25:41 +04:00
|
|
|
/*
|
|
|
|
* If this is the Ifile, and we've already written the Ifile in this
|
|
|
|
* partial segment, just overwrite it (it's not on disk yet) and
|
|
|
|
* continue.
|
|
|
|
*
|
|
|
|
* XXX we know that the bp that we get the second time around has
|
|
|
|
* already been gathered.
|
|
|
|
*/
|
|
|
|
if(ip->i_number == LFS_IFILE_INUM && sp->idp) {
|
|
|
|
*(sp->idp) = ip->i_din.ffs_din;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
bp = sp->ibp;
|
2000-07-03 05:45:46 +04:00
|
|
|
cdp = ((struct dinode *)bp->b_data) + (sp->ninodes % INOPB(fs));
|
|
|
|
*cdp = ip->i_din.ffs_din;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are cleaning, ensure that we don't write UNWRITTEN disk
|
|
|
|
* addresses to disk.
|
|
|
|
*/
|
|
|
|
if (ip->i_lfs_effnblks != ip->i_ffs_blocks) {
|
2000-07-05 02:30:37 +04:00
|
|
|
#ifdef DEBUG_LFS
|
2000-07-03 05:45:46 +04:00
|
|
|
printf("lfs_writeinode: cleansing ino %d (%d != %d)\n",
|
|
|
|
ip->i_number, ip->i_lfs_effnblks, ip->i_ffs_blocks);
|
2000-07-05 02:30:37 +04:00
|
|
|
#endif
|
2000-07-03 05:45:46 +04:00
|
|
|
for (daddrp = cdp->di_db; daddrp < cdp->di_ib + NIADDR;
|
|
|
|
daddrp++) {
|
|
|
|
if (*daddrp == UNWRITTEN) {
|
2000-07-03 12:20:58 +04:00
|
|
|
#ifdef DEBUG_LFS
|
2000-07-03 05:45:46 +04:00
|
|
|
printf("lfs_writeinode: wiping UNWRITTEN\n");
|
|
|
|
#endif
|
|
|
|
*daddrp = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-06-16 02:25:41 +04:00
|
|
|
|
2000-07-05 02:30:37 +04:00
|
|
|
if(ip->i_flag & IN_CLEANING)
|
2000-07-06 02:25:43 +04:00
|
|
|
LFS_CLR_UINO(ip, IN_CLEANING);
|
2000-07-05 02:30:37 +04:00
|
|
|
else {
|
2000-07-06 02:25:43 +04:00
|
|
|
/* XXX IN_ALLMOD */
|
|
|
|
LFS_CLR_UINO(ip, IN_ACCESSED | IN_ACCESS | IN_CHANGE |
|
|
|
|
IN_UPDATE);
|
|
|
|
if (ip->i_lfs_effnblks == ip->i_ffs_blocks)
|
|
|
|
LFS_CLR_UINO(ip, IN_MODIFIED);
|
2000-11-27 06:33:57 +03:00
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
else
|
|
|
|
printf("lfs_writeinode: ino %d: real blks=%d, "
|
|
|
|
"eff=%d\n", ip->i_number, ip->i_ffs_blocks,
|
|
|
|
ip->i_lfs_effnblks);
|
|
|
|
#endif
|
2000-07-05 02:30:37 +04:00
|
|
|
}
|
|
|
|
|
1999-06-16 02:25:41 +04:00
|
|
|
if(ip->i_number == LFS_IFILE_INUM) /* We know sp->idp == NULL */
|
2000-07-03 05:45:46 +04:00
|
|
|
sp->idp = ((struct dinode *)bp->b_data) +
|
|
|
|
(sp->ninodes % INOPB(fs));
|
1999-04-12 04:04:21 +04:00
|
|
|
if(gotblk) {
|
2000-11-17 22:14:41 +03:00
|
|
|
LFS_LOCK_BUF(bp);
|
1999-04-12 04:04:21 +04:00
|
|
|
brelse(bp);
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Increment inode count in segment summary block. */
|
|
|
|
++((SEGSUM *)(sp->segsum))->ss_ninos;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* If this page is full, set flag to allocate a new page. */
|
|
|
|
if (++sp->ninodes % INOPB(fs) == 0)
|
|
|
|
sp->ibp = NULL;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* If updating the ifile, update the super-block. Update the disk
|
|
|
|
* address and access times for this inode in the ifile.
|
|
|
|
*/
|
|
|
|
ino = ip->i_number;
|
|
|
|
if (ino == LFS_IFILE_INUM) {
|
|
|
|
daddr = fs->lfs_idaddr;
|
|
|
|
fs->lfs_idaddr = bp->b_blkno;
|
|
|
|
} else {
|
|
|
|
LFS_IENTRY(ifp, fs, ino, ibp);
|
|
|
|
daddr = ifp->if_daddr;
|
|
|
|
ifp->if_daddr = bp->b_blkno;
|
1999-09-04 02:48:51 +04:00
|
|
|
#ifdef LFS_DEBUG_NEXTFREE
|
|
|
|
if(ino > 3 && ifp->if_nextfree) {
|
|
|
|
vprint("lfs_writeinode",ITOV(ip));
|
|
|
|
printf("lfs_writeinode: updating free ino %d\n",
|
|
|
|
ip->i_number);
|
|
|
|
}
|
|
|
|
#endif
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
error = VOP_BWRITE(ibp); /* Ifile */
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
2000-11-12 05:13:51 +03:00
|
|
|
* Account the inode: it no longer belongs to its former segment,
|
|
|
|
* though it will not belong to the new segment until that segment
|
|
|
|
* is actually written.
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
#ifdef DEBUG
|
2000-11-12 05:13:51 +03:00
|
|
|
/*
|
|
|
|
* The inode's last address should not be in the current partial
|
|
|
|
* segment, except under exceptional circumstances (lfs_writevnodes
|
|
|
|
* had to start over, and in the meantime more blocks were written
|
|
|
|
* to a vnode). Although the previous inode won't be accounted in
|
|
|
|
* su_nbytes until lfs_writeseg, this shouldn't be a problem as we
|
|
|
|
* have more data blocks in the current partial segment.
|
|
|
|
*/
|
2000-06-07 00:19:14 +04:00
|
|
|
if (daddr >= fs->lfs_lastpseg && daddr <= bp->b_blkno)
|
|
|
|
printf("lfs_writeinode: last inode addr in current pseg "
|
2000-07-03 05:45:46 +04:00
|
|
|
"(ino %d daddr 0x%x)\n", ino, daddr);
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
#endif
|
2000-06-07 00:19:14 +04:00
|
|
|
if (daddr != LFS_UNUSED_DADDR) {
|
1994-06-08 15:41:58 +04:00
|
|
|
LFS_SEGENTRY(sup, fs, datosn(fs, daddr), bp);
|
|
|
|
#ifdef DIAGNOSTIC
|
1998-10-23 04:32:35 +04:00
|
|
|
if (sup->su_nbytes < DINODE_SIZE) {
|
2000-07-03 05:45:46 +04:00
|
|
|
printf("lfs_writeinode: negative bytes "
|
|
|
|
"(segment %d short by %d)\n",
|
|
|
|
datosn(fs, daddr),
|
|
|
|
(int)DINODE_SIZE - sup->su_nbytes);
|
1999-06-16 02:25:41 +04:00
|
|
|
panic("lfs_writeinode: negative bytes");
|
|
|
|
sup->su_nbytes = DINODE_SIZE;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
#endif
|
1998-10-23 04:32:35 +04:00
|
|
|
sup->su_nbytes -= DINODE_SIZE;
|
1994-06-08 15:41:58 +04:00
|
|
|
redo_ifile =
|
1999-03-10 03:20:00 +03:00
|
|
|
(ino == LFS_IFILE_INUM && !(bp->b_flags & B_GATHERED));
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
error = VOP_BWRITE(bp); /* Ifile */
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
return (redo_ifile);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_gatherblock(sp, bp, sptr)
|
|
|
|
struct segment *sp;
|
|
|
|
struct buf *bp;
|
|
|
|
int *sptr;
|
|
|
|
{
|
|
|
|
struct lfs *fs;
|
|
|
|
int version;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* If full, finish this segment. We may be doing I/O, so
|
|
|
|
* release and reacquire the splbio().
|
|
|
|
*/
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sp->vp == NULL)
|
|
|
|
panic ("lfs_gatherblock: Null vp in segment");
|
|
|
|
#endif
|
|
|
|
fs = sp->fs;
|
1998-03-01 05:20:01 +03:00
|
|
|
if (sp->sum_bytes_left < sizeof(ufs_daddr_t) ||
|
|
|
|
sp->seg_bytes_left < bp->b_bcount) {
|
1994-06-08 15:41:58 +04:00
|
|
|
if (sptr)
|
|
|
|
splx(*sptr);
|
|
|
|
lfs_updatemeta(sp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
version = sp->fip->fi_version;
|
|
|
|
(void) lfs_writeseg(fs, sp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->fip->fi_version = version;
|
|
|
|
sp->fip->fi_ino = VTOI(sp->vp)->i_number;
|
|
|
|
/* Add the current file to the segment summary. */
|
|
|
|
++((SEGSUM *)(sp->segsum))->ss_nfinfo;
|
|
|
|
sp->sum_bytes_left -=
|
1999-03-10 03:20:00 +03:00
|
|
|
sizeof(struct finfo) - sizeof(ufs_daddr_t);
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
if (sptr)
|
|
|
|
*sptr = splbio();
|
|
|
|
return(1);
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if(bp->b_flags & B_GATHERED) {
|
|
|
|
printf("lfs_gatherblock: already gathered! Ino %d, lbn %d\n",
|
|
|
|
sp->fip->fi_ino, bp->b_lblkno);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Insert into the buffer list, update the FINFO block. */
|
|
|
|
bp->b_flags |= B_GATHERED;
|
|
|
|
*sp->cbpp++ = bp;
|
|
|
|
sp->fip->fi_blocks[sp->fip->fi_nblocks++] = bp->b_lblkno;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
sp->sum_bytes_left -= sizeof(ufs_daddr_t);
|
|
|
|
sp->seg_bytes_left -= bp->b_bcount;
|
1994-06-08 15:41:58 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
int
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_gather(fs, sp, vp, match)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct segment *sp;
|
|
|
|
struct vnode *vp;
|
|
|
|
int (*match) __P((struct lfs *, struct buf *));
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
1999-03-10 03:20:00 +03:00
|
|
|
int s, count=0;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->vp = vp;
|
|
|
|
s = splbio();
|
1998-03-01 05:20:01 +03:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifndef LFS_NO_BACKBUF_HACK
|
|
|
|
loop: for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = bp->b_vnbufs.le_next) {
|
|
|
|
#else /* LFS_NO_BACKBUF_HACK */
|
|
|
|
/* This is a hack to see if ordering the blocks in LFS makes a difference. */
|
|
|
|
# define BUF_OFFSET (((void *)&bp->b_vnbufs.le_next) - (void *)bp)
|
|
|
|
# define BACK_BUF(BP) ((struct buf *)(((void *)BP->b_vnbufs.le_prev) - BUF_OFFSET))
|
|
|
|
# define BEG_OF_LIST ((struct buf *)(((void *)&vp->v_dirtyblkhd.lh_first) - BUF_OFFSET))
|
1998-03-01 05:20:01 +03:00
|
|
|
/* Find last buffer. */
|
1999-03-10 03:20:00 +03:00
|
|
|
loop: for (bp = vp->v_dirtyblkhd.lh_first; bp && bp->b_vnbufs.le_next != NULL;
|
1998-03-01 05:20:01 +03:00
|
|
|
bp = bp->b_vnbufs.le_next);
|
|
|
|
for (; bp && bp != BEG_OF_LIST; bp = BACK_BUF(bp)) {
|
1999-03-10 03:20:00 +03:00
|
|
|
#endif /* LFS_NO_BACKBUF_HACK */
|
|
|
|
if ((bp->b_flags & (B_BUSY|B_GATHERED)) || !match(fs, bp))
|
1994-06-08 15:41:58 +04:00
|
|
|
continue;
|
1999-09-04 02:48:51 +04:00
|
|
|
if(vp->v_type == VBLK) {
|
|
|
|
/* For block devices, just write the blocks. */
|
|
|
|
/* XXX Do we really need to even do this? */
|
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
if(count==0)
|
|
|
|
printf("BLK(");
|
|
|
|
printf(".");
|
|
|
|
#endif
|
|
|
|
/* Get the block before bwrite, so we don't corrupt the free list */
|
|
|
|
bp->b_flags |= B_BUSY;
|
|
|
|
bremfree(bp);
|
|
|
|
bwrite(bp);
|
|
|
|
} else {
|
1994-06-08 15:41:58 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2000-05-06 00:59:20 +04:00
|
|
|
if ((bp->b_flags & (B_CALL|B_INVAL))==B_INVAL) {
|
|
|
|
printf("lfs_gather: lbn %d is B_INVAL\n",
|
|
|
|
bp->b_lblkno);
|
|
|
|
VOP_PRINT(bp->b_vp);
|
|
|
|
}
|
1999-09-04 02:48:51 +04:00
|
|
|
if (!(bp->b_flags & B_DELWRI))
|
|
|
|
panic("lfs_gather: bp not B_DELWRI");
|
|
|
|
if (!(bp->b_flags & B_LOCKED)) {
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
printf("lfs_gather: lbn %d blk %d"
|
|
|
|
" not B_LOCKED\n", bp->b_lblkno,
|
|
|
|
bp->b_blkno);
|
1999-09-04 02:48:51 +04:00
|
|
|
VOP_PRINT(bp->b_vp);
|
|
|
|
panic("lfs_gather: bp not B_LOCKED");
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
#endif
|
1999-09-04 02:48:51 +04:00
|
|
|
if (lfs_gatherblock(sp, bp, &s)) {
|
|
|
|
goto loop;
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1999-09-04 02:48:51 +04:00
|
|
|
count++;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
1999-09-04 02:48:51 +04:00
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
if(vp->v_type == VBLK && count)
|
|
|
|
printf(")\n");
|
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_updatemeta(sp);
|
|
|
|
sp->vp = NULL;
|
1999-03-10 03:20:00 +03:00
|
|
|
return count;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the metadata that points to the blocks listed in the FINFO
|
|
|
|
* array.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_updatemeta(sp)
|
|
|
|
struct segment *sp;
|
|
|
|
{
|
|
|
|
SEGUSE *sup;
|
2000-07-05 02:30:37 +04:00
|
|
|
struct buf *bp;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct lfs *fs;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct indir a[NIADDR + 2], *ap;
|
|
|
|
struct inode *ip;
|
1998-03-01 05:20:01 +03:00
|
|
|
ufs_daddr_t daddr, lbn, off;
|
2000-05-06 00:59:20 +04:00
|
|
|
daddr_t ooff;
|
1998-03-01 05:20:01 +03:00
|
|
|
int error, i, nblocks, num;
|
2000-07-03 05:45:46 +04:00
|
|
|
int bb;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
vp = sp->vp;
|
|
|
|
nblocks = &sp->fip->fi_blocks[sp->fip->fi_nblocks] - sp->start_lbp;
|
1998-03-01 05:20:01 +03:00
|
|
|
if (nblocks < 0)
|
|
|
|
panic("This is a bad thing\n");
|
1994-06-08 15:41:58 +04:00
|
|
|
if (vp == NULL || nblocks == 0)
|
|
|
|
return;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Sort the blocks. */
|
1999-03-10 03:20:00 +03:00
|
|
|
/*
|
|
|
|
* XXX KS - We have to sort even if the blocks come from the
|
|
|
|
* cleaner, because there might be other pending blocks on the
|
|
|
|
* same inode...and if we don't sort, and there are fragments
|
|
|
|
* present, blocks may be written in the wrong place.
|
|
|
|
*/
|
|
|
|
/* if (!(sp->seg_flags & SEGM_CLEAN)) */
|
|
|
|
lfs_shellsort(sp->start_bpp, sp->start_lbp, nblocks);
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
/*
|
|
|
|
* Record the length of the last block in case it's a fragment.
|
|
|
|
* If there are indirect blocks present, they sort last. An
|
|
|
|
* indirect block will be lfs_bsize and its presence indicates
|
|
|
|
* that you cannot have fragments.
|
|
|
|
*/
|
|
|
|
sp->fip->fi_lastlength = sp->start_bpp[nblocks - 1]->b_bcount;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Assign disk addresses, and update references to the logical
|
|
|
|
* block and the segment usage information.
|
|
|
|
*/
|
|
|
|
fs = sp->fs;
|
|
|
|
for (i = nblocks; i--; ++sp->start_bpp) {
|
|
|
|
lbn = *sp->start_lbp++;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
(*sp->start_bpp)->b_blkno = off = fs->lfs_offset;
|
1999-03-26 00:54:10 +03:00
|
|
|
if((*sp->start_bpp)->b_blkno == (*sp->start_bpp)->b_lblkno) {
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
printf("lfs_updatemeta: ino %d blk %d"
|
|
|
|
" has same lbn and daddr\n",
|
|
|
|
VTOI(vp)->i_number, off);
|
1999-03-26 00:54:10 +03:00
|
|
|
}
|
2001-01-09 08:05:35 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if((*sp->start_bpp)->b_bcount < fs->lfs_bsize && i != 0)
|
|
|
|
panic("lfs_updatemeta: fragment is not last block\n");
|
|
|
|
#endif
|
2000-07-03 05:45:46 +04:00
|
|
|
bb = fragstodb(fs, numfrags(fs, (*sp->start_bpp)->b_bcount));
|
|
|
|
fs->lfs_offset += bb;
|
1996-02-10 01:28:45 +03:00
|
|
|
error = ufs_bmaparray(vp, lbn, &daddr, a, &num, NULL);
|
|
|
|
if (error)
|
1994-06-08 15:41:58 +04:00
|
|
|
panic("lfs_updatemeta: ufs_bmaparray %d", error);
|
|
|
|
ip = VTOI(vp);
|
|
|
|
switch (num) {
|
|
|
|
case 0:
|
2000-05-06 00:59:20 +04:00
|
|
|
ooff = ip->i_ffs_db[lbn];
|
2000-07-05 02:30:37 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ooff == 0) {
|
2000-07-03 05:45:46 +04:00
|
|
|
printf("lfs_updatemeta[1]: warning: writing "
|
2000-07-05 02:30:37 +04:00
|
|
|
"ino %d lbn %d at 0x%x, was 0x0\n",
|
|
|
|
ip->i_number, lbn, off);
|
2000-07-03 05:45:46 +04:00
|
|
|
}
|
2000-07-05 02:30:37 +04:00
|
|
|
#endif
|
|
|
|
if (ooff == UNWRITTEN)
|
|
|
|
ip->i_ffs_blocks += bb;
|
|
|
|
ip->i_ffs_db[lbn] = off;
|
1994-06-08 15:41:58 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
2000-05-06 00:59:20 +04:00
|
|
|
ooff = ip->i_ffs_ib[a[0].in_off];
|
2000-07-05 02:30:37 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ooff == 0) {
|
2000-07-03 05:45:46 +04:00
|
|
|
printf("lfs_updatemeta[2]: warning: writing "
|
2000-07-05 02:30:37 +04:00
|
|
|
"ino %d lbn %d at 0x%x, was 0x0\n",
|
|
|
|
ip->i_number, lbn, off);
|
2000-07-03 05:45:46 +04:00
|
|
|
}
|
2000-07-05 02:30:37 +04:00
|
|
|
#endif
|
|
|
|
if (ooff == UNWRITTEN)
|
|
|
|
ip->i_ffs_blocks += bb;
|
|
|
|
ip->i_ffs_ib[a[0].in_off] = off;
|
1994-06-08 15:41:58 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ap = &a[num - 1];
|
|
|
|
if (bread(vp, ap->in_lbn, fs->lfs_bsize, NOCRED, &bp))
|
|
|
|
panic("lfs_updatemeta: bread bno %d",
|
1999-03-10 03:20:00 +03:00
|
|
|
ap->in_lbn);
|
2000-07-05 02:30:37 +04:00
|
|
|
|
2000-05-06 00:59:20 +04:00
|
|
|
ooff = ((ufs_daddr_t *)bp->b_data)[ap->in_off];
|
2000-07-05 02:30:37 +04:00
|
|
|
#if DEBUG
|
|
|
|
if (ooff == 0) {
|
2000-07-03 05:45:46 +04:00
|
|
|
printf("lfs_updatemeta[3]: warning: writing "
|
2000-07-05 02:30:37 +04:00
|
|
|
"ino %d lbn %d at 0x%x, was 0x0\n",
|
|
|
|
ip->i_number, lbn, off);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
2000-07-05 02:30:37 +04:00
|
|
|
#endif
|
|
|
|
if (ooff == UNWRITTEN)
|
|
|
|
ip->i_ffs_blocks += bb;
|
|
|
|
((ufs_daddr_t *)bp->b_data)[ap->in_off] = off;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
(void) VOP_BWRITE(bp);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
2000-07-05 02:30:37 +04:00
|
|
|
#ifdef DEBUG
|
2000-06-07 00:19:14 +04:00
|
|
|
if (daddr >= fs->lfs_lastpseg && daddr <= off) {
|
|
|
|
printf("lfs_updatemeta: ino %d, lbn %d, addr = %x "
|
|
|
|
"in same pseg\n", VTOI(sp->vp)->i_number,
|
|
|
|
(*sp->start_bpp)->b_lblkno, daddr);
|
|
|
|
}
|
2000-07-05 02:30:37 +04:00
|
|
|
#endif
|
|
|
|
/* Update segment usage information. */
|
2000-06-07 00:19:14 +04:00
|
|
|
if (daddr > 0) {
|
1994-06-08 15:41:58 +04:00
|
|
|
LFS_SEGENTRY(sup, fs, datosn(fs, daddr), bp);
|
|
|
|
#ifdef DIAGNOSTIC
|
1998-03-01 05:20:01 +03:00
|
|
|
if (sup->su_nbytes < (*sp->start_bpp)->b_bcount) {
|
1994-06-08 15:41:58 +04:00
|
|
|
/* XXX -- Change to a panic. */
|
2000-07-05 02:30:37 +04:00
|
|
|
printf("lfs_updatemeta: negative bytes "
|
|
|
|
"(segment %d short by %ld)\n",
|
|
|
|
datosn(fs, daddr),
|
|
|
|
(*sp->start_bpp)->b_bcount -
|
|
|
|
sup->su_nbytes);
|
|
|
|
printf("lfs_updatemeta: ino %d, lbn %d, "
|
|
|
|
"addr = %x\n", VTOI(sp->vp)->i_number,
|
|
|
|
(*sp->start_bpp)->b_lblkno, daddr);
|
1999-06-16 02:25:41 +04:00
|
|
|
panic("lfs_updatemeta: negative bytes");
|
|
|
|
sup->su_nbytes = (*sp->start_bpp)->b_bcount;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
#endif
|
1998-03-01 05:20:01 +03:00
|
|
|
sup->su_nbytes -= (*sp->start_bpp)->b_bcount;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
error = VOP_BWRITE(bp); /* Ifile */
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start a new segment.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lfs_initseg(fs)
|
|
|
|
struct lfs *fs;
|
|
|
|
{
|
|
|
|
struct segment *sp;
|
|
|
|
SEGUSE *sup;
|
|
|
|
SEGSUM *ssp;
|
|
|
|
struct buf *bp;
|
|
|
|
int repeat;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
sp = fs->lfs_sp;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
repeat = 0;
|
|
|
|
/* Advance to the next segment. */
|
|
|
|
if (!LFS_PARTIAL_FITS(fs)) {
|
2000-07-05 02:30:37 +04:00
|
|
|
/* lfs_avail eats the remaining space */
|
|
|
|
fs->lfs_avail -= fs->lfs_dbpseg - (fs->lfs_offset -
|
|
|
|
fs->lfs_curseg);
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Wake up any cleaning procs waiting on this file system. */
|
|
|
|
wakeup(&lfs_allclean_wakeup);
|
1998-03-01 05:20:01 +03:00
|
|
|
wakeup(&fs->lfs_nextseg);
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_newseg(fs);
|
|
|
|
repeat = 1;
|
|
|
|
fs->lfs_offset = fs->lfs_curseg;
|
|
|
|
sp->seg_number = datosn(fs, fs->lfs_curseg);
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
sp->seg_bytes_left = dbtob(fs->lfs_dbpseg);
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* If the segment contains a superblock, update the offset
|
|
|
|
* and summary address to skip over it.
|
|
|
|
*/
|
|
|
|
LFS_SEGENTRY(sup, fs, sp->seg_number, bp);
|
|
|
|
if (sup->su_flags & SEGUSE_SUPERBLOCK) {
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
fs->lfs_offset += btodb(LFS_SBPAD);
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->seg_bytes_left -= LFS_SBPAD;
|
|
|
|
}
|
|
|
|
brelse(bp);
|
|
|
|
} else {
|
|
|
|
sp->seg_number = datosn(fs, fs->lfs_curseg);
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
sp->seg_bytes_left = dbtob(fs->lfs_dbpseg -
|
|
|
|
(fs->lfs_offset - fs->lfs_curseg));
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
fs->lfs_lastpseg = fs->lfs_offset;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->fs = fs;
|
|
|
|
sp->ibp = NULL;
|
1999-06-16 02:25:41 +04:00
|
|
|
sp->idp = NULL;
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->ninodes = 0;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Get a new buffer for SEGSUM and enter it into the buffer list. */
|
|
|
|
sp->cbpp = sp->bpp;
|
1999-03-10 03:20:00 +03:00
|
|
|
*sp->cbpp = lfs_newbuf(VTOI(fs->lfs_ivnode)->i_devvp,
|
|
|
|
fs->lfs_offset, LFS_SUMMARY_SIZE);
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->segsum = (*sp->cbpp)->b_data;
|
|
|
|
bzero(sp->segsum, LFS_SUMMARY_SIZE);
|
|
|
|
sp->start_bpp = ++sp->cbpp;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
fs->lfs_offset += btodb(LFS_SUMMARY_SIZE);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Set point to SEGSUM, initialize it. */
|
|
|
|
ssp = sp->segsum;
|
|
|
|
ssp->ss_next = fs->lfs_nextseg;
|
|
|
|
ssp->ss_nfinfo = ssp->ss_ninos = 0;
|
1998-03-01 05:20:01 +03:00
|
|
|
ssp->ss_magic = SS_MAGIC;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
/* Set pointer to first FINFO, initialize it. */
|
1994-08-21 07:15:32 +04:00
|
|
|
sp->fip = (struct finfo *)((caddr_t)sp->segsum + sizeof(SEGSUM));
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->fip->fi_nblocks = 0;
|
|
|
|
sp->start_lbp = &sp->fip->fi_blocks[0];
|
1998-03-01 05:20:01 +03:00
|
|
|
sp->fip->fi_lastlength = 0;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
sp->seg_bytes_left -= LFS_SUMMARY_SIZE;
|
|
|
|
sp->sum_bytes_left = LFS_SUMMARY_SIZE - sizeof(SEGSUM);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
return(repeat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the next segment to write.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_newseg(fs)
|
|
|
|
struct lfs *fs;
|
|
|
|
{
|
|
|
|
CLEANERINFO *cip;
|
|
|
|
SEGUSE *sup;
|
|
|
|
struct buf *bp;
|
|
|
|
int curseg, isdirty, sn;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
LFS_SEGENTRY(sup, fs, datosn(fs, fs->lfs_nextseg), bp);
|
|
|
|
sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
|
1994-06-08 15:41:58 +04:00
|
|
|
sup->su_nbytes = 0;
|
|
|
|
sup->su_nsums = 0;
|
|
|
|
sup->su_ninos = 0;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
(void) VOP_BWRITE(bp); /* Ifile */
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
LFS_CLEANERINFO(cip, fs, bp);
|
|
|
|
--cip->clean;
|
|
|
|
++cip->dirty;
|
1999-03-10 03:20:00 +03:00
|
|
|
fs->lfs_nclean = cip->clean;
|
2000-11-12 10:58:36 +03:00
|
|
|
LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
fs->lfs_lastseg = fs->lfs_curseg;
|
|
|
|
fs->lfs_curseg = fs->lfs_nextseg;
|
|
|
|
for (sn = curseg = datosn(fs, fs->lfs_curseg);;) {
|
|
|
|
sn = (sn + 1) % fs->lfs_nseg;
|
|
|
|
if (sn == curseg)
|
|
|
|
panic("lfs_nextseg: no clean segments");
|
|
|
|
LFS_SEGENTRY(sup, fs, sn, bp);
|
|
|
|
isdirty = sup->su_flags & SEGUSE_DIRTY;
|
|
|
|
brelse(bp);
|
|
|
|
if (!isdirty)
|
|
|
|
break;
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
++fs->lfs_nactive;
|
|
|
|
fs->lfs_nextseg = sntoda(fs, sn);
|
1999-03-10 03:20:00 +03:00
|
|
|
if(lfs_dostats) {
|
|
|
|
++lfs_stats.segsused;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_writeseg(fs, sp)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct segment *sp;
|
|
|
|
{
|
2000-07-03 05:45:46 +04:00
|
|
|
struct buf **bpp, *bp, *cbp, *newbp;
|
1994-06-08 15:41:58 +04:00
|
|
|
SEGUSE *sup;
|
|
|
|
SEGSUM *ssp;
|
|
|
|
dev_t i_dev;
|
|
|
|
u_long *datap, *dp;
|
1998-03-01 05:20:01 +03:00
|
|
|
int do_again, i, nblocks, s;
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef LFS_TRACK_IOS
|
|
|
|
int j;
|
|
|
|
#endif
|
1996-02-10 01:28:45 +03:00
|
|
|
int (*strategy)__P((void *));
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_strategy_args vop_strategy_a;
|
|
|
|
u_short ninos;
|
1999-03-10 03:20:00 +03:00
|
|
|
struct vnode *devvp;
|
1994-06-08 15:41:58 +04:00
|
|
|
char *p;
|
1999-03-10 03:20:00 +03:00
|
|
|
struct vnode *vn;
|
1999-04-12 04:25:13 +04:00
|
|
|
struct inode *ip;
|
2000-07-03 05:45:46 +04:00
|
|
|
daddr_t *daddrp;
|
2000-07-05 02:30:37 +04:00
|
|
|
int changed;
|
1999-03-10 03:20:00 +03:00
|
|
|
#if defined(DEBUG) && defined(LFS_PROPELLER)
|
|
|
|
static int propeller;
|
|
|
|
char propstring[4] = "-\\|/";
|
|
|
|
|
|
|
|
printf("%c\b",propstring[propeller++]);
|
|
|
|
if(propeller==4)
|
|
|
|
propeller = 0;
|
|
|
|
#endif
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* If there are no buffers other than the segment summary to write
|
|
|
|
* and it is not a checkpoint, don't do anything. On a checkpoint,
|
|
|
|
* even if there aren't any buffers, you need to write the superblock.
|
|
|
|
*/
|
|
|
|
if ((nblocks = sp->cbpp - sp->bpp) == 1)
|
|
|
|
return (0);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1999-06-16 02:25:41 +04:00
|
|
|
i_dev = VTOI(fs->lfs_ivnode)->i_dev;
|
|
|
|
devvp = VTOI(fs->lfs_ivnode)->i_devvp;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Update the segment usage information. */
|
|
|
|
LFS_SEGENTRY(sup, fs, sp->seg_number, bp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
/* Loop through all blocks, except the segment summary. */
|
1999-06-16 02:25:41 +04:00
|
|
|
for (bpp = sp->bpp; ++bpp < sp->cbpp; ) {
|
|
|
|
if((*bpp)->b_vp != devvp)
|
|
|
|
sup->su_nbytes += (*bpp)->b_bcount;
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
ssp = (SEGSUM *)sp->segsum;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
ninos = (ssp->ss_ninos + INOPB(fs) - 1) / INOPB(fs);
|
1999-06-16 02:25:41 +04:00
|
|
|
sup->su_nbytes += ssp->ss_ninos * DINODE_SIZE;
|
|
|
|
/* sup->su_nbytes += LFS_SUMMARY_SIZE; */
|
1994-06-08 15:41:58 +04:00
|
|
|
sup->su_lastmod = time.tv_sec;
|
|
|
|
sup->su_ninos += ninos;
|
|
|
|
++sup->su_nsums;
|
2000-07-05 02:30:37 +04:00
|
|
|
fs->lfs_dmeta += (btodb(LFS_SUMMARY_SIZE) + fsbtodb(fs, ninos));
|
|
|
|
fs->lfs_avail -= btodb(LFS_SUMMARY_SIZE);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
do_again = !(bp->b_flags & B_GATHERED);
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
(void)VOP_BWRITE(bp); /* Ifile */
|
2000-07-03 05:45:46 +04:00
|
|
|
/*
|
|
|
|
* Mark blocks B_BUSY, to prevent then from being changed between
|
|
|
|
* the checksum computation and the actual write.
|
|
|
|
*
|
|
|
|
* If we are cleaning, check indirect blocks for UNWRITTEN, and if
|
|
|
|
* there are any, replace them with copies that have UNASSIGNED
|
|
|
|
* instead.
|
|
|
|
*/
|
|
|
|
for (bpp = sp->bpp, i = nblocks - 1; i--;) {
|
|
|
|
++bpp;
|
|
|
|
if((*bpp)->b_flags & B_CALL)
|
|
|
|
continue;
|
|
|
|
bp = *bpp;
|
|
|
|
again:
|
|
|
|
s = splbio();
|
|
|
|
if(bp->b_flags & B_BUSY) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("lfs_writeseg: avoiding potential data "
|
|
|
|
"summary corruption for ino %d, lbn %d\n",
|
|
|
|
VTOI(bp->b_vp)->i_number, bp->b_lblkno);
|
|
|
|
#endif
|
|
|
|
bp->b_flags |= B_WANTED;
|
|
|
|
tsleep(bp, (PRIBIO + 1), "lfs_writeseg", 0);
|
|
|
|
splx(s);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
bp->b_flags |= B_BUSY;
|
|
|
|
splx(s);
|
|
|
|
/* Check and replace indirect block UNWRITTEN bogosity */
|
|
|
|
if(bp->b_lblkno < 0 && bp->b_vp != devvp && bp->b_vp &&
|
|
|
|
VTOI(bp->b_vp)->i_ffs_blocks !=
|
|
|
|
VTOI(bp->b_vp)->i_lfs_effnblks) {
|
2000-07-03 12:20:58 +04:00
|
|
|
#ifdef DEBUG_LFS
|
2000-07-03 05:45:46 +04:00
|
|
|
printf("lfs_writeseg: cleansing ino %d (%d != %d)\n",
|
|
|
|
VTOI(bp->b_vp)->i_number,
|
|
|
|
VTOI(bp->b_vp)->i_lfs_effnblks,
|
|
|
|
VTOI(bp->b_vp)->i_ffs_blocks);
|
2000-07-03 12:20:58 +04:00
|
|
|
#endif
|
2000-07-03 05:45:46 +04:00
|
|
|
/* Make a copy we'll make changes to */
|
|
|
|
newbp = lfs_newbuf(bp->b_vp, bp->b_lblkno,
|
|
|
|
bp->b_bcount);
|
|
|
|
newbp->b_blkno = bp->b_blkno;
|
|
|
|
memcpy(newbp->b_data, bp->b_data,
|
|
|
|
newbp->b_bcount);
|
|
|
|
*bpp = newbp;
|
|
|
|
|
2000-07-05 02:30:37 +04:00
|
|
|
changed = 0;
|
2000-07-03 05:45:46 +04:00
|
|
|
for (daddrp = (daddr_t *)(newbp->b_data);
|
|
|
|
daddrp < (daddr_t *)(newbp->b_data +
|
|
|
|
newbp->b_bcount); daddrp++) {
|
|
|
|
if (*daddrp == UNWRITTEN) {
|
2000-07-05 02:30:37 +04:00
|
|
|
++changed;
|
2000-07-03 12:20:58 +04:00
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
printf("lfs_writeseg: replacing UNWRITTEN\n");
|
2000-07-03 05:45:46 +04:00
|
|
|
#endif
|
|
|
|
*daddrp = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-07-05 02:30:37 +04:00
|
|
|
/*
|
|
|
|
* Get rid of the old buffer. Don't mark it clean,
|
|
|
|
* though, if it still has dirty data on it.
|
|
|
|
*/
|
|
|
|
if (changed) {
|
|
|
|
bp->b_flags &= ~(B_ERROR | B_GATHERED);
|
|
|
|
if (bp->b_flags & B_CALL)
|
|
|
|
lfs_freebuf(bp);
|
2000-09-09 08:13:43 +04:00
|
|
|
else {
|
|
|
|
/* Still on free list, leave it there */
|
|
|
|
s = splbio();
|
|
|
|
bp->b_flags &= ~B_BUSY;
|
|
|
|
if (bp->b_flags & B_WANTED)
|
|
|
|
wakeup(bp);
|
|
|
|
splx(s);
|
2000-11-17 22:14:41 +03:00
|
|
|
/*
|
|
|
|
* We have to re-decrement lfs_avail
|
|
|
|
* since this block is going to come
|
|
|
|
* back around to us in the next
|
|
|
|
* segment.
|
|
|
|
*/
|
|
|
|
fs->lfs_avail -= btodb(bp->b_bcount);
|
2000-09-09 08:13:43 +04:00
|
|
|
}
|
2000-07-05 02:30:37 +04:00
|
|
|
} else {
|
|
|
|
bp->b_flags &= ~(B_ERROR | B_READ | B_DELWRI |
|
2000-11-17 22:14:41 +03:00
|
|
|
B_GATHERED);
|
|
|
|
LFS_UNLOCK_BUF(bp);
|
2000-07-05 02:30:37 +04:00
|
|
|
if (bp->b_flags & B_CALL)
|
|
|
|
lfs_freebuf(bp);
|
|
|
|
else {
|
|
|
|
bremfree(bp);
|
|
|
|
bp->b_flags |= B_DONE;
|
|
|
|
reassignbuf(bp, bp->b_vp);
|
|
|
|
brelse(bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-03 05:45:46 +04:00
|
|
|
}
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Compute checksum across data and then across summary; the first
|
|
|
|
* block (the summary block) is skipped. Set the create time here
|
|
|
|
* so that it's guaranteed to be later than the inode mod times.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* Fix this to do it inline, instead of malloc/copy.
|
|
|
|
*/
|
|
|
|
datap = dp = malloc(nblocks * sizeof(u_long), M_SEGMENT, M_WAITOK);
|
|
|
|
for (bpp = sp->bpp, i = nblocks - 1; i--;) {
|
1999-03-10 03:20:00 +03:00
|
|
|
if (((*++bpp)->b_flags & (B_CALL|B_INVAL)) == (B_CALL|B_INVAL)) {
|
1994-06-08 15:41:58 +04:00
|
|
|
if (copyin((*bpp)->b_saveaddr, dp++, sizeof(u_long)))
|
2000-07-03 05:45:46 +04:00
|
|
|
panic("lfs_writeseg: copyin failed [1]: "
|
|
|
|
"ino %d blk %d",
|
|
|
|
VTOI((*bpp)->b_vp)->i_number,
|
|
|
|
(*bpp)->b_lblkno);
|
|
|
|
} else
|
1994-06-08 15:41:58 +04:00
|
|
|
*dp++ = ((u_long *)(*bpp)->b_data)[0];
|
|
|
|
}
|
|
|
|
ssp->ss_create = time.tv_sec;
|
|
|
|
ssp->ss_datasum = cksum(datap, (nblocks - 1) * sizeof(u_long));
|
|
|
|
ssp->ss_sumsum =
|
|
|
|
cksum(&ssp->ss_datasum, LFS_SUMMARY_SIZE - sizeof(ssp->ss_sumsum));
|
|
|
|
free(datap, M_SEGMENT);
|
2000-06-28 00:57:11 +04:00
|
|
|
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
fs->lfs_bfree -= (fsbtodb(fs, ninos) + btodb(LFS_SUMMARY_SIZE));
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
strategy = devvp->v_op[VOFFSET(vop_strategy)];
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When we simply write the blocks we lose a rotation for every block
|
|
|
|
* written. To avoid this problem, we allocate memory in chunks, copy
|
1999-03-10 03:20:00 +03:00
|
|
|
* the buffers into the chunk and write the chunk. CHUNKSIZE is the
|
1994-06-08 15:41:58 +04:00
|
|
|
* largest size I/O devices can handle.
|
2000-03-14 02:52:25 +03:00
|
|
|
* When the data is copied to the chunk, turn off the B_LOCKED bit
|
1994-06-08 15:41:58 +04:00
|
|
|
* and brelse the buffer (which will move them to the LRU list). Add
|
|
|
|
* the B_CALL flag to the buffer header so we can count I/O's for the
|
|
|
|
* checkpoints and so we can release the allocated memory.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* This should be removed if the new virtual memory system allows us to
|
|
|
|
* easily make the buffers contiguous in kernel memory and if that's
|
|
|
|
* fast enough.
|
|
|
|
*/
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
#define CHUNKSIZE MAXPHYS
|
|
|
|
|
|
|
|
if(devvp==NULL)
|
|
|
|
panic("devvp is NULL");
|
|
|
|
for (bpp = sp->bpp,i = nblocks; i;) {
|
|
|
|
cbp = lfs_newbuf(devvp, (*bpp)->b_blkno, CHUNKSIZE);
|
1994-06-08 15:41:58 +04:00
|
|
|
cbp->b_dev = i_dev;
|
|
|
|
cbp->b_flags |= B_ASYNC | B_BUSY;
|
1998-03-01 05:20:01 +03:00
|
|
|
cbp->b_bcount = 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-26 00:54:10 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
2000-09-10 01:03:31 +04:00
|
|
|
if(datosn(fs, (*bpp)->b_blkno + btodb((*bpp)->b_bcount) - 1) !=
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
datosn(fs, cbp->b_blkno)) {
|
1999-03-26 00:54:10 +03:00
|
|
|
panic("lfs_writeseg: Segment overwrite");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-11-17 23:08:30 +03:00
|
|
|
s = splbio();
|
1999-03-10 03:20:00 +03:00
|
|
|
if(fs->lfs_iocount >= LFS_THROTTLE) {
|
|
|
|
tsleep(&fs->lfs_iocount, PRIBIO+1, "lfs throttle", 0);
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
++fs->lfs_iocount;
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef LFS_TRACK_IOS
|
|
|
|
for(j=0;j<LFS_THROTTLE;j++) {
|
|
|
|
if(fs->lfs_pending[j]==LFS_UNUSED_DADDR) {
|
|
|
|
fs->lfs_pending[j] = cbp->b_blkno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* LFS_TRACK_IOS */
|
|
|
|
for (p = cbp->b_data; i && cbp->b_bcount < CHUNKSIZE; i--) {
|
1998-03-01 05:20:01 +03:00
|
|
|
bp = *bpp;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
if (bp->b_bcount > (CHUNKSIZE - cbp->b_bcount))
|
1998-03-01 05:20:01 +03:00
|
|
|
break;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Fake buffers from the cleaner are marked as B_INVAL.
|
|
|
|
* We need to copy the data from user space rather than
|
|
|
|
* from the buffer indicated.
|
|
|
|
* XXX == what do I do on an error?
|
|
|
|
*/
|
1999-03-10 03:20:00 +03:00
|
|
|
if ((bp->b_flags & (B_CALL|B_INVAL)) == (B_CALL|B_INVAL)) {
|
1994-06-08 15:41:58 +04:00
|
|
|
if (copyin(bp->b_saveaddr, p, bp->b_bcount))
|
1999-03-10 03:20:00 +03:00
|
|
|
panic("lfs_writeseg: copyin failed [2]");
|
1994-06-08 15:41:58 +04:00
|
|
|
} else
|
|
|
|
bcopy(bp->b_data, p, bp->b_bcount);
|
|
|
|
p += bp->b_bcount;
|
1998-03-01 05:20:01 +03:00
|
|
|
cbp->b_bcount += bp->b_bcount;
|
2000-11-17 22:14:41 +03:00
|
|
|
LFS_UNLOCK_BUF(bp);
|
1994-06-08 15:41:58 +04:00
|
|
|
bp->b_flags &= ~(B_ERROR | B_READ | B_DELWRI |
|
2000-11-17 22:14:41 +03:00
|
|
|
B_GATHERED);
|
1999-03-10 03:20:00 +03:00
|
|
|
vn = bp->b_vp;
|
1994-06-08 15:41:58 +04:00
|
|
|
if (bp->b_flags & B_CALL) {
|
|
|
|
/* if B_CALL, it was created with newbuf */
|
1999-03-10 03:20:00 +03:00
|
|
|
lfs_freebuf(bp);
|
1994-06-08 15:41:58 +04:00
|
|
|
} else {
|
|
|
|
bremfree(bp);
|
|
|
|
bp->b_flags |= B_DONE;
|
1999-03-10 03:20:00 +03:00
|
|
|
if(vn)
|
|
|
|
reassignbuf(bp, vn);
|
1994-06-08 15:41:58 +04:00
|
|
|
brelse(bp);
|
|
|
|
}
|
1999-04-12 04:25:13 +04:00
|
|
|
|
|
|
|
bpp++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the last block for this vnode, but
|
|
|
|
* there are other blocks on its dirty list,
|
|
|
|
* set IN_MODIFIED/IN_CLEANING depending on what
|
|
|
|
* sort of block. Only do this for our mount point,
|
|
|
|
* not for, e.g., inode blocks that are attached to
|
|
|
|
* the devvp.
|
|
|
|
*/
|
|
|
|
if(i>1 && vn && *bpp && (*bpp)->b_vp != vn
|
|
|
|
&& (*bpp)->b_vp && (bp=vn->v_dirtyblkhd.lh_first)!=NULL &&
|
|
|
|
vn->v_mount == fs->lfs_ivnode->v_mount)
|
|
|
|
{
|
|
|
|
ip = VTOI(vn);
|
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
printf("lfs_writeseg: marking ino %d\n",ip->i_number);
|
|
|
|
#endif
|
2000-07-06 02:25:43 +04:00
|
|
|
if(bp->b_flags & B_CALL)
|
|
|
|
LFS_SET_UINO(ip, IN_CLEANING);
|
|
|
|
else
|
|
|
|
LFS_SET_UINO(ip, IN_MODIFIED);
|
1999-04-12 04:25:13 +04:00
|
|
|
}
|
1999-03-26 01:26:52 +03:00
|
|
|
/* if(vn->v_dirtyblkhd.lh_first == NULL) */
|
|
|
|
wakeup(vn);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
++cbp->b_vp->v_numoutput;
|
|
|
|
splx(s);
|
|
|
|
/*
|
|
|
|
* XXXX This is a gross and disgusting hack. Since these
|
|
|
|
* buffers are physically addressed, they hang off the
|
|
|
|
* device vnode (devvp). As a result, they have no way
|
|
|
|
* of getting to the LFS superblock or lfs structure to
|
|
|
|
* keep track of the number of I/O's pending. So, I am
|
|
|
|
* going to stuff the fs into the saveaddr field of
|
|
|
|
* the buffer (yuk).
|
|
|
|
*/
|
|
|
|
cbp->b_saveaddr = (caddr_t)fs;
|
|
|
|
vop_strategy_a.a_desc = VDESC(vop_strategy);
|
|
|
|
vop_strategy_a.a_bp = cbp;
|
|
|
|
(strategy)(&vop_strategy_a);
|
|
|
|
}
|
2000-11-17 22:14:41 +03:00
|
|
|
#if 1 || defined(DEBUG)
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
2000-11-17 22:14:41 +03:00
|
|
|
* After doing a big write, we recalculate how many buffers are
|
1994-06-08 15:41:58 +04:00
|
|
|
* really still left on the locked queue.
|
|
|
|
*/
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
s = splbio();
|
|
|
|
lfs_countlocked(&locked_queue_count, &locked_queue_bytes);
|
|
|
|
splx(s);
|
1994-06-08 15:41:58 +04:00
|
|
|
wakeup(&locked_queue_count);
|
2000-11-17 22:14:41 +03:00
|
|
|
#endif /* 1 || DEBUG */
|
1999-03-10 03:20:00 +03:00
|
|
|
if(lfs_dostats) {
|
|
|
|
++lfs_stats.psegwrites;
|
|
|
|
lfs_stats.blocktot += nblocks - 1;
|
|
|
|
if (fs->lfs_sp->seg_flags & SEGM_SYNC)
|
|
|
|
++lfs_stats.psyncwrites;
|
|
|
|
if (fs->lfs_sp->seg_flags & SEGM_CLEAN) {
|
|
|
|
++lfs_stats.pcleanwrites;
|
|
|
|
lfs_stats.cleanblocks += nblocks - 1;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
return (lfs_initseg(fs) || do_again);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-03-10 03:20:00 +03:00
|
|
|
lfs_writesuper(fs, daddr)
|
1994-06-08 15:41:58 +04:00
|
|
|
struct lfs *fs;
|
1999-03-10 03:20:00 +03:00
|
|
|
daddr_t daddr;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
dev_t i_dev;
|
1996-02-10 01:28:45 +03:00
|
|
|
int (*strategy) __P((void *));
|
1994-06-08 15:41:58 +04:00
|
|
|
int s;
|
|
|
|
struct vop_strategy_args vop_strategy_a;
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef LFS_CANNOT_ROLLFW
|
|
|
|
/*
|
|
|
|
* If we can write one superblock while another is in
|
|
|
|
* progress, we risk not having a complete checkpoint if we crash.
|
|
|
|
* So, block here if a superblock write is in progress.
|
|
|
|
*/
|
1999-11-17 23:08:30 +03:00
|
|
|
s = splbio();
|
1999-03-10 03:20:00 +03:00
|
|
|
while(fs->lfs_sbactive) {
|
|
|
|
tsleep(&fs->lfs_sbactive, PRIBIO+1, "lfs sb", 0);
|
|
|
|
}
|
|
|
|
fs->lfs_sbactive = daddr;
|
1999-11-17 23:08:30 +03:00
|
|
|
splx(s);
|
1999-03-10 03:20:00 +03:00
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
i_dev = VTOI(fs->lfs_ivnode)->i_dev;
|
|
|
|
strategy = VTOI(fs->lfs_ivnode)->i_devvp->v_op[VOFFSET(vop_strategy)];
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/* Set timestamp of this version of the superblock */
|
|
|
|
fs->lfs_tstamp = time.tv_sec;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Checksum the superblock and copy it into a buffer. */
|
1998-09-12 01:27:12 +04:00
|
|
|
fs->lfs_cksum = lfs_sb_cksum(&(fs->lfs_dlfs));
|
1999-03-10 03:20:00 +03:00
|
|
|
bp = lfs_newbuf(VTOI(fs->lfs_ivnode)->i_devvp, daddr, LFS_SBPAD);
|
1998-09-12 01:27:12 +04:00
|
|
|
*(struct dlfs *)bp->b_data = fs->lfs_dlfs;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
bp->b_dev = i_dev;
|
|
|
|
bp->b_flags |= B_BUSY | B_CALL | B_ASYNC;
|
|
|
|
bp->b_flags &= ~(B_DONE | B_ERROR | B_READ | B_DELWRI);
|
|
|
|
bp->b_iodone = lfs_supercallback;
|
1999-03-10 03:20:00 +03:00
|
|
|
/* XXX KS - same nasty hack as above */
|
|
|
|
bp->b_saveaddr = (caddr_t)fs;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
vop_strategy_a.a_desc = VDESC(vop_strategy);
|
|
|
|
vop_strategy_a.a_bp = bp;
|
|
|
|
s = splbio();
|
|
|
|
++bp->b_vp->v_numoutput;
|
2000-06-28 00:57:11 +04:00
|
|
|
++fs->lfs_iocount;
|
1994-06-08 15:41:58 +04:00
|
|
|
splx(s);
|
|
|
|
(strategy)(&vop_strategy_a);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Logical block number match routines used when traversing the dirty block
|
|
|
|
* chain.
|
|
|
|
*/
|
1999-03-10 03:20:00 +03:00
|
|
|
int
|
|
|
|
lfs_match_fake(fs, bp)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
1999-03-26 01:26:52 +03:00
|
|
|
return (bp->b_flags & B_CALL);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
int
|
|
|
|
lfs_match_data(fs, bp)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
return (bp->b_lblkno >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_match_indir(fs, bp)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
int lbn;
|
|
|
|
|
|
|
|
lbn = bp->b_lblkno;
|
|
|
|
return (lbn < 0 && (-lbn - NDADDR) % NINDIR(fs) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_match_dindir(fs, bp)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
int lbn;
|
|
|
|
|
|
|
|
lbn = bp->b_lblkno;
|
|
|
|
return (lbn < 0 && (-lbn - NDADDR) % NINDIR(fs) == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_match_tindir(fs, bp)
|
|
|
|
struct lfs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
int lbn;
|
|
|
|
|
|
|
|
lbn = bp->b_lblkno;
|
|
|
|
return (lbn < 0 && (-lbn - NDADDR) % NINDIR(fs) == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-03-10 03:20:00 +03:00
|
|
|
* XXX - The only buffers that are going to hit these functions are the
|
|
|
|
* segment write blocks, or the segment summaries, or the superblocks.
|
|
|
|
*
|
|
|
|
* All of the above are created by lfs_newbuf, and so do not need to be
|
|
|
|
* released via brelse.
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_callback(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
struct lfs *fs;
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef LFS_TRACK_IOS
|
|
|
|
int j;
|
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
fs = (struct lfs *)bp->b_saveaddr;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (fs->lfs_iocount == 0)
|
|
|
|
panic("lfs_callback: zero iocount\n");
|
|
|
|
#endif
|
1999-03-10 03:20:00 +03:00
|
|
|
if (--fs->lfs_iocount < LFS_THROTTLE)
|
1994-06-08 15:41:58 +04:00
|
|
|
wakeup(&fs->lfs_iocount);
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef LFS_TRACK_IOS
|
|
|
|
for(j=0;j<LFS_THROTTLE;j++) {
|
|
|
|
if(fs->lfs_pending[j]==bp->b_blkno) {
|
|
|
|
fs->lfs_pending[j] = LFS_UNUSED_DADDR;
|
|
|
|
wakeup(&(fs->lfs_pending[j]));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* LFS_TRACK_IOS */
|
1994-06-08 15:41:58 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
lfs_freebuf(bp);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lfs_supercallback(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
1999-03-10 03:20:00 +03:00
|
|
|
struct lfs *fs;
|
|
|
|
|
|
|
|
fs = (struct lfs *)bp->b_saveaddr;
|
2000-06-28 00:57:11 +04:00
|
|
|
#ifdef LFS_CANNOT_ROLLFW
|
2000-05-19 08:34:39 +04:00
|
|
|
fs->lfs_sbactive = 0;
|
1999-03-10 03:20:00 +03:00
|
|
|
wakeup(&fs->lfs_sbactive);
|
|
|
|
#endif
|
2000-06-28 00:57:11 +04:00
|
|
|
if (--fs->lfs_iocount < LFS_THROTTLE)
|
|
|
|
wakeup(&fs->lfs_iocount);
|
1999-03-10 03:20:00 +03:00
|
|
|
lfs_freebuf(bp);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shellsort (diminishing increment sort) from Data Structures and
|
|
|
|
* Algorithms, Aho, Hopcraft and Ullman, 1983 Edition, page 290;
|
|
|
|
* see also Knuth Vol. 3, page 84. The increments are selected from
|
|
|
|
* formula (8), page 95. Roughly O(N^3/2).
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This is our own private copy of shellsort because we want to sort
|
|
|
|
* two parallel arrays (the array of buffer pointers and the array of
|
|
|
|
* logical block numbers) simultaneously. Note that we cast the array
|
|
|
|
* of logical block numbers to a unsigned in this routine so that the
|
|
|
|
* negative block numbers (meta data blocks) sort AFTER the data blocks.
|
|
|
|
*/
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
void
|
|
|
|
lfs_shellsort(bp_array, lb_array, nmemb)
|
|
|
|
struct buf **bp_array;
|
1998-03-01 05:20:01 +03:00
|
|
|
ufs_daddr_t *lb_array;
|
2000-03-30 16:41:09 +04:00
|
|
|
int nmemb;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
|
|
|
static int __rsshell_increments[] = { 4, 1, 0 };
|
2000-03-30 16:41:09 +04:00
|
|
|
int incr, *incrp, t1, t2;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct buf *bp_temp;
|
|
|
|
u_long lb_temp;
|
|
|
|
|
1996-02-10 01:28:45 +03:00
|
|
|
for (incrp = __rsshell_increments; (incr = *incrp++) != 0;)
|
1994-06-08 15:41:58 +04:00
|
|
|
for (t1 = incr; t1 < nmemb; ++t1)
|
|
|
|
for (t2 = t1 - incr; t2 >= 0;)
|
|
|
|
if (lb_array[t2] > lb_array[t2 + incr]) {
|
|
|
|
lb_temp = lb_array[t2];
|
|
|
|
lb_array[t2] = lb_array[t2 + incr];
|
|
|
|
lb_array[t2 + incr] = lb_temp;
|
|
|
|
bp_temp = bp_array[t2];
|
|
|
|
bp_array[t2] = bp_array[t2 + incr];
|
|
|
|
bp_array[t2 + incr] = bp_temp;
|
|
|
|
t2 -= incr;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check VXLOCK. Return 1 if the vnode is locked. Otherwise, vget it.
|
|
|
|
*/
|
1996-02-10 01:28:45 +03:00
|
|
|
int
|
1994-06-08 15:41:58 +04:00
|
|
|
lfs_vref(vp)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnode *vp;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
1999-03-10 03:20:00 +03:00
|
|
|
/*
|
|
|
|
* If we return 1 here during a flush, we risk vinvalbuf() not
|
|
|
|
* being able to flush all of the pages from this vnode, which
|
|
|
|
* will cause it to panic. So, return 0 if a flush is in progress.
|
|
|
|
*/
|
|
|
|
if (vp->v_flag & VXLOCK) {
|
|
|
|
if(IS_FLUSHING(VTOI(vp)->i_lfs,vp)) {
|
|
|
|
return 0;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
return(1);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
return (vget(vp, 0));
|
|
|
|
}
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
/*
|
|
|
|
* This is vrele except that we do not want to VOP_INACTIVE this vnode. We
|
|
|
|
* inline vrele here to avoid the vn_lock and VOP_INACTIVE call at the end.
|
|
|
|
*/
|
1994-06-08 15:41:58 +04:00
|
|
|
void
|
|
|
|
lfs_vunref(vp)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnode *vp;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
1999-03-26 00:54:10 +03:00
|
|
|
/*
|
|
|
|
* Analogous to lfs_vref, if the node is flushing, fake it.
|
|
|
|
*/
|
|
|
|
if((vp->v_flag & VXLOCK) && IS_FLUSHING(VTOI(vp)->i_lfs,vp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock(&vp->v_interlock);
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
1999-03-26 00:54:10 +03:00
|
|
|
if(vp->v_usecount<=0) {
|
2000-06-28 00:57:11 +04:00
|
|
|
printf("lfs_vunref: inum is %d\n", VTOI(vp)->i_number);
|
2000-11-27 11:39:39 +03:00
|
|
|
printf("lfs_vunref: flags are 0x%x\n", vp->v_flag);
|
|
|
|
printf("lfs_vunref: usecount = %d\n", vp->v_usecount);
|
1999-03-10 03:20:00 +03:00
|
|
|
panic("lfs_vunref: v_usecount<0");
|
|
|
|
}
|
|
|
|
#endif
|
1998-03-01 05:20:01 +03:00
|
|
|
vp->v_usecount--;
|
|
|
|
if (vp->v_usecount > 0) {
|
|
|
|
simple_unlock(&vp->v_interlock);
|
|
|
|
return;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
1998-03-01 05:20:01 +03:00
|
|
|
* insert at tail of LRU list
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock(&vnode_free_list_slock);
|
2000-01-19 03:03:04 +03:00
|
|
|
if (vp->v_holdcnt > 0)
|
|
|
|
TAILQ_INSERT_TAIL(&vnode_hold_list, vp, v_freelist);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_unlock(&vnode_free_list_slock);
|
|
|
|
simple_unlock(&vp->v_interlock);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We use this when we have vnodes that were loaded in solely for cleaning.
|
|
|
|
* There is no reason to believe that these vnodes will be referenced again
|
|
|
|
* soon, since the cleaning process is unrelated to normal filesystem
|
|
|
|
* activity. Putting cleaned vnodes at the tail of the list has the effect
|
|
|
|
* of flushing the vnode LRU. So, put vnodes that were loaded only for
|
|
|
|
* cleaning at the head of the list, instead.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_vunref_head(vp)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnode *vp;
|
1999-03-10 03:20:00 +03:00
|
|
|
{
|
|
|
|
simple_lock(&vp->v_interlock);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(vp->v_usecount==0) {
|
|
|
|
panic("lfs_vunref: v_usecount<0");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
vp->v_usecount--;
|
|
|
|
if (vp->v_usecount > 0) {
|
|
|
|
simple_unlock(&vp->v_interlock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* insert at head of LRU list
|
|
|
|
*/
|
|
|
|
simple_lock(&vnode_free_list_slock);
|
|
|
|
TAILQ_INSERT_HEAD(&vnode_free_list, vp, v_freelist);
|
|
|
|
simple_unlock(&vnode_free_list_slock);
|
|
|
|
simple_unlock(&vp->v_interlock);
|
|
|
|
}
|
|
|
|
|