Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Blame · ci/agent/disk.go

Line attribution on main · 37 line(s)

4e3759da
Keenan Nemetz
1h ago
1 package agent
2
3 // The runner's disk, as the only bound a job tree has.
4 //
5 // A job's workspace is a bind mount from the host: the runtime cannot quota it, and a
6 // filesystem quota there would need root and a filesystem that supports one. What the
7 // runner can promise is that it notices, so a job that writes without a bound costs
8 // that job instead of the machine. The reserve is one statfs on the filesystem holding
9 // --dir, checked while a command runs, and reported with the numbers.
10
11 import (
12 "syscall"
13 )
14
15 // freeBytes reports how many bytes are available to this user on the filesystem
16 // holding dir.
17 func freeBytes(dir string) (int64, error) {
18 var st syscall.Statfs_t
19 if err := syscall.Statfs(dir, &st); err != nil {
20 return 0, err
21 }
22 return int64(st.Bavail) * int64(st.Bsize), nil
23 }
24
25 // diskLow reports whether the filesystem holding dir has less than reserve bytes
26 // free. A reserve of zero disables the check, which is what a runner whose --dir is
27 // on its own sized filesystem may choose.
28 func diskLow(dir string, reserve int64) (free int64, low bool, err error) {
29 if reserve <= 0 || dir == "" {
30 return 0, false, nil
31 }
32 free, err = freeBytes(dir)
33 if err != nil {
34 return 0, false, err
35 }
36 return free, free < reserve, nil
37 }