]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
include/ceph_fs: un-inline encoding functions
authorMax Kellermann <max.kellermann@ionos.com>
Thu, 24 Apr 2025 12:01:57 +0000 (14:01 +0200)
committerVenky Shankar <vshankar@redhat.com>
Tue, 22 Jul 2025 05:11:00 +0000 (10:41 +0530)
Reduce header dependencies.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/common/ceph_fs.cc
src/crimson/CMakeLists.txt
src/include/ceph_fs.h

index 46c668421d2c94395dfd6f3918f82ba8edd85e56..8b5e5ba42a8466ff5a2c4e9e8d8602d1574e8939 100644 (file)
@@ -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)
 {
index 0af1a6fd4634b66fff8cda94f9b3554fef0cbe7b..95d7d34d14376ff882e4128cebffaefca55e7b9d 100644 (file)
@@ -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
index 9b2d67aebf60d0a83903572f8bb309f87704bf52..e0e91a0554e970708f15ae77dc1b980fb568984a 100644 (file)
@@ -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 {