Skip to content

Commit 73fe337

Browse files
committed
fix: logic to detect attached disks.
Move from counting disks with valid partitions to disk bus type.
1 parent f3b0187 commit 73fe337

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

internal/driver/limits.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,11 @@ func attachedVolumeCount(hw hwinfo.HardwareInfo) (int, error) {
4444
count := 0
4545
for _, disk := range bdev.Disks {
4646
driveType := strings.ToLower(disk.DriveType.String())
47-
// Skip loopbacks, virtual devices, CD-ROMs, and removable drives
48-
if disk.IsRemovable || driveType == "virtual" || driveType == "cdrom" {
47+
controllerType := strings.ToLower(disk.StorageController.String())
48+
if driveType == "virtual" || driveType == "cdrom" || controllerType == "loop" || controllerType == "unknown" {
4949
continue
5050
}
51-
52-
// Only consider disks that have partitions and aren't read-only
53-
if len(disk.Partitions) > 0 {
54-
count++
55-
}
51+
count++
5652
}
5753
return count, nil
5854
}

internal/driver/limits_test.go

+25-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/jaypipes/ghw"
8+
"github.com/jaypipes/ghw/pkg/block"
89
"go.uber.org/mock/gomock"
910

1011
"github.com/linode/linode-blockstorage-csi-driver/mocks"
@@ -67,8 +68,9 @@ func TestAttachedVolumeCount(t *testing.T) {
6768
blkInfo: &ghw.BlockInfo{
6869
Disks: []*ghw.Disk{
6970
{
70-
DriveType: DRIVE_TYPE_VIRTUAL,
71-
IsRemovable: false,
71+
DriveType: DRIVE_TYPE_VIRTUAL,
72+
StorageController: block.StorageControllerUnknown,
73+
IsRemovable: false,
7274
Partitions: []*ghw.Partition{
7375
{
7476
Name: "vd1p1",
@@ -77,6 +79,18 @@ func TestAttachedVolumeCount(t *testing.T) {
7779
},
7880
},
7981
},
82+
{
83+
DriveType: DRIVE_TYPE_VIRTUAL,
84+
StorageController: block.StorageControllerLoop,
85+
IsRemovable: false,
86+
Partitions: []*ghw.Partition{
87+
{
88+
Name: "loop1",
89+
MountPoint: "/mnt/virtual1",
90+
SizeBytes: 1024 * 1024 * 1024,
91+
},
92+
},
93+
},
8094
},
8195
},
8296
},
@@ -86,8 +100,9 @@ func TestAttachedVolumeCount(t *testing.T) {
86100
blkInfo: &ghw.BlockInfo{
87101
Disks: []*ghw.Disk{
88102
{
89-
DriveType: DRIVE_TYPE_VIRTUAL,
90-
IsRemovable: false,
103+
DriveType: DRIVE_TYPE_VIRTUAL,
104+
IsRemovable: false,
105+
StorageController: block.StorageControllerUnknown,
91106
Partitions: []*ghw.Partition{
92107
{
93108
Name: "vd1p1",
@@ -97,8 +112,9 @@ func TestAttachedVolumeCount(t *testing.T) {
97112
},
98113
},
99114
{
100-
DriveType: DRIVE_TYPE_VIRTUAL,
101-
IsRemovable: false,
115+
DriveType: DRIVE_TYPE_VIRTUAL,
116+
IsRemovable: false,
117+
StorageController: block.StorageControllerLoop,
102118
Partitions: []*ghw.Partition{
103119
{
104120
Name: "loop1",
@@ -108,8 +124,9 @@ func TestAttachedVolumeCount(t *testing.T) {
108124
},
109125
},
110126
{
111-
DriveType: DRIVE_TYPE_SSD,
112-
IsRemovable: false,
127+
DriveType: DRIVE_TYPE_SSD,
128+
IsRemovable: false,
129+
StorageController: block.StorageControllerSCSI,
113130
Partitions: []*ghw.Partition{
114131
{
115132
Name: "nvme0n1",

internal/driver/nodeserver_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/container-storage-interface/spec/lib/go/csi"
1111
"github.com/jaypipes/ghw"
12+
"github.com/jaypipes/ghw/pkg/block"
1213
"go.uber.org/mock/gomock"
1314
"k8s.io/mount-utils"
1415
"k8s.io/utils/exec"
@@ -733,8 +734,9 @@ func TestNodeGetInfo(t *testing.T) {
733734
blkInfo: &ghw.BlockInfo{
734735
Disks: []*ghw.Disk{
735736
{
736-
DriveType: ghw.DRIVE_TYPE_SSD,
737-
IsRemovable: false,
737+
DriveType: ghw.DRIVE_TYPE_SSD,
738+
IsRemovable: false,
739+
StorageController: block.StorageControllerSCSI,
738740
Partitions: []*ghw.Partition{
739741
{
740742
Name: "sda",

0 commit comments

Comments
 (0)