From efb24e609a57ade676fa1caa5a5e169f476ad3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 19 Feb 2024 21:11:58 -0500 Subject: [PATCH] incusd/instances: Generalize Ceph logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber --- cmd/incusd/instance_post.go | 20 ++++++++++---------- cmd/incusd/instances_post.go | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/incusd/instance_post.go b/cmd/incusd/instance_post.go index 12b23d305e8..459de607881 100644 --- a/cmd/incusd/instance_post.go +++ b/cmd/incusd/instance_post.go @@ -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. @@ -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 } diff --git a/cmd/incusd/instances_post.go b/cmd/incusd/instances_post.go index 7cadc36f7f7..8b8236dfc70 100644 --- a/cmd/incusd/instances_post.go +++ b/cmd/incusd/instances_post.go @@ -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"] @@ -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) }