2020-09-17 23:02:40 +03:00
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
2021-02-06 01:26:07 +03:00
|
|
|
// License: VNPL-1.1 (see README.md for details)
|
2020-09-17 23:02:40 +03:00
|
|
|
|
2019-11-03 22:04:25 +03:00
|
|
|
#pragma once
|
|
|
|
|
2022-08-21 01:21:13 +03:00
|
|
|
struct blockstore_init_meta_buf
|
|
|
|
{
|
|
|
|
uint8_t *buf = NULL;
|
|
|
|
uint64_t size = 0;
|
|
|
|
uint64_t offset = 0;
|
|
|
|
int state = 0;
|
|
|
|
};
|
|
|
|
|
2019-11-03 22:04:25 +03:00
|
|
|
class blockstore_init_meta
|
|
|
|
{
|
2019-12-15 14:49:10 +03:00
|
|
|
blockstore_impl_t *bs;
|
2022-01-15 23:55:10 +03:00
|
|
|
int wait_state = 0;
|
2021-04-10 17:18:10 +03:00
|
|
|
bool zero_on_init = false;
|
2019-12-02 02:44:56 +03:00
|
|
|
void *metadata_buffer = NULL;
|
2022-08-21 01:21:13 +03:00
|
|
|
blockstore_init_meta_buf bufs[2] = {};
|
|
|
|
int submitted = 0;
|
2019-11-21 21:51:52 +03:00
|
|
|
struct io_uring_sqe *sqe;
|
|
|
|
struct ring_data_t *data;
|
2022-08-21 01:21:13 +03:00
|
|
|
uint64_t md_offset = 0;
|
|
|
|
uint64_t next_offset = 0;
|
2024-03-03 18:20:43 +03:00
|
|
|
uint64_t last_read_offset = 0;
|
2022-08-21 01:21:13 +03:00
|
|
|
uint64_t entries_loaded = 0;
|
2022-12-17 03:02:32 +03:00
|
|
|
unsigned entries_per_block = 0;
|
|
|
|
int i = 0, j = 0;
|
|
|
|
std::vector<uint64_t> entries_to_zero;
|
|
|
|
bool handle_meta_block(uint8_t *buf, uint64_t count, uint64_t done_cnt);
|
2022-08-21 01:21:13 +03:00
|
|
|
void handle_event(ring_data_t *data, int buf_num);
|
2019-11-03 22:04:25 +03:00
|
|
|
public:
|
2019-12-15 14:49:10 +03:00
|
|
|
blockstore_init_meta(blockstore_impl_t *bs);
|
2019-11-05 02:43:21 +03:00
|
|
|
int loop();
|
2019-11-03 22:04:25 +03:00
|
|
|
};
|
|
|
|
|
2019-11-30 23:32:10 +03:00
|
|
|
struct bs_init_journal_done
|
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
uint64_t pos, len;
|
|
|
|
};
|
|
|
|
|
2019-11-03 22:04:25 +03:00
|
|
|
class blockstore_init_journal
|
|
|
|
{
|
2019-12-15 14:49:10 +03:00
|
|
|
blockstore_impl_t *bs;
|
2019-11-30 23:32:10 +03:00
|
|
|
int wait_state = 0, wait_count = 0, handle_res = 0;
|
2019-11-28 20:23:26 +03:00
|
|
|
uint64_t entries_loaded = 0;
|
2019-11-04 01:42:40 +03:00
|
|
|
uint32_t crc32_last = 0;
|
2019-11-15 14:09:41 +03:00
|
|
|
bool started = false;
|
2020-01-16 00:35:35 +03:00
|
|
|
uint64_t next_free;
|
2019-11-30 23:32:10 +03:00
|
|
|
std::vector<bs_init_journal_done> done;
|
2021-03-28 00:16:12 +03:00
|
|
|
std::vector<obj_ver_id> double_allocs;
|
2022-09-19 01:12:33 +03:00
|
|
|
std::vector<iovec> small_write_data;
|
2019-11-30 23:32:10 +03:00
|
|
|
uint64_t journal_pos = 0;
|
|
|
|
uint64_t continue_pos = 0;
|
|
|
|
void *init_write_buf = NULL;
|
|
|
|
uint64_t init_write_sector = 0;
|
2019-11-04 15:46:33 +03:00
|
|
|
bool wrapped = false;
|
2019-11-30 23:32:10 +03:00
|
|
|
void *submitted_buf;
|
2019-11-19 19:49:52 +03:00
|
|
|
struct io_uring_sqe *sqe;
|
|
|
|
struct ring_data_t *data;
|
|
|
|
journal_entry_start *je_start;
|
2019-11-19 20:03:19 +03:00
|
|
|
std::function<void(ring_data_t*)> simple_callback;
|
2019-11-30 23:32:10 +03:00
|
|
|
int handle_journal_part(void *buf, uint64_t done_pos, uint64_t len);
|
2019-11-13 21:17:04 +03:00
|
|
|
void handle_event(ring_data_t *data);
|
2021-03-27 23:21:18 +03:00
|
|
|
void erase_dirty_object(blockstore_dirty_db_t::iterator dirty_it);
|
2019-11-03 22:04:25 +03:00
|
|
|
public:
|
2019-12-15 14:49:10 +03:00
|
|
|
blockstore_init_journal(blockstore_impl_t* bs);
|
2019-11-05 02:43:21 +03:00
|
|
|
int loop();
|
2019-11-03 22:04:25 +03:00
|
|
|
};
|