Last active
November 29, 2023 10:01
-
-
Save louiszuckerman/4392640 to your computer and use it in GitHub Desktop.
Glusterfs GFID Resolver Turns a GFID into a real path in the brick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "$#" < "2" || "$#" > "3" ]]; then | |
cat <<END | |
Glusterfs GFID resolver -- turns a GFID into a real file path | |
Usage: $0 <brick-path> <gfid> [-q] | |
<brick-path> : the path to your glusterfs brick (required) | |
<gfid> : the gfid you wish to resolve to a real path (required) | |
-q : quieter output (optional) | |
with this option only the actual resolved path is printed. | |
without this option $0 will print the GFID, | |
whether it identifies a file or directory, and the resolved | |
path to the real file or directory. | |
Theory: | |
The .glusterfs directory in the brick root has files named by GFIDs | |
If the GFID identifies a directory, then this file is a symlink to the | |
actual directory. If the GFID identifies a file then this file is a | |
hard link to the actual file. | |
END | |
exit | |
fi | |
BRICK="$1" | |
GFID="$2" | |
GP1=`cut -c 1-2 <<<"$GFID"` | |
GP2=`cut -c 3-4 <<<"$GFID"` | |
GFIDPRE="$BRICK"/.glusterfs/"$GP1"/"$GP2" | |
GFIDPATH="$GFIDPRE"/"$GFID" | |
if [[ "$#" == "2" ]]; then | |
echo -ne "$GFID\t==\t" | |
fi | |
if [[ -h "$GFIDPATH" ]]; then | |
if [[ "$#" == "2" ]]; then | |
echo -ne "Directory:\t" | |
fi | |
DIRPATH="$GFIDPRE"/`readlink "$GFIDPATH"` | |
echo $(cd $(dirname "$DIRPATH"); pwd -P)/$(basename "$DIRPATH") | |
else | |
if [[ "$#" == "2" ]]; then | |
echo -ne "File:\t" | |
fi | |
INUM=`ls -i "$GFIDPATH" | cut -f 1 -d \ ` | |
find "$BRICK" -inum "$INUM" ! -path \*.glusterfs/\* | |
fi |
Great piece of software! :)
Saved the day!
Many thanks.
Great~! Thx. :)
I get the following output:
c4b19f1c-cc18-4727-87a4-18de8fe0078f == Directory: /tmp/gfid-resolver.sh: line 46: cd: /data/brick/.glusterfs/c4/b1/../../92/1b/921bfe8e-81ef-4579-b335-abfa2c7e6aea: Too many levels of symbolic links
/tmp/OC_DEFAULT_MODULE
any idea what's wrong?
@semiosis, what does it mean when I get this output: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx == File:
after I run the script?
Hmm not giving me an output I expect,
8><---
glusterp2.graywitch.co.nz:
Brick glusterp1:/bricks/brick1/gv0
gfid:eafb8799-4e7a-4264-9213-26997c5a4693
Status: Connected
Number of entries in split-brain: 1
8><---
8><---
[root@glusterp2 fb]# sh gfid.run /bricks/brick1/gv0 eafb8799-4e7a-4264-9213-26997c5a4693 -q
[root@glusterp2 fb]#
8><---
?
Looks like replacing readlink
with readlink -f
will simplify the script and make it more robust against the Too many levels of symbolic links
errors.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really helpful :)