]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMDSPeerRequest.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / messages / MMDSPeerRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
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
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15
16 #ifndef CEPH_MMDSPEERREQUEST_H
17 #define CEPH_MMDSPEERREQUEST_H
18
19 #include "mds/mdstypes.h"
20 #include "messages/MMDSOp.h"
21
22 class MMDSPeerRequest final : public MMDSOp {
23 static constexpr int HEAD_VERSION = 1;
24 static constexpr int COMPAT_VERSION = 1;
25 public:
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;
31
32 static constexpr int OP_LINKPREP = 4;
33 static constexpr int OP_UNLINKPREP = 5;
34 static constexpr int OP_LINKPREPACK = -4;
35
36 static constexpr int OP_RENAMEPREP = 7;
37 static constexpr int OP_RENAMEPREPACK = -7;
38
39 static constexpr int OP_WRLOCK = 8;
40 static constexpr int OP_WRLOCKACK = -8;
41 static constexpr int OP_UNWRLOCK = 9;
42
43 static constexpr int OP_RMDIRPREP = 10;
44 static constexpr int OP_RMDIRPREPACK = -10;
45
46 static constexpr int OP_DROPLOCKS = 11;
47
48 static constexpr int OP_RENAMENOTIFY = 12;
49 static constexpr int OP_RENAMENOTIFYACK = -12;
50
51 static constexpr int OP_FINISH = 17;
52 static constexpr int OP_COMMITTED = -18;
53
54 static constexpr int OP_ABORT = 20; // used for recovery only
55 //static constexpr int OP_COMMIT = 21; // used for recovery only
56
57
58 static const char *get_opname(int o) {
59 switch (o) {
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;
99 mutable __u16 flags; /* XXX HACK for mark_interrupted */
100
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;
109
110 // for locking
111 __u16 lock_type; // lock object type
112 MDSCacheObjectInfo object_info;
113
114 // for authpins
115 std::vector<MDSCacheObjectInfo> authpins;
116
117 public:
118 // for rename prep
119 filepath srcdnpath;
120 filepath destdnpath;
121 std::string alternate_name;
122 std::set<mds_rank_t> witnesses;
123 ceph::buffer::list inode_export;
124 version_t inode_export_v;
125 mds_rank_t srcdn_auth;
126 utime_t op_stamp;
127
128 mutable ceph::buffer::list straybl; // stray dir + dentry
129 ceph::buffer::list srci_snapbl;
130 ceph::buffer::list desti_snapbl;
131
132 public:
133 metareqid_t get_reqid() const { return reqid; }
134 __u32 get_attempt() const { return attempt; }
135 int get_op() const { return op; }
136 bool is_reply() const { return op < 0; }
137
138 int get_lock_type() const { return lock_type; }
139 const MDSCacheObjectInfo &get_object_info() const { return object_info; }
140 MDSCacheObjectInfo &get_object_info() { return object_info; }
141 const MDSCacheObjectInfo &get_authpin_freeze() const { return object_info; }
142 MDSCacheObjectInfo &get_authpin_freeze() { return object_info; }
143
144 const std::vector<MDSCacheObjectInfo>& get_authpins() const { return authpins; }
145 std::vector<MDSCacheObjectInfo>& get_authpins() { return authpins; }
146 void mark_nonblocking() { flags |= FLAG_NONBLOCKING; }
147 bool is_nonblocking() const { return (flags & FLAG_NONBLOCKING); }
148 void mark_error_wouldblock() { flags |= FLAG_WOULDBLOCK; }
149 bool is_error_wouldblock() const { return (flags & FLAG_WOULDBLOCK); }
150 void mark_not_journaled() { flags |= FLAG_NOTJOURNALED; }
151 bool is_not_journaled() const { return (flags & FLAG_NOTJOURNALED); }
152 void mark_error_rofs() { flags |= FLAG_EROFS; }
153 bool is_error_rofs() const { return (flags & FLAG_EROFS); }
154 bool is_abort() const { return (flags & FLAG_ABORT); }
155 void mark_abort() { flags |= FLAG_ABORT; }
156 bool is_interrupted() const { return (flags & FLAG_INTERRUPTED); }
157 void mark_interrupted() const { flags |= FLAG_INTERRUPTED; }
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; }
163
164 void set_lock_type(int t) { lock_type = t; }
165 const ceph::buffer::list& get_lock_data() const { return inode_export; }
166 ceph::buffer::list& get_lock_data() { return inode_export; }
167
168 protected:
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},
172 reqid(ri), attempt(att), op(o), flags(0), lock_type(0),
173 inode_export_v(0), srcdn_auth(MDS_RANK_NONE) { }
174 ~MMDSPeerRequest() final {}
175
176 public:
177 void encode_payload(uint64_t features) override {
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);
196 encode(alternate_name, payload);
197 }
198 void decode_payload() override {
199 using ceph::decode;
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);
218 decode(alternate_name, p);
219 }
220
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
224 << "." << attempt
225 << " " << get_opname(op)
226 << ")";
227 }
228 private:
229 template<class T, typename... Args>
230 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
231 template<class T, typename... Args>
232 friend MURef<T> crimson::make_message(Args&&... args);
233 };
234
235 #endif