35 assert(res2 == 0 || errno == EEXIST);
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);
67 FILE *gc_flagged_file = fopen(gc_path.c_str(),
"w");
68 for (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),
113 i += thread_context->
thread_total * +(max_val / max_dir_name)) {
115 for (
unsigned j = i; j < i + (max_val / max_dir_name); j++) {
117 unsigned path_pos = offset;
118 for (
int level =
kDirLevels - 1; level >= 0; level--) {
125 dir_path[path_pos] =
'\0';
127 DIR *cur_dir_ent = opendir(dir_path);
128 assert(cur_dir_ent != NULL);
129 struct stat stat_buf;
131 while ((de = readdir(cur_dir_ent)) != NULL) {
132 if (posix_ctx->
gc_flagged.count(de->d_ino) > 0
134 snprintf(dir_path + path_pos,
sizeof(dir_path) - path_pos,
"%s",
136 stat(dir_path, &stat_buf);
137 if (stat_buf.st_nlink == 1) {
139 bytes_removed += stat_buf.st_size;
140 int res = unlink(dir_path);
146 closedir(cur_dir_ent);
150 ->
Xadd(files_removed);
152 ->
Xadd(bytes_removed);
174 "Number of deduplicated files removed by Garbage Collector");
176 "Sum of sizes of removed files");
178 if (thread_total > 1) {
179 pthread_t *workers =
reinterpret_cast<pthread_t *
>(
180 smalloc(
sizeof(pthread_t) * thread_total));
184 thread_contexts[i].
ctx =
ctx;
185 thread_contexts[i].
stat = gc_statistics;
187 &thread_contexts[i]);
192 pthread_join(workers[i], NULL);
198 thread_contexts[0].
ctx =
ctx;
199 thread_contexts[0].
stat = gc_statistics;
204 free(thread_contexts);
205 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,...)