]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_index_lock_sync() and mail_index_unlock()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 16 Apr 2020 11:46:03 +0000 (14:46 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 16 Apr 2020 11:52:20 +0000 (14:52 +0300)
src/lib-index/mail-index.c
src/lib-index/mail-index.h

index fa9226efd656238c9d2ca617bc9bb8713aea396e..6b54979e07d896cb22fbf07f8c0272decab88b5f 100644 (file)
@@ -1037,6 +1037,25 @@ void mail_index_fchown(struct mail_index *index, int fd, const char *path)
                mail_index_file_set_syscall_error(index, path, "fchmod()");
 }
 
+int mail_index_lock_sync(struct mail_index *index, const char *lock_reason)
+{
+       uint32_t file_seq;
+       uoff_t file_offset;
+
+       return mail_transaction_log_sync_lock(index->log, lock_reason,
+                                             &file_seq, &file_offset);
+}
+
+void mail_index_unlock(struct mail_index *index, const char *long_lock_reason)
+{
+       mail_transaction_log_sync_unlock(index->log, long_lock_reason);
+}
+
+bool mail_index_is_locked(struct mail_index *index)
+{
+       return index->log_sync_locked;
+}
+
 void mail_index_set_syscall_error(struct mail_index *index,
                                  const char *function)
 {
index 6c725e8fc8336d8d6cfe4e2d80fd5f557dbeea16..b9ab3aaf7fdbe4da5cc0e5bed132f9ec554c5318 100644 (file)
@@ -490,6 +490,18 @@ int mail_index_sync_commit(struct mail_index_sync_ctx **ctx);
    actually written to index file. */
 void mail_index_sync_rollback(struct mail_index_sync_ctx **ctx);
 
+/* Lock the index exclusively. This is the same locking as what happens when
+   syncing the index. It's not necessary to normally call this function, unless
+   doing something special such as rebuilding the index outside syncing.
+   Returns 0 on success, -1 if locking failed for any reason. */
+int mail_index_lock_sync(struct mail_index *index, const char *lock_reason);
+/* Unlock the locked index. The index must have been locked previously with
+   mail_index_lock_sync(). If the lock had been kept for excessively long,
+   a warning is logged with the long_lock_reason. */
+void mail_index_unlock(struct mail_index *index, const char *long_lock_reason);
+/* Returns TRUE if index is currently exclusively locked. */
+bool mail_index_is_locked(struct mail_index *index);
+
 /* Mark index file corrupted. Invalidates all views. */
 void mail_index_mark_corrupted(struct mail_index *index);
 /* Check and fix any found problems. Returns -1 if we couldn't lock for sync,