Skip to content

Commit

Permalink
storage,rhp: hide Read/Write system errors
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed May 10, 2024
1 parent 3637fb3 commit f3151af
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion host/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ func (vm *VolumeManager) Write(root types.Hash256, data *[rhp2.SectorSize]byte)
},
Timestamp: time.Now(),
})
return fmt.Errorf("failed to write sector data: %w", err)
return err
}
vm.log.Debug("wrote sector", zap.String("root", root.String()), zap.Int64("volume", loc.Volume), zap.Uint64("index", loc.Index), zap.Duration("elapsed", time.Since(start)))

Expand Down
13 changes: 13 additions & 0 deletions host/storage/verrors_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !windows
// +build !windows

package storage

import (
"errors"
"syscall"
)

func isNotEnoughStorageErr(err error) bool {
return errors.Is(err, syscall.ENOSPC)
}
14 changes: 14 additions & 0 deletions host/storage/verrors_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build windows
// +build windows

package storage

import (
"errors"

"golang.org/x/sys/windows"
)

func isNotEnoughStorageErr(err error) bool {
return errors.Is(err, windows.ERROR_DISK_FULL)
}
6 changes: 5 additions & 1 deletion host/storage/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ func (v *volume) WriteSector(data *[rhp2.SectorSize]byte, index uint64) error {
}
_, err := v.data.WriteAt(data[:], int64(index*rhp2.SectorSize))
if err != nil {
err = fmt.Errorf("failed to write sector to index %v: %w", index, err)
if isNotEnoughStorageErr(err) {
err = ErrNotEnoughStorage
} else {
err = fmt.Errorf("failed to write sector to index %v: %w", index, err)
}
}
go v.incrementWriteStats(err)
return err
Expand Down
9 changes: 6 additions & 3 deletions rhp/v3/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ func (pe *programExecutor) executeAppendSector(instr *rhp3.InstrAppendSector, lo
}

release, err := pe.storage.Write(root, sector)
if err != nil {
return nil, nil, fmt.Errorf("failed to write sector: %w", err)
if errors.Is(err, storage.ErrNotEnoughStorage) {
return nil, nil, err
} else if err != nil {
return nil, nil, ErrHostInternalError
}
pe.releaseFuncs = append(pe.releaseFuncs, release)
pe.updater.AppendSector(root)
Expand Down Expand Up @@ -275,7 +277,8 @@ func (pe *programExecutor) executeReadSector(instr *rhp3.InstrReadSector, log *z

sector, err := pe.storage.Read(root)
if err != nil {
return nil, nil, fmt.Errorf("failed to read sector %q: %w", root, err)
log.Error("failed to read sector", zap.String("root", root.String()), zap.Error(err))
return nil, nil, ErrHostInternalError
}

// if no proof was requested, return the data
Expand Down

0 comments on commit f3151af

Please sign in to comment.