s3-talloc Change TALLOC_ARRAY() to talloc_array()
[samba.git] / source3 / smbd / oplock.c
index 03bf21101548aa2ad15fac1bf5860164680ec2b2..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.
@@ -53,18 +54,22 @@ void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp)
 }
 
 /****************************************************************************
- Attempt to set an oplock on a file. Always succeeds if kernel oplocks are
- disabled (just sets flags). Returns True if oplock set.
+ 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
+ if oplock set.
 ****************************************************************************/
 
 bool set_file_oplock(files_struct *fsp, int oplock_type)
 {
-       if ((fsp->oplock_type == LEVEL_II_OPLOCK)
-           && koplocks && !(koplocks->flags & KOPLOCKS_LEVEL2_SUPPORTED)) {
-               DEBUG(10, ("Refusing level2 oplock, kernel oplocks don't "
-                          "support them\n"));
-               return false;
+       if (fsp->oplock_type == LEVEL_II_OPLOCK) {
+               if (koplocks &&
+                   !(koplocks->flags & KOPLOCKS_LEVEL2_SUPPORTED)) {
+                       DEBUG(10, ("Refusing level2 oplock, kernel oplocks "
+                                  "don't support them\n"));
+                       return false;
+               }
        }
+
        if ((fsp->oplock_type != NO_OPLOCK) &&
            (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK) &&
            koplocks &&
@@ -219,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"));
@@ -348,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);
 
@@ -818,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,
@@ -873,9 +887,8 @@ void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e)
        SIVAL(msg,OP_BREAK_MSG_FILE_ID_OFFSET,e->share_file_id);
        SIVAL(msg,OP_BREAK_MSG_UID_OFFSET,e->uid);
        SSVAL(msg,OP_BREAK_MSG_FLAGS_OFFSET,e->flags);
-#ifdef CLUSTER_SUPPORT
+       SIVAL(msg,OP_BREAK_MSG_NAME_HASH_OFFSET,e->name_hash);
        SIVAL(msg,OP_BREAK_MSG_VNN_OFFSET,e->pid.vnn);
-#endif
 }
 
 /****************************************************************************
@@ -896,9 +909,8 @@ void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
        e->share_file_id = (unsigned long)IVAL(msg,OP_BREAK_MSG_FILE_ID_OFFSET);
        e->uid = (uint32)IVAL(msg,OP_BREAK_MSG_UID_OFFSET);
        e->flags = (uint16)SVAL(msg,OP_BREAK_MSG_FLAGS_OFFSET);
-#ifdef CLUSTER_SUPPORT
+       e->name_hash = IVAL(msg,OP_BREAK_MSG_NAME_HASH_OFFSET);
        e->pid.vnn = IVAL(msg,OP_BREAK_MSG_VNN_OFFSET);
-#endif
 }
 
 /****************************************************************************
@@ -922,11 +934,12 @@ bool init_oplocks(struct messaging_context *msg_ctx)
 
        if (lp_kernel_oplocks()) {
 #if HAVE_KERNEL_OPLOCKS_IRIX
-               koplocks = irix_init_kernel_oplocks(talloc_autofree_context());
+               koplocks = irix_init_kernel_oplocks(NULL);
 #elif HAVE_KERNEL_OPLOCKS_LINUX
-               koplocks = linux_init_kernel_oplocks(talloc_autofree_context());
+               koplocks = linux_init_kernel_oplocks(NULL);
 #elif HAVE_ONEFS
-               koplocks = onefs_init_kernel_oplocks(talloc_autofree_context());
+#error Isilon, please check if the NULL context is okay here. Thanks!
+               koplocks = onefs_init_kernel_oplocks(NULL);
 #endif
        }