_close_writer(log.writer);
log.writer = NULL;
+ log.t.clear();
vselector.reset(nullptr);
_stop_alloc();
nodes.file_map.clear();
nodes.dir_map.clear();
super = bluefs_super_t();
- log.t.clear();
_shutdown_logger();
}
new_log_dev_cur = BDEV_NEWDB;
new_log_dev_next = BDEV_DB;
}
- _rewrite_log_and_layout_sync_LN_LD(false,
+ _rewrite_log_and_layout_sync_LNF_LD(false,
BDEV_NEWDB,
new_log_dev_cur,
new_log_dev_next,
layout);
//}
} else if(id == BDEV_NEWWAL) {
- _rewrite_log_and_layout_sync_LN_LD(false,
+ _rewrite_log_and_layout_sync_LNF_LD(false,
BDEV_DB,
BDEV_NEWWAL,
BDEV_WAL,
new_log_dev_next;
}
- _rewrite_log_and_layout_sync_LN_LD(
+ _rewrite_log_and_layout_sync_LNF_LD(
false,
(flags & REMOVE_DB) ? BDEV_SLOW : BDEV_DB,
new_log_dev_cur,
BDEV_DB :
BDEV_SLOW;
- _rewrite_log_and_layout_sync_LN_LD(
+ _rewrite_log_and_layout_sync_LNF_LD(
false,
super_dev,
new_log_dev_cur,
}
}
+
+/**
+To modify fnode both FileWriter::lock and File::lock must be obtained.
+The special case is when we modify bluefs log (ino 1) or
+we are compacting log (ino 0).
+
+In any case it is enough to hold File::lock to be sure fnode will not be modified.
+*/
struct lock_fnode_print {
BlueFS::FileRef file;
lock_fnode_print(BlueFS::FileRef file) : file(file) {};
<< " on " << lock_fnode_print(file) << dendl;
ceph_assert(file->refs > 0);
ceph_assert(ceph_mutex_is_locked(log.lock));
+ ceph_assert(ceph_mutex_is_locked(nodes.lock));
--file->refs;
if (file->refs == 0) {
void BlueFS::invalidate_cache(FileRef f, uint64_t offset, uint64_t length)
{
std::lock_guard l(f->lock);
- dout(10) << __func__ << " file " << lock_fnode_print(f)
+ dout(10) << __func__ << " file " << f->fnode
<< " 0x" << std::hex << offset << "~" << length << std::dec
<< dendl;
if (offset & ~super.block_mask()) {
{
if (!cct->_conf->bluefs_replay_recovery_disable_compact) {
if (cct->_conf->bluefs_compact_log_sync) {
- _compact_log_sync_LN_LD();
+ _compact_log_sync_LNF_LD();
} else {
_compact_log_async_LD_NF_D();
}
return true;
}
-void BlueFS::_compact_log_dump_metadata_N(bluefs_transaction_t *t,
+void BlueFS::_compact_log_dump_metadata_NF(bluefs_transaction_t *t,
int flags)
{
std::lock_guard nl(nodes.lock);
}
}
-void BlueFS::_compact_log_sync_LN_LD()
+void BlueFS::_compact_log_sync_LNF_LD()
{
dout(10) << __func__ << dendl;
- auto prefer_bdev =
- vselector->select_prefer_bdev(log.writer->file->vselector_hint);
- _rewrite_log_and_layout_sync_LN_LD(true,
+ uint8_t prefer_bdev;
+ {
+ std::lock_guard ll(log.lock);
+ prefer_bdev =
+ vselector->select_prefer_bdev(log.writer->file->vselector_hint);
+ }
+ _rewrite_log_and_layout_sync_LNF_LD(true,
BDEV_DB,
prefer_bdev,
prefer_bdev,
logger->inc(l_bluefs_log_compactions);
}
-void BlueFS::_rewrite_log_and_layout_sync_LN_LD(bool allocate_with_fallback,
+void BlueFS::_rewrite_log_and_layout_sync_LNF_LD(bool allocate_with_fallback,
int super_dev,
int log_dev,
int log_dev_new,
<< " flags:" << flags
<< dendl;
bluefs_transaction_t t;
- _compact_log_dump_metadata_N(&t, flags);
+ _compact_log_dump_metadata_NF(&t, flags);
dout(20) << __func__ << " op_jump_seq " << log.seq_live << dendl;
t.op_jump_seq(log.seq_live);
&new_log->fnode);
ceph_assert(r == 0);
- // we might have some more ops in log_t due to _allocate call
- // t.claim_ops(log_t); no we no longer track allocations in log
-
bufferlist bl;
encode(t, bl);
_pad_bl(bl);
}
}
-/**
- * Adds file modifications from `dirty.files` to bluefs transactions
- * already stored in `log.t`. Writes them to disk and waits until are stable.
- * Guarantees that file modifications with `want_seq` are already stable on disk.
- * In addition may insert jump forward transaction to log write position `jump_to`.
- *
- * it should lock ability to:
- * 1) add to log.t
- * 2) modify dirty.files
- * 3) add to pending_release
- *
- * pending_release and log.t go with same lock
- */
// Returns log seq that was live before advance.
uint64_t BlueFS::_log_advance_seq()
return 0;
}
-void BlueFS::flush_range/*WF*/(FileWriter *h, uint64_t offset, uint64_t length) {
+void BlueFS::flush_range(FileWriter *h, uint64_t offset, uint64_t length) {
std::unique_lock hl(h->lock);
_flush_range_F(h, offset, length);
}
}
}
if (flushed_sum) {
- _maybe_compact_log_LN_NF_LD_D();
+ _maybe_compact_log_LNF_NF_LD_D();
}
}
ceph_assert(r == 0);
}
if (r == 0 && flushed) {
- _maybe_compact_log_LN_NF_LD_D();
+ _maybe_compact_log_LNF_NF_LD_D();
}
}
if (old_dirty_seq) {
_flush_and_sync_log_LD(old_dirty_seq);
}
- _maybe_compact_log_LN_NF_LD_D();
+ _maybe_compact_log_LNF_NF_LD_D();
return 0;
}
}
if (!avoid_compact) {
- _maybe_compact_log_LN_NF_LD_D();
+ _maybe_compact_log_LNF_NF_LD_D();
}
}
-void BlueFS::_maybe_compact_log_LN_NF_LD_D()
+void BlueFS::_maybe_compact_log_LNF_NF_LD_D()
{
if (!cct->_conf->bluefs_replay_recovery_disable_compact &&
_should_start_compact_log_L_N()) {
if (cct->_conf->bluefs_compact_log_sync) {
- _compact_log_sync_LN_LD();
+ _compact_log_sync_LNF_LD();
} else {
_compact_log_async_LD_NF_D();
}