Skip to content

Commit

Permalink
add GetDevicesFromGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
HikariKnight committed Mar 7, 2023
1 parent 8bc9587 commit 42a74c2
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lib/iommu.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (i *IOMMU) Read() {
pci, err := ghw.PCI(ghw.WithDisableWarnings())
ErrorCheck(err)

// Regex to get IOMMU groups and their devices from filepath
iommu_regex := regexp.MustCompile(`/sys/kernel/iommu_groups/(.*)/devices/(.*)`)
for _, iommu_device := range iommu_devices {
matches := iommu_regex.FindStringSubmatch(iommu_device)
Expand Down Expand Up @@ -134,6 +135,36 @@ func MatchSubclass(searchval string) []string {
return devs
}

// Function to print everything inside a specific IOMMU group
func GetDevicesFromGroups(groups []int) []string {
// Make an output string slice
var output []string

// As long as we are asked to get devices from any specific IOMMU groups
if len(groups) > 0 {
// Get all IOMMU devices
alldevs := NewIOMMU()

// For each IOMMU group given we will print the devices in each group
for _, group := range groups {
// Check if the IOMMU Group exists
if _, iommu_num := alldevs.Groups[group]; !iommu_num {
ErrorCheck(fmt.Errorf("IOMMU Group %v does not exist", group))
} else {
// For each device in specified IOMMU group
for _, device := range alldevs.Groups[group].Devices {
// Generate output line
line := GenDeviceLine(group, device)

// Append line to output
output = append(output, line)
}
}
}
}
return output
}

// Old deprecated functions marked for removal/rework below this comment

func MatchDEVs(kernelmodules bool, regex string) []string{
Expand All @@ -150,4 +181,4 @@ func MatchDEVs(kernelmodules bool, regex string) []string{
}

return devs
}
}

0 comments on commit 42a74c2

Please sign in to comment.