2020-03-23 11:40:02 +00:00
|
|
|
package stores
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
)
|
|
|
|
|
2020-07-06 14:13:42 +00:00
|
|
|
type PathType string
|
2020-05-26 08:25:29 +00:00
|
|
|
|
2020-05-20 16:36:46 +00:00
|
|
|
const (
|
2020-07-06 14:13:42 +00:00
|
|
|
PathStorage = "storage"
|
|
|
|
PathSealing = "sealing"
|
2020-05-20 16:36:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AcquireMode string
|
2020-05-26 08:25:29 +00:00
|
|
|
|
2020-05-20 16:36:46 +00:00
|
|
|
const (
|
|
|
|
AcquireMove = "move"
|
|
|
|
AcquireCopy = "copy"
|
|
|
|
)
|
|
|
|
|
2020-03-23 11:40:02 +00:00
|
|
|
type Store interface {
|
2020-06-15 12:32:17 +00:00
|
|
|
AcquireSector(ctx context.Context, s abi.SectorID, spt abi.RegisteredSealProof, existing SectorFileType, allocate SectorFileType, sealing PathType, op AcquireMode) (paths SectorPaths, stores SectorPaths, err error)
|
2020-05-13 18:45:14 +00:00
|
|
|
Remove(ctx context.Context, s abi.SectorID, types SectorFileType, force bool) error
|
2020-03-25 18:21:53 +00:00
|
|
|
|
2020-05-20 16:36:46 +00:00
|
|
|
// like remove, but doesn't remove the primary sector copy, nor the last
|
|
|
|
// non-primary copy if there no primary copies
|
|
|
|
RemoveCopies(ctx context.Context, s abi.SectorID, types SectorFileType) error
|
|
|
|
|
2020-03-25 18:21:53 +00:00
|
|
|
// move sectors into storage
|
2020-06-15 12:32:17 +00:00
|
|
|
MoveStorage(ctx context.Context, s abi.SectorID, spt abi.RegisteredSealProof, types SectorFileType) error
|
2020-03-25 18:21:53 +00:00
|
|
|
|
2020-03-23 22:43:38 +00:00
|
|
|
FsStat(ctx context.Context, id ID) (FsStat, error)
|
2020-03-23 11:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Stat(path string) (FsStat, error) {
|
|
|
|
var stat syscall.Statfs_t
|
|
|
|
if err := syscall.Statfs(path, &stat); err != nil {
|
|
|
|
return FsStat{}, xerrors.Errorf("statfs: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return FsStat{
|
2020-07-06 16:36:44 +00:00
|
|
|
Capacity: int64(stat.Blocks) * stat.Bsize,
|
|
|
|
Available: int64(stat.Bavail) * stat.Bsize,
|
2020-03-23 11:40:02 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2020-03-23 22:43:38 +00:00
|
|
|
|
|
|
|
type FsStat struct {
|
2020-07-06 16:36:44 +00:00
|
|
|
Capacity int64
|
|
|
|
Available int64 // Available to use for sector storage
|
|
|
|
Used int64
|
|
|
|
Reserved int64
|
2020-03-23 22:43:38 +00:00
|
|
|
}
|