]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/librados_test_stub/TestMemCluster.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / librados_test_stub / TestMemCluster.h
CommitLineData
7c673cae
FG
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_TEST_MEM_CLUSTER_H
5#define CEPH_TEST_MEM_CLUSTER_H
6
7#include "test/librados_test_stub/TestCluster.h"
8#include "include/buffer.h"
9#include "include/interval_set.h"
10#include "include/int_types.h"
11#include "common/Cond.h"
12#include "common/Mutex.h"
13#include "common/RefCountedObj.h"
14#include "common/RWLock.h"
15#include <boost/shared_ptr.hpp>
16#include <list>
17#include <map>
18#include <set>
19#include <string>
20
21namespace librados {
22
23class TestMemCluster : public TestCluster {
24public:
25 typedef std::map<std::string, bufferlist> OMap;
11fdf7f2
TL
26 typedef std::map<ObjectLocator, OMap> FileOMaps;
27 typedef std::map<ObjectLocator, bufferlist> FileTMaps;
7c673cae 28 typedef std::map<std::string, bufferlist> XAttrs;
11fdf7f2
TL
29 typedef std::map<ObjectLocator, XAttrs> FileXAttrs;
30 typedef std::set<ObjectHandler*> ObjectHandlers;
31 typedef std::map<ObjectLocator, ObjectHandlers> FileHandlers;
7c673cae
FG
32
33 struct File {
34 File();
35 File(const File &rhs);
36
37 bufferlist data;
38 time_t mtime;
39
40 uint64_t snap_id;
41 std::vector<uint64_t> snaps;
42 interval_set<uint64_t> snap_overlap;
43
44 bool exists;
45 RWLock lock;
46 };
47 typedef boost::shared_ptr<File> SharedFile;
48
49 typedef std::list<SharedFile> FileSnapshots;
11fdf7f2 50 typedef std::map<ObjectLocator, FileSnapshots> Files;
7c673cae
FG
51
52 typedef std::set<uint64_t> SnapSeqs;
53 struct Pool : public RefCountedObject {
54 Pool();
55
56 int64_t pool_id = 0;
57
58 SnapSeqs snap_seqs;
59 uint64_t snap_id = 1;
60
61 RWLock file_lock;
62 Files files;
63 FileOMaps file_omaps;
64 FileTMaps file_tmaps;
65 FileXAttrs file_xattrs;
11fdf7f2 66 FileHandlers file_handlers;
7c673cae
FG
67 };
68
69 TestMemCluster();
70 ~TestMemCluster() override;
71
72 TestRadosClient *create_rados_client(CephContext *cct) override;
73
11fdf7f2
TL
74 int register_object_handler(int64_t pool_id, const ObjectLocator& locator,
75 ObjectHandler* object_handler) override;
76 void unregister_object_handler(int64_t pool_id, const ObjectLocator& locator,
77 ObjectHandler* object_handler) override;
78
7c673cae
FG
79 int pool_create(const std::string &pool_name);
80 int pool_delete(const std::string &pool_name);
81 int pool_get_base_tier(int64_t pool_id, int64_t* base_tier);
82 int pool_list(std::list<std::pair<int64_t, std::string> >& v);
83 int64_t pool_lookup(const std::string &name);
84 int pool_reverse_lookup(int64_t id, std::string *name);
85
86 Pool *get_pool(int64_t pool_id);
87 Pool *get_pool(const std::string &pool_name);
88
89 void allocate_client(uint32_t *nonce, uint64_t *global_id);
90 void deallocate_client(uint32_t nonce);
91
92 bool is_blacklisted(uint32_t nonce) const;
93 void blacklist(uint32_t nonce);
94
11fdf7f2
TL
95 void transaction_start(const ObjectLocator& locator);
96 void transaction_finish(const ObjectLocator& locator);
7c673cae
FG
97
98private:
99
100 typedef std::map<std::string, Pool*> Pools;
101 typedef std::set<uint32_t> Blacklist;
102
103 mutable Mutex m_lock;
104
105 Pools m_pools;
106 int64_t m_pool_id = 0;
107
108 uint32_t m_next_nonce;
109 uint64_t m_next_global_id = 1234;
110
111 Blacklist m_blacklist;
112
113 Cond m_transaction_cond;
11fdf7f2
TL
114 std::set<ObjectLocator> m_transactions;
115
116 Pool *get_pool(const Mutex& lock, int64_t pool_id);
7c673cae
FG
117
118};
119
120} // namespace librados
121
122#endif // CEPH_TEST_MEM_CLUSTER_H