CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cache.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_CACHE_H_
6 #define CVMFS_CACHE_H_
7 
8 #ifndef __STDC_FORMAT_MACROS
9 #define __STDC_FORMAT_MACROS
10 #endif
11 
12 #include <stdint.h>
13 
14 #include <string>
15 
16 #include "hash.h"
17 #include "manifest.h"
18 #include "util/pointer.h"
19 
20 
21 class QuotaManager;
22 
29 };
30 
31 enum CacheModes {
34 };
35 
36 
66  public:
72  static const uint64_t kSizeUnknown;
73 
77  enum ObjectType {
79  kTypeCatalog, // implies pinned
82  };
83 
89  struct ObjectInfo {
91  ObjectInfo(ObjectType t, const std::string &d) : type(t), description(d) { }
92 
97  std::string description;
98  };
99 
103  struct BlessedObject {
104  explicit BlessedObject(const shash::Any &id) : id(id), info() { }
106  : id(id)
107  , info(info) { }
109  : id(id)
110  , info(type, "") { }
111  BlessedObject(const shash::Any &id, const std::string &description)
112  : id(id)
113  , info(kTypeRegular, description) { }
115  const shash::Any &id,
117  const std::string &description)
118  : id(id)
119  , info(type, description) { }
120 
123  };
124  // Convenience constructors, users can call Open(CacheManager::Bless(my_hash))
125  static inline BlessedObject Bless(const shash::Any &id) {
126  return BlessedObject(id);
127  }
128  static inline BlessedObject Bless(
129  const shash::Any &id,
130  const ObjectInfo &info)
131  {
132  return BlessedObject(id, info);
133  }
134  static inline BlessedObject Bless(const shash::Any &id, ObjectType type) {
135  return BlessedObject(id, type);
136  }
137  static inline BlessedObject Bless(
138  const shash::Any &id,
139  const std::string &description)
140  {
141  return BlessedObject(id, description);
142  }
143  static inline BlessedObject Bless(
144  const shash::Any &id,
146  const std::string &description)
147  {
148  return BlessedObject(id, type, description);
149  }
150 
151  virtual CacheManagerIds id() = 0;
156  virtual std::string Describe() = 0;
157 
158  virtual bool AcquireQuotaManager(QuotaManager *quota_mgr) = 0;
159 
160  virtual ~CacheManager();
167  virtual int Open(const BlessedObject &object) = 0;
168  virtual int64_t GetSize(int fd) = 0;
169  virtual int Close(int fd) = 0;
170  virtual int64_t Pread(int fd, void *buf, uint64_t size, uint64_t offset) = 0;
171  virtual int Dup(int fd) = 0;
172  virtual int Readahead(int fd) = 0;
173 
174  virtual uint32_t SizeOfTxn() = 0;
175  virtual int StartTxn(const shash::Any &id, uint64_t size, void *txn) = 0;
176  virtual void CtrlTxn(const ObjectInfo &object_info,
177  const int flags, // reserved for future use
178  void *txn) = 0;
179  virtual int64_t Write(const void *buf, uint64_t sz, void *txn) = 0;
180  virtual int Reset(void *txn) = 0;
181  virtual int AbortTxn(void *txn) = 0;
182  virtual int OpenFromTxn(void *txn) = 0;
183  virtual int CommitTxn(void *txn) = 0;
184 
185  virtual void Spawn() = 0;
186 
187  int OpenPinned(const shash::Any &id,
188  const std::string &description,
189  bool is_catalog);
190  int ChecksumFd(int fd, shash::Any *id);
191  bool Open2Mem(const shash::Any &id, const std::string &description,
192  unsigned char **buffer, uint64_t *size);
193  bool CommitFromMem(const shash::Any &id,
194  const unsigned char *buffer,
195  const uint64_t size,
196  const std::string &description);
197 
199 
200  // Rescue the open file table during reload of the fuse module. For the
201  // POSIX cache, nothing needs to be done because the table is keep in the
202  // kernel for the process. Other cache managers need to do it manually.
203  void *SaveState(const int fd_progress);
210  int RestoreState(const int fd_progress, void *state);
211  void FreeState(const int fd_progress, void *state);
212 
219  virtual manifest::Breadcrumb LoadBreadcrumb(const std::string & /*fqrn*/) {
220  return manifest::Breadcrumb();
221  }
222  virtual bool StoreBreadcrumb(const manifest::Manifest &/*manifest*/) {
223  return false;
224  }
225 
226  protected:
227  CacheManager();
228 
229  // Unless overwritten, Saving/Restoring states will crash the Fuse module
230  virtual void *DoSaveState() { return NULL; }
231  virtual int DoRestoreState(void *data) { return false; }
232  virtual bool DoFreeState(void *data) { return false; }
233 
238 
239  private:
240  static const unsigned kStateVersion = 0;
241 
246  struct State : SingleCopy {
250  , concrete_state(NULL)
251  { }
252 
253  unsigned version;
256  };
257 }; // class CacheManager
258 
259 #endif // CVMFS_CACHE_H_
int ChecksumFd(int fd, shash::Any *id)
Definition: cache.cc:39
BlessedObject(const shash::Any &id, ObjectType type)
Definition: cache.h:108
virtual int64_t GetSize(int fd)=0
static BlessedObject Bless(const shash::Any &id, const std::string &description)
Definition: cache.h:137
int OpenPinned(const shash::Any &id, const std::string &description, bool is_catalog)
Definition: cache.cc:170
BlessedObject(const shash::Any &id, const ObjectInfo info)
Definition: cache.h:105
BlessedObject(const shash::Any &id, ObjectType type, const std::string &description)
Definition: cache.h:114
int RestoreState(const int fd_progress, void *state)
Definition: cache.cc:194
virtual void Spawn()=0
virtual ~CacheManager()
Definition: cache.cc:30
CacheManagerIds manager_type
Definition: cache.h:254
CacheModes
Definition: cache.h:31
virtual manifest::Breadcrumb LoadBreadcrumb(const std::string &)
Definition: cache.h:219
void * SaveState(const int fd_progress)
Definition: cache.cc:221
unsigned version
Definition: cache.h:253
virtual int AbortTxn(void *txn)=0
virtual bool StoreBreadcrumb(const manifest::Manifest &)
Definition: cache.h:222
virtual int Open(const BlessedObject &object)=0
virtual void * DoSaveState()
Definition: cache.h:230
virtual bool DoFreeState(void *data)
Definition: cache.h:232
virtual CacheManagerIds id()=0
std::string description
Definition: cache.h:97
static BlessedObject Bless(const shash::Any &id, ObjectType type, const std::string &description)
Definition: cache.h:143
void * concrete_state
Definition: cache.h:255
BlessedObject(const shash::Any &id)
Definition: cache.h:104
virtual int DoRestoreState(void *data)
Definition: cache.h:231
static BlessedObject Bless(const shash::Any &id, const ObjectInfo &info)
Definition: cache.h:128
static BlessedObject Bless(const shash::Any &id, ObjectType type)
Definition: cache.h:134
virtual int CommitTxn(void *txn)=0
virtual int OpenFromTxn(void *txn)=0
ObjectType type
Definition: cache.h:93
CacheManagerIds
Definition: cache.h:23
ObjectInfo(ObjectType t, const std::string &d)
Definition: cache.h:91
bool CommitFromMem(const shash::Any &id, const unsigned char *buffer, const uint64_t size, const std::string &description)
Definition: cache.cc:79
bool Open2Mem(const shash::Any &id, const std::string &description, unsigned char **buffer, uint64_t *size)
Definition: cache.cc:127
virtual int Close(int fd)=0
virtual int Reset(void *txn)=0
static const unsigned kStateVersion
Definition: cache.h:240
void FreeState(const int fd_progress, void *state)
Definition: cache.cc:100
static BlessedObject Bless(const shash::Any &id)
Definition: cache.h:125
CacheManager()
Definition: cache.cc:27
QuotaManager * quota_mgr()
Definition: cache.h:198
QuotaManager * quota_mgr_
Definition: cache.h:237
virtual uint32_t SizeOfTxn()=0
BlessedObject(const shash::Any &id, const std::string &description)
Definition: cache.h:111
virtual int Dup(int fd)=0
virtual int Readahead(int fd)=0
virtual bool AcquireQuotaManager(QuotaManager *quota_mgr)=0
virtual int StartTxn(const shash::Any &id, uint64_t size, void *txn)=0
static void size_t size
Definition: smalloc.h:47
virtual int64_t Pread(int fd, void *buf, uint64_t size, uint64_t offset)=0
virtual std::string Describe()=0
virtual int64_t Write(const void *buf, uint64_t sz, void *txn)=0
static const uint64_t kSizeUnknown
Definition: cache.h:72
virtual void CtrlTxn(const ObjectInfo &object_info, const int flags, void *txn)=0