Skip to content

Commit 885124e

Browse files
committed
cmd/buildlet: remount OpenBSD & FreeBSD filesystems on boot
OpenBSD is deployed and tested. FreeBSD has only been tested by hand, but this CL doesn't fail the buildlet if the remount fails. It only logs either way. Updates golang/go#17104 Change-Id: Ia9662b42ae8305ad9eaa4292c94fa3194cc26b11 Reviewed-on: https://go-review.googlesource.com/29238 Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 122739b commit 885124e

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

cmd/buildlet/buildlet.go

+39-6
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,28 @@ func main() {
9191
case "macstadium_vm":
9292
configureMacStadium()
9393
}
94-
if runtime.GOOS == "plan9" {
95-
log.SetOutput(&plan9LogWriter{w: os.Stderr})
96-
}
9794
onGCE := metadata.OnGCE()
98-
if runtime.GOOS == "linux" && onGCE && !inKube {
99-
if w, err := os.OpenFile("/dev/console", os.O_WRONLY, 0); err == nil {
100-
log.SetOutput(w)
95+
switch runtime.GOOS {
96+
case "plan9":
97+
log.SetOutput(&plan9LogWriter{w: os.Stderr})
98+
case "linux":
99+
if onGCE && !inKube {
100+
if w, err := os.OpenFile("/dev/console", os.O_WRONLY, 0); err == nil {
101+
log.SetOutput(w)
102+
}
101103
}
102104
}
105+
103106
log.Printf("buildlet starting.")
104107
flag.Parse()
105108

109+
// Optimize emphemeral filesystems. Prefer speed over safety, since these machines
110+
// will be gone soon.
111+
switch runtime.GOOS {
112+
case "openbsd", "freebsd":
113+
makeBSDFilesystemFast()
114+
}
115+
106116
if *listenAddr == "AUTO" && *reverse == "" {
107117
v := defaultListenAddr()
108118
log.Printf("Will listen on %s", v)
@@ -1198,3 +1208,26 @@ func vmwareGetInfo(key string) string {
11981208
}
11991209
return strings.TrimSpace(stdout.String())
12001210
}
1211+
1212+
func makeBSDFilesystemFast() {
1213+
if !metadata.OnGCE() {
1214+
log.Printf("Not on GCE; not remounting root filesystem.")
1215+
return
1216+
}
1217+
btype, err := metadata.InstanceAttributeValue("builder-type")
1218+
if _, ok := err.(metadata.NotDefinedError); ok && len(btype) == 0 {
1219+
log.Printf("Not remounting root filesystem due to missing builder-type metadata.")
1220+
return
1221+
}
1222+
if err != nil {
1223+
log.Printf("Not remounting root filesystem due to failure getting builder type instance metadata: %v", err)
1224+
return
1225+
}
1226+
// Tested on OpenBSD and FreeBSD:
1227+
out, err := exec.Command("/sbin/mount", "-u", "-o", "async,noatime", "/").CombinedOutput()
1228+
if err != nil {
1229+
log.Printf("Warning: failed to remount %s root filesystem with async,noatime: %v, %s", runtime.GOOS, err, out)
1230+
return
1231+
}
1232+
log.Printf("Remounted / with async,noatime.")
1233+
}

0 commit comments

Comments
 (0)