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 <dmitry.osipenko@collabora.com>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Acked-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30988>
This commit is contained in:
Michel Dänzer
2024-09-17 15:18:36 +02:00
committed by Marge Bot
parent 13c44abaac
commit e596882dd1
+10 -6
View File
@@ -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);