From f684d9101adce1b5db92609052c8e83fcc6b374e Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 10 Apr 2021 02:14:17 +0300 Subject: [PATCH] Refuse to start with old journal version --- src/blockstore_flush.cpp | 1 + src/blockstore_init.cpp | 19 +++++++++++++++---- src/blockstore_journal.h | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/blockstore_flush.cpp b/src/blockstore_flush.cpp index c6d5c271..efd468f5 100644 --- a/src/blockstore_flush.cpp +++ b/src/blockstore_flush.cpp @@ -602,6 +602,7 @@ resume_1: .size = sizeof(journal_entry_start), .reserved = 0, .journal_start = new_trim_pos, + .version = JOURNAL_VERSION, }; ((journal_entry_start*)flusher->journal_superblock)->crc32 = je_crc32((journal_entry*)flusher->journal_superblock); data->iov = (struct iovec){ flusher->journal_superblock, bs->journal_block_size }; diff --git a/src/blockstore_init.cpp b/src/blockstore_init.cpp index 9697ab0e..5c066b37 100644 --- a/src/blockstore_init.cpp +++ b/src/blockstore_init.cpp @@ -231,7 +231,7 @@ resume_1: wait_state = 1; return 1; } - if (iszero((uint64_t*)submitted_buf, 3)) + if (iszero((uint64_t*)submitted_buf, bs->journal.block_size)) { // Journal is empty // FIXME handle this wrapping to journal_block_size better (maybe) @@ -246,6 +246,7 @@ resume_1: .size = sizeof(journal_entry_start), .reserved = 0, .journal_start = bs->journal.block_size, + .version = JOURNAL_VERSION, }; ((journal_entry_start*)submitted_buf)->crc32 = je_crc32((journal_entry*)submitted_buf); if (bs->readonly) @@ -296,11 +297,21 @@ resume_1: je_start = (journal_entry_start*)submitted_buf; if (je_start->magic != JOURNAL_MAGIC || je_start->type != JE_START || - je_start->size != sizeof(journal_entry_start) || - je_crc32((journal_entry*)je_start) != je_start->crc32) + je_crc32((journal_entry*)je_start) != je_start->crc32 || + je_start->size != sizeof(journal_entry_start) && je_start->size != JE_START_LEGACY_SIZE) { // Entry is corrupt - throw std::runtime_error("first entry of the journal is corrupt"); + fprintf(stderr, "First entry of the journal is corrupt\n"); + exit(1); + } + if (je_start->size == JE_START_LEGACY_SIZE || je_start->version != JOURNAL_VERSION) + { + fprintf( + stderr, "The code only supports journal version %d, but it is %lu on disk." + " Please use the previous version to flush the journal before upgrading OSD\n", + JOURNAL_VERSION, je_start->size == JE_START_LEGACY_SIZE ? 0 : je_start->version + ); + exit(1); } next_free = journal_pos = bs->journal.used_start = je_start->journal_start; if (!bs->journal.inmemory) diff --git a/src/blockstore_journal.h b/src/blockstore_journal.h index aadc01a6..ef1befa4 100644 --- a/src/blockstore_journal.h +++ b/src/blockstore_journal.h @@ -7,6 +7,7 @@ #define MIN_JOURNAL_SIZE 4*1024*1024 #define JOURNAL_MAGIC 0x4A33 +#define JOURNAL_VERSION 1 #define JOURNAL_BUFFER_SIZE 4*1024*1024 // We reserve some extra space for future stabilize requests during writes @@ -37,7 +38,9 @@ struct __attribute__((__packed__)) journal_entry_start uint32_t size; uint32_t reserved; uint64_t journal_start; + uint64_t version; }; +#define JE_START_LEGACY_SIZE 24 struct __attribute__((__packed__)) journal_entry_small_write {