shithub: gefs

Download patch

ref: e65b37e27a53bbfd2c6c65fae56a7c5c035a5a47
parent: e890dc8b4dc048c1c463de08e685c9854a18c8ca
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Oct 29 00:28:52 EDT 2022

cache: clear block address on uncache

if we leave the block address in the LRU, we may
end up uncaching an unrelated block when we pluck
the block off the lru:

	uncache(A[addr=x])
	freeblk(A[addr=x])
	cache(newblk()) => B(addr=x)
	pluck() // unache(A[addr=x]); clobbers B

this is bad, so lets not do it.

--- a/cache.c
+++ b/cache.c
@@ -67,6 +67,8 @@
 		fs->ctail->cnext = b;
 	if(fs->chead == nil)
 		fs->chead = b;
+	b->bp.addr = -1;
+	b->bp.hash = -1;
 	b->cprev = fs->ctail;
 	fs->ctail = b;
 	rwakeup(&fs->lrurz);
@@ -110,6 +112,8 @@
 	for(b = bkt->b; b != nil; b = b->hnext){
 		if(b->bp.addr == addr){
 			*p = b->hnext;
+			b->bp.addr = -1;
+			b->bp.hash = -1;
 			clrflag(b, Bcached);
 			b->hnext = nil;
 			break;