svn commit: r248628 - stable/9/sbin/fsck_ffs
Kirk McKusick
mckusick at FreeBSD.org
Fri Mar 22 22:50:49 UTC 2013
Author: mckusick
Date: Fri Mar 22 22:50:48 2013
New Revision: 248628
URL: http://svnweb.freebsd.org/changeset/base/248628
Log:
MFS of 246812:
Update fsck_ffs buffer cache manager to use TAILQ macros.
No functional changes.
Modified:
stable/9/sbin/fsck_ffs/fsck.h
stable/9/sbin/fsck_ffs/fsutil.c
Directory Properties:
stable/9/sbin/fsck_ffs/ (props changed)
Modified: stable/9/sbin/fsck_ffs/fsck.h
==============================================================================
--- stable/9/sbin/fsck_ffs/fsck.h Fri Mar 22 22:46:19 2013 (r248627)
+++ stable/9/sbin/fsck_ffs/fsck.h Fri Mar 22 22:50:48 2013 (r248628)
@@ -67,10 +67,13 @@
#include <stdlib.h>
#include <stdio.h>
+#include <sys/queue.h>
+
#define MAXDUP 10 /* limit on dup blks (per inode) */
#define MAXBAD 10 /* limit on bad blks (per inode) */
-#define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */
-#define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */
+#define MINBUFS 10 /* minimum number of buffers required */
+#define MAXBUFS 40 /* maximum space to allocate to buffers */
+#define INOBUFSIZE 64*1024 /* size of buffer to read inodes in pass1 */
union dinode {
struct ufs1_dinode dp1;
@@ -130,8 +133,7 @@ struct inostatlist {
* buffer cache structure.
*/
struct bufarea {
- struct bufarea *b_next; /* free list queue */
- struct bufarea *b_prev; /* free list queue */
+ TAILQ_ENTRY(bufarea) b_list; /* buffer list */
ufs2_daddr_t b_bno;
int b_size;
int b_errs;
@@ -159,10 +161,11 @@ struct bufarea {
(bp)->b_un.b_indir2[i] = (val); \
} while (0)
-#define B_INUSE 1
+/*
+ * Buffer flags
+ */
+#define B_INUSE 0x00000001 /* Buffer is in use */
-#define MINBUFS 5 /* minimum number of buffers required */
-struct bufarea bufhead; /* head of list of other blks in filesys */
struct bufarea sblk; /* file system superblock */
struct bufarea cgblk; /* cylinder group blocks */
struct bufarea *pdirbp; /* current directory contents */
Modified: stable/9/sbin/fsck_ffs/fsutil.c
==============================================================================
--- stable/9/sbin/fsck_ffs/fsutil.c Fri Mar 22 22:46:19 2013 (r248627)
+++ stable/9/sbin/fsck_ffs/fsutil.c Fri Mar 22 22:50:48 2013 (r248628)
@@ -67,6 +67,8 @@ long diskreads, totalreads; /* Disk cach
struct timeval slowio_starttime;
int slowio_delay_usec = 10000; /* Initial IO delay for background fsck */
int slowio_pollcnt;
+static TAILQ_HEAD(buflist, bufarea) bufhead; /* head of buffer cache list */
+static int numbufs; /* size of buffer cache */
int
ftypeok(union dinode *dp)
@@ -161,8 +163,8 @@ bufinit(void)
errx(EEXIT, "cannot allocate buffer pool");
cgblk.b_un.b_buf = bufp;
initbarea(&cgblk);
- bufhead.b_next = bufhead.b_prev = &bufhead;
- bufcnt = MAXBUFSPACE / sblock.fs_bsize;
+ TAILQ_INIT(&bufhead);
+ bufcnt = MAXBUFS;
if (bufcnt < MINBUFS)
bufcnt = MINBUFS;
for (i = 0; i < bufcnt; i++) {
@@ -174,13 +176,10 @@ bufinit(void)
errx(EEXIT, "cannot allocate buffer pool");
}
bp->b_un.b_buf = bufp;
- bp->b_prev = &bufhead;
- bp->b_next = bufhead.b_next;
- bufhead.b_next->b_prev = bp;
- bufhead.b_next = bp;
+ TAILQ_INSERT_HEAD(&bufhead, bp, b_list);
initbarea(bp);
}
- bufhead.b_size = i; /* save number of buffers */
+ numbufs = i; /* save number of buffers */
}
/*
@@ -191,23 +190,19 @@ getdatablk(ufs2_daddr_t blkno, long size
{
struct bufarea *bp;
- for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next)
+ TAILQ_FOREACH(bp, &bufhead, b_list)
if (bp->b_bno == fsbtodb(&sblock, blkno))
goto foundit;
- for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev)
+ TAILQ_FOREACH_REVERSE(bp, &bufhead, buflist, b_list)
if ((bp->b_flags & B_INUSE) == 0)
break;
- if (bp == &bufhead)
+ if (bp == NULL)
errx(EEXIT, "deadlocked buffer pool");
getblk(bp, blkno, size);
/* fall through */
foundit:
- bp->b_prev->b_next = bp->b_next;
- bp->b_next->b_prev = bp->b_prev;
- bp->b_prev = &bufhead;
- bp->b_next = bufhead.b_next;
- bufhead.b_next->b_prev = bp;
- bufhead.b_next = bp;
+ TAILQ_REMOVE(&bufhead, bp, b_list);
+ TAILQ_INSERT_HEAD(&bufhead, bp, b_list);
bp->b_flags |= B_INUSE;
return (bp);
}
@@ -273,7 +268,7 @@ void
ckfini(int markclean)
{
struct bufarea *bp, *nbp;
- int ofsmodified, cnt = 0;
+ int ofsmodified, cnt;
if (bkgrdflag) {
unlink(snapname);
@@ -294,6 +289,10 @@ ckfini(int markclean)
rerun = 1;
}
}
+ if (debug && totalreads > 0)
+ printf("cache with %d buffers missed %ld of %ld (%d%%)\n",
+ numbufs, diskreads, totalreads,
+ (int)(diskreads * 100 / totalreads));
if (fswritefd < 0) {
(void)close(fsreadfd);
return;
@@ -308,15 +307,16 @@ ckfini(int markclean)
}
flush(fswritefd, &cgblk);
free(cgblk.b_un.b_buf);
- for (bp = bufhead.b_prev; bp && bp != &bufhead; bp = nbp) {
+ cnt = 0;
+ TAILQ_FOREACH_REVERSE_SAFE(bp, &bufhead, buflist, b_list, nbp) {
+ TAILQ_REMOVE(&bufhead, bp, b_list);
cnt++;
flush(fswritefd, bp);
- nbp = bp->b_prev;
free(bp->b_un.b_buf);
free((char *)bp);
}
- if (bufhead.b_size != cnt)
- errx(EEXIT, "panic: lost %d buffers", bufhead.b_size - cnt);
+ if (numbufs != cnt)
+ errx(EEXIT, "panic: lost %d buffers", numbufs - cnt);
pbp = pdirbp = (struct bufarea *)0;
if (cursnapshot == 0 && sblock.fs_clean != markclean) {
if ((sblock.fs_clean = markclean) != 0) {
@@ -342,9 +342,6 @@ ckfini(int markclean)
rerun = 1;
}
}
- if (debug && totalreads > 0)
- printf("cache missed %ld of %ld (%d%%)\n", diskreads,
- totalreads, (int)(diskreads * 100 / totalreads));
(void)close(fsreadfd);
(void)close(fswritefd);
}
More information about the svn-src-stable-9
mailing list