]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MMDSSlaveRequest.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / messages / MMDSSlaveRequest.h
CommitLineData
7c673cae
FG
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_MMDSSLAVEREQUEST_H
17#define CEPH_MMDSSLAVEREQUEST_H
18
19#include "msg/Message.h"
20#include "mds/mdstypes.h"
21
9f95a23c
TL
22class MMDSSlaveRequest : public SafeMessage {
23 static constexpr int HEAD_VERSION = 1;
24 static constexpr int COMPAT_VERSION = 1;
11fdf7f2 25public:
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) {
7c673cae
FG
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;
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;
113
114 // for authpins
115 vector<MDSCacheObjectInfo> authpins;
116
117 public:
118 // for rename prep
119 filepath srcdnpath;
120 filepath destdnpath;
121 set<mds_rank_t> witnesses;
122 bufferlist inode_export;
123 version_t inode_export_v;
31f18b77 124 mds_rank_t srcdn_auth;
7c673cae
FG
125 utime_t op_stamp;
126
11fdf7f2
TL
127 mutable bufferlist straybl; // stray dir + dentry
128 bufferlist srci_snapbl;
129 bufferlist desti_snapbl;
7c673cae
FG
130
131public:
11fdf7f2 132 metareqid_t get_reqid() const { return reqid; }
7c673cae 133 __u32 get_attempt() const { return attempt; }
11fdf7f2
TL
134 int get_op() const { return op; }
135 bool is_reply() const { return op < 0; }
7c673cae 136
11fdf7f2
TL
137 int get_lock_type() const { return lock_type; }
138 const MDSCacheObjectInfo &get_object_info() const { return object_info; }
7c673cae 139 MDSCacheObjectInfo &get_object_info() { return object_info; }
11fdf7f2 140 const MDSCacheObjectInfo &get_authpin_freeze() const { return object_info; }
7c673cae
FG
141 MDSCacheObjectInfo &get_authpin_freeze() { return object_info; }
142
11fdf7f2 143 const vector<MDSCacheObjectInfo>& get_authpins() const { return authpins; }
7c673cae 144 vector<MDSCacheObjectInfo>& get_authpins() { return authpins; }
9f95a23c
TL
145 void mark_nonblocking() { flags |= FLAG_NONBLOCKING; }
146 bool is_nonblocking() const { return (flags & FLAG_NONBLOCKING); }
7c673cae 147 void mark_error_wouldblock() { flags |= FLAG_WOULDBLOCK; }
11fdf7f2 148 bool is_error_wouldblock() const { return (flags & FLAG_WOULDBLOCK); }
7c673cae 149 void mark_not_journaled() { flags |= FLAG_NOTJOURNALED; }
11fdf7f2 150 bool is_not_journaled() const { return (flags & FLAG_NOTJOURNALED); }
7c673cae 151 void mark_error_rofs() { flags |= FLAG_EROFS; }
11fdf7f2
TL
152 bool is_error_rofs() const { return (flags & FLAG_EROFS); }
153 bool is_abort() const { return (flags & FLAG_ABORT); }
7c673cae 154 void mark_abort() { flags |= FLAG_ABORT; }
11fdf7f2
TL
155 bool is_interrupted() const { return (flags & FLAG_INTERRUPTED); }
156 void mark_interrupted() const { flags |= FLAG_INTERRUPTED; }
9f95a23c
TL
157 bool should_notify_blocking() const { return (flags & FLAG_NOTIFYBLOCKING); }
158 void mark_notify_blocking() { flags |= FLAG_NOTIFYBLOCKING; }
159 void clear_notify_blocking() const { flags &= ~FLAG_NOTIFYBLOCKING; }
160 bool is_req_blocked() const { return (flags & FLAG_REQBLOCKED); }
161 void mark_req_blocked() { flags |= FLAG_REQBLOCKED; }
7c673cae
FG
162
163 void set_lock_type(int t) { lock_type = t; }
11fdf7f2
TL
164 const bufferlist& get_lock_data() const { return inode_export; }
165 bufferlist& get_lock_data() { return inode_export; }
7c673cae 166
11fdf7f2 167protected:
9f95a23c 168 MMDSSlaveRequest() : SafeMessage{MSG_MDS_SLAVE_REQUEST, HEAD_VERSION, COMPAT_VERSION} { }
7c673cae 169 MMDSSlaveRequest(metareqid_t ri, __u32 att, int o) :
9f95a23c 170 SafeMessage{MSG_MDS_SLAVE_REQUEST, HEAD_VERSION, COMPAT_VERSION},
7c673cae 171 reqid(ri), attempt(att), op(o), flags(0), lock_type(0),
31f18b77 172 inode_export_v(0), srcdn_auth(MDS_RANK_NONE) { }
7c673cae
FG
173 ~MMDSSlaveRequest() override {}
174
175public:
176 void encode_payload(uint64_t features) override {
11fdf7f2
TL
177 using ceph::encode;
178 encode(reqid, payload);
179 encode(attempt, payload);
180 encode(op, payload);
181 encode(flags, payload);
182 encode(lock_type, payload);
183 encode(object_info, payload);
184 encode(authpins, payload);
185 encode(srcdnpath, payload);
186 encode(destdnpath, payload);
187 encode(witnesses, payload);
188 encode(op_stamp, payload);
189 encode(inode_export, payload);
190 encode(inode_export_v, payload);
191 encode(srcdn_auth, payload);
192 encode(straybl, payload);
193 encode(srci_snapbl, payload);
194 encode(desti_snapbl, payload);
7c673cae
FG
195 }
196 void decode_payload() override {
11fdf7f2
TL
197 auto p = payload.cbegin();
198 decode(reqid, p);
199 decode(attempt, p);
200 decode(op, p);
201 decode(flags, p);
202 decode(lock_type, p);
203 decode(object_info, p);
204 decode(authpins, p);
205 decode(srcdnpath, p);
206 decode(destdnpath, p);
207 decode(witnesses, p);
208 decode(op_stamp, p);
209 decode(inode_export, p);
210 decode(inode_export_v, p);
211 decode(srcdn_auth, p);
212 decode(straybl, p);
213 decode(srci_snapbl, p);
214 decode(desti_snapbl, p);
7c673cae
FG
215 }
216
11fdf7f2 217 std::string_view get_type_name() const override { return "slave_request"; }
7c673cae
FG
218 void print(ostream& out) const override {
219 out << "slave_request(" << reqid
220 << "." << attempt
221 << " " << get_opname(op)
222 << ")";
223 }
9f95a23c
TL
224private:
225 template<class T, typename... Args>
226 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
7c673cae
FG
227};
228
229#endif