From 1c2a0b9c30d0d5facba16ded32b7168081f08668 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Thu, 21 Jul 2022 15:36:43 +0800 Subject: [PATCH] crimson/os/seastore: move Transaction::src_t to seastore_types.h Signed-off-by: Yingxin Cheng --- src/crimson/os/seastore/cache.h | 4 +-- src/crimson/os/seastore/seastore_types.cc | 22 +++++++++++++++ src/crimson/os/seastore/seastore_types.h | 25 +++++++++++++++++ src/crimson/os/seastore/transaction.h | 33 +---------------------- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/crimson/os/seastore/cache.h b/src/crimson/os/seastore/cache.h index 7e2228953b15e..254af8395c4e8 100644 --- a/src/crimson/os/seastore/cache.h +++ b/src/crimson/os/seastore/cache.h @@ -1164,10 +1164,10 @@ private: }; template - using counter_by_src_t = std::array; + using counter_by_src_t = std::array; static constexpr std::size_t NUM_SRC_COMB = - Transaction::SRC_MAX * (Transaction::SRC_MAX + 1) / 2; + TRANSACTION_TYPE_MAX * (TRANSACTION_TYPE_MAX + 1) / 2; struct { counter_by_src_t trans_created_by_src; diff --git a/src/crimson/os/seastore/seastore_types.cc b/src/crimson/os/seastore/seastore_types.cc index a9b0d1c5fd486..ea3c63ad76455 100644 --- a/src/crimson/os/seastore/seastore_types.cc +++ b/src/crimson/os/seastore/seastore_types.cc @@ -309,6 +309,28 @@ void record_size_t::account(const delta_info_t& delta) plain_mdlength += ceph::encoded_sizeof(delta); } +std::ostream &operator<<(std::ostream &os, transaction_type_t type) +{ + switch (type) { + case transaction_type_t::MUTATE: + return os << "MUTATE"; + case transaction_type_t::READ: + return os << "READ"; + case transaction_type_t::CLEANER_TRIM: + return os << "CLEANER_TRIM"; + case transaction_type_t::TRIM_BACKREF: + return os << "TRIM_BACKREF"; + case transaction_type_t::CLEANER_RECLAIM: + return os << "CLEANER_RECLAIM"; + case transaction_type_t::MAX: + return os << "TRANS_TYPE_NULL"; + default: + return os << "INVALID_TRANS_TYPE(" + << static_cast(type) + << ")"; + } +} + std::ostream &operator<<(std::ostream& out, const record_size_t& rsize) { return out << "record_size_t(" diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index a14ccaeb27776..324c839f316ca 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -1541,6 +1541,31 @@ struct segment_tail_t { }; std::ostream &operator<<(std::ostream &out, const segment_tail_t &tail); +enum class transaction_type_t : uint8_t { + MUTATE = 0, + READ, // including weak and non-weak read transactions + CLEANER_TRIM, + TRIM_BACKREF, + CLEANER_RECLAIM, + MAX +}; + +static constexpr auto TRANSACTION_TYPE_NULL = transaction_type_t::MAX; + +static constexpr auto TRANSACTION_TYPE_MAX = static_cast( + transaction_type_t::MAX); + +std::ostream &operator<<(std::ostream &os, transaction_type_t type); + +constexpr bool is_valid_transaction(transaction_type_t type) { + return type < transaction_type_t::MAX; +} + +constexpr bool is_cleaner_transaction(transaction_type_t type) { + return (type >= transaction_type_t::CLEANER_TRIM && + type < transaction_type_t::MAX); +} + struct record_size_t { extent_len_t plain_mdlength = 0; // mdlength without the record header extent_len_t dlength = 0; diff --git a/src/crimson/os/seastore/transaction.h b/src/crimson/os/seastore/transaction.h index f81bc62e5f5c5..2917065b178fe 100644 --- a/src/crimson/os/seastore/transaction.h +++ b/src/crimson/os/seastore/transaction.h @@ -293,15 +293,7 @@ public: return ret; } - enum class src_t : uint8_t { - MUTATE = 0, - READ, // including weak and non-weak read transactions - CLEANER_TRIM, - TRIM_BACKREF, - CLEANER_RECLAIM, - MAX - }; - static constexpr auto SRC_MAX = static_cast(src_t::MAX); + using src_t = transaction_type_t; src_t get_src() const { return src; } @@ -542,29 +534,6 @@ private: }; using TransactionRef = Transaction::Ref; -inline std::ostream& operator<<(std::ostream& os, - const Transaction::src_t& src) { - switch (src) { - case Transaction::src_t::MUTATE: - return os << "MUTATE"; - case Transaction::src_t::READ: - return os << "READ"; - case Transaction::src_t::CLEANER_TRIM: - return os << "CLEANER_TRIM"; - case Transaction::src_t::TRIM_BACKREF: - return os << "TRIM_BACKREF"; - case Transaction::src_t::CLEANER_RECLAIM: - return os << "CLEANER_RECLAIM"; - default: - ceph_abort("impossible"); - } -} - -constexpr bool is_cleaner_transaction(Transaction::src_t src) { - return (src >= Transaction::src_t::CLEANER_TRIM && - src < Transaction::src_t::MAX); -} - /// Should only be used with dummy staged-fltree node extent manager inline TransactionRef make_test_transaction() { return std::make_unique( -- 2.39.5