Skip to content

Commit

Permalink
librbd: fix don't send get_stripe_unit_count if striping is not enabled
Browse files Browse the repository at this point in the history
Fixes: http://tracker.ceph.com/issues/21360

Signed-off-by: Yanhu Cao <gmayyyha@gmail.com>
  • Loading branch information
gmayyyha committed Sep 14, 2017
1 parent f609c0e commit f93e5f1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/cls/rbd/cls_rbd_client.cc
Expand Up @@ -54,6 +54,26 @@ namespace librbd {
return get_immutable_metadata_finish(&it, object_prefix, order);
}

void get_features_start(librados::ObjectReadOperation *op) {
bufferlist features_bl;
snapid_t snap = CEPH_NOSNAP;
::encode(snap, features_bl);
::encode(true, features_bl);
op->exec("rbd", "get_features", features_bl);
}

int get_features_finish(bufferlist::iterator *it,
uint64_t *features) {
try {
// get_features
::decode(*features, *it);
} catch (const buffer::error &err) {
return -EBADMSG;
}
return 0;
}


void get_mutable_metadata_start(librados::ObjectReadOperation *op,
bool read_only) {
snapid_t snap = CEPH_NOSNAP;
Expand Down
4 changes: 4 additions & 0 deletions src/cls/rbd/cls_rbd_client.h
Expand Up @@ -28,6 +28,10 @@ namespace librbd {
int get_immutable_metadata(librados::IoCtx *ioctx, const std::string &oid,
std::string *object_prefix, uint8_t *order);

void get_features_start(librados::ObjectReadOperation *op);
int get_features_finish(bufferlist::iterator *it,
uint64_t *features);

void get_mutable_metadata_start(librados::ObjectReadOperation *op,
bool read_only);
int get_mutable_metadata_finish(bufferlist::iterator *it,
Expand Down
43 changes: 43 additions & 0 deletions src/librbd/image/OpenRequest.cc
Expand Up @@ -277,7 +277,50 @@ Context *OpenRequest<I>::handle_v2_get_immutable_metadata(int *result) {
<< cpp_strerror(*result) << dendl;
send_close_image(*result);
} else {
send_v2_get_features();
}

return nullptr;
}

template <typename I>
void OpenRequest<I>::send_v2_get_features() {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 10) << this << " " << __func__ << dendl;

librados::ObjectReadOperation op;
cls_client::get_features_start(&op);

using klass = OpenRequest<I>;
librados::AioCompletion *comp = create_rados_callback<
klass, &klass::handle_v2_get_features>(this);
m_out_bl.clear();
m_image_ctx->md_ctx.aio_operate(m_image_ctx->header_oid, comp, &op,
&m_out_bl);
comp->release();
}

template <typename I>
Context *OpenRequest<I>::handle_v2_get_features(int *result) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 10) << __func__ << ": r=" << *result << dendl;

if (*result == 0) {
bufferlist::iterator it = m_out_bl.begin();
*result = cls_client::get_features_finish(
&it, &m_image_ctx->features);
}
if (*result < 0) {
lderr(cct) << "failed to retreive features: "
<< cpp_strerror(*result) << dendl;
send_close_image(*result);
return nullptr;
}

if (m_image_ctx->test_features(RBD_FEATURE_STRIPINGV2)) {
send_v2_get_stripe_unit_count();
} else {
send_v2_get_create_timestamp();
}

return nullptr;
Expand Down
8 changes: 7 additions & 1 deletion src/librbd/image/OpenRequest.h
Expand Up @@ -49,9 +49,12 @@ class OpenRequest {
* V2_GET_IMMUTABLE_METADATA |
* | |
* v |
* V2_GET_STRIPE_UNIT_COUNT |
* V2_GET_FEATURES |
* | |
* v |
* V2_GET_STRIPE_UNIT_COUNT (skip if |
* | disabled) |
* v |
* V2_GET_CREATE_TIMESTAMP |
* | |
* v |
Expand Down Expand Up @@ -105,6 +108,9 @@ class OpenRequest {
void send_v2_get_immutable_metadata();
Context *handle_v2_get_immutable_metadata(int *result);

void send_v2_get_features();
Context *handle_v2_get_features(int *result);

void send_v2_get_stripe_unit_count();
Context *handle_v2_get_stripe_unit_count(int *result);

Expand Down

0 comments on commit f93e5f1

Please sign in to comment.