2009-08-06 04:51:55 +04:00
|
|
|
/* $NetBSD: coalesce.c,v 1.18 2009/08/06 00:51:55 pooka Exp $ */
|
2002-06-06 04:56:49 +04:00
|
|
|
|
|
|
|
/*-
|
2006-03-30 23:10:13 +04:00
|
|
|
* Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
|
2002-06-06 04:56:49 +04: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/lfs/lfs.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <util.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <err.h>
|
|
|
|
|
|
|
|
#include <syslog.h>
|
|
|
|
|
2006-03-30 23:10:13 +04:00
|
|
|
#include "bufcache.h"
|
|
|
|
#include "vnode.h"
|
|
|
|
#include "cleaner.h"
|
2009-08-06 04:51:55 +04:00
|
|
|
#include "kernelops.h"
|
2002-06-06 04:56:49 +04:00
|
|
|
|
2002-06-14 04:58:39 +04:00
|
|
|
extern int debug, do_mmap;
|
2002-06-06 04:56:49 +04:00
|
|
|
|
2006-03-30 23:10:13 +04:00
|
|
|
int log2int(int n)
|
2002-06-14 04:58:39 +04:00
|
|
|
{
|
|
|
|
int log;
|
|
|
|
|
|
|
|
log = 0;
|
|
|
|
while (n > 0) {
|
|
|
|
++log;
|
2006-03-30 23:10:13 +04:00
|
|
|
n >>= 1;
|
2002-06-14 04:58:39 +04:00
|
|
|
}
|
|
|
|
return log - 1;
|
|
|
|
}
|
|
|
|
|
2002-06-14 09:21:21 +04:00
|
|
|
enum coalesce_returncodes {
|
|
|
|
COALESCE_OK = 0,
|
|
|
|
COALESCE_NOINODE,
|
|
|
|
COALESCE_TOOSMALL,
|
|
|
|
COALESCE_BADSIZE,
|
|
|
|
COALESCE_BADBLOCKSIZE,
|
|
|
|
COALESCE_NOMEM,
|
|
|
|
COALESCE_BADBMAPV,
|
2006-03-30 23:10:13 +04:00
|
|
|
COALESCE_BADMARKV,
|
2002-06-14 09:21:21 +04:00
|
|
|
COALESCE_NOTWORTHIT,
|
|
|
|
COALESCE_NOTHINGLEFT,
|
2002-12-15 11:38:17 +03:00
|
|
|
COALESCE_EIO,
|
2002-06-14 09:21:21 +04:00
|
|
|
|
|
|
|
COALESCE_MAXERROR
|
|
|
|
};
|
|
|
|
|
2009-03-16 03:08:10 +03:00
|
|
|
const char *coalesce_return[] = {
|
2002-06-14 09:21:21 +04:00
|
|
|
"Successfully coalesced",
|
|
|
|
"File not in use or inode not found",
|
|
|
|
"Not large enough to coalesce",
|
|
|
|
"Negative size",
|
|
|
|
"Not enough blocks to account for size",
|
|
|
|
"Malloc failed",
|
2003-02-26 02:12:06 +03:00
|
|
|
"LFCNBMAPV failed",
|
2002-06-14 09:21:21 +04:00
|
|
|
"Not broken enough to fix",
|
|
|
|
"Too many blocks not found",
|
|
|
|
"Too many blocks found in active segments",
|
2002-12-15 11:38:17 +03:00
|
|
|
"I/O error",
|
2002-06-14 09:21:21 +04:00
|
|
|
|
|
|
|
"No such error"
|
|
|
|
};
|
|
|
|
|
2006-03-30 23:10:13 +04:00
|
|
|
static struct ufs1_dinode *
|
|
|
|
get_dinode(struct clfs *fs, ino_t ino)
|
|
|
|
{
|
|
|
|
IFILE *ifp;
|
|
|
|
daddr_t daddr;
|
|
|
|
struct ubuf *bp;
|
|
|
|
struct ufs1_dinode *dip, *r;
|
|
|
|
|
|
|
|
lfs_ientry(&ifp, fs, ino, &bp);
|
|
|
|
daddr = ifp->if_daddr;
|
2007-10-09 01:41:12 +04:00
|
|
|
brelse(bp, 0);
|
2006-03-30 23:10:13 +04:00
|
|
|
|
|
|
|
if (daddr == 0x0)
|
|
|
|
return NULL;
|
|
|
|
|
2008-05-16 13:21:59 +04:00
|
|
|
bread(fs->clfs_devvp, daddr, fs->lfs_ibsize, NOCRED, 0, &bp);
|
2006-03-30 23:10:13 +04:00
|
|
|
for (dip = (struct ufs1_dinode *)bp->b_data;
|
|
|
|
dip < (struct ufs1_dinode *)(bp->b_data + fs->lfs_ibsize); dip++)
|
|
|
|
if (dip->di_inumber == ino) {
|
|
|
|
r = (struct ufs1_dinode *)malloc(sizeof(*r));
|
|
|
|
memcpy(r, dip, sizeof(*r));
|
2007-10-09 01:41:12 +04:00
|
|
|
brelse(bp, 0);
|
2006-03-30 23:10:13 +04:00
|
|
|
return r;
|
|
|
|
}
|
2007-10-09 01:41:12 +04:00
|
|
|
brelse(bp, 0);
|
2006-03-30 23:10:13 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-06 04:56:49 +04:00
|
|
|
/*
|
|
|
|
* Find out if this inode's data blocks are discontinuous; if they are,
|
2003-02-24 11:48:17 +03:00
|
|
|
* rewrite them using markv. Return the number of inodes rewritten.
|
2002-06-06 04:56:49 +04:00
|
|
|
*/
|
2006-03-30 23:10:13 +04:00
|
|
|
static int
|
|
|
|
clean_inode(struct clfs *fs, ino_t ino)
|
2002-06-06 04:56:49 +04:00
|
|
|
{
|
2003-02-24 11:48:17 +03:00
|
|
|
BLOCK_INFO *bip = NULL, *tbip;
|
2006-03-30 23:10:13 +04:00
|
|
|
CLEANERINFO cip;
|
|
|
|
struct ubuf *bp;
|
2003-04-02 14:39:19 +04:00
|
|
|
struct ufs1_dinode *dip;
|
2006-03-30 23:10:13 +04:00
|
|
|
struct clfs_seguse *sup;
|
|
|
|
struct lfs_fcntl_markv /* {
|
|
|
|
BLOCK_INFO *blkiov;
|
|
|
|
int blkcnt;
|
|
|
|
} */ lim;
|
2003-01-25 00:55:02 +03:00
|
|
|
daddr_t toff;
|
2006-03-30 23:10:13 +04:00
|
|
|
int i;
|
|
|
|
int nb, onb, noff;
|
2002-12-15 11:38:17 +03:00
|
|
|
int retval;
|
2006-03-30 23:10:13 +04:00
|
|
|
int bps;
|
2002-06-06 04:56:49 +04:00
|
|
|
|
2006-03-30 23:10:13 +04:00
|
|
|
dip = get_dinode(fs, ino);
|
2002-06-06 04:56:49 +04:00
|
|
|
if (dip == NULL)
|
2002-06-14 09:21:21 +04:00
|
|
|
return COALESCE_NOINODE;
|
2002-06-06 04:56:49 +04:00
|
|
|
|
2003-02-24 11:48:17 +03:00
|
|
|
/* Compute file block size, set up for bmapv */
|
2006-03-30 23:10:13 +04:00
|
|
|
onb = nb = lblkno(fs, dip->di_size);
|
2002-06-14 04:58:39 +04:00
|
|
|
|
|
|
|
/* XXX for now, don't do any file small enough to have fragments */
|
2006-04-02 03:53:11 +04:00
|
|
|
if (nb < NDADDR) {
|
|
|
|
free(dip);
|
2002-06-14 09:21:21 +04:00
|
|
|
return COALESCE_TOOSMALL;
|
2006-04-02 03:53:11 +04:00
|
|
|
}
|
2002-06-14 04:58:39 +04:00
|
|
|
|
|
|
|
/* Sanity checks */
|
2009-03-16 03:08:10 +03:00
|
|
|
#if 0 /* di_size is uint64_t -- this is a noop */
|
2002-06-14 04:58:39 +04:00
|
|
|
if (dip->di_size < 0) {
|
2006-03-30 23:10:13 +04:00
|
|
|
dlog("ino %d, negative size (%" PRId64 ")", ino, dip->di_size);
|
2006-04-02 03:53:11 +04:00
|
|
|
free(dip);
|
2002-06-14 09:21:21 +04:00
|
|
|
return COALESCE_BADSIZE;
|
2002-06-14 04:58:39 +04:00
|
|
|
}
|
2009-03-16 03:08:10 +03:00
|
|
|
#endif
|
2002-06-06 04:56:49 +04:00
|
|
|
if (nb > dip->di_blocks) {
|
2006-03-30 23:10:13 +04:00
|
|
|
dlog("ino %d, computed blocks %d > held blocks %d", ino, nb,
|
|
|
|
dip->di_blocks);
|
2006-04-02 03:53:11 +04:00
|
|
|
free(dip);
|
2002-06-14 09:21:21 +04:00
|
|
|
return COALESCE_BADBLOCKSIZE;
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
2002-06-14 04:58:39 +04:00
|
|
|
|
2003-02-24 11:48:17 +03:00
|
|
|
bip = (BLOCK_INFO *)malloc(sizeof(BLOCK_INFO) * nb);
|
2002-06-06 04:56:49 +04:00
|
|
|
if (bip == NULL) {
|
2005-08-19 06:06:29 +04:00
|
|
|
syslog(LOG_WARNING, "ino %llu, %d blocks: %m",
|
|
|
|
(unsigned long long)ino, nb);
|
2006-04-02 03:53:11 +04:00
|
|
|
free(dip);
|
2002-06-14 09:21:21 +04:00
|
|
|
return COALESCE_NOMEM;
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
|
|
|
for (i = 0; i < nb; i++) {
|
2003-02-24 11:48:17 +03:00
|
|
|
memset(bip + i, 0, sizeof(BLOCK_INFO));
|
2002-06-06 04:56:49 +04:00
|
|
|
bip[i].bi_inode = ino;
|
|
|
|
bip[i].bi_lbn = i;
|
2002-06-14 04:58:39 +04:00
|
|
|
bip[i].bi_version = dip->di_gen;
|
2002-06-06 04:56:49 +04:00
|
|
|
/* Don't set the size, but let lfs_bmap fill it in */
|
|
|
|
}
|
2006-03-30 23:10:13 +04:00
|
|
|
lim.blkiov = bip;
|
|
|
|
lim.blkcnt = nb;
|
2009-08-06 04:51:55 +04:00
|
|
|
if (kops.ko_fcntl(fs->clfs_ifilefd, LFCNBMAPV, &lim) < 0) {
|
2006-03-30 23:10:13 +04:00
|
|
|
syslog(LOG_WARNING, "%s: coalesce: LFCNBMAPV: %m",
|
|
|
|
fs->lfs_fsmnt);
|
2002-12-15 11:38:17 +03:00
|
|
|
retval = COALESCE_BADBMAPV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
for (i = 0; i < nb; i++) {
|
|
|
|
printf("bi_size = %d, bi_ino = %d, "
|
|
|
|
"bi_lbn = %d, bi_daddr = %d\n",
|
|
|
|
bip[i].bi_size, bip[i].bi_inode, bip[i].bi_lbn,
|
|
|
|
bip[i].bi_daddr);
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
2002-12-15 11:38:17 +03:00
|
|
|
#endif
|
2002-06-06 04:56:49 +04:00
|
|
|
noff = toff = 0;
|
|
|
|
for (i = 1; i < nb; i++) {
|
2006-03-30 23:10:13 +04:00
|
|
|
if (bip[i].bi_daddr != bip[i - 1].bi_daddr + fs->lfs_frag)
|
2002-06-06 04:56:49 +04:00
|
|
|
++noff;
|
2002-11-24 11:47:28 +03:00
|
|
|
toff += abs(bip[i].bi_daddr - bip[i - 1].bi_daddr
|
2006-03-30 23:10:13 +04:00
|
|
|
- fs->lfs_frag) >> fs->lfs_fbshift;
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this file is not discontinuous, there's no point in rewriting it.
|
2006-03-30 23:10:13 +04:00
|
|
|
*
|
|
|
|
* Explicitly allow a certain amount of discontinuity, since large
|
|
|
|
* files will be broken among segments and medium-sized files
|
|
|
|
* can have a break or two and it's okay.
|
2002-06-06 04:56:49 +04:00
|
|
|
*/
|
2002-06-14 04:58:39 +04:00
|
|
|
if (nb <= 1 || noff == 0 || noff < log2int(nb) ||
|
2006-03-30 23:10:13 +04:00
|
|
|
segtod(fs, noff) * 2 < nb) {
|
2002-12-15 11:38:17 +03:00
|
|
|
retval = COALESCE_NOTWORTHIT;
|
|
|
|
goto out;
|
2002-06-06 04:56:49 +04:00
|
|
|
} else if (debug)
|
2005-08-19 06:06:29 +04:00
|
|
|
syslog(LOG_DEBUG, "ino %llu total discontinuity "
|
|
|
|
"%d (%lld) for %d blocks", (unsigned long long)ino,
|
|
|
|
noff, (long long)toff, nb);
|
2002-06-06 04:56:49 +04:00
|
|
|
|
|
|
|
/* Search for blocks in active segments; don't move them. */
|
|
|
|
for (i = 0; i < nb; i++) {
|
|
|
|
if (bip[i].bi_daddr <= 0)
|
|
|
|
continue;
|
2006-03-30 23:10:13 +04:00
|
|
|
sup = &fs->clfs_segtab[dtosn(fs, bip[i].bi_daddr)];
|
|
|
|
if (sup->flags & SEGUSE_ACTIVE)
|
2002-06-06 04:56:49 +04:00
|
|
|
bip[i].bi_daddr = LFS_UNUSED_DADDR; /* 0 */
|
|
|
|
}
|
2006-03-30 23:10:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get rid of any blocks we've marked dead. If this is an older
|
|
|
|
* kernel that doesn't have bmapv fill in the block sizes, we'll
|
|
|
|
* toss everything here.
|
2002-06-06 04:56:49 +04:00
|
|
|
*/
|
2006-03-30 23:10:13 +04:00
|
|
|
onb = nb;
|
2006-05-12 23:33:02 +04:00
|
|
|
toss_old_blocks(fs, &bip, &nb, NULL);
|
2006-03-30 23:10:13 +04:00
|
|
|
nb = i;
|
2002-06-06 04:56:49 +04:00
|
|
|
|
2002-06-14 04:58:39 +04:00
|
|
|
/*
|
|
|
|
* We may have tossed enough blocks that it is no longer worthwhile
|
|
|
|
* to rewrite this inode.
|
|
|
|
*/
|
2006-03-30 23:10:13 +04:00
|
|
|
if (nb == 0 || onb - nb > log2int(onb)) {
|
2002-06-14 09:21:21 +04:00
|
|
|
if (debug)
|
|
|
|
syslog(LOG_DEBUG, "too many blocks tossed, not rewriting");
|
2006-03-30 23:10:13 +04:00
|
|
|
retval = COALESCE_NOTHINGLEFT;
|
|
|
|
goto out;
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
|
|
|
|
2006-03-30 23:10:13 +04:00
|
|
|
/*
|
2002-06-06 04:56:49 +04:00
|
|
|
* We are going to rewrite this inode.
|
|
|
|
* For any remaining blocks, read in their contents.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < nb; i++) {
|
|
|
|
bip[i].bi_bp = malloc(bip[i].bi_size);
|
2002-12-15 11:38:17 +03:00
|
|
|
if (bip[i].bi_bp == NULL) {
|
|
|
|
syslog(LOG_WARNING, "allocate block buffer size=%d: %m",
|
|
|
|
bip[i].bi_size);
|
|
|
|
retval = COALESCE_NOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2006-03-30 23:10:13 +04:00
|
|
|
|
2009-08-06 04:51:55 +04:00
|
|
|
if (kops.ko_pread(fs->clfs_devfd, bip[i].bi_bp, bip[i].bi_size,
|
2006-03-30 23:10:13 +04:00
|
|
|
fsbtob(fs, bip[i].bi_daddr)) < 0) {
|
2002-12-15 11:38:17 +03:00
|
|
|
retval = COALESCE_EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
|
|
|
if (debug)
|
2005-08-19 06:06:29 +04:00
|
|
|
syslog(LOG_DEBUG, "ino %llu markv %d blocks",
|
|
|
|
(unsigned long long)ino, nb);
|
2002-06-06 04:56:49 +04:00
|
|
|
|
2002-06-14 04:58:39 +04:00
|
|
|
/*
|
|
|
|
* Write in segment-sized chunks. If at any point we'd write more
|
|
|
|
* than half of the available segments, sleep until that's not
|
|
|
|
* true any more.
|
|
|
|
*/
|
2006-03-30 23:10:13 +04:00
|
|
|
bps = segtod(fs, 1);
|
2002-06-06 04:56:49 +04:00
|
|
|
for (tbip = bip; tbip < bip + nb; tbip += bps) {
|
2006-03-30 23:10:13 +04:00
|
|
|
do {
|
2008-05-16 13:21:59 +04:00
|
|
|
bread(fs->lfs_ivnode, 0, fs->lfs_bsize, NOCRED, 0, &bp);
|
2006-03-30 23:10:13 +04:00
|
|
|
cip = *(CLEANERINFO *)bp->b_data;
|
2007-10-09 01:41:12 +04:00
|
|
|
brelse(bp, B_INVAL);
|
2006-03-30 23:10:13 +04:00
|
|
|
|
|
|
|
if (cip.clean < 4) /* XXX magic number 4 */
|
2009-08-06 04:51:55 +04:00
|
|
|
kops.ko_fcntl(fs->clfs_ifilefd,
|
|
|
|
LFCNSEGWAIT, NULL);
|
2006-03-30 23:10:13 +04:00
|
|
|
} while(cip.clean < 4);
|
|
|
|
|
|
|
|
lim.blkiov = tbip;
|
|
|
|
lim.blkcnt = (tbip + bps < bip + nb ? bps : nb % bps);
|
2009-08-06 04:51:55 +04:00
|
|
|
if (kops.ko_fcntl(fs->clfs_ifilefd, LFCNMARKV, &lim) < 0) {
|
2006-03-30 23:10:13 +04:00
|
|
|
retval = COALESCE_BADMARKV;
|
|
|
|
goto out;
|
2002-06-14 04:58:39 +04:00
|
|
|
}
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
|
|
|
|
2002-12-15 11:38:17 +03:00
|
|
|
retval = COALESCE_OK;
|
|
|
|
out:
|
2006-03-30 23:10:13 +04:00
|
|
|
free(dip);
|
2002-12-15 11:38:17 +03:00
|
|
|
if (bip) {
|
|
|
|
for (i = 0; i < onb; i++)
|
|
|
|
if (bip[i].bi_bp)
|
|
|
|
free(bip[i].bi_bp);
|
|
|
|
free(bip);
|
|
|
|
}
|
|
|
|
return retval;
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try coalescing every inode in the filesystem.
|
|
|
|
* Return the number of inodes actually altered.
|
|
|
|
*/
|
2006-03-30 23:10:13 +04:00
|
|
|
int clean_all_inodes(struct clfs *fs)
|
2002-06-06 04:56:49 +04:00
|
|
|
{
|
2006-03-30 23:10:13 +04:00
|
|
|
int i, r, maxino;
|
2002-06-14 09:21:21 +04:00
|
|
|
int totals[COALESCE_MAXERROR];
|
2006-03-30 23:10:13 +04:00
|
|
|
struct stat st;
|
2002-06-06 04:56:49 +04:00
|
|
|
|
2002-06-14 09:21:21 +04:00
|
|
|
memset(totals, 0, sizeof(totals));
|
2006-03-30 23:10:13 +04:00
|
|
|
|
|
|
|
fstat(fs->clfs_ifilefd, &st);
|
|
|
|
maxino = fs->lfs_ifpb * (st.st_size >> fs->lfs_bshift) -
|
|
|
|
fs->lfs_segtabsz - fs->lfs_cleansz;
|
|
|
|
|
|
|
|
for (i = 0; i < maxino; i++) {
|
|
|
|
r = clean_inode(fs, i);
|
2002-06-14 09:21:21 +04:00
|
|
|
++totals[r];
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
2002-06-14 09:21:21 +04:00
|
|
|
|
|
|
|
for (i = 0; i < COALESCE_MAXERROR; i++)
|
|
|
|
if (totals[i])
|
|
|
|
syslog(LOG_DEBUG, "%s: %d", coalesce_return[i],
|
2006-03-30 23:10:13 +04:00
|
|
|
totals[i]);
|
|
|
|
|
2002-06-14 09:21:21 +04:00
|
|
|
return totals[COALESCE_OK];
|
2002-06-06 04:56:49 +04:00
|
|
|
}
|
|
|
|
|
2006-03-30 23:10:13 +04:00
|
|
|
/*
|
|
|
|
* Fork a child process to coalesce this fs.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fork_coalesce(struct clfs *fs)
|
2002-06-06 04:56:49 +04:00
|
|
|
{
|
|
|
|
static pid_t childpid;
|
2002-06-14 04:58:39 +04:00
|
|
|
int num;
|
|
|
|
|
2006-03-30 23:10:13 +04:00
|
|
|
/*
|
|
|
|
* If already running a coalescing child, don't start a new one.
|
|
|
|
*/
|
2002-06-06 04:56:49 +04:00
|
|
|
if (childpid) {
|
2006-03-30 23:10:13 +04:00
|
|
|
if (waitpid(childpid, NULL, WNOHANG) == childpid)
|
2002-06-06 04:56:49 +04:00
|
|
|
childpid = 0;
|
|
|
|
}
|
|
|
|
if (childpid && kill(childpid, 0) >= 0) {
|
|
|
|
/* already running a coalesce process */
|
2002-06-14 04:58:39 +04:00
|
|
|
if (debug)
|
|
|
|
syslog(LOG_DEBUG, "coalescing already in progress");
|
2002-06-06 04:56:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2006-03-30 23:10:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fork a child and let the child coalease
|
|
|
|
*/
|
2002-06-06 04:56:49 +04:00
|
|
|
childpid = fork();
|
|
|
|
if (childpid < 0) {
|
2006-03-30 23:10:13 +04:00
|
|
|
syslog(LOG_ERR, "%s: fork to coaleasce: %m", fs->lfs_fsmnt);
|
2002-06-06 04:56:49 +04:00
|
|
|
return 0;
|
|
|
|
} else if (childpid == 0) {
|
2006-03-30 23:10:13 +04:00
|
|
|
syslog(LOG_NOTICE, "%s: new coalescing process, pid %d",
|
|
|
|
fs->lfs_fsmnt, getpid());
|
|
|
|
num = clean_all_inodes(fs);
|
|
|
|
syslog(LOG_NOTICE, "%s: coalesced %d discontiguous inodes",
|
|
|
|
fs->lfs_fsmnt, num);
|
2002-06-06 04:56:49 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
2006-03-30 23:10:13 +04:00
|
|
|
|
2002-06-06 04:56:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|