Skip to content

Commit

Permalink
Fix store type back to loop and a possible test issue
Browse files Browse the repository at this point in the history
Set back the storage controller to identify loop devices and try to fix
a potential problem with running the generic block tests in a host with
loop devices.

Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Apr 3, 2022
1 parent e75e68f commit 7e3184b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const (
STORAGE_CONTROLLER_NVME // Non-volatile Memory Express
STORAGE_CONTROLLER_VIRTIO // Virtualized storage controller/driver
STORAGE_CONTROLLER_MMC // Multi-media controller (used for mobile phone storage devices)
STORAGE_CONTROLLER_VIRTUAL // virtual controller, i.e. for a loop device
STORAGE_CONTROLLER_LOOP // loop device
)

var (
Expand All @@ -107,7 +107,7 @@ var (
STORAGE_CONTROLLER_NVME: "NVMe",
STORAGE_CONTROLLER_VIRTIO: "virtio",
STORAGE_CONTROLLER_MMC: "MMC",
STORAGE_CONTROLLER_VIRTUAL: "virtual",
STORAGE_CONTROLLER_LOOP: "loop",
}

// NOTE(fromani): the keys are all lowercase and do not match
Expand All @@ -122,7 +122,7 @@ var (
"nvme": STORAGE_CONTROLLER_NVME,
"virtio": STORAGE_CONTROLLER_VIRTIO,
"mmc": STORAGE_CONTROLLER_MMC,
"virtual": STORAGE_CONTROLLER_VIRTUAL,
"loop": STORAGE_CONTROLLER_LOOP,
}
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/block/block_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func disks(ctx *context.Context, paths *linuxpath.Paths) []*Disk {
wwn := diskWWN(paths, dname)
removable := diskIsRemovable(paths, dname)

if storageController == STORAGE_CONTROLLER_VIRTUAL && size == 0 {
if storageController == STORAGE_CONTROLLER_LOOP && size == 0 {
// We don't care about unused loop devices...
continue
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func diskTypes(dname string) (
storageController = STORAGE_CONTROLLER_MMC
} else if strings.HasPrefix(dname, "loop") {
driveType = DRIVE_TYPE_VIRTUAL
storageController = STORAGE_CONTROLLER_VIRTUAL
storageController = STORAGE_CONTROLLER_LOOP
}

return driveType, storageController
Expand Down
2 changes: 1 addition & 1 deletion pkg/block/block_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestDiskTypes(t *testing.T) {
line: "loop0",
expected: entry{
driveType: DRIVE_TYPE_VIRTUAL,
storageController: STORAGE_CONTROLLER_VIRTUAL,
storageController: STORAGE_CONTROLLER_LOOP,
},
},
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ func TestBlock(t *testing.T) {
t.Fatalf("Expected >0 disks. Got %d", len(disks))
}

d0 := disks[0]
var d0 *block.Disk
// Skip loop devices on generic tests as we don't know what the underlying system is going to have
// And loop devices don't have Serial Numbers for example.
for _, d := range disks {
if d.StorageController != block.STORAGE_CONTROLLER_LOOP {
d0 = d
break
}
}
if d0.Name == "" {
t.Fatalf("Expected disk name, but got \"\"")
}
Expand Down

0 comments on commit 7e3184b

Please sign in to comment.