]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
AsyncConnection: Make sign_message ahead of construct message bufferlist 5245/head
authorHaomai Wang <haomaiwang@gmail.com>
Tue, 14 Jul 2015 18:06:36 +0000 (02:06 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Tue, 14 Jul 2015 18:21:43 +0000 (02:21 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/msg/async/AsyncConnection.cc

index bc1b803a176683802a9621f339a0dc4de7c19e10..2cec7fde0903b9da885964333a29118c726eaded 100644 (file)
@@ -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)) {