From: Sage Weil Date: Thu, 28 Apr 2016 14:09:29 +0000 (-0400) Subject: osd: create osd id if it does not exist X-Git-Tag: v11.0.0~638^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d2cab3a898a0635c14f0ae56aa3bb3d2e1d0f486;p=ceph.git 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 --- 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;