Module Name:    src
Committed By:   dholland
Date:           Sun Jul 31 18:27:27 UTC 2016

Modified Files:
        src/sbin/fsck_lfs: bufcache.c

Log Message:
PR 51264 Jose Luis Rodriguez Garcia: lfs userland bufcache rehash is broken


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sbin/fsck_lfs/bufcache.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/fsck_lfs/bufcache.c
diff -u src/sbin/fsck_lfs/bufcache.c:1.15 src/sbin/fsck_lfs/bufcache.c:1.16
--- src/sbin/fsck_lfs/bufcache.c:1.15	Sun Mar 29 19:35:58 2015
+++ src/sbin/fsck_lfs/bufcache.c	Sun Jul 31 18:27:26 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: bufcache.c,v 1.15 2015/03/29 19:35:58 chopps Exp $ */
+/* $NetBSD: bufcache.c,v 1.16 2016/07/31 18:27:26 dholland Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -101,17 +101,19 @@ bufinit(int max)
 /* Widen the hash table. */
 void bufrehash(int max)
 {
-	int i, newhashmax, newhashmask;
+	int i, newhashmax;
 	struct ubuf *bp, *nbp;
 	struct bufhash_struct *np;
 
-	if (max < 0 || max < hashmax)
+	if (max < 0 || max <= hashmax)
 		return;
 
 	/* Round up to a power of two */
 	for (newhashmax = 1; newhashmax < max; newhashmax <<= 1)
 		;
-	newhashmask = newhashmax - 1;
+
+	/* update the mask right away so vl_hash() uses it */
+	hashmask = newhashmax - 1;
 
 	/* Allocate new empty hash table, if we can */
 	np = emalloc(newhashmax * sizeof(*bufhash));
@@ -134,7 +136,6 @@ void bufrehash(int max)
 	free(bufhash);
 	bufhash = np;
 	hashmax = newhashmax;
-	hashmask = newhashmask;
 }
 
 /* Print statistics of buffer cache usage */

Reply via email to