]>
Commit | Line | Data |
---|---|---|
f67539c2 | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
7c673cae FG |
2 | // vim: ts=8 sw=2 smarttab |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
f67539c2 | 10 | * License version 2.1, as published by the Free Software |
7c673cae | 11 | * Foundation. See file COPYING. |
f67539c2 | 12 | * |
7c673cae FG |
13 | */ |
14 | ||
15 | ||
f67539c2 TL |
16 | #ifndef CEPH_MMDSPEERREQUEST_H |
17 | #define CEPH_MMDSPEERREQUEST_H | |
7c673cae | 18 | |
7c673cae | 19 | #include "mds/mdstypes.h" |
f67539c2 | 20 | #include "messages/MMDSOp.h" |
7c673cae | 21 | |
f67539c2 | 22 | class MMDSPeerRequest final : public MMDSOp { |
9f95a23c TL |
23 | static constexpr int HEAD_VERSION = 1; |
24 | static constexpr int COMPAT_VERSION = 1; | |
11fdf7f2 | 25 | public: |
11fdf7f2 TL |
26 | static constexpr int OP_XLOCK = 1; |
27 | static constexpr int OP_XLOCKACK = -1; | |
28 | static constexpr int OP_UNXLOCK = 2; | |
29 | static constexpr int OP_AUTHPIN = 3; | |
30 | static constexpr int OP_AUTHPINACK = -3; | |
7c673cae | 31 | |
11fdf7f2 TL |
32 | static constexpr int OP_LINKPREP = 4; |
33 | static constexpr int OP_UNLINKPREP = 5; | |
34 | static constexpr int OP_LINKPREPACK = -4; | |
7c673cae | 35 | |
11fdf7f2 TL |
36 | static constexpr int OP_RENAMEPREP = 7; |
37 | static constexpr int OP_RENAMEPREPACK = -7; | |
7c673cae | 38 | |
11fdf7f2 TL |
39 | static constexpr int OP_WRLOCK = 8; |
40 | static constexpr int OP_WRLOCKACK = -8; | |
41 | static constexpr int OP_UNWRLOCK = 9; | |
7c673cae | 42 | |
11fdf7f2 TL |
43 | static constexpr int OP_RMDIRPREP = 10; |
44 | static constexpr int OP_RMDIRPREPACK = -10; | |
7c673cae | 45 | |
11fdf7f2 | 46 | static constexpr int OP_DROPLOCKS = 11; |
7c673cae | 47 | |
11fdf7f2 TL |
48 | static constexpr int OP_RENAMENOTIFY = 12; |
49 | static constexpr int OP_RENAMENOTIFYACK = -12; | |
7c673cae | 50 | |
11fdf7f2 TL |
51 | static constexpr int OP_FINISH = 17; |
52 | static constexpr int OP_COMMITTED = -18; | |
7c673cae | 53 | |
11fdf7f2 TL |
54 | static constexpr int OP_ABORT = 20; // used for recovery only |
55 | //static constexpr int OP_COMMIT = 21; // used for recovery only | |
7c673cae | 56 | |
11fdf7f2 TL |
57 | |
58 | static const char *get_opname(int o) { | |
f67539c2 | 59 | switch (o) { |
7c673cae FG |
60 | case OP_XLOCK: return "xlock"; |
61 | case OP_XLOCKACK: return "xlock_ack"; | |
62 | case OP_UNXLOCK: return "unxlock"; | |
63 | case OP_AUTHPIN: return "authpin"; | |
64 | case OP_AUTHPINACK: return "authpin_ack"; | |
65 | ||
66 | case OP_LINKPREP: return "link_prep"; | |
67 | case OP_LINKPREPACK: return "link_prep_ack"; | |
68 | case OP_UNLINKPREP: return "unlink_prep"; | |
69 | ||
70 | case OP_RENAMEPREP: return "rename_prep"; | |
71 | case OP_RENAMEPREPACK: return "rename_prep_ack"; | |
72 | ||
73 | case OP_FINISH: return "finish"; // commit | |
74 | case OP_COMMITTED: return "committed"; | |
75 | ||
76 | case OP_WRLOCK: return "wrlock"; | |
77 | case OP_WRLOCKACK: return "wrlock_ack"; | |
78 | case OP_UNWRLOCK: return "unwrlock"; | |
79 | ||
80 | case OP_RMDIRPREP: return "rmdir_prep"; | |
81 | case OP_RMDIRPREPACK: return "rmdir_prep_ack"; | |
82 | ||
83 | case OP_DROPLOCKS: return "drop_locks"; | |
84 | ||
85 | case OP_RENAMENOTIFY: return "rename_notify"; | |
86 | case OP_RENAMENOTIFYACK: return "rename_notify_ack"; | |
87 | ||
88 | case OP_ABORT: return "abort"; | |
89 | //case OP_COMMIT: return "commit"; | |
90 | ||
91 | default: ceph_abort(); return 0; | |
92 | } | |
93 | } | |
94 | ||
95 | private: | |
96 | metareqid_t reqid; | |
97 | __u32 attempt; | |
98 | __s16 op; | |
11fdf7f2 | 99 | mutable __u16 flags; /* XXX HACK for mark_interrupted */ |
7c673cae | 100 | |
9f95a23c TL |
101 | static constexpr unsigned FLAG_NONBLOCKING = 1<<0; |
102 | static constexpr unsigned FLAG_WOULDBLOCK = 1<<1; | |
103 | static constexpr unsigned FLAG_NOTJOURNALED = 1<<2; | |
104 | static constexpr unsigned FLAG_EROFS = 1<<3; | |
105 | static constexpr unsigned FLAG_ABORT = 1<<4; | |
106 | static constexpr unsigned FLAG_INTERRUPTED = 1<<5; | |
107 | static constexpr unsigned FLAG_NOTIFYBLOCKING = 1<<6; | |
108 | static constexpr unsigned FLAG_REQBLOCKED = 1<<7; | |
7c673cae FG |
109 | |
110 | // for locking | |
111 | __u16 lock_type; // lock object type | |
112 | MDSCacheObjectInfo object_info; | |
f67539c2 | 113 | |
7c673cae | 114 | // for authpins |
f67539c2 | 115 | std::vector<MDSCacheObjectInfo> authpins; |
7c673cae FG |
116 | |
117 | public: | |
118 | // for rename prep | |
119 | filepath srcdnpath; | |
120 | filepath destdnpath; | |
f67539c2 TL |
121 | std::string alternate_name; |
122 | std::set<mds_rank_t> witnesses; | |
123 | ceph::buffer::list inode_export; | |
7c673cae | 124 | version_t inode_export_v; |
31f18b77 | 125 | mds_rank_t srcdn_auth; |
7c673cae FG |
126 | utime_t op_stamp; |
127 | ||
f67539c2 TL |
128 | mutable ceph::buffer::list straybl; // stray dir + dentry |
129 | ceph::buffer::list srci_snapbl; | |
130 | ceph::buffer::list desti_snapbl; | |
7c673cae FG |
131 | |
132 | public: | |
11fdf7f2 | 133 | metareqid_t get_reqid() const { return reqid; } |
7c673cae | 134 | __u32 get_attempt() const { return attempt; } |
11fdf7f2 TL |
135 | int get_op() const { return op; } |
136 | bool is_reply() const { return op < 0; } | |
7c673cae | 137 | |
11fdf7f2 TL |
138 | int get_lock_type() const { return lock_type; } |
139 | const MDSCacheObjectInfo &get_object_info() const { return object_info; } | |
7c673cae | 140 | MDSCacheObjectInfo &get_object_info() { return object_info; } |
11fdf7f2 | 141 | const MDSCacheObjectInfo &get_authpin_freeze() const { return object_info; } |
7c673cae FG |
142 | MDSCacheObjectInfo &get_authpin_freeze() { return object_info; } |
143 | ||
f67539c2 TL |
144 | const std::vector<MDSCacheObjectInfo>& get_authpins() const { return authpins; } |
145 | std::vector<MDSCacheObjectInfo>& get_authpins() { return authpins; } | |
9f95a23c TL |
146 | void mark_nonblocking() { flags |= FLAG_NONBLOCKING; } |
147 | bool is_nonblocking() const { return (flags & FLAG_NONBLOCKING); } | |
7c673cae | 148 | void mark_error_wouldblock() { flags |= FLAG_WOULDBLOCK; } |
11fdf7f2 | 149 | bool is_error_wouldblock() const { return (flags & FLAG_WOULDBLOCK); } |
7c673cae | 150 | void mark_not_journaled() { flags |= FLAG_NOTJOURNALED; } |
11fdf7f2 | 151 | bool is_not_journaled() const { return (flags & FLAG_NOTJOURNALED); } |
7c673cae | 152 | void mark_error_rofs() { flags |= FLAG_EROFS; } |
11fdf7f2 TL |
153 | bool is_error_rofs() const { return (flags & FLAG_EROFS); } |
154 | bool is_abort() const { return (flags & FLAG_ABORT); } | |
7c673cae | 155 | void mark_abort() { flags |= FLAG_ABORT; } |
11fdf7f2 TL |
156 | bool is_interrupted() const { return (flags & FLAG_INTERRUPTED); } |
157 | void mark_interrupted() const { flags |= FLAG_INTERRUPTED; } | |
9f95a23c TL |
158 | bool should_notify_blocking() const { return (flags & FLAG_NOTIFYBLOCKING); } |
159 | void mark_notify_blocking() { flags |= FLAG_NOTIFYBLOCKING; } | |
160 | void clear_notify_blocking() const { flags &= ~FLAG_NOTIFYBLOCKING; } | |
161 | bool is_req_blocked() const { return (flags & FLAG_REQBLOCKED); } | |
162 | void mark_req_blocked() { flags |= FLAG_REQBLOCKED; } | |
7c673cae FG |
163 | |
164 | void set_lock_type(int t) { lock_type = t; } | |
f67539c2 TL |
165 | const ceph::buffer::list& get_lock_data() const { return inode_export; } |
166 | ceph::buffer::list& get_lock_data() { return inode_export; } | |
7c673cae | 167 | |
11fdf7f2 | 168 | protected: |
f67539c2 TL |
169 | MMDSPeerRequest() : MMDSOp{MSG_MDS_PEER_REQUEST, HEAD_VERSION, COMPAT_VERSION} { } |
170 | MMDSPeerRequest(metareqid_t ri, __u32 att, int o) : | |
171 | MMDSOp{MSG_MDS_PEER_REQUEST, HEAD_VERSION, COMPAT_VERSION}, | |
7c673cae | 172 | reqid(ri), attempt(att), op(o), flags(0), lock_type(0), |
31f18b77 | 173 | inode_export_v(0), srcdn_auth(MDS_RANK_NONE) { } |
f67539c2 | 174 | ~MMDSPeerRequest() final {} |
7c673cae FG |
175 | |
176 | public: | |
177 | void encode_payload(uint64_t features) override { | |
11fdf7f2 TL |
178 | using ceph::encode; |
179 | encode(reqid, payload); | |
180 | encode(attempt, payload); | |
181 | encode(op, payload); | |
182 | encode(flags, payload); | |
183 | encode(lock_type, payload); | |
184 | encode(object_info, payload); | |
185 | encode(authpins, payload); | |
186 | encode(srcdnpath, payload); | |
187 | encode(destdnpath, payload); | |
188 | encode(witnesses, payload); | |
189 | encode(op_stamp, payload); | |
190 | encode(inode_export, payload); | |
191 | encode(inode_export_v, payload); | |
192 | encode(srcdn_auth, payload); | |
193 | encode(straybl, payload); | |
194 | encode(srci_snapbl, payload); | |
195 | encode(desti_snapbl, payload); | |
f67539c2 | 196 | encode(alternate_name, payload); |
7c673cae FG |
197 | } |
198 | void decode_payload() override { | |
f67539c2 | 199 | using ceph::decode; |
11fdf7f2 TL |
200 | auto p = payload.cbegin(); |
201 | decode(reqid, p); | |
202 | decode(attempt, p); | |
203 | decode(op, p); | |
204 | decode(flags, p); | |
205 | decode(lock_type, p); | |
206 | decode(object_info, p); | |
207 | decode(authpins, p); | |
208 | decode(srcdnpath, p); | |
209 | decode(destdnpath, p); | |
210 | decode(witnesses, p); | |
211 | decode(op_stamp, p); | |
212 | decode(inode_export, p); | |
213 | decode(inode_export_v, p); | |
214 | decode(srcdn_auth, p); | |
215 | decode(straybl, p); | |
216 | decode(srci_snapbl, p); | |
217 | decode(desti_snapbl, p); | |
f67539c2 | 218 | decode(alternate_name, p); |
7c673cae FG |
219 | } |
220 | ||
f67539c2 TL |
221 | std::string_view get_type_name() const override { return "peer_request"; } |
222 | void print(std::ostream& out) const override { | |
223 | out << "peer_request(" << reqid | |
7c673cae | 224 | << "." << attempt |
f67539c2 | 225 | << " " << get_opname(op) |
7c673cae | 226 | << ")"; |
f67539c2 | 227 | } |
9f95a23c TL |
228 | private: |
229 | template<class T, typename... Args> | |
f67539c2 | 230 | friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); |
20effc67 TL |
231 | template<class T, typename... Args> |
232 | friend MURef<T> crimson::make_message(Args&&... args); | |
7c673cae FG |
233 | }; |
234 | ||
235 | #endif |