From: Max Kellermann Date: Thu, 24 Apr 2025 12:01:57 +0000 (+0200) Subject: include/ceph_fs: un-inline encoding functions X-Git-Tag: v21.0.0~256^2~78^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a56aede3ef47dfe4964d155b2564c9a422667a1a;p=ceph.git include/ceph_fs: un-inline encoding functions Reduce header dependencies. Signed-off-by: Max Kellermann --- diff --git a/src/common/ceph_fs.cc b/src/common/ceph_fs.cc index 46c668421d2c..8b5e5ba42a84 100644 --- a/src/common/ceph_fs.cc +++ b/src/common/ceph_fs.cc @@ -9,6 +9,109 @@ */ #include "include/ceph_fs.h" +#include "include/encoding.h" + +void encode(const struct ceph_mds_request_head& h, ceph::buffer::list& bl) { + using ceph::encode; + encode(h.version, bl); + encode(h.oldest_client_tid, bl); + encode(h.mdsmap_epoch, bl); + encode(h.flags, bl); + + // For old MDS daemons + __u8 num_retry = __u32(h.ext_num_retry); + __u8 num_fwd = __u32(h.ext_num_fwd); + encode(num_retry, bl); + encode(num_fwd, bl); + + encode(h.num_releases, bl); + encode(h.op, bl); + encode(h.caller_uid, bl); + encode(h.caller_gid, bl); + encode(h.ino, bl); + bl.append((char*)&h.args, sizeof(h.args)); + + if (h.version >= 2) { + encode(h.ext_num_retry, bl); + encode(h.ext_num_fwd, bl); + } + + if (h.version >= 3) { + __u32 struct_len = sizeof(struct ceph_mds_request_head); + encode(struct_len, bl); + encode(h.owner_uid, bl); + encode(h.owner_gid, bl); + + /* + * Please, add new fields handling here. + * You don't need to check h.version as we do it + * in decode(), because decode can properly skip + * all unsupported fields if h.version >= 3. + */ + } +} + +void decode(struct ceph_mds_request_head& h, ceph::buffer::list::const_iterator& bl) { + using ceph::decode; + unsigned struct_end = bl.get_off(); + + decode(h.version, bl); + decode(h.oldest_client_tid, bl); + decode(h.mdsmap_epoch, bl); + decode(h.flags, bl); + decode(h.num_retry, bl); + decode(h.num_fwd, bl); + decode(h.num_releases, bl); + decode(h.op, bl); + decode(h.caller_uid, bl); + decode(h.caller_gid, bl); + decode(h.ino, bl); + bl.copy(sizeof(h.args), (char*)&(h.args)); + + if (h.version >= 2) { + decode(h.ext_num_retry, bl); + decode(h.ext_num_fwd, bl); + } else { + h.ext_num_retry = h.num_retry; + h.ext_num_fwd = h.num_fwd; + } + + if (h.version >= 3) { + decode(h.struct_len, bl); + struct_end += h.struct_len; + + decode(h.owner_uid, bl); + decode(h.owner_gid, bl); + } else { + /* + * client is old: let's take caller_{u,g}id as owner_{u,g}id + * this is how it worked before adding of owner_{u,g}id fields. + */ + h.owner_uid = h.caller_uid; + h.owner_gid = h.caller_gid; + } + + /* add new fields handling here */ + + /* + * From version 3 we have struct_len field. + * It allows us to properly handle a case + * when client send struct ceph_mds_request_head + * bigger in size than MDS supports. In this + * case we just want to skip all remaining bytes + * at the end. + * + * See also DECODE_FINISH macro. Unfortunately, + * we can't start using it right now as it will be + * an incompatible protocol change. + */ + if (h.version >= 3) { + if (bl.get_off() > struct_end) + throw ::ceph::buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); + if (bl.get_off() < struct_end) + bl += struct_end - bl.get_off(); + } +} int ceph_flags_to_mode(int flags) { diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index 0af1a6fd4634..95d7d34d1437 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -33,6 +33,7 @@ add_library(crimson-common STATIC ${PROJECT_SOURCE_DIR}/src/common/ceph_argparse.cc ${PROJECT_SOURCE_DIR}/src/common/ceph_context.cc ${PROJECT_SOURCE_DIR}/src/common/ceph_crypto.cc + ${PROJECT_SOURCE_DIR}/src/common/ceph_fs.cc ${PROJECT_SOURCE_DIR}/src/common/ceph_hash.cc ${PROJECT_SOURCE_DIR}/src/common/ceph_time.cc ${PROJECT_SOURCE_DIR}/src/common/ceph_strings.cc diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 9b2d67aebf60..e0e91a0554e9 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -14,8 +14,7 @@ #include "msgr.h" #include "rados.h" -#include "include/encoding.h" -#include "include/denc.h" +#include "include/buffer.h" // for ceph::buffer::list /* * The data structures defined here are shared between Linux kernel and @@ -686,107 +685,8 @@ struct ceph_mds_request_head { __le32 owner_uid, owner_gid; /* used for OPs which create inodes */ } __attribute__ ((packed)); -void inline encode(const struct ceph_mds_request_head& h, ceph::buffer::list& bl) { - using ceph::encode; - encode(h.version, bl); - encode(h.oldest_client_tid, bl); - encode(h.mdsmap_epoch, bl); - encode(h.flags, bl); - - // For old MDS daemons - __u8 num_retry = __u32(h.ext_num_retry); - __u8 num_fwd = __u32(h.ext_num_fwd); - encode(num_retry, bl); - encode(num_fwd, bl); - - encode(h.num_releases, bl); - encode(h.op, bl); - encode(h.caller_uid, bl); - encode(h.caller_gid, bl); - encode(h.ino, bl); - bl.append((char*)&h.args, sizeof(h.args)); - - if (h.version >= 2) { - encode(h.ext_num_retry, bl); - encode(h.ext_num_fwd, bl); - } - - if (h.version >= 3) { - __u32 struct_len = sizeof(struct ceph_mds_request_head); - encode(struct_len, bl); - encode(h.owner_uid, bl); - encode(h.owner_gid, bl); - - /* - * Please, add new fields handling here. - * You don't need to check h.version as we do it - * in decode(), because decode can properly skip - * all unsupported fields if h.version >= 3. - */ - } -} - -void inline decode(struct ceph_mds_request_head& h, ceph::buffer::list::const_iterator& bl) { - using ceph::decode; - unsigned struct_end = bl.get_off(); - - decode(h.version, bl); - decode(h.oldest_client_tid, bl); - decode(h.mdsmap_epoch, bl); - decode(h.flags, bl); - decode(h.num_retry, bl); - decode(h.num_fwd, bl); - decode(h.num_releases, bl); - decode(h.op, bl); - decode(h.caller_uid, bl); - decode(h.caller_gid, bl); - decode(h.ino, bl); - bl.copy(sizeof(h.args), (char*)&(h.args)); - - if (h.version >= 2) { - decode(h.ext_num_retry, bl); - decode(h.ext_num_fwd, bl); - } else { - h.ext_num_retry = h.num_retry; - h.ext_num_fwd = h.num_fwd; - } - - if (h.version >= 3) { - decode(h.struct_len, bl); - struct_end += h.struct_len; - - decode(h.owner_uid, bl); - decode(h.owner_gid, bl); - } else { - /* - * client is old: let's take caller_{u,g}id as owner_{u,g}id - * this is how it worked before adding of owner_{u,g}id fields. - */ - h.owner_uid = h.caller_uid; - h.owner_gid = h.caller_gid; - } - - /* add new fields handling here */ - - /* - * From version 3 we have struct_len field. - * It allows us to properly handle a case - * when client send struct ceph_mds_request_head - * bigger in size than MDS supports. In this - * case we just want to skip all remaining bytes - * at the end. - * - * See also DECODE_FINISH macro. Unfortunately, - * we can't start using it right now as it will be - * an incompatible protocol change. - */ - if (h.version >= 3) { - if (bl.get_off() > struct_end) - throw ::ceph::buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); - if (bl.get_off() < struct_end) - bl += struct_end - bl.get_off(); - } -} +void encode(const struct ceph_mds_request_head& h, ceph::buffer::list& bl); +void decode(struct ceph_mds_request_head& h, ceph::buffer::list::const_iterator& bl); /* cap/lease release record */ struct ceph_mds_request_release {