Skip to content

Instantly share code, notes, and snippets.

@aravindavk
Last active February 24, 2016 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aravindavk/afb16813261794faa432 to your computer and use it in GitHub Desktop.
Save aravindavk/afb16813261794faa432 to your computer and use it in GitHub Desktop.
To find directory path from GFID. Usage: python dirname_from_gfid.py <BRICK_ROOT> <GFID>
#!/usr/bin/env python
import os
import sys
ROOT_GFID = "00000000-0000-0000-0000-000000000001"
def symlink_gfid_to_path(brick, gfid):
"""
Each directories are symlinked to file named GFID
in .glusterfs directory of brick backend. Using readlink
we get PARGFID/basename of dir. readlink recursively till
we get PARGFID as ROOT_GFID.
"""
if gfid == ROOT_GFID:
return ""
out_path = ""
while True:
path = os.path.join(brick, ".glusterfs", gfid[0:2], gfid[2:4], gfid)
path_readlink = os.readlink(path)
pgfid = os.path.dirname(path_readlink)
out_path = os.path.join(os.path.basename(path_readlink), out_path)
if pgfid == "../../00/00/%s" % ROOT_GFID:
break
gfid = os.path.basename(pgfid)
return out_path
if __name__ == "__main__":
brick_path = sys.argv[1]
gfid = sys.argv[2]
print (symlink_gfid_to_path(brick_path, gfid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment