From 164e0cb23cd2e30d4cd2cb4ca2bad32e885bb754 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 10 Jul 2014 22:23:37 +0200 Subject: [PATCH] smbd: Simplify strict_lock_default with early returns Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher --- source3/locking/locking.c | 58 ++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/source3/locking/locking.c b/source3/locking/locking.c index dd6c15ff91a..1c0659ac043 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -103,6 +103,7 @@ void init_strict_lock_struct(files_struct *fsp, bool strict_lock_default(files_struct *fsp, struct lock_struct *plock) { + struct byte_range_lock *br_lck; int strict_locking = lp_strict_locking(fsp->conn->params); bool ret = False; @@ -115,44 +116,33 @@ bool strict_lock_default(files_struct *fsp, struct lock_struct *plock) } if (strict_locking == Auto) { - if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && (plock->lock_type == READ_LOCK || plock->lock_type == WRITE_LOCK)) { - DEBUG(10,("is_locked: optimisation - exclusive oplock on file %s\n", fsp_str_dbg(fsp))); - ret = True; - } else if ((fsp->oplock_type == LEVEL_II_OPLOCK) && - (plock->lock_type == READ_LOCK)) { - DEBUG(10,("is_locked: optimisation - level II oplock on file %s\n", fsp_str_dbg(fsp))); - ret = True; - } else { - struct byte_range_lock *br_lck; - - br_lck = brl_get_locks_readonly(fsp); - 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); + if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && + (plock->lock_type == READ_LOCK || + plock->lock_type == WRITE_LOCK)) { + DEBUG(10, ("is_locked: optimisation - exclusive oplock " + "on file %s\n", fsp_str_dbg(fsp))); + return true; } - } else { - struct byte_range_lock *br_lck; - - br_lck = brl_get_locks_readonly(fsp); - if (!br_lck) { - return True; + if ((fsp->oplock_type == LEVEL_II_OPLOCK) && + (plock->lock_type == READ_LOCK)) { + DEBUG(10, ("is_locked: optimisation - level II oplock " + "on file %s\n", fsp_str_dbg(fsp))); + return true; } - ret = brl_locktest(br_lck, - plock->context.smblctx, - plock->context.pid, - plock->start, - plock->size, - plock->lock_type, - plock->lock_flav); } + br_lck = brl_get_locks_readonly(fsp); + 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); + DEBUG(10, ("strict_lock_default: flavour = %s brl start=%ju " "len=%ju %s for fnum %ju file %s\n", lock_flav_name(plock->lock_flav), -- 2.11.4.GIT