Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mds / SnapServer.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_SNAPSERVER_H
16 #define CEPH_SNAPSERVER_H
17
18 #include "MDSTableServer.h"
19 #include "snap.h"
20
21 class MDSRank;
22 class MonClient;
23
24 class SnapServer : public MDSTableServer {
25 protected:
26   MonClient *mon_client;
27   snapid_t last_snap;
28   map<snapid_t, SnapInfo> snaps;
29   map<int, set<snapid_t> > need_to_purge;
30   
31   map<version_t, SnapInfo> pending_update;
32   map<version_t, pair<snapid_t,snapid_t> > pending_destroy; // (removed_snap, seq)
33   set<version_t>           pending_noop;
34
35   version_t last_checked_osdmap;
36
37 public:
38   SnapServer(MDSRank *m, MonClient *monc)
39     : MDSTableServer(m, TABLE_SNAP), mon_client(monc), last_checked_osdmap(0)
40   {}
41     
42   void reset_state() override;
43   void encode_server_state(bufferlist& bl) const override {
44     ENCODE_START(3, 3, bl);
45     ::encode(last_snap, bl);
46     ::encode(snaps, bl);
47     ::encode(need_to_purge, bl);
48     ::encode(pending_update, bl);
49     ::encode(pending_destroy, bl);
50     ::encode(pending_noop, bl);
51     ENCODE_FINISH(bl);
52   }
53   void decode_server_state(bufferlist::iterator& bl) override {
54     DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl);
55     ::decode(last_snap, bl);
56     ::decode(snaps, bl);
57     ::decode(need_to_purge, bl);
58     ::decode(pending_update, bl);
59     if (struct_v >= 2)
60       ::decode(pending_destroy, bl);
61     else {
62       map<version_t, snapid_t> t;
63       ::decode(t, bl);
64       for (map<version_t, snapid_t>::iterator p = t.begin(); p != t.end(); ++p)
65         pending_destroy[p->first].first = p->second; 
66     } 
67     ::decode(pending_noop, bl);
68     DECODE_FINISH(bl);
69   }
70
71   // To permit enc/decoding in isolation in dencoder
72   SnapServer() : MDSTableServer(NULL, TABLE_SNAP), last_checked_osdmap(0) {}
73   void encode(bufferlist& bl) const {
74     encode_server_state(bl);
75   }
76   void decode(bufferlist::iterator& bl) {
77     decode_server_state(bl);
78   }
79   void dump(Formatter *f) const;
80   static void generate_test_instances(list<SnapServer*>& ls);
81
82   // server bits
83   void _prepare(bufferlist &bl, uint64_t reqid, mds_rank_t bymds) override;
84   bool _is_prepared(version_t tid) const;
85   bool _commit(version_t tid, MMDSTableRequest *req=NULL) override;
86   void _rollback(version_t tid) override;
87   void _server_update(bufferlist& bl) override;
88   void handle_query(MMDSTableRequest *m) override;
89
90   void check_osd_map(bool force);
91 };
92 WRITE_CLASS_ENCODER(SnapServer)
93
94 #endif