mirror of
				https://github.com/NVIDIA/nvidia-container-toolkit
				synced 2025-06-26 18:18:24 +00:00 
			
		
		
		
	Move isTegraSystem to internal info package
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
		
							parent
							
								
									cf7bb91481
								
							
						
					
					
						commit
						3a1404f2f4
					
				| @ -18,8 +18,6 @@ package modifier | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/config" | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" | ||||
| @ -27,6 +25,7 @@ import ( | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/discover" | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv" | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/edits" | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/info" | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/oci" | ||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/requirements" | ||||
| 	"github.com/opencontainers/runtime-spec/specs-go" | ||||
| @ -189,7 +188,7 @@ func resolveAutoDiscoverMode(logger *logrus.Logger, mode string) (rmode string) | ||||
| 		logger.Infof("Auto-detected discover mode as '%v'", rmode) | ||||
| 	}() | ||||
| 
 | ||||
| 	isTegra, reason := isTegraSystem() | ||||
| 	isTegra, reason := info.IsTegraSystem() | ||||
| 	logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason) | ||||
| 
 | ||||
| 	if isTegra { | ||||
| @ -198,28 +197,3 @@ func resolveAutoDiscoverMode(logger *logrus.Logger, mode string) (rmode string) | ||||
| 
 | ||||
| 	return "legacy" | ||||
| } | ||||
| 
 | ||||
| // isTegraSystem returns true if the system is detected as a Tegra-based system
 | ||||
| func isTegraSystem() (bool, string) { | ||||
| 	const tegraReleaseFile = "/etc/nv_tegra_release" | ||||
| 	const tegraFamilyFile = "/sys/devices/soc0/family" | ||||
| 
 | ||||
| 	if info, err := os.Stat(tegraReleaseFile); err == nil && !info.IsDir() { | ||||
| 		return true, fmt.Sprintf("%v found", tegraReleaseFile) | ||||
| 	} | ||||
| 
 | ||||
| 	if info, err := os.Stat(tegraFamilyFile); err != nil || !info.IsDir() { | ||||
| 		return false, fmt.Sprintf("%v not found", tegraFamilyFile) | ||||
| 	} | ||||
| 
 | ||||
| 	contents, err := os.ReadFile(tegraFamilyFile) | ||||
| 	if err != nil { | ||||
| 		return false, fmt.Sprintf("could not read %v", tegraFamilyFile) | ||||
| 	} | ||||
| 
 | ||||
| 	if strings.HasPrefix(strings.ToLower(string(contents)), "tegra") { | ||||
| 		return true, fmt.Sprintf("%v has 'tegra' prefix", tegraFamilyFile) | ||||
| 	} | ||||
| 
 | ||||
| 	return false, fmt.Sprintf("%v has no 'tegra' prefix", tegraFamilyFile) | ||||
| } | ||||
|  | ||||
							
								
								
									
										48
									
								
								internal/info/tegra.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								internal/info/tegra.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| /** | ||||
| # 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 info | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"strings" | ||||
| ) | ||||
| 
 | ||||
| // IsTegraSystem returns true if the system is detected as a Tegra-based system
 | ||||
| func IsTegraSystem() (bool, string) { | ||||
| 	const tegraReleaseFile = "/etc/nv_tegra_release" | ||||
| 	const tegraFamilyFile = "/sys/devices/soc0/family" | ||||
| 
 | ||||
| 	if info, err := os.Stat(tegraReleaseFile); err == nil && !info.IsDir() { | ||||
| 		return true, fmt.Sprintf("%v found", tegraReleaseFile) | ||||
| 	} | ||||
| 
 | ||||
| 	if info, err := os.Stat(tegraFamilyFile); err != nil || !info.IsDir() { | ||||
| 		return false, fmt.Sprintf("%v not found", tegraFamilyFile) | ||||
| 	} | ||||
| 
 | ||||
| 	contents, err := os.ReadFile(tegraFamilyFile) | ||||
| 	if err != nil { | ||||
| 		return false, fmt.Sprintf("could not read %v", tegraFamilyFile) | ||||
| 	} | ||||
| 
 | ||||
| 	if strings.HasPrefix(strings.ToLower(string(contents)), "tegra") { | ||||
| 		return true, fmt.Sprintf("%v has 'tegra' prefix", tegraFamilyFile) | ||||
| 	} | ||||
| 
 | ||||
| 	return false, fmt.Sprintf("%v has no 'tegra' prefix", tegraFamilyFile) | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user