]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: use kclient xattr to lookup client id 42081/head
authorPatrick Donnelly <pdonnell@redhat.com>
Tue, 29 Jun 2021 00:15:19 +0000 (17:15 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 2 Jul 2021 19:07:42 +0000 (12:07 -0700)
Added relatively recently but in RHEL 8.4.

Fixes: https://tracker.ceph.com/issues/51183
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
qa/tasks/cephfs/kernel_mount.py

index 95e3b401bb87ef49ddca2a570bb133023d8aba49..55fdae5d9e84d205e4fca7bd4d73c7e78625b777 100644 (file)
@@ -151,46 +151,24 @@ class KernelMount(CephFSMount):
         if self.mounted:
             self.umount()
 
-    def _find_debug_dir(self):
+    def _get_debug_dir(self):
         """
-        Find the debugfs folder for this mount
+        Get the debugfs folder for this mount
         """
-        pyscript = dedent("""
-            import glob
-            import os
-            import json
 
-            def get_id_to_dir():
-                result = {}
-                for dir in glob.glob("/sys/kernel/debug/ceph/*"):
-                    mds_sessions_lines = open(os.path.join(dir, "mds_sessions")).readlines()
-                    client_id = mds_sessions_lines[1].split()[1].strip('"')
+        cluster_name = 'ceph'
+        fsid = self.ctx.ceph[cluster_name].fsid
 
-                    result[client_id] = dir
-                return result
+        global_id = self._get_global_id()
 
-            print(json.dumps(get_id_to_dir()))
-            """)
-
-        output = self.client_remote.sh([
-            'sudo', 'python3', '-c', pyscript
-        ], timeout=(5*60))
-        client_id_to_dir = json.loads(output)
-
-        try:
-            return client_id_to_dir[self.client_id]
-        except KeyError:
-            log.error("Client id '{0}' debug dir not found (clients seen were: {1})".format(
-                self.client_id, ",".join(client_id_to_dir.keys())
-            ))
-            raise
+        return os.path.join("/sys/kernel/debug/ceph/", f"{fsid}.client{global_id}")
 
     def read_debug_file(self, filename):
         """
         Read the debug file "filename", return None if the file doesn't exist.
         """
 
-        path = os.path.join(self._find_debug_dir(), filename)
+        path = os.path.join(self._get_debug_dir(), filename)
 
         stdout = StringIO()
         stderr = StringIO()
@@ -203,6 +181,46 @@ class KernelMount(CephFSMount):
                 return None
             raise
 
+    def _get_global_id(self):
+        try:
+            p = self.run_shell_payload("getfattr --only-values -n ceph.client_id .", stdout=StringIO())
+            v = p.stdout.getvalue()
+            prefix = "client"
+            assert v.startswith(prefix)
+            return int(v[len(prefix):])
+        except CommandFailedError:
+            # Probably this fallback can be deleted in a few releases when the kernel xattr is widely available.
+            log.debug("Falling back to messy global_id lookup via /sys...")
+
+            pyscript = dedent("""
+                import glob
+                import os
+                import json
+
+                def get_id_to_dir():
+                    result = {}
+                    for dir in glob.glob("/sys/kernel/debug/ceph/*"):
+                        mds_sessions_lines = open(os.path.join(dir, "mds_sessions")).readlines()
+                        global_id = mds_sessions_lines[0].split()[1].strip('"')
+                        client_id = mds_sessions_lines[1].split()[1].strip('"')
+                        result[client_id] = global_id
+                    return result
+                print(json.dumps(get_id_to_dir()))
+            """)
+
+            output = self.client_remote.sh([
+                'sudo', 'python3', '-c', pyscript
+            ], timeout=(5*60))
+            client_id_to_global_id = json.loads(output)
+
+            try:
+                return client_id_to_global_id[self.client_id]
+            except KeyError:
+                log.error("Client id '{0}' debug dir not found (clients seen were: {1})".format(
+                    self.client_id, ",".join(client_id_to_global_id.keys())
+                ))
+                raise
+
     def get_global_id(self):
         """
         Look up the CephFS client ID for this mount, using debugfs.
@@ -210,11 +228,7 @@ class KernelMount(CephFSMount):
 
         assert self.mounted
 
-        mds_sessions = self.read_debug_file("mds_sessions")
-        assert mds_sessions 
-
-        lines = mds_sessions.split("\n")
-        return int(lines[0].split()[1])
+        return self._get_global_id()
 
     @property
     def _global_addr(self):