aboutsummaryrefslogtreecommitdiffstats
path: root/vm/vm.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-11-25 12:07:11 +0100
committerDmitry Vyukov <dvyukov@google.com>2024-11-25 11:18:31 +0000
commit7e02dfac6584de88e03df494ca500b59802d93eb (patch)
treeaf0a55b5e65966a5715f917383ca3d2f59982932 /vm/vm.go
parent36dfdd05f93ef886e289dd5cc91330d8ae1d0182 (diff)
vm: dedup VM count restriction in debug mode
Move the VM count restriction logic info vm package. This avoids lots of duplication, makes it supported for VM types that failed to do this, and allows to unify more VM count logic in future.
Diffstat (limited to 'vm/vm.go')
-rw-r--r--vm/vm.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/vm/vm.go b/vm/vm.go
index 27e6f319e..91398167d 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -20,6 +20,7 @@ import (
"sync/atomic"
"time"
+ "github.com/google/syzkaller/pkg/log"
"github.com/google/syzkaller/pkg/mgrconfig"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/report"
@@ -48,6 +49,7 @@ type Pool struct {
workdir string
template string
timeouts targets.Timeouts
+ count int
activeCount int32
snapshot bool
hostFuzzer bool
@@ -131,12 +133,18 @@ func Create(cfg *mgrconfig.Config, debug bool) (*Pool, error) {
if err != nil {
return nil, err
}
+ count := impl.Count()
+ if debug && count > 1 {
+ log.Logf(0, "limiting number of VMs from %v to 1 in debug mode", count)
+ count = 1
+ }
return &Pool{
impl: impl,
typ: typ,
workdir: env.Workdir,
template: cfg.WorkdirTemplate,
timeouts: cfg.Timeouts,
+ count: count,
snapshot: cfg.Snapshot,
hostFuzzer: cfg.SysTarget.HostFuzzer,
statOutputReceived: stat.New("vm output", "Bytes of VM console output received",
@@ -145,12 +153,12 @@ func Create(cfg *mgrconfig.Config, debug bool) (*Pool, error) {
}
func (pool *Pool) Count() int {
- return pool.impl.Count()
+ return pool.count
}
func (pool *Pool) Create(index int) (*Instance, error) {
- if index < 0 || index >= pool.Count() {
- return nil, fmt.Errorf("invalid VM index %v (count %v)", index, pool.Count())
+ if index < 0 || index >= pool.count {
+ return nil, fmt.Errorf("invalid VM index %v (count %v)", index, pool.count)
}
workdir, err := osutil.ProcessTempDir(pool.workdir)
if err != nil {
@@ -335,7 +343,7 @@ func (inst *Instance) Close() error {
type Dispatcher = dispatcher.Pool[*Instance]
func NewDispatcher(pool *Pool, def dispatcher.Runner[*Instance]) *Dispatcher {
- return dispatcher.NewPool(pool.Count(), pool.Create, def)
+ return dispatcher.NewPool(pool.count, pool.Create, def)
}
type monitor struct {