Skip to content

fix(storage): roll back unmounted volumes on getBlockVolumes error - #860

Open
Anand-240 wants to merge 1 commit into
urunc-dev:mainfrom
Anand-240:fix/rollback-block-volumes-on-error
Open

fix(storage): roll back unmounted volumes on getBlockVolumes error#860
Anand-240 wants to merge 1 commit into
urunc-dev:mainfrom
Anand-240:fix/rollback-block-volumes-on-error

Conversation

@Anand-240

Copy link
Copy Markdown
Contributor

Description

getBlockVolumes unmounts host bind mounts one at a time so they can be handed to the guest as block devices. The problem is that if any mount after the first one fails during that process (bad mountinfo, autoclear flag change fails, or the unmount itself fails), the function bails out immediately and throws away the list of volumes it had already unmounted. Those earlier mounts just stay detached on the host, and since create fails before state.json gets written, delete doesn't even know they exist to restore them.

This PR adds rollbackBlockVolumes, which restores whatever was already unmounted (reusing the existing restoreBlockVolumes logic) before the error is returned. It also covers the case where the autoclear flag got cleared on a device but the unmount call itself failed, by restoring that flag directly.

Related issues

How was this tested?

  • gofmt -l clean
  • Built and vetted with GOOS=linux GOARCH=amd64 (no build/vet issues)
  • Added two unit tests for rollbackBlockVolumes covering the no-op case and volumes without a host mountpoint
  • Didn't have a Linux box handy to run the full make test_unikontainers / e2e suite, so leaving that to CI

LLM usage

Used Claude to help track down the bug and put this fix together, reviewed and tested everything myself before opening this.

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

getBlockVolumes unmounts each supported bind-mounted block volume from
the host one at a time. If any mount after the first failed to
process (a later getMountInfo error, a failed setLoopAutoclear, or a
failed mount.Unmount), the function returned immediately and dropped
the list of volumes it had already unmounted. Those earlier host
mounts were never restored, and since create failed before state.json
was written, delete had no record of them either. The result was
host bind mounts left permanently detached after a single transient
failure during container creation.

Add rollbackBlockVolumes, which restores any already-unmounted volumes
via the existing restoreBlockVolumes helper before an error is
returned from getBlockVolumes. Also handle the case where the
autoclear flag was cleared on a device but its unmount still failed,
by restoring the flag directly for that entry.

Fixes: urunc-dev#859
Signed-off-by: Anand-240 <srivastavaanandprakash16@gmail.com>
@netlify

netlify Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit 15d39a8
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a69f62a283f9c000734941b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Partial host-mount unmounts in getBlockVolumes are silently discarded on error, permanently orphaning already-unmounted block volumes

1 participant