Browse Source

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

blocking-uring-test
Vitaliy Filippov 3 years ago
parent
commit
78807eb244
  1. 8
      blockstore_journal.cpp
  2. 1
      blockstore_journal.h

8
blockstore_journal.cpp

@ -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;

1
blockstore_journal.h

@ -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);

Loading…
Cancel
Save