From: Jason Dillaman Date: Mon, 14 Dec 2015 22:41:49 +0000 (-0500) Subject: librbd: optionally validate RBD pool configuration (snapshot support) X-Git-Tag: v10.0.2~37^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1fea4dadc60e13518e9ee55d136fbc4e9d3a621e;p=ceph.git librbd: optionally validate RBD pool configuration (snapshot support) Fixes: #13633 Signed-off-by: Jason Dillaman --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index fff089736ffb..95fe22d203ce 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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 diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 37ded6c246c4..fbc9a533f2b5 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -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;