lstat in Ubuntu 20.04 LX zones reporting incorrect values
I noticed that my build zones that use ccache were filling up despite there being a configured limit to the cache size. Despite the filesystem being full, ccache reporting was showing a much smaller size.
Ccache is using lstat to get the block count for the cache files (st_blocks) which is multiplied by 512 to approximate the size.
Picking a random cache file I see the following on a 16.04 zone:
- stat /home/.ccache/7/5/e446e54e52e11df06f2f588aae4c35-2994365.o
Size: 602072 Blocks: 1285 IO Block: 131072 regular file
which would give the size as 657920.
However, on a 20.04 zone:
- stat /home/.ccache/e/5/6a9c5k5jfcncsj97gmtmr4f6vc2vgeqR
Size: 1130311 Blocks: 662 IO Block: 131072 regular file
which would give the size as 318464, about 28% of the actual size!
Changing the ccache code to just use st_size, still gives accurate reporting elsewhere but now over reports the space used by ~3.5 (1/0.28)
This also breaks du:
- ls -lh ccache
-rwxr-xr-x 1 root root 1.8M Mar 21 02:43 ccache
- du -sh ccache
So, it looks like lstat has a problem in Ubuntu 20.04 LX zones.