From e596882dd16dd0374a621a0ca2be87fade08cd05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Tue, 17 Sep 2024 15:18:36 +0200 Subject: [PATCH] util/mesa-db: Recreate files if header load or index update fails The previous behaviour had these issues: 1. It meant that this part of the cache couldn't be used this time. 2. It left the corrupted index/cache files unchanged, so the same failure might happen again next time. Recreating the index & cache files for this part means it can be used, it just loses any previously cached contents. Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko Acked-by: Timothy Arceri Part-of: --- src/util/mesa_cache_db.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/util/mesa_cache_db.c b/src/util/mesa_cache_db.c index 384ac556fe5..d5c2a9f1f13 100644 --- a/src/util/mesa_cache_db.c +++ b/src/util/mesa_cache_db.c @@ -335,10 +335,6 @@ mesa_db_load(struct mesa_cache_db *db, bool reload) !mesa_db_load_header(&db->index) || db->cache.uuid != db->index.uuid) { - /* This is unexpected to happen on reload, bail out */ - if (reload) - goto fail; - if (!mesa_db_recreate_files(db)) goto fail; } else { @@ -350,8 +346,16 @@ mesa_db_load(struct mesa_cache_db *db, bool reload) if (reload) mesa_db_hash_table_reset(db); - if (!mesa_db_update_index(db)) - goto fail; + /* The update failed so we assume the files are corrupt and + * recreate them. + */ + if (!mesa_db_update_index(db)) { + mesa_db_recreate_files(db); + db->index.offset = ftell(db->index.file); + + if (!mesa_db_update_index(db)) + goto fail; + } if (!reload) mesa_db_unlock(db);