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

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