Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qemu_nbd: Disable allocation depth for raw format #21

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ovirt_imageio/_internal/nbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,13 @@ def _set_meta_context(self, dirty_bitmap=None):
if ctx_name == dirty_bitmap:
self.dirty_bitmap = dirty_bitmap

# Warn if we failed to activate some meta context. This may affect
# performance or reduce funcionaliity.
# Log if some meta context is not available. This may affect
# performance or reduce funcionaliity, but is expected when using old
# qemu-nbd (e.g. 4.2.0) or when using raw volume that does not provide
# interesting allocation depth, and triggers a bug in qemu 6.2.0.
for ctx_name in queries:
if ctx_name not in self._meta_context:
log.warning("Failed to activate %s", ctx_name)
log.info("Meta context %s is not available", ctx_name)

def _format_meta_context_data(self, *queries):
"""
Expand Down
8 changes: 7 additions & 1 deletion ovirt_imageio/_internal/qemu_nbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ def start(self):
# support RHEL users that have qemu-nbd 4.2.0. Add the option only on
# qemu-nbd >= 5.2.0, and disable backing_chain=False otherwise.
if version() >= (5, 2, 0):
cmd.append("--allocation-depth")
# qemu-nbd 6.2.0 introduced a regression, returning wrong
# base:allocation results on the second call when accessing raw
# image. Since raw image always reports single allocation depth
# extent, we can safely disable it for raw images.
# https://lists.nongnu.org/archive/html/qemu-block/2022-01/msg00292.html
if self.fmt != "raw":
cmd.append("--allocation-depth")
elif self.fmt == "qcow2" and not self.backing_chain:
raise RuntimeError(
"backing_chain=False requires qemu-nbd >= 5.2.0")
Expand Down
2 changes: 1 addition & 1 deletion test/nbd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_handshake(tmpdir, export, fmt):
assert c.maximum_block_size == 32 * 1024**2
# Both available in in current qemu-nbd (>= 5.2.0).
assert c.has_base_allocation
assert c.has_allocation_depth
assert c.has_allocation_depth == (fmt != "raw")


def test_raw_read(tmpdir):
Expand Down
24 changes: 16 additions & 8 deletions test/qemu_nbd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,14 @@ def test_detect_zeroes_enabled(tmpdir, fmt, detect_zeroes):
c.flush()
extents = c.extents(0, size)

assert extents == {
"base:allocation": [nbd.Extent(length=1048576, flags=3)],
"qemu:allocation-depth": [nbd.Extent(length=1048576, flags=0)],
}
assert extents["base:allocation"] == [
nbd.Extent(length=1048576, flags=3),
]

if fmt != "raw":
assert extents["qemu:allocation-depth"] == [
nbd.Extent(length=1048576, flags=0),
]


@pytest.mark.parametrize("fmt", ["raw", "qcow2"])
Expand All @@ -338,7 +342,11 @@ def test_detect_zeroes_disabled(tmpdir, fmt, detect_zeroes):
c.flush()
extents = c.extents(0, size)

assert extents == {
"base:allocation": [nbd.Extent(length=1048576, flags=0)],
"qemu:allocation-depth": [nbd.Extent(length=1048576, flags=0)],
}
assert extents["base:allocation"] == [
nbd.Extent(length=1048576, flags=0),
]

if fmt != "raw":
assert extents["qemu:allocation-depth"] == [
nbd.Extent(length=1048576, flags=0),
]