-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[POSIX] Pass path to df(1) reference rather than device #2344
Conversation
Otherwise this test fails for environments with active bind-mounts. For example, consider the following: $ mount test.img testdir $ mount --rbind /usr/src testdir/usr/src $ chroot testdir /bin/bash $ python3 Python 3.11.6 (main, Dec 5 2023, 11:03:00) [GCC 13.2.1 20230826] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import psutil, pprint >>> pprint.pprint(psutil.disk_partitions(all=False)) [sdiskpart(device='/dev/loop0', mountpoint='/', fstype='ext4', opts='rw,relatime', maxfile=255, maxpath=4096), sdiskpart(device='/dev/loop0', mountpoint='/usr/src', fstype='ext4', opts='ro,noatime', maxfile=255, maxpath=4096)] >>> pprint.pprint([psutil.disk_usage(x.mountpoint) for x in psutil.disk_partitions(all=False)]) [sdiskusage(total=20530814976, used=7411703808, free=12053757952, percent=38.1), sdiskusage(total=134679105536, used=42708791296, free=85081747456, percent=33.4)] >>> $ df / && df /usr/src Filesystem 1K-blocks Used Available Use% Mounted on /dev/loop0 20049624 7237992 11771248 39% / Filesystem 1K-blocks Used Available Use% Mounted on /dev/root 131522564 41707804 83087644 34% /usr/src Note that psutil has the correct size data, but the wrong block device. If we pass the path to df(1) instead of the incorrect block device, then df(1) will return results from the correct filesystem. Signed-off-by: matoro <[email protected]>
Why is it wrong? (I don't mean related to this test, but in general) |
Because
So maybe that is the correct thing to do? This SO answer says:
But I'm not really sure. |
Hmm, interesting. It must be noted that we use I'm tempted not to merge your PR since the test failure reliably reproduces the problem, so it's good we have it. I'd rather try to fix the problem itself. |
That only tells us how to go from major/minor to block name, but what call would we use to go from mountpoint to major/minor? If we switch from What about if we left Edit: This might not work on SunOS or HP-UX. |
coreutils uses This appears to have major/minor numbers available, AND true block device names.
But this is again Linux-specific and not for other Unix. |
After research here I have come to conclusion that the root of the issue is indeed using Therefore I believe the correct approach to this is to prioritize |
Can you please open a new issue pointing to this one which contains a lot of useful info? |
Summary
Description
Otherwise this test fails for environments with active bind-mounts. For example, consider the following:
Note that psutil has the correct size data, but the wrong block device. If we pass the path to
df(1)
instead of the incorrect block device, thendf(1)
will return results from the correct filesystem.