]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
OSDMonitor: Do not allow OSD removal using setmaxosd
authorAnand Bhat <anand.bhat@sandisk.com>
Thu, 14 Aug 2014 04:22:56 +0000 (09:52 +0530)
committerSage Weil <sage@redhat.com>
Thu, 14 Aug 2014 19:58:50 +0000 (12:58 -0700)
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 <anand.bhat@sandisk.com>
src/mon/OSDMonitor.cc

index ade6081f68d110b82a85666ec56ca5791ae45f7b..72dc1e645b418e848e96122b0a651d439af09d71 100644 (file)
@@ -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);