-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
[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 |
test/system/160-volumes.bats
Outdated
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 | ||
" |
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.
This looks like a NOP. Copy/paste artifact maybe?
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.
No, second one has NeedsCopyUp set to False.
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.
...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.
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.
Went with inspect check.
test/system/160-volumes.bats
Outdated
mountpoint="$output" | ||
test -e "$mountpoint/passwd" | ||
run_podman volume inspect --format '{{.MountCount}}' $myvolume | ||
is "$output" "0" "Mount count should be 0" |
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.
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)
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.
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
}
]
test/system/160-volumes.bats
Outdated
|
||
run_podman run --rm --volume $myvolume:/vol $IMAGE true | ||
run_podman volume inspect --format '{{ .NeedsCopyUp }}' $myvolume | ||
is "${output}" "true" "NeedsCopyUP should be true" |
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.
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.
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.
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"` |
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.
Is there a way to test NeedsChown
?
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.
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 |
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.
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.
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.
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.
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'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.
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.
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.
996d0d6
to
e2d8533
Compare
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 <[email protected]>
/lgtm This behavior, frankly, makes no sense to me. But it matches what Docker does, so I guess we're obligated to follow. |
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 [email protected]