Skip to content

Commit 7d9fe53

Browse files
committed
A number of small mdir commit tweaks
- Adopted -2,-2 for unbounded lfs3_mdir_commit___ ranges that include gstate. Why not? We treat any negative upper bound as unbounded and it's a bit easier to read. - Prefer <=-2 when checking for rid bounds that include gstate. - Prefer <=-2 when checking for attached rattr weights. - Cleaned up a couple outdated comments. No code changes: code stack ctx before: 35160 2136 660 after: 35160 (+0.0%) 2136 (+0.0%) 660 (+0.0%) code stack ctx gbmap before: 38020 2152 772 gbmap after: 38020 (+0.0%) 2152 (+0.0%) 772 (+0.0%)
1 parent d233750 commit 7d9fe53

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

lfs3.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ static inline bool lfs3_rattr_isgrow_(lfs3_rattr_t rattr) {
20072007
#ifndef LFS3_RDONLY
20082008
static inline lfs3_srid_t lfs3_rattr_weight(const lfs3_rattr_t *rattr) {
20092009
lfs3_srid_t weight = lfs3_rattr_weight_(rattr[0]);
2010-
if (weight == -2) {
2010+
if (weight <= -2) {
20112011
return rattr[1];
20122012
} else {
20132013
return weight;
@@ -2018,7 +2018,7 @@ static inline lfs3_srid_t lfs3_rattr_weight(const lfs3_rattr_t *rattr) {
20182018
#ifndef LFS3_RDONLY
20192019
static inline const lfs3_rattr_t *lfs3_rattr_args(const lfs3_rattr_t *rattr) {
20202020
lfs3_srid_t weight = lfs3_rattr_weight_(rattr[0]);
2021-
if (weight == -2) {
2021+
if (weight <= -2) {
20222022
return &rattr[2];
20232023
} else {
20242024
return &rattr[1];
@@ -8652,15 +8652,10 @@ static int lfs3_mdir_compact___(lfs3_t *lfs3,
86528652
//
86538653
// it's really tempting to deduplicate this via recursion! but we
86548654
// can't do that here
8655-
//
8656-
// TODO this true?
8657-
// note that any inlined updates here depend on the pre-commit state
8658-
// (btree), not the staged state (btree_), this is important,
8659-
// we can't trust btree_ after a failed commit
86608655

86618656
// assume we keep any gcksumdelta, this will get fixed the first time
86628657
// we commit anything
8663-
if (start_rid == -2) {
8658+
if (start_rid <= -2) {
86648659
mdir_->gcksumdelta = mdir->gcksumdelta;
86658660
}
86668661

@@ -8833,7 +8828,7 @@ compact:;
88338828
mdir_->r.blocks[0], mdir_->r.blocks[1]);
88348829
#endif
88358830

8836-
// don't copy over gcksum if relocating
8831+
// don't copy over gstate if relocating
88378832
lfs3_srid_t start_rid_ = start_rid;
88388833
if (relocated) {
88398834
start_rid_ = lfs3_smax(start_rid_, -1);
@@ -9018,7 +9013,7 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
90189013
// attempt to commit/compact the mdir normally
90199014
lfs3_mdir_t mdir_[2];
90209015
lfs3_srid_t split_rid;
9021-
int err = lfs3_mdir_commit__(lfs3, &mdir_[0], mdir, -2, -1,
9016+
int err = lfs3_mdir_commit__(lfs3, &mdir_[0], mdir, -2, -2,
90229017
&split_rid,
90239018
mdir->mid, rattrs);
90249019
if (err && err != LFS3_ERR_RANGE
@@ -9346,7 +9341,7 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
93469341

93479342
// commit mrootchild
93489343
lfs3_mdir_t mrootparent_;
9349-
err = lfs3_mdir_commit__(lfs3, &mrootparent_, &mrootparent, -2, -1,
9344+
err = lfs3_mdir_commit__(lfs3, &mrootparent_, &mrootparent, -2, -2,
93509345
NULL,
93519346
-1, LFS3_RATTRS(
93529347
LFS3_RATTR(2, LFS3_TAG_MROOT, 0, LFS3_FROM_MPTR),
@@ -9393,7 +9388,7 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
93939388
goto failed;
93949389
}
93959390

9396-
err = lfs3_mdir_commit___(lfs3, &mrootanchor_, -2, -1,
9391+
err = lfs3_mdir_commit___(lfs3, &mrootanchor_, -2, -2,
93979392
-1, LFS3_RATTRS(
93989393
LFS3_RATTR(2, LFS3_TAG_MAGIC, 0, LFS3_FROM_BUF, 8),
93999394
LFS3_RATTR_ARG("littlefs"),

0 commit comments

Comments
 (0)