From 85da8c055280cd45553b6b335e9fb226d6e2801e Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 8 Apr 2011 19:50:31 +0300 Subject: [PATCH] Linux NFS: fstat() may return ENOENT instead of ESTALE in some kernel versions. --- src/lib-index/mail-cache.c | 4 ++-- src/lib-index/mail-index-map-read.c | 4 ++-- src/lib-index/mail-index-strmap.c | 2 +- src/lib-index/mail-index.c | 2 +- src/lib-index/mail-transaction-log-file.c | 2 +- src/lib-index/mailbox-list-index.c | 2 +- src/lib/compat.h | 4 ++++ 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index f2a7bfd659..5964d9b634 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -86,7 +86,7 @@ static void mail_cache_init_file_cache(struct mail_cache *cache) if (fstat(cache->fd, &st) == 0) file_cache_set_size(cache->file_cache, st.st_size); - else if (errno != ESTALE) + else if (!ESTALE_FSTAT(errno)) mail_cache_set_syscall_error(cache, "fstat()"); cache->st_ino = st.st_ino; @@ -132,7 +132,7 @@ static bool mail_cache_need_reopen(struct mail_cache *cache) the same inode as the old one. we'll catch this here by checking if fstat() fails with ESTALE */ if (fstat(cache->fd, &st) < 0) { - if (errno == ESTALE) + if (ESTALE_FSTAT(errno)) return TRUE; mail_cache_set_syscall_error(cache, "fstat()"); return FALSE; diff --git a/src/lib-index/mail-index-map-read.c b/src/lib-index/mail-index-map-read.c index a64834471b..6fdfc781de 100644 --- a/src/lib-index/mail-index-map-read.c +++ b/src/lib-index/mail-index-map-read.c @@ -281,7 +281,7 @@ static int mail_index_read_map(struct mail_index_map *map, uoff_t file_size, if (fstat(index->fd, &st) == 0) file_size = st.st_size; else { - if (errno != ESTALE) { + if (!ESTALE_FSTAT(errno)) { mail_index_set_syscall_error(index, "fstat()"); return -1; } @@ -322,7 +322,7 @@ static int mail_index_map_latest_file(struct mail_index *index) if (fstat(index->fd, &st) == 0) file_size = st.st_size; else { - if (errno != ESTALE) { + if (!ESTALE_FSTAT(errno)) { mail_index_set_syscall_error(index, "fstat()"); mail_index_unlock(index, &lock_id); return -1; diff --git a/src/lib-index/mail-index-strmap.c b/src/lib-index/mail-index-strmap.c index 913ee926f9..35cb90f4ab 100644 --- a/src/lib-index/mail-index-strmap.c +++ b/src/lib-index/mail-index-strmap.c @@ -308,7 +308,7 @@ static bool mail_index_strmap_need_reopen(struct mail_index_strmap *strmap) /* FIXME: nfs flush */ if (fstat(strmap->fd, &st1) < 0) { - if (errno != ESTALE) + if (!ESTALE_FSTAT(errno)) mail_index_strmap_set_syscall_error(strmap, "fstat()"); return TRUE; } diff --git a/src/lib-index/mail-index.c b/src/lib-index/mail-index.c index 14dac68723..e7eee0cdf7 100644 --- a/src/lib-index/mail-index.c +++ b/src/lib-index/mail-index.c @@ -656,7 +656,7 @@ int mail_index_reopen_if_changed(struct mail_index *index) } if (fstat(index->fd, &st1) < 0) { - if (errno != ESTALE) + if (!ESTALE_FSTAT(errno)) return mail_index_set_syscall_error(index, "fstat()"); /* deleted/recreated, reopen */ } else if (st1.st_ino == st2.st_ino && diff --git a/src/lib-index/mail-transaction-log-file.c b/src/lib-index/mail-transaction-log-file.c index ffde3538c1..2b5a9abbdc 100644 --- a/src/lib-index/mail-transaction-log-file.c +++ b/src/lib-index/mail-transaction-log-file.c @@ -560,7 +560,7 @@ mail_transaction_log_file_stat(struct mail_transaction_log_file *file, struct stat st; if (fstat(file->fd, &st) < 0) { - if (errno != ESTALE || !ignore_estale) + if (!ESTALE_FSTAT(errno) || !ignore_estale) log_file_set_syscall_error(file, "fstat()"); return -1; } diff --git a/src/lib-index/mailbox-list-index.c b/src/lib-index/mailbox-list-index.c index 7e7167b694..a8b6688790 100644 --- a/src/lib-index/mailbox-list-index.c +++ b/src/lib-index/mailbox-list-index.c @@ -232,7 +232,7 @@ static int mailbox_list_index_is_recreated(struct mailbox_list_index *index) return -1; } if (fstat(index->fd, &st2) < 0) { - if (errno == ESTALE) + if (ESTALE_FSTAT(errno)) return 1; mailbox_list_index_set_syscall_error(index, "fstat()"); return -1; diff --git a/src/lib/compat.h b/src/lib/compat.h index abc01e4543..f90c4e40af 100644 --- a/src/lib/compat.h +++ b/src/lib/compat.h @@ -253,6 +253,10 @@ int i_my_clock_gettime(int clk_id, struct timespec *tp); #define EDESTDIREXISTS(errno) \ ((errno) == EEXIST || (errno) == ENOTEMPTY || (errno) == EBUSY) +/* fstat() returns ENOENT instead of ESTALE with some Linux versions */ +#define ESTALE_FSTAT(errno) \ + ((errno) == ESTALE || (errno) == ENOENT) + #if !defined(_POSIX_SYNCHRONIZED_IO) && \ defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060) -- 2.47.3