Subject: bug#17833: coreutils 8.22 df

From: Pádraig Brady <[email-masked]>
Date: Tue, 08 Jul 2014 18:28:51 +0100

On 06/25/2014 01:24 PM, Gabor Z. Papp wrote:
> * Pádraig Brady <[email-masked]>:
> 
> | > $ cat /etc/mtab 
> | > /dev/md0 / ext3 rw,errors=remount-ro 0 0
> | > proc /proc proc rw,relatime 0 0
> | > sysfs /sys sysfs rw,relatime 0 0
> | > tmpfs /dev tmpfs rw,relatime,size=4k,mode=755 0 0
> | > devpts /dev/pts devpts rw,relatime,mode=620 0 0
> | > /dev/md1 /var/archive ext3 rw,errors=remount-ro 0 1
> | > /var/archive/home /home none rw,bind 0 0
> | > /var/archive/spool /var/spool none rw,bind 0 0
> | > /var/archive/www /var/lib/www none rw,bind 0 0
> 
> | Is this mtab really a link to /proc/mounts?
> 
> No, its a standalone file.
> 
> | That's the normal case on modern Linux distros.
> 
> Its not a modern linux. :-)
> 
> | > $ df-8.22 -h
> | > Filesystem      Size  Used Avail Use% Mounted on
> | > /dev/md0         21G  8.8G   11G  46% /
> | > tmpfs           4.0K     0  4.0K   0% /dev
> | > 
> | > And where is /dev/md1 ?
> 
> | Not sure what's going on here.
> | Since you've compiled various versions,
> | could you replace src/df.c in your 8.22 build dir with:
> | http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=blob_plain;f=src/df.c;hb=HEAD
> | There have been many df changes since 8.22, so it would
> | be good to check with the latest.
> 
> $ /tmp/df-git -h
> Filesystem      Size  Used Avail Use% Mounted on
> /dev/md0         21G  9.0G   11G  47% /
> tmpfs           4.0K     0  4.0K   0% /dev
> 
> Same problem, /dev/md1 missing.

The missing entry is due to the bind mounts being classified as "dummy" devices.
There is code in gnulib to explicitly avoid that for bind mounts,
however that was negated with this change:
http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=62bb7a8b
Now that change is correct in isolation, but when combined
with the incomplete original change, it triggered the issue.
The attached patch should fix this up.

> 
> | > running df from coreutils 8.21 shows different result:
> | > 
> | > $ df-8.21 -h
> | > Filesystem         Size  Used Avail Use% Mounted on
> | > /dev/md0            21G  8.8G   11G  46% /
> | > tmpfs              4.0K     0  4.0K   0% /dev
> | > /var/archive/home  273G  244G   29G  90% /home
> | > 
> | > Still weird.
> 
> | As part of the device de-duplication logic we used in 8.21
> | we're favoring '/home' since it's shorter than '/var/archive'
> | and thus we're using the '/var/archive/home' "device".
> 
> | > Trying with 8.20:
> | > 
> | > $ df-8.20 -h
> | > Filesystem      Size  Used Avail Use% Mounted on
> | > /dev/md0         21G  8.8G   11G  46% /
> | > tmpfs           4.0K     0  4.0K   0% /dev
> | > /dev/md1        273G  244G   29G  90% /var/archive
> 
> | I agree that this is the best output for your case.
> 
> Right.
> 
> | I suppose we could stat the sources in the de-duplication logic
> | to favor real devices. I.E. stat '/var/archive/home' and '/dev/md1'
> | in your case to favor the latter.

That's something we could still do in addition in coreutils.

thanks,
Pádraig.

>From cbf9cb454f76c64088989bd246f3e5f73256329c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Tue, 8 Jul 2014 18:17:03 +0100
Subject: [PATCH] mountlist: don't treat bind mounts as dummy mounts

This was originally implemented with commit 613bcb62,
however that change failed to check for hasmntopt().
Then a subsequent commit 62bb7a8b caused hasmntopt()
to be replaced on most platforms.

* m4/ls-mntd-fs.m4: Check for hasmntopt() in the MOUNTED_GETMNTENT1
case also.
---
 ChangeLog        |    6 ++++++
 m4/ls-mntd-fs.m4 |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 81e800f..231558f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-07-08  Pádraig Brady  <[email-masked]>
+
+	mountlist: don't treat bind mounts as dummy mounts
+	* m4/ls-mntd-fs.m4: Check for hasmntopt() in the MOUNTED_GETMNTENT1
+	case also.
+
 2014-07-07  Eli Zaretskii  <[email-masked]>
 	    Paul Eggert  <[email-masked]>
 
diff --git a/m4/ls-mntd-fs.m4 b/m4/ls-mntd-fs.m4
index a5e169b..563ed71 100644
--- a/m4/ls-mntd-fs.m4
+++ b/m4/ls-mntd-fs.m4
@@ -151,6 +151,7 @@ if test $ac_cv_func_getmntent = yes; then
         [Define if there is a function named getmntent for reading the list
          of mounted file systems, and that function takes a single argument.
          (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
+      AC_CHECK_FUNCS([hasmntopt])
     fi
   fi
 
-- 
1.7.7.6