47 std::vector<std::string>
list;
48 std::vector<std::string>::iterator
it;
53 is_alien(false), cache_base_defined(false),
54 cache_dir_defined(false), quota_limit(0)
58 if (is_alien && quota_limit > 0) {
59 error_reason =
"Alien cache cannot be managed (no quota manager allowed)";
62 if (is_alien && workspace ==
"") {
63 error_reason =
"Workspace option needs to be set for alien cache";
66 if ((is_alien ? 1 : 0) +
67 (cache_base_defined ? 1 : 0) +
68 (cache_dir_defined ? 1 : 0) != 1) {
69 error_reason =
"CVMFS_CACHE_DIR, CVMFS_CACHE_BASE and CVMFS_CACHE_ALIEN "
70 "are mutually exclusive. Exactly one needs to be defined.";
133 return (uint32_t) *(
reinterpret_cast<const uint32_t *
>(key.
digest) + 1);
137 return (uint32_t) key;
180 }
else if (static_cast<int32_t>(
object.refcnt) + change_by < 0) {
184 object.refcnt += change_by;
185 if (
object.refcnt == 0) {
206 info->
size =
object.size;
211 uint32_t *
size,
unsigned char *buffer) {
216 if (offset >
object.size) {
220 if (bytes_read < 0) {
223 *size =
static_cast<uint32_t
>(bytes_read);
238 transaction.
hash = *id;
239 transaction.
txn = txn;
264 if ((bytes_written >= 0) && (static_cast<uint32_t>(bytes_written) == size)) {
351 int main(
int argc,
char **argv) {
353 fprintf(stderr,
"Missing argument: path to config file\n");
362 "cannot parse options file %s", argv[1]);
367 if (debug_log != NULL) {
374 if (locator == NULL) {
376 "CVMFS_CACHE_PLUGIN_LOCATOR missing");
382 char *watchdog_crash_dump_path =
385 if (watchdog_crash_dump_path)
390 if (!settings.IsValid()) {
392 "Invalid config in file %s: %s", argv[1],
393 settings.error_reason.c_str());
402 memset(empty_hash.
digest, 0, 20);
414 memset(&callbacks, 0,
sizeof(callbacks));
432 "failed to listen on %s", locator);
440 if ((pid = fork()) == 0) {
441 if ((pid = fork()) == 0) {
442 int null_read = open(
"/dev/null", O_RDONLY);
443 int null_write = open(
"/dev/null", O_WRONLY);
444 assert((null_read >= 0) && (null_write >= 0));
445 int retval = dup2(null_read, 0);
447 retval = dup2(null_write, 1);
449 retval = dup2(null_write, 2);
462 waitpid(pid, &statloc, 0);
473 "Running unsupervised. Quit by SIGINT (CTRL+C)");
int posix_breadcrumb_store(const char *fqrn, const cvmcache_breadcrumb *breadcrumb)
struct cvmcache_hash catalog_hash
int(* cvmcache_chrefcnt)(struct cvmcache_hash *id, int32_t change_by)
struct cvmcache_hash Cpphash2Chash(const shash::Any &hash)
virtual int64_t Write(const void *buf, uint64_t size, void *txn)
SmallHashDynamic< uint64_t, Txn > * g_transactions
virtual int Open(const LabeledObject &object)
virtual int CommitTxn(void *txn)
int(* cvmcache_info)(struct cvmcache_info *info)
std::vector< std::string > list
void cvmcache_terminate(struct cvmcache_context *ctx)
static const int kLabelCatalog
uint32_t cvmcache_hash_hasher(const struct cvmcache_hash &key)
int cvmcache_listen(struct cvmcache_context *ctx, char *locator)
Settings GetSettings(cvmcache_option_map *options)
void cvmcache_cleanup_global()
virtual int AbortTxn(void *txn)
struct cvmcache_hash hash
void cvmcache_terminate_watchdog()
int posix_pread(struct cvmcache_hash *id, uint64_t offset, uint32_t *size, unsigned char *buffer)
const SettingsPublisher & settings() const
virtual int64_t GetSize(int fd)
int posix_breadcrumb_load(const char *fqrn, cvmcache_breadcrumb *breadcrumb)
assert((mem||(size==0))&&"Out Of Memory")
virtual void CtrlTxn(const Label &label, const int flags, void *txn)
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)
int posix_info(struct cvmcache_info *info)
#define SetLogDebugFile(filename)
unsigned char digest[digest_size_]
virtual int OpenFromTxn(void *txn)
void cvmcache_wait_for(struct cvmcache_context *ctx)
int64_t String2Int64(const string &value)
int posix_abort_txn(uint64_t txn_id)
static PosixCacheManager * Create(const std::string &cache_path, const bool alien_cache, const RenameWorkarounds rename_workaround=kRenameNormal, const bool do_refcount=true)
int(* cvmcache_write_txn)(uint64_t txn_id, unsigned char *buffer, uint32_t size)
virtual int StartTxn(const shash::Any &id, uint64_t size, void *txn)
virtual manifest::Breadcrumb LoadBreadcrumb(const std::string &fqrn)
SmallHashDynamic< struct cvmcache_hash, CacheObject > * g_opened_objects
cvmcache_object_type type
PosixCacheManager * g_cache_mgr
SmallHashDynamic< uint64_t, Listing > * g_listings
bool operator!=(const cvmcache_hash &a, const cvmcache_hash &b)
int posix_commit_txn(uint64_t txn_id)
uint32_t uint64_hasher(const uint64_t &key)
void cvmcache_options_free(char *value)
atomic_int32 g_terminated
void cvmcache_spawn_watchdog(const char *crash_dump_file)
void cvmcache_options_fini(cvmcache_option_map *opts)
void handle_sigint(int sig)
int posix_start_txn(struct cvmcache_hash *id, uint64_t txn_id, struct cvmcache_object_info *info)
enum cvmcache_object_type type
struct cvmcache_context * cvmcache_init(struct cvmcache_callbacks *callbacks)
void cvmcache_init_global()
static const int kLabelVolatile
int cvmcache_options_parse(cvmcache_option_map *opts, const char *path)
#define CVMCACHE_SIZE_UNKNOWN
bool operator==(const cvmcache_hash &a, const cvmcache_hash &b)
void cvmcache_process_requests(struct cvmcache_context *ctx, unsigned nworkers)
int(* cvmcache_breadcrumb_store)(const char *fqrn, const cvmcache_breadcrumb *breadcrumb)
int posix_write_txn(uint64_t txn_id, unsigned char *buffer, uint32_t size)
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_abort_txn)(uint64_t txn_id)
int posix_chrefcnt(struct cvmcache_hash *id, int32_t change_by)
std::string MakeCanonicalPath(const std::string &path)
int posix_obj_info(struct cvmcache_hash *id, struct cvmcache_object_info *info)
virtual bool StoreBreadcrumb(const manifest::Manifest &manifest)
int(* cvmcache_obj_info)(struct cvmcache_hash *id, struct cvmcache_object_info *info)
shash::Any Chash2Cpphash(const struct cvmcache_hash *h)
std::vector< std::string >::iterator it
virtual int Close(int fd)
virtual int64_t Pread(int fd, void *buf, uint64_t size, uint64_t offset)
cvmcache_object_type type
virtual uint32_t SizeOfTxn()
cvmcache_option_map * cvmcache_options_init()
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)