Subject: du: bind mount causes corrupted filesystem warning (despite -x !)

From: Alan Jenkins <[email-masked]>
Date: Fri, 01 Jan 2010 14:09:00 +0000

Package: coreutils
Version: 8.1-1
Severity: normal

To reproduce:

$ mkdir -p /mnt/root
$ mount --bind / /mnt/root

(I have this in /etc/fstab...
 it lets me access parts of / which are hidden by other mounted filesystems - 
 this happens to be useful for reasons too long and obscure to be worth explaining)

$ du -x
du: WARNING: Circular directory structure.
This almost certainly means that you have a corrupted file system.
NOTIFY YOUR SYSTEM MANAGER.
The following directory is part of the cycle:
  `./mnt/root'
....

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.33-rc1eeepc-test3 (SMP w/1 CPU core)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages coreutils depends on:
ii  libacl1                       2.2.49-1   Access control list shared library
ii  libattr1                      1:2.4.44-1 Extended attribute shared library
ii  libc6                         2.10.2-2   GNU C Library: Shared libraries
ii  libselinux1                   2.0.89-4   SELinux runtime shared libraries

coreutils recommends no packages.

coreutils suggests no packages.

-- no debconf information

---

From: Jim Meyering <[email-masked]>
Date: Fri, 01 Jan 2010 18:39:26 +0100

> The following directory is part of the cycle:

Thanks for the report.
I confirm that this still happens with the latest.

For now, I suggest you use e.g.,

    du --exclude=/mnt -x /

Unless such bind mounts appear to be common,
I may just leave the current semantics as they are.

By the way, would you want du to traverse each
root partition directory twice?

---

From: Alan Jenkins <[email-masked]>
Date: Fri, 01 Jan 2010 21:03:16 +0000

> root partition directory twice?

No.  I was thinking that -x would treat bind mounts like other mounts, 
and not traverse them.

I guess the problem is that -x is taken to mean "stay on this 
_filesystem_ only", as opposed to "stay on this _mount_ only".

And "stay on this filesystem" is probably easier to implement; you just 
check st_dev.  "Stay on this mount" requires checking /etc/mtab or 
/proc/mounts.

It doesn't seem too hard to add an extra check before printing the 
warning.  But I agree this is probably obscure, so I don't blame you for 
not being very bothered about it :-).

Thanks
Alan

---

From: Jim Meyering <[email-masked]>
Date: Fri, 01 Jan 2010 22:30:51 +0100

Alan Jenkins wrote:
> And "stay on this filesystem" is probably easier to implement; you
> just check st_dev.  "Stay on this mount" requires checking /etc/mtab
> or /proc/mounts.
>
> warning.  But I agree this is probably obscure, so I don't blame you
> for not being very bothered about it :-).

Eventually we'll probably do precisely that, and merely warn
(or maybe suppress or water-down the diagnostic), rather than failing.