Skip to content

Commit bde5ae9

Browse files
authored
Merge pull request ceph#62948 from MaxKellermann/cephfs_includes
cephfs: include cleanup Reviewed-by: Venky Shankar <[email protected]>
2 parents 68b677b + 3679175 commit bde5ae9

File tree

17 files changed

+414
-326
lines changed

17 files changed

+414
-326
lines changed

ceph.spec.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,9 @@ fi
25592559
%{_includedir}/cephfs/types.h
25602560
%dir %{_includedir}/cephfs/metrics
25612561
%{_includedir}/cephfs/metrics/Types.h
2562+
%{_includedir}/cephfs/dump.h
2563+
%{_includedir}/cephfs/json.h
2564+
%{_includedir}/cephfs/keys_and_values.h
25622565
%{_libdir}/libcephfs.so
25632566
%{_libdir}/libcephfs_proxy.so
25642567
%{_libdir}/pkgconfig/cephfs.pc

debian/libcephfs-dev.install

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ usr/include/cephfs/ceph_ll_client.h
22
usr/include/cephfs/libcephfs.h
33
usr/include/cephfs/types.h
44
usr/include/cephfs/metrics/Types.h
5+
usr/include/cephfs/dump.h
6+
usr/include/cephfs/json.h
7+
usr/include/cephfs/keys_and_values.h
58
usr/lib/libcephfs.so
69
usr/lib/libcephfs_proxy.so
710
usr/lib/pkgconfig/cephfs.pc

src/client/Client.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ using namespace std::literals::string_view_literals;
114114
#include "posix_acl.h"
115115

116116
#include "include/ceph_assert.h"
117+
#include "include/cephfs/keys_and_values.h"
117118
#include "include/stat.h"
118119

119120
#include "include/cephfs/ceph_ll_client.h"

src/common/ceph_fs.cc

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,111 @@
77
/*
88
* Some non-inline ceph helpers
99
*/
10-
#include "include/types.h"
10+
11+
#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+
}
11115

12116
int ceph_flags_to_mode(int flags)
13117
{

src/common/fs_types.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
#include "common/ceph_json.h"
88
#include "include/denc.h"
99

10+
#include <iostream>
11+
12+
void inodeno_t::dump(ceph::Formatter *f) const {
13+
f->dump_unsigned("val", val);
14+
}
15+
16+
std::ostream& operator<<(std::ostream& out, const inodeno_t& ino) {
17+
return out << std::hex << "0x" << ino.val << std::dec;
18+
}
19+
1020
void dump(const ceph_file_layout& l, ceph::Formatter *f)
1121
{
1222
f->dump_unsigned("stripe_unit", l.fl_stripe_unit);

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)