Last active
November 15, 2015 09:12
-
-
Save aravindavk/29f673f13c2f8963447e to your computer and use it in GitHub Desktop.
python find_gfid_issues.py <BRICK_PATH>
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
import sys | |
import os | |
import xattr | |
import uuid | |
from errno import ENODATA | |
IGNORE_DIRS = [".glusterfs", ".trashcan"] | |
def valid_symlink(brick_path, path, gfid): | |
path = path.replace(brick_path, "") | |
pdir = os.path.dirname(path) | |
bname = os.path.basename(path) | |
if bname == "": | |
return True | |
if pdir == "": | |
pgfid = "00000000-0000-0000-0000-000000000001" | |
else: | |
pgfid = str(uuid.UUID(bytes=xattr.get(os.path.join(brick_path, | |
pdir), | |
"trusted.gfid"))) | |
expected_link_target = os.path.join("..", | |
"..", | |
pgfid[0:2], | |
pgfid[2:4], | |
pgfid, | |
bname) | |
backend_path = os.path.join(brick_path, | |
".glusterfs", | |
gfid[0:2], | |
gfid[2:4], | |
gfid) | |
if os.path.islink(backend_path): | |
link_target = os.readlink(backend_path) | |
if link_target == expected_link_target: | |
return True | |
return False | |
def crawl(brick_path, path, ignore_dirs=[]): | |
if path in ignore_dirs: | |
return | |
try: | |
gfid = str(uuid.UUID(bytes=xattr.get(path, "trusted.gfid"))) | |
if not valid_symlink(brick_path, path, gfid): | |
print "{0:17}: {1}".format("INVALID SYMLINK", path) | |
except IOError as e: | |
if e.errno == ENODATA: | |
print "{0:17}: {1}".format("NO GFID(DIR)", path) | |
files = os.listdir(path) | |
for f in files: | |
p = os.path.join(path, f) | |
if os.path.isdir(p): | |
crawl(brick_path, p, ignore_dirs) | |
else: | |
try: | |
gfid = str(uuid.UUID(bytes=xattr.get(p, "trusted.gfid"))) | |
except IOError as e: | |
if e.errno == ENODATA: | |
print "{0:17}: {1}".format("NO GFID(FILE)", p) | |
if __name__ == "__main__": | |
brick = sys.argv[1] | |
ignore_dirs = [os.path.join(brick, v) for v in IGNORE_DIRS] | |
crawl(brick, brick, ignore_dirs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about the performance ?