Skip to content

Commit 4010afe

Browse files
committed
trv: Reintroduced LFS3_T_EXCL
With the relaxation of traversal behavior under mutation, I think it makes sense to bring back LFS3_T_EXCL. If only to allow traversals to gaurantee termination under mutation. Now that traversals no longer guarantee forward progress, it's possible to get stuck looping indefinitely if the filesystem is constantly being mutated. Non-excl traversals are probably still useful for GC work and debugging threads, but LFS3_T_EXCL now allows traversals to terminate immediately with LFS3_ERR_BUSY at the first sign of unrelated filesystem mutation: LFS3_T_EXCL 0x00000008 Error if filesystem modified Internally, we already track unrelated mutation to avoid corrupt state (LFS3_t_DIRTY), so this is a very low-cost feature: code stack ctx before: 35944 2280 660 after: 35964 (+0.1%) 2280 (+0.0%) 660 (+0.0%) code stack ctx gbmap before: 38916 2296 772 gbmap after: 38940 (+0.1%) 2296 (+0.0%) 772 (+0.0%) code stack ctx gc before: 36016 2280 768 gc after: 36036 (+0.1%) 2280 (+0.0%) 768 (+0.0%)
1 parent 8bb43ac commit 4010afe

File tree

5 files changed

+405
-29
lines changed

5 files changed

+405
-29
lines changed

lfs3.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7355,6 +7355,10 @@ static inline bool lfs3_t_ismtreeonly(uint32_t flags) {
73557355
return flags & LFS3_T_MTREEONLY;
73567356
}
73577357

7358+
static inline bool lfs3_t_isexcl(uint32_t flags) {
7359+
return flags & LFS3_T_EXCL;
7360+
}
7361+
73587362
static inline bool lfs3_t_ismkconsistent(uint32_t flags) {
73597363
(void)flags;
73607364
#ifndef LFS3_RDONLY
@@ -16914,6 +16918,7 @@ int lfs3_trv_open(lfs3_t *lfs3, lfs3_trv_t *trv, uint32_t flags) {
1691416918
LFS3_IFDEF_RDONLY(0, LFS3_T_RDWR)
1691516919
| LFS3_T_RDONLY
1691616920
| LFS3_T_MTREEONLY
16921+
| LFS3_T_EXCL
1691716922
| LFS3_IFDEF_RDONLY(0, LFS3_T_MKCONSISTENT)
1691816923
| LFS3_IFDEF_RDONLY(0, LFS3_T_RELOOKAHEAD)
1691916924
| LFS3_IFDEF_RDONLY(0,
@@ -16959,6 +16964,12 @@ int lfs3_trv_read(lfs3_t *lfs3, lfs3_trv_t *trv,
1695916964
struct lfs3_tinfo *tinfo) {
1696016965
LFS3_ASSERT(lfs3_handle_isopen(lfs3, &trv->gc.t.h));
1696116966

16967+
// filesystem modified? excl? terminate early
16968+
if (lfs3_t_isexcl(trv->gc.t.h.flags)
16969+
&& lfs3_t_isdirty(trv->gc.t.h.flags)) {
16970+
return LFS3_ERR_BUSY;
16971+
}
16972+
1696216973
// check for pending grms every step, just in case some other
1696316974
// operation introduced new grms
1696416975
#ifndef LFS3_RDONLY

lfs3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ enum lfs3_err {
7777
LFS3_ERR_UNKNOWN = -1, // Unknown error
7878
LFS3_ERR_INVAL = -22, // Invalid parameter
7979
LFS3_ERR_NOTSUP = -95, // Operation not supported
80+
LFS3_ERR_BUSY = -16, // Device or resource busy
8081
LFS3_ERR_IO = -5, // Error during device operation
8182
LFS3_ERR_CORRUPT = -84, // Corrupted
8283
LFS3_ERR_NOENT = -2, // No directory entry
@@ -318,6 +319,7 @@ enum lfs3_btype {
318319
#define LFS3_T_RDONLY 1 // Open traversal as read only
319320
#define LFS3_T_MTREEONLY \
320321
0x00000002 // Only traverse the mtree
322+
#define LFS3_T_EXCL 0x00000008 // Error if filesystem modified
321323
#ifndef LFS3_RDONLY
322324
#define LFS3_T_MKCONSISTENT \
323325
0x00000100 // Make the filesystem consistent

scripts/dbgerr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ERR_UNKNOWN = -1 # Unknown error
1313
ERR_INVAL = -22 # Invalid parameter
1414
ERR_NOTSUP = -95 # Operation not supported
15+
ERR_BUSY = -16 # Device or resource busy
1516
ERR_IO = -5 # Error during device operation
1617
ERR_CORRUPT = -84 # Corrupted
1718
ERR_NOENT = -2 # No directory entry

scripts/dbgflags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
T_RDWR = 0 # -^ Open traversal as read and write
140140
T_RDONLY = 1 # -^ Open traversal as read only
141141
T_MTREEONLY = 0x00000002 # -- Only traverse the mtree
142+
T_EXCL = 0x00000008 # -- Error if filesystem modified
142143
T_MKCONSISTENT = 0x00000100 # -- Make the filesystem consistent
143144
T_RELOOKAHEAD = 0x00000200 # -- Repopulate lookahead buffer
144145
T_REGBMAP = 0x00000400 # -- Repopulate the gbmap

0 commit comments

Comments
 (0)