/*
Unix SMB/CIFS implementation.
- generic byte range locking code
+ generic byte range locking code - tdb backend
- Copyright (C) Andrew Tridgell 1992-2004
+ Copyright (C) Andrew Tridgell 1992-2006
Copyright (C) Jeremy Allison 1992-2000
This program is free software; you can redistribute it and/or modify
#include "lib/messaging/irpc.h"
#include "libcli/libcli.h"
#include "cluster/cluster.h"
+#include "ntvfs/common/brlock.h"
/*
in this module a "DATA_BLOB *file_key" is a blob that uniquely identifies
as it is applied consistently.
*/
-struct brl_context;
+/* this struct is typicaly attached to tcon */
+struct brl_context {
+ struct tdb_wrap *w;
+ struct server_id server;
+ struct messaging_context *messaging_ctx;
+};
+
/*
the lock context contains the elements that define whether one
lock is the same as another lock
struct lock_struct last_lock;
};
-/* this struct is typicaly attached to tcon */
-struct brl_context {
- struct tdb_wrap *w;
- struct server_id server;
- struct messaging_context *messaging_ctx;
-};
-
/*
Open up the brlock.tdb database. Close it down using
talloc_free(). We need the messaging_ctx to allow for
pending lock notifications.
*/
-struct brl_context *brl_init(TALLOC_CTX *mem_ctx, struct server_id server,
- struct messaging_context *messaging_ctx)
+static struct brl_context *brl_tdb_init(TALLOC_CTX *mem_ctx, struct server_id server,
+ struct messaging_context *messaging_ctx)
{
char *path;
struct brl_context *brl;
return brl;
}
-struct brl_handle *brl_create_handle(TALLOC_CTX *mem_ctx, struct ntvfs_handle *ntvfs, DATA_BLOB *file_key)
+static struct brl_handle *brl_tdb_create_handle(TALLOC_CTX *mem_ctx, struct ntvfs_handle *ntvfs,
+ DATA_BLOB *file_key)
{
struct brl_handle *brlh;
/*
see if two locking contexts are equal
*/
-static BOOL brl_same_context(struct lock_context *ctx1, struct lock_context *ctx2)
+static BOOL brl_tdb_same_context(struct lock_context *ctx1, struct lock_context *ctx2)
{
return (cluster_id_equal(&ctx1->server, &ctx2->server) &&
ctx1->smbpid == ctx2->smbpid &&
/*
see if lck1 and lck2 overlap
*/
-static BOOL brl_overlap(struct lock_struct *lck1,
+static BOOL brl_tdb_overlap(struct lock_struct *lck1,
struct lock_struct *lck2)
{
/* this extra check is not redundent - it copes with locks
/*
See if lock2 can be added when lock1 is in place.
*/
-static BOOL brl_conflict(struct lock_struct *lck1,
+static BOOL brl_tdb_conflict(struct lock_struct *lck1,
struct lock_struct *lck2)
{
/* pending locks don't conflict with anything */
return False;
}
- if (brl_same_context(&lck1->context, &lck2->context) &&
+ if (brl_tdb_same_context(&lck1->context, &lck2->context) &&
lck2->lock_type == READ_LOCK && lck1->ntvfs == lck2->ntvfs) {
return False;
}
- return brl_overlap(lck1, lck2);
+ return brl_tdb_overlap(lck1, lck2);
}
Check to see if this lock conflicts, but ignore our own locks on the
same fnum only.
*/
-static BOOL brl_conflict_other(struct lock_struct *lck1, struct lock_struct *lck2)
+static BOOL brl_tdb_conflict_other(struct lock_struct *lck1, struct lock_struct *lck2)
{
/* pending locks don't conflict with anything */
if (lck1->lock_type >= PENDING_READ_LOCK ||
* locks even if the context is the same. JRA. See LOCKTEST7
* in smbtorture.
*/
- if (brl_same_context(&lck1->context, &lck2->context) &&
+ if (brl_tdb_same_context(&lck1->context, &lck2->context) &&
lck1->ntvfs == lck2->ntvfs &&
(lck2->lock_type == READ_LOCK || lck1->lock_type == WRITE_LOCK)) {
return False;
}
- return brl_overlap(lck1, lck2);
+ return brl_tdb_overlap(lck1, lck2);
}
is the same as this one and changes its error code. I wonder if any
app depends on this?
*/
-static NTSTATUS brl_lock_failed(struct brl_handle *brlh, struct lock_struct *lock)
+static NTSTATUS brl_tdb_lock_failed(struct brl_handle *brlh, struct lock_struct *lock)
{
/*
* this function is only called for non pending lock!
someone else closing an overlapping lock range) a messaging
notification is sent, identified by the notify_ptr
*/
-NTSTATUS brl_lock(struct brl_context *brl,
- struct brl_handle *brlh,
- uint16_t smbpid,
- uint64_t start, uint64_t size,
- enum brl_type lock_type,
- void *notify_ptr)
+static NTSTATUS brl_tdb_lock(struct brl_context *brl,
+ struct brl_handle *brlh,
+ uint16_t smbpid,
+ uint64_t start, uint64_t size,
+ enum brl_type lock_type,
+ void *notify_ptr)
{
TDB_DATA kbuf, dbuf;
int count=0, i;
/* here we need to force that the last_lock isn't overwritten */
lock = brlh->last_lock;
- status = brl_lock(brl, brlh, smbpid, start, size, rw, NULL);
+ status = brl_tdb_lock(brl, brlh, smbpid, start, size, rw, NULL);
brlh->last_lock = lock;
if (NT_STATUS_IS_OK(status)) {
locks = (struct lock_struct *)dbuf.dptr;
count = dbuf.dsize / sizeof(*locks);
for (i=0; i<count; i++) {
- if (brl_conflict(&locks[i], &lock)) {
- status = brl_lock_failed(brlh, &lock);
+ if (brl_tdb_conflict(&locks[i], &lock)) {
+ status = brl_tdb_lock_failed(brlh, &lock);
goto fail;
}
}
locks that cover this range and if we find any then notify the server that it should
retry the lock
*/
-static void brl_notify_unlock(struct brl_context *brl,
+static void brl_tdb_notify_unlock(struct brl_context *brl,
struct lock_struct *locks, int count,
struct lock_struct *removed_lock)
{
for (i=0;i<count;i++) {
if (locks[i].lock_type >= PENDING_READ_LOCK &&
- brl_overlap(&locks[i], removed_lock)) {
- if (last_notice != -1 && brl_overlap(&locks[i], &locks[last_notice])) {
+ brl_tdb_overlap(&locks[i], removed_lock)) {
+ if (last_notice != -1 && brl_tdb_overlap(&locks[i], &locks[last_notice])) {
continue;
}
if (locks[i].lock_type == PENDING_WRITE_LOCK) {
send notifications for all pending locks - the file is being closed by this
user
*/
-static void brl_notify_all(struct brl_context *brl,
+static void brl_tdb_notify_all(struct brl_context *brl,
struct lock_struct *locks, int count)
{
int i;
for (i=0;i<count;i++) {
if (locks->lock_type >= PENDING_READ_LOCK) {
- brl_notify_unlock(brl, locks, count, &locks[i]);
+ brl_tdb_notify_unlock(brl, locks, count, &locks[i]);
}
}
}
/*
Unlock a range of bytes.
*/
-NTSTATUS brl_unlock(struct brl_context *brl,
- struct brl_handle *brlh,
- uint16_t smbpid,
- uint64_t start, uint64_t size)
+static NTSTATUS brl_tdb_unlock(struct brl_context *brl,
+ struct brl_handle *brlh,
+ uint16_t smbpid,
+ uint64_t start, uint64_t size)
{
TDB_DATA kbuf, dbuf;
int count, i;
for (i=0; i<count; i++) {
struct lock_struct *lock = &locks[i];
- if (brl_same_context(&lock->context, &context) &&
+ if (brl_tdb_same_context(&lock->context, &context) &&
lock->ntvfs == brlh->ntvfs &&
lock->start == start &&
lock->size == size &&
count--;
/* send notifications for any relevant pending locks */
- brl_notify_unlock(brl, locks, count, &removed_lock);
+ brl_tdb_notify_unlock(brl, locks, count, &removed_lock);
dbuf.dsize = count * sizeof(*locks);
given up trying to establish a lock or when they have succeeded in
getting it. In either case they no longer need to be notified.
*/
-NTSTATUS brl_remove_pending(struct brl_context *brl,
- struct brl_handle *brlh,
- void *notify_ptr)
+static NTSTATUS brl_tdb_remove_pending(struct brl_context *brl,
+ struct brl_handle *brlh,
+ void *notify_ptr)
{
TDB_DATA kbuf, dbuf;
int count, i;
/*
Test if we are allowed to perform IO on a region of an open file
*/
-NTSTATUS brl_locktest(struct brl_context *brl,
- struct brl_handle *brlh,
- uint16_t smbpid,
- uint64_t start, uint64_t size,
- enum brl_type lock_type)
+static NTSTATUS brl_tdb_locktest(struct brl_context *brl,
+ struct brl_handle *brlh,
+ uint16_t smbpid,
+ uint64_t start, uint64_t size,
+ enum brl_type lock_type)
{
TDB_DATA kbuf, dbuf;
int count, i;
count = dbuf.dsize / sizeof(*locks);
for (i=0; i<count; i++) {
- if (brl_conflict_other(&locks[i], &lock)) {
+ if (brl_tdb_conflict_other(&locks[i], &lock)) {
free(dbuf.dptr);
return NT_STATUS_FILE_LOCK_CONFLICT;
}
/*
Remove any locks associated with a open file.
*/
-NTSTATUS brl_close(struct brl_context *brl,
- struct brl_handle *brlh)
+static NTSTATUS brl_tdb_close(struct brl_context *brl,
+ struct brl_handle *brlh)
{
TDB_DATA kbuf, dbuf;
int count, i, dcount=0;
/* tell all pending lock holders for this file that
they have a chance now. This is a bit indiscriminant,
but works OK */
- brl_notify_all(brl, locks, count);
+ brl_tdb_notify_all(brl, locks, count);
dbuf.dsize = count * sizeof(*locks);
return status;
}
+
+static const struct brlock_ops brlock_tdb_ops = {
+ .brl_init = brl_tdb_init,
+ .brl_create_handle = brl_tdb_create_handle,
+ .brl_lock = brl_tdb_lock,
+ .brl_unlock = brl_tdb_unlock,
+ .brl_remove_pending = brl_tdb_remove_pending,
+ .brl_locktest = brl_tdb_locktest,
+ .brl_close = brl_tdb_close
+};
+
+
+void brl_tdb_init_ops(void)
+{
+ brl_set_ops(&brlock_tdb_ops);
+}