Skip to content

Commit

Permalink
read data correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbi committed Feb 5, 2025
1 parent 912daac commit a703133
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 0 additions & 2 deletions libvirtnbdbackup/qemu/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,10 @@ def startNbdkitProcess(
f"{args.listen_port}",
"-e",
f"{self.exportName}",
"--filter=blocksize",
"--filter=cow",
"-v",
"python",
f"{nbdkitModule}",
f"maxlen={args.blocksize}",
f"blockmap={blockMap}",
f"disk={fullImage}",
f"debug={debug}",
Expand Down
8 changes: 6 additions & 2 deletions virtnbd-nbdkit-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def pread(h, buf, offset, flags):

log(f"Processing block: {block}")

# where to read in the stream file
fileOffset = block["offset"] - block["originalOffset"] + offset

dataFile = block["file"]
Expand Down Expand Up @@ -182,13 +183,16 @@ def pread(h, buf, offset, flags):
None,
)
if not next_block:
raise RuntimeError("Unable to find next block")
raise RuntimeError("Unable to locate next block")

log(f"Found next block: {next_block}")

if next_block["data"]:
log(f"Read {remaining} data size from next block.")
data += os.pread(h, remaining, next_block["offset"])
fileOffset = (
next_block["offset"] - next_block["originalOffset"] + offset
)
data += os.pread(h, remaining, fileOffset)
remaining -= remaining
else:
log(f"Next block contains zeroes, return {remaining} zeroes")
Expand Down

0 comments on commit a703133

Please sign in to comment.