From: Anand Bhat Date: Thu, 14 Aug 2014 04:22:56 +0000 (+0530) Subject: OSDMonitor: Do not allow OSD removal using setmaxosd X-Git-Tag: v0.85~42 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a1c3afb60a248eac7eb472bd2dad4aed3b38c871;p=ceph.git 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 --- diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index ade6081f68d1..72dc1e645b41 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);