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

Set volume NeedsCopyUp to false iff data was copied up #12733

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Jan 3, 2022

Currently Docker copies up the first volume on a mountpoint with
data.

Fixes: #12714

Also added NeedsCopyUP, NeedsChown and MountCount to the podman volume
inspect code.

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 3, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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:

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 3, 2022
Comment on lines 343 to 358
run_podman run --rm --volume $myvolume:/vol $IMAGE true
# Confirm that it shows up in 'volume ls', and confirm values
run_podman volume ls --format json
tests="
Name | $myvolume
Driver | local
NeedsCopyUp | true
"
run_podman run --rm --volume $myvolume:/etc $IMAGE ls /etc/passwd
# Confirm that it shows up in 'volume ls', and confirm values
run_podman volume ls --format json
tests="
Name | $myvolume
Driver | local
NeedsCopyUp | false
"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a NOP. Copy/paste artifact maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, second one has NeedsCopyUp set to False.

Copy link
Collaborator

Choose a reason for hiding this comment

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

...but there's no parse_table. These last two definitions of test are not actually used.

Signing out for the day since, as I just learned, today is a holiday.

Copy link
Member Author

Choose a reason for hiding this comment

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

Went with inspect check.

mountpoint="$output"
test -e "$mountpoint/passwd"
run_podman volume inspect --format '{{.MountCount}}' $myvolume
is "$output" "0" "Mount count should be 0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

How would you test a nonzero MountCount? If it's easy, would you mind adding a test? (I tried real quick but couldn't figure it out)

Copy link
Member Author

Choose a reason for hiding this comment

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

We probably should to this in a separate PR once local mounts are allowed on rootless. (My other PR).

sudo ./bin/podman volume create -o device=tmpfs --opt type=tmpfs dan
$ sudo ./bin/podman volume inspect dan
[
    {
        "Name": "dan",
        "Driver": "local",
        "Mountpoint": "/var/lib/containers/storage/volumes/dan/_data",
        "CreatedAt": "2022-01-04T10:30:45.886433913-05:00",
        "Labels": {},
        "Scope": "local",
        "Options": {
            "device": "tmpfs",
            "type": "tmpfs"
        },
        "MountCount": 0,
        "NeedsCopyUp": true,
        "NeedsChown": true
    }
]
$ sudo ./bin/podman run -d -v dan:/tmp alpine sleep infinity
$ sudo ./bin/podman volume inspect dan
[
    {
        "Name": "dan",
        "Driver": "local",
        "Mountpoint": "/var/lib/containers/storage/volumes/dan/_data",
        "CreatedAt": "2022-01-04T10:30:45.886433913-05:00",
        "Labels": {},
        "Scope": "local",
        "Options": {
            "device": "tmpfs",
            "type": "tmpfs"
        },
        "MountCount": 1,
        "NeedsCopyUp": true
    }
]
 $ sudo podman stop -l -t 0
34cf2f16f45b28ac23a9b66178f82e1dca3c3ebeed6fe3cd6d5d5c17b1f8987b
$ sudo ./bin/podman volume inspect dan
[
    {
        "Name": "dan",
        "Driver": "local",
        "Mountpoint": "/var/lib/containers/storage/volumes/dan/_data",
        "CreatedAt": "2022-01-04T10:30:45.886433913-05:00",
        "Labels": {},
        "Scope": "local",
        "Options": {
            "device": "tmpfs",
            "type": "tmpfs"
        },
        "MountCount": 0,
        "NeedsCopyUp": true
    }
]


run_podman run --rm --volume $myvolume:/vol $IMAGE true
run_podman volume inspect --format '{{ .NeedsCopyUp }}' $myvolume
is "${output}" "true" "NeedsCopyUP should be true"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The description is tautological. What is it about this test case that makes NeedsCopyUp be true, and could the description be changed to express that? E.g. "volume .NeedsCopyUp after mounting on /vol". Similarly for the next one on line 349.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

// NeedsChown indicates that the next time the volume is mounted into
// a container, the container will chown the volume to the container process
// UID/GID.
NeedsChown bool `json:"NeedsChown,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to test NeedsChown?

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 test.

@@ -1753,6 +1746,13 @@ func (c *Container) mountNamedVolume(v *ContainerNamedVolume, mountpoint string)
return vol, nil
}

// Set NeedsCopyUp to false since we are about to do first copy
Copy link
Member

Choose a reason for hiding this comment

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

Why is this moving up? This could cause us to trap the volume in a loop of attempting to copy up if reading the source to copy up fails.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we want to set the valure to false, Only if the copy up succeeded. Currently we set the copyup to false if there is nothing to copy up on the first mount. Whereas Docker only sets it on a successfully copy up.
$ docker run -v myvol:/myvol ... # No copyup
$ docker run -v myvol:/etc ... # Copyup

Versus we do
$ docker run -v myvol:/myvol ... # No copyup
$ docker run -v myvol:/etc ... # No copyup

The goal of this PR is to match Docker.

Copy link
Member

Choose a reason for hiding this comment

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

I'm still a bit worried about this one - it seems like we won't set NeedsCopyUp to false if the directory we want to copy up either does not exist or is empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

If this matches Docker it should not a problem. In the first case you don't want the flag to be set.
If the first time there is an error, you fix the error, now the copyup will not happen, and you have to delete the volume and recreate it.

@rhatdan rhatdan force-pushed the copy branch 2 times, most recently from 996d0d6 to e2d8533 Compare January 4, 2022 15:34
@edsantiago
Copy link
Collaborator

Tests LGTM; I'd like @mheon to confirm that his concerns are addressed.

Currently Docker copies up the first volume on a mountpoint with
data.

Fixes: containers#12714

Also added NeedsCopyUP, NeedsChown and MountCount to the podman volume
inspect code.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@mheon
Copy link
Member

mheon commented Jan 7, 2022

/lgtm

This behavior, frankly, makes no sense to me. But it matches what Docker does, so I guess we're obligated to follow.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 7, 2022
@openshift-merge-robot openshift-merge-robot merged commit 41934ac into containers:main Jan 7, 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 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 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 behavior with shared volumes : copying files from mounted path
4 participants