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

Add podman volume mount support #13318

Merged
merged 1 commit into from
Mar 1, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Feb 22, 2022

Fixes: #12768

Signed-off-by: Daniel J Walsh [email protected]

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

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

Nice new feature. Some suggestions for the tests.

Comment on lines 404 to 406
touch $mnt/$myfile
run_podman run -v ${myvolume}:/vol1:z $IMAGE ls /vol1
is "$output" "$myfile" "$myfile should exists within the containers volume"
Copy link
Member

Choose a reason for hiding this comment

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

inconsistent indentation; mix of tabs and spaces. Also, s/exists/exist/

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a small test for rootless.

@@ -387,4 +387,27 @@ NeedsChown | true
run_podman volume rm $myvolume
}

@test "podman volume mount" {
skip_if_remote "podman --remote volume mount not supported"
Copy link
Member

Choose a reason for hiding this comment

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

Test doesn't really do anything when rootless. Why not just skip_if_rootless?

test/system/160-volumes.bats Outdated Show resolved Hide resolved
test/system/160-volumes.bats Outdated Show resolved Hide resolved
@edsantiago
Copy link
Member

oh, and linter is unhappy

pkg/domain/infra/abi/volumes.go:182:1: receiver name ir should be consistent with previous receiver name ic for ContainerEngine (golint)
func (ir *ContainerEngine) VolumeMount(ctx context.Context, nameOrIDs []string) ([]*entities.ContainerMountReport, error) {
^
pkg/domain/infra/abi/volumes.go:198:1: receiver name ir should be consistent with previous receiver name ic for ContainerEngine (golint)
func (ir *ContainerEngine) VolumeUnmount(ctx context.Context, nameOrIDs []string) ([]*entities.ContainerUnmountReport, error) {
^
pkg/domain/infra/abi/auto-update.go:10:28: ST1016: methods on the same type should have the same receiver name (seen 2x "ir", 97x "ic") (stylecheck)
func (ic *ContainerEngine) AutoUpdate(ctx context.Context, options entities.AutoUpdateOptions) ([]*entities.AutoUpdateReport, []error) {
                           ^
make: *** [Makefile:251: golangci-lint] Error 1

libpod/volume.go Outdated
@@ -255,3 +255,11 @@ func (v *Volume) IsDangling() (bool, error) {
func (v *Volume) UsesVolumeDriver() bool {
return !(v.config.Driver == define.VolumeDriverLocal || v.config.Driver == "")
}

func (v *Volume) Mount() (string, error) {
return v.config.MountPoint, v.mount()
Copy link
Member

Choose a reason for hiding this comment

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

Need to v.lock.Lock(); defer v.lock.Unlock() here and Unmount

Copy link
Member

Choose a reason for hiding this comment

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

Thinking about this a bit more - v.config.MountPoint may not be populated until v.mount() runs (I think this is mostly a volume plugins thing), so it's safer to do err := v.mount(); return v.config.MountPoint, err

@mheon
Copy link
Member

mheon commented Feb 23, 2022

If you do a podman run using a volume, then do a podman volume unmount on it when the container is running - does that break anything? Want to make sure we don't need to add extra checks around that.

@rhatdan rhatdan force-pushed the volume branch 2 times, most recently from e7ce688 to 026821e Compare February 23, 2022 19:54
@rhatdan
Copy link
Member Author

rhatdan commented Feb 23, 2022

Since it is in a different mount namespace the unmount will not effect the running container.

Tested this out with a tmpfs container.

@mheon
Copy link
Member

mheon commented Feb 23, 2022

That isn't true? The volume mounts are made before the container is created, and then we bind-mount the mountpoint into the container - so there is no difference between a container requesting an unmount, and a user requesting an unmount, save for the fact that the container is still potentially running. I'm worried that we'll still set the mount counter to 0 if the unmount fails because the volume is in use, which would result in the volume being considered unmounted when it is still mounted.

@rhatdan
Copy link
Member Author

rhatdan commented Feb 23, 2022

What I see is the mount point in the podman unshare aria shows the tmpfs is no longer mounted, but if I exec into the container I see the tmpfs is still mounted and the data I created on it it is still available. This is because in the containers mount namespace the file system is still mounted.
If I run another container on the volume, I will see different content because the tmpfs will get mounted again.

@edsantiago
Copy link
Member

@mheon from my testing, podman volume unmount is a NOP. Actually, volume mount is, too, all it does is display a path to an existing volume. It does not seem to increment refcnt. podman is perfectly happy to volume rm while I still "have" the volume "mounted":

$ sudo bin/podman volume mount myvolume
/var/lib/containers/storage/volumes/myvolume/_data
$ sudo touch files in there, etc etc
$ sudo bin/podman volume rm myvolume
myvolume
$ sudo ls /var/lib/containers/storage/volumes/myvolume
ls: cannot access '/var/lib/containers/storage/volumes/myvolume': No such file or directory

@mheon
Copy link
Member

mheon commented Feb 23, 2022

@edsantiago Did you make the volume with options that would require a mount take place - e.g. podman volume create --opt type=tmpfs --opt device=tmpfs myvolume or similar (options may not work perfectly, I'm going off memory here)?

@edsantiago
Copy link
Member

Uh, no, it was just a plain simple volume create. I was just surprised that podman pulled the rug out from under me while I thought I had the volume "mounted". Not a big deal though.

@mheon
Copy link
Member

mheon commented Feb 23, 2022

Ah - yeah, it's a short-circuit operation unless the volume actually needs a mount. Should probably make that clear in the manpages.

It should always be safe to invoke mount and unmount, even on volumes that don't require a mount, to be clear; it's just that some volumes don't require them, and others do. I think the recommended workflow after the patches would always involve using them.

@rhatdan
Copy link
Member Author

rhatdan commented Feb 24, 2022

I think the bind mount happens after the tmpfs mount which causes the tmpfs mount to leak into the mount namespace.
Bottom line I did the following

$ podman unshare
# ./bin/podman volume create --opt device=tmpfs --opt type=tmpfs --opt o=uid=1000,gid=1000 testvol
# ./bin/podman run -d -v testvol:/vol:Z fedora sleep 1000
52fee416c7a0ac40f085654f4564693d4b5ffc181ec48c174e272378f0283fab
# mount | grep _data
tmpfs on /home/dwalsh/.local/share/containers/storage/volumes/testvol/_data type tmpfs (rw,relatime,seclabel,uid=100999,gid=100999,inode64)
# ./bin/podman exec -l touch /vol/dan
# ./bin/podman volume unmount testvol
testvol
# mount | grep _data
# ./bin/podman exec -l ls /vol
dan

@@ -178,3 +178,35 @@ func (ic *ContainerEngine) VolumeMounted(ctx context.Context, nameOrID string) (
}
return &entities.BoolReport{Value: false}, nil
}

func (ic *ContainerEngine) VolumeMount(ctx context.Context, nameOrIDs []string) ([]*entities.ContainerMountReport, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to use ContainerMountReport or should we make a new type for VolumeMount for consistency?

return reports, nil
}

func (ic *ContainerEngine) VolumeUnmount(ctx context.Context, nameOrIDs []string) ([]*entities.ContainerUnmountReport, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, type consistency.

@rhatdan
Copy link
Member Author

rhatdan commented Feb 28, 2022

@containers/podman-maintainers PTAL

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 1, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago, giuseppe, rhatdan

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:
  • OWNERS [edsantiago,giuseppe,rhatdan]

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

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

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 1, 2022
@openshift-merge-robot openshift-merge-robot merged commit 87d22e1 into containers:main Mar 1, 2022
@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 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 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.

[RFE] podman volume mount|unmount command
8 participants