-
Notifications
You must be signed in to change notification settings - Fork 182
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
expose SRIOV information #230
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// Use and distribution licensed under the Apache license version 2. | ||
// | ||
// See the COPYING file in the root project directory for full text. | ||
// | ||
|
||
package commands | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jaypipes/ghw" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// sriovCmd represents the listing command | ||
var sriovCmd = &cobra.Command{ | ||
Use: "sriov", | ||
Short: "Show SRIOV devices information for the host system", | ||
RunE: showSRIOV, | ||
} | ||
|
||
// showSRIOV show SRIOV physical device information for the host system. | ||
func showSRIOV(cmd *cobra.Command, args []string) error { | ||
sriov, err := ghw.SRIOV() | ||
if err != nil { | ||
return errors.Wrap(err, "error getting SRIOV info") | ||
} | ||
|
||
switch outputFormat { | ||
case outputFormatHuman: | ||
fmt.Printf("%v\n", sriov) | ||
|
||
for _, dev := range sriov.PhysicalFunctions { | ||
fmt.Printf(" %v\n", dev) | ||
} | ||
case outputFormatJSON: | ||
fmt.Printf("%s\n", sriov.JSONString(pretty)) | ||
case outputFormatYAML: | ||
fmt.Printf("%s", sriov.YAMLString()) | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(sriovCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,19 @@ func scanPCIDeviceRoot(root string) (fileSpecs []string, pciRoots []string) { | |
"revision", | ||
"vendor", | ||
} | ||
|
||
perDevEntriesOpt := []string{ | ||
"driver", | ||
"net/*", | ||
"physfn", | ||
"sriov_*", | ||
"virtfn*", | ||
} | ||
|
||
ignoreSet := newKeySet( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary to create a new if _, ignored := ignoreSet[globbedEntry]; ignored {
continue
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure thing, will simplify |
||
"sriov_vf_msix_count", // linux >= 5.14, write-only | ||
) | ||
|
||
entries, err := ioutil.ReadDir(root) | ||
if err != nil { | ||
return []string{}, []string{} | ||
|
@@ -96,6 +109,25 @@ func scanPCIDeviceRoot(root string) (fileSpecs []string, pciRoots []string) { | |
fileSpecs = append(fileSpecs, filepath.Join(pciEntry, perNetEntry)) | ||
} | ||
|
||
for _, perNetEntryOpt := range perDevEntriesOpt { | ||
netEntryOptPath := filepath.Join(pciEntry, perNetEntryOpt) | ||
|
||
items, err := filepath.Glob(netEntryOptPath) | ||
if err != nil { | ||
// TODO: we skip silently because we don't have | ||
// a ctx handy, so we can't do ctx.Warn :\ | ||
continue | ||
} | ||
|
||
for _, item := range items { | ||
globbedEntry := filepath.Base(item) | ||
if ignoreSet.Contains(globbedEntry) { | ||
continue | ||
} | ||
fileSpecs = append(fileSpecs, item) | ||
} | ||
} | ||
|
||
if isPCIBridge(entryPath) { | ||
trace("adding new PCI root %q\n", entryName) | ||
pciRoots = append(pciRoots, pciEntry) | ||
|
@@ -149,3 +181,19 @@ func isPCIBridge(entryPath string) bool { | |
} | ||
return false | ||
} | ||
|
||
// TODO: make this a real package | ||
type keySet map[string]struct{} | ||
|
||
func newKeySet(keys ...string) keySet { | ||
ks := make(map[string]struct{}) | ||
for _, key := range keys { | ||
ks[key] = struct{}{} | ||
} | ||
return ks | ||
} | ||
|
||
func (ks keySet) Contains(key string) bool { | ||
_, ok := ks[key] | ||
return ok | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend removing this. :) The interfaces we publish are specific to a Git tag or SHA1 per Go package versioning and semver behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem! will remove.