Subject: Re: bug#12730: coreutils-8.20: FAIL: tests/du/bind-mount-dir-cycle.sh

From: [email-masked]
Date: Thu, 25 Oct 2012 20:08:56 +0200 (CEST)

----- Mail original -----
> De: "Jim Meyering" <[email-masked]>
> À: "g esp" <[email-masked]>
> Cc: [email-masked]
> Envoyé: Jeudi 25 Octobre 2012 18:22:21
> Objet: bug#12730: coreutils-8.20: FAIL: tests/du/bind-mount-dir-cycle.sh
> 

> > The line in /etc/mtab that let hash.c take a different code path is
> > rootfs / rootfs rw 0 0
> 
I withdraw my conclusion concerning rootfs line.
I made something wrong during testing as I can't reproduce that result now.

> You wrote this:
> 
>   chroot-i486] root:/usr/src/coreutils-8.20$ rm -f /etc/mtab
>   [chroot-i486] root:/usr/src/coreutils-8.20$ ln -sf /proc/mounts /etc/mtab
>   [chroot-i486] root:/usr/src/coreutils-8.20$ mount --bind a a/b
>   [chroot-i486] root:/usr/src/coreutils-8.20$ du a
>   du: mount point 'a/b' already traversed
>   4       a
> 
>   [chroot-i486] root:/usr/src/coreutils-8.20$ umount a/b
>   [chroot-i486] root:/usr/src/coreutils-8.20$ rm -f /etc/mtab
>   [chroot-i486] root:/usr/src/coreutils-8.20$ grep ' / ' /proc/mounts >/etc/mtab
>   [chroot-i486] root:/usr/src/coreutils-8.20$ mount --bind a a/b
>   [chroot-i486] root:/usr/src/coreutils-8.20$ du a
>   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:
>     'a/b'
> 
>   4       a
> 
> Does the latter mount command arrange to add a line to the
> one-line (root-only) /etc/mtab ?
> 
Yes
I created a/b by hand directly in /usr/src/coreutils-8.20.

[chroot-i486] root:/usr/src/coreutils-8.20$ grep '^\/dev.* / ' /proc/mounts >/etc/mtab
[chroot-i486] root:/usr/src/coreutils-8.20$ mount --bind a a/b
[chroot-i486] root:/usr/src/coreutils-8.20$ cat /etc/mtab
/dev/disk/by-uuid/7a235d64-5d04-41ac-a959-70465eb74fc8 / ext3 rw,relatime,errors=remount-ro,barrier=1,data=ordered 0 0
/usr/src/coreutils-8.20/a /usr/src/coreutils-8.20/a/b none rw,bind 0 0

The behavior difference is in hash_lookup in if (bucket->data == NULL) test. I added a few printf to find that.
With symlink /etc/mtab, code go further, with regular /etc/mtab, code return NULL there.

> To me, it looks like the *lack* of a line for the a/b mount
> is the problem.  When you remove the symlink the mount command
> does not update the regular-file /etc/mtab, so mount-listing
> code cannot see that a/b is bind-mounted.
> 
No, this is not a missing line but understanding that line content.

To prove that, I started again with a new mtab,
- mounted a/b without writting to mtab
- copied to mtab a line content with a/b mounted exactly the same as in /proc/mounts case,
- hash_lookup answer changed
.
[chroot-i486] root:/usr/src/coreutils-8.20$ rm -f /etc/mtab
[chroot-i486] root:/usr/src/coreutils-8.20$ grep '^\/dev.* / ' /proc/mounts >/etc/mtab
[chroot-i486] root:/usr/src/coreutils-8.20$ mount -n --bind a a/b
[chroot-i486] root:/usr/src/coreutils-8.20$ echo '/dev/disk/by-uuid/7a235d64-5d04-41ac-a959-70465eb74fc8 /usr/src/coreutils-8.20/a/b ext3 rw,relatime,errors=remount-ro,barrier=1,data=ordered 0 0' >>/etc/mtab
[chroot-i486] root:/usr/src/coreutils-8.20$ ./src/du a
./src/du: mount point 'a/b' already traversed
4       a

Gilles