Addiitonal patches for 9.0.0 dmpd

Resolves: #2020660 #2020661 #2020662
This commit is contained in:
Marian Csontos 2021-11-05 22:26:12 +01:00
parent 1717a3c38a
commit d01bfdc1e8
5 changed files with 533 additions and 1 deletions

View File

@ -0,0 +1,197 @@
From 637fc5ec0869145d1b5272ee0e1e51e21517be79 Mon Sep 17 00:00:00 2001
From: Ming-Hung Tsai <mtsai@redhat.com>
Date: Mon, 7 Jun 2021 14:54:04 +0800
Subject: [PATCH] [thin] Clear superblock flags in restored metadata
The needs_check flag is unnecessary for a restored metadata since
it is assumed clean and has no errors
(cherry picked from commit 62536defc86f12363e4178ee5a2cefc40fa416d9)
---
ft-lib/bcache.c | 20 ++++++++++---
functional-tests/thin-functional-tests.scm | 46 ++++++++++++++++++++++++++++++
functional-tests/thin/xml.scm | 4 +--
thin-provisioning/restore_emitter.cc | 2 +-
4 files changed, 65 insertions(+), 7 deletions(-)
diff --git a/ft-lib/bcache.c b/ft-lib/bcache.c
index ee5b6c5..1c63377 100644
--- a/ft-lib/bcache.c
+++ b/ft-lib/bcache.c
@@ -201,8 +201,10 @@ static int engine_issue(struct io_engine *e, int fd, enum dir d,
cb_array[0] = &cb->cb;
r = io_submit(e->aio_context, 1, cb_array);
- if (r < 0)
+ if (r < 0) {
+ warn("io_submit failed, ret=%d\n", r);
cb_free(e->cbs, cb);
+ }
return r;
}
@@ -219,7 +221,7 @@ static int engine_wait(struct io_engine *e, struct timespec *ts, complete_fn fn)
memset(&event, 0, sizeof(event));
r = io_getevents(e->aio_context, 1, MAX_IO, event, ts);
if (r < 0) {
- warn("io_getevents failed");
+ warn("io_getevents failed, ret=%d\n", r);
return r;
}
@@ -514,12 +516,22 @@ static void relink(struct block *b)
*/
static int issue_low_level(struct block *b, enum dir d)
{
+ int r;
struct bcache *cache = b->cache;
sector_t sb = b->index * cache->block_sectors;
sector_t se = sb + cache->block_sectors;
set_flags(b, BF_IO_PENDING);
+ cache->nr_io_pending++;
+ list_add_tail(&b->list, &cache->io_pending);
- return engine_issue(cache->engine, cache->fd, d, sb, se, b->data, b);
+ r = engine_issue(cache->engine, cache->fd, d, sb, se, b->data, b);
+ if (r < 0) {
+ list_del(&b->list);
+ cache->nr_io_pending--;
+ clear_flags(b, BF_IO_PENDING);
+ return r;
+ }
+ return 0;
}
static void issue_read(struct block *b)
@@ -709,7 +721,7 @@ struct bcache *bcache_simple(const char *path, unsigned nr_cache_blocks)
int r;
struct stat info;
struct bcache *cache;
- int fd = open(path, O_DIRECT | O_EXCL | O_RDONLY);
+ int fd = open(path, O_DIRECT | O_EXCL | O_RDWR);
uint64_t s;
if (fd < 0) {
diff --git a/functional-tests/thin-functional-tests.scm b/functional-tests/thin-functional-tests.scm
index 55b0e60..fcabddf 100644
--- a/functional-tests/thin-functional-tests.scm
+++ b/functional-tests/thin-functional-tests.scm
@@ -12,6 +12,7 @@
(process)
(scenario-string-constants)
(temp-file)
+ (thin metadata)
(thin xml)
(srfi s8 receive))
@@ -30,6 +31,12 @@
(with-temp-file-containing ((v "thin.xml" (fmt #f (generate-xml 10 1000))))
b1 b2 ...))))
+ (define-syntax with-needs-check-thin-xml
+ (syntax-rules ()
+ ((_ (v) b1 b2 ...)
+ (with-temp-file-containing ((v "thin.xml" (fmt #f (generate-xml 10 1000 1))))
+ b1 b2 ...))))
+
(define-syntax with-valid-metadata
(syntax-rules ()
((_ (md) b1 b2 ...)
@@ -63,6 +70,28 @@
(damage-superblock md)
b1 b2 ...))))
+ (define superblock-salt 160774)
+ (define (set-needs-check-flag md)
+ (with-bcache (cache md 1)
+ (with-block (b cache 0 (get-flags dirty))
+ (let ((sb (block->superblock b)))
+ (ftype-set! ThinSuperblock (flags) sb 1)
+ ;;;;;; 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))
+ (let ((sb (block->superblock b)))
+ (ftype-ref ThinSuperblock (flags) sb)))))
+
+ (define (assert-metadata-needs-check md)
+ (assert-equal (get-superblock-flags md) 1))
+
+ (define (assert-metadata-clean md)
+ (assert-equal (get-superblock-flags md) 0))
+
;; We have to export something that forces all the initialisation expressions
;; to run.
(define (register-thin-tests) #t)
@@ -173,6 +202,13 @@
;;;-----------------------------------------------------------
;;; thin_restore scenarios
;;;-----------------------------------------------------------
+ (define-scenario (thin-restore clear-needs-check-flag)
+ "thin_restore should clear the needs-check flag"
+ (with-empty-metadata (md)
+ (with-needs-check-thin-xml (xml)
+ (run-ok-rcv (stdout _) (thin-restore "-i" xml "-o" md "-q")
+ (assert-eof stdout)))
+ (assert-metadata-clean md)))
(define-scenario (thin-restore print-version-v)
"print help (-V)"
@@ -439,6 +475,16 @@
;;;-----------------------------------------------------------
;;; thin_repair scenarios
;;;-----------------------------------------------------------
+ (define-scenario (thin-repair clear-needs-check-flag)
+ "thin_repair should clear the needs-check flag"
+ (with-valid-metadata (md1)
+ (set-needs-check-flag md1)
+ (assert-metadata-needs-check md1)
+ (with-empty-metadata (md2)
+ (run-ok-rcv (stdout stderr) (thin-repair "-i" md1 "-o" md2)
+ (assert-eof stderr))
+ (assert-metadata-clean md2))))
+
(define-scenario (thin-repair dont-repair-xml)
"Fails gracefully if run on XML rather than metadata"
(with-thin-xml (xml)
diff --git a/functional-tests/thin/xml.scm b/functional-tests/thin/xml.scm
index 551a536..7d9314b 100644
--- a/functional-tests/thin/xml.scm
+++ b/functional-tests/thin/xml.scm
@@ -22,7 +22,7 @@
(length . ,nr-mappings)
(time . 1)))))
- (define (generate-xml max-thins max-mappings)
+ (define (generate-xml max-thins max-mappings . needs-check)
(let ((nr-thins ((make-uniform-generator 1 max-thins)))
(nr-mappings-g (make-uniform-generator (div-down max-mappings 2)
max-mappings)))
@@ -30,7 +30,7 @@
(tag 'superblock `((uuid . "")
(time . 1)
(transaction . 1)
- (flags . 0)
+ (flags . ,(if (null? needs-check) 0 (car needs-check)))
(version . 2)
(data-block-size . 128)
(nr-data-blocks . ,(apply + nr-mappings)))
diff --git a/thin-provisioning/restore_emitter.cc b/thin-provisioning/restore_emitter.cc
index 6e95a53..114ba4f 100644
--- a/thin-provisioning/restore_emitter.cc
+++ b/thin-provisioning/restore_emitter.cc
@@ -57,7 +57,7 @@ namespace {
memcpy(&sb.uuid_, uuid.c_str(), std::min(sizeof(sb.uuid_), uuid.length()));
sb.time_ = time;
sb.trans_id_ = trans_id;
- sb.flags_ = flags ? *flags : 0;
+ sb.flags_ = 0;
sb.version_ = version ? *version : 1;
sb.data_block_size_ = data_block_size;
sb.metadata_snap_ = metadata_snap ? *metadata_snap : 0;
--
1.8.3.1

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

@ -8,7 +8,7 @@
Summary: Device-mapper Persistent Data Tools
Name: device-mapper-persistent-data
Version: 0.9.0
Release: 10%{?dist}%{?release_suffix}
Release: 11%{?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
@ -31,6 +31,11 @@ Patch12: 0011-file_utils-Fix-resource-leak.patch
Patch13: 0012-thin_delta-Clean-up-duplicated-code.patch
Patch14: 0013-build-Remove-lboost_iostreams-linker-flag.patch
Patch15: 0014-cargo-update.patch
# BZ 202066{0,1,2}:
Patch16: 0015-thin-Clear-superblock-flags-in-restored-metadata.patch
Patch17: 0016-thin_repair-thin_dump-Fix-sorting-of-data-mapping-ca.patch
Patch18: 0017-thin_repair-thin_dump-Change-the-label-type-for-empt.patch
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
@ -86,6 +91,10 @@ END
%patch13 -p1 -b .backup13
%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
%if 0%{?rhel}
@ -162,6 +171,9 @@ make DESTDIR=%{buildroot} MANDIR=%{_mandir} install-rust-tools
#% {_sbindir}/thin_show_duplicates
%changelog
* Fri Nov 05 2021 Marian Csontos <mcsontos@redhat.com> - 0.9.0-11
- Fix several corner cases in thin_repair.
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 0.9.0-10
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688