Mercurial > dovecot > original-hg > dovecot-1.2
changeset 318:6f82f54b8e27 HEAD
out of disk space -fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 26 Sep 2002 00:24:32 +0300 |
parents | 79d9a40fbb72 |
children | d0cff4da67ac |
files | src/lib-index/mail-custom-flags.c src/lib-index/mail-index-util.c |
diffstat | 2 files changed, 41 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-custom-flags.c Wed Sep 25 23:24:56 2002 +0300 +++ b/src/lib-index/mail-custom-flags.c Thu Sep 26 00:24:32 2002 +0300 @@ -34,6 +34,7 @@ size_t mmap_length; unsigned int syncing:1; + unsigned int noupdate:1; }; static int lock_file(MailCustomFlags *mcf, int type); @@ -63,31 +64,37 @@ static int custom_flags_init(MailCustomFlags *mcf) { static char buf[HEADER_SIZE] = "0000\n"; + int failed; off_t pos; if (!lock_file(mcf, F_WRLCK)) return FALSE; + failed = FALSE; + /* make sure it's still empty after locking */ pos = lseek(mcf->fd, 0, SEEK_END); - if (pos != -1 && pos < HEADER_SIZE) + if (pos >= 0 && pos < HEADER_SIZE) pos = lseek(mcf->fd, 0, SEEK_SET); - if (pos == -1) { + if (pos < 0) { index_cf_set_syscall_error(mcf, "lseek()"); - return FALSE; + failed = TRUE; } /* write the header - it's a 4 byte counter as hex */ - if (write_full(mcf->fd, buf, HEADER_SIZE) < 0) { + if (!failed && write_full(mcf->fd, buf, HEADER_SIZE) < 0) { + if (errno == ENOSPC) + mcf->index->nodiskspace = TRUE; + index_cf_set_syscall_error(mcf, "write_full()"); - return FALSE; + failed = TRUE; } if (!lock_file(mcf, F_UNLCK)) return FALSE; - return TRUE; + return !failed; } static void custom_flags_sync(MailCustomFlags *mcf) @@ -96,6 +103,9 @@ unsigned int num; int i; + if (mcf->noupdate) + return; + memcpy(mcf->sync_counter, mcf->mmap_base, COUNTER_SIZE); for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) { @@ -157,6 +167,9 @@ return TRUE; } + if (mcf->noupdate) + return TRUE; + if (mcf->mmap_length != 0 && memcmp(mcf->sync_counter, mcf->mmap_base, COUNTER_SIZE) == 0) return TRUE; @@ -220,9 +233,10 @@ path = t_strconcat(index->dir, "/", CUSTOM_FLAGS_FILE_NAME, NULL); fd = open(path, O_RDWR | O_CREAT, 0660); if (fd == -1) { - index_set_error(index, "Can't open custom flags file %s: %m", - path); - return FALSE; + if (errno == ENOSPC) + index->nodiskspace = TRUE; + + return index_file_set_syscall_error(index, path, "open()"); } mcf = i_new(MailCustomFlags, 1); @@ -238,11 +252,13 @@ if (mcf->mmap_length < HEADER_SIZE) { /* we just created it, write the header */ mcf->syncing = TRUE; - if (!custom_flags_init(mcf) || !update_mmap(mcf)) { + if ((!custom_flags_init(mcf) || !update_mmap(mcf)) && + !index->nodiskspace) { mail_custom_flags_free(mcf); return FALSE; } mcf->syncing = FALSE; + mcf->noupdate = index->nodiskspace; } custom_flags_sync(mcf); @@ -258,8 +274,13 @@ for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) i_free(mcf->custom_flags[i]); - (void)munmap(mcf->mmap_base, mcf->mmap_length); - (void)close(mcf->fd); + if (mcf->mmap_base != NULL) { + if (munmap(mcf->mmap_base, mcf->mmap_length) < 0) + index_cf_set_syscall_error(mcf, "munmap()"); + } + + if (close(mcf->fd) < 0) + index_cf_set_syscall_error(mcf, "close()"); i_free(mcf->filepath); i_free(mcf); @@ -455,6 +476,9 @@ return i; } + if (mcf->noupdate) + return -1; + /* unlock + write lock, don't directly change from read -> write lock to prevent deadlocking */ if (mcf->lock_type != F_WRLCK) {
--- a/src/lib-index/mail-index-util.c Wed Sep 25 23:24:56 2002 +0300 +++ b/src/lib-index/mail-index-util.c Thu Sep 26 00:24:32 2002 +0300 @@ -96,8 +96,12 @@ condition). also, might not won't work through NFS but that can't be helped. */ fd = open(*path, O_RDWR | O_CREAT | O_EXCL, 0660); - if (fd == -1) + if (fd == -1) { + if (errno == ENOSPC) + index->nodiskspace = TRUE; + index_set_error(index, "Can't create temp index %s: %m", *path); + } return fd; }