svn commit: samba r13805 - in trunk/source: locking smbd

jra at samba.org jra at samba.org
Fri Mar 3 03:57:35 GMT 2006


Author: jra
Date: 2006-03-03 03:57:34 +0000 (Fri, 03 Mar 2006)
New Revision: 13805

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=13805

Log:
Simply logic in Windows unlock function. Still pass
lock tests...
Jeremy.

Modified:
   trunk/source/locking/brlock.c
   trunk/source/smbd/blocking.c


Changeset:
Modified: trunk/source/locking/brlock.c
===================================================================
--- trunk/source/locking/brlock.c	2006-03-03 03:00:52 UTC (rev 13804)
+++ trunk/source/locking/brlock.c	2006-03-03 03:57:34 UTC (rev 13805)
@@ -702,11 +702,12 @@
 		void *pre_unlock_data)
 {
 	unsigned int i, j;
+	struct lock_struct *lock;
 	struct lock_struct *locks = (struct lock_struct *)br_lck->lock_data;
 
 #if ZERO_ZERO
 	for (i = 0; i < br_lck->num_locks; i++) {
-		struct lock_struct *lock = &locks[i];
+		lock = &locks[i];
 
 		if (lock->lock_type == WRITE_LOCK &&
 		    brl_same_context(&lock->context, &plock->context) &&
@@ -732,61 +733,68 @@
 #endif
 
 	for (i = 0; i < br_lck->num_locks; i++) {
-		struct lock_struct *lock = &locks[i];
+		lock = &locks[i];
 
-		if (brl_same_context(&lock->context, &plock->context) &&
-				lock->fnum == plock->fnum &&
-				lock->start == plock->start &&
-				lock->size == plock->size) {
+		/* Only remove our own locks that match in start, size, and flavour. */
+		if (!brl_same_context(&lock->context, &plock->context) ||
+					lock->fnum != plock->fnum ||
+					lock->lock_flav != WINDOWS_LOCK ||
+					lock->start != plock->start ||
+					lock->size != plock->size ) {
+			continue;
+		}
 
-			if (remove_pending_locks_only && lock->lock_type != PENDING_LOCK) {
-				continue;
-			}
+		if (remove_pending_locks_only && lock->lock_type == PENDING_LOCK) {
+			/* Found this particular pending lock - delete it */
+			break;
+		}
 
-			if (lock->lock_type != PENDING_LOCK) {
+		if (lock->lock_type != PENDING_LOCK) {
+			/* Found it. */
+			break;
+		}
+	}
 
-				/* Do any POSIX unlocks needed. */
-				if (pre_unlock_fn) {
-					(*pre_unlock_fn)(pre_unlock_data);
-				}
+	if (i == br_lck->num_locks) {
+		/* we didn't find it */
+		return False;
+	}
 
-				/* 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];
+	/* Do any POSIX unlocks needed. */
+	if (pre_unlock_fn) {
+		(*pre_unlock_fn)(pre_unlock_data);
+	}
 
-					/* Ignore non-pending locks. */
-					if (pend_lock->lock_type != PENDING_LOCK) {
-						continue;
-					}
+	/* 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];
 
-					/* We could send specific lock info here... */
-					if (brl_pending_overlap(lock, pend_lock)) {
-						DEBUG(10,("brl_unlock: sending unlock message to pid %s\n",
-							procid_str_static(&pend_lock->context.pid )));
+		/* Ignore non-pending locks. */
+		if (pend_lock->lock_type != PENDING_LOCK) {
+			continue;
+		}
 
-						become_root();
-						message_send_pid(pend_lock->context.pid,
-								MSG_SMB_UNLOCK,
-								NULL, 0, True);
-						unbecome_root();
-					}
-				}
-			}
+		/* We could send specific lock info here... */
+		if (brl_pending_overlap(lock, pend_lock)) {
+			DEBUG(10,("brl_unlock: sending unlock message to pid %s\n",
+				procid_str_static(&pend_lock->context.pid )));
 
-			/* found it - delete it */
-			if (i < br_lck->num_locks - 1) {
-				memmove(&locks[i], &locks[i+1], 
-					sizeof(*locks)*((br_lck->num_locks-1) - i));
-			}
-
-			br_lck->num_locks -= 1;
-			br_lck->modified = True;
-			return True;
+			become_root();
+			message_send_pid(pend_lock->context.pid,
+					MSG_SMB_UNLOCK,
+					NULL, 0, True);
+			unbecome_root();
 		}
 	}
 
-	/* we didn't find it */
-	return False;
+	if (i < br_lck->num_locks - 1) {
+		memmove(&locks[i], &locks[i+1], 
+			sizeof(*locks)*((br_lck->num_locks-1) - i));
+	}
+
+	br_lck->num_locks -= 1;
+	br_lck->modified = True;
+	return True;
 }
 
 /****************************************************************************
@@ -799,8 +807,7 @@
 		void (*pre_unlock_fn)(void *),
 		void *pre_unlock_data)
 {
-	/* Placeholder for now. */
-	return True;
+	return False;
 }
 
 /****************************************************************************

Modified: trunk/source/smbd/blocking.c
===================================================================
--- trunk/source/smbd/blocking.c	2006-03-03 03:00:52 UTC (rev 13804)
+++ trunk/source/smbd/blocking.c	2006-03-03 03:57:34 UTC (rev 13805)
@@ -35,6 +35,7 @@
 	SMB_BIG_UINT offset;
 	SMB_BIG_UINT count;
 	uint16 lock_pid;
+	enum brl_flavour lock_flav;
 	char *inbuf;
 	int length;
 } blocking_lock_record;
@@ -122,6 +123,7 @@
 	blr->expire_time = (lock_timeout == -1) ? (time_t)-1 : time(NULL) + (time_t)lock_timeout;
 	blr->lock_num = lock_num;
 	blr->lock_pid = lock_pid;
+	blr->lock_flav = WINDOWS_LOCK;
 	blr->offset = offset;
 	blr->count = count;
 	memcpy(blr->inbuf, inbuf, length);
@@ -140,7 +142,7 @@
 			offset,
 			count,
 			PENDING_LOCK,
-			WINDOWS_LOCK,
+			blr->lock_flav,
 			&my_lock_ctx);
 	TALLOC_FREE(br_lck);
 
@@ -568,7 +570,7 @@
 					procid_self(),
 					blr->offset,
 					blr->count,
-					WINDOWS_LOCK,
+					blr->lock_flav,
 					True,
 					NULL,
 					NULL);
@@ -604,7 +606,7 @@
 					procid_self(),
 					blr->offset,
 					blr->count,
-					WINDOWS_LOCK,
+					blr->lock_flav,
 					True,
 					NULL,
 					NULL);
@@ -709,7 +711,7 @@
 					procid_self(),
 					blr->offset,
 					blr->count,
-					WINDOWS_LOCK,
+					blr->lock_flav,
 					True,
 					NULL,
 					NULL);
@@ -763,7 +765,7 @@
 					procid_self(),
 					blr->offset,
 					blr->count,
-					WINDOWS_LOCK,
+					blr->lock_flav,
 					True,
 					NULL,
 					NULL);
@@ -793,7 +795,7 @@
 					procid_self(),
 					blr->offset,
 					blr->count,
-					WINDOWS_LOCK,
+					blr->lock_flav,
 					True,
 					NULL,
 					NULL);



More information about the samba-cvs mailing list