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

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