]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async: return right away in NetHandler::set_priority() if not supported 14795/head
authorKefu Chai <kchai@redhat.com>
Wed, 26 Apr 2017 02:47:29 +0000 (10:47 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 26 Apr 2017 04:16:57 +0000 (12:16 +0800)
* SO_PRIORITY is linux specific, so no need to check __linux__
* early return if priority is less than 0 (maybe we should also return if
  it's higher than 6?), the less indent.
* store errno if fails to set SO_PRIORITY before printing log messages.
* guard the whole function with '#ifdef SO_PRIORITY' so on platforms
  where this option is not supported, this function will be a no-op.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/msg/async/net_handler.cc
src/msg/simple/Pipe.cc

index 059f9220948aa46b99d98108fd511b81ef0af7a2..d43e6a45a01bfecaa72b207e60438efe040953ab 100644 (file)
@@ -125,44 +125,45 @@ int NetHandler::set_socket_options(int sd, bool nodelay, int size)
 
 void NetHandler::set_priority(int sd, int prio, int domain)
 {
-  if (prio >= 0) {
-    int r = -1;
+#ifdef SO_PRIORITY
+  if (prio < 0) {
+    return;
+  }
 #ifdef IPTOS_CLASS_CS6
-    int iptos = IPTOS_CLASS_CS6;
+  int iptos = IPTOS_CLASS_CS6;
+  int r = -1;
+  if (domain == AF_INET) {
     r = ::setsockopt(sd, IPPROTO_IP, IP_TOS, &iptos, sizeof(iptos));
-    if (domain == AF_INET) {
-      r = ::setsockopt(sd, IPPROTO_IP, IP_TOS, &iptos, sizeof(iptos));
-      r = -errno;
-      if (r < 0) {
-        ldout(cct,0) << "couldn't set IP_TOS to " << iptos
-                           << ": " << cpp_strerror(r) << dendl;
-      }
-    } else if (domain == AF_INET6) {
-      r = ::setsockopt(sd, IPPROTO_IPV6, IPV6_TCLASS, &iptos, sizeof(iptos));
-      if (r)
-       r = -errno;
-      if (r < 0) {
-        ldout(cct,0) << "couldn't set IPV6_TCLASS to " << iptos
-                           << ": " << cpp_strerror(r) << dendl;
-      }
-    } else {
-      ldout(cct,0) << "couldn't set ToS of unknown family to " << iptos
-                         << dendl;
+    if (r < 0) {
+      r = errno;
+      ldout(cct,0) << "couldn't set IP_TOS to " << iptos
+                  << ": " << cpp_strerror(r) << dendl;
     }
-#endif
-#if defined(SO_PRIORITY) 
-    // setsockopt(IPTOS_CLASS_CS6) sets the priority of the socket as 0.
-    // See http://goo.gl/QWhvsD and http://goo.gl/laTbjT
-    // We need to call setsockopt(SO_PRIORITY) after it.
-#if defined(__linux__)
-    r = ::setsockopt(sd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio));
-#endif
+  } else if (domain == AF_INET6) {
+    r = ::setsockopt(sd, IPPROTO_IPV6, IPV6_TCLASS, &iptos, sizeof(iptos));
     if (r < 0) {
-      ldout(cct, 0) << __func__ << " couldn't set SO_PRIORITY to " << prio
-                    << ": " << cpp_strerror(errno) << dendl;
+      r = errno;
+      ldout(cct,0) << "couldn't set IPV6_TCLASS to " << iptos
+                  << ": " << cpp_strerror(r) << dendl;
     }
-#endif
+  } else {
+    lderr(cct) << "couldn't set ToS of unknown family (" << domain << ")"
+              << " to " << iptos << dendl;
+    return;
+  }
+#endif // IPTOS_CLASS_CS6
+  // setsockopt(IPTOS_CLASS_CS6) sets the priority of the socket as 0.
+  // See http://goo.gl/QWhvsD and http://goo.gl/laTbjT
+  // We need to call setsockopt(SO_PRIORITY) after it.
+  r = ::setsockopt(sd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio));
+  if (r < 0) {
+    r = errno;
+    ldout(cct, 0) << __func__ << " couldn't set SO_PRIORITY to " << prio
+                 << ": " << cpp_strerror(r) << dendl;
   }
+#else
+  return;
+#endif // SO_PRIORITY
 }
 
 int NetHandler::generic_connect(const entity_addr_t& addr, const entity_addr_t &bind_addr, bool nonblock)
index fa5df0a184fbca7c3dbc491cc6c92f01cf9f769a..b1ec5e533ad761ca4d5af5fda2bb054460ed41d0 100644 (file)
@@ -917,6 +917,7 @@ void Pipe::set_socket_options()
   }
 #endif
 
+#ifdef SO_PRIORITY
   int prio = msgr->get_socket_priority();
   if (prio >= 0) {
     int r = -1;
@@ -938,17 +939,15 @@ void Pipe::set_socket_options()
                            << ": " << cpp_strerror(r) << dendl;
       }
     } else {
-      ldout(msgr->cct,0) << "couldn't set ToS of unknown family to " << iptos
-                         << dendl;
+      lderr(msgr->cct) << "couldn't set ToS of unknown family ("
+                      << peer_addr.get_family() << ")"
+                      << " to " << iptos << dendl;
     }
 #endif
-#if defined(SO_PRIORITY) 
     // setsockopt(IPTOS_CLASS_CS6) sets the priority of the socket as 0.
     // See http://goo.gl/QWhvsD and http://goo.gl/laTbjT
     // We need to call setsockopt(SO_PRIORITY) after it.
-#if defined(__linux__)
     r = ::setsockopt(sd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio));
-#endif
     if (r < 0) {
       r = -errno;
       ldout(msgr->cct,0) << "couldn't set SO_PRIORITY to " << prio