From b655468cf6646bdcc6bb78fe87492cf34b54713f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 7 Mar 2008 19:12:14 +0100 Subject: vfs_cifs: disable level2 oplocks if the frontend client doesn't support them metze (This used to be commit a63910e8e5c075aff45b8eb0d246d2823f09bb9c) --- source4/ntvfs/cifs/vfs_cifs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/ntvfs') diff --git a/source4/ntvfs/cifs/vfs_cifs.c b/source4/ntvfs/cifs/vfs_cifs.c index 901dd2cf7c..58183b5e60 100644 --- a/source4/ntvfs/cifs/vfs_cifs.c +++ b/source4/ntvfs/cifs/vfs_cifs.c @@ -207,7 +207,11 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, io.in.service = remote_share; io.in.service_type = "?????"; lp_smbcli_options(ntvfs->ctx->lp_ctx, &io.in.options); - + + if (!(ntvfs->ctx->client_caps & NTVFS_CLIENT_CAP_LEVEL_II_OPLOCKS)) { + io.in.options.use_level2_oplocks = false; + } + creq = smb_composite_connect_send(&io, private, lp_resolve_context(ntvfs->ctx->lp_ctx), ntvfs->ctx->event_ctx); -- cgit From 6c27daeeca9c2649896b70fba78c3c401159defe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 7 Mar 2008 10:33:57 +0100 Subject: opendb_tdb: pass down struct messaging_context directly to odb_oplock_break_send() metze (This used to be commit c993b07f7d5caf290ccb9ca81961aa35a3ed1f02) --- source4/ntvfs/common/opendb_tdb.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source4/ntvfs') diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 0736af3d1e..75424e65f6 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -263,7 +263,7 @@ 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, +static NTSTATUS odb_oplock_break_send(struct messaging_context *msg_ctx, struct opendb_entry *e, uint8_t level) { @@ -280,7 +280,7 @@ static NTSTATUS odb_oplock_break_send(struct odb_context *odb, blob = data_blob_const(&op_break, sizeof(op_break)); - status = messaging_send(odb->ntvfs_ctx->msg_ctx, e->server, + status = messaging_send(msg_ctx, e->server, MSG_NTVFS_OPLOCK_BREAK, &blob); NT_STATUS_NOT_OK_RETURN(status); @@ -348,7 +348,8 @@ static NTSTATUS odb_tdb_open_can_internal(struct odb_context *odb, !file->entries[i].allow_level_II_oplock) { oplock_return = OPLOCK_BREAK_TO_NONE; } - odb_oplock_break_send(odb, &file->entries[i], + odb_oplock_break_send(odb->ntvfs_ctx->msg_ctx, + &file->entries[i], oplock_return); return NT_STATUS_OPLOCK_NOT_GRANTED; } @@ -396,7 +397,8 @@ static NTSTATUS odb_tdb_open_can_internal(struct odb_context *odb, !file->entries[i].allow_level_II_oplock) { oplock_return = OPLOCK_BREAK_TO_NONE; } - odb_oplock_break_send(odb, &file->entries[i], + odb_oplock_break_send(odb->ntvfs_ctx->msg_ctx, + &file->entries[i], oplock_return); return NT_STATUS_OPLOCK_NOT_GRANTED; } @@ -655,7 +657,8 @@ static NTSTATUS odb_tdb_break_oplocks(struct odb_lock *lck) * and we just send a break to none to all of them * without waiting for a release */ - odb_oplock_break_send(odb, &file.entries[i], + odb_oplock_break_send(odb->ntvfs_ctx->msg_ctx, + &file.entries[i], OPLOCK_BREAK_TO_NONE); file.entries[i].oplock_level = OPLOCK_NONE; modified = true; -- cgit From 75a412a46975754e75679f5d072e6ce688fee894 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 7 Mar 2008 17:50:17 +0100 Subject: pvfs_open: always call odb_can_open() before odb_open_file() odb_open_file() will later change to not redo the logic of odb_can_open(). metze (This used to be commit b09a1461ac595be1b6530221b7df5211084884cc) --- source4/ntvfs/posix/pvfs_open.c | 51 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) (limited to 'source4/ntvfs') diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 47b44b9634..1ed517c719 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -290,6 +290,15 @@ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs, } /* see if we are allowed to open at the same time as existing opens */ + status = odb_can_open(lck, name->stream_id, + share_access, access_mask, del_on_close, + io->generic.in.open_disposition, false); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(lck); + return status; + } + + /* now really mark the file as open */ status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, share_access, access_mask, del_on_close, io->generic.in.open_disposition, @@ -344,6 +353,14 @@ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs, return NT_STATUS_INTERNAL_DB_CORRUPTION; } + status = odb_can_open(lck, name->stream_id, + share_access, access_mask, del_on_close, + io->generic.in.open_disposition, false); + + if (!NT_STATUS_IS_OK(status)) { + goto cleanup_delete; + } + status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, share_access, access_mask, del_on_close, io->generic.in.open_disposition, @@ -663,6 +680,18 @@ static NTSTATUS pvfs_create_file(struct pvfs_state *pvfs, allow_level_II_oplock = true; } + status = odb_can_open(lck, name->stream_id, + share_access, access_mask, del_on_close, + io->generic.in.open_disposition, false); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(lck); + /* bad news, we must have hit a race - we don't delete the file + here as the most likely scenario is that someone else created + the file at the same time */ + close(fd); + return status; + } + status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, share_access, access_mask, del_on_close, io->generic.in.open_disposition, @@ -801,7 +830,7 @@ static void pvfs_odb_retry_callback(void *_r, enum pvfs_wait_notice reason) /* setup for a retry of a request that was rejected - by odb_open_file() or odb_can_open() + by odb_can_open() */ NTSTATUS pvfs_odb_retry_setup(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, @@ -1253,11 +1282,9 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, } /* see if we are allowed to open at the same time as existing opens */ - status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, - share_access, access_mask, del_on_close, - io->generic.in.open_disposition, - false, allow_level_II_oplock, - oplock_level, &oplock_granted); + status = odb_can_open(lck, name->stream_id, + share_access, access_mask, del_on_close, + io->generic.in.open_disposition, false); /* * on a sharing violation we need to retry when the file is closed by @@ -1276,6 +1303,18 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, return status; } + /* now really mark the file as open */ + status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, + share_access, access_mask, del_on_close, + io->generic.in.open_disposition, + false, allow_level_II_oplock, + oplock_level, &oplock_granted); + + if (!NT_STATUS_IS_OK(status)) { + talloc_free(lck); + return status; + } + if (pvfs->flags & PVFS_FLAG_FAKE_OPLOCKS) { oplock_granted = OPLOCK_BATCH; } else if (oplock_granted != OPLOCK_NONE) { -- cgit From e5e799aeb6b57ade1dd9c1a1d2c3aab1ad08d6df Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 7 Mar 2008 18:23:34 +0100 Subject: opendb: force odb_can_open() before odb_open_file() Now there's only odb_can_open() which handles the share_access rules. And odb_open_file() only adds the new opendb_entry into the database and calculates the granted oplock level. metze (This used to be commit db0853ae4fead34ef382bbfcfe2f46453ab8b73b) --- source4/ntvfs/common/opendb.c | 14 ++--- source4/ntvfs/common/opendb.h | 3 - source4/ntvfs/common/opendb_tdb.c | 120 +++++++++++++++++++++----------------- 3 files changed, 72 insertions(+), 65 deletions(-) (limited to 'source4/ntvfs') diff --git a/source4/ntvfs/common/opendb.c b/source4/ntvfs/common/opendb.c index a7e5458aaf..1cc077137c 100644 --- a/source4/ntvfs/common/opendb.c +++ b/source4/ntvfs/common/opendb.c @@ -87,23 +87,21 @@ _PUBLIC_ DATA_BLOB odb_get_key(TALLOC_CTX *mem_ctx, struct odb_lock *lck) } /* - register an open file in the open files database. This implements the share_access - rules + register an open file in the open files database. + The share_access rules are implemented by odb_can_open() + and it's needed to call odb_can_open() before + odb_open_file() otherwise NT_STATUS_INTERNAL_ERROR is returned 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, const char *path, - 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 allow_level_II_oplock, uint32_t oplock_level, uint32_t *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, allow_level_II_oplock, + return ops->odb_open_file(lck, file_handle, path, + allow_level_II_oplock, oplock_level, oplock_granted); } diff --git a/source4/ntvfs/common/opendb.h b/source4/ntvfs/common/opendb.h index 1c7f815dea..fb3223aea9 100644 --- a/source4/ntvfs/common/opendb.h +++ b/source4/ntvfs/common/opendb.h @@ -27,9 +27,6 @@ struct opendb_ops { DATA_BLOB (*odb_get_key)(TALLOC_CTX *mem_ctx, struct odb_lock *lck); 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, - uint32_t open_disposition, bool break_to_none, bool allow_level_II_oplock, uint32_t oplock_level, uint32_t *oplock_granted); NTSTATUS (*odb_open_file_pending)(struct odb_lock *lck, void *private); diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c index 75424e65f6..f71416ec83 100644 --- a/source4/ntvfs/common/opendb_tdb.c +++ b/source4/ntvfs/common/opendb_tdb.c @@ -63,6 +63,11 @@ struct odb_context { struct odb_lock { struct odb_context *odb; TDB_DATA key; + + struct { + struct opendb_entry *e; + bool attrs_only; + } can_open; }; /* @@ -130,6 +135,8 @@ static struct odb_lock *odb_tdb_lock(TALLOC_CTX *mem_ctx, return NULL; } + ZERO_STRUCT(lck->can_open); + talloc_set_destructor(lck, odb_lock_destructor); return lck; @@ -411,30 +418,35 @@ static NTSTATUS odb_tdb_open_can_internal(struct odb_context *odb, } /* - register an open file in the open files database. This implements the share_access - rules + register an open file in the open files database. + The share_access rules are implemented by odb_can_open() + and it's needed to call odb_can_open() before + odb_open_file() otherwise NT_STATUS_INTERNAL_ERROR is returned 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, const char *path, - 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 allow_level_II_oplock, uint32_t oplock_level, uint32_t *oplock_granted) { struct odb_context *odb = lck->odb; - struct opendb_entry e; struct opendb_file file; NTSTATUS status; - bool attrs_only = false; + + if (!lck->can_open.e) { + return NT_STATUS_INTERNAL_ERROR; + } if (odb->oplocks == false) { oplock_level = OPLOCK_NONE; } + if (!oplock_granted) { + 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 */ @@ -444,67 +456,55 @@ static NTSTATUS odb_tdb_open_file(struct odb_lock *lck, 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.allow_level_II_oplock = allow_level_II_oplock; - e.oplock_level = OPLOCK_NONE; - /* possibly grant an exclusive, batch or level2 oplock */ + if (lck->can_open.attrs_only) { + oplock_level = OPLOCK_NONE; + } else if (oplock_level == OPLOCK_EXCLUSIVE) { + if (file.num_entries == 0) { + oplock_level = OPLOCK_EXCLUSIVE; + } else if (allow_level_II_oplock) { + oplock_level = OPLOCK_LEVEL_II; + } else { + oplock_level = OPLOCK_NONE; + } + } else if (oplock_level == OPLOCK_BATCH) { + if (file.num_entries == 0) { + oplock_level = OPLOCK_BATCH; + } else if (allow_level_II_oplock) { + oplock_level = OPLOCK_LEVEL_II; + } else { + oplock_level = OPLOCK_NONE; + } + } else if (oplock_level == OPLOCK_LEVEL_II) { + oplock_level = OPLOCK_LEVEL_II; + } else { + oplock_level = OPLOCK_NONE; + } + if (oplock_granted) { - if (attrs_only) { - e.oplock_level = OPLOCK_NONE; - *oplock_granted = NO_OPLOCK_RETURN; - } else if (oplock_level == OPLOCK_EXCLUSIVE) { - if (file.num_entries == 0) { - e.oplock_level = OPLOCK_EXCLUSIVE; - *oplock_granted = EXCLUSIVE_OPLOCK_RETURN; - } else if (allow_level_II_oplock) { - e.oplock_level = OPLOCK_LEVEL_II; - *oplock_granted = LEVEL_II_OPLOCK_RETURN; - } else { - e.oplock_level = OPLOCK_NONE; - *oplock_granted = NO_OPLOCK_RETURN; - } + if (oplock_level == OPLOCK_EXCLUSIVE) { + *oplock_granted = EXCLUSIVE_OPLOCK_RETURN; } else if (oplock_level == OPLOCK_BATCH) { - if (file.num_entries == 0) { - e.oplock_level = OPLOCK_BATCH; - *oplock_granted = BATCH_OPLOCK_RETURN; - } else if (allow_level_II_oplock) { - e.oplock_level = OPLOCK_LEVEL_II; - *oplock_granted = LEVEL_II_OPLOCK_RETURN; - } else { - e.oplock_level = OPLOCK_NONE; - *oplock_granted = NO_OPLOCK_RETURN; - } + *oplock_granted = BATCH_OPLOCK_RETURN; } else if (oplock_level == OPLOCK_LEVEL_II) { - e.oplock_level = OPLOCK_LEVEL_II; *oplock_granted = LEVEL_II_OPLOCK_RETURN; } else { - e.oplock_level = OPLOCK_NONE; *oplock_granted = NO_OPLOCK_RETURN; } } + lck->can_open.e->file_handle = file_handle; + 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 */ file.entries = talloc_realloc(lck, file.entries, struct opendb_entry, file.num_entries+1); NT_STATUS_HAVE_NO_MEMORY(file.entries); - file.entries[file.num_entries] = e; + file.entries[file.num_entries] = *lck->can_open.e; file.num_entries++; return odb_push_record(lck, &file); @@ -807,20 +807,32 @@ static NTSTATUS odb_tdb_can_open(struct odb_lock *lck, struct odb_context *odb = lck->odb; NTSTATUS status; struct opendb_file file; - bool attrs_only = false; status = odb_pull_record(lck, &file); if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { - return NT_STATUS_OK; + goto ok; } NT_STATUS_NOT_OK_RETURN(status); status = odb_tdb_open_can_internal(odb, &file, stream_id, share_access, access_mask, delete_on_close, open_disposition, - break_to_none, &attrs_only); + break_to_none, &lck->can_open.attrs_only); NT_STATUS_NOT_OK_RETURN(status); +ok: + lck->can_open.e = talloc(lck, struct opendb_entry); + NT_STATUS_HAVE_NO_MEMORY(lck->can_open.e); + + lck->can_open.e->server = odb->ntvfs_ctx->server_id; + lck->can_open.e->file_handle = NULL; + lck->can_open.e->stream_id = stream_id; + lck->can_open.e->share_access = share_access; + lck->can_open.e->access_mask = access_mask; + lck->can_open.e->delete_on_close = delete_on_close; + lck->can_open.e->allow_level_II_oplock = false; + lck->can_open.e->oplock_level = OPLOCK_NONE; + return NT_STATUS_OK; } -- cgit From db669e1eb13effb08b1111405587c8c6dde95954 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 7 Mar 2008 18:28:48 +0100 Subject: pvfs_open: fix the odb_open_file() callers metze (This used to be commit 5fdca988c687f58fe2fddd3c8eff5f461207065b) --- source4/ntvfs/posix/pvfs_open.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'source4/ntvfs') diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 1ed517c719..2e757e1742 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -299,10 +299,8 @@ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs, } /* now really mark the file as open */ - status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, - share_access, access_mask, del_on_close, - io->generic.in.open_disposition, - false, false, OPLOCK_NONE, NULL); + status = odb_open_file(lck, f->handle, name->full_name, + false, OPLOCK_NONE, NULL); if (!NT_STATUS_IS_OK(status)) { talloc_free(lck); @@ -361,10 +359,8 @@ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs, goto cleanup_delete; } - status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, - share_access, access_mask, del_on_close, - io->generic.in.open_disposition, - false, false, OPLOCK_NONE, NULL); + status = odb_open_file(lck, f->handle, name->full_name, + false, OPLOCK_NONE, NULL); if (!NT_STATUS_IS_OK(status)) { goto cleanup_delete; @@ -692,10 +688,8 @@ static NTSTATUS pvfs_create_file(struct pvfs_state *pvfs, return status; } - status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, - share_access, access_mask, del_on_close, - io->generic.in.open_disposition, - false, allow_level_II_oplock, + status = odb_open_file(lck, f->handle, name->full_name, + allow_level_II_oplock, oplock_level, &oplock_granted); talloc_free(lck); if (!NT_STATUS_IS_OK(status)) { @@ -1304,10 +1298,8 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, } /* now really mark the file as open */ - status = odb_open_file(lck, f->handle, name->full_name, name->stream_id, - share_access, access_mask, del_on_close, - io->generic.in.open_disposition, - false, allow_level_II_oplock, + status = odb_open_file(lck, f->handle, name->full_name, + allow_level_II_oplock, oplock_level, &oplock_granted); if (!NT_STATUS_IS_OK(status)) { -- cgit