]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: simplify 'osd crush reweight ...' flow 1872/head
authorSage Weil <sage@inktank.com>
Sun, 25 May 2014 21:04:06 +0000 (14:04 -0700)
committerSage Weil <sage@inktank.com>
Tue, 27 May 2014 22:42:08 +0000 (15:42 -0700)
Use the goto labels; drop the do/while.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/OSDMonitor.cc

index 54d9780f222e845f1e3f1b5dd3bd911324a1c21b..2f44c8859e67e76e839fc097d95052d4e2355122 100644 (file)
@@ -3939,45 +3939,43 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
     } while (false);
 
   } else if (prefix == "osd crush reweight") {
-    do {
-      // osd crush reweight <name> <weight>
-      CrushWrapper newcrush;
-      _get_pending_crush(newcrush);
+    // osd crush reweight <name> <weight>
+    CrushWrapper newcrush;
+    _get_pending_crush(newcrush);
 
-      string name;
-      cmd_getval(g_ceph_context, cmdmap, "name", name);
-      if (!newcrush.name_exists(name)) {
-       err = -ENOENT;
-       ss << "device '" << name << "' does not appear in the crush map";
-       break;
-      }
+    string name;
+    cmd_getval(g_ceph_context, cmdmap, "name", name);
+    if (!newcrush.name_exists(name)) {
+      err = -ENOENT;
+      ss << "device '" << name << "' does not appear in the crush map";
+      goto reply;
+    }
 
-      int id = newcrush.get_item_id(name);
-      if (id < 0) {
-       ss << "device '" << name << "' is not a leaf in the crush map";
-       break;
-      }
-      double w;
-      if (!cmd_getval(g_ceph_context, cmdmap, "weight", w)) {
-        ss << "unable to parse weight value '"
-           << cmd_vartype_stringify(cmdmap["weight"]) << "'";
-        err = -EINVAL;
-        break;
-      }
+    int id = newcrush.get_item_id(name);
+    if (id < 0) {
+      ss << "device '" << name << "' is not a leaf in the crush map";
+      err = -EINVAL;
+      goto reply;
+    }
+    double w;
+    if (!cmd_getval(g_ceph_context, cmdmap, "weight", w)) {
+      ss << "unable to parse weight value '"
+        << cmd_vartype_stringify(cmdmap["weight"]) << "'";
+      err = -EINVAL;
+      goto reply;
+    }
 
-      err = newcrush.adjust_item_weightf(g_ceph_context, id, w);
-      if (err >= 0) {
-       pending_inc.crush.clear();
-       newcrush.encode(pending_inc.crush);
-       ss << "reweighted item id " << id << " name '" << name << "' to " << w
-          << " in crush map";
-       getline(ss, rs);
-       wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs,
+    err = newcrush.adjust_item_weightf(g_ceph_context, id, w);
+    if (err < 0)
+      goto reply;
+    pending_inc.crush.clear();
+    newcrush.encode(pending_inc.crush);
+    ss << "reweighted item id " << id << " name '" << name << "' to " << w
+       << " in crush map";
+    getline(ss, rs);
+    wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs,
                                                  get_last_committed() + 1));
-       return true;
-      }
-    } while (false);
-
+    return true;
   } else if (prefix == "osd crush reweight-subtree") {
     // osd crush reweight <name> <weight>
     CrushWrapper newcrush;