From: Radoslaw Zarzynski Date: Mon, 23 Sep 2019 17:04:22 +0000 (+0200) Subject: crimson/osd: delegate executing osd op in objclass. X-Git-Tag: v15.1.0~801^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=db5479d2ee0274ddf7dae940898ea25c53d15907;p=ceph.git crimson/osd: delegate executing osd op in objclass. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/crimson/osd/objclass.cc b/src/crimson/osd/objclass.cc index bade26240c0e..9b61edcb573d 100644 --- a/src/crimson/osd/objclass.cc +++ b/src/crimson/osd/objclass.cc @@ -18,6 +18,16 @@ #include "auth/Crypto.h" #include "common/armor.h" +static inline int execute_osd_op(cls_method_context_t hctx, OSDOp& op) +{ + try { + reinterpret_cast(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) @@ -69,38 +79,21 @@ int cls_cxx_create(cls_method_context_t hctx, const bool exclusive) { OSDOp op{CEPH_OSD_OP_CREATE}; op.op.flags = (exclusive ? CEPH_OSD_OP_FLAG_EXCL : 0); - try { - reinterpret_cast(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(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(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 { @@ -136,10 +129,8 @@ int cls_cxx_read2(cls_method_context_t hctx, op.op.extent.offset = ofs; op.op.extent.length = len; op.op.flags = op_flags; - try { - reinterpret_cast(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(); @@ -156,12 +147,7 @@ int cls_cxx_write2(cls_method_context_t hctx, op.op.extent.length = len; op.op.flags = op_flags; op.indata = *inbl; - try { - reinterpret_cast(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) @@ -170,12 +156,7 @@ 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(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, @@ -187,11 +168,8 @@ 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(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; } } @@ -200,14 +178,11 @@ int cls_cxx_replace(cls_method_context_t hctx, wop.op.extent.offset = ofs; wop.op.extent.length = len; wop.indata = *inbl; - - try { - reinterpret_cast(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) @@ -215,25 +190,7 @@ 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(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(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, @@ -243,13 +200,11 @@ 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(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, @@ -267,24 +222,14 @@ int cls_cxx_setxattr(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(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(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, @@ -303,10 +248,8 @@ int cls_cxx_map_get_keys(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(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(); @@ -329,10 +272,8 @@ int cls_cxx_map_get_vals(cls_method_context_t hctx, encode(start_obj, op.indata); encode(max_to_get, op.indata); encode(filter_prefix, op.indata); - try { - reinterpret_cast(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(); @@ -358,10 +299,8 @@ int cls_cxx_map_get_val(cls_method_context_t hctx, std::set k{key}; encode(k, op.indata); } - try { - reinterpret_cast(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 m; try { @@ -388,13 +327,7 @@ int cls_cxx_map_set_val(cls_method_context_t hctx, m[key] = *inbl; encode(m, op.indata); } - - try { - reinterpret_cast(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, @@ -402,13 +335,7 @@ int cls_cxx_map_set_vals(cls_method_context_t hctx, { OSDOp op{ CEPH_OSD_OP_OMAPSETVALS }; encode(*map, op.indata); - - try { - reinterpret_cast(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)