r5014: Split out the request to send an async level II oplock break into a
authorJeremy Allison <jra@samba.org>
Wed, 26 Jan 2005 20:01:21 +0000 (20:01 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:55:11 +0000 (10:55 -0500)
new function to make it clear when it's called. Remove async parameter
that had been overloaded into request_oplock_break.
Inspired by work from Nadav Danieli <nadavd@exanet.com>.
Jeremy.

source/smbd/open.c
source/smbd/oplock.c

index bf3fbf7fecd556afbed62caaf134432421731a8b..70632a20eb71d3c806079d93fbda46d1da0c3c19 100644 (file)
@@ -665,7 +665,7 @@ dev = %x, inode = %.0f\n", *p_oplock_request, share_entry->op_type, fname, (unsi
                                /* Oplock break - unlock to request it. */
                                unlock_share_entry(conn, dev, inode);
                                
-                               opb_ret = request_oplock_break(share_entry, False);
+                               opb_ret = request_oplock_break(share_entry);
                                
                                /* Now relock. */
                                lock_share_entry(conn, dev, inode);
index 8d1b6911e7f5e200ebc90189cf51ffb9d30b3d82..a55d5443d56b3cbfcd556a1dbdc56628afb8f18a 100644 (file)
@@ -944,12 +944,12 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id,
 }
 
 /****************************************************************************
-Send an oplock break message to another smbd process. If the oplock is held 
-by the local smbd then call the oplock break function directly.
-Note this function is always called with the share mode lock *NOT* held.
+ Send an oplock break message to another smbd process. If the oplock is held 
+ by the local smbd then call the oplock break function directly.
+ This function is called with no share locks held.
 ****************************************************************************/
 
-BOOL request_oplock_break(share_mode_entry *share_entry, BOOL async)
+BOOL request_oplock_break(share_mode_entry *share_entry)
 {
        char op_break_msg[OPLOCK_BREAK_MSG_LEN];
        struct sockaddr_in addr_out;
@@ -990,7 +990,7 @@ dev = %x, inode = %.0f, file_id = %lu and no fsp found !\n",
        /* We need to send a OPLOCK_BREAK_CMD message to the port in the share mode entry. */
 
        if (LEVEL_II_OPLOCK_TYPE(share_entry->op_type)) {
-               break_cmd_type = async ? ASYNC_LEVEL_II_OPLOCK_BREAK_CMD : LEVEL_II_OPLOCK_BREAK_CMD;
+               break_cmd_type = LEVEL_II_OPLOCK_BREAK_CMD;
        } else {
                break_cmd_type = OPLOCK_BREAK_CMD;
        }
@@ -1008,7 +1008,7 @@ dev = %x, inode = %.0f, file_id = %lu and no fsp found !\n",
        addr_out.sin_family = AF_INET;
    
        if( DEBUGLVL( 3 ) ) {
-               dbgtext( "request_oplock_break: sending a %s oplock break message to ", async ? "asynchronous" : "synchronous" );
+               dbgtext( "request_oplock_break: sending a synchronous oplock break message to " );
                dbgtext( "pid %d on port %d ", (int)share_entry->pid, share_entry->op_port );
                dbgtext( "for dev = %x, inode = %.0f, file_id = %lu\n",
             (unsigned int)dev, (double)inode, file_id );
@@ -1027,16 +1027,6 @@ dev = %x, inode = %.0f, file_id = %lu and no fsp found !\n",
                return False;
        }
 
-       /*
-        * If we just sent a message to a level II oplock share entry in async mode then
-        * we are done and may return.
-        */
-
-       if (LEVEL_II_OPLOCK_TYPE(share_entry->op_type) && async) {
-               DEBUG(3,("request_oplock_break: sent async break message to level II entry.\n"));
-               return True;
-       }
-
        /*
         * Now we must await the oplock broken message coming back
         * from the target smbd process. Timeout if it fails to
@@ -1149,6 +1139,57 @@ BOOL attempt_close_oplocked_file(files_struct *fsp)
        return False;
 }
 
+/****************************************************************************
+ Send an asynchronous oplock break message to another smbd process.
+****************************************************************************/
+
+static BOOL request_remote_level2_async_oplock_break(share_mode_entry *share_entry)
+{
+       char op_break_msg[OPLOCK_BREAK_MSG_LEN];
+       struct sockaddr_in addr_out;
+       pid_t pid = sys_getpid();
+       SMB_DEV_T dev = share_entry->dev;
+       SMB_INO_T inode = share_entry->inode;
+       unsigned long file_id = share_entry->share_file_id;
+
+       /* We need to send a ASYNC_LEVEL_II_OPLOCK_BREAK_CMD message to the port in the share mode entry. */
+
+       SSVAL(op_break_msg,OPBRK_MESSAGE_CMD_OFFSET,ASYNC_LEVEL_II_OPLOCK_BREAK_CMD);
+       memcpy(op_break_msg+OPLOCK_BREAK_PID_OFFSET,(char *)&pid,sizeof(pid));
+       memcpy(op_break_msg+OPLOCK_BREAK_DEV_OFFSET,(char *)&dev,sizeof(dev));
+       memcpy(op_break_msg+OPLOCK_BREAK_INODE_OFFSET,(char *)&inode,sizeof(inode));
+       memcpy(op_break_msg+OPLOCK_BREAK_FILEID_OFFSET,(char *)&file_id,sizeof(file_id));
+
+       /* Set the address and port. */
+       memset((char *)&addr_out,'\0',sizeof(addr_out));
+       addr_out.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+       addr_out.sin_port = htons( share_entry->op_port );
+       addr_out.sin_family = AF_INET;
+   
+       if( DEBUGLVL( 3 ) ) {
+               dbgtext( "request_remote_level2_async_oplock_break: sending an asynchronous oplock break message to ");
+               dbgtext( "pid %d on port %d ", (int)share_entry->pid, share_entry->op_port );
+               dbgtext( "for dev = %x, inode = %.0f, file_id = %lu\n",
+            (unsigned int)dev, (double)inode, file_id );
+       }
+
+       if(sys_sendto(oplock_sock,op_break_msg,OPLOCK_BREAK_MSG_LEN,0,
+                       (struct sockaddr *)&addr_out,sizeof(addr_out)) < 0) {
+               if( DEBUGLVL( 0 ) ) {
+                       dbgtext( "request_remote_level2_async_oplock_break: failed when sending a oplock " );
+                       dbgtext( "break message to pid %d ", (int)share_entry->pid );
+                       dbgtext( "on port %d ", share_entry->op_port );
+                       dbgtext( "for dev = %x, inode = %.0f, file_id = %lu\n",
+                               (unsigned int)dev, (double)inode, file_id );
+                       dbgtext( "Error was %s\n", strerror(errno) );
+               }
+               return False;
+       }
+
+       DEBUG(3,("request_remote_level2_async_oplock_break: sent async break message to level II entry.\n"));
+       return True;
+}
+
 /****************************************************************************
  This function is called on any file modification or lock request. If a file
  is level 2 oplocked then it must tell all other level 2 holders to break to none.
@@ -1234,7 +1275,7 @@ void release_level_2_oplocks_on_change(files_struct *fsp)
                         */
 
                        DEBUG(10,("release_level_2_oplocks_on_change: breaking remote oplock (async).\n"));
-                       request_oplock_break(share_entry, True);
+                       request_remote_level2_async_oplock_break(share_entry);
                }
        }