Skip to content

Commit

Permalink
Merge pull request #8380 from dillaman/wip-cls-fadvise
Browse files Browse the repository at this point in the history
cls_rbd: pass WILLNEED fadvise flags during object map update

Reviewed-by: Josh Durgin <jdurgin@redhat.com>
Reviewed-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Apr 3, 2016
2 parents fdef226 + 77391b3 commit bf38318
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/cls/rbd/cls_rbd.cc
Expand Up @@ -2332,7 +2332,8 @@ int object_map_update(cls_method_context_t hctx, bufferlist *in, bufferlist *out

BitVector<2> object_map;
bufferlist header_bl;
r = cls_cxx_read(hctx, 0, object_map.get_header_length(), &header_bl);
r = cls_cxx_read2(hctx, 0, object_map.get_header_length(), &header_bl,
CEPH_OSD_OP_FLAG_FADVISE_WILLNEED);
if (r < 0) {
CLS_ERR("object map header read failed");
return r;
Expand All @@ -2347,8 +2348,9 @@ int object_map_update(cls_method_context_t hctx, bufferlist *in, bufferlist *out
}

bufferlist footer_bl;
r = cls_cxx_read(hctx, object_map.get_footer_offset(),
size - object_map.get_footer_offset(), &footer_bl);
r = cls_cxx_read2(hctx, object_map.get_footer_offset(),
size - object_map.get_footer_offset(), &footer_bl,
CEPH_OSD_OP_FLAG_FADVISE_WILLNEED);
if (r < 0) {
CLS_ERR("object map footer read failed");
return r;
Expand All @@ -2372,8 +2374,8 @@ int object_map_update(cls_method_context_t hctx, bufferlist *in, bufferlist *out
&byte_offset, &byte_length);

bufferlist data_bl;
r = cls_cxx_read(hctx, object_map.get_header_length() + byte_offset,
byte_length, &data_bl);
r = cls_cxx_read2(hctx, object_map.get_header_length() + byte_offset,
byte_length, &data_bl, CEPH_OSD_OP_FLAG_FADVISE_WILLNEED);
if (r < 0) {
CLS_ERR("object map data read failed");
return r;
Expand All @@ -2386,7 +2388,7 @@ int object_map_update(cls_method_context_t hctx, bufferlist *in, bufferlist *out
CLS_ERR("failed to decode data chunk [%" PRIu64 "]: %s",
byte_offset, err.what());
return -EINVAL;
}
}

bool updated = false;
for (uint64_t object_no = start_object_no; object_no < end_object_no;
Expand All @@ -2407,21 +2409,22 @@ int object_map_update(cls_method_context_t hctx, bufferlist *in, bufferlist *out

bufferlist data_bl;
object_map.encode_data(data_bl, byte_offset, byte_length);
r = cls_cxx_write(hctx, object_map.get_header_length() + byte_offset,
data_bl.length(), &data_bl);
r = cls_cxx_write2(hctx, object_map.get_header_length() + byte_offset,
data_bl.length(), &data_bl,
CEPH_OSD_OP_FLAG_FADVISE_WILLNEED);
if (r < 0) {
CLS_ERR("failed to write object map header: %s", cpp_strerror(r).c_str());
return r;
CLS_ERR("failed to write object map header: %s", cpp_strerror(r).c_str());
return r;
}

footer_bl.clear();
object_map.encode_footer(footer_bl);
r = cls_cxx_write(hctx, object_map.get_footer_offset(), footer_bl.length(),
&footer_bl);
r = cls_cxx_write2(hctx, object_map.get_footer_offset(), footer_bl.length(),
&footer_bl, CEPH_OSD_OP_FLAG_FADVISE_WILLNEED);
if (r < 0) {
CLS_ERR("failed to write object map footer: %s", cpp_strerror(r).c_str());
CLS_ERR("failed to write object map footer: %s", cpp_strerror(r).c_str());
return r;
}
}
} else {
CLS_LOG(20, "object_map_update: no update necessary");
}
Expand Down
14 changes: 14 additions & 0 deletions src/objclass/class_api.cc
Expand Up @@ -268,13 +268,20 @@ int cls_cxx_stat2(cls_method_context_t hctx, uint64_t *size, ceph::real_time *mt
}

int cls_cxx_read(cls_method_context_t hctx, int ofs, int len, bufferlist *outbl)
{
return cls_cxx_read2(hctx, ofs, len, outbl, 0);
}

int cls_cxx_read2(cls_method_context_t hctx, int ofs, int len,
bufferlist *outbl, uint32_t op_flags)
{
ReplicatedPG::OpContext **pctx = (ReplicatedPG::OpContext **)hctx;
vector<OSDOp> ops(1);
int ret;
ops[0].op.op = CEPH_OSD_OP_SYNC_READ;
ops[0].op.extent.offset = ofs;
ops[0].op.extent.length = len;
ops[0].op.flags = op_flags;
ret = (*pctx)->pg->do_osd_ops(*pctx, ops);
if (ret < 0)
return ret;
Expand All @@ -283,12 +290,19 @@ int cls_cxx_read(cls_method_context_t hctx, int ofs, int len, bufferlist *outbl)
}

int cls_cxx_write(cls_method_context_t hctx, int ofs, int len, bufferlist *inbl)
{
return cls_cxx_write2(hctx, ofs, len, inbl, 0);
}

int cls_cxx_write2(cls_method_context_t hctx, int ofs, int len,
bufferlist *inbl, uint32_t op_flags)
{
ReplicatedPG::OpContext **pctx = (ReplicatedPG::OpContext **)hctx;
vector<OSDOp> ops(1);
ops[0].op.op = CEPH_OSD_OP_WRITE;
ops[0].op.extent.offset = ofs;
ops[0].op.extent.length = len;
ops[0].op.flags = op_flags;
ops[0].indata = *inbl;
return (*pctx)->pg->do_osd_ops(*pctx, ops);
}
Expand Down
4 changes: 4 additions & 0 deletions src/objclass/objclass.h
Expand Up @@ -145,7 +145,11 @@ extern int cls_cxx_remove(cls_method_context_t hctx);
extern int cls_cxx_stat(cls_method_context_t hctx, uint64_t *size, time_t *mtime);
extern int cls_cxx_stat2(cls_method_context_t hctx, uint64_t *size, ceph::real_time *mtime);
extern int cls_cxx_read(cls_method_context_t hctx, int ofs, int len, bufferlist *bl);
extern int cls_cxx_read2(cls_method_context_t hctx, int ofs, int len,
bufferlist *bl, uint32_t op_flags);
extern int cls_cxx_write(cls_method_context_t hctx, int ofs, int len, bufferlist *bl);
extern int cls_cxx_write2(cls_method_context_t hctx, int ofs, int len,
bufferlist *bl, uint32_t op_flags);
extern int cls_cxx_write_full(cls_method_context_t hctx, bufferlist *bl);
extern int cls_cxx_getxattr(cls_method_context_t hctx, const char *name,
bufferlist *outbl);
Expand Down
10 changes: 10 additions & 0 deletions src/test/librados_test_stub/LibradosTestStub.cc
Expand Up @@ -1118,6 +1118,11 @@ int cls_cxx_map_set_vals(cls_method_context_t hctx,

int cls_cxx_read(cls_method_context_t hctx, int ofs, int len,
bufferlist *outbl) {
return cls_cxx_read2(hctx, ofs, len, outbl, 0);
}

int cls_cxx_read2(cls_method_context_t hctx, int ofs, int len,
bufferlist *outbl, uint32_t op_flags) {
librados::TestClassHandler::MethodContext *ctx =
reinterpret_cast<librados::TestClassHandler::MethodContext*>(hctx);
return ctx->io_ctx_impl->read(ctx->oid, len, ofs, outbl);
Expand All @@ -1138,6 +1143,11 @@ int cls_cxx_stat(cls_method_context_t hctx, uint64_t *size, time_t *mtime) {

int cls_cxx_write(cls_method_context_t hctx, int ofs, int len,
bufferlist *inbl) {
return cls_cxx_write2(hctx, ofs, len, inbl, 0);
}

int cls_cxx_write2(cls_method_context_t hctx, int ofs, int len,
bufferlist *inbl, uint32_t op_flags) {
librados::TestClassHandler::MethodContext *ctx =
reinterpret_cast<librados::TestClassHandler::MethodContext*>(hctx);
return ctx->io_ctx_impl->write(ctx->oid, *inbl, len, ofs, ctx->snapc);
Expand Down

0 comments on commit bf38318

Please sign in to comment.