From a6b3a217e86bcb63bd8270989b9c9b6f10d8ecff Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Mon, 16 Sep 2019 12:41:24 +0300 Subject: [PATCH 1/4] crihook: fix ineffective Errorf call Returned error instead of calling errors.Errorf with no effect. --- cmd/fpga_crihook/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/fpga_crihook/main.go b/cmd/fpga_crihook/main.go index a0dea139..70b2d6df 100644 --- a/cmd/fpga_crihook/main.go +++ b/cmd/fpga_crihook/main.go @@ -167,7 +167,7 @@ func (he *hookEnv) getFPGAParams(config *Config) ([]fpgaParams, error) { for num, region := range regionEnv { afu, ok := afuEnv[num] if !ok { - errors.Errorf("Environment variable %s%s is not set", fpgaAfuEnvPrefix, num) + return nil, errors.Errorf("Environment variable %s%s is not set", fpgaAfuEnvPrefix, num) } // Find a device suitable for the region/interface id From 73ac87cd8de86f19b37c9bdf8be3ad0e67ee4650 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Mon, 16 Sep 2019 12:50:29 +0300 Subject: [PATCH 2/4] crihook; fix forgotten error check --- cmd/fpga_crihook/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/fpga_crihook/main.go b/cmd/fpga_crihook/main.go index 70b2d6df..d4bd66f6 100644 --- a/cmd/fpga_crihook/main.go +++ b/cmd/fpga_crihook/main.go @@ -270,6 +270,9 @@ func (he *hookEnv) process(reader io.Reader) error { defer bitstream.Close() err = port.PR(bitstream, false) + if err != nil { + return err + } programmedAfu = port.GetAcceleratorTypeUUID() From 8d21aff5acfa08569ae4ecdfb63b15695ce753af Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Mon, 16 Sep 2019 12:51:50 +0300 Subject: [PATCH 3/4] crihook: removed unused field --- cmd/fpga_crihook/main.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmd/fpga_crihook/main.go b/cmd/fpga_crihook/main.go index d4bd66f6..469cfe47 100644 --- a/cmd/fpga_crihook/main.go +++ b/cmd/fpga_crihook/main.go @@ -52,12 +52,6 @@ type Config struct { Env []string `json:"env"` } `json:"process"` Linux struct { - Resources struct { - Devices []struct { - Major int `json:"major,omitempty"` - Minor int `json:"minor,omitempty"` - } `json:"devices"` - } `json:"resources"` Devices []Device `json:"devices"` } `json:"linux"` } From 57b4927eda0ed081d727f1f3e10868a05a92ea7b Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Mon, 16 Sep 2019 12:56:35 +0300 Subject: [PATCH 4/4] crihook: simplified NewHookEnv signature --- cmd/fpga_crihook/main.go | 11 ++++------- cmd/fpga_crihook/main_test.go | 10 ++-------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/cmd/fpga_crihook/main.go b/cmd/fpga_crihook/main.go index 469cfe47..c35b9178 100644 --- a/cmd/fpga_crihook/main.go +++ b/cmd/fpga_crihook/main.go @@ -97,13 +97,13 @@ type fpgaParams struct { portDevice string } -func newHookEnv(sysFsPrefix, bitstreamDir string, config string, execer utilsexec.Interface) (*hookEnv, error) { +func newHookEnv(sysFsPrefix, bitstreamDir string, config string, execer utilsexec.Interface) *hookEnv { return &hookEnv{ sysFsPrefix: sysFsPrefix, bitstreamDir: bitstreamDir, config: config, execer: execer, - }, nil + } } func (he *hookEnv) getConfig(stdinJ *Stdin) (*Config, error) { @@ -283,12 +283,9 @@ func main() { os.Setenv("PATH", "/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin") } - he, err := newHookEnv("", fpgaBitStreamDirectory, configJSON, utilsexec.New()) - if err == nil { - err = he.process(os.Stdin) - } + he := newHookEnv("", fpgaBitStreamDirectory, configJSON, utilsexec.New()) - if err != nil { + if err := he.process(os.Stdin); err != nil { fmt.Printf("%+v\n", err) os.Exit(1) } diff --git a/cmd/fpga_crihook/main_test.go b/cmd/fpga_crihook/main_test.go index 6aab1f64..c1e8fb12 100644 --- a/cmd/fpga_crihook/main_test.go +++ b/cmd/fpga_crihook/main_test.go @@ -158,10 +158,7 @@ func TestGetConfig(t *testing.T) { t.Fatalf("can't decode %s: %+v", fname, err) } - he, err := newHookEnv("", "", tc.configJSON, nil) - if err != nil { - t.Fatalf("can't create HookEnv for config JSON %s: %+v", tc.configJSON, err) - } + he := newHookEnv("", "", tc.configJSON, nil) config, err := he.getConfig(stdinJ) if err != nil { @@ -287,10 +284,7 @@ func TestGetFPGAParams(t *testing.T) { t.Fatalf("can't create temp files: %+v", err) } - he, err := newHookEnv(tmpdir, "", tc.configJSON, nil) - if err != nil { - t.Fatalf("can't create HookEnv for config JSON %s: %+v", tc.configJSON, err) - } + he := newHookEnv(tmpdir, "", tc.configJSON, nil) stdinJ, err := getStdin(stdin) if err != nil {