ref: 54321e719b4375e7c6b8076c1bd3f5649ef8f1f1
parent: 8ad21d99f5b7db36769ac57d265f2f1c5bacd37c
author: Ori Bernstein <[email protected]>
date: Sun Dec 10 17:26:09 EST 2023
load, ream: oops, committed junk
--- a/load.c
+++ b/load.c
@@ -64,9 +64,7 @@
Arena *a;
Bptr bp;
Tree *t;
- Dir *d;
int i, k;
- vlong eb;
if((dump = mallocz(sizeof(*dump), 1)) == nil)
sysfatal("malloc: %r");
@@ -82,16 +80,10 @@
fs->narena = 1;
if((fs->fd = open(dev, ORDWR)) == -1)
sysfatal("open %s: %r", dev);
- if((d = dirfstat(fs->fd)) == nil)
- sysfatal("stat %s: %r", dev);
-
- eb = d->length - (d->length%Blksz) - Blksz;
bp = (Bptr){0, -1, -1};
fs->sb0 = getblk(bp, GBnochk);
- bp = (Bptr){eb, -1, -1};
+ bp = (Bptr){512*MiB, -1, -1};
fs->sb1 = getblk(bp, GBnochk);
- free(d);
-
unpacksb(fs, fs->sb0->buf, Blksz);
if((fs->arenas = calloc(fs->narena, sizeof(Arena))) == nil)
sysfatal("malloc: %r");
--- a/ream.c
+++ b/ream.c
@@ -168,7 +168,15 @@
Blk *b, *hd, *tl;
b = cachepluck();
+ if(start == 512*MiB){
+ start += Blksz;
+ asz -= Blksz;
+ }
addr = start+Blksz; /* leave room for arena hdr */
+ if(addr == 512*MiB){
+ addr += Blksz;
+ asz -= Blksz;
+ }
a->loghd.addr = -1;
a->loghd.hash = -1;
@@ -188,6 +196,11 @@
PACK64(p, asz-Blksz); p += 8; /* len */
PACK64(p, b->bp.addr|LogAlloc); p += 8; /* addr */
PACK64(p, Blksz); p += 8; /* len */
+ /* backup sb */
+ if(start <= 512*MiB && start+asz > 512*MiB){
+ PACK64(p, (512*MiB)|LogAlloc1);
+ p += 8;
+ }
PACK64(p, (uvlong)LogSync); p += 8; /* barrier */
b->logsz = p - b->data;
finalize(b);
@@ -248,30 +261,31 @@
sz = d->length;
free(d);
+ if(sz < 512*MiB+Blksz)
+ sysfatal("ream: disk too small");
mnt = emalloc(sizeof(Mount), 1);
mnt->root = mallocz(sizeof(Tree), 1);
adm = mallocz(sizeof(Mount), 1);
adm->root = mallocz(sizeof(Tree), 1);
- sz = sz - sz%Blksz - 2*Blksz;
-
- fs->narena = (sz + 64ULL*GiB - 1) / (64ULL*GiB);
- if(fs->narena < 8)
- fs->narena = 8;
- if(fs->narena >= 128)
- fs->narena = 128;
+ sz = sz - sz%Blksz;
+ fs->narena = (sz + 4096ULL*GiB - 1) / (4096ULL*GiB);
+ if(fs->narena < 4)
+ fs->narena = 4;
+ if(fs->narena >= 32)
+ fs->narena = 32;
fs->arenas = emalloc(fs->narena*sizeof(Arena), 1);
off = Blksz;
asz = sz/fs->narena;
- asz = asz - (asz % Blksz) - Blksz;
+ asz = asz - (asz % Blksz) - 2*Blksz;
fs->arenasz = asz;
sb0 = cachepluck();
sb1 = cachepluck();
sb0->bp = (Bptr){0, -1, -1};
- sb1->bp = (Bptr){sz+Blksz, -1, -1};
+ sb1->bp = (Bptr){512*MiB, -1, -1};
fs->arenabp = emalloc(fs->narena * sizeof(Bptr), 1);
for(i = 0; i < fs->narena; i++){
@@ -279,7 +293,8 @@
print("\tarena %d: %lld blocks at %llx\n", i, asz/Blksz, off);
initarena(a, off, asz);
fs->arenabp[i] = a->hd->bp;
- off += asz+Blksz;
+ off += asz+2*Blksz;
+
}
for(i = 0; i < fs->narena; i++){