From d2cab3a898a0635c14f0ae56aa3bb3d2e1d0f486 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 28 Apr 2016 10:09:29 -0400 Subject: [PATCH] osd: create osd id if it does not exist Most tools create the osd id before trying to start ceph-osd. Notably, teuthology does not. We could fix that, but we would be changing behavior, as the osd boot will happily create the osd id on the fly for us. Other provisioning tools might rely on that behavior. Instead, just allocate the id sooner in the process (if necessary). Signed-off-by: Sage Weil --- src/osd/OSD.cc | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 0dde567091ec..b544de3edc7e 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2796,18 +2796,39 @@ int OSD::update_crush_location() } cmd += "]}"; - dout(10) << __func__ << " cmd: " << cmd << dendl; - vector vcmd{cmd}; - bufferlist inbl; - - C_SaferCond w; - string outs; - int r = monc->start_mon_command(vcmd, inbl, NULL, &outs, &w); - if (r == 0) - r = w.wait(); - if (r < 0) { - derr << __func__ << " fail: '" << outs << "': " << cpp_strerror(r) << dendl; - return r; + bool created = false; + while (true) { + dout(10) << __func__ << " cmd: " << cmd << dendl; + vector vcmd{cmd}; + bufferlist inbl; + C_SaferCond w; + string outs; + int r = monc->start_mon_command(vcmd, inbl, NULL, &outs, &w); + if (r == 0) + r = w.wait(); + if (r < 0) { + if (r == -ENOENT && !created) { + string newcmd = "{\"prefix\": \"osd create\", \"id\": " + stringify(whoami) + + ", \"uuid\": \"" + stringify(superblock.osd_fsid) + "\"}"; + vector vnewcmd{newcmd}; + bufferlist inbl; + C_SaferCond w; + string outs; + int r = monc->start_mon_command(vnewcmd, inbl, NULL, &outs, &w); + if (r == 0) + r = w.wait(); + if (r < 0) { + derr << __func__ << " fail: osd does not exist and created failed: " + << cpp_strerror(r) << dendl; + return r; + } + created = true; + continue; + } + derr << __func__ << " fail: '" << outs << "': " << cpp_strerror(r) << dendl; + return r; + } + break; } return 0; -- 2.47.3