2000-12-03 08:56:27 +03:00
|
|
|
/* $NetBSD: lfs_alloc.c,v 1.46 2000/12/03 05:56:27 perseant Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/*-
|
2000-06-28 00:57:11 +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.
|
|
|
|
*
|
1994-06-29 10:39:25 +04:00
|
|
|
* @(#)lfs_alloc.c 8.4 (Berkeley) 1/4/94
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
|
1998-06-09 11:46:31 +04:00
|
|
|
#if defined(_KERNEL) && !defined(_LKM)
|
1998-06-08 08:27:50 +04:00
|
|
|
#include "opt_quota.h"
|
1998-06-09 11:46:31 +04:00
|
|
|
#endif
|
1998-06-08 08:27:50 +04:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/param.h>
|
1996-02-10 01:28:45 +03:00
|
|
|
#include <sys/systm.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/malloc.h>
|
1998-09-01 07:26:05 +04:00
|
|
|
#include <sys/pool.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
#include <ufs/ufs/ufsmount.h>
|
1996-02-10 01:28:45 +03:00
|
|
|
#include <ufs/ufs/ufs_extern.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
#include <ufs/lfs/lfs.h>
|
|
|
|
#include <ufs/lfs/lfs_extern.h>
|
|
|
|
|
2000-06-28 00:57:11 +04:00
|
|
|
extern int lfs_dirvcount;
|
1999-03-10 03:20:00 +03:00
|
|
|
extern struct lock ufs_hashlock;
|
|
|
|
|
2000-11-27 06:33:57 +03:00
|
|
|
static int extend_ifile(struct lfs *, struct ucred *);
|
|
|
|
static int lfs_ialloc(struct lfs *, struct vnode *, ino_t, int, struct vnode **);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a particular inode with a particular version number, freeing
|
|
|
|
* any previous versions of this inode that may have gone before.
|
|
|
|
* Used by the roll-forward code.
|
|
|
|
*
|
|
|
|
* XXX this function does not have appropriate locking to be used on a live fs;
|
|
|
|
* XXX but something similar could probably be used for an "undelete" call.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lfs_rf_valloc(struct lfs *fs, ino_t ino, int version, struct proc *p,
|
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
|
|
|
IFILE *ifp;
|
|
|
|
struct buf *bp;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct inode *ip;
|
|
|
|
ino_t tino, oldnext;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, just try a vget. If the version number is the one we want,
|
|
|
|
* we don't have to do anything else. If the version number is wrong,
|
|
|
|
* take appropriate action.
|
|
|
|
*/
|
|
|
|
error = VFS_VGET(fs->lfs_ivnode->v_mount, ino, &vp);
|
|
|
|
if (error == 0) {
|
|
|
|
/* printf("lfs_rf_valloc[1]: ino %d vp %p\n", ino, vp); */
|
|
|
|
|
|
|
|
*vpp = vp;
|
|
|
|
ip = VTOI(vp);
|
|
|
|
if (ip->i_ffs_gen == version)
|
|
|
|
return 0;
|
|
|
|
else if (ip->i_ffs_gen < version) {
|
|
|
|
VOP_TRUNCATE(vp, (off_t)0, 0, NOCRED, p);
|
|
|
|
ip->i_ffs_gen = version;
|
|
|
|
LFS_SET_UINO(ip, IN_CHANGE | IN_MODIFIED | IN_UPDATE);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/* printf("ino %d: asked for version %d but got %d\n",
|
|
|
|
ino, version, ip->i_ffs_gen); */
|
|
|
|
vput(vp);
|
|
|
|
*vpp = NULLVP;
|
|
|
|
return EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The inode is not in use. Find it on the free list.
|
|
|
|
*/
|
|
|
|
/* If the Ifile is too short to contain this inum, extend it */
|
|
|
|
while (VTOI(fs->lfs_ivnode)->i_ffs_size <=
|
|
|
|
dbtob(fsbtodb(fs, ino / fs->lfs_ifpb + fs->lfs_cleansz +
|
|
|
|
fs->lfs_segtabsz))) {
|
|
|
|
extend_ifile(fs, NOCRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
LFS_IENTRY(ifp, fs, ino, bp);
|
|
|
|
oldnext = ifp->if_nextfree;
|
|
|
|
ifp->if_version = version;
|
|
|
|
brelse(bp);
|
|
|
|
|
|
|
|
if (ino == fs->lfs_free) {
|
|
|
|
fs->lfs_free = oldnext;
|
|
|
|
} else {
|
|
|
|
tino = fs->lfs_free;
|
|
|
|
while(1) {
|
|
|
|
LFS_IENTRY(ifp, fs, tino, bp);
|
|
|
|
if (ifp->if_nextfree == ino ||
|
|
|
|
ifp->if_nextfree == LFS_UNUSED_INUM)
|
|
|
|
break;
|
|
|
|
tino = ifp->if_nextfree;
|
|
|
|
brelse(bp);
|
|
|
|
}
|
|
|
|
if (ifp->if_nextfree == LFS_UNUSED_INUM) {
|
|
|
|
brelse(bp);
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
ifp->if_nextfree = oldnext;
|
|
|
|
VOP_BWRITE(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = lfs_ialloc(fs, fs->lfs_ivnode, ino, version, &vp);
|
|
|
|
if (error == 0) {
|
|
|
|
/*
|
|
|
|
* Make it VREG so we can put blocks on it. We will change
|
|
|
|
* this later if it turns out to be some other kind of file.
|
|
|
|
*/
|
|
|
|
ip = VTOI(vp);
|
|
|
|
ip->i_ffs_mode = IFREG;
|
|
|
|
ip->i_ffs_nlink = 1;
|
|
|
|
ip->i_ffs_effnlink = 1;
|
|
|
|
ufs_vinit(vp->v_mount, lfs_specop_p, lfs_fifoop_p, &vp);
|
|
|
|
ip = VTOI(vp);
|
|
|
|
|
|
|
|
/* printf("lfs_rf_valloc: ino %d vp %p\n", ino, vp); */
|
|
|
|
|
|
|
|
/* The dirop-nature of this vnode is past */
|
|
|
|
(void)lfs_vunref(vp);
|
|
|
|
--lfs_dirvcount;
|
|
|
|
vp->v_flag &= ~VDIROP;
|
|
|
|
--fs->lfs_nadirop;
|
|
|
|
ip->i_flag &= ~IN_ADIROP;
|
|
|
|
}
|
|
|
|
*vpp = vp;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
extend_ifile(struct lfs *fs, struct ucred *cred)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct inode *ip;
|
|
|
|
IFILE *ifp;
|
|
|
|
struct buf *bp;
|
|
|
|
int error;
|
|
|
|
ufs_daddr_t i, blkno, max;
|
|
|
|
ino_t oldlast;
|
|
|
|
|
|
|
|
vp = fs->lfs_ivnode;
|
|
|
|
(void)lfs_vref(vp);
|
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
ip = VTOI(vp);
|
|
|
|
blkno = lblkno(fs, ip->i_ffs_size);
|
|
|
|
if ((error = VOP_BALLOC(vp, ip->i_ffs_size, fs->lfs_bsize, cred, 0,
|
|
|
|
&bp)) != 0) {
|
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
lfs_vunref(vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
ip->i_ffs_size += fs->lfs_bsize;
|
|
|
|
uvm_vnp_setsize(vp, ip->i_ffs_size);
|
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
|
|
|
|
i = (blkno - fs->lfs_segtabsz - fs->lfs_cleansz) *
|
|
|
|
fs->lfs_ifpb;
|
|
|
|
oldlast = fs->lfs_free;
|
|
|
|
fs->lfs_free = i;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(fs->lfs_free == LFS_UNUSED_INUM)
|
|
|
|
panic("inode 0 allocated [2]");
|
|
|
|
#endif /* DIAGNOSTIC */
|
|
|
|
max = i + fs->lfs_ifpb;
|
|
|
|
/* printf("extend ifile for ino %d--%d\n", i, max); */
|
|
|
|
for (ifp = (struct ifile *)bp->b_data; i < max; ++ifp) {
|
|
|
|
ifp->if_version = 1;
|
|
|
|
ifp->if_daddr = LFS_UNUSED_DADDR;
|
|
|
|
ifp->if_nextfree = ++i;
|
|
|
|
}
|
|
|
|
ifp--;
|
|
|
|
ifp->if_nextfree = oldlast;
|
|
|
|
(void) VOP_BWRITE(bp); /* Ifile */
|
|
|
|
lfs_vunref(vp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Allocate a new inode. */
|
|
|
|
/* ARGSUSED */
|
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
|
|
|
/* VOP_BWRITE 2i times */
|
1994-06-08 15:41:58 +04:00
|
|
|
int
|
1996-02-10 01:28:45 +03:00
|
|
|
lfs_valloc(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_valloc_args /* {
|
1999-03-10 03:20:00 +03:00
|
|
|
struct vnode *a_pvp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
} */ *ap = v;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct lfs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
struct ifile *ifp;
|
|
|
|
ino_t new_ino;
|
|
|
|
int error;
|
2000-06-22 22:31:49 +04:00
|
|
|
int new_gen;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
fs = VTOI(ap->a_pvp)->i_lfs;
|
2000-06-28 00:57:11 +04:00
|
|
|
if (fs->lfs_ronly)
|
|
|
|
return EROFS;
|
|
|
|
*ap->a_vpp = NULL;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
/*
|
2000-06-07 00:19:14 +04:00
|
|
|
* Use lfs_seglock here, instead of fs->lfs_freelock, to ensure that
|
|
|
|
* the free list is not changed in between the time that the ifile
|
|
|
|
* blocks are written to disk and the time that the superblock is
|
|
|
|
* written to disk.
|
|
|
|
*
|
|
|
|
* XXX this sucks. We should instead encode the head of the free
|
2000-11-27 06:33:57 +03:00
|
|
|
* list into the CLEANERINFO block of the Ifile. [XXX v2]
|
1999-03-10 03:20:00 +03:00
|
|
|
*/
|
2000-06-07 00:19:14 +04:00
|
|
|
lfs_seglock(fs, SEGM_PROT);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
/* Get the head of the freelist. */
|
1994-06-08 15:41:58 +04:00
|
|
|
new_ino = fs->lfs_free;
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(new_ino == LFS_UNUSED_INUM) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
lfs_dump_super(fs);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
panic("inode 0 allocated [1]");
|
|
|
|
}
|
|
|
|
#endif /* DIAGNOSTIC */
|
1994-06-08 15:41:58 +04:00
|
|
|
#ifdef ALLOCPRINT
|
2000-11-27 06:33:57 +03:00
|
|
|
printf("lfs_valloc: allocate inode %d\n", new_ino);
|
1994-06-08 15:41:58 +04:00
|
|
|
#endif
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Remove the inode from the free list and write the new start
|
|
|
|
* of the free list into the superblock.
|
|
|
|
*/
|
|
|
|
LFS_IENTRY(ifp, fs, new_ino, bp);
|
|
|
|
if (ifp->if_daddr != LFS_UNUSED_DADDR)
|
2000-11-27 06:33:57 +03:00
|
|
|
panic("lfs_valloc: inuse inode %d on the free list", new_ino);
|
1994-06-08 15:41:58 +04:00
|
|
|
fs->lfs_free = ifp->if_nextfree;
|
2000-06-22 22:46:57 +04:00
|
|
|
new_gen = ifp->if_version; /* version was updated by vfree */
|
1999-11-12 19:56:48 +03:00
|
|
|
brelse(bp);
|
1999-12-15 10:19:07 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Extend IFILE so that the next lfs_valloc will succeed. */
|
|
|
|
if (fs->lfs_free == LFS_UNUSED_INUM) {
|
2000-11-27 06:33:57 +03:00
|
|
|
if ((error = extend_ifile(fs, ap->a_cred)) != 0) {
|
2000-06-28 00:57:11 +04:00
|
|
|
fs->lfs_free = new_ino;
|
2000-11-27 06:33:57 +03:00
|
|
|
lfs_segunlock(fs);
|
|
|
|
return error;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(fs->lfs_free == LFS_UNUSED_INUM)
|
|
|
|
panic("inode 0 allocated [3]");
|
|
|
|
#endif /* DIAGNOSTIC */
|
|
|
|
|
2000-06-07 00:19:14 +04:00
|
|
|
lfs_segunlock(fs);
|
2000-01-19 03:03:04 +03:00
|
|
|
|
2000-11-27 06:33:57 +03:00
|
|
|
return lfs_ialloc(fs, ap->a_pvp, new_ino, new_gen, ap->a_vpp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
lfs_ialloc(struct lfs *fs, struct vnode *pvp, ino_t new_ino, int new_gen,
|
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
|
|
|
struct inode *ip;
|
|
|
|
struct vnode *vp;
|
|
|
|
IFILE *ifp;
|
|
|
|
struct buf *bp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = getnewvnode(VT_LFS, pvp->v_mount, lfs_vnodeop_p, &vp);
|
|
|
|
/* printf("lfs_ialloc: ino %d vp %p error %d\n", new_ino, vp, error);*/
|
|
|
|
if (error)
|
2000-06-28 00:57:11 +04:00
|
|
|
goto errout;
|
2000-07-01 00:45:38 +04:00
|
|
|
|
|
|
|
lockmgr(&ufs_hashlock, LK_EXCLUSIVE, 0);
|
|
|
|
/* Create an inode to associate with the vnode. */
|
2000-11-27 06:33:57 +03:00
|
|
|
lfs_vcreate(pvp->v_mount, new_ino, vp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
ip = VTOI(vp);
|
|
|
|
/* Zero out the direct and indirect block addresses. */
|
1998-10-23 04:32:35 +04:00
|
|
|
bzero(&ip->i_din, sizeof(ip->i_din));
|
1997-06-11 14:09:37 +04:00
|
|
|
ip->i_din.ffs_din.di_inumber = new_ino;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Set a new generation number for this inode. */
|
2000-11-27 06:33:57 +03:00
|
|
|
if (new_gen)
|
|
|
|
ip->i_ffs_gen = new_gen;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Insert into the inode hash table. */
|
|
|
|
ufs_ihashins(ip);
|
1999-11-06 23:33:05 +03:00
|
|
|
lockmgr(&ufs_hashlock, LK_RELEASE, 0);
|
2000-11-27 06:33:57 +03:00
|
|
|
|
1998-06-25 00:58:44 +04:00
|
|
|
error = ufs_vinit(vp->v_mount, lfs_specop_p, lfs_fifoop_p, &vp);
|
2000-11-27 06:33:57 +03:00
|
|
|
ip = VTOI(vp);
|
1996-02-10 01:28:45 +03:00
|
|
|
if (error) {
|
1994-06-08 15:41:58 +04:00
|
|
|
vput(vp);
|
2000-06-28 00:57:11 +04:00
|
|
|
goto errout;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
2000-11-27 06:33:57 +03:00
|
|
|
/* printf("lfs_ialloc[2]: ino %d vp %p\n", new_ino, vp);*/
|
1999-03-10 03:20:00 +03:00
|
|
|
|
2000-11-27 06:33:57 +03:00
|
|
|
*vpp = vp;
|
2000-06-28 00:57:11 +04:00
|
|
|
#if 1
|
1999-03-10 03:20:00 +03:00
|
|
|
if(!(vp->v_flag & VDIROP)) {
|
2000-06-22 22:11:45 +04:00
|
|
|
(void)lfs_vref(vp);
|
1999-11-06 23:33:05 +03:00
|
|
|
++lfs_dirvcount;
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
vp->v_flag |= VDIROP;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
2000-05-27 04:19:52 +04:00
|
|
|
if(!(ip->i_flag & IN_ADIROP))
|
|
|
|
++fs->lfs_nadirop;
|
|
|
|
ip->i_flag |= IN_ADIROP;
|
2000-06-28 00:57:11 +04:00
|
|
|
#endif
|
|
|
|
VREF(ip->i_devvp);
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Set superblock modified bit and increment file count. */
|
|
|
|
fs->lfs_fmod = 1;
|
|
|
|
++fs->lfs_nfiles;
|
|
|
|
return (0);
|
2000-06-28 00:57:11 +04:00
|
|
|
|
|
|
|
errout:
|
|
|
|
/*
|
|
|
|
* Put the new inum back on the free list.
|
|
|
|
*/
|
|
|
|
LFS_IENTRY(ifp, fs, new_ino, bp);
|
|
|
|
ifp->if_daddr = LFS_UNUSED_DADDR;
|
|
|
|
ifp->if_nextfree = fs->lfs_free;
|
|
|
|
fs->lfs_free = new_ino;
|
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-06-28 00:57:11 +04:00
|
|
|
|
2000-11-27 06:33:57 +03:00
|
|
|
*vpp = NULLVP;
|
2000-06-28 00:57:11 +04:00
|
|
|
return (error);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new vnode/inode pair and initialize what fields we can. */
|
2000-07-01 00:45:38 +04:00
|
|
|
void
|
|
|
|
lfs_vcreate(mp, ino, vp)
|
1994-06-08 15:41:58 +04:00
|
|
|
struct mount *mp;
|
|
|
|
ino_t ino;
|
2000-07-01 00:45:38 +04:00
|
|
|
struct vnode *vp;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
|
|
|
struct inode *ip;
|
|
|
|
struct ufsmount *ump;
|
1996-03-25 15:53:35 +03:00
|
|
|
#ifdef QUOTA
|
|
|
|
int i;
|
|
|
|
#endif
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Get a pointer to the private mount structure. */
|
|
|
|
ump = VFSTOUFS(mp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Initialize the inode. */
|
1998-09-01 07:26:05 +04:00
|
|
|
ip = pool_get(&lfs_inode_pool, PR_WAITOK);
|
2000-07-01 00:45:38 +04:00
|
|
|
vp->v_data = ip;
|
|
|
|
ip->i_vnode = vp;
|
1994-06-08 15:41:58 +04:00
|
|
|
ip->i_devvp = ump->um_devvp;
|
|
|
|
ip->i_dev = ump->um_dev;
|
1997-06-11 14:09:37 +04:00
|
|
|
ip->i_number = ip->i_din.ffs_din.di_inumber = ino;
|
1994-06-08 15:41:58 +04:00
|
|
|
ip->i_lfs = ump->um_lfs;
|
|
|
|
#ifdef QUOTA
|
|
|
|
for (i = 0; i < MAXQUOTAS; i++)
|
|
|
|
ip->i_dquot[i] = NODQUOT;
|
|
|
|
#endif
|
|
|
|
ip->i_lockf = 0;
|
|
|
|
ip->i_diroff = 0;
|
1997-06-11 14:09:37 +04:00
|
|
|
ip->i_ffs_mode = 0;
|
|
|
|
ip->i_ffs_size = 0;
|
|
|
|
ip->i_ffs_blocks = 0;
|
2000-07-03 12:20:58 +04:00
|
|
|
ip->i_lfs_effnblks = 0;
|
2000-07-06 02:25:43 +04:00
|
|
|
ip->i_flag = 0;
|
2000-11-27 06:33:57 +03:00
|
|
|
LFS_SET_UINO(ip, IN_CHANGE | IN_MODIFIED);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free an inode. */
|
|
|
|
/* ARGUSED */
|
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
|
|
|
/* VOP_BWRITE 2i times */
|
1994-06-08 15:41:58 +04:00
|
|
|
int
|
1996-02-10 01:28:45 +03:00
|
|
|
lfs_vfree(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_vfree_args /* {
|
1999-03-10 03:20:00 +03:00
|
|
|
struct vnode *a_pvp;
|
|
|
|
ino_t a_ino;
|
|
|
|
int a_mode;
|
|
|
|
} */ *ap = v;
|
1994-06-08 15:41:58 +04:00
|
|
|
SEGUSE *sup;
|
|
|
|
struct buf *bp;
|
|
|
|
struct ifile *ifp;
|
|
|
|
struct inode *ip;
|
1999-12-15 10:19:07 +03:00
|
|
|
struct vnode *vp;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct lfs *fs;
|
1998-03-01 05:20:01 +03:00
|
|
|
ufs_daddr_t old_iaddr;
|
1994-06-08 15:41:58 +04:00
|
|
|
ino_t ino;
|
1999-12-15 10:19:07 +03:00
|
|
|
extern int lfs_dirvcount;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Get the inode number and file system. */
|
1999-12-15 10:19:07 +03:00
|
|
|
vp = ap->a_pvp;
|
|
|
|
ip = VTOI(vp);
|
1994-06-08 15:41:58 +04:00
|
|
|
fs = ip->i_lfs;
|
|
|
|
ino = ip->i_number;
|
2000-06-07 00:19:14 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Right now this is unnecessary since we take the seglock.
|
|
|
|
* But if the seglock is no longer necessary (e.g. we put the
|
|
|
|
* head of the free list into the Ifile) we will need to drain
|
|
|
|
* this vnode of any pending writes.
|
|
|
|
*/
|
|
|
|
if (WRITEINPROG(vp))
|
|
|
|
tsleep(vp, (PRIBIO+1), "lfs_vfree", 0);
|
|
|
|
#endif
|
|
|
|
lfs_seglock(fs, SEGM_PROT);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1999-12-15 10:19:07 +03:00
|
|
|
if(vp->v_flag & VDIROP) {
|
|
|
|
--lfs_dirvcount;
|
|
|
|
vp->v_flag &= ~VDIROP;
|
|
|
|
wakeup(&lfs_dirvcount);
|
|
|
|
lfs_vunref(vp);
|
|
|
|
}
|
2000-06-28 00:57:11 +04:00
|
|
|
if (ip->i_flag & IN_ADIROP) {
|
|
|
|
--fs->lfs_nadirop;
|
|
|
|
ip->i_flag &= ~IN_ADIROP;
|
|
|
|
}
|
1999-12-15 10:19:07 +03:00
|
|
|
|
2000-07-06 02:25:43 +04:00
|
|
|
LFS_CLR_UINO(ip, IN_ACCESSED|IN_CLEANING|IN_MODIFIED);
|
2000-05-31 05:40:01 +04:00
|
|
|
ip->i_flag &= ~IN_ALLMOD;
|
2000-07-06 02:25:43 +04:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Set the ifile's inode entry to unused, increment its version number
|
|
|
|
* and link it into the free chain.
|
|
|
|
*/
|
|
|
|
LFS_IENTRY(ifp, fs, ino, bp);
|
|
|
|
old_iaddr = ifp->if_daddr;
|
|
|
|
ifp->if_daddr = LFS_UNUSED_DADDR;
|
|
|
|
++ifp->if_version;
|
|
|
|
ifp->if_nextfree = fs->lfs_free;
|
|
|
|
fs->lfs_free = ino;
|
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 */
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(fs->lfs_free == LFS_UNUSED_INUM) {
|
|
|
|
panic("inode 0 freed");
|
|
|
|
}
|
|
|
|
#endif /* DIAGNOSTIC */
|
1994-06-08 15:41:58 +04:00
|
|
|
if (old_iaddr != LFS_UNUSED_DADDR) {
|
|
|
|
LFS_SEGENTRY(sup, fs, datosn(fs, old_iaddr), bp);
|
1999-06-16 02:25:41 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1999-03-10 03:20:00 +03:00
|
|
|
if (sup->su_nbytes < DINODE_SIZE) {
|
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_vfree: negative byte count"
|
|
|
|
" (segment %d short by %d)\n",
|
|
|
|
datosn(fs, old_iaddr),
|
|
|
|
(int)DINODE_SIZE - sup->su_nbytes);
|
1999-06-16 02:25:41 +04:00
|
|
|
panic("lfs_vfree: negative byte count");
|
1999-03-10 03:20:00 +03:00
|
|
|
sup->su_nbytes = DINODE_SIZE;
|
|
|
|
}
|
1999-06-16 02:25:41 +04:00
|
|
|
#endif
|
1998-10-23 04:32:35 +04:00
|
|
|
sup->su_nbytes -= DINODE_SIZE;
|
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
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Set superblock modified bit and decrement file count. */
|
|
|
|
fs->lfs_fmod = 1;
|
|
|
|
--fs->lfs_nfiles;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
2000-06-07 00:19:14 +04:00
|
|
|
lfs_segunlock(fs);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|