Skip to content

Commit

Permalink
lxd/instance_post: Prevent live migration of instances with custom vo…
Browse files Browse the repository at this point in the history
…lumes

Signed-off-by: Din Music <din.music@canonical.com>
  • Loading branch information
MusicDin committed Jan 17, 2024
1 parent 6605050 commit 0f577b5
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lxd/instance_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/canonical/lxd/lxd/db"
dbCluster "github.com/canonical/lxd/lxd/db/cluster"
"github.com/canonical/lxd/lxd/db/operationtype"
"github.com/canonical/lxd/lxd/device"
"github.com/canonical/lxd/lxd/instance"
"github.com/canonical/lxd/lxd/instance/instancetype"
"github.com/canonical/lxd/lxd/operations"
Expand Down Expand Up @@ -618,7 +619,7 @@ func instancePostMigration(s *state.State, inst instance.Instance, newName strin
return nil
}

// Move a non-ceph container to another cluster node.
// Move an instnace to another cluster node. Source and target members must be online.
func instancePostClusteringMigrate(s *state.State, r *http.Request, srcPool storagePools.Pool, srcInst instance.Instance, newInstName string, srcMember db.NodeInfo, newMember db.NodeInfo, stateful bool, allowInconsistent bool) (func(op *operations.Operation) error, error) {
srcMemberOffline := srcMember.IsOffline(s.GlobalConfig.OfflineThreshold())

Expand All @@ -629,7 +630,7 @@ func instancePostClusteringMigrate(s *state.State, r *http.Request, srcPool stor
}

// Save the original value of the "volatile.apply_template" config key,
// since we'll want to preserve it in the copied container.
// since we'll want to preserve it in the copied instance.
origVolatileApplyTemplate := srcInst.LocalConfig()["volatile.apply_template"]

// Check we can convert the instance to the volume types needed.
Expand Down Expand Up @@ -956,7 +957,25 @@ func migrateInstance(s *state.State, r *http.Request, inst instance.Instance, ta
return err
}

// Check if we are migrating a ceph-based instance.
// In case of live migration, ensure all instance disks can be migrated.
if req.Live && inst.IsRunning() {
volatileGet := func() map[string]string { return map[string]string{} }
volatileSet := func(_ map[string]string) error { return nil }
for deviceName, rawConfig := range inst.ExpandedDevices() {
dev, err := device.New(inst, s, deviceName, rawConfig, volatileGet, volatileSet)
if err != nil {
return err
}

devConfig := dev.Config()

if devConfig["type"] == "disk" && !shared.IsRootDiskDevice(devConfig) {
return fmt.Errorf("Cannot live migrate instance with attached custom volume")
}
}
}

// Retrieve storage pool of the source instance.
srcPool, err := storagePools.LoadByInstance(s, inst)
if err != nil {
return fmt.Errorf("Failed loading instance storage pool: %w", err)
Expand Down

0 comments on commit 0f577b5

Please sign in to comment.