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

Finding drive vid in lsblk vendor #1094

Merged
merged 3 commits into from
Feb 24, 2024
Merged
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
11 changes: 4 additions & 7 deletions pkg/base/linuxutils/lsblk/lsblk.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,8 @@ func (l *LSBLK) GetBlockDevices(device string) ([]BlockDevice, error) {
// Receives an instance of drivecrd.Drive struct
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one general comments is to create an issue first and link the issue to the PR. and put [ISSUE-xxx] in PR title.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

// Returns drive's path based on provided drivecrd.Drive or error if something went wrong
func (l *LSBLK) SearchDrivePath(drive *api.Drive) (string, error) {
// device path might be already set by hwmgr
device := drive.Path
if device != "" {
return device, nil
}

device := ""
// try to find it with lsblk
lsblkOut, err := l.GetBlockDevices("")
if err != nil {
Expand All @@ -178,8 +174,9 @@ func (l *LSBLK) SearchDrivePath(drive *api.Drive) (string, error) {
vid := drive.VID
pid := drive.PID
for _, l := range lsblkOut {
if strings.EqualFold(l.Serial, sn) && strings.EqualFold(l.Vendor, vid) &&
strings.EqualFold(l.Model, pid) {
lvid := strings.TrimSpace(l.Vendor)
if strings.EqualFold(l.Serial, sn) && strings.EqualFold(lvid, vid) &&
strings.HasPrefix(l.Model, pid) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically, it is ok.
just noted that: if pid is null string(""), then strings.HasPrefix will also return true. but in our case, pid seems to not able to be null. we may need re-look at this code in later release as well.

device = l.Name
break
}
Expand Down