Skip to content

Commit

Permalink
add multipath device support
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBednar committed Apr 27, 2023
1 parent 2acbaee commit c8b6b5e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/localvolumediscovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
PartType DiscoveredDeviceType = "part"
// LVMType is an LVM type
LVMType DiscoveredDeviceType = "lvm"
// MultiPathType is a multipath type
MultiPathType DiscoveredDeviceType = "mpath"
)

// LocalVolumeDiscoverySpec defines the desired state of LocalVolumeDiscovery
Expand Down
8 changes: 7 additions & 1 deletion diskmaker/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ func getDiscoverdDevices(blockDevices []internal.BlockDevice) []v1alpha1.Discove
klog.Warningf("failed to parse size for the device %q. Error %v", blockDevice.Name, err)
}

path, err := blockDevice.GetDevPath()
if err != nil {
klog.Warningf("failed to parse path for the device %q. Error %v", blockDevice.KName, err)
}
discoveredDevice := v1alpha1.DiscoveredDevice{
Path: fmt.Sprintf("/dev/%s", blockDevice.Name),
Path: path,
Model: blockDevice.Model,
Vendor: blockDevice.Vendor,
FSType: blockDevice.FSType,
Expand Down Expand Up @@ -308,6 +312,8 @@ func parseDeviceType(deviceType string) v1alpha1.DiscoveredDeviceType {
return v1alpha1.PartType
case deviceType == "lvm":
return v1alpha1.LVMType
case deviceType == "mpath":
return v1alpha1.MultiPathType
}

return ""
Expand Down
4 changes: 2 additions & 2 deletions diskmaker/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func TestGetDiscoveredDevices(t *testing.T) {
{
Name: "sda",
KName: "dm-0",
FSType: "xfs",
FSType: "",
Type: "mpath",
Size: "62913494528",
Model: "",
Expand All @@ -494,7 +494,7 @@ func TestGetDiscoveredDevices(t *testing.T) {
Serial: "",
Size: int64(62913494528),
Property: "NonRotational",
FSType: "xfs",
FSType: "",
Status: v1alpha1.DeviceStatus{State: v1alpha1.NotAvailable},
},
},
Expand Down
12 changes: 9 additions & 3 deletions internal/diskutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
StateSuspended = "suspended"
// DiskByIDDir is the path for symlinks to the device by id.
DiskByIDDir = "/dev/disk/by-id/"
// DiskDMDir is the path for symlinks of device mapper disks (e.g. mpath)
DiskDMDir = "/dev/mapper/"
)

// IDPathNotFoundError indicates that a symlink to the device was not found in /dev/disk/by-id/
Expand Down Expand Up @@ -146,11 +148,15 @@ func (b BlockDevice) HasBindMounts() (bool, string, error) {
}

// GetDevPath for block device (/dev/sdx)
func (b BlockDevice) GetDevPath() (string, error) {
func (b BlockDevice) GetDevPath() (path string, err error) {
if b.KName == "" {
return "", fmt.Errorf("empty KNAME")
path = ""
err = fmt.Errorf("empty KNAME")
}
return filepath.Join("/dev/", b.KName), nil

path = filepath.Join("/dev/", b.KName)

return
}

// GetPathByID check on BlockDevice
Expand Down

0 comments on commit c8b6b5e

Please sign in to comment.