From 30ddc85e542eb2a8dd876416473a39471ac82156 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 12 Nov 2011 13:41:59 -0800 Subject: [PATCH] mon: make initial osdmap optional If an initial osdmap is not provided, we generate an empty one. The user add osds on their own after that. Signed-off-by: Sage Weil --- src/ceph_mon.cc | 17 +++++++++-------- src/mon/Monitor.cc | 3 ++- src/mon/OSDMonitor.cc | 19 ++++++++++++++----- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index ff65c55c6be39..88932fb0cc7b7 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -99,8 +99,6 @@ int main(int argc, const char **argv) // -- mkfs -- if (mkfs) { common_init_finish(g_ceph_context); - if (g_conf->monmap.empty() || osdmapfn.empty()) - usage(); bufferlist monmapbl, osdmapbl; std::string error; @@ -124,6 +122,7 @@ int main(int argc, const char **argv) int err = MonClient::build_initial_monmap(g_ceph_context, monmap); if (err < 0) { cerr << argv[0] << ": error generating initial monmap: " << cpp_strerror(err) << std::endl; + usage(); exit(1); } } @@ -134,16 +133,18 @@ int main(int argc, const char **argv) } if (monmap.fsid.is_zero()) { - cerr << argv[0] << ": generated monmap has no fsid; use --fsid" << std::endl; + cerr << argv[0] << ": generated monmap has no fsid; use '--fsid '" << std::endl; exit(10); } // osdmap - err = osdmapbl.read_file(osdmapfn.c_str(), &error); - if (err < 0) { - cerr << argv[0] << ": error reading " << osdmapfn << ": " - << error << std::endl; - exit(1); + if (osdmapfn.length()) { + err = osdmapbl.read_file(osdmapfn.c_str(), &error); + if (err < 0) { + cerr << argv[0] << ": error reading " << osdmapfn << ": " + << error << std::endl; + exit(1); + } } // go diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 3ebf762895b68..7412e6fcc1c2e 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -1553,7 +1553,8 @@ int Monitor::mkfs(bufferlist& osdmapbl) monmap->set_epoch(0); // must be 0 to avoid confusing first MonmapMonitor::update_from_paxos() store->put_bl_ss(monmapbl, "mkfs", "monmap"); - store->put_bl_ss(osdmapbl, "mkfs", "osdmap"); + if (osdmapbl.length()) + store->put_bl_ss(osdmapbl, "mkfs", "osdmap"); KeyRing keyring; r = keyring.load(g_ceph_context, g_conf->keyring); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 4dba0fbab3ee7..9380ce025fbbf 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -67,13 +67,18 @@ void OSDMonitor::create_initial() { dout(10) << "create_initial for " << mon->monmap->fsid << dendl; + OSDMap newmap; + bufferlist bl; mon->store->get_bl_ss(bl, "mkfs", "osdmap"); - - OSDMap newmap; - newmap.decode(bl); + if (bl.length()) { + newmap.decode(bl); + newmap.set_fsid(mon->monmap->fsid); + } else { + newmap.build_simple(g_ceph_context, 0, mon->monmap->fsid, 0, 0, + g_conf->osd_pg_bits, g_conf->osd_pgp_bits, g_conf->osd_lpg_bits); + } newmap.set_epoch(1); - newmap.set_fsid(mon->monmap->fsid); newmap.created = newmap.modified = ceph_clock_now(g_ceph_context); // encode into pending incremental @@ -1745,7 +1750,7 @@ bool OSDMonitor::prepare_command(MMonCommand *m) int i; if (m->cmd.size() > 2) { i = atoi(m->cmd[2].c_str()); - if (i < 0 || i >= osdmap.get_max_osd()) { + if (i < 0) { ss << i << " is not a valid osd id"; err = -ERANGE; goto out; @@ -1755,6 +1760,10 @@ bool OSDMonitor::prepare_command(MMonCommand *m) err = -EEXIST; goto out; } + if (i >= osdmap.get_max_osd()) { + if (i >= pending_inc.new_max_osd) + pending_inc.new_max_osd = i + 1; + } if (pending_inc.new_up_client.count(i) || (pending_inc.new_state.count(i) && (pending_inc.new_state[i] & CEPH_OSD_EXISTS))) { -- 2.39.5