Skip to content

Commit 538cc1a

Browse files
committed
pkg/cdi: fix a build failure on windows.
Fix the most obvious build failure on windows. Signed-off-by: Krisztian Litkey <[email protected]>
1 parent a80a40e commit 538cc1a

File tree

3 files changed

+83
-33
lines changed

3 files changed

+83
-33
lines changed

pkg/cdi/container-edits.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import (
2727
"github.com/container-orchestrated-devices/container-device-interface/specs-go"
2828
oci "github.com/opencontainers/runtime-spec/specs-go"
2929
ocigen "github.com/opencontainers/runtime-tools/generate"
30-
31-
runc "github.com/opencontainers/runc/libcontainer/devices"
3230
)
3331

3432
const (
@@ -289,37 +287,6 @@ func ensureOCIHooks(spec *oci.Spec) {
289287
}
290288
}
291289

292-
// fillMissingInfo fills in missing mandatory attributes from the host device.
293-
func (d *DeviceNode) fillMissingInfo() error {
294-
if d.HostPath == "" {
295-
d.HostPath = d.Path
296-
}
297-
298-
if d.Type != "" && (d.Major != 0 || d.Type == "p") {
299-
return nil
300-
}
301-
302-
hostDev, err := runc.DeviceFromPath(d.HostPath, "rwm")
303-
if err != nil {
304-
return errors.Wrapf(err, "failed to stat CDI host device %q", d.HostPath)
305-
}
306-
307-
if d.Type == "" {
308-
d.Type = string(hostDev.Type)
309-
} else {
310-
if d.Type != string(hostDev.Type) {
311-
return errors.Errorf("CDI device (%q, %q), host type mismatch (%s, %s)",
312-
d.Path, d.HostPath, d.Type, string(hostDev.Type))
313-
}
314-
}
315-
if d.Major == 0 && d.Type != "p" {
316-
d.Major = hostDev.Major
317-
d.Minor = hostDev.Minor
318-
}
319-
320-
return nil
321-
}
322-
323290
// sortMounts sorts the mounts in the given OCI Spec.
324291
func sortMounts(specgen *ocigen.Generator) {
325292
mounts := specgen.Mounts()

pkg/cdi/container-edits_unix.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
/*
5+
Copyright © 2021 The CDI Authors
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package cdi
21+
22+
import (
23+
runc "github.com/opencontainers/runc/libcontainer/devices"
24+
"github.com/pkg/errors"
25+
)
26+
27+
// fillMissingInfo fills in missing mandatory attributes from the host device.
28+
func (d *DeviceNode) fillMissingInfo() error {
29+
if d.HostPath == "" {
30+
d.HostPath = d.Path
31+
}
32+
33+
if d.Type != "" && (d.Major != 0 || d.Type == "p") {
34+
return nil
35+
}
36+
37+
hostDev, err := runc.DeviceFromPath(d.HostPath, "rwm")
38+
if err != nil {
39+
return errors.Wrapf(err, "failed to stat CDI host device %q", d.HostPath)
40+
}
41+
42+
if d.Type == "" {
43+
d.Type = string(hostDev.Type)
44+
} else {
45+
if d.Type != string(hostDev.Type) {
46+
return errors.Errorf("CDI device (%q, %q), host type mismatch (%s, %s)",
47+
d.Path, d.HostPath, d.Type, string(hostDev.Type))
48+
}
49+
}
50+
if d.Major == 0 && d.Type != "p" {
51+
d.Major = hostDev.Major
52+
d.Minor = hostDev.Minor
53+
}
54+
55+
return nil
56+
}

pkg/cdi/container-edits_windows.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build windows
2+
// +build windows
3+
4+
/*
5+
Copyright © 2021 The CDI Authors
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package cdi
21+
22+
import "fmt"
23+
24+
// fillMissingInfo fills in missing mandatory attributes from the host device.
25+
func (d *DeviceNode) fillMissingInfo() error {
26+
return fmt.Errorf("unimplemented")
27+
}

0 commit comments

Comments
 (0)