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

REST API /system/df UsageData.RefCount on volumes is always 1 #15720

Closed
benoitf opened this issue Sep 9, 2022 · 3 comments · Fixed by #15753
Closed

REST API /system/df UsageData.RefCount on volumes is always 1 #15720

benoitf opened this issue Sep 9, 2022 · 3 comments · Fixed by #15753
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. podman-desktop

Comments

@benoitf
Copy link
Contributor

benoitf commented Sep 9, 2022

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

In order to see who is using a volume, I'm using the RefCount attribute of UsageData field

But even if you create a volume without using it, it returns 1.
And if you create multiple containers using that volume, it's still using 1

Steps to reproduce the issue:

  1. Create a volume without using it
$ dummyVolume=$(podman volume create)

Use REST api to see refCount

$ curl --silent --unix-socket /Users/benoitf/.local/share/containers/podman/machine/podman-machine-default/podman.sock "http:/v1.41/system/df" | jq --arg volumeName $dummyVolume '.Volumes[] | select(.Name == ($volumeName))'
{
  "Driver": "",
  "Labels": {},
  "Mountpoint": "",
  "Name": "413f47a2d1656a4ec6e876543dc8a0caa5256c670a425638eff7be9730da0229",
  "Options": null,
  "Scope": "local",
  "UsageData": {
    "RefCount": 1,
    "Size": 0
  }
}

It's already invalid

  1. Now, try to start containers using that volume
$ podman run -d --mount "type=volume,src=$dummyVolume,target=/foo" docker.io/library/httpd
$ podman run -d --mount "type=volume,src=$dummyVolume,target=/foo" docker.io/library/httpd
  1. Rest API is still invalid
$ curl --silent --unix-socket /Users/benoitf/.local/share/containers/podman/machine/podman-machine-default/podman.sock "http:/v1.41/system/df" | jq --arg volumeName $dummyVolume '.Volumes[] | select(.Name == ($volumeName))'
{
  "Driver": "",
  "Labels": {},
  "Mountpoint": "",
  "Name": "413f47a2d1656a4ec6e876543dc8a0caa5256c670a425638eff7be9730da0229",
  "Options": null,
  "Scope": "local",
  "UsageData": {
    "RefCount": 1,
    "Size": 0
  }
}

And we still have our container using it

$ podman inspect 18e7216f21ab0eddb5fab99c388ba04030809b6870cd0c595e7bc84008c7fb3d | jq '.[0].Mounts'
[
  {
    "Type": "volume",
    "Name": "413f47a2d1656a4ec6e876543dc8a0caa5256c670a425638eff7be9730da0229",
    "Source": "/var/home/core/.local/share/containers/storage/volumes/413f47a2d1656a4ec6e876543dc8a0caa5256c670a425638eff7be9730da0229/_data",
    "Destination": "/foo",
    "Driver": "local",
    "Mode": "",
    "Options": [
      "nosuid",
      "nodev",
      "rbind"
    ],
    "RW": true,
    "Propagation": "rprivate"
  }
]

Describe the results you received:
RefCount = 1

Describe the results you expected:
Valid RefCount

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

4.2.1

Output of podman info:

(paste your output here)

Package info (e.g. output of rpm -q podman or apt list podman):

(paste your output here)

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)

Yes/No

Additional environment details (AWS, VirtualBox, physical, etc.):

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 9, 2022
@benoitf
Copy link
Contributor Author

benoitf commented Sep 9, 2022

Implementation is bogus:

@vrothberg
Copy link
Member

Thanks for reaching out, @benoitf!

@mheon PTAL

@mheon
Copy link
Member

mheon commented Sep 12, 2022

We can get an array of containers referencing a volume via VolumeInUse() from the state. Get the length of the array, and we have the refcount. I can take this.

@mheon mheon self-assigned this Sep 12, 2022
mheon added a commit to mheon/libpod that referenced this issue Sep 12, 2022
The field was already exposed already in the `system df` output
so this just required a bit of plumbing and testing.

As part of this, fix `podman systemd df` volume in-use logic.
Previously, volumes were only considered to be in use if the
container using them was running. This does not match Docker's
behavior, where a volume is considered in use as long as a
container exists that uses the volume, even if said container is
not running.

Fixes containers#15720

Signed-off-by: Matthew Heon <[email protected]>
@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 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. podman-desktop
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants