From: Igor Golikov Date: Tue, 18 Feb 2025 11:45:57 +0000 (+0000) Subject: mds,client: change result field handling in the MClientReply message X-Git-Tag: testing/wip-khiremat-testing-20250422.120708-squid-debug~110^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f3824ad6cc3ded205dec3b89c801e92839152216;p=ceph-ci.git mds,client: change result field handling in the MClientReply message Signed-off-by: Igor Golikov Fixes: https://tracker.ceph.com/issues/64611 (cherry picked from commit bd3b248ab9f51fe4d17ea57400f698ad1963f9a0) --- diff --git a/src/messages/MClientReply.h b/src/messages/MClientReply.h index 028c4200c14..a18c595edb1 100644 --- a/src/messages/MClientReply.h +++ b/src/messages/MClientReply.h @@ -336,21 +336,17 @@ public: epoch_t get_mdsmap_epoch() const { return head.mdsmap_epoch; } int get_result() const { - #ifdef _WIN32 - // libclient and libcephfs return CEPHFS_E* errors, which are basically - // Linux errno codes. If we convert mds errors to host errno values, we - // end up mixing error codes. - // - // For Windows, we'll preserve the original error value, which is expected - // to be a linux (CEPHFS_E*) error. It may be worth doing the same for - // other platforms. + // MDS now uses host errors, as defined in errno.cc, for current platform. + // errorcode32_t is converting, internally, the error code from host to ceph, when encoding, and vice versa, + // when decoding, resulting having LINUX codes on the wire, and HOST code on the receiver. + // assumes this code is executing after decode_payload() function has been called return head.result; - #else - return ceph_to_hostos_errno((__s32)(__u32)head.result); - #endif } - void set_result(int r) { head.result = r; } + // errorcode32_t is used in decode/encode methods + void set_result(int r) { + head.result = r; + } void set_unsafe() { head.safe = 0; } @@ -363,8 +359,8 @@ protected: memset(&head, 0, sizeof(head)); header.tid = req.get_tid(); head.op = req.get_op(); - head.result = result; head.safe = 1; + set_result(result); } ~MClientReply() final {} @@ -390,6 +386,13 @@ public: using ceph::decode; auto p = payload.cbegin(); decode(head, p); + // errorcode32_t implements conversion from/to different host error codes + // casting needed since error codes are signed int32 and head.result is unsigned int32 + // errortype_t::code_t is alias for __s32, which is signed + // ceph_mds_reply_head::code_t is alias for __le32 which is unsigned + errorcode32_t temp; + temp.set_wire_to_host(static_cast(head.result)); + head.result = static_cast(temp.code); decode(trace_bl, p); decode(extra_bl, p); decode(snapbl, p); @@ -397,7 +400,16 @@ public: } void encode_payload(uint64_t features) override { using ceph::encode; - encode(head, payload); + // errorcode32_t implements conversion from/to different host error codes + // casting needed since error codes are signed int32 and head.result is unsigned int32 + // errortype_t::code_t is alias for __s32, which is signed + // ceph_mds_reply_head::code_t is alias for __le32 which is unsigned + // the Messenger layer expects to be able to call encode_payload multiple times on message retries + // this is the reason we must copy the head and to modify the copy's 'result' field + auto temp_head = head; + errorcode32_t temp{static_cast(temp_head.result)}; + temp_head.result = static_cast(temp.get_host_to_wire()); + encode(temp_head, payload); encode(trace_bl, payload); encode(extra_bl, payload); encode(snapbl, payload); diff --git a/src/messages/MCommandReply.h b/src/messages/MCommandReply.h index ed627c85cab..1a07b5bf150 100644 --- a/src/messages/MCommandReply.h +++ b/src/messages/MCommandReply.h @@ -31,6 +31,9 @@ public: : Message{MSG_COMMAND_REPLY}, r(_r) { header.tid = m->get_tid(); } + // MDS now uses host errors, as defined in errno.cc, for current platform. + // errorcode32_t is converting, internally, the error code from host to ceph, when encoding, and vice versa, + // when decoding, resulting having LINUX codes on the wire, and HOST code on the receiver. MCommandReply(int _r, std::string_view s) : Message{MSG_COMMAND_REPLY}, r(_r), rs(s) { }