Skip to content

Commit

Permalink
Add node info to failed mount logging.
Browse files Browse the repository at this point in the history
Signed-off-by: James Munson <james.munson@suse.com>
  • Loading branch information
james-munson committed Mar 9, 2024
1 parent 81254ac commit c06d8cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions csi/node_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func (ns *NodeServer) nodeStageSharedVolume(volumeID, shareEndpoint, targetPath
if err == nil {
return nil
}
// Still failed. Log with mounting node and kernel version for possible troubleshooting.
osInfo := getOSInfo()
log.WithError(err).Warnf("Failed to mount volume %v on node %s with kernel release %s.", volumeID, ns.nodeID, osInfo)
}
return status.Error(codes.Internal, err.Error())
}
Expand Down
26 changes: 26 additions & 0 deletions csi/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"
"time"

"github.com/container-storage-interface/spec/lib/go/csi"
Expand Down Expand Up @@ -460,3 +461,28 @@ func requiresSharedAccess(vol *longhornclient.Volume, cap *csi.VolumeCapability)
func getStageBlockVolumePath(stagingTargetPath, volumeID string) string {
return filepath.Join(stagingTargetPath, volumeID)
}

// We use this utility function because csi-plugin has no datastore object to ask about kubernetes node,
// and the go-common-lib/ns functions won't work because the /proc mount path is different.
func getOSInfo() string {
utsname := &syscall.Utsname{}
if err := syscall.Uname(utsname); err != nil {
logrus.WithError(err).Warn("Failed making syscall Uname.")
return "<unknown OS>"
}

extract := func(field [65]int8) string {
output := make([]byte, 0, len(field))
for _, b := range field {
if b == 0x00 {
break
}
output = append(output, byte(b))
}
return string(output)
}

// Extract the kernel release and OS version from the utsname structure
osInfo := extract(utsname.Release) + ", " + extract(utsname.Version)
return osInfo
}

0 comments on commit c06d8cf

Please sign in to comment.