diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-11-25 12:07:11 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-11-25 11:18:31 +0000 |
| commit | 7e02dfac6584de88e03df494ca500b59802d93eb (patch) | |
| tree | af0a55b5e65966a5715f917383ca3d2f59982932 /vm | |
| parent | 36dfdd05f93ef886e289dd5cc91330d8ae1d0182 (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')
| -rw-r--r-- | vm/adb/adb.go | 3 | ||||
| -rw-r--r-- | vm/bhyve/bhyve.go | 4 | ||||
| -rw-r--r-- | vm/gce/gce.go | 4 | ||||
| -rw-r--r-- | vm/gvisor/gvisor.go | 4 | ||||
| -rwxr-xr-x | vm/isolated/isolated.go | 7 | ||||
| -rw-r--r-- | vm/qemu/qemu.go | 4 | ||||
| -rw-r--r-- | vm/vm.go | 16 | ||||
| -rw-r--r-- | vm/vmm/vmm.go | 4 | ||||
| -rw-r--r-- | vm/vmware/vmware.go | 4 |
9 files changed, 12 insertions, 38 deletions
diff --git a/vm/adb/adb.go b/vm/adb/adb.go index 67336f008..e914acded 100644 --- a/vm/adb/adb.go +++ b/vm/adb/adb.go @@ -115,9 +115,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { return nil, fmt.Errorf("invalid adb device id '%v'", device.Serial) } } - if env.Debug { - cfg.Devices = cfg.Devices[:1] - } pool := &Pool{ cfg: cfg, env: env, diff --git a/vm/bhyve/bhyve.go b/vm/bhyve/bhyve.go index d00055a32..35f6354d3 100644 --- a/vm/bhyve/bhyve.go +++ b/vm/bhyve/bhyve.go @@ -74,10 +74,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { if cfg.Count < 1 || cfg.Count > 128 { return nil, fmt.Errorf("invalid config param count: %v, want [1-128]", cfg.Count) } - if env.Debug && cfg.Count > 1 { - log.Logf(0, "limiting number of VMs from %v to 1 in debug mode", cfg.Count) - cfg.Count = 1 - } pool := &Pool{ cfg: cfg, env: env, diff --git a/vm/gce/gce.go b/vm/gce/gce.go index dbed89bee..f9f5ded00 100644 --- a/vm/gce/gce.go +++ b/vm/gce/gce.go @@ -105,10 +105,6 @@ func Ctor(env *vmimpl.Env, consoleReadCmd string) (*Pool, error) { if cfg.Count < 1 || cfg.Count > 1000 { return nil, fmt.Errorf("invalid config param count: %v, want [1, 1000]", cfg.Count) } - if env.Debug && cfg.Count > 1 { - log.Logf(0, "limiting number of VMs from %v to 1 in debug mode", cfg.Count) - cfg.Count = 1 - } if cfg.MachineType == "" { return nil, fmt.Errorf("machine_type parameter is empty") } diff --git a/vm/gvisor/gvisor.go b/vm/gvisor/gvisor.go index 4d0a82300..8336ee450 100644 --- a/vm/gvisor/gvisor.go +++ b/vm/gvisor/gvisor.go @@ -71,10 +71,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { return nil, fmt.Errorf("invalid config param memory_total_bytes: %v, want [%d,%d]", minMemory, cfg.MemoryTotalBytes, hostTotalMemory) } - if env.Debug && cfg.Count > 1 { - log.Logf(0, "limiting number of VMs from %v to 1 in debug mode", cfg.Count) - cfg.Count = 1 - } if !osutil.IsExist(env.Image) { return nil, fmt.Errorf("image file %q does not exist", env.Image) } diff --git a/vm/isolated/isolated.go b/vm/isolated/isolated.go index 3b8b8720d..2e5ce50a9 100755 --- a/vm/isolated/isolated.go +++ b/vm/isolated/isolated.go @@ -83,13 +83,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { return nil, fmt.Errorf("the number of Targets and the number of USBDevNums should be same") } } - if env.Debug && len(cfg.Targets) > 1 { - log.Logf(0, "limiting number of targets from %v to 1 in debug mode", len(cfg.Targets)) - cfg.Targets = cfg.Targets[:1] - if len(cfg.USBDevNums) > 1 { - cfg.USBDevNums = cfg.USBDevNums[:1] - } - } pool := &Pool{ cfg: cfg, env: env, diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go index 7096d7af3..a6a61be19 100644 --- a/vm/qemu/qemu.go +++ b/vm/qemu/qemu.go @@ -280,10 +280,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { if cfg.Count < 1 || cfg.Count > 1024 { return nil, fmt.Errorf("invalid config param count: %v, want [1, 1024]", cfg.Count) } - if env.Debug && cfg.Count > 1 { - log.Logf(0, "limiting number of VMs from %v to 1 in debug mode", cfg.Count) - cfg.Count = 1 - } if _, err := exec.LookPath(cfg.Qemu); err != nil { return nil, err } @@ -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 { diff --git a/vm/vmm/vmm.go b/vm/vmm/vmm.go index 246a87fb1..90ec66ad7 100644 --- a/vm/vmm/vmm.go +++ b/vm/vmm/vmm.go @@ -74,10 +74,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { if cfg.Count < 1 || cfg.Count > 128 { return nil, fmt.Errorf("invalid config param count: %v, want [1-128]", cfg.Count) } - if env.Debug && cfg.Count > 1 { - log.Logf(0, "limiting number of VMs from %v to 1 in debug mode", cfg.Count) - cfg.Count = 1 - } if cfg.Mem < 128 || cfg.Mem > 1048576 { return nil, fmt.Errorf("invalid config param mem: %v, want [128-1048576]", cfg.Mem) } diff --git a/vm/vmware/vmware.go b/vm/vmware/vmware.go index 56a97e016..104c3d6a9 100644 --- a/vm/vmware/vmware.go +++ b/vm/vmware/vmware.go @@ -65,10 +65,6 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { if _, err := exec.LookPath("vmrun"); err != nil { return nil, fmt.Errorf("cannot find vmrun") } - if env.Debug && cfg.Count > 1 { - log.Logf(0, "limiting number of VMs from %v to 1 in debug mode", cfg.Count) - cfg.Count = 1 - } pool := &Pool{ cfg: cfg, env: env, |
