auto-detect ip for all non-monitor components from initial exchange with monitor

This commit is contained in:
Sage Weil 2008-05-11 16:54:53 -07:00
parent 2e030e2424
commit bf886e1766
8 changed files with 36 additions and 60 deletions

View File

@ -9,7 +9,6 @@ big items
- cas
- meta vs data crush rules
- ip-less startup for userspace items
- use libuuid
userspace client
@ -26,7 +25,6 @@ userspace client
kernel client
- direct mds requests intelligently
- readdir on large directories
- flush caps on sync, fsync, etc.
- do we need to block?
- timeout mds session close on umount

View File

@ -218,6 +218,12 @@ bool MDSMonitor::preprocess_beacon(MMDSBeacon *m)
goto out;
}
// first time we've seen it?
if (m->get_mds_inst().addr.ipaddr.sin_addr.s_addr == htonl(INADDR_ANY)) {
m->get_mds_inst() = m->get_source_inst();
m->clear_payload();
}
dout(12) << "preprocess_beacon " << *m
<< " from " << m->get_mds_inst()
<< dendl;

View File

@ -199,6 +199,12 @@ void Monitor::handle_command(MMonCommand *m)
return;
}
// first time we've seen it?
if (m->inst.addr.ipaddr.sin_addr.s_addr == htonl(INADDR_ANY)) {
m->inst = m->get_source_inst();
m->clear_payload();
}
dout(0) << "handle_command " << *m << dendl;
string rs;
if (!m->cmd.empty()) {

View File

@ -467,6 +467,12 @@ bool OSDMonitor::preprocess_boot(MOSDBoot *m)
return true;
}
// first time we've seen it?
if (m->inst.addr.ipaddr.sin_addr.s_addr == htonl(INADDR_ANY)) {
m->inst = m->get_source_inst();
m->clear_payload();
}
assert(m->inst.name.is_osd());
int from = m->inst.name.num();

View File

@ -92,36 +92,6 @@ int Rank::Accepter::bind(int64_t force_nonce)
// bind to a socket
dout(10) << "accepter.bind" << dendl;
char hostname[100];
memset(hostname, 0, 100);
gethostname(hostname, 100);
dout(2) << "accepter.bind my hostname is " << hostname << dendl;
// is there a .ceph_hosts file?
if (g_conf.ms_hosts) {
ifstream fh;
fh.open(g_conf.ms_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) << g_conf.ms_hosts << ": host '" << host << "' -> '" << addr << "'" << dendl;
if (host == hostname) {
parse_ip_port(addr.c_str(), g_my_addr);
dout(1) << g_conf.ms_hosts << ": my addr is " << g_my_addr << dendl;
break;
}
}
fh.close();
}
}
// use whatever user specified (if anything)
sockaddr_in listen_addr = g_my_addr.ipaddr;
@ -158,28 +128,9 @@ int Rank::Accepter::bind(int64_t force_nonce)
return -errno;
}
// figure out my_addr
if (g_my_addr != entity_addr_t()) {
// user specified it, easy peasy.
rank.rank_addr = g_my_addr;
} else {
// my IP is... HELP!
struct hostent *myhostname = gethostbyname(hostname);
if (!myhostname) {
derr(0) << "accepter.bind unable to resolve hostname '" << hostname
<< "', please specify your ip with --bind x.x.x.x"
<< dendl;
return -1;
}
// look up my hostname.
listen_addr.sin_family = myhostname->h_addrtype;
memcpy((char*)&listen_addr.sin_addr.s_addr,
myhostname->h_addr_list[0],
myhostname->h_length);
rank.rank_addr.ipaddr = listen_addr;
rank.rank_addr.set_port(0);
}
rank.rank_addr = g_my_addr;
if (rank.rank_addr != entity_addr_t())
rank.need_addr = false;
if (rank.rank_addr.get_port() == 0) {
entity_addr_t tmp;
tmp.ipaddr = listen_addr;
@ -1405,6 +1356,14 @@ void Rank::Pipe::reader()
if (erank < rank.max_local && rank.local[erank]) {
// find entity
entity = rank.local[erank];
// first message?
if (rank.need_addr) {
entity->_myinst.addr = rank.rank_addr = m->get_dest_inst().addr;
dout(0) << "reader my rank addr is " << rank.rank_addr << dendl;
rank.need_addr = false;
}
} else {
derr(0) << "reader got message " << *m << " for " << m->get_dest() << ", which isn't local" << dendl;
}

View File

@ -320,6 +320,7 @@ private:
bool started;
// where i listen
bool need_addr;
entity_addr_t rank_addr;
// local
@ -344,7 +345,7 @@ private:
void reaper();
public:
Rank() : started(false),
Rank() : started(false), need_addr(true),
max_local(0), num_local(0) { }
~Rank() { }

View File

@ -27,7 +27,7 @@ $CEPH_BIN/monmaptool --create --clobber --add $IP:12345 --print .ceph_monmap
$CEPH_BIN/mkmonfs --clobber mondata/mon0 --mon 0 --monmap .ceph_monmap
# shared args
ARGS="-d --bind $IP"
ARGS="-d"
# start monitor
$CEPH_BIN/cmon $ARGS mondata/mon0 --debug_mon 10 --debug_ms 1
@ -44,7 +44,7 @@ do
done
# mds
$CEPH_BIN/cmds $ARGS # --debug_ms 1 #--debug_mds 20 --debug_ms 20
$CEPH_BIN/cmds $ARGS # --debug_ms 1 #--debug_mds 20 --debug_ms 20
echo "started. stop.sh to stop. see out/* (e.g. 'tail -f out/????') for debug output."

View File

@ -8,7 +8,7 @@ rm out/*
# figure machine's ip
HOSTNAME=`hostname`
IP=`host $HOSTNAME | cut -d ' ' -f 4`
IP=`host $HOSTNAME | grep $HOSTNAME | cut -d ' ' -f 4`
[ "$CEPH_BIN" == "" ] && CEPH_BIN=.
echo hostname $HOSTNAME
@ -27,7 +27,7 @@ $CEPH_BIN/monmaptool --create --clobber --add $IP:12345 --print .ceph_monmap
$CEPH_BIN/mkmonfs --clobber mondata/mon0 --mon 0 --monmap .ceph_monmap
# shared args
ARGS="-d --bind $IP"
ARGS="-d"
# start monitor
$CEPH_BIN/cmon $ARGS mondata/mon0 --debug_mon 10 --debug_ms 1
@ -43,7 +43,7 @@ do
done
# mds
$CEPH_BIN/cmds $ARGS --debug_ms 1 --debug_mds 20 #--debug_ms 20
$CEPH_BIN/cmds $ARGS --debug_ms 1 --debug_mds 20 --mds_thrash_fragments 1 #--debug_ms 20
echo "started. stop.sh to stop. see out/* (e.g. 'tail -f out/????') for debug output."