feat: Go backup restore VF switchdev#145
Conversation
Pull Request Test Coverage Report for Build 19696076708Details
💛 - Coveralls |
Greptile OverviewGreptile SummaryThis PR extends the network configuration backup/restore system to support switchdev mode for VF representors, implementing the Go equivalent of existing bash script functionality. Key Changes:
Issues Found:
Confidence Score: 3/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant NetConfig
participant Sysfs as /sys/class/net
participant Netlink
participant Driver as mlx5_core
Note over User,Driver: Save Phase (Switchdev Mode)
User->>NetConfig: Save()
NetConfig->>NetConfig: discoverSwitchdevRepresentors()
NetConfig->>Sysfs: Read phys_port_name & phys_switch_id
NetConfig->>Sysfs: Scan subsystem for representors
NetConfig->>Netlink: Get representor config (MTU, admin state)
NetConfig-->>User: Configuration saved
Note over User,Driver: Restore Phase (Switchdev Mode)
User->>NetConfig: Restore()
NetConfig->>NetConfig: restoreVFConfigurations(switchdev)
NetConfig->>Driver: Unbind VF from driver
Note over NetConfig: Skip rebind for switchdev (handled later)
NetConfig->>NetConfig: Set eswitch mode to switchdev
NetConfig->>NetConfig: rebindVFsInSwitchdevMode()
NetConfig->>Driver: Bind VF to driver
Note over NetConfig: Wait 3s bind delay
NetConfig->>Netlink: Restore VF MTU & admin state
NetConfig->>NetConfig: restoreRepresentors()
NetConfig->>Sysfs: Find current representor by phys attributes
NetConfig->>NetConfig: Rename representor if needed
NetConfig->>Netlink: Set representor MTU & admin state
NetConfig-->>User: Restore complete
|
| // Wait for bind delay (matches bash script) | ||
| time.Sleep(1 * time.Second) // BIND_DELAY_SEC equivalent | ||
| // Wait for bind delay (matches bash script) | ||
| time.Sleep(3 * time.Second) // BIND_DELAY_SEC equivalent |
There was a problem hiding this comment.
style: Check that the bind delay increase from 1s to 3s doesn't negatively impact restore performance for devices with many VFs
|
|
||
| // Wait for bind delay (matches bash script) | ||
| time.Sleep(1 * time.Second) // BIND_DELAY_SEC equivalent | ||
| time.Sleep(3 * time.Second) // BIND_DELAY_SEC equivalent |
There was a problem hiding this comment.
style: Check that this bind delay matches the bash script value and is necessary for switchdev mode stability
Signed-off-by: Fred Rolland <frolland@nvidia.com>
| // isRepresentorPhysPortName checks if a phys_port_name indicates a representor | ||
| func (n *netconfig) isRepresentorPhysPortName(physPortName string) bool { | ||
| // Format: "pf{port_num}vf{vf_id}" (e.g., "pf1vf3") | ||
| re := regexp.MustCompile(`^pf(\d+)vf(\d+)$`) |
There was a problem hiding this comment.
style: Regex is compiled on every call in a hot loop (called for every network device in findDeviceRepresentors). Consider compiling once at package level:
| re := regexp.MustCompile(`^pf(\d+)vf(\d+)$`) | |
| var representorRegex = regexp.MustCompile(`^pf(\d+)vf(\d+)$`) |
Then use representorRegex.MatchString(physPortName) instead of recompiling each time
|
|
||
| // parseRepresentorPhysPortName parses representor phys_port_name to extract PF port and VF ID | ||
| func (n *netconfig) parseRepresentorPhysPortName(physPortName string) (pfPortNum, vfID string, err error) { | ||
| re := regexp.MustCompile(`^pf(\d+)vf(\d+)$`) |
There was a problem hiding this comment.
style: Same regex compiled twice - once here and once in isRepresentorPhysPortName:1350. Use a single package-level compiled regex instead
| // Wait for bind delay (matches bash script) | ||
| time.Sleep(1 * time.Second) // BIND_DELAY_SEC equivalent | ||
| // Wait for bind delay (matches bash script) | ||
| time.Sleep(3 * time.Second) // BIND_DELAY_SEC equivalent |
There was a problem hiding this comment.
logic: Bind delay is 3s but the bash script uses BIND_DELAY_SEC=4 (see commit 3ce9ba9). This inconsistency could cause issues
| time.Sleep(3 * time.Second) // BIND_DELAY_SEC equivalent | |
| time.Sleep(4 * time.Second) // BIND_DELAY_SEC equivalent (matches bash script default) |
| @@ -460,7 +494,7 @@ func (n *netconfig) rebindVFsInSwitchdevMode(ctx context.Context, device *Mellan | |||
| } | |||
|
|
|||
| // Wait for bind delay (matches bash script) | |||
There was a problem hiding this comment.
logic: Same issue - bind delay is 3s but bash script uses 4s (see commit 3ce9ba9)
| // Wait for bind delay (matches bash script) | |
| time.Sleep(4 * time.Second) // BIND_DELAY_SEC equivalent (matches bash script default) |
No description provided.