1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

smbd: Remove the ZERO_ZERO define

This code went in with e8e98c9ea06 in 2001 without any mention in the
commit message.

I don't remember all details, but there was some discussion around the
offset=0,length=0 lock being somehow special. These days [MS-FSA]
defines the required behaviour (don't conflict) and we implement that
behaviour.

If someone still remembers why this code is in and thinks it's
worthwhile, that's what version control is for.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Volker Lendecke 2024-05-15 17:26:27 +02:00 committed by Andrew Bartlett
parent 3542f938c5
commit 979f3e2399

View File

@ -38,8 +38,6 @@
#undef DBGC_CLASS #undef DBGC_CLASS
#define DBGC_CLASS DBGC_LOCKING #define DBGC_CLASS DBGC_LOCKING
#define ZERO_ZERO 0
/* The open brlock.tdb database. */ /* The open brlock.tdb database. */
static struct db_context *brlock_db; static struct db_context *brlock_db;
@ -268,32 +266,6 @@ static bool brl_conflict_posix(const struct lock_struct *lck1,
return brl_overlap(lck1, lck2); return brl_overlap(lck1, lck2);
} }
#if ZERO_ZERO
static bool brl_conflict1(const struct lock_struct *lck1,
const struct lock_struct *lck2)
{
if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) {
return False;
}
if (brl_same_context(&lck1->context, &lck2->context) &&
lck2->lock_type == READ_LOCK && lck1->fnum == lck2->fnum) {
return False;
}
if (lck2->start == 0 && lck2->size == 0 && lck1->size != 0) {
return True;
}
if (lck1->start >= (lck2->start + lck2->size) ||
lck2->start >= (lck1->start + lck1->size)) {
return False;
}
return True;
}
#endif
/**************************************************************************** /****************************************************************************
Check to see if this lock conflicts, but ignore our own locks on the Check to see if this lock conflicts, but ignore our own locks on the
same fnum only. This is the read/write lock check code path. same fnum only. This is the read/write lock check code path.
@ -399,21 +371,6 @@ void brl_shutdown(void)
TALLOC_FREE(brlock_db); TALLOC_FREE(brlock_db);
} }
#if ZERO_ZERO
/****************************************************************************
Compare two locks for sorting.
****************************************************************************/
static int lock_compare(const struct lock_struct *lck1,
const struct lock_struct *lck2)
{
if (lck1->start != lck2->start) {
return NUMERIC_CMP(lck1->start, lck2->start);
}
return NUMERIC_CMP(lck1->size, lck2->size);
}
#endif
/**************************************************************************** /****************************************************************************
Lock a range of bytes - Windows lock semantics. Lock a range of bytes - Windows lock semantics.
****************************************************************************/ ****************************************************************************/
@ -446,12 +403,6 @@ NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
plock->context.smblctx = locks[i].context.smblctx; plock->context.smblctx = locks[i].context.smblctx;
return NT_STATUS_LOCK_NOT_GRANTED; return NT_STATUS_LOCK_NOT_GRANTED;
} }
#if ZERO_ZERO
if (plock->start == 0 && plock->size == 0 &&
locks[i].size == 0) {
break;
}
#endif
} }
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_WINDOWS_BRL); contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_WINDOWS_BRL);
@ -983,12 +934,6 @@ NTSTATUS brl_lock(
ZERO_STRUCT(lock); ZERO_STRUCT(lock);
#if !ZERO_ZERO
if (start == 0 && size == 0) {
DEBUG(0,("client sent 0/0 lock - please report this\n"));
}
#endif
lock = (struct lock_struct) { lock = (struct lock_struct) {
.context.smblctx = smblctx, .context.smblctx = smblctx,
.context.pid = pid, .context.pid = pid,
@ -1007,10 +952,6 @@ NTSTATUS brl_lock(
ret = brl_lock_posix(br_lck, &lock); ret = brl_lock_posix(br_lck, &lock);
} }
#if ZERO_ZERO
/* sort the lock list */
TYPESAFE_QSORT(br_lck->lock_data, (size_t)br_lck->num_locks, lock_compare);
#endif
/* If we're returning an error, return who blocked us. */ /* If we're returning an error, return who blocked us. */
if (!NT_STATUS_IS_OK(ret) && psmblctx) { if (!NT_STATUS_IS_OK(ret) && psmblctx) {
*blocker_pid = lock.context.pid; *blocker_pid = lock.context.pid;
@ -1032,31 +973,6 @@ bool brl_unlock_windows_default(struct byte_range_lock *br_lck,
SMB_ASSERT(plock->lock_type == UNLOCK_LOCK); SMB_ASSERT(plock->lock_type == UNLOCK_LOCK);
#if ZERO_ZERO
/* Delete write locks by preference... The lock list
is sorted in the zero zero case. */
for (i = 0; i < br_lck->num_locks; i++) {
struct lock_struct *lock = &locks[i];
if (lock->lock_type == WRITE_LOCK &&
brl_same_context(&lock->context, &plock->context) &&
lock->fnum == plock->fnum &&
lock->lock_flav == WINDOWS_LOCK &&
lock->start == plock->start &&
lock->size == plock->size) {
/* found it - delete it */
deleted_lock_type = lock->lock_type;
break;
}
}
if (i != br_lck->num_locks) {
/* We found it - don't search again. */
goto unlock_continue;
}
#endif
for (i = 0; i < br_lck->num_locks; i++) { for (i = 0; i < br_lck->num_locks; i++) {
struct lock_struct *lock = &locks[i]; struct lock_struct *lock = &locks[i];
@ -1077,10 +993,6 @@ bool brl_unlock_windows_default(struct byte_range_lock *br_lck,
return False; return False;
} }
#if ZERO_ZERO
unlock_continue:
#endif
ARRAY_DEL_ELEMENT(locks, i, br_lck->num_locks); ARRAY_DEL_ELEMENT(locks, i, br_lck->num_locks);
br_lck->num_locks -= 1; br_lck->num_locks -= 1;
br_lck->modified = True; br_lck->modified = True;