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

Enable specifying directory as device on container with --device #2412

Merged
merged 1 commit into from
Mar 6, 2019

Conversation

QiWang19
Copy link
Contributor

@QiWang19 QiWang19 commented Feb 22, 2019

If device on host is specified a directory, enable user to specify the directory on container.
$ sudo podman run --device /dev/snd:/dev/snd:rmw localhost/qi
fix #2380
Signed-off-by: Qi Wang [email protected]

@QiWang19 QiWang19 changed the title Enable specifying directory as device on container using podkan run --device Enable specifying directory as device on container with --device Feb 22, 2019
@QiWang19 QiWang19 force-pushed the iss2380 branch 10 times, most recently from 92a3d8e to 004a3e8 Compare February 23, 2019 22:33
@vrothberg
Copy link
Member

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: QiWang19, vrothberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 25, 2019
Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI doesn't seem happy but I tested it locally 👍 Besides that, just a small comment to make the code easier to read.

found := false
// mount the internal devices recursively
if err := filepath.Walk(resolvedDevicePath, func(dpath string, f os.FileInfo, e error) error {

if f.Mode()&os.ModeDevice == os.ModeDevice {
found = true
device := dpath

if len(devs) > 1 {
if len(devs) > 1 && devs[1][0] == '/' {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment to that? I wasn't familiar with those specific parts and it took me a while to understand it. Although the compiler might be smart enough to move len(devs) > 1 && devs[1][0] == '/' outside the walk func, can we move the checks outside the walk and assign them to some booleans that describe it a bit more?

Something as follows (just an example) might be easier to read:

destSpecified := len(devs) > 1 && devs[1][0] == '/'
modeSpecified := len(devs) > 1 && devs[1][0] != '/'
destAndModeSpecified := len(devs) > 2
destOrModeSpecified := len(devs) > 1
// mount the internal devices recursively
if err := filepath.Walk(resolvedDevicePath, fun [...]

@QiWang19
Copy link
Contributor Author

/retest

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @QiWang19 👍

found := false
destSpecified := len(devs) > 1 && devs[1][0] == '/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this crash if len(devs[1]) == 0? I don't know how we generate the devs array

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's a good catch. It can crash, see a minimal example: https://play.golang.org/p/Yk52BfKvh2q

if len(devs) > 2 {
return errors.Wrapf(unix.EINVAL, "not allowed to specify destination with a directory %s", devicePath)
if devmode != "" {
return errors.Errorf("invalid device specification %s", devicePath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return errors.Wrapf(unix.EINVAL, ...)

@@ -72,4 +72,12 @@ var _ = Describe("Podman run device", func() {
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Not(Equal(0)))
})

FIt("podman run device host device and container device parameter are directories", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove F from FIt...

@QiWang19 QiWang19 force-pushed the iss2380 branch 2 times, most recently from 04ef91c to 1b90c72 Compare February 26, 2019 15:28
@mheon
Copy link
Member

mheon commented Feb 27, 2019

Needs to update RELEASE_NOTES.md with changes

@mheon
Copy link
Member

mheon commented Feb 27, 2019

Nevermind the noise, we'll do this instead

@rhatdan
Copy link
Member

rhatdan commented Mar 5, 2019

@QiWang19 Can you fix my comment so we can get this one in.

@QiWang19
Copy link
Contributor Author

QiWang19 commented Mar 5, 2019

fixed them. See the CI tests.

@vrothberg
Copy link
Member

/retest

@QiWang19
Copy link
Contributor Author

QiWang19 commented Mar 6, 2019

bot, retest this please

@QiWang19
Copy link
Contributor Author

QiWang19 commented Mar 6, 2019

Needs lgtm label. 🤔

@mheon
Copy link
Member

mheon commented Mar 6, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 6, 2019
@openshift-merge-robot openshift-merge-robot merged commit f50715e into containers:master Mar 6, 2019
@QiWang19 QiWang19 deleted the iss2380 branch June 26, 2020 15:09
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Podman run device argument can't specify device on container
6 participants