diff options
| author | Ravishankar N <ravishankar@redhat.com> | 2016-03-21 16:38:25 +0530 | 
|---|---|---|
| committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2016-03-24 20:56:38 -0700 | 
| commit | 7b3d848dd711e43453f46ef06056c2b92536c201 (patch) | |
| tree | 3e5938260e7fdfa57546d41309adf265bda645a1 /extras | |
| parent | 7e5531eb957cb181d6bbf0978be120a064df262b (diff) | |
extras:add gfid-to-dirname.sh
Backport of http://review.gluster.org/#/c/13797/
Add a script that converts the gfid-string of a directory into absolute
path name w.r.t the brick path.
Example:gfid-to-dirname.sh /home/ravi/bricks/brick1 e9c81321-f009-41b0-a009-cd77888c217e
Location of the directory corresponding to gfid:e9c81321-f009-41b0-a009-cd77888c217e is /home/ravi/bricks/brick1/d1/d2/d3/d4/d5/d6/d7/
Change-Id: I276ddf9c4f3d11a5b1932286d848b00b5ea1895d
BUG: 1320367
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
(cherry picked from commit afbdcda3f4d6ffb906976064e0fa6f6b824718c8)
Reviewed-on: http://review.gluster.org/13812
Smoke: Gluster Build System <jenkins@build.gluster.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Diffstat (limited to 'extras')
| -rwxr-xr-x | extras/gfid-to-dirname.sh | 46 | 
1 files changed, 46 insertions, 0 deletions
diff --git a/extras/gfid-to-dirname.sh b/extras/gfid-to-dirname.sh new file mode 100755 index 00000000000..fd359fab58a --- /dev/null +++ b/extras/gfid-to-dirname.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +function read_symlink() +{ +        DOT_GLUSTERFS_PATH=$BRICK_PATH/.glusterfs +        gfid_string=$1 +        symlink_path="$DOT_GLUSTERFS_PATH/${gfid_string:0:2}/${gfid_string:2:2}/$gfid_string" +        #remove trailing '/' +        symlink_path=${symlink_path%/} +        linkname=$(readlink $symlink_path) +        if [ $? -ne 0 ]; then +                echo "readlink of $symlink_path returned an error." >&2 +                exit -1 +        fi +        echo $linkname +} + +main() +{ +        if [ $# -lt 2 ] ;then +                echo "Usage: $0 <brick-path> <gfid-string-of-directory>" +                echo "Example: $0 /bricks/brick1 1b835012-1ae5-4f0d-9db4-64de574d891c" +                exit -1 +        fi + +        BRICK_PATH=$1 +        name=$(read_symlink $2) +        if [ $? -ne 0 ]; then +                exit -1 +        fi + +        while [ ${name:12:36} != "00000000-0000-0000-0000-000000000001" ] +        do +                LOCATION=`basename $name`/$LOCATION +                GFID_STRING=${name:12:36} +                name=$(read_symlink $GFID_STRING) +                if [ $? -ne 0 ]; then +                        exit -1 +                fi +        done + +        LOCATION=`basename $name`/$LOCATION +        echo "Location of the directory corresponding to gfid:$2 is $BRICK_PATH/$LOCATION" +} + +main "$@"  | 
