From: Michael Vrable Date: Wed, 3 Nov 2010 23:38:03 +0000 (-0700) Subject: Bugfix in partial log fetching. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=7355d6bac79109cd893b7b0f4ffac77b0b8f438c;p=bluesky.git 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. --- 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);