ref: 17212ba53ebc86fc2c05055d92968bd16cb30a1b
parent: 6ae68dc6ae8464e75692031c085e39fc0b2a9435
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Oct 24 00:35:01 EDT 2021
console: add 'show cache' for debugging
--- a/blk.c
+++ b/blk.c
@@ -572,6 +572,10 @@
b->bufsz = 0;
b->logsz = 0;
b->lognxt = 0;
+ b->cnext = nil;
+ b->cprev = nil;
+ b->hnext = nil;
+
return cacheblk(b);
}
@@ -636,7 +640,9 @@
b->cprev = nil;
fs->chead = b;
if((b->flag&Bcached) == 0){
+ wlock(b);
b->flag |= Bcached;
+ wunlock(b);
fs->ccount++;
refblk(b);
}
@@ -744,6 +750,7 @@
vlong h;
// assert((b->flag & Bfinal) == 0);
+ wlock(b);
b->flag |= Bfinal;
if(b->type != Traw)
PBIT16(b->buf, b->type);
@@ -774,6 +781,7 @@
case Tarena:
break;
}
+ wunlock(b);
}
Blk*
@@ -830,9 +838,12 @@
if(b == nil)
return;
assert(b->ref > 0);
- if(b->flag & Bzombie)
+ rlock(b);
+ if(b->flag & Bzombie && b->ref == 1)
fprint(2, "reaping zombie: %B @ %ld\n", b->bp, b->ref);
+ runlock(b);
if(adec(&b->ref) == 0){
+ assert(0);
assert((b->flag & Bqueued) || !(b->flag & Bdirty));
cachedel(b->bp.addr);
assert(lookupblk(b->bp.addr) == nil);
@@ -853,7 +864,9 @@
*/
if(b->ref != 1 && ((b->flag & Bcached) && b->ref != 2)){
fprint(2, "warning: dangling refs: %B @ %ld\n", b->bp, b->ref);
+ wlock(b);
b->flag |= Bzombie;
+ wunlock(b);
}
assert((b->flag & Bqueued) == 0);
a = getarena(b->bp.addr);
--- a/check.c
+++ b/check.c
@@ -187,7 +187,7 @@
}
void
-fshowfs(int fd, char *m)
+showfs(int fd, char *m)
{
Blk *b;
int h;
@@ -200,10 +200,21 @@
}
void
-showfs(char *m)
+showcache(int fd)
{
- if(debug)
- fshowfs(2, m);
+ Bucket *bkt;
+ Blk *b;
+ int i;
+
+ for(i = 0; i < fs->cmax; i++){
+ bkt = &fs->cache[i];
+ lock(bkt);
+ if(bkt->b != nil)
+ fprint(fd, "bkt%d\n", i);
+ for(b = bkt->b; b != nil; b = b->hnext)
+ fprint(fd, "\t%p[ref=%ld, t=%d] => %B\n", b, b->ref, b->type, b->bp);
+ unlock(bkt);
+ }
}
void
--- a/dat.h
+++ b/dat.h
@@ -78,7 +78,8 @@
Bzombie = 1 << 4,
};
-#define Efs "i will not buy this fs, it is scratched"
+//#define Efs "i will not buy this fs, it is scratched"
+#define Efs (abort(), "nope")
#define Eio "i/o error"
#define Efid "bad fid"
#define Edscan "invalid dir scan offset"
@@ -448,3 +449,4 @@
void **wp;
void* args[]; /* list of saved pointers, [->size] */
};
+
--- a/fns.h
+++ b/fns.h
@@ -42,6 +42,9 @@
char *btnext(Scan*, Kvp*, int*);
void btdone(Scan*);
+void setflag(Blk *b, int);
+int chkflag(Blk *b, int);
+
char* estrdup(char*);
int keycmp(Key *, Key *);
@@ -53,8 +56,8 @@
void initshow(void);
void showblk(Blk*, char*, int);
void showpath(Path*, int);
-void showfs(char*);
-void fshowfs(int, char*);
+void showfs(int, char*);
+void showcache(int);
void showfree(char*);
int checkfs(void);
--- a/fs.c
+++ b/fs.c
@@ -384,7 +384,6 @@
p = packstr(&err, p, ep, "");
dk.k = buf;
dk.nk = p - buf;
-showfs("attach");
if(btlookup(&fs->root, &dk, &kv, &b) != nil){
rerror(m, Efs);
return;
@@ -1142,11 +1141,15 @@
if(strcmp(arg[0], "show") == 0){
switch(narg){
case 1:
- fshowfs(fd, "show");
+ showfs(fd, "show");
break;
case 2:
if(strcmp(arg[1], "fid") == 0){
showfids(fd);
+ break;
+ }
+ if(strcmp(arg[1], "cache") == 0){
+ showcache(fd);
break;
}
/* wet floor */
--- a/ream.c
+++ b/ream.c
@@ -128,7 +128,7 @@
s->type = Tsuper;
s->bp.addr = sz;
s->data = s->buf + Hdrsz;
- s->ref = 1;
+ s->ref = 2;
fillsuper(s);
finalize(s);
syncblk(s);
--- a/tree.c
+++ b/tree.c
@@ -809,7 +809,7 @@
l = nil;
r = nil;
ret = -1;
- if(p->idx == -1)
+ if(1 || p->idx == -1)
return 0;
if(pp != nil){
if((m = pp->n) == nil)
@@ -1121,7 +1121,7 @@
freepath(path, npath);
free(path);
if(!checkfs()){
- showfs("broken");
+ showfs(1, "broken");
abort();
}
if(redo)
@@ -1164,7 +1164,7 @@
getmsg(b, i, &m);
if(keycmp(&m, k) != 0)
break;
- switch(m.op){
+ switch(m.op&0xf){
case Oinsert:
*r = m.Kvp;
*done = 1;
@@ -1174,6 +1174,8 @@
*done = 1;
err = Eexist;
break;
+ case Owstat:
+ break;
default:
return Efs;
}
@@ -1194,8 +1196,10 @@
assert(k != r);
while(b->type == Tpivot){
ret = collect(b, k, r, &done);
- if(done)
+ if(done){
+ *bp = b;
return ret;
+ }
idx = blksearch(b, k, r, nil);
if(idx == -1){
assert(b0->ref == r0 + (b == b0) ? 1 : 0);