zfs check initial version (wip)

This commit is contained in:
Edwin Eefting 2022-02-20 17:39:17 +01:00
parent a115f0bd17
commit 14c45d2b34
2 changed files with 9 additions and 7 deletions

View File

@ -39,8 +39,8 @@ class ZfsCheck(CliBase):
return args
def hash_filesystem(self, snapshot):
"""
def hash_filesystem(self, snapshot, count, bs):
""" recursively hash all files in this snapshot, using block_hash_tree()
:type snapshot: ZfsDataset.ZfsDataset
"""
@ -54,14 +54,16 @@ class ZfsCheck(CliBase):
self.debug("Hashing tree: {}".format(mnt))
if not self.args.test:
for (file, block, hash) in block_hash_tree(mnt):
for (file, block, hash) in block_hash_tree(mnt, count, bs):
print("{}\t{}\t{}".format(file, block, hash))
finally:
self.debug("Cleaning up temporary mount point")
snapshot.unmount()
self.debug("Cleaning up temporary mount point")
self.node.run(["rmdir", mnt], hide_errors=True, valid_exitcodes=[])
# def hash_volume(self, snapshot):
def run(self):
@ -78,9 +80,9 @@ class ZfsCheck(CliBase):
dataset_type=snapshot.parent.properties['type']
if dataset_type=='volume':
self.checksum_volume(snapshot)
self.checksum_volume(snapshot, self.args.count, self.args.block_size)
elif dataset_type=='filesystem':
self.hash_filesystem(snapshot)
self.hash_filesystem(snapshot, self.args.count, self.args.block_size)
else:
raise Exception("huh?")

View File

@ -36,7 +36,7 @@ def block_hash(fname, count=10000, bs=4006):
hash = hashlib.sha1()
block_nr = 0
chunk_nr = 0
for block in iter(lambda: f.read(4096), b""):
for block in iter(lambda: f.read(bs), b""):
hash.update(block)
block_nr = block_nr + 1
if block_nr % count == 0: