X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Flog.c;h=d9ad11b64a2084dbcf0ea7467a15cc3aeadb2d09;hb=7355d6bac79109cd893b7b0f4ffac77b0b8f438c;hp=88b95df335e0f7beae8f81433d4bfda7b10e7d6b;hpb=72de763405222cc8f9bc5c75fd163362ec0f2266;p=bluesky.git 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);