ref: 8255d0db25b1a87f2f604d87d82ca41e66e92db3
parent: 56bd332994102b4e194819abb5e087a8895452f9
author: 9ferno <[email protected]>
date: Thu Nov 24 12:04:36 EST 2022
cleanup the dentry on removal
--- a/9p.c
+++ b/9p.c
@@ -644,7 +644,6 @@
aux->tlocked = 0;
req->ofcall.qid = fid->qid;
req->ofcall.iounit = Iounit;
- settag(cbuf, Tdentry, dchild->path);
putbuf(cbuf, 1); /* save Iobuf of the content */
/*
only add it to the directory dentry if we are adding a new dentry block
@@ -1451,7 +1450,7 @@
/* free the old last blocks */
if(oldbuf)
- putbuffree(oldbuf);
+ freeblockbuf(oldbuf);
d->size += howmuch;
return 1;
}
@@ -1554,7 +1553,7 @@
/* free the old last blocks */
if(oldbuf)
- putbuffree(oldbuf);
+ freeblockbuf(oldbuf);
d->size += dbuf->appendsize;
dbuf->appendsize = 0;
return 1;
--- a/blk.c
+++ b/blk.c
@@ -105,11 +105,11 @@
showdentry(fd, buf);
return;
}else if(tag == Tdata){
- fprint(fd, "%s %d %llud %llud\n", tagnames[tag], t->len, t->dblkno, t->path);
+ fprint(fd, "%s %llud %llud %d\n", tagnames[tag], t->path, t->dblkno, t->len);
showdata(fd, buf);
return;
}else if(tag < Maxtind)
- fprint(fd, "%s %d %llud %llud\n", tagnames[tag], r->veri, r->dblkno, r->path);
+ fprint(fd, "%s %llud %d %llud\n", tagnames[tag], r->path, r->veri, r->dblkno);
if(tag >= Tind0 && tag < Maxtind)
showind(fd, buf);
--- a/dat.h
+++ b/dat.h
@@ -338,9 +338,9 @@
Tblank = 0,
Tfree = 0, /* free block */
Tnone = 0,
+ Tdata, /* actual file contents */
Tdentry, /* directory entry, size = Dentrysize */
/* Tdata & indirect blocks are last, to allow for greater depth */
- Tdata, /* actual file contents */
Tind0, /* contains a list of Tdata block numbers for files
and Tdentry block numbers for directories.*/
Tind1, /* contains a list of Tind0 block numbers */
@@ -350,7 +350,7 @@
/* gap for more indirect block depth in future.
It can be put upto Tind7 without needing any code changes */
Maxtind, /* should be Tind0+Niblock */
- MAXTAG,
+ MAXTAG = Maxtind,
Tmaxind = Maxtind - 1,
};
--- a/dentry.c
+++ b/dentry.c
@@ -81,7 +81,7 @@
}
u64
-updateindblock(u64 indblkno, u64 reli, u16 tag, u64 path, u64 blkno)
+updateindblock(u64 dblkno, u64 indblkno, u64 reli, u16 tag, u64 path, u64 blkno)
{
Iobuf *buf;
u64 n, childindblkno;
@@ -95,6 +95,7 @@
dprint("%s",errstring[Efull]);
return 0;
}
+ buf->new->dblkno = dblkno;
indblkno = buf->blkno;
}else{
if((buf = getmetachk(indblkno, Bwritable, tag, path)) == nil){
@@ -121,7 +122,7 @@
dprint("%s",errstring[Ephase]);
return 0;
}
- childindblkno = updateindblock(buf->new->bufa[reli/n],
+ childindblkno = updateindblock(dblkno, buf->new->bufa[reli/n],
reli%n, tag-1, path,
blkno);
buf->new->bufa[reli/n] = childindblkno;
@@ -151,7 +152,7 @@
addrelative(Dentry *d, u64 dblkno, u64 reli, u64 blkno)
{
u64 path, nblkno;
- u16 tag;
+ u8 tag;
if(chatty9p > 2)
dprint("addrelative %llud:%s reli %llud blkno %llud\n",
@@ -165,9 +166,9 @@
tag = rel2tind(reli);
if(chatty9p > 2)
- dprint(" reli %llud tag %s d->iblocks[tag-Tind0] %llud blkno %llud\n",
- reli, tagnames[tag], d->iblocks[tag-Tind0], blkno);
- if((nblkno = updateindblock(d->iblocks[tag-Tind0], reli-tagstartreli(tag), tag, path, blkno)) == 0){
+ dprint("addrelative(): reli %llud tag %s d->iblocks[%d] %llud blkno %llud\n",
+ reli, tagnames[tag], tag-Tind0, d->iblocks[tag-Tind0], blkno);
+ if((nblkno = updateindblock(dblkno, d->iblocks[tag-Tind0], reli-tagstartreli(tag), tag, path, blkno)) == 0){
dprint("%s",errstring[Ephase]);
return 0;
}
@@ -310,11 +311,12 @@
return;
dbuf = getmetachk(dblkno, Bwritable, Tdentry, qpath);
if(dbuf == nil)
- dprint("%s",errstring[Ephase]);
+ dprint("%s",errstring[Ephase]);
size = dbuf->new->size;
memcpy(&d, dbuf->new, sizeof(Dentry));
- memset(((Dentry*)dbuf->new)->buf, 0, Ddatasize);
+ memset(dbuf->new, 0, Blocksize);
settag(dbuf, Tdentry, Qpnone);
+ dbuf->new->verd = d.verd;
if(dbuf->append){ /* data not yet written */
freememunits((u8*)dbuf->append, Maxdatablockunits);
dbuf->append = nil;
@@ -361,7 +363,9 @@
if(dbuf == nil)
dprint("%s",errstring[Ephase]);
memcpy(&d, dbuf->new, sizeof(Dentry));
+ memset(dbuf->new, 0, Blocksize);
settag(dbuf, Tdentry, Qpnone);
+ dbuf->new->verd = d.verd;
putbuf(dbuf, 1);
/*
--- a/iobuf.c
+++ b/iobuf.c
@@ -310,7 +310,7 @@
dprint("getbufchk caller pc 0x%p\n", getcallerpc(&blkno));
b = getbuf(blkno, len, readonly, Bused);
if(b != nil)
- if(tag != Tdata){
+ if(tag > Tdata && tag < MAXTAG){
recentmetadata(b->m, &b->cur, &b->new);
if(readonly == 0){ /* writable */
memcpy(b->new, b->cur, Blocksize);
@@ -427,6 +427,13 @@
else
devwrite(p->blkno+(p->new>p->cur?1:0), p->new, 1);
}
+ }else if(p->xiobuf[0] > Tdata && p->xiobuf[0] < MAXTAG){
+ /*
+ make the new->ver below the cur->ver so the new gets
+ overwritten the next time instead of a memcpy() to
+ copy the contents over.
+ */
+ p->new->verd = p->cur->verd-1;
}
if(chkwunlock(p) == 0){
showbuf(p);
@@ -444,43 +451,6 @@
}
}
-/* only caller is freeblockbuf().
- These blocks do not need to be written to the disk.
- Hence, avoiding putwrite().
- */
-void
-putbuffree(Iobuf *p)
-{
- if(p == nil){
- panic("putbuffree p == nil called by %#p\n", getcallerpc(&p));
- dprint("%s\n", errstring[Ephase]);
- return;
- }
- if(p->io == nil){
- showbuf(p);
- panic("putbuffree p->io == nil by %#p\n", getcallerpc(&p));
- dprint("%s\n", errstring[Ephase]);
- return;
- }
-
- if(chatty9p > 4)
- dprint("putbuffree p->blkno %llud\n", p->blkno);
-
- if(p->readers){
- chkrunlock(p);
- // if(chatty9p > 4)
- panic(" .. runlock()'ed\n");
- }else{
- if(canwlock(p)){
- panic("putbuffree: buffer not locked %llud\n", p->blkno);
- }
- if(chkwunlock(p) == 0){
- showbuf(p);
- panic("putbuffree chkwunlock(p) == 0 called by %#p\n", getcallerpc(&p));
- }
- }
-}
-
int
checktag(Iobuf *p, u16 len, u8 tag, u64 qpath)
{
@@ -518,6 +488,7 @@
pc, devfile, (u64)p->blkno,
tagnames[ptag], (u64)pqpath,
tagnames[tag], (u64)qpath);
+ panic("checktag failed\n");
}
return 0;
}
@@ -538,7 +509,7 @@
p->io->path = qpath;
}else{
((Dentry*)p->new)->tag = tag;
- ((Dentry*)p->new)->path = ((Dentry*)p->new)->qpath = qpath;
+ ((Dentry*)p->new)->path = qpath;
}
}
--- a/sub.c
+++ b/sub.c
@@ -130,7 +130,7 @@
/* clear the buf to avoid leaks on reuse */
memset(buf->xiobuf, 0, buf->len*Blocksize);
bfree(&frees, buf->blkno, buf->len);
- putbuffree(buf);
+ putbuf(buf, 0);
}
/* add the block to the extents used to manage free blocks */
--- a/tests/regress.rc
+++ b/tests/regress.rc
@@ -93,10 +93,8 @@
chkreli.rc
chkextents.rc
for (t in test.*){
-# rununi mfs $t
rununi mafs $t
-# runmp mfs $t
-# runmp mafs $t
+ runmp mafs $t
}
}
if not {
@@ -107,9 +105,7 @@
chkextents.rc
}
if not {
-# rununi mfs $*
rununi mafs $*
-# runmp mfs $*
-# runmp mafs $*
+ runmp mafs $*
}
}
--- a/tests/test.2/action.rc
+++ b/tests/test.2/action.rc
@@ -5,7 +5,7 @@
# du -a /n/^$service^/
for(t in 0 1 01 2 3 4 5 7){
-#for(t in 4 7){
+# for(t in 0){
touch /n/^$service^/file1
echo ./6.offsets -s test.2/^$t^.start -o `{cat test.2/^$t^.offset} -a test.2/^$t^.add /n/^$service^/file1
./6.offsets -s test.2/^$t^.start -o `{cat test.2/^$t^.offset} -a test.2/^$t^.add /n/^$service^/file1
--- a/tests/test.2/blocks/23
+++ b/tests/test.2/blocks/23
@@ -1,4 +1,4 @@
-Tdentry 71 39
+Tdentry 71 35
name file1
uid 10006
gid -1
@@ -6,7 +6,7 @@
size 0
pdblkno 20
pqpath 20
-mtime 1669260591000000000
+mtime 1669333591284727201
path 71
version 0
mode 666