diff options
author | Christopher Haster <chaster@utexas.edu> | 2018-08-25 01:45:45 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-10-18 18:00:49 +0300 |
commit | 6db5202bdc7393158914e349fedb63c5e34628e5 (patch) | |
tree | c24a18ab41d3176f053d7f6808b815d13edb80a6 /tests | |
parent | a43f9b3cd5d94c20e64ebb106d93821175660f34 (diff) |
Modified valid bit to provide an early check on all tags
The valid bit present in tags is a requirement to properly detect the
end of commits in metadata logs. The way it works is that the CRC entry is
allowed to specify what is needed from the next tag's valid bit. If it's
incorrect, we've reached the end of the commit. We then set the valid bit to
indicate when we tried to program a new commit. If we lose power, this
commit will still be thrown out by a bad checksum.
However, the valid bit is unused outside of the CRC entry. Here we turn on the
valid bit for all tags, which means we have a decent chance of exiting early
if we hit a half-written commit. We still need to guarantee detection of
the valid bit on commits following the CRC entry, so we allow the CRC
entry to flip the expected valid bit.
The only tricky part is what valid bit we expect by default, since this
is used on the first commit on a metadata log. Here we default to a 1,
which gives us the fastest exit on blocks that erase to 0. This is
because blocks that erase to 1s will implicitly flip the valid bit of
the next tag, allowing us to exit on the next tag.
If we defaulted to 0, we could exit faster on disks that erase to 1, but
would need to scan the entire block on disks that erase to 0 before we
realize a CRC commit is never coming.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/corrupt.py | 2 | ||||
-rwxr-xr-x | tests/debug.py | 12 |
2 files changed, 8 insertions, 6 deletions
diff --git a/tests/corrupt.py b/tests/corrupt.py index 5e2a9a3..9b5d4bd 100755 --- a/tests/corrupt.py +++ b/tests/corrupt.py @@ -11,7 +11,7 @@ def corrupt(block): file.read(4) # go to last commit - tag = 0 + tag = 0xffffffff while True: try: ntag, = struct.unpack('<I', file.read(4)) diff --git a/tests/debug.py b/tests/debug.py index 65b0ad0..117416a 100755 --- a/tests/debug.py +++ b/tests/debug.py @@ -12,7 +12,7 @@ TYPES = { (0x1f0, 0x080): 'globals', (0x1ff, 0x0c0): 'tail soft', (0x1ff, 0x0c1): 'tail hard', - (0x1ff, 0x0f0): 'crc', + (0x1f0, 0x0f0): 'crc', (0x1ff, 0x040): 'struct dir', (0x1ff, 0x041): 'struct inline', (0x1ff, 0x042): 'struct ctz', @@ -63,7 +63,7 @@ def main(*blocks): print "%-4s %-8s %-14s %3s %3s %s" % ( 'off', 'tag', 'type', 'id', 'len', 'dump') - tag = 0 + tag = 0xffffffff off = 4 while True: try: @@ -79,23 +79,25 @@ def main(*blocks): type = (tag & 0x7fc00000) >> 22 id = (tag & 0x003ff000) >> 12 size = (tag & 0x00000fff) >> 0 + iscrc = (type & 0x1f0) == 0x0f0 data = file.read(size) - if type == 0x0f0: + if iscrc: crc = binascii.crc32(data[:4], crc) else: crc = binascii.crc32(data, crc) print '%04x: %08x %-14s %3s %3d %-23s %-8s' % ( off, tag, - typeof(type) + (' bad!' if type == 0x0f0 and ~crc else ''), + typeof(type) + (' bad!' if iscrc and ~crc else ''), id if id != 0x3ff else '.', size, ' '.join('%02x' % ord(c) for c in data[:8]), ''.join(c if c >= ' ' and c <= '~' else '.' for c in data[:8])) off += tag & 0xfff - if type == 0x0f0: + if iscrc: crc = 0 + tag ^= (type & 1) << 31 return 0 |