From a1c3afb60a248eac7eb472bd2dad4aed3b38c871 Mon Sep 17 00:00:00 2001 From: Anand Bhat Date: Thu, 14 Aug 2014 09:52:56 +0530 Subject: [PATCH] OSDMonitor: Do not allow OSD removal using setmaxosd Description: Currently setmaxosd command allows removal of OSDs by providing a number less than current max OSD number. This causes abrupt removal of OSDs causing data loss as well as kernel panic when kernel RBDs are involved. Fix is to avoid removal of OSDs if any of the OSDs in the range between current max OSD number and new max OSD number is part of the cluster. Fixes: #8865 Signed-off-by: Anand Bhat --- src/mon/OSDMonitor.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index ade6081f68d11..72dc1e645b418 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -4522,6 +4522,23 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m, goto reply; } + // Don't allow shrinking OSD number as this will cause data loss + // and may cause kernel crashes. + // Note: setmaxosd sets the maximum OSD number and not the number of OSDs + if (newmax < osdmap.get_max_osd()) { + // Check if the OSDs exist between current max and new value. + // If there are any OSDs exist, then don't allow shrinking number + // of OSDs. + for (int i = newmax; i <= osdmap.get_max_osd(); i++) { + if (osdmap.exists(i)) { + err = -EBUSY; + ss << "cannot shrink max_osd to " << newmax + << " because osd." << i << " (and possibly others) still in use"; + goto reply; + } + } + } + pending_inc.new_max_osd = newmax; ss << "set new max_osd = " << pending_inc.new_max_osd; getline(ss, rs); -- 2.39.5