s3-talloc Change TALLOC_ARRAY() to talloc_array()
[samba.git] / source3 / smbd / oplock.c
index 31cedc415e3800a6efabf398e215ab4491656925..8482a00f641a0fe30cddf280e89f06952ebec373 100644 (file)
@@ -21,8 +21,9 @@
 
 #define DBGC_CLASS DBGC_LOCKING
 #include "includes.h"
+#include "smbd/smbd.h"
 #include "smbd/globals.h"
-#include "librpc/gen_ndr/messaging.h"
+#include "messages.h"
 
 /****************************************************************************
  Get the number of current exclusive oplocks.
@@ -52,17 +53,6 @@ void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp)
                           msg, MSG_SMB_KERNEL_BREAK_SIZE);
 }
 
-static bool file_has_brlocks(files_struct *fsp)
-{
-       struct byte_range_lock *br_lck;
-
-       br_lck = brl_get_locks_readonly(fsp);
-       if (!br_lck)
-               return false;
-
-       return br_lck->num_locks > 0 ? true : false;
-}
-
 /****************************************************************************
  Attempt to set an oplock on a file. Succeeds if kernel oplocks are
  disabled (just sets flags) and no byte-range locks in the file. Returns True
@@ -72,12 +62,6 @@ static bool file_has_brlocks(files_struct *fsp)
 bool set_file_oplock(files_struct *fsp, int oplock_type)
 {
        if (fsp->oplock_type == LEVEL_II_OPLOCK) {
-               if (lp_locking(fsp->conn->params) && file_has_brlocks(fsp)) {
-                       DEBUG(10, ("Refusing level2 oplock because of "
-                                  "byte-range locks on the file\n"));
-                       return false;
-               }
-
                if (koplocks &&
                    !(koplocks->flags & KOPLOCKS_LEVEL2_SUPPORTED)) {
                        DEBUG(10, ("Refusing level2 oplock, kernel oplocks "
@@ -240,7 +224,7 @@ bool should_notify_deferred_opens()
 static char *new_break_message_smb1(TALLOC_CTX *mem_ctx,
                                   files_struct *fsp, int cmd)
 {
-       char *result = TALLOC_ARRAY(mem_ctx, char, smb_size + 8*2 + 0);
+       char *result = talloc_array(mem_ctx, char, smb_size + 8*2 + 0);
 
        if (result == NULL) {
                DEBUG(0, ("talloc failed\n"));
@@ -369,7 +353,7 @@ static void add_oplock_timeout_handler(files_struct *fsp)
        }
 
        fsp->oplock_timeout =
-               event_add_timed(smbd_event_context(), fsp,
+               event_add_timed(server_event_context(), fsp,
                                timeval_current_ofs(OPLOCK_BREAK_TIMEOUT, 0),
                                oplock_timeout_handler, fsp);
 
@@ -839,8 +823,17 @@ static void contend_level2_oplocks_begin_default(files_struct *fsp,
                 */
 
                if (procid_is_me(&share_entry->pid)) {
+                       struct files_struct *cur_fsp =
+                               initial_break_processing(fsp->conn->sconn,
+                                       share_entry->id,
+                                       share_entry->share_file_id);
                        wait_before_sending_break();
-                       break_level2_to_none_async(fsp);
+                       if (cur_fsp != NULL) {
+                               break_level2_to_none_async(cur_fsp);
+                       } else {
+                               DEBUG(3, ("release_level_2_oplocks_on_change: "
+                               "Did not find fsp, ignoring\n"));
+                       }
                } else {
                        messaging_send_buf(fsp->conn->sconn->msg_ctx,
                                        share_entry->pid,
@@ -895,9 +888,7 @@ void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e)
        SIVAL(msg,OP_BREAK_MSG_UID_OFFSET,e->uid);
        SSVAL(msg,OP_BREAK_MSG_FLAGS_OFFSET,e->flags);
        SIVAL(msg,OP_BREAK_MSG_NAME_HASH_OFFSET,e->name_hash);
-#ifdef CLUSTER_SUPPORT
        SIVAL(msg,OP_BREAK_MSG_VNN_OFFSET,e->pid.vnn);
-#endif
 }
 
 /****************************************************************************
@@ -919,9 +910,7 @@ void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
        e->uid = (uint32)IVAL(msg,OP_BREAK_MSG_UID_OFFSET);
        e->flags = (uint16)SVAL(msg,OP_BREAK_MSG_FLAGS_OFFSET);
        e->name_hash = IVAL(msg,OP_BREAK_MSG_NAME_HASH_OFFSET);
-#ifdef CLUSTER_SUPPORT
        e->pid.vnn = IVAL(msg,OP_BREAK_MSG_VNN_OFFSET);
-#endif
 }
 
 /****************************************************************************