From: Gabriel Ivăncescu gabrielopcode@gmail.com
The first fstat on the source happens for create_link only, so the new one isn't redundant in that case, but reduces syscalls in case of links.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- server/fd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/server/fd.c b/server/fd.c index 5fc994cf2dd..5ccca271b8a 100644 --- a/server/fd.c +++ b/server/fd.c @@ -2641,7 +2641,7 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr, da struct unicode_str nt_name, int create_link, unsigned int flags ) { struct inode *inode; - struct stat st, st2; + struct stat st; char *name; const unsigned int replace = flags & FILE_RENAME_REPLACE_IF_EXISTS;
@@ -2691,7 +2691,7 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr, da
if (!stat( name, &st )) { - if (!fstat( fd->unix_fd, &st2 ) && st.st_ino == st2.st_ino && st.st_dev == st2.st_dev) + if (st.st_ino == fd->inode->ino && st.st_dev == fd->inode->device->dev) { if (!create_link) rename_same_file( fd->unix_name, name, S_ISDIR( st.st_mode ) ); else if (!replace) set_error( STATUS_OBJECT_NAME_COLLISION ); @@ -2734,7 +2734,7 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr, da
/* link() expects that the target doesn't exist */ /* rename() cannot replace files with directories */ - if (create_link || S_ISDIR( st2.st_mode )) + if (create_link || (!fstat( fd->unix_fd, &st ) && S_ISDIR( st.st_mode ))) { if (unlink( name )) {