aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-02-22 18:57:46 +0100
committerDmitry Vyukov <dvyukov@google.com>2019-02-22 19:01:22 +0100
commitbaad4d3621fe1810df733c5cef0e4ab55c76f054 (patch)
tree22df71a0060e32884065644a66cc56bafa090d30 /pkg
parent9b05a0a131fdfb47696fe0d8967fd5bc6d8d5112 (diff)
pkg/build: minor assorted improvements for netbsd
Create /fastboot and /var/db/entropy-file files. Check that we copy kernel into the right location. Fix code style.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/build/netbsd.go51
1 files changed, 25 insertions, 26 deletions
diff --git a/pkg/build/netbsd.go b/pkg/build/netbsd.go
index 31d44598a..a412bbc4e 100644
--- a/pkg/build/netbsd.go
+++ b/pkg/build/netbsd.go
@@ -60,11 +60,7 @@ no options SVS
return fmt.Errorf("failed to copy %v -> %v: %v", fullSrc, fullDst, err)
}
}
-
- if vmType == "qemu" || vmType == "gce" {
- return CopyKernelToDisk(outputDir)
- }
- return nil
+ return CopyKernelToDisk(targetArch, outputDir)
}
func (ctx netbsd) clean(kernelDir string) error {
@@ -75,57 +71,60 @@ func (ctx netbsd) clean(kernelDir string) error {
return nil
}
-// Copy the compiled kernel to the qemu disk image using ssh
-func CopyKernelToDisk(outputDir string) error {
- temp := []byte(`
+// Copy the compiled kernel to the qemu disk image using ssh.
+func CopyKernelToDisk(targetArch, outputDir string) error {
+ vmConfig := `
{
"snapshot": false,
"mem": 1024
-} `)
- VMconfig := (*json.RawMessage)(&temp)
- // Create config for booting the disk image
+}`
+ // Create config for booting the disk image.
cfg := &mgrconfig.Config{
Workdir: outputDir,
Image: filepath.Join(outputDir, "image"),
SSHKey: filepath.Join(outputDir, "key"),
SSHUser: "root",
TargetOS: "netbsd",
- TargetArch: "amd64",
- TargetVMArch: "amd64",
+ TargetArch: targetArch,
+ TargetVMArch: targetArch,
Type: "qemu",
- VM: *VMconfig,
+ VM: json.RawMessage([]byte(vmConfig)),
}
- // Create a VM pool
+ // Create a VM pool.
pool, err := vm.Create(cfg, false)
if err != nil {
- return fmt.Errorf("failed to create a VM Pool : %v", err)
+ return fmt.Errorf("failed to create a VM Pool: %v", err)
}
- // Create a new reporter instance
+ // Create a new reporter instance.
reporter, err := report.NewReporter(cfg)
if err != nil {
- return fmt.Errorf("failed to create a Reporter : %v", err)
+ return fmt.Errorf("failed to create a Reporter: %v", err)
}
- // Create a VM instance (We need only one)
+ // Create a VM instance (we need only one).
inst, err := pool.Create(0)
if err != nil {
- return fmt.Errorf("failed to create the VM Instance : %v", err)
+ return fmt.Errorf("failed to create the VM Instance: %v", err)
}
defer inst.Close()
// Copy the kernel into the disk image and replace it
- // This makes use of the fact that the file is copied by default to /
kernel, err := inst.Copy(filepath.Join(outputDir, "netbsd"))
if err != nil {
- return fmt.Errorf("error Copying the kernel %v: %v", kernel, err)
+ return fmt.Errorf("error copying the kernel: %v", err)
+ }
+ if kernel != "/netbsd" {
+ return fmt.Errorf("kernel is copied into wrong location: %v", kernel)
}
- // Run sync so that the copied image is stored properly
- outc, errc, err := inst.Run(time.Minute, nil, "sync")
+ // Run sync so that the copied image is stored properly.
+ // /var/db/entropy-file prevents a non-fatal warning during boot.
+ // /fastboot file prevents disk check on start.
+ outc, errc, err := inst.Run(time.Minute, nil, "touch /fastboot; echo syzkaller > /var/db/entropy-file; sync")
if err != nil {
return fmt.Errorf("error syncing the instance %v", err)
}
- // Make sure that the command has executed properly
+ // Make sure that the command has executed properly.
rep := inst.MonitorExecution(outc, errc, reporter, vm.ExitNormal)
if rep != nil {
- return fmt.Errorf("error executng poweroff : %v", rep.Title)
+ return fmt.Errorf("error executing sync: %v", rep.Title)
}
return nil
}