Skip to content

Commit

Permalink
Don't cache data by default in GROW FUSE module
Browse files Browse the repository at this point in the history
  • Loading branch information
tshaffe1 committed Sep 7, 2017
1 parent 61df543 commit 446b886
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions grow/src/grow_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@
struct fuse_root *root = ctx->private_data;

static FILE *stats_out = NULL;
static int cache_data = 0;

static struct options {
int show_help;
const char *basedir;
const char *stats_file;
int cache_data;
} options;

static const struct fuse_opt option_spec[] = {
OPTION("--basedir %s", basedir),
OPTION("--stats-file %s", stats_file),
OPTION("--cache", cache_data),
OPTION("-h", show_help),
OPTION("--help", show_help),
FUSE_OPT_END
Expand All @@ -71,6 +74,12 @@ static int cache_open(struct fuse_root *root, const char *path, int flags) {
if (!e) return -errno;
if (flags&O_WRONLY || flags&O_RDWR) return -EROFS;

if (!cache_data) {
stats_inc("grow.fuse.direct_open", 1);
while (path[0] == '/') ++path;
return openat(root->fd, path, flags);
}

retry:
if (retries > 10) return -ELOOP;
snprintf(cachepath, sizeof(cachepath), "%c%c/%s", e->checksum[0], e->checksum[1], &e->checksum[2]);
Expand Down Expand Up @@ -382,6 +391,7 @@ int main(int argc, char *argv[]) {
assert(fuse_opt_add_arg(&args, "-ononempty") == 0);
assert(fuse_opt_add_arg(&args, "-okernel_cache") == 0);

cache_data = options.cache_data;
if (options.stats_file) {
stats_enable();
stats_out = fopen(options.stats_file, "w");
Expand All @@ -390,21 +400,23 @@ int main(int argc, char *argv[]) {
}
}

char path[PATH_MAX];
char *tmpdir = getenv("TMPDIR");
if (!tmpdir) tmpdir = "/tmp";
snprintf(path, sizeof(path), "%s/.growcache", tmpdir);
if (mkdir(path, 0755) < 0 && errno != EEXIST) {
fatal("failed to make cache dir %s: %s", path, strerror(errno));
}
root.cache = open(path, O_PATH|O_DIRECTORY);
if (root.cache < 0) {
fatal("failed to open cache dir %s: %s", path, strerror(errno));
}
for (unsigned i = 0; i < 256; i++) {
sprintf(path, "%02x", i);
if (mkdirat(root.cache, path, 0755) < 0 && errno != EEXIST) {
fatal("failed to make cache subdir %s: path", path, strerror(errno));
if (cache_data) {
char path[PATH_MAX];
char *tmpdir = getenv("TMPDIR");
if (!tmpdir) tmpdir = "/tmp";
snprintf(path, sizeof(path), "%s/.growcache", tmpdir);
if (mkdir(path, 0755) < 0 && errno != EEXIST) {
fatal("failed to make cache dir %s: %s", path, strerror(errno));
}
root.cache = open(path, O_PATH|O_DIRECTORY);
if (root.cache < 0) {
fatal("failed to open cache dir %s: %s", path, strerror(errno));
}
for (unsigned i = 0; i < 256; i++) {
sprintf(path, "%02x", i);
if (mkdirat(root.cache, path, 0755) < 0 && errno != EEXIST) {
fatal("failed to make cache subdir %s: path", path, strerror(errno));
}
}
}

Expand Down

0 comments on commit 446b886

Please sign in to comment.