import device-mapper-persistent-data-0.9.0-5.el8

This commit is contained in:
CentOS Sources 2021-11-11 04:18:06 +00:00 committed by Stepan Oksanichenko
parent 2ffa4705d5
commit 6029f71f86
4 changed files with 336 additions and 1 deletions

View File

@ -0,0 +1,72 @@
From 9388ab17da885dbd99d8b68217b282646ce9d73d Mon Sep 17 00:00:00 2001
From: Ming-Hung Tsai <mtsai@redhat.com>
Date: Mon, 16 Aug 2021 18:16:29 +0800
Subject: [PATCH 1/3] [thin_repair/thin_dump] Fix sorting of data mapping
candidates
- Fix the references for sorting. The timestamp statistics is stored
in node_info corresponding to the second element.
- Fix the timestamp comparison routine. The mapping root with more recent
blocks should have higher priority.
(cherry picked from commit 371df963113e7af7b97d2158757e35c44804ccb4)
---
thin-provisioning/metadata_dumper.cc | 37 +++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc
index 665c762..37c6969 100644
--- a/thin-provisioning/metadata_dumper.cc
+++ b/thin-provisioning/metadata_dumper.cc
@@ -252,26 +252,33 @@ namespace {
bool cmp_time_counts(pair<node_info, node_info> const &lhs_pair,
pair<node_info, node_info> const &rhs_pair) {
- auto const &lhs = lhs_pair.first.time_counts;
- auto const &rhs = rhs_pair.first.time_counts;
+ auto const &lhs = lhs_pair.second.time_counts;
+ auto const &rhs = rhs_pair.second.time_counts;
- for (auto lhs_it = lhs.crbegin(); lhs_it != lhs.crend(); lhs_it++) {
- for (auto rhs_it = rhs.crbegin(); rhs_it != rhs.crend(); rhs_it++) {
- if (lhs_it->first > rhs_it->first)
- return true;
- else if (rhs_it->first > lhs_it->first)
- return false;
+ auto lhs_it = lhs.crbegin();
+ auto rhs_it = rhs.crbegin();
+ while (lhs_it != lhs.crend() && rhs_it != rhs.crend()) {
- else if (lhs_it->second > rhs_it->second)
- return true;
+ auto lhs_time = lhs_it->first;
+ auto rhs_time = rhs_it->first;
+ auto lhs_count = lhs_it->second;
+ auto rhs_count = rhs_it->second;
- else if (rhs_it->second > lhs_it->second)
- return false;
- }
- }
+ if (lhs_time > rhs_time)
+ return true;
+ else if (rhs_time > lhs_time)
+ return false;
+ else if (lhs_count > rhs_count)
+ return true;
+ else if (rhs_count > lhs_count)
+ return false;
+
+ lhs_it++;
+ rhs_it++;
+ }
- return true;
+ return (lhs_it != lhs.crend()) ? true : false;
}
class gatherer {
--
1.8.3.1

View File

@ -0,0 +1,122 @@
From 4a2b112e98fe4c66f805eb690bfe1ae7ba342e5b Mon Sep 17 00:00:00 2001
From: Ming-Hung Tsai <mtsai@redhat.com>
Date: Thu, 19 Aug 2021 18:38:23 +0800
Subject: [PATCH 2/3] [thin_repair/thin_dump] Change the label type for empty
leaves
Empty leaves now are treated as bottom-level leaves, so that empty
devices could be recovered.
(cherry picked from commit d3f796f5e35162b0867ee2ba8de781f14ad35c61)
---
functional-tests/thin-functional-tests.scm | 53 +++++++++++++++++++++++++++++-
thin-provisioning/metadata_dumper.cc | 8 +++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/functional-tests/thin-functional-tests.scm b/functional-tests/thin-functional-tests.scm
index fcabddf..d06a5a3 100644
--- a/functional-tests/thin-functional-tests.scm
+++ b/functional-tests/thin-functional-tests.scm
@@ -14,7 +14,8 @@
(temp-file)
(thin metadata)
(thin xml)
- (srfi s8 receive))
+ (srfi s8 receive)
+ (xml))
(define-tool thin-check)
(define-tool thin-delta)
@@ -96,6 +97,32 @@
;; to run.
(define (register-thin-tests) #t)
+ ;; XML of metadata with empty thins
+ (define xml-with-empty-thins
+ (fmt #f
+ (tag 'superblock `((uuid . "")
+ (time . 0)
+ (transaction . 1)
+ (flags . 0)
+ (version . 2)
+ (data-block-size . 128)
+ (nr-data-blocks . 1024))
+ (tag 'device `((dev-id . 1)
+ (mapped-blocks . 16)
+ (transaction . 0)
+ (creation-time . 0)
+ (snap-time . 0))
+ (tag 'range-mapping `((origin-begin . 0)
+ (data-begin . 0)
+ (length . 16)
+ (time . 0))))
+ (tag 'device `((dev-id . 2)
+ (mapped-blocks . 0)
+ (transaction . 0)
+ (creation-time . 0)
+ (snap-time . 0))
+ " "))))
+
;;;-----------------------------------------------------------
;;; thin_check scenarios
;;;-----------------------------------------------------------
@@ -376,6 +403,17 @@
(run-fail-rcv (_ stderr) (thin-dump "--repair" "--transaction-id=5" "--data-block-size=128" md)
(assert-matches ".*nr data blocks.*" stderr))))
+ (define-scenario (thin-dump repair-superblock with-empty-devices)
+ "metadata with empty devices could be recovered"
+ (with-temp-file-sized ((md "thin.bin" (meg 4)))
+ (with-temp-file-containing ((xml "thin.xml" xml-with-empty-thins))
+ (run-ok (thin-restore "-i" xml "-o" md)))
+ (run-ok-rcv (expected-xml _) (thin-dump md)
+ (damage-superblock md)
+ (run-ok-rcv (repaired-xml stderr) (thin-dump "--repair" "--transaction-id=1" "--data-block-size=128" "--nr-data-blocks=1024" md)
+ (assert-eof stderr)
+ (assert-equal expected-xml repaired-xml)))))
+
;;;-----------------------------------------------------------
;;; thin_rmap scenarios
;;;-----------------------------------------------------------
@@ -572,6 +610,19 @@
(run-fail-rcv (_ stderr) (thin-repair "--transaction-id=5" "--data-block-size=128" "-i" md1 "-o" md2)
(assert-matches ".*nr data blocks.*" stderr)))))
+ (define-scenario (thin-repair superblock with-empty-devices)
+ "metadata with empty devices could be recovered"
+ (with-temp-file-sized ((md1 "thin.bin" (meg 4)))
+ (with-temp-file-containing ((xml "thin.xml" xml-with-empty-thins))
+ (run-ok (thin-restore "-i" xml "-o" md1)))
+ (run-ok-rcv (expected-xml _) (thin-dump md1)
+ (damage-superblock md1)
+ (with-empty-metadata (md2)
+ (run-ok-rcv (_ stderr) (thin-repair "--transaction-id=1" "--data-block-size=128" "--nr-data-blocks=1024" "-i" md1 "-o" md2)
+ (assert-eof stderr))
+ (run-ok-rcv (repaired-xml stderr) (thin-dump md2)
+ (assert-eof stderr)
+ (assert-equal expected-xml repaired-xml))))))
;;;-----------------------------------------------------------
;;; thin_metadata_pack scenarios
diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc
index 37c6969..d169c27 100644
--- a/thin-provisioning/metadata_dumper.cc
+++ b/thin-provisioning/metadata_dumper.cc
@@ -438,6 +438,14 @@ namespace {
// in the bottom 24 bits. This means every block/time apart from block 0
// will result in a value that's outside the range of the metadata device.
bool is_top_level(node_ref<uint64_traits> &n) {
+ // A leaf node of value-size 8 and without mappings should be
+ // treated as a bottom-level leaf, so that it could be referenced
+ // by top-level nodes, if any. On the other hand, an empty
+ // top-level leaf doesn't help repairing.
+ if (!n.get_nr_entries()) {
+ return false;
+ }
+
auto nr_metadata_blocks = bm_.get_nr_blocks();
for (unsigned i = 0; i < n.get_nr_entries(); i++)
--
1.8.3.1

View File

@ -0,0 +1,129 @@
From 992bb5feeb9e1994d4c31b4b13dbae594dd3c87a Mon Sep 17 00:00:00 2001
From: Ming-Hung Tsai <mtsai@redhat.com>
Date: Tue, 24 Aug 2021 16:20:50 +0800
Subject: [PATCH 3/3] [thin_repair/thin_dump] Check consistency of thin_ids
before running a regular dump
(cherry picked from commit 73dda15b5977dfa45cbfa36edddf4c19d279767b)
---
functional-tests/thin-functional-tests.scm | 56 ++++++++++++++++++++++++++++++
thin-provisioning/metadata_dumper.cc | 8 +++--
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/functional-tests/thin-functional-tests.scm b/functional-tests/thin-functional-tests.scm
index d06a5a3..37d3df9 100644
--- a/functional-tests/thin-functional-tests.scm
+++ b/functional-tests/thin-functional-tests.scm
@@ -81,6 +81,15 @@
(let ((csum (checksum-block b (ftype-sizeof unsigned-32) superblock-salt)))
(ftype-set! ThinSuperblock (csum) sb csum))))))
+ (define (tamper-mapping-root md mapping-root)
+ (with-bcache (cache md 1)
+ (with-block (b cache 0 (get-flags dirty))
+ (let ((sb (block->superblock b)))
+ (ftype-set! ThinSuperblock (data-mapping-root) sb mapping-root)
+ ;;;;;; Update the csum manually since the block validator for ft-lib is not ready
+ (let ((csum (checksum-block b (ftype-sizeof unsigned-32) superblock-salt)))
+ (ftype-set! ThinSuperblock (csum) sb csum))))))
+
(define (get-superblock-flags md)
(with-bcache (cache md 1)
(with-block (b cache 0 (get-flags))
@@ -97,6 +106,26 @@
;; to run.
(define (register-thin-tests) #t)
+ ;; An deterministic simple XML for testing
+ (define simple-thin-xml
+ (fmt #f
+ (tag 'superblock `((uuid . "")
+ (time . 0)
+ (transaction . 1)
+ (flags . 0)
+ (version . 2)
+ (data-block-size . 128)
+ (nr-data-blocks . 1024))
+ (tag 'device `((dev-id . 1)
+ (mapped-blocks . 16)
+ (transaction . 0)
+ (creation-time . 0)
+ (snap-time . 0))
+ (tag 'range-mapping `((origin-begin . 0)
+ (data-begin . 0)
+ (length . 16)
+ (time . 0)))))))
+
;; XML of metadata with empty thins
(define xml-with-empty-thins
(fmt #f
@@ -414,6 +443,18 @@
(assert-eof stderr)
(assert-equal expected-xml repaired-xml)))))
+ (define-scenario (thin-dump repair-superblock inconsistent-device-ids)
+ "metadata with inconsistent device ids should be repaired"
+ (with-temp-file-sized ((md "thin.bin" (meg 4)))
+ (with-temp-file-containing ((xml "thin.xml" simple-thin-xml))
+ (run-ok (thin-restore "-i" xml "-o" md)))
+ (run-ok-rcv (expected-xml _) (thin-dump md)
+ ;;;;;; simulate multiple activation by replacing the mapping root with a bottom-level leaf
+ (tamper-mapping-root md 10)
+ (run-ok-rcv (repaired-xml stderr) (thin-dump "--repair" md)
+ (assert-eof stderr)
+ (assert-equal expected-xml repaired-xml)))))
+
;;;-----------------------------------------------------------
;;; thin_rmap scenarios
;;;-----------------------------------------------------------
@@ -624,6 +665,21 @@
(assert-eof stderr)
(assert-equal expected-xml repaired-xml))))))
+ (define-scenario (thin-repair superblock inconsistent-device-ids)
+ "metadata with inconsistent device ids should be repaired"
+ (with-temp-file-sized ((md1 "thin.bin" (meg 4)))
+ (with-temp-file-containing ((xml "thin.xml" simple-thin-xml))
+ (run-ok (thin-restore "-i" xml "-o" md1)))
+ (run-ok-rcv (expected-xml _) (thin-dump md1)
+ ;;;;;; simulate multiple activation by replacing the mapping root with a bottom-level leaf
+ (tamper-mapping-root md1 10)
+ (with-empty-metadata (md2)
+ (run-ok-rcv (_ stderr) (thin-repair "-i" md1 "-o" md2)
+ (assert-eof stderr))
+ (run-ok-rcv (repaired-xml stderr) (thin-dump md2)
+ (assert-eof stderr)
+ (assert-equal expected-xml repaired-xml))))))
+
;;;-----------------------------------------------------------
;;; thin_metadata_pack scenarios
;;;-----------------------------------------------------------
diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc
index d169c27..0ca4afe 100644
--- a/thin-provisioning/metadata_dumper.cc
+++ b/thin-provisioning/metadata_dumper.cc
@@ -412,6 +412,9 @@ namespace {
if (rhs == ms.end())
continue;
+ if (lhs->second != rhs->second)
+ continue;
+
filtered.push_back(make_pair(p.first.b, p.second.b));
}
@@ -886,8 +889,9 @@ namespace {
auto tm = open_tm(bm, superblock_detail::SUPERBLOCK_LOCATION);
- if (!get_dev_ids(*tm, msb->device_details_root_) ||
- !get_map_ids(*tm, msb->data_mapping_root_))
+ auto maybe_dev_ids = get_dev_ids(*tm, msb->device_details_root_);
+ auto maybe_map_ids = get_map_ids(*tm, msb->data_mapping_root_);
+ if (!maybe_dev_ids || !maybe_map_ids || (*maybe_dev_ids) != (*maybe_map_ids))
find_better_roots_(bm, *msb);
emit_trees_(bm, *msb, e, opts);
--
1.8.3.1

View File

@ -10,7 +10,7 @@
Summary: Device-mapper Persistent Data Tools
Name: device-mapper-persistent-data
Version: 0.9.0
Release: 4%{?dist}%{?release_suffix}
Release: 5%{?dist}%{?release_suffix}
License: GPLv3+
URL: https://github.com/jthornber/thin-provisioning-tools
#Source0: https://github.com/jthornber/thin-provisioning-tools/archive/thin-provisioning-tools-%%{version}.tar.gz
@ -36,6 +36,12 @@ Patch14: 0013-build-Remove-lboost_iostreams-linker-flag.patch
Patch15: 0014-cargo-update.patch
# BZ 1993290:
Patch16: 0015-thin-Clear-superblock-flags-in-restored-metadata.patch
# BZ 2001000:
Patch17: 0016-thin_repair-thin_dump-Fix-sorting-of-data-mapping-ca.patch
# BZ 2000896:
Patch18: 0017-thin_repair-thin_dump-Change-the-label-type-for-empt.patch
# BZ 2000981:
Patch19: 0018-thin_repair-thin_dump-Check-consistency-of-thin_ids-.patch
BuildRequires: autoconf, expat-devel, libaio-devel, libstdc++-devel, boost-devel, gcc-c++
Requires: expat
@ -88,6 +94,9 @@ END
%patch14 -p1 -b .backup14
# NOTE: patch 15 is above at the rust setup
%patch16 -p1 -b .backup16
%patch17 -p1 -b .backup17
%patch18 -p1 -b .backup18
%patch19 -p1 -b .backup19
echo %{version}-%{release} > VERSION
%build
@ -158,6 +167,9 @@ make DESTDIR=%{buildroot} MANDIR=%{_mandir} install-rust-tools
#% {_sbindir}/thin_show_duplicates
%changelog
* Tue Sep 07 2021 Marian Csontos <mcsontos@redhat.com> - 0.9.0-5
- Fix several corner cases in thin_repair.
* Tue Aug 16 2021 Marian Csontos <mcsontos@redhat.com> - 0.9.0-4
- Fix thin_repair clearing needs_check flag in repaired metadata.