Allow to forcibly set meta_format

hotfix-1.0.0
Vitaliy Filippov 2023-06-03 01:08:09 +03:00
parent 874a766b62
commit de48fa3fd2
2 changed files with 29 additions and 31 deletions

View File

@ -44,6 +44,7 @@ void blockstore_disk_t::parse_config(std::map<std::string, std::string> & config
journal_block_size = parse_size(config["journal_block_size"]); journal_block_size = parse_size(config["journal_block_size"]);
meta_block_size = parse_size(config["meta_block_size"]); meta_block_size = parse_size(config["meta_block_size"]);
bitmap_granularity = parse_size(config["bitmap_granularity"]); bitmap_granularity = parse_size(config["bitmap_granularity"]);
meta_format = stoull_full(config["meta_format"]);
if (config["data_csum_type"] == "crc32c") if (config["data_csum_type"] == "crc32c")
{ {
data_csum_type = BLOCKSTORE_CSUM_CRC32C; data_csum_type = BLOCKSTORE_CSUM_CRC32C;
@ -191,26 +192,28 @@ void blockstore_disk_t::calc_lengths(bool skip_meta_check)
// required metadata size // required metadata size
block_count = data_len / data_block_size; block_count = data_len / data_block_size;
meta_len = (1 + (block_count - 1 + meta_block_size / clean_entry_size) / (meta_block_size / clean_entry_size)) * meta_block_size; meta_len = (1 + (block_count - 1 + meta_block_size / clean_entry_size) / (meta_block_size / clean_entry_size)) * meta_block_size;
if (meta_format == BLOCKSTORE_META_FORMAT_V1 ||
!meta_format && !skip_meta_check && meta_area_size < meta_len && !data_csum_type)
{
uint64_t clean_entry_v0_size = sizeof(clean_disk_entry) + 2*clean_entry_bitmap_size;
uint64_t meta_v0_len = (1 + (block_count - 1 + meta_block_size / clean_entry_v0_size)
/ (meta_block_size / clean_entry_v0_size)) * meta_block_size;
if (meta_format == BLOCKSTORE_META_FORMAT_V1 || meta_area_size >= meta_v0_len)
{
// Old metadata fits.
printf("Warning: Using old metadata format without checksums because the new format doesn't fit into provided area\n");
clean_entry_size = clean_entry_v0_size;
meta_len = meta_v0_len;
meta_format = BLOCKSTORE_META_FORMAT_V1;
}
else
meta_format = BLOCKSTORE_META_FORMAT_V2;
}
else
meta_format = BLOCKSTORE_META_FORMAT_V2;
if (!skip_meta_check && meta_area_size < meta_len) if (!skip_meta_check && meta_area_size < meta_len)
{ {
if (!data_csum_type && !meta_format) throw std::runtime_error("Metadata area is too small, need at least "+std::to_string(meta_len)+" bytes");
{
uint64_t clean_entry_v0_size = sizeof(clean_disk_entry) + 2*clean_entry_bitmap_size;
uint64_t meta_v0_len = (1 + (block_count - 1 + meta_block_size / clean_entry_v0_size)
/ (meta_block_size / clean_entry_v0_size)) * meta_block_size;
if (meta_area_size >= meta_v0_len)
{
// Old metadata fits.
printf("Warning: Forcing metadata format without checksums because the new format doesn't fit into provided area\n");
clean_entry_size = clean_entry_v0_size;
meta_len = meta_v0_len;
meta_format = BLOCKSTORE_META_FORMAT_V1;
}
}
if (meta_area_size < meta_len)
{
throw std::runtime_error("Metadata area is too small, need at least "+std::to_string(meta_len)+" bytes");
}
} }
// requested journal size // requested journal size
if (!skip_meta_check && cfg_journal_size > journal_len) if (!skip_meta_check && cfg_journal_size > journal_len)

View File

@ -80,14 +80,17 @@ resume_1:
blockstore_meta_header_v2_t *hdr = (blockstore_meta_header_v2_t *)metadata_buffer; blockstore_meta_header_v2_t *hdr = (blockstore_meta_header_v2_t *)metadata_buffer;
hdr->zero = 0; hdr->zero = 0;
hdr->magic = BLOCKSTORE_META_MAGIC_V1; hdr->magic = BLOCKSTORE_META_MAGIC_V1;
hdr->version = BLOCKSTORE_META_FORMAT_V2; hdr->version = bs->dsk.meta_format;
hdr->meta_block_size = bs->dsk.meta_block_size; hdr->meta_block_size = bs->dsk.meta_block_size;
hdr->data_block_size = bs->dsk.data_block_size; hdr->data_block_size = bs->dsk.data_block_size;
hdr->bitmap_granularity = bs->dsk.bitmap_granularity; hdr->bitmap_granularity = bs->dsk.bitmap_granularity;
hdr->data_csum_type = bs->dsk.data_csum_type; if (bs->dsk.meta_format >= BLOCKSTORE_META_FORMAT_V2)
hdr->csum_block_size = bs->dsk.csum_block_size; {
hdr->header_csum = 0; hdr->data_csum_type = bs->dsk.data_csum_type;
hdr->header_csum = crc32c(0, hdr, sizeof(*hdr)); hdr->csum_block_size = bs->dsk.csum_block_size;
hdr->header_csum = 0;
hdr->header_csum = crc32c(0, hdr, sizeof(*hdr));
}
} }
if (bs->readonly) if (bs->readonly)
{ {
@ -123,14 +126,6 @@ resume_1:
); );
exit(1); exit(1);
} }
if (bs->dsk.meta_format && bs->dsk.meta_format != hdr->version)
{
printf(
"Metadata format version is %lu on disk, but %lu is currently selected in OSD configuration.\n"
" Please upgrade using vitastor-disk.\n", hdr->version, bs->dsk.meta_format
);
exit(1);
}
if (hdr->version == BLOCKSTORE_META_FORMAT_V2) if (hdr->version == BLOCKSTORE_META_FORMAT_V2)
{ {
uint32_t csum = hdr->header_csum; uint32_t csum = hdr->header_csum;