]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: detect existing fs and duplicate name earlier 13471/head
authorPatrick Donnelly <pdonnell@redhat.com>
Fri, 17 Feb 2017 02:26:12 +0000 (21:26 -0500)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 17 Feb 2017 02:34:42 +0000 (21:34 -0500)
Detecting creation of an equivalent fs was made impossible by
052c3d3f681017d56b5b0ee5cf6f65bffc952a4c, as an existing file system
will obviously have objects in its pool. This commit moves the pool with
objects check later and uses a more helpful errno (EEXIST) for the case
where a fs with the same name already exists (but uses different pools).

Fixes: http://tracker.ceph.com/issues/18964
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/mon/MDSMonitor.cc

index 4dbce27162c7d3bf23cee3d78f4da93e9e837618..e834678f6eb97662705dd55f609a912a653fec65 100644 (file)
@@ -1582,27 +1582,17 @@ int MDSMonitor::management_command(
       return -ENOENT;
     }
 
-    string force;
-    cmd_getval(g_ceph_context,cmdmap, "force", force);
-    int64_t metadata_num_objects = mon->pgmon()->pg_map.pg_pool_sum[metadata].stats.sum.num_objects;
-    if (force != "--force" && metadata_num_objects > 0) {
-      ss << "pool '" << metadata_name
-        << "' already contains some objects. Use an empty pool instead.";
-      return -EINVAL;
-    }
-
     string data_name;
     cmd_getval(g_ceph_context, cmdmap, "data", data_name);
     int64_t data = mon->osdmon()->osdmap.lookup_pg_pool_name(data_name);
     if (data < 0) {
       ss << "pool '" << data_name << "' does not exist";
       return -ENOENT;
-    }
-    if (data == 0) {
+    } else if (data == 0) {
       ss << "pool '" << data_name << "' has id 0, which CephFS does not allow. Use another pool or recreate it to get a non-zero pool id.";
       return -EINVAL;
     }
-   
+
     string fs_name;
     cmd_getval(g_ceph_context, cmdmap, "fs_name", fs_name);
     if (fs_name.empty()) {
@@ -1610,9 +1600,7 @@ int MDSMonitor::management_command(
         // commmands that refer to FS by name in future.
         ss << "Filesystem name may not be empty";
         return -EINVAL;
-    }
-
-    if (pending_fsmap.get_filesystem(fs_name)) {
+    } else if (pending_fsmap.get_filesystem(fs_name)) {
       auto fs = pending_fsmap.get_filesystem(fs_name);
       if (*(fs->mds_map.data_pools.begin()) == data
           && fs->mds_map.metadata_pool == metadata) {
@@ -1621,10 +1609,19 @@ int MDSMonitor::management_command(
         return 0;
       } else {
         ss << "filesystem already exists with name '" << fs_name << "'";
-        return -EINVAL;
+        return -EEXIST;
       }
     }
 
+    string force;
+    cmd_getval(g_ceph_context,cmdmap, "force", force);
+    int64_t metadata_num_objects = mon->pgmon()->pg_map.pg_pool_sum[metadata].stats.sum.num_objects;
+    if (force != "--force" && metadata_num_objects > 0) {
+      ss << "pool '" << metadata_name
+        << "' already contains some objects. Use an empty pool instead.";
+      return -EINVAL;
+    }
+
     if (pending_fsmap.filesystem_count() > 0
         && !pending_fsmap.get_enable_multiple()) {
       ss << "Creation of multiple filesystems is disabled.  To enable "