summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2008-03-07 12:21:11 +0100
committerStefan Metzmacher <metze@samba.org>2008-03-12 17:35:06 +0100
commit49c86b73bf1babf151835d4afdbfb132f2e2c34e (patch)
treece67096f342ac59b7d1a23abd0ac08a9ddf99bcd
parentd93f2f2e800591c68798e4a38da8fc982dac6a61 (diff)
downloadsamba-49c86b73bf1babf151835d4afdbfb132f2e2c34e.tar.gz
samba-49c86b73bf1babf151835d4afdbfb132f2e2c34e.tar.bz2
samba-49c86b73bf1babf151835d4afdbfb132f2e2c34e.zip
opendb_tdb: use sys_lease to setup kernel oplocks
metze (This used to be commit e473068bddfaa9028ab8ee49291035313b35fed3)
-rw-r--r--source4/ntvfs/common/config.mk5
-rw-r--r--source4/ntvfs/common/opendb_tdb.c46
2 files changed, 42 insertions, 9 deletions
diff --git a/source4/ntvfs/common/config.mk b/source4/ntvfs/common/config.mk
index 2fc0942ed4..3963ebcdee 100644
--- a/source4/ntvfs/common/config.mk
+++ b/source4/ntvfs/common/config.mk
@@ -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
################################################
diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c
index 9b4a5bfa9f..be78e09958 100644
--- a/source4/ntvfs/common/opendb_tdb.c
+++ b/source4/ntvfs/common/opendb_tdb.c
@@ -49,11 +49,13 @@
#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);
}