summaryrefslogtreecommitdiffstats
path: root/source3/locking/brlock.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-07-11 13:27:39 +0200
committerStefan Metzmacher <metze@samba.org>2014-07-22 15:32:39 +0200
commit50b74ccb6ae37f193f1f109a04a9a15ed48dfae5 (patch)
treea0cb699f0187b08f8e04ddec2109b4d79bbae0c0 /source3/locking/brlock.c
parenta48c0a42ce44bffc6132ce19555aa8f168c8957a (diff)
downloadsamba-50b74ccb6ae37f193f1f109a04a9a15ed48dfae5.tar.gz
samba-50b74ccb6ae37f193f1f109a04a9a15ed48dfae5.tar.xz
samba-50b74ccb6ae37f193f1f109a04a9a15ed48dfae5.zip
smbd: Restructure brl_conflict_other
It took me really long to grasp what's going on in this routine. I hope its logic is easier to understand now Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'source3/locking/brlock.c')
-rw-r--r--source3/locking/brlock.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index e881b8fd78..fe61305612 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -239,28 +239,53 @@ static bool brl_conflict_other(const struct lock_struct *lock,
return False;
}
- /* POSIX flavour locks never conflict here - this is only called
- in the read/write path. */
-
if (lock->lock_flav == POSIX_LOCK &&
rw_probe->lock_flav == POSIX_LOCK) {
+ /*
+ * POSIX flavour locks never conflict here - this is only called
+ * in the read/write path.
+ */
return False;
}
- /*
- * Incoming WRITE locks conflict with existing READ locks even
- * if the context is the same. JRA. See LOCKTEST7 in smbtorture.
- */
+ if (!brl_overlap(lock, rw_probe)) {
+ /*
+ * I/O can only conflict when overlapping a lock, thus let it
+ * pass
+ */
+ return false;
+ }
- if (!(rw_probe->lock_type == WRITE_LOCK &&
- lock->lock_type == READ_LOCK)) {
- if (brl_same_context(&lock->context, &rw_probe->context) &&
- lock->fnum == rw_probe->fnum) {
- return False;
- }
+ if (!brl_same_context(&lock->context, &rw_probe->context)) {
+ /*
+ * Different process, conflict
+ */
+ return true;
}
- return brl_overlap(lock, rw_probe);
+ if (lock->fnum != rw_probe->fnum) {
+ /*
+ * Different file handle, conflict
+ */
+ return true;
+ }
+
+ if ((lock->lock_type == READ_LOCK) &&
+ (rw_probe->lock_type == WRITE_LOCK)) {
+ /*
+ * Incoming WRITE locks conflict with existing READ locks even
+ * if the context is the same. JRA. See LOCKTEST7 in
+ * smbtorture.
+ */
+ return true;
+ }
+
+ /*
+ * I/O request compatible with existing lock, let it pass without
+ * conflict
+ */
+
+ return false;
}
/****************************************************************************