From 2faab769ecf6a7a46f2a857d0c9454e9a8059015 Mon Sep 17 00:00:00 2001 From: Sylvester Carolan Date: Thu, 30 May 2024 17:00:49 -0400 Subject: [PATCH] Exit gracefully from mount when linux host does not support file system 9p. --- cmd/minikube/cmd/mount.go | 5 +++++ pkg/minikube/detect/detect_linux.go | 29 ++++++++++++++++++++++++++ pkg/minikube/detect/detect_nonlinux.go | 5 +++++ pkg/minikube/reason/reason.go | 2 ++ 4 files changed, 41 insertions(+) diff --git a/cmd/minikube/cmd/mount.go b/cmd/minikube/cmd/mount.go index 07e3545e38..345e2adac7 100644 --- a/cmd/minikube/cmd/mount.go +++ b/cmd/minikube/cmd/mount.go @@ -186,6 +186,11 @@ var mountCmd = &cobra.Command{ cfg.Options[parts[0]] = parts[1] } + if runtime.GOOS == "linux" && !detect.IsNinePSupported() { + exit.Message(reason.HostUnsupported, "The host does not support filesystem 9p.") + + } + // An escape valve to allow future hackers to try NFS, VirtFS, or other FS types. if !supportedFilesystems[cfg.Type] { out.WarningT("{{.type}} is not yet a supported filesystem. We will try anyways!", out.V{"type": cfg.Type}) diff --git a/pkg/minikube/detect/detect_linux.go b/pkg/minikube/detect/detect_linux.go index 4774ee688c..41b15e31e2 100644 --- a/pkg/minikube/detect/detect_linux.go +++ b/pkg/minikube/detect/detect_linux.go @@ -19,6 +19,8 @@ limitations under the License. package detect import ( + "os" + "path/filepath" "runtime" "golang.org/x/sys/unix" @@ -54,3 +56,30 @@ func cgroupVersion() string { return "" } } + +func IsNinePSupported() bool { + // assume true from non-linux + if runtime.GOOS != "linux" { + return true + } + _, err := os.Stat(getModuleRoot() + "/kernel/fs/9p") + return err == nil +} + +func getModuleRoot() string { + // assume true from non-linux + if runtime.GOOS != "linux" { + return "" + } + uname := unix.Utsname{} + if err := unix.Uname(&uname); err != nil { + return "" + } + + i := 0 + for ; uname.Release[i] != 0; i++ { + continue + } + return filepath.Join("/lib/modules", string(uname.Release[:i])) + +} diff --git a/pkg/minikube/detect/detect_nonlinux.go b/pkg/minikube/detect/detect_nonlinux.go index ab2f0eb704..18d0920ea2 100644 --- a/pkg/minikube/detect/detect_nonlinux.go +++ b/pkg/minikube/detect/detect_nonlinux.go @@ -22,3 +22,8 @@ package detect func cgroupVersion() string { return "v1" } + +// Assume 9p is supported by non linux apps +func IsNinePSupported() bool { + return true +} diff --git a/pkg/minikube/reason/reason.go b/pkg/minikube/reason/reason.go index 16d4268e7b..afdf136014 100644 --- a/pkg/minikube/reason/reason.go +++ b/pkg/minikube/reason/reason.go @@ -288,6 +288,8 @@ var ( HostPurge = Kind{ID: "HOST_PURGE", ExitCode: ExHostError} // minikube failed to persist profile config HostSaveProfile = Kind{ID: "HOST_SAVE_PROFILE", ExitCode: ExHostConfig} + // Host doesn't support 9p + HostUnsupported = Kind{ID: "HOST_UNSUPPORTED", ExitCode: ExHostUnsupported} // minikube could not find a provider for the selected driver ProviderNotFound = Kind{ID: "PROVIDER_NOT_FOUND", ExitCode: ExProviderNotFound}