Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/vminfo: remove Context from the constructor #5702

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/rpcserver/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func RunLocal(cfg *LocalConfig) error {
cfg: cfg,
setupDone: make(chan bool),
}
serv := newImpl(cfg.Context, &cfg.Config, ctx)
serv := newImpl(&cfg.Config, ctx)
if err := serv.Listen(); err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func New(cfg *RemoteConfig) (Server, error) {
if !cfg.Experimental.RemoteCover {
features &= ^flatrpc.FeatureExtraCoverage
}
return newImpl(context.Background(), &Config{
return newImpl(&Config{
Config: vminfo.Config{
Target: cfg.Target,
VMType: cfg.Type,
Expand All @@ -180,11 +180,11 @@ func New(cfg *RemoteConfig) (Server, error) {
}, cfg.Manager), nil
}

func newImpl(ctx context.Context, cfg *Config, mgr Manager) *server {
func newImpl(cfg *Config, mgr Manager) *server {
// Note that we use VMArch, rather than Arch. We need the kernel address ranges and bitness.
sysTarget := targets.Get(cfg.Target.OS, cfg.VMArch)
cfg.Procs = min(cfg.Procs, prog.MaxPids)
checker := vminfo.New(ctx, &cfg.Config)
checker := vminfo.New(&cfg.Config)
baseSource := queue.DynamicSource(checker)
return &server{
cfg: cfg,
Expand Down Expand Up @@ -372,7 +372,9 @@ func checkRevisions(a *flatrpc.ConnectRequest, target *prog.Target) error {
}

func (serv *server) runCheck(info *flatrpc.InfoRequest) error {
enabledCalls, disabledCalls, features, checkErr := serv.checker.Run(info.Files, info.Features)
// TODO: take context as a parameter.
enabledCalls, disabledCalls, features, checkErr := serv.checker.Run(context.Background(),
info.Files, info.Features)
enabledCalls, transitivelyDisabled := serv.target.TransitivelyEnabledCalls(enabledCalls)
// Note: need to print disbled syscalls before failing due to an error.
// This helps to debug "all system calls are disabled".
Expand Down
4 changes: 2 additions & 2 deletions pkg/vminfo/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func TestLinuxSyscalls(t *testing.T) {
cfg := testConfig(t, targets.Linux, targets.AMD64)
checker := New(context.Background(), cfg)
checker := New(cfg)
filesystems := []string{
// Without sysfs, the checks would also disable mount().
"", "sysfs", "ext4", "binder", "",
Expand All @@ -40,7 +40,7 @@ func TestLinuxSyscalls(t *testing.T) {
}
stop := make(chan struct{})
go createSuccessfulResults(checker, stop)
enabled, disabled, features, err := checker.Run(files, allFeatures())
enabled, disabled, features, err := checker.Run(context.Background(), files, allFeatures())
close(stop)
if err != nil {
t.Fatal(err)
Expand Down
21 changes: 11 additions & 10 deletions pkg/vminfo/vminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type KernelModule struct {

type Checker struct {
checker
source queue.Source
checkContext *checkContext
cfg *Config
source queue.Source
executor queue.Executor
}

type Config struct {
Expand All @@ -54,7 +55,7 @@ type Config struct {
SandboxArg int64
}

func New(ctx context.Context, cfg *Config) *Checker {
func New(cfg *Config) *Checker {
var impl checker
switch cfg.Target.OS {
case targets.Linux:
Expand All @@ -68,9 +69,10 @@ func New(ctx context.Context, cfg *Config) *Checker {
}
executor := queue.Plain()
return &Checker{
checker: impl,
source: queue.Deduplicate(executor),
checkContext: newCheckContext(ctx, cfg, impl, executor),
cfg: cfg,
checker: impl,
executor: executor,
source: queue.Deduplicate(executor),
}
}

Expand Down Expand Up @@ -99,11 +101,10 @@ func (checker *Checker) MachineInfo(fileInfos []*flatrpc.FileInfo) ([]*KernelMod
return modules, info.Bytes(), nil
}

func (checker *Checker) Run(files []*flatrpc.FileInfo, featureInfos []*flatrpc.FeatureInfo) (
func (checker *Checker) Run(ctx context.Context, files []*flatrpc.FileInfo, featureInfos []*flatrpc.FeatureInfo) (
map[*prog.Syscall]bool, map[*prog.Syscall]string, Features, error) {
ctx := checker.checkContext
checker.checkContext = nil
return ctx.do(files, featureInfos)
cc := newCheckContext(ctx, checker.cfg, checker.checker, checker.executor)
return cc.do(files, featureInfos)
}

// Implementation of the queue.Source interface.
Expand Down
6 changes: 3 additions & 3 deletions pkg/vminfo/vminfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func TestSyscalls(t *testing.T) {
t.Run(target.OS+"/"+target.Arch, func(t *testing.T) {
t.Parallel()
cfg := testConfig(t, target.OS, target.Arch)
checker := New(context.Background(), cfg)
checker := New(cfg)
stop := make(chan struct{})
go createSuccessfulResults(checker, stop)
enabled, disabled, _, err := checker.Run(nil, allFeatures())
enabled, disabled, _, err := checker.Run(context.Background(), nil, allFeatures())
close(stop)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -126,7 +126,7 @@ func createSuccessfulResults(source queue.Source, stop chan struct{}) {

func hostChecker(t *testing.T) (*Checker, []*flatrpc.FileInfo) {
cfg := testConfig(t, runtime.GOOS, runtime.GOARCH)
checker := New(context.Background(), cfg)
checker := New(cfg)
files := readFiles(checker.RequiredFiles())
return checker, files
}
Expand Down
Loading