mirror of
https://github.com/ceph/ceph
synced 2025-02-17 16:07:37 +00:00
librbd: optionally validate RBD pool configuration (snapshot support)
Fixes: #13633 Signed-off-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
parent
03f719cb32
commit
1fea4dadc6
src
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user