Blame SOURCES/0008-lvm-Fix-reading-statistics-for-VDO-pools-with-VDO-8.patch

940a02
From e0fcbae856454dba9df3f8df800d74fde66731e5 Mon Sep 17 00:00:00 2001
940a02
From: Vojtech Trefny <vtrefny@redhat.com>
940a02
Date: Tue, 31 Aug 2021 14:07:23 +0200
940a02
Subject: [PATCH] lvm: Fix reading statistics for VDO pools with VDO 8
940a02
940a02
The statistics are no longer available in /sys/kvdo, in the latest
940a02
version of kvdo we need to use /sys/block/<pool>/vdo/statistics.
940a02
940a02
Resolves: rhbz#1994220
940a02
---
940a02
 src/plugins/vdo_stats.c | 42 +++++++++++++++++++++++++++++++++++++----
940a02
 1 file changed, 38 insertions(+), 4 deletions(-)
940a02
940a02
diff --git a/src/plugins/vdo_stats.c b/src/plugins/vdo_stats.c
940a02
index ed04b51..2e244aa 100644
940a02
--- a/src/plugins/vdo_stats.c
940a02
+++ b/src/plugins/vdo_stats.c
940a02
@@ -133,6 +133,23 @@ static void add_computed_stats (GHashTable *stats) {
940a02
     add_journal_stats (stats);
940a02
 }
940a02
 
940a02
+static gchar* _dm_node_from_name (const gchar *map_name, GError **error) {
940a02
+    gchar *dev_path = NULL;
940a02
+    gchar *ret = NULL;
940a02
+    gchar *dev_mapper_path = g_strdup_printf ("/dev/mapper/%s", map_name);
940a02
+
940a02
+    dev_path = bd_utils_resolve_device (dev_mapper_path, error);
940a02
+    g_free (dev_mapper_path);
940a02
+    if (!dev_path)
940a02
+        /* error is already populated */
940a02
+        return NULL;
940a02
+
940a02
+    ret = g_path_get_basename (dev_path);
940a02
+    g_free (dev_path);
940a02
+
940a02
+    return ret;
940a02
+}
940a02
+
940a02
 GHashTable __attribute__ ((visibility ("hidden")))
940a02
 *vdo_get_stats_full (const gchar *name, GError **error) {
940a02
     GHashTable *stats;
940a02
@@ -141,14 +158,31 @@ GHashTable __attribute__ ((visibility ("hidden")))
940a02
     const gchar *direntry;
940a02
     gchar *s;
940a02
     gchar *val = NULL;
940a02
+    g_autofree gchar *dm_node = NULL;
940a02
 
940a02
-    /* TODO: does the `name` need to be escaped? */
940a02
-    stats_dir = g_build_path (G_DIR_SEPARATOR_S, VDO_SYS_PATH, name, "statistics", NULL);
940a02
+    /* try "new" (kvdo >= 8) path first -- /sys/block/dm-X/vdo/statistics */
940a02
+    dm_node = _dm_node_from_name (name, error);
940a02
+    if (dm_node == NULL) {
940a02
+        g_prefix_error (error, "Failed to get DM node for %s: ", name);
940a02
+        return NULL;
940a02
+    }
940a02
+
940a02
+    stats_dir = g_build_path (G_DIR_SEPARATOR_S, "/sys/block", dm_node, "vdo/statistics", NULL);
940a02
     dir = g_dir_open (stats_dir, 0, error);
940a02
     if (dir == NULL) {
940a02
-        g_prefix_error (error, "Error reading statistics from %s: ", stats_dir);
940a02
+        g_debug ("Failed to read VDO stats using the new API, falling back to %s: %s",
940a02
+                 VDO_SYS_PATH, (*error)->message);
940a02
         g_free (stats_dir);
940a02
-        return NULL;
940a02
+        g_clear_error (error);
940a02
+
940a02
+        /* lets try /sys/kvdo */
940a02
+        stats_dir = g_build_path (G_DIR_SEPARATOR_S, VDO_SYS_PATH, name, "statistics", NULL);
940a02
+        dir = g_dir_open (stats_dir, 0, error);
940a02
+        if (dir == NULL) {
940a02
+            g_prefix_error (error, "Error reading statistics from %s: ", stats_dir);
940a02
+            g_free (stats_dir);
940a02
+            return NULL;
940a02
+        }
940a02
     }
940a02
 
940a02
     stats = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
940a02
-- 
940a02
2.31.1
940a02