Renamed a few superblock-related things

- supermdir -> mroot
- supermagic -> magic
- superconfig -> config
This commit is contained in:
Christopher Haster
2023-05-09 12:26:05 -05:00
parent 7925f9f019
commit 975a98b099
6 changed files with 82 additions and 82 deletions
+40 -40
View File
@@ -587,9 +587,9 @@ enum lfsr_tag_type {
LFSR_TAG_UNR = 0x0002,
LFSR_TAG_MKUNR = 0x0006, // in-device only
LFSR_TAG_SUPERMAGIC = 0x0030,
LFSR_TAG_SUPERCONFIG = 0x0040,
LFSR_TAG_SUPERMDIR = 0x0110,
LFSR_TAG_MAGIC = 0x0030,
LFSR_TAG_CONFIG = 0x0040,
LFSR_TAG_MROOT = 0x0110,
LFSR_TAG_NAME = 0x1000,
LFSR_TAG_BRANCH = 0x1000,
@@ -5148,20 +5148,20 @@ static inline int lfsr_mtree_isinlined(lfs_t *lfs) {
static inline lfs_ssize_t lfsr_mtree_weight(lfs_t *lfs) {
// inlined mdir?
if (lfsr_mtree_isinlined(lfs)) {
return lfs->supermdir.rbyd.weight;
return lfs->mroot.rbyd.weight;
} else {
return lfsr_btree_weight(&lfs->mtree);
}
}
static int lfsr_mtree_lookup(lfs_t *lfs, lfs_ssize_t mid, lfsr_mdir_t *mdir_) {
// TODO should we really allow -1=>supermdir lookup?
// TODO should we really allow -1=>mroot lookup?
LFS_ASSERT(mid >= -1);
LFS_ASSERT(mid < lfsr_mtree_weight(lfs));
// looking up supermdir?
// looking up mroot?
if (mid < 0) {
*mdir_ = lfs->supermdir;
*mdir_ = lfs->mroot;
return 0;
// look up mdir in actual mtree
@@ -5252,9 +5252,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
mdir->rbyd = rbyd_;
// TODO synchronize open mdirs?
// synchronize supermdir
if (mdir->mid == -1 && mdir != &lfs->supermdir) {
lfs->supermdir = *mdir;
// synchronize mroot
if (mdir->mid == -1 && mdir != &lfs->mroot) {
lfs->mroot = *mdir;
}
// successful commit
@@ -5274,7 +5274,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
lfs_size_t lower_id;
lfs_size_t lower_dsize;
// supermdirs without inlined mdirs must fit, skip the check for
// mroots without inlined mdirs must fit, skip the check for
// compaction threshold in this case, we'll error in lfsr_rbyd_append
// if we don't fit
if (!(mdir->mid < 0 && !lfsr_mtree_isinlined(lfs))) {
@@ -5290,7 +5290,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
}
if (estimate != LFSR_ESTIMATE_FITS) {
// are we inlined into the supermdir? we need to uninline
// are we inlined into the mroot? we need to uninline
// before we split, and it's possible uninlining makes the mdir
// small enough that we don't even need to split
if (lfsr_mtree_isinlined(lfs)) {
@@ -5362,9 +5362,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
}
// if we don't have inlined mdirs, then we shouldn't have any
// ids>=0 in the supermdir, this check is necessary as a part
// ids>=0 in the mroot, this check is necessary as a part
// of uninlining, and it simplifies things to do this on every
// compact of the supermdir
// compact of the mroot
//
// note that unlining only triggers on compact, so we should never
// end up id>=0 outside of a compact
@@ -5390,7 +5390,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
//
// take care to skip superattrs (id=-1) if we're uninlining, or only
// allow superattrs if we've uninlined and are now committing to our
// supermdir
// mroot
for (lfs_size_t i = 0; i < attr_count; i++) {
if (!(uninlining && attrs[i].id < 0)
&& !(mdir_.mid < 0
@@ -5443,20 +5443,20 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
// TODO deduplicate mdir synchronization?
// TODO synchronize open mdirs?
// synchronize supermdir
if (mdir->mid == -1 && mdir != &lfs->supermdir) {
lfs->supermdir = *mdir;
// synchronize mroot
if (mdir->mid == -1 && mdir != &lfs->mroot) {
lfs->mroot = *mdir;
}
break;
} else {
// update our mdir, prepare supermdir
// update our mdir, prepare mroot
if (*rid < 0) {
// wait to update mdir after supdermdir update
} else {
*mdir = mdir_;
mdir = &lfs->supermdir;
mdir = &lfs->mroot;
}
// TODO synchronize open mdirs?
@@ -5478,11 +5478,11 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
}
// mark mtree as dirty and tail recurse to write it and any pending
// superattrs to the supermdir
// superattrs to the mroot
dirty_mtree = true;
continue;
// // prepare commit to supermdir
// // prepare commit to mroot
// lfsr_tag_t tag;
// d = lfsr_btree_todisk(lfs, &lfs->mtree, &tag, recurse_buf);
// if (d < 0) {
@@ -5705,16 +5705,16 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
return err;
}
// update our mdir, prepare supermdir
// update our mdir, prepare mroot
if (uninlining && *rid < 0) {
// wait to update mdir after supdermdir update
} else if (*rid < split_id) {
*mdir = mdir_;
mdir = &lfs->supermdir;
mdir = &lfs->mroot;
} else if (*rid >= split_id) {
*mdir = sibling;
*rid -= split_id;
mdir = &lfs->supermdir;
mdir = &lfs->mroot;
}
// TODO synchronize open mdirs?
@@ -5755,7 +5755,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
return err;
}
// mark mtree as dirty and tail recurse to write it to the supermdir
// mark mtree as dirty and tail recurse to write it to the mroot
dirty_mtree = true;
// only include superattrs if we're uninlining
if (!uninlining) {
@@ -5763,7 +5763,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
}
continue;
// // prepare commit to supermdir
// // prepare commit to mroot
// lfs_ssize_t d = lfsr_btree_todisk(lfs, &lfs->mtree, &tag, recurse_buf);
// if (d < 0) {
// return d;
@@ -5804,10 +5804,10 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_ssize_t *rid,
// - 32-bit file_limit => 5 byte leb128 (worst case)
// => 30 bytes total
//
#define LFSR_SUPERCONFIG_DSIZE (1+1+1+1+5+5+1+5+5+5)
#define LFSR_CONFIG_DSIZE (1+1+1+1+5+5+1+5+5+5)
static lfs_ssize_t lfsr_superconfig_todisk(lfs_t *lfs,
uint8_t buffer[static LFSR_SUPERCONFIG_DSIZE]) {
uint8_t buffer[static LFSR_CONFIG_DSIZE]) {
// TODO most of these should also be in the lfs_config/lfs_t structs
// note we take a shortcut for for single-byte leb128s, but these
@@ -5906,7 +5906,7 @@ static int lfsr_mountinited(lfs_t *lfs) {
// has magic string?
lfsr_data_t data;
err = lfsr_mdir_lookup(lfs, &mdir, -1, LFSR_TAG_SUPERMAGIC, &data);
err = lfsr_mdir_lookup(lfs, &mdir, -1, LFSR_TAG_MAGIC, &data);
if (err && err != LFS_ERR_NOENT) {
return err;
}
@@ -5930,7 +5930,7 @@ static int lfsr_mountinited(lfs_t *lfs) {
}
// lookup the superconfig
err = lfsr_mdir_lookup(lfs, &mdir, -1, LFSR_TAG_SUPERCONFIG, &data);
err = lfsr_mdir_lookup(lfs, &mdir, -1, LFSR_TAG_CONFIG, &data);
if (err && err != LFS_ERR_NOENT) {
return err;
}
@@ -6130,16 +6130,16 @@ static int lfsr_mountinited(lfs_t *lfs) {
}
}
// lookup supermdir
// lookup mroot
//
// if we have a supermdir, this is actually a fake superblock and
// if we have a mroot, this is actually a fake superblock and
// we need to parse the next superblock in the chain
err = lfsr_mdir_lookup(lfs, &mdir, -1, LFSR_TAG_SUPERMDIR, &data);
err = lfsr_mdir_lookup(lfs, &mdir, -1, LFSR_TAG_MROOT, &data);
if (err && err != LFS_ERR_NOENT) {
return err;
}
// no more supermdirs means we found our real superblock
// no more mroots means we found our real superblock
if (err == LFS_ERR_NOENT) {
break;
}
@@ -6178,19 +6178,19 @@ static int lfsr_mountinited(lfs_t *lfs) {
lfs->mtree = LFSR_BTREE_NULL;
}
lfs->supermdir = mdir;
lfs->mroot = mdir;
return 0;
}
static int lfsr_formatinited(lfs_t *lfs) {
uint8_t buf[LFSR_SUPERCONFIG_DSIZE];
uint8_t buf[LFSR_CONFIG_DSIZE];
lfs_ssize_t d = lfsr_superconfig_todisk(lfs, buf);
if (d < 0) {
return d;
}
for (int i = 0; i < 2; i++) {
// write superblock to both rbyds in the root supermdir to hopefully
// write superblock to both rbyds in the root mroot to hopefully
// avoid mounting an older filesystem on disk
lfsr_rbyd_t rbyd = {.block=i, .rev=i+1, .off=0, .trunk=0};
@@ -6200,8 +6200,8 @@ static int lfsr_formatinited(lfs_t *lfs) {
}
err = lfsr_rbyd_commit(lfs, &rbyd, LFSR_ATTRS(
LFSR_ATTR(-1, SUPERMAGIC, 0, "littlefs", 8),
LFSR_ATTR(-1, SUPERCONFIG, 0, buf, d)));
LFSR_ATTR(-1, MAGIC, 0, "littlefs", 8),
LFSR_ATTR(-1, CONFIG, 0, buf, d)));
if (err) {
return err;
}
+2 -2
View File
@@ -372,7 +372,7 @@ typedef union lfsr_btree {
typedef struct lfsr_mdir {
// -2 => an out-of-tree mdir
// -1 => supermdir
// -1 => mroot
// >=0 => bid in the mtree
lfs_ssize_t mid;
lfs_block_t other_block;
@@ -469,7 +469,7 @@ typedef struct lfs {
lfs_size_t attr_max;
// begin lfsr things
lfsr_mdir_t supermdir;
lfsr_mdir_t mroot;
lfsr_btree_t mtree;
#ifdef LFS_MIGRATE
+9 -9
View File
@@ -8,9 +8,9 @@ import struct
TAG_UNR = 0x0002
TAG_SUPERMAGIC = 0x0030
TAG_SUPERCONFIG = 0x0040
TAG_SUPERMDIR = 0x0110
TAG_MAGIC = 0x0030
TAG_CONFIG = 0x0040
TAG_MROOT = 0x0110
TAG_NAME = 0x1000
TAG_BRANCH = 0x1000
TAG_REG = 0x1010
@@ -91,18 +91,18 @@ def tagrepr(tag, w, size, off=None):
return 'unr%s%s' % (
' w%d' % w if w else '',
' %d' % size if size else '')
elif (tag & 0xfffc) == TAG_SUPERMAGIC:
return '%ssupermagic%s %d' % (
elif (tag & 0xfffc) == TAG_MAGIC:
return '%smagic%s %d' % (
'rm' if tag & 0x2 else '',
' w%d' % w if w else '',
size)
elif (tag & 0xfffc) == TAG_SUPERCONFIG:
return '%ssuperconfig%s %d' % (
elif (tag & 0xfffc) == TAG_CONFIG:
return '%sconfig%s %d' % (
'rm' if tag & 0x2 else '',
' w%d' % w if w else '',
size)
elif (tag & 0xfffc) == TAG_SUPERMDIR:
return '%ssupermdir%s %d' % (
elif (tag & 0xfffc) == TAG_MROOT:
return '%smroot%s %d' % (
'rm' if tag & 0x2 else '',
' w%d' % w if w else '',
size)
+9 -9
View File
@@ -18,9 +18,9 @@ COLORS = [
TAG_UNR = 0x0002
TAG_SUPERMAGIC = 0x0030
TAG_SUPERCONFIG = 0x0040
TAG_SUPERMDIR = 0x0110
TAG_MAGIC = 0x0030
TAG_CONFIG = 0x0040
TAG_MROOT = 0x0110
TAG_NAME = 0x1000
TAG_BRANCH = 0x1000
TAG_REG = 0x1010
@@ -101,18 +101,18 @@ def tagrepr(tag, w, size, off=None):
return 'unr%s%s' % (
' w%d' % w if w else '',
' %d' % size if size else '')
elif (tag & 0xfffc) == TAG_SUPERMAGIC:
return '%ssupermagic%s %d' % (
elif (tag & 0xfffc) == TAG_MAGIC:
return '%smagic%s %d' % (
'rm' if tag & 0x2 else '',
' w%d' % w if w else '',
size)
elif (tag & 0xfffc) == TAG_SUPERCONFIG:
return '%ssuperconfig%s %d' % (
elif (tag & 0xfffc) == TAG_CONFIG:
return '%sconfig%s %d' % (
'rm' if tag & 0x2 else '',
' w%d' % w if w else '',
size)
elif (tag & 0xfffc) == TAG_SUPERMDIR:
return '%ssupermdir%s %d' % (
elif (tag & 0xfffc) == TAG_MROOT:
return '%smroot%s %d' % (
'rm' if tag & 0x2 else '',
' w%d' % w if w else '',
size)
+19 -19
View File
@@ -1,5 +1,5 @@
# test a single supermdir
[cases.test_mtree_one_supermdir]
# test a single mroot
[cases.test_mtree_one_mroot]
code = '''
lfs_t lfs;
lfsr_format(&lfs, cfg) => 0;
@@ -7,32 +7,32 @@ code = '''
lfsr_unmount(&lfs) => 0;
'''
# test a single supermdir with a custom attribute
[cases.test_mtree_one_supermdir_attr]
# test a single mroot with a custom attribute
[cases.test_mtree_one_mroot_attr]
in = 'lfs.c'
code = '''
lfs_t lfs;
lfsr_format(&lfs, cfg) => 0;
lfsr_mount(&lfs, cfg) => 0;
lfsr_mdir_commit(&lfs, &lfs.supermdir, &(lfs_ssize_t){-1}, LFSR_ATTRS(
lfsr_mdir_commit(&lfs, &lfs.mroot, &(lfs_ssize_t){-1}, LFSR_ATTRS(
LFSR_ATTR(-1, UATTR(1), 0, "ardvark", 7))) => 0;
uint8_t buffer[7];
lfsr_mdir_get(&lfs, &lfs.supermdir,
lfsr_mdir_get(&lfs, &lfs.mroot,
-1, LFSR_TAG_UATTR(1), buffer, 7) => 7;
assert(memcmp(buffer, "ardvark", 7) == 0);
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
lfsr_mdir_get(&lfs, &lfs.supermdir,
lfsr_mdir_get(&lfs, &lfs.mroot,
-1, LFSR_TAG_UATTR(1), buffer, 7) => 7;
assert(memcmp(buffer, "ardvark", 7) == 0);
lfsr_unmount(&lfs) => 0;
'''
# test a single supermdir with many commits
[cases.test_mtree_one_supermdir_many_commits]
# test a single mroot with many commits
[cases.test_mtree_one_mroot_many_commits]
defines.N = [5, 5000]
in = 'lfs.c'
code = '''
@@ -42,11 +42,11 @@ code = '''
lfsr_mount(&lfs, cfg) => 0;
for (lfs_size_t i = 0; i < N; i++) {
lfsr_mdir_commit(&lfs, &lfs.supermdir, &(lfs_ssize_t){-1}, LFSR_ATTRS(
lfsr_mdir_commit(&lfs, &lfs.mroot, &(lfs_ssize_t){-1}, LFSR_ATTRS(
LFSR_ATTR(-1, UATTR(1), 0, &alphas[i % 26], 1))) => 0;
uint8_t buffer[4];
lfsr_mdir_get(&lfs, &lfs.supermdir,
lfsr_mdir_get(&lfs, &lfs.mroot,
-1, LFSR_TAG_UATTR(1), buffer, 4) => 1;
assert(memcmp(buffer, &alphas[i % 26], 1) == 0);
}
@@ -54,13 +54,13 @@ code = '''
lfsr_mount(&lfs, cfg) => 0;
uint8_t buffer[4];
lfsr_mdir_get(&lfs, &lfs.supermdir,
lfsr_mdir_get(&lfs, &lfs.mroot,
-1, LFSR_TAG_UATTR(1), buffer, 4) => 1;
assert(memcmp(buffer, &alphas[(N-1) % 26], 1) == 0);
lfsr_unmount(&lfs) => 0;
'''
# TODO test many supermdirs
# TODO test many mroots
# try creating a range of entries that may or may not split our mtree
[cases.test_mtree_splitting]
@@ -91,7 +91,7 @@ code = '''
lfsr_mount(&lfs, cfg) => 0;
lfs_ssize_t mid = -1;
rid = 0;
mdir = lfs.supermdir;
mdir = lfs.mroot;
for (lfs_size_t i = 0; i < N; i++) {
if (rid >= (lfs_ssize_t)mdir.rbyd.weight) {
@@ -109,7 +109,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
'''
# create a range of entries, and commit to the supermdir several times,
# create a range of entries, and commit to the mroot several times,
# this makes it more likely to force uninlining without necessarily
# splitting
[cases.test_mtree_uninlining]
@@ -138,11 +138,11 @@ code = '''
}
for (lfs_size_t i = 0; i < M; i++) {
lfsr_mdir_commit(&lfs, &lfs.supermdir, &(lfs_ssize_t){-1}, LFSR_ATTRS(
lfsr_mdir_commit(&lfs, &lfs.mroot, &(lfs_ssize_t){-1}, LFSR_ATTRS(
LFSR_ATTR(-1, UATTR(1), 0, &alphas[i % 26], 1))) => 0;
uint8_t buffer[4];
lfsr_mdir_get(&lfs, &lfs.supermdir,
lfsr_mdir_get(&lfs, &lfs.mroot,
-1, LFSR_TAG_UATTR(1), buffer, 4) => 1;
assert(memcmp(buffer, &alphas[i % 26], 1) == 0);
}
@@ -151,7 +151,7 @@ code = '''
lfsr_mount(&lfs, cfg) => 0;
lfs_ssize_t mid = -1;
rid = 0;
mdir = lfs.supermdir;
mdir = lfs.mroot;
for (lfs_size_t i = 0; i < N; i++) {
if (rid >= (lfs_ssize_t)mdir.rbyd.weight) {
@@ -168,7 +168,7 @@ code = '''
}
uint8_t buffer[4];
lfsr_mdir_get(&lfs, &lfs.supermdir,
lfsr_mdir_get(&lfs, &lfs.mroot,
-1, LFSR_TAG_UATTR(1), buffer, 4) => 1;
assert(memcmp(buffer, &alphas[(M-1) % 26], 1) == 0);
lfsr_unmount(&lfs) => 0;
+3 -3
View File
@@ -44,10 +44,10 @@ code = '''
lfsr_mount(&lfs, cfg) => 0;
uint8_t buf[LFSR_MPAIR_DSIZE];
lfs_ssize_t d = lfsr_mpair_todisk(&lfs,
lfsr_mdir_mpair(&lfs.supermdir), buf);
lfsr_mdir_mpair(&lfs.mroot), buf);
assert(d >= 0);
lfsr_mdir_commit(&lfs, &lfs.supermdir, &(lfs_ssize_t){-1}, LFSR_ATTRS(
LFSR_ATTR(-1, SUPERMDIR, 0, buf, d))) => 0;
lfsr_mdir_commit(&lfs, &lfs.mroot, &(lfs_ssize_t){-1}, LFSR_ATTRS(
LFSR_ATTR(-1, MROOT, 0, buf, d))) => 0;
lfsr_unmount(&lfs) => 0;
// now detect the cycle