From: Kefu Chai Date: Fri, 30 Aug 2019 06:17:42 +0000 (+0800) Subject: osd: use get_req<> instead of static_cast<>(get_req()) X-Git-Tag: v15.1.0~1652^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=228916db34432ad1cb34fd46dcc0296f77e1ae52;p=ceph.git osd: use get_req<> instead of static_cast<>(get_req()) less repeating, better readability Signed-off-by: Kefu Chai --- diff --git a/src/osd/DynamicPerfStats.h b/src/osd/DynamicPerfStats.h index e88b21c9dd04..ff4bd98d942e 100644 --- a/src/osd/DynamicPerfStats.h +++ b/src/osd/DynamicPerfStats.h @@ -115,7 +115,7 @@ public: OSDPerfMetricSubKey *sub_key) { ceph_assert(d.is_supported()); - auto m = static_cast(op.get_req()); + auto m = op.get_req(); std::string match_string; switch(d.type) { case OSDPerfMetricSubKeyType::CLIENT_ID: diff --git a/src/osd/ECBackend.cc b/src/osd/ECBackend.cc index cad3fc40cc21..7a7ccd7d71d2 100644 --- a/src/osd/ECBackend.cc +++ b/src/osd/ECBackend.cc @@ -803,7 +803,7 @@ bool ECBackend::_handle_message( return true; } case MSG_OSD_EC_READ: { - const MOSDECSubOpRead *op = static_cast(_op->get_req()); + auto op = _op->get_req(); MOSDECSubOpReadReply *reply = new MOSDECSubOpReadReply; reply->pgid = get_parent()->primary_spg_t(); reply->map_epoch = get_osdmap_epoch(); @@ -825,7 +825,7 @@ bool ECBackend::_handle_message( return true; } case MSG_OSD_PG_PUSH: { - const MOSDPGPush *op = static_cast(_op->get_req()); + auto op = _op->get_req(); RecoveryMessages rm; for (vector::const_iterator i = op->pushes.begin(); i != op->pushes.end(); diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 40afda69d33e..8f63a4de8c1e 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1557,7 +1557,7 @@ void OSDService::reply_op_error(OpRequestRef op, int err) void OSDService::reply_op_error(OpRequestRef op, int err, eversion_t v, version_t uv) { - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == CEPH_MSG_OSD_OP); int flags; flags = m->get_flags() & (CEPH_OSD_FLAG_ACK|CEPH_OSD_FLAG_ONDISK); @@ -1573,7 +1573,7 @@ void OSDService::handle_misdirected_op(PG *pg, OpRequestRef op) return; } - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == CEPH_MSG_OSD_OP); ceph_assert(m->get_map_epoch() >= pg->get_history().same_primary_since); @@ -6892,8 +6892,7 @@ void OSD::dispatch_session_waiting(SessionRef session, OSDMapRef osdmap) while (i != session->waiting_on_map.end()) { OpRequestRef op = &(*i); ceph_assert(ms_can_fast_dispatch(op->get_req())); - const MOSDFastDispatchOp *m = static_cast( - op->get_req()); + auto m = op->get_req(); if (m->get_min_epoch() > osdmap->get_epoch()) { break; } @@ -8867,7 +8866,7 @@ void OSD::handle_pg_create(OpRequestRef op) // NOTE: this can be removed in P release (mimic is the last version to // send MOSDPGCreate messages). - const MOSDPGCreate *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_CREATE); dout(10) << "handle_pg_create " << *m << dendl; @@ -9869,7 +9868,7 @@ void OSD::get_latest_osdmap() int OSD::init_op_flags(OpRequestRef& op) { - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); vector::const_iterator iter; // client flags have no bearing on whether an op is a read, write, etc. diff --git a/src/osd/OpRequest.h b/src/osd/OpRequest.h index 896317b161ed..4f1fa5411286 100644 --- a/src/osd/OpRequest.h +++ b/src/osd/OpRequest.h @@ -110,6 +110,10 @@ public: epoch_t min_epoch = 0; ///< min epoch needed to handle this msg bool hitset_inserted; + + template + const T* get_req() const { return static_cast(request); } + const Message *get_req() const { return request; } Message *get_nonconst_req() { return request; } diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 88d86957ad9e..3a0cda831626 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -374,8 +374,7 @@ bool PG::op_has_sufficient_caps(OpRequestRef& op) if (op->get_req()->get_type() != CEPH_MSG_OSD_OP) return true; - const MOSDOp *req = static_cast(op->get_req()); - + auto req = op->get_req(); auto priv = req->get_connection()->get_priv(); auto session = static_cast(priv.get()); if (!session) { @@ -1833,7 +1832,7 @@ void PG::on_activate_committed() void PG::do_replica_scrub_map(OpRequestRef op) { - const MOSDRepScrubMap *m = static_cast(op->get_req()); + auto m = op->get_req(); dout(7) << __func__ << " " << *m << dendl; if (m->map_epoch < info.history.same_interval_since) { dout(10) << __func__ << " discarding old from " @@ -1907,8 +1906,7 @@ void PG::handle_scrub_reserve_request(OpRequestRef op) dout(20) << __func__ << ": failed to reserve remotely" << dendl; scrubber.reserved = false; } - const MOSDScrubReserve *m = - static_cast(op->get_req()); + auto m = op->get_req(); Message *reply = new MOSDScrubReserve( spg_t(info.pgid.pgid, get_primary().shard), m->map_epoch, @@ -2395,7 +2393,7 @@ void PG::replica_scrub( OpRequestRef op, ThreadPool::TPHandle &handle) { - const MOSDRepScrub *msg = static_cast(op->get_req()); + auto msg = op->get_req(); ceph_assert(!scrubber.active_rep_scrub); dout(7) << "replica_scrub" << dendl; @@ -3413,7 +3411,7 @@ ostream& operator<<(ostream& out, const PG& pg) bool PG::can_discard_op(OpRequestRef& op) { - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); if (cct->_conf->osd_discard_disconnected_ops && OSD::op_is_discardable(m)) { dout(20) << " discard " << *m << dendl; return true; @@ -3465,7 +3463,7 @@ bool PG::can_discard_op(OpRequestRef& op) template bool PG::can_discard_replica_op(OpRequestRef& op) { - const T *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSGTYPE); int from = m->get_source().num(); @@ -3500,7 +3498,7 @@ bool PG::can_discard_replica_op(OpRequestRef& op) bool PG::can_discard_scan(OpRequestRef op) { - const MOSDPGScan *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_SCAN); if (old_peering_msg(m->map_epoch, m->query_epoch)) { @@ -3512,7 +3510,7 @@ bool PG::can_discard_scan(OpRequestRef op) bool PG::can_discard_backfill(OpRequestRef op) { - const MOSDPGBackfill *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_BACKFILL); if (old_peering_msg(m->map_epoch, m->query_epoch)) { diff --git a/src/osd/PGBackend.cc b/src/osd/PGBackend.cc index 744bb3f89d4c..361293833c07 100644 --- a/src/osd/PGBackend.cc +++ b/src/osd/PGBackend.cc @@ -116,7 +116,7 @@ bool PGBackend::handle_message(OpRequestRef op) void PGBackend::handle_recovery_delete(OpRequestRef op) { - const MOSDPGRecoveryDelete *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_RECOVERY_DELETE); dout(20) << __func__ << " " << op << dendl; @@ -149,7 +149,7 @@ void PGBackend::handle_recovery_delete(OpRequestRef op) void PGBackend::handle_recovery_delete_reply(OpRequestRef op) { - const MOSDPGRecoveryDeleteReply *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_RECOVERY_DELETE_REPLY); dout(20) << __func__ << " " << op << dendl; diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index e5a642c44c95..f3249bfe86b1 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -1438,7 +1438,7 @@ void PrimaryLogPG::get_src_oloc(const object_t& oid, const object_locator_t& olo void PrimaryLogPG::handle_backoff(OpRequestRef& op) { - const MOSDBackoff *m = static_cast(op->get_req()); + auto m = op->get_req(); SessionRef session{static_cast(m->get_connection()->get_priv().get())}; if (!session) return; // drop it. @@ -1588,8 +1588,7 @@ void PrimaryLogPG::do_request( case MSG_OSD_SCRUB_RESERVE: { - const MOSDScrubReserve *m = - static_cast(op->get_req()); + auto m = op->get_req(); switch (m->type) { case MOSDScrubReserve::REQUEST: handle_scrub_reserve_request(op); @@ -2150,8 +2149,7 @@ PrimaryLogPG::cache_result_t PrimaryLogPG::maybe_handle_manifest_detail( ObjectContextRef obc) { ceph_assert(obc); - if (static_cast(op->get_req())->get_flags() & - CEPH_OSD_FLAG_IGNORE_REDIRECT) { + if (op->get_req()->get_flags() & CEPH_OSD_FLAG_IGNORE_REDIRECT) { dout(20) << __func__ << ": ignoring redirect due to flag" << dendl; return cache_result_t::NOOP; } @@ -2163,7 +2161,7 @@ PrimaryLogPG::cache_result_t PrimaryLogPG::maybe_handle_manifest_detail( return cache_result_t::NOOP; } - vector ops = static_cast(op->get_req())->ops; + vector ops = op->get_req()->ops; for (vector::iterator p = ops.begin(); p != ops.end(); ++p) { OSDOp& osd_op = *p; ceph_osd_op& op = osd_op.op; @@ -2229,7 +2227,7 @@ PrimaryLogPG::cache_result_t PrimaryLogPG::maybe_handle_manifest_detail( for (auto& p : obc->obs.oi.manifest.chunk_map) { if (p.second.is_missing()) { - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); const object_locator_t oloc = m->get_object_locator(); promote_object(obc, obc->obs.oi.soid, oloc, op, NULL); return cache_result_t::BLOCKED_PROMOTE; @@ -2464,7 +2462,7 @@ void PrimaryLogPG::record_write_error(OpRequestRef op, const hobject_t &soid, { dout(20) << __func__ << " r=" << r << dendl; ceph_assert(op->may_write()); - const osd_reqid_t &reqid = static_cast(op->get_req())->get_reqid(); + const osd_reqid_t &reqid = op->get_req()->get_reqid(); mempool::osd_pglog::list entries; entries.push_back(pg_log_entry_t(pg_log_entry_t::ERROR, soid, get_next_version(), eversion_t(), 0, @@ -2485,7 +2483,7 @@ void PrimaryLogPG::record_write_error(OpRequestRef op, const hobject_t &soid, {} void operator()() { ldpp_dout(pg, 20) << "finished " << __func__ << " r=" << r << dendl; - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); int flags = m->get_flags() & (CEPH_OSD_FLAG_ACK | CEPH_OSD_FLAG_ONDISK); MOSDOpReply *reply = orig_reply.detach(); if (reply == nullptr) { @@ -2523,7 +2521,7 @@ PrimaryLogPG::cache_result_t PrimaryLogPG::maybe_handle_cache_detail( if (op && op->get_req() && op->get_req()->get_type() == CEPH_MSG_OSD_OP && - (static_cast(op->get_req())->get_flags() & + (op->get_req()->get_flags() & CEPH_OSD_FLAG_IGNORE_CACHE)) { dout(20) << __func__ << ": ignoring cache due to flag" << dendl; return cache_result_t::NOOP; @@ -2571,7 +2569,7 @@ PrimaryLogPG::cache_result_t PrimaryLogPG::maybe_handle_cache_detail( missing_oid = obc->obs.oi.soid; } - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); const object_locator_t oloc = m->get_object_locator(); if (op->need_skip_handle_cache()) { @@ -2755,7 +2753,7 @@ bool PrimaryLogPG::maybe_promote(ObjectContextRef obc, void PrimaryLogPG::do_cache_redirect(OpRequestRef op) { - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); int flags = m->get_flags() & (CEPH_OSD_FLAG_ACK|CEPH_OSD_FLAG_ONDISK); MOSDOpReply *reply = new MOSDOpReply(m, -ENOENT, get_osdmap_epoch(), flags, false); @@ -2966,7 +2964,7 @@ void PrimaryLogPG::finish_proxy_read(hobject_t oid, ceph_tid_t tid, int r) osd->logger->inc(l_osd_tier_proxy_read); - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); OpContext *ctx = new OpContext(op, m->get_reqid(), &prdop->ops, this); ctx->reply = new MOSDOpReply(m, 0, get_osdmap_epoch(), 0, false); ctx->user_at_version = prdop->user_version; @@ -3404,7 +3402,7 @@ void PrimaryLogPG::finish_proxy_write(hobject_t oid, ceph_tid_t tid, int r) osd->logger->inc(l_osd_tier_proxy_write); - const MOSDOp *m = static_cast(pwop->op->get_req()); + auto m = pwop->op->get_req(); ceph_assert(m != NULL); if (!pwop->sent_reply) { @@ -3598,7 +3596,7 @@ void PrimaryLogPG::execute_ctx(OpContext *ctx) ctx->reset_obs(ctx->obc); ctx->update_log_only = false; // reset in case finish_copyfrom() is re-running execute_ctx OpRequestRef op = ctx->op; - const MOSDOp *m = static_cast(op->get_req()); + auto m = op->get_req(); ObjectContextRef obc = ctx->obc; const hobject_t& soid = obc->obs.oi.soid; @@ -3834,7 +3832,7 @@ void PrimaryLogPG::log_op_stats(const OpRequest& op, const uint64_t inb, const uint64_t outb) { - const MOSDOp* const m = static_cast(op.get_req()); + auto m = op.get_req(); const utime_t now = ceph_clock_now(); const utime_t latency = now - m->get_recv_stamp(); @@ -3896,7 +3894,7 @@ void PrimaryLogPG::do_scan( OpRequestRef op, ThreadPool::TPHandle &handle) { - const MOSDPGScan *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_SCAN); dout(10) << "do_scan " << *m << dendl; @@ -3971,7 +3969,7 @@ void PrimaryLogPG::do_scan( void PrimaryLogPG::do_backfill(OpRequestRef op) { - const MOSDPGBackfill *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_BACKFILL); dout(10) << "do_backfill " << *m << dendl; @@ -8269,7 +8267,7 @@ int PrimaryLogPG::prepare_transaction(OpContext *ctx) ctx->delta_stats.num_objects > 0) && // FIXME: keys? (pool.info.has_flag(pg_pool_t::FLAG_FULL) || get_osdmap()->test_flag(CEPH_OSDMAP_FULL))) { - const MOSDOp *m = static_cast(ctx->op->get_req()); + auto m = ctx->op->get_req(); if (ctx->reqid.name.is_mds() || // FIXME: ignore MDS for now m->has_flag(CEPH_OSD_FLAG_FULL_FORCE)) { dout(20) << __func__ << " full, but proceeding due to FULL_FORCE or MDS" @@ -8424,7 +8422,7 @@ void PrimaryLogPG::apply_stats( void PrimaryLogPG::complete_read_ctx(int result, OpContext *ctx) { - const MOSDOp *m = static_cast(ctx->op->get_req()); + auto m = ctx->op->get_req(); ceph_assert(ctx->async_reads_complete()); for (vector::iterator p = ctx->ops->begin(); @@ -10281,7 +10279,7 @@ void PrimaryLogPG::eval_repop(RepGather *repop) { const MOSDOp *m = NULL; if (repop->op) - m = static_cast(repop->op->get_req()); + m = repop->op->get_req(); if (m) dout(10) << "eval_repop " << *repop << dendl; diff --git a/src/osd/ReplicatedBackend.cc b/src/osd/ReplicatedBackend.cc index 02e2c4840808..f083a02cd8dc 100644 --- a/src/osd/ReplicatedBackend.cc +++ b/src/osd/ReplicatedBackend.cc @@ -543,7 +543,7 @@ void ReplicatedBackend::op_commit( void ReplicatedBackend::do_repop_reply(OpRequestRef op) { static_cast(op->get_nonconst_req())->finish_decode(); - const MOSDRepOpReply *r = static_cast(op->get_req()); + auto r = op->get_req(); ceph_assert(r->get_header().type == MSG_OSD_REPOPREPLY); op->mark_started(); @@ -555,9 +555,9 @@ void ReplicatedBackend::do_repop_reply(OpRequestRef op) auto iter = in_progress_ops.find(rep_tid); if (iter != in_progress_ops.end()) { InProgressOp &ip_op = *iter->second; - const MOSDOp *m = NULL; + const MOSDOp *m = nullptr; if (ip_op.op) - m = static_cast(ip_op.op->get_req()); + m = ip_op.op->get_req(); if (m) dout(7) << __func__ << ": tid " << ip_op.tid << " op " //<< *m @@ -744,7 +744,7 @@ int ReplicatedBackend::be_deep_scrub( void ReplicatedBackend::_do_push(OpRequestRef op) { - const MOSDPGPush *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_PUSH); pg_shard_t from = m->from; @@ -811,7 +811,7 @@ struct C_ReplicatedBackend_OnPullComplete : GenContext { void ReplicatedBackend::_do_pull_response(OpRequestRef op) { - const MOSDPGPush *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_PUSH); pg_shard_t from = m->from; @@ -881,7 +881,7 @@ void ReplicatedBackend::do_pull(OpRequestRef op) void ReplicatedBackend::do_push_reply(OpRequestRef op) { - const MOSDPGPushReply *m = static_cast(op->get_req()); + auto m = op->get_req(); ceph_assert(m->get_type() == MSG_OSD_PG_PUSH_REPLY); pg_shard_t from = m->from; @@ -1009,7 +1009,7 @@ void ReplicatedBackend::issue_op( void ReplicatedBackend::do_repop(OpRequestRef op) { static_cast(op->get_nonconst_req())->finish_decode(); - const MOSDRepOp *m = static_cast(op->get_req()); + auto m = op->get_req(); int msg_type = m->get_type(); ceph_assert(MSG_OSD_REPOP == msg_type); @@ -1113,7 +1113,7 @@ void ReplicatedBackend::repop_commit(RepModifyRef rm) rm->committed = true; // send commit. - const MOSDRepOp *m = static_cast(rm->op->get_req()); + auto m = rm->op->get_req(); ceph_assert(m->get_type() == MSG_OSD_REPOP); dout(10) << __func__ << " on op " << *m << ", sending commit to osd." << rm->ackerosd