gbmap: Added LFS3_T_REBUILDGBMAP and friends

This adds LFS3_T_REBUILDGBMAP and friends, and enables incremental gbmap
rebuilds as a part of gc/traversal work:

  LFS3_M_REBUILDGBMAP   0x00000400  Rebuild the gbmap
  LFS3_GC_REBUILDGBMAP  0x00000400  Rebuild the gbmap
  LFS3_I_REBUILDGBMAP   0x00000400  The gbmap is not full
  LFS3_T_REBUILDGBMAP   0x00000400  Rebuild the gbmap

On paper, this is more or less identical to repopulating the lookahead
buffer -- traverse the filesystem, mark blocks as in-use, adopt the new
gbmap/lookahead buffer on success -- but a couple nuances make
rebuilding the gbmap a bit trickier:

- Unlike the lookahead buffer, which eagerly zeros in allocation, we
  need an explicit zeroing pass before we start marking blocks as
  in-use. This means multiple traversals can potentially conflict with
  each other, risking the adoption of a clobbered gbmap.

- The gbmap, which stores information on disk, relies on block
  allocation and the temporary "in-flight window" defined by allocator
  ckpoints to avoid circular block states during gbmap rebuilds. This
  makes gbmap rebuilds sensitive to allocator ckpoints, which we
  consider more-or-less a noop in other parts of the system.

  Though now that I'm writing this, it might have been possible to
  instead include gbmap rebuild snapshots in fs traversals... but that
  would probably have been much more complicated.

- Rebuilding the gbmap requires writing to disk and is generally much
  more expensive/destructive. We want to avoid trying to rebuild the
  gbmap when it's not possible to actually make progress.

On top of this, the current trv-clobber system is a delicate,
error-prone mess.

---

To simplify everything related to gbmap rebuilds, I added a new
internal traversal flag: LFS3_t_CKPOINTED:

  LFS3_t_CKPOINTED  0x04000000  Filesystem ckpointed during traversal

LFS3_t_CKPOINTED is set, unconditionally, on all open traversals in
lfs3_alloc_ckpoint, and provides a simple, robust mechanism for checking
if _any_ allocator checkpoints have occured since a traversal was
started. Since lfs3_alloc_ckpoint is required before any block
allocation, this provides a strong guarantee that nothing funny happened
to any allocator state during a traversal.

This makes lfs3_alloc_ckpoint a bit less cheap, but the strong
guarantees that allocator state is unmodified during traversal are well
worth it.

This makes both lookahead and gbmap passes simpler, safer, and easier to
reason about.

I'd like to adopt something similar+stronger for LFs3_t_MUTATED, and
reduce this back to two flags, but that can be a future commit.

---

Unfortunately due to the potential for recursion, this ended up reusing
less logic between lfs3_alloc_rebuildgbmap and lfs3_mtree_gc than I had
hoped, but at like the main chunks (lfs3_alloc_remap,
lfs3_gbmap_setbptr, lfs3_alloc_adoptgbmap) could be split out into
common functions.

The result is a decent chunk of code and stack, but the value is high as
incremental gbmap rebuilds are the only option to reduce the latency
spikes introduced by the gbmap allocator (it's not significantly worse
than the lookahead buffer, but both do require traversing the entire
filesystem):

                 code          stack          ctx
  before:       37164           2352          684
  after:        37208 (+0.1%)   2360 (+0.3%)  684 (+0.0%)

                 code          stack          ctx
  gbmap before: 39708           2376          848
  gbmap after:  40100 (+1.0%)   2432 (+2.4%)  848 (+0.0%)

Note the gbmap build is now measured with LFS3_GBMAP=1, instead of
LFS3_YES_GBMAP=1 (maybe-gbmap) as before. This includes the cost of
mkgbmap, lfs3_f_isgbmap, etc.
This commit is contained in:
Christopher Haster
2025-10-15 01:24:10 -05:00
parent 5bfa2a1071
commit f5508a1b6c
6 changed files with 1520 additions and 519 deletions

271
lfs3.c
View File

@ -7399,6 +7399,15 @@ static inline bool lfs3_t_islookahead(uint32_t flags) {
#endif
}
static inline bool lfs3_t_isrebuildgbmap(uint32_t flags) {
(void)flags;
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
return flags & LFS3_T_REBUILDGBMAP;
#else
return false;
#endif
}
static inline bool lfs3_t_iscompact(uint32_t flags) {
(void)flags;
#ifndef LFS3_RDONLY
@ -7451,6 +7460,10 @@ static inline void lfs3_t_setbtype(uint32_t *flags, uint8_t btype) {
*flags = (*flags & ~LFS3_t_BTYPE) | lfs3_t_btypeflags(btype);
}
static inline bool lfs3_t_isckpointed(uint32_t flags) {
return flags & LFS3_t_CKPOINTED;
}
static inline bool lfs3_t_isdirty(uint32_t flags) {
return flags & LFS3_t_DIRTY;
}
@ -10588,12 +10601,64 @@ eot:;
// needed in lfs3_mtree_gc
static int lfs3_mdir_mkconsistent(lfs3_t *lfs3, lfs3_mdir_t *mdir);
static inline void lfs3_alloc_ckpoint_(lfs3_t *lfs3);
static void lfs3_alloc_markfree(lfs3_t *lfs3, lfs3_block_t known);
static int lfs3_gbmap_remap(lfs3_t *lfs3, lfs3_btree_t *gbmap,
lfs3_tag_t tag, lfs3_tag_t tag_);
static int lfs3_gbmap_setbptr(lfs3_t *lfs3, lfs3_btree_t *gbmap,
lfs3_tag_t tag, const lfs3_bptr_t *bptr,
lfs3_tag_t tag_);
static void lfs3_alloc_adoptgbmap(lfs3_t *lfs3,
const lfs3_btree_t *gbmap, lfs3_block_t known);
// high-level mutating traversal, handle extra features that require
// mutation here
static lfs3_stag_t lfs3_mtree_gc(lfs3_t *lfs3, lfs3_trv_t *trv,
lfs3_bptr_t *bptr_) {
// start of traversal?
if (lfs3_t_tstate(trv->b.h.flags) == LFS3_TSTATE_MROOTANCHOR) {
// checkpoint the allocator to maximize any lookahead scans
#ifndef LFS3_RDONLY
if (lfs3_t_islookahead(trv->b.h.flags)
&& !lfs3_t_isckpointed(trv->b.h.flags)) {
lfs3_alloc_ckpoint_(lfs3);
// keep our own ckpointed flag clear
trv->b.h.flags &= ~LFS3_t_CKPOINTED;
}
#endif
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
// create a new gbmap snapshot
//
// note because we bail as soon as a ckpoint is triggered
// (lfs3_t_isckpointed), we don't need to traverse this
if (lfs3_t_isrebuildgbmap(trv->b.h.flags)
&& !lfs3_t_ismtreeonly(trv->b.h.flags)
&& lfs3_f_isgbmap(lfs3->flags)) {
// at least checkpoint the lookahead buffer
lfs3_alloc_ckpoint_(lfs3);
// create a copy of the gbmap
trv->gbmap_ = lfs3->gbmap.b;
// mark any in-use blocks as free
//
// we do this instead of creating a new gbmap to (1) preserve any
// erased/bad info and (2) try to best use any available
// erased-state
int err = lfs3_gbmap_remap(lfs3, &trv->gbmap_,
LFS3_TAG_BMINUSE,
LFS3_TAG_BMFREE);
if (err) {
return err;
}
// keep our own ckpointed flag clear
trv->b.h.flags &= ~LFS3_t_CKPOINTED;
}
#endif
}
dropped:;
lfs3_stag_t tag = lfs3_mtree_traverse(lfs3, trv,
bptr_);
@ -10612,13 +10677,32 @@ dropped:;
trv->b.h.flags = lfs3_t_swapdirty(trv->b.h.flags);
int err;
// track in-use blocks?
// mark in-use blocks in lookahead?
#ifndef LFS3_2BONLY
if (lfs3_t_islookahead(trv->b.h.flags)) {
if (lfs3_t_islookahead(trv->b.h.flags)
&& !lfs3_t_ismtreeonly(trv->b.h.flags)
&& !lfs3_t_isckpointed(trv->b.h.flags)) {
lfs3_alloc_markbptr(lfs3, tag, bptr_);
}
#endif
// mark in-use blocks in gbmap?
#ifdef LFS3_GBMAP
if (lfs3_t_isrebuildgbmap(trv->b.h.flags)
&& !lfs3_t_ismtreeonly(trv->b.h.flags)
&& lfs3_f_isgbmap(lfs3->flags)
&& !lfs3_t_isckpointed(trv->b.h.flags)) {
err = lfs3_gbmap_setbptr(lfs3, &trv->gbmap_, tag, bptr_,
LFS3_TAG_BMINUSE);
if (err) {
goto failed;
}
// keep our own ckpointed flag clear
trv->b.h.flags &= ~LFS3_t_CKPOINTED;
}
#endif
// mkconsistencing mdirs?
if (lfs3_t_ismkconsistent(trv->b.h.flags)
&& lfs3_t_ismkconsistent(lfs3->flags)
@ -10674,8 +10758,8 @@ dropped:;
#endif
return tag;
#ifndef LFS3_RDONLY
failed:;
#ifndef LFS3_RDONLY
// swap back dirty/mutated flags
trv->b.h.flags = lfs3_t_swapdirty(trv->b.h.flags);
return err;
@ -10687,12 +10771,21 @@ eot:;
#ifndef LFS3_2BONLY
if (lfs3_t_islookahead(trv->b.h.flags)
&& !lfs3_t_ismtreeonly(trv->b.h.flags)
&& !lfs3_t_isdirty(trv->b.h.flags)
&& !lfs3_t_ismutated(trv->b.h.flags)) {
&& !lfs3_t_isckpointed(trv->b.h.flags)) {
lfs3_alloc_markfree(lfs3, lfs3->lookahead.ckpoint);
}
#endif
// was gbmap rebuild successful?
#ifdef LFS3_GBMAP
if (lfs3_t_isrebuildgbmap(trv->b.h.flags)
&& !lfs3_t_ismtreeonly(trv->b.h.flags)
&& lfs3_f_isgbmap(lfs3->flags)
&& !lfs3_t_isckpointed(trv->b.h.flags)) {
lfs3_alloc_adoptgbmap(lfs3, &trv->gbmap_, lfs3->lookahead.ckpoint);
}
#endif
// was mkconsistent successful?
if (lfs3_t_ismkconsistent(trv->b.h.flags)
&& !lfs3_t_isdirty(trv->b.h.flags)) {
@ -10981,6 +11074,36 @@ static int lfs3_gbmap_setbptr(lfs3_t *lfs3, lfs3_btree_t *gbmap,
}
#endif
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
// not this is not completely atomic, but worst case we just end up with
// only some ranges remapped
static int lfs3_gbmap_remap(lfs3_t *lfs3, lfs3_btree_t *gbmap,
lfs3_tag_t tag, lfs3_tag_t tag_) {
lfs3_block_t block__ = -1;
while (true) {
lfs3_block_t weight__;
lfs3_stag_t tag__ = lfs3_gbmap_lookupnext(lfs3, gbmap, block__+1,
&block__, &weight__);
if (tag__ < 0) {
if (tag__ == LFS3_ERR_NOENT) {
break;
}
return tag__;
}
if (tag__ == tag) {
int err = lfs3_gbmap_set_(lfs3, gbmap, block__, weight__,
tag_);
if (err) {
return err;
}
}
}
return 0;
}
#endif
/// Block allocator ///
@ -10988,7 +11111,16 @@ static int lfs3_gbmap_setbptr(lfs3_t *lfs3, lfs3_btree_t *gbmap,
// checkpoint only the lookahead buffer
#ifndef LFS3_RDONLY
static inline void lfs3_alloc_ckpoint_(lfs3_t *lfs3) {
// set ckpoint = disk size
lfs3->lookahead.ckpoint = lfs3->block_count;
// mark all traversals as ckpointed
// TODO should this be a function? non-clobbering?
for (lfs3_handle_t *h = lfs3->handles; h; h = h->next) {
if (lfs3_o_type(h->flags) == LFS3_type_TRV) {
h->flags |= LFS3_t_CKPOINTED;
}
}
}
#endif
@ -11137,10 +11269,7 @@ static void lfs3_alloc_markfree(lfs3_t *lfs3, lfs3_block_t known) {
8*lfs3->cfg->lookahead_size,
known);
// TODO how does this interact with the gbmap?
//
// signal that lookahead is full, this may be cleared by
// lfs3_alloc_findfree
// signal that lookahead is full, this is cleared on first alloc
lfs3->flags &= ~LFS3_I_LOOKAHEAD;
// eagerly find the next free block so lookahead scans can make
@ -11180,6 +11309,9 @@ static void lfs3_alloc_inc(lfs3_t *lfs3) {
if (lfs3_f_isgbmap(lfs3->flags)) {
lfs3->gbmap.window = (lfs3->gbmap.window + 1) % lfs3->block_count;
lfs3->gbmap.known = lfs3_smax(lfs3->gbmap.known-1, 0);
// signal that the gbmap is no longer full
lfs3->flags |= LFS3_I_REBUILDGBMAP;
}
#endif
}
@ -11319,6 +11451,18 @@ static lfs3_sblock_t lfs3_alloc(lfs3_t *lfs3, uint32_t flags) {
}
#endif
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
static void lfs3_alloc_adoptgbmap(lfs3_t *lfs3,
const lfs3_btree_t *gbmap, lfs3_block_t known) {
// adopt new gbmap
lfs3->gbmap.known = known;
lfs3->gbmap.b = *gbmap;
// signal that gbmap is full, this is cleared on first alloc
lfs3->flags &= ~LFS3_I_REBUILDGBMAP;
}
#endif
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
static int lfs3_alloc_rebuildgbmap(lfs3_t *lfs3) {
LFS3_INFO("Rebuilding gbmap "
@ -11334,33 +11478,17 @@ static int lfs3_alloc_rebuildgbmap(lfs3_t *lfs3) {
// we do this instead of creating a new gbmap to (1) preserve any
// erased/bad info and (2) try to best use any available
// erased-state
lfs3_block_t block = -1;
int err;
while (true) {
lfs3_block_t weight;
lfs3_stag_t tag = lfs3_gbmap_lookupnext(lfs3, &gbmap_, block+1,
&block, &weight);
if (tag < 0) {
if (tag == LFS3_ERR_NOENT) {
break;
}
err = tag;
goto failed;
}
if (tag == LFS3_TAG_BMINUSE) {
err = lfs3_gbmap_set_(lfs3, &gbmap_, block, weight,
LFS3_TAG_BMFREE);
if (err) {
goto failed;
}
}
int err = lfs3_gbmap_remap(lfs3, &gbmap_,
LFS3_TAG_BMINUSE,
LFS3_TAG_BMFREE);
if (err) {
goto failed;
}
// traverse the filesystem, building up knowledge of what blocks are
// in-use
lfs3_trv_t trv;
lfs3_trv_init(&trv, LFS3_T_RDONLY | LFS3_T_LOOKAHEAD);
lfs3_trv_init(&trv, LFS3_T_RDONLY);
while (true) {
lfs3_bptr_t bptr;
lfs3_stag_t tag = lfs3_mtree_traverse(lfs3, &trv,
@ -11388,8 +11516,7 @@ static int lfs3_alloc_rebuildgbmap(lfs3_t *lfs3) {
// this avoids extra writing at a risk of needing to rebuild the
// gbmap if we lose power
//
lfs3->gbmap.known = lfs3->lookahead.ckpoint;
lfs3->gbmap.b = gbmap_;
lfs3_alloc_adoptgbmap(lfs3, &gbmap_, lfs3->lookahead.ckpoint);
return 0;
failed:;
@ -15321,6 +15448,7 @@ static int lfs3_init(lfs3_t *lfs3, uint32_t flags,
LFS3_ASSERT((lfs3->cfg->gc_flags & ~(
LFS3_GC_MKCONSISTENT
| LFS3_GC_LOOKAHEAD
| LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, 0)
| LFS3_GC_COMPACT
| LFS3_GC_CKMETA
| LFS3_GC_CKDATA)) == 0);
@ -15342,6 +15470,7 @@ static int lfs3_init(lfs3_t *lfs3, uint32_t flags,
LFS3_ASSERT(lfs3->cfg->fragment_size <= lfs3->cfg->block_size/4);
#endif
// TODO move this to mount?
// setup flags
lfs3->flags = flags
// assume we contain orphans until proven otherwise
@ -16155,6 +16284,15 @@ static int lfs3_mountinited(lfs3_t *lfs3) {
// if we have a gbmap, position our lookahead buffer at the last
// known gbmap window
lfs3->lookahead.window = lfs3->gbmap.window;
// and mark our gbmap as rebuildable if known window does not
// include the entire disk
//
// unfortunately the use of block allocation during gbmap
// rebuilds means this almost never happens
if (lfs3->gbmap.known < lfs3->block_count) {
lfs3->flags |= LFS3_I_REBUILDGBMAP;
}
#endif
} else {
@ -16210,6 +16348,9 @@ int lfs3_mount(lfs3_t *lfs3, uint32_t flags,
#ifdef LFS3_YES_LOOKAHEAD
flags |= LFS3_M_LOOKAHEAD;
#endif
#ifdef LFS3_YES_REBUILDGBMAP
flags |= LFS3_YES_REBUILDGBMAP;
#endif
#ifdef LFS3_YES_COMPACT
flags |= LFS3_M_COMPACT;
#endif
@ -16234,12 +16375,15 @@ int lfs3_mount(lfs3_t *lfs3, uint32_t flags,
| LFS3_IFDEF_CKDATACKSUMS(LFS3_M_CKDATACKSUMS, 0)
| LFS3_IFDEF_RDONLY(0, LFS3_M_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_M_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_M_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_M_COMPACT)
| LFS3_M_CKMETA
| LFS3_M_CKDATA)) == 0);
// these flags require a writable filesystem
LFS3_ASSERT(!lfs3_m_isrdonly(flags) || !lfs3_t_ismkconsistent(flags));
LFS3_ASSERT(!lfs3_m_isrdonly(flags) || !lfs3_t_islookahead(flags));
LFS3_ASSERT(!lfs3_m_isrdonly(flags) || !lfs3_t_isrebuildgbmap(flags));
LFS3_ASSERT(!lfs3_m_isrdonly(flags) || !lfs3_t_iscompact(flags));
int err = lfs3_init(lfs3,
@ -16268,6 +16412,8 @@ int lfs3_mount(lfs3_t *lfs3, uint32_t flags,
if (flags & (
LFS3_IFDEF_RDONLY(0, LFS3_M_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_M_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_M_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_M_COMPACT)
| LFS3_M_CKMETA
| LFS3_M_CKDATA)) {
@ -16276,6 +16422,8 @@ int lfs3_mount(lfs3_t *lfs3, uint32_t flags,
flags & (
LFS3_IFDEF_RDONLY(0, LFS3_M_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_M_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_M_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_M_COMPACT)
| LFS3_M_CKMETA
| LFS3_M_CKDATA),
@ -16618,6 +16766,8 @@ int lfs3_fs_stat(lfs3_t *lfs3, struct lfs3_fsinfo *fsinfo) {
| LFS3_IFDEF_CKDATACKSUMS(LFS3_I_CKDATACKSUMS, 0)
| LFS3_IFDEF_RDONLY(0, LFS3_I_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_I_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_I_COMPACT)
| LFS3_I_CKMETA
| LFS3_I_CKDATA
@ -16885,15 +17035,19 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_trv_t *trv,
LFS3_ASSERT((flags & ~(
LFS3_IFDEF_RDONLY(0, LFS3_T_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_T_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_T_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_T_COMPACT)
| LFS3_T_CKMETA
| LFS3_T_CKDATA)) == 0);
// these flags require a writable filesystem
LFS3_ASSERT(!lfs3_m_isrdonly(lfs3->flags) || !lfs3_t_ismkconsistent(flags));
LFS3_ASSERT(!lfs3_m_isrdonly(lfs3->flags) || !lfs3_t_islookahead(flags));
LFS3_ASSERT(!lfs3_m_isrdonly(lfs3->flags) || !lfs3_t_isrebuildgbmap(flags));
LFS3_ASSERT(!lfs3_m_isrdonly(lfs3->flags) || !lfs3_t_iscompact(flags));
// some flags don't make sense when only traversing the mtree
LFS3_ASSERT(!lfs3_t_ismtreeonly(flags) || !lfs3_t_islookahead(flags));
LFS3_ASSERT(!lfs3_t_ismtreeonly(flags) || !lfs3_t_isrebuildgbmap(flags));
LFS3_ASSERT(!lfs3_t_ismtreeonly(flags) || !lfs3_t_isckdata(flags));
// fix pending grms if requested
@ -16912,36 +17066,26 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_trv_t *trv,
(lfs3->flags & (
LFS3_IFDEF_RDONLY(0, LFS3_I_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_I_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_I_COMPACT)
| LFS3_I_CKMETA
| LFS3_I_CKDATA)));
while (pending && (lfs3_off_t)steps > 0) {
// checkpoint the allocator to maximize any lookahead scans
//
// TODO how does the gbmap interact with LFS3_T_LOOKAHEAD? Should
// we populate it? use a different flag?
//
#ifndef LFS3_RDONLY
if (lfs3_t_islookahead(trv->b.h.flags)) {
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
}
#endif
// start a new traversal?
if (!lfs3_handle_isopen(lfs3, &trv->b.h)) {
lfs3_trv_init(trv, pending);
lfs3_handle_open(lfs3, &trv->b.h);
}
// don't bother with lookahead if we've mutated
// don't bother with lookahead/gbmap if we've ckpointed
#ifndef LFS3_RDONLY
if (lfs3_t_isdirty(trv->b.h.flags)
|| lfs3_t_ismutated(trv->b.h.flags)) {
if (lfs3_t_isckpointed(trv->b.h.flags)) {
trv->b.h.flags &= ~LFS3_T_LOOKAHEAD;
#ifdef LFS3_GBMAP
trv->b.h.flags &= ~LFS3_T_REBUILDGBMAP;
#endif
}
#endif
@ -16949,6 +17093,8 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_trv_t *trv,
if (!(trv->b.h.flags & (
LFS3_IFDEF_RDONLY(0, LFS3_T_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_T_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_T_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_T_COMPACT)
| LFS3_T_CKMETA
| LFS3_T_CKDATA))) {
@ -16959,6 +17105,8 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_trv_t *trv,
// do we really need a full traversal?
if (!(trv->b.h.flags & (
LFS3_IFDEF_RDONLY(0, LFS3_T_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_T_REBUILDGBMAP, 0))
| LFS3_T_CKMETA
| LFS3_T_CKDATA))) {
trv->b.h.flags |= LFS3_T_MTREEONLY;
@ -16980,6 +17128,8 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_trv_t *trv,
pending &= lfs3->flags & (
LFS3_IFDEF_RDONLY(0, LFS3_I_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_I_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_I_COMPACT)
| LFS3_I_CKMETA
| LFS3_I_CKDATA);
@ -17013,6 +17163,8 @@ int lfs3_fs_unck(lfs3_t *lfs3, uint32_t flags) {
LFS3_ASSERT((flags & ~(
LFS3_IFDEF_RDONLY(0, LFS3_I_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_I_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_I_COMPACT)
| LFS3_I_CKMETA
| LFS3_I_CKDATA)) == 0);
@ -17243,6 +17395,8 @@ int lfs3_trv_open(lfs3_t *lfs3, lfs3_trv_t *trv, uint32_t flags) {
| LFS3_T_MTREEONLY
| LFS3_IFDEF_RDONLY(0, LFS3_T_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_T_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0,
LFS3_IFDEF_GBMAP(LFS3_T_REBUILDGBMAP, 0))
| LFS3_IFDEF_RDONLY(0, LFS3_T_COMPACT)
| LFS3_T_CKMETA
| LFS3_T_CKDATA)) == 0);
@ -17251,9 +17405,11 @@ int lfs3_trv_open(lfs3_t *lfs3, lfs3_trv_t *trv, uint32_t flags) {
// these flags require a writable traversal
LFS3_ASSERT(!lfs3_t_isrdonly(flags) || !lfs3_t_ismkconsistent(flags));
LFS3_ASSERT(!lfs3_t_isrdonly(flags) || !lfs3_t_islookahead(flags));
LFS3_ASSERT(!lfs3_t_isrdonly(flags) || !lfs3_t_isrebuildgbmap(flags));
LFS3_ASSERT(!lfs3_t_isrdonly(flags) || !lfs3_t_iscompact(flags));
// some flags don't make sense when only traversing the mtree
LFS3_ASSERT(!lfs3_t_ismtreeonly(flags) || !lfs3_t_islookahead(flags));
LFS3_ASSERT(!lfs3_t_ismtreeonly(flags) || !lfs3_t_isrebuildgbmap(flags));
LFS3_ASSERT(!lfs3_t_ismtreeonly(flags) || !lfs3_t_isckdata(flags));
// setup traversal state
@ -17300,20 +17456,6 @@ int lfs3_trv_read(lfs3_t *lfs3, lfs3_trv_t *trv,
}
#endif
// checkpoint the allocator to maximize any lookahead scans
//
// TODO how does the gbmap interact with LFS3_T_LOOKAHEAD? Should
// we populate it? use a different flag?
//
#ifndef LFS3_RDONLY
if (lfs3_t_islookahead(trv->b.h.flags)) {
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
}
#endif
while (true) {
// some redund blocks left over?
if (trv->blocks[0] != -1) {
@ -17409,6 +17551,7 @@ static int lfs3_trv_rewind_(lfs3_t *lfs3, lfs3_trv_t *trv) {
// reset traversal
lfs3_trv_init(trv,
trv->b.h.flags
& ~LFS3_t_CKPOINTED
& ~LFS3_t_DIRTY
& ~LFS3_t_MUTATED
& ~LFS3_t_TSTATE);

22
lfs3.h
View File

@ -236,6 +236,10 @@ enum lfs3_type {
#define LFS3_M_LOOKAHEAD \
0x00000200 // Populate lookahead buffer
#endif
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
#define LFS3_M_REBUILDGBMAP \
0x00000400 // Rebuild the gbmap
#endif
#ifndef LFS3_RDONLY
#define LFS3_M_COMPACT 0x00000800 // Compact metadata logs
#endif
@ -277,6 +281,10 @@ enum lfs3_type {
#define LFS3_I_LOOKAHEAD \
0x00000200 // Lookahead buffer is not full
#endif
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
#define LFS3_I_REBUILDGBMAP \
0x00000400 // The gbmap is not full
#endif
#ifndef LFS3_RDONLY
#define LFS3_I_COMPACT 0x00000800 // Filesystem may have uncompacted metadata
#endif
@ -318,6 +326,10 @@ enum lfs3_btype {
#define LFS3_T_LOOKAHEAD \
0x00000200 // Populate lookahead buffer
#endif
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
#define LFS3_T_REBUILDGBMAP \
0x00000400 // Rebuild the gbmap
#endif
#ifndef LFS3_RDONLY
#define LFS3_T_COMPACT 0x00000800 // Compact metadata logs
#endif
@ -329,6 +341,8 @@ enum lfs3_btype {
#define LFS3_t_TSTATE 0x000f0000 // The current traversal state
#define LFS3_t_BTYPE 0x00f00000 // The current block type
#define LFS3_t_ZOMBIE 0x08000000 // File has been removed
#define LFS3_t_CKPOINTED \
0x04000000 // Filesystem ckpointed during traversal
#define LFS3_t_DIRTY 0x02000000 // Filesystem modified during traversal
#define LFS3_t_MUTATED 0x01000000 // Filesystem modified by traversal
@ -341,6 +355,10 @@ enum lfs3_btype {
#define LFS3_GC_LOOKAHEAD \
0x00000200 // Populate lookahead buffer
#endif
#if !defined(LFS3_RDONLY) && defined(LFS3_GBMAP)
#define LFS3_GC_REBUILDGBMAP \
0x00000400 // Rebuild the gbmap
#endif
#ifndef LFS3_RDONLY
#define LFS3_GC_COMPACT 0x00000800 // Compact metadata logs
#endif
@ -810,6 +828,10 @@ typedef struct lfs3_trv {
// bshrub/btree traversal state
lfs3_sbid_t bid;
// rebuild gbmap when traversing with rebuildgbmap
#ifdef LFS3_GBMAP
lfs3_btree_t gbmap_;
#endif
// recalculate gcksum when traversing with ckmeta
uint32_t gcksum;
// pending blocks, only used in lfs3_trv_read

View File

@ -90,6 +90,7 @@ FLAGS = [
('M_MKCONSISTENT', 0x00000100, "Make the filesystem consistent" ),
('M_LOOKAHEAD', 0x00000200, "Populate lookahead buffer" ),
('M_REBUILDGBMAP', 0x00000400, "Rebuild the gbmap" ),
('M_COMPACT', 0x00000800, "Compact metadata logs" ),
('M_CKMETA', 0x00001000, "Check metadata checksums" ),
('M_CKDATA', 0x00002000, "Check metadata + data checksums" ),
@ -97,6 +98,7 @@ FLAGS = [
# GC flags
('GC_MKCONSISTENT',0x00000100, "Make the filesystem consistent" ),
('GC_LOOKAHEAD', 0x00000200, "Populate lookahead buffer" ),
('GC_REBUILDGBMAP',0x00000400, "Rebuild the gbmap" ),
('GC_COMPACT', 0x00000800, "Compact metadata logs" ),
('GC_CKMETA', 0x00001000, "Check metadata checksums" ),
('GC_CKDATA', 0x00002000, "Check metadata + data checksums" ),
@ -114,6 +116,7 @@ FLAGS = [
('I_MKCONSISTENT', 0x00000100, "Filesystem needs mkconsistent to write" ),
('I_LOOKAHEAD', 0x00000200, "Lookahead buffer is not full" ),
('I_REBUILDGBMAP', 0x00000400, "The gbmap is not full" ),
('I_COMPACT', 0x00000800, "Filesystem may have uncompacted metadata" ),
('I_CKMETA', 0x00001000, "Metadata checksums not checked recently" ),
('I_CKDATA', 0x00002000, "Data checksums not checked recently" ),
@ -132,6 +135,7 @@ FLAGS = [
('T_MKCONSISTENT',
0x00000100, "Make the filesystem consistent" ),
('T_LOOKAHEAD', 0x00000200, "Populate lookahead buffer" ),
('T_REBUILDGBMAP', 0x00000400, "Rebuild the gbmap" ),
('T_COMPACT', 0x00000800, "Compact metadata logs" ),
('T_CKMETA', 0x00001000, "Check metadata checksums" ),
('T_CKDATA', 0x00002000, "Check metadata + data checksums" ),
@ -149,18 +153,20 @@ FLAGS = [
0x00000000, "Tstate = mroot-anchor" ),
('^_MROOTCHAIN', 0x00010000, "Tstate = mroot-chain" ),
('^_MTREE', 0x00020000, "Tstate = mtree" ),
('^_BMAP', 0x00030000, "Tstate = bmap" ),
('^_MDIRS', 0x00040000, "Tstate = mtree-mdirs" ),
('^_MDIR', 0x00050000, "Tstate = mdir" ),
('^_BTREE', 0x00060000, "Tstate = btree" ),
('^_HANDLES', 0x00070000, "Tstate = open-mdirs" ),
('^_HBTREE', 0x00080000, "Tstate = open-btree" ),
('^_DONE', 0x00090000, "Tstate = done" ),
('^_MDIRS', 0x00030000, "Tstate = mtree-mdirs" ),
('^_MDIR', 0x00040000, "Tstate = mdir" ),
('^_BTREE', 0x00050000, "Tstate = btree" ),
('^_HANDLES', 0x00060000, "Tstate = open-mdirs" ),
('^_HBTREE', 0x00070000, "Tstate = open-btree" ),
('^_GBMAP', 0x00080000, "Tstate = gbmap" ),
('^_GBMAP_P', 0x00090000, "Tstate = gbmap_p" ),
('^_DONE', 0x000a0000, "Tstate = done" ),
('t_BTYPE', 0x00f00000, "The current block type" ),
('^_MDIR', 0x00100000, "Btype = mdir" ),
('^_BTREE', 0x00200000, "Btype = btree" ),
('^_DATA', 0x00300000, "Btype = data" ),
('t_ZOMBIE', 0x08000000, "File has been removed" ),
('t_CKPOINTED', 0x04000000, "Filesystem ckpointed during traversal" ),
('t_DIRTY', 0x02000000, "Filesystem modified during traversal" ),
('t_MUTATED', 0x01000000, "Filesystem modified by traversal" ),

View File

@ -4,6 +4,15 @@
# GC-API specific things here
after = ['test_trvs']
# Test both with and without the gbmap if available
defines.GBMAP = [false, true]
if = '''
LFS3_IFDEF_YES_GBMAP(
GBMAP,
LFS3_IFDEF_GBMAP(true, !GBMAP))
'''
# test that lookahead can make progress in isolation
[cases.test_gc_lookahead_progress]
defines.CKMETA = [false, true]
@ -25,7 +34,10 @@ defines.SIZE = [
ifdef = 'LFS3_GC'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -92,7 +104,10 @@ if = 'CKMETA || CKDATA'
ifdef = 'LFS3_GC'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -147,6 +162,159 @@ code = '''
'''
# test that rebuildgbmap can make progress in isolation
[cases.test_gc_rebuildgbmap_progress]
defines.LOOKAHEAD = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.GC_FLAGS = '''
LFS3_GC_REBUILDGBMAP
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
'''
defines.GC_STEPS = [-1, 1, 2, 10, 100, 1000]
defines.SIZE = [
'BLOCK_SIZE/2',
'BLOCK_SIZE',
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
if = 'GBMAP'
ifdef = ['LFS3_GC', 'LFS3_GBMAP']
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
// create a file
lfs3_file_t file;
lfs3_file_open(&lfs3, &file, "spider",
LFS3_O_WRONLY | LFS3_O_CREAT | LFS3_O_EXCL) => 0;
uint8_t wbuf[SIZE];
for (lfs3_size_t j = 0; j < SIZE; j++) {
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
}
lfs3_file_write(&lfs3, &file, wbuf, SIZE) => SIZE;
lfs3_file_close(&lfs3, &file) => 0;
// expect dirty initial state or else our test doesn't work
struct lfs3_fsinfo fsinfo;
lfs3_fs_stat(&lfs3, &fsinfo) => 0;
assert(fsinfo.flags & LFS3_I_REBUILDGBMAP);
assert(lfs3.handles != &lfs3.gc.trv.b.h);
// run GC until we make progress
for (lfs3_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
LFS3_ASSERT(i < 2*BLOCK_COUNT);
lfs3_fs_gc(&lfs3) => 0;
lfs3_fs_stat(&lfs3, &fsinfo) => 0;
if (!(fsinfo.flags & LFS3_I_REBUILDGBMAP)) {
break;
}
}
// check the file contents
lfs3_file_open(&lfs3, &file, "spider", LFS3_O_RDONLY) => 0;
uint8_t rbuf[SIZE];
lfs3_file_read(&lfs3, &file, rbuf, SIZE) => SIZE;
assert(memcmp(rbuf, wbuf, SIZE) == 0);
lfs3_file_close(&lfs3, &file) => 0;
lfs3_unmount(&lfs3) => 0;
'''
# test that rebuildgbmap dirtying still works with the GC API
[cases.test_gc_rebuildgbmap_mutation]
defines.LOOKAHEAD = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.GC_FLAGS = '''
LFS3_GC_REBUILDGBMAP
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
'''
defines.SIZE = [
'BLOCK_SIZE/2',
'BLOCK_SIZE',
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
if = [
# we need something to keep the traversal running
'CKMETA || CKDATA',
'GBMAP',
]
ifdef = ['LFS3_GC', 'LFS3_GBMAP']
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
// create a file
lfs3_file_t file;
lfs3_file_open(&lfs3, &file, "spider",
LFS3_O_WRONLY | LFS3_O_CREAT | LFS3_O_EXCL) => 0;
uint8_t wbuf[SIZE];
for (lfs3_size_t j = 0; j < SIZE; j++) {
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
}
lfs3_file_write(&lfs3, &file, wbuf, SIZE) => SIZE;
lfs3_file_close(&lfs3, &file) => 0;
// expect dirty initial state or else our test doesn't work
struct lfs3_fsinfo fsinfo;
lfs3_fs_stat(&lfs3, &fsinfo) => 0;
assert(fsinfo.flags & LFS3_I_REBUILDGBMAP);
assert(lfs3.handles != &lfs3.gc.trv.b.h);
// run GC one step
lfs3_fs_gc(&lfs3) => 0;
assert(lfs3.handles == &lfs3.gc.trv.b.h);
// mutate the filesystem
lfs3_file_open(&lfs3, &file, "spider",
LFS3_O_WRONLY | LFS3_O_TRUNC) => 0;
for (lfs3_size_t j = 0; j < SIZE; j++) {
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
}
lfs3_file_write(&lfs3, &file, wbuf, SIZE) => SIZE;
lfs3_file_close(&lfs3, &file) => 0;
// run GC until our traversal is done
while (lfs3.handles == &lfs3.gc.trv.b.h) {
lfs3_fs_gc(&lfs3) => 0;
}
// we should _not_ make progress
lfs3_fs_stat(&lfs3, &fsinfo) => 0;
assert(fsinfo.flags & LFS3_I_REBUILDGBMAP);
// check the file contents
lfs3_file_open(&lfs3, &file, "spider", LFS3_O_RDONLY) => 0;
uint8_t rbuf[SIZE];
lfs3_file_read(&lfs3, &file, rbuf, SIZE) => SIZE;
assert(memcmp(rbuf, wbuf, SIZE) == 0);
lfs3_file_close(&lfs3, &file) => 0;
lfs3_unmount(&lfs3) => 0;
'''
# test that compact can make progress in isolation
[cases.test_gc_compact_progress]
defines.LOOKAHEAD = [false, true]
@ -172,7 +340,10 @@ defines.SIZE = [
ifdef = 'LFS3_GC'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -261,7 +432,10 @@ if = 'CKMETA || CKDATA'
ifdef = 'LFS3_GC'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -359,7 +533,10 @@ defines.ORPHANS = [1, 2, 3, 100]
ifdef = 'LFS3_GC'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -461,7 +638,10 @@ defines.SIZE = 'FILE_CACHE_SIZE/2'
defines.ORPHANS = [1, 2, 3, 100]
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -572,7 +752,10 @@ if = 'CKMETA || CKDATA'
ifdef = 'LFS3_GC'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -699,7 +882,10 @@ code = '''
assert(i < 2*BLOCK_COUNT);
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create an interesting filesystem
@ -799,7 +985,10 @@ code = '''
assert(i < 2*BLOCK_COUNT);
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create an interesting filesystem
@ -901,7 +1090,10 @@ code = '''
assert(i < 2*BLOCK_COUNT);
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create an interesting filesystem
@ -988,7 +1180,10 @@ code = '''
assert(i < 2*BLOCK_COUNT);
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create an interesting filesystem
@ -1087,7 +1282,10 @@ code = '''
assert(i < 2*BLOCK_COUNT);
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create an interesting filesystem
@ -1250,7 +1448,10 @@ code = '''
assert(i < 2*BLOCK_COUNT);
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create an interesting filesystem
@ -1398,12 +1599,14 @@ done:;
defines.AFTER = [0, 1, 2, 3]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -1422,10 +1625,14 @@ defines.SIZE = [
if = [
'(SIZE*N)/BLOCK_SIZE <= 32',
'LFS3_IFDEF_GC(true, AFTER != 0)',
'GBMAP || !REBUILDGBMAP',
]
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create an interesting filesystem
@ -1456,10 +1663,14 @@ code = '''
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| LFS3_I_LOOKAHEAD
| ((GBMAP)
? (LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
& fsinfo.flags)
: 0)
| LFS3_I_COMPACT
| LFS3_I_CKMETA
| LFS3_I_CKDATA
| LFS3_IFDEF_YES_GBMAP(LFS3_I_GBMAP, 0)));
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, -1) : 0)));
// run gc
if (AFTER == 0) {
@ -1477,6 +1688,9 @@ code = '''
if (!(fsinfo.flags & (
((MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((REBUILDGBMAP)
? LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
: 0)
| ((COMPACT) ? LFS3_I_COMPACT : 0)
| ((CKMETA) ? LFS3_I_CKMETA : 0)
| ((CKDATA) ? LFS3_I_CKDATA : 0)))) {
@ -1506,17 +1720,20 @@ code = '''
if (!(fsinfo.flags & (
((MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((REBUILDGBMAP)
? LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
: 0)
| ((COMPACT) ? LFS3_I_COMPACT : 0)
| ((CKMETA) ? LFS3_I_CKMETA : 0)
| ((CKDATA) ? LFS3_I_CKDATA : 0)))) {
break;
}
if (MKCONSISTENT) {
if (MKCONSISTENT && (fsinfo.flags & LFS3_I_MKCONSISTENT)) {
lfs3_fs_mkconsistent(&lfs3) => 0;
}
if (LOOKAHEAD) {
if (LOOKAHEAD && (fsinfo.flags & LFS3_I_LOOKAHEAD)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
@ -1532,7 +1749,25 @@ code = '''
lfs3_trv_close(&lfs3, &trv) => 0;
}
if (COMPACT) {
#ifdef LFS3_GBMAP
if (REBUILDGBMAP && (fsinfo.flags & LFS3_I_REBUILDGBMAP)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
LFS3_T_RDWR | LFS3_T_REBUILDGBMAP) => 0;
while (true) {
struct lfs3_tinfo tinfo;
int err = lfs3_trv_read(&lfs3, &trv, &tinfo);
assert(err == 0 || err == LFS3_ERR_NOENT);
if (err == LFS3_ERR_NOENT) {
break;
}
}
lfs3_trv_close(&lfs3, &trv) => 0;
}
#endif
if (COMPACT && (fsinfo.flags & LFS3_I_COMPACT)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
@ -1548,11 +1783,11 @@ code = '''
lfs3_trv_close(&lfs3, &trv) => 0;
}
if (CKMETA) {
if (CKMETA && (fsinfo.flags & LFS3_I_CKMETA)) {
lfs3_fs_ckmeta(&lfs3) => 0;
}
if (CKDATA) {
if (CKDATA && (fsinfo.flags & LFS3_I_CKDATA)) {
lfs3_fs_ckdata(&lfs3) => 0;
}
}
@ -1571,11 +1806,17 @@ code = '''
assert(fsinfo.flags == (
((!MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((!LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((!REBUILDGBMAP)
? ((GBMAP)
? (LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
& fsinfo.flags)
: 0)
: 0)
| ((!COMPACT) ? LFS3_I_COMPACT : 0)
// note ckdata implies ckmeta
| ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0)
| ((!CKDATA) ? LFS3_I_CKDATA : 0)
| LFS3_IFDEF_YES_GBMAP(LFS3_I_GBMAP, 0)));
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, -1) : 0)));
lfs3_unmount(&lfs3) => 0;
'''
@ -1589,12 +1830,14 @@ code = '''
defines.AFTER = [0, 1, 2, 3]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -1613,10 +1856,14 @@ defines.SIZE = [
if = [
'(SIZE*N)/BLOCK_SIZE <= 32',
'LFS3_IFDEF_GC(true, AFTER != 0)',
'GBMAP || !REBUILDGBMAP',
]
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create an interesting filesystem
@ -1647,10 +1894,14 @@ code = '''
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| LFS3_I_LOOKAHEAD
| ((GBMAP)
? (LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
& fsinfo.flags)
: 0)
| LFS3_I_COMPACT
| LFS3_I_CKMETA
| LFS3_I_CKDATA
| LFS3_IFDEF_YES_GBMAP(LFS3_I_GBMAP, 0)));
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, -1) : 0)));
// run gc
if (AFTER == 0) {
@ -1668,6 +1919,9 @@ code = '''
if (!(fsinfo.flags & (
((MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((REBUILDGBMAP)
? LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
: 0)
| ((COMPACT) ? LFS3_I_COMPACT : 0)
| ((CKMETA) ? LFS3_I_CKMETA : 0)
| ((CKDATA) ? LFS3_I_CKDATA : 0)))) {
@ -1697,17 +1951,20 @@ code = '''
if (!(fsinfo.flags & (
((MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((REBUILDGBMAP)
? LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
: 0)
| ((COMPACT) ? LFS3_I_COMPACT : 0)
| ((CKMETA) ? LFS3_I_CKMETA : 0)
| ((CKDATA) ? LFS3_I_CKDATA : 0)))) {
break;
}
if (MKCONSISTENT) {
if (MKCONSISTENT && (fsinfo.flags & LFS3_I_MKCONSISTENT)) {
lfs3_fs_mkconsistent(&lfs3) => 0;
}
if (LOOKAHEAD) {
if (LOOKAHEAD && (fsinfo.flags & LFS3_I_LOOKAHEAD)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
@ -1723,7 +1980,25 @@ code = '''
lfs3_trv_close(&lfs3, &trv) => 0;
}
if (COMPACT) {
#ifdef LFS3_GBMAP
if (REBUILDGBMAP && (fsinfo.flags & LFS3_I_REBUILDGBMAP)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
LFS3_T_RDWR | LFS3_T_REBUILDGBMAP) => 0;
while (true) {
struct lfs3_tinfo tinfo;
int err = lfs3_trv_read(&lfs3, &trv, &tinfo);
assert(err == 0 || err == LFS3_ERR_NOENT);
if (err == LFS3_ERR_NOENT) {
break;
}
}
lfs3_trv_close(&lfs3, &trv) => 0;
}
#endif
if (COMPACT && (fsinfo.flags & LFS3_I_COMPACT)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
@ -1739,11 +2014,11 @@ code = '''
lfs3_trv_close(&lfs3, &trv) => 0;
}
if (CKMETA) {
if (CKMETA && (fsinfo.flags & LFS3_I_CKMETA)) {
lfs3_fs_ckmeta(&lfs3) => 0;
}
if (CKDATA) {
if (CKDATA && (fsinfo.flags & LFS3_I_CKDATA)) {
lfs3_fs_ckdata(&lfs3) => 0;
}
}
@ -1762,11 +2037,17 @@ code = '''
assert(fsinfo.flags == (
((!MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((!LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((!REBUILDGBMAP)
? ((GBMAP)
? (LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
& fsinfo.flags)
: 0)
: 0)
| ((!COMPACT) ? LFS3_I_COMPACT : 0)
// note ckdata implies ckmeta
| ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0)
| ((!CKDATA) ? LFS3_I_CKDATA : 0)
| LFS3_IFDEF_YES_GBMAP(LFS3_I_GBMAP, 0)));
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, -1) : 0)));
// test that we can reset flags with lfs3_fs_unck
lfs3_fs_unck(&lfs3, GC_FLAGS) => 0;
@ -1776,12 +2057,18 @@ code = '''
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| LFS3_I_LOOKAHEAD
| ((REBUILDGBMAP)
? LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1U)
: (GBMAP)
? (LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
& fsinfo.flags)
: 0)
| LFS3_I_COMPACT
// note ckdata implies ckmeta, but uncking ckdata does
// _not_ imply uncking ckmeta
| ((!(CKDATA && !CKMETA)) ? LFS3_I_CKMETA : 0)
| LFS3_I_CKDATA
| LFS3_IFDEF_YES_GBMAP(LFS3_I_GBMAP, 0)));
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, -1) : 0)));
// run gc
if (AFTER == 0) {
@ -1799,6 +2086,9 @@ code = '''
if (!(fsinfo.flags & (
((MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((REBUILDGBMAP)
? LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
: 0)
| ((COMPACT) ? LFS3_I_COMPACT : 0)
| ((CKMETA) ? LFS3_I_CKMETA : 0)
| ((CKDATA) ? LFS3_I_CKDATA : 0)))) {
@ -1828,17 +2118,20 @@ code = '''
if (!(fsinfo.flags & (
((MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((REBUILDGBMAP)
? LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
: 0)
| ((COMPACT) ? LFS3_I_COMPACT : 0)
| ((CKMETA) ? LFS3_I_CKMETA : 0)
| ((CKDATA) ? LFS3_I_CKDATA : 0)))) {
break;
}
if (MKCONSISTENT) {
if (MKCONSISTENT && (fsinfo.flags & LFS3_I_MKCONSISTENT)) {
lfs3_fs_mkconsistent(&lfs3) => 0;
}
if (LOOKAHEAD) {
if (LOOKAHEAD && (fsinfo.flags & LFS3_I_LOOKAHEAD)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
@ -1854,7 +2147,25 @@ code = '''
lfs3_trv_close(&lfs3, &trv) => 0;
}
if (COMPACT) {
#ifdef LFS3_GBMAP
if (REBUILDGBMAP && (fsinfo.flags & LFS3_I_REBUILDGBMAP)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
LFS3_T_RDWR | LFS3_T_REBUILDGBMAP) => 0;
while (true) {
struct lfs3_tinfo tinfo;
int err = lfs3_trv_read(&lfs3, &trv, &tinfo);
assert(err == 0 || err == LFS3_ERR_NOENT);
if (err == LFS3_ERR_NOENT) {
break;
}
}
lfs3_trv_close(&lfs3, &trv) => 0;
}
#endif
if (COMPACT && (fsinfo.flags & LFS3_I_COMPACT)) {
// we need an explicit traversal for this
lfs3_trv_t trv;
lfs3_trv_open(&lfs3, &trv,
@ -1870,11 +2181,11 @@ code = '''
lfs3_trv_close(&lfs3, &trv) => 0;
}
if (CKMETA) {
if (CKMETA && (fsinfo.flags & LFS3_I_CKMETA)) {
lfs3_fs_ckmeta(&lfs3) => 0;
}
if (CKDATA) {
if (CKDATA && (fsinfo.flags & LFS3_I_CKDATA)) {
lfs3_fs_ckdata(&lfs3) => 0;
}
}
@ -1893,11 +2204,17 @@ code = '''
assert(fsinfo.flags == (
((!MKCONSISTENT) ? LFS3_I_MKCONSISTENT : 0)
| ((!LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| ((!REBUILDGBMAP)
? ((GBMAP)
? (LFS3_IFDEF_GBMAP(LFS3_I_REBUILDGBMAP, -1)
& fsinfo.flags)
: 0)
: 0)
| ((!COMPACT) ? LFS3_I_COMPACT : 0)
// note ckdata implies ckmeta
| ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0)
| ((!CKDATA) ? LFS3_I_CKDATA : 0)
| LFS3_IFDEF_YES_GBMAP(LFS3_I_GBMAP, 0)));
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, -1) : 0)));
lfs3_unmount(&lfs3) => 0;
'''
@ -1908,12 +2225,14 @@ code = '''
defines.N = 100
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -1929,10 +2248,14 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
if = 'GBMAP || !REBUILDGBMAP'
ifdef = 'LFS3_GC'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -1977,12 +2300,14 @@ code = '''
defines.N = 100
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -1998,10 +2323,14 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
if = 'GBMAP || !REBUILDGBMAP'
ifdef = 'LFS3_GC'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
uint32_t prng = 42;
@ -2053,6 +2382,7 @@ code = '''
[cases.test_gc_spam_dir_many]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
@ -2060,6 +2390,7 @@ defines.UNCK = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -2068,11 +2399,15 @@ defines.GC_STEPS = [-1, 1, 2, 10, 100, 1000]
# set compact thresh to minimum
defines.GC_COMPACT_THRESH = 'BLOCK_SIZE/2'
defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256]
if = 'GBMAP || !REBUILDGBMAP'
ifdef = 'LFS3_GC'
code = '''
// test creating directories
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// make this many directories
@ -2157,6 +2492,7 @@ code = '''
[cases.test_gc_spam_dir_fuzz]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
@ -2164,6 +2500,7 @@ defines.UNCK = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -2175,11 +2512,15 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256]
defines.OPS = '2*N'
defines.SEED = 42
fuzz = 'SEED'
if = 'GBMAP || !REBUILDGBMAP'
ifdef = 'LFS3_GC'
code = '''
// test fuzz with dirs
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// set up a simulation to compare against
@ -2332,6 +2673,7 @@ code = '''
[cases.test_gc_spam_file_many]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
@ -2339,6 +2681,7 @@ defines.UNCK = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -2356,12 +2699,18 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'4*BLOCK_SIZE',
]
if = '(SIZE*N)/BLOCK_SIZE <= 32'
if = [
'(SIZE*N)/BLOCK_SIZE <= 32',
'GBMAP || !REBUILDGBMAP',
]
ifdef = 'LFS3_GC'
code = '''
// test creating files
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create this many files
@ -2430,6 +2779,7 @@ code = '''
[cases.test_gc_spam_file_fuzz]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
@ -2437,6 +2787,7 @@ defines.UNCK = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -2457,12 +2808,18 @@ defines.SIZE = [
]
defines.SEED = 42
fuzz = 'SEED'
if = '(SIZE*N)/BLOCK_SIZE <= 16'
if = [
'(SIZE*N)/BLOCK_SIZE <= 16',
'GBMAP || !REBUILDGBMAP',
]
ifdef = 'LFS3_GC'
code = '''
// test fuzz with files
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// set up a simulation to compare against
@ -2667,6 +3024,7 @@ code = '''
[cases.test_gc_spam_fwrite_fuzz]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
@ -2674,6 +3032,7 @@ defines.UNCK = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -2703,12 +3062,16 @@ if = [
'CHUNK <= SIZE',
# this just saves testing time
'SIZE <= 4*1024*FRAGMENT_SIZE',
'GBMAP || !REBUILDGBMAP',
]
ifdef = 'LFS3_GC'
code = '''
// test with complex file writes
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// create a file
@ -2824,6 +3187,7 @@ code = '''
[cases.test_gc_spam_uz_fuzz]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
@ -2831,6 +3195,7 @@ defines.UNCK = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -2851,12 +3216,18 @@ defines.SIZE = [
]
defines.SEED = 42
fuzz = 'SEED'
if = '(SIZE*N)/BLOCK_SIZE <= 16'
if = [
'(SIZE*N)/BLOCK_SIZE <= 16',
'GBMAP || !REBUILDGBMAP',
]
ifdef = 'LFS3_GC'
code = '''
// test with uncreats, zombies, etc
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// set up a simulation to compare against
@ -3268,6 +3639,7 @@ code = '''
[cases.test_gc_spam_uzd_fuzz]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
@ -3275,6 +3647,7 @@ defines.UNCK = [false, true]
defines.GC_FLAGS = '''
((MKCONSISTENT) ? LFS3_GC_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_GC_LOOKAHEAD : 0)
| ((REBUILDGBMAP) ? LFS3_IFDEF_GBMAP(LFS3_GC_REBUILDGBMAP, -1) : 0)
| ((COMPACT) ? LFS3_GC_COMPACT : 0)
| ((CKMETA) ? LFS3_GC_CKMETA : 0)
| ((CKDATA) ? LFS3_GC_CKDATA : 0)
@ -3295,12 +3668,18 @@ defines.SIZE = [
]
defines.SEED = 42
fuzz = 'SEED'
if = '(SIZE*N)/BLOCK_SIZE <= 16'
if = [
'(SIZE*N)/BLOCK_SIZE <= 16',
'GBMAP || !REBUILDGBMAP',
]
ifdef = 'LFS3_GC'
code = '''
// test with uncreats, zombies, dirs, etc
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
lfs3_format(&lfs3,
LFS3_F_RDWR
| ((GBMAP) ? LFS3_IFDEF_GBMAP(LFS3_F_GBMAP, -1) : 0),
CFG) => 0;
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
// set up a simulation to compare against

View File

@ -25,6 +25,7 @@ defines.CKMETAPARITY = [false, true]
defines.CKDATACKSUMS = [false, true]
defines.MKCONSISTENT = [false, true]
defines.LOOKAHEAD = [false, true]
defines.REBUILDGBMAP = [false, true]
defines.COMPACT = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
@ -38,6 +39,8 @@ if = [
'LFS3_IFDEF_CKDATACKSUMS(true, !CKDATACKSUMS)',
'!RDONLY || !MKCONSISTENT',
'!RDONLY || !LOOKAHEAD',
'LFS3_IFDEF_YES_GBMAP(true, !REBUILDGBMAP)',
'!RDONLY || !REBUILDGBMAP',
'!RDONLY || !COMPACT',
]
code = '''
@ -59,6 +62,9 @@ code = '''
: 0)
| ((MKCONSISTENT) ? LFS3_M_MKCONSISTENT : 0)
| ((LOOKAHEAD) ? LFS3_M_LOOKAHEAD : 0)
| ((REBUILDGBMAP)
? LFS3_IFDEF_GBMAP(LFS3_M_REBUILDGBMAP, -1)
: 0)
| ((COMPACT) ? LFS3_M_COMPACT : 0)
| ((CKMETA) ? LFS3_M_CKMETA : 0)
| ((CKDATA) ? LFS3_M_CKDATA : 0),
@ -192,6 +198,77 @@ code = '''
lfs3_unmount(&lfs3) => 0;
'''
[cases.test_mount_t_rebuildgbmap]
ifdef = 'LFS3_GBMAP'
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.SIZE = [
'BLOCK_SIZE/2',
'BLOCK_SIZE',
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR | LFS3_F_GBMAP, CFG) => 0;
uint32_t prng = 42;
// gbmap is persistant, so by default we _don't_ need a gbmap scan
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
struct lfs3_fsinfo fsinfo;
lfs3_fs_stat(&lfs3, &fsinfo) => 0;
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| LFS3_I_LOOKAHEAD
| LFS3_I_COMPACT
| LFS3_I_CKMETA
| LFS3_I_CKDATA
| LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, 0)));
// write to a file
lfs3_file_t file;
lfs3_file_open(&lfs3, &file, "jellyfish",
LFS3_O_WRONLY | LFS3_O_CREAT | LFS3_O_EXCL) => 0;
uint8_t wbuf[SIZE];
for (lfs3_size_t j = 0; j < SIZE; j++) {
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
}
lfs3_file_write(&lfs3, &file, wbuf, SIZE) => SIZE;
lfs3_file_close(&lfs3, &file) => 0;
lfs3_unmount(&lfs3) => 0;
// but if we allocated any blocks our gbmap will be inexhaustive
lfs3_mount(&lfs3, LFS3_M_RDWR, CFG) => 0;
lfs3_fs_stat(&lfs3, &fsinfo) => 0;
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| LFS3_I_LOOKAHEAD
| LFS3_I_REBUILDGBMAP
| LFS3_I_COMPACT
| LFS3_I_CKMETA
| LFS3_I_CKDATA
| LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, 0)));
lfs3_unmount(&lfs3) => 0;
// with LFS3_M_REBUILDGBMAP, mount performs a gbmap rebuild
lfs3_mount(&lfs3,
LFS3_M_RDWR
| LFS3_M_LOOKAHEAD
| LFS3_M_REBUILDGBMAP
| ((CKMETA) ? LFS3_M_CKMETA : 0)
| ((CKDATA) ? LFS3_M_CKDATA : 0),
CFG) => 0;
lfs3_fs_stat(&lfs3, &fsinfo) => 0;
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| LFS3_I_COMPACT
// note ckdata implies ckmeta
| ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0)
| ((!CKDATA) ? LFS3_I_CKDATA : 0)
| LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, 0)));
lfs3_unmount(&lfs3) => 0;
'''
[cases.test_mount_t_compact]
defines.LOOKAHEAD = [false, true]
defines.CKMETA = [false, true]
@ -241,6 +318,9 @@ code = '''
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| LFS3_I_LOOKAHEAD
| LFS3_IFDEF_YES_GBMAP(
(SIZE >= BLOCK_SIZE/4) ? LFS3_I_REBUILDGBMAP : 0,
0)
| LFS3_I_COMPACT
| LFS3_I_CKMETA
| LFS3_I_CKDATA
@ -259,6 +339,9 @@ code = '''
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| ((!LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| LFS3_IFDEF_YES_GBMAP(
(SIZE >= BLOCK_SIZE/4) ? LFS3_I_REBUILDGBMAP : 0,
0)
// note ckdata implies ckmeta
| ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0)
| ((!CKDATA) ? LFS3_I_CKDATA : 0)
@ -345,6 +428,9 @@ code = '''
assert(fsinfo.flags == (
LFS3_I_MKCONSISTENT
| LFS3_I_LOOKAHEAD
| LFS3_IFDEF_YES_GBMAP(
(ORPHANS >= 100) ? LFS3_I_REBUILDGBMAP : 0,
0)
| LFS3_I_COMPACT
| LFS3_I_CKMETA
| LFS3_I_CKDATA
@ -363,6 +449,9 @@ code = '''
lfs3_fs_stat(&lfs3, &fsinfo) => 0;
assert(fsinfo.flags == (
((!LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0)
| LFS3_IFDEF_YES_GBMAP(
(ORPHANS >= 100) ? LFS3_I_REBUILDGBMAP : 0,
0)
| ((!COMPACT) ? LFS3_I_COMPACT : 0)
// note ckdata implies ckmeta
| ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0)

File diff suppressed because it is too large Load Diff