2022-06-02 12:33:11 +00:00
|
|
|
/**
|
|
|
|
# Copyright (c) 2022, 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.
|
|
|
|
**/
|
|
|
|
|
|
|
|
package discover
|
|
|
|
|
|
|
|
import (
|
2023-03-22 12:27:43 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
2022-06-02 12:33:11 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
|
|
|
)
|
|
|
|
|
|
|
|
type gdsDeviceDiscoverer struct {
|
|
|
|
None
|
2023-03-22 12:27:43 +00:00
|
|
|
logger logger.Interface
|
2022-06-02 12:33:11 +00:00
|
|
|
devices Discover
|
|
|
|
mounts Discover
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewGDSDiscoverer creates a discoverer for GPUDirect Storage devices and mounts.
|
2023-03-22 12:27:43 +00:00
|
|
|
func NewGDSDiscoverer(logger logger.Interface, root string) (Discover, error) {
|
2022-07-06 09:37:14 +00:00
|
|
|
devices := NewCharDeviceDiscoverer(
|
|
|
|
logger,
|
|
|
|
[]string{"/dev/nvidia-fs*"},
|
|
|
|
root,
|
|
|
|
)
|
2022-06-02 12:33:11 +00:00
|
|
|
|
2022-07-15 14:42:06 +00:00
|
|
|
udev := NewMounts(
|
|
|
|
logger,
|
2023-07-18 13:36:03 +00:00
|
|
|
lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(root)),
|
2022-07-15 14:42:06 +00:00
|
|
|
root,
|
|
|
|
[]string{"/run/udev"},
|
|
|
|
)
|
2022-06-02 12:33:11 +00:00
|
|
|
|
2022-07-15 14:42:06 +00:00
|
|
|
cufile := NewMounts(
|
|
|
|
logger,
|
2022-12-02 10:38:40 +00:00
|
|
|
lookup.NewFileLocator(
|
|
|
|
lookup.WithLogger(logger),
|
|
|
|
lookup.WithRoot(root),
|
|
|
|
),
|
2022-07-15 14:42:06 +00:00
|
|
|
root,
|
|
|
|
[]string{"/etc/cufile.json"},
|
|
|
|
)
|
2022-06-23 14:01:04 +00:00
|
|
|
|
2022-06-02 12:33:11 +00:00
|
|
|
d := gdsDeviceDiscoverer{
|
|
|
|
logger: logger,
|
|
|
|
devices: devices,
|
2022-07-05 08:28:40 +00:00
|
|
|
mounts: Merge(udev, cufile),
|
2022-06-02 12:33:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &d, nil
|
|
|
|
}
|
|
|
|
|
2022-06-23 14:01:04 +00:00
|
|
|
// Devices discovers the nvidia-fs device nodes for use with GPUDirect Storage
|
2022-06-02 12:33:11 +00:00
|
|
|
func (d *gdsDeviceDiscoverer) Devices() ([]Device, error) {
|
2022-07-06 09:37:14 +00:00
|
|
|
return d.devices.Devices()
|
2022-06-02 12:33:11 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 14:01:04 +00:00
|
|
|
// Mounts discovers the required mounts for GPUDirect Storage.
|
2022-06-02 12:33:11 +00:00
|
|
|
// If no devices are discovered the discovered mounts are empty
|
|
|
|
func (d *gdsDeviceDiscoverer) Mounts() ([]Mount, error) {
|
|
|
|
devices, err := d.Devices()
|
|
|
|
if err != nil || len(devices) == 0 {
|
|
|
|
d.logger.Debugf("No nvidia-fs devices detected; skipping detection of mounts")
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return d.mounts.Mounts()
|
|
|
|
}
|