ref: 81092632561b4605f1fc366a9b2cfc6e11d3b57c
parent: 8417419572f7f1a14fe052fa46edfd4d2bc15a04
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 2 12:07:03 EST 2022
snap: fix deadlist handling
--- a/blk.c
+++ b/blk.c
@@ -286,8 +286,6 @@
return 0;
}
-showlst("a", a);
-showlst("b", b);
o = b->head.addr|LogChain;
p = a->tail->data + a->tail->logsz;
PBIT64(p, o);
@@ -295,20 +293,15 @@
return -1;
putblk(a->tail);
a->tail = b->tail;
-showlst("grafted", b);
return 0;
}
int
-deadlistappend(Tree *t, Bptr bp)
+killblk(Tree *t, Bptr bp)
{
Oplog *l;
int i;
-dprint("deadlisted %B [%p::%B]\n", bp, t, t->bp);
-//fprint(2, "predeadlist\n");
-//showtreeroot(2, t);
-//fprint(2, "----\n");
l = nil;
for(i = 0; i < Ndead; i++){
l = &t->dead[i];
@@ -317,9 +310,6 @@
}
if(logappend(l, nil, bp.addr, Blksz, bp.gen, LogDead) == -1)
return -1;
-//fprint(2, "postdeadlist\n");
-//showtreeroot(2, t);
-//fprint(2, "@@@@@@@@@@@@@@@@@@\n");
return 0;
}
@@ -330,7 +320,7 @@
* recursion.
*/
int
-freelistappend(Arena *a, vlong off, int op)
+logop(Arena *a, vlong off, int op)
{
cachedel(off);
if(logappend(&a->log, a, off, Blksz, Blksz, op) == -1)
@@ -629,7 +619,7 @@
a = getarena(b);
if(freerange(a->free, b, Blksz) == -1)
goto out;
- if(freelistappend(a, b, LogFree) == -1)
+ if(logop(a, b, LogFree) == -1)
goto out;
r = 0;
out:
@@ -668,7 +658,7 @@
unlock(a);
goto Again;
}
- if(freelistappend(a, b, LogAlloc) == -1){
+ if(logop(a, b, LogAlloc) == -1){
unlock(a);
return -1;
}
@@ -870,7 +860,7 @@
dprint("[%s] free blk %B\n", (t == &fs->snap) ? "snap" : "data", bp);
if(bp.gen <= t->gen){
- deadlistappend(t, bp);
+ killblk(t, bp);
return;
}
if((f = malloc(sizeof(Bfree))) == nil)
--- a/dump.c
+++ b/dump.c
@@ -329,23 +329,23 @@
{
int i;
- fprint(fd, "\tref:\t%d\n", t->ref);
fprint(fd, "\tgen:\t%lld\n", t->gen);
- fprint(fd, "\tht:\t%d\n", t->ht);
- fprint(fd, "\tbp:\t%B\n", t->bp);
+// fprint(fd, "\tref:\t%d\n", t->ref);
+// fprint(fd, "\tht:\t%d\n", t->ht);
+// fprint(fd, "\tbp:\t%B\n", t->bp);
for(i = 0; i < Ndead; i++){
- fprint(fd, "\tdeadlist %d\n", i);
- fprint(fd, "\t\tprev:\t%llx\n", t->prev[i]);
- fprint(fd, "\t\tfhead:\t%B\n", t->dead[i].head);
- if(t->dead[i].tail != nil){
- fprint(fd, "\t\tftailp:%llx\n", t->dead[i].tail->bp.addr);
- fprint(fd, "\t\tftailh:%llx\n", t->dead[i].tail->bp.hash);
- }else{
- fprint(fd, "\t\tftailp:\t-1\n");
- fprint(fd, "\t\tftailh:\t-1\n");
- }
- fprint(fd, "\t\tdead[%d]: (%B)\n", i, t->dead[i].head);
- scandead(&t->dead[i], showdeadbp, &fd);
+ fprint(fd, "\tdeadlist[%d]: prev=%llx\n", i, t->prev[i]);
+// fprint(fd, "\t\tprev:\t%llx\n", t->prev[i]);
+// fprint(fd, "\t\tfhead:\t%B\n", t->dead[i].head);
+// if(t->dead[i].tail != nil){
+// fprint(fd, "\t\tftailp:%llx\n", t->dead[i].tail->bp.addr);
+// fprint(fd, "\t\tftailh:%llx\n", t->dead[i].tail->bp.hash);
+// }else{
+// fprint(fd, "\t\tftailp:\t-1\n");
+// fprint(fd, "\t\tftailh:\t-1\n");
+// }
+// fprint(fd, "\t\tdead[%d]: (%B)\n", i, t->dead[i].head);
+// scandead(&t->dead[i], showdeadbp, &fd);
}
}
--- a/fns.h
+++ b/fns.h
@@ -25,6 +25,7 @@
void quiesce(int);
void freeblk(Tree*, Blk*);
void freebp(Tree*, Bptr);
+int killblk(Tree*, Bptr);
int graft(Oplog*, Oplog*);
void reclaimblk(Bptr);
ushort blkfill(Blk*);
@@ -34,6 +35,7 @@
char* fillsuper(Blk*);
Tree* newsnap(Tree*);
char* freesnap(Tree*, Tree*);
+int savesnap(Tree*);
char* labelsnap(char*, vlong);
char* unlabelsnap(vlong, char*);
char* refsnap(vlong);
@@ -138,5 +140,6 @@
/* it's in libc... */
extern int cas(long*, long, long);
+extern int fas32(int*, int);
extern int cas64(u64int*, u64int, u64int);
uvlong inc64(uvlong*, uvlong);
--- a/fs.c
+++ b/fs.c
@@ -33,6 +33,9 @@
}
}
f->mnt->root = n;
+fprint(2, "updated\n");
+showtreeroot(2, n);
+fprint(2, "==================================\n");
closesnap(t);
qunlock(&fs->snaplk);
sync();
--- a/snap.c
+++ b/snap.c
@@ -201,6 +201,12 @@
reclaimblk(bp);
}
+void
+redeadlist(Bptr bp, void *pt)
+{
+ killblk(pt, bp);
+}
+
char*
freesnap(Tree *snap, Tree *next)
{
@@ -210,35 +216,38 @@
assert(snap->gen != next->gen);
assert(next->prev[0] == snap->gen);
-//fprint(2, "next tree\n");
-//showtreeroot(2, next);
-//fprint(2, "snap tree\n");
-//showtreeroot(2, snap);
+fprint(2, "next tree\n");
+showtreeroot(2, next);
+fprint(2, "snap tree\n");
+showtreeroot(2, snap);
+
+ dl = next->dead[Ndead-1];
scandead(&next->dead[0], freedead, nil);
- for(i = 0; i < Ndead-1; i++){
+ for(i = 0; i < Ndead-2; i++){
+ if(graft(&snap->dead[i], &next->dead[i+1]) == -1)
+ return Efs;
next->prev[i] = snap->prev[i];
- dl = snap->dead[i];
- if(i < Ndead-1)
- if(graft(&dl, &next->dead[i+1]) == -1)
- return Efs;
- next->dead[i] = dl;
+ next->dead[i] = snap->dead[i];
}
-//fprint(2, "transferred\n");
-//showtreeroot(2, next);
+ for(; i < Ndead; i++){
+ next->prev[i] = snap->prev[i];
+ next->dead[i] = snap->dead[i];
+ }
+ scandead(&dl, redeadlist, next);
+
+fprint(2, "transferred\n");
+showtreeroot(2, next);
+fprint(2, "==================================\n");
return nil;
}
-Tree*
-newsnap(Tree *t)
+int
+savesnap(Tree *t)
{
char kbuf[Snapsz], vbuf[Treesz];
- vlong gen;
char *p, *e;
- Tree *r;
Msg m;
int i;
-
- gen = inc64(&fs->nextgen, 1);
for(i = 0; i < Ndead; i++){
if(t->dead[i].tail != nil){
finalize(t->dead[i].tail);
@@ -256,13 +265,25 @@
m.nv = p - vbuf;
if((e = btupsert(&fs->snap, &m, 1)) != nil){
fprint(2, "error snapshotting: %s\n", e);
- qunlock(&fs->snaplk);
- return nil;
+ return -1;
}
+ return 0;
+}
- if((r = malloc(sizeof(Tree))) == nil)
+
+Tree*
+newsnap(Tree *t)
+{
+ vlong gen;
+ Tree *r;
+ int i;
+
+ if(savesnap(t) == -1)
return nil;
+ if((r = malloc(sizeof(Tree))) == nil)
+ return nil;
+ gen = inc64(&fs->nextgen, 1);
memset(&r->lk, 0, sizeof(r->lk));
r->snext = fs->osnap;
r->memref = 1;