-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oci/deviceFromPath(): correctly check device types
This ports the changes of opencontainers/runc@95a59bf to this repository. From that PR: (mode&S_IFCHR == S_IFCHR) is the wrong way of checking the type of an inode because the S_IF* bits are actually not a bitmask and instead must be checked using S_IF*. This bug was neatly hidden behind a (major == 0) sanity-check but that was removed by [1]. In addition, add a test that makes sure that HostDevices() doesn't give rubbish results -- because we broke this and fixed this before[2]. [1]: opencontainers/runc@24388be ("configs: use different types for .Devices and .Resources.Devices") [2]: opencontainers/runc@3ed492a ("Handle non-devices correctly in DeviceFromPath") Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Loading branch information
Showing
2 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//go:build !windows && !darwin | ||
// +build !windows,!darwin | ||
|
||
/* | ||
Copyright The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package oci | ||
|
||
import "testing" | ||
|
||
func TestHostDevicesAllValid(t *testing.T) { | ||
devices, err := HostDevices() | ||
if err != nil { | ||
t.Fatalf("failed to get host devices: %v", err) | ||
} | ||
|
||
for _, device := range devices { | ||
// Devices can't have major number 0. | ||
if device.Major == 0 { | ||
t.Errorf("device entry %+v has zero major number", device) | ||
} | ||
switch device.Type { | ||
case blockDevice, charDevice: | ||
case fifoDevice: | ||
t.Logf("fifo devices shouldn't show up from HostDevices") | ||
fallthrough | ||
default: | ||
t.Errorf("device entry %+v has unexpected type %v", device, device.Type) | ||
} | ||
} | ||
} |