From da32890cf5955700d43833297b413b2dd1e5d83c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 19 Sep 2020 11:02:19 +0800 Subject: [PATCH] crimson/osd: split PG::get_oid_and_lock() into two methods for better readability Signed-off-by: Kefu Chai --- src/crimson/osd/pg.cc | 21 +++++++++++---------- src/crimson/osd/pg.h | 9 ++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index 3abe129c2fe41..0b225cff604d1 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -717,23 +717,24 @@ seastar::future> PG::do_pg_ops(Ref m) }); } -std::pair PG::get_oid_and_lock( - const MOSDOp &m, - const OpInfo &op_info) +hobject_t PG::get_oid(const MOSDOp &m) +{ + return (m.get_snapid() == CEPH_SNAPDIR ? + m.get_hobj().get_head() : + m.get_hobj()); +} + +RWState::State PG::get_lock_type(const OpInfo &op_info) { - auto oid = m.get_snapid() == CEPH_SNAPDIR ? - m.get_hobj().get_head() : m.get_hobj(); - RWState::State lock_type = RWState::RWNONE; if (op_info.rwordered() && op_info.may_read()) { - lock_type = RWState::RWState::RWEXCL; + return RWState::RWEXCL; } else if (op_info.rwordered()) { - lock_type = RWState::RWState::RWWRITE; + return RWState::RWWRITE; } else { ceph_assert(op_info.may_read()); - lock_type = RWState::RWState::RWREAD; + return RWState::RWREAD; } - return std::make_pair(oid, lock_type); } std::optional PG::resolve_oid( diff --git a/src/crimson/osd/pg.h b/src/crimson/osd/pg.h index 7cdd054c33a37..0f1e92417c695 100644 --- a/src/crimson/osd/pg.h +++ b/src/crimson/osd/pg.h @@ -482,9 +482,8 @@ public: void handle_activate_map(PeeringCtx &rctx); void handle_initialize(PeeringCtx &rctx); - static std::pair get_oid_and_lock( - const MOSDOp &m, - const OpInfo &op_info); + static hobject_t get_oid(const MOSDOp &m); + static RWState::State get_lock_type(const OpInfo &op_info); static std::optional resolve_oid( const SnapSet &snapset, const hobject_t &oid); @@ -514,8 +513,8 @@ public: if (__builtin_expect(stopping, false)) { throw crimson::common::system_shutdown_exception(); } - auto [oid, type] = get_oid_and_lock(*m, op_info); - return get_locked_obc(op, oid, type) + RWState::State type = get_lock_type(op_info); + return get_locked_obc(op, get_oid(*m), type) .safe_then([f=std::forward(f), type=type](auto obc) { return f(obc).finally([obc, type=type] { obc->put_lock_type(type); -- 2.39.5