Skip to content

Commit

Permalink
multiple device request issue
Browse files Browse the repository at this point in the history
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/<netdev>/afxdp.sock note, this
could be modified to be /tmp/afxdp_dp/<netdev>/afxdp.sock if
preferred.

Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan committed Nov 7, 2023
1 parent 38317c2 commit 6a31a01
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ build: builddp buildcni
docker: ## Build docker image
@echo "****** Docker Image ******"
@echo
docker build -t localhost:5000/afxdp-device-plugin -f images/amd64.dockerfile .
docker build -t afxdp-device-plugin -f images/amd64.dockerfile .
@echo
@echo

podman: ## Build podman image
@echo "****** Podman Image ******"
@echo
podman build -t localhost:5000/afxdp-device-plugin -f images/amd64.dockerfile .
podman build -t afxdp-device-plugin -f images/amd64.dockerfile .
@echo
@echo

Expand Down
19 changes: 11 additions & 8 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ var (
afxdpMinimumLinux = "4.18.0" // minimum Linux version for AF_XDP support

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

/* BPF*/
bpfMapPodPath = "/tmp/xsks_map"
bpfMapPodPath = "/tmp/"
xsk_map = "/xsks_map"

udsDirFileMode = 0700 // permissions for the directory in which we create our uds sockets
Expand Down Expand Up @@ -216,6 +217,7 @@ type uds struct {
SockDir string
DirFileMode int
PodPath string
SockName string
Handshake handshake
}

Expand Down Expand Up @@ -326,6 +328,7 @@ func init() {
SockDir: udsSockDir,
DirFileMode: udsDirFileMode,
PodPath: udsPodPath,
SockName: udsPodSock,
Handshake: handshake{
Version: handshakeHandshakeVersion,
RequestVersion: handshakeRequestVersion,
Expand Down
30 changes: 18 additions & 12 deletions internal/deviceplugin/poolManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,22 @@ func (pm *PoolManager) Allocate(ctx context.Context,
cresp := new(pluginapi.ContainerAllocateResponse)
envs := make(map[string]string)

if !pm.UdsServerDisable {
cresp.Mounts = append(cresp.Mounts, &pluginapi.Mount{
HostPath: udsPath,
ContainerPath: constants.Uds.PodPath,
ReadOnly: false,
})
}

//loop each device request per container
for _, devName := range crqt.DevicesIDs {
device := pm.Devices[devName]
pretty, _ := tools.PrettyString(device.Public())
logging.Debugf("Device: %s", pretty)

containerSockPath := constants.Uds.PodPath + device.Name() + constants.Uds.SockName

if !pm.UdsServerDisable {
cresp.Mounts = append(cresp.Mounts, &pluginapi.Mount{
HostPath: udsPath,
ContainerPath: containerSockPath,
ReadOnly: false,
})
}

if device.Mode() != pm.Mode {
err := fmt.Errorf("pool mode %s does not match device mode %s", pm.Mode, device.Mode())
logging.Errorf("%v", err)
Expand Down Expand Up @@ -265,16 +267,21 @@ func (pm *PoolManager) Allocate(ctx context.Context,

//FULL PATH WILL INCLUDE THE XSKMAP...
fullPath := pinPath + constants.Bpf.Xsk_map
logging.Debugf("mapping %s to %s", fullPath, constants.Bpf.BpfMapPodPath)
containerMapPath := constants.Bpf.BpfMapPodPath + device.Name() + constants.Bpf.Xsk_map
logging.Debugf("mapping %s to %s", fullPath, containerMapPath)
cresp.Mounts = append(cresp.Mounts, &pluginapi.Mount{
HostPath: fullPath,
ContainerPath: constants.Bpf.BpfMapPodPath,
ContainerPath: containerMapPath,
ReadOnly: false,
})
}
}

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

}

if !pm.UdsServerDisable {
Expand Down

0 comments on commit 6a31a01

Please sign in to comment.