scripts: Added simple mroot cycle detectors to dbg scripts
These work by keeping a set of all seen mroots as we descend down the mroot chain. Simple, but it works. The downside of this approach is that the mroot set grows unbounded, but it's unlikely we'll ever have enough mroots in a system for this to really matter. This fixes scripts like dbgbmap.py getting stuck on intentional mroot cycles created for testing. It's not a problem for a foreground script to get stuck in an infinite loop, since you can just kill it, but a background script getting stuck at 100% CPU is a bit more annoying.
This commit is contained in:
+21
-16
@@ -75,10 +75,10 @@ def bdgeom(s):
|
||||
return int(s, b)
|
||||
|
||||
# parse some rbyd addr encodings
|
||||
# 0xa -> [0xa]
|
||||
# 0xa.c -> [(0xa, 0xc)]
|
||||
# 0x{a,b} -> [0xa, 0xb]
|
||||
# 0x{a,b}.c -> [(0xa, 0xc), (0xb, 0xc)]
|
||||
# 0xa -> (0xa,)
|
||||
# 0xa.c -> ((0xa, 0xc),)
|
||||
# 0x{a,b} -> (0xa, 0xb)
|
||||
# 0x{a,b}.c -> ((0xa, 0xc), (0xb, 0xc))
|
||||
def rbydaddr(s):
|
||||
s = s.strip()
|
||||
b = 10
|
||||
@@ -109,7 +109,7 @@ def rbydaddr(s):
|
||||
else:
|
||||
addr.append(int(s, b))
|
||||
|
||||
return addr
|
||||
return tuple(addr)
|
||||
|
||||
def crc32c(data, crc=0):
|
||||
crc ^= 0xffffffff
|
||||
@@ -263,29 +263,34 @@ TBranch = co.namedtuple('TBranch', 'a, b, d, c')
|
||||
|
||||
# our core rbyd type
|
||||
class Rbyd:
|
||||
def __init__(self, block, data, rev, eoff, trunk, weight, cksum):
|
||||
self.block = block
|
||||
def __init__(self, blocks, data, rev, eoff, trunk, weight, cksum):
|
||||
if isinstance(blocks, int):
|
||||
blocks = (blocks,)
|
||||
|
||||
self.blocks = tuple(blocks)
|
||||
self.data = data
|
||||
self.rev = rev
|
||||
self.eoff = eoff
|
||||
self.trunk = trunk
|
||||
self.weight = weight
|
||||
self.cksum = cksum
|
||||
self.redund_blocks = []
|
||||
|
||||
@property
|
||||
def block(self):
|
||||
return self.blocks[0]
|
||||
|
||||
def addr(self):
|
||||
if not self.redund_blocks:
|
||||
if len(self.blocks) == 1:
|
||||
return '0x%x.%x' % (self.block, self.trunk)
|
||||
else:
|
||||
return '0x{%x,%s}.%x' % (
|
||||
self.block,
|
||||
','.join('%x' % block for block in self.redund_blocks),
|
||||
return '0x{%s}.%x' % (
|
||||
','.join('%x' % block for block in self.blocks),
|
||||
self.trunk)
|
||||
|
||||
@classmethod
|
||||
def fetch(cls, f, block_size, blocks, trunk=None):
|
||||
if isinstance(blocks, int):
|
||||
blocks = [blocks]
|
||||
blocks = (blocks,)
|
||||
|
||||
if len(blocks) > 1:
|
||||
# fetch all blocks
|
||||
@@ -303,9 +308,9 @@ class Rbyd:
|
||||
i = i_
|
||||
# keep track of the other blocks
|
||||
rbyd = rbyds[i]
|
||||
rbyd.redund_blocks = [
|
||||
rbyd.blocks += tuple(
|
||||
rbyds[(i+1+j) % len(rbyds)].block
|
||||
for j in range(len(rbyds)-1)]
|
||||
for j in range(len(rbyds)-1))
|
||||
return rbyd
|
||||
else:
|
||||
# block may encode a trunk
|
||||
@@ -605,7 +610,7 @@ def main(disk, roots=None, *,
|
||||
|
||||
# flatten roots, default to block 0
|
||||
if not roots:
|
||||
roots = [[0]]
|
||||
roots = [(0,)]
|
||||
roots = [block for roots_ in roots for block in roots_]
|
||||
|
||||
# we seek around a bunch, so just keep the disk open
|
||||
|
||||
Reference in New Issue
Block a user