Fix include paths to new location of libutil.
[sfrench/samba-autobuild/.git] / source4 / ntvfs / posix / pvfs_lock.c
index df85b2b77526d960b94f9baf5046033129a37091..173b2fe187fdee8108b629ea57da02733afbff2f 100644 (file)
@@ -22,7 +22,7 @@
 #include "includes.h"
 #include "vfs_posix.h"
 #include "system/time.h"
-#include "lib/util/dlinklist.h"
+#include "../lib/util/dlinklist.h"
 #include "messaging/messaging.h"
 
 
@@ -31,7 +31,7 @@
 */
 NTSTATUS pvfs_check_lock(struct pvfs_state *pvfs,
                         struct pvfs_file *f,
-                        uint16_t smbpid,
+                        uint32_t smbpid,
                         uint64_t offset, uint64_t count,
                         enum brl_type rw)
 {
@@ -68,13 +68,8 @@ static void pvfs_lock_async_failed(struct pvfs_state *pvfs,
                                   int i,
                                   NTSTATUS status)
 {
-       /* in SMB2 mode we also try to unlock failing lock */ 
-       if (req->ctx->protocol != PROTOCOL_SMB2) {
-               i--;
-       }
-
        /* undo the locks we just did */
-       for (;i>=0;i--) {
+       for (i--;i>=0;i--) {
                brl_unlock(pvfs->brl_context,
                           f->brl_handle,
                           locks[i].pid,
@@ -294,6 +289,10 @@ NTSTATUS pvfs_lock(struct ntvfs_module_context *ntvfs,
                return ntvfs_map_lock(ntvfs, req, lck);
        }
 
+       if (lck->lockx.in.mode & LOCKING_ANDX_OPLOCK_RELEASE) {
+               return pvfs_oplock_release(ntvfs, req, lck);
+       }
+
        f = pvfs_find_fd(pvfs, req, lck->lockx.in.file.ntvfs);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
@@ -303,6 +302,9 @@ NTSTATUS pvfs_lock(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_FILE_IS_A_DIRECTORY;
        }
 
+       status = pvfs_break_level2_oplocks(f);
+       NT_STATUS_NOT_OK_RETURN(status);
+
        if (lck->lockx.in.timeout != 0 && 
            (req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
                pending = talloc(f, struct pvfs_pending_lock);
@@ -338,13 +340,6 @@ NTSTATUS pvfs_lock(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_DOS(ERRDOS, ERRnoatomiclocks);
        }
 
-       if (lck->lockx.in.mode & LOCKING_ANDX_OPLOCK_RELEASE) {
-               DEBUG(0,("received unexpected oplock break\n"));
-               talloc_free(pending);
-               return NT_STATUS_NOT_IMPLEMENTED;
-       }
-
-
        /* the unlocks happen first */
        locks = lck->lockx.in.locks;
 
@@ -390,12 +385,9 @@ NTSTATUS pvfs_lock(struct ntvfs_module_context *ntvfs,
                                DLIST_ADD(f->pending_list, pending);
                                return NT_STATUS_OK;
                        }
-                       /* in SMB2 mode we also try to unlock failing lock */ 
-                       if (req->ctx->protocol != PROTOCOL_SMB2) {
-                               i--;
-                       }
+
                        /* undo the locks we just did */
-                       for (;i>=0;i--) {
+                       for (i--;i>=0;i--) {
                                brl_unlock(pvfs->brl_context,
                                           f->brl_handle,
                                           locks[i].pid,