Created
December 10, 2015 11:54
-
-
Save aravindavk/d1d0ca9c874b7d3d8d86 to your computer and use it in GitHub Desktop.
This file contains 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
import xattr | |
import sys | |
import os | |
ROOT_GFID = "00000000-0000-0000-0000-000000000001" | |
PFX = "user.pgfid" | |
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 | |
def gfid_to_path(brick, gfid): | |
backend_path = os.path.join(brick, ".glusterfs", gfid[0:2], gfid[2:4], | |
gfid) | |
if os.path.isdir(backend_path): | |
print symlink_gfid_to_path(brick, gfid) | |
all_xattrs = xattr.list(backend_path, nofollow=True) | |
for x in all_xattrs: | |
if x.startswith(PFX): | |
pgfid = x.split(".")[2] | |
pdir = symlink_gfid_to_path(brick, pgfid) | |
bn = xattr.get(backend_path, x, nofollow=True) | |
print os.path.join(pdir, bn) | |
if __name__ == "__main__": | |
gfid_to_path(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment