From b7075f659fdd636d23f5d319c15ead010ce2d404 Mon Sep 17 00:00:00 2001 From: Gu Zhongyan Date: Mon, 12 Mar 2018 11:41:32 +0800 Subject: [PATCH 1/2] mon/OSDMonitor: clean up cmd 'osd tree-from' Handle 'bucket not exist' and 'not a bucket' case Signed-off-by: Gu Zhongyan --- src/mon/OSDMonitor.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index a67f6064049e8..6a39698498e90 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -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 states; cmd_getval(cct, cmdmap, "states", states); From 241af6c72ed1f78bb2e98db816a8cfb772dc20f8 Mon Sep 17 00:00:00 2001 From: Gu Zhongyan Date: Mon, 12 Mar 2018 17:08:34 +0800 Subject: [PATCH 2/2] qa/workunits/mon/crush_ops.sh: test osd tree-from Signed-off-by: Gu Zhongyan --- qa/workunits/mon/crush_ops.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qa/workunits/mon/crush_ops.sh b/qa/workunits/mon/crush_ops.sh index 40c10801df5c6..6c13b69908125 100755 --- a/qa/workunits/mon/crush_ops.sh +++ b/qa/workunits/mon/crush_ops.sh @@ -90,6 +90,9 @@ ceph osd tree | grep -c host1 | grep -q 1 # now an orphan ceph osd crush rm osd.$o1 host1 ceph osd crush rm host1 ceph osd tree | grep -c host1 | grep -q 0 +expect_false ceph osd tree-from host1 +ceph osd tree-from host2 +expect_false ceph osd tree-from osd.$o2 expect_false ceph osd crush rm bar # not empty ceph osd crush unlink host2