Skip to content

Commit a56aede

Browse files
MaxKellermannvshankar
authored andcommitted
include/ceph_fs: un-inline encoding functions
Reduce header dependencies. Signed-off-by: Max Kellermann <[email protected]>
1 parent 8b822b3 commit a56aede

File tree

3 files changed

+107
-103
lines changed

3 files changed

+107
-103
lines changed

src/common/ceph_fs.cc

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,109 @@
99
*/
1010

1111
#include "include/ceph_fs.h"
12+
#include "include/encoding.h"
13+
14+
void encode(const struct ceph_mds_request_head& h, ceph::buffer::list& bl) {
15+
using ceph::encode;
16+
encode(h.version, bl);
17+
encode(h.oldest_client_tid, bl);
18+
encode(h.mdsmap_epoch, bl);
19+
encode(h.flags, bl);
20+
21+
// For old MDS daemons
22+
__u8 num_retry = __u32(h.ext_num_retry);
23+
__u8 num_fwd = __u32(h.ext_num_fwd);
24+
encode(num_retry, bl);
25+
encode(num_fwd, bl);
26+
27+
encode(h.num_releases, bl);
28+
encode(h.op, bl);
29+
encode(h.caller_uid, bl);
30+
encode(h.caller_gid, bl);
31+
encode(h.ino, bl);
32+
bl.append((char*)&h.args, sizeof(h.args));
33+
34+
if (h.version >= 2) {
35+
encode(h.ext_num_retry, bl);
36+
encode(h.ext_num_fwd, bl);
37+
}
38+
39+
if (h.version >= 3) {
40+
__u32 struct_len = sizeof(struct ceph_mds_request_head);
41+
encode(struct_len, bl);
42+
encode(h.owner_uid, bl);
43+
encode(h.owner_gid, bl);
44+
45+
/*
46+
* Please, add new fields handling here.
47+
* You don't need to check h.version as we do it
48+
* in decode(), because decode can properly skip
49+
* all unsupported fields if h.version >= 3.
50+
*/
51+
}
52+
}
53+
54+
void decode(struct ceph_mds_request_head& h, ceph::buffer::list::const_iterator& bl) {
55+
using ceph::decode;
56+
unsigned struct_end = bl.get_off();
57+
58+
decode(h.version, bl);
59+
decode(h.oldest_client_tid, bl);
60+
decode(h.mdsmap_epoch, bl);
61+
decode(h.flags, bl);
62+
decode(h.num_retry, bl);
63+
decode(h.num_fwd, bl);
64+
decode(h.num_releases, bl);
65+
decode(h.op, bl);
66+
decode(h.caller_uid, bl);
67+
decode(h.caller_gid, bl);
68+
decode(h.ino, bl);
69+
bl.copy(sizeof(h.args), (char*)&(h.args));
70+
71+
if (h.version >= 2) {
72+
decode(h.ext_num_retry, bl);
73+
decode(h.ext_num_fwd, bl);
74+
} else {
75+
h.ext_num_retry = h.num_retry;
76+
h.ext_num_fwd = h.num_fwd;
77+
}
78+
79+
if (h.version >= 3) {
80+
decode(h.struct_len, bl);
81+
struct_end += h.struct_len;
82+
83+
decode(h.owner_uid, bl);
84+
decode(h.owner_gid, bl);
85+
} else {
86+
/*
87+
* client is old: let's take caller_{u,g}id as owner_{u,g}id
88+
* this is how it worked before adding of owner_{u,g}id fields.
89+
*/
90+
h.owner_uid = h.caller_uid;
91+
h.owner_gid = h.caller_gid;
92+
}
93+
94+
/* add new fields handling here */
95+
96+
/*
97+
* From version 3 we have struct_len field.
98+
* It allows us to properly handle a case
99+
* when client send struct ceph_mds_request_head
100+
* bigger in size than MDS supports. In this
101+
* case we just want to skip all remaining bytes
102+
* at the end.
103+
*
104+
* See also DECODE_FINISH macro. Unfortunately,
105+
* we can't start using it right now as it will be
106+
* an incompatible protocol change.
107+
*/
108+
if (h.version >= 3) {
109+
if (bl.get_off() > struct_end)
110+
throw ::ceph::buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__));
111+
if (bl.get_off() < struct_end)
112+
bl += struct_end - bl.get_off();
113+
}
114+
}
12115

13116
int ceph_flags_to_mode(int flags)
14117
{

src/crimson/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ add_library(crimson-common STATIC
3333
${PROJECT_SOURCE_DIR}/src/common/ceph_argparse.cc
3434
${PROJECT_SOURCE_DIR}/src/common/ceph_context.cc
3535
${PROJECT_SOURCE_DIR}/src/common/ceph_crypto.cc
36+
${PROJECT_SOURCE_DIR}/src/common/ceph_fs.cc
3637
${PROJECT_SOURCE_DIR}/src/common/ceph_hash.cc
3738
${PROJECT_SOURCE_DIR}/src/common/ceph_time.cc
3839
${PROJECT_SOURCE_DIR}/src/common/ceph_strings.cc

src/include/ceph_fs.h

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
#include "msgr.h"
1616
#include "rados.h"
17-
#include "include/encoding.h"
18-
#include "include/denc.h"
17+
#include "include/buffer.h" // for ceph::buffer::list
1918

2019
/*
2120
* The data structures defined here are shared between Linux kernel and
@@ -686,107 +685,8 @@ struct ceph_mds_request_head {
686685
__le32 owner_uid, owner_gid; /* used for OPs which create inodes */
687686
} __attribute__ ((packed));
688687

689-
void inline encode(const struct ceph_mds_request_head& h, ceph::buffer::list& bl) {
690-
using ceph::encode;
691-
encode(h.version, bl);
692-
encode(h.oldest_client_tid, bl);
693-
encode(h.mdsmap_epoch, bl);
694-
encode(h.flags, bl);
695-
696-
// For old MDS daemons
697-
__u8 num_retry = __u32(h.ext_num_retry);
698-
__u8 num_fwd = __u32(h.ext_num_fwd);
699-
encode(num_retry, bl);
700-
encode(num_fwd, bl);
701-
702-
encode(h.num_releases, bl);
703-
encode(h.op, bl);
704-
encode(h.caller_uid, bl);
705-
encode(h.caller_gid, bl);
706-
encode(h.ino, bl);
707-
bl.append((char*)&h.args, sizeof(h.args));
708-
709-
if (h.version >= 2) {
710-
encode(h.ext_num_retry, bl);
711-
encode(h.ext_num_fwd, bl);
712-
}
713-
714-
if (h.version >= 3) {
715-
__u32 struct_len = sizeof(struct ceph_mds_request_head);
716-
encode(struct_len, bl);
717-
encode(h.owner_uid, bl);
718-
encode(h.owner_gid, bl);
719-
720-
/*
721-
* Please, add new fields handling here.
722-
* You don't need to check h.version as we do it
723-
* in decode(), because decode can properly skip
724-
* all unsupported fields if h.version >= 3.
725-
*/
726-
}
727-
}
728-
729-
void inline decode(struct ceph_mds_request_head& h, ceph::buffer::list::const_iterator& bl) {
730-
using ceph::decode;
731-
unsigned struct_end = bl.get_off();
732-
733-
decode(h.version, bl);
734-
decode(h.oldest_client_tid, bl);
735-
decode(h.mdsmap_epoch, bl);
736-
decode(h.flags, bl);
737-
decode(h.num_retry, bl);
738-
decode(h.num_fwd, bl);
739-
decode(h.num_releases, bl);
740-
decode(h.op, bl);
741-
decode(h.caller_uid, bl);
742-
decode(h.caller_gid, bl);
743-
decode(h.ino, bl);
744-
bl.copy(sizeof(h.args), (char*)&(h.args));
745-
746-
if (h.version >= 2) {
747-
decode(h.ext_num_retry, bl);
748-
decode(h.ext_num_fwd, bl);
749-
} else {
750-
h.ext_num_retry = h.num_retry;
751-
h.ext_num_fwd = h.num_fwd;
752-
}
753-
754-
if (h.version >= 3) {
755-
decode(h.struct_len, bl);
756-
struct_end += h.struct_len;
757-
758-
decode(h.owner_uid, bl);
759-
decode(h.owner_gid, bl);
760-
} else {
761-
/*
762-
* client is old: let's take caller_{u,g}id as owner_{u,g}id
763-
* this is how it worked before adding of owner_{u,g}id fields.
764-
*/
765-
h.owner_uid = h.caller_uid;
766-
h.owner_gid = h.caller_gid;
767-
}
768-
769-
/* add new fields handling here */
770-
771-
/*
772-
* From version 3 we have struct_len field.
773-
* It allows us to properly handle a case
774-
* when client send struct ceph_mds_request_head
775-
* bigger in size than MDS supports. In this
776-
* case we just want to skip all remaining bytes
777-
* at the end.
778-
*
779-
* See also DECODE_FINISH macro. Unfortunately,
780-
* we can't start using it right now as it will be
781-
* an incompatible protocol change.
782-
*/
783-
if (h.version >= 3) {
784-
if (bl.get_off() > struct_end)
785-
throw ::ceph::buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__));
786-
if (bl.get_off() < struct_end)
787-
bl += struct_end - bl.get_off();
788-
}
789-
}
688+
void encode(const struct ceph_mds_request_head& h, ceph::buffer::list& bl);
689+
void decode(struct ceph_mds_request_head& h, ceph::buffer::list::const_iterator& bl);
790690

791691
/* cap/lease release record */
792692
struct ceph_mds_request_release {

0 commit comments

Comments
 (0)