aboutsummaryrefslogtreecommitdiffstats
path: root/vm
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-07-23 14:13:28 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-07-23 13:30:23 +0000
commit53c2e8ad91fd5f64989a4e6a923926990130b5cd (patch)
treea4ba74c7dcaebf772436725f3ccf2e4e65baa659 /vm
parente50e8da5c493b37bff754d816c11218eba03d715 (diff)
vmimpl: refactor VM type registration
Pass Type struct directly during registration. This allows to add additional optional parameters to VM types without changing all VM implementations. We we will need to add SupportsSnapshots flag and one flag to resolve #5028. With this change it will be possible to add "SupportsSnapshots: true" to just one VM type implemenetation.
Diffstat (limited to 'vm')
-rw-r--r--vm/adb/adb.go4
-rw-r--r--vm/bhyve/bhyve.go5
-rw-r--r--vm/cuttlefish/cuttlefish.go5
-rw-r--r--vm/gce/gce.go5
-rw-r--r--vm/gvisor/gvisor.go5
-rwxr-xr-xvm/isolated/isolated.go4
-rw-r--r--vm/proxyapp/init.go7
-rw-r--r--vm/qemu/qemu.go5
-rw-r--r--vm/starnix/starnix.go5
-rw-r--r--vm/vm_test.go4
-rw-r--r--vm/vmimpl/vmimpl.go11
-rw-r--r--vm/vmm/vmm.go5
-rw-r--r--vm/vmware/vmware.go4
13 files changed, 48 insertions, 21 deletions
diff --git a/vm/adb/adb.go b/vm/adb/adb.go
index 2fd401084..67336f008 100644
--- a/vm/adb/adb.go
+++ b/vm/adb/adb.go
@@ -27,7 +27,9 @@ import (
)
func init() {
- vmimpl.Register("adb", ctor, false)
+ vmimpl.Register("adb", vmimpl.Type{
+ Ctor: ctor,
+ })
}
type Device struct {
diff --git a/vm/bhyve/bhyve.go b/vm/bhyve/bhyve.go
index 57515ba22..d00055a32 100644
--- a/vm/bhyve/bhyve.go
+++ b/vm/bhyve/bhyve.go
@@ -21,7 +21,10 @@ import (
)
func init() {
- vmimpl.Register("bhyve", ctor, true)
+ vmimpl.Register("bhyve", vmimpl.Type{
+ Ctor: ctor,
+ Overcommit: true,
+ })
}
type Config struct {
diff --git a/vm/cuttlefish/cuttlefish.go b/vm/cuttlefish/cuttlefish.go
index 73014cf4e..dcc825fbf 100644
--- a/vm/cuttlefish/cuttlefish.go
+++ b/vm/cuttlefish/cuttlefish.go
@@ -28,7 +28,10 @@ const (
)
func init() {
- vmimpl.Register("cuttlefish", ctor, true)
+ vmimpl.Register("cuttlefish", vmimpl.Type{
+ Ctor: ctor,
+ Overcommit: true,
+ })
}
type Pool struct {
diff --git a/vm/gce/gce.go b/vm/gce/gce.go
index 8de0b56db..e65ee836b 100644
--- a/vm/gce/gce.go
+++ b/vm/gce/gce.go
@@ -35,7 +35,10 @@ import (
)
func init() {
- vmimpl.Register("gce", ctor, true)
+ vmimpl.Register("gce", vmimpl.Type{
+ Ctor: ctor,
+ Overcommit: true,
+ })
}
type Config struct {
diff --git a/vm/gvisor/gvisor.go b/vm/gvisor/gvisor.go
index ca3a8472c..4d0a82300 100644
--- a/vm/gvisor/gvisor.go
+++ b/vm/gvisor/gvisor.go
@@ -26,7 +26,10 @@ import (
)
func init() {
- vmimpl.Register(targets.GVisor, ctor, true)
+ vmimpl.Register(targets.GVisor, vmimpl.Type{
+ Ctor: ctor,
+ Overcommit: true,
+ })
}
type Config struct {
diff --git a/vm/isolated/isolated.go b/vm/isolated/isolated.go
index 99e7ad78a..3b8b8720d 100755
--- a/vm/isolated/isolated.go
+++ b/vm/isolated/isolated.go
@@ -24,7 +24,9 @@ import (
const pstoreConsoleFile = "/sys/fs/pstore/console-ramoops-0"
func init() {
- vmimpl.Register("isolated", ctor, false)
+ vmimpl.Register("isolated", vmimpl.Type{
+ Ctor: ctor,
+ })
}
type Config struct {
diff --git a/vm/proxyapp/init.go b/vm/proxyapp/init.go
index 467187f46..0500298e6 100644
--- a/vm/proxyapp/init.go
+++ b/vm/proxyapp/init.go
@@ -27,12 +27,11 @@ func makeDefaultParams() *proxyAppParams {
}
func init() {
- vmimpl.Register(
- "proxyapp",
- func(env *vmimpl.Env) (vmimpl.Pool, error) {
+ vmimpl.Register("proxyapp", vmimpl.Type{
+ Ctor: func(env *vmimpl.Env) (vmimpl.Pool, error) {
return ctor(makeDefaultParams(), env)
},
- false)
+ })
}
// Package configuration VARs are mostly needed for tests.
diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go
index 4d9859c0c..a8faf54b9 100644
--- a/vm/qemu/qemu.go
+++ b/vm/qemu/qemu.go
@@ -27,7 +27,10 @@ import (
func init() {
var _ vmimpl.Infoer = (*instance)(nil)
- vmimpl.Register("qemu", ctor, true)
+ vmimpl.Register("qemu", vmimpl.Type{
+ Ctor: ctor,
+ Overcommit: true,
+ })
}
type Config struct {
diff --git a/vm/starnix/starnix.go b/vm/starnix/starnix.go
index 65c921ee3..f722badcf 100644
--- a/vm/starnix/starnix.go
+++ b/vm/starnix/starnix.go
@@ -25,7 +25,10 @@ import (
func init() {
var _ vmimpl.Infoer = (*instance)(nil)
- vmimpl.Register(targets.Starnix, ctor, true)
+ vmimpl.Register(targets.Starnix, vmimpl.Type{
+ Ctor: ctor,
+ Overcommit: true,
+ })
}
type Config struct {
diff --git a/vm/vm_test.go b/vm/vm_test.go
index 278a4b63d..eb642830f 100644
--- a/vm/vm_test.go
+++ b/vm/vm_test.go
@@ -81,7 +81,9 @@ func init() {
ctor := func(env *vmimpl.Env) (vmimpl.Pool, error) {
return &testPool{}, nil
}
- vmimpl.Register("test", ctor, false)
+ vmimpl.Register("test", vmimpl.Type{
+ Ctor: ctor,
+ })
}
type Test struct {
diff --git a/vm/vmimpl/vmimpl.go b/vm/vmimpl/vmimpl.go
index ce2a0dfb6..ac38a6634 100644
--- a/vm/vmimpl/vmimpl.go
+++ b/vm/vmimpl/vmimpl.go
@@ -124,15 +124,14 @@ func (err InfraError) InfraError() (string, []byte) {
}
// Register registers a new VM type within the package.
-func Register(typ string, ctor ctorFunc, allowsOvercommit bool) {
- Types[typ] = Type{
- Ctor: ctor,
- Overcommit: allowsOvercommit,
- }
+func Register(typ string, desc Type) {
+ Types[typ] = desc
}
type Type struct {
- Ctor ctorFunc
+ Ctor ctorFunc
+ // It's possible to create out-of-thin-air instances of this type.
+ // Out-of-thin-air instances are used by syz-ci for image testing, patch testing, bisection, etc.
Overcommit bool
}
diff --git a/vm/vmm/vmm.go b/vm/vmm/vmm.go
index 6a6242882..246a87fb1 100644
--- a/vm/vmm/vmm.go
+++ b/vm/vmm/vmm.go
@@ -25,7 +25,10 @@ import (
var vmctlStatusRegex = regexp.MustCompile(`^\s+([0-9]+)\b.*\brunning`)
func init() {
- vmimpl.Register("vmm", ctor, true)
+ vmimpl.Register("vmm", vmimpl.Type{
+ Ctor: ctor,
+ Overcommit: true,
+ })
}
type Config struct {
diff --git a/vm/vmware/vmware.go b/vm/vmware/vmware.go
index 210a4957a..56a97e016 100644
--- a/vm/vmware/vmware.go
+++ b/vm/vmware/vmware.go
@@ -23,7 +23,9 @@ import (
)
func init() {
- vmimpl.Register("vmware", ctor, false)
+ vmimpl.Register("vmware", vmimpl.Type{
+ Ctor: ctor,
+ })
}
type Config struct {