Author: jra Date: 2006-03-30 18:55:46 +0000 (Thu, 30 Mar 2006) New Revision: 14827
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14827 Log: Fix lock tests 4 and 5 when underlying POSIX locks are enabled. Fix crash bug in error case on blocking lock processing. Jeremy. Modified: trunk/source/locking/brlock.c trunk/source/smbd/blocking.c trunk/source/smbd/trans2.c Changeset: Modified: trunk/source/locking/brlock.c =================================================================== --- trunk/source/locking/brlock.c 2006-03-30 15:47:41 UTC (rev 14826) +++ trunk/source/locking/brlock.c 2006-03-30 18:55:46 UTC (rev 14827) @@ -371,7 +371,7 @@ lock type so it can cope with the difference between Windows "stacking" locks and POSIX "flat" ones. */ - if (lp_posix_locking(SNUM(fsp->conn))) { + if ((plock->lock_type != PENDING_LOCK) && lp_posix_locking(SNUM(fsp->conn))) { if (!set_posix_lock(fsp, plock->start, plock->size, plock->lock_type, WINDOWS_LOCK)) { if (errno == EACCES || errno == EAGAIN) { return NT_STATUS_FILE_LOCK_CONFLICT; @@ -660,7 +660,7 @@ lock type so it can cope with the difference between Windows "stacking" locks and POSIX "flat" ones. */ - if (lp_posix_locking(SNUM(fsp->conn))) { + if ((plock->lock_type != PENDING_LOCK) && lp_posix_locking(SNUM(fsp->conn))) { if (!set_posix_lock(fsp, plock->start, plock->size, plock->lock_type, POSIX_LOCK)) { if (errno == EACCES || errno == EAGAIN) { SAFE_FREE(tp); @@ -800,6 +800,11 @@ return False; } + /* Unlock any POSIX regions. */ + if(lp_posix_locking(br_lck->fsp->conn->cnum)) { + release_posix_lock(br_lck->fsp, plock->start, plock->size); + } + /* Send unlock messages to any pending waiters that overlap. */ for (j=0; j < br_lck->num_locks; j++) { struct lock_struct *pend_lock = &locks[j]; @@ -876,8 +881,8 @@ lock = &locks[i]; /* Only remove our own locks - ignore fnum. */ - if (!brl_same_context(&lock->context, &plock->context) || - lock->lock_type == PENDING_LOCK) { + if (lock->lock_type == PENDING_LOCK || + !brl_same_context(&lock->context, &plock->context)) { memcpy(&tp[count], lock, sizeof(struct lock_struct)); count++; continue; @@ -945,6 +950,11 @@ return True; } + /* Unlock any POSIX regions. */ + if(lp_posix_locking(br_lck->fsp->conn->cnum)) { + release_posix_lock(br_lck->fsp, plock->start, plock->size); + } + /* Realloc so we don't leak entries per unlock call. */ if (count) { tp = (struct lock_struct *)SMB_REALLOC(tp, count * sizeof(*locks)); Modified: trunk/source/smbd/blocking.c =================================================================== --- trunk/source/smbd/blocking.c 2006-03-30 15:47:41 UTC (rev 14826) +++ trunk/source/smbd/blocking.c 2006-03-30 18:55:46 UTC (rev 14827) @@ -100,6 +100,9 @@ return False; } + blr->next = NULL; + blr->prev = NULL; + if((blr->inbuf = (char *)SMB_MALLOC(length)) == NULL) { DEBUG(0,("push_blocking_lock_request: Malloc fail (2)!\n" )); SAFE_FREE(blr); @@ -281,19 +284,29 @@ static void blocking_lock_reply_error(blocking_lock_record *blr, NTSTATUS status) { switch(blr->com_type) { +#if 0 + /* We no longer push blocking lock requests for anything but lockingX and trans2. */ case SMBlock: case SMBlockread: generic_blocking_lock_error(blr, status); break; +#endif case SMBlockingX: reply_lockingX_error(blr, status); break; + case SMBtrans2: + case SMBtranss2: + generic_blocking_lock_error(blr, status); + break; default: DEBUG(0,("blocking_lock_reply_error: PANIC - unknown type on blocking lock queue - exiting.!\n")); exit_server("PANIC - unknown type on blocking lock queue"); } } +#if 0 +/* We no longer push blocking lock requests for anything but lockingX and trans2. */ + /**************************************************************************** Attempt to finish off getting all pending blocking locks for a lockread call. Returns True if we want to be removed from the list. @@ -431,6 +444,7 @@ send_blocking_reply(outbuf,outsize); return True; } +#endif /**************************************************************************** Attempt to finish off getting all pending blocking locks for a lockingX call. @@ -524,12 +538,16 @@ static BOOL blocking_lock_record_process(blocking_lock_record *blr) { switch(blr->com_type) { +#if 0 + /* We no longer push blocking lock requests for anything but lockingX and trans2. */ case SMBlock: return process_lock(blr); case SMBlockread: return process_lockread(blr); +#endif case SMBlockingX: return process_lockingX(blr); + /* TODO - need to add POSIX SMBtrans and SMBtranss switch here. */ default: DEBUG(0,("blocking_lock_record_process: PANIC - unknown type on blocking lock queue - exiting.!\n")); exit_server("PANIC - unknown type on blocking lock queue"); Modified: trunk/source/smbd/trans2.c =================================================================== --- trunk/source/smbd/trans2.c 2006-03-30 15:47:41 UTC (rev 14826) +++ trunk/source/smbd/trans2.c 2006-03-30 18:55:46 UTC (rev 14827) @@ -4521,6 +4521,24 @@ &my_lock_ctx); /* TODO: Deal with rescheduling blocking lock fail here... */ + if (lp_blocking_locks(SNUM(conn)) && ERROR_WAS_LOCK_DENIED(status)) { + /* + * A blocking lock was requested. Package up + * this smb into a queued request and push it + * onto the blocking lock queue. + */ + if(push_blocking_lock_request(inbuf, length, + fsp, + -1, /* infinite timeout. */ + 0, + lock_pid, + lock_type, + POSIX_LOCK, + offset, + count)) { + return -1; + } + } } if (!NT_STATUS_IS_OK(status)) {