Skip to content

Commit

Permalink
v2 volume: prevent from errors in spdk_tgt when deleting a volume
Browse files Browse the repository at this point in the history
To prevent from the "no such device" error in spdk_tgt when deleting a volume,
remove the raid bdev before tearing down the replicas.

Longhorn 7568

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit authored and David Ko committed Jan 8, 2024
1 parent e5f7071 commit 1a206d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion controller/setting_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ func (sc *SettingController) cleanupInstanceManager(dataEngine longhorn.DataEngi
}

for _, im := range imMap {
sc.logger.Infof("Cleaning up the instance manager for %v data engine", dataEngine)
sc.logger.Infof("Cleaning up the instance manager %v for %v data engine", im.Name, dataEngine)
if err := sc.ds.DeleteInstanceManager(im.Name); err != nil {
return err
}
Expand Down
23 changes: 23 additions & 0 deletions controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,29 @@ func (c *VolumeController) syncVolume(key string) (err error) {
}
}
}
if datastore.IsDataEngineV2(volume.Spec.DataEngine) {
// To prevent from the "no such device" error in spdk_tgt,
// remove the raid bdev before tearing down the replicas.
engines, err := c.ds.ListVolumeEnginesRO(volume.Name)
if err != nil {
return err
}
if len(engines) > 0 {
replicaDeleted := false
for _, r := range replicas {
if r.DeletionTimestamp != nil {
replicaDeleted = true
break
}
}
if !replicaDeleted {
c.logger.Infof("Volume (%s) %v still has engines %v, so skip deleting its replicas until the engines have been deleted",
volume.Spec.DataEngine, volume.Name, engines)
return nil
}
}
}

for _, r := range replicas {
if r.DeletionTimestamp == nil {
if err := c.ds.DeleteReplica(r.Name); err != nil {
Expand Down

0 comments on commit 1a206d9

Please sign in to comment.