]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osdmap: maintain a pool-creating build_simple() for use in unit tests
authorGreg Farnum <gfarnum@redhat.com>
Wed, 14 Jun 2017 20:05:19 +0000 (13:05 -0700)
committerSage Weil <sage@redhat.com>
Wed, 28 Jun 2017 14:52:49 +0000 (10:52 -0400)
Change the standard build_simple() so it no longer takes pg[p]_num -- these
params were unused. Add a new build_simple_with_pool() that can be called
when we want the rbd pool to be created by default. These are implemented
via a simple switched function (marked private).

Update the existing callers so they choose the right one for their needs.

Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/mon/OSDMonitor.cc
src/osd/OSDMap.cc
src/osd/OSDMap.h
src/test/osd/TestOSDMap.cc
src/test/osd/TestPGLog.cc
src/tools/osdmaptool.cc

index f1a1c7285558550b6d3182fb9f3f72406e054b06..85e0c32c88cf3be8095c33507890a1fa773f68c7 100644 (file)
@@ -213,8 +213,7 @@ void OSDMonitor::create_initial()
     newmap.decode(bl);
     newmap.set_fsid(mon->monmap->fsid);
   } else {
-    newmap.build_simple(g_ceph_context, 0, mon->monmap->fsid, 0,
-                       g_conf->osd_pg_bits, g_conf->osd_pgp_bits);
+    newmap.build_simple(g_ceph_context, 0, mon->monmap->fsid, 0);
   }
   newmap.set_epoch(1);
   newmap.created = newmap.modified = ceph_clock_now();
index eaf884673978d465316695e7eb326437c488c2ab..d178459f0a8e7fadc9efbacfce149dff729751e4 100644 (file)
@@ -2893,7 +2893,7 @@ void OSDMap::generate_test_instances(list<OSDMap*>& o)
   CephContext *cct = new CephContext(CODE_ENVIRONMENT_UTILITY);
   o.push_back(new OSDMap);
   uuid_d fsid;
-  o.back()->build_simple(cct, 1, fsid, 16, 7, 8);
+  o.back()->build_simple(cct, 1, fsid, 16);
   o.back()->created = o.back()->modified = utime_t(1, 2);  // fix timestamp
   o.back()->blacklist[entity_addr_t()] = utime_t(5, 6);
   cct->put();
@@ -3227,8 +3227,9 @@ bool OSDMap::crush_ruleset_in_use(int ruleset) const
   return false;
 }
 
-int OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid,
-                         int nosd, int pg_bits, int pgp_bits)
+int OSDMap::build_simple_optioned(CephContext *cct, epoch_t e, uuid_d &fsid,
+                                 int nosd, int pg_bits, int pgp_bits,
+                                 bool default_pool)
 {
   ldout(cct, 10) << "build_simple on " << nosd
                 << " osds" << dendl;
@@ -3267,6 +3268,7 @@ int OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid,
     set_max_osd(maxosd + 1);
   }
 
+
   stringstream ss;
   int r;
   if (nosd >= 0)
@@ -3275,6 +3277,42 @@ int OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid,
     r = build_simple_crush_map_from_conf(cct, *crush, &ss);
   assert(r == 0);
 
+  int poolbase = get_max_osd() ? get_max_osd() : 1;
+
+  int const default_replicated_rule = crush->get_osd_pool_default_crush_replicated_ruleset(cct);
+  assert(default_replicated_rule >= 0);
+
+  if (default_pool) {
+    // pgp_num <= pg_num
+    if (pgp_bits > pg_bits)
+      pgp_bits = pg_bits;
+
+    vector<string> pool_names;
+    pool_names.push_back("rbd");
+    for (auto &plname : pool_names) {
+      int64_t pool = ++pool_max;
+      pools[pool].type = pg_pool_t::TYPE_REPLICATED;
+      pools[pool].flags = cct->_conf->osd_pool_default_flags;
+      if (cct->_conf->osd_pool_default_flag_hashpspool)
+       pools[pool].set_flag(pg_pool_t::FLAG_HASHPSPOOL);
+      if (cct->_conf->osd_pool_default_flag_nodelete)
+       pools[pool].set_flag(pg_pool_t::FLAG_NODELETE);
+      if (cct->_conf->osd_pool_default_flag_nopgchange)
+       pools[pool].set_flag(pg_pool_t::FLAG_NOPGCHANGE);
+      if (cct->_conf->osd_pool_default_flag_nosizechange)
+       pools[pool].set_flag(pg_pool_t::FLAG_NOSIZECHANGE);
+      pools[pool].size = cct->_conf->osd_pool_default_size;
+      pools[pool].min_size = cct->_conf->get_osd_pool_default_min_size();
+      pools[pool].crush_rule = default_replicated_rule;
+      pools[pool].object_hash = CEPH_STR_HASH_RJENKINS;
+      pools[pool].set_pg_num(poolbase << pg_bits);
+      pools[pool].set_pgp_num(poolbase << pgp_bits);
+      pools[pool].last_change = epoch;
+      pool_name[pool] = plname;
+      name_pool[plname] = pool;
+    }
+  }
+
   for (int i=0; i<get_max_osd(); i++) {
     set_state(i, 0);
     set_weight(i, CEPH_OSD_OUT);
index b2bcb461d947d302a28f84d39d8a3b26713c9d60..8e065ac58e6aeeac36dc95771477c008d2ddde84 100644 (file)
@@ -1300,8 +1300,20 @@ public:
    * @param num_osd [in] number of OSDs if >= 0 or read from conf if < 0
    * @return **0** on success, negative errno on error.
    */
+private:
+  int build_simple_optioned(CephContext *cct, epoch_t e, uuid_d &fsid,
+                           int num_osd, int pg_bits, int pgp_bits,
+                           bool default_pool);
+public:
   int build_simple(CephContext *cct, epoch_t e, uuid_d &fsid,
-                  int num_osd, int pg_bits, int pgp_bits);
+                  int num_osd) {
+    return build_simple_optioned(cct, e, fsid, num_osd, 0, 0, false);
+  }
+  int build_simple_with_pool(CephContext *cct, epoch_t e, uuid_d &fsid,
+                            int num_osd, int pg_bits, int pgp_bits) {
+    return build_simple_optioned(cct, e, fsid, num_osd,
+                                pg_bits, pgp_bits, true);
+  }
   static int _build_crush_types(CrushWrapper& crush);
   static int build_simple_crush_map(CephContext *cct, CrushWrapper& crush,
                                    int num_osd, ostream *ss);
index c1db4bad0bd63b49551c58ac7e23a54e880a5a48..32b2065cef4dd1a834d06e73874ebf65aa749bb1 100644 (file)
@@ -40,7 +40,7 @@ public:
 
   void set_up_map() {
     uuid_d fsid;
-    osdmap.build_simple(g_ceph_context, 0, fsid, num_osds, 6, 6);
+    osdmap.build_simple(g_ceph_context, 0, fsid, num_osds);
     OSDMap::Incremental pending_inc(osdmap.get_epoch() + 1);
     pending_inc.fsid = osdmap.get_fsid();
     entity_addr_t sample_addr;
index 8e10c7532f3a2190149299b21e0d03d797723cc2..18a2d64ac5b89a4cbae86c0df5d27700a4da655a 100644 (file)
@@ -1874,7 +1874,7 @@ TEST_F(PGLogTest, filter_log_1) {
     OSDMap *osdmap = new OSDMap;
     uuid_d test_uuid;
     test_uuid.generate_random();
-    osdmap->build_simple(g_ceph_context, epoch, test_uuid, max_osd, bits, bits);
+    osdmap->build_simple_with_pool(g_ceph_context, epoch, test_uuid, max_osd, bits, bits);
     osdmap->set_state(osd_id, CEPH_OSD_EXISTS);
 
     const string hit_set_namespace("internal");
index ab6346f80f301aa80cbfb413dcc5020c80aac574..c0b82cb5c0faca92aada4606fe815c06fa1e4cf5 100644 (file)
@@ -290,7 +290,7 @@ int main(int argc, const char **argv)
     }
     uuid_d fsid;
     memset(&fsid, 0, sizeof(uuid_d));
-    osdmap.build_simple(g_ceph_context, 0, fsid, num_osd, pg_bits, pgp_bits);
+    osdmap.build_simple_with_pool(g_ceph_context, 0, fsid, num_osd, pg_bits, pgp_bits);
     modified = true;
   }