+ /* There are actually two cases: a full deserialization if we have not ever
+ * read the object before, and a partial deserialization where the metadata
+ * is already in memory and we just need to remap the data. If the object
+ * type has not yet been set, we'll need to read and parse the metadata.
+ * Once that is done, we can fall through the case of remapping the data
+ * itself. */
+ if (log->type == LOGTYPE_UNKNOWN) {
+ BlueSkyRCStr *raw = NULL;
+ if ((log->location_flags | log->pending_write) & CLOUDLOG_JOURNAL) {
+ raw = bluesky_log_map_object(log->fs, -1, log->log_seq,
+ log->log_offset, log->log_size);
+ }
+
+ if (raw == NULL && (log->location_flags & CLOUDLOG_CLOUD)) {
+ log->location_flags &= ~CLOUDLOG_JOURNAL;
+ raw = bluesky_log_map_object(log->fs,
+ log->location.directory,
+ log->location.sequence,
+ log->location.offset,
+ log->location.size);
+ }
+
+ g_assert(raw != NULL);
+ bluesky_deserialize_cloudlog(log, raw->data, raw->len);
+ bluesky_string_unref(raw);
+ }
+
+ /* At this point all metadata should be available and we need only remap
+ * the object data. */
+
+ int offset;
+ if ((log->location_flags | log->pending_write) & CLOUDLOG_JOURNAL) {
+ bluesky_cloudlog_stats_update(log, -1);
+ offset = log->log_offset + sizeof(struct log_header);
+ log->data = bluesky_log_map_object(log->fs, -1, log->log_seq,
+ offset, log->data_size);
+ bluesky_cloudlog_stats_update(log, 1);
+ }
+
+ if (log->data == NULL && (log->location_flags & CLOUDLOG_CLOUD)) {
+ log->location_flags &= ~CLOUDLOG_JOURNAL;
+ bluesky_cloudlog_stats_update(log, -1);
+ offset = log->location.offset + sizeof(struct cloudlog_header);
+ log->data = bluesky_log_map_object(log->fs, log->location.directory,
+ log->location.sequence,
+ offset, log->data_size);
+ bluesky_cloudlog_stats_update(log, 1);
+ }