-
Notifications
You must be signed in to change notification settings - Fork 28
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
Handle non-directory entries in /sys/class/net #52
base: master
Are you sure you want to change the base?
Conversation
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.
thanks for the enhancement!
pkg/sysfsnet/interfaces_linux.go
Outdated
if !info.IsDir() { | ||
return "", nil | ||
} |
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.
What if we do this check earlier, and call readMACFromFile()
only if it's a dir?
Will this work?
diff --git a/pkg/sysfsnet/interfaces_linux.go b/pkg/sysfsnet/interfaces_linux.go
index f4a295f..138b788 100644
--- a/pkg/sysfsnet/interfaces_linux.go
+++ b/pkg/sysfsnet/interfaces_linux.go
@@ -39,6 +39,9 @@ func Interfaces() ([]Interface, error) {
}
for _, dentry := range dents {
+ if !dentry.IsDir() {
+ continue
+ }
hwText, err := readMACFromFile(filepath.Join(sysClassNet, dentry.Name(), "address"))
if os.IsNotExist(err) {
continue
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.
I agree this is much cleaner - I'll make the change and test locally
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.
Thanks - looks like we are very close to merging this. Let me know if you need anything.
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.
Looks good now with that change, I did have to call os.Stat() first becuase os.DirEntry(dentry) resolves to a symlink and IsDir()/FileInfo doesn't check the target
// os.Stat to follow symlinks and return the info of the target | ||
info, err := os.Stat(entryPath) | ||
if err != nil { | ||
continue |
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.
I think we should at least log err
as a warning before continue
. That may be other reasons why os.Stat(entryPath)
could fail, and we don't want it to always fail silently.
@@ -45,4 +50,9 @@ func TestInterfaces(t *testing.T) { | |||
if !reflect.DeepEqual(want, got) { | |||
t.Fatalf("want MACs=%v, got MACs=%v", want, got) | |||
} | |||
|
|||
// Ensure non-directory entry is ignored | |||
if _, exists := got[""]; exists { |
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.
I think got[""]
is too broad. Can you add some test string to the bonding_masters
file and then make sure they aren't present in got
.
Problem:
If non-directory entries are in /sys/class/net - the driver fails to enumerate interface macs.
Solution:
Before attempting to open /sys/class/net/[interface]/address, checks if /sys/class/net/[interface] is a directory. If it is not, ignore it and continue enumerating the interfaces
Related Issue:
harvester/harvester#7232
Test plan:
All test pass running
make ci
, built and pushed and tested in cluster with the following logs: