diff options
author | Rajesh <rajesh@gluster.com> | 2011-08-24 12:47:24 +0530 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-11-11 02:01:28 -0800 |
commit | cb9ffbe767b8e5edb30bee95e33ebe9945101250 (patch) | |
tree | c5edcd6b2f3d1302a36321fa7276ead95782ff12 /xlators | |
parent | 359eee148b2be5aaf9677f61f98b89a50d0f1b88 (diff) |
mount/fuse: check for recursive mounts
Adding check_recursive_mount() in mount.glusterfs.in
to check if mount point is in the lineage of any
brick path. Gracefully fails if mount point leads
to recursive mount.
Change-Id: Iedc4cd767d241c8e256181e472c0815f3831a316
BUG: 2003
Reviewed-on: http://review.gluster.com/314
Reviewed-by: Amar Tumballi <amar@gluster.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@gluster.com>
Diffstat (limited to 'xlators')
-rwxr-xr-x | xlators/mount/fuse/utils/mount.glusterfs.in | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/xlators/mount/fuse/utils/mount.glusterfs.in b/xlators/mount/fuse/utils/mount.glusterfs.in index ab11a9788f7..b485a6f724f 100755 --- a/xlators/mount/fuse/utils/mount.glusterfs.in +++ b/xlators/mount/fuse/utils/mount.glusterfs.in @@ -149,7 +149,7 @@ start_glusterfs () cmd_line1=$(echo "$cmd_line1 $mount_point"); $cmd_line1 - inode=$(stat -c %i $mount_point 2>/dev/null); + inode=$(stat -c %i $mount_point 2>/dev/null); # this is required if the stat returns error if [ -z "$inode" ]; then inode="0"; @@ -178,6 +178,63 @@ mount.glusterfs --version" } +# check for recursive mounts. i.e, mounting over an existing brick +check_recursive_mount () +{ + if [ $2 = "/" ]; then + echo Cannot mount over root; + exit 2; + fi + # GFID check first + # remove trailing / from mount point + mnt_dir=${2%/}; + + # check whether getfattr exists + which getfattr > /dev/null; + if [ $? -ne 0 ]; then + return; + fi + + getfattr -n trusted.gfid $mnt_dir 2>/dev/null | grep -iq "trusted.gfid="; + if [ $? -eq 0 ]; then + echo "ERROR: $mnt_dir is in use as a brick of a gluster volume"; + exit 2; + fi + + # check if the mount point is a brick's parent directory + brick_path=(`cat /etc/glusterd/vols/*/bricks/* | grep ^path | cut -d "=" -f 2`); + root_inode=`stat -Lc %i /`; + root_dev=`stat -Lc %d /`; + mnt_inode=`stat -Lc %i $mnt_dir`; + mnt_dev=`stat -Lc %d $mnt_dir`; + for brick in "$brick_path"; + do + # evaluate brick path to see if this is local, if non-local, skip iteration + ls $brick > /dev/null 2>&1; + if [ $? -ne 0 ]; then + continue; + fi + getfattr -n trusted.gfid "$brick" 2>/dev/null | grep -iq "trusted.gfid="; + if [ $? -ne 0 ]; then + continue; + else + # brick is local + while [ 1 ]; + do + tmp_brick="$brick"; + brick="$brick"/..; + brick_dev=`stat -Lc %d $brick`; + brick_inode=`stat -Lc %i $brick`; + if [ "$mnt_inode" -eq "$brick_inode" -a "$mnt_dev" -eq "$brick_dev" ]; then + echo ERROR: $mnt_dir is a parent of the brick $tmp_brick; + exit 2; + fi + [ "$root_inode" -ne "$brick_inode" -o "$root_dev" -ne "$brick_dev" ] || break; + done; + fi + done; +} + main () { helper=$(echo "$@" | sed -n 's/.*\--[ ]*\([^ ]*\).*/\1/p'); @@ -274,6 +331,8 @@ main () exit 0; fi + check_recursive_mount "$@"; + fs_options=$(echo "$fs_options,$new_fs_options"); # Append fuse.glusterfs to PRUNEFS variable in updatedb.conf(5). updatedb(8) |