]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: optionally validate RBD pool configuration (snapshot support)
authorJason Dillaman <dillaman@redhat.com>
Mon, 14 Dec 2015 22:41:49 +0000 (17:41 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 14 Dec 2015 22:41:49 +0000 (17:41 -0500)
Fixes: #13633
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/common/config_opts.h
src/librbd/internal.cc

index fff089736ffb2fafaf55da625540d01e5ba05f3a..95fe22d203ce62dd2ad7652f1f132a7e5d6c150b 100644 (file)
@@ -995,6 +995,7 @@ OPTION(rbd_request_timed_out_seconds, OPT_INT, 30) // number of seconds before m
 OPTION(rbd_skip_partial_discard, OPT_BOOL, false) // when trying to discard a range inside an object, set to true to skip zeroing the range.
 OPTION(rbd_enable_alloc_hint, OPT_BOOL, true) // when writing a object, it will issue a hint to osd backend to indicate the expected size object need
 OPTION(rbd_tracing, OPT_BOOL, false) // true if LTTng-UST tracepoints should be enabled
+OPTION(rbd_validate_pool, OPT_BOOL, true) // true if empty pools should be validated for RBD compatibility
 
 /*
  * The following options change the behavior for librbd's image creation methods that
index 37ded6c246c4c10881f511bbf5715170dadbd1a3..fbc9a533f2b51e6533b0c713c9f92789dc6c0432 100644 (file)
@@ -222,6 +222,41 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
   return r;
 }
 
+int validate_pool(IoCtx &io_ctx, CephContext *cct) {
+  if (!cct->_conf->rbd_validate_pool) {
+    return 0;
+  }
+
+  int r = io_ctx.stat(RBD_DIRECTORY, NULL, NULL);
+  if (r == 0) {
+    return 0;
+  } else if (r < 0 && r != -ENOENT) {
+    lderr(cct) << "failed to stat RBD directory: " << cpp_strerror(r) << dendl;
+    return r;
+  }
+
+  // allocate a self-managed snapshot id if this a new pool to force
+  // self-managed snapshot mode
+  uint64_t snap_id;
+  r = io_ctx.selfmanaged_snap_create(&snap_id);
+  if (r == -EINVAL) {
+    lderr(cct) << "pool not configured for self-managed RBD snapshot support"
+               << dendl;
+    return r;
+  } else if (r < 0) {
+    lderr(cct) << "failed to allocate self-managed snapshot: "
+               << cpp_strerror(r) << dendl;
+    return r;
+  }
+
+  r = io_ctx.selfmanaged_snap_remove(snap_id);
+  if (r < 0) {
+    lderr(cct) << "failed to release self-managed snapshot " << snap_id
+               << ": " << cpp_strerror(r) << dendl;
+  }
+  return 0;
+}
+
 } // anonymous namespace
 
   const string id_obj_name(const string &name)
@@ -1142,8 +1177,14 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
                uint64_t size, int order)
   {
     CephContext *cct = (CephContext *)io_ctx.cct();
+
+    int r = validate_pool(io_ctx, cct);
+    if (r < 0) {
+      return r;
+    }
+
     ldout(cct, 2) << "adding rbd image to directory..." << dendl;
-    int r = tmap_set(io_ctx, imgname);
+    r = tmap_set(io_ctx, imgname);
     if (r < 0) {
       lderr(cct) << "error adding image to directory: " << cpp_strerror(r)
                 << dendl;
@@ -1190,9 +1231,14 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
 
     ceph_file_layout layout;
 
+    int r = validate_pool(io_ctx, cct);
+    if (r < 0) {
+      return r;
+    }
+
     id_obj = id_obj_name(imgname);
 
-    int r = io_ctx.create(id_obj, true);
+    r = io_ctx.create(id_obj, true);
     if (r < 0) {
       lderr(cct) << "error creating rbd id object: " << cpp_strerror(r)
                 << dendl;