-
Notifications
You must be signed in to change notification settings - Fork 135
Use ip commands to bypass netlink PAGE_SIZE limit for InfiniBand devices #1026
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
3e6eaa9
058235d
ac651c6
4597d2a
5885689
ef08ad1
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package infiniband | ||
|
|
||
| import ( | ||
| "crypto/rand" | ||
| "errors" | ||
| "fmt" | ||
| "io/fs" | ||
|
|
@@ -36,20 +37,39 @@ type infiniband struct { | |
| kernelHelper types.KernelInterface | ||
| } | ||
|
|
||
| // ConfigureVfGUID configures and sets a GUID for an IB VF device | ||
| func (i *infiniband) ConfigureVfGUID(vfAddr string, pfAddr string, vfID int, pfLink netlink.Link) error { | ||
| log.Log.Info("ConfigureVfGUID(): configure vf guid", "vfAddr", vfAddr, "pfAddr", pfAddr, "vfID", vfID) | ||
|
|
||
| guid := generateRandomGUID() | ||
|
|
||
| // GetVfGUID gets a GUID for an IB VF device (checks pool first, then generates random) | ||
| func (i *infiniband) GetVfGUID(pfAddr string, vfID int) (net.HardwareAddr, error) { | ||
| if i.guidPool != nil { | ||
| guidFromPool, err := i.guidPool.GetVFGUID(pfAddr, vfID) | ||
| if err != nil { | ||
| log.Log.Info("ConfigureVfGUID(): failed to get GUID from IB GUID pool", "address", vfAddr, "error", err) | ||
| return err | ||
| log.Log.Error(err, "GetVfGUID(): failed to get GUID from IB GUID pool", "pfAddr", pfAddr, "vfID", vfID) | ||
| return nil, err | ||
| } | ||
| guid = guidFromPool | ||
| return guidFromPool, nil | ||
| } | ||
|
|
||
| // Fallback to random GUID generation if pool is not available. | ||
| // Using crypto/rand for cryptographically secure random numbers to avoid collisions. | ||
| guid := make(net.HardwareAddr, 8) | ||
| if _, err := rand.Read(guid); err != nil { | ||
| return nil, fmt.Errorf("failed to generate random GUID: %w", err) | ||
| } | ||
| // Set U/L bit to indicate locally administered address. | ||
| guid[0] |= 0x02 | ||
| // Unset I/G bit for unicast. | ||
| guid[0] &^= 0x01 | ||
| return guid, nil | ||
| } | ||
|
Comment on lines
+41
to
+62
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. The current implementation for random GUID generation relies on
For generating unique identifiers like GUIDs, I suggest refactoring this function to use Note: The suggestion requires importing func (i *infiniband) GetVfGUID(pfAddr string, vfID int) (net.HardwareAddr, error) {
if i.guidPool != nil {
guidFromPool, err := i.guidPool.GetVFGUID(pfAddr, vfID)
if err != nil {
log.Log.Error(err, "GetVfGUID(): failed to get GUID from IB GUID pool", "pfAddr", pfAddr, "vfID", vfID)
return nil, err
}
return guidFromPool, nil
}
// Fallback to random GUID generation if pool is not available.
// Using crypto/rand for cryptographically secure random numbers to avoid collisions.
guid := make(net.HardwareAddr, 8)
if _, err := rand.Read(guid); err != nil {
return nil, fmt.Errorf("failed to generate random GUID: %w", err)
}
// Set U/L bit to indicate locally administered address.
guid[0] |= 0x02
// Unset I/G bit for unicast.
guid[0] &^= 0x01
return guid, nil
} |
||
|
|
||
| // ConfigureVfGUID configures and sets a GUID for an IB VF device | ||
| func (i *infiniband) ConfigureVfGUID(vfAddr string, pfAddr string, vfID int, pfLink netlink.Link) error { | ||
| log.Log.Info("ConfigureVfGUID(): configure vf guid", "vfAddr", vfAddr, "pfAddr", pfAddr, "vfID", vfID) | ||
|
|
||
| guid, err := i.GetVfGUID(pfAddr, vfID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| log.Log.Info("ConfigureVfGUID(): set vf guid", "address", vfAddr, "guid", guid) | ||
|
|
||
| return i.applyVfGUIDToInterface(guid, vfAddr, vfID, pfLink) | ||
|
|
||
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.
The log message at line 46 is misleading. It states "using random GUID", but the function returns an error instead of falling back to the randomly generated GUID. This can make debugging difficult. The log level should also be
Errorsince an error is being handled and returned, which is a better practice for error logging.