From: Sage Weil Date: Mon, 28 Nov 2011 00:10:46 +0000 (-0800) Subject: mon: search for local ip during mkfs X-Git-Tag: v0.39~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ce6572273943ffdca4b7dc5344152d6c35106a2d;p=ceph-ci.git mon: search for local ip during mkfs If an address isn't explicitly specified during mkfs, look for an unnamed monitor in the (generated) monmap and see if any of those addresses is configured on the local machine. If so, assume it's us, and name ourselves in the seed monmap. Signed-off-by: Sage Weil --- diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index 5c46a367f05..f0cca8ccf56 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -129,7 +129,7 @@ int main(int argc, const char **argv) usage(); exit(1); } - + // am i part of the initial quorum? if (monmap.contains(g_conf->name.get_id())) { // hmm, make sure the ip listed exists on the current host? @@ -147,9 +147,23 @@ int main(int argc, const char **argv) } } else { // is a local address listed without a name? if so, name myself. - - // ******* + list ls; + monmap.list_addrs(ls); + entity_addr_t local; + if (have_local_addr(g_ceph_context, ls, &local)) { + string name; + monmap.get_addr_name(local, name); + + if (name.find("noname-") == 0) { + cout << argv[0] << ": mon." << name << " " << local + << " is local, renaming to mon." << g_conf->name.get_id() << std::endl; + monmap.rename(name, g_conf->name.get_id()); + } else { + cout << argv[0] << ": mon." << name << " " << local + << " is local, but not 'noname-' + something; not assuming it's me" << std::endl; + } + } } } diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index c46c0bda2c8..651a1466ae8 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -83,6 +83,13 @@ class MonMap { epoch_t get_epoch() { return epoch; } void set_epoch(epoch_t e) { epoch = e; } + void list_addrs(list& ls) const { + for (map::const_iterator p = mon_addr.begin(); + p != mon_addr.end(); + ++p) + ls.push_back(p->second); + } + void add(const string &name, const entity_addr_t &addr) { assert(mon_addr.count(name) == 0); mon_addr[name] = addr;