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:
parent
03add75030
commit
87be76b878
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user