8 #define __STDC_FORMAT_MACROS
14 #include <sys/types.h>
56 const_cast<cvmcache_hash *>(&(other.
hash))) < 0;
101 unsigned char *buffer)
105 if (offset > data.length())
108 std::min(*size, static_cast<uint32_t>(data.length() - offset));
109 memcpy(buffer, data.data() + offset, nbytes);
121 partial_object.
id = *id;
123 partial_object.
refcnt = 1;
136 unsigned char *buffer,
162 for (map<ComparableHash, Object>::const_iterator i =
storage.begin(),
163 i_end =
storage.end(); i != i_end; ++i)
166 if (i->second.refcnt > 0)
181 for (map<ComparableHash, Object>::iterator i =
storage.begin(),
182 i_end =
storage.end(); i != i_end; )
189 unsigned length = i->second.data.length();
190 map<ComparableHash, Object>::iterator delete_me = i++;
199 for (map<ComparableHash, Object>::iterator i =
storage.begin(),
200 i_end =
storage.end(); i != i_end; )
202 if (i->second.refcnt > 0) {
206 unsigned length = i->second.data.length();
207 map<ComparableHash, Object>::iterator delete_me = i++;
226 lst.
elems =
new vector<Object>();
227 for (map<ComparableHash, Object>::const_iterator i =
storage.begin(),
228 i_end =
storage.end(); i != i_end; ++i)
230 lst.
elems->push_back(i->second);
245 vector<Object> *elems = lst.
elems;
246 if ((*elems)[lst.
pos].type == lst.
type) {
247 item->
id = (*elems)[lst.
pos].id;
248 item->
size = (*elems)[lst.
pos].data.length();
249 item->
type = (*elems)[lst.
pos].type;
250 item->
pinned = (*elems)[lst.
pos].refcnt > 0;
253 : strdup((*elems)[lst.
pos].description.c_str());
281 map<std::string, cvmcache_breadcrumb>::const_iterator itr =
285 *breadcrumb = itr->second;
289 static void Usage(
const char *progname) {
290 printf(
"%s <config file>\n", progname);
294 int main(
int argc,
char **argv) {
304 printf(
"cannot parse options file %s\n", argv[1]);
308 if (locator == NULL) {
309 printf(
"CVMFS_CACHE_PLUGIN_LOCATOR missing\n");
319 memset(&callbacks, 0,
sizeof(callbacks));
339 fprintf(stderr,
"failed to listen on %s\n", locator);
347 if ((pid = fork()) == 0) {
348 if ((pid = fork()) == 0) {
349 int null_read = open(
"/dev/null", O_RDONLY);
350 int null_write = open(
"/dev/null", O_WRONLY);
351 assert((null_read >= 0) && (null_write >= 0));
352 int retval = dup2(null_read, 0);
354 retval = dup2(null_write, 1);
356 retval = dup2(null_write, 2);
369 waitpid(pid, &statloc, 0);
374 printf(
"Listening for cvmfs clients on %s\n", locator);
375 printf(
"NOTE: this process needs to run as user cvmfs\n\n");
381 while (
true) sleep(1);
384 printf(
"Press <R ENTER> to ask clients to release nested catalogs\n");
385 printf(
"Press <Ctrl+D> to quit\n");
388 int retval = read(fileno(stdin), &buf, 1);
392 printf(
" ... asking clients to release nested catalogs\n");
400 printf(
" ... good bye\n");
static int null_write_txn(uint64_t txn_id, unsigned char *buffer, uint32_t size)
static int null_chrefcnt(struct cvmcache_hash *id, int32_t change_by)
int(* cvmcache_chrefcnt)(struct cvmcache_hash *id, int32_t change_by)
struct cvmcache_context * ctx
static int null_pread(struct cvmcache_hash *id, uint64_t offset, uint32_t *size, unsigned char *buffer)
struct cvmcache_hash hash
int(* cvmcache_info)(struct cvmcache_info *info)
static void Usage(const char *progname)
void cvmcache_terminate(struct cvmcache_context *ctx)
int cvmcache_listen(struct cvmcache_context *ctx, char *locator)
int(* cvmcache_listing_next)(int64_t lst_id, struct cvmcache_object_info *item)
void cvmcache_cleanup_global()
void cvmcache_terminate_watchdog()
static int null_listing_begin(uint64_t lst_id, enum cvmcache_object_type type)
static int null_breadcrumb_store(const char *fqrn, const cvmcache_breadcrumb *breadcrumb)
assert((mem||(size==0))&&"Out Of Memory")
int cvmcache_is_supervised()
map< uint64_t, TxnInfo > transactions
static int null_info(struct cvmcache_info *info)
int(* cvmcache_pread)(struct cvmcache_hash *id, uint64_t offset, uint32_t *size, unsigned char *buffer)
map< std::string, cvmcache_breadcrumb > breadcrumbs
int(* cvmcache_breadcrumb_load)(const char *fqrn, cvmcache_breadcrumb *breadcrumb)
static int null_start_txn(struct cvmcache_hash *id, uint64_t txn_id, struct cvmcache_object_info *info)
map< ComparableHash, Object > storage
void cvmcache_wait_for(struct cvmcache_context *ctx)
static int null_listing_end(int64_t listing_id)
static int null_shrink(uint64_t shrink_to, uint64_t *used)
static int null_breadcrumb_load(const char *fqrn, cvmcache_breadcrumb *breadcrumb)
void cvmcache_ask_detach(struct cvmcache_context *ctx)
int(* cvmcache_write_txn)(uint64_t txn_id, unsigned char *buffer, uint32_t size)
map< uint64_t, Listing > listings
int cvmcache_hash_cmp(struct cvmcache_hash *a, struct cvmcache_hash *b)
bool operator<(SharedPtr< T > const &a, SharedPtr< U > const &b)
cvmcache_object_type type
void cvmcache_options_free(char *value)
void cvmcache_spawn_watchdog(const char *crash_dump_file)
void cvmcache_options_fini(cvmcache_option_map *opts)
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)
static int null_obj_info(struct cvmcache_hash *id, struct cvmcache_object_info *info)
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)
char * cvmcache_options_get(cvmcache_option_map *opts, const char *key)
cvmcache_object_type type
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)
ComparableHash(const struct cvmcache_hash &h)
static int null_abort_txn(uint64_t txn_id)
int(* cvmcache_obj_info)(struct cvmcache_hash *id, struct cvmcache_object_info *info)
static int null_listing_next(int64_t listing_id, struct cvmcache_object_info *item)
static int null_commit_txn(uint64_t txn_id)
cvmcache_option_map * cvmcache_options_init()