]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: create osd id if it does not exist 8357/head
authorSage Weil <sage@redhat.com>
Thu, 28 Apr 2016 14:09:29 +0000 (10:09 -0400)
committerSage Weil <sage@redhat.com>
Mon, 9 May 2016 12:55:00 +0000 (08:55 -0400)
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 <sage@redhat.com>
src/osd/OSD.cc

index 0dde567091ecade737bf2776b0a53e0012181de5..b544de3edc7edae25425786c13a830c05fceeb0e 100644 (file)
@@ -2796,18 +2796,39 @@ int OSD::update_crush_location()
   }
   cmd += "]}";
 
-  dout(10) << __func__ << " cmd: " << cmd << dendl;
-  vector<string> 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<string> 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<string> 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;