74b1de
From f89242132dc4756c827113154cc6ad18ad6bde88 Mon Sep 17 00:00:00 2001
74b1de
From: Milind Changire <mchangir@redhat.com>
74b1de
Date: Tue, 19 Feb 2019 12:49:12 +0530
74b1de
Subject: [PATCH 327/335] glusterfind: integrate with gfid2path
74b1de
74b1de
Integration with gfid2path helps avoid file-system crawl and saves
74b1de
precious time. Extended attributes starting with "trusted.gfid2path."
74b1de
are read and the <PGFID>/<BN> values are extracted and the <PGFID> is
74b1de
iteratively resolved from the brick backend to arrive at the full path.
74b1de
74b1de
>Change-Id: I593b02880e3413b77bfceed4a36b00d401f03bc0
74b1de
>fixes: #529
74b1de
>Signed-off-by: Milind Changire <mchangir@redhat.com>
74b1de
>Signed-off-by: Shwetha K Acharya <sacharya@redhat.com>
74b1de
74b1de
backport of https://review.gluster.org/#/c/glusterfs/+/22225/
74b1de
BUG: 1599802
74b1de
Change-Id: I593b02880e3413b77bfceed4a36b00d401f03bc0
74b1de
Signed-off-by: Milind Changire <mchangir@redhat.com>
74b1de
Signed-off-by: Shwetha K Acharya <sacharya@redhat.com>
74b1de
Reviewed-on: https://code.engineering.redhat.com/gerrit/185706
74b1de
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
74b1de
---
74b1de
 tools/glusterfind/src/changelog.py | 45 ++++++++++++++++++++++++++++++++++----
74b1de
 1 file changed, 41 insertions(+), 4 deletions(-)
74b1de
74b1de
diff --git a/tools/glusterfind/src/changelog.py b/tools/glusterfind/src/changelog.py
74b1de
index ef982db..d8f97e0 100644
74b1de
--- a/tools/glusterfind/src/changelog.py
74b1de
+++ b/tools/glusterfind/src/changelog.py
74b1de
@@ -114,6 +114,43 @@ def populate_pgfid_and_inodegfid(brick, changelog_data):
74b1de
                 continue
74b1de
 
74b1de
 
74b1de
+def enum_hard_links_using_gfid2path(brick, gfid, args):
74b1de
+    hardlinks = []
74b1de
+    p = os.path.join(brick, ".glusterfs", gfid[0:2], gfid[2:4], gfid)
74b1de
+    if not os.path.isdir(p):
74b1de
+        # we have a symlink or a normal file
74b1de
+        try:
74b1de
+            file_xattrs = xattr.list(p)
74b1de
+            for x in file_xattrs:
74b1de
+                if x.startswith("trusted.gfid2path."):
74b1de
+                    # get the value for the xattr i.e. <PGFID>/<BN>
74b1de
+                    v = xattr.getxattr(p, x)
74b1de
+                    pgfid, bn = v.split(os.sep)
74b1de
+                    try:
74b1de
+                        path = symlink_gfid_to_path(brick, pgfid)
74b1de
+                        fullpath = os.path.join(path, bn)
74b1de
+                        fullpath = output_path_prepare(fullpath, args)
74b1de
+                        hardlinks.append(fullpath)
74b1de
+                    except (IOError, OSError) as e:
74b1de
+                        logger.warn("Error converting to path: %s" % e)
74b1de
+                        continue
74b1de
+        except (IOError, OSError):
74b1de
+            pass
74b1de
+    return hardlinks
74b1de
+
74b1de
+
74b1de
+def gfid_to_all_paths_using_gfid2path(brick, changelog_data, args):
74b1de
+    path = ""
74b1de
+    for row in changelog_data.gfidpath_get({"path1": "", "type": "MODIFY"}):
74b1de
+        gfid = row[3].strip()
74b1de
+        logger.debug("Processing gfid %s" % gfid)
74b1de
+        hardlinks = enum_hard_links_using_gfid2path(brick, gfid, args)
74b1de
+
74b1de
+        path = ",".join(hardlinks)
74b1de
+
74b1de
+        changelog_data.gfidpath_update({"path1": path}, {"gfid": gfid})
74b1de
+
74b1de
+
74b1de
 def gfid_to_path_using_pgfid(brick, changelog_data, args):
74b1de
     """
74b1de
     For all the pgfids collected, Converts to Path and
74b1de
@@ -314,11 +351,11 @@ def get_changes(brick, hash_dir, log_file, start, end, args):
74b1de
     changelog_data.commit()
74b1de
     logger.info("[2/4] Finished 'pgfid to path' conversions.")
74b1de
 
74b1de
-    # Convert all GFIDs for which no other additional details available
74b1de
-    logger.info("[3/4] Starting 'gfid to path using pgfid' conversions ...")
74b1de
-    gfid_to_path_using_pgfid(brick, changelog_data, args)
74b1de
+    # Convert all gfids recorded for data and metadata to all hardlink paths
74b1de
+    logger.info("[3/4] Starting 'gfid2path' conversions ...")
74b1de
+    gfid_to_all_paths_using_gfid2path(brick, changelog_data, args)
74b1de
     changelog_data.commit()
74b1de
-    logger.info("[3/4] Finished 'gfid to path using pgfid' conversions.")
74b1de
+    logger.info("[3/4] Finished 'gfid2path' conversions.")
74b1de
 
74b1de
     # If some GFIDs fail to get converted from previous step,
74b1de
     # convert using find
74b1de
-- 
74b1de
1.8.3.1
74b1de