crimson/osd: split PG::get_oid_and_lock() into two methods
authorKefu Chai <kchai@redhat.com>
Sat, 19 Sep 2020 03:02:19 +0000 (11:02 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 19 Sep 2020 05:30:51 +0000 (13:30 +0800)
for better readability

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/pg.cc
src/crimson/osd/pg.h

index 3abe129c2fe410a5ea50c49703974986a54344ad..0b225cff604d14dd14313301d48db2d3f711f8a8 100644 (file)
@@ -717,23 +717,24 @@ seastar::future<Ref<MOSDOpReply>> PG::do_pg_ops(Ref<MOSDOp> m)
   });
 }
 
-std::pair<hobject_t, RWState::State> 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<hobject_t> PG::resolve_oid(
index 7cdd054c33a3701ca20748b43d59bef199aa1ad6..0f1e92417c695ca962a6b8653ce9fcf6631ca8d6 100644 (file)
@@ -482,9 +482,8 @@ public:
   void handle_activate_map(PeeringCtx &rctx);
   void handle_initialize(PeeringCtx &rctx);
 
-  static std::pair<hobject_t, RWState::State> 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<hobject_t> 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>(f), type=type](auto obc) {
        return f(obc).finally([obc, type=type] {
          obc->put_lock_type(type);