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