]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: make pool creation idempotent
authorSage Weil <sage@inktank.com>
Mon, 23 Jul 2012 23:03:46 +0000 (16:03 -0700)
committerSage Weil <sage@inktank.com>
Fri, 27 Jul 2012 17:43:25 +0000 (10:43 -0700)
Return success if the pool already exists.  Part of #2638.

Also, fix this so we wait until a creating pool is created before we reply.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/OSDMonitor.cc

index bd94ddd654da8ac2f70a6eaafc26d29d0e8bf7c8..0d29e38a324357ab08cfbb67595c57fac8841250 100644 (file)
@@ -1698,14 +1698,11 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
 int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_rule,
                                  unsigned pg_num, unsigned pgp_num)
 {
-  if (osdmap.name_pool.count(name)) {
-    return -EEXIST;
-  }
   for (map<int64_t,string>::iterator p = pending_inc.new_pool_names.begin();
        p != pending_inc.new_pool_names.end();
        ++p) {
     if (p->second == name)
-      return -EEXIST;
+      return 0;
   }
 
   if (-1 == pending_inc.new_pool_max)
@@ -2322,15 +2319,24 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
             }
           }
         }
+
+       if (osdmap.name_pool.count(m->cmd[3])) {
+         ss << "pool '" << m->cmd[3] << "' already exists";
+         err = 0;
+         goto out;
+       }
+
         err = prepare_new_pool(m->cmd[3], 0,  // auid=0 for admin created pool
                               -1,            // default crush rule
                               pg_num, pgp_num);
-        if (err < 0) {
-          if (err == -EEXIST)
-            ss << "pool '" << m->cmd[3] << "' exists";
+        if (err < 0 && err != -EEXIST) {
           goto out;
         }
-       ss << "pool '" << m->cmd[3] << "' created";
+       if (err == -EEXIST) {
+         ss << "pool '" << m->cmd[3] << "' already exists";
+       } else {
+         ss << "pool '" << m->cmd[3] << "' created";
+       }
        getline(ss, rs);
        paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
        return true;
@@ -2593,7 +2599,7 @@ bool OSDMonitor::preprocess_pool_op_create(MPoolOp *m)
 
   int64_t pool = osdmap.lookup_pg_pool_name(m->name.c_str());
   if (pool >= 0) {
-    _pool_op_reply(m, -EEXIST, osdmap.get_epoch());
+    _pool_op_reply(m, 0, osdmap.get_epoch());
     return true;
   }