Download this file
| 1 | //go:build linux |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "github.com/carlosframework/platform/internal/instancefs" |
| 8 | "os" |
| 9 | "time" |
| 10 | |
| 11 | "github.com/carlosframework/platform/internal/hostbox" |
| 12 | "github.com/carlosframework/platform/internal/instancectl" |
| 13 | "golang.org/x/sys/unix" |
| 14 | ) |
| 15 | |
| 16 | func (f *servingParkFS) room() error { |
| 17 | parent, _, err := f.parent() |
| 18 | if err != nil { |
| 19 | return err |
| 20 | } |
| 21 | defer parent.Close() |
| 22 | return servingRoomFile(parent) |
| 23 | } |
| 24 | |
| 25 | func servingRoomFile(parent *os.File) error { |
| 26 | var s unix.Statfs_t |
| 27 | if err := unix.Fstatfs(int(parent.Fd()), &s); err != nil { |
| 28 | return err |
| 29 | } |
| 30 | if s.Bsize <= 0 || s.Blocks > ^uint64(0)/uint64(s.Bsize) || s.Bavail > ^uint64(0)/uint64(s.Bsize) { |
| 31 | return hostbox.ErrChanged |
| 32 | } |
| 33 | if s.Bavail*uint64(s.Bsize) < instancectl.DiskFloor(s.Blocks*uint64(s.Bsize)) { |
| 34 | return instancectl.ErrDiskFull |
| 35 | } |
| 36 | return nil |
| 37 | } |
| 38 | |
| 39 | func (p *servingParkRoot) maintainServingParks(ctx context.Context, after string) (string, error) { |
| 40 | fs, ok := p.ledger.fs.(*servingParkFS) |
| 41 | if !ok { |
| 42 | return after, hostbox.ErrUnsupported |
| 43 | } |
| 44 | return maintainServingParkPass(ctx, after, func(call context.Context) error { return p.ledger.maintainParks(call, fs.room) }, p.recoverServingParks, 10*time.Second) |
| 45 | } |
| 46 | |
| 47 | func claimServingRoom(data string) error { |
| 48 | parent, err := instancefs.OpenDirBeneath(data, "instances") |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | defer parent.Close() |
| 53 | return servingRoomFile(parent) |
| 54 | } |
| 55 | |