From bbf5842e02f95dc3adb26347774ab63f3a7b0781 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Wed, 15 Jul 2015 02:06:36 +0800 Subject: [PATCH] AsyncConnection: Make sign_message ahead of construct message bufferlist Signed-off-by: Haomai Wang --- src/msg/async/AsyncConnection.cc | 47 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/msg/async/AsyncConnection.cc b/src/msg/async/AsyncConnection.cc index bc1b803a17668..2cec7fde0903b 100644 --- a/src/msg/async/AsyncConnection.cc +++ b/src/msg/async/AsyncConnection.cc @@ -1947,7 +1947,7 @@ int AsyncConnection::send_message(Message *m) Mutex::Locker l(write_lock); // "features" changes will change the payload encoding - if (can_write == NOWRITE || get_features() != f) { + if (can_fast_prepare && (can_write == NOWRITE || get_features() != f)) { // ensure the correctness of message encoding bl.clear(); m->get_payload().clear(); @@ -2213,14 +2213,34 @@ int AsyncConnection::write_message(Message *m, bufferlist& bl) m->get(); } + m->calc_header_crc(); + + ceph_msg_header& header = m->get_header(); + ceph_msg_footer& footer = m->get_footer(); + + // TODO: let sign_message could be reentry? + // Now that we have all the crcs calculated, handle the + // digital signature for the message, if the AsyncConnection has session + // security set up. Some session security options do not + // actually calculate and check the signature, but they should + // handle the calls to sign_message and check_signature. PLR + if (session_security.get() == NULL) { + ldout(async_msgr->cct, 20) << __func__ << " no session security" << dendl; + } else { + if (session_security->sign_message(m)) { + ldout(async_msgr->cct, 20) << __func__ << " failed to sign m=" + << m << "): sig = " << footer.sig << dendl; + } else { + ldout(async_msgr->cct, 20) << __func__ << " signed m=" << m + << "): sig = " << footer.sig << dendl; + } + } + bufferlist complete_bl; // send tag char tag = CEPH_MSGR_TAG_MSG; complete_bl.append(&tag, sizeof(tag)); - m->calc_header_crc(); - ceph_msg_header& header = m->get_header(); - ceph_msg_footer& footer = m->get_footer(); if (has_feature(CEPH_FEATURE_NOSRCADDR)) { complete_bl.append((char*)&header, sizeof(header)); } else { @@ -2230,7 +2250,6 @@ int AsyncConnection::write_message(Message *m, bufferlist& bl) oldheader.src.addr = get_peer_addr(); oldheader.orig_src = oldheader.src; oldheader.reserved = header.reserved; - // delay crc calculate to "inject_msg_header_crc" oldheader.crc = ceph_crc32c(0, (unsigned char*)&oldheader, sizeof(oldheader) - sizeof(oldheader.crc)); complete_bl.append((char*)&oldheader, sizeof(oldheader)); @@ -2244,24 +2263,6 @@ int AsyncConnection::write_message(Message *m, bufferlist& bl) complete_bl.claim_append(bl); - // TODO: let sign_message could be reentry? - // Now that we have all the crcs calculated, handle the - // digital signature for the message, if the AsyncConnection has session - // security set up. Some session security options do not - // actually calculate and check the signature, but they should - // handle the calls to sign_message and check_signature. PLR - if (session_security.get() == NULL) { - ldout(async_msgr->cct, 20) << __func__ << " no session security" << dendl; - } else { - if (session_security->sign_message(m)) { - ldout(async_msgr->cct, 20) << __func__ << " failed to sign m=" - << m << "): sig = " << footer.sig << dendl; - } else { - ldout(async_msgr->cct, 20) << __func__ << " signed m=" << m - << "): sig = " << footer.sig << dendl; - } - } - // send footer; if receiver doesn't support signatures, use the old footer format ceph_msg_footer_old old_footer; if (has_feature(CEPH_FEATURE_MSG_AUTH)) { -- 2.47.3