From 7355d6bac79109cd893b7b0f4ffac77b0b8f438c Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 3 Nov 2010 16:38:03 -0700 Subject: [PATCH] Bugfix in partial log fetching. Do not bother mapping the file until the data is available, otherwise the mapping may be deleted from under us while we are waiting. --- bluesky/log.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/bluesky/log.c b/bluesky/log.c index 88b95df..d9ad11b 100644 --- a/bluesky/log.c +++ b/bluesky/log.c @@ -581,26 +581,6 @@ BlueSkyRCStr *bluesky_log_map_object(BlueSkyCloudLog *item, gboolean map_data) file_size = item->location.size; } - if (map->addr == NULL) { - int fd = openat(log->dirfd, map->filename, O_RDONLY); - - if (fd < 0) { - fprintf(stderr, "Error opening logfile %s: %m\n", map->filename); - goto exit2; - } - - off_t length = lseek(fd, 0, SEEK_END); - map->addr = (const char *)mmap(NULL, length, PROT_READ, MAP_SHARED, - fd, 0); - g_atomic_int_add(&log->disk_used, -(map->len / 1024)); - map->len = length; - g_atomic_int_add(&log->disk_used, map->len / 1024); - - g_atomic_int_inc(&map->refcount); - - close(fd); - } - /* Log segments fetched from the cloud might only be partially-fetched. * Check whether the object we are interested in is available. */ if (location == CLOUDLOG_CLOUD) { @@ -627,6 +607,26 @@ BlueSkyRCStr *bluesky_log_map_object(BlueSkyCloudLog *item, gboolean map_data) } } + if (map->addr == NULL) { + int fd = openat(log->dirfd, map->filename, O_RDONLY); + + if (fd < 0) { + fprintf(stderr, "Error opening logfile %s: %m\n", map->filename); + goto exit2; + } + + off_t length = lseek(fd, 0, SEEK_END); + map->addr = (const char *)mmap(NULL, length, PROT_READ, MAP_SHARED, + fd, 0); + g_atomic_int_add(&log->disk_used, -(map->len / 1024)); + map->len = length; + g_atomic_int_add(&log->disk_used, map->len / 1024); + + g_atomic_int_inc(&map->refcount); + + close(fd); + } + if (map_data) { if (location == CLOUDLOG_JOURNAL) file_offset += sizeof(struct log_header); -- 2.20.1