]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osdmap: apply mon_max_osd when generating osdmap from conf
authorSage Weil <sage@inktank.com>
Tue, 14 Aug 2012 21:26:23 +0000 (14:26 -0700)
committerSage Weil <sage@inktank.com>
Tue, 14 Aug 2012 23:06:55 +0000 (16:06 -0700)
This prevents users from having an [osd.1234567] section and blowing up
their memory usage.

Signed-off-by: Sage Weil <sage@inktank.com>
src/osd/OSDMap.cc
src/osd/OSDMap.h
src/osdmaptool.cc

index b24257f2d6c0616c0c7c68977e15660300036027..960f02d9b8a210cecdad38447cc4388caf42a94c 100644 (file)
@@ -1520,8 +1520,8 @@ void OSDMap::build_simple_crush_map(CephContext *cct, CrushWrapper& crush,
   crush.finalize();
 }
 
-void OSDMap::build_simple_from_conf(CephContext *cct, epoch_t e, uuid_d &fsid,
-                                   int pg_bits, int pgp_bits)
+int OSDMap::build_simple_from_conf(CephContext *cct, epoch_t e, uuid_d &fsid,
+                                  int pg_bits, int pgp_bits)
 {
   ldout(cct, 10) << "build_simple_from_conf with "
                 << pg_bits << " pg bits per osd, "
@@ -1547,6 +1547,10 @@ void OSDMap::build_simple_from_conf(CephContext *cct, epoch_t e, uuid_d &fsid,
     if (*end != '\0')
       continue;
 
+    if (o > cct->_conf->mon_max_osd) {
+      lderr(cct) << "[osd." << o << "] in config has id > mon_max_osd " << cct->_conf->mon_max_osd << dendl;
+      return -ERANGE;
+    }
     numosd++;
     if (o > maxosd)
       maxosd = o;
@@ -1585,6 +1589,8 @@ void OSDMap::build_simple_from_conf(CephContext *cct, epoch_t e, uuid_d &fsid,
     set_state(i, 0);
     set_weight(i, CEPH_OSD_OUT);
   }
+
+  return 0;
 }
 
 void OSDMap::build_simple_crush_map_from_conf(CephContext *cct, CrushWrapper& crush,
index e34802a8209dc54f557b04a6faee72fc1dc4c4d3..edb94261c4899db92253cd2a7b5b15a0a4e80cf4 100644 (file)
@@ -512,8 +512,8 @@ public:
    */
   void build_simple(CephContext *cct, epoch_t e, uuid_d &fsid,
                    int num_osd, int pg_bits, int pgp_bits);
-  void build_simple_from_conf(CephContext *cct, epoch_t e, uuid_d &fsid,
-                             int pg_bits, int pgp_bits);
+  int build_simple_from_conf(CephContext *cct, epoch_t e, uuid_d &fsid,
+                            int pg_bits, int pgp_bits);
   static void build_simple_crush_map(CephContext *cct, CrushWrapper& crush,
                                     map<int, const char*>& poolsets, int num_osd);
   static void build_simple_crush_map_from_conf(CephContext *cct, CrushWrapper& crush,
index 4bfb0ad09c671762746d7d2a31b34a0df4887e63..e5fc60dc9c179799bdbb57e1601cf44a930ef8ce 100644 (file)
@@ -189,7 +189,9 @@ int main(int argc, const char **argv)
   if (create_from_conf) {
     uuid_d fsid;
     memset(&fsid, 0, sizeof(uuid_d));
-    osdmap.build_simple_from_conf(g_ceph_context, 0, fsid, pg_bits, pgp_bits);
+    int r = osdmap.build_simple_from_conf(g_ceph_context, 0, fsid, pg_bits, pgp_bits);
+    if (r < 0)
+      return -1;
     modified = true;
   }