Skip to content

Commit d82b14e

Browse files
committed
fix: be more tolerant to error handling in Mounts API
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> (cherry picked from commit 87be76b)
1 parent d350027 commit d82b14e

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

cmd/talosctl/cmd/talos/mounts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var mountsCmd = &cobra.Command{
3131
resp, err := c.Mounts(ctx, grpc.Peer(&remotePeer))
3232
if err != nil {
3333
if resp == nil {
34-
return fmt.Errorf("error getting interfaces: %s", err)
34+
return fmt.Errorf("error getting mount information: %s", err)
3535
}
3636

3737
cli.Warning("%s", err)

internal/app/machined/internal/server/v1alpha1/v1alpha1_server.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,26 +1081,20 @@ func (s *Server) Mounts(ctx context.Context, in *emptypb.Empty) (reply *machine.
10811081
filesystem := fields[0]
10821082
mountpoint := fields[1]
10831083

1084-
f, err := os.Stat(mountpoint)
1085-
if err != nil {
1086-
multiErr = multierror.Append(multiErr, err)
1087-
1088-
continue
1089-
}
1090-
1091-
if mode := f.Mode(); !mode.IsDir() {
1092-
continue
1093-
}
1094-
1095-
if err := unix.Statfs(mountpoint, &stat); err != nil {
1096-
multiErr = multierror.Append(multiErr, err)
1084+
var (
1085+
totalSize uint64
1086+
totalAvail uint64
1087+
)
10971088

1098-
continue
1089+
if statInfo, err := os.Stat(mountpoint); err == nil && statInfo.Mode().IsDir() {
1090+
if err := unix.Statfs(mountpoint, &stat); err != nil {
1091+
multiErr = multierror.Append(multiErr, err)
1092+
} else {
1093+
totalSize = uint64(stat.Bsize) * stat.Blocks
1094+
totalAvail = uint64(stat.Bsize) * stat.Bavail
1095+
}
10991096
}
11001097

1101-
totalSize := uint64(stat.Bsize) * stat.Blocks
1102-
totalAvail := uint64(stat.Bsize) * stat.Bavail
1103-
11041098
stat := &machine.MountStat{
11051099
Filesystem: filesystem,
11061100
Size: totalSize,

0 commit comments

Comments
 (0)