From 9d1ef1595c8cf2ec2b7fe95840d13550ede87c5b Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Thu, 25 Feb 2021 21:15:22 +1100 Subject: [PATCH] util/disk_cache: make MESA_DISK_CACHE_READ_ONLY_FOZ_DBS a relative path Rather than passing in full paths this changes things so that we can just pass in filenames relative to the current cache directory. Part-of: --- src/util/disk_cache.c | 2 +- src/util/disk_cache_os.c | 9 ++------- src/util/disk_cache_os.h | 3 +-- src/util/fossilize_db.c | 13 +++++++------ src/util/fossilize_db.h | 2 +- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index 3617fc1f1d2..511b2c7920d 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -112,7 +112,7 @@ disk_cache_create(const char *gpu_name, const char *driver_id, goto path_fail; if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false)) { - if (!disk_cache_load_cache_index(local, cache, path)) + if (!disk_cache_load_cache_index(local, cache)) goto path_fail; } diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index 865ff7bf3dd..1f6cbeb3bd4 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -953,15 +953,10 @@ disk_cache_write_item_to_disk_foz(struct disk_cache_put_job *dc_job) } bool -disk_cache_load_cache_index(void *mem_ctx, struct disk_cache *cache, - char *path) +disk_cache_load_cache_index(void *mem_ctx, struct disk_cache *cache) { - path = ralloc_asprintf(mem_ctx, "%s/foz_cache", cache->path); - if (path == NULL) - return false; - /* Load cache index into a hash map (from fossilise files) */ - return foz_prepare(&cache->foz_db, path); + return foz_prepare(&cache->foz_db, cache->path); } bool diff --git a/src/util/disk_cache_os.h b/src/util/disk_cache_os.h index 69fd0b7134a..a87140bf6ac 100644 --- a/src/util/disk_cache_os.h +++ b/src/util/disk_cache_os.h @@ -124,8 +124,7 @@ bool disk_cache_enabled(void); bool -disk_cache_load_cache_index(void *mem_ctx, struct disk_cache *cache, - char *path); +disk_cache_load_cache_index(void *mem_ctx, struct disk_cache *cache); bool disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache, diff --git a/src/util/fossilize_db.c b/src/util/fossilize_db.c index 91f8f8cb0b0..3adfaf1ab2c 100644 --- a/src/util/fossilize_db.c +++ b/src/util/fossilize_db.c @@ -97,13 +97,13 @@ check_files_opened_successfully(FILE *file, FILE *db_idx) } static bool -create_foz_db_filenames(char *base_filename, char **filename, +create_foz_db_filenames(char *cache_path, char *name, char **filename, char **idx_filename) { - if (asprintf(filename, "%s.foz", base_filename) == -1) + if (asprintf(filename, "%s/%s.foz", cache_path, name) == -1) return false; - if (asprintf(idx_filename, "%s_idx.foz", base_filename) == -1) { + if (asprintf(idx_filename, "%s/%s_idx.foz", cache_path, name) == -1) { free(*filename); return false; } @@ -232,11 +232,11 @@ fail: * read cache entries from the foz db containing the actual cache entries. */ bool -foz_prepare(struct foz_db *foz_db, char *base_filename) +foz_prepare(struct foz_db *foz_db, char *cache_path) { char *filename = NULL; char *idx_filename = NULL; - if (!create_foz_db_filenames(base_filename, &filename, &idx_filename)) + if (!create_foz_db_filenames(cache_path, "foz_cache", &filename, &idx_filename)) return false; /* Open the default foz dbs for read/write. If the files didn't already exist @@ -269,7 +269,8 @@ foz_prepare(struct foz_db *foz_db, char *base_filename) filename = NULL; idx_filename = NULL; - if (!create_foz_db_filenames(foz_db_filename, &filename, &idx_filename)) { + if (!create_foz_db_filenames(cache_path, foz_db_filename, &filename, + &idx_filename)) { free(foz_db_filename); continue; /* Ignore invalid user provided filename and continue */ } diff --git a/src/util/fossilize_db.h b/src/util/fossilize_db.h index 3cfd0a01cad..f9d62290aac 100644 --- a/src/util/fossilize_db.h +++ b/src/util/fossilize_db.h @@ -84,7 +84,7 @@ struct foz_db { }; bool -foz_prepare(struct foz_db *foz_db, char *filename); +foz_prepare(struct foz_db *foz_db, char *cache_path); void foz_destroy(struct foz_db *foz_db);