Fix journal space check (do not overwrite the beginning of the journal)
parent
ffff742078
commit
78807eb244
|
@ -7,12 +7,12 @@ blockstore_journal_check_t::blockstore_journal_check_t(blockstore *bs)
|
||||||
next_pos = bs->journal.next_free;
|
next_pos = bs->journal.next_free;
|
||||||
next_sector = bs->journal.cur_sector;
|
next_sector = bs->journal.cur_sector;
|
||||||
next_in_pos = bs->journal.in_sector_pos;
|
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
|
// 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)
|
int blockstore_journal_check_t::check_available(blockstore_operation *op, int required, int size, int data_after)
|
||||||
{
|
{
|
||||||
bool wrapped = false;
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int fits = (512 - next_in_pos) / size;
|
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)
|
if (next_pos >= bs->journal.len)
|
||||||
{
|
{
|
||||||
next_pos = 512;
|
next_pos = 512;
|
||||||
wrapped = true;
|
right_dir = false;
|
||||||
}
|
}
|
||||||
next_in_pos = 0;
|
next_in_pos = 0;
|
||||||
if (bs->journal.sector_info[next_sector].usage_count > 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;
|
next_pos = next_pos + data_after;
|
||||||
if (next_pos > bs->journal.len)
|
if (next_pos > bs->journal.len)
|
||||||
{
|
{
|
||||||
wrapped = true;
|
|
||||||
next_pos = 512 + data_after;
|
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.
|
// No space in the journal. Wait for it.
|
||||||
op->wait_for = WAIT_JOURNAL;
|
op->wait_for = WAIT_JOURNAL;
|
||||||
|
|
|
@ -137,6 +137,7 @@ struct blockstore_journal_check_t
|
||||||
blockstore *bs;
|
blockstore *bs;
|
||||||
uint64_t next_pos, next_sector, next_in_pos;
|
uint64_t next_pos, next_sector, next_in_pos;
|
||||||
int sectors_required;
|
int sectors_required;
|
||||||
|
bool right_dir; // writing to the end or the beginning of the ring buffer
|
||||||
|
|
||||||
blockstore_journal_check_t(blockstore *bs);
|
blockstore_journal_check_t(blockstore *bs);
|
||||||
int check_available(blockstore_operation *op, int required, int size, int data_after);
|
int check_available(blockstore_operation *op, int required, int size, int data_after);
|
||||||
|
|
Loading…
Reference in New Issue