]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
.ceph_hosts files
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Thu, 16 Aug 2007 17:39:56 +0000 (17:39 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Thu, 16 Aug 2007 17:39:56 +0000 (17:39 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1639 29311d96-e01e-0410-9327-a35deaab8ce9

branches/sage/mds/config.cc
branches/sage/mds/msg/SimpleMessenger.cc

index 7e7a93c8981dfec637b6a91a2c4c32f7184d958a..0c7e311b1f47bce4bd25a6806a30c399c8c68aaf 100644 (file)
@@ -412,10 +412,6 @@ bool parse_ip_port(const char *s, entity_addr_t& a)
       cerr << "should period at " << off << endl;
       return false;   // should have 3 periods
     }
-    if (count == 3 && *s != ':') {
-      cerr << "expected : at " << off << endl;
-      return false;  // then a colon
-    }
     s++; off++;
 
     if (count <= 3)
@@ -424,6 +420,7 @@ bool parse_ip_port(const char *s, entity_addr_t& a)
       a.port = val;
     
     count++;
+    if (count == 4 && *s != ':') break;
     if (count == 5) break;  
   }
   
index a38e3eaf7bd88faffbad5e25b6daf0d203047a80..1929eca62e93d6d17b90ec484ed8324127c6ef06 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <netdb.h>
 
+#include <iostream>
+#include <fstream>
 
 #undef dout
 #define dout(l)  if (l<=g_conf.debug_ms) cout << g_clock.now() << " -- " << rank.my_addr << " "
@@ -81,9 +83,39 @@ void noop_signal_handler(int s)
 int Rank::Accepter::start()
 {
   // bind to a socket
-  dout(10) << "accepter.start binding to listen " << endl;
+  dout(10) << "accepter.start" << endl;
   
-  // use whatever user specified..
+  char hostname[100];
+  gethostname(hostname, 100);
+  dout(1) << "accepter.start my hostname is " << hostname << endl;
+
+  // is there a .ceph_hosts file?
+  {
+    ifstream fh;
+    fh.open(".ceph_hosts");
+    if (fh.is_open()) {
+      while (1) {
+       string line;
+       getline(fh, line);
+       if (fh.eof()) break;
+       if (line[0] == '#' || line[0] == ';') continue;
+       int ospace = line.find(" ");
+       if (!ospace) continue;
+       string host = line.substr(0, ospace);
+       string addr = line.substr(ospace+1);
+       dout(15) << ".ceph_hosts: host '" << host << "' -> '" << addr << "'" << endl;
+       if (host == hostname) {
+         parse_ip_port(addr.c_str(), g_my_addr);
+         g_my_addr.nonce = getpid(); // FIXME: pid might not be best choice here.
+         dout(0) << ".ceph_hosts: my addr is " << g_my_addr << endl;
+         break;
+       }
+      }
+      fh.close();
+    }
+  }
+
+  // use whatever user specified (if anything)
   g_my_addr.make_addr(rank.listen_addr);
 
   /* socket creation */
@@ -106,22 +138,16 @@ int Rank::Accepter::start()
   rc = ::listen(listen_sd, 1000);
   assert(rc >= 0);
   
-  // my address is...  HELP HELP HELP!
-  char host[100];
-  bzero(host, 100);
-  gethostname(host, 100);
-  //dout(10) << "accepter.start my hostname is " << host << endl;
-
-  struct hostent *myhostname = gethostbyname( host ); 
-
   // figure out my_addr
-  if (g_my_addr.port > 0) {
+  if (g_my_addr != entity_addr_t()) {
     // user specified it, easy peasy.
     rank.my_addr = g_my_addr;
   } else {
-    // look up my hostname.  blech!  this sucks.
+    // my address is...  HELP HELP HELP!    
+    struct hostent *myhostname = gethostbyname(hostname); 
+    
     rank.listen_addr.sin_family = myhostname->h_addrtype;
-    memcpy((char *) &rank.listen_addr.sin_addr.s_addr, 
+    memcpy((char*)&rank.listen_addr.sin_addr.s_addr, 
           myhostname->h_addr_list[0], 
           myhostname->h_length);