glusterfs中,使用gfid定位文件的方法

Glusterfs中,在brick对应的path下,有一个.glusterfs文件夹,其中保存了相应文件的gfid。
比如,有文件的gfid是860fc6e5-73fc-42a6-af49-c75f98b52d0c,则其对应gfid路径为:

.glusterfs/86/0f/860fc6e5-73fc-42a6-af49-c75f98b52d0c

第一级目录对应gfid的1-2位。第二级目录对应gfid的3-4位。

在这个路径下,有一个名字为$gfid的文件,用ls -i查看其inode:

    ls -i 860fc6e5-73fc-42a6-af49-c75f98b52d0c
    5242923 860fc6e5-73fc-42a6-af49-c75f98b52d0c

即,这个gfid文件的inode编号是5242923

如果860fc6e5-73fc-42a6-af49-c75f98b52d0c映射的文件是目录,则它是一个指向这个目录真实位置的符号链接。
如果860fc6e5-73fc-42a6-af49-c75f98b52d0c映射的文件是文件,则它是一个指向这个文件真实位置的硬链接。

所以,可以通过inode找到其具体的位置:

    #在brick路径下执行
   find ./ -inum "5242923" ! -path \*.glusterfs/\*

有人已经实现了脚本(gfid-resolver.sh)[https://gist.github.com/semiosis/4392640]。
粘贴如下:

#!/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

posted @ 2015-12-27 18:21  Vman  Views(2837)  Comments(0Edit  收藏  举报