server: Do not open second file descriptor for locks if file is already opened with...
authorAlexander Morozov <amorozov@etersoft.ru>
Fri, 10 Jul 2009 13:23:44 +0000 (17:23 +0400)
committerVitaly Lipatov <lav@etersoft.ru>
Wed, 15 Jul 2009 18:16:37 +0000 (22:16 +0400)
server/fd.c

index c6bf6b711fb3d180ba2ce8d6ed0e965d93b95611..787e8031cc51e9cb04e36c5a9ed69fb2f4315fd7 100644 (file)
@@ -1134,6 +1134,7 @@ static int file_lock_signaled( struct object *obj, struct thread *thread )
 static int set_unix_lock( struct fd *fd, file_pos_t start, file_pos_t end, int type )
 {
     struct flock fl;
+    int lock_fd;
 
     if (!fd->fs_locks) return 1;  /* no fs locks possible for this fd */
     for (;;)
@@ -1149,7 +1150,9 @@ 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;
+        lock_fd = inode_get_lock_fd( fd->inode );
+        if (lock_fd == -1) lock_fd = fd->unix_fd;
+        if (fcntl( lock_fd, F_SETLK, &fl ) != -1) return 1;
        /* perror("Etersoft warning (some error during lock):"); */
         switch(errno)
         {
@@ -1602,6 +1605,7 @@ static int check_sharing( struct fd *fd, unsigned int access, unsigned int shari
     unsigned int existing_sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
     unsigned int existing_access = 0;
     struct list *ptr;
+    int lock_fd;
 
     /* if access mode is 0, sharing mode is ignored */
     if (!access) sharing = existing_sharing;
@@ -1619,7 +1623,13 @@ 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 ) );
+    {
+        lock_fd = inode_get_lock_fd( fd->inode );
+        if (lock_fd == -1 && (access & FILE_UNIX_READ_ACCESS) &&
+            (access & FILE_UNIX_WRITE_ACCESS))
+            lock_fd = fd->unix_fd;
+        etersoft_sharing_set_test_fd( lock_fd );
+    }
     if (etersoft_sharing_pre)
         fd->cifs = etersoft_sharing_pre(fd->unix_fd, fd->access, fd->sharing,
             &existing_access, &existing_sharing);
@@ -1741,7 +1751,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 );