chiark / gitweb /
mmap: resize arrays dynamically
[elogind.git] / src / journal / journal-file.c
index 3cf28a7f3c25f85de9d61efcd69df82c6db1f2c6..c6b25ce54b29ba47b0060045570aacad4e84b36a 100644 (file)
@@ -65,7 +65,7 @@ void journal_file_close(JournalFile *f) {
         assert(f);
 
         /* Write the final tag */
-        if (f->seal)
+        if (f->seal && f->writable)
                 journal_file_append_tag(f);
 
         /* Sync everything to disk, before we mark the file offline */
@@ -252,7 +252,9 @@ static int journal_file_verify_header(JournalFile *f) {
         }
 
         f->compress = !!(le32toh(f->header->incompatible_flags) & HEADER_INCOMPATIBLE_COMPRESSED);
-        f->seal = !!(le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED);
+
+        if (f->writable)
+                f->seal = !!(le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED);
 
         return 0;
 }
@@ -796,6 +798,14 @@ uint64_t journal_file_entry_array_n_items(Object *o) {
         return (le64toh(o->object.size) - offsetof(Object, entry_array.items)) / sizeof(uint64_t);
 }
 
+uint64_t journal_file_hash_table_n_items(Object *o) {
+        assert(o);
+        assert(o->object.type == OBJECT_DATA_HASH_TABLE ||
+               o->object.type == OBJECT_FIELD_HASH_TABLE);
+
+        return (le64toh(o->object.size) - offsetof(Object, hash_table.items)) / sizeof(HashItem);
+}
+
 static int link_entry_into_array(JournalFile *f,
                                  le64_t *first,
                                  le64_t *idx,
@@ -1993,10 +2003,7 @@ int journal_file_open(
         if (mmap_cache)
                 f->mmap = mmap_cache_ref(mmap_cache);
         else {
-                /* One context for each type, plus the zeroth catchall
-                 * context. One fd for the file plus one for each type
-                 * (which we need during verification */
-                f->mmap = mmap_cache_new(_OBJECT_TYPE_MAX, 1 + _OBJECT_TYPE_MAX);
+                f->mmap = mmap_cache_new();
                 if (!f->mmap) {
                         r = -ENOMEM;
                         goto fail;