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>
This commit is contained in:
Andrey Smirnov 2024-01-31 18:22:35 +04:00
parent 03add75030
commit 87be76b878
No known key found for this signature in database
GPG Key ID: FE042E3D4085A811
2 changed files with 12 additions and 18 deletions

View File

@ -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)

View File

@ -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)
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
}
}
if mode := f.Mode(); !mode.IsDir() {
continue
}
if err := unix.Statfs(mountpoint, &stat); err != nil {
multiErr = multierror.Append(multiErr, err)
continue
}
totalSize := uint64(stat.Bsize) * stat.Blocks
totalAvail := uint64(stat.Bsize) * stat.Bavail
stat := &machine.MountStat{
Filesystem: filesystem,
Size: totalSize,