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

Inconsistent reporting of st_nlink #435

Open
allisonkarlitskaya opened this issue Jan 28, 2025 · 0 comments
Open

Inconsistent reporting of st_nlink #435

allisonkarlitskaya opened this issue Jan 28, 2025 · 0 comments

Comments

@allisonkarlitskaya
Copy link

  1. Enable fuse-overlayfs for your container config:
$ cat ~/.config/containers/storage.conf 
[storage]
driver="overlay"

[storage.options.overlay]
mount_program = "/usr/bin/fuse-overlayfs"
  1. podman run -it --rm fedora
    In this container image the /usr/share/crypto-policies/DEFAULT/bind.txt and /usr/share/crypto-policies/back-ends/DEFAULT/bind.config files are hardlinked.

  2. Run this command:

# stat /usr/share/crypto-policies/DEFAULT/bind.txt
...
Device: 0,125	Inode: 50057153    Links: 1
...

Note the device and inode, and the fact that Links: 1.

  1. Run this command:
# stat /usr/share/crypto-policies/back-ends/DEFAULT/bind.config 
...
Device: 0,125	Inode: 50057153    Links: 2
...

Note that this is the same inode, on the same device, but somehow it has Links: 2 now.

  1. Run this command (which is the same as the first command):
# stat /usr/share/crypto-policies/DEFAULT/bind.txt 
...
Device: 0,125	Inode: 50057153    Links: 2
...

And now note that Links: 2 as well when accessing the file through the original filename (which used to report Links: 1 in step 3).

The only think I can think of is that fuse-overlayfs reports st_nlink as 1 until it "sees" the second hardlink to the file, at which point it updates its opinion to st_nlink being 2, and persists that change in some kind of a cache.

Maybe it's doing that to avoid leaking outside information into the container? ie: maybe there are extra hardlinks that the container should not know about?

Either way, this is causing problems with programs inside of the container that attempt to detect hardlinks by collecting (dev, inode) values from files that have st_nlink > 1.

allisonkarlitskaya added a commit to allisonkarlitskaya/composefs-rs that referenced this issue Jan 28, 2025
While pairing with Timothée we discovered that the examples don't work
on his system because the `cfsctl create-image` on the inside of the
container build fails to detect all hardlinks.  The difference is that
his podman storage driver is using fuse-overlayfs, which doesn't always
accurately report `st_nlink`.  The behaviour is odd: when observing the
hardlink via the first filename it will report a given `(st_dev,
st_ino)` with `st_nlink` of 1 but when inspecting it via the second
filename it will report the same `(st_dev, st_ino)` but with `st_nlink`
of 2 this time.

Let's just be "less clever" and store all non-directory inodes in our
hashtable as potential hardlinks.

See containers/fuse-overlayfs#435

Signed-off-by: Allison Karlitskaya <[email protected]>
Co-Authored-By: Timothée Ravier <[email protected]>
travier added a commit to containers/composefs-rs that referenced this issue Jan 29, 2025
While pairing with Timothée we discovered that the examples don't work
on his system because the `cfsctl create-image` on the inside of the
container build fails to detect all hardlinks.  The difference is that
his podman storage driver is using fuse-overlayfs, which doesn't always
accurately report `st_nlink`.  The behaviour is odd: when observing the
hardlink via the first filename it will report a given `(st_dev,
st_ino)` with `st_nlink` of 1 but when inspecting it via the second
filename it will report the same `(st_dev, st_ino)` but with `st_nlink`
of 2 this time.

Let's just be "less clever" and store all non-directory inodes in our
hashtable as potential hardlinks.

See containers/fuse-overlayfs#435

Signed-off-by: Allison Karlitskaya <[email protected]>
Co-Authored-By: Timothée Ravier <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant