#include "auth/Crypto.h"
#include "common/armor.h"
+static inline int execute_osd_op(cls_method_context_t hctx, OSDOp& op)
+{
+ try {
+ reinterpret_cast<ceph::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
+ return 0;
+ } catch (crimson::osd::error& e) {
+ return -e.code().value();
+ }
+}
+
int cls_call(cls_method_context_t hctx, const char *cls, const char *method,
char *indata, int datalen,
char **outdata, int *outdatalen)
{
OSDOp op{CEPH_OSD_OP_CREATE};
op.op.flags = (exclusive ? CEPH_OSD_OP_FLAG_EXCL : 0);
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_remove(cls_method_context_t hctx)
{
OSDOp op{CEPH_OSD_OP_DELETE};
-
- // we're blocking here which presumes execution in Seastar's thread.
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_stat(cls_method_context_t hctx, uint64_t *size, time_t *mtime)
{
OSDOp op{CEPH_OSD_OP_STAT};
-
- // we're blocking here which presumes execution in Seastar's thread.
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- } catch (crimson::osd::error& e) {
- return -e.code().value();
+ if (const auto ret = execute_osd_op(hctx, op); ret < 0) {
+ return ret;
}
-
utime_t ut;
uint64_t s;
try {
op.op.extent.offset = ofs;
op.op.extent.length = len;
op.op.flags = op_flags;
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- } catch (crimson::osd::error& e) {
- return -e.code().value();
+ if (const auto ret = execute_osd_op(hctx, op); ret < 0) {
+ return ret;
}
outbl->claim(op.outdata);
return outbl->length();
op.op.extent.length = len;
op.op.flags = op_flags;
op.indata = *inbl;
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_write_full(cls_method_context_t hctx, bufferlist * const inbl)
op.op.extent.offset = 0;
op.op.extent.length = inbl->length();
op.indata = *inbl;
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_replace(cls_method_context_t hctx,
OSDOp top{CEPH_OSD_OP_TRUNCATE};
top.op.extent.offset = 0;
top.op.extent.length = 0;
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(top).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
+ if (const auto ret = execute_osd_op(hctx, top); ret < 0) {
+ return ret;
}
}
wop.op.extent.offset = ofs;
wop.op.extent.length = len;
wop.indata = *inbl;
-
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(wop).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
+ if (const auto ret = execute_osd_op(hctx, wop); ret < 0) {
+ return ret;
}
}
+ return 0;
}
int cls_cxx_truncate(cls_method_context_t hctx, int ofs)
OSDOp op{CEPH_OSD_OP_TRUNCATE};
op.op.extent.offset = ofs;
op.op.extent.length = 0;
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
-}
-
-int cls_cxx_write_zero(cls_method_context_t hctx, int ofs, int len)
-{
- OSDOp op{CEPH_OSD_OP_ZERO};
- op.op.extent.offset = ofs;
- op.op.extent.length = len;
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_getxattr(cls_method_context_t hctx,
OSDOp op{CEPH_OSD_OP_GETXATTR};
op.op.xattr.name_len = strlen(name);
op.indata.append(name, op.op.xattr.name_len);
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- outbl->claim(op.outdata);
- return outbl->length();
- } catch (crimson::osd::error& e) {
- return -e.code().value();
+ if (const auto ret = execute_osd_op(hctx, op); ret < 0) {
+ return ret;
}
+ outbl->claim(op.outdata);
+ return outbl->length();
}
int cls_cxx_getxattrs(cls_method_context_t hctx,
op.op.xattr.value_len = inbl->length();
op.indata.append(name, op.op.xattr.name_len);
op.indata.append(*inbl);
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_snap_revert(cls_method_context_t hctx, snapid_t snapid)
{
OSDOp op{op = CEPH_OSD_OP_ROLLBACK};
op.op.snap.snapid = snapid;
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_map_get_all_vals(cls_method_context_t hctx,
OSDOp op{ CEPH_OSD_OP_OMAPGETKEYS };
encode(start_obj, op.indata);
encode(max_to_get, op.indata);
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- } catch (crimson::osd::error& e) {
- return -e.code().value();
+ if (const auto ret = execute_osd_op(hctx, op); ret < 0) {
+ return ret;
}
try {
auto iter = op.outdata.cbegin();
encode(start_obj, op.indata);
encode(max_to_get, op.indata);
encode(filter_prefix, op.indata);
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- } catch (crimson::osd::error& e) {
- return -e.code().value();
+ if (const auto ret = execute_osd_op(hctx, op); ret < 0) {
+ return ret;
}
try {
auto iter = op.outdata.cbegin();
std::set<std::string> k{key};
encode(k, op.indata);
}
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- } catch (crimson::osd::error& e) {
- return -e.code().value();
+ if (const auto ret = execute_osd_op(hctx, op); ret < 0) {
+ return ret;
}
std::map<std::string, ceph::bufferlist> m;
try {
m[key] = *inbl;
encode(m, op.indata);
}
-
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_map_set_vals(cls_method_context_t hctx,
{
OSDOp op{ CEPH_OSD_OP_OMAPSETVALS };
encode(*map, op.indata);
-
- try {
- reinterpret_cast<crimson::osd::OpsExecuter*>(hctx)->execute_osd_op(op).get();
- return 0;
- } catch (crimson::osd::error& e) {
- return -e.code().value();
- }
+ return execute_osd_op(hctx, op);
}
int cls_cxx_map_clear(cls_method_context_t hctx)