Adopted internal LFSR_TAG_GRMPUSH for atomic self-grming commits
So instead of special behavior for only bookmark tags, LFSR_TAG_GRMPUSH
allows pushing any mid to the grm queue.
The benefit of LFSR_TAG_GRMPUSH, vs just calling lfsr_grm_push before
lfsr_mdir_commit, is that you can push mids that don't exist yet. This
lets you to create self-grming mids that effectively don't exist until
some other work has completed.
We currently use this to atomically create directory + bookmark entries,
but it may have some other uses in the future.
---
The extra rattr does add a bit of code, but fortunately no stack, since
lfsr_mkdir is not on the stack hot-path:
code stack ctx
before: 35768 2368 640
after: 35796 (+0.1%) 2368 (+0.0%) 640 (+0.0%)
This commit is contained in:
@@ -1163,8 +1163,9 @@ enum lfsr_tag {
|
||||
LFSR_TAG_INTERNAL = 0x0800,
|
||||
LFSR_TAG_RATTRS = 0x0800,
|
||||
LFSR_TAG_SHRUBCOMMIT = 0x0801,
|
||||
LFSR_TAG_MOVE = 0x0802,
|
||||
LFSR_TAG_ATTRS = 0x0803,
|
||||
LFSR_TAG_GRMPUSH = 0x0802,
|
||||
LFSR_TAG_MOVE = 0x0803,
|
||||
LFSR_TAG_ATTRS = 0x0804,
|
||||
|
||||
// some in-device only tag modifiers
|
||||
LFSR_TAG_RM = 0x8000,
|
||||
@@ -7894,6 +7895,11 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
|
||||
return err;
|
||||
}
|
||||
|
||||
// push a new grm, this tag lets us push grms atomically when
|
||||
// creating new mids
|
||||
} else if (rattrs[i].tag == LFSR_TAG_GRMPUSH) {
|
||||
// do nothing here, this is handled up in lfsr_mdir_commit
|
||||
|
||||
// move tags copy over any tags associated with the source's rid
|
||||
// TODO can this be deduplicated with lfsr_mdir_compact__ more?
|
||||
// it _really_ wants to be deduplicated
|
||||
@@ -8512,8 +8518,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
||||
// keep in mind we revert to on-disk gstate if we run into an error
|
||||
lfsr_smid_t mid_ = mdir->mid;
|
||||
for (lfs_size_t i = 0; i < rattr_count; i++) {
|
||||
// automatically create grms for new bookmarks
|
||||
if (rattrs[i].tag == LFSR_TAG_BOOKMARK) {
|
||||
// push a new grm, this tag lets us push grms atomically when
|
||||
// creating new mids
|
||||
if (rattrs[i].tag == LFSR_TAG_GRMPUSH) {
|
||||
lfsr_grm_push(lfs, mid_);
|
||||
|
||||
// adjust pending grms?
|
||||
@@ -10273,7 +10280,9 @@ int lfsr_mkdir(lfs_t *lfs, const char *path) {
|
||||
lfs_alloc_ckpoint(lfs);
|
||||
err = lfsr_mdir_commit(lfs, &mdir, LFSR_RATTRS(
|
||||
LFSR_RATTR_NAME(
|
||||
LFSR_TAG_BOOKMARK, +1, did_, NULL, 0)));
|
||||
LFSR_TAG_BOOKMARK, +1, did_, NULL, 0),
|
||||
LFSR_RATTR(
|
||||
LFSR_TAG_GRMPUSH, 0)));
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user