[Wine-patches] [eterhack 2/2] server: Do not open second file descriptor for locks if file is already opened with O_RDWR.

Alexander Morozov amorozov на etersoft.ru
Пт Июл 10 14:23:04 MSD 2009


----------- следующая часть -----------
From de361af09147a73d06f220a26bbcbf9da5d5ccb2 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Fri, 10 Jul 2009 14:15:16 +0400
Subject: [eterhack 2/2] server: Do not open second file descriptor for locks if file is already opened with O_RDWR.

---
 server/fd.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/server/fd.c b/server/fd.c
index 16f3eeb..9a1c7a8 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -1130,6 +1130,13 @@ static int file_lock_signaled( struct object *obj, struct thread *thread )
     return !lock->process;
 }
 
+static int get_lock_fd( struct fd *fd )
+{
+    int lock_fd = inode_get_lock_fd( fd->inode );
+    if (lock_fd == -1) lock_fd = fd->unix_fd;
+    return lock_fd;
+}
+
 /* set (or remove) a Unix lock if possible for the given range. returns 1 if lock permitted */
 static int set_unix_lock( struct fd *fd, file_pos_t start, file_pos_t end, int type )
 {
@@ -1149,7 +1156,7 @@ static int set_unix_lock( struct fd *fd, file_pos_t start, file_pos_t end, int t
 	if (!fl.l_len) {
 		TRACEL(stderr, "LEN is NULL!!!!!!!!!!");
 	}
-        if (fcntl( inode_get_lock_fd( fd->inode ), F_SETLK, &fl ) != -1) return 1;
+        if (fcntl( get_lock_fd( fd ), F_SETLK, &fl ) != -1) return 1;
 	/* perror("Etersoft warning (some error during lock):"); */
         switch(errno)
         {
@@ -1619,7 +1626,7 @@ static int check_sharing( struct fd *fd, unsigned int access, unsigned int shari
     }
     /* Etersoft: Set existing modes from special lock region state, get cifs status */
     if (etersoft_sharing_set_test_fd)
-        etersoft_sharing_set_test_fd( inode_get_lock_fd( fd->inode ) );
+        etersoft_sharing_set_test_fd( get_lock_fd( fd ) );
     if (etersoft_sharing_pre)
         fd->cifs = etersoft_sharing_pre(fd->unix_fd, fd->access, fd->sharing,
             &existing_access, &existing_sharing);
@@ -1741,7 +1748,7 @@ struct fd *open_fd( const char *name, int flags, mode_t *mode, unsigned int acce
         fd->closed = closed_fd;
         list_add_head( &inode->open, &fd->inode_entry );
 
-        if (inode_get_lock_fd( inode ) == -1)
+        if (rw_mode != O_RDWR && inode_get_lock_fd( inode ) == -1)
         {
             lock_fd = open( name, O_RDWR );
             inode_set_lock_fd( inode, lock_fd );
-- 
1.6.3.3



Подробная информация о списке рассылки Wine-patches