fix(convert): wait for nbd device release before qemu-img convert - #144
Merged
Merged
Conversation
|
@imlk0 ,您好,您的请求已接收,请耐心等待结果。 |
|
@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。 |
qemu-nbd --disconnect returns before the nbd daemon finishes exiting and releases the OFD write lock it holds on the backing image. The previous fixed "sleep 2" guard at step 11 was a race: under load (e.g. CI containers) qemu-img convert intermittently failed with qemu-img: Could not open '...input.qcow2.work': Failed to get shared "write" lock Polling blockdev --getsize64 is not a reliable fix either — the device reports size 0 while the daemon still holds the file lock, so the poll exits immediately and the race is back (reproduced on PR CI). Replace the fixed sleep with disk::nbd_disconnect_and_wait, which polls lsof on the image file: once no process holds it open the daemon has exited and the lock is released. Bounded by interval + max attempts so it never blocks forever. qemu-img convert then runs once the lock is truly gone. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
imlk0
force-pushed
the
fix-nbd-disconnect-race
branch
from
September 29, 2026 04:50
a3aa5ad to
29c39b2
Compare
|
@imlk0 ,您好,您的请求已接收,请耐心等待结果。 |
|
@imlk0 ,您好,未检测到有镜像需要构建,如需重新检测请评论 /start 。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
test-convertintermittently fails at step 11 with:Example failing run: https://github.com/openanolis/cryptpilot/actions/runs/36511833625/job/109231935489
Root cause
At step 11 (
cryptpilot-convert.sh), the nbd device was detached with a fixed guard:qemu-nbd --disconnectreturns before the nbd daemon finishes exiting and releases the OFD write lock it holds on the backing image. The fixedsleep 2covers it most of the time but is a race: under CI load the lock can still be held whenqemu-img convertopens the image, so it bails out.A first attempt polled
blockdev --getsize64(== 0 means free device). That is not a reliable signal — confirmed on this PR's own CI, the device reports size 0 within the same millisecond as--disconnectwhile the daemon still holds the file lock, so the poll exits immediately and the race is back.Fix
Replace the fixed sleep with
disk::nbd_disconnect_and_wait, which disconnects and then pollslsofon the image file (lsof -t "${image}"): once no process holds the file open, the daemon has exited and the OFD write lock is released.qemu-img convertonly runs after the lock is truly gone. The loop is bounded by interval + max attempts (never blocks forever); on timeout it warns and proceeds rather than hard-failing.lsofis already installed by the test harness (tool_packages=(qemu-img cryptsetup veritysetup lvm2 parted e2fsprogs lsof ...)).Assisted-by
Assisted-by: Claude:claude-opus-4-8