osd: remove stale dm device during osd-prepare-job

During osd-prepare-job,

The encrypted device is found to be closed in some cases when
the OSD deployment has been removed manually accompanied
by any of following cases:
- node reboot
- csi managed PVC being unmounted etc

while re-opening the block to re-hydrate the OSDInfo,
the dm device `<pvc-name>-block-dmcrypt` clashes with
the one used by OSD pod which is stale by now.
This commit adds cmd to remove this stale dm device.
Error with output "No such device" is ignored.

Signed-off-by: Rakshith R <rar@redhat.com>
(cherry picked from commit 24fa9ed935)
This commit is contained in:
Rakshith R authored and Mergify committed 2022-12-08 18:26:46 +00:00
1 parent 16aa094fde
commit 69d628ce9b
2 files changed
+21 -3

No files matched your search

+16 -3
View File
@@ -33,9 +33,10 @@ import (
)
const (
cryptsetupBinary = "cryptsetup"
dmsetupBinary = "dmsetup"
luksOpenCmdTimeOut = 90 * time.Second
cryptsetupBinary = "cryptsetup"
dmsetupBinary = "dmsetup"
luksOpenCmdTimeOut = 90 * time.Second
removeEncryptedDeviceCmdTimeOut = 30 * time.Second
)
var (
@@ -172,6 +173,18 @@ func openEncryptedDevice(context *clusterd.Context, disk, target, passphrase str
return nil
}
func removeEncryptedDevice(context *clusterd.Context, target string) error {
args := []string{"remove", "--force", target}
output, err := context.Executor.ExecuteCommandWithTimeout(removeEncryptedDeviceCmdTimeOut, "dmsetup", args...)
// ignore error if no device was found.
if err != nil {
return errors.Wrapf(err, "failed to remove dm device %q: %q", target, output)
}
logger.Debugf("successfully removed stale dm device %q", target)
return nil
}
func isCephEncryptedBlock(context *clusterd.Context, currentClusterFSID string, disk string) bool {
metadata, err := dumpLUKS(context, disk)
if err != nil {
+5
View File
@@ -974,6 +974,11 @@ func GetCephVolumeRawOSDs(context *clusterd.Context, clusterInfo *client.Cluster
}
target := oposd.EncryptionDMName(pvcName, oposd.DmcryptBlockType)
// remove stale dm device left by previous OSD.
err = removeEncryptedDevice(context, target)
if err != nil {
logger.Warningf("failed to remove stale dm device %q: %q", target, err)
}
err = openEncryptedDevice(context, block, target, passphrase)
if err != nil {
return nil, errors.Wrapf(err, "failed to open encrypted block device %q on %q", block, target)