Subject: Re: Bug#563254: du: bind mount causes corrupted filesystem warning (despite -x !)

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

Alan Jenkins wrote:
> Jim Meyering wrote:
>> Alan Jenkins wrote:
>>
>>> 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'
>>> ....
>>>
>>
>> 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?
>>
>
> 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 :-).

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