summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-11-24 07:27:06 +0000
committercharnier <charnier@FreeBSD.org>1997-11-24 07:27:06 +0000
commit2066ba97cf5c286395d1e3584cff4e8fdb31a545 (patch)
tree9977be3575366e0e8048c1a3c6b51ac9b87b8085 /libexec
parente3613c1ac3a4b511341940c0bfc4df0ddbdc8582 (diff)
downloadFreeBSD-src-2066ba97cf5c286395d1e3584cff4e8fdb31a545.zip
FreeBSD-src-2066ba97cf5c286395d1e3584cff4e8fdb31a545.tar.gz
Use err(3) instead of local redefinition. Add usage. -Wall cleaning.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/lfs_cleanerd/cleanerd.c49
-rw-r--r--libexec/lfs_cleanerd/lfs_cleanerd.86
-rw-r--r--libexec/lfs_cleanerd/library.c58
-rw-r--r--libexec/lfs_cleanerd/misc.c49
-rw-r--r--libexec/lfs_cleanerd/print.c10
5 files changed, 79 insertions, 93 deletions
diff --git a/libexec/lfs_cleanerd/cleanerd.c b/libexec/lfs_cleanerd/cleanerd.c
index f8877a8..d909107 100644
--- a/libexec/lfs_cleanerd/cleanerd.c
+++ b/libexec/lfs_cleanerd/cleanerd.c
@@ -29,18 +29,20 @@
* 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.
- *
- * $Id: cleanerd.c,v 1.6 1997/02/22 14:21:44 peter Exp $
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)cleanerd.c 8.2 (Berkeley) 1/13/94";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/param.h>
@@ -50,13 +52,13 @@ static char sccsid[] = "@(#)cleanerd.c 8.2 (Berkeley) 1/13/94";
#include <ufs/ufs/dinode.h>
#include <ufs/lfs/lfs.h>
+#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "clean.h"
-char *special = "cleanerd";
int do_small = 0;
int do_mmap = 0;
struct cleaner_stats {
@@ -94,6 +96,7 @@ int clean_segment __P((FS_INFO *, int));
int cost_benefit __P((FS_INFO *, SEGUSE *));
int cost_compare __P((const void *, const void *));
void sig_report __P((int));
+static void usage __P((void));
/*
* Cleaning Cost Functions:
@@ -136,7 +139,7 @@ cost_benefit(fsp, su)
*/
#ifdef VERBOSE
if (live < 0 || live > seg_size(lfsp)) {
- err(0, "Bad segusage count: %d", live);
+ warnx("bad segusage count: %d", live);
live = 0;
}
#endif
@@ -154,10 +157,9 @@ main(argc, argv)
struct statfs *lstatfsp; /* file system stats */
struct timeval timeout; /* sleep timeout */
fsid_t fsid;
- int i, nodaemon;
+ int nodaemon;
int opt, cmd_err;
char *fs_name; /* name of filesystem to clean */
- extern int optind;
cmd_err = nodaemon = 0;
while ((opt = getopt(argc, argv, "smd")) != -1) {
@@ -178,7 +180,7 @@ main(argc, argv)
argc -= optind;
argv += optind;
if (cmd_err || (argc != 1))
- err(1, "usage: lfs_cleanerd [-smd] fs_name");
+ usage();
fs_name = argv[0];
@@ -187,12 +189,12 @@ main(argc, argv)
signal(SIGUSR2, sig_report);
if (fs_getmntinfo(&lstatfsp, fs_name, MOUNT_LFS) == 0) {
/* didn't find the filesystem */
- err(1, "lfs_cleanerd: filesystem %s isn't an LFS!", fs_name);
+ errx(1, "filesystem %s isn't an LFS", fs_name);
}
if (!nodaemon) /* should we become a daemon, chdir to / & close fd's */
if (daemon(0, 0) == -1)
- err(1, "lfs_cleanerd: couldn't become a daemon!");
+ errx(1, "couldn't become a daemon");
timeout.tv_sec = 5*60; /* five minutes */
timeout.tv_usec = 0;
@@ -214,13 +216,20 @@ main(argc, argv)
(void)printf("Cleaner going to sleep.\n");
#endif
if (lfs_segwait(&fsid, &timeout) < 0)
- err(0, "lfs_segwait: returned error\n");
+ warnx("lfs_segwait: returned error");
#ifdef VERBOSE
(void)printf("Cleaner waking up.\n");
#endif
}
}
+static void
+usage()
+{
+ fprintf(stderr, "usage: lfs_cleanerd [-smd] fs_name\n");
+ exit (1);
+}
+
/* return the number of segments cleaned */
int
clean_loop(fsp)
@@ -244,7 +253,7 @@ clean_loop(fsp)
if (fsp->fi_cip->clean < max_free_segs &&
(fsp->fi_cip->clean <= MIN_SEGS(&fsp->fi_lfs) ||
fsp->fi_cip->clean < max_free_segs * BUSY_LIM)) {
- printf("Cleaner Running at %s (%d of %d segments available)\n",
+ printf("Cleaner Running at %s (%d of %ld segments available)\n",
ctime(&now), fsp->fi_cip->clean, max_free_segs);
clean_fs(fsp, cost_benefit);
return (1);
@@ -255,7 +264,7 @@ clean_loop(fsp)
* clean space.
*/
if (getloadavg(loadavg, MAXLOADS) == -1) {
- perror("getloadavg: failed\n");
+ warn("getloadavg failed");
return (-1);
}
if (loadavg[ONE_MIN] == 0.2 && loadavg[FIVE_MIN] &&
@@ -283,7 +292,7 @@ clean_fs(fsp, cost_func)
if ((segs =
malloc(fsp->fi_lfs.lfs_nseg * sizeof(struct seglist))) == NULL) {
- err(0, "malloc failed");
+ warnx("malloc failed");
return;
}
i = choose_segments(fsp, segs, cost_func);
@@ -295,10 +304,10 @@ clean_fs(fsp, cost_func)
if (i)
for (i = MIN(i, NUM_TO_CLEAN(fsp)), sp = segs; i-- ; ++sp) {
if (clean_segment(fsp, sp->sl_id) < 0)
- perror("clean_segment failed");
+ warn("clean_segment failed");
else if (lfs_segclean(&fsp->fi_statfsp->f_fsid,
sp->sl_id) < 0)
- perror("lfs_segclean failed");
+ warn("lfs_segclean failed");
printf("Completed cleaning segment %d\n", sp->sl_id);
}
free(segs);
@@ -393,13 +402,13 @@ clean_segment(fsp, id)
/* map the segment into a buffer */
if (mmap_segment(fsp, id, &seg_buf, do_mmap) < 0) {
- err(0, "mmap_segment failed");
+ warn("mmap_segment failed");
++cleaner_stats.segs_error;
return (-1);
}
/* get a list of blocks that are contained by the segment */
if (lfs_segmapv(fsp, id, seg_buf, &block_array, &num_blocks) < 0) {
- err(0, "clean_segment: lfs_segmapv failed");
+ warn("clean_segment: lfs_segmapv failed");
++cleaner_stats.segs_error;
return (-1);
}
@@ -412,7 +421,7 @@ clean_segment(fsp, id)
/* get the current disk address of blocks contained by the segment */
if (lfs_bmapv(&fsp->fi_statfsp->f_fsid, block_array, num_blocks) < 0) {
- perror("clean_segment: lfs_bmapv failed\n");
+ warn("clean_segment: lfs_bmapv failed");
++cleaner_stats.segs_error;
return -1;
}
@@ -452,7 +461,7 @@ clean_segment(fsp, id)
clean_blocks = maxblocks < num_blocks ? maxblocks : num_blocks;
if (lfs_markv(&fsp->fi_statfsp->f_fsid,
bp, clean_blocks) < 0) {
- err(0, "clean_segment: lfs_markv failed");
+ warn("clean_segment: lfs_markv failed");
++cleaner_stats.segs_error;
return (-1);
}
diff --git a/libexec/lfs_cleanerd/lfs_cleanerd.8 b/libexec/lfs_cleanerd/lfs_cleanerd.8
index cd09119..7ce8c33 100644
--- a/libexec/lfs_cleanerd/lfs_cleanerd.8
+++ b/libexec/lfs_cleanerd/lfs_cleanerd.8
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)lfs_cleanerd.8 8.2 (Berkeley) 12/11/93
-.\" $Id: lfs_cleanerd.8,v 1.5 1997/02/22 14:21:45 peter Exp $
+.\" $Id: lfs_cleanerd.8,v 1.6 1997/06/23 04:02:09 steve Exp $
.\"
.Dd December 11, 1993
.Dt LFS_CLEANERD 8
@@ -44,7 +44,7 @@
.Pa node
.Sh DESCRIPTION
The
-.Nm lfs_cleanerd
+.Nm
command starts a daemon process which garbage-collects
the log-structured file system residing at the point named by
.Ar node
@@ -74,6 +74,6 @@ When cleaning the file system, read data in small chunks.
.Xr mount_lfs 8
.Sh HISTORY
The
-.Nm lfs_cleanerd
+.Nm
utility first appeared in
.Bx 4.4 .
diff --git a/libexec/lfs_cleanerd/library.c b/libexec/lfs_cleanerd/library.c
index 1a83076..a7094bb 100644
--- a/libexec/lfs_cleanerd/library.c
+++ b/libexec/lfs_cleanerd/library.c
@@ -29,12 +29,14 @@
* 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.
- *
- * $Id: library.c,v 1.7 1997/02/22 14:21:45 peter Exp $
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)library.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/param.h>
@@ -47,6 +49,7 @@ static char sccsid[] = "@(#)library.c 8.1 (Berkeley) 6/4/93";
#include <ufs/ufs/dinode.h>
#include <ufs/lfs/lfs.h>
+#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -61,6 +64,7 @@ void add_inodes __P((FS_INFO *, BLOCK_INFO *, int *, SEGSUM *, caddr_t,
daddr_t));
int bi_compare __P((const void *, const void *));
int bi_toss __P((const void *, const void *, const void *));
+u_long cksum __P((void *, size_t));
void get_ifile __P((FS_INFO *, int));
int get_superblock __P((FS_INFO *, struct lfs *));
int pseg_valid __P((FS_INFO *, SEGSUM *));
@@ -109,7 +113,6 @@ get_fs_info (lstatfsp, use_mmap)
int use_mmap; /* IN: mmap or read */
{
FS_INFO *fsp;
- int i;
fsp = (FS_INFO *)malloc(sizeof(FS_INFO));
if (fsp == NULL)
@@ -118,7 +121,7 @@ get_fs_info (lstatfsp, use_mmap)
fsp->fi_statfsp = lstatfsp;
if (get_superblock (fsp, &fsp->fi_lfs))
- err(1, "get_fs_info: get_superblock failed");
+ errx(1, "get_fs_info: get_superblock failed");
fsp->fi_daddr_shift =
fsp->fi_lfs.lfs_bshift - fsp->fi_lfs.lfs_fsbtodb;
get_ifile (fsp, use_mmap);
@@ -135,10 +138,8 @@ reread_fs_info(fsp, use_mmap)
FS_INFO *fsp; /* IN: prointer fs_infos to reread */
int use_mmap;
{
- int i;
-
if (statfs(fsp->fi_statfsp->f_mntonname, fsp->fi_statfsp))
- err(1, "reread_fs_info: statfs failed");
+ errx(1, "reread_fs_info: statfs failed");
get_ifile (fsp, use_mmap);
}
@@ -157,7 +158,7 @@ get_superblock (fsp, sbp)
strcat(mntfromname, fsp->fi_statfsp->f_mntfromname+5);
if ((fid = open(mntfromname, O_RDONLY, (mode_t)0)) < 0) {
- err(0, "get_superblock: bad open");
+ warn("get_superblock: bad open");
return (-1);
}
@@ -211,14 +212,14 @@ get_ifile (fsp, use_mmap)
if (fsp->fi_cip)
free(fsp->fi_cip);
if (!(ifp = malloc (file_stat.st_size)))
- err (1, "get_ifile: malloc failed");
+ errx(1, "get_ifile: malloc failed");
redo_read:
count = read (fid, ifp, (size_t) file_stat.st_size);
if (count < 0)
err(1, "get_ifile: bad ifile read");
else if (count < file_stat.st_size) {
- err(0, "get_ifile");
+ warnx("get_ifile");
if (lseek(fid, 0, SEEK_SET) < 0)
err(1, "get_ifile: bad ifile lseek");
goto redo_read;
@@ -262,11 +263,14 @@ lfs_segmapv(fsp, seg, seg_buf, blocks, bcount)
BLOCK_INFO *bip;
SEGSUM *sp;
SEGUSE *sup;
- FINFO *fip;
struct lfs *lfsp;
caddr_t s, segend;
daddr_t pseg_addr, seg_addr;
- int i, nelem, nblocks, sumsize;
+ int nelem, nblocks;
+#ifdef DIAGNOSTIC
+ FINFO *fip;
+ int i, sumsize;
+#endif /* DIAGNOSTIC */
time_t timestamp;
lfsp = &fsp->fi_lfs;
@@ -277,9 +281,10 @@ lfs_segmapv(fsp, seg, seg_buf, blocks, bcount)
sup = SEGUSE_ENTRY(lfsp, fsp->fi_segusep, seg);
s = seg_buf + (sup->su_flags & SEGUSE_SUPERBLOCK ? LFS_SBPAD : 0);
seg_addr = sntoda(lfsp, seg);
- pseg_addr = seg_addr + (sup->su_flags & SEGUSE_SUPERBLOCK ? btodb(LFS_SBPAD) : 0);
+ pseg_addr = seg_addr +
+ (sup->su_flags & SEGUSE_SUPERBLOCK ? btodb(LFS_SBPAD) : 0);
#ifdef VERBOSE
- printf("\tsegment buffer at: 0x%x\tseg_addr 0x%x\n", s, seg_addr);
+ printf("\tsegment buffer at: 0x%x\tseg_addr 0x%x\n", s, seg_addr);
#endif /* VERBOSE */
*bcount = 0;
@@ -310,12 +315,9 @@ lfs_segmapv(fsp, seg, seg_buf, blocks, bcount)
(fip->fi_nblocks - 1) * sizeof(daddr_t);
fip = (FINFO *)(&fip->fi_blocks[fip->fi_nblocks]);
}
- if (sumsize > LFS_SUMMARY_SIZE) {
- fprintf(stderr,
- "Segment %d summary block too big: %d\n",
+ if (sumsize > LFS_SUMMARY_SIZE)
+ errx(1, "segment %d summary block too big: %d",
seg, sumsize);
- exit(1);
- }
#endif
if (*bcount + nblocks + sp->ss_ninos > nelem) {
@@ -424,7 +426,7 @@ add_inodes (fsp, bip, countp, sp, seg_buf, seg_addr)
caddr_t seg_buf; /* the buffer containing the segment's data */
daddr_t seg_addr; /* disk address of seg_buf */
{
- struct dinode *di;
+ struct dinode *di = NULL;
struct lfs *lfsp;
IFILE *ifp;
BLOCK_INFO *bp;
@@ -535,7 +537,7 @@ mmap_segment (fsp, segment, segbuf, use_mmap)
strcat(mntfromname, fsp->fi_statfsp->f_mntfromname+5);
if ((fid = open(mntfromname, O_RDONLY, (mode_t)0)) < 0) {
- err(0, "mmap_segment: bad open");
+ warn("mmap_segment: bad open");
return (-1);
}
@@ -543,7 +545,7 @@ mmap_segment (fsp, segment, segbuf, use_mmap)
*segbuf = mmap ((caddr_t)0, seg_size(lfsp), PROT_READ,
MAP_SHARED, fid, seg_byte);
if (*segbuf == MAP_FAILED) {
- err(0, "mmap_segment: mmap failed");
+ warn("mmap_segment: mmap failed");
return (0);
}
} else {
@@ -554,19 +556,19 @@ mmap_segment (fsp, segment, segbuf, use_mmap)
/* malloc the space for the buffer */
*segbuf = malloc(ssize);
if (!*segbuf) {
- err(0, "mmap_segment: malloc failed");
+ warnx("mmap_segment: malloc failed");
return(0);
}
/* read the segment data into the buffer */
if (lseek (fid, seg_byte, SEEK_SET) != seg_byte) {
- err (0, "mmap_segment: bad lseek");
+ warn("mmap_segment: bad lseek");
free(*segbuf);
return (-1);
}
if (read (fid, *segbuf, ssize) != ssize) {
- err (0, "mmap_segment: bad read");
+ warn("mmap_segment: bad read");
free(*segbuf);
return (-1);
}
@@ -614,9 +616,9 @@ bi_compare(a, b)
ba = a;
bb = b;
- if (diff = (int)(ba->bi_inode - bb->bi_inode))
+ if ((diff = (int)(ba->bi_inode - bb->bi_inode)))
return (diff);
- if (diff = (int)(ba->bi_lbn - bb->bi_lbn)) {
+ if ((diff = (int)(ba->bi_lbn - bb->bi_lbn))) {
if (ba->bi_lbn == LFS_UNUSED_LBN)
return(-1);
else if (bb->bi_lbn == LFS_UNUSED_LBN)
@@ -628,7 +630,7 @@ bi_compare(a, b)
else
return (diff);
}
- if (diff = (int)(ba->bi_segcreate - bb->bi_segcreate))
+ if ((diff = (int)(ba->bi_segcreate - bb->bi_segcreate)))
return (diff);
diff = (int)(ba->bi_daddr - bb->bi_daddr);
return (diff);
diff --git a/libexec/lfs_cleanerd/misc.c b/libexec/lfs_cleanerd/misc.c
index ad6e11a..e0b7071 100644
--- a/libexec/lfs_cleanerd/misc.c
+++ b/libexec/lfs_cleanerd/misc.c
@@ -32,49 +32,20 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
+#include <err.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-
-extern char *special;
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const int fatal, const char *fmt, ...)
-#else
-err(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "%s: ", special);
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- if (errno)
- (void)fprintf(stderr, " %s", strerror(errno));
- (void)fprintf(stderr, "\n");
- if (fatal)
- exit(1);
-}
+#include <unistd.h>
void
get(fd, off, p, len)
@@ -86,9 +57,9 @@ get(fd, off, p, len)
int rbytes;
if (lseek(fd, off, SEEK_SET) < 0)
- err(1, "%s: %s", special, strerror(errno));
+ err(1, NULL);
if ((rbytes = read(fd, p, len)) < 0)
- err(1, "%s: %s", special, strerror(errno));
+ err(1, NULL);
if (rbytes != len)
- err(1, "%s: short read (%d, not %d)", special, rbytes, len);
+ errx(1, "short read (%d, not %d)", rbytes, len);
}
diff --git a/libexec/lfs_cleanerd/print.c b/libexec/lfs_cleanerd/print.c
index 8468f12..0c0de62 100644
--- a/libexec/lfs_cleanerd/print.c
+++ b/libexec/lfs_cleanerd/print.c
@@ -29,12 +29,14 @@
* 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.
- *
- * $Id$
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/4/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/param.h>
@@ -45,10 +47,12 @@ static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/4/93";
#include <ufs/ufs/dinode.h>
#include <ufs/lfs/lfs.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include "clean.h"
+u_long cksum __P((void *, size_t));
+
/*
* Print out a summary block; return number of blocks in segment; 0
* for empty segment or corrupt segment.
OpenPOWER on IntegriCloud