Skip to content

Commit

Permalink
fix: be more tolerant to error handling in Mounts API
Browse files Browse the repository at this point in the history
Fixes #8202

If some mountpoint can't be queried successfully for 'diskfree'
information, don't treat that as an error, and report zero values for
disk usage/size instead.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Jan 31, 2024
1 parent 03add75 commit 87be76b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/talos/mounts.go
Expand Up @@ -31,7 +31,7 @@ var mountsCmd = &cobra.Command{
resp, err := c.Mounts(ctx, grpc.Peer(&remotePeer))
if err != nil {
if resp == nil {
return fmt.Errorf("error getting interfaces: %s", err)
return fmt.Errorf("error getting mount information: %s", err)
}

cli.Warning("%s", err)
Expand Down
28 changes: 11 additions & 17 deletions internal/app/machined/internal/server/v1alpha1/v1alpha1_server.go
Expand Up @@ -1075,26 +1075,20 @@ func (s *Server) Mounts(ctx context.Context, in *emptypb.Empty) (reply *machine.
filesystem := fields[0]
mountpoint := fields[1]

f, err := os.Stat(mountpoint)
if err != nil {
multiErr = multierror.Append(multiErr, err)

continue
}

if mode := f.Mode(); !mode.IsDir() {
continue
}

if err := unix.Statfs(mountpoint, &stat); err != nil {
multiErr = multierror.Append(multiErr, err)
var (
totalSize uint64
totalAvail uint64
)

continue
if statInfo, err := os.Stat(mountpoint); err == nil && statInfo.Mode().IsDir() {
if err := unix.Statfs(mountpoint, &stat); err != nil {
multiErr = multierror.Append(multiErr, err)
} else {
totalSize = uint64(stat.Bsize) * stat.Blocks
totalAvail = uint64(stat.Bsize) * stat.Bavail
}
}

totalSize := uint64(stat.Bsize) * stat.Blocks
totalAvail := uint64(stat.Bsize) * stat.Bavail

stat := &machine.MountStat{
Filesystem: filesystem,
Size: totalSize,
Expand Down

0 comments on commit 87be76b

Please sign in to comment.