1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
16 #ifndef CEPH_MMDSSLAVEREQUEST_H
17 #define CEPH_MMDSSLAVEREQUEST_H
19 #include "msg/Message.h"
20 #include "mds/mdstypes.h"
22 class MMDSSlaveRequest : public Message {
24 static const int OP_XLOCK = 1;
25 static const int OP_XLOCKACK = -1;
26 static const int OP_UNXLOCK = 2;
27 static const int OP_AUTHPIN = 3;
28 static const int OP_AUTHPINACK = -3;
30 static const int OP_LINKPREP = 4;
31 static const int OP_UNLINKPREP = 5;
32 static const int OP_LINKPREPACK = -4;
34 static const int OP_RENAMEPREP = 7;
35 static const int OP_RENAMEPREPACK = -7;
37 static const int OP_WRLOCK = 8;
38 static const int OP_WRLOCKACK = -8;
39 static const int OP_UNWRLOCK = 9;
41 static const int OP_RMDIRPREP = 10;
42 static const int OP_RMDIRPREPACK = -10;
44 static const int OP_DROPLOCKS = 11;
46 static const int OP_RENAMENOTIFY = 12;
47 static const int OP_RENAMENOTIFYACK = -12;
49 static const int OP_FINISH = 17;
50 static const int OP_COMMITTED = -18;
52 static const int OP_ABORT = 20; // used for recovery only
53 //static const int OP_COMMIT = 21; // used for recovery only
56 const static char *get_opname(int o) {
58 case OP_XLOCK: return "xlock";
59 case OP_XLOCKACK: return "xlock_ack";
60 case OP_UNXLOCK: return "unxlock";
61 case OP_AUTHPIN: return "authpin";
62 case OP_AUTHPINACK: return "authpin_ack";
64 case OP_LINKPREP: return "link_prep";
65 case OP_LINKPREPACK: return "link_prep_ack";
66 case OP_UNLINKPREP: return "unlink_prep";
68 case OP_RENAMEPREP: return "rename_prep";
69 case OP_RENAMEPREPACK: return "rename_prep_ack";
71 case OP_FINISH: return "finish"; // commit
72 case OP_COMMITTED: return "committed";
74 case OP_WRLOCK: return "wrlock";
75 case OP_WRLOCKACK: return "wrlock_ack";
76 case OP_UNWRLOCK: return "unwrlock";
78 case OP_RMDIRPREP: return "rmdir_prep";
79 case OP_RMDIRPREPACK: return "rmdir_prep_ack";
81 case OP_DROPLOCKS: return "drop_locks";
83 case OP_RENAMENOTIFY: return "rename_notify";
84 case OP_RENAMENOTIFYACK: return "rename_notify_ack";
86 case OP_ABORT: return "abort";
87 //case OP_COMMIT: return "commit";
89 default: ceph_abort(); return 0;
99 static const unsigned FLAG_NONBLOCK = 1<<0;
100 static const unsigned FLAG_WOULDBLOCK = 1<<1;
101 static const unsigned FLAG_NOTJOURNALED = 1<<2;
102 static const unsigned FLAG_EROFS = 1<<3;
103 static const unsigned FLAG_ABORT = 1<<4;
104 static const unsigned FLAG_INTERRUPTED = 1<<5;
107 __u16 lock_type; // lock object type
108 MDSCacheObjectInfo object_info;
111 vector<MDSCacheObjectInfo> authpins;
117 set<mds_rank_t> witnesses;
118 bufferlist inode_export;
119 version_t inode_export_v;
120 bufferlist srci_replica;
121 mds_rank_t srcdn_auth;
124 bufferlist stray; // stray dir + dentry
127 metareqid_t get_reqid() { return reqid; }
128 __u32 get_attempt() const { return attempt; }
129 int get_op() { return op; }
130 bool is_reply() { return op < 0; }
132 int get_lock_type() { return lock_type; }
133 MDSCacheObjectInfo &get_object_info() { return object_info; }
134 MDSCacheObjectInfo &get_authpin_freeze() { return object_info; }
136 vector<MDSCacheObjectInfo>& get_authpins() { return authpins; }
137 void mark_nonblock() { flags |= FLAG_NONBLOCK; }
138 bool is_nonblock() { return (flags & FLAG_NONBLOCK); }
139 void mark_error_wouldblock() { flags |= FLAG_WOULDBLOCK; }
140 bool is_error_wouldblock() { return (flags & FLAG_WOULDBLOCK); }
141 void mark_not_journaled() { flags |= FLAG_NOTJOURNALED; }
142 bool is_not_journaled() { return (flags & FLAG_NOTJOURNALED); }
143 void mark_error_rofs() { flags |= FLAG_EROFS; }
144 bool is_error_rofs() { return (flags & FLAG_EROFS); }
145 bool is_abort() { return (flags & FLAG_ABORT); }
146 void mark_abort() { flags |= FLAG_ABORT; }
147 bool is_interrupted() { return (flags & FLAG_INTERRUPTED); }
148 void mark_interrupted() { flags |= FLAG_INTERRUPTED; }
150 void set_lock_type(int t) { lock_type = t; }
154 MMDSSlaveRequest() : Message(MSG_MDS_SLAVE_REQUEST) { }
155 MMDSSlaveRequest(metareqid_t ri, __u32 att, int o) :
156 Message(MSG_MDS_SLAVE_REQUEST),
157 reqid(ri), attempt(att), op(o), flags(0), lock_type(0),
158 inode_export_v(0), srcdn_auth(MDS_RANK_NONE) { }
160 ~MMDSSlaveRequest() override {}
163 void encode_payload(uint64_t features) override {
164 ::encode(reqid, payload);
165 ::encode(attempt, payload);
166 ::encode(op, payload);
167 ::encode(flags, payload);
168 ::encode(lock_type, payload);
169 ::encode(object_info, payload);
170 ::encode(authpins, payload);
171 ::encode(srcdnpath, payload);
172 ::encode(destdnpath, payload);
173 ::encode(witnesses, payload);
174 ::encode(op_stamp, payload);
175 ::encode(inode_export, payload);
176 ::encode(inode_export_v, payload);
177 ::encode(srcdn_auth, payload);
178 ::encode(srci_replica, payload);
179 ::encode(stray, payload);
181 void decode_payload() override {
182 bufferlist::iterator p = payload.begin();
184 ::decode(attempt, p);
187 ::decode(lock_type, p);
188 ::decode(object_info, p);
189 ::decode(authpins, p);
190 ::decode(srcdnpath, p);
191 ::decode(destdnpath, p);
192 ::decode(witnesses, p);
193 ::decode(op_stamp, p);
194 ::decode(inode_export, p);
195 ::decode(inode_export_v, p);
196 ::decode(srcdn_auth, p);
197 ::decode(srci_replica, p);
201 const char *get_type_name() const override { return "slave_request"; }
202 void print(ostream& out) const override {
203 out << "slave_request(" << reqid
205 << " " << get_opname(op)