Rename meta_version to meta_format

Vitaliy Filippov 2023-06-03 01:06:54 +03:00
parent 384bd8e28f
commit 874a766b62
7 changed files with 30 additions and 30 deletions

View File

@ -193,7 +193,7 @@ void blockstore_disk_t::calc_lengths(bool skip_meta_check)
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 (!skip_meta_check && meta_area_size < meta_len) if (!skip_meta_check && meta_area_size < meta_len)
{ {
if (!data_csum_type && !meta_version) if (!data_csum_type && !meta_format)
{ {
uint64_t clean_entry_v0_size = sizeof(clean_disk_entry) + 2*clean_entry_bitmap_size; 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) uint64_t meta_v0_len = (1 + (block_count - 1 + meta_block_size / clean_entry_v0_size)
@ -204,7 +204,7 @@ void blockstore_disk_t::calc_lengths(bool skip_meta_check)
printf("Warning: Forcing metadata format without checksums because the new format doesn't fit into provided area\n"); 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; clean_entry_size = clean_entry_v0_size;
meta_len = meta_v0_len; meta_len = meta_v0_len;
meta_version = BLOCKSTORE_META_VERSION_V1; meta_format = BLOCKSTORE_META_FORMAT_V1;
} }
} }
if (meta_area_size < meta_len) if (meta_area_size < meta_len)

View File

@ -33,7 +33,7 @@ struct blockstore_disk_t
bool disable_flock = false; bool disable_flock = false;
int meta_fd = -1, data_fd = -1, journal_fd = -1; int meta_fd = -1, data_fd = -1, journal_fd = -1;
uint64_t meta_offset, meta_device_sect, meta_device_size, meta_len, meta_version = 0; uint64_t meta_offset, meta_device_sect, meta_device_size, meta_len, meta_format = 0;
uint64_t data_offset, data_device_sect, data_device_size, data_len; uint64_t data_offset, data_device_sect, data_device_size, data_len;
uint64_t journal_offset, journal_device_sect, journal_device_size, journal_len; uint64_t journal_offset, journal_device_sect, journal_device_size, journal_len;

View File

@ -665,7 +665,7 @@ void journal_flusher_co::update_metadata_entry()
new_entry->version = cur.version; new_entry->version = cur.version;
if (!bs->inmemory_meta) if (!bs->inmemory_meta)
memcpy(&new_entry->bitmap, new_clean_bitmap, bs->dsk.clean_dyn_size); memcpy(&new_entry->bitmap, new_clean_bitmap, bs->dsk.clean_dyn_size);
if (bs->dsk.meta_version >= BLOCKSTORE_META_VERSION_V2) if (bs->dsk.meta_format >= BLOCKSTORE_META_FORMAT_V2)
{ {
// Calculate metadata entry checksum // Calculate metadata entry checksum
uint32_t *new_entry_csum = (uint32_t*)((uint8_t*)new_entry + bs->dsk.clean_entry_size - 4); uint32_t *new_entry_csum = (uint32_t*)((uint8_t*)new_entry + bs->dsk.clean_entry_size - 4);
@ -810,7 +810,7 @@ bool journal_flusher_co::clear_incomplete_csum_block_bits(int wait_base)
calc_block_checksums(new_data_csums, true); calc_block_checksums(new_data_csums, true);
if (!bs->inmemory_meta) if (!bs->inmemory_meta)
memcpy(&new_entry->bitmap, new_clean_bitmap, bs->dsk.clean_dyn_size); memcpy(&new_entry->bitmap, new_clean_bitmap, bs->dsk.clean_dyn_size);
if (bs->dsk.meta_version >= BLOCKSTORE_META_VERSION_V2) if (bs->dsk.meta_format >= BLOCKSTORE_META_FORMAT_V2)
{ {
// calculate metadata entry checksum // calculate metadata entry checksum
uint32_t *new_entry_csum = (uint32_t*)((uint8_t*)new_entry + bs->dsk.clean_entry_size - 4); uint32_t *new_entry_csum = (uint32_t*)((uint8_t*)new_entry + bs->dsk.clean_entry_size - 4);

View File

@ -93,8 +93,8 @@
// "VITAstor" // "VITAstor"
#define BLOCKSTORE_META_MAGIC_V1 0x726F747341544956l #define BLOCKSTORE_META_MAGIC_V1 0x726F747341544956l
#define BLOCKSTORE_META_VERSION_V1 1 #define BLOCKSTORE_META_FORMAT_V1 1
#define BLOCKSTORE_META_VERSION_V2 2 #define BLOCKSTORE_META_FORMAT_V2 2
// metadata header (superblock) // metadata header (superblock)
struct __attribute__((__packed__)) blockstore_meta_header_v1_t struct __attribute__((__packed__)) blockstore_meta_header_v1_t

View File

@ -80,7 +80,7 @@ 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_VERSION_V2; hdr->version = BLOCKSTORE_META_FORMAT_V2;
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;
@ -114,7 +114,7 @@ resume_1:
else else
{ {
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;
if (hdr->zero != 0 || hdr->magic != BLOCKSTORE_META_MAGIC_V1 || hdr->version < BLOCKSTORE_META_VERSION_V1) if (hdr->zero != 0 || hdr->magic != BLOCKSTORE_META_MAGIC_V1 || hdr->version < BLOCKSTORE_META_FORMAT_V1)
{ {
printf( printf(
"Metadata is corrupt or too old (pre-0.6.x).\n" "Metadata is corrupt or too old (pre-0.6.x).\n"
@ -123,15 +123,15 @@ resume_1:
); );
exit(1); exit(1);
} }
if (bs->dsk.meta_version && bs->dsk.meta_version != hdr->version) if (bs->dsk.meta_format && bs->dsk.meta_format != hdr->version)
{ {
printf( printf(
"Metadata format version is %lu on disk, but %lu is currently selected in OSD configuration.\n" "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_version " Please upgrade using vitastor-disk.\n", hdr->version, bs->dsk.meta_format
); );
exit(1); exit(1);
} }
if (hdr->version == BLOCKSTORE_META_VERSION_V2) if (hdr->version == BLOCKSTORE_META_FORMAT_V2)
{ {
uint32_t csum = hdr->header_csum; uint32_t csum = hdr->header_csum;
hdr->header_csum = 0; hdr->header_csum = 0;
@ -141,9 +141,9 @@ resume_1:
exit(1); exit(1);
} }
hdr->header_csum = csum; hdr->header_csum = csum;
bs->dsk.meta_version = BLOCKSTORE_META_VERSION_V2; bs->dsk.meta_format = BLOCKSTORE_META_FORMAT_V2;
} }
else if (hdr->version == BLOCKSTORE_META_VERSION_V1) else if (hdr->version == BLOCKSTORE_META_FORMAT_V1)
{ {
hdr->data_csum_type = 0; hdr->data_csum_type = 0;
hdr->csum_block_size = 0; hdr->csum_block_size = 0;
@ -152,14 +152,14 @@ resume_1:
bs->dsk.clean_entry_size = sizeof(clean_disk_entry) + bs->dsk.clean_entry_bitmap_size*2; bs->dsk.clean_entry_size = sizeof(clean_disk_entry) + bs->dsk.clean_entry_bitmap_size*2;
bs->dsk.meta_len = (1 + (bs->dsk.block_count - 1 + bs->dsk.meta_block_size / bs->dsk.clean_entry_size) bs->dsk.meta_len = (1 + (bs->dsk.block_count - 1 + bs->dsk.meta_block_size / bs->dsk.clean_entry_size)
/ (bs->dsk.meta_block_size / bs->dsk.clean_entry_size)) * bs->dsk.meta_block_size; / (bs->dsk.meta_block_size / bs->dsk.clean_entry_size)) * bs->dsk.meta_block_size;
bs->dsk.meta_version = BLOCKSTORE_META_VERSION_V1; bs->dsk.meta_format = BLOCKSTORE_META_FORMAT_V1;
printf("Warning: Starting with metadata in the old format without checksums, as stored on disk\n"); printf("Warning: Starting with metadata in the old format without checksums, as stored on disk\n");
} }
else if (hdr->version > BLOCKSTORE_META_VERSION_V2) else if (hdr->version > BLOCKSTORE_META_FORMAT_V2)
{ {
printf( printf(
"Metadata format is too new for me (stored version is %lu, max supported %u).\n", "Metadata format is too new for me (stored version is %lu, max supported %u).\n",
hdr->version, BLOCKSTORE_META_VERSION_V2 hdr->version, BLOCKSTORE_META_FORMAT_V2
); );
exit(1); exit(1);
} }
@ -327,7 +327,7 @@ bool blockstore_init_meta::handle_meta_block(uint8_t *buf, uint64_t entries_per_
clean_disk_entry *entry = (clean_disk_entry*)(buf + i*bs->dsk.clean_entry_size); clean_disk_entry *entry = (clean_disk_entry*)(buf + i*bs->dsk.clean_entry_size);
if (entry->oid.inode > 0) if (entry->oid.inode > 0)
{ {
if (bs->dsk.meta_version >= BLOCKSTORE_META_VERSION_V2) if (bs->dsk.meta_format >= BLOCKSTORE_META_FORMAT_V2)
{ {
// Check entry crc32 // Check entry crc32
uint32_t *entry_csum = (uint32_t*)((uint8_t*)entry + bs->dsk.clean_entry_size - 4); uint32_t *entry_csum = (uint32_t*)((uint8_t*)entry + bs->dsk.clean_entry_size - 4);

View File

@ -31,14 +31,14 @@ int disk_tool_t::process_meta(std::function<void(blockstore_meta_header_v2_t *)>
blockstore_meta_header_v2_t *hdr = (blockstore_meta_header_v2_t *)data; blockstore_meta_header_v2_t *hdr = (blockstore_meta_header_v2_t *)data;
if (hdr->zero == 0 && hdr->magic == BLOCKSTORE_META_MAGIC_V1) if (hdr->zero == 0 && hdr->magic == BLOCKSTORE_META_MAGIC_V1)
{ {
if (hdr->version == BLOCKSTORE_META_VERSION_V1) if (hdr->version == BLOCKSTORE_META_FORMAT_V1)
{ {
// Vitastor 0.6-0.8 - static array of clean_disk_entry with bitmaps // Vitastor 0.6-0.8 - static array of clean_disk_entry with bitmaps
hdr->data_csum_type = 0; hdr->data_csum_type = 0;
hdr->csum_block_size = 0; hdr->csum_block_size = 0;
hdr->header_csum = 0; hdr->header_csum = 0;
} }
else if (hdr->version == BLOCKSTORE_META_VERSION_V2) else if (hdr->version == BLOCKSTORE_META_FORMAT_V2)
{ {
// Vitastor 0.9 - static array of clean_disk_entry with bitmaps and checksums // Vitastor 0.9 - static array of clean_disk_entry with bitmaps and checksums
if (hdr->data_csum_type != 0 && if (hdr->data_csum_type != 0 &&
@ -54,7 +54,7 @@ int disk_tool_t::process_meta(std::function<void(blockstore_meta_header_v2_t *)>
else else
{ {
// Unsupported version // Unsupported version
fprintf(stderr, "Metadata format is too new for me (stored version is %lu, max supported %u).\n", hdr->version, BLOCKSTORE_META_VERSION_V2); fprintf(stderr, "Metadata format is too new for me (stored version is %lu, max supported %u).\n", hdr->version, BLOCKSTORE_META_FORMAT_V2);
free(data); free(data);
close(dsk.meta_fd); close(dsk.meta_fd);
dsk.meta_fd = -1; dsk.meta_fd = -1;
@ -74,7 +74,7 @@ int disk_tool_t::process_meta(std::function<void(blockstore_meta_header_v2_t *)>
hdr = (blockstore_meta_header_v2_t *)data; hdr = (blockstore_meta_header_v2_t *)data;
} }
} }
dsk.meta_version = hdr->version; dsk.meta_format = hdr->version;
dsk.data_block_size = hdr->data_block_size; dsk.data_block_size = hdr->data_block_size;
dsk.csum_block_size = hdr->csum_block_size; dsk.csum_block_size = hdr->csum_block_size;
dsk.data_csum_type = hdr->data_csum_type; dsk.data_csum_type = hdr->data_csum_type;
@ -85,7 +85,7 @@ int disk_tool_t::process_meta(std::function<void(blockstore_meta_header_v2_t *)>
? ((hdr->data_block_size+hdr->csum_block_size-1)/hdr->csum_block_size ? ((hdr->data_block_size+hdr->csum_block_size-1)/hdr->csum_block_size
*(hdr->data_csum_type & 0xff)) *(hdr->data_csum_type & 0xff))
: 0) : 0)
+ (dsk.meta_version == BLOCKSTORE_META_VERSION_V2 ? 4 /*entry_csum*/ : 0); + (dsk.meta_format == BLOCKSTORE_META_FORMAT_V2 ? 4 /*entry_csum*/ : 0);
uint64_t block_num = 0; uint64_t block_num = 0;
hdr_fn(hdr); hdr_fn(hdr);
hdr = NULL; hdr = NULL;
@ -164,7 +164,7 @@ void disk_tool_t::dump_meta_header(blockstore_meta_header_v2_t *hdr)
{ {
if (hdr) if (hdr)
{ {
if (hdr->version == BLOCKSTORE_META_VERSION_V1) if (hdr->version == BLOCKSTORE_META_FORMAT_V1)
{ {
printf( printf(
"{\"version\":\"0.6\",\"meta_block_size\":%u,\"data_block_size\":%u,\"bitmap_granularity\":%u," "{\"version\":\"0.6\",\"meta_block_size\":%u,\"data_block_size\":%u,\"bitmap_granularity\":%u,"
@ -172,7 +172,7 @@ void disk_tool_t::dump_meta_header(blockstore_meta_header_v2_t *hdr)
hdr->meta_block_size, hdr->data_block_size, hdr->bitmap_granularity hdr->meta_block_size, hdr->data_block_size, hdr->bitmap_granularity
); );
} }
else if (hdr->version == BLOCKSTORE_META_VERSION_V2) else if (hdr->version == BLOCKSTORE_META_FORMAT_V2)
{ {
printf( printf(
"{\"version\":\"0.9\",\"meta_block_size\":%u,\"data_block_size\":%u,\"bitmap_granularity\":%u," "{\"version\":\"0.9\",\"meta_block_size\":%u,\"data_block_size\":%u,\"bitmap_granularity\":%u,"
@ -235,8 +235,8 @@ int disk_tool_t::write_json_meta(json11::Json meta)
blockstore_meta_header_v2_t *new_hdr = (blockstore_meta_header_v2_t *)new_meta_buf; blockstore_meta_header_v2_t *new_hdr = (blockstore_meta_header_v2_t *)new_meta_buf;
new_hdr->zero = 0; new_hdr->zero = 0;
new_hdr->magic = BLOCKSTORE_META_MAGIC_V1; new_hdr->magic = BLOCKSTORE_META_MAGIC_V1;
new_hdr->version = meta["version"].uint64_value() == BLOCKSTORE_META_VERSION_V1 new_hdr->version = meta["version"].uint64_value() == BLOCKSTORE_META_FORMAT_V1
? BLOCKSTORE_META_VERSION_V1 : BLOCKSTORE_META_VERSION_V2; ? BLOCKSTORE_META_FORMAT_V1 : BLOCKSTORE_META_FORMAT_V2;
new_hdr->meta_block_size = meta["meta_block_size"].uint64_value() new_hdr->meta_block_size = meta["meta_block_size"].uint64_value()
? meta["meta_block_size"].uint64_value() : 4096; ? meta["meta_block_size"].uint64_value() : 4096;
new_hdr->data_block_size = meta["data_block_size"].uint64_value() new_hdr->data_block_size = meta["data_block_size"].uint64_value()
@ -249,7 +249,7 @@ int disk_tool_t::write_json_meta(json11::Json meta)
? BLOCKSTORE_CSUM_CRC32C ? BLOCKSTORE_CSUM_CRC32C
: BLOCKSTORE_CSUM_NONE); : BLOCKSTORE_CSUM_NONE);
new_hdr->csum_block_size = meta["csum_block_size"].uint64_value(); new_hdr->csum_block_size = meta["csum_block_size"].uint64_value();
uint32_t new_clean_entry_header_size = (new_hdr->version == BLOCKSTORE_META_VERSION_V1 uint32_t new_clean_entry_header_size = (new_hdr->version == BLOCKSTORE_META_FORMAT_V1
? sizeof(clean_disk_entry) : sizeof(clean_disk_entry) + 4 /*entry_csum*/); ? sizeof(clean_disk_entry) : sizeof(clean_disk_entry) + 4 /*entry_csum*/);
new_clean_entry_bitmap_size = (new_hdr->data_block_size / new_hdr->bitmap_granularity + 7) / 8; new_clean_entry_bitmap_size = (new_hdr->data_block_size / new_hdr->bitmap_granularity + 7) / 8;
new_data_csum_size = (new_hdr->data_csum_type new_data_csum_size = (new_hdr->data_csum_type
@ -278,7 +278,7 @@ int disk_tool_t::write_json_meta(json11::Json meta)
((uint8_t*)new_entry) + sizeof(clean_disk_entry)); ((uint8_t*)new_entry) + sizeof(clean_disk_entry));
fromhexstr(e["ext_bitmap"].string_value(), new_clean_entry_bitmap_size, fromhexstr(e["ext_bitmap"].string_value(), new_clean_entry_bitmap_size,
((uint8_t*)new_entry) + sizeof(clean_disk_entry) + new_clean_entry_bitmap_size); ((uint8_t*)new_entry) + sizeof(clean_disk_entry) + new_clean_entry_bitmap_size);
if (new_hdr->version == BLOCKSTORE_META_VERSION_V2) if (new_hdr->version == BLOCKSTORE_META_FORMAT_V2)
{ {
if (new_hdr->data_csum_type != 0) if (new_hdr->data_csum_type != 0)
{ {

View File

@ -466,7 +466,7 @@ int disk_tool_t::resize_rewrite_meta()
blockstore_meta_header_v2_t *new_hdr = (blockstore_meta_header_v2_t *)new_meta_buf; blockstore_meta_header_v2_t *new_hdr = (blockstore_meta_header_v2_t *)new_meta_buf;
new_hdr->zero = 0; new_hdr->zero = 0;
new_hdr->magic = BLOCKSTORE_META_MAGIC_V1; new_hdr->magic = BLOCKSTORE_META_MAGIC_V1;
new_hdr->version = BLOCKSTORE_META_VERSION_V1; new_hdr->version = BLOCKSTORE_META_FORMAT_V1;
new_hdr->meta_block_size = dsk.meta_block_size; new_hdr->meta_block_size = dsk.meta_block_size;
new_hdr->data_block_size = dsk.data_block_size; new_hdr->data_block_size = dsk.data_block_size;
new_hdr->bitmap_granularity = dsk.bitmap_granularity ? dsk.bitmap_granularity : 4096; new_hdr->bitmap_granularity = dsk.bitmap_granularity ? dsk.bitmap_granularity : 4096;