From: Vikhyat Umrao Date: Fri, 1 Apr 2016 11:25:36 +0000 (+0530) Subject: librados: modify Pipe::connect() to return the error code X-Git-Tag: v11.0.0~781^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cad38dca0c90fb2ee4b589f336f8272122f50ad6;p=ceph.git librados: modify Pipe::connect() to return the error code Fixes: http://tracker.ceph.com/issues/15308 Signed-off-by: Vikhyat Umrao --- diff --git a/src/msg/simple/Pipe.cc b/src/msg/simple/Pipe.cc index f6eee3394154..74efa72015c0 100644 --- a/src/msg/simple/Pipe.cc +++ b/src/msg/simple/Pipe.cc @@ -883,7 +883,7 @@ int Pipe::connect() pipe_lock.Unlock(); char tag = -1; - int rc; + int rc = -1; struct msghdr msg; struct iovec msgvec[2]; int msglen; @@ -901,7 +901,8 @@ int Pipe::connect() // create socket? sd = ::socket(peer_addr.get_family(), SOCK_STREAM, 0); if (sd < 0) { - lderr(msgr->cct) << "connect couldn't created socket " << cpp_strerror(errno) << dendl; + rc = -errno; + lderr(msgr->cct) << "connect couldn't created socket " << cpp_strerror(rc) << dendl; goto fail; } @@ -913,15 +914,17 @@ int Pipe::connect() ldout(msgr->cct,10) << "connecting to " << peer_addr << dendl; rc = ::connect(sd, (sockaddr*)&peer_addr.addr, peer_addr.addr_size()); if (rc < 0) { + rc = -errno; ldout(msgr->cct,2) << "connect error " << peer_addr - << ", " << cpp_strerror(errno) << dendl; + << ", " << cpp_strerror(rc) << dendl; goto fail; } // verify banner // FIXME: this should be non-blocking, or in some other way verify the banner as we get it. - if (tcp_read((char*)&banner, strlen(CEPH_BANNER)) < 0) { - ldout(msgr->cct,2) << "connect couldn't read banner, " << cpp_strerror(errno) << dendl; + rc = tcp_read((char*)&banner, strlen(CEPH_BANNER)); + if (rc < 0) { + ldout(msgr->cct,2) << "connect couldn't read banner, " << cpp_strerror(rc) << dendl; goto fail; } if (memcmp(banner, CEPH_BANNER, strlen(CEPH_BANNER))) { @@ -935,8 +938,9 @@ int Pipe::connect() msg.msg_iov = msgvec; msg.msg_iovlen = 1; msglen = msgvec[0].iov_len; - if (do_sendmsg(&msg, msglen)) { - ldout(msgr->cct,2) << "connect couldn't write my banner, " << cpp_strerror(errno) << dendl; + rc = do_sendmsg(&msg, msglen); + if (rc < 0) { + ldout(msgr->cct,2) << "connect couldn't write my banner, " << cpp_strerror(rc) << dendl; goto fail; } @@ -950,8 +954,9 @@ int Pipe::connect() #endif addrbl.push_back(std::move(p)); } - if (tcp_read(addrbl.c_str(), addrbl.length()) < 0) { - ldout(msgr->cct,2) << "connect couldn't read peer addrs, " << cpp_strerror(errno) << dendl; + rc = tcp_read(addrbl.c_str(), addrbl.length()); + if (rc < 0) { + ldout(msgr->cct,2) << "connect couldn't read peer addrs, " << cpp_strerror(rc) << dendl; goto fail; } { @@ -987,8 +992,9 @@ int Pipe::connect() msg.msg_iov = msgvec; msg.msg_iovlen = 1; msglen = msgvec[0].iov_len; - if (do_sendmsg(&msg, msglen)) { - ldout(msgr->cct,2) << "connect couldn't write my addr, " << cpp_strerror(errno) << dendl; + rc = do_sendmsg(&msg, msglen); + if (rc < 0) { + ldout(msgr->cct,2) << "connect couldn't write my addr, " << cpp_strerror(rc) << dendl; goto fail; } ldout(msgr->cct,10) << "connect sent my addr " << msgr->my_inst.addr << dendl; @@ -1028,15 +1034,17 @@ int Pipe::connect() ldout(msgr->cct,10) << "connect sending gseq=" << gseq << " cseq=" << cseq << " proto=" << connect.protocol_version << dendl; - if (do_sendmsg(&msg, msglen)) { - ldout(msgr->cct,2) << "connect couldn't write gseq, cseq, " << cpp_strerror(errno) << dendl; + rc = do_sendmsg(&msg, msglen); + if (rc < 0) { + ldout(msgr->cct,2) << "connect couldn't write gseq, cseq, " << cpp_strerror(rc) << dendl; goto fail; } ldout(msgr->cct,20) << "connect wrote (self +) cseq, waiting for reply" << dendl; ceph_msg_connect_reply reply; - if (tcp_read((char*)&reply, sizeof(reply)) < 0) { - ldout(msgr->cct,2) << "connect read reply " << cpp_strerror(errno) << dendl; + rc = tcp_read((char*)&reply, sizeof(reply)); + if (rc < 0) { + ldout(msgr->cct,2) << "connect read reply " << cpp_strerror(rc) << dendl; goto fail; } @@ -1056,8 +1064,9 @@ int Pipe::connect() if (reply.authorizer_len) { ldout(msgr->cct,10) << "reply.authorizer_len=" << reply.authorizer_len << dendl; bufferptr bp = buffer::create(reply.authorizer_len); - if (tcp_read(bp.c_str(), reply.authorizer_len) < 0) { - ldout(msgr->cct,10) << "connect couldn't read connect authorizer_reply" << dendl; + rc = tcp_read(bp.c_str(), reply.authorizer_len); + if (rc < 0) { + ldout(msgr->cct,10) << "connect couldn't read connect authorizer_reply" << cpp_strerror(rc) << dendl; goto fail; } authorizer_reply.push_back(bp); @@ -1148,8 +1157,9 @@ int Pipe::connect() if (reply.tag == CEPH_MSGR_TAG_SEQ) { ldout(msgr->cct,10) << "got CEPH_MSGR_TAG_SEQ, reading acked_seq and writing in_seq" << dendl; uint64_t newly_acked_seq = 0; - if (tcp_read((char*)&newly_acked_seq, sizeof(newly_acked_seq)) < 0) { - ldout(msgr->cct,2) << "connect read error on newly_acked_seq" << dendl; + rc = tcp_read((char*)&newly_acked_seq, sizeof(newly_acked_seq)); + if (rc < 0) { + ldout(msgr->cct,2) << "connect read error on newly_acked_seq" << cpp_strerror(rc) << dendl; goto fail_locked; } ldout(msgr->cct,2) << " got newly_acked_seq " << newly_acked_seq @@ -1230,7 +1240,7 @@ int Pipe::connect() stop_locked: delete authorizer; - return -1; + return rc; } void Pipe::register_pipe() @@ -2210,16 +2220,16 @@ int Pipe::do_sendmsg(struct msghdr *msg, unsigned len, bool more) #endif if (r == 0) ldout(msgr->cct,10) << "do_sendmsg hmm do_sendmsg got r==0!" << dendl; - if (r < 0) { - ldout(msgr->cct,1) << "do_sendmsg error " << cpp_strerror(errno) << dendl; + if (r < 0) { + r = -errno; + ldout(msgr->cct,1) << "do_sendmsg error " << cpp_strerror(r) << dendl; restore_sigpipe(); - return -1; + return r; } if (state == STATE_CLOSED) { ldout(msgr->cct,10) << "do_sendmsg oh look, state == CLOSED, giving up" << dendl; - errno = EINTR; restore_sigpipe(); - return -1; // close enough + return -EINTR; // close enough } len -= r; @@ -2441,7 +2451,7 @@ int Pipe::write_message(const ceph_msg_header& header, const ceph_msg_footer& fo int Pipe::tcp_read(char *buf, unsigned len) { if (sd < 0) - return -1; + return -EINVAL; while (len > 0) { @@ -2470,7 +2480,7 @@ int Pipe::tcp_read(char *buf, unsigned len) int Pipe::tcp_read_wait() { if (sd < 0) - return -1; + return -EINVAL; struct pollfd pfd; short evmask; pfd.fd = sd; @@ -2483,7 +2493,7 @@ int Pipe::tcp_read_wait() return 0; if (poll(&pfd, 1, msgr->timeout) <= 0) - return -1; + return -errno; evmask = POLLERR | POLLHUP | POLLNVAL; #if defined(__linux__)