mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 3 years ago
Clone

Blame SOURCES/lvm2-2_03_14-vdo-read-new-sysfs-path.patch

0c180e
From 1c6992d37eff5af7134a11b662eacc1bab538ac2 Mon Sep 17 00:00:00 2001
0c180e
From: Zdenek Kabelac <zkabelac@redhat.com>
0c180e
Date: Thu, 9 Sep 2021 14:59:38 +0200
0c180e
Subject: [PATCH 1/5] vdo: read new sysfs path
0c180e
0c180e
New versions of kvdo module exposes statistics at new location:
0c180e
/sys/block/dm-XXX/vdo/statistics/...
0c180e
0c180e
Enhance lvm2 to access this location first.
0c180e
Also if the statistic info is missing - make it 'debug' level info,
0c180e
so it is not failing 'lvs' command.
0c180e
0c180e
(cherry picked from commit e6f735d411e5911de186a610932c9bb9638275eb)
0c180e
0c180e
Conflicts:
0c180e
	WHATS_NEW
0c180e
---
0c180e
 WHATS_NEW                        |  1 +
0c180e
 lib/activate/dev_manager.c       |  7 +++---
0c180e
 lib/metadata/metadata-exported.h |  3 ++-
0c180e
 lib/metadata/vdo_manip.c         | 46 ++++++++++++++++++++++------------------
0c180e
 4 files changed, 32 insertions(+), 25 deletions(-)
0c180e
0c180e
diff --git a/WHATS_NEW b/WHATS_NEW
0c180e
index b751009..c5a5ca5 100644
0c180e
--- a/WHATS_NEW
0c180e
+++ b/WHATS_NEW
0c180e
@@ -1,5 +1,6 @@
0c180e
 Version 2.03.14 - 
0c180e
 ==================================
0c180e
+  Support newer location for VDO statistics.
0c180e
   Improve lvm_import_vdo script.
0c180e
   Support VDO LV with lvcreate -ky.
0c180e
   Fix lvconvert for VDO LV bigger then 2T.
0c180e
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
0c180e
index c4a6739..0d954d1 100644
0c180e
--- a/lib/activate/dev_manager.c
0c180e
+++ b/lib/activate/dev_manager.c
0c180e
@@ -157,6 +157,7 @@ out:
0c180e
 
0c180e
 static int _get_segment_status_from_target_params(const char *target_name,
0c180e
 						  const char *params,
0c180e
+						  const struct dm_info *dminfo,
0c180e
 						  struct lv_seg_status *seg_status)
0c180e
 {
0c180e
 	const struct lv_segment *seg = seg_status->seg;
0c180e
@@ -216,7 +217,7 @@ static int _get_segment_status_from_target_params(const char *target_name,
0c180e
 			return_0;
0c180e
 		seg_status->type = SEG_STATUS_SNAPSHOT;
0c180e
 	} else if (segtype_is_vdo_pool(segtype)) {
0c180e
-		if (!parse_vdo_pool_status(seg_status->mem, seg->lv, params, &seg_status->vdo_pool))
0c180e
+		if (!parse_vdo_pool_status(seg_status->mem, seg->lv, params, dminfo, &seg_status->vdo_pool))
0c180e
 			return_0;
0c180e
 		seg_status->type = SEG_STATUS_VDO_POOL;
0c180e
 	} else if (segtype_is_writecache(segtype)) {
0c180e
@@ -320,7 +321,7 @@ static int _info_run(const char *dlid, struct dm_info *dminfo,
0c180e
 		} while (target);
0c180e
 
0c180e
 		if (!target_name ||
0c180e
-		    !_get_segment_status_from_target_params(target_name, target_params, seg_status))
0c180e
+		    !_get_segment_status_from_target_params(target_name, target_params, dminfo, seg_status))
0c180e
 			stack;
0c180e
 	}
0c180e
 
0c180e
@@ -1886,7 +1887,7 @@ int dev_manager_vdo_pool_status(struct dev_manager *dm,
0c180e
 		goto out;
0c180e
 	}
0c180e
 
0c180e
-	if (!parse_vdo_pool_status(dm->mem, lv, params, *status))
0c180e
+	if (!parse_vdo_pool_status(dm->mem, lv, params, &info, *status))
0c180e
 		goto_out;
0c180e
 
0c180e
 	(*status)->mem = dm->mem;
0c180e
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
0c180e
index adbbe76..7c21b4d 100644
0c180e
--- a/lib/metadata/metadata-exported.h
0c180e
+++ b/lib/metadata/metadata-exported.h
0c180e
@@ -1364,7 +1364,8 @@ const char *get_vdo_write_policy_name(enum dm_vdo_write_policy policy);
0c180e
 uint64_t get_vdo_pool_virtual_size(const struct lv_segment *vdo_pool_seg);
0c180e
 int update_vdo_pool_virtual_size(struct lv_segment *vdo_pool_seg);
0c180e
 int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_pool_lv,
0c180e
-			  const char *params, struct lv_status_vdo *status);
0c180e
+			  const char *params, const struct dm_info *dminfo,
0c180e
+			  struct lv_status_vdo *status);
0c180e
 struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
0c180e
 					   const struct dm_vdo_target_params *vtp,
0c180e
 					   uint32_t *virtual_extents,
0c180e
diff --git a/lib/metadata/vdo_manip.c b/lib/metadata/vdo_manip.c
0c180e
index 3f2de1a..2917f29 100644
0c180e
--- a/lib/metadata/vdo_manip.c
0c180e
+++ b/lib/metadata/vdo_manip.c
0c180e
@@ -123,48 +123,56 @@ int update_vdo_pool_virtual_size(struct lv_segment *vdo_pool_seg)
0c180e
 	return 1;
0c180e
 }
0c180e
 
0c180e
-static int _sysfs_get_kvdo_value(const char *dm_name, const char *vdo_param, uint64_t *value)
0c180e
+static int _sysfs_get_kvdo_value(const char *dm_name, const struct dm_info *dminfo,
0c180e
+				 const char *vdo_param, uint64_t *value)
0c180e
 {
0c180e
 	char path[PATH_MAX];
0c180e
 	char temp[64];
0c180e
 	int fd, size, r = 0;
0c180e
 
0c180e
-	if (dm_snprintf(path, sizeof(path), "%skvdo/%s/%s",
0c180e
-			dm_sysfs_dir(), dm_name, vdo_param) < 0) {
0c180e
-		log_error("Failed to build kmod path.");
0c180e
+	if (dm_snprintf(path, sizeof(path), "%s/block/dm-%d/vdo/%s",
0c180e
+			dm_sysfs_dir(), dminfo->minor, vdo_param) < 0) {
0c180e
+		log_debug("Failed to build kvdo path.");
0c180e
 		return 0;
0c180e
 	}
0c180e
 
0c180e
 	if ((fd = open(path, O_RDONLY)) < 0) {
0c180e
-		if (errno != ENOENT)
0c180e
-			log_sys_error("open", path);
0c180e
-		else
0c180e
+		/* try with older location */
0c180e
+		if (dm_snprintf(path, sizeof(path), "%skvdo/%s/%s",
0c180e
+				dm_sysfs_dir(), dm_name, vdo_param) < 0) {
0c180e
+			log_debug("Failed to build kvdo path.");
0c180e
+			return 0;
0c180e
+		}
0c180e
+
0c180e
+		if ((fd = open(path, O_RDONLY)) < 0) {
0c180e
 			log_sys_debug("open", path);
0c180e
-		goto bad;
0c180e
+			goto bad;
0c180e
+		}
0c180e
 	}
0c180e
 
0c180e
 	if ((size = read(fd, temp, sizeof(temp) - 1)) < 0) {
0c180e
-		log_sys_error("read", path);
0c180e
+		log_sys_debug("read", path);
0c180e
 		goto bad;
0c180e
 	}
0c180e
 	temp[size] = 0;
0c180e
 	errno = 0;
0c180e
 	*value = strtoll(temp, NULL, 0);
0c180e
 	if (errno) {
0c180e
-		log_sys_error("strtool", path);
0c180e
+		log_sys_debug("strtool", path);
0c180e
 		goto bad;
0c180e
 	}
0c180e
 
0c180e
 	r = 1;
0c180e
 bad:
0c180e
 	if (fd >= 0 && close(fd))
0c180e
-		log_sys_error("close", path);
0c180e
+		log_sys_debug("close", path);
0c180e
 
0c180e
 	return r;
0c180e
 }
0c180e
 
0c180e
 int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_pool_lv,
0c180e
-			  const char *params, struct lv_status_vdo *status)
0c180e
+			  const char *params, const struct dm_info *dminfo,
0c180e
+			  struct lv_status_vdo *status)
0c180e
 {
0c180e
 	struct dm_vdo_status_parse_result result;
0c180e
 	char *dm_name;
0c180e
@@ -188,15 +196,11 @@ int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_
0c180e
 
0c180e
 	status->vdo = result.status;
0c180e
 
0c180e
-	if (result.status->operating_mode == DM_VDO_MODE_NORMAL) {
0c180e
-		if (!_sysfs_get_kvdo_value(dm_name, "statistics/data_blocks_used",
0c180e
-					   &status->data_blocks_used))
0c180e
-			return_0;
0c180e
-
0c180e
-		if (!_sysfs_get_kvdo_value(dm_name, "statistics/logical_blocks_used",
0c180e
-					   &status->logical_blocks_used))
0c180e
-			return_0;
0c180e
-
0c180e
+	if ((result.status->operating_mode == DM_VDO_MODE_NORMAL) &&
0c180e
+	    _sysfs_get_kvdo_value(dm_name, dminfo, "statistics/data_blocks_used",
0c180e
+				  &status->data_blocks_used) &&
0c180e
+	    _sysfs_get_kvdo_value(dm_name, dminfo, "statistics/logical_blocks_used",
0c180e
+				  &status->logical_blocks_used)) {
0c180e
 		status->usage = dm_make_percent(result.status->used_blocks,
0c180e
 						result.status->total_blocks);
0c180e
 		status->saving = dm_make_percent(status->logical_blocks_used - status->data_blocks_used,
0c180e
-- 
0c180e
1.8.3.1
0c180e