Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mds / JournalPointer.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
16 #ifndef JOURNAL_POINTER_H
17 #define JOURNAL_POINTER_H
18
19 #include "include/encoding.h"
20 #include "mdstypes.h"
21
22 class Objecter;
23 class Mutex;
24
25 // This always lives in the same location for a given MDS
26 // instance, it tells the daemon where to look for the journal.
27 class JournalPointer {
28   // MDS rank
29   int node_id;
30   // Metadata pool ID
31   int64_t pool_id;
32
33   std::string get_object_id() const;
34
35   public:
36   // The currently active journal
37   inodeno_t front;
38   // The backup journal, if any (may be 0)
39   inodeno_t back;
40
41   void encode(bufferlist &bl) const {
42     ENCODE_START(1, 1, bl);
43     ::encode(front, bl);
44     ::encode(back, bl);
45     ENCODE_FINISH(bl);
46   }
47
48   void decode(bufferlist::iterator &bl) {
49     DECODE_START(1, bl);
50     ::decode(front, bl);
51     ::decode(back, bl);
52     DECODE_FINISH(bl);
53   }
54
55   JournalPointer(int node_id_, int64_t pool_id_) : node_id(node_id_), pool_id(pool_id_),
56     front(0), back(0) {}
57
58   JournalPointer() : node_id(-1), pool_id(-1), front(0), back(0) {}
59
60   int load(Objecter *objecter);
61   int save(Objecter *objecter) const;
62   void save(Objecter *objecter, Context *completion) const;
63
64   bool is_null() const {
65     return front == 0 && back == 0;
66   }
67
68   void dump(Formatter *f) const {
69     f->open_object_section("journal_pointer");
70     {
71       f->dump_unsigned("front", front);
72       f->dump_unsigned("back", back);
73     }
74     f->close_section(); // journal_header
75   }
76
77   static void generate_test_instances(std::list<JournalPointer*> &ls)
78   {
79     ls.push_back(new JournalPointer());
80     ls.push_back(new JournalPointer());
81     ls.back()->front = 0xdeadbeef;
82     ls.back()->back = 0xfeedbead;
83   }
84 };
85 WRITE_CLASS_ENCODER(JournalPointer)
86
87 #endif // JOURNAL_POINTER_H