Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect iSCSI devices #300

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
DRIVE_TYPE_FDD // Floppy disk drive
DRIVE_TYPE_ODD // Optical disk drive
DRIVE_TYPE_SSD // Solid-state drive
DRIVE_TYPE_ISCSI // iSCSI drive
)

var (
Expand All @@ -38,6 +39,7 @@ var (
DRIVE_TYPE_FDD: "FDD",
DRIVE_TYPE_ODD: "ODD",
DRIVE_TYPE_SSD: "SSD",
DRIVE_TYPE_ISCSI: "ISCSI",
}

// NOTE(fromani): the keys are all lowercase and do not match
Expand All @@ -51,6 +53,7 @@ var (
"fdd": DRIVE_TYPE_FDD,
"odd": DRIVE_TYPE_ODD,
"ssd": DRIVE_TYPE_SSD,
"iscsi": DRIVE_TYPE_ISCSI,
}
)

Expand Down
3 changes: 3 additions & 0 deletions pkg/block/block_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func disks(ctx *context.Context, paths *linuxpath.Paths) []*Disk {
size := diskSizeBytes(paths, dname)
pbs := diskPhysicalBlockSizeBytes(paths, dname)
busPath := diskBusPath(paths, dname)
if strings.Contains(busPath, "-iscsi-") {
driveType = DRIVE_TYPE_ISCSI
ffromani marked this conversation as resolved.
Show resolved Hide resolved
}
node := diskNUMANodeID(paths, dname)
vendor := diskVendor(paths, dname)
model := diskModel(paths, dname)
Expand Down
39 changes: 39 additions & 0 deletions pkg/block/block_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
package block

import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
"testing"

"github.com/jaypipes/ghw/pkg/context"
"github.com/jaypipes/ghw/pkg/linuxpath"
)

func TestParseMountEntry(t *testing.T) {
Expand Down Expand Up @@ -179,3 +184,37 @@ func TestDiskTypes(t *testing.T) {
}
}
}

func TestISCSI(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {
t.Skip("Skipping block tests.")
}

baseDir, _ := ioutil.TempDir("", "test")
defer os.RemoveAll(baseDir)
ctx := context.New()
ctx.Chroot = baseDir
paths := linuxpath.New(ctx)

_ = os.MkdirAll(paths.SysBlock, 0755)
_ = os.MkdirAll(paths.RunUdevData, 0755)

// Emulate an iSCSI device
_ = os.Mkdir(filepath.Join(paths.SysBlock, "sda"), 0755)
_ = ioutil.WriteFile(filepath.Join(paths.SysBlock, "sda", "size"), []byte("500118192\n"), 0644)
_ = ioutil.WriteFile(filepath.Join(paths.SysBlock, "sda", "dev"), []byte("259:0\n"), 0644)
_ = os.Mkdir(filepath.Join(paths.SysBlock, "sda", "queue"), 0755)
_ = ioutil.WriteFile(filepath.Join(paths.SysBlock, "sda", "queue", "rotational"), []byte("0\n"), 0644)
_ = ioutil.WriteFile(filepath.Join(paths.SysBlock, "sda", "queue", "physical_block_size"), []byte("512\n"), 0644)
_ = os.Mkdir(filepath.Join(paths.SysBlock, "sda", "device"), 0755)
_ = ioutil.WriteFile(filepath.Join(paths.SysBlock, "sda", "device", "vendor"), []byte("LIO-ORG\n"), 0644)
udevData := "E:ID_MODEL=disk0\nE:ID_SERIAL=6001405961d8b6f55cf48beb0de296b2\n" +
"E:ID_PATH=ip-192.168.130.10:3260-iscsi-iqn.2022-01.com.redhat.foo:disk0-lun-0\n" +
"E:ID_WWN=0x6001405961d8b6f55cf48beb0de296b2\n"
_ = ioutil.WriteFile(filepath.Join(paths.RunUdevData, "b259:0"), []byte(udevData), 0644)

diskInventory := disks(ctx, paths)
if diskInventory[0].DriveType != DRIVE_TYPE_ISCSI {
t.Fatalf("Got drive type %s, but expected ISCSI", diskInventory[0].DriveType)
}
}