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 <mathias.chapelain@proton.ch>
This commit is contained in:
Mathias Chapelain committed 2024-08-29 08:47:32 +02:00
1 parent 5218e1d70e
commit 52ca68d46e
2 files changed
+34 -18

No files matched your search

+19 -11
View File
@@ -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)
}
}
}
}
+15 -7
View File
@@ -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,