opendb_tdb: use sys_lease to setup kernel oplocks
authorStefan Metzmacher <metze@samba.org>
Fri, 7 Mar 2008 11:21:11 +0000 (12:21 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 12 Mar 2008 16:35:06 +0000 (17:35 +0100)
metze
(This used to be commit e473068bddfaa9028ab8ee49291035313b35fed3)

source4/ntvfs/common/config.mk
source4/ntvfs/common/opendb_tdb.c

index 2fc0942ed40400a3acde7c0aceea7e520b7b4a7d..3963ebcdee46f5660bf5308a9ab7e677da147ed7 100644 (file)
@@ -9,7 +9,10 @@ OBJ_FILES = \
                opendb.o \
                opendb_tdb.o \
                notify.o
-PUBLIC_DEPENDENCIES = NDR_OPENDB NDR_NOTIFY sys_notify share LIBDBWRAP
+PUBLIC_DEPENDENCIES = \
+               NDR_OPENDB NDR_NOTIFY \
+               sys_notify sys_lease \
+               share LIBDBWRAP
 PRIVATE_DEPENDENCIES = brlock_ctdb opendb_ctdb
 # End LIBRARY ntvfs_common
 ################################################
index 9b4a5bfa9f6d8ea8a118ce6cb5ccd2320f6daabb..be78e0995810497e8fad6da7e75caaff1760d6b8 100644 (file)
 #include "ntvfs/common/ntvfs_common.h"
 #include "cluster/cluster.h"
 #include "param/param.h"
+#include "ntvfs/sysdep/sys_lease.h"
 
 struct odb_context {
        struct tdb_wrap *w;
        struct ntvfs_context *ntvfs_ctx;
        bool oplocks;
+       struct sys_lease_context *lease_ctx;
 };
 
 /*
@@ -72,6 +74,10 @@ struct odb_lock {
        } can_open;
 };
 
+static NTSTATUS odb_oplock_break_send(struct messaging_context *msg_ctx,
+                                     struct opendb_entry *e,
+                                     uint8_t level);
+
 /*
   Open up the openfiles.tdb database. Close it down using
   talloc_free(). We need the messaging_ctx to allow for pending open
@@ -98,6 +104,11 @@ static struct odb_context *odb_tdb_init(TALLOC_CTX *mem_ctx,
        /* leave oplocks disabled by default until the code is working */
        odb->oplocks = lp_parm_bool(ntvfs_ctx->lp_ctx, NULL, "opendb", "oplocks", false);
 
+       odb->lease_ctx = sys_lease_context_create(ntvfs_ctx->config, odb,
+                                                 ntvfs_ctx->event_ctx,
+                                                 ntvfs_ctx->msg_ctx,
+                                                 odb_oplock_break_send);
+
        return odb;
 }
 
@@ -491,23 +502,29 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck,
                oplock_level    = OPLOCK_NONE;
        }
 
+       lck->can_open.e->file_handle            = file_handle;
+       lck->can_open.e->fd                     = fd;
+       lck->can_open.e->allow_level_II_oplock  = allow_level_II_oplock;
+       lck->can_open.e->oplock_level           = oplock_level;
+
+       if (odb->lease_ctx && fd) {
+               NTSTATUS status;
+               status = sys_lease_setup(odb->lease_ctx, lck->can_open.e);
+               NT_STATUS_NOT_OK_RETURN(status);
+       }
+
        if (oplock_granted) {
-               if (oplock_level == OPLOCK_EXCLUSIVE) {
+               if (lck->can_open.e->oplock_level == OPLOCK_EXCLUSIVE) {
                        *oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
-               } else if (oplock_level == OPLOCK_BATCH) {
+               } else if (lck->can_open.e->oplock_level == OPLOCK_BATCH) {
                        *oplock_granted = BATCH_OPLOCK_RETURN;
-               } else if (oplock_level == OPLOCK_LEVEL_II) {
+               } else if (lck->can_open.e->oplock_level == OPLOCK_LEVEL_II) {
                        *oplock_granted = LEVEL_II_OPLOCK_RETURN;
                } else {
                        *oplock_granted = NO_OPLOCK_RETURN;
                }
        }
 
-       lck->can_open.e->file_handle            = file_handle;
-       lck->can_open.e->fd                     = fd;
-       lck->can_open.e->allow_level_II_oplock  = allow_level_II_oplock;
-       lck->can_open.e->oplock_level           = oplock_level;
-
        /* it doesn't conflict, so add it to the end */
        lck->file.entries = talloc_realloc(lck, lck->file.entries,
                                           struct opendb_entry,
@@ -570,6 +587,11 @@ static NTSTATUS odb_tdb_close_file(struct odb_lock *lck, void *file_handle,
                        if (lck->file.entries[i].delete_on_close) {
                                lck->file.delete_on_close = true;
                        }
+                       if (odb->lease_ctx && lck->file.entries[i].fd) {
+                               NTSTATUS status;
+                               status = sys_lease_remove(odb->lease_ctx, &lck->file.entries[i]);
+                               NT_STATUS_NOT_OK_RETURN(status);
+                       }
                        if (i < lck->file.num_entries-1) {
                                memmove(lck->file.entries+i, lck->file.entries+i+1,
                                        (lck->file.num_entries - (i+1)) *
@@ -623,6 +645,13 @@ static NTSTATUS odb_tdb_update_oplock(struct odb_lock *lck, void *file_handle,
                if (file_handle == lck->file.entries[i].file_handle &&
                    cluster_id_equal(&odb->ntvfs_ctx->server_id, &lck->file.entries[i].server)) {
                        lck->file.entries[i].oplock_level = oplock_level;
+
+                       if (odb->lease_ctx && lck->file.entries[i].fd) {
+                               NTSTATUS status;
+                               status = sys_lease_update(odb->lease_ctx, &lck->file.entries[i]);
+                               NT_STATUS_NOT_OK_RETURN(status);
+                       }
+
                        break;
                }
        }
@@ -833,5 +862,6 @@ static const struct opendb_ops opendb_tdb_ops = {
 
 void odb_tdb_init_ops(void)
 {
+       sys_lease_init();
        odb_set_ops(&opendb_tdb_ops);
 }