diff --git a/src/blockstore_read.cpp b/src/blockstore_read.cpp index 73c11465..74351370 100644 --- a/src/blockstore_read.cpp +++ b/src/blockstore_read.cpp @@ -505,7 +505,7 @@ int blockstore_impl_t::dequeue_read(blockstore_op_t *read_op) for (auto & rv: PRIV(read_op)->read_vec) { if (rv.journal_sector) - journal.used_sectors[rv.journal_sector-1]++; + journal.used_sectors.at(rv.journal_sector-1)++; } } read_op->retval = 0; @@ -966,7 +966,7 @@ void blockstore_impl_t::handle_read_event(ring_data_t *data, blockstore_op_t *op { if (rv.journal_sector) { - auto used = --journal.used_sectors[rv.journal_sector-1]; + auto used = --journal.used_sectors.at(rv.journal_sector-1); if (used == 0) { journal.used_sectors.erase(rv.journal_sector-1); diff --git a/src/blockstore_rollback.cpp b/src/blockstore_rollback.cpp index 50b6eb88..9726d843 100644 --- a/src/blockstore_rollback.cpp +++ b/src/blockstore_rollback.cpp @@ -215,7 +215,7 @@ void blockstore_impl_t::erase_dirty(blockstore_dirty_db_t::iterator dirty_start, #endif data_alloc->set(dirty_it->second.location >> dsk.block_order, false); } - auto used = --journal.used_sectors[dirty_it->second.journal_sector]; + auto used = --journal.used_sectors.at(dirty_it->second.journal_sector); #ifdef BLOCKSTORE_DEBUG printf( "remove usage of journal offset %08lx by %lx:%lx v%lu (%lu refs)\n", dirty_it->second.journal_sector, diff --git a/src/blockstore_sync.cpp b/src/blockstore_sync.cpp index d29035b5..578e2dcc 100644 --- a/src/blockstore_sync.cpp +++ b/src/blockstore_sync.cpp @@ -116,7 +116,10 @@ int blockstore_impl_t::continue_sync(blockstore_op_t *op) journal, (dirty_entry.state & BS_ST_INSTANT) ? JE_BIG_WRITE_INSTANT : JE_BIG_WRITE, sizeof(journal_entry_big_write) + dyn_size ); - dirty_entry.journal_sector = journal.sector_info[journal.cur_sector].offset; + auto jsec = dirty_entry.journal_sector = journal.sector_info[journal.cur_sector].offset; + assert(journal.next_free >= journal.used_start + ? (jsec >= journal.used_start && jsec < journal.next_free) + : (jsec >= journal.used_start || jsec < journal.next_free)); journal.used_sectors[journal.sector_info[journal.cur_sector].offset]++; #ifdef BLOCKSTORE_DEBUG printf( diff --git a/src/blockstore_write.cpp b/src/blockstore_write.cpp index fe768f88..99e749aa 100644 --- a/src/blockstore_write.cpp +++ b/src/blockstore_write.cpp @@ -436,7 +436,19 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op) journal, op->opcode == BS_OP_WRITE_STABLE ? JE_SMALL_WRITE_INSTANT : JE_SMALL_WRITE, sizeof(journal_entry_small_write) + dyn_size ); - dirty_it->second.journal_sector = journal.sector_info[journal.cur_sector].offset; + auto jsec = dirty_it->second.journal_sector = journal.sector_info[journal.cur_sector].offset; + if (!(journal.next_free >= journal.used_start + ? (jsec >= journal.used_start && jsec < journal.next_free) + : (jsec >= journal.used_start || jsec < journal.next_free))) + { + printf( + "BUG: journal offset %08lx is used by %lx:%lx v%lu (%lu refs) BUT used_start=%lx next_free=%lx\n", + dirty_it->second.journal_sector, dirty_it->first.oid.inode, dirty_it->first.oid.stripe, dirty_it->first.version, + journal.used_sectors[journal.sector_info[journal.cur_sector].offset], + journal.used_start, journal.next_free + ); + abort(); + } journal.used_sectors[journal.sector_info[journal.cur_sector].offset]++; #ifdef BLOCKSTORE_DEBUG printf( @@ -558,7 +570,19 @@ resume_2: journal, op->opcode == BS_OP_WRITE_STABLE ? JE_BIG_WRITE_INSTANT : JE_BIG_WRITE, sizeof(journal_entry_big_write) + dyn_size ); - dirty_it->second.journal_sector = journal.sector_info[journal.cur_sector].offset; + auto jsec = dirty_it->second.journal_sector = journal.sector_info[journal.cur_sector].offset; + if (!(journal.next_free >= journal.used_start + ? (jsec >= journal.used_start && jsec < journal.next_free) + : (jsec >= journal.used_start || jsec < journal.next_free))) + { + printf( + "BUG: journal offset %08lx is used by %lx:%lx v%lu (%lu refs) BUT used_start=%lx next_free=%lx\n", + dirty_it->second.journal_sector, dirty_it->first.oid.inode, dirty_it->first.oid.stripe, dirty_it->first.version, + journal.used_sectors[journal.sector_info[journal.cur_sector].offset], + journal.used_start, journal.next_free + ); + abort(); + } journal.used_sectors[journal.sector_info[journal.cur_sector].offset]++; #ifdef BLOCKSTORE_DEBUG printf(