Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mds / events / ESlaveUpdate.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 #ifndef CEPH_MDS_ESLAVEUPDATE_H
16 #define CEPH_MDS_ESLAVEUPDATE_H
17
18 #include "../LogEvent.h"
19 #include "EMetaBlob.h"
20
21 /*
22  * rollback records, for remote/slave updates, which may need to be manually
23  * rolled back during journal replay.  (or while active if master fails, but in 
24  * that case these records aren't needed.)
25  */ 
26 struct link_rollback {
27   metareqid_t reqid;
28   inodeno_t ino;
29   bool was_inc;
30   utime_t old_ctime;
31   utime_t old_dir_mtime;
32   utime_t old_dir_rctime;
33
34   link_rollback() : ino(0), was_inc(false) {}
35
36   void encode(bufferlist& bl) const;
37   void decode(bufferlist::iterator& bl);
38   void dump(Formatter *f) const;
39   static void generate_test_instances(list<link_rollback*>& ls);
40 };
41 WRITE_CLASS_ENCODER(link_rollback)
42
43 /*
44  * this is only used on an empty dir with a dirfrag on a remote node.
45  * we are auth for nothing.  all we need to do is relink the directory
46  * in the hierarchy properly during replay to avoid breaking the
47  * subtree map.
48  */
49 struct rmdir_rollback {
50   metareqid_t reqid;
51   dirfrag_t src_dir;
52   string src_dname;
53   dirfrag_t dest_dir;
54   string dest_dname;
55
56   void encode(bufferlist& bl) const;
57   void decode(bufferlist::iterator& bl);
58   void dump(Formatter *f) const;
59   static void generate_test_instances(list<rmdir_rollback*>& ls);
60 };
61 WRITE_CLASS_ENCODER(rmdir_rollback)
62
63 struct rename_rollback {
64   struct drec {
65     dirfrag_t dirfrag;
66     utime_t dirfrag_old_mtime;
67     utime_t dirfrag_old_rctime;
68     inodeno_t ino, remote_ino;
69     string dname;
70     char remote_d_type;
71     utime_t old_ctime;
72     
73     drec() : remote_d_type((char)S_IFREG) {}
74
75     void encode(bufferlist& bl) const;
76     void decode(bufferlist::iterator& bl);
77     void dump(Formatter *f) const;
78     static void generate_test_instances(list<drec*>& ls);
79   };
80   WRITE_CLASS_MEMBER_ENCODER(drec)
81
82   metareqid_t reqid;
83   drec orig_src, orig_dest;
84   drec stray; // we know this is null, but we want dname, old mtime/rctime
85   utime_t ctime;
86
87   void encode(bufferlist& bl) const;
88   void decode(bufferlist::iterator& bl);
89   void dump(Formatter *f) const;
90   static void generate_test_instances(list<rename_rollback*>& ls);
91 };
92 WRITE_CLASS_ENCODER(rename_rollback::drec)
93 WRITE_CLASS_ENCODER(rename_rollback)
94
95
96 class ESlaveUpdate : public LogEvent {
97 public:
98   const static int OP_PREPARE = 1;
99   const static int OP_COMMIT = 2;
100   const static int OP_ROLLBACK = 3;
101   
102   const static int LINK = 1;
103   const static int RENAME = 2;
104   const static int RMDIR = 3;
105
106   /*
107    * we journal a rollback metablob that contains the unmodified metadata
108    * too, because we may be updating previously dirty metadata, which 
109    * will allow old log segments to be trimmed.  if we end of rolling back,
110    * those updates could be lost.. so we re-journal the unmodified metadata,
111    * and replay will apply _either_ commit or rollback.
112    */
113   EMetaBlob commit;
114   bufferlist rollback;
115   string type;
116   metareqid_t reqid;
117   mds_rank_t master;
118   __u8 op;  // prepare, commit, abort
119   __u8 origop; // link | rename
120
121   ESlaveUpdate() : LogEvent(EVENT_SLAVEUPDATE), master(0), op(0), origop(0) { }
122   ESlaveUpdate(MDLog *mdlog, const char *s, metareqid_t ri, int mastermds, int o, int oo) : 
123     LogEvent(EVENT_SLAVEUPDATE), commit(mdlog), 
124     type(s),
125     reqid(ri),
126     master(mastermds),
127     op(o), origop(oo) { }
128   
129   void print(ostream& out) const override {
130     if (type.length())
131       out << type << " ";
132     out << " " << (int)op;
133     if (origop == LINK) out << " link";
134     if (origop == RENAME) out << " rename";
135     out << " " << reqid;
136     out << " for mds." << master;
137     out << commit;
138   }
139
140   EMetaBlob *get_metablob() override { return &commit; }
141
142   void encode(bufferlist& bl, uint64_t features) const override;
143   void decode(bufferlist::iterator& bl) override;
144   void dump(Formatter *f) const override;
145   static void generate_test_instances(list<ESlaveUpdate*>& ls);
146
147   void replay(MDSRank *mds) override;
148 };
149 WRITE_CLASS_ENCODER_FEATURES(ESlaveUpdate)
150
151 #endif