Skip to content

Commit

Permalink
fix(preflight): check the system default NFS version in mount config
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn-9830

Signed-off-by: Raphanus Lo <yunchang.lo@suse.com>
  • Loading branch information
Raphanus Lo authored and COLDTURNIP committed Dec 11, 2024
1 parent c026165 commit d33a227
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/longhornctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ CLI for Longhorn troubleshooting and operations.
* [longhornctl trim](longhornctl_trim.md) - Longhorn trimming operations
* [longhornctl version](longhornctl_version.md) - Print longhornctl version

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Longhorn checking operations
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl check preflight](longhornctl_check_preflight.md) - Check Longhorn preflight

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_check_preflight.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ INFO[2024-07-16T17:17:42+08:00] Completed preflight checker

* [longhornctl check](longhornctl_check.md) - Longhorn checking operations

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ longhornctl doc [output directory] [flags]

* [longhornctl](longhornctl.md) - Longhorn commandline interface.

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Export Longhorn resources
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl export replica](longhornctl_export_replica.md) - Export Longhorn replica

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_export_replica.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ lost+found
* [longhornctl export](longhornctl_export.md) - Export Longhorn resources
* [longhornctl export replica stop](longhornctl_export_replica_stop.md) - Stop exporting Longhorn replica

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_export_replica_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ INFO[2024-07-16T17:29:14+08:00] Successfully stopped exporting replica

* [longhornctl export replica](longhornctl_export_replica.md) - Export Longhorn replica

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Longhorn information gathering operations
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl get replica](longhornctl_get_replica.md) - Get Longhorn replica information

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_get_replica.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ INFO[2024-07-16T17:23:51+08:00] Completed replica getter

* [longhornctl get](longhornctl_get.md) - Longhorn information gathering operations

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_global-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ longhornctl global-options [flags]

* [longhornctl](longhornctl.md) - Longhorn commandline interface.

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Longhorn installation operations
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl install preflight](longhornctl_install_preflight.md) - Install Longhorn preflight

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_install_preflight.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ INFO[2024-07-16T17:09:08+08:00] Completed preflight installer. Use 'longhornctl
* [longhornctl install](longhornctl_install.md) - Longhorn installation operations
* [longhornctl install preflight stop](longhornctl_install_preflight_stop.md) - Stop Longhorn preflight installer

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_install_preflight_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ INFO[2024-07-16T17:21:32+08:00] Successfully stopped preflight installer

* [longhornctl install preflight](longhornctl_install_preflight.md) - Install Longhorn preflight

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_trim.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Longhorn trimming operations
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl trim volume](longhornctl_trim_volume.md) - Trim a Longhorn volume

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_trim_volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ INFO[2024-07-16T17:32:01+08:00] Completed volume trimmer vo

* [longhornctl trim](longhornctl_trim.md) - Longhorn trimming operations

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
2 changes: 1 addition & 1 deletion docs/longhornctl_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ longhornctl version [flags]

* [longhornctl](longhornctl.md) - Longhorn commandline interface.

###### Auto generated by spf13/cobra on 13-Oct-2024
###### Auto generated by spf13/cobra on 27-Nov-2024
80 changes: 45 additions & 35 deletions pkg/local/preflight/checker.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package preflight

import (
"bufio"
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
Expand All @@ -17,7 +15,9 @@ import (
kubeclient "k8s.io/client-go/kubernetes"

commonkube "github.com/longhorn/go-common-libs/kubernetes"
commonnfs "github.com/longhorn/go-common-libs/nfs"
commonns "github.com/longhorn/go-common-libs/ns"
commonsys "github.com/longhorn/go-common-libs/sys"
commontypes "github.com/longhorn/go-common-libs/types"

"github.com/longhorn/cli/pkg/consts"
Expand Down Expand Up @@ -420,52 +420,62 @@ func (local *Checker) checkModulesLoaded(spdkDependent bool) error {
func (local *Checker) checkNFSv4Support() error {
logrus.Info("Checking if NFS4 (either 4.0, 4.1 or 4.2) is supported")

// check kernel capability
var isKernelSupport = false

kernelVersion, err := utils.GetKernelVersion()
if err != nil {
return err
}
kernelConfigPath := "/boot/config-" + kernelVersion
kernelConfigPath = filepath.Join(consts.VolumeMountHostDirectory, kernelConfigPath)
configFile, err := os.Open(kernelConfigPath)
hostBootDir := filepath.Join(consts.VolumeMountHostDirectory, commontypes.SysBootDirectory)
kernelConfigMap, err := commonsys.GetBootKernelConfigMap(hostBootDir, kernelVersion)
if err != nil {
return err
}
defer func(configFile *os.File) {
_ = configFile.Close()
}(configFile)

scanner := bufio.NewScanner(configFile)

for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "CONFIG_NFS_V4_2=") ||
strings.HasPrefix(line, "CONFIG_NFS_V4_1=") ||
strings.HasPrefix(line, "CONFIG_NFS_V4=") {
option := strings.Split(line, "=")
if len(option) == 2 {
if option[1] == "y" {
local.collection.Log.Info = append(local.collection.Log.Info, "NFS4 is supported")
return nil
} else if option[1] == "m" {
// Check if the module is loaded
moduleLoaded, err := utils.IsModuleLoaded(option[0])
if err != nil {
continue
}
if moduleLoaded {
local.collection.Log.Info = append(local.collection.Log.Info, "NFS4 is supported")
return nil
}
}
for configItem, module := range map[string]string{"CONFIG_NFS_V4_2": "nfs", "CONFIG_NFS_V4_1": "nfs", "CONFIG_NFS_V4": "nfs"} {
if configVal, exist := kernelConfigMap[configItem]; !exist {
continue
} else if configVal == "y" {
isKernelSupport = true
break
} else if configVal == "m" {
// Check if the module is loaded
moduleLoaded, err := utils.IsModuleLoaded(module)
if err != nil {
continue
}
if moduleLoaded {
isKernelSupport = true
break
}
}
}

if err := scanner.Err(); err != nil {
return errors.Wrap(err, "failed to check NFS4 support")
if !isKernelSupport {
local.collection.Log.Error = append(local.collection.Log.Error, "NFS4 is not supported")
return nil
}

// check default NFS protocol version
var isSupportedNFSVersion bool

hostEtcDir := filepath.Join(consts.VolumeMountHostDirectory, commontypes.SysEtcDirectory)
nfsMajor, nfsMinor, err := commonnfs.GetSystemDefaultNFSVersion(hostEtcDir)
if err == nil {
isSupportedNFSVersion = nfsMajor == 4 && (nfsMinor == 0 || nfsMinor == 1 || nfsMinor == 2)
} else if errors.Is(err, commontypes.ErrNotConfigured) {
// NFSv4 by default
isSupportedNFSVersion = true
} else {
local.collection.Log.Error = append(local.collection.Log.Error, "Failed to read NFS mount config")
return err
}

if !isSupportedNFSVersion {
local.collection.Log.Warn = append(local.collection.Log.Warn, "NFS4 is supported, but default protocol version is not 4, 4.1, or 4.2. Please refer to the NFS mount configuration manual page for more information: man 5 nfsmount.conf")
}

local.collection.Log.Error = append(local.collection.Log.Error, "NFS4 is not supported")
local.collection.Log.Info = append(local.collection.Log.Info, "NFS4 is supported")
return nil
}

Expand Down
97 changes: 97 additions & 0 deletions vendor/github.com/longhorn/go-common-libs/nfs/nfs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ github.com/longhorn/go-common-libs/exec
github.com/longhorn/go-common-libs/io
github.com/longhorn/go-common-libs/kubernetes
github.com/longhorn/go-common-libs/longhorn
github.com/longhorn/go-common-libs/nfs
github.com/longhorn/go-common-libs/ns
github.com/longhorn/go-common-libs/proc
github.com/longhorn/go-common-libs/sync
Expand Down

0 comments on commit d33a227

Please sign in to comment.