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