lib/repo: Handle EACCES for POSIX locking
authorJonathan Lebon <jonathan@jlebon.com>
Tue, 30 Jun 2020 19:05:19 +0000 (15:05 -0400)
committerJonathan Lebon <jonathan@jlebon.com>
Tue, 30 Jun 2020 19:09:41 +0000 (15:09 -0400)
If `glnx_make_lock_file` falls back to `flock`, on NFS this uses POSIX
locks (`F_SETLK`). As such, we need to be able to handle `EACCES` as
well as `EAGAIN` (see `fnctl(2)`).

I think this is what coreos-ostree-importer has been hitting, which runs
on RHEL7 in the Fedora infra and does locking over an NFS share where
multiple apps could concurrently pull things into the repo.

src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo.c

index 7dd68e9664473efb8d736cb26a1a8d3f7a636d40..727e853bfadacfa93bed3e37d494a259dd422116 100644 (file)
@@ -1933,7 +1933,7 @@ rename_pending_loose_objects (OstreeRepo        *self,
   return TRUE;
 }
 
-/* Try to lock a transaction stage directory created by
+/* Try to lock and delete a transaction stage directory created by
  * ostree_repo_prepare_transaction().
  */
 static gboolean
index 5fd92bb9d47e863ba9e139d0950a57221c4106de..82dd286af769d827b03cf795cd38bdb4166c9202 100644 (file)
@@ -5980,7 +5980,9 @@ _ostree_repo_try_lock_tmpdir (int            tmpdir_dfd,
   if (!glnx_make_lock_file (tmpdir_dfd, lock_name, LOCK_EX | LOCK_NB,
                             file_lock_out, &local_error))
     {
-      if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
+      /* we need to handle EACCES too in the case of POSIX locks; see F_SETLK in fcntl(2) */
+      if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)
+          || g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED))
         {
           did_lock = FALSE;
         }