crimson/os/seastore/cbj: remove duplicate configs in cbj_header_t

Also, this commits remove cbj::mkfs_config_t and use device's
information.

Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
This commit is contained in:
myoungwon oh 2022-10-17 18:52:29 +09:00
parent fb3a1bd5d3
commit 25f6b0f23a
6 changed files with 48 additions and 81 deletions

View File

@ -16,12 +16,9 @@ namespace crimson::os::seastore::journal {
std::ostream &operator<<(std::ostream &out,
const CircularBoundedJournal::cbj_header_t &header)
{
return out << "cbj_header_t(magic=" << header.magic
<< ", uuid=" << header.uuid
<< ", block_size=" << header.block_size
<< ", size=" << header.size
return out << "cbj_header_t("
<< ", dirty_tail=" << header.dirty_tail
<< ", "<< device_id_printer_t{header.device_id}
<< ", alloc_tail=" << header.alloc_tail
<< ")";
}
@ -31,23 +28,19 @@ CircularBoundedJournal::CircularBoundedJournal(
const std::string &path)
: trimmer(trimmer), device(device), path(path) {}
CircularBoundedJournal::mkfs_ret
CircularBoundedJournal::mkfs(const mkfs_config_t& config)
CircularBoundedJournal::mkfs_ret CircularBoundedJournal::mkfs()
{
LOG_PREFIX(CircularBoundedJournal::mkfs);
assert(device);
assert(config.block_size == device->get_block_size());
ceph::bufferlist bl;
CircularBoundedJournal::cbj_header_t head;
head.block_size = config.block_size;
head.size = config.total_size - device->get_block_size();
assert(device->get_journal_size());
head.dirty_tail =
journal_seq_t{0,
convert_abs_addr_to_paddr(
device->get_block_size(),
config.device_id)};
device->get_device_id())};
head.alloc_tail = head.dirty_tail;
head.device_id = config.device_id;
encode(head, bl);
header = head;
set_written_to(head.dirty_tail);
@ -131,7 +124,7 @@ CircularBoundedJournal::submit_record_ret CircularBoundedJournal::submit_record(
DEBUG("roll");
paddr_t paddr = convert_abs_addr_to_paddr(
get_start_addr(),
header.device_id);
get_device_id());
set_written_to(
journal_seq_t{++written_to.segment_seq, paddr});
if (encoded_size > get_available_size()) {
@ -153,13 +146,13 @@ CircularBoundedJournal::submit_record_ret CircularBoundedJournal::submit_record(
DEBUG("roll");
paddr_t paddr = convert_abs_addr_to_paddr(
get_start_addr(),
header.device_id);
get_device_id());
set_written_to(
journal_seq_t{++written_to.segment_seq, paddr});
} else {
paddr_t paddr = convert_abs_addr_to_paddr(
new_written_to,
header.device_id);
get_device_id());
set_written_to(
journal_seq_t{written_to.segment_seq, paddr});
}
@ -185,7 +178,7 @@ CircularBoundedJournal::submit_record_ret CircularBoundedJournal::submit_record(
paddr_t paddr = convert_abs_addr_to_paddr(
target + r_size.get_mdlength(),
header.device_id);
get_device_id());
auto submit_result = record_locator_t{
paddr,
write_result
@ -286,7 +279,7 @@ Journal::replay_ret CircularBoundedJournal::replay(
-> replay_ertr::future<seastar::stop_iteration> {
paddr_t record_paddr = convert_abs_addr_to_paddr(
cursor_addr,
header.device_id);
get_device_id());
return read_record(record_paddr, expected_seq
).safe_then([this, &is_rolled, &cursor_addr, &d_handler, &expected_seq, FNAME](auto ret)
-> replay_ertr::future<seastar::stop_iteration> {
@ -307,7 +300,7 @@ Journal::replay_ret CircularBoundedJournal::replay(
bufferlist mdbuf;
mdbuf.substr_of(bl, 0, r_header.mdlength);
paddr_t record_block_base = paddr_t::make_blk_paddr(
header.device_id, cursor_addr + r_header.mdlength);
get_device_id(), cursor_addr + r_header.mdlength);
auto maybe_record_deltas_list = try_decode_deltas(
r_header, mdbuf, record_block_base);
if (!maybe_record_deltas_list) {
@ -335,7 +328,7 @@ Journal::replay_ret CircularBoundedJournal::replay(
}
paddr_t addr = convert_abs_addr_to_paddr(
cursor_addr,
header.device_id);
get_device_id());
set_written_to(
journal_seq_t{expected_seq, addr});
return seastar::do_with(

View File

@ -23,7 +23,6 @@
namespace crimson::os::seastore::journal {
constexpr rbm_abs_addr CBJOURNAL_START_ADDRESS = 0;
constexpr uint64_t CBJOURNAL_MAGIC = 0xCCCC;
using RBMDevice = random_block_device::RBMDevice;
/**
@ -53,29 +52,11 @@ using RBMDevice = random_block_device::RBMDevice;
*
*/
constexpr uint64_t DEFAULT_SIZE = 1 << 26;
constexpr uint64_t DEFAULT_TEST_CBJOURNAL_SIZE = 1 << 26;
constexpr uint64_t DEFAULT_BLOCK_SIZE = 4096;
class CircularBoundedJournal : public Journal {
public:
struct mkfs_config_t {
std::string path;
size_t block_size = 0;
size_t total_size = 0;
device_id_t device_id = 0;
seastore_meta_t meta;
static mkfs_config_t get_default() {
device_id_t d_id = 1 << (std::numeric_limits<device_id_t>::digits - 1);
return mkfs_config_t {
"",
DEFAULT_BLOCK_SIZE,
DEFAULT_SIZE,
d_id,
seastore_meta_t {}
};
}
};
CircularBoundedJournal(
JournalTrimmer &trimmer, RBMDevice* device, const std::string &path);
~CircularBoundedJournal() {}
@ -165,10 +146,9 @@ public:
*
* make a new journal layout even if old journal exists
*
* @param mkfs_config_t
*
*/
mkfs_ret mkfs(const mkfs_config_t& config);
mkfs_ret mkfs();
/**
@ -194,29 +174,14 @@ public:
*/
struct cbj_header_t {
uint64_t magic = CBJOURNAL_MAGIC;
uuid_d uuid;
uint64_t block_size = 0; // block size of underlying device
uint64_t size = 0; // max length of journal
// start offset of CircularBoundedJournal in the device
journal_seq_t dirty_tail;
journal_seq_t alloc_tail;
device_id_t device_id;
DENC(cbj_header_t, v, p) {
DENC_START(1, 1, p);
denc(v.magic, p);
denc(v.uuid, p);
denc(v.block_size, p);
denc(v.size, p);
denc(v.dirty_tail, p);
denc(v.alloc_tail, p);
denc(v.device_id, p);
DENC_FINISH(p);
}
};
@ -237,11 +202,12 @@ public:
auto rbm_tail = get_rbm_addr(get_dirty_tail());
return rbm_written_to >= rbm_tail ?
rbm_written_to - rbm_tail :
rbm_written_to + header.size + get_block_size()
rbm_written_to + get_total_size() + get_block_size()
- rbm_tail;
}
size_t get_total_size() const {
return header.size;
assert(device);
return device->get_journal_size() - get_block_size();
}
rbm_abs_addr get_start_addr() const {
return CBJOURNAL_START_ADDRESS + get_block_size();
@ -289,13 +255,14 @@ public:
written_to = seq;
}
device_id_t get_device_id() const {
return header.device_id;
return device->get_device_id();
}
extent_len_t get_block_size() const {
return header.block_size;
assert(device);
return device->get_block_size();
}
rbm_abs_addr get_journal_end() const {
return get_start_addr() + header.size + get_block_size(); // journal size + header length
return get_start_addr() + get_total_size() + get_block_size(); // journal size + header length
}
seastar::future<> finish_commit(transaction_type_t type) final;
private:

View File

@ -163,6 +163,14 @@ public:
using stat_device_ret =
read_ertr::future<seastar::stat_data>;
virtual stat_device_ret stat_device() = 0;
uint64_t get_journal_size() const {
return super.journal_size;
}
void set_journal_size(uint64_t size) {
super.journal_size = size;
}
};
class TestMemory : public RBMDevice {

View File

@ -649,8 +649,7 @@ TransactionManagerRef make_transaction_manager(
roll_start = 0;
} else {
// FIXME: get from runtime configration instead of static defaults
roll_size = journal::CircularBoundedJournal::mkfs_config_t
::get_default().total_size;
roll_size = journal::DEFAULT_TEST_CBJOURNAL_SIZE;
// see CircularBoundedJournal::get_start_addr()
roll_start = journal::CBJOURNAL_START_ADDRESS +
primary_device->get_block_size();

View File

@ -13,6 +13,7 @@
#include "crimson/os/seastore/random_block_manager/rbm_device.h"
#include "crimson/os/seastore/seastore_types.h"
#include "test/crimson/seastore/transaction_manager_test_state.h"
#include "crimson/os/seastore/random_block_manager/block_rb_manager.h"
using namespace crimson;
using namespace crimson::os;
@ -128,7 +129,6 @@ struct cbjournal_test_t : public seastar_test_suite_t, JournalTrimmer
std::default_random_engine generator;
uint64_t block_size;
CircularBoundedJournal::mkfs_config_t config;
WritePipeline pipeline;
cbjournal_test_t() {
@ -136,10 +136,6 @@ struct cbjournal_test_t : public seastar_test_suite_t, JournalTrimmer
CBTEST_DEFAULT_TEST_SIZE + CBTEST_DEFAULT_BLOCK_SIZE,
CBTEST_DEFAULT_BLOCK_SIZE);
cbj.reset(new CircularBoundedJournal(*this, device, std::string()));
device_id_t d_id = 1 << (std::numeric_limits<device_id_t>::digits - 1);
config.block_size = CBTEST_DEFAULT_BLOCK_SIZE;
config.total_size = CBTEST_DEFAULT_TEST_SIZE;
config.device_id = d_id;
block_size = CBTEST_DEFAULT_BLOCK_SIZE;
cbj->set_write_pipeline(&pipeline);
}
@ -252,9 +248,14 @@ struct cbjournal_test_t : public seastar_test_suite_t, JournalTrimmer
auto mkfs() {
return device->mount(
).safe_then([this]() {
return cbj->mkfs(config
).safe_then([]() {
return seastar::now();
device_config_t config = get_rbm_ephemeral_device_config(0, 1);
device->set_journal_size(CBTEST_DEFAULT_TEST_SIZE);
return device->mkfs(config
).safe_then([this]() {
return cbj->mkfs(
).safe_then([]() {
return seastar::now();
});
});
}).unsafe_get0();
}
@ -440,8 +441,6 @@ TEST_F(cbjournal_test_t, update_header)
replay();
ASSERT_EQ(update_header.dirty_tail.offset, update_header.dirty_tail.offset);
ASSERT_EQ(header.block_size, update_header.block_size);
ASSERT_EQ(header.size, update_header.size);
});
}

View File

@ -17,6 +17,7 @@
#include "crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.h"
#include "crimson/os/seastore/random_block_manager/rbm_device.h"
#include "crimson/os/seastore/journal/circular_bounded_journal.h"
#include "crimson/os/seastore/random_block_manager/block_rb_manager.h"
using namespace crimson;
using namespace crimson::os;
@ -116,15 +117,17 @@ protected:
seastar::future<> randomblock_setup()
{
auto config =
journal::CircularBoundedJournal::mkfs_config_t::get_default();
rb_device.reset(new random_block_device::TestMemory(
config.total_size + config.block_size, config.block_size));
rb_device->set_device_id(
1 << (std::numeric_limits<device_id_t>::digits - 1));
journal::DEFAULT_TEST_CBJOURNAL_SIZE + journal::DEFAULT_BLOCK_SIZE,
journal::DEFAULT_BLOCK_SIZE));
return rb_device->mount().handle_error(crimson::ct_error::assert_all{}
).then([this]() {
return segment_setup();
device_config_t config = get_rbm_ephemeral_device_config(0, 1);
rb_device->set_journal_size(journal::DEFAULT_TEST_CBJOURNAL_SIZE);
return rb_device->mkfs(config).handle_error(crimson::ct_error::assert_all{}
).then([this]() {
return segment_setup();
});
});
}
@ -220,9 +223,7 @@ protected:
crimson::ct_error::assert_all{"Error in mkfs"}
);
} else {
auto config = journal::CircularBoundedJournal::mkfs_config_t::get_default();
return static_cast<journal::CircularBoundedJournal*>(tm->get_journal())->mkfs(
config
).safe_then([this]() {
return tm->mkfs(
).handle_error(