Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit d717535

Browse files
committed
multiple device request issue
the issue is if a single pod requests different devices from different pools it results in multiple uds servers serving the same container and all attempt to mount their uds to the pod as /tmp/afxdp.sock. A similar issue exists for the AFXDP_DEVICES env var that's set in each container. This patch fixes the first issue by mounting the xsksocket at /tmp/afxdp_dp/<netdev>/afxdp.sock, a similar issue also existed for the bpf map pinning support. Signed-off-by: Maryam Tahhan <[email protected]>
1 parent 38317c2 commit d717535

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ build: builddp buildcni
7373
docker: ## Build docker image
7474
@echo "****** Docker Image ******"
7575
@echo
76-
docker build -t localhost:5000/afxdp-device-plugin -f images/amd64.dockerfile .
76+
docker build -t afxdp-device-plugin -f images/amd64.dockerfile .
7777
@echo
7878
@echo
7979

8080
podman: ## Build podman image
8181
@echo "****** Podman Image ******"
8282
@echo
83-
podman build -t localhost:5000/afxdp-device-plugin -f images/amd64.dockerfile .
83+
podman build -t afxdp-device-plugin -f images/amd64.dockerfile .
8484
@echo
8585
@echo
8686

constants/constants.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ var (
7474
afxdpMinimumLinux = "4.18.0" // minimum Linux version for AF_XDP support
7575

7676
/* UDS*/
77-
udsMaxTimeout = 300 // maximum configurable uds timeout in seconds
78-
udsMinTimeout = 30 // minimum (and default) uds timeout in seconds
79-
udsMsgBufSize = 64 // uds message buffer size
80-
udsCtlBufSize = 4 // uds control buffer size
81-
udsProtocol = "unixpacket" // uds protocol: "unix"=SOCK_STREAM, "unixdomain"=SOCK_DGRAM, "unixpacket"=SOCK_SEQPACKET
82-
udsSockDir = "/tmp/afxdp_dp/" // host location where we place our uds sockets. If changing location remember to update daemonset mount point
83-
udsPodPath = "/tmp/afxdp.sock" // the uds filepath as it will appear in the end user application pod
77+
udsMaxTimeout = 300 // maximum configurable uds timeout in seconds
78+
udsMinTimeout = 30 // minimum (and default) uds timeout in seconds
79+
udsMsgBufSize = 64 // uds message buffer size
80+
udsCtlBufSize = 4 // uds control buffer size
81+
udsProtocol = "unixpacket" // uds protocol: "unix"=SOCK_STREAM, "unixdomain"=SOCK_DGRAM, "unixpacket"=SOCK_SEQPACKET
82+
udsSockDir = "/tmp/afxdp_dp/" // host location where we place our uds sockets. If changing location remember to update daemonset mount point
83+
udsPodPath = "/tmp/" // the uds filepath as it will appear in the end user application pod
84+
udsPodSock = "/afxdp.sock"
8485

8586
/* BPF*/
86-
bpfMapPodPath = "/tmp/xsks_map"
87+
bpfMapPodPath = "/tmp/"
8788
xsk_map = "/xsks_map"
8889

8990
udsDirFileMode = 0700 // permissions for the directory in which we create our uds sockets
@@ -216,6 +217,7 @@ type uds struct {
216217
SockDir string
217218
DirFileMode int
218219
PodPath string
220+
SockName string
219221
Handshake handshake
220222
}
221223

@@ -326,6 +328,7 @@ func init() {
326328
SockDir: udsSockDir,
327329
DirFileMode: udsDirFileMode,
328330
PodPath: udsPodPath,
331+
SockName: udsPodSock,
329332
Handshake: handshake{
330333
Version: handshakeHandshakeVersion,
331334
RequestVersion: handshakeRequestVersion,

internal/deviceplugin/poolManager.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,22 @@ func (pm *PoolManager) Allocate(ctx context.Context,
196196
cresp := new(pluginapi.ContainerAllocateResponse)
197197
envs := make(map[string]string)
198198

199-
if !pm.UdsServerDisable {
200-
cresp.Mounts = append(cresp.Mounts, &pluginapi.Mount{
201-
HostPath: udsPath,
202-
ContainerPath: constants.Uds.PodPath,
203-
ReadOnly: false,
204-
})
205-
}
206-
207199
//loop each device request per container
208200
for _, devName := range crqt.DevicesIDs {
209201
device := pm.Devices[devName]
210202
pretty, _ := tools.PrettyString(device.Public())
211203
logging.Debugf("Device: %s", pretty)
212204

205+
containerSockPath := constants.Uds.PodPath + device.Name() + constants.Uds.SockName
206+
207+
if !pm.UdsServerDisable {
208+
cresp.Mounts = append(cresp.Mounts, &pluginapi.Mount{
209+
HostPath: udsPath,
210+
ContainerPath: containerSockPath,
211+
ReadOnly: false,
212+
})
213+
}
214+
213215
if device.Mode() != pm.Mode {
214216
err := fmt.Errorf("pool mode %s does not match device mode %s", pm.Mode, device.Mode())
215217
logging.Errorf("%v", err)
@@ -265,16 +267,21 @@ func (pm *PoolManager) Allocate(ctx context.Context,
265267

266268
//FULL PATH WILL INCLUDE THE XSKMAP...
267269
fullPath := pinPath + constants.Bpf.Xsk_map
268-
logging.Debugf("mapping %s to %s", fullPath, constants.Bpf.BpfMapPodPath)
270+
containerMapPath := constants.Bpf.BpfMapPodPath + device.Name() + constants.Bpf.Xsk_map
271+
logging.Debugf("mapping %s to %s", fullPath, containerMapPath)
269272
cresp.Mounts = append(cresp.Mounts, &pluginapi.Mount{
270273
HostPath: fullPath,
271-
ContainerPath: constants.Bpf.BpfMapPodPath,
274+
ContainerPath: containerMapPath,
272275
ReadOnly: false,
273276
})
274277
}
275278
}
276279

277-
envs[constants.Devices.EnvVarList] = strings.Join(crqt.DevicesIDs, " ")
280+
// MT this doesn't really work as the env var is being set per Allocate request
281+
// Could leave the app to deduce the af_xdp device name from the path above
282+
// or write the device name into a file in the same path as the xskmap
283+
// or just drop altogher?
284+
envs[constants.Devices.EnvVarList] = strings.Join(crqt.DevicesIDs[:], " ")
278285
envsPrint, err := tools.PrettyString(envs)
279286
if err != nil {
280287
logging.Errorf("Error printing container environment variables: %v", err)
@@ -283,7 +290,6 @@ func (pm *PoolManager) Allocate(ctx context.Context,
283290
}
284291
cresp.Envs = envs
285292
response.ContainerResponses = append(response.ContainerResponses, cresp)
286-
287293
}
288294

289295
if !pm.UdsServerDisable {

0 commit comments

Comments
 (0)