]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add file_cache_new_path() to include path in error messages.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 14 Dec 2016 17:35:05 +0000 (19:35 +0200)
committerGitLab <gitlab@git.dovecot.net>
Thu, 15 Dec 2016 11:02:10 +0000 (13:02 +0200)
src/lib/file-cache.c
src/lib/file-cache.h

index e7d66d2bde45ff3c9c64a24875b088f2517ee44c..5ec00936b219a2ca9901f013682464bbe0d62c2a 100644 (file)
@@ -9,6 +9,7 @@
 
 struct file_cache {
        int fd;
+       char *path;
        buffer_t *page_bitmask;
 
        void *mmap_base;
@@ -17,11 +18,17 @@ struct file_cache {
 };
 
 struct file_cache *file_cache_new(int fd)
+{
+       return file_cache_new_path(fd, "");
+}
+
+struct file_cache *file_cache_new_path(int fd, const char *path)
 {
        struct file_cache *cache;
 
        cache = i_new(struct file_cache, 1);
        cache->fd = fd;
+       cache->path = i_strdup(path);
        cache->page_bitmask = buffer_create_dynamic(default_pool, 128);
        return cache;
 }
@@ -34,9 +41,10 @@ void file_cache_free(struct file_cache **_cache)
 
        if (cache->mmap_base != NULL) {
                if (munmap_anon(cache->mmap_base, cache->mmap_length) < 0)
-                       i_error("munmap_anon() failed: %m");
+                       i_error("munmap_anon(%s) failed: %m", cache->path);
        }
        buffer_free(&cache->page_bitmask);
+       i_free(cache->path);
        i_free(cache);
 }
 
@@ -63,8 +71,8 @@ int file_cache_set_size(struct file_cache *cache, uoff_t size)
                return 0;
 
        if (size > (size_t)-1) {
-               i_error("file_cache_set_size(%"PRIuUOFF_T"): size too large",
-                       size);
+               i_error("file_cache_set_size(%s, %"PRIuUOFF_T"): size too large",
+                       cache->path, size);
                return -1;
        }
 
@@ -72,7 +80,8 @@ int file_cache_set_size(struct file_cache *cache, uoff_t size)
        if (cache->mmap_base == NULL) {
                cache->mmap_base = mmap_anon(size);
                if (cache->mmap_base == MAP_FAILED) {
-                       i_error("mmap_anon(%"PRIuUOFF_T") failed: %m", size);
+                       i_error("mmap_anon(%s, %"PRIuUOFF_T") failed: %m",
+                               cache->path, size);
                        cache->mmap_base = NULL;
                        cache->mmap_length = 0;
                        return -1;
@@ -81,7 +90,8 @@ int file_cache_set_size(struct file_cache *cache, uoff_t size)
                new_base = mremap_anon(cache->mmap_base, cache->mmap_length,
                                       size, MREMAP_MAYMOVE);
                if (new_base == MAP_FAILED) {
-                       i_error("mremap_anon(%"PRIuUOFF_T") failed: %m", size);
+                       i_error("mremap_anon(%s, %"PRIuUOFF_T") failed: %m",
+                               cache->path, size);
                        return -1;
                }
 
@@ -118,7 +128,7 @@ ssize_t file_cache_read(struct file_cache *cache, uoff_t offset, size_t size)
 
                 if (fstat(cache->fd, &st) < 0) {
                         if (errno != ESTALE)
-                                i_error("fstat(file_cache) failed: %m");
+                                i_error("fstat(%s) failed: %m", cache->path);
                        return -1;
                }
 
index 45d94d455dad18e654b9f7dc103f4749e2a8ef9d..afffbd4cb3c7caef0f646b525195223e1504a828 100644 (file)
@@ -4,6 +4,7 @@
 /* Create a new file cache. It works very much like file-backed mmap()ed
    memory, but it works more nicely with remote filesystems (no SIGBUS). */
 struct file_cache *file_cache_new(int fd);
+struct file_cache *file_cache_new_path(int fd, const char *path);
 /* Destroy the cache and set cache pointer to NULL. */
 void file_cache_free(struct file_cache **cache);