shithub: gefs

Download patch

ref: a82f38d12ba6ead66c7bad1f842ba8ac65084fbe
parent: e330f1506aaea5dd5b478b7f1466712cb46b2af0
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Nov 12 16:45:36 EST 2022

check: rename badblk to badtree

--- a/blk.c
+++ b/blk.c
@@ -709,7 +709,7 @@
 		return nil;
 
 	setflag(r, Bdirty);
-	r->bp.hash = b->bp.hash;
+	r->bp.hash = -1;
 	r->nval = b->nval;
 	r->valsz = b->valsz;
 	r->nbuf = b->nbuf;
--- a/cache.c
+++ b/cache.c
@@ -81,6 +81,7 @@
 	Bucket *bkt;
 	u32int h;
 
+	qlock(&fs->lrulk);
 	assert(b->magic == Magic);
 	h = ihash(b->bp.addr);
 	bkt = &fs->cache[h % fs->cmax];
@@ -87,13 +88,18 @@
 	lock(bkt);
 	if(checkflag(b, Bcached)){
 		unlock(bkt);
+		qunlock(&fs->lrulk);
 		return;
 	}
+	assert(b->hnext == nil);
+	for(Blk *bb = bkt->b; bb != nil; bb = bb->hnext)
+		assert(b != bb);
 	setflag(b, Bcached);
 	b->cached = getcallerpc(&b);
 	b->hnext = bkt->b;
 	bkt->b = b;
 	unlock(bkt);
+	qunlock(&fs->lrulk);
 }
 
 void
@@ -168,8 +174,8 @@
 	assert(b->magic == Magic);
 	assert(b->ref == 0);
 	cachedel(b->bp.addr);
-	assert(!checkflag(b, Bcached));
 	lrudel(b);
+	assert(!checkflag(b, Bcached));
 	b->flag = 0;
 	b->lasthold = 0;
 	b->lastdrop = 0;
--- a/check.c
+++ b/check.c
@@ -23,7 +23,7 @@
 }
 
 static int
-badblk(int fd, Blk *b, int h, Kvp *lo, Kvp *hi)
+badtree(int fd, Blk *b, int h, Kvp *lo, Kvp *hi)
 {
 	Kvp x, y;
 	Msg mx, my;
@@ -79,7 +79,7 @@
 				fprint(fd, "mismatched block fill\n");
 				fail++;
 			}
-			if(badblk(fd, c, h - 1, &x, &y))
+			if(badtree(fd, c, h - 1, &x, &y))
 				fail++;
 			dropblk(c);
 		}
@@ -105,7 +105,7 @@
 			fprint(fd, "corrupt block: %r\n");
 			fail++;
 		}
-		if(c != nil && badblk(fd, c, h - 1, &y, nil))
+		if(c != nil && badtree(fd, c, h - 1, &y, nil))
 			fail++;
 	}
 	if(b->type == Tpivot){
@@ -188,7 +188,7 @@
 	if(badfree())
 		ok = 0;
 	if((b = getroot(&fs->snap, &height)) != nil){
-		if(badblk(fd, b, height-1, nil, 0))
+		if(badtree(fd, b, height-1, nil, 0))
 			ok = 0;
 		dropblk(b);
 	}
@@ -214,12 +214,12 @@
 			break;
 		}
 		if((b = getroot(t, &height)) != nil){
-			if(badblk(fd, b, height-1, nil, 0))
+			if(badtree(fd, b, height-1, nil, 0))
 				ok = 0;
 			dropblk(b);
 			continue;
 		}
-		if(badblk(fd, b, height-1, nil, 0))
+		if(badtree(fd, b, height-1, nil, 0))
 			ok = 0;
 		dropblk(b);
 	}