Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Switch to accessor functions for elements of the LFS on-disk
details: https://anonhg.NetBSD.org/src/rev/1ab93cf9d5b1
branches: trunk
changeset: 809619:1ab93cf9d5b1
user: dholland <dholland%NetBSD.org@localhost>
date: Fri Jul 24 06:56:41 2015 +0000
description:
Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)
It also gets rid of cpp abuse in the form of fake structure member
macros.
Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)
XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
diffstat:
libexec/lfs_cleanerd/cleaner.h | 43 +++++-
libexec/lfs_cleanerd/coalesce.c | 12 +-
libexec/lfs_cleanerd/lfs_cleanerd.c | 86 +++++-----
sbin/dump_lfs/lfs_inode.c | 48 ++--
sbin/fsck_lfs/dir.c | 24 +-
sbin/fsck_lfs/inode.c | 30 +-
sbin/fsck_lfs/lfs.c | 95 +++++-----
sbin/fsck_lfs/main.c | 8 +-
sbin/fsck_lfs/pass0.c | 12 +-
sbin/fsck_lfs/pass1.c | 14 +-
sbin/fsck_lfs/pass4.c | 4 +-
sbin/fsck_lfs/pass5.c | 31 +-
sbin/fsck_lfs/pass6.c | 74 ++++----
sbin/fsck_lfs/segwrite.c | 114 ++++++------
sbin/fsck_lfs/segwrite.h | 6 +-
sbin/fsck_lfs/setup.c | 81 ++++----
sbin/fsck_lfs/utilities.c | 6 +-
sbin/newfs_lfs/make_lfs.c | 149 +++++++++--------
sbin/resize_lfs/resize_lfs.c | 4 +-
sbin/scan_ffs/scan_ffs.c | 23 +-
sys/lib/libsa/lfsv1.c | 6 +-
sys/lib/libsa/lfsv2.c | 6 +-
sys/lib/libsa/ufs.c | 46 +----
sys/ufs/lfs/lfs.h | 300 +++++++++++++++++++++++------------
sys/ufs/lfs/lfs_alloc.c | 42 ++--
sys/ufs/lfs/lfs_balloc.c | 34 ++--
sys/ufs/lfs/lfs_bio.c | 32 ++-
sys/ufs/lfs/lfs_inode.c | 64 +++---
sys/ufs/lfs/lfs_pages.c | 14 +-
sys/ufs/lfs/lfs_rfw.c | 45 ++--
sys/ufs/lfs/lfs_segment.c | 183 +++++++++++----------
sys/ufs/lfs/lfs_subr.c | 16 +-
sys/ufs/lfs/lfs_syscalls.c | 42 ++--
sys/ufs/lfs/lfs_vfsops.c | 113 ++++++------
sys/ufs/lfs/lfs_vnops.c | 12 +-
sys/ufs/lfs/ulfs_inode.h | 6 +-
sys/ufs/lfs/ulfs_quota2.c | 6 +-
sys/ufs/lfs/ulfs_readwrite.c | 15 +-
usr.sbin/dumplfs/dumplfs.c | 202 ++++++++++++------------
39 files changed, 1090 insertions(+), 958 deletions(-)
diffs (truncated from 5464 to 300 lines):
diff -r 6a035e9a5698 -r 1ab93cf9d5b1 libexec/lfs_cleanerd/cleaner.h
--- a/libexec/lfs_cleanerd/cleaner.h Fri Jul 24 06:53:24 2015 +0000
+++ b/libexec/lfs_cleanerd/cleaner.h Fri Jul 24 06:56:41 2015 +0000
@@ -16,7 +16,7 @@
* The cleaner's view of the superblock data structure.
*/
struct clfs {
- struct dlfs lfs_dlfs; /* Leverage LFS lfs_* defines here */
+ struct dlfs lfs_dlfs;
/* Ifile */
int clfs_ifilefd; /* Ifile file descriptor */
@@ -37,6 +37,47 @@
int clfs_onhold; /* If cleaning this fs is on hold */
};
+/* ugh... */
+#define CLFS_DEF_SB_ACCESSOR(type, field) \
+ static __unused inline type \
+ clfs_sb_get##field(struct clfs *fs) \
+ { \
+ return fs->lfs_dlfs.dlfs_##field; \
+ } \
+ static __unused inline void \
+ clfs_sb_set##field(struct clfs *fs, type val) \
+ { \
+ fs->lfs_dlfs.dlfs_##field = val; \
+ } \
+ static __unused inline void \
+ clfs_sb_add##field(struct clfs *fs, type val) \
+ { \
+ fs->lfs_dlfs.dlfs_##field += val; \
+ }
+
+/* more ugh... */
+CLFS_DEF_SB_ACCESSOR(u_int32_t, ssize);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, bsize);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, fsize);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, frag);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, ifile);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, ifpb);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, sepb);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, nseg);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, cleansz);
+CLFS_DEF_SB_ACCESSOR(u_int32_t, segtabsz);
+
+/* still more ugh... */
+#define lfs_sb_getssize(fs) clfs_sb_getssize(fs)
+#define lfs_sb_getbsize(fs) clfs_sb_getbsize(fs)
+#define lfs_sb_getfsize(fs) clfs_sb_getfsize(fs)
+#define lfs_sb_getfrag(fs) clfs_sb_getfrag(fs)
+#define lfs_sb_getifpb(fs) clfs_sb_getifpb(fs)
+#define lfs_sb_getsepb(fs) clfs_sb_getsepb(fs)
+#define lfs_sb_getnseg(fs) clfs_sb_getnseg(fs)
+#define lfs_sb_getcleansz(fs) clfs_sb_getcleansz(fs)
+#define lfs_sb_getsegtabsz(fs) clfs_sb_getsegtabsz(fs)
+
/*
* Fraction of the could-be-clean segments required to be clean.
*/
diff -r 6a035e9a5698 -r 1ab93cf9d5b1 libexec/lfs_cleanerd/coalesce.c
--- a/libexec/lfs_cleanerd/coalesce.c Fri Jul 24 06:53:24 2015 +0000
+++ b/libexec/lfs_cleanerd/coalesce.c Fri Jul 24 06:56:41 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: coalesce.c,v 1.24 2015/03/29 19:35:58 chopps Exp $ */
+/* $NetBSD: coalesce.c,v 1.25 2015/07/24 06:56:41 dholland Exp $ */
/*-
* Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
@@ -215,10 +215,10 @@
#endif
noff = toff = 0;
for (i = 1; i < nb; i++) {
- if (bip[i].bi_daddr != bip[i - 1].bi_daddr + fs->lfs_frag)
+ if (bip[i].bi_daddr != bip[i - 1].bi_daddr + clfs_sb_getfrag(fs))
++noff;
toff += abs(bip[i].bi_daddr - bip[i - 1].bi_daddr
- - fs->lfs_frag) >> fs->lfs_fbshift;
+ - clfs_sb_getfrag(fs)) >> fs->lfs_fbshift;
}
/*
@@ -297,7 +297,7 @@
bps = lfs_segtod(fs, 1);
for (tbip = bip; tbip < bip + nb; tbip += bps) {
do {
- bread(fs->lfs_ivnode, 0, fs->lfs_bsize, 0, &bp);
+ bread(fs->lfs_ivnode, 0, clfs_sb_getbsize(fs), 0, &bp);
cip = *(CLEANERINFO *)bp->b_data;
brelse(bp, B_INVAL);
@@ -339,8 +339,8 @@
memset(totals, 0, sizeof(totals));
fstat(fs->clfs_ifilefd, &st);
- maxino = fs->lfs_ifpb * (st.st_size >> fs->lfs_bshift) -
- fs->lfs_segtabsz - fs->lfs_cleansz;
+ maxino = lfs_sb_getifpb(fs) * (st.st_size >> fs->lfs_bshift) -
+ lfs_sb_getsegtabsz(fs) - lfs_sb_getcleansz(fs);
for (i = 0; i < maxino; i++) {
r = clean_inode(fs, i);
diff -r 6a035e9a5698 -r 1ab93cf9d5b1 libexec/lfs_cleanerd/lfs_cleanerd.c
--- a/libexec/lfs_cleanerd/lfs_cleanerd.c Fri Jul 24 06:53:24 2015 +0000
+++ b/libexec/lfs_cleanerd/lfs_cleanerd.c Fri Jul 24 06:56:41 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_cleanerd.c,v 1.38 2015/03/29 19:35:58 chopps Exp $ */
+/* $NetBSD: lfs_cleanerd.c,v 1.39 2015/07/24 06:56:41 dholland Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -264,8 +264,8 @@
strncpy((char *)fs->lfs_fsmnt, fsname, MNAMELEN);
/* Set up vnodes for Ifile and raw device */
- fs->lfs_ivnode = fd_vget(fs->clfs_ifilefd, fs->lfs_bsize, 0, 0);
- fs->clfs_devvp = fd_vget(fs->clfs_devfd, fs->lfs_fsize, fs->lfs_ssize,
+ fs->lfs_ivnode = fd_vget(fs->clfs_ifilefd, clfs_sb_getbsize(fs), 0, 0);
+ fs->clfs_devvp = fd_vget(fs->clfs_devfd, clfs_sb_getfsize(fs), clfs_sb_getssize(fs),
atatime);
/* Allocate and clear segtab */
@@ -312,9 +312,9 @@
/* If Ifile is larger than buffer cache, rehash */
fstat(fs->clfs_ifilefd, &st);
- if (st.st_size / fs->lfs_bsize > hashmax) {
+ if (st.st_size / clfs_sb_getbsize(fs) > hashmax) {
ohashmax = hashmax;
- bufrehash(st.st_size / fs->lfs_bsize);
+ bufrehash(st.st_size / clfs_sb_getbsize(fs));
dlog("%s: resized buffer hash from %d to %d",
fs->lfs_fsmnt, ohashmax, hashmax);
}
@@ -330,12 +330,13 @@
{
int error;
- error = bread(fs->lfs_ivnode, ino / fs->lfs_ifpb + fs->lfs_cleansz +
- fs->lfs_segtabsz, fs->lfs_bsize, 0, bpp);
+ error = bread(fs->lfs_ivnode,
+ ino / lfs_sb_getifpb(fs) + lfs_sb_getcleansz(fs) +
+ lfs_sb_getsegtabsz(fs), clfs_sb_getbsize(fs), 0, bpp);
if (error)
syslog(LOG_ERR, "%s: ientry failed for ino %d",
fs->lfs_fsmnt, (int)ino);
- *ifpp = (IFILE *)(*bpp)->b_data + ino % fs->lfs_ifpb;
+ *ifpp = (IFILE *)(*bpp)->b_data + ino % lfs_sb_getifpb(fs);
return;
}
@@ -513,7 +514,7 @@
syslog(LOG_WARNING, "fixing short FINFO at %x (seg %d)",
odaddr, lfs_dtosn(fs, odaddr));
- bread(fs->clfs_devvp, odaddr, fs->lfs_fsize,
+ bread(fs->clfs_devvp, odaddr, clfs_sb_getfsize(fs),
0, &nbp);
nssp = (SEGSUM *)nbp->b_data;
--nssp->ss_nfinfo;
@@ -542,7 +543,7 @@
/* Read all the blocks from the data summary */
for (i = 0; i < fip->fi_nblocks; i++) {
size = (i == fip->fi_nblocks - 1) ?
- fip->fi_lastlength : fs->lfs_bsize;
+ fip->fi_lastlength : clfs_sb_getbsize(fs);
cp = fd_ptrget(fs->clfs_devvp, daddr);
ck = lfs_cksum_part(cp, sizeof(u_int32_t), ck);
daddr += lfs_btofsb(fs, size);
@@ -568,7 +569,7 @@
bip[*bic + i].bi_segcreate = ssp->ss_create;
bip[*bic + i].bi_version = fip->fi_version;
bip[*bic + i].bi_size = (i == fip->fi_nblocks - 1) ?
- fip->fi_lastlength : fs->lfs_bsize;
+ fip->fi_lastlength : clfs_sb_getbsize(fs);
cp = fd_ptrget(fs->clfs_devvp, daddr);
ck = lfs_cksum_part(cp, sizeof(u_int32_t), ck);
bip[*bic + i].bi_bp = cp;
@@ -617,7 +618,7 @@
fp = fopen(copylog_filename, "ab");
if (fp != NULL) {
- if (fwrite(cp, (size_t)fs->lfs_ssize, 1, fp) != 1) {
+ if (fwrite(cp, (size_t)clfs_sb_getssize(fs), 1, fp) != 1) {
perror("writing segment to copy log");
}
}
@@ -653,12 +654,12 @@
/* Note bytes read for stats */
cleaner_stats.segs_cleaned++;
- cleaner_stats.bytes_read += fs->lfs_ssize;
+ cleaner_stats.bytes_read += clfs_sb_getssize(fs);
++fs->clfs_nactive;
npseg = 0;
while(lfs_dtosn(fs, daddr) == sn &&
- lfs_dtosn(fs, daddr + lfs_btofsb(fs, fs->lfs_bsize)) == sn) {
+ lfs_dtosn(fs, daddr + lfs_btofsb(fs, clfs_sb_getbsize(fs))) == sn) {
daddr = parse_pseg(fs, daddr, bipp, bic);
if (daddr == 0x0) {
++cleaner_stats.segs_error;
@@ -702,7 +703,7 @@
return;
}
- if (t->nbytes > fs->lfs_ssize) {
+ if (t->nbytes > clfs_sb_getssize(fs)) {
/* Another type of error */
syslog(LOG_WARNING, "segment %d: bad seguse count %d",
sn, t->nbytes);
@@ -719,16 +720,16 @@
* We count the summary headers as "dirty" to avoid cleaning very
* old and very full segments.
*/
- benefit = (int64_t)fs->lfs_ssize - t->nbytes -
- (t->nsums + 1) * fs->lfs_fsize;
- if (fs->lfs_bsize > fs->lfs_fsize) /* fragmentation */
- benefit -= (fs->lfs_bsize / 2);
+ benefit = (int64_t)clfs_sb_getssize(fs) - t->nbytes -
+ (t->nsums + 1) * clfs_sb_getfsize(fs);
+ if (clfs_sb_getbsize(fs) > clfs_sb_getfsize(fs)) /* fragmentation */
+ benefit -= (clfs_sb_getbsize(fs) / 2);
if (benefit <= 0) {
t->priority = 0;
return;
}
- cost = fs->lfs_ssize + t->nbytes;
+ cost = clfs_sb_getssize(fs) + t->nbytes;
t->priority = (256 * benefit * age) / cost;
return;
@@ -867,7 +868,7 @@
/* Record statistics */
for (i = nb = 0; i < bic; i++)
nb += bip[i].bi_size;
- util = ((double)nb) / (fs->clfs_nactive * fs->lfs_ssize);
+ util = ((double)nb) / (fs->clfs_nactive * clfs_sb_getssize(fs));
cleaner_stats.util_tot += util;
cleaner_stats.util_sos += util * util;
cleaner_stats.bytes_written += nb;
@@ -964,10 +965,10 @@
/*
* Look for IFILE blocks, unless this is the Ifile.
*/
- if (bip[i].bi_inode != fs->lfs_ifile) {
- lbn = fs->lfs_cleansz + bip[i].bi_inode /
- fs->lfs_ifpb;
- *ifc += check_or_add(fs->lfs_ifile, lbn,
+ if (bip[i].bi_inode != clfs_sb_getifile(fs)) {
+ lbn = lfs_sb_getcleansz(fs) + bip[i].bi_inode /
+ lfs_sb_getifpb(fs);
+ *ifc += check_or_add(clfs_sb_getifile(fs), lbn,
bip, bic, &ebip, &ebic);
}
}
@@ -1012,10 +1013,11 @@
/* Read the segment table into our private structure */
npos = 0;
- for (i = 0; i < fs->lfs_nseg; i+= fs->lfs_sepb) {
- bread(fs->lfs_ivnode, fs->lfs_cleansz + i / fs->lfs_sepb,
- fs->lfs_bsize, 0, &bp);
- for (j = 0; j < fs->lfs_sepb && i + j < fs->lfs_nseg; j++) {
+ for (i = 0; i < lfs_sb_getnseg(fs); i+= lfs_sb_getsepb(fs)) {
+ bread(fs->lfs_ivnode,
+ lfs_sb_getcleansz(fs) + i / lfs_sb_getsepb(fs),
+ clfs_sb_getbsize(fs), 0, &bp);
+ for (j = 0; j < lfs_sb_getsepb(fs) && i + j < lfs_sb_getnseg(fs); j++) {
sup = ((SEGUSE *)bp->b_data) + j;
fs->clfs_segtab[i + j].nbytes = sup->su_nbytes;
fs->clfs_segtab[i + j].nsums = sup->su_nsums;
@@ -1048,10 +1050,10 @@
ngood = 0;
if (use_bytes) {
/* Set attainable goal */
- goal = fs->lfs_ssize * atatime;
- if (goal > (cip->clean - 1) * fs->lfs_ssize / 2)
- goal = MAX((cip->clean - 1) * fs->lfs_ssize,
- fs->lfs_ssize) / 2;
+ goal = clfs_sb_getssize(fs) * atatime;
+ if (goal > (cip->clean - 1) * clfs_sb_getssize(fs) / 2)
+ goal = MAX((cip->clean - 1) * clfs_sb_getssize(fs),
+ clfs_sb_getssize(fs)) / 2;
dlog("%s: cleaning with goal %" PRId64
" bytes (%d segs clean, %d cleanable)",
@@ -1064,7 +1066,7 @@
if (fs->clfs_segtabp[i]->priority == 0)
break;
/* Upper bound on number of segments at once */
- if (ngood * fs->lfs_ssize > 4 * goal)
+ if (ngood * clfs_sb_getssize(fs) > 4 * goal)
break;
sn = (fs->clfs_segtabp[i] - fs->clfs_segtab);
dlog("%s: add seg %d prio %" PRIu64
@@ -1115,7 +1117,7 @@
/* Record statistics */
for (i = nb = 0; i < bic; i++)
Home |
Main Index |
Thread Index |
Old Index