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/ceph_mutex.h"
12   	#include "common/RefCountedObj.h"
13   	#include "common/RWLock.h"
14   	#include <boost/shared_ptr.hpp>
15   	#include <list>
16   	#include <map>
17   	#include <set>
18   	#include <string>
19   	
20   	namespace librados {
21   	
22   	class TestMemCluster : public TestCluster {
23   	public:
24   	  typedef std::map<std::string, bufferlist> OMap;
25   	  typedef std::map<ObjectLocator, OMap> FileOMaps;
26   	  typedef std::map<ObjectLocator, bufferlist> FileTMaps;
27   	  typedef std::map<std::string, bufferlist> XAttrs;
28   	  typedef std::map<ObjectLocator, XAttrs> FileXAttrs;
29   	  typedef std::set<ObjectHandler*> ObjectHandlers;
30   	  typedef std::map<ObjectLocator, ObjectHandlers> FileHandlers;
31   	
32   	  struct File {
33   	    File();
34   	    File(const File &rhs);
35   	
36   	    bufferlist data;
(1) Event member_decl: Class member declaration for "mtime".
Also see events: [uninit_member]
37   	    time_t mtime;
38   	
39   	    uint64_t snap_id;
40   	    std::vector<uint64_t> snaps;
41   	    interval_set<uint64_t> snap_overlap;
42   	
43   	    bool exists;
44   	    ceph::shared_mutex lock =
45   	      ceph::make_shared_mutex("TestMemCluster::File::lock");
46   	  };
47   	  typedef boost::shared_ptr<File> SharedFile;
48   	
49   	  typedef std::list<SharedFile> FileSnapshots;
50   	  typedef std::map<ObjectLocator, FileSnapshots> Files;
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   	    ceph::shared_mutex file_lock =
62   	      ceph::make_shared_mutex("TestMemCluster::Pool::file_lock");
63   	    Files files;
64   	    FileOMaps file_omaps;
65   	    FileTMaps file_tmaps;
66   	    FileXAttrs file_xattrs;
67   	    FileHandlers file_handlers;
68   	  };
69   	
70   	  TestMemCluster();
71   	  ~TestMemCluster() override;
72   	
73   	  TestRadosClient *create_rados_client(CephContext *cct) override;
74   	
75   	  int register_object_handler(int64_t pool_id, const ObjectLocator& locator,
76   	                              ObjectHandler* object_handler) override;
77   	  void unregister_object_handler(int64_t pool_id, const ObjectLocator& locator,
78   	                                 ObjectHandler* object_handler) override;
79   	
80   	  int pool_create(const std::string &pool_name);
81   	  int pool_delete(const std::string &pool_name);
82   	  int pool_get_base_tier(int64_t pool_id, int64_t* base_tier);
83   	  int pool_list(std::list<std::pair<int64_t, std::string> >& v);
84   	  int64_t pool_lookup(const std::string &name);
85   	  int pool_reverse_lookup(int64_t id, std::string *name);
86   	
87   	  Pool *get_pool(int64_t pool_id);
88   	  Pool *get_pool(const std::string &pool_name);
89   	
90   	  void allocate_client(uint32_t *nonce, uint64_t *global_id);
91   	  void deallocate_client(uint32_t nonce);
92   	
93   	  bool is_blacklisted(uint32_t nonce) const;
94   	  void blacklist(uint32_t nonce);
95   	
96   	  void transaction_start(const ObjectLocator& locator);
97   	  void transaction_finish(const ObjectLocator& locator);
98   	
99   	private:
100  	
101  	  typedef std::map<std::string, Pool*>		Pools;
102  	  typedef std::set<uint32_t> Blacklist;
103  	
104  	  mutable ceph::mutex m_lock =
105  	    ceph::make_mutex("TestMemCluster::m_lock");
106  	
107  	  Pools	m_pools;
108  	  int64_t m_pool_id = 0;
109  	
110  	  uint32_t m_next_nonce;
111  	  uint64_t m_next_global_id = 1234;
112  	
113  	  Blacklist m_blacklist;
114  	
115  	  ceph::condition_variable m_transaction_cond;
116  	  std::set<ObjectLocator> m_transactions;
117  	
118  	  Pool *get_pool(const ceph::mutex& lock, int64_t pool_id);
119  	
120  	};
121  	
122  	} // namespace librados
123  	
124  	#endif // CEPH_TEST_MEM_CLUSTER_H
125