LLVM 24.0.0git
PluginAPI_functions.h
Go to the documentation of this file.
1/*===----------------------------------------------------------------------===*\
2|* *|
3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* The functions for the LLVM CAS plugin API. Intended for assisting *|
11|* implementations of the API. *|
12|* The API is experimental and subject to change. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef LLVM_C_CAS_PLUGINAPI_FUNCTIONS_H
17#define LLVM_C_CAS_PLUGINAPI_FUNCTIONS_H
18
20#include "llvm-c/ExternC.h"
21
22#ifndef LLCAS_PUBLIC
23#ifdef _WIN32
24#define LLCAS_PUBLIC __declspec(dllexport)
25#else
26#define LLCAS_PUBLIC
27#endif
28#endif
29
31
32/**
33 * Returns the \c LLCAS_VERSION_MAJOR and \c LLCAS_VERSION_MINOR values that the
34 * plugin was compiled with.
35 * Intended for assisting compatibility with different versions.
36 */
37LLCAS_PUBLIC void llcas_get_plugin_version(unsigned *major, unsigned *minor);
38
39/**
40 * Releases memory of C string pointers provided by other functions.
41 */
43
44/**
45 * Cancels the asynchronous query associated with the \c llcas_cancellable_t.
46 */
48
49/**
50 * Releases memory associated with given \c llcas_cancellable_t.
51 */
53
54/**
55 * Options object to configure creation of \c llcas_cas_t. After passing to
56 * \c llcas_cas_create, its memory can be released via
57 * \c llcas_cas_options_dispose.
58 */
60
62
63/**
64 * Receives the \c LLCAS_VERSION_MAJOR and \c LLCAS_VERSION_MINOR values that
65 * the client was compiled with.
66 * Intended for assisting compatibility with different versions.
67 */
69 unsigned major,
70 unsigned minor);
71
72/**
73 * Receives a local file-system path that the plugin should use for any on-disk
74 * resources/caches.
75 */
77 const char *path);
78
79/**
80 * Receives a name/value strings pair, for the plugin to set as a custom option
81 * it supports. These are usually passed through as invocation options and are
82 * opaque to the client.
83 *
84 * \param error optional pointer to receive an error message if an error
85 * occurred. If set, the memory it points to needs to be released via
86 * \c llcas_string_dispose.
87 * \returns true if there was an error, false otherwise.
88 */
90 const char *name,
91 const char *value, char **error);
92
93/**
94 * Creates a new \c llcas_cas_t object. The objects returned from the other
95 * functions are only valid to use while the \c llcas_cas_t object that they
96 * came from is still valid.
97 *
98 * \param error optional pointer to receive an error message if an error
99 * occurred. If set, the memory it points to needs to be released via
100 * \c llcas_string_dispose.
101 * \returns \c NULL if there was an error.
102 */
104
105/**
106 * Releases memory of \c llcas_cas_t. After calling this it is invalid to keep
107 * using objects that originated from this \c llcas_cas_t instance.
108 */
110
111/**
112 * Get the local storage size of the CAS/cache data in bytes.
113 *
114 * \param error optional pointer to receive an error message if an error
115 * occurred. If set, the memory it points to needs to be released via
116 * \c llcas_string_dispose.
117 * \returns the local storage size of the CAS/cache data, or -1 if the
118 * implementation does not support reporting such size, or -2 if an error
119 * occurred.
120 */
122
123/**
124 * Set the size for limiting disk storage growth.
125 *
126 * \param size_limit the maximum size limit in bytes. 0 means no limit. Negative
127 * values are invalid.
128 * \param error optional pointer to receive an error message if an error
129 * occurred. If set, the memory it points to needs to be released via
130 * \c llcas_string_dispose.
131 * \returns true if there was an error, false otherwise.
132 */
133LLCAS_PUBLIC bool
135
136/**
137 * Prune local storage to reduce its size according to the desired size limit.
138 * Pruning can happen concurrently with other operations.
139 *
140 * \returns true if there was an error, false otherwise.
141 */
143
144/**
145 * Validate the CAS contents.
146 *
147 * \param check_hash if true, the hash of each object is recomputed and compared
148 * against the one it is stored under.
149 * \param error optional pointer to receive an error message if an error
150 * occurred. If set, the memory it points to needs to be released via
151 * \c llcas_string_dispose.
152 * \returns true if there was an error, false otherwise.
153 */
155 char **error);
156
157/**
158 * Validate the on-disk CAS and action cache contents in-process, if needed.
159 *
160 * This is called without a \c llcas_cas_t being created for the given
161 * options. The implementation decides whether validation is needed, e.g.
162 * whether the contents have already been validated since the last system boot,
163 * and should record a successful validation so that it can be skipped next
164 * time. A validation that fails or crashes should be detectable by
165 * \c llcas_cas_recover_ondisk_data, e.g. by recording that validation is
166 * pending before validating and only clearing it once validation succeeds.
167 *
168 * Clients that want to be resilient to unexpected crashes during validation
169 * may call this from a separate process and call
170 * \c llcas_cas_recover_ondisk_data if it fails or crashes.
171 *
172 * \param check_hash if true, the hash of each object is recomputed and compared
173 * against the one it is stored under.
174 * \param force if true, validation is performed even if it is not needed.
175 * \param error optional pointer to receive an error message if an error
176 * occurred. If set, the memory it points to needs to be released via
177 * \c llcas_string_dispose.
178 * \returns \c LLCAS_VALIDATION_RESULT_VALID or
179 * \c LLCAS_VALIDATION_RESULT_SKIPPED, or \c LLCAS_VALIDATION_RESULT_ERROR if
180 * validation could not be performed or the data is invalid.
181 */
183 llcas_cas_options_t, bool check_hash, bool force, char **error);
184
185/**
186 * Recover from invalid on-disk CAS and action cache contents after
187 * \c llcas_cas_validate_if_needed failed or crashed, e.g. by discarding them.
188 *
189 * This is called without a \c llcas_cas_t being created for the given
190 * options. Multiple processes may attempt recovery concurrently after a failed
191 * validation; the implementation should skip recovery if the contents have
192 * been recovered or successfully validated in the meantime.
193 *
194 * \param error optional pointer to receive an error message if an error
195 * occurred. If set, the memory it points to needs to be released via
196 * \c llcas_string_dispose.
197 * \returns \c LLCAS_VALIDATION_RESULT_RECOVERED or
198 * \c LLCAS_VALIDATION_RESULT_SKIPPED, or \c LLCAS_VALIDATION_RESULT_ERROR if
199 * recovery could not be performed.
200 */
203
204/**
205 * \returns the hash schema name that the plugin is using. The string memory it
206 * points to needs to be released via \c llcas_string_dispose.
207 */
209
210/**
211 * Parses the printed digest and returns the digest hash bytes.
212 *
213 * \param printed_digest a C string that was previously provided by
214 * \c llcas_digest_print.
215 * \param bytes pointer to a buffer for writing the digest bytes. Can be \c NULL
216 * if \p bytes_size is 0.
217 * \param bytes_size the size of the buffer.
218 * \param error optional pointer to receive an error message if an error
219 * occurred. If set, the memory it points to needs to be released via
220 * \c llcas_string_dispose.
221 * \returns 0 if there was an error. If \p bytes_size is smaller than the
222 * required size to fit the digest bytes, returns the required buffer size
223 * without writing to \c bytes. Otherwise writes the digest bytes to \p bytes
224 * and returns the number of written bytes.
225 */
227 const char *printed_digest,
228 uint8_t *bytes, size_t bytes_size,
229 char **error);
230
231/**
232 * Returns a string for the given digest bytes that can be passed to
233 * \c llcas_digest_parse.
234 *
235 * \param printed_id pointer to receive the printed digest string. The memory it
236 * points to needs to be released via \c llcas_string_dispose.
237 * \param error optional pointer to receive an error message if an error
238 * occurred. If set, the memory it points to needs to be released via
239 * \c llcas_string_dispose.
240 * \returns true if there was an error, false otherwise.
241 */
243 char **printed_id, char **error);
244
245/**
246 * Provides the \c llcas_objectid_t value for the given \c llcas_digest_t.
247 *
248 * \param digest the digest bytes that the returned \c llcas_objectid_t
249 * represents.
250 * \param p_id pointer to store the returned \c llcas_objectid_t object.
251 * \param error optional pointer to receive an error message if an error
252 * occurred. If set, the memory it points to needs to be released via
253 * \c llcas_string_dispose.
254 * \returns true if there was an error, false otherwise.
255 */
257 llcas_objectid_t *p_id, char **error);
258
259/**
260 * \returns the \c llcas_digest_t value for the given \c llcas_objectid_t.
261 * The memory that the buffer points to is valid for the lifetime of the
262 * \c llcas_cas_t object.
263 */
266
267/**
268 * Checks whether a \c llcas_objectid_t points to an existing object.
269 *
270 * \param globally For CAS implementations that distinguish between local CAS
271 * and remote/distributed CAS, \p globally set to false indicates that the
272 * lookup will be restricted to the local CAS, returning "not found" even if the
273 * object might exist in the remote CAS.
274 * \param error optional pointer to receive an error message if an error
275 * occurred. If set, the memory it points to needs to be released via
276 * \c llcas_string_dispose.
277 * \returns one of \c llcas_lookup_result_t.
278 */
281 bool globally,
282 char **error);
283
284/**
285 * Loads the object that \c llcas_objectid_t points to.
286 *
287 * \param error optional pointer to receive an error message if an error
288 * occurred. If set, the memory it points to needs to be released via
289 * \c llcas_string_dispose.
290 * \returns one of \c llcas_lookup_result_t.
291 */
294
295/**
296 * Like \c llcas_cas_load_object but loading happens via a callback function.
297 * Whether the call is asynchronous or not depends on the implementation.
298 *
299 * \param ctx_cb pointer to pass to the callback function.
300 *
301 * \param[out] cancel_tok optional pointer to receive a \c llcas_cancellable_t.
302 */
304 void *ctx_cb,
306 llcas_cancellable_t *cancel_tok);
307
308/**
309 * Stores the object with the provided data buffer and \c llcas_objectid_t
310 * references, and provides its associated \c llcas_objectid_t.
311 *
312 * \param refs pointer to array of \c llcas_objectid_t. Can be \c NULL if
313 * \p refs_count is 0.
314 * \param refs_count number of \c llcas_objectid_t objects in the array.
315 * \param p_id pointer to store the returned \c llcas_objectid_t object.
316 * \param error optional pointer to receive an error message if an error
317 * occurred. If set, the memory it points to needs to be released via
318 * \c llcas_string_dispose.
319 * \returns true if there was an error, false otherwise.
320 */
322 const llcas_objectid_t *refs,
323 size_t refs_count,
324 llcas_objectid_t *p_id, char **error);
325
326/**
327 * Stores the data of a file and provides its associated \c llcas_objectid_t.
328 *
329 * An underlying implementation could perform optimizations that reduce I/O
330 * and disk space consumption.
331 *
332 * If there are any concurrent modifications to the file, the contents in the
333 * CAS may be corrupt.
334 *
335 * \param filepath path to the file.
336 * \param p_id pointer to store the returned \c llcas_objectid_t object.
337 * \param error optional pointer to receive an error message if an error
338 * occurred. If set, the memory it points to needs to be released via
339 * \c llcas_string_dispose.
340 * \returns true if there was an error, false otherwise.
341 */
343 const char *filepath,
344 llcas_objectid_t *p_id,
345 char **error);
346
347/**
348 * \returns the data buffer of the provided \c llcas_loaded_object_t. The buffer
349 * pointer must be 8-byte aligned and \c NULL terminated. The memory that the
350 * buffer points to is valid for the lifetime of the \c llcas_cas_t object.
351 */
354
355/**
356 * \returns a data buffer for the provided \c llcas_loaded_object_t that stays
357 * valid after the \c llcas_cas_t is disposed of. The buffer pointer must be
358 * 8-byte aligned and \c NULL terminated. It must be released via
359 * \c llcas_standalone_data_dispose, which may outlive the \c llcas_cas_t.
360 *
361 * This is an optimization over copying the buffer returned by
362 * \c llcas_loaded_object_get_data: an implementation that can hand out storage
363 * outliving itself, e.g. a mapping of a file it does not keep open, avoids the
364 * copy. Implementing it is optional, and requires
365 * \c llcas_standalone_data_dispose to be implemented as well.
366 */
369
370/**
371 * Releases a buffer returned by \c llcas_loaded_object_get_standalone_data.
372 *
373 * This may be called after the \c llcas_cas_t that produced the buffer has
374 * been disposed of, so it must not depend on it.
375 */
377
378/**
379 * \returns the references of the provided \c llcas_loaded_object_t.
380 */
383
384/**
385 * \returns the number of references in the provided \c llcas_object_refs_t.
386 */
389
390/**
391 * \returns the \c llcas_objectid_t of the reference at \p index. It is invalid
392 * to pass an index that is out of the range of references.
393 */
396 size_t index);
397
398/**
399 * Exports the data of an object to a file path. It does not include any
400 * references of the object.
401 *
402 * An underlying implementation could perform optimizations that reduce I/O
403 * and disk space consumption.
404 *
405 * \param filepath the file path to write the data to.
406 * \param error optional pointer to receive an error message if an error
407 * occurred. If set, the memory it points to needs to be released via
408 * \c llcas_string_dispose.
409 * \returns true if there was an error, false otherwise.
410 */
411LLCAS_PUBLIC bool
413 const char *filepath, char **error);
414
415/**
416 * Retrieves the \c llcas_objectid_t value associated with a \p key.
417 *
418 * \param p_value pointer to store the returned \c llcas_objectid_t object.
419 * \param globally if true it is a hint to the underlying implementation that
420 * the lookup is profitable to be done on a distributed caching level, not just
421 * locally. The implementation is free to ignore this flag.
422 * \param error optional pointer to receive an error message if an error
423 * occurred. If set, the memory it points to needs to be released via
424 * \c llcas_string_dispose.
425 * \returns one of \c llcas_lookup_result_t.
426 */
428 llcas_cas_t, llcas_digest_t key, llcas_objectid_t *p_value, bool globally,
429 char **error);
430
431/**
432 * Like \c llcas_actioncache_get_for_digest but result is provided to a callback
433 * function. Whether the call is asynchronous or not depends on the
434 * implementation.
435 *
436 * \param ctx_cb pointer to pass to the callback function.
437 *
438 * \param[out] cancel_tok optional pointer to receive a \c llcas_cancellable_t.
439 */
441 llcas_cas_t, llcas_digest_t key, bool globally, void *ctx_cb,
443
444/**
445 * Associates a \c llcas_objectid_t \p value with a \p key. It is invalid to set
446 * a different \p value to the same \p key.
447 *
448 * \param globally if true it is a hint to the underlying implementation that
449 * the association is profitable to be done on a distributed caching level, not
450 * just locally. The implementation is free to ignore this flag.
451 * \param error optional pointer to receive an error message if an error
452 * occurred. If set, the memory it points to needs to be released via
453 * \c llcas_string_dispose.
454 * \returns true if there was an error, false otherwise.
455 */
457 llcas_digest_t key,
458 llcas_objectid_t value,
459 bool globally, char **error);
460
461/**
462 * Like \c llcas_actioncache_put_for_digest but result is provided to a callback
463 * function. Whether the call is asynchronous or not depends on the
464 * implementation.
465 *
466 * \param ctx_cb pointer to pass to the callback function.
467 *
468 * \param[out] cancel_tok optional pointer to receive a \c llcas_cancellable_t.
469 */
471 llcas_cas_t, llcas_digest_t key, llcas_objectid_t value, bool globally,
472 void *ctx_cb, llcas_actioncache_put_cb, llcas_cancellable_t *cancel_tok);
473
474/**
475 * Validate the action cache contents.
476 *
477 * \param error optional pointer to receive an error message if an error
478 * occurred. If set, the memory it points to needs to be released via
479 * \c llcas_string_dispose.
480 * \returns true if there was an error, false otherwise.
481 */
483
485
486#endif /* LLVM_C_CAS_PLUGINAPI_FUNCTIONS_H */
#define LLVM_C_EXTERN_C_BEGIN
Definition ExternC.h:35
#define LLVM_C_EXTERN_C_END
Definition ExternC.h:36
LLCAS_PUBLIC bool llcas_digest_print(llcas_cas_t, llcas_digest_t, char **printed_id, char **error)
Returns a string for the given digest bytes that can be passed to llcas_digest_parse.
LLCAS_PUBLIC void llcas_cancellable_dispose(llcas_cancellable_t)
Releases memory associated with given llcas_cancellable_t.
LLVM_C_EXTERN_C_BEGIN LLCAS_PUBLIC void llcas_get_plugin_version(unsigned *major, unsigned *minor)
Returns the LLCAS_VERSION_MAJOR and LLCAS_VERSION_MINOR values that the plugin was compiled with.
LLCAS_PUBLIC void llcas_actioncache_get_for_digest_async(llcas_cas_t, llcas_digest_t key, bool globally, void *ctx_cb, llcas_actioncache_get_cb, llcas_cancellable_t *cancel_tok)
Like llcas_actioncache_get_for_digest but result is provided to a callback function.
LLCAS_PUBLIC llcas_cas_t llcas_cas_create(llcas_cas_options_t, char **error)
Creates a new llcas_cas_t object.
LLCAS_PUBLIC int64_t llcas_cas_get_ondisk_size(llcas_cas_t, char **error)
Get the local storage size of the CAS/cache data in bytes.
LLCAS_PUBLIC bool llcas_cas_store_from_filepath(llcas_cas_t, const char *filepath, llcas_objectid_t *p_id, char **error)
Stores the data of a file and provides its associated llcas_objectid_t.
LLCAS_PUBLIC char * llcas_cas_get_hash_schema_name(llcas_cas_t)
LLCAS_PUBLIC void llcas_string_dispose(char *)
Releases memory of C string pointers provided by other functions.
LLCAS_PUBLIC bool llcas_cas_validate(llcas_cas_t, bool check_hash, char **error)
Validate the CAS contents.
LLCAS_PUBLIC llcas_cas_options_t llcas_cas_options_create(void)
Options object to configure creation of llcas_cas_t.
LLCAS_PUBLIC bool llcas_actioncache_validate(llcas_cas_t, char **error)
Validate the action cache contents.
LLCAS_PUBLIC bool llcas_loaded_object_export_data_to_filepath(llcas_cas_t, llcas_loaded_object_t, const char *filepath, char **error)
Exports the data of an object to a file path.
LLCAS_PUBLIC llcas_lookup_result_t llcas_actioncache_get_for_digest(llcas_cas_t, llcas_digest_t key, llcas_objectid_t *p_value, bool globally, char **error)
Retrieves the llcas_objectid_t value associated with a key.
LLCAS_PUBLIC bool llcas_cas_store_object(llcas_cas_t, llcas_data_t, const llcas_objectid_t *refs, size_t refs_count, llcas_objectid_t *p_id, char **error)
Stores the object with the provided data buffer and llcas_objectid_t references, and provides its ass...
LLCAS_PUBLIC llcas_validation_result_t llcas_cas_recover_ondisk_data(llcas_cas_options_t, char **error)
Recover from invalid on-disk CAS and action cache contents after llcas_cas_validate_if_needed failed ...
LLCAS_PUBLIC void llcas_cas_options_set_ondisk_path(llcas_cas_options_t, const char *path)
Receives a local file-system path that the plugin should use for any on-disk resources/caches.
LLCAS_PUBLIC size_t llcas_object_refs_get_count(llcas_cas_t, llcas_object_refs_t)
LLCAS_PUBLIC bool llcas_cas_prune_ondisk_data(llcas_cas_t, char **error)
Prune local storage to reduce its size according to the desired size limit.
LLCAS_PUBLIC unsigned llcas_digest_parse(llcas_cas_t, const char *printed_digest, uint8_t *bytes, size_t bytes_size, char **error)
Parses the printed digest and returns the digest hash bytes.
LLCAS_PUBLIC llcas_objectid_t llcas_object_refs_get_id(llcas_cas_t, llcas_object_refs_t, size_t index)
LLCAS_PUBLIC void llcas_cas_dispose(llcas_cas_t)
Releases memory of llcas_cas_t.
LLCAS_PUBLIC void llcas_cas_load_object_async(llcas_cas_t, llcas_objectid_t, void *ctx_cb, llcas_cas_load_object_cb, llcas_cancellable_t *cancel_tok)
Like llcas_cas_load_object but loading happens via a callback function.
LLCAS_PUBLIC void llcas_actioncache_put_for_digest_async(llcas_cas_t, llcas_digest_t key, llcas_objectid_t value, bool globally, void *ctx_cb, llcas_actioncache_put_cb, llcas_cancellable_t *cancel_tok)
Like llcas_actioncache_put_for_digest but result is provided to a callback function.
LLCAS_PUBLIC void llcas_cas_options_set_client_version(llcas_cas_options_t, unsigned major, unsigned minor)
Receives the LLCAS_VERSION_MAJOR and LLCAS_VERSION_MINOR values that the client was compiled with.
LLCAS_PUBLIC llcas_lookup_result_t llcas_cas_contains_object(llcas_cas_t, llcas_objectid_t, bool globally, char **error)
Checks whether a llcas_objectid_t points to an existing object.
LLCAS_PUBLIC bool llcas_actioncache_put_for_digest(llcas_cas_t, llcas_digest_t key, llcas_objectid_t value, bool globally, char **error)
Associates a llcas_objectid_t value with a key.
LLCAS_PUBLIC llcas_lookup_result_t llcas_cas_load_object(llcas_cas_t, llcas_objectid_t, llcas_loaded_object_t *, char **error)
Loads the object that llcas_objectid_t points to.
LLCAS_PUBLIC void llcas_standalone_data_dispose(llcas_data_t)
Releases a buffer returned by llcas_loaded_object_get_standalone_data.
LLCAS_PUBLIC llcas_validation_result_t llcas_cas_validate_if_needed(llcas_cas_options_t, bool check_hash, bool force, char **error)
Validate the on-disk CAS and action cache contents in-process, if needed.
LLCAS_PUBLIC llcas_data_t llcas_loaded_object_get_standalone_data(llcas_cas_t, llcas_loaded_object_t)
LLCAS_PUBLIC bool llcas_cas_get_objectid(llcas_cas_t, llcas_digest_t digest, llcas_objectid_t *p_id, char **error)
Provides the llcas_objectid_t value for the given llcas_digest_t.
#define LLCAS_PUBLIC
LLCAS_PUBLIC llcas_digest_t llcas_objectid_get_digest(llcas_cas_t, llcas_objectid_t)
LLCAS_PUBLIC llcas_object_refs_t llcas_loaded_object_get_refs(llcas_cas_t, llcas_loaded_object_t)
LLCAS_PUBLIC llcas_data_t llcas_loaded_object_get_data(llcas_cas_t, llcas_loaded_object_t)
LLCAS_PUBLIC bool llcas_cas_set_ondisk_size_limit(llcas_cas_t, int64_t size_limit, char **error)
Set the size for limiting disk storage growth.
LLCAS_PUBLIC void llcas_cancellable_cancel(llcas_cancellable_t)
Cancels the asynchronous query associated with the llcas_cancellable_t.
LLCAS_PUBLIC void llcas_cas_options_dispose(llcas_cas_options_t)
LLCAS_PUBLIC bool llcas_cas_options_set_option(llcas_cas_options_t, const char *name, const char *value, char **error)
Receives a name/value strings pair, for the plugin to set as a custom option it supports.
struct llcas_cas_options_s * llcas_cas_options_t
struct llcas_cancellable_s * llcas_cancellable_t
void(* llcas_actioncache_get_cb)(void *ctx, llcas_lookup_result_t, llcas_objectid_t, char *error)
Callback for llcas_actioncache_get_for_digest_async.
struct llcas_cas_s * llcas_cas_t
llcas_validation_result_t
Return values for llcas_cas_validate_if_needed and llcas_cas_recover_ondisk_data.
llcas_lookup_result_t
Return values for a load operation.
void(* llcas_cas_load_object_cb)(void *ctx, llcas_lookup_result_t, llcas_loaded_object_t, char *error)
Callback for llcas_cas_load_object_async.
void(* llcas_actioncache_put_cb)(void *ctx, bool failed, char *error)
Callback for llcas_actioncache_put_for_digest_async.
static const char * name
#define error(X)
Data buffer for stored CAS objects.
Digest hash bytes.
A loaded CAS object.
Object references for a CAS object.
Identifier for a CAS object.