]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: file-lock - Rename file_{wait,try}_lock_error() to file_{wait,try}_lock().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 20 Sep 2021 00:39:08 +0000 (02:39 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 23 Sep 2021 07:03:28 +0000 (07:03 +0000)
src/lib-dict/dict-file.c
src/lib-fs/fs-posix.c
src/lib-index/mail-index-lock.c
src/lib-index/mail-index-strmap.c
src/lib-storage/index/dbox-common/dbox-file.c
src/lib/file-create-locked.c
src/lib/file-lock.c
src/lib/file-lock.h
src/plugins/fts-squat/squat-trie.c
src/plugins/fts-squat/squat-uidlist.c

index eef096e0f810f23c52740fba97e10fa10cdbb18d..54ff92b7455d5f7b63d2e73ce1e529132f8eaa58 100644 (file)
@@ -522,10 +522,10 @@ file_dict_lock(struct file_dict *dict, struct file_lock **lock_r,
        *lock_r = NULL;
        do {
                file_lock_free(lock_r);
-               if (file_wait_lock_error(dict->fd, dict->path, F_WRLCK,
-                                        dict->lock_method,
-                                        file_dict_dotlock_settings.timeout,
-                                        lock_r, &error) <= 0) {
+               if (file_wait_lock(dict->fd, dict->path, F_WRLCK,
+                                  dict->lock_method,
+                                  file_dict_dotlock_settings.timeout,
+                                  lock_r, &error) <= 0) {
                        *error_r = t_strdup_printf(
                                "file_wait_lock(%s) failed: %s",
                                dict->path, error);
index 9e9d3e4a8e7460338cf366ad1145d648bba5be7c..66859b888085814a36e6228bb0d8578c2047325e 100644 (file)
@@ -702,15 +702,13 @@ fs_posix_lock(struct fs_file *_file, unsigned int secs, struct fs_lock **lock_r)
                             file->full_path);
 #else
                if (secs == 0) {
-                       ret = file_try_lock_error(file->fd, file->full_path,
-                                                 F_WRLCK,
-                                                 FILE_LOCK_METHOD_FLOCK,
-                                                 &fs_lock.file_lock, &error);
+                       ret = file_try_lock(file->fd, file->full_path, F_WRLCK,
+                                           FILE_LOCK_METHOD_FLOCK,
+                                           &fs_lock.file_lock, &error);
                } else {
-                       ret = file_wait_lock_error(file->fd, file->full_path,
-                                                  F_WRLCK,
-                                                  FILE_LOCK_METHOD_FLOCK, secs,
-                                                  &fs_lock.file_lock, &error);
+                       ret = file_wait_lock(file->fd, file->full_path, F_WRLCK,
+                                            FILE_LOCK_METHOD_FLOCK, secs,
+                                            &fs_lock.file_lock, &error);
                }
                if (ret < 0) {
                        fs_set_error_errno(_file->event, "flock(%s) failed: %s",
index e14461b5e88b67fd1bd0cb93d363812d9c82f6f3..83e106ec90e6b552e35ee472e4dba519725dba3e 100644 (file)
@@ -35,8 +35,8 @@ int mail_index_lock_fd(struct mail_index *index, const char *path, int fd,
                return 1;
        }
 
-       ret = file_wait_lock_error(fd, path, lock_type, index->set.lock_method,
-                                  timeout_secs, lock_r, &error);
+       ret = file_wait_lock(fd, path, lock_type, index->set.lock_method,
+                            timeout_secs, lock_r, &error);
        if (ret < 0)
                e_error(index->event, "%s", error);
        return ret;
index ddfbc547a5ec3c8abe9791345eb9d56fae82a478..c377508b92f7c829c3ff9640f9d8a361986a4a77 100644 (file)
@@ -1049,10 +1049,10 @@ static int mail_index_strmap_lock(struct mail_index_strmap *strmap)
 
                timeout_secs = I_MIN(MAIL_INDEX_STRMAP_TIMEOUT_SECS,
                                     strmap->index->set.max_lock_timeout_secs);
-               ret = file_wait_lock_error(strmap->fd, strmap->path, F_WRLCK,
-                                          strmap->index->set.lock_method,
-                                          timeout_secs, &strmap->file_lock,
-                                          &error);
+               ret = file_wait_lock(strmap->fd, strmap->path, F_WRLCK,
+                                    strmap->index->set.lock_method,
+                                    timeout_secs, &strmap->file_lock,
+                                    &error);
                if (ret <= 0) {
                        mail_index_set_error(strmap->index,
                                "file_wait_lock() failed with strmap index file %s: %s",
index dd4a2dbf6c87844b8fe2bfd7c20bbd9fb4bfbd46..fca8f4402346ccf0edf75f22e9ea769dde170650 100644 (file)
@@ -313,8 +313,8 @@ int dbox_file_try_lock(struct dbox_file *file)
        i_assert(file->fd != -1);
 
 #ifdef DBOX_FILE_LOCK_METHOD_FLOCK
-       ret = file_try_lock_error(file->fd, file->cur_path, F_WRLCK,
-                                 FILE_LOCK_METHOD_FLOCK, &file->lock, &error);
+       ret = file_try_lock(file->fd, file->cur_path, F_WRLCK,
+                           FILE_LOCK_METHOD_FLOCK, &file->lock, &error);
        if (ret < 0) {
                mail_storage_set_critical(&file->storage->storage,
                        "file_try_lock(%s) failed: %s", file->cur_path, error);
index 2d68b690aef7d625fb0db4f714e9802066fd07a8..38c9137713af72e8da1f883e714314d0a0860853 100644 (file)
@@ -29,8 +29,8 @@ try_lock_existing(int fd, const char *path,
                *error_r = t_strdup_printf("fstat(%s) failed: %m", path);
                return -1;
        }
-       if (file_wait_lock_error(fd, path, F_WRLCK, set->lock_method,
-                                set->lock_timeout_secs, lock_r, error_r) <= 0)
+       if (file_wait_lock(fd, path, F_WRLCK, set->lock_method,
+                          set->lock_timeout_secs, lock_r, error_r) <= 0)
                return -1;
        if (stat(path, &st2) == 0) {
                ret = st1.st_ino == st2.st_ino &&
@@ -104,8 +104,8 @@ try_create_new(const char *path, const struct file_create_settings *set,
        }
 
        ret = -1;
-       if (file_try_lock_error(fd, str_c(temp_path), F_WRLCK,
-                               set->lock_method, lock_r, error_r) <= 0) {
+       if (file_try_lock(fd, str_c(temp_path), F_WRLCK, set->lock_method,
+                         lock_r, error_r) <= 0) {
        } else if (link(str_c(temp_path), path) < 0) {
                if (errno == EEXIST) {
                        /* just created by somebody else */
index d35d7fdfcaa8fe7468f23a68ec26c2086ab3e672..5cfe00a2bc042aff9d85eba39a6a0e7956b1fd26 100644 (file)
@@ -56,12 +56,12 @@ const char *file_lock_method_to_str(enum file_lock_method method)
        i_unreached();
 }
 
-int file_try_lock_error(int fd, const char *path, int lock_type,
-                       enum file_lock_method lock_method,
-                       struct file_lock **lock_r, const char **error_r)
+int file_try_lock(int fd, const char *path, int lock_type,
+                 enum file_lock_method lock_method,
+                 struct file_lock **lock_r, const char **error_r)
 {
-       return file_wait_lock_error(fd, path, lock_type, lock_method, 0,
-                                   lock_r, error_r);
+       return file_wait_lock(fd, path, lock_type, lock_method, 0,
+                             lock_r, error_r);
 }
 
 static const char *
@@ -285,10 +285,9 @@ static int file_lock_do(int fd, const char *path, int lock_type,
        return 1;
 }
 
-int file_wait_lock_error(int fd, const char *path, int lock_type,
-                        enum file_lock_method lock_method,
-                        unsigned int timeout_secs,
-                        struct file_lock **lock_r, const char **error_r)
+int file_wait_lock(int fd, const char *path, int lock_type,
+                  enum file_lock_method lock_method, unsigned int timeout_secs,
+                  struct file_lock **lock_r, const char **error_r)
 {
        struct file_lock *lock;
        int ret;
@@ -382,8 +381,8 @@ static void file_try_unlink_locked(struct file_lock *lock)
        int ret;
 
        file_unlock_real(lock);
-       ret = file_try_lock_error(lock->fd, lock->path, F_WRLCK,
-                                 lock->lock_method, &temp_lock, &error);
+       ret = file_try_lock(lock->fd, lock->path, F_WRLCK, lock->lock_method,
+                           &temp_lock, &error);
        if (ret < 0) {
                i_error("file_lock_free(): Unexpectedly failed to retry locking %s: %s",
                        lock->path, error);
index 77e0dd9550a2ab15e7c6ee60d2bb7b581820213f..4769c0ed71397ee6d0d536f56c2b7f21bab1b1f4 100644 (file)
@@ -23,15 +23,14 @@ const char *file_lock_method_to_str(enum file_lock_method method);
 
 /* Lock the file. Returns 1 if successful, 0 if file is already locked,
    or -1 if error. lock_type is F_WRLCK or F_RDLCK. */
-int file_try_lock_error(int fd, const char *path, int lock_type,
-                       enum file_lock_method lock_method,
-                       struct file_lock **lock_r, const char **error_r);
+int file_try_lock(int fd, const char *path, int lock_type,
+                 enum file_lock_method lock_method,
+                 struct file_lock **lock_r, const char **error_r);
 /* Like lock_try_lock(), but return 0 only after having tried to lock for
    timeout_secs. */
-int file_wait_lock_error(int fd, const char *path, int lock_type,
-                        enum file_lock_method lock_method,
-                        unsigned int timeout_secs,
-                        struct file_lock **lock_r, const char **error_r);
+int file_wait_lock(int fd, const char *path, int lock_type,
+                  enum file_lock_method lock_method, unsigned int timeout_secs,
+                  struct file_lock **lock_r, const char **error_r);
 /* Change the lock type. WARNING: This isn't an atomic operation!
    The result is the same as file_unlock() + file_try_lock(). */
 int file_lock_try_update(struct file_lock *lock, int lock_type);
index 10c83f19c9608f4b6979df4b74385c02a9c92789..d18b00495186322b936e1abd48004e137eb97a23 100644 (file)
@@ -292,10 +292,10 @@ static int squat_trie_lock(struct squat_trie *trie, int lock_type,
 
        for (;;) {
                if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
-                       ret = file_wait_lock_error(trie->fd, trie->path,
-                                                  lock_type, trie->lock_method,
-                                                  SQUAT_TRIE_LOCK_TIMEOUT,
-                                                  file_lock_r, &error);
+                       ret = file_wait_lock(trie->fd, trie->path,
+                                            lock_type, trie->lock_method,
+                                            SQUAT_TRIE_LOCK_TIMEOUT,
+                                            file_lock_r, &error);
                        if (ret < 0) {
                                i_error("squat trie %s: %s",
                                        trie->path, error);
@@ -1629,10 +1629,10 @@ static int squat_trie_write(struct squat_trie_build_context *ctx)
                        return -1;
 
                if (trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
-                       ret = file_wait_lock_error(fd, path, F_WRLCK,
-                                                  trie->lock_method,
-                                                  SQUAT_TRIE_LOCK_TIMEOUT,
-                                                  &file_lock, &error);
+                       ret = file_wait_lock(fd, path, F_WRLCK,
+                                            trie->lock_method,
+                                            SQUAT_TRIE_LOCK_TIMEOUT,
+                                            &file_lock, &error);
                        if (ret <= 0) {
                                i_error("file_wait_lock(%s) failed: %s",
                                        path, error);
index 7364431f5a2ab25f8aefcee83f7d6817e191e22e..caf9854acc8fc50eb5bdd454532552628d7c3895 100644 (file)
@@ -609,11 +609,11 @@ static int squat_uidlist_lock(struct squat_uidlist *uidlist)
                i_assert(uidlist->dotlock == NULL);
 
                if (uidlist->trie->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
-                       ret = file_wait_lock_error(uidlist->fd, uidlist->path,
-                                                  F_WRLCK,
-                                                  uidlist->trie->lock_method,
-                                                  SQUAT_TRIE_LOCK_TIMEOUT,
-                                                  &uidlist->file_lock, &error);
+                       ret = file_wait_lock(uidlist->fd, uidlist->path,
+                                            F_WRLCK,
+                                            uidlist->trie->lock_method,
+                                            SQUAT_TRIE_LOCK_TIMEOUT,
+                                            &uidlist->file_lock, &error);
                        if (ret < 0) {
                                i_error("squat uidlist %s: %s",
                                        uidlist->path, error);