Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit 2fd3635

Browse files
gauravkghildiyalaojea
authored andcommitted
fix: Properly handle RDMA subsystem's shared and exclusive mode
An RDMA device can only be assigned to a network namespace when the RDMA subsystem is set to an "exclusive" network namespace mode. When the subsystem is set to "shared" mode, an attempt to assign an RDMA device to a network namespace will result in failure. Additionally, "If there are active network namespaces and if one or more RDMA devices exist, changing mode from shared to exclusive returns error code EBUSY." Ref. https://man7.org/linux/man-pages/man8/rdma-system.8.html
1 parent 5108266 commit 2fd3635

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pkg/driver/rdmadevice.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,39 @@ import (
2121

2222
"github.com/vishvananda/netlink"
2323
"github.com/vishvananda/netns"
24+
"k8s.io/klog/v2"
25+
)
26+
27+
const (
28+
// rdmaNetnsModeShared and rdmaNetnsModeExclusive define the RDMA subsystem
29+
// network namespace mode. An RDMA device can only be assigned to a network
30+
// namespace when the RDMA subsystem is set to an "exclusive" network
31+
// namespace mode. When the subsystem is set to "shared" mode, an attempt to
32+
// assign an RDMA device to a network namespace will result in failure.
33+
// Additionally, "If there are active network namespaces and if one or more
34+
// RDMA devices exist, changing mode from shared to exclusive returns error
35+
// code EBUSY."
36+
//
37+
// Ref. https://man7.org/linux/man-pages/man8/rdma-system.8.html
38+
rdmaNetnsModeShared = "shared"
39+
rdmaNetnsModeExclusive = "exclusive"
2440
)
2541

2642
// Based on existing RDMA CNI plugin
2743
// https://github.com/k8snetworkplumbingwg/rdma-cni
2844

2945
func nsAttachRdmadev(hostIfName string, containerNsPAth string) error {
46+
rdmaNetnsMode, err := netlink.RdmaSystemGetNetnsMode()
47+
if err != nil {
48+
return fmt.Errorf("failed to determine the RDMA subsystem's network namespace mode: %w", err)
49+
}
50+
if rdmaNetnsMode == rdmaNetnsModeShared {
51+
// TODO: Potentially move this check to the function invokers side for
52+
// improved visiblity and expectation of what this function does.
53+
klog.Info("Skipping setting network namespace for RDMA device since RDMA sybsystem is currently configured for shared mode.")
54+
return nil
55+
}
56+
3057
containerNs, err := netns.GetFromPath(containerNsPAth)
3158
if err != nil {
3259
return fmt.Errorf("could not get network namespace from path %s for network device %s : %w", containerNsPAth, hostIfName, err)

0 commit comments

Comments
 (0)