Blob Blame History Raw
From e7b6438f17f5f2870477c0ebd2ff3ac7b02f6ca7 Mon Sep 17 00:00:00 2001
From: Zdenek Kabelac <zkabelac@redhat.com>
Date: Thu, 9 Sep 2021 14:59:38 +0200
Subject: [PATCH 2/3] vdo: read new sysfs path

New versions of kvdo module exposes statistics at new location:
/sys/block/dm-XXX/vdo/statistics/...

Enhance lvm2 to access this location first.
Also if the statistic info is missing - make it 'debug' level info,
so it is not failing 'lvs' command.

(cherry picked from commit e6f735d411e5911de186a610932c9bb9638275eb)

Conflicts:
	WHATS_NEW
---
 WHATS_NEW                        |  4 ++++
 lib/activate/dev_manager.c       |  7 +++---
 lib/metadata/metadata-exported.h |  3 ++-
 lib/metadata/vdo_manip.c         | 46 ++++++++++++++++++++++------------------
 4 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/WHATS_NEW b/WHATS_NEW
index d5c9669..958e745 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,3 +1,7 @@
+Version 2.03.14 - 
+==================================
+  Support newer location for VDO statistics.
+
 Version 2.03.13 - 11th August 2021
 ==================================
   Changes in udev support:
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index c4a6739..0d954d1 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -157,6 +157,7 @@ out:
 
 static int _get_segment_status_from_target_params(const char *target_name,
 						  const char *params,
+						  const struct dm_info *dminfo,
 						  struct lv_seg_status *seg_status)
 {
 	const struct lv_segment *seg = seg_status->seg;
@@ -216,7 +217,7 @@ static int _get_segment_status_from_target_params(const char *target_name,
 			return_0;
 		seg_status->type = SEG_STATUS_SNAPSHOT;
 	} else if (segtype_is_vdo_pool(segtype)) {
-		if (!parse_vdo_pool_status(seg_status->mem, seg->lv, params, &seg_status->vdo_pool))
+		if (!parse_vdo_pool_status(seg_status->mem, seg->lv, params, dminfo, &seg_status->vdo_pool))
 			return_0;
 		seg_status->type = SEG_STATUS_VDO_POOL;
 	} else if (segtype_is_writecache(segtype)) {
@@ -320,7 +321,7 @@ static int _info_run(const char *dlid, struct dm_info *dminfo,
 		} while (target);
 
 		if (!target_name ||
-		    !_get_segment_status_from_target_params(target_name, target_params, seg_status))
+		    !_get_segment_status_from_target_params(target_name, target_params, dminfo, seg_status))
 			stack;
 	}
 
@@ -1886,7 +1887,7 @@ int dev_manager_vdo_pool_status(struct dev_manager *dm,
 		goto out;
 	}
 
-	if (!parse_vdo_pool_status(dm->mem, lv, params, *status))
+	if (!parse_vdo_pool_status(dm->mem, lv, params, &info, *status))
 		goto_out;
 
 	(*status)->mem = dm->mem;
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 96a9533..7bac5b9 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -1365,7 +1365,8 @@ const char *get_vdo_write_policy_name(enum dm_vdo_write_policy policy);
 uint64_t get_vdo_pool_virtual_size(const struct lv_segment *vdo_pool_seg);
 int update_vdo_pool_virtual_size(struct lv_segment *vdo_pool_seg);
 int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_pool_lv,
-			  const char *params, struct lv_status_vdo *status);
+			  const char *params, const struct dm_info *dminfo,
+			  struct lv_status_vdo *status);
 struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
 					   const struct dm_vdo_target_params *vtp,
 					   uint32_t *virtual_extents,
diff --git a/lib/metadata/vdo_manip.c b/lib/metadata/vdo_manip.c
index 3f2de1a..2917f29 100644
--- a/lib/metadata/vdo_manip.c
+++ b/lib/metadata/vdo_manip.c
@@ -123,48 +123,56 @@ int update_vdo_pool_virtual_size(struct lv_segment *vdo_pool_seg)
 	return 1;
 }
 
-static int _sysfs_get_kvdo_value(const char *dm_name, const char *vdo_param, uint64_t *value)
+static int _sysfs_get_kvdo_value(const char *dm_name, const struct dm_info *dminfo,
+				 const char *vdo_param, uint64_t *value)
 {
 	char path[PATH_MAX];
 	char temp[64];
 	int fd, size, r = 0;
 
-	if (dm_snprintf(path, sizeof(path), "%skvdo/%s/%s",
-			dm_sysfs_dir(), dm_name, vdo_param) < 0) {
-		log_error("Failed to build kmod path.");
+	if (dm_snprintf(path, sizeof(path), "%s/block/dm-%d/vdo/%s",
+			dm_sysfs_dir(), dminfo->minor, vdo_param) < 0) {
+		log_debug("Failed to build kvdo path.");
 		return 0;
 	}
 
 	if ((fd = open(path, O_RDONLY)) < 0) {
-		if (errno != ENOENT)
-			log_sys_error("open", path);
-		else
+		/* try with older location */
+		if (dm_snprintf(path, sizeof(path), "%skvdo/%s/%s",
+				dm_sysfs_dir(), dm_name, vdo_param) < 0) {
+			log_debug("Failed to build kvdo path.");
+			return 0;
+		}
+
+		if ((fd = open(path, O_RDONLY)) < 0) {
 			log_sys_debug("open", path);
-		goto bad;
+			goto bad;
+		}
 	}
 
 	if ((size = read(fd, temp, sizeof(temp) - 1)) < 0) {
-		log_sys_error("read", path);
+		log_sys_debug("read", path);
 		goto bad;
 	}
 	temp[size] = 0;
 	errno = 0;
 	*value = strtoll(temp, NULL, 0);
 	if (errno) {
-		log_sys_error("strtool", path);
+		log_sys_debug("strtool", path);
 		goto bad;
 	}
 
 	r = 1;
 bad:
 	if (fd >= 0 && close(fd))
-		log_sys_error("close", path);
+		log_sys_debug("close", path);
 
 	return r;
 }
 
 int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_pool_lv,
-			  const char *params, struct lv_status_vdo *status)
+			  const char *params, const struct dm_info *dminfo,
+			  struct lv_status_vdo *status)
 {
 	struct dm_vdo_status_parse_result result;
 	char *dm_name;
@@ -188,15 +196,11 @@ int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_
 
 	status->vdo = result.status;
 
-	if (result.status->operating_mode == DM_VDO_MODE_NORMAL) {
-		if (!_sysfs_get_kvdo_value(dm_name, "statistics/data_blocks_used",
-					   &status->data_blocks_used))
-			return_0;
-
-		if (!_sysfs_get_kvdo_value(dm_name, "statistics/logical_blocks_used",
-					   &status->logical_blocks_used))
-			return_0;
-
+	if ((result.status->operating_mode == DM_VDO_MODE_NORMAL) &&
+	    _sysfs_get_kvdo_value(dm_name, dminfo, "statistics/data_blocks_used",
+				  &status->data_blocks_used) &&
+	    _sysfs_get_kvdo_value(dm_name, dminfo, "statistics/logical_blocks_used",
+				  &status->logical_blocks_used)) {
 		status->usage = dm_make_percent(result.status->used_blocks,
 						result.status->total_blocks);
 		status->saving = dm_make_percent(status->logical_blocks_used - status->data_blocks_used,
-- 
1.8.3.1