-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
WIP DNM support Path in OCI spec's LinuxDeviceCgroup #3609
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,62 @@ | ||
package devices | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/opencontainers/runc/libcontainer/devices" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var ( | ||
errNotDev = errors.New("not a block or character device") | ||
errMismatch = errors.New("device type/major/minor specified do not match those of the actual device") | ||
) | ||
|
||
// checkPath checks the Path component of the cgroups device rule, if set. In | ||
// case device type/major/minor are also set, the device is checked to have the | ||
// same type and major:minor. In case those are not set, they are populated | ||
// from the actual device node. | ||
func checkPath(r *devices.Rule) error { | ||
if r.Path == "" { | ||
return nil | ||
} | ||
|
||
var stat unix.Stat_t | ||
if err := unix.Lstat(r.Path, &stat); err != nil { | ||
return &os.PathError{Op: "lstat", Path: r.Path, Err: err} | ||
} | ||
|
||
var ( | ||
devType devices.Type | ||
devNumber = uint64(stat.Rdev) //nolint:unconvert // Rdev is uint32 on e.g. MIPS. | ||
major = int64(unix.Major(devNumber)) | ||
minor = int64(unix.Minor(devNumber)) | ||
) | ||
switch stat.Mode & unix.S_IFMT { | ||
case unix.S_IFBLK: | ||
devType = devices.BlockDevice | ||
case unix.S_IFCHR: | ||
devType = devices.CharDevice | ||
default: | ||
return &os.PathError{Op: "pathCheck", Path: r.Path, Err: errNotDev} | ||
} | ||
|
||
if r.Minor == -1 && r.Major == -1 && r.Type == devices.WildcardDevice { | ||
// Those are defaults in specconv.CreateCroupConfig, meaning | ||
// these fields were not set in spec, so fill them in from the | ||
// actual device. | ||
r.Major = major | ||
r.Minor = minor | ||
r.Type = devType | ||
return nil | ||
} | ||
|
||
// Otherwise (both Path and Type/Major/Minor are specified, | ||
// which is redundant), do a sanity check. | ||
if r.Major != major || r.Minor != minor || r.Type != devType { | ||
return &os.PathError{Op: "pathCheck", Path: r.Path, Err: errMismatch} | ||
} | ||
|
||
return nil | ||
} |
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
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
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
5 changes: 5 additions & 0 deletions
5
vendor/github.com/opencontainers/runtime-spec/specs-go/config.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this will cause issues with upgrades.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this can't affect
runc exec
,runc stop
etc, and forrunc update
we currently skip devices entirely. Having said that, this is a valid concern as we might changerunc update
to manage devices in the future.What I wanted to achieve with this is to not have two fields named
Path
as this makes the code less readable. Seems that's inevitable...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant more generally that I'm worried we'll have a repeat of the
initProcessTime
issue (which ended up with Docker having some super dodgy patching code to work around the issue) --state.json
is deserialised when loading container state, and if you upgrade runc such that the two JSON specs are no longer compatible you'll end up with errors after upgrading. Then again, I think that extra fields don't produce errors injson.Decode
?