]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: clean up cmd 'osd tree-from'
authorGu Zhongyan <guzhongyan@360.cn>
Mon, 12 Mar 2018 03:41:32 +0000 (11:41 +0800)
committerGu Zhongyan <guzhongyan@360.cn>
Mon, 12 Mar 2018 03:41:32 +0000 (11:41 +0800)
Handle 'bucket not exist' and 'not a bucket' case

Signed-off-by: Gu Zhongyan <guzhongyan@360.cn>
src/mon/OSDMonitor.cc

index a67f6064049e8565e2717e706e209efc727154c4..6a39698498e90c3a5803e762381e13df39f3a3f3 100644 (file)
@@ -3709,8 +3709,20 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
       rdata.append(ds);
     } else if (prefix == "osd tree" || prefix == "osd tree-from") {
       string bucket;
-      if (prefix == "osd tree-from")
-       cmd_getval(cct, cmdmap, "bucket", bucket);
+      if (prefix == "osd tree-from") {
+        cmd_getval(cct, cmdmap, "bucket", bucket);
+        if (!osdmap.crush->name_exists(bucket)) {
+          ss << "bucket '" << bucket << "' does not exist";
+          r = -ENOENT;
+          goto reply;
+        }
+        int id = osdmap.crush->get_item_id(bucket);
+        if (id >= 0) {
+          ss << "\"" << bucket << "\" is not a bucket";
+          r = -EINVAL;
+          goto reply;
+        }
+      }
 
       vector<string> states;
       cmd_getval(cct, cmdmap, "states", states);