CernVM-FS  2.12.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 // 4 --> 5:
17 // - Add revision to breadcrumb
18 #define LIBCVMFS_CACHE_REVISION 5
19 
20 #include <stdint.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 // Map C++ classes to their C interface names
25 typedef class SimpleOptionsParser cvmcache_option_map;
26 #else
27 typedef struct OptionsManager cvmcache_option_map;
28 #endif
29 
30 // Mirrors cvmfs::EnumHashAlgorithm protobuf definition
35 };
36 
37 // Mirrors cvmfs::EnumStatus protobuf definition
41  CVMCACHE_STATUS_NOSUPPORT, // Not implemented by the cache plugin
42  CVMCACHE_STATUS_FORBIDDEN, // Client is not allowed to perform the operation
43  CVMCACHE_STATUS_NOSPACE, // Cache is full
44  CVMCACHE_STATUS_NOENTRY, // Object is not in cache
45  CVMCACHE_STATUS_MALFORMED, // Malformed request
46  CVMCACHE_STATUS_IOERR, // General I/O error
47  CVMCACHE_STATUS_CORRUPTED, // Crc32 verification failed
48  // Certain parts of a multipart request never arrived
50  CVMCACHE_STATUS_BADCOUNT, // Attempt to set a negative reference count
51  // Attempt to read from an offset larger than the object size
53  // Cache content could not be evicted to requested size
55 };
56 
57 // Mirrors cvmfs::EnumObjectType protobuf definition
62 };
63 
64 // Mirrors cvmfs::EnumCapability protobuf definition
67  // A read-only cache needs to be pre-populated by other means
69  // Proper refcounting is implemented; for lower tier caches, this capability
70  // can be unset and reference counting can simply beomce file existence check
72  CVMCACHE_CAP_SHRINK = 4, // clients can ask the cache to shrink
73  CVMCACHE_CAP_INFO = 8, // cache plugin knows about its fill level
74  CVMCACHE_CAP_SHRINK_RATE = 16, // cache knows number of cleanup operations
75  CVMCACHE_CAP_LIST = 32, // cache can return a list of objects
77  CVMCACHE_CAP_BREADCRUMB = 64, // cache can load and store breadcrumps
79 };
80 
81 #define CVMCACHE_SIZE_UNKNOWN (uint64_t(-1))
82 
83 struct cvmcache_hash {
84  unsigned char digest[20];
85  char algorithm;
86 } __attribute__((__packed__));
87 
89  struct cvmcache_hash id;
90  uint64_t size;
92  int pinned;
93  char *description;
94 };
95 
96 struct cvmcache_info {
97  uint64_t size_bytes;
98  uint64_t used_bytes;
99  uint64_t pinned_bytes;
100  int64_t no_shrink;
101 };
102 
103 struct cvmcache_context;
104 
106  uint64_t id;
109 };
110 
113  uint64_t timestamp;
114  uint64_t revision;
115 };
116 
120 int cvmcache_hash_cmp(struct cvmcache_hash *a, struct cvmcache_hash *b);
124 char *cvmcache_hash_print(const struct cvmcache_hash *h);
125 
134  int (*cvmcache_chrefcnt)(struct cvmcache_hash *id, int32_t change_by);
138  int (*cvmcache_obj_info)(struct cvmcache_hash *id,
139  struct cvmcache_object_info *info);
144  int (*cvmcache_pread)(struct cvmcache_hash *id,
145  uint64_t offset,
146  uint32_t *size,
147  unsigned char *buffer);
152  uint64_t txn_id,
153  struct cvmcache_object_info *info);
157  int (*cvmcache_write_txn)(uint64_t txn_id,
158  unsigned char *buffer,
159  uint32_t size);
163  int (*cvmcache_commit_txn)(uint64_t txn_id);
164  int (*cvmcache_abort_txn)(uint64_t txn_id);
165 
166  int (*cvmcache_info)(struct cvmcache_info *info);
167  int (*cvmcache_shrink)(uint64_t shrink_to, uint64_t *used);
172  int (*cvmcache_listing_begin)(uint64_t lst_id,
174  int (*cvmcache_listing_next)(int64_t lst_id,
175  struct cvmcache_object_info *item);
176  int (*cvmcache_listing_end)(int64_t lst_id);
177 
178  int (*cvmcache_breadcrumb_store)(const char *fqrn,
179  const cvmcache_breadcrumb *breadcrumb);
180  int (*cvmcache_breadcrumb_load)(const char *fqrn,
181  cvmcache_breadcrumb *breadcrumb);
182 
184 };
185 
189 void cvmcache_init_global();
200 
201 struct cvmcache_context *cvmcache_init(struct cvmcache_callbacks *callbacks);
206 int cvmcache_listen(struct cvmcache_context *ctx, char *locator);
211 void cvmcache_process_requests(struct cvmcache_context *ctx, unsigned nworkers);
228 
235 void cvmcache_spawn_watchdog(const char *crash_dump_file);
237 
244 
245 
246 // Options parsing from libcvmfs without "libcvmfs legacy" support
247 
248 cvmcache_option_map *cvmcache_options_init();
253 void cvmcache_options_fini(cvmcache_option_map *opts);
258 void cvmcache_options_set(cvmcache_option_map *opts,
259  const char *key, const char *value);
264 int cvmcache_options_parse(cvmcache_option_map *opts, const char *path);
269 void cvmcache_options_unset(cvmcache_option_map *opts, const char *key);
274 char *cvmcache_options_get(cvmcache_option_map *opts, const char *key);
279 char *cvmcache_options_dump(cvmcache_option_map *opts);
283 void cvmcache_options_free(char *value);
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 #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:320
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
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:54
cvmcache_option_map * cvmcache_options_init()
uint32_t cvmcache_max_object_size(struct cvmcache_context *ctx)