]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: smbd: Allow check_parent_exists() to return the errno from STAT/LSTAT on the...
authorJeremy Allison <jra@samba.org>
Tue, 11 May 2021 18:31:55 +0000 (11:31 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 11 May 2021 22:08:36 +0000 (22:08 +0000)
Not yet used.

This will allow us to avoid an duplicate STAT/LSTAT system call
on the parent pathname in a hot code path of the caller in the next commit.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Richard Sharpe <realrichardsharpe@gmail.com>
source3/smbd/filename.c

index 5d7a51b8031091bb102df07286fbbb38bd576b1e..6181afce8984f20021c7b5c4d99d9cc5d802b2e9 100644 (file)
@@ -162,7 +162,8 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
                                bool posix_pathnames,
                                const struct smb_filename *smb_fname,
                                char **pp_dirpath,
-                               char **pp_start)
+                               char **pp_start,
+                               int *p_parent_stat_errno)
 {
        char *parent_name = NULL;
        struct smb_filename *parent_fname = NULL;
@@ -211,6 +212,16 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
           with the normal tree walk. */
 
        if (ret == -1) {
+               /*
+                * Optimization. Preserving the
+                * errno from the STAT/LSTAT here
+                * will allow us to save a duplicate
+                * STAT/LSTAT system call of the parent
+                * pathname in a hot code path in the caller.
+                */
+               if (p_parent_stat_errno != NULL) {
+                       *p_parent_stat_errno = errno;
+               }
                goto no_optimization_out;
        }
 
@@ -1206,7 +1217,8 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
                                                state->posix_pathnames,
                                                state->smb_fname,
                                                &state->dirpath,
-                                               &state->name);
+                                               &state->name,
+                                               NULL);
                        errno = saved_errno;
                        if (!NT_STATUS_IS_OK(status)) {
                                goto fail;
@@ -1287,7 +1299,8 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
                                        state->posix_pathnames,
                                        state->smb_fname,
                                        &state->dirpath,
-                                       &state->name);
+                                       &state->name,
+                                       NULL);
                errno = saved_errno;
                if (!NT_STATUS_IS_OK(status)) {
                        goto fail;