diff options
author | Christopher Haster <chaster@utexas.edu> | 2020-01-21 02:35:45 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2020-01-21 04:27:27 +0300 |
commit | f4b6a6b3284d8b721ba3db0bba93ee45fde7ead9 (patch) | |
tree | c6bba36b3f00ab3e96acfc1106d72a43858adaff /scripts | |
parent | 9453ebd15d590778a5207920b2671a4fff91a9e0 (diff) |
Fixed issues with neighbor updates during moves
The root of the problem was some assumptions about what tags could be
sent to lfs_dir_commit.
- The first assumption is that there could be only one splice (create/delete)
tag at a time, which is trivially broken by the core commit in lfs_rename.
- The second assumption is that there is at most one create and one delete in
a single commit. This is less obvious but turns out to not be true in
the case that we rename a file such that it overwrites another file in
the same directory (1 delete for source file, 1 delete for destination).
- The third assumption was that there was an ordering to the
delete/creates passed to lfs_dir_commit. It may be possible to force all
deletes to follow creates by rearranging the tags in lfs_rename, but
this risks overflowing tag ids.
The way the lfs_dir_commit first collected the "deletetag" and "createtag"
broke all three of these assumptions. And because we lose the ordering
information we can no longer apply the directory changes to open files
correctly. The file ids may be shifted in a way that doesn't reflect the
actual operations on disk.
These problems were made worst by lfs_dir_commit cleaning up moves
implicitly, which also creates deletes implicitly. While cleaning up moves
in lfs_dir_commit may save some code size, it makes the commit logic much more
difficult to implement correctly.
This bug turned into pulling out a dead tree stump, roots and all.
I ended up reworking how lfs_dir_commit updates open files so that it
has less assumptions, now it just traverses the commit tags multiple
times in order to update file ids after a successful commit in the
correct order.
This also got rid of the dir copy by carefully updating split dirs
after all files have an up-to-date copy of the original dir.
I also just removed the implicit move cleanup. It turns out the only
commits that can occur before we have cleaned up the move is in
lfs_fs_relocate, so it was simple enough to explicitly handle this case
when we update our parent and pred during a relocate.
Cases where we may need to fix moves:
- In lfs_rename when we move a file/dir
- In lfs_demove if we lose power
- In lfs_fs_relocate if we have to relocate our parent and we find it
had a pending move (or else the move will be outdated)
- In lfs_fs_relocate if we have to relocate our predecessor and we find it
had a pending move (or else the move will be outdated)
Note the two cases in lfs_fs_relocate may be recursive. But
lfs_fs_relocate can only trigger other lfs_fs_relocates so it's not
possible for pending moves to spill out into other filesystem commits
And of couse, I added several tests to cover these situations. Hopefully
the rename-with-open-files logic should be fairly locked down now.
found with initial fix by eastmoutain
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/readmdir.py | 34 | ||||
-rwxr-xr-x | scripts/readtree.py | 19 |
2 files changed, 36 insertions, 17 deletions
diff --git a/scripts/readmdir.py b/scripts/readmdir.py index a60acbe..1730f02 100755 --- a/scripts/readmdir.py +++ b/scripts/readmdir.py @@ -106,6 +106,13 @@ class Tag: 0x3ff if self.isattr else 0, 0) + def chid(self, nid): + ntag = Tag(self.type, nid, self.size) + if hasattr(self, 'off'): ntag.off = self.off + if hasattr(self, 'data'): ntag.data = self.data + if hasattr(self, 'crc'): ntag.crc = self.crc + return ntag + def typerepr(self): if self.is_('crc') and getattr(self, 'crc', 0xffffffff) != 0xffffffff: return 'crc (bad)' @@ -197,22 +204,29 @@ class MetadataPair: crc = 0 tag = Tag(int(tag) ^ ((tag.type & 1) << 31)) + # find active ids + self.ids = list(it.takewhile( + lambda id: Tag('name', id, 0) in self, + it.count())) + # find most recent tags self.tags = [] for tag in self.log: if tag.is_('crc') or tag.is_('splice'): continue - - if tag in self and self[tag] is tag: - self.tags.append(tag) + elif tag.id == 0x3ff: + if tag in self and self[tag] is tag: + self.tags.append(tag) + else: + # id could have change, I know this is messy and slow + # but it works + for id in self.ids: + ntag = tag.chid(id) + if ntag in self and self[ntag] is tag: + self.tags.append(ntag) self.tags = sorted(self.tags) - # and ids - self.ids = list(it.takewhile( - lambda id: Tag('name', id, 0) in self, - it.count())) - def __bool__(self): return bool(self.log) @@ -247,8 +261,8 @@ class MetadataPair: gdiff += tag.schunk - if (int(gmask) & int(tag)) == (int(gmask) & int( - Tag(gtag.type, gtag.id - gdiff, gtag.size))): + if ((int(gmask) & int(tag)) == + (int(gmask) & int(gtag.chid(gtag.id - gdiff)))): if tag.size == 0x3ff: # deleted break diff --git a/scripts/readtree.py b/scripts/readtree.py index 2bae10e..7d112fd 100755 --- a/scripts/readtree.py +++ b/scripts/readtree.py @@ -38,6 +38,8 @@ def dumptags(args, mdir, f): '<II', tag.data[:8].ljust(8, b'\xff'))) if tag.is_('inlinestruct'): f.write(" inline size %d" % tag.size) + if tag.is_('gstate'): + f.write(" 0x%s" % ''.join('%02x' % c for c in tag.data)) if tag.is_('tail'): f.write(" tail {%#x, %#x}" % struct.unpack( '<II', tag.data[:8].ljust(8, b'\xff'))) @@ -56,7 +58,7 @@ def dumpentries(args, mdir, f): struct_ = mdir[Tag('struct', id_, 0)] f.write("id %d %s %s" % ( - name.id, name.typerepr(), + id_, name.typerepr(), json.dumps(name.data.decode('utf8')))) if struct_.is_('dirstruct'): f.write(" dir {%#x, %#x}" % struct.unpack( @@ -177,11 +179,14 @@ def main(args): for mdir in dir: for tag in mdir.tags: if tag.is_('dir'): - npath = tag.data.decode('utf8') - dirstruct = mdir[Tag('dirstruct', tag.id, 0)] - nblocks = struct.unpack('<II', dirstruct.data) - nmdir = dirtable[tuple(sorted(nblocks))] - pending.append(((path + '/' + npath), nmdir)) + try: + npath = tag.data.decode('utf8') + dirstruct = mdir[Tag('dirstruct', tag.id, 0)] + nblocks = struct.unpack('<II', dirstruct.data) + nmdir = dirtable[tuple(sorted(nblocks))] + pending.append(((path + '/' + npath), nmdir)) + except KeyError: + pass dir[0].path = path.replace('//', '/') @@ -209,7 +214,7 @@ def main(args): blocks = struct.unpack('<II', gstate[4:4+8].ljust(8, b'\xff')) if tag.size: print(" orphans %d" % tag.size) - if not tag.isvalid: + if tag.type: print(" move dir {%#x, %#x} id %d" % ( blocks[0], blocks[1], tag.id)) |