From 27e322bb4d5a25a2a1ebc5df36690590d86e3afd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 22 Feb 2008 10:18:13 +0100 Subject: opendb: add odb_get_key() function to get the key back from a struct odb_lock metze (This used to be commit 11f35a2a4d383b506ced35ba06120f9531bac70c) --- source4/ntvfs/common/opendb.c | 4 ++++ source4/ntvfs/common/opendb.h | 1 + source4/ntvfs/common/opendb_tdb.c | 7 +++++++ 3 files changed, 12 insertions(+) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb.c b/source4/ntvfs/common/opendb.c index 4826ca5c26..f12f23817d 100644 --- a/source4/ntvfs/common/opendb.c +++ b/source4/ntvfs/common/opendb.c @@ -81,6 +81,10 @@ _PUBLIC_ struct odb_lock *odb_lock(TALLOC_CTX *mem_ctx, return ops->odb_lock(mem_ctx, odb, file_key); } +_PUBLIC_ DATA_BLOB odb_get_key(TALLOC_CTX *mem_ctx, struct odb_lock *lck) +{ + return ops->odb_get_key(mem_ctx, lck); +} /* register an open file in the open files database. This implements the share_access diff --git a/source4/ntvfs/common/opendb.h b/source4/ntvfs/common/opendb.h index 231ae3d7de..5472cea418 100644 --- a/source4/ntvfs/common/opendb.h +++ b/source4/ntvfs/common/opendb.h @@ -24,6 +24,7 @@ struct opendb_ops { struct ntvfs_context *ntvfs_ctx); struct odb_lock *(*odb_lock)(TALLOC_CTX *mem_ctx, struct odb_context *odb, DATA_BLOB *file_key); + DATA_BLOB (*odb_get_key)(TALLOC_CTX *mem_ctx, struct odb_lock *lck); NTSTATUS (*odb_open_file)(struct odb_lock *lck, void *file_handle, uint32_t stream_id, uint32_t share_access, uint32_t access_mask, bool delete_on_close, diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index abd9ca708b..469cf28374 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -134,6 +134,12 @@ static struct odb_lock *odb_tdb_lock(TALLOC_CTX *mem_ctx, return lck; } +static DATA_BLOB odb_tdb_get_key(TALLOC_CTX *mem_ctx, struct odb_lock *lck) +{ + return data_blob_talloc(mem_ctx, lck->key.dptr, lck->key.dsize); +} + + /* determine if two odb_entry structures conflict @@ -609,6 +615,7 @@ static NTSTATUS odb_tdb_can_open(struct odb_lock *lck, static const struct opendb_ops opendb_tdb_ops = { .odb_init = odb_tdb_init, .odb_lock = odb_tdb_lock, + .odb_get_key = odb_tdb_get_key, .odb_open_file = odb_tdb_open_file, .odb_open_file_pending = odb_tdb_open_file_pending, .odb_close_file = odb_tdb_close_file, -- cgit From 6cb9c1c61d8087457420a56f5296662417a25bd4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 21 Feb 2008 12:20:31 +0100 Subject: opendb: send also the oplock break level on MSG_NTVFS_OPLOCK_BREAK metze (This used to be commit 49402007f6e9e02a29792344c088e40d1a9b7acf) --- source4/ntvfs/common/opendb.h | 4 ++++ source4/ntvfs/common/opendb_tdb.c | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb.h b/source4/ntvfs/common/opendb.h index 5472cea418..ccf6db27a0 100644 --- a/source4/ntvfs/common/opendb.h +++ b/source4/ntvfs/common/opendb.h @@ -43,6 +43,10 @@ struct opendb_ops { uint32_t access_mask); }; +struct opendb_oplock_break { + void *file_handle; + uint8_t level; +}; void odb_set_ops(const struct opendb_ops *new_ops); void odb_tdb_init_ops(void); diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 469cf28374..25f37f5e26 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -259,12 +259,28 @@ static NTSTATUS odb_push_record(struct odb_lock *lck, struct opendb_file *file) /* send an oplock break to a client */ -static NTSTATUS odb_oplock_break_send(struct odb_context *odb, struct opendb_entry *e) +static NTSTATUS odb_oplock_break_send(struct odb_context *odb, + struct opendb_entry *e, + uint8_t level) { + NTSTATUS status; + struct opendb_oplock_break op_break; + DATA_BLOB blob; + + ZERO_STRUCT(op_break); + /* tell the server handling this open file about the need to send the client a break */ - return messaging_send_ptr(odb->ntvfs_ctx->msg_ctx, e->server, - MSG_NTVFS_OPLOCK_BREAK, e->file_handle); + op_break.file_handle = e->file_handle; + op_break.level = level; + + blob = data_blob_const(&op_break, sizeof(op_break)); + + status = messaging_send(odb->ntvfs_ctx->msg_ctx, e->server, + MSG_NTVFS_OPLOCK_BREAK, &blob); + NT_STATUS_NOT_OK_RETURN(status); + + return NT_STATUS_OK; } /* @@ -318,7 +334,8 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, break request and suspending this call until the break is acknowledged or the file is closed */ - odb_oplock_break_send(odb, &file.entries[i]); + odb_oplock_break_send(odb, &file.entries[i], + OPLOCK_BREAK_TO_LEVEL_II/*TODO*/); return NT_STATUS_OPLOCK_NOT_GRANTED; } } @@ -342,7 +359,8 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, exclusive oplocks afterwards. */ for (i=0;i Date: Thu, 21 Feb 2008 16:12:27 +0100 Subject: opendb: add odb_update_oplock() call metze (This used to be commit df576d69c6981a4879a0e9447069fcfacb3588db) --- source4/ntvfs/common/opendb.c | 6 ++++++ source4/ntvfs/common/opendb.h | 2 ++ source4/ntvfs/common/opendb_tdb.c | 45 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb.c b/source4/ntvfs/common/opendb.c index f12f23817d..4ac10806e1 100644 --- a/source4/ntvfs/common/opendb.c +++ b/source4/ntvfs/common/opendb.c @@ -170,3 +170,9 @@ _PUBLIC_ NTSTATUS odb_can_open(struct odb_lock *lck, { return ops->odb_can_open(lck, share_access, create_options, access_mask); } + +_PUBLIC_ NTSTATUS odb_update_oplock(struct odb_lock *lck, void *file_handle, + uint32_t oplock_level) +{ + return ops->odb_update_oplock(lck, file_handle, oplock_level); +} diff --git a/source4/ntvfs/common/opendb.h b/source4/ntvfs/common/opendb.h index ccf6db27a0..c34a07d6fa 100644 --- a/source4/ntvfs/common/opendb.h +++ b/source4/ntvfs/common/opendb.h @@ -41,6 +41,8 @@ struct opendb_ops { NTSTATUS (*odb_can_open)(struct odb_lock *lck, uint32_t share_access, uint32_t create_options, uint32_t access_mask); + NTSTATUS (*odb_update_oplock)(struct odb_lock *lck, void *file_handle, + uint32_t oplock_level); }; struct opendb_oplock_break { diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 25f37f5e26..3d4a760e2e 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -2,7 +2,8 @@ Unix SMB/CIFS implementation. Copyright (C) Andrew Tridgell 2004 - + Copyright (C) Stefan Metzmacher 2008 + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or @@ -463,6 +464,45 @@ static NTSTATUS odb_tdb_close_file(struct odb_lock *lck, void *file_handle) return odb_push_record(lck, &file); } +/* + update the oplock level of the client +*/ +static NTSTATUS odb_tdb_update_oplock(struct odb_lock *lck, void *file_handle, + uint32_t oplock_level) +{ + struct odb_context *odb = lck->odb; + struct opendb_file file; + int i; + NTSTATUS status; + + status = odb_pull_record(lck, &file); + NT_STATUS_NOT_OK_RETURN(status); + + /* find the entry, and update it */ + for (i=0;intvfs_ctx->server_id, &file.entries[i].server)) { + file.entries[i].oplock_level = oplock_level; + break; + } + } + + if (i == file.num_entries) { + return NT_STATUS_UNSUCCESSFUL; + } + + /* send any pending notifications, removing them once sent */ + for (i=0;intvfs_ctx->msg_ctx, + file.pending[i].server, + MSG_PVFS_RETRY_OPEN, + file.pending[i].notify_ptr); + } + file.num_pending = 0; + + return odb_push_record(lck, &file); +} + /* remove a pending opendb entry @@ -641,7 +681,8 @@ static const struct opendb_ops opendb_tdb_ops = { .odb_rename = odb_tdb_rename, .odb_set_delete_on_close = odb_tdb_set_delete_on_close, .odb_get_delete_on_close = odb_tdb_get_delete_on_close, - .odb_can_open = odb_tdb_can_open + .odb_can_open = odb_tdb_can_open, + .odb_update_oplock = odb_tdb_update_oplock }; -- cgit From f94008e45a15666439766488edf84b21a86111ee Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 22 Feb 2008 16:30:13 +0100 Subject: opendb: add odb_break_oplocks() function This send breaks to none to all level2 holders metze (This used to be commit bd3654500b14e4ed8d4a8bb25ff9da5035a16a8b) --- source4/ntvfs/common/opendb.c | 5 +++++ source4/ntvfs/common/opendb.h | 1 + source4/ntvfs/common/opendb_tdb.c | 40 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb.c b/source4/ntvfs/common/opendb.c index 4ac10806e1..3f5d7210be 100644 --- a/source4/ntvfs/common/opendb.c +++ b/source4/ntvfs/common/opendb.c @@ -176,3 +176,8 @@ _PUBLIC_ NTSTATUS odb_update_oplock(struct odb_lock *lck, void *file_handle, { return ops->odb_update_oplock(lck, file_handle, oplock_level); } + +_PUBLIC_ NTSTATUS odb_break_oplocks(struct odb_lock *lck) +{ + return ops->odb_break_oplocks(lck); +} diff --git a/source4/ntvfs/common/opendb.h b/source4/ntvfs/common/opendb.h index c34a07d6fa..c46390446c 100644 --- a/source4/ntvfs/common/opendb.h +++ b/source4/ntvfs/common/opendb.h @@ -43,6 +43,7 @@ struct opendb_ops { uint32_t access_mask); NTSTATUS (*odb_update_oplock)(struct odb_lock *lck, void *file_handle, uint32_t oplock_level); + NTSTATUS (*odb_break_oplocks)(struct odb_lock *lck); }; struct opendb_oplock_break { diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 3d4a760e2e..dd2fb138d6 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -503,6 +503,43 @@ static NTSTATUS odb_tdb_update_oplock(struct odb_lock *lck, void *file_handle, return odb_push_record(lck, &file); } +/* + send oplocks breaks to none to all level2 holders +*/ +static NTSTATUS odb_tdb_break_oplocks(struct odb_lock *lck) +{ + struct odb_context *odb = lck->odb; + NTSTATUS status; + struct opendb_file file; + int i; + bool modified = true; + + status = odb_pull_record(lck, &file); + if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { + return NT_STATUS_OK; + } + NT_STATUS_NOT_OK_RETURN(status); + + /* see if anyone has an oplock, which we need to break */ + for (i=0;i Date: Fri, 22 Feb 2008 17:26:40 +0100 Subject: opendb_tdb: grant level2 oplocks metze (This used to be commit 57f1b9d11cfcac3b5fdee1ad9e4ba81d0859c8dc) --- source4/ntvfs/common/opendb_tdb.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index dd2fb138d6..3310532406 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -367,18 +367,32 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, } /* - possibly grant an exclusive or batch oplock if this is the only client - with the file open. We don't yet grant levelII oplocks. + possibly grant an exclusive, batch or level2 oplock */ - if (oplock_granted != NULL) { - if ((oplock_level == OPLOCK_BATCH || - oplock_level == OPLOCK_EXCLUSIVE) && - file.num_entries == 0) { - (*oplock_granted) = oplock_level; + if (oplock_granted) { + if (oplock_level == OPLOCK_EXCLUSIVE) { + if (file.num_entries == 0) { + e.oplock_level = OPLOCK_EXCLUSIVE; + *oplock_granted = EXCLUSIVE_OPLOCK_RETURN; + } else { + e.oplock_level = OPLOCK_NONE; + *oplock_granted = NO_OPLOCK_RETURN; + } + } else if (oplock_level == OPLOCK_BATCH) { + if (file.num_entries == 0) { + e.oplock_level = OPLOCK_BATCH; + *oplock_granted = BATCH_OPLOCK_RETURN; + } else { + e.oplock_level = OPLOCK_LEVEL_II; + *oplock_granted = LEVEL_II_OPLOCK_RETURN; + } + } else if (oplock_level == OPLOCK_LEVEL_II) { + e.oplock_level = OPLOCK_LEVEL_II; + *oplock_granted = LEVEL_II_OPLOCK_RETURN; } else { - (*oplock_granted) = OPLOCK_NONE; + e.oplock_level = OPLOCK_NONE; + *oplock_granted = NO_OPLOCK_RETURN; } - e.oplock_level = (*oplock_granted); } /* it doesn't conflict, so add it to the end */ -- cgit From c749b66ead71af3076d4f911aa0cd65e35284ca4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 22 Feb 2008 17:26:40 +0100 Subject: opendb_tdb: attribute only opens doesn't conflict with BATCH oplocks metze (This used to be commit 7872b05abe7532676c4cc25620b96ea5d59117d2) --- source4/ntvfs/common/opendb_tdb.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 3310532406..b445981b57 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -189,7 +189,7 @@ static NTSTATUS share_conflict(struct opendb_entry *e1, struct opendb_entry *e2) e2->share_access, NTCREATEX_SHARE_ACCESS_DELETE); CHECK_MASK(e2->access_mask, SEC_STD_DELETE, e1->share_access, NTCREATEX_SHARE_ACCESS_DELETE); - +#undef CHECK_MASK return NT_STATUS_OK; } @@ -284,6 +284,25 @@ static NTSTATUS odb_oplock_break_send(struct odb_context *odb, return NT_STATUS_OK; } +static bool access_attributes_only(uint32_t access_mask, + uint32_t open_disposition) +{ + switch (open_disposition) { + case NTCREATEX_DISP_SUPERSEDE: + case NTCREATEX_DISP_OVERWRITE_IF: + case NTCREATEX_DISP_OVERWRITE: + return false; + default: + break; + } +#define CHECK_MASK(m,g) ((m) && (((m) & ~(g))==0) && (((m) & (g)) != 0)) + return CHECK_MASK(access_mask, + SEC_STD_SYNCHRONIZE | + SEC_FILE_READ_ATTRIBUTE | + SEC_FILE_WRITE_ATTRIBUTE); +#undef CHECK_MASK +} + /* register an open file in the open files database. This implements the share_access rules @@ -302,6 +321,8 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, int i; struct opendb_file file; NTSTATUS status; + uint32_t open_disposition = 0; + bool attrs_only = false; if (odb->oplocks == false) { oplock_level = OPLOCK_NONE; @@ -328,6 +349,15 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, /* see if anyone has an oplock, which we need to break */ for (i=0;i Date: Mon, 25 Feb 2008 16:14:23 +0100 Subject: opendb_tdb: add force break to none logic metze (This used to be commit fbfe953ba347a902297bd8eae900ca70efd2db01) --- source4/ntvfs/common/opendb_tdb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index b445981b57..656e113742 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -322,6 +322,7 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, struct opendb_file file; NTSTATUS status; uint32_t open_disposition = 0; + bool break_to_none = false; bool attrs_only = false; if (odb->oplocks == false) { @@ -349,6 +350,7 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, /* see if anyone has an oplock, which we need to break */ for (i=0;i Date: Mon, 25 Feb 2008 16:26:04 +0100 Subject: opendb_tdb: move sharemode, oplock logic into odb_tdb_open_can_internal() metze (This used to be commit 65cfe71b2617598f8e38d04537cfc9ce44a36680) --- source4/ntvfs/common/opendb_tdb.c | 191 ++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 89 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 656e113742..9c273f9617 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -146,7 +146,10 @@ static DATA_BLOB odb_tdb_get_key(TALLOC_CTX *mem_ctx, struct odb_lock *lck) return NT_STATUS_OK on no conflict */ -static NTSTATUS share_conflict(struct opendb_entry *e1, struct opendb_entry *e2) +static NTSTATUS share_conflict(struct opendb_entry *e1, + uint32_t stream_id, + uint32_t share_access, + uint32_t access_mask) { /* if either open involves no read.write or delete access then it can't conflict */ @@ -157,18 +160,18 @@ static NTSTATUS share_conflict(struct opendb_entry *e1, struct opendb_entry *e2) SEC_STD_DELETE))) { return NT_STATUS_OK; } - if (!(e2->access_mask & (SEC_FILE_WRITE_DATA | - SEC_FILE_APPEND_DATA | - SEC_FILE_READ_DATA | - SEC_FILE_EXECUTE | - SEC_STD_DELETE))) { + if (!(access_mask & (SEC_FILE_WRITE_DATA | + SEC_FILE_APPEND_DATA | + SEC_FILE_READ_DATA | + SEC_FILE_EXECUTE | + SEC_STD_DELETE))) { return NT_STATUS_OK; } /* data IO access masks. This is skipped if the two open handles are on different streams (as in that case the masks don't interact) */ - if (e1->stream_id != e2->stream_id) { + if (e1->stream_id != stream_id) { return NT_STATUS_OK; } @@ -176,18 +179,18 @@ static NTSTATUS share_conflict(struct opendb_entry *e1, struct opendb_entry *e2) if (((am) & (right)) && !((sa) & (share))) return NT_STATUS_SHARING_VIOLATION CHECK_MASK(e1->access_mask, SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA, - e2->share_access, NTCREATEX_SHARE_ACCESS_WRITE); - CHECK_MASK(e2->access_mask, SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA, + share_access, NTCREATEX_SHARE_ACCESS_WRITE); + CHECK_MASK(access_mask, SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA, e1->share_access, NTCREATEX_SHARE_ACCESS_WRITE); CHECK_MASK(e1->access_mask, SEC_FILE_READ_DATA | SEC_FILE_EXECUTE, - e2->share_access, NTCREATEX_SHARE_ACCESS_READ); - CHECK_MASK(e2->access_mask, SEC_FILE_READ_DATA | SEC_FILE_EXECUTE, + share_access, NTCREATEX_SHARE_ACCESS_READ); + CHECK_MASK(access_mask, SEC_FILE_READ_DATA | SEC_FILE_EXECUTE, e1->share_access, NTCREATEX_SHARE_ACCESS_READ); CHECK_MASK(e1->access_mask, SEC_STD_DELETE, - e2->share_access, NTCREATEX_SHARE_ACCESS_DELETE); - CHECK_MASK(e2->access_mask, SEC_STD_DELETE, + share_access, NTCREATEX_SHARE_ACCESS_DELETE); + CHECK_MASK(access_mask, SEC_STD_DELETE, e1->share_access, NTCREATEX_SHARE_ACCESS_DELETE); #undef CHECK_MASK return NT_STATUS_OK; @@ -303,53 +306,20 @@ static bool access_attributes_only(uint32_t access_mask, #undef CHECK_MASK } -/* - register an open file in the open files database. This implements the share_access - rules - - Note that the path is only used by the delete on close logic, not - for comparing with other filenames -*/ -static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, - uint32_t stream_id, uint32_t share_access, - uint32_t access_mask, bool delete_on_close, - const char *path, - uint32_t oplock_level, uint32_t *oplock_granted) +static NTSTATUS odb_tdb_open_can_internal(struct odb_context *odb, + const struct opendb_file *file, + uint32_t stream_id, uint32_t share_access, + uint32_t access_mask, bool delete_on_close, + uint32_t open_disposition, bool break_to_none, + bool *_attrs_only) { - struct odb_context *odb = lck->odb; - struct opendb_entry e; - int i; - struct opendb_file file; NTSTATUS status; - uint32_t open_disposition = 0; - bool break_to_none = false; + uint32_t i; bool attrs_only = false; - if (odb->oplocks == false) { - oplock_level = OPLOCK_NONE; - } - - status = odb_pull_record(lck, &file); - if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { - /* initialise a blank structure */ - ZERO_STRUCT(file); - file.path = path; - } else { - NT_STATUS_NOT_OK_RETURN(status); - } - - /* see if it conflicts */ - e.server = odb->ntvfs_ctx->server_id; - e.file_handle = file_handle; - e.stream_id = stream_id; - e.share_access = share_access; - e.access_mask = access_mask; - e.delete_on_close = delete_on_close; - e.oplock_level = OPLOCK_NONE; - /* see if anyone has an oplock, which we need to break */ - for (i=0;inum_entries;i++) { + if (file->entries[i].oplock_level == OPLOCK_BATCH) { bool oplock_return = OPLOCK_BREAK_TO_LEVEL_II; /* if this is an attribute only access * it doesn't conflict with a BACTCH oplock @@ -370,21 +340,22 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, if (break_to_none) { oplock_return = OPLOCK_BREAK_TO_NONE; } - odb_oplock_break_send(odb, &file.entries[i], + odb_oplock_break_send(odb, &file->entries[i], oplock_return); return NT_STATUS_OPLOCK_NOT_GRANTED; } } - if (file.delete_on_close || - (file.num_entries != 0 && delete_on_close)) { + if (file->delete_on_close || + (file->num_entries != 0 && delete_on_close)) { /* while delete on close is set, no new opens are allowed */ return NT_STATUS_DELETE_PENDING; } /* check for sharing violations */ - for (i=0;inum_entries;i++) { + status = share_conflict(&file->entries[i], stream_id, + share_access, access_mask); NT_STATUS_NOT_OK_RETURN(status); } @@ -393,14 +364,70 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, till these are broken. Note that we check for batch oplocks before checking for sharing violations, and check for exclusive oplocks afterwards. */ - for (i=0;inum_entries;i++) { + if (file->entries[i].oplock_level == OPLOCK_EXCLUSIVE) { + odb_oplock_break_send(odb, &file->entries[i], OPLOCK_BREAK_TO_NONE); return NT_STATUS_OPLOCK_NOT_GRANTED; } } + if (_attrs_only) { + *_attrs_only = attrs_only; + } + return NT_STATUS_OK; +} + +/* + register an open file in the open files database. This implements the share_access + rules + + Note that the path is only used by the delete on close logic, not + for comparing with other filenames +*/ +static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, + uint32_t stream_id, uint32_t share_access, + uint32_t access_mask, bool delete_on_close, + const char *path, + uint32_t oplock_level, uint32_t *oplock_granted) +{ + struct odb_context *odb = lck->odb; + struct opendb_entry e; + struct opendb_file file; + NTSTATUS status; + uint32_t open_disposition = 0; + bool break_to_none = false; + bool attrs_only = false; + + if (odb->oplocks == false) { + oplock_level = OPLOCK_NONE; + } + + status = odb_pull_record(lck, &file); + if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { + /* initialise a blank structure */ + ZERO_STRUCT(file); + file.path = path; + } else { + NT_STATUS_NOT_OK_RETURN(status); + } + + /* see if it conflicts */ + status = odb_tdb_open_can_internal(odb, &file, stream_id, + share_access, access_mask, + delete_on_close, open_disposition, + break_to_none, &attrs_only); + NT_STATUS_NOT_OK_RETURN(status); + + /* see if it conflicts */ + e.server = odb->ntvfs_ctx->server_id; + e.file_handle = file_handle; + e.stream_id = stream_id; + e.share_access = share_access; + e.access_mask = access_mask; + e.delete_on_close = delete_on_close; + e.oplock_level = OPLOCK_NONE; + /* possibly grant an exclusive, batch or level2 oplock */ @@ -719,8 +746,11 @@ static NTSTATUS odb_tdb_can_open(struct odb_lock *lck, struct odb_context *odb = lck->odb; NTSTATUS status; struct opendb_file file; - struct opendb_entry e; - int i; + uint32_t stream_id = 0; + uint32_t open_disposition = 0; + bool delete_on_close = false; + bool break_to_none = false; + bool attrs_only = false; status = odb_pull_record(lck, &file); if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { @@ -728,32 +758,15 @@ static NTSTATUS odb_tdb_can_open(struct odb_lock *lck, } NT_STATUS_NOT_OK_RETURN(status); - if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) && - file.num_entries != 0) { - return NT_STATUS_SHARING_VIOLATION; + if (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) { + delete_on_close = true; } - if (file.delete_on_close) { - return NT_STATUS_DELETE_PENDING; - } - - e.server = odb->ntvfs_ctx->server_id; - e.file_handle = NULL; - e.stream_id = 0; - e.share_access = share_access; - e.access_mask = access_mask; - - for (i=0;i Date: Mon, 25 Feb 2008 20:20:35 +0100 Subject: opendb_tdb: only file->delete_on_close == true should give DELETE_PENDING metze (This used to be commit 5b12157e0f0f1cf6ea90503a72b56ab2032cb6e5) --- source4/ntvfs/common/opendb_tdb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 9c273f9617..8b5e4850d9 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -346,12 +346,15 @@ static NTSTATUS odb_tdb_open_can_internal(struct odb_context *odb, } } - if (file->delete_on_close || - (file->num_entries != 0 && delete_on_close)) { + if (file->delete_on_close) { /* while delete on close is set, no new opens are allowed */ return NT_STATUS_DELETE_PENDING; } + if (file->num_entries != 0 && delete_on_close) { + return NT_STATUS_SHARING_VIOLATION; + } + /* check for sharing violations */ for (i=0;inum_entries;i++) { status = share_conflict(&file->entries[i], stream_id, -- cgit From facdc472c7e6dbca0553a5e0dfb100be322339ce Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 25 Feb 2008 16:47:48 +0100 Subject: opendb: pass down open_disposition and break_to_none to odb_open_file() metze (This used to be commit aaaa26ae5e810495f313dfada771a8de86cedbd4) --- source4/ntvfs/common/opendb.c | 13 +++++++------ source4/ntvfs/common/opendb.h | 7 ++++--- source4/ntvfs/common/opendb_tdb.c | 7 +++---- 3 files changed, 14 insertions(+), 13 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb.c b/source4/ntvfs/common/opendb.c index 3f5d7210be..c380355466 100644 --- a/source4/ntvfs/common/opendb.c +++ b/source4/ntvfs/common/opendb.c @@ -93,15 +93,16 @@ _PUBLIC_ DATA_BLOB odb_get_key(TALLOC_CTX *mem_ctx, struct odb_lock *lck) Note that the path is only used by the delete on close logic, not for comparing with other filenames */ -_PUBLIC_ NTSTATUS odb_open_file(struct odb_lock *lck, void *file_handle, - uint32_t stream_id, uint32_t share_access, +_PUBLIC_ NTSTATUS odb_open_file(struct odb_lock *lck, + void *file_handle, const char *path, + uint32_t stream_id, uint32_t share_access, uint32_t access_mask, bool delete_on_close, - const char *path, + uint32_t open_disposition, bool break_to_none, uint32_t oplock_level, uint32_t *oplock_granted) { - return ops->odb_open_file(lck, file_handle, stream_id, share_access, - access_mask, delete_on_close, path, oplock_level, - oplock_granted); + return ops->odb_open_file(lck, file_handle, path, stream_id, share_access, + access_mask, delete_on_close, open_disposition, + break_to_none, oplock_level, oplock_granted); } diff --git a/source4/ntvfs/common/opendb.h b/source4/ntvfs/common/opendb.h index c46390446c..205d2228ea 100644 --- a/source4/ntvfs/common/opendb.h +++ b/source4/ntvfs/common/opendb.h @@ -25,10 +25,11 @@ struct opendb_ops { struct odb_lock *(*odb_lock)(TALLOC_CTX *mem_ctx, struct odb_context *odb, DATA_BLOB *file_key); DATA_BLOB (*odb_get_key)(TALLOC_CTX *mem_ctx, struct odb_lock *lck); - NTSTATUS (*odb_open_file)(struct odb_lock *lck, void *file_handle, - uint32_t stream_id, uint32_t share_access, + NTSTATUS (*odb_open_file)(struct odb_lock *lck, + void *file_handle, const char *path, + uint32_t stream_id, uint32_t share_access, uint32_t access_mask, bool delete_on_close, - const char *path, + uint32_t open_disposition, bool break_to_none, uint32_t oplock_level, uint32_t *oplock_granted); NTSTATUS (*odb_open_file_pending)(struct odb_lock *lck, void *private); NTSTATUS (*odb_close_file)(struct odb_lock *lck, void *file_handle); diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 8b5e4850d9..d41a5c371e 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -388,18 +388,17 @@ static NTSTATUS odb_tdb_open_can_internal(struct odb_context *odb, Note that the path is only used by the delete on close logic, not for comparing with other filenames */ -static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, void *file_handle, +static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, + void *file_handle, const char *path, uint32_t stream_id, uint32_t share_access, uint32_t access_mask, bool delete_on_close, - const char *path, + uint32_t open_disposition, bool break_to_none, uint32_t oplock_level, uint32_t *oplock_granted) { struct odb_context *odb = lck->odb; struct opendb_entry e; struct opendb_file file; NTSTATUS status; - uint32_t open_disposition = 0; - bool break_to_none = false; bool attrs_only = false; if (odb->oplocks == false) { -- cgit From 7264a8b7ca5f91120dbc30fcbe8e8402f09ae883 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 25 Feb 2008 17:48:13 +0100 Subject: opendb: unify the parameters of odb_open_file() and odb_can_open() metze (This used to be commit e6b708a52b0eada3fd374b66292ded3b0f6ce217) --- source4/ntvfs/common/opendb.c | 8 +++++--- source4/ntvfs/common/opendb.h | 5 +++-- source4/ntvfs/common/opendb_tdb.c | 13 +++---------- 3 files changed, 11 insertions(+), 15 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb.c b/source4/ntvfs/common/opendb.c index c380355466..36144d0406 100644 --- a/source4/ntvfs/common/opendb.c +++ b/source4/ntvfs/common/opendb.c @@ -166,10 +166,12 @@ _PUBLIC_ NTSTATUS odb_get_delete_on_close(struct odb_context *odb, create_options and access_mask */ _PUBLIC_ NTSTATUS odb_can_open(struct odb_lock *lck, - uint32_t share_access, uint32_t create_options, - uint32_t access_mask) + uint32_t stream_id, uint32_t share_access, + uint32_t access_mask, bool delete_on_close, + uint32_t open_disposition, bool break_to_none) { - return ops->odb_can_open(lck, share_access, create_options, access_mask); + return ops->odb_can_open(lck, stream_id, share_access, access_mask, + delete_on_close, open_disposition, break_to_none); } _PUBLIC_ NTSTATUS odb_update_oplock(struct odb_lock *lck, void *file_handle, diff --git a/source4/ntvfs/common/opendb.h b/source4/ntvfs/common/opendb.h index 205d2228ea..9591bcf6b9 100644 --- a/source4/ntvfs/common/opendb.h +++ b/source4/ntvfs/common/opendb.h @@ -40,8 +40,9 @@ struct opendb_ops { DATA_BLOB *key, bool *del_on_close, int *open_count, char **path); NTSTATUS (*odb_can_open)(struct odb_lock *lck, - uint32_t share_access, uint32_t create_options, - uint32_t access_mask); + uint32_t stream_id, uint32_t share_access, + uint32_t access_mask, bool delete_on_close, + uint32_t open_disposition, bool break_to_none); NTSTATUS (*odb_update_oplock)(struct odb_lock *lck, void *file_handle, uint32_t oplock_level); NTSTATUS (*odb_break_oplocks)(struct odb_lock *lck); diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index d41a5c371e..73c04b7c4f 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -742,16 +742,13 @@ static NTSTATUS odb_tdb_get_delete_on_close(struct odb_context *odb, create_options and access_mask */ static NTSTATUS odb_tdb_can_open(struct odb_lock *lck, - uint32_t share_access, uint32_t create_options, - uint32_t access_mask) + uint32_t stream_id, uint32_t share_access, + uint32_t access_mask, bool delete_on_close, + uint32_t open_disposition, bool break_to_none) { struct odb_context *odb = lck->odb; NTSTATUS status; struct opendb_file file; - uint32_t stream_id = 0; - uint32_t open_disposition = 0; - bool delete_on_close = false; - bool break_to_none = false; bool attrs_only = false; status = odb_pull_record(lck, &file); @@ -760,10 +757,6 @@ static NTSTATUS odb_tdb_can_open(struct odb_lock *lck, } NT_STATUS_NOT_OK_RETURN(status); - if (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) { - delete_on_close = true; - } - status = odb_tdb_open_can_internal(odb, &file, stream_id, share_access, access_mask, delete_on_close, open_disposition, -- cgit From 2b94ffe5e7303c1d321b9a9c6a612f77f1ac58b2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 26 Feb 2008 12:52:46 +0100 Subject: opendb_tdb: with break_to_none attribute only opens also break oplocks metze (This used to be commit c475353e34154eb13e35cc8b6cf553e3986f8677) --- source4/ntvfs/common/opendb_tdb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source4/ntvfs/common') diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 73c04b7c4f..fe5a0a8864 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -288,7 +288,8 @@ static NTSTATUS odb_oplock_break_send(struct odb_context *odb, } static bool access_attributes_only(uint32_t access_mask, - uint32_t open_disposition) + uint32_t open_disposition, + bool break_to_none) { switch (open_disposition) { case NTCREATEX_DISP_SUPERSEDE: @@ -298,6 +299,11 @@ static bool access_attributes_only(uint32_t access_mask, default: break; } + + if (break_to_none) { + return false; + } + #define CHECK_MASK(m,g) ((m) && (((m) & ~(g))==0) && (((m) & (g)) != 0)) return CHECK_MASK(access_mask, SEC_STD_SYNCHRONIZE | @@ -326,7 +332,8 @@ static NTSTATUS odb_tdb_open_can_internal(struct odb_context *odb, * but we'll not grant the oplock below */ attrs_only = access_attributes_only(access_mask, - open_disposition); + open_disposition, + break_to_none); if (attrs_only) { break; } -- cgit