aboutsummaryrefslogtreecommitdiffstats
path: root/community/libblockdev/dont-use-deprecated-g_memdup.patch
blob: 38201509dd46f95ed42d856d4e8caf298e35a370 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 5528baef6ccc835a06c45f9db34a2c9c3f2dd940 Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Tue, 16 Mar 2021 12:05:37 +0100
Subject: [PATCH] vdo: Do not use g_memdup in bd_vdo_stats_copy

g_memdup is deprecated and the replacement g_memdup2 is not yet
available so lets just do the copy manually.
---
 src/lib/plugin_apis/vdo.api | 17 ++++++++++++++++-
 src/plugins/vdo.c           | 17 ++++++++++++++++-
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/lib/plugin_apis/vdo.api b/src/lib/plugin_apis/vdo.api
index 936f8e0c..312de4e5 100644
--- a/src/lib/plugin_apis/vdo.api
+++ b/src/lib/plugin_apis/vdo.api
@@ -170,7 +170,22 @@ void bd_vdo_stats_free (BDVDOStats *stats) {
  * Deprecated: 2.24: Use LVM-VDO integration instead.
  */
 BDVDOStats* bd_vdo_stats_copy (BDVDOStats *stats) {
-    return g_memdup (stats, sizeof (BDVDOStats));
+    if (stats == NULL)
+        return NULL;
+
+    BDVDOStats *new_stats = g_new0 (BDVDOStats, 1);
+
+    new_stats->block_size = stats->block_size;
+    new_stats->logical_block_size = stats->logical_block_size;
+    new_stats->physical_blocks = stats->physical_blocks;
+    new_stats->data_blocks_used = stats->data_blocks_used;
+    new_stats->overhead_blocks_used = stats->overhead_blocks_used;
+    new_stats->logical_blocks_used = stats->logical_blocks_used;
+    new_stats->used_percent = stats->used_percent;
+    new_stats->saving_percent = stats->saving_percent;
+    new_stats->write_amplification_ratio = stats->write_amplification_ratio;
+
+    return new_stats;
 }
 
 GType bd_vdo_stats_get_type () {
diff --git a/src/plugins/vdo.c b/src/plugins/vdo.c
index 2352394b..d4430997 100644
--- a/src/plugins/vdo.c
+++ b/src/plugins/vdo.c
@@ -81,7 +81,22 @@ void bd_vdo_stats_free (BDVDOStats *stats) {
 }
 
 BDVDOStats* bd_vdo_stats_copy (BDVDOStats *stats) {
-    return g_memdup (stats, sizeof (BDVDOStats));
+    if (stats == NULL)
+        return NULL;
+
+    BDVDOStats *new_stats = g_new0 (BDVDOStats, 1);
+
+    new_stats->block_size = stats->block_size;
+    new_stats->logical_block_size = stats->logical_block_size;
+    new_stats->physical_blocks = stats->physical_blocks;
+    new_stats->data_blocks_used = stats->data_blocks_used;
+    new_stats->overhead_blocks_used = stats->overhead_blocks_used;
+    new_stats->logical_blocks_used = stats->logical_blocks_used;
+    new_stats->used_percent = stats->used_percent;
+    new_stats->saving_percent = stats->saving_percent;
+    new_stats->write_amplification_ratio = stats->write_amplification_ratio;
+
+    return new_stats;
 }