file, open: create directly the file if possible

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2019-07-24 17:09:38 +02:00
parent 348f60a277
commit 6dbc45b821
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED

10
main.c
View File

@ -2850,6 +2850,16 @@ create_file (struct ovl_data *lo, int dirfd, const char *path, uid_t uid, gid_t
char wd_tmp_file_name[32]; char wd_tmp_file_name[32];
int ret; int ret;
/* try to create directly the file if it doesn't need to be chowned. */
if (uid == lo->uid && gid == lo->gid)
{
ret = TEMP_FAILURE_RETRY (openat (get_upper_layer (lo)->fd, path, flags, mode));
if (ret == 0)
return ret;
/* if it fails (e.g. there is a whiteout) then fallback to create it in
the working dir + rename. */
}
sprintf (wd_tmp_file_name, "%lu", get_next_wd_counter ()); sprintf (wd_tmp_file_name, "%lu", get_next_wd_counter ());
fd = TEMP_FAILURE_RETRY (openat (lo->workdir_fd, wd_tmp_file_name, flags, mode)); fd = TEMP_FAILURE_RETRY (openat (lo->workdir_fd, wd_tmp_file_name, flags, mode));