Skip to content

Commit

Permalink
incusd/instances: Generalize Ceph logic
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Feb 20, 2024
1 parent fae09a1 commit efb24e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions cmd/incusd/instance_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,17 +873,17 @@ func instancePostClusteringMigrate(s *state.State, r *http.Request, srcPool stor
return run, nil
}

// instancePostClusteringMigrateWithCeph handles moving a ceph instance from a source member that is offline.
// instancePostClusteringMigrateRemoteStorage handles moving an instance from a source member that is offline.
// This function must be run on the target cluster member to move the instance to.
func instancePostClusteringMigrateWithCeph(s *state.State, r *http.Request, srcPool storagePools.Pool, srcInst instance.Instance, newInstName string, newMember db.NodeInfo, stateful bool) (func(op *operations.Operation) error, error) {
// Sense checks to avoid unexpected behaviour.
if srcPool.Driver().Info().Name != "ceph" {
return nil, fmt.Errorf("Source instance's storage pool is not of type ceph")
func instancePostClusteringMigrateRemoteStorage(s *state.State, r *http.Request, srcPool storagePools.Pool, srcInst instance.Instance, newInstName string, newMember db.NodeInfo, stateful bool) (func(op *operations.Operation) error, error) {
// Quick checks to avoid unexpected behaviour.
if !srcPool.Driver().Info().Remote {
return nil, fmt.Errorf("Source instance's storage pool is not remote")
}

// Check this function is only run on the target member.
if s.ServerName != newMember.Name {
return nil, fmt.Errorf("Ceph instance move when source member is offline must be run on target member")
return nil, fmt.Errorf("Remote instance move when source member is offline must be run on target member")
}

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

// Check if we are migrating a ceph-based instance.
// Check if we are migrating a remote instance.
srcPool, err := storagePools.LoadByInstance(s, inst)
if err != nil {
return fmt.Errorf("Failed loading instance storage pool: %w", err)
}

// Only use instancePostClusteringMigrateWithCeph when source member is offline.
if srcMember.IsOffline(s.GlobalConfig.OfflineThreshold()) && srcPool.Driver().Info().Name == "ceph" {
f, err := instancePostClusteringMigrateWithCeph(s, r, srcPool, inst, req.Name, newMember, req.Live)
// Only use instancePostClusteringMigrateRemoteStorage when source member is offline.
if srcMember.IsOffline(s.GlobalConfig.OfflineThreshold()) && srcPool.Driver().Info().Remote {
f, err := instancePostClusteringMigrateRemoteStorage(s, r, srcPool, inst, req.Name, newMember, req.Live)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/incusd/instances_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func createFromCopy(s *state.State, r *http.Request, projectName string, profile
serverName := s.ServerName

if serverName != source.Location() {
// Check if we are copying from a ceph-based container.
// Check if we are copying from a remote storage instance.
_, rootDevice, _ := internalInstance.GetRootDiskDevice(source.ExpandedDevices().CloneNative())
sourcePoolName := rootDevice["pool"]

Expand All @@ -468,7 +468,7 @@ func createFromCopy(s *state.State, r *http.Request, projectName string, profile
return response.SmartError(err)
}

if pool.Driver != "ceph" {
if !util.ValueInSlice(pool.Driver, db.StorageRemoteDriverNames()) {
// Redirect to migration
return clusterCopyContainerInternal(s, r, source, projectName, profiles, req)
}
Expand Down

0 comments on commit efb24e6

Please sign in to comment.