2020-05-14 11:34:17 +03:00
|
|
|
/* $NetBSD: segwrite.c,v 1.48 2020/05/14 08:34:17 msaitoh Exp $ */
|
2003-03-28 11:09:52 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Konrad E. Schroder <perseant@hhhh.org>.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* 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.
|
2003-08-07 14:04:22 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2003-03-28 11:09:52 +03:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @(#)lfs_segment.c 8.10 (Berkeley) 6/10/95
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Partial segment writer, taken from the kernel and adapted for userland.
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
|
|
|
/* Override certain things to make <ufs/lfs/lfs.h> work */
|
2013-06-06 04:54:49 +04:00
|
|
|
#define VU_DIROP 0x01000000 /* XXX XXX from sys/vnode.h */
|
2003-03-28 11:09:52 +03:00
|
|
|
#define vnode uvnode
|
|
|
|
#define buf ubuf
|
|
|
|
#define panic call_panic
|
|
|
|
|
|
|
|
#include <ufs/lfs/lfs.h>
|
2015-07-28 08:09:34 +03:00
|
|
|
#include <ufs/lfs/lfs_accessors.h>
|
2013-06-08 06:16:03 +04:00
|
|
|
#include <ufs/lfs/lfs_inode.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2006-11-09 22:36:36 +03:00
|
|
|
#include <util.h>
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
#include "bufcache.h"
|
2020-04-03 22:36:32 +03:00
|
|
|
#include "extern.h"
|
2005-09-13 08:14:17 +04:00
|
|
|
#include "lfs_user.h"
|
2003-03-28 11:09:52 +03:00
|
|
|
#include "segwrite.h"
|
|
|
|
|
|
|
|
/* Compatibility definitions */
|
|
|
|
off_t written_bytes = 0;
|
|
|
|
off_t written_data = 0;
|
|
|
|
off_t written_indir = 0;
|
|
|
|
off_t written_dev = 0;
|
|
|
|
int written_inodes = 0;
|
|
|
|
|
|
|
|
/* Global variables */
|
|
|
|
time_t write_time;
|
|
|
|
|
2015-08-12 21:27:01 +03:00
|
|
|
static void lfs_shellsort(struct lfs *,
|
|
|
|
struct ubuf **, union lfs_blocks *, int, int);
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/*
|
|
|
|
* Logical block number match routines used when traversing the dirty block
|
|
|
|
* chain.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lfs_match_data(struct lfs * fs, struct ubuf * bp)
|
|
|
|
{
|
|
|
|
return (bp->b_lblkno >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_match_indir(struct lfs * fs, struct ubuf * bp)
|
|
|
|
{
|
|
|
|
daddr_t lbn;
|
|
|
|
|
|
|
|
lbn = bp->b_lblkno;
|
2013-06-18 22:18:57 +04:00
|
|
|
return (lbn < 0 && (-lbn - ULFS_NDADDR) % LFS_NINDIR(fs) == 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_match_dindir(struct lfs * fs, struct ubuf * bp)
|
|
|
|
{
|
|
|
|
daddr_t lbn;
|
|
|
|
|
|
|
|
lbn = bp->b_lblkno;
|
2013-06-18 22:18:57 +04:00
|
|
|
return (lbn < 0 && (-lbn - ULFS_NDADDR) % LFS_NINDIR(fs) == 1);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_match_tindir(struct lfs * fs, struct ubuf * bp)
|
|
|
|
{
|
|
|
|
daddr_t lbn;
|
|
|
|
|
|
|
|
lbn = bp->b_lblkno;
|
2013-06-18 22:18:57 +04:00
|
|
|
return (lbn < 0 && (-lbn - ULFS_NDADDR) % LFS_NINDIR(fs) == 2);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a checkpoint.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lfs_segwrite(struct lfs * fs, int flags)
|
|
|
|
{
|
|
|
|
struct inode *ip;
|
|
|
|
struct segment *sp;
|
|
|
|
struct uvnode *vp;
|
2015-08-12 21:26:26 +03:00
|
|
|
SEGSUM *ssp;
|
2003-03-28 11:09:52 +03:00
|
|
|
int redo;
|
|
|
|
|
|
|
|
lfs_seglock(fs, flags | SEGM_CKP);
|
|
|
|
sp = fs->lfs_sp;
|
|
|
|
|
|
|
|
lfs_writevnodes(fs, sp, VN_REG);
|
|
|
|
lfs_writevnodes(fs, sp, VN_DIROP);
|
2015-08-12 21:26:26 +03:00
|
|
|
ssp = (SEGSUM *)sp->segsum;
|
|
|
|
lfs_ss_setflags(fs, ssp, lfs_ss_getflags(fs, ssp) & ~(SS_CONT));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
do {
|
|
|
|
vp = fs->lfs_ivnode;
|
|
|
|
fs->lfs_flags &= ~LFS_IFDIRTY;
|
|
|
|
ip = VTOI(vp);
|
2015-07-24 09:56:41 +03:00
|
|
|
if (LIST_FIRST(&vp->v_dirtyblkhd) != NULL || lfs_sb_getidaddr(fs) <= 0)
|
2003-03-28 11:09:52 +03:00
|
|
|
lfs_writefile(fs, sp, vp);
|
|
|
|
|
|
|
|
redo = lfs_writeinode(fs, sp, ip);
|
|
|
|
redo += lfs_writeseg(fs, sp);
|
|
|
|
redo += (fs->lfs_flags & LFS_IFDIRTY);
|
|
|
|
} while (redo);
|
|
|
|
|
|
|
|
lfs_segunlock(fs);
|
|
|
|
#if 0
|
|
|
|
printf("wrote %" PRId64 " bytes (%" PRId32 " fsb)\n",
|
2013-06-18 22:18:57 +04:00
|
|
|
written_bytes, (ulfs_daddr_t)lfs_btofsb(fs, written_bytes));
|
2003-03-28 11:09:52 +03:00
|
|
|
printf("wrote %" PRId64 " bytes data (%" PRId32 " fsb)\n",
|
2013-06-18 22:18:57 +04:00
|
|
|
written_data, (ulfs_daddr_t)lfs_btofsb(fs, written_data));
|
2003-03-28 11:09:52 +03:00
|
|
|
printf("wrote %" PRId64 " bytes indir (%" PRId32 " fsb)\n",
|
2013-06-18 22:18:57 +04:00
|
|
|
written_indir, (ulfs_daddr_t)lfs_btofsb(fs, written_indir));
|
2003-03-28 11:09:52 +03:00
|
|
|
printf("wrote %" PRId64 " bytes dev (%" PRId32 " fsb)\n",
|
2013-06-18 22:18:57 +04:00
|
|
|
written_dev, (ulfs_daddr_t)lfs_btofsb(fs, written_dev));
|
2003-03-28 11:09:52 +03:00
|
|
|
printf("wrote %d inodes (%" PRId32 " fsb)\n",
|
2013-06-18 22:18:57 +04:00
|
|
|
written_inodes, lfs_btofsb(fs, written_inodes * fs->lfs_ibsize));
|
2003-03-28 11:09:52 +03:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the dirty blocks associated with a vnode.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_writefile(struct lfs * fs, struct segment * sp, struct uvnode * vp)
|
|
|
|
{
|
|
|
|
struct ubuf *bp;
|
2015-08-12 21:27:01 +03:00
|
|
|
FINFO *fip;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct inode *ip;
|
|
|
|
IFILE *ifp;
|
2015-08-12 21:26:26 +03:00
|
|
|
SEGSUM *ssp;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
ip = VTOI(vp);
|
|
|
|
|
2015-07-24 09:56:41 +03:00
|
|
|
if (sp->seg_bytes_left < lfs_sb_getbsize(fs) ||
|
2015-08-12 21:27:01 +03:00
|
|
|
sp->sum_bytes_left < FINFOSIZE(fs) + LFS_BLKPTRSIZE(fs))
|
2003-03-28 11:09:52 +03:00
|
|
|
(void) lfs_writeseg(fs, sp);
|
|
|
|
|
2015-08-12 21:27:01 +03:00
|
|
|
sp->sum_bytes_left -= FINFOSIZE(fs);
|
2015-08-12 21:26:26 +03:00
|
|
|
ssp = (SEGSUM *)sp->segsum;
|
|
|
|
lfs_ss_setnfinfo(fs, ssp, lfs_ss_getnfinfo(fs, ssp) + 1);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-08-12 21:26:26 +03:00
|
|
|
if (vp->v_uflag & VU_DIROP) {
|
|
|
|
lfs_ss_setflags(fs, ssp,
|
|
|
|
lfs_ss_getflags(fs, ssp) | (SS_DIROP | SS_CONT));
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
fip = sp->fip;
|
2015-08-12 21:27:01 +03:00
|
|
|
lfs_fi_setnblocks(fs, fip, 0);
|
|
|
|
lfs_fi_setino(fs, fip, ip->i_number);
|
|
|
|
LFS_IENTRY(ifp, fs, lfs_fi_getino(fs, fip), bp);
|
|
|
|
lfs_fi_setversion(fs, fip, lfs_if_getversion(fs, ifp));
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_data);
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_indir);
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_dindir);
|
|
|
|
lfs_gather(fs, sp, vp, lfs_match_tindir);
|
|
|
|
|
|
|
|
fip = sp->fip;
|
2015-08-12 21:27:01 +03:00
|
|
|
if (lfs_fi_getnblocks(fs, fip) != 0) {
|
2015-08-12 21:26:26 +03:00
|
|
|
sp->fip = NEXT_FINFO(fs, fip);
|
2015-08-12 21:27:01 +03:00
|
|
|
lfs_blocks_fromfinfo(fs, &sp->start_lbp, sp->fip);
|
2003-03-28 11:09:52 +03:00
|
|
|
} else {
|
2015-08-12 21:27:01 +03:00
|
|
|
/* XXX shouldn't this update sp->fip? */
|
|
|
|
sp->sum_bytes_left += FINFOSIZE(fs);
|
2015-08-12 21:26:26 +03:00
|
|
|
lfs_ss_setnfinfo(fs, ssp, lfs_ss_getnfinfo(fs, ssp) - 1);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_writeinode(struct lfs * fs, struct segment * sp, struct inode * ip)
|
|
|
|
{
|
|
|
|
struct ubuf *bp, *ibp;
|
2015-08-12 21:28:00 +03:00
|
|
|
union lfs_dinode *cdp;
|
2003-03-28 11:09:52 +03:00
|
|
|
IFILE *ifp;
|
|
|
|
SEGUSE *sup;
|
2015-08-12 21:26:26 +03:00
|
|
|
SEGSUM *ssp;
|
2003-03-28 11:09:52 +03:00
|
|
|
daddr_t daddr;
|
|
|
|
ino_t ino;
|
2015-10-03 11:28:15 +03:00
|
|
|
IINFO *iip;
|
|
|
|
int i, fsb = 0;
|
2003-03-28 11:09:52 +03:00
|
|
|
int redo_ifile = 0;
|
|
|
|
struct timespec ts;
|
|
|
|
int gotblk = 0;
|
|
|
|
|
|
|
|
/* Allocate a new inode block if necessary. */
|
|
|
|
if ((ip->i_number != LFS_IFILE_INUM || sp->idp == NULL) &&
|
|
|
|
sp->ibp == NULL) {
|
|
|
|
/* Allocate a new segment if necessary. */
|
2015-07-24 09:59:31 +03:00
|
|
|
if (sp->seg_bytes_left < lfs_sb_getibsize(fs) ||
|
2015-09-01 09:15:02 +03:00
|
|
|
sp->sum_bytes_left < LFS_BLKPTRSIZE(fs))
|
2003-03-28 11:09:52 +03:00
|
|
|
(void) lfs_writeseg(fs, sp);
|
|
|
|
|
|
|
|
/* Get next inode block. */
|
2015-07-24 09:56:41 +03:00
|
|
|
daddr = lfs_sb_getoffset(fs);
|
|
|
|
lfs_sb_addoffset(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->ibp = *sp->cbpp++ =
|
2013-06-18 22:18:57 +04:00
|
|
|
getblk(fs->lfs_devvp, LFS_FSBTODB(fs, daddr),
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_sb_getibsize(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->ibp->b_flags |= B_GATHERED;
|
|
|
|
gotblk++;
|
|
|
|
|
|
|
|
/* Zero out inode numbers */
|
2015-08-12 21:28:00 +03:00
|
|
|
for (i = 0; i < LFS_INOPB(fs); ++i) {
|
|
|
|
union lfs_dinode *tmpdip;
|
|
|
|
|
|
|
|
tmpdip = DINO_IN_BLOCK(fs, sp->ibp->b_data, i);
|
|
|
|
lfs_dino_setinumber(fs, tmpdip, 0);
|
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
++sp->start_bpp;
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Set remaining space counters. */
|
2015-07-24 09:56:41 +03:00
|
|
|
sp->seg_bytes_left -= lfs_sb_getibsize(fs);
|
2015-09-01 09:15:02 +03:00
|
|
|
sp->sum_bytes_left -= LFS_BLKPTRSIZE(fs);
|
2015-10-03 11:28:15 +03:00
|
|
|
|
|
|
|
/* Store the address in the segment summary. */
|
|
|
|
iip = NTH_IINFO(fs, sp->segsum, sp->ninodes / LFS_INOPB(fs));
|
|
|
|
lfs_ii_setblock(fs, iip, daddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
/* Update the inode times and copy the inode onto the inode page. */
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
ts.tv_sec = write_time;
|
|
|
|
/* XXX kludge --- don't redirty the ifile just to put times on it */
|
|
|
|
if (ip->i_number != LFS_IFILE_INUM)
|
|
|
|
LFS_ITIMES(ip, &ts, &ts, &ts);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
2015-08-19 23:33:29 +03:00
|
|
|
lfs_copy_dinode(fs, sp->idp, ip->i_din);
|
2015-09-01 09:08:37 +03:00
|
|
|
ip->i_lfs_osize = lfs_dino_getsize(fs, ip->i_din);
|
2003-03-28 11:09:52 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bp = sp->ibp;
|
2015-08-12 21:28:00 +03:00
|
|
|
cdp = DINO_IN_BLOCK(fs, bp->b_data, sp->ninodes % LFS_INOPB(fs));
|
2015-08-19 23:33:29 +03:00
|
|
|
lfs_copy_dinode(fs, cdp, ip->i_din);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* If all blocks are goig to disk, update the "size on disk" */
|
2015-09-01 09:08:37 +03:00
|
|
|
ip->i_lfs_osize = lfs_dino_getsize(fs, ip->i_din);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
if (ip->i_number == LFS_IFILE_INUM) /* We know sp->idp == NULL */
|
2015-08-12 21:28:00 +03:00
|
|
|
sp->idp = DINO_IN_BLOCK(fs, bp->b_data, sp->ninodes % LFS_INOPB(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
if (gotblk) {
|
|
|
|
LFS_LOCK_BUF(bp);
|
2006-05-24 02:35:20 +04:00
|
|
|
assert(!(bp->b_flags & B_INVAL));
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
/* Increment inode count in segment summary block. */
|
2015-08-12 21:26:26 +03:00
|
|
|
ssp = (SEGSUM *)sp->segsum;
|
|
|
|
lfs_ss_setninos(fs, ssp, lfs_ss_getninos(fs, ssp) + 1);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* If this page is full, set flag to allocate a new page. */
|
2013-06-18 22:18:57 +04:00
|
|
|
if (++sp->ninodes % LFS_INOPB(fs) == 0)
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->ibp = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If updating the ifile, update the super-block. Update the disk
|
2015-08-12 21:25:51 +03:00
|
|
|
* address for this inode in the ifile.
|
2003-03-28 11:09:52 +03:00
|
|
|
*/
|
|
|
|
ino = ip->i_number;
|
|
|
|
if (ino == LFS_IFILE_INUM) {
|
2015-07-24 09:56:41 +03:00
|
|
|
daddr = lfs_sb_getidaddr(fs);
|
|
|
|
lfs_sb_setidaddr(fs, LFS_DBTOFSB(fs, bp->b_blkno));
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
sbdirty();
|
2003-03-28 11:09:52 +03:00
|
|
|
} else {
|
|
|
|
LFS_IENTRY(ifp, fs, ino, ibp);
|
2015-08-12 21:25:51 +03:00
|
|
|
daddr = lfs_if_getdaddr(fs, ifp);
|
|
|
|
lfs_if_setdaddr(fs, ifp, LFS_DBTOFSB(fs, bp->b_blkno) + fsb);
|
2013-10-19 05:09:58 +04:00
|
|
|
(void)LFS_BWRITE_LOG(ibp); /* Ifile */
|
2003-03-28 11:09:52 +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.
|
|
|
|
*/
|
|
|
|
if (daddr != LFS_UNUSED_DADDR) {
|
2013-06-18 22:18:57 +04:00
|
|
|
u_int32_t oldsn = lfs_dtosn(fs, daddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_SEGENTRY(sup, fs, oldsn, bp);
|
2015-08-12 21:28:00 +03:00
|
|
|
sup->su_nbytes -= DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
redo_ifile =
|
|
|
|
(ino == LFS_IFILE_INUM && !(bp->b_flags & B_GATHERED));
|
|
|
|
if (redo_ifile)
|
|
|
|
fs->lfs_flags |= LFS_IFDIRTY;
|
|
|
|
LFS_WRITESEGENTRY(sup, fs, oldsn, bp); /* Ifile */
|
|
|
|
}
|
|
|
|
return redo_ifile;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_gatherblock(struct segment * sp, struct ubuf * bp)
|
|
|
|
{
|
|
|
|
struct lfs *fs;
|
2015-08-12 21:26:26 +03:00
|
|
|
SEGSUM *ssp;
|
2003-03-28 11:09:52 +03:00
|
|
|
int version;
|
|
|
|
int j, blksinblk;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If full, finish this segment. We may be doing I/O, so
|
|
|
|
* release and reacquire the splbio().
|
|
|
|
*/
|
|
|
|
fs = sp->fs;
|
2015-07-24 09:56:41 +03:00
|
|
|
blksinblk = howmany(bp->b_bcount, lfs_sb_getbsize(fs));
|
2015-09-01 09:15:02 +03:00
|
|
|
if (sp->sum_bytes_left < LFS_BLKPTRSIZE(fs) * blksinblk ||
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->seg_bytes_left < bp->b_bcount) {
|
|
|
|
lfs_updatemeta(sp);
|
|
|
|
|
2015-08-12 21:27:01 +03:00
|
|
|
version = lfs_fi_getversion(fs, sp->fip);
|
2003-03-28 11:09:52 +03:00
|
|
|
(void) lfs_writeseg(fs, sp);
|
|
|
|
|
2015-08-12 21:27:01 +03:00
|
|
|
lfs_fi_setversion(fs, sp->fip, version);
|
|
|
|
lfs_fi_setino(fs, sp->fip, VTOI(sp->vp)->i_number);
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Add the current file to the segment summary. */
|
2015-08-12 21:26:26 +03:00
|
|
|
ssp = (SEGSUM *)sp->segsum;
|
|
|
|
lfs_ss_setnfinfo(fs, ssp, lfs_ss_getnfinfo(fs, ssp) + 1);
|
2015-08-12 21:27:01 +03:00
|
|
|
sp->sum_bytes_left -= FINFOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Insert into the buffer list, update the FINFO block. */
|
|
|
|
bp->b_flags |= B_GATHERED;
|
|
|
|
/* bp->b_flags &= ~B_DONE; */
|
|
|
|
|
|
|
|
*sp->cbpp++ = bp;
|
2015-08-12 21:27:01 +03:00
|
|
|
for (j = 0; j < blksinblk; j++) {
|
|
|
|
unsigned bn;
|
|
|
|
|
|
|
|
bn = lfs_fi_getnblocks(fs, sp->fip);
|
|
|
|
lfs_fi_setnblocks(fs, sp->fip, bn + 1);
|
2020-05-14 11:34:17 +03:00
|
|
|
lfs_fi_setblock(fs, sp->fip, bn, bp->b_lblkno + j);
|
2015-08-12 21:27:01 +03:00
|
|
|
}
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-09-01 09:15:02 +03:00
|
|
|
sp->sum_bytes_left -= LFS_BLKPTRSIZE(fs) * blksinblk;
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->seg_bytes_left -= bp->b_bcount;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_gather(struct lfs * fs, struct segment * sp, struct uvnode * vp, int (*match) (struct lfs *, struct ubuf *))
|
|
|
|
{
|
|
|
|
struct ubuf *bp, *nbp;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
sp->vp = vp;
|
|
|
|
loop:
|
|
|
|
for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
|
|
|
|
nbp = LIST_NEXT(bp, b_vnbufs);
|
|
|
|
|
|
|
|
assert(bp->b_flags & B_DELWRI);
|
|
|
|
if ((bp->b_flags & (B_BUSY | B_GATHERED)) || !match(fs, bp)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (lfs_gatherblock(sp, bp)) {
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
lfs_updatemeta(sp);
|
|
|
|
sp->vp = NULL;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change the given block's address to ndaddr, finding its previous
|
2013-06-06 04:52:50 +04:00
|
|
|
* location using ulfs_bmaparray().
|
2003-03-28 11:09:52 +03:00
|
|
|
*
|
|
|
|
* Account for this change in the segment table.
|
|
|
|
*/
|
2015-09-01 09:15:02 +03:00
|
|
|
static void
|
2003-03-28 11:09:52 +03:00
|
|
|
lfs_update_single(struct lfs * fs, struct segment * sp, daddr_t lbn,
|
2015-09-01 09:15:02 +03:00
|
|
|
daddr_t ndaddr, int size)
|
2003-03-28 11:09:52 +03:00
|
|
|
{
|
|
|
|
SEGUSE *sup;
|
|
|
|
struct ubuf *bp;
|
2013-06-06 04:52:50 +04:00
|
|
|
struct indir a[ULFS_NIADDR + 2], *ap;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct inode *ip;
|
|
|
|
struct uvnode *vp;
|
|
|
|
daddr_t daddr, ooff;
|
|
|
|
int num, error;
|
2010-02-17 02:20:30 +03:00
|
|
|
int osize;
|
|
|
|
int frags, ofrags;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
vp = sp->vp;
|
|
|
|
ip = VTOI(vp);
|
|
|
|
|
2013-06-06 04:52:50 +04:00
|
|
|
error = ulfs_bmaparray(fs, vp, lbn, &daddr, a, &num);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (error)
|
2015-06-17 02:18:54 +03:00
|
|
|
errx(EXIT_FAILURE, "%s: ulfs_bmaparray returned %d looking up lbn %"
|
|
|
|
PRId64 "", __func__, error, lbn);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (daddr > 0)
|
2013-06-18 22:18:57 +04:00
|
|
|
daddr = LFS_DBTOFSB(fs, daddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2013-06-18 22:18:57 +04:00
|
|
|
frags = lfs_numfrags(fs, size);
|
2003-03-28 11:09:52 +03:00
|
|
|
switch (num) {
|
|
|
|
case 0:
|
2015-09-01 09:08:37 +03:00
|
|
|
ooff = lfs_dino_getdb(fs, ip->i_din, lbn);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (ooff == UNWRITTEN)
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setblocks(fs, ip->i_din,
|
|
|
|
lfs_dino_getblocks(fs, ip->i_din) + frags);
|
2003-03-28 11:09:52 +03:00
|
|
|
else {
|
|
|
|
/* possible fragment truncation or extension */
|
2013-06-18 22:18:57 +04:00
|
|
|
ofrags = lfs_btofsb(fs, ip->i_lfs_fragsize[lbn]);
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setblocks(fs, ip->i_din,
|
|
|
|
lfs_dino_getblocks(fs, ip->i_din) + (frags - ofrags));
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setdb(fs, ip->i_din, lbn, ndaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-09-01 09:08:37 +03:00
|
|
|
ooff = lfs_dino_getib(fs, ip->i_din, a[0].in_off);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (ooff == UNWRITTEN)
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setblocks(fs, ip->i_din,
|
|
|
|
lfs_dino_getblocks(fs, ip->i_din) + frags);
|
|
|
|
lfs_dino_setib(fs, ip->i_din, a[0].in_off, ndaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ap = &a[num - 1];
|
2015-07-24 09:56:41 +03:00
|
|
|
if (bread(vp, ap->in_lbn, lfs_sb_getbsize(fs), 0, &bp))
|
2015-06-17 02:18:54 +03:00
|
|
|
errx(EXIT_FAILURE, "%s: bread bno %" PRId64, __func__,
|
2003-03-28 11:09:52 +03:00
|
|
|
ap->in_lbn);
|
|
|
|
|
2015-09-01 09:08:37 +03:00
|
|
|
ooff = lfs_iblock_get(fs, bp->b_data, ap->in_off);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (ooff == UNWRITTEN)
|
2015-09-01 09:08:37 +03:00
|
|
|
lfs_dino_setblocks(fs, ip->i_din,
|
|
|
|
lfs_dino_getblocks(fs, ip->i_din) + frags);
|
|
|
|
lfs_iblock_set(fs, bp->b_data, ap->in_off, ndaddr);
|
2003-03-28 11:09:52 +03:00
|
|
|
(void) VOP_BWRITE(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update segment usage information, based on old size
|
|
|
|
* and location.
|
|
|
|
*/
|
|
|
|
if (daddr > 0) {
|
2013-06-18 22:18:57 +04:00
|
|
|
u_int32_t oldsn = lfs_dtosn(fs, daddr);
|
2013-06-06 04:52:50 +04:00
|
|
|
if (lbn >= 0 && lbn < ULFS_NDADDR)
|
2003-03-28 11:09:52 +03:00
|
|
|
osize = ip->i_lfs_fragsize[lbn];
|
|
|
|
else
|
2015-07-24 09:56:41 +03:00
|
|
|
osize = lfs_sb_getbsize(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_SEGENTRY(sup, fs, oldsn, bp);
|
|
|
|
sup->su_nbytes -= osize;
|
|
|
|
if (!(bp->b_flags & B_GATHERED))
|
|
|
|
fs->lfs_flags |= LFS_IFDIRTY;
|
|
|
|
LFS_WRITESEGENTRY(sup, fs, oldsn, bp);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now that this block has a new address, and its old
|
|
|
|
* segment no longer owns it, we can forget about its
|
|
|
|
* old size.
|
|
|
|
*/
|
2013-06-06 04:52:50 +04:00
|
|
|
if (lbn >= 0 && lbn < ULFS_NDADDR)
|
2003-03-28 11:09:52 +03:00
|
|
|
ip->i_lfs_fragsize[lbn] = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the metadata that points to the blocks listed in the FINFO
|
|
|
|
* array.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_updatemeta(struct segment * sp)
|
|
|
|
{
|
|
|
|
struct ubuf *sbp;
|
|
|
|
struct lfs *fs;
|
|
|
|
struct uvnode *vp;
|
|
|
|
daddr_t lbn;
|
|
|
|
int i, nblocks, num;
|
2010-02-17 02:20:30 +03:00
|
|
|
int frags;
|
2003-03-28 11:09:52 +03:00
|
|
|
int bytesleft, size;
|
2015-08-12 21:27:01 +03:00
|
|
|
union lfs_blocks tmpptr;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-08-12 21:27:01 +03:00
|
|
|
fs = sp->fs;
|
2003-03-28 11:09:52 +03:00
|
|
|
vp = sp->vp;
|
2015-08-12 21:27:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This code was cutpasted from the kernel. See the
|
|
|
|
* corresponding comment in lfs_segment.c.
|
|
|
|
*/
|
|
|
|
#if 0
|
2003-03-28 11:09:52 +03:00
|
|
|
nblocks = &sp->fip->fi_blocks[sp->fip->fi_nblocks] - sp->start_lbp;
|
2015-08-12 21:27:01 +03:00
|
|
|
#else
|
|
|
|
lfs_blocks_fromvoid(fs, &tmpptr, (void *)NEXT_FINFO(fs, sp->fip));
|
|
|
|
nblocks = lfs_blocks_sub(fs, &tmpptr, &sp->start_lbp);
|
|
|
|
//nblocks_orig = nblocks;
|
|
|
|
#endif
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
if (vp == NULL || nblocks == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This count may be high due to oversize blocks from lfs_gop_write.
|
|
|
|
* Correct for this. (XXX we should be able to keep track of these.)
|
|
|
|
*/
|
|
|
|
for (i = 0; i < nblocks; i++) {
|
|
|
|
if (sp->start_bpp[i] == NULL) {
|
|
|
|
printf("nblocks = %d, not %d\n", i, nblocks);
|
|
|
|
nblocks = i;
|
|
|
|
break;
|
|
|
|
}
|
2015-07-24 09:56:41 +03:00
|
|
|
num = howmany(sp->start_bpp[i]->b_bcount, lfs_sb_getbsize(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
nblocks -= num - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort the blocks.
|
|
|
|
*/
|
2015-08-12 21:27:01 +03:00
|
|
|
lfs_shellsort(fs, sp->start_bpp, &sp->start_lbp, nblocks, lfs_sb_getbsize(fs));
|
2003-03-28 11:09:52 +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.
|
|
|
|
*/
|
2015-08-12 21:27:01 +03:00
|
|
|
lfs_fi_setlastlength(fs, sp->fip, ((sp->start_bpp[nblocks - 1]->b_bcount - 1) &
|
|
|
|
lfs_sb_getbmask(fs)) + 1);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Assign disk addresses, and update references to the logical
|
|
|
|
* block and the segment usage information.
|
|
|
|
*/
|
|
|
|
for (i = nblocks; i--; ++sp->start_bpp) {
|
|
|
|
sbp = *sp->start_bpp;
|
2015-08-12 21:27:01 +03:00
|
|
|
lbn = lfs_blocks_get(fs, &sp->start_lbp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-07-24 09:56:41 +03:00
|
|
|
sbp->b_blkno = LFS_FSBTODB(fs, lfs_sb_getoffset(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we write a frag in the wrong place, the cleaner won't
|
|
|
|
* be able to correctly identify its size later, and the
|
|
|
|
* segment will be uncleanable. (Even worse, it will assume
|
|
|
|
* that the indirect block that actually ends the list
|
|
|
|
* is of a smaller size!)
|
|
|
|
*/
|
2015-07-24 09:59:31 +03:00
|
|
|
if ((sbp->b_bcount & lfs_sb_getbmask(fs)) && i != 0)
|
2015-06-17 02:18:54 +03:00
|
|
|
errx(EXIT_FAILURE, "%s: fragment is not last block", __func__);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For each subblock in this possibly oversized block,
|
|
|
|
* update its address on disk.
|
|
|
|
*/
|
|
|
|
for (bytesleft = sbp->b_bcount; bytesleft > 0;
|
2015-07-24 09:56:41 +03:00
|
|
|
bytesleft -= lfs_sb_getbsize(fs)) {
|
|
|
|
size = MIN(bytesleft, lfs_sb_getbsize(fs));
|
2013-06-18 22:18:57 +04:00
|
|
|
frags = lfs_numfrags(fs, size);
|
2015-08-12 21:27:01 +03:00
|
|
|
lbn = lfs_blocks_get(fs, &sp->start_lbp, 0);
|
|
|
|
lfs_blocks_inc(fs, &sp->start_lbp);
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_update_single(fs, sp, lbn, lfs_sb_getoffset(fs), size);
|
|
|
|
lfs_sb_addoffset(fs, frags);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start a new segment.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lfs_initseg(struct lfs * fs)
|
|
|
|
{
|
|
|
|
struct segment *sp;
|
|
|
|
SEGUSE *sup;
|
|
|
|
SEGSUM *ssp;
|
|
|
|
struct ubuf *bp, *sbp;
|
|
|
|
int repeat;
|
|
|
|
|
|
|
|
sp = fs->lfs_sp;
|
|
|
|
|
|
|
|
repeat = 0;
|
|
|
|
|
|
|
|
/* Advance to the next segment. */
|
|
|
|
if (!LFS_PARTIAL_FITS(fs)) {
|
|
|
|
/* lfs_avail eats the remaining space */
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_subavail(fs, lfs_sb_getfsbpseg(fs) - (lfs_sb_getoffset(fs) -
|
|
|
|
lfs_sb_getcurseg(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
lfs_newseg(fs);
|
|
|
|
repeat = 1;
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_setoffset(fs, lfs_sb_getcurseg(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-07-24 09:56:41 +03:00
|
|
|
sp->seg_number = lfs_dtosn(fs, lfs_sb_getcurseg(fs));
|
|
|
|
sp->seg_bytes_left = lfs_fsbtob(fs, lfs_sb_getfsbpseg(fs));
|
2003-03-28 11:09:52 +03: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) {
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_addoffset(fs, lfs_btofsb(fs, LFS_SBPAD));
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->seg_bytes_left -= LFS_SBPAD;
|
|
|
|
}
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Segment zero could also contain the labelpad */
|
2015-08-02 21:14:16 +03:00
|
|
|
if (lfs_sb_getversion(fs) > 1 && sp->seg_number == 0 &&
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_sb_gets0addr(fs) < lfs_btofsb(fs, LFS_LABELPAD)) {
|
|
|
|
lfs_sb_addoffset(fs, lfs_btofsb(fs, LFS_LABELPAD) - lfs_sb_gets0addr(fs));
|
|
|
|
sp->seg_bytes_left -= LFS_LABELPAD - lfs_fsbtob(fs, lfs_sb_gets0addr(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-24 09:56:41 +03:00
|
|
|
sp->seg_number = lfs_dtosn(fs, lfs_sb_getcurseg(fs));
|
|
|
|
sp->seg_bytes_left = lfs_fsbtob(fs, lfs_sb_getfsbpseg(fs) -
|
|
|
|
(lfs_sb_getoffset(fs) - lfs_sb_getcurseg(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_setlastpseg(fs, lfs_sb_getoffset(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
sp->fs = fs;
|
|
|
|
sp->ibp = NULL;
|
|
|
|
sp->idp = NULL;
|
|
|
|
sp->ninodes = 0;
|
|
|
|
sp->ndupino = 0;
|
|
|
|
|
|
|
|
/* Get a new buffer for SEGSUM and enter it into the buffer list. */
|
|
|
|
sp->cbpp = sp->bpp;
|
2005-03-25 23:16:37 +03:00
|
|
|
sbp = *sp->cbpp = getblk(fs->lfs_devvp,
|
2015-07-24 09:56:41 +03:00
|
|
|
LFS_FSBTODB(fs, lfs_sb_getoffset(fs)), lfs_sb_getsumsize(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->segsum = sbp->b_data;
|
2015-07-24 09:56:41 +03:00
|
|
|
memset(sp->segsum, 0, lfs_sb_getsumsize(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->start_bpp = ++sp->cbpp;
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_addoffset(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* Set point to SEGSUM, initialize it. */
|
|
|
|
ssp = sp->segsum;
|
2015-08-12 21:26:26 +03:00
|
|
|
lfs_ss_setnext(fs, ssp, lfs_sb_getnextseg(fs));
|
|
|
|
lfs_ss_setnfinfo(fs, ssp, 0);
|
|
|
|
lfs_ss_setninos(fs, ssp, 0);
|
|
|
|
lfs_ss_setmagic(fs, ssp, SS_MAGIC);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* Set pointer to first FINFO, initialize it. */
|
2015-08-12 21:26:26 +03:00
|
|
|
sp->fip = SEGSUM_FINFOBASE(fs, ssp);
|
2015-08-12 21:27:01 +03:00
|
|
|
lfs_fi_setnblocks(fs, sp->fip, 0);
|
|
|
|
lfs_blocks_fromfinfo(fs, &sp->start_lbp, sp->fip);
|
|
|
|
lfs_fi_setlastlength(fs, sp->fip, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-07-24 09:56:41 +03:00
|
|
|
sp->seg_bytes_left -= lfs_sb_getsumsize(fs);
|
|
|
|
sp->sum_bytes_left = lfs_sb_getsumsize(fs) - SEGSUM_SIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
LFS_LOCK_BUF(sbp);
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(sbp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
return repeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the next segment to write.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_newseg(struct lfs * fs)
|
|
|
|
{
|
|
|
|
CLEANERINFO *cip;
|
|
|
|
SEGUSE *sup;
|
|
|
|
struct ubuf *bp;
|
|
|
|
int curseg, isdirty, sn;
|
|
|
|
|
2015-07-24 09:56:41 +03:00
|
|
|
LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, lfs_sb_getnextseg(fs)), bp);
|
2003-03-28 11:09:52 +03:00
|
|
|
sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
|
|
|
|
sup->su_nbytes = 0;
|
|
|
|
sup->su_nsums = 0;
|
|
|
|
sup->su_ninos = 0;
|
2015-07-24 09:56:41 +03:00
|
|
|
LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, lfs_sb_getnextseg(fs)), bp);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
LFS_CLEANERINFO(cip, fs, bp);
|
2015-08-12 21:25:03 +03:00
|
|
|
lfs_ci_shiftcleantodirty(fs, cip, 1);
|
|
|
|
lfs_sb_setnclean(fs, lfs_ci_getclean(fs, cip));
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
|
|
|
|
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_setlastseg(fs, lfs_sb_getcurseg(fs));
|
|
|
|
lfs_sb_setcurseg(fs, lfs_sb_getnextseg(fs));
|
|
|
|
for (sn = curseg = lfs_dtosn(fs, lfs_sb_getcurseg(fs)) + lfs_sb_getinterleave(fs);;) {
|
2015-07-24 09:59:31 +03:00
|
|
|
sn = (sn + 1) % lfs_sb_getnseg(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
if (sn == curseg)
|
2015-06-17 02:18:54 +03:00
|
|
|
errx(EXIT_FAILURE, "%s: no clean segments", __func__);
|
2003-03-28 11:09:52 +03:00
|
|
|
LFS_SEGENTRY(sup, fs, sn, bp);
|
|
|
|
isdirty = sup->su_flags & SEGUSE_DIRTY;
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
if (!isdirty)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++fs->lfs_nactive;
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_setnextseg(fs, lfs_sntod(fs, sn));
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_writeseg(struct lfs * fs, struct segment * sp)
|
|
|
|
{
|
|
|
|
struct ubuf **bpp, *bp;
|
|
|
|
SEGUSE *sup;
|
|
|
|
SEGSUM *ssp;
|
|
|
|
char *datap, *dp;
|
|
|
|
int i;
|
|
|
|
int do_again, nblocks, byteoffset;
|
|
|
|
size_t el_size;
|
|
|
|
u_short ninos;
|
2015-08-12 21:26:26 +03:00
|
|
|
size_t sumstart;
|
2003-03-28 11:09:52 +03:00
|
|
|
struct uvnode *devvp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
nblocks = sp->cbpp - sp->bpp;
|
|
|
|
#if 0
|
|
|
|
printf("write %d blocks at 0x%x\n",
|
2013-06-18 22:18:57 +04:00
|
|
|
nblocks, (int)LFS_DBTOFSB(fs, (*sp->bpp)->b_blkno));
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
#endif
|
|
|
|
if (nblocks == 1)
|
2003-03-28 11:09:52 +03:00
|
|
|
return 0;
|
|
|
|
|
2005-03-25 23:16:37 +03:00
|
|
|
devvp = fs->lfs_devvp;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* Update the segment usage information. */
|
|
|
|
LFS_SEGENTRY(sup, fs, sp->seg_number, bp);
|
Various improvements to fsck_lfs, to wit:
* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
2006-07-19 03:37:13 +04:00
|
|
|
sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
/* Loop through all blocks, except the segment summary. */
|
|
|
|
for (bpp = sp->bpp; ++bpp < sp->cbpp;) {
|
|
|
|
if ((*bpp)->b_vp != devvp) {
|
|
|
|
sup->su_nbytes += (*bpp)->b_bcount;
|
|
|
|
}
|
2013-06-18 22:18:57 +04:00
|
|
|
assert(lfs_dtosn(fs, LFS_DBTOFSB(fs, (*bpp)->b_blkno)) == sp->seg_number);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ssp = (SEGSUM *) sp->segsum;
|
2015-08-12 21:26:26 +03:00
|
|
|
lfs_ss_setflags(fs, ssp, lfs_ss_getflags(fs, ssp) | SS_RFW);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-08-12 21:26:26 +03:00
|
|
|
ninos = (lfs_ss_getninos(fs, ssp) + LFS_INOPB(fs) - 1) / LFS_INOPB(fs);
|
2015-08-12 21:28:00 +03:00
|
|
|
sup->su_nbytes += lfs_ss_getninos(fs, ssp) * DINOSIZE(fs);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-08-02 21:14:16 +03:00
|
|
|
if (lfs_sb_getversion(fs) == 1)
|
2003-03-28 11:09:52 +03:00
|
|
|
sup->su_olastmod = write_time;
|
|
|
|
else
|
|
|
|
sup->su_lastmod = write_time;
|
|
|
|
sup->su_ninos += ninos;
|
|
|
|
++sup->su_nsums;
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_sb_adddmeta(fs, (lfs_btofsb(fs, lfs_sb_getsumsize(fs)) + lfs_btofsb(fs, ninos *
|
|
|
|
lfs_sb_getibsize(fs))));
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
do_again = !(bp->b_flags & B_GATHERED);
|
|
|
|
LFS_WRITESEGENTRY(sup, fs, sp->seg_number, bp); /* Ifile */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-08-02 21:14:16 +03:00
|
|
|
if (lfs_sb_getversion(fs) == 1)
|
2003-03-28 11:09:52 +03:00
|
|
|
el_size = sizeof(u_long);
|
|
|
|
else
|
|
|
|
el_size = sizeof(u_int32_t);
|
2006-11-09 22:36:36 +03:00
|
|
|
datap = dp = emalloc(nblocks * el_size);
|
2003-03-28 11:09:52 +03:00
|
|
|
for (bpp = sp->bpp, i = nblocks - 1; i--;) {
|
|
|
|
++bpp;
|
|
|
|
/* Loop through gop_write cluster blocks */
|
|
|
|
for (byteoffset = 0; byteoffset < (*bpp)->b_bcount;
|
2015-07-24 09:56:41 +03:00
|
|
|
byteoffset += lfs_sb_getbsize(fs)) {
|
2003-03-28 11:09:52 +03:00
|
|
|
memcpy(dp, (*bpp)->b_data + byteoffset, el_size);
|
|
|
|
dp += el_size;
|
|
|
|
}
|
2003-03-31 23:56:59 +04:00
|
|
|
bremfree(*bpp);
|
2003-03-28 11:09:52 +03:00
|
|
|
(*bpp)->b_flags |= B_BUSY;
|
|
|
|
}
|
2015-08-02 21:14:16 +03:00
|
|
|
if (lfs_sb_getversion(fs) == 1)
|
2015-08-12 21:26:26 +03:00
|
|
|
lfs_ss_setocreate(fs, ssp, write_time);
|
2003-03-28 11:09:52 +03:00
|
|
|
else {
|
2015-08-12 21:26:26 +03:00
|
|
|
lfs_ss_setcreate(fs, ssp, write_time);
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_addserial(fs, 1);
|
2015-08-12 21:26:26 +03:00
|
|
|
lfs_ss_setserial(fs, ssp, lfs_sb_getserial(fs));
|
|
|
|
lfs_ss_setident(fs, ssp, lfs_sb_getident(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
/* Set the summary block busy too */
|
|
|
|
bremfree(*(sp->bpp));
|
|
|
|
(*(sp->bpp))->b_flags |= B_BUSY;
|
|
|
|
|
2015-08-12 21:26:26 +03:00
|
|
|
lfs_ss_setdatasum(fs, ssp, cksum(datap, (nblocks - 1) * el_size));
|
|
|
|
sumstart = lfs_ss_getsumstart(fs);
|
|
|
|
lfs_ss_setsumsum(fs, ssp,
|
|
|
|
cksum((char *)ssp + sumstart, lfs_sb_getsumsize(fs) - sumstart));
|
2003-03-28 11:09:52 +03:00
|
|
|
free(datap);
|
|
|
|
datap = dp = NULL;
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_subbfree(fs, (lfs_btofsb(fs, ninos * lfs_sb_getibsize(fs)) +
|
|
|
|
lfs_btofsb(fs, lfs_sb_getsumsize(fs))));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
if (devvp == NULL)
|
2015-06-17 02:18:54 +03:00
|
|
|
errx(EXIT_FAILURE, "devvp is NULL");
|
2003-03-28 11:09:52 +03:00
|
|
|
for (bpp = sp->bpp, i = nblocks; i; bpp++, i--) {
|
|
|
|
bp = *bpp;
|
|
|
|
#if 0
|
2003-03-31 23:56:59 +04:00
|
|
|
printf("i = %d, bp = %p, flags %lx, bn = %" PRIx64 "\n",
|
2003-03-28 11:09:52 +03:00
|
|
|
nblocks - i, bp, bp->b_flags, bp->b_blkno);
|
|
|
|
printf(" vp = %p\n", bp->b_vp);
|
2005-03-25 23:16:37 +03:00
|
|
|
if (bp->b_vp != fs->lfs_devvp)
|
2003-03-28 11:09:52 +03:00
|
|
|
printf(" ino = %d lbn = %" PRId64 "\n",
|
|
|
|
VTOI(bp->b_vp)->i_number, bp->b_lblkno);
|
|
|
|
#endif
|
2005-03-25 23:16:37 +03:00
|
|
|
if (bp->b_vp == fs->lfs_devvp)
|
2003-03-28 11:09:52 +03:00
|
|
|
written_dev += bp->b_bcount;
|
|
|
|
else {
|
|
|
|
if (bp->b_lblkno >= 0)
|
|
|
|
written_data += bp->b_bcount;
|
|
|
|
else
|
|
|
|
written_indir += bp->b_bcount;
|
|
|
|
}
|
2003-03-31 23:56:59 +04:00
|
|
|
bp->b_flags &= ~(B_DELWRI | B_READ | B_GATHERED | B_ERROR |
|
|
|
|
B_LOCKED);
|
2003-03-28 11:09:52 +03:00
|
|
|
bwrite(bp);
|
|
|
|
written_bytes += bp->b_bcount;
|
|
|
|
}
|
|
|
|
written_inodes += ninos;
|
|
|
|
|
|
|
|
return (lfs_initseg(fs) || do_again);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our own copy of shellsort. XXX use qsort or heapsort.
|
|
|
|
*/
|
2015-08-12 21:27:01 +03:00
|
|
|
static void
|
|
|
|
lfs_shellsort(struct lfs *fs,
|
|
|
|
struct ubuf ** bp_array, union lfs_blocks *lb_array, int nmemb, int size)
|
2003-03-28 11:09:52 +03:00
|
|
|
{
|
|
|
|
static int __rsshell_increments[] = {4, 1, 0};
|
|
|
|
int incr, *incrp, t1, t2;
|
|
|
|
struct ubuf *bp_temp;
|
|
|
|
|
|
|
|
for (incrp = __rsshell_increments; (incr = *incrp++) != 0;)
|
|
|
|
for (t1 = incr; t1 < nmemb; ++t1)
|
|
|
|
for (t2 = t1 - incr; t2 >= 0;)
|
|
|
|
if ((u_int32_t) bp_array[t2]->b_lblkno >
|
|
|
|
(u_int32_t) bp_array[t2 + incr]->b_lblkno) {
|
|
|
|
bp_temp = bp_array[t2];
|
|
|
|
bp_array[t2] = bp_array[t2 + incr];
|
|
|
|
bp_array[t2 + incr] = bp_temp;
|
|
|
|
t2 -= incr;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Reform the list of logical blocks */
|
|
|
|
incr = 0;
|
|
|
|
for (t1 = 0; t1 < nmemb; t1++) {
|
|
|
|
for (t2 = 0; t2 * size < bp_array[t1]->b_bcount; t2++) {
|
2015-08-12 21:27:01 +03:00
|
|
|
lfs_blocks_set(fs, lb_array, incr++,
|
|
|
|
bp_array[t1]->b_lblkno + t2);
|
2003-03-28 11:09:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lfs_seglock --
|
|
|
|
* Single thread the segment writer.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lfs_seglock(struct lfs * fs, unsigned long flags)
|
|
|
|
{
|
|
|
|
struct segment *sp;
|
2015-07-24 09:56:41 +03:00
|
|
|
size_t allocsize;
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
if (fs->lfs_seglock) {
|
|
|
|
++fs->lfs_seglock;
|
|
|
|
fs->lfs_sp->seg_flags |= flags;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fs->lfs_seglock = 1;
|
|
|
|
|
2006-11-09 22:36:36 +03:00
|
|
|
sp = fs->lfs_sp = emalloc(sizeof(*sp));
|
2015-07-24 09:56:41 +03:00
|
|
|
allocsize = lfs_sb_getssize(fs) * sizeof(struct ubuf *);
|
|
|
|
sp->bpp = emalloc(allocsize);
|
2003-12-24 04:39:27 +03:00
|
|
|
if (!sp->bpp)
|
2015-07-24 09:56:41 +03:00
|
|
|
err(!preen, "Could not allocate %zu bytes", allocsize);
|
2003-03-28 11:09:52 +03:00
|
|
|
sp->seg_flags = flags;
|
|
|
|
sp->vp = NULL;
|
|
|
|
sp->seg_iocount = 0;
|
|
|
|
(void) lfs_initseg(fs);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lfs_segunlock --
|
|
|
|
* Single thread the segment writer.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lfs_segunlock(struct lfs * fs)
|
|
|
|
{
|
|
|
|
struct segment *sp;
|
|
|
|
struct ubuf *bp;
|
|
|
|
|
|
|
|
sp = fs->lfs_sp;
|
|
|
|
|
|
|
|
if (fs->lfs_seglock == 1) {
|
|
|
|
if (sp->bpp != sp->cbpp) {
|
|
|
|
/* Free allocated segment summary */
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_suboffset(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
|
2003-03-28 11:09:52 +03:00
|
|
|
bp = *sp->bpp;
|
|
|
|
bremfree(bp);
|
|
|
|
bp->b_flags |= B_DONE | B_INVAL;
|
|
|
|
bp->b_flags &= ~B_DELWRI;
|
|
|
|
reassignbuf(bp, bp->b_vp);
|
|
|
|
bp->b_flags |= B_BUSY; /* XXX */
|
2007-10-09 01:39:49 +04:00
|
|
|
brelse(bp, 0);
|
2003-03-28 11:09:52 +03:00
|
|
|
} else
|
|
|
|
printf("unlock to 0 with no summary");
|
|
|
|
|
|
|
|
free(sp->bpp);
|
|
|
|
sp->bpp = NULL;
|
|
|
|
free(sp);
|
|
|
|
fs->lfs_sp = NULL;
|
|
|
|
|
|
|
|
fs->lfs_nactive = 0;
|
|
|
|
|
|
|
|
/* Since we *know* everything's on disk, write both sbs */
|
2015-07-24 09:59:31 +03:00
|
|
|
lfs_writesuper(fs, lfs_sb_getsboff(fs, 0));
|
|
|
|
lfs_writesuper(fs, lfs_sb_getsboff(fs, 1));
|
2003-03-28 11:09:52 +03:00
|
|
|
|
|
|
|
--fs->lfs_seglock;
|
|
|
|
fs->lfs_lockpid = 0;
|
|
|
|
} else if (fs->lfs_seglock == 0) {
|
2015-06-17 02:18:54 +03:00
|
|
|
errx(EXIT_FAILURE, "Seglock not held");
|
2003-03-28 11:09:52 +03:00
|
|
|
} else {
|
|
|
|
--fs->lfs_seglock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lfs_writevnodes(struct lfs *fs, struct segment *sp, int op)
|
|
|
|
{
|
|
|
|
struct inode *ip;
|
|
|
|
struct uvnode *vp;
|
|
|
|
int inodes_written = 0;
|
|
|
|
|
|
|
|
LIST_FOREACH(vp, &vnodelist, v_mntvnodes) {
|
|
|
|
if (vp->v_bmap_op != lfs_vop_bmap)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ip = VTOI(vp);
|
|
|
|
|
2007-10-11 00:42:20 +04:00
|
|
|
if ((op == VN_DIROP && !(vp->v_uflag & VU_DIROP)) ||
|
|
|
|
(op != VN_DIROP && (vp->v_uflag & VU_DIROP))) {
|
2003-03-28 11:09:52 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Write the inode/file if dirty and it's not the IFILE.
|
|
|
|
*/
|
2017-06-10 11:13:15 +03:00
|
|
|
if (ip->i_state & IN_ALLMOD || !LIST_EMPTY(&vp->v_dirtyblkhd)) {
|
2003-03-28 11:09:52 +03:00
|
|
|
if (ip->i_number != LFS_IFILE_INUM)
|
|
|
|
lfs_writefile(fs, sp, vp);
|
|
|
|
(void) lfs_writeinode(fs, sp, ip);
|
|
|
|
inodes_written++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return inodes_written;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-09-01 09:15:02 +03:00
|
|
|
lfs_writesuper(struct lfs *fs, daddr_t daddr)
|
2003-03-28 11:09:52 +03:00
|
|
|
{
|
|
|
|
struct ubuf *bp;
|
|
|
|
|
|
|
|
/* Set timestamp of this version of the superblock */
|
2015-08-02 21:14:16 +03:00
|
|
|
if (lfs_sb_getversion(fs) == 1)
|
2015-07-24 09:56:41 +03:00
|
|
|
lfs_sb_setotstamp(fs, write_time);
|
|
|
|
lfs_sb_settstamp(fs, write_time);
|
2003-03-28 11:09:52 +03:00
|
|
|
|
2015-08-02 21:18:09 +03:00
|
|
|
__CTASSERT(sizeof(struct dlfs) == sizeof(struct dlfs64));
|
|
|
|
|
2003-03-28 11:09:52 +03:00
|
|
|
/* Checksum the superblock and copy it into a buffer. */
|
2015-08-02 21:18:09 +03:00
|
|
|
lfs_sb_setcksum(fs, lfs_sb_cksum(fs));
|
2003-03-28 11:09:52 +03:00
|
|
|
assert(daddr > 0);
|
2013-06-18 22:18:57 +04:00
|
|
|
bp = getblk(fs->lfs_devvp, LFS_FSBTODB(fs, daddr), LFS_SBPAD);
|
2015-08-02 21:18:09 +03:00
|
|
|
memcpy(bp->b_data, &fs->lfs_dlfs_u, sizeof(struct dlfs));
|
2003-03-28 11:09:52 +03:00
|
|
|
memset(bp->b_data + sizeof(struct dlfs), 0,
|
|
|
|
LFS_SBPAD - sizeof(struct dlfs));
|
|
|
|
|
|
|
|
bwrite(bp);
|
|
|
|
}
|