From unknown Wed Jun 18 23:11:29 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#21372 <21372@debbugs.gnu.org> To: bug#21372 <21372@debbugs.gnu.org> Subject: Status: df prioritizes some bind mounts over real ones. Reply-To: bug#21372 <21372@debbugs.gnu.org> Date: Thu, 19 Jun 2025 06:11:29 +0000 retitle 21372 df prioritizes some bind mounts over real ones. reassign 21372 coreutils submitter 21372 Dave Chiluk severity 21372 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 28 17:08:52 2015 Received: (at submit) by debbugs.gnu.org; 28 Aug 2015 21:08:52 +0000 Received: from localhost ([127.0.0.1]:41732 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVQtH-0006Mb-QR for submit@debbugs.gnu.org; Fri, 28 Aug 2015 17:08:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45772) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVQUC-0005mO-Az for submit@debbugs.gnu.org; Fri, 28 Aug 2015 16:42:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZVQUB-0006ja-1n for submit@debbugs.gnu.org; Fri, 28 Aug 2015 16:42:55 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_20 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:57824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZVQUA-0006jW-Va for submit@debbugs.gnu.org; Fri, 28 Aug 2015 16:42:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZVQUA-0007Z8-6u for bug-coreutils@gnu.org; Fri, 28 Aug 2015 16:42:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZVQU6-0006iv-UY for bug-coreutils@gnu.org; Fri, 28 Aug 2015 16:42:54 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:42424) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZVQU6-0006ir-Oo for bug-coreutils@gnu.org; Fri, 28 Aug 2015 16:42:50 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZVQU6-0004mC-4S for bug-coreutils@gnu.org; Fri, 28 Aug 2015 20:42:50 +0000 From: Dave Chiluk To: bug-coreutils@gnu.org Subject: df prioritizes some bind mounts over real ones. Date: Fri, 28 Aug 2015 15:42:44 -0500 Message-Id: <1440794565-4951-1-git-send-email-chiluk@canonical.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 28 Aug 2015 17:08:49 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) With the recent move to /proc/self/mountinfo `df` now returns bind mounts instead of the original mount when the directory being bound to is shorter than the original mount destination. For example: * $ mount 192.168.1.2:/raid on /raid type nfs /dev/sdc5 on /data type ext4 (rw) $ mount -o bind /data/a on /a type none (rw,bind) $ mount -o bind /raid/temp on /b type none (rw,bind) $df Filesystem 1K-blocks Used Available Use% Mounted on 192.168.1.2:/raid 449830616 229975284 196982196 54% /a /dev/sdc5 7752072192 5581343744 1780023296 76% /b I'd expect to see the original mount prioritized over the bind mount. Like so. $ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdc5 449830616 229975284 196982196 54% /data 192.168.1.2:/raid 7752072192 5581438976 1779929088 76% /raid This is both mildly incorrect and misleading. As the source device in both cases isn't exactly what is being mounted at the destination directory. Instead it is a subdir of the filesystem that is being mounted there. I'm submitting patches to both gnulib and coreutils to correct this issue. Thank you, Dave Chiluk From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 28 17:27:50 2015 Received: (at submit) by debbugs.gnu.org; 28 Aug 2015 21:27:50 +0000 Received: from localhost ([127.0.0.1]:41766 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVRBd-0006pL-95 for submit@debbugs.gnu.org; Fri, 28 Aug 2015 17:27:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45773) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVQUC-0005mP-Gh for submit@debbugs.gnu.org; Fri, 28 Aug 2015 16:42:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZVQUB-0006jj-Ex for submit@debbugs.gnu.org; Fri, 28 Aug 2015 16:42:56 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:47774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZVQUB-0006jf-Bf for submit@debbugs.gnu.org; Fri, 28 Aug 2015 16:42:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZVQUA-0007Z7-6s for bug-coreutils@gnu.org; Fri, 28 Aug 2015 16:42:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZVQU7-0006j6-MN for bug-coreutils@gnu.org; Fri, 28 Aug 2015 16:42:54 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:42425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZVQU7-0006j1-Gj for bug-coreutils@gnu.org; Fri, 28 Aug 2015 16:42:51 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZVQU6-0004mC-SN for bug-coreutils@gnu.org; Fri, 28 Aug 2015 20:42:51 +0000 From: Dave Chiluk To: bug-coreutils@gnu.org Subject: [PATCH] df: fix prioritize real mounts over bind mounts Date: Fri, 28 Aug 2015 15:42:45 -0500 Message-Id: <1440794565-4951-2-git-send-email-chiluk@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440794565-4951-1-git-send-email-chiluk@canonical.com> References: <1440794565-4951-1-git-send-email-chiluk@canonical.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 28 Aug 2015 17:27:47 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Fixes an issue where bind mounts with shorter mount directories than the original mount are prioritized when running df. The root cause of this is that /proc/self/mountinfo now lists the filesystem device with bind mounts rather than the source directory. With /etc/mtab the source device was listed as the originating directory so this was not an issue. More information is available here. https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 --- src/df.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/df.c b/src/df.c index 2e541b9..13e2661 100644 --- a/src/df.c +++ b/src/df.c @@ -652,9 +652,12 @@ filter_mount_list (bool devices_only) else if ((strchr (me->me_devname, '/') /* let "real" devices with '/' in the name win. */ && ! strchr (devlist->me->me_devname, '/')) - /* let a shorter mountdir win. */ - || (strlen (devlist->me->me_mountdir) + /* let a shorter mountdir win. */ + /* Only if it's not a bind mount.*/ + || ((strlen (devlist->me->me_mountdir) > strlen (me->me_mountdir)) + && (strlen (devlist->me->me_mountroot) + > strlen(me->me_mountroot))) /* let an entry overmounted on a new device win... */ || (! STREQ (devlist->me->me_devname, me->me_devname) /* ... but only when matching an existing mnt point, -- 1.9.1 From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 28 20:38:04 2015 Received: (at 21372) by debbugs.gnu.org; 29 Aug 2015 00:38:04 +0000 Received: from localhost ([127.0.0.1]:41902 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVU9k-0004IM-1u for submit@debbugs.gnu.org; Fri, 28 Aug 2015 20:38:04 -0400 Received: from mail2.vodafone.ie ([213.233.128.44]:5241) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVU9g-0004Hw-06 for 21372@debbugs.gnu.org; Fri, 28 Aug 2015 20:38:01 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq0JAID+4FVtTKvs/2dsb2JhbABdgklSHzVpv3wKhXgBAgKBM0wBAQEBAQGBC0EFg14BAQQBAiQLAVYLDQsJFg8JAwIBAgEWLwYBDAgBARqIFAEItjaOdwEBCAIBH4tihRKELAEEjG6IUYUGhQuEcoZ/kVgmhAA9MwGCTAEBAQ Received: from unknown (HELO localhost.localdomain) ([109.76.171.236]) by mail2.vodafone.ie with ESMTP; 29 Aug 2015 01:37:56 +0100 Message-ID: <55E0FEE3.6070805@draigBrady.com> Date: Sat, 29 Aug 2015 01:37:55 +0100 From: =?windows-1252?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Dave Chiluk , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH] df: fix prioritize real mounts over bind mounts References: <1440794565-4951-1-git-send-email-chiluk@canonical.com> <1440794565-4951-2-git-send-email-chiluk@canonical.com> In-Reply-To: <1440794565-4951-2-git-send-email-chiluk@canonical.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 28/08/15 21:42, Dave Chiluk wrote: > Fixes an issue where bind mounts with shorter mount directories than the > original mount are prioritized when running df. The root cause of this > is that /proc/self/mountinfo now lists the filesystem device with bind > mounts rather than the source directory. With /etc/mtab the source > device was listed as the originating directory so this was not an issue. > > More information is available here. > https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 It's debatable as to whether we should prefer standard mounts over bind mounts, but I'm 60:40 for preferring mount points (more towards) the root of the device. > --- > src/df.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/src/df.c b/src/df.c > index 2e541b9..13e2661 100644 > --- a/src/df.c > +++ b/src/df.c > @@ -652,9 +652,12 @@ filter_mount_list (bool devices_only) > else if ((strchr (me->me_devname, '/') > /* let "real" devices with '/' in the name win. */ > && ! strchr (devlist->me->me_devname, '/')) > - /* let a shorter mountdir win. */ > - || (strlen (devlist->me->me_mountdir) > + /* let a shorter mountdir win. */ > + /* Only if it's not a bind mount.*/ > + || ((strlen (devlist->me->me_mountdir) > > strlen (me->me_mountdir)) > + && (strlen (devlist->me->me_mountroot) > + > strlen(me->me_mountroot))) I think this should be: >= strlen (me->me_mountroot) > /* let an entry overmounted on a new device win... */ > || (! STREQ (devlist->me->me_devname, me->me_devname) > /* ... but only when matching an existing mnt point, > Cool, so that depends on http://lists.gnu.org/archive/html/bug-gnulib/2015-08/msg00030.html I had some personal notes RE the mountroot element, which I'll add here for reference. "$ findmnt --df shows bind mounts (and BTRFS subvols) like: SOURCE FSTYPE SIZE USED AVAIL USE% TARGET /dev/sdb2 xfs 12.7G 9.4G 3.3G 74% / /dev/sdb2[/etc] xfs /root/chroot Note the blank stats for the bind mount (df would probably use - - - here). The mountroot is presented in mountinfo and we could adjust mountlist.c to return this element, to allow df to present the bindmount info? Not sure about that actually since findmnt already does this, and also df is DEVICE oriented as per the name." So while we mightn't distinguish the bind mounts like findmnt does, it seems it's still useful to return the mountroot element. This should not introduce API concerns since gnulib is not released as a separate lib. thanks! Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 28 23:44:40 2015 Received: (at 21372) by debbugs.gnu.org; 29 Aug 2015 03:44:40 +0000 Received: from localhost ([127.0.0.1]:41922 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVX4J-0000i6-O4 for submit@debbugs.gnu.org; Fri, 28 Aug 2015 23:44:40 -0400 Received: from mail2.vodafone.ie ([213.233.128.44]:59584) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVX4G-0000ht-Px for 21372@debbugs.gnu.org; Fri, 28 Aug 2015 23:44:37 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMFAAsq4VVtTKvs/2dsb2JhbABdgklSgn3BaYJYAoEzTAEBAQEBAYELhCMBAQEDAScLAVYLDQsJFAIPCQMCAQIBRQYBDAgBARqICAwBtj6OdwEri2KFEoQsAQSMbohRlgKRWCaEAD2DAAEBAQ Received: from unknown (HELO localhost.localdomain) ([109.76.171.236]) by mail2.vodafone.ie with ESMTP; 29 Aug 2015 04:44:35 +0100 Message-ID: <55E12AA2.4000601@draigBrady.com> Date: Sat, 29 Aug 2015 04:44:34 +0100 From: =?windows-1252?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Dave Chiluk , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH] df: fix prioritize real mounts over bind mounts References: <1440794565-4951-1-git-send-email-chiluk@canonical.com> <1440794565-4951-2-git-send-email-chiluk@canonical.com> <55E0FEE3.6070805@draigBrady.com> In-Reply-To: <55E0FEE3.6070805@draigBrady.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 29/08/15 01:37, Pádraig Brady wrote: > On 28/08/15 21:42, Dave Chiluk wrote: >> diff --git a/src/df.c b/src/df.c >> index 2e541b9..13e2661 100644 >> --- a/src/df.c >> +++ b/src/df.c >> @@ -652,9 +652,12 @@ filter_mount_list (bool devices_only) >> else if ((strchr (me->me_devname, '/') >> /* let "real" devices with '/' in the name win. */ >> && ! strchr (devlist->me->me_devname, '/')) >> - /* let a shorter mountdir win. */ >> - || (strlen (devlist->me->me_mountdir) >> + /* let a shorter mountdir win. */ >> + /* Only if it's not a bind mount.*/ >> + || ((strlen (devlist->me->me_mountdir) >> > strlen (me->me_mountdir)) >> + && (strlen (devlist->me->me_mountroot) >> + > strlen(me->me_mountroot))) > > I think this should be: >= strlen (me->me_mountroot) Also we need to cater for NULL me_mountroot. From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 31 16:11:33 2015 Received: (at 21372) by debbugs.gnu.org; 31 Aug 2015 20:11:33 +0000 Received: from localhost ([127.0.0.1]:44075 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWVQT-0004eA-6q for submit@debbugs.gnu.org; Mon, 31 Aug 2015 16:11:33 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:44116) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWVQR-0004dy-AS for 21372@debbugs.gnu.org; Mon, 31 Aug 2015 16:11:31 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZWVQQ-000645-4R; Mon, 31 Aug 2015 20:11:30 +0000 Message-ID: <55E4B4F0.6030101@canonical.com> Date: Mon, 31 Aug 2015 15:11:28 -0500 From: Dave Chiluk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: =?windows-1252?Q?P=E1draig_Brady?= , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH] df: fix prioritize real mounts over bind mounts References: <1440794565-4951-1-git-send-email-chiluk@canonical.com> <1440794565-4951-2-git-send-email-chiluk@canonical.com> <55E0FEE3.6070805@draigBrady.com> <55E12AA2.4000601@draigBrady.com> In-Reply-To: <55E12AA2.4000601@draigBrady.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: chiluk@canonical.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On 08/28/2015 10:44 PM, Pádraig Brady wrote: > On 29/08/15 01:37, Pádraig Brady wrote: >> On 28/08/15 21:42, Dave Chiluk wrote: > >>> diff --git a/src/df.c b/src/df.c >>> index 2e541b9..13e2661 100644 >>> --- a/src/df.c >>> +++ b/src/df.c >>> @@ -652,9 +652,12 @@ filter_mount_list (bool devices_only) >>> else if ((strchr (me->me_devname, '/') >>> /* let "real" devices with '/' in the name win. */ >>> && ! strchr (devlist->me->me_devname, '/')) >>> - /* let a shorter mountdir win. */ >>> - || (strlen (devlist->me->me_mountdir) >>> + /* let a shorter mountdir win. */ >>> + /* Only if it's not a bind mount.*/ >>> + || ((strlen (devlist->me->me_mountdir) >>> > strlen (me->me_mountdir)) >>> + && (strlen (devlist->me->me_mountroot) >>> + > strlen(me->me_mountroot))) >> >> I think this should be: >= strlen (me->me_mountroot) > > Also we need to cater for NULL me_mountroot. > All good review suggestions, I'll post a revised patch shortly. Dave. From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 31 17:05:07 2015 Received: (at 21372) by debbugs.gnu.org; 31 Aug 2015 21:05:07 +0000 Received: from localhost ([127.0.0.1]:44170 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWWGI-0007T8-U8 for submit@debbugs.gnu.org; Mon, 31 Aug 2015 17:05:07 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:44586) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWWGG-0007T0-A4 for 21372@debbugs.gnu.org; Mon, 31 Aug 2015 17:05:04 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZWWGF-0000di-7C; Mon, 31 Aug 2015 21:05:03 +0000 From: Dave Chiluk To: P@draigBrady.com, 21372@debbugs.gnu.org Subject: [PATCH] df: fix prioritize real mounts over bind mounts Date: Mon, 31 Aug 2015 16:05:00 -0500 Message-Id: <1441055100-8689-1-git-send-email-chiluk@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <55E4B4F0.6030101@canonical.com> References: <55E4B4F0.6030101@canonical.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Fixes an issue where bind mounts with shorter mount directories than the original mount are prioritized when running df. The root cause of this is that /proc/self/mountinfo now lists the filesystem device with bind mounts rather than the source directory. With /etc/mtab the source device was listed as the originating directory so this was not an issue. More information is available here. https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 --- src/df.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/df.c b/src/df.c index 2e541b9..00c77c1 100644 --- a/src/df.c +++ b/src/df.c @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) else if ((strchr (me->me_devname, '/') /* let "real" devices with '/' in the name win. */ && ! strchr (devlist->me->me_devname, '/')) - /* let a shorter mountdir win. */ - || (strlen (devlist->me->me_mountdir) + /* let a shorter mountdir win. */ + /* Only if it's not a bind mount. */ + || ((strlen (devlist->me->me_mountdir) > strlen (me->me_mountdir)) + && (devlist->me->me_mntroot != NULL + && me->me_mntroot != NULL + && (strlen (devlist->me->me_mntroot) + > strlen(me->me_mntroot)))) /* let an entry overmounted on a new device win... */ || (! STREQ (devlist->me->me_devname, me->me_devname) /* ... but only when matching an existing mnt point, -- 1.9.1 From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 11 16:31:57 2015 Received: (at 21372) by debbugs.gnu.org; 11 Sep 2015 20:31:58 +0000 Received: from localhost ([127.0.0.1]:57341 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZaUzF-0000Qi-Hj for submit@debbugs.gnu.org; Fri, 11 Sep 2015 16:31:57 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:47212) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZaU54-0005yz-Ss for 21372@debbugs.gnu.org; Fri, 11 Sep 2015 15:33:55 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZaU53-0005KT-Py; Fri, 11 Sep 2015 19:33:53 +0000 Message-ID: <55F32C9F.1030402@canonical.com> Date: Fri, 11 Sep 2015 14:33:51 -0500 From: Dave Chiluk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: =?windows-1252?Q?P=E1draig_Brady?= , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH] df: fix prioritize real mounts over bind mounts References: <1440794565-4951-1-git-send-email-chiluk@canonical.com> <1440794565-4951-2-git-send-email-chiluk@canonical.com> <55E0FEE3.6070805@draigBrady.com> <55E12AA2.4000601@draigBrady.com> <55E4B4F0.6030101@canonical.com> In-Reply-To: <55E4B4F0.6030101@canonical.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-Mailman-Approved-At: Fri, 11 Sep 2015 16:31:56 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: dave.chiluk@canonical.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) I sent out a revised patch here. http://lists.gnu.org/archive/html/bug-coreutils/2015-08/msg00087.html Have you had any chance to take a look at it? Thanks, Dave Chiluk On 08/31/2015 03:11 PM, Dave Chiluk wrote: > On 08/28/2015 10:44 PM, Pádraig Brady wrote: >> On 29/08/15 01:37, Pádraig Brady wrote: >>> On 28/08/15 21:42, Dave Chiluk wrote: >> >>>> diff --git a/src/df.c b/src/df.c >>>> index 2e541b9..13e2661 100644 >>>> --- a/src/df.c >>>> +++ b/src/df.c >>>> @@ -652,9 +652,12 @@ filter_mount_list (bool devices_only) >>>> else if ((strchr (me->me_devname, '/') >>>> /* let "real" devices with '/' in the name win. */ >>>> && ! strchr (devlist->me->me_devname, '/')) >>>> - /* let a shorter mountdir win. */ >>>> - || (strlen (devlist->me->me_mountdir) >>>> + /* let a shorter mountdir win. */ >>>> + /* Only if it's not a bind mount.*/ >>>> + || ((strlen (devlist->me->me_mountdir) >>>> > strlen (me->me_mountdir)) >>>> + && (strlen (devlist->me->me_mountroot) >>>> + > strlen(me->me_mountroot))) >>> >>> I think this should be: >= strlen (me->me_mountroot) >> >> Also we need to cater for NULL me_mountroot. >> > > All good review suggestions, I'll post a revised patch shortly. > > Dave. > From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 11 16:42:24 2015 Received: (at 21372) by debbugs.gnu.org; 11 Sep 2015 20:42:24 +0000 Received: from localhost ([127.0.0.1]:57397 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZaV9L-0000hd-L4 for submit@debbugs.gnu.org; Fri, 11 Sep 2015 16:42:23 -0400 Received: from mail2.vodafone.ie ([213.233.128.44]:20904) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZaV9J-0000hT-HZ for 21372@debbugs.gnu.org; Fri, 11 Sep 2015 16:42:22 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwFAH4781VtTIH4/2dsb2JhbABdglFSVINFvF6FeQKBV0wBAQEBAQGBC4QkAQEEJwsBVgsNCwkWDwkDAgECAUUGAQwIAQEaiBQBCL16jiIBAQgCARsEhXiFeIUUhCwBBIx3iF+FCpEDkWZjhAI9ilIBAQE Received: from unknown (HELO localhost.localdomain) ([109.76.129.248]) by mail2.vodafone.ie with ESMTP; 11 Sep 2015 21:42:20 +0100 Message-ID: <55F33CAC.9010909@draigBrady.com> Date: Fri, 11 Sep 2015 21:42:20 +0100 From: =?windows-1252?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Dave Chiluk , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH] df: fix prioritize real mounts over bind mounts References: <55E4B4F0.6030101@canonical.com> <1441055100-8689-1-git-send-email-chiluk@canonical.com> In-Reply-To: <1441055100-8689-1-git-send-email-chiluk@canonical.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 31/08/15 22:05, Dave Chiluk wrote: > Fixes an issue where bind mounts with shorter mount directories than the > original mount are prioritized when running df. The root cause of this > is that /proc/self/mountinfo now lists the filesystem device with bind > mounts rather than the source directory. With /etc/mtab the source > device was listed as the originating directory so this was not an issue. > > More information is available here. > https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 > --- > src/df.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/src/df.c b/src/df.c > index 2e541b9..00c77c1 100644 > --- a/src/df.c > +++ b/src/df.c > @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) > else if ((strchr (me->me_devname, '/') > /* let "real" devices with '/' in the name win. */ > && ! strchr (devlist->me->me_devname, '/')) > - /* let a shorter mountdir win. */ > - || (strlen (devlist->me->me_mountdir) > + /* let a shorter mountdir win. */ > + /* Only if it's not a bind mount. */ > + || ((strlen (devlist->me->me_mountdir) > > strlen (me->me_mountdir)) > + && (devlist->me->me_mntroot != NULL > + && me->me_mntroot != NULL > + && (strlen (devlist->me->me_mntroot) > + > strlen(me->me_mntroot)))) As previously mentioned, should this be >= ? We'll need to look at tests. This will be quite tricky given the current avoidance of /proc/self/mountinfo in tests. I'll look at adding a separate test for this. thanks, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 11 17:55:12 2015 Received: (at 21372) by debbugs.gnu.org; 11 Sep 2015 21:55:12 +0000 Received: from localhost ([127.0.0.1]:57451 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZaWHo-0005Uc-4b for submit@debbugs.gnu.org; Fri, 11 Sep 2015 17:55:12 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:47828) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZaWHm-0005UU-28 for 21372@debbugs.gnu.org; Fri, 11 Sep 2015 17:55:10 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZaWHl-0001t5-3T; Fri, 11 Sep 2015 21:55:09 +0000 Message-ID: <55F34DBB.5030302@canonical.com> Date: Fri, 11 Sep 2015 16:55:07 -0500 From: Dave Chiluk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: =?windows-1252?Q?P=E1draig_Brady?= , Dave Chiluk , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH] df: fix prioritize real mounts over bind mounts References: <55E4B4F0.6030101@canonical.com> <1441055100-8689-1-git-send-email-chiluk@canonical.com> <55F33CAC.9010909@draigBrady.com> In-Reply-To: <55F33CAC.9010909@draigBrady.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: dave.chiluk@canonical.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On 09/11/2015 03:42 PM, Pádraig Brady wrote: > On 31/08/15 22:05, Dave Chiluk wrote: >> Fixes an issue where bind mounts with shorter mount directories than the >> original mount are prioritized when running df. The root cause of this >> is that /proc/self/mountinfo now lists the filesystem device with bind >> mounts rather than the source directory. With /etc/mtab the source >> device was listed as the originating directory so this was not an issue. >> >> More information is available here. >> https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 >> --- >> src/df.c | 9 +++++++-- >> 1 file changed, 7 insertions(+), 2 deletions(-) >> >> diff --git a/src/df.c b/src/df.c >> index 2e541b9..00c77c1 100644 >> --- a/src/df.c >> +++ b/src/df.c >> @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) >> else if ((strchr (me->me_devname, '/') >> /* let "real" devices with '/' in the name win. */ >> && ! strchr (devlist->me->me_devname, '/')) >> - /* let a shorter mountdir win. */ >> - || (strlen (devlist->me->me_mountdir) >> + /* let a shorter mountdir win. */ >> + /* Only if it's not a bind mount. */ >> + || ((strlen (devlist->me->me_mountdir) >> > strlen (me->me_mountdir)) >> + && (devlist->me->me_mntroot != NULL >> + && me->me_mntroot != NULL >> + && (strlen (devlist->me->me_mntroot) >> + > strlen(me->me_mntroot)))) > > As previously mentioned, should this be >= ? Sorry my apologies for not addressing that. I don't think it should be (strlen (devlist->me->me_mntroot)>= strlen(me->me_mntroot)), because that would give preference to later mounts of the same me_mntroot directory *(I'm specifically thinking of the case where both me_mntroot = "/"). However, looking at the code again, I realized that by adding the NULL checks I have actually changed the behavior for non-linux OS's since the NULL checks would always defeat the (strlen (devlist->me->me_mountdir) > strlen (me->me_mountdir) check. I'm going to think through this nasty if case and see if I can make it prettier. > > We'll need to look at tests. > This will be quite tricky given the current > avoidance of /proc/self/mountinfo in tests. > I'll look at adding a separate test for this. > > thanks, > Pádraig. > Additionally I agree with you that we should mirror the find_mnt bracketting behavior. /dev/sdb2 xfs 12.7G 9.4G 3.3G 74% / /dev/sdb2[/etc] xfs /root/chroot I'll submit that in a different patch once we have this more squared away. Thanks, Dave. From debbugs-submit-bounces@debbugs.gnu.org Fri Sep 11 18:02:38 2015 Received: (at 21372) by debbugs.gnu.org; 11 Sep 2015 22:02:39 +0000 Received: from localhost ([127.0.0.1]:57456 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZaWP0-0005fv-99 for submit@debbugs.gnu.org; Fri, 11 Sep 2015 18:02:38 -0400 Received: from mail2.vodafone.ie ([213.233.128.44]:62141) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZaWOx-0005fl-E3 for 21372@debbugs.gnu.org; Fri, 11 Sep 2015 18:02:36 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al0FAD5O81VtTIH4/2dsb2JhbABdglFSVINFvF2FeQKBUUwBAQEBAQGBC4QkAQEEJwsBVgsNCwkWDwkDAgECAUUGAQwIAQEaiBQBCL1Xjh8BAQgCARsEhXiFeIUUhCwFjHeIX4UKkQORZmOEAj2KUAEBAQ Received: from unknown (HELO localhost.localdomain) ([109.76.129.248]) by mail2.vodafone.ie with ESMTP; 11 Sep 2015 23:02:34 +0100 Message-ID: <55F34F79.2080901@draigBrady.com> Date: Fri, 11 Sep 2015 23:02:33 +0100 From: =?windows-1252?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: dave.chiluk@canonical.com, Dave Chiluk , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH] df: fix prioritize real mounts over bind mounts References: <55E4B4F0.6030101@canonical.com> <1441055100-8689-1-git-send-email-chiluk@canonical.com> <55F33CAC.9010909@draigBrady.com> <55F34DBB.5030302@canonical.com> In-Reply-To: <55F34DBB.5030302@canonical.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 11/09/15 22:55, Dave Chiluk wrote: > On 09/11/2015 03:42 PM, Pádraig Brady wrote: >> On 31/08/15 22:05, Dave Chiluk wrote: >>> Fixes an issue where bind mounts with shorter mount directories than the >>> original mount are prioritized when running df. The root cause of this >>> is that /proc/self/mountinfo now lists the filesystem device with bind >>> mounts rather than the source directory. With /etc/mtab the source >>> device was listed as the originating directory so this was not an issue. >>> >>> More information is available here. >>> https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 >>> --- >>> src/df.c | 9 +++++++-- >>> 1 file changed, 7 insertions(+), 2 deletions(-) >>> >>> diff --git a/src/df.c b/src/df.c >>> index 2e541b9..00c77c1 100644 >>> --- a/src/df.c >>> +++ b/src/df.c >>> @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) >>> else if ((strchr (me->me_devname, '/') >>> /* let "real" devices with '/' in the name win. */ >>> && ! strchr (devlist->me->me_devname, '/')) >>> - /* let a shorter mountdir win. */ >>> - || (strlen (devlist->me->me_mountdir) >>> + /* let a shorter mountdir win. */ >>> + /* Only if it's not a bind mount. */ >>> + || ((strlen (devlist->me->me_mountdir) >>> > strlen (me->me_mountdir)) >>> + && (devlist->me->me_mntroot != NULL >>> + && me->me_mntroot != NULL >>> + && (strlen (devlist->me->me_mntroot) >>> + > strlen(me->me_mntroot)))) >> >> As previously mentioned, should this be >= ? > Sorry my apologies for not addressing that. I don't think it should be > (strlen (devlist->me->me_mntroot)>= strlen(me->me_mntroot)), because > that would give preference to later mounts of the same me_mntroot > directory *(I'm specifically thinking of the case where both me_mntroot > = "/"). > > However, looking at the code again, I realized that by adding the NULL > checks I have actually changed the behavior for non-linux OS's since the > NULL checks would always defeat the (strlen (devlist->me->me_mountdir) > > strlen (me->me_mountdir) check. > > I'm going to think through this nasty if case and see if I can make it > prettier. > >> >> We'll need to look at tests. >> This will be quite tricky given the current >> avoidance of /proc/self/mountinfo in tests. >> I'll look at adding a separate test for this. >> >> thanks, >> Pádraig. >> > > Additionally I agree with you that we should mirror the find_mnt > bracketting behavior. > /dev/sdb2 xfs 12.7G 9.4G 3.3G 74% / > /dev/sdb2[/etc] xfs /root/chroot > > I'll submit that in a different patch once we have this more squared away. Well I mentioned that df was "DEVICE oriented" and so should probably not worry about distinguishing that, especially as the functionality is already provided by findmnt(1). thanks, Pádraig From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 21 15:52:39 2015 Received: (at 21372) by debbugs.gnu.org; 21 Sep 2015 19:52:39 +0000 Received: from localhost ([127.0.0.1]:40746 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ze78g-0003ez-Sm for submit@debbugs.gnu.org; Mon, 21 Sep 2015 15:52:39 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:36249) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ze78e-0003er-Uc for 21372@debbugs.gnu.org; Mon, 21 Sep 2015 15:52:37 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1Ze78d-0008Fd-ST; Mon, 21 Sep 2015 19:52:36 +0000 From: Dave Chiluk To: 21372@debbugs.gnu.org, P@draigBrady.com, Dave Chiluk Subject: [PATCH v3] df: fix prioritize real mounts over bind mounts Date: Mon, 21 Sep 2015 14:52:33 -0500 Message-Id: <1442865153-19780-1-git-send-email-chiluk@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <55F34F79.2080901@draigBrady.com> References: <55F34F79.2080901@draigBrady.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Fixes an issue where bind mounts with shorter mount directories than the original mount are prioritized when running df. The root cause of this is that /proc/self/mountinfo now lists the filesystem device with bind mounts rather than the source directory. With /etc/mtab the source device was listed as the originating directory so this was not an issue. More information is available here. https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 --- src/df.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/df.c b/src/df.c index 2e541b9..fa13c25 100644 --- a/src/df.c +++ b/src/df.c @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) else if ((strchr (me->me_devname, '/') /* let "real" devices with '/' in the name win. */ && ! strchr (devlist->me->me_devname, '/')) - /* let a shorter mountdir win. */ - || (strlen (devlist->me->me_mountdir) + /* let a shorter mountdir win. If it's mntroot is */ + /* also shorter. i.e. not a bind mount. */ + || ((strlen (devlist->me->me_mountdir) > strlen (me->me_mountdir)) + && (devlist->me->me_mntroot == NULL + || me->me_mntroot == NULL + || (strlen (devlist->me->me_mntroot) + > strlen(me->me_mntroot)))) /* let an entry overmounted on a new device win... */ || (! STREQ (devlist->me->me_devname, me->me_devname) /* ... but only when matching an existing mnt point, -- 1.9.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 21 15:57:25 2015 Received: (at 21372) by debbugs.gnu.org; 21 Sep 2015 19:57:25 +0000 Received: from localhost ([127.0.0.1]:40750 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ze7DI-0003lv-Jz for submit@debbugs.gnu.org; Mon, 21 Sep 2015 15:57:24 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:36361) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ze7DG-0003lo-R3 for 21372@debbugs.gnu.org; Mon, 21 Sep 2015 15:57:23 -0400 Received: from 2.general.chiluk.us.vpn ([10.172.65.169]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1Ze7DG-0000KA-6y; Mon, 21 Sep 2015 19:57:22 +0000 Message-ID: <56006120.7090002@canonical.com> Date: Mon, 21 Sep 2015 14:57:20 -0500 From: Dave Chiluk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Dave Chiluk , 21372@debbugs.gnu.org, P@draigBrady.com Subject: Re: [PATCH v3] df: fix prioritize real mounts over bind mounts References: <55F34F79.2080901@draigBrady.com> <1442865153-19780-1-git-send-email-chiluk@canonical.com> In-Reply-To: <1442865153-19780-1-git-send-email-chiluk@canonical.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: dave.chiluk@canonical.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Ignore this patch, I just had an epiphany realized why (strlen (devlist->me->me_mntroot) >= strlen(me->me_mntroot)))) should be the logic. v4 coming shortly. Sorry, Dave. On 09/21/2015 02:52 PM, Dave Chiluk wrote: > Fixes an issue where bind mounts with shorter mount directories than the > original mount are prioritized when running df. The root cause of this > is that /proc/self/mountinfo now lists the filesystem device with bind > mounts rather than the source directory. With /etc/mtab the source > device was listed as the originating directory so this was not an issue. > > More information is available here. > https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 > --- > src/df.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/src/df.c b/src/df.c > index 2e541b9..fa13c25 100644 > --- a/src/df.c > +++ b/src/df.c > @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) > else if ((strchr (me->me_devname, '/') > /* let "real" devices with '/' in the name win. */ > && ! strchr (devlist->me->me_devname, '/')) > - /* let a shorter mountdir win. */ > - || (strlen (devlist->me->me_mountdir) > + /* let a shorter mountdir win. If it's mntroot is */ > + /* also shorter. i.e. not a bind mount. */ > + || ((strlen (devlist->me->me_mountdir) > > strlen (me->me_mountdir)) > + && (devlist->me->me_mntroot == NULL > + || me->me_mntroot == NULL > + || (strlen (devlist->me->me_mntroot) > + > strlen(me->me_mntroot)))) > /* let an entry overmounted on a new device win... */ > || (! STREQ (devlist->me->me_devname, me->me_devname) > /* ... but only when matching an existing mnt point, > From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 21 16:04:16 2015 Received: (at 21372) by debbugs.gnu.org; 21 Sep 2015 20:04:16 +0000 Received: from localhost ([127.0.0.1]:40755 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ze7Jv-0003wi-Vg for submit@debbugs.gnu.org; Mon, 21 Sep 2015 16:04:16 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:36395) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ze7Ju-0003wa-6H for 21372@debbugs.gnu.org; Mon, 21 Sep 2015 16:04:14 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1Ze7Jt-0000Sr-Ej; Mon, 21 Sep 2015 20:04:13 +0000 From: Dave Chiluk To: 21372@debbugs.gnu.org, P@draigBrady.com, Dave Chiluk Subject: [PATCH v4] df: fix prioritize real mounts over bind mounts Date: Mon, 21 Sep 2015 15:04:11 -0500 Message-Id: <1442865851-30601-1-git-send-email-chiluk@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <55F34F79.2080901@draigBrady.com> References: <55F34F79.2080901@draigBrady.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Fixes an issue where bind mounts with shorter mount directories than the original mount are prioritized when running df. The root cause of this is that /proc/self/mountinfo now lists the filesystem device with bind mounts rather than the source directory. With /etc/mtab the source device was listed as the originating directory so this was not an issue. More information is available here. https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 --- src/df.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/df.c b/src/df.c index 2e541b9..4a3afa2 100644 --- a/src/df.c +++ b/src/df.c @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) else if ((strchr (me->me_devname, '/') /* let "real" devices with '/' in the name win. */ && ! strchr (devlist->me->me_devname, '/')) - /* let a shorter mountdir win. */ - || (strlen (devlist->me->me_mountdir) + /* let a shorter mountdir win. If it's mntroot is */ + /* also shorter. i.e. not a bind mount. */ + || ((strlen (devlist->me->me_mountdir) > strlen (me->me_mountdir)) + && (devlist->me->me_mntroot == NULL + || me->me_mntroot == NULL + || (strlen (devlist->me->me_mntroot) + >= strlen(me->me_mntroot)))) /* let an entry overmounted on a new device win... */ || (! STREQ (devlist->me->me_devname, me->me_devname) /* ... but only when matching an existing mnt point, -- 1.9.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 21 18:44:58 2015 Received: (at 21372-done) by debbugs.gnu.org; 21 Sep 2015 22:44:58 +0000 Received: from localhost ([127.0.0.1]:41035 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ze9pS-0007wG-31 for submit@debbugs.gnu.org; Mon, 21 Sep 2015 18:44:58 -0400 Received: from mail1.vodafone.ie ([213.233.128.43]:6291) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ze9pP-0007w7-V1 for 21372-done@debbugs.gnu.org; Mon, 21 Sep 2015 18:44:56 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnoZAEqHAFZtTe0K/2dsb2JhbABdglJSVINFh2e1EoV5AoE1TAEBAQEBAYELhCUBAQQnCwFWCw0LCRYPCQMCAQIBRQYBDAgBARqIFAEIvSeOLQEBCAIBGwSFeIV4hRSELAEEjH2IZ4URiUOHSolKiDljhAI9iiABAQE Received: from unknown (HELO localhost.localdomain) ([109.77.237.10]) by mail1.vodafone.ie with ESMTP; 21 Sep 2015 23:44:54 +0100 Message-ID: <56008865.5050004@draigBrady.com> Date: Mon, 21 Sep 2015 23:44:53 +0100 From: =?windows-1252?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Dave Chiluk , 21372-done@debbugs.gnu.org Subject: Re: bug#21372: [PATCH v4] df: fix prioritize real mounts over bind mounts References: <55F34F79.2080901@draigBrady.com> <1442865851-30601-1-git-send-email-chiluk@canonical.com> In-Reply-To: <1442865851-30601-1-git-send-email-chiluk@canonical.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 21372-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 21/09/15 21:04, Dave Chiluk wrote: > Fixes an issue where bind mounts with shorter mount directories than the > original mount are prioritized when running df. The root cause of this > is that /proc/self/mountinfo now lists the filesystem device with bind > mounts rather than the source directory. With /etc/mtab the source > device was listed as the originating directory so this was not an issue. > > More information is available here. > https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 > --- > src/df.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/src/df.c b/src/df.c > index 2e541b9..4a3afa2 100644 > --- a/src/df.c > +++ b/src/df.c > @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) > else if ((strchr (me->me_devname, '/') > /* let "real" devices with '/' in the name win. */ > && ! strchr (devlist->me->me_devname, '/')) > - /* let a shorter mountdir win. */ > - || (strlen (devlist->me->me_mountdir) > + /* let a shorter mountdir win. If it's mntroot is */ > + /* also shorter. i.e. not a bind mount. */ > + || ((strlen (devlist->me->me_mountdir) > > strlen (me->me_mountdir)) > + && (devlist->me->me_mntroot == NULL > + || me->me_mntroot == NULL > + || (strlen (devlist->me->me_mntroot) > + >= strlen(me->me_mntroot)))) > /* let an entry overmounted on a new device win... */ > || (! STREQ (devlist->me->me_devname, me->me_devname) > /* ... but only when matching an existing mnt point, > This logic looks correct thanks. I'll adjust the comment a bit and maybe refactor all the conditions to a single nearer_device_root boolean. I'll push this later on, with the associated gnulib update. thanks, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 21 20:43:39 2015 Received: (at 21372) by debbugs.gnu.org; 22 Sep 2015 00:43:39 +0000 Received: from localhost ([127.0.0.1]:41047 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeBgI-0002Kb-C9 for submit@debbugs.gnu.org; Mon, 21 Sep 2015 20:43:38 -0400 Received: from mail1.vodafone.ie ([213.233.128.43]:48667) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeBgG-0002KR-1c for 21372@debbugs.gnu.org; Mon, 21 Sep 2015 20:43:37 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQFAG6jAFZtTe0K/2dsb2JhbABdglJSVGMGgly8eoV2AQICgTpMAQEBAQEBgQuEJAEBAQQnYgsNBAMBAgEJFg8JAwIBAgE9CAYBDAYCAQEWBIgUAQMFvH2OLwEBAQEBAQQBAQEBAQEchXiFeIR8DAyELAWMfYhngkqBXWqJQ4dKiUqBBIc1Y4QCPTOJbQEBAQ Received: from unknown (HELO localhost.localdomain) ([109.77.237.10]) by mail1.vodafone.ie with ESMTP; 22 Sep 2015 01:43:34 +0100 Message-ID: <5600A435.1070304@draigBrady.com> Date: Tue, 22 Sep 2015 01:43:33 +0100 From: =?windows-1252?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Dave Chiluk , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH v4] df: fix prioritize real mounts over bind mounts References: <55F34F79.2080901@draigBrady.com> <1442865851-30601-1-git-send-email-chiluk@canonical.com> <56008865.5050004@draigBrady.com> In-Reply-To: <56008865.5050004@draigBrady.com> Content-Type: multipart/mixed; boundary="------------020901000203090402030104" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) This is a multi-part message in MIME format. --------------020901000203090402030104 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit On 21/09/15 23:44, Pádraig Brady wrote: > On 21/09/15 21:04, Dave Chiluk wrote: >> Fixes an issue where bind mounts with shorter mount directories than the >> original mount are prioritized when running df. The root cause of this >> is that /proc/self/mountinfo now lists the filesystem device with bind >> mounts rather than the source directory. With /etc/mtab the source >> device was listed as the originating directory so this was not an issue. >> >> More information is available here. >> https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 >> --- >> src/df.c | 9 +++++++-- >> 1 file changed, 7 insertions(+), 2 deletions(-) >> >> diff --git a/src/df.c b/src/df.c >> index 2e541b9..4a3afa2 100644 >> --- a/src/df.c >> +++ b/src/df.c >> @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) >> else if ((strchr (me->me_devname, '/') >> /* let "real" devices with '/' in the name win. */ >> && ! strchr (devlist->me->me_devname, '/')) >> - /* let a shorter mountdir win. */ >> - || (strlen (devlist->me->me_mountdir) >> + /* let a shorter mountdir win. If it's mntroot is */ >> + /* also shorter. i.e. not a bind mount. */ >> + || ((strlen (devlist->me->me_mountdir) >> > strlen (me->me_mountdir)) >> + && (devlist->me->me_mntroot == NULL >> + || me->me_mntroot == NULL >> + || (strlen (devlist->me->me_mntroot) >> + >= strlen(me->me_mntroot)))) >> /* let an entry overmounted on a new device win... */ >> || (! STREQ (devlist->me->me_devname, me->me_devname) >> /* ... but only when matching an existing mnt point, >> > > This logic looks correct thanks. > I'll adjust the comment a bit and maybe refactor > all the conditions to a single nearer_device_root boolean. > > I'll push this later on, > with the associated gnulib update. Attached is the refactored patch, with also lots of adjustments to commit messages. I'll apply tomorrow. thanks, Pádraig. --------------020901000203090402030104 Content-Type: text/x-patch; name="df-elide-bind-mounts.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="df-elide-bind-mounts.patch" >From 1e925a0a80a783401129dff6840709928c8cf951 Mon Sep 17 00:00:00 2001 From: Dave Chiluk Date: Mon, 21 Sep 2015 15:04:11 -0500 Subject: [PATCH] df: prioritize mounts nearer the device root In the presence of bind mounts of a device, the 4th "mount root" field from /proc/self/mountinfo is now considered, so as to prefer mount points closer to the root of the device. Note on older systems with an /etc/mtab file, the source device was listed as the originating directory, and so this was not an issue. Details at http://pad.lv/1432871 * src/df.c (filter_mount_list): When deduplicating mount entries, only prefer sources nearer or at the root of the device, when the target is nearer the root of the device. * NEWS: Mention the change in behavior. --- NEWS | 3 +++ src/df.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 63574da..9aec259 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,9 @@ GNU coreutils NEWS -*- outline -*- base64 no longer supports hex or oct --wrap parameters, thus better supporting decimals with leading zeros. + df now prefers sources towards the root of a device when + eliding duplicate bind mounted entries. + ** Improvements du no longer stats all mount points at startup, only doing so diff --git a/src/df.c b/src/df.c index 2e541b9..7b294e5 100644 --- a/src/df.c +++ b/src/df.c @@ -641,6 +641,13 @@ filter_mount_list (bool devices_only) if (devlist) { + bool target_nearer_root = strlen (devlist->me->me_mountdir) + > strlen (me->me_mountdir); + /* With bind mounts, prefer items nearer the root of the source */ + bool source_below_root = devlist->me->me_mntroot != NULL + && me->me_mntroot != NULL + && (strlen (devlist->me->me_mntroot) + < strlen(me->me_mntroot)); if (! print_grand_total && me->me_remote && devlist->me->me_remote && ! STREQ (devlist->me->me_devname, me->me_devname)) { @@ -652,9 +659,8 @@ filter_mount_list (bool devices_only) else if ((strchr (me->me_devname, '/') /* let "real" devices with '/' in the name win. */ && ! strchr (devlist->me->me_devname, '/')) - /* let a shorter mountdir win. */ - || (strlen (devlist->me->me_mountdir) - > strlen (me->me_mountdir)) + /* let points towards the root of the device win. */ + || (target_nearer_root && ! source_below_root) /* let an entry overmounted on a new device win... */ || (! STREQ (devlist->me->me_devname, me->me_devname) /* ... but only when matching an existing mnt point, -- 2.4.1 --------------020901000203090402030104-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 22 18:03:41 2015 Received: (at 21372) by debbugs.gnu.org; 22 Sep 2015 22:03:41 +0000 Received: from localhost ([127.0.0.1]:42012 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeVf3-0005jt-1k for submit@debbugs.gnu.org; Tue, 22 Sep 2015 18:03:41 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:51390) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeVf0-0005jk-2J for 21372@debbugs.gnu.org; Tue, 22 Sep 2015 18:03:38 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZeVey-0003F6-IZ; Tue, 22 Sep 2015 22:03:36 +0000 Message-ID: <5601D036.4050009@canonical.com> Date: Tue, 22 Sep 2015 17:03:34 -0500 From: Dave Chiluk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: =?windows-1252?Q?P=E1draig_Brady?= , Dave Chiluk , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH v4] df: fix prioritize real mounts over bind mounts References: <55F34F79.2080901@draigBrady.com> <1442865851-30601-1-git-send-email-chiluk@canonical.com> <56008865.5050004@draigBrady.com> <5600A435.1070304@draigBrady.com> In-Reply-To: <5600A435.1070304@draigBrady.com> Content-Type: multipart/mixed; boundary="------------020405080607060701040602" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: dave.chiluk@canonical.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) This is a multi-part message in MIME format. --------------020405080607060701040602 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit I like and appreciate the refactor, but I think the variable name "target_nearer_device_root" for the boolean, follows the existing code better. I also fixed the logic to match the new name. Dave. On 09/21/2015 07:43 PM, Pádraig Brady wrote: > On 21/09/15 23:44, Pádraig Brady wrote: >> On 21/09/15 21:04, Dave Chiluk wrote: >>> Fixes an issue where bind mounts with shorter mount directories than the >>> original mount are prioritized when running df. The root cause of this >>> is that /proc/self/mountinfo now lists the filesystem device with bind >>> mounts rather than the source directory. With /etc/mtab the source >>> device was listed as the originating directory so this was not an issue. >>> >>> More information is available here. >>> https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 >>> --- >>> src/df.c | 9 +++++++-- >>> 1 file changed, 7 insertions(+), 2 deletions(-) >>> >>> diff --git a/src/df.c b/src/df.c >>> index 2e541b9..4a3afa2 100644 >>> --- a/src/df.c >>> +++ b/src/df.c >>> @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) >>> else if ((strchr (me->me_devname, '/') >>> /* let "real" devices with '/' in the name win. */ >>> && ! strchr (devlist->me->me_devname, '/')) >>> - /* let a shorter mountdir win. */ >>> - || (strlen (devlist->me->me_mountdir) >>> + /* let a shorter mountdir win. If it's mntroot is */ >>> + /* also shorter. i.e. not a bind mount. */ >>> + || ((strlen (devlist->me->me_mountdir) >>> > strlen (me->me_mountdir)) >>> + && (devlist->me->me_mntroot == NULL >>> + || me->me_mntroot == NULL >>> + || (strlen (devlist->me->me_mntroot) >>> + >= strlen(me->me_mntroot)))) >>> /* let an entry overmounted on a new device win... */ >>> || (! STREQ (devlist->me->me_devname, me->me_devname) >>> /* ... but only when matching an existing mnt point, >>> >> >> This logic looks correct thanks. >> I'll adjust the comment a bit and maybe refactor >> all the conditions to a single nearer_device_root boolean. >> >> I'll push this later on, >> with the associated gnulib update. > > Attached is the refactored patch, > with also lots of adjustments to commit messages. > I'll apply tomorrow. > > thanks, > Pádraig. > --------------020405080607060701040602 Content-Type: text/x-patch; name="0001-df-prioritize-mounts-nearer-the-device-root.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-df-prioritize-mounts-nearer-the-device-root.patch" >From 6d926c16018d1406f7477c9e44bc0ed55bf09836 Mon Sep 17 00:00:00 2001 From: Dave Chiluk Date: Mon, 21 Sep 2015 15:04:11 -0500 Subject: [PATCH] df: prioritize mounts nearer the device root In the presence of bind mounts of a device, the 4th "mount root" field from /proc/self/mountinfo is now considered, so as to prefer mount points closer to the root of the device. Note on older systems with an /etc/mtab file, the source device was listed as the originating directory, and so this was not an issue. Details at http://pad.lv/1432871 * src/df.c (filter_mount_list): When deduplicating mount entries, only prefer sources nearer or at the root of the device, when the target is nearer the root of the device. * NEWS: Mention the change in behavior. --- NEWS | 3 +++ src/df.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 63574da..9aec259 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,9 @@ GNU coreutils NEWS -*- outline -*- base64 no longer supports hex or oct --wrap parameters, thus better supporting decimals with leading zeros. + df now prefers sources towards the root of a device when + eliding duplicate bind mounted entries. + ** Improvements du no longer stats all mount points at startup, only doing so diff --git a/src/df.c b/src/df.c index 2e541b9..7e7b2ba 100644 --- a/src/df.c +++ b/src/df.c @@ -641,6 +641,13 @@ filter_mount_list (bool devices_only) if (devlist) { + bool target_nearer_root = strlen (devlist->me->me_mountdir) + > strlen (me->me_mountdir); + /* With bind mounts, prefer items nearer the root of the device */ + bool target_nearer_device_root = devlist->me->me_mntroot != NULL + && me->me_mntroot != NULL + && (strlen (devlist->me->me_mntroot) + >= strlen(me->me_mntroot)); if (! print_grand_total && me->me_remote && devlist->me->me_remote && ! STREQ (devlist->me->me_devname, me->me_devname)) { @@ -652,9 +659,8 @@ filter_mount_list (bool devices_only) else if ((strchr (me->me_devname, '/') /* let "real" devices with '/' in the name win. */ && ! strchr (devlist->me->me_devname, '/')) - /* let a shorter mountdir win. */ - || (strlen (devlist->me->me_mountdir) - > strlen (me->me_mountdir)) + /* let points towards the root of the device win. */ + || (target_nearer_root && target_nearer_device_root) /* let an entry overmounted on a new device win... */ || (! STREQ (devlist->me->me_devname, me->me_devname) /* ... but only when matching an existing mnt point, -- 2.5.0 --------------020405080607060701040602-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 22 18:28:22 2015 Received: (at 21372) by debbugs.gnu.org; 22 Sep 2015 22:28:22 +0000 Received: from localhost ([127.0.0.1]:42041 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeW2v-0006Ie-Fp for submit@debbugs.gnu.org; Tue, 22 Sep 2015 18:28:21 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:51616) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeW2t-0006IW-US for 21372@debbugs.gnu.org; Tue, 22 Sep 2015 18:28:20 -0400 Received: from 1.general.chiluk.us.vpn ([10.172.65.168]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZeW2t-0005PY-AZ; Tue, 22 Sep 2015 22:28:19 +0000 Message-ID: <5601D601.50303@canonical.com> Date: Tue, 22 Sep 2015 17:28:17 -0500 From: Dave Chiluk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: =?windows-1252?Q?P=E1draig_Brady?= , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH v4] df: fix prioritize real mounts over bind mounts References: <55F34F79.2080901@draigBrady.com> <1442865851-30601-1-git-send-email-chiluk@canonical.com> <56008865.5050004@draigBrady.com> <5600A435.1070304@draigBrady.com> <5601D036.4050009@canonical.com> In-Reply-To: <5601D036.4050009@canonical.com> Content-Type: multipart/mixed; boundary="------------060304060701050308060404" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: dave.chiluk@canonical.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) This is a multi-part message in MIME format. --------------060304060701050308060404 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit The patch I just sent out broke existing behavior on non-linux again. I'm really beginning to hate that if statement. Anyhow, I fixed that, and changed it around for readability. Dave. On 09/22/2015 05:03 PM, Dave Chiluk wrote: > I like and appreciate the refactor, but I think the variable name > "target_nearer_device_root" for the boolean, follows the existing code > better. I also fixed the logic to match the new name. > > Dave. > > On 09/21/2015 07:43 PM, Pádraig Brady wrote: >> On 21/09/15 23:44, Pádraig Brady wrote: >>> On 21/09/15 21:04, Dave Chiluk wrote: >>>> Fixes an issue where bind mounts with shorter mount directories than the >>>> original mount are prioritized when running df. The root cause of this >>>> is that /proc/self/mountinfo now lists the filesystem device with bind >>>> mounts rather than the source directory. With /etc/mtab the source >>>> device was listed as the originating directory so this was not an issue. >>>> >>>> More information is available here. >>>> https://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/1432871 >>>> --- >>>> src/df.c | 9 +++++++-- >>>> 1 file changed, 7 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/src/df.c b/src/df.c >>>> index 2e541b9..4a3afa2 100644 >>>> --- a/src/df.c >>>> +++ b/src/df.c >>>> @@ -652,9 +652,14 @@ filter_mount_list (bool devices_only) >>>> else if ((strchr (me->me_devname, '/') >>>> /* let "real" devices with '/' in the name win. */ >>>> && ! strchr (devlist->me->me_devname, '/')) >>>> - /* let a shorter mountdir win. */ >>>> - || (strlen (devlist->me->me_mountdir) >>>> + /* let a shorter mountdir win. If it's mntroot is */ >>>> + /* also shorter. i.e. not a bind mount. */ >>>> + || ((strlen (devlist->me->me_mountdir) >>>> > strlen (me->me_mountdir)) >>>> + && (devlist->me->me_mntroot == NULL >>>> + || me->me_mntroot == NULL >>>> + || (strlen (devlist->me->me_mntroot) >>>> + >= strlen(me->me_mntroot)))) >>>> /* let an entry overmounted on a new device win... */ >>>> || (! STREQ (devlist->me->me_devname, me->me_devname) >>>> /* ... but only when matching an existing mnt point, >>>> >>> >>> This logic looks correct thanks. >>> I'll adjust the comment a bit and maybe refactor >>> all the conditions to a single nearer_device_root boolean. >>> >>> I'll push this later on, >>> with the associated gnulib update. >> >> Attached is the refactored patch, >> with also lots of adjustments to commit messages. >> I'll apply tomorrow. >> >> thanks, >> Pádraig. >> > --------------060304060701050308060404 Content-Type: text/x-patch; name="0001-df-prioritize-mounts-nearer-the-device-root.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-df-prioritize-mounts-nearer-the-device-root.patch" >From d477261ec951ca51c3c85b08cd466b8cf24ae27a Mon Sep 17 00:00:00 2001 From: Dave Chiluk Date: Mon, 21 Sep 2015 15:04:11 -0500 Subject: [PATCH] df: prioritize mounts nearer the device root In the presence of bind mounts of a device, the 4th "mount root" field from /proc/self/mountinfo is now considered, so as to prefer mount points closer to the root of the device. Note on older systems with an /etc/mtab file, the source device was listed as the originating directory, and so this was not an issue. Details at http://pad.lv/1432871 * src/df.c (filter_mount_list): When deduplicating mount entries, only prefer sources nearer or at the root of the device, when the target is nearer the root of the device. * NEWS: Mention the change in behavior. --- NEWS | 3 +++ src/df.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 63574da..9aec259 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,9 @@ GNU coreutils NEWS -*- outline -*- base64 no longer supports hex or oct --wrap parameters, thus better supporting decimals with leading zeros. + df now prefers sources towards the root of a device when + eliding duplicate bind mounted entries. + ** Improvements du no longer stats all mount points at startup, only doing so diff --git a/src/df.c b/src/df.c index 2e541b9..b96155e 100644 --- a/src/df.c +++ b/src/df.c @@ -641,6 +641,13 @@ filter_mount_list (bool devices_only) if (devlist) { + bool target_nearer_root = strlen (devlist->me->me_mountdir) + > strlen (me->me_mountdir); + /* With bind mounts, prefer items nearer the root of the device */ + bool target_nearer_device_root = ! (devlist->me->me_mntroot != NULL + && me->me_mntroot != NULL + && (strlen (devlist->me->me_mntroot) + < strlen(me->me_mntroot))); if (! print_grand_total && me->me_remote && devlist->me->me_remote && ! STREQ (devlist->me->me_devname, me->me_devname)) { @@ -652,9 +659,8 @@ filter_mount_list (bool devices_only) else if ((strchr (me->me_devname, '/') /* let "real" devices with '/' in the name win. */ && ! strchr (devlist->me->me_devname, '/')) - /* let a shorter mountdir win. */ - || (strlen (devlist->me->me_mountdir) - > strlen (me->me_mountdir)) + /* let points towards the root of the device win. */ + || (target_nearer_root && target_nearer_device_root) /* let an entry overmounted on a new device win... */ || (! STREQ (devlist->me->me_devname, me->me_devname) /* ... but only when matching an existing mnt point, -- 2.5.0 --------------060304060701050308060404-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 22 18:47:52 2015 Received: (at 21372) by debbugs.gnu.org; 22 Sep 2015 22:47:52 +0000 Received: from localhost ([127.0.0.1]:42045 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeWLn-0006lS-H6 for submit@debbugs.gnu.org; Tue, 22 Sep 2015 18:47:51 -0400 Received: from mail2.vodafone.ie ([213.233.128.44]:64486) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeWLl-0006lK-OQ for 21372@debbugs.gnu.org; Tue, 22 Sep 2015 18:47:50 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0IAMnZAVZtTIMS/2dsb2JhbABdglJSgwSBFcAoglYCgUlMAQEBAQEBgQtBBYNfAQEEJwsBVgsNCwkWDwkDAgECAUUHDAgBAYguAbx7jiwBK4V4hXiFFIQsAQSVZ5YikgpjhAI9gzmGZwEBAQ Received: from unknown (HELO localhost.localdomain) ([109.76.131.18]) by mail2.vodafone.ie with ESMTP; 22 Sep 2015 23:47:48 +0100 Subject: Re: bug#21372: [PATCH v4] df: fix prioritize real mounts over bind mounts To: dave.chiluk@canonical.com, 21372@debbugs.gnu.org References: <55F34F79.2080901@draigBrady.com> <1442865851-30601-1-git-send-email-chiluk@canonical.com> <56008865.5050004@draigBrady.com> <5600A435.1070304@draigBrady.com> <5601D036.4050009@canonical.com> <5601D601.50303@canonical.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= X-Enigmail-Draft-Status: N1110 Message-ID: <5601DA93.9080100@draigBrady.com> Date: Tue, 22 Sep 2015 23:47:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <5601D601.50303@canonical.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 22/09/15 23:28, Dave Chiluk wrote: > The patch I just sent out broke existing behavior on non-linux again. > I'm really beginning to hate that if statement. Anyhow, I fixed that, > and changed it around for readability. bool target_nearer_device_root = ! (devlist->me->me_mntroot != NULL && me->me_mntroot != NULL && (strlen (devlist->me->me_mntroot) < strlen(me->me_mntroot))); While this is logically correct it's confusing as mntroot is related to the source, not the target. Also the >= implicit in the !< conflicts with "nearer", where "as_near_or_nearer" would be more accurate. That's why I kept the ! outside of the boolean. I'll go with my orig naming unless there are major objections. thanks, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 23 09:51:18 2015 Received: (at 21372) by debbugs.gnu.org; 23 Sep 2015 13:51:18 +0000 Received: from localhost ([127.0.0.1]:42459 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZekS5-000579-H9 for submit@debbugs.gnu.org; Wed, 23 Sep 2015 09:51:17 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58810) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZekS3-00056x-AA for 21372@debbugs.gnu.org; Wed, 23 Sep 2015 09:51:15 -0400 Received: from 2.general.chiluk.us.vpn ([10.172.65.169]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZekS2-0004Xc-7l; Wed, 23 Sep 2015 13:51:14 +0000 Message-ID: <5602AE50.9050807@canonical.com> Date: Wed, 23 Sep 2015 08:51:12 -0500 From: Dave Chiluk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: =?windows-1252?Q?P=E1draig_Brady?= , 21372@debbugs.gnu.org Subject: Re: bug#21372: [PATCH v4] df: fix prioritize real mounts over bind mounts References: <55F34F79.2080901@draigBrady.com> <1442865851-30601-1-git-send-email-chiluk@canonical.com> <56008865.5050004@draigBrady.com> <5600A435.1070304@draigBrady.com> <5601D036.4050009@canonical.com> <5601D601.50303@canonical.com> <5601DA93.9080100@draigBrady.com> In-Reply-To: <5601DA93.9080100@draigBrady.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 21372 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: dave.chiluk@canonical.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) On 09/22/2015 05:47 PM, Pádraig Brady wrote: > On 22/09/15 23:28, Dave Chiluk wrote: >> The patch I just sent out broke existing behavior on non-linux again. >> I'm really beginning to hate that if statement. Anyhow, I fixed that, >> and changed it around for readability. > > > bool target_nearer_device_root = ! (devlist->me->me_mntroot != NULL > && me->me_mntroot != NULL > && (strlen (devlist->me->me_mntroot) > < strlen(me->me_mntroot))); > > While this is logically correct it's confusing > as mntroot is related to the source, not the target. > Also the >= implicit in the !< conflicts with "nearer", > where "as_near_or_nearer" would be more accurate. > That's why I kept the ! outside of the boolean. > > I'll go with my orig naming unless there are major objections. > > thanks, > Pádraig. > I was reading target as referring to the current me that is being iterated on. I still don't like the variable "source_below_root". This implies to me that the source filesystem dir is below the root (i.e. "/") of the filesystem, which obviously would not be possible. How about "longer_mntroot" or "source_longer_mntroot". That way the later logic reads "target_nearer_root && ! source_longer_mntroot" It's more explicit, and implies which variable within the mount_entry that we care about. I think at this point we're really just splitting hairs. Dave. From unknown Wed Jun 18 23:11:29 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 22 Oct 2015 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator