From b78130eaaf27170f4da579c6bdeb147ddc7210fc Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 4 Dec 2018 21:00:54 -0500 Subject: [PATCH] Use absolute path in example device plugin deviceDir is used for specifying mount/device host paths, and those should be absolute paths. --- plugins/device/cmd/example/device.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/device/cmd/example/device.go b/plugins/device/cmd/example/device.go index cccc1de2c..1c96ea348 100644 --- a/plugins/device/cmd/example/device.go +++ b/plugins/device/cmd/example/device.go @@ -256,6 +256,11 @@ func (d *FsDevice) Reserve(deviceIDs []string) (*device.ContainerReservation, er return nil, status.New(codes.InvalidArgument, "no device ids given").Err() } + deviceDir, err := filepath.Abs(d.deviceDir) + if err != nil { + return nil, status.Newf(codes.Internal, "failed to load device dir abs path").Err() + } + resp := &device.ContainerReservation{} for _, id := range deviceIDs { @@ -265,10 +270,10 @@ func (d *FsDevice) Reserve(deviceIDs []string) (*device.ContainerReservation, er } // Add a mount - resp.Devices = append(resp.Devices, &device.DeviceSpec{ - TaskPath: fmt.Sprintf("/dev/%s", id), - HostPath: filepath.Join(d.deviceDir, id), - CgroupPerms: "rw", + resp.Mounts = append(resp.Mounts, &device.Mount{ + TaskPath: fmt.Sprintf("/tmp/task-mounts/%s", id), + HostPath: filepath.Join(deviceDir, id), + ReadOnly: false, }) }