X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fjournal-file.c;h=b7e5cf0ab5bff9576aa74b2e155874f62e80612b;hp=14eae8f57e3c65b164e3a58d8cc692ef60d4cde9;hb=fa28bc2df724e4aff46d19cb7aa732cc64c71061;hpb=248c78c79c5cca9b981800d816a77591e504066a diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 14eae8f57..b7e5cf0ab 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -315,7 +315,7 @@ static int journal_file_verify_header(JournalFile *f) { } static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size) { - uint64_t old_size, new_size, file_size; + uint64_t old_size, new_size; int r; assert(f); @@ -356,6 +356,11 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size) } } + /* Increase by larger blocks at once */ + new_size = ((new_size+FILE_SIZE_INCREASE-1) / FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE; + if (f->metrics.max_size > 0 && new_size > f->metrics.max_size) + new_size = f->metrics.max_size; + /* Note that the glibc fallocate() fallback is very inefficient, hence we try to minimize the allocation area as we can. */ @@ -363,16 +368,8 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size) if (r != 0) return -r; - /* Increase the file size a bit further than this, so that we - * we can create larger memory maps to cache */ - file_size = ((new_size+FILE_SIZE_INCREASE-1) / FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE; - if (file_size > (uint64_t) f->last_stat.st_size) { - if (file_size > new_size) - ftruncate(f->fd, file_size); - - if (fstat(f->fd, &f->last_stat) < 0) - return -errno; - } + if (fstat(f->fd, &f->last_stat) < 0) + return -errno; f->header->arena_size = htole64(new_size - le64toh(f->header->header_size)); @@ -1013,7 +1010,10 @@ static int journal_file_append_data( if (r < 0) return r; - eq = memchr(data, '=', size); + if (!data) + eq = NULL; + else + eq = memchr(data, '=', size); if (eq && eq > data) { uint64_t fp; Object *fo; @@ -1628,8 +1628,6 @@ static int generic_array_bisect( else left = y + 1; } - - last_index = (uint64_t) -1; } for (;;) { @@ -2733,7 +2731,8 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6 ts.realtime = le64toh(o->entry.realtime); n = journal_file_entry_n_items(o); - items = alloca(sizeof(EntryItem) * n); + /* alloca() can't take 0, hence let's allocate at least one */ + items = alloca(sizeof(EntryItem) * MAX(1u, n)); for (i = 0; i < n; i++) { uint64_t l, h;