Skip to content

Commit 475fc7c

Browse files
committed
osd: check devlinks while cleaning osd disks
In getOSDDiskToBeWiped(), when the RealPath doesn't match the device path reported by ceph-volume, also check each entry in the space-separated DevLinks string. This handles the case where ceph-volume raw list reports an LVM symlink (e.g. /dev/rhel/ceph-data) that differs from the resolved RealPath (e.g. /dev/mapper/rhel-ceph--data). Signed-off-by: Santosh <sapillai@redhat.com>
1 parent b0ae620 commit 475fc7c

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

@@ -968,8 +969,12 @@ func getOSDDiskToBeWiped(context *clusterd.Context, existingOSDDevice string) (*
968969

969970
var osdDisk *sys.LocalDisk
970971
for _, desiredDevice := range context.Devices {
971-
if desiredDevice.RealPath == existingOSDDevice {
972+
// Also check DevLinks since ceph-volume may report a symlink path
973+
// (e.g. /dev/rhel/ceph-data) that differs from RealPath
974+
// (e.g. /dev/mapper/rhel-ceph--data)
975+
if desiredDevice.RealPath == existingOSDDevice || slices.Contains(strings.Split(desiredDevice.DevLinks, " "), existingOSDDevice) {
972976
osdDisk = desiredDevice
977+
break
973978
}
974979
}
975980
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{
@@ -2226,4 +2239,35 @@ func TestWipeDevicesFromOtherClusters(t *testing.T) {
22262239
context.Executor = executor
22272240
err = agent.WipeDevicesFromOtherClusters(context)
22282241
assert.NoError(t, err)
2242+
2243+
// `ceph-volume raw list` returns an LVM symlink path (/dev/rhel/ceph-data) while
2244+
// the device RealPath is /dev/mapper/rhel-ceph--data. The device should still be
2245+
// matched via DevLinks and zapped.
2246+
executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) {
2247+
logger.Infof("%s %v", command, args)
2248+
if slices.Contains(args, "raw") && slices.Contains(args, "list") {
2249+
return cephVolumeRAWLVMSymlinkTestResult, nil
2250+
}
2251+
return "", errors.Errorf("unknown command %s %s", command, args)
2252+
}
2253+
executor.MockExecuteCommandWithCombinedOutput = func(command string, args ...string) (string, error) {
2254+
logger.Infof("%s %v", command, args)
2255+
devicePath := "/dev/mapper/rhel-ceph--data"
2256+
if slices.Contains(args, "zap") {
2257+
if !slices.Contains(args, devicePath) {
2258+
return "", errors.Errorf("expected device %s to be zapped but got %v", devicePath, args)
2259+
}
2260+
return "", nil
2261+
}
2262+
return "", errors.Errorf("unknown command %s %s", command, args)
2263+
}
2264+
context = &clusterd.Context{
2265+
Devices: []*sys.LocalDisk{{
2266+
RealPath: "/dev/mapper/rhel-ceph--data",
2267+
DevLinks: "/dev/rhel/ceph-data /dev/disk/by-id/dm-name-rhel-ceph--data /dev/mapper/rhel-ceph--data",
2268+
}},
2269+
}
2270+
context.Executor = executor
2271+
err = agent.WipeDevicesFromOtherClusters(context)
2272+
assert.NoError(t, err)
22292273
}

0 commit comments

Comments
 (0)