Skip to content

Commit

Permalink
crimson/os/seastore: move backref_entry_t to a separate header
Browse files Browse the repository at this point in the history
For reuse.

Signed-off-by: Yingxin Cheng <[email protected]>
  • Loading branch information
cyx1231st committed Dec 18, 2024
1 parent be00314 commit 4a39328
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 108 deletions.
127 changes: 127 additions & 0 deletions src/crimson/os/seastore/backref_entry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include <memory>
#include <iostream>

#if FMT_VERSION >= 90000
#include <fmt/ostream.h>
#endif

#include <boost/intrusive/set.hpp>

#include "crimson/os/seastore/seastore_types.h"

namespace crimson::os::seastore {

struct backref_entry_t {
using ref_t = std::unique_ptr<backref_entry_t>;

backref_entry_t(
const paddr_t& paddr,
const laddr_t& laddr,
extent_len_t len,
extent_types_t type)
: paddr(paddr),
laddr(laddr),
len(len),
type(type) {
assert(len > 0);
}
paddr_t paddr = P_ADDR_NULL;
laddr_t laddr = L_ADDR_NULL;
extent_len_t len = 0;
extent_types_t type = extent_types_t::NONE;
friend bool operator< (
const backref_entry_t &l,
const backref_entry_t &r) {
return l.paddr < r.paddr;
}
friend bool operator> (
const backref_entry_t &l,
const backref_entry_t &r) {
return l.paddr > r.paddr;
}
friend bool operator== (
const backref_entry_t &l,
const backref_entry_t &r) {
return l.paddr == r.paddr;
}

using set_hook_t =
boost::intrusive::set_member_hook<
boost::intrusive::link_mode<
boost::intrusive::auto_unlink>>;
set_hook_t backref_set_hook;
using backref_set_member_options = boost::intrusive::member_hook<
backref_entry_t,
set_hook_t,
&backref_entry_t::backref_set_hook>;
using multiset_t = boost::intrusive::multiset<
backref_entry_t,
backref_set_member_options,
boost::intrusive::constant_time_size<false>>;

struct cmp_t {
using is_transparent = paddr_t;
bool operator()(
const backref_entry_t &l,
const backref_entry_t &r) const {
return l.paddr < r.paddr;
}
bool operator()(const paddr_t l, const backref_entry_t &r) const {
return l < r.paddr;
}
bool operator()(const backref_entry_t &l, const paddr_t r) const {
return l.paddr < r;
}
};

static ref_t create_alloc(
const paddr_t& paddr,
const laddr_t& laddr,
extent_len_t len,
extent_types_t type) {
assert(is_backref_mapped_type(type));
assert(laddr != L_ADDR_NULL);
return std::make_unique<backref_entry_t>(
paddr, laddr, len, type);
}

static ref_t create_retire(
const paddr_t& paddr,
extent_len_t len,
extent_types_t type) {
assert(is_backref_mapped_type(type) ||
is_retired_placeholder_type(type));
return std::make_unique<backref_entry_t>(
paddr, L_ADDR_NULL, len, type);
}

static ref_t create(const alloc_blk_t& delta) {
return std::make_unique<backref_entry_t>(
delta.paddr, delta.laddr, delta.len, delta.type);
}
};

inline std::ostream &operator<<(std::ostream &out, const backref_entry_t &ent) {
return out << "backref_entry_t{"
<< ent.paddr << "~0x" << std::hex << ent.len << std::dec << ", "
<< "laddr: " << ent.laddr << ", "
<< "type: " << ent.type
<< "}";
}

using backref_entry_ref = backref_entry_t::ref_t;
using backref_entry_mset_t = backref_entry_t::multiset_t;
using backref_entry_refs_t = std::vector<backref_entry_ref>;
using backref_entryrefs_by_seq_t = std::map<journal_seq_t, backref_entry_refs_t>;
using backref_entry_query_set_t = std::set<backref_entry_t, backref_entry_t::cmp_t>;

} // namespace crimson::os::seastore

#if FMT_VERSION >= 90000
template <> struct fmt::formatter<crimson::os::seastore::backref_entry_t> : fmt::ostream_formatter {};
#endif
8 changes: 0 additions & 8 deletions src/crimson/os/seastore/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ SET_SUBSYS(seastore_cache);

namespace crimson::os::seastore {

std::ostream &operator<<(std::ostream &out, const backref_entry_t &ent) {
return out << "backref_entry_t{"
<< ent.paddr << "~0x" << std::hex << ent.len << std::dec << ", "
<< "laddr: " << ent.laddr << ", "
<< "type: " << ent.type
<< "}";
}

Cache::Cache(
ExtentPlacementManager &epm)
: epm(epm),
Expand Down
101 changes: 1 addition & 100 deletions src/crimson/os/seastore/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

#pragma once

#include <iostream>

#include "seastar/core/shared_future.hh"

#include "include/buffer.h"

#include "crimson/common/errorator.h"
#include "crimson/common/errorator-loop.h"
#include "crimson/os/seastore/backref_entry.h"
#include "crimson/os/seastore/cached_extent.h"
#include "crimson/os/seastore/extent_placement_manager.h"
#include "crimson/os/seastore/logging.h"
Expand Down Expand Up @@ -38,104 +37,6 @@ class FixedKVBtree;
class BackrefManager;
class SegmentProvider;

struct backref_entry_t {
using ref_t = std::unique_ptr<backref_entry_t>;

backref_entry_t(
const paddr_t& paddr,
const laddr_t& laddr,
extent_len_t len,
extent_types_t type)
: paddr(paddr),
laddr(laddr),
len(len),
type(type) {
assert(len > 0);
}
paddr_t paddr = P_ADDR_NULL;
laddr_t laddr = L_ADDR_NULL;
extent_len_t len = 0;
extent_types_t type = extent_types_t::NONE;
friend bool operator< (
const backref_entry_t &l,
const backref_entry_t &r) {
return l.paddr < r.paddr;
}
friend bool operator> (
const backref_entry_t &l,
const backref_entry_t &r) {
return l.paddr > r.paddr;
}
friend bool operator== (
const backref_entry_t &l,
const backref_entry_t &r) {
return l.paddr == r.paddr;
}

using set_hook_t =
boost::intrusive::set_member_hook<
boost::intrusive::link_mode<
boost::intrusive::auto_unlink>>;
set_hook_t backref_set_hook;
using backref_set_member_options = boost::intrusive::member_hook<
backref_entry_t,
set_hook_t,
&backref_entry_t::backref_set_hook>;
using multiset_t = boost::intrusive::multiset<
backref_entry_t,
backref_set_member_options,
boost::intrusive::constant_time_size<false>>;

struct cmp_t {
using is_transparent = paddr_t;
bool operator()(
const backref_entry_t &l,
const backref_entry_t &r) const {
return l.paddr < r.paddr;
}
bool operator()(const paddr_t l, const backref_entry_t &r) const {
return l < r.paddr;
}
bool operator()(const backref_entry_t &l, const paddr_t r) const {
return l.paddr < r;
}
};

static ref_t create_alloc(
const paddr_t& paddr,
const laddr_t& laddr,
extent_len_t len,
extent_types_t type) {
assert(is_backref_mapped_type(type));
assert(laddr != L_ADDR_NULL);
return std::make_unique<backref_entry_t>(
paddr, laddr, len, type);
}

static ref_t create_retire(
const paddr_t& paddr,
extent_len_t len,
extent_types_t type) {
assert(is_backref_mapped_type(type) ||
is_retired_placeholder_type(type));
return std::make_unique<backref_entry_t>(
paddr, L_ADDR_NULL, len, type);
}

static ref_t create(const alloc_blk_t& delta) {
return std::make_unique<backref_entry_t>(
delta.paddr, delta.laddr, delta.len, delta.type);
}
};

std::ostream &operator<<(std::ostream &out, const backref_entry_t &ent);

using backref_entry_ref = backref_entry_t::ref_t;
using backref_entry_mset_t = backref_entry_t::multiset_t;
using backref_entry_refs_t = std::vector<backref_entry_ref>;
using backref_entryrefs_by_seq_t = std::map<journal_seq_t, backref_entry_refs_t>;
using backref_entry_query_set_t = std::set<backref_entry_t, backref_entry_t::cmp_t>;

/**
* Cache
*
Expand Down

0 comments on commit 4a39328

Please sign in to comment.