* 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;
}
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));
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
r = journal_file_fstat(f);
if (r < 0)
goto fail;
-
- newly_created = true;
}
if (f->last_stat.st_size < (off_t) HEADER_SIZE_MIN) {