Skip to content

Commit

Permalink
Merge pull request #7182: hammer: Verify self-managed snapshot functi…
Browse files Browse the repository at this point in the history
…onality on image create

Reviewed-by: Loic Dachary <ldachary@redhat.com>
  • Loading branch information
Loic Dachary committed Jan 29, 2016
2 parents d150843 + 8c28f2f commit d6f1f26
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/common/config_opts.h
Expand Up @@ -902,6 +902,7 @@ OPTION(rbd_blacklist_on_break_lock, OPT_BOOL, true) // whether to blacklist clie
OPTION(rbd_blacklist_expire_seconds, OPT_INT, 0) // number of seconds to blacklist - set to 0 for OSD default
OPTION(rbd_request_timed_out_seconds, OPT_INT, 30) // number of seconds before maint request times out
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
Expand Down
50 changes: 48 additions & 2 deletions src/librbd/internal.cc
Expand Up @@ -135,6 +135,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)
Expand Down Expand Up @@ -872,8 +907,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;
Expand Down Expand Up @@ -918,9 +959,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;
Expand Down

0 comments on commit d6f1f26

Please sign in to comment.