CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
libcvmfs_cache.h
Go to the documentation of this file.
1 
6 #ifndef CVMFS_CACHE_PLUGIN_LIBCVMFS_CACHE_H_
7 #define CVMFS_CACHE_PLUGIN_LIBCVMFS_CACHE_H_
8 
9 // Revision Changelog
10 // 1 --> 2:
11 // - Add CVMCACHE_CAP_WRITE capability, adjust other capability constants
12 // 2 --> 3:
13 // - Add cvmcache_get_session()
14 // 3 --> 4:
15 // - Add breadcrumb management
16 #define LIBCVMFS_CACHE_REVISION 4
17 
18 #include <stdint.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 // Map C++ clases to their C interface names
23 typedef class SimpleOptionsParser cvmcache_option_map;
24 #else
25 typedef struct OptionsManager cvmcache_option_map;
26 #endif
27 
28 // Mirrors cvmfs::EnumHashAlgorithm protobuf definition
33 };
34 
35 // Mirrors cvmfs::EnumStatus protobuf definition
39  CVMCACHE_STATUS_NOSUPPORT, // Not implemented by the cache plugin
40  CVMCACHE_STATUS_FORBIDDEN, // Client is not allowed to perform the operation
41  CVMCACHE_STATUS_NOSPACE, // Cache is full
42  CVMCACHE_STATUS_NOENTRY, // Object is not in cache
43  CVMCACHE_STATUS_MALFORMED, // Malformed request
44  CVMCACHE_STATUS_IOERR, // General I/O error
45  CVMCACHE_STATUS_CORRUPTED, // Crc32 verification failed
46  // Certain parts of a multipart request never arrived
48  CVMCACHE_STATUS_BADCOUNT, // Attempt to set a negative reference count
49  // Attempt to read from an offset larger than the object size
51  // Cache content could not be evicted to requested size
53 };
54 
55 // Mirrors cvmfs::EnumObjectType protobuf definition
60 };
61 
62 // Mirrors cvmfs::EnumCapability protobuf definition
65  // A read-only cache needs to be pre-populated by other means
67  // Proper refcounting is implemented; for lower tier caches, this capability
68  // can be unset and reference counting can simply beomce file existence check
70  CVMCACHE_CAP_SHRINK = 4, // clients can ask the cache to shrink
71  CVMCACHE_CAP_INFO = 8, // cache plugin knows about its fill level
72  CVMCACHE_CAP_SHRINK_RATE = 16, // cache knows number of cleanup operations
73  CVMCACHE_CAP_LIST = 32, // cache can return a list of objects
75  CVMCACHE_CAP_BREADCRUMB = 64, // cache can load and store breadcrumps
77 };
78 
79 #define CVMCACHE_SIZE_UNKNOWN (uint64_t(-1))
80 
81 struct cvmcache_hash {
82  unsigned char digest[20];
83  char algorithm;
84 } __attribute__((__packed__));
85 
87  struct cvmcache_hash id;
88  uint64_t size;
90  int pinned;
91  char *description;
92 };
93 
94 struct cvmcache_info {
95  uint64_t size_bytes;
96  uint64_t used_bytes;
97  uint64_t pinned_bytes;
98  int64_t no_shrink;
99 };
100 
101 struct cvmcache_context;
102 
104  uint64_t id;
107 };
108 
111  uint64_t timestamp;
112 };
113 
117 int cvmcache_hash_cmp(struct cvmcache_hash *a, struct cvmcache_hash *b);
121 char *cvmcache_hash_print(const struct cvmcache_hash *h);
122 
131  int (*cvmcache_chrefcnt)(struct cvmcache_hash *id, int32_t change_by);
135  int (*cvmcache_obj_info)(struct cvmcache_hash *id,
136  struct cvmcache_object_info *info);
141  int (*cvmcache_pread)(struct cvmcache_hash *id,
142  uint64_t offset,
143  uint32_t *size,
144  unsigned char *buffer);
149  uint64_t txn_id,
150  struct cvmcache_object_info *info);
154  int (*cvmcache_write_txn)(uint64_t txn_id,
155  unsigned char *buffer,
156  uint32_t size);
160  int (*cvmcache_commit_txn)(uint64_t txn_id);
161  int (*cvmcache_abort_txn)(uint64_t txn_id);
162 
163  int (*cvmcache_info)(struct cvmcache_info *info);
164  int (*cvmcache_shrink)(uint64_t shrink_to, uint64_t *used);
169  int (*cvmcache_listing_begin)(uint64_t lst_id,
171  int (*cvmcache_listing_next)(int64_t lst_id,
172  struct cvmcache_object_info *item);
173  int (*cvmcache_listing_end)(int64_t lst_id);
174 
175  int (*cvmcache_breadcrumb_store)(const char *fqrn,
176  const cvmcache_breadcrumb *breadcrumb);
177  int (*cvmcache_breadcrumb_load)(const char *fqrn,
178  cvmcache_breadcrumb *breadcrumb);
179 
181 };
182 
186 void cvmcache_init_global();
197 
198 struct cvmcache_context *cvmcache_init(struct cvmcache_callbacks *callbacks);
203 int cvmcache_listen(struct cvmcache_context *ctx, char *locator);
208 void cvmcache_process_requests(struct cvmcache_context *ctx, unsigned nworkers);
225 
232 void cvmcache_spawn_watchdog(const char *crash_dump_file);
234 
241 
242 
243 // Options parsing from libcvmfs without "libcvmfs legacy" support
244 
245 cvmcache_option_map *cvmcache_options_init();
250 void cvmcache_options_fini(cvmcache_option_map *opts);
255 void cvmcache_options_set(cvmcache_option_map *opts,
256  const char *key, const char *value);
261 int cvmcache_options_parse(cvmcache_option_map *opts, const char *path);
266 void cvmcache_options_unset(cvmcache_option_map *opts, const char *key);
271 char *cvmcache_options_get(cvmcache_option_map *opts, const char *key);
276 char *cvmcache_options_dump(cvmcache_option_map *opts);
280 void cvmcache_options_free(char *value);
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 
286 #endif // CVMFS_CACHE_PLUGIN_LIBCVMFS_CACHE_H_
struct cvmcache_hash catalog_hash
int(* cvmcache_chrefcnt)(struct cvmcache_hash *id, int32_t change_by)
struct cvmcache_context * ctx
Session * session() const
Definition: repository.h:309
cvmcache_object_type
void cvmcache_terminate(struct cvmcache_context *ctx)
int cvmcache_listen(struct cvmcache_context *ctx, char *locator)
struct cvmcache_hash id
int(* cvmcache_listing_next)(int64_t lst_id, struct cvmcache_object_info *item)
void cvmcache_cleanup_global()
void cvmcache_terminate_watchdog()
char * cvmcache_options_dump(cvmcache_option_map *opts)
uint64_t pinned_bytes
int cvmcache_is_supervised()
int(* cvmcache_pread)(struct cvmcache_hash *id, uint64_t offset, uint32_t *size, unsigned char *buffer)
int(* cvmcache_breadcrumb_load)(const char *fqrn, cvmcache_breadcrumb *breadcrumb)
struct cvmcache_object_info __attribute__
Definition: atomic.h:24
void cvmcache_wait_for(struct cvmcache_context *ctx)
uint64_t used_bytes
int64_t no_shrink
void cvmcache_ask_detach(struct cvmcache_context *ctx)
int(* cvmcache_write_txn)(uint64_t txn_id, unsigned char *buffer, uint32_t size)
int cvmcache_hash_cmp(struct cvmcache_hash *a, struct cvmcache_hash *b)
unsigned char digest[20]
void cvmcache_get_session(cvmcache_session *session)
void cvmcache_options_free(char *value)
void cvmcache_spawn_watchdog(const char *crash_dump_file)
void cvmcache_options_fini(cvmcache_option_map *opts)
char * cvmcache_hash_print(const struct cvmcache_hash *h)
uint64_t size_bytes
enum cvmcache_object_type type
struct cvmcache_context * cvmcache_init(struct cvmcache_callbacks *callbacks)
void cvmcache_init_global()
int cvmcache_options_parse(cvmcache_option_map *opts, const char *path)
int(* cvmcache_shrink)(uint64_t shrink_to, uint64_t *used)
cvmcache_status
void cvmcache_options_unset(cvmcache_option_map *opts, const char *key)
cvmcache_hash_algorithm
int(* cvmcache_listing_begin)(uint64_t lst_id, enum cvmcache_object_type type)
void cvmcache_process_requests(struct cvmcache_context *ctx, unsigned nworkers)
int(* cvmcache_breadcrumb_store)(const char *fqrn, const cvmcache_breadcrumb *breadcrumb)
cvmcache_capabilities
char * cvmcache_options_get(cvmcache_option_map *opts, const char *key)
int(* cvmcache_commit_txn)(uint64_t txn_id)
int(* cvmcache_start_txn)(struct cvmcache_hash *id, uint64_t txn_id, struct cvmcache_object_info *info)
int(* cvmcache_listing_end)(int64_t lst_id)
int(* cvmcache_abort_txn)(uint64_t txn_id)
void cvmcache_options_set(cvmcache_option_map *opts, const char *key, const char *value)
int(* cvmcache_obj_info)(struct cvmcache_hash *id, struct cvmcache_object_info *info)
static void size_t size
Definition: smalloc.h:47
cvmcache_option_map * cvmcache_options_init()
uint32_t cvmcache_max_object_size(struct cvmcache_context *ctx)