Skip to content

Commit

Permalink
Merge pull request #133 from raharper/test/add-test-for-virt-ssd-hint
Browse files Browse the repository at this point in the history
Fix regression where non-raid attached disks did not determine correct disk type
  • Loading branch information
hallyn authored Feb 22, 2024
2 parents 7b7d307 + 749ccdd commit 247dd95
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
33 changes: 33 additions & 0 deletions linux/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,39 @@ func TestGetAttachType(t *testing.T) {
}))
}

func TestGetDiskType(t *testing.T) {
assert := assert.New(t)
systemVirtType = virtKvm
result, err := getDiskType(disko.UdevInfo{
Name: "vdb",
SysPath: "/devices/pci0000:00/0000:00:03.0/virtio1/block/vdb",
Properties: map[string]string{
"DEVLINKS": "/dev/disk/by-path/pci-0000:00:03.0 /dev/disk/by-path/virtio-pci-0000:00:03.0 /dev/disk/by-id/virtio-ssd-disk0-ssd",
"DEVNAME": "/dev/vdb",
"DEVPATH": "/devices/pci0000:00/0000:00:03.0/virtio1/block/vdb",
"DEVTYPE": "disk",
"DISKSEQ": "42",
"ID_PATH": "pci-0000:00:03.0",
"ID_PATH_TAG": "pci-0000_00_03_0",
"ID_SERIAL": "ssd-disk0-ssd",
"MAJOR": "253",
"MINOR": "16",
"SUBSYSTEM": "block",
"USEC_INITIALIZED": "2422574",
},
Symlinks: []string{
"disk/by-diskseq/42",
"disk/by-path/pci-0000:00:03.0",
"disk/by-path/virtio-pci-0000:00:03.0",
"disk/by-id/virtio-ssd-disk0-ssd",
},
})
if err != nil {
t.Errorf("expected err = nil, got %s", err)
}
assert.Equal(disko.SSD.String(), result.String())
}

func genTempGptDisk(tmpd string, fsize uint64) (disko.Disk, error) {
fpath := path.Join(tmpd, "mydisk")

Expand Down
8 changes: 8 additions & 0 deletions linux/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ func (ls *linuxSystem) ScanDisk(devicePath string) (disko.Disk, error) {
}
}

// check disk type if it wasn't on raid
if attachType != disko.RAID {
diskType, err = getDiskType(udInfo)
if err != nil {
return disko.Disk{}, fmt.Errorf("error while getting disk type: %s", err)
}
}

ro, err = getDiskReadOnly(name)
if err != nil {
return disko.Disk{}, err
Expand Down

0 comments on commit 247dd95

Please sign in to comment.