smbd: Simplify brl_locktest
authorVolker Lendecke <vl@samba.org>
Fri, 11 Jul 2014 13:35:45 +0000 (11 15:35 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 22 Jul 2014 13:32:39 +0000 (22 15:32 +0200)
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 <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/locking/brlock.c
source3/locking/locking.c
source3/locking/proto.h

index fe61305..84849e6 100644 (file)
@@ -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 "
index 1c0659a..0a99449 100644 (file)
@@ -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",
index 3db9e7a..722779f 100644 (file)
@@ -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,