Skip to content

Commit b2def4c

Browse files
Merge pull request rook#17123 from sp98/fix-forceful-osd-deletion
osd: check devlinks while cleaning osd disks
2 parents b8b149f + 475fc7c commit b2def4c

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

pkg/daemon/ceph/osd/volume.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"path"
2626
"path/filepath"
2727
"regexp"
28+
"slices"
2829
"strconv"
2930
"strings"
3031

@@ -975,8 +976,12 @@ func getOSDDiskToBeWiped(context *clusterd.Context, existingOSDDevice string) (*
975976

976977
var osdDisk *sys.LocalDisk
977978
for _, desiredDevice := range context.Devices {
978-
if desiredDevice.RealPath == existingOSDDevice {
979+
// Also check DevLinks since ceph-volume may report a symlink path
980+
// (e.g. /dev/rhel/ceph-data) that differs from RealPath
981+
// (e.g. /dev/mapper/rhel-ceph--data)
982+
if desiredDevice.RealPath == existingOSDDevice || slices.Contains(strings.Split(desiredDevice.DevLinks, " "), existingOSDDevice) {
979983
osdDisk = desiredDevice
984+
break
980985
}
981986
}
982987
return osdDisk, encryptedBlock, nil

pkg/daemon/ceph/osd/volume_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,19 @@ var cephVolumeRawPartitionTestResult = `{
301301
}
302302
}`
303303

304+
// ceph-volume raw list reports the device via an LVM symlink (/dev/rhel/ceph-data)
305+
// while the inventory RealPath is /dev/mapper/rhel-ceph--data.
306+
var cephVolumeRAWLVMSymlinkTestResult = `{
307+
"0": {
308+
"ceph_fsid": "4bfe8b72-5e69-4330-b6c0-4d914db8ab89",
309+
"device": "/dev/rhel/ceph-data",
310+
"osd_id": 0,
311+
"osd_uuid": "c03d7353-96e5-4a41-98de-830dfff97d06",
312+
"type": "bluestore"
313+
}
314+
}
315+
`
316+
304317
func createPVCAvailableDevices() *DeviceOsdMapping {
305318
devices := &DeviceOsdMapping{
306319
Entries: map[string]*DeviceOsdIDEntry{
@@ -2282,4 +2295,35 @@ func TestWipeDevicesFromOtherClusters(t *testing.T) {
22822295
context.Executor = executor
22832296
err = agent.WipeDevicesFromOtherClusters(context)
22842297
assert.NoError(t, err)
2298+
2299+
// `ceph-volume raw list` returns an LVM symlink path (/dev/rhel/ceph-data) while
2300+
// the device RealPath is /dev/mapper/rhel-ceph--data. The device should still be
2301+
// matched via DevLinks and zapped.
2302+
executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) {
2303+
logger.Infof("%s %v", command, args)
2304+
if slices.Contains(args, "raw") && slices.Contains(args, "list") {
2305+
return cephVolumeRAWLVMSymlinkTestResult, nil
2306+
}
2307+
return "", errors.Errorf("unknown command %s %s", command, args)
2308+
}
2309+
executor.MockExecuteCommandWithCombinedOutput = func(command string, args ...string) (string, error) {
2310+
logger.Infof("%s %v", command, args)
2311+
devicePath := "/dev/mapper/rhel-ceph--data"
2312+
if slices.Contains(args, "zap") {
2313+
if !slices.Contains(args, devicePath) {
2314+
return "", errors.Errorf("expected device %s to be zapped but got %v", devicePath, args)
2315+
}
2316+
return "", nil
2317+
}
2318+
return "", errors.Errorf("unknown command %s %s", command, args)
2319+
}
2320+
context = &clusterd.Context{
2321+
Devices: []*sys.LocalDisk{{
2322+
RealPath: "/dev/mapper/rhel-ceph--data",
2323+
DevLinks: "/dev/rhel/ceph-data /dev/disk/by-id/dm-name-rhel-ceph--data /dev/mapper/rhel-ceph--data",
2324+
}},
2325+
}
2326+
context.Executor = executor
2327+
err = agent.WipeDevicesFromOtherClusters(context)
2328+
assert.NoError(t, err)
22852329
}

0 commit comments

Comments
 (0)