From 52ca68d46e3f0ef3e1df8393ad8760ab5cf01efa Mon Sep 17 00:00:00 2001 From: Mathias Chapelain Date: Fri, 23 Aug 2024 15:32:56 +0200 Subject: [PATCH] osd: discover metadata and wal devices for raw device cleanup When doing the clean-up of raw device OSDs, it was not taking metadata and wal devices into account. This commit discover them via the output of `ceph-volume raw list`, which is returning `device_db` and/or `device_wal` if they are present. After discovering the metadata and wal device it also clean them and close the encrypted device if any. Signed-off-by: Mathias Chapelain --- pkg/daemon/ceph/cleanup/disk.go | 30 +++++++++++++++++++----------- pkg/daemon/ceph/osd/volume.go | 22 +++++++++++++++------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/pkg/daemon/ceph/cleanup/disk.go b/pkg/daemon/ceph/cleanup/disk.go index 484c48bf9557..e6d148a8cd85 100644 --- a/pkg/daemon/ceph/cleanup/disk.go +++ b/pkg/daemon/ceph/cleanup/disk.go @@ -179,21 +179,29 @@ func (s *DiskSanitizer) executeSanitizeCommand(osdInfo oposd.OSDInfo, wg *sync.W // On return, notify the WaitGroup that we’re done defer wg.Done() - output, err := s.context.Executor.ExecuteCommandWithCombinedOutput(shredUtility, s.buildShredArgs(osdInfo.BlockPath)...) - if err != nil { - logger.Errorf("failed to sanitize osd disk %q. %s. %v", osdInfo.BlockPath, output, err) - } + for _, device := range []string{osdInfo.BlockPath, osdInfo.MetadataPath, osdInfo.WalPath} { + if device == "" { + continue + } - logger.Infof("%s\n", output) - logger.Infof("successfully sanitized osd disk %q", osdInfo.BlockPath) + output, err := s.context.Executor.ExecuteCommandWithCombinedOutput(shredUtility, s.buildShredArgs(device)...) + + logger.Infof("%s\n", output) - // If the device is encrypted let's close it after sanitizing its content - if osdInfo.Encrypted { - err := osd.CloseEncryptedDevice(s.context, osdInfo.BlockPath) if err != nil { - logger.Errorf("failed to close encrypted osd disk %q. %v", osdInfo.BlockPath, err) + logger.Errorf("failed to sanitize osd disk %q. %s. %v", device, output, err) } else { - logger.Infof("successfully closed encrypted osd disk %q", osdInfo.BlockPath) + logger.Infof("successfully sanitized osd disk %q", device) + } + + // If the device is encrypted let's close it after sanitizing its content + if osdInfo.Encrypted { + err := osd.CloseEncryptedDevice(s.context, device) + if err != nil { + logger.Errorf("failed to close encrypted osd disk %q. %v", device, err) + } else { + logger.Infof("successfully closed encrypted osd disk %q", device) + } } } } diff --git a/pkg/daemon/ceph/osd/volume.go b/pkg/daemon/ceph/osd/volume.go index a01b67055e84..75029082b193 100644 --- a/pkg/daemon/ceph/osd/volume.go +++ b/pkg/daemon/ceph/osd/volume.go @@ -64,11 +64,13 @@ var ( ) type osdInfoBlock struct { - CephFsid string `json:"ceph_fsid"` - Device string `json:"device"` - OsdID int `json:"osd_id"` - OsdUUID string `json:"osd_uuid"` - Type string `json:"type"` + CephFsid string `json:"ceph_fsid"` + Device string `json:"device"` + DeviceDb string `json:"device_db"` + DeviceWal string `json:"device_wal"` + OsdID int `json:"osd_id"` + OsdUUID string `json:"osd_uuid"` + Type string `json:"type"` } type osdInfo struct { @@ -993,6 +995,8 @@ func GetCephVolumeRawOSDs(context *clusterd.Context, clusterInfo *client.Cluster // blockPath represents the path of the OSD block // it can be the one passed from the function's call or discovered by the c-v list command var blockPath string + var blockMetadataPath string + var blockWalPath string // If block is passed, check if it's an encrypted device, this is needed to get the correct // device path and populate the OSDInfo for that OSD @@ -1123,8 +1127,12 @@ func GetCephVolumeRawOSDs(context *clusterd.Context, clusterInfo *client.Cluster // If no block is specified let's take the one we discovered if setDevicePathFromList { blockPath = osdInfo.Device + blockMetadataPath = osdInfo.DeviceDb + blockWalPath = osdInfo.DeviceWal } else { blockPath = block + blockMetadataPath = metadataBlock + blockWalPath = walBlock } osdStore := osdInfo.Type @@ -1139,8 +1147,8 @@ func GetCephVolumeRawOSDs(context *clusterd.Context, clusterInfo *client.Cluster // Thus in the activation sequence we might activate the wrong OSD and have OSDInfo messed up // Hence, let's use the PVC name instead which will always remain consistent BlockPath: blockPath, - MetadataPath: metadataBlock, - WalPath: walBlock, + MetadataPath: blockMetadataPath, + WalPath: blockWalPath, SkipLVRelease: true, LVBackedPV: lvBackedPV, CVMode: cvMode,