shithub: gefs

Download patch

ref: 452c9c92908ef863d29da08345e0b5747a99d411
parent: 0cd57a02a29ae329b70f185d957a1008660d43e4
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Oct 29 12:21:11 EDT 2023

snap: keep old snap tree blocks in deadlists

--- a/blk.c
+++ b/blk.c
@@ -931,7 +931,7 @@
 	Bfree *f;
 	ulong ge;
 
-	if(t != nil && t != &fs->snap && bp.gen <= t->gen){
+	if(t == &fs->snap || (t != nil && bp.gen <= t->gen)){
 		killblk(t, bp);
 		return;
 	}
@@ -1233,5 +1233,16 @@
 			sysfatal("sync arena: %r");
 		qunlock(a);
 	}
+	/*
+	 * Pass 4: clean up the old snap tree's deadlist
+	 */
+	freedl(&fs->snapdl, 1);
+	fs->snapdl.hd.addr = -1;
+	fs->snapdl.hd.hash = -1;
+	fs->snapdl.hd.gen = -1;
+	fs->snapdl.tl.addr = -1;
+	fs->snapdl.tl.hash = -1;
+	fs->snapdl.tl.gen = -1;
+	fs->snapdl.ins = nil;
 	qunlock(&fs->synclk);
 }
--- a/dat.h
+++ b/dat.h
@@ -466,6 +466,7 @@
 	int	blksz;
 	int	bufspc;
 	Tree	snap;
+	Dlist	snapdl;
 	int	narena;
 	vlong	arenasz;
 	vlong	nextqid;
--- a/pack.c
+++ b/pack.c
@@ -561,12 +561,16 @@
 	int i;
 
 	assert(sz == Blksz);
-	memcpy(p, "gefs0006", 8);	p += 8;
+	memcpy(p, "gefs0007", 8);	p += 8;
 	PACK32(p, Blksz);		p += 4;
 	PACK32(p, Bufspc);		p += 4;
 	PACK32(p, fi->snap.ht);		p += 4;
 	PACK64(p, fi->snap.bp.addr);	p += 8;
 	PACK64(p, fi->snap.bp.hash);	p += 8;
+	PACK64(p, fi->snapdl.hd.addr);	p += 8;
+	PACK64(p, fi->snapdl.hd.hash);	p += 8;
+	PACK64(p, fi->snapdl.tl.addr);	p += 8;
+	PACK64(p, fi->snapdl.tl.hash);	p += 8;
 	PACK32(p, fi->narena);		p += 4;
 	PACK64(p, fi->arenasz);		p += 8;
 	PACK64(p, fi->nextqid);		p += 8;
@@ -585,21 +589,28 @@
 	int i;
 
 	assert(sz == Blksz);
-	if(memcmp(p, "gefs0006", 8) != 0){
+	if(memcmp(p, "gefs0007", 8) != 0){
 		werrstr("wrong block header %.8s\n", p);
 		return nil;
 	}
 	p += 8;
-	fi->blksz = UNPACK32(p);	p += 4;
-	fi->bufspc = UNPACK32(p);	p += 4;
-	fi->snap.ht = UNPACK32(p);	p += 4;
-	fi->snap.bp.addr = UNPACK64(p);	p += 8;
-	fi->snap.bp.hash = UNPACK64(p);	p += 8;
-	fi->snap.bp.gen = -1;		p += 0;
-	fi->narena = UNPACK32(p);	p += 4;
-	fi->arenasz = UNPACK64(p);	p += 8;
-	fi->nextqid = UNPACK64(p);	p += 8;
-	fi->nextgen = UNPACK64(p);	p += 8;
+	fi->blksz = UNPACK32(p);		p += 4;
+	fi->bufspc = UNPACK32(p);		p += 4;
+	fi->snap.ht = UNPACK32(p);		p += 4;
+	fi->snap.bp.addr = UNPACK64(p);		p += 8;
+	fi->snap.bp.hash = UNPACK64(p);		p += 8;
+	fi->snap.bp.gen = -1;			p += 0;
+	fi->snapdl.hd.addr = UNPACK64(p);	p += 8;
+	fi->snapdl.hd.hash = UNPACK64(p);	p += 8;
+	fi->snapdl.gen = -1;			p += 0;
+	fi->snapdl.tl.addr = UNPACK64(p);	p += 8;
+	fi->snapdl.tl.hash = UNPACK64(p);	p += 8;
+	fi->snapdl.gen = -1;			p += 0;
+	fi->snapdl.gen = 
+	fi->narena = UNPACK32(p);		p += 4;
+	fi->arenasz = UNPACK64(p);		p += 8;
+	fi->nextqid = UNPACK64(p);		p += 8;
+	fi->nextgen = UNPACK64(p);		p += 8;
 	fi->qgen = UNPACK64(p);	p += 8;
 	fi->arenabp = malloc(fi->narena * sizeof(Bptr));
 	for(i = 0; i < fi->narena; i++){
--- a/ream.c
+++ b/ream.c
@@ -351,6 +351,10 @@
 
 	fs->snap.bp = tb->bp;
 	fs->snap.ht = 1;
+	fs->snapdl.hd.addr = -1;
+	fs->snapdl.hd.hash = -1;
+	fs->snapdl.tl.addr = -1;
+	fs->snapdl.tl.hash = -1;
 	fs->nextqid = Nreamqid;
 
 	dropblk(mb);
--- a/snap.c
+++ b/snap.c
@@ -541,8 +541,10 @@
 	Blk *b;
 	char *p;
 
-	if((dl = getdl(t->gen, bp.gen)) == nil)
-		return -1;
+	if(t == &fs->snap)
+		dl = &fs->snapdl;
+	else if((dl = getdl(t->gen, bp.gen)) == nil)
+ 		return -1;
 	if(dl->ins == nil || Dlspc - dl->ins->deadsz < 8){
 		if((b = newblk(&fs->snap, Tdlist)) == nil){
 			putdl(dl);
@@ -566,6 +568,7 @@
 	dl->ins->flag |=  Bdirty;
 	dl->ins->deadsz += 8;
 	PACK64(p, bp.addr);
-	putdl(dl);
+	if(t != &fs->snap)
+		putdl(dl);
 	return 0;
 }