]> git.proxmox.com Git - ceph.git/blob - ceph/src/client/MetaRequest.h
import ceph quincy 17.2.4
[ceph.git] / ceph / src / client / MetaRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_CLIENT_METAREQUEST_H
5 #define CEPH_CLIENT_METAREQUEST_H
6
7
8 #include "include/types.h"
9 #include "include/xlist.h"
10 #include "include/filepath.h"
11 #include "mds/mdstypes.h"
12 #include "InodeRef.h"
13 #include "UserPerm.h"
14
15 #include "messages/MClientRequest.h"
16 #include "messages/MClientReply.h"
17
18 class Dentry;
19 class dir_result_t;
20
21 struct MetaRequest {
22 private:
23 InodeRef _inode, _old_inode, _other_inode;
24 Dentry *_dentry = NULL; //associated with path
25 Dentry *_old_dentry = NULL; //associated with path2
26 int abort_rc = 0;
27 public:
28 ceph::coarse_mono_time created = ceph::coarse_mono_clock::zero();
29 uint64_t tid = 0;
30 utime_t op_stamp;
31 ceph_mds_request_head head;
32 filepath path, path2;
33 std::string alternate_name;
34 bufferlist data;
35 int inode_drop = 0; //the inode caps this operation will drop
36 int inode_unless = 0; //unless we have these caps already
37 int old_inode_drop = 0, old_inode_unless = 0;
38 int dentry_drop = 0, dentry_unless = 0;
39 int old_dentry_drop = 0, old_dentry_unless = 0;
40 int other_inode_drop = 0, other_inode_unless = 0;
41 std::vector<MClientRequest::Release> cap_releases;
42
43 int regetattr_mask = 0; // getattr mask if i need to re-stat after a traceless reply
44
45 utime_t sent_stamp;
46 mds_rank_t mds = -1; // who i am asking
47 mds_rank_t resend_mds = -1; // someone wants you to (re)send the request here
48 bool send_to_auth = false; // must send to auth mds
49 __u32 sent_on_mseq = 0; // mseq at last submission of this request
50 int num_fwd = 0; // # of times i've been forwarded
51 int retry_attempt = 0;
52 std::atomic<uint64_t> ref = { 1 };
53
54 ceph::cref_t<MClientReply> reply = NULL; // the reply
55 bool kick = false;
56 bool success = false;
57
58 // readdir result
59 dir_result_t *dirp = NULL;
60
61 //possible responses
62 bool got_unsafe = false;
63
64 xlist<MetaRequest*>::item item;
65 xlist<MetaRequest*>::item unsafe_item;
66 xlist<MetaRequest*>::item unsafe_dir_item;
67 xlist<MetaRequest*>::item unsafe_target_item;
68
69 ceph::condition_variable *caller_cond = NULL; // who to take up
70 ceph::condition_variable *dispatch_cond = NULL; // who to kick back
71 std::list<ceph::condition_variable*> waitfor_safe;
72
73 InodeRef target;
74 UserPerm perms;
75
76 explicit MetaRequest(int op) :
77 item(this), unsafe_item(this), unsafe_dir_item(this),
78 unsafe_target_item(this) {
79 memset(&head, 0, sizeof(head));
80 head.op = op;
81 }
82 ~MetaRequest();
83
84 /**
85 * Prematurely terminate the request, such that callers
86 * to make_request will receive `rc` as their result.
87 */
88 void abort(int rc)
89 {
90 ceph_assert(rc != 0);
91 abort_rc = rc;
92 }
93
94 /**
95 * Whether abort() has been called for this request
96 */
97 inline bool aborted() const
98 {
99 return abort_rc != 0;
100 }
101
102 /**
103 * Given that abort() has been called for this request, what `rc` was
104 * passed into it?
105 */
106 int get_abort_code() const
107 {
108 return abort_rc;
109 }
110
111 void set_inode(Inode *in) {
112 _inode = in;
113 }
114 Inode *inode() {
115 return _inode.get();
116 }
117 void take_inode(InodeRef *out) {
118 out->swap(_inode);
119 }
120 void set_old_inode(Inode *in) {
121 _old_inode = in;
122 }
123 Inode *old_inode() {
124 return _old_inode.get();
125 }
126 void take_old_inode(InodeRef *out) {
127 out->swap(_old_inode);
128 }
129 void set_other_inode(Inode *in) {
130 _other_inode = in;
131 }
132 Inode *other_inode() {
133 return _other_inode.get();
134 }
135 void take_other_inode(InodeRef *out) {
136 out->swap(_other_inode);
137 }
138 void set_dentry(Dentry *d);
139 Dentry *dentry();
140 void set_old_dentry(Dentry *d);
141 Dentry *old_dentry();
142
143 MetaRequest* get() {
144 ref++;
145 return this;
146 }
147
148 /// psuedo-private put method; use Client::put_request()
149 bool _put() {
150 int v = --ref;
151 return v == 0;
152 }
153
154 // normal fields
155 void set_tid(ceph_tid_t t) { tid = t; }
156 void set_oldest_client_tid(ceph_tid_t t) { head.oldest_client_tid = t; }
157 void inc_num_fwd() { head.num_fwd = head.num_fwd + 1; }
158 void set_retry_attempt(int a) { head.num_retry = a; }
159 void set_filepath(const filepath& fp) { path = fp; }
160 void set_filepath2(const filepath& fp) { path2 = fp; }
161 void set_alternate_name(std::string an) { alternate_name = an; }
162 void set_string2(const char *s) { path2.set_path(std::string_view(s), 0); }
163 void set_caller_perms(const UserPerm& _perms) {
164 perms.shallow_copy(_perms);
165 head.caller_uid = perms.uid();
166 head.caller_gid = perms.gid();
167 }
168 uid_t get_uid() { return perms.uid(); }
169 uid_t get_gid() { return perms.gid(); }
170 void set_data(const bufferlist &d) { data = d; }
171 void set_dentry_wanted() {
172 head.flags = head.flags | CEPH_MDS_FLAG_WANT_DENTRY;
173 }
174 int get_op() { return head.op; }
175 ceph_tid_t get_tid() { return tid; }
176 filepath& get_filepath() { return path; }
177 filepath& get_filepath2() { return path2; }
178
179 bool is_write() {
180 return
181 (head.op & CEPH_MDS_OP_WRITE) ||
182 (head.op == CEPH_MDS_OP_OPEN && (head.args.open.flags & (O_CREAT|O_TRUNC)));
183 }
184 bool can_forward() {
185 if ((head.op & CEPH_MDS_OP_WRITE) ||
186 head.op == CEPH_MDS_OP_OPEN) // do not forward _any_ open request.
187 return false;
188 return true;
189 }
190 bool auth_is_best(int issued) {
191 if (send_to_auth)
192 return true;
193
194 /* Any write op ? */
195 if (head.op & CEPH_MDS_OP_WRITE)
196 return true;
197
198 switch (head.op) {
199 case CEPH_MDS_OP_OPEN:
200 case CEPH_MDS_OP_READDIR:
201 return true;
202 case CEPH_MDS_OP_GETATTR:
203 /*
204 * If any 'x' caps is issued we can just choose the auth MDS
205 * instead of the random replica MDSes. Because only when the
206 * Locker is in LOCK_EXEC state will the loner client could
207 * get the 'x' caps. And if we send the getattr requests to
208 * any replica MDS it must auth pin and tries to rdlock from
209 * the auth MDS, and then the auth MDS need to do the Locker
210 * state transition to LOCK_SYNC. And after that the lock state
211 * will change back.
212 *
213 * This cost much when doing the Locker state transition and
214 * usually will need to revoke caps from clients.
215 *
216 * And for the 'Xs' caps for getxattr we will also choose the
217 * auth MDS, because the MDS side code is buggy due to setxattr
218 * won't notify the replica MDSes when the values changed and
219 * the replica MDS will return the old values. Though we will
220 * fix it in MDS code, but this still makes sense for old ceph.
221 */
222 if (((head.args.getattr.mask & CEPH_CAP_ANY_SHARED) &&
223 (issued & CEPH_CAP_ANY_EXCL)) ||
224 (head.args.getattr.mask & (CEPH_STAT_RSTAT | CEPH_STAT_CAP_XATTR)))
225 return true;
226 default:
227 return false;
228 }
229 }
230
231 void dump(Formatter *f) const;
232
233 };
234
235 #endif