mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
journal-file: port journal_file_open() to openat_report_new()
We so far had some magic logic in place that files we open for write with size zero are freshly created. That of course is a bogus assumption, in particular as this code deals with corrupted file systems which oftentimes contain zero size inodes from left-over runs. Let's fix this properly, and actually let the kernel tell us whether it create the file or not.
This commit is contained in:
parent
d120d897ec
commit
db5e7d75dc
@ -3424,9 +3424,9 @@ int journal_file_open(
|
||||
* or so, we likely fail quickly than block for long. For regular files O_NONBLOCK has no effect, hence
|
||||
* it doesn't hurt in that case. */
|
||||
|
||||
f->fd = open(f->path, f->flags|O_CLOEXEC|O_NONBLOCK, f->mode);
|
||||
f->fd = openat_report_new(AT_FDCWD, f->path, f->flags|O_CLOEXEC|O_NONBLOCK, f->mode, &newly_created);
|
||||
if (f->fd < 0) {
|
||||
r = -errno;
|
||||
r = f->fd;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -3436,6 +3436,19 @@ int journal_file_open(
|
||||
r = fd_nonblock(f->fd, false);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
if (!newly_created) {
|
||||
r = journal_file_fstat(f);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
}
|
||||
} else {
|
||||
r = journal_file_fstat(f);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
/* If we just got the fd passed in, we don't really know if we created the file anew */
|
||||
newly_created = f->last_stat.st_size == 0 && f->writable;
|
||||
}
|
||||
|
||||
f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, prot_from_flags(flags));
|
||||
@ -3444,12 +3457,7 @@ int journal_file_open(
|
||||
goto fail;
|
||||
}
|
||||
|
||||
r = journal_file_fstat(f);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
if (f->last_stat.st_size == 0 && f->writable) {
|
||||
|
||||
if (newly_created) {
|
||||
(void) journal_file_warn_btrfs(f);
|
||||
|
||||
/* Let's attach the creation time to the journal file, so that the vacuuming code knows the age of this
|
||||
@ -3476,8 +3484,6 @@ int journal_file_open(
|
||||
r = journal_file_fstat(f);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
newly_created = true;
|
||||
}
|
||||
|
||||
if (f->last_stat.st_size < (off_t) HEADER_SIZE_MIN) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user