<< ", written_to=" << header.written_to
<< ", flsg=" << header.flag
<< ", header_checksum=" << header.header_checksum
- << ", start=" << header.start
- << ", end=" << header.end
<< ")";
}
LOG_PREFIX(CircularBoundedJournal::mkfs);
return _open_device(path
).safe_then([this, config, FNAME]() mutable -> mkfs_ret {
- rbm_abs_addr start_addr = convert_paddr_to_abs_addr(
- config.start);
assert(static_cast<seastore_off_t>(config.block_size) ==
device->get_block_size());
ceph::bufferlist bl;
CircularBoundedJournal::cbj_header_t head;
head.block_size = config.block_size;
- rbm_abs_addr end_addr = convert_paddr_to_abs_addr(
- config.end);
- head.size = end_addr - start_addr
- - device->get_block_size();
+ head.size = config.total_size - device->get_block_size();
head.start_offset = device->get_block_size();
head.written_to = head.start_offset;
head.applied_to = head.start_offset;
- head.start = start_addr;
- head.end = end_addr;
head.device_id = config.device_id;
+ start_dev_addr = config.start;
encode(head, bl);
header = head;
DEBUG(
open_for_write_ertr::pass_further{},
crimson::ct_error::assert_all{
"Invalid error read_header"
- }).safe_then([this, FNAME](auto p) mutable {
+ }).safe_then([this, start, FNAME](auto p) mutable {
auto &[head, bl] = *p;
header = head;
DEBUG("header : {}", header);
paddr_t paddr = convert_abs_addr_to_paddr(
get_written_to(),
header.device_id);
- header.size = header.end - header.start - get_block_size();
+ start_dev_addr = start;
init = true;
return open_for_write_ret(
open_for_write_ertr::ready_future_marker{},
{
LOG_PREFIX(CircularBoundedJournal::append_record);
std::vector<std::pair<rbm_abs_addr, bufferlist>> writes;
- if (addr + bl.length() <= header.end) {
+ if (addr + bl.length() <= get_journal_end()) {
writes.push_back(std::make_pair(addr, bl));
} else {
// write remaining data---in this case,
// data is splited into two parts before due to the end of CircularBoundedJournal.
// the following code is to write the second part
bufferlist first_write, next_write;
- first_write.substr_of(bl, 0, header.end - addr);
+ first_write.substr_of(bl, 0, get_journal_end() - addr);
writes.push_back(std::make_pair(addr, first_write));
next_write.substr_of(
bl, first_write.length(), bl.length() - first_write.length());
auto r_size = record_group_size_t(record.size, get_block_size());
auto encoded_size = r_size.get_encoded_length();
if (get_written_to() +
- ceph::encoded_sizeof_bounded<record_group_header_t>() > header.end) {
+ ceph::encoded_sizeof_bounded<record_group_header_t>() > get_journal_end()) {
// not enough space between written_to and the end of journal,
// so that update used size to increase the amount of the remaing space
// | cbjournal |
std::move(record), device->get_block_size(),
j_seq, 0);
auto target = get_written_to();
- if (get_written_to() + to_write.length() >= header.end) {
+ if (get_written_to() + to_write.length() >= get_journal_end()) {
set_written_to(get_start_addr() +
- (to_write.length() - (header.end - get_written_to())));
+ (to_write.length() - (get_journal_end() - get_written_to())));
} else {
set_written_to(get_written_to() + to_write.length());
}
{
LOG_PREFIX(CircularBoundedJournal::device_write_bl);
auto length = bl.length();
- if (offset + length > header.end) {
+ if (offset + length > get_journal_end()) {
return crimson::ct_error::erange::make();
}
bl.rebuild_aligned(get_block_size());
);
});
}).safe_then([this, &cursor_addr]() {
- if (cursor_addr >= header.end) {
- cursor_addr = (cursor_addr - header.end) + get_start_addr();
+ if (cursor_addr >= get_journal_end()) {
+ cursor_addr = (cursor_addr - get_journal_end()) + get_start_addr();
}
if (get_written_to() +
- ceph::encoded_sizeof_bounded<record_group_header_t>() > header.end) {
+ ceph::encoded_sizeof_bounded<record_group_header_t>() > get_journal_end()) {
cursor_addr = get_start_addr();
}
return replay_ertr::make_ready_future<
off);
rbm_abs_addr addr = offset;
auto read_length = get_block_size();
- if (addr + get_block_size() > header.end) {
+ if (addr + get_block_size() > get_journal_end()) {
addr = get_start_addr();
- read_length = header.end - offset;
+ read_length = get_journal_end() - offset;
}
DEBUG("read_record: reading record from abs addr {} read length {}",
addr, read_length);
auto next_read = h.mdlength + h.dlength - read_length;
DEBUG(" next_read_addr {}, next_read_length {} ",
next_read_addr, next_read);
- if (header.end < next_read_addr + next_read) {
+ if (get_journal_end() < next_read_addr + next_read) {
// In this case, need two more reads.
// The first is to read remain bytes to the end of cbjournal
// The second is to read the data at the begining of cbjournal
- next_read = header.end - (addr + read_length);
+ next_read = get_journal_end() - (addr + read_length);
}
DEBUG("read_entry: additional reading addr {} length {}",
next_read_addr,
DEBUG(
"sync header of CircularBoundedJournal, length {}",
bl.length());
- return device_write_bl(header.start, bl);
+ return device_write_bl(start_dev_addr, bl);
}
}
public:
struct mkfs_config_t {
std::string path;
- paddr_t start;
- paddr_t end;
+ rbm_abs_addr start = 0;
size_t block_size = 0;
size_t total_size = 0;
device_id_t device_id = 0;
device_id_t d_id = 1 << (std::numeric_limits<device_id_t>::digits - 1);
return mkfs_config_t {
"",
- paddr_t::make_blk_paddr(d_id, 0),
- paddr_t::make_blk_paddr(d_id, DEFAULT_SIZE),
+ 0,
DEFAULT_BLOCK_SIZE,
DEFAULT_SIZE,
d_id,
uint64_t flag = 0; // represent features (reserved)
checksum_t header_checksum = 0; // checksum of entire cbj_header_t
- rbm_abs_addr start = 0; // start address of CircularBoundedJournal
- rbm_abs_addr end = 0; // start address of CircularBoundedJournal
device_id_t device_id;
DENC(cbj_header_t, v, p) {
denc(v.magic, p);
denc(v.uuid, p);
denc(v.block_size, p);
+ denc(v.size, p);
denc(v.start_offset, p);
denc(v.flag, p);
denc(v.header_checksum, p);
- denc(v.start, p);
- denc(v.end, p);
denc(v.device_id, p);
DENC_FINISH(p);
size_t get_block_size() const {
return header.block_size;
}
+ rbm_abs_addr get_journal_end() const {
+ return header.size + get_block_size(); // journal size + header length
+ }
void add_device(NVMeBlockDevice* dev) {
device = dev;
}
WritePipeline *write_pipeline = nullptr;
bool init = false;
segment_seq_t cur_segment_seq = 0; // segment seq to track the sequence to written records
+ rbm_abs_addr start_dev_addr = 0; // cbjournal start address in device
};
std::ostream &operator<<(std::ostream &out, const CircularBoundedJournal::cbj_header_t &header);
device = new nvme_device::TestMemory(CBTEST_DEFAULT_TEST_SIZE);
cbj.reset(new CircularBoundedJournal(device, std::string()));
device_id_t d_id = 1 << (std::numeric_limits<device_id_t>::digits - 1);
- config.start = paddr_t::make_blk_paddr(d_id, 0);
- config.end = paddr_t::make_blk_paddr(d_id, CBTEST_DEFAULT_TEST_SIZE);
+ config.start = 0;
config.block_size = CBTEST_DEFAULT_BLOCK_SIZE;
config.total_size = CBTEST_DEFAULT_TEST_SIZE;
config.device_id = d_id;
return cbj->mkfs(config).unsafe_get0();
}
auto open() {
- rbm_abs_addr addr = convert_paddr_to_abs_addr(
- config.start);
- return cbj->open_for_write(addr).unsafe_get0();
+ return cbj->open_for_write(config.start).unsafe_get0();
}
auto get_available_size() {
return cbj->get_available_size();
ASSERT_EQ(update_header.applied_to, update_header.applied_to);
ASSERT_EQ(header.block_size, update_header.block_size);
- ASSERT_EQ(header.start, update_header.start);
- ASSERT_EQ(header.end, update_header.end);
ASSERT_EQ(header.size, update_header.size);
ASSERT_EQ(header.written_to + record_total_size, update_header.written_to);
});