35 assert(res2 == 0 || errno == EEXIST);
36 std::string gc_path = std::string(ctx->
data)
39 FILE *gc_flagged_file = fopen(gc_path.c_str(),
"r");
40 assert(gc_flagged_file != NULL);
43 size_t read = fread(&cur_ino,
sizeof(ino_t), 1, gc_flagged_file);
47 assert(feof(gc_flagged_file) != 0);
51 int res = fclose(gc_flagged_file);
64 std::string gc_path = std::string(ctx->
data)
66 FILE *gc_flagged_file = fopen(gc_path.c_str(),
"w");
68 std::map<ino_t, bool>::const_iterator it = posix_ctx->
gc_flagged.begin();
72 fwrite(&(it->first),
sizeof(ino_t), 1, gc_flagged_file);
75 fclose(gc_flagged_file);
93 int64_t files_removed = 0;
94 int64_t bytes_removed = 0;
96 int offset = strlen(thread_context->
ctx->
data)+1;
99 snprintf(dir_path, offset,
"%s", thread_context->
ctx->
data);
100 dir_path[offset-1]=
'/';
102 char dir_name_template[6];
103 snprintf(dir_name_template,
104 sizeof(dir_name_template),
112 i+=thread_context->
thread_total*+(max_val/max_dir_name)) {
114 for (
unsigned j = i; j < i+(max_val/max_dir_name); j++) {
116 unsigned path_pos = offset;
120 const unsigned cur_dir
122 snprintf(dir_path+path_pos,
126 dir_path[path_pos]=
'\0';
128 DIR *cur_dir_ent = opendir(dir_path);
129 assert(cur_dir_ent != NULL);
130 struct stat stat_buf;
132 while ((de = readdir(cur_dir_ent)) != NULL) {
133 if (posix_ctx->
gc_flagged.count(de->d_ino) > 0
135 snprintf(dir_path+path_pos,
sizeof(dir_path)-path_pos,
"%s",
137 stat(dir_path, &stat_buf);
138 if (stat_buf.st_nlink == 1) {
140 bytes_removed+=stat_buf.st_size;
141 int res = unlink(dir_path);
147 closedir(cur_dir_ent);
173 "Number of deduplicated files removed by Garbage Collector");
175 "Sum of sizes of removed files");
177 if (thread_total > 1) {
179 =
reinterpret_cast<pthread_t *
>(smalloc(
sizeof(pthread_t) * thread_total));
183 thread_contexts[i].
ctx =
ctx;
184 thread_contexts[i].
stat = gc_statistics;
185 int retval = pthread_create(&workers[i], NULL,
191 pthread_join(workers[i], NULL);
197 thread_contexts[0].
ctx =
ctx;
198 thread_contexts[0].
stat = gc_statistics;
203 free(thread_contexts);
204 delete gc_statistics;
#define POSIX_GARBAGE_DIR
std::map< ino_t, bool > gc_flagged
Counter * Register(const std::string &name, const std::string &desc)
struct cvmcache_context * ctx
void * PosixGcMainWorker(void *data)
#define POSIX_GARBAGE_FLAGGED_FILE
void FinalizeGarbageCollection(struct fs_traversal_context *ctx)
assert((mem||(size==0))&&"Out Of Memory")
void InitializeGarbageCollection(struct fs_traversal_context *ctx)
bool FileExists(const std::string &path)
Counter * Lookup(const std::string &name) const
int RunGarbageCollection(struct fs_traversal_context *ctx)
const unsigned kDigitsPerDirLevel
const unsigned kDirLevels
#define POSIX_GC_STAT_BYTES_REMOVED
int64_t Xadd(const int64_t delta)
std::string PrintList(const PrintOptions print_options)
struct fs_traversal_context * ctx
#define POSIX_GC_STAT_FILES_REMOVED
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)