fix(proxmox): stop leaking unused disks on reinstall#140
Merged
Conversation
Repeated/retried reinstalls imported into an already-populated scsi0 slot, causing Proxmox to move the previous disk to an unused[n] config entry instead of deleting it. With the reinstall pipeline's retry policy these accumulated indefinitely (observed 62 unused disks on one VM). - import_disk now force-removes scsi0 + any unused[n] before importing, making import idempotent across retries (covers create + reinstall) - unlink_primary_disk sweeps unused[n] alongside scsi0 - new delete_unused_disks trait method (Proxmox removes only unused[n], never the live scsi0) is run for every live VM in the periodic patch_host flow to clean up already-accumulated orphans Adds get_vm_config_raw to read dynamic unused[n] keys and regression tests for the cleanup logic.
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.
Fixes #94
During VM reinstall on Proxmox hosts, a lot of
unused[n]disks were being left attached to VMs (observed 62 on VM 1100).Root cause
The reinstall pipeline imports the template disk into
scsi0viaqm set --scsi0 <storage>:0,import-from=.... Whenscsi0is still populated, Proxmox moves the existing disk to anunused[n]config entry instead of deleting it. Because the pipeline has a retry policy, a transient failure re-runs the import step and orphans the previous disk each time — so they accumulate indefinitely.Fix
import_disknow force-removesscsi0+ anyunused[n]before importing, making the import idempotent across retries (covers both the create and reinstall pipelines).unlink_primary_disksweepsunused[n]alongsidescsi0.delete_unused_diskstrait method (default no-op; Proxmox removes onlyunused[n], never the livescsi0) is run for every live VM in the periodicpatch_hostflow, so already-accumulated orphans across all VMs/hosts get cleaned up automatically over time.get_vm_config_rawto read dynamicunused[n]keys (the typedVmConfigdrops them).Tests
test_cleanup_vm_disks_removes_unused— asserts onlyunused[n](notscsi0) are force-unlinked.test_cleanup_vm_disks_noop_when_nothing_to_remove— no unlink request when nothing to clean.Manual remediation
For already-affected VMs, remove the orphans on the host:
No API surface change.