diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-11-25 12:03:30 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-11-25 14:12:10 +0000 |
| commit | 02832ca35ded902878eb2a3aa43a1235de5f8ac4 (patch) | |
| tree | d9f362983f5df58518549650bc27806853b38b6f /pkg/vminfo/vminfo.go | |
| parent | a84878fcfef572bb166d73bcc5974ea50a3fde64 (diff) | |
pkg/vminfo: refactor few things
Use default nop implementation for most openbsd/netbsd methods.
Move linux-specific vm type checks to linux code.
Remove indirection for CheckFiles as we have for RequiredFiles.
Diffstat (limited to 'pkg/vminfo/vminfo.go')
| -rw-r--r-- | pkg/vminfo/vminfo.go | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/pkg/vminfo/vminfo.go b/pkg/vminfo/vminfo.go index 89a35e2b2..d2a728585 100644 --- a/pkg/vminfo/vminfo.go +++ b/pkg/vminfo/vminfo.go @@ -37,7 +37,6 @@ type KernelModule struct { type Checker struct { checker - vmType string source queue.Source checkContext *checkContext } @@ -59,18 +58,17 @@ func New(ctx context.Context, cfg *Config) *Checker { var impl checker switch cfg.Target.OS { case targets.Linux: - impl = new(linux) + impl = &linux{vmType: cfg.VMType} case targets.NetBSD: impl = new(netbsd) case targets.OpenBSD: impl = new(openbsd) default: - impl = new(stub) + impl = new(nopChecker) } executor := queue.Plain() return &Checker{ checker: impl, - vmType: cfg.VMType, source: queue.Deduplicate(ctx, executor), checkContext: newCheckContext(ctx, cfg, impl, executor), } @@ -78,11 +76,7 @@ func New(ctx context.Context, cfg *Config) *Checker { func (checker *Checker) MachineInfo(fileInfos []*flatrpc.FileInfo) ([]*KernelModule, []byte, error) { files := createVirtualFilesystem(fileInfos) - var modules []*KernelModule - var err error - if checker.vmType != targets.GVisor && checker.vmType != targets.Starnix { - modules, err = checker.parseModules(files) - } + modules, err := checker.parseModules(files) if err != nil { return nil, nil, err } @@ -105,10 +99,6 @@ func (checker *Checker) MachineInfo(fileInfos []*flatrpc.FileInfo) ([]*KernelMod return modules, info.Bytes(), nil } -func (checker *Checker) CheckFiles() []string { - return checker.checkFiles() -} - func (checker *Checker) Run(files []*flatrpc.FileInfo, featureInfos []*flatrpc.FeatureInfo) ( map[*prog.Syscall]bool, map[*prog.Syscall]string, Features, error) { ctx := checker.checkContext @@ -128,7 +118,7 @@ type machineInfoFunc func(files filesystem, w io.Writer) (string, error) type checker interface { RequiredFiles() []string - checkFiles() []string + CheckFiles() []string parseModules(files filesystem) ([]*KernelModule, error) machineInfos() []machineInfoFunc syscallCheck(*checkContext, *prog.Syscall) string @@ -179,24 +169,24 @@ func (files filesystem) ReadDir(dir string) []string { return res } -type stub int +type nopChecker int -func (stub) RequiredFiles() []string { +func (nopChecker) RequiredFiles() []string { return nil } -func (stub) checkFiles() []string { +func (nopChecker) CheckFiles() []string { return nil } -func (stub) parseModules(files filesystem) ([]*KernelModule, error) { +func (nopChecker) parseModules(files filesystem) ([]*KernelModule, error) { return nil, nil } -func (stub) machineInfos() []machineInfoFunc { +func (nopChecker) machineInfos() []machineInfoFunc { return nil } -func (stub) syscallCheck(*checkContext, *prog.Syscall) string { +func (nopChecker) syscallCheck(*checkContext, *prog.Syscall) string { return "" } |
