Karel
Thanks a lot for your comments, it is helpful to us.
On 02/11/15 at 12:39pm, Karel Zak wrote:
On Wed, Feb 11, 2015 at 03:17:48PM +0800, Dave Young wrote:
> Karel Zak is maintaining util-linux, he as a blog about bind mount:
>
http://karelzak.blogspot.sg/2011/04/bind-mounts-mtab-and-read-only.html
>
> Ccing him. Karel, can you help reviewing this patch to differenciate
> bind mount?
It seems I need new blog post to more explicitly explain that there is
no "bind mounts" at all, the "bind" is operation, not status.
Ok, so there's nothing we can do to differenciate them because they are
just same..
> On 02/10/15 at 06:46pm, Minfei Huang wrote:
> > To solve this issue, we should determine the real mountpont, if the
> > directory is a bind mounted directory.
There is no real and bind mountpoint, both is the same thing. The
bind operation creates another independent connection to the filesystem.
> > +# findmnt uses the option "-v, --nofsroot" to exclusive the [/dir]
> > +# in the SOURCE column for bind-mounts, then if $_dev equals to
> > +# $_dev_no_bind, the mountpoint is not bind mounted directory.
The [/dir] means that you have mounted subdirectory rather than root
of the filesystem.
mount /dev/sdc1 /mnt/A
mkdir /mnt/A/subdir
mount --bind /mnt/A/subdir /mnt/B
mount --bind /mnt/A /mnt/C
TARGET SOURCE FSTYPE OPTIONS
/mnt/A /dev/sdc1 ext4 rw,relatime,seclabel,stripe=32,data=ordered
/mnt/B /dev/sdc1[/subdir] ext4 rw,relatime,seclabel,stripe=32,data=ordered
/mnt/C /dev/sdc1 ext4 rw,relatime,seclabel,stripe=32,data=ordered
... for /mnt/C there is no [/dir]
Note that btrfs uses the same if you mount btrfs subvolume.
> > +is_bind_mount()
> > +{
> > + local _dev=$(findmnt -k -n -r -o SOURCE $1)
> > + local _dev_no_bind=$(findmnt -k -n -r -v -o SOURCE $1)
> > +
> > + if [[ $_dev = $_dev_no_bind ]]; then
> > + return 1
> > + else
> > + return 0
> > + fi
> > +}
> > +
> > +# We are looking to see if a part of dump path is mounted on some disk.
> > +# But we don't want to look for bind mounted directories. So we should
> > +# determine the real mountpoint, if the directory is a bind mounted
> > +# directory.
> > get_mntpoint_from_path()
> > {
> > - echo $(df $1 | tail -1 | awk '{print $NF}')
> > + local _mnt=$(df $1 | tail -1 | awk '{print $NF}')
local _mnt=$(findmnt -n -o TARGET --target $1)
> > +
> > + if is_bind_mount $mnt; then
> > + # bind mounted directory, we should find the real mount point
> > + # where the device mounts.
> > + for m in `findmnt -k -n -r -o TARGET $_dev_no_bind`; do
> > + if ! is_bind_mount $m; then
> > + echo $m
> > + break
> > + fi
> > + done
The mountpoint created by bind operation is independent on previous
mounts,
mount /mnt/sda1 /A
mount --bind /A /B
umount /A
is pretty valid situation and /B still points to the filesystem.
Hmm, got it, so they are equal, but for subdirectory mount there will be
dependency?
> > + else
> > + echo $_mnt
> > + fi
> > }
I'm not sure if I good understand the original problem, but I'm sure
that care about bind mounts is mistake ;-) If the problem is that
dump is not in the filesystem root then you can try to check if the
root of the filesystem is mounted somewhere else, but maybe the best
would be avoid such fragile setup at all.
We need to know more about the setup of atomic systems, will add you to
the rh bug cc
Thanks
Dave