Fix journal space check (do not overwrite the beginning of the journal)

blocking-uring-test
Vitaliy Filippov 2019-11-27 11:35:11 +03:00
parent ffff742078
commit 78807eb244
2 changed files with 5 additions and 4 deletions

View File

@ -7,12 +7,12 @@ blockstore_journal_check_t::blockstore_journal_check_t(blockstore *bs)
next_pos = bs->journal.next_free;
next_sector = bs->journal.cur_sector;
next_in_pos = bs->journal.in_sector_pos;
right_dir = next_pos >= bs->journal.used_start;
}
// Check if we can write <required> entries of <size> bytes and <data_after> data bytes after them to the journal
int blockstore_journal_check_t::check_available(blockstore_operation *op, int required, int size, int data_after)
{
bool wrapped = false;
while (1)
{
int fits = (512 - next_in_pos) / size;
@ -30,7 +30,7 @@ int blockstore_journal_check_t::check_available(blockstore_operation *op, int re
if (next_pos >= bs->journal.len)
{
next_pos = 512;
wrapped = true;
right_dir = false;
}
next_in_pos = 0;
if (bs->journal.sector_info[next_sector].usage_count > 0)
@ -49,11 +49,11 @@ int blockstore_journal_check_t::check_available(blockstore_operation *op, int re
next_pos = next_pos + data_after;
if (next_pos > bs->journal.len)
{
wrapped = true;
next_pos = 512 + data_after;
right_dir = false;
}
}
if (wrapped && next_pos >= bs->journal.used_start)
if (!right_dir && next_pos >= bs->journal.used_start-512)
{
// No space in the journal. Wait for it.
op->wait_for = WAIT_JOURNAL;

View File

@ -137,6 +137,7 @@ struct blockstore_journal_check_t
blockstore *bs;
uint64_t next_pos, next_sector, next_in_pos;
int sectors_required;
bool right_dir; // writing to the end or the beginning of the ring buffer
blockstore_journal_check_t(blockstore *bs);
int check_available(blockstore_operation *op, int required, int size, int data_after);