From 188017ea324e7c6b7aba7f51a9baa490c0690a01 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 11 Jul 2014 15:35:45 +0200 Subject: [PATCH] smbd: Simplify brl_locktest Pass "struct lock_struct" as a parameter. This had to be destructured before the call and re-constructed inside brl_locktest. Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher --- source3/locking/brlock.c | 32 +++++++++++++------------------- source3/locking/locking.c | 8 +------- source3/locking/proto.h | 9 ++------- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c index fe613056121..84849e6452a 100644 --- a/source3/locking/brlock.c +++ b/source3/locking/brlock.c @@ -1345,35 +1345,20 @@ bool brl_unlock(struct messaging_context *msg_ctx, Returns True if the region required is currently unlocked, False if locked. ****************************************************************************/ -bool brl_locktest(struct byte_range_lock *br_lck, - uint64_t smblctx, - struct server_id pid, - br_off start, - br_off size, - enum brl_type lock_type, - enum brl_flavour lock_flav) +bool brl_locktest(const struct byte_range_lock *br_lck, + const struct lock_struct *rw_probe) { bool ret = True; unsigned int i; - struct lock_struct lock; const struct lock_struct *locks = br_lck->lock_data; files_struct *fsp = br_lck->fsp; - lock.context.smblctx = smblctx; - lock.context.pid = pid; - lock.context.tid = br_lck->fsp->conn->cnum; - lock.start = start; - lock.size = size; - lock.fnum = fsp->fnum; - lock.lock_type = lock_type; - lock.lock_flav = lock_flav; - /* Make sure existing locks don't conflict */ for (i=0; i < br_lck->num_locks; i++) { /* * Our own locks don't conflict. */ - if (brl_conflict_other(&locks[i], &lock)) { + if (brl_conflict_other(&locks[i], rw_probe)) { return False; } } @@ -1384,7 +1369,16 @@ bool brl_locktest(struct byte_range_lock *br_lck, * This only conflicts with Windows locks, not POSIX locks. */ - if(lp_posix_locking(fsp->conn->params) && (lock_flav == WINDOWS_LOCK)) { + if(lp_posix_locking(fsp->conn->params) && + (rw_probe->lock_flav == WINDOWS_LOCK)) { + /* + * Make copies -- is_posix_locked might modify the values + */ + + br_off start = rw_probe->start; + br_off size = rw_probe->size; + enum brl_type lock_type = rw_probe->lock_type; + ret = is_posix_locked(fsp, &start, &size, &lock_type, WINDOWS_LOCK); DEBUG(10, ("brl_locktest: posix start=%ju len=%ju %s for %s " diff --git a/source3/locking/locking.c b/source3/locking/locking.c index 1c0659ac043..0a994496d11 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -135,13 +135,7 @@ bool strict_lock_default(files_struct *fsp, struct lock_struct *plock) if (!br_lck) { return true; } - ret = brl_locktest(br_lck, - plock->context.smblctx, - plock->context.pid, - plock->start, - plock->size, - plock->lock_type, - plock->lock_flav); + ret = brl_locktest(br_lck, plock); DEBUG(10, ("strict_lock_default: flavour = %s brl start=%ju " "len=%ju %s for fnum %ju file %s\n", diff --git a/source3/locking/proto.h b/source3/locking/proto.h index 3db9e7aa584..722779f3ce1 100644 --- a/source3/locking/proto.h +++ b/source3/locking/proto.h @@ -58,13 +58,8 @@ bool brl_unlock(struct messaging_context *msg_ctx, bool brl_unlock_windows_default(struct messaging_context *msg_ctx, struct byte_range_lock *br_lck, const struct lock_struct *plock); -bool brl_locktest(struct byte_range_lock *br_lck, - uint64_t smblctx, - struct server_id pid, - br_off start, - br_off size, - enum brl_type lock_type, - enum brl_flavour lock_flav); +bool brl_locktest(const struct byte_range_lock *br_lck, + const struct lock_struct *rw_probe); NTSTATUS brl_lockquery(struct byte_range_lock *br_lck, uint64_t *psmblctx, struct server_id pid, -- 2.11.4.GIT