Mesa (staging/21.1): util/fossilize_db: Be conservative about header length check for locking.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Aug 9 07:32:38 UTC 2021


Module: Mesa
Branch: staging/21.1
Commit: eb865f3b90cccb36e2f8898f442b10ba2e186488
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb865f3b90cccb36e2f8898f442b10ba2e186488

Author: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Date:   Thu Aug  5 01:30:25 2021 +0200

util/fossilize_db: Be conservative about header length check for locking.

Don't anticipate seeing any partial written headers but just in case we
should probably wait on the lock to make sure whatever header was being
written is finished being written.

Fixes: 4f0f8133a35 "util/fossilize_db: Do not lock the fossilize db permanently."
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12204>
(cherry picked from commit 96bfefe8d1209b6aaa56fd77ca570789d82efb6e)

---

 .pick_status.json       | 2 +-
 src/util/fossilize_db.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 166bae1eed6..452b024c965 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -175,7 +175,7 @@
         "description": "util/fossilize_db: Be conservative about header length check for locking.",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "4f0f8133a35ec2fec8d99936cd7425e40d092169"
     },
diff --git a/src/util/fossilize_db.c b/src/util/fossilize_db.c
index 8d773e78ec3..4a25d077ee4 100644
--- a/src/util/fossilize_db.c
+++ b/src/util/fossilize_db.c
@@ -203,8 +203,9 @@ load_foz_dbs(struct foz_db *foz_db, FILE *db_idx, uint8_t file_idx,
    size_t len = ftell(db_idx);
    rewind(db_idx);
 
-   /* Try not to take the lock if len > 0, but if it is 0 we take the lock to initialize the files. */
-   if (len == 0) {
+   /* Try not to take the lock if len >= the size of the header, but if it is smaller we take the
+    * lock to potentially initialize the files. */
+   if (len < sizeof(stream_reference_magic_and_version)) {
       /* Wait for 100 ms in case of contention, after that we prioritize getting the app started. */
       int err = lock_file_with_timeout(foz_db->file[file_idx], 100000000);
       if (err == -1)



More information about the mesa-commit mailing list