xfsdump: handle bind mount targets

Today, xfsdump looks at the mount point it was handed, gets
the inode of that directory, and assumes that it is the
filesystem's root inode.

This doesn't work if we have bind-mounted a subdirectory
somewhere, and point xfsdump at that.  The inode number retrieved
is not the filesystem's root inode number, and because this
goes into the dump header and gets checked on restore, things
go badly when the root inode found in the dump does not match
the root inode in the dump header:

# mkfs.xfs -dfile,name=fsfile,size=16g
# mkdir mnt
# mount -o loop fsfile mnt
# mkdir -p mnt/dir
# mkdir -p mnt2/dir
# mount -o bind mnt/dir mnt2/dir
# xfsdump -v trace -J -F -l 0 -  `pwd`/mnt2/dir | xfsdump/restore/xfsrestore -v trace -t - 
...
xfsrestore: tree.c:759: tree_begindir: Assertion `ino != persp->p_rootino || hardh == persp->p_rooth' failed.
#

Fix this by using bulkstat to get the first valid inode in the filesystem.
Compare this to the inode number of the mounted directory, and if they
differ, issue a notice that this may be a bind mount (which means that
more than just the tree under the mount will be dumped; the whole
filesystem is dumped by default).

Reported-by: Jason L Tibbitts III <tibbs@math.uh.edu>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
1 file changed