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