2022-11-23 15:29:18 +00:00
|
|
|
/**
|
|
|
|
# Copyright (c) NVIDIA CORPORATION. All rights reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
**/
|
|
|
|
|
2023-02-07 11:04:03 +00:00
|
|
|
package discover
|
2022-11-23 15:29:18 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-22 12:27:43 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
2022-11-23 15:29:18 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
|
|
|
)
|
|
|
|
|
2023-02-07 11:07:05 +00:00
|
|
|
type ipcMounts mounts
|
|
|
|
|
2022-11-23 15:29:18 +00:00
|
|
|
// NewIPCDiscoverer creats a discoverer for NVIDIA IPC sockets.
|
2024-09-16 09:19:02 +00:00
|
|
|
func NewIPCDiscoverer(logger logger.Interface, driverRoot string, includePersistencedSocket bool) (Discover, error) {
|
|
|
|
var requiredSockets []string
|
|
|
|
if includePersistencedSocket {
|
|
|
|
requiredSockets = append(requiredSockets, "/nvidia-persistenced/socket")
|
|
|
|
}
|
|
|
|
requiredSockets = append(requiredSockets, "/nvidia-fabricmanager/socket")
|
|
|
|
|
2023-03-16 13:30:43 +00:00
|
|
|
sockets := newMounts(
|
2022-11-23 15:29:18 +00:00
|
|
|
logger,
|
2022-12-02 10:38:40 +00:00
|
|
|
lookup.NewFileLocator(
|
|
|
|
lookup.WithLogger(logger),
|
2023-02-02 14:42:01 +00:00
|
|
|
lookup.WithRoot(driverRoot),
|
2023-03-16 13:30:43 +00:00
|
|
|
lookup.WithSearchPaths("/run", "/var/run"),
|
|
|
|
lookup.WithCount(1),
|
|
|
|
),
|
|
|
|
driverRoot,
|
2024-09-16 09:19:02 +00:00
|
|
|
requiredSockets,
|
2023-03-16 13:30:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
mps := newMounts(
|
|
|
|
logger,
|
|
|
|
lookup.NewFileLocator(
|
|
|
|
lookup.WithLogger(logger),
|
|
|
|
lookup.WithRoot(driverRoot),
|
|
|
|
lookup.WithCount(1),
|
2022-12-02 10:38:40 +00:00
|
|
|
),
|
2023-02-02 14:42:01 +00:00
|
|
|
driverRoot,
|
2022-11-23 15:29:18 +00:00
|
|
|
[]string{
|
|
|
|
"/tmp/nvidia-mps",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-03-16 13:30:43 +00:00
|
|
|
d := Merge(
|
|
|
|
(*ipcMounts)(sockets),
|
|
|
|
(*ipcMounts)(mps),
|
|
|
|
)
|
|
|
|
return d, nil
|
2023-02-07 11:07:05 +00:00
|
|
|
}
|
|
|
|
|
2023-02-07 11:11:02 +00:00
|
|
|
// Mounts returns the discovered mounts with "noexec" added to the mount options.
|
2023-02-07 11:07:05 +00:00
|
|
|
func (d *ipcMounts) Mounts() ([]Mount, error) {
|
|
|
|
mounts, err := (*mounts)(d).Mounts()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-02-07 11:11:02 +00:00
|
|
|
var modifiedMounts []Mount
|
|
|
|
for _, m := range mounts {
|
|
|
|
mount := m
|
2023-08-25 15:38:36 +00:00
|
|
|
mount.Options = append(mount.Options, "noexec")
|
2023-02-07 11:11:02 +00:00
|
|
|
modifiedMounts = append(modifiedMounts, mount)
|
|
|
|
}
|
|
|
|
|
|
|
|
return modifiedMounts, nil
|
2022-11-23 15:29:18 +00:00
|
|
|
}
|