Skip to content

handle: use per-request sockets for VF-only configuration - #1209

Open
l8huang wants to merge 1 commit into
vishvananda:mainfrom
l8huang:vf-only
Open

handle: use per-request sockets for VF-only configuration#1209
l8huang wants to merge 1 commit into
vishvananda:mainfrom
l8huang:vf-only

Conversation

@l8huang

@l8huang l8huang commented Aug 6, 2026

Copy link
Copy Markdown

description

PR #1174 changed ConfigureHandle to configure the package-wide pkgHandle through NewHandleWithOptions, which creates persistent netlink sockets in the pkgHandle.

Because pkgHandle.sockets remains bound to the network namespace where it was created, the following operations could target the wrong namespace after the calling OS thread changed namespaces.

This PR returns a handle without nil sockets when the caller only disables VF information collection:

NewHandleWithOptions(HandleOptions{
    DisableVFInfoCollection: true,
})

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Handles configured only to disable virtual-function information collection can now operate without a persistent socket.
    • Network namespace behavior is now clearly documented for persistent and socketless handles.
  • Bug Fixes

    • Preserved existing socket-based behavior when retry, namespace, or netlink family options are configured.
  • Tests

    • Added coverage for option propagation, socket allocation, cleanup, retries, namespaces, and netlink family settings.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7d562717-25b0-4bed-9f54-da845a5be26b

📥 Commits

Reviewing files that changed from the base of the PR and between 156a440 and 37dcc4e.

📒 Files selected for processing (2)
  • handle_linux.go
  • handle_linux_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • handle_linux.go
  • handle_linux_test.go

📝 Walkthrough

Walkthrough

NewHandleWithOptions now creates a socketless handle when only DisableVFInfoCollection is enabled. Documentation clarifies network namespace behavior. Tests cover option propagation, socket allocation, request wiring, and cleanup.

Changes

Handle construction

Layer / File(s) Summary
Handle option construction
handle_linux.go
NewHandleWithOptions uses a socketless handle for the VF-info-only configuration. Other configurations retain persistent-socket construction. HandleOptions.NetNS documentation describes namespace behavior.
Handle construction validation
handle_linux_test.go
Table-driven tests cover VF-info disabling, retries, network namespaces, netlink families, socket allocation, request socket wiring, option propagation, and cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: using per-request sockets for VF-only configuration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thediveo

thediveo commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

I simply don't understand this PR and I'm afraid that because of its convoluted AI generated description that it would make the situation worse by complicating the current API hidden state and behavior even more.

@l8huang

l8huang commented Aug 6, 2026

Copy link
Copy Markdown
Author

@thediveo updated PR description, hope it's easier to understand now

Comment thread handle_linux.go
// specified, the returned Handle creates a socket for each request in the
// caller's current network namespace instead of keeping persistent sockets.
func NewHandleWithOptions(opts HandleOptions, nlFamilies ...int) (*Handle, error) {
if opts.DisableVFInfoCollection && !opts.RetryInterrupted && opts.NetNS == nil && len(nlFamilies) == 0 {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how widely is NewHandleWithOptions() used now, so just want to open a small window to allow disabling VFInfoCollection without init Handle.sockets.

PR vishvananda#1174 changed ConfigureHandle() to configure the package-wide pkgHandle
through NewHandleWithOptions(), which creates persistent netlink sockets
in the pkgHandle.

Because pkgHandle.sockets remains bound to the network namespace where
it was created, the following operations could target the wrong namespace
after the calling OS thread changed namespaces.

This PR returns a handle without nil sockets when the caller only disables
VF information collection:

NewHandleWithOptions(HandleOptions{
    DisableVFInfoCollection: true,
})

Signed-off-by: Lei Huang <leihuang.dev8@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@l8huang

l8huang commented Aug 7, 2026

Copy link
Copy Markdown
Author

@vishvananda @aboch could you please take a look? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants