Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/fsck_lfs Fail gracefully if we are asked to expand the ...



details:   https://anonhg.NetBSD.org/src/rev/6679e32b8a5c
branches:  trunk
changeset: 581026:6679e32b8a5c
user:      perseant <perseant%NetBSD.org@localhost>
date:      Fri May 20 18:59:36 2005 +0000

description:
Fail gracefully if we are asked to expand the buffer cache hash table size
when there is no memory available to do so.  Use the uvnode's strategy
routine to retrieve data from the device, rather than always using pread().
Add a buffer header flag that specifies external management of the buffer's
data area.

All of this in support of a new cleaner, which is not included in this commit.

diffstat:

 sbin/fsck_lfs/bufcache.c |  31 +++++++++++++------------------
 sbin/fsck_lfs/bufcache.h |   3 ++-
 2 files changed, 15 insertions(+), 19 deletions(-)

diffs (93 lines):

diff -r a3c8ccf68f52 -r 6679e32b8a5c sbin/fsck_lfs/bufcache.c
--- a/sbin/fsck_lfs/bufcache.c  Fri May 20 18:01:46 2005 +0000
+++ b/sbin/fsck_lfs/bufcache.c  Fri May 20 18:59:36 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bufcache.c,v 1.6 2005/04/11 23:19:24 perseant Exp $ */
+/* $NetBSD: bufcache.c,v 1.7 2005/05/20 18:59:36 perseant Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -119,8 +119,10 @@
                ;
        newhashmask = newhashmax - 1;
 
-       /* Allocate new empty hash table */
+       /* Allocate new empty hash table, if we can */
        np = (struct bufhash_struct *)malloc(newhashmax * sizeof(*bufhash));
+               if (np == NULL)
+                       return;
        for (i = 0; i < newhashmax; i++)
                LIST_INIT(&np[i]);
 
@@ -163,7 +165,8 @@
        bp->b_flags |= B_NEEDCOMMIT;
        LIST_REMOVE(bp, b_vnbufs);
        LIST_REMOVE(bp, b_hash);
-       free(bp->b_data);
+       if (!(bp->b_flags & B_DONTFREE))
+               free(bp->b_data);
        free(bp);
        --nbufs;
 }
@@ -275,15 +278,12 @@
                        break;
                }
 #ifdef DEBUG
-               else {
-                       if (!warned) {
-                               warnx("allocating more than %d buffers",
-                                       maxbufs);
-                               ++warned;
-                       }
-                       break;
+               else if (!warned) {
+                       warnx("allocating more than %d buffers", maxbufs);
+                       ++warned;
                }
 #endif
+               break;
        }
        ++nbufs;
        bp = (struct ubuf *) malloc(sizeof(*bp));
@@ -353,7 +353,7 @@
 {
        struct ubuf *bp;
        daddr_t daddr;
-       int error, count;
+       int error;
 
        bp = getblk(vp, lbn, size);
        *bpp = bp;
@@ -371,13 +371,8 @@
        error = VOP_BMAP(vp, lbn, &daddr);
        bp->b_blkno = daddr;
        if (daddr >= 0) {
-               count = pread(vp->v_fd, bp->b_data, bp->b_bcount,
-                               dbtob((off_t) daddr));
-               if (count == bp->b_bcount) {
-                       bp->b_flags |= B_DONE;
-                       return 0;
-               }
-               return -1;
+               bp->b_flags |= B_READ;
+               return VOP_STRATEGY(bp);
        }
        memset(bp->b_data, 0, bp->b_bcount);
        return 0;
diff -r a3c8ccf68f52 -r 6679e32b8a5c sbin/fsck_lfs/bufcache.h
--- a/sbin/fsck_lfs/bufcache.h  Fri May 20 18:01:46 2005 +0000
+++ b/sbin/fsck_lfs/bufcache.h  Fri May 20 18:59:36 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bufcache.h,v 1.4 2005/04/11 23:19:24 perseant Exp $    */
+/*     $NetBSD: bufcache.h,v 1.5 2005/05/20 18:59:36 perseant Exp $    */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -107,6 +107,7 @@
 #define        B_INVAL         0x00002000      /* Does not contain valid info. */
 #define        B_LOCKED        0x00004000      /* Locked in core (not reusable). */
 #define        B_READ          0x00100000      /* Read buffer. */
+#define        B_DONTFREE      0x00010000      /* b_data not managed by bufcache */
 
 LIST_HEAD(bufhash_struct, ubuf);
 



Home | Main Index | Thread Index | Old Index