From 6dbc45b821f0f9544e4c789656edf9f7c6017af9 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 24 Jul 2019 17:09:38 +0200 Subject: [PATCH] file, open: create directly the file if possible Signed-off-by: Giuseppe Scrivano --- main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.c b/main.c index 9b34be6..75b3af4 100644 --- a/main.c +++ b/main.c @@ -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]; 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 ()); fd = TEMP_FAILURE_RETRY (openat (lo->workdir_fd, wd_tmp_file_name, flags, mode));