[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / smbd / oplock.c
index 9f3679390b894251fcf16fa046a58aec9e1e2070..9ac9d7628400c7bf9671975f22b408e40579ae88 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #define DBGC_CLASS DBGC_LOCKING
@@ -120,7 +119,7 @@ BOOL set_file_oplock(files_struct *fsp, int oplock_type)
 
        DEBUG(5,("set_file_oplock: granted oplock on file %s, %s/%lu, "
                    "tv_sec = %x, tv_usec = %x\n",
-                fsp->fsp_name, file_id_static_string(&fsp->file_id),
+                fsp->fsp_name, file_id_string_tos(&fsp->file_id),
                 fsp->fh->gen_id, (int)fsp->open_time.tv_sec,
                 (int)fsp->open_time.tv_usec ));
 
@@ -152,6 +151,8 @@ void release_file_oplock(files_struct *fsp)
        fsp->sent_oplock_break = NO_BREAK_SENT;
        
        flush_write_cache(fsp, OPLOCK_RELEASE_FLUSH);
+
+       TALLOC_FREE(fsp->oplock_timeout);
 }
 
 /****************************************************************************
@@ -191,7 +192,7 @@ BOOL remove_oplock(files_struct *fsp)
        if (!ret) {
                DEBUG(0,("remove_oplock: failed to remove share oplock for "
                         "file %s fnum %d, %s\n",
-                        fsp->fsp_name, fsp->fnum, file_id_static_string(&fsp->file_id)));
+                        fsp->fsp_name, fsp->fnum, file_id_string_tos(&fsp->file_id)));
        }
        release_file_oplock(fsp);
        TALLOC_FREE(lck);
@@ -216,7 +217,7 @@ BOOL downgrade_oplock(files_struct *fsp)
        if (!ret) {
                DEBUG(0,("downgrade_oplock: failed to downgrade share oplock "
                         "for file %s fnum %d, file_id %s\n",
-                        fsp->fsp_name, fsp->fnum, file_id_static_string(&fsp->file_id)));
+                        fsp->fsp_name, fsp->fnum, file_id_string_tos(&fsp->file_id)));
        }
 
        downgrade_file_oplock(fsp);
@@ -252,7 +253,7 @@ static char *new_break_smb_message(TALLOC_CTX *mem_ctx,
        }
 
        memset(result,'\0',smb_size);
-       set_message(NULL,result,8,0,True);
+       set_message(result,8,0,True);
        SCVAL(result,smb_com,SMBlockingX);
        SSVAL(result,smb_tid,fsp->conn->cnum);
        SSVAL(result,smb_pid,0xFFFF);
@@ -288,7 +289,7 @@ static files_struct *initial_break_processing(struct file_id id, unsigned long f
 
        if( DEBUGLVL( 3 ) ) {
                dbgtext( "initial_break_processing: called for %s/%u\n",
-                        file_id_static_string(&id), (int)file_id);
+                        file_id_string_tos(&id), (int)file_id);
                dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
                        exclusive_oplocks_open, level_II_oplocks_open );
        }
@@ -305,7 +306,7 @@ static files_struct *initial_break_processing(struct file_id id, unsigned long f
                /* The file could have been closed in the meantime - return success. */
                if( DEBUGLVL( 3 ) ) {
                        dbgtext( "initial_break_processing: cannot find open file with " );
-                       dbgtext( "file_id %s gen_id = %lu", file_id_static_string(&id), file_id);
+                       dbgtext( "file_id %s gen_id = %lu", file_id_string_tos(&id), file_id);
                        dbgtext( "allowing break to succeed.\n" );
                }
                return NULL;
@@ -325,7 +326,7 @@ static files_struct *initial_break_processing(struct file_id id, unsigned long f
                if( DEBUGLVL( 3 ) ) {
                        dbgtext( "initial_break_processing: file %s ", fsp->fsp_name );
                        dbgtext( "(file_id = %s gen_id = %lu) has no oplock.\n",
-                                file_id_static_string(&id), fsp->fh->gen_id );
+                                file_id_string_tos(&id), fsp->fh->gen_id );
                        dbgtext( "Allowing break to succeed regardless.\n" );
                }
                return NULL;
@@ -341,12 +342,8 @@ static void oplock_timeout_handler(struct event_context *ctx,
 {
        files_struct *fsp = (files_struct *)private_data;
 
-       /* Ensure we always remove this event. */
-       if (fsp->oplock_timeout != NULL) {
-               /* Remove the timed event handler. */
-               TALLOC_FREE(fsp->oplock_timeout);
-               fsp->oplock_timeout = NULL;
-       }
+       /* Remove the timed event handler. */
+       TALLOC_FREE(fsp->oplock_timeout);
        DEBUG(0, ("Oplock break failed for file %s -- replying anyway\n", fsp->fsp_name));
        global_client_failed_oplock_break = True;
        remove_oplock(fsp);
@@ -408,7 +405,7 @@ static void process_oplock_async_level2_break_message(struct messaging_context *
        message_to_share_mode_entry(&msg, (char *)data->data);
 
        DEBUG(10, ("Got oplock async level 2 break message from pid %d: %s/%lu\n",
-                  (int)procid_to_pid(&src), file_id_static_string(&msg.id), msg.share_file_id));
+                  (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id));
 
        fsp = initial_break_processing(msg.id, msg.share_file_id);
 
@@ -496,7 +493,7 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
        message_to_share_mode_entry(&msg, (char *)data->data);
 
        DEBUG(10, ("Got oplock break message from pid %d: %s/%lu\n",
-                  (int)procid_to_pid(&src), file_id_static_string(&msg.id), msg.share_file_id));
+                  (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id));
 
        fsp = initial_break_processing(msg.id, msg.share_file_id);
 
@@ -526,7 +523,7 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
        if (EXCLUSIVE_OPLOCK_TYPE(msg.op_type) &&
            !EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
                DEBUG(3, ("Already downgraded oplock on %s: %s\n",
-                         file_id_static_string(&fsp->file_id),
+                         file_id_string_tos(&fsp->file_id),
                          fsp->fsp_name));
                /* We just send the same message back. */
                messaging_send_buf(msg_ctx, src, MSG_SMB_BREAK_RESPONSE,
@@ -608,7 +605,7 @@ static void process_kernel_oplock_break(struct messaging_context *msg_ctx,
        file_id = (unsigned long)IVAL(data->data, 16);
 
        DEBUG(10, ("Got kernel oplock break message from pid %d: %s/%u\n",
-                  (int)procid_to_pid(&src), file_id_static_string(&id),
+                  (int)procid_to_pid(&src), file_id_string_tos(&id),
                   (unsigned int)file_id));
 
        fsp = initial_break_processing(id, file_id);
@@ -698,7 +695,7 @@ static void process_oplock_break_response(struct messaging_context *msg_ctx,
        message_to_share_mode_entry(&msg, (char *)data->data);
 
        DEBUG(10, ("Got oplock break response from pid %d: %s/%lu mid %u\n",
-                  (int)procid_to_pid(&src), file_id_static_string(&msg.id), msg.share_file_id,
+                  (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id,
                   (unsigned int)msg.op_mid));
 
        /* Here's the hack from open.c, store the mid in the 'port' field */
@@ -727,7 +724,7 @@ static void process_open_retry_message(struct messaging_context *msg_ctx,
        message_to_share_mode_entry(&msg, (char *)data->data);
 
        DEBUG(10, ("Got open retry msg from pid %d: %s mid %u\n",
-                  (int)procid_to_pid(&src), file_id_static_string(&msg.id),
+                  (int)procid_to_pid(&src), file_id_string_tos(&msg.id),
                   (unsigned int)msg.op_mid));
 
        schedule_deferred_open_smb_message(msg.op_mid);
@@ -833,6 +830,9 @@ void share_mode_entry_to_message(char *msg, struct share_mode_entry *e)
        SIVAL(msg,44,e->share_file_id);
        SIVAL(msg,48,e->uid);
        SSVAL(msg,52,e->flags);
+#ifdef CLUSTER_SUPPORT
+       SIVAL(msg,54,e->pid.vnn);
+#endif
 }
 
 /****************************************************************************
@@ -853,6 +853,9 @@ void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
        e->share_file_id = (unsigned long)IVAL(msg,44);
        e->uid = (uint32)IVAL(msg,48);
        e->flags = (uint16)SVAL(msg,52);
+#ifdef CLUSTER_SUPPORT
+       e->pid.vnn = IVAL(msg,54);
+#endif
 }
 
 /****************************************************************************