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