Skip to content

Commit 2f349bd

Browse files
authored
Merge pull request #522 from masnax/dependent-vols
Support dependent volumes
2 parents 471b020 + 7e8a0b3 commit 2f349bd

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

internal/target/incus.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,8 @@ func (t *InternalIncusTarget) SetupVM(ctx context.Context, instDef migration.Ins
634634

635635
tgtClient := t.incusClient.UseTarget(instInfo.Location)
636636
defaultDiskDef := map[string]string{
637-
"type": "disk",
637+
"type": "disk",
638+
"dependent": "true",
638639
}
639640

640641
// Create volumes for the remaining disks.
@@ -729,12 +730,30 @@ func (t *InternalIncusTarget) CleanupVM(ctx context.Context, name string, requir
729730
return fmt.Errorf("Failed to wait for delete operation for instance %q: %w", name, err)
730731
}
731732

732-
tgtClient := t.incusClient.UseTarget(instInfo.Location)
733+
volsByPool := map[string]map[string]bool{}
733734
for _, dev := range instInfo.Devices {
734-
if dev["type"] == "disk" && dev["user.migration_source"] != "" && dev["source"] != "" {
735-
err := tgtClient.DeleteStoragePoolVolume(dev["pool"], "custom", dev["source"])
736-
if err != nil {
737-
return fmt.Errorf("Failed to delete instance %q storage volume %q on pool %q: %w", name, dev["source"], dev["pool"], err)
735+
if dev["type"] == "disk" && dev["user.migration_source"] != "" && dev["source"] != "" && dev["pool"] != "" {
736+
if volsByPool[dev["pool"]] == nil {
737+
volsByPool[dev["pool"]] = map[string]bool{}
738+
}
739+
740+
volsByPool[dev["pool"]][dev["source"]] = true
741+
}
742+
}
743+
744+
tgtClient := t.incusClient.UseTarget(instInfo.Location)
745+
for pool, volsByName := range volsByPool {
746+
volNames, err := tgtClient.GetStoragePoolVolumeNames(pool)
747+
if err != nil {
748+
return fmt.Errorf("Failed to find %q volumes for instance %q: %w", pool, name, err)
749+
}
750+
751+
for _, vol := range volNames {
752+
if volsByName[vol] {
753+
err := tgtClient.DeleteStoragePoolVolume(pool, "custom", vol)
754+
if err != nil {
755+
return fmt.Errorf("Failed to delete instance %q storage volume %q on pool %q: %w", name, vol, pool, err)
756+
}
738757
}
739758
}
740759
}

ui/src/components/InstanceOverrides.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ const InstanceOverrides: FC = () => {
134134
values.distribution != instance?.distribution
135135
? values.distribution
136136
: "",
137-
distribution_version: values.distribution_version,
137+
distribution_version:
138+
values.distribution_version != instance?.distribution_version
139+
? values.distribution_version
140+
: "",
138141
started_after_migration: values.started_after_migration == "true",
139142
stopped_after_migration: values.stopped_after_migration == "true",
140143
};

0 commit comments

Comments
 (0)