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

jra at samba.org jra at samba.org
Thu Apr 13 22:21:38 GMT 2006


Author: jra
Date: 2006-04-13 22:21:37 +0000 (Thu, 13 Apr 2006)
New Revision: 15082

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

Log:
Using talloc with destructors is nice and all, but in this
case it's in a performace critical path and it *hurts* us.
Go back to plain malloc/free with an explicit destructor
call.
Jeremy.

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


Changeset:
Modified: trunk/source/locking/brlock.c
===================================================================
--- trunk/source/locking/brlock.c	2006-04-13 15:57:56 UTC (rev 15081)
+++ trunk/source/locking/brlock.c	2006-04-13 22:21:37 UTC (rev 15082)
@@ -1304,10 +1304,8 @@
  Unlock the record.
 ********************************************************************/
 
-static int byte_range_lock_destructor(void *p)
+int byte_range_lock_destructor(struct byte_range_lock *br_lck)
 {
-	struct byte_range_lock *br_lck =
-		talloc_get_type_abort(p, struct byte_range_lock);
 	TDB_DATA key;
 
 	key.dptr = (char *)&br_lck->key;
@@ -1336,6 +1334,7 @@
 
 	tdb_chainunlock(tdb, key);
 	SAFE_FREE(br_lck->lock_data);
+	SAFE_FREE(br_lck);
 	return 0;
 }
 
@@ -1344,12 +1343,11 @@
  Leave the record locked.
 ********************************************************************/
 
-struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
-					files_struct *fsp)
+struct byte_range_lock *brl_get_locks(files_struct *fsp)
 {
 	TDB_DATA key;
 	TDB_DATA data;
-	struct byte_range_lock *br_lck = TALLOC_P(mem_ctx, struct byte_range_lock);
+	struct byte_range_lock *br_lck = SMB_MALLOC_P(struct byte_range_lock);
 
 	if (br_lck == NULL) {
 		return NULL;
@@ -1367,12 +1365,10 @@
 
 	if (tdb_chainlock(tdb, key) != 0) {
 		DEBUG(3, ("Could not lock byte range lock entry\n"));
-		TALLOC_FREE(br_lck);
+		SAFE_FREE(br_lck);
 		return NULL;
 	}
 
-	talloc_set_destructor(br_lck, byte_range_lock_destructor);
-
 	data = tdb_fetch(tdb, key);
 	br_lck->lock_data = (void *)data.dptr;
 	br_lck->num_locks = data.dsize / sizeof(struct lock_struct);

Modified: trunk/source/locking/locking.c
===================================================================
--- trunk/source/locking/locking.c	2006-04-13 15:57:56 UTC (rev 15081)
+++ trunk/source/locking/locking.c	2006-04-13 22:21:37 UTC (rev 15082)
@@ -100,7 +100,7 @@
 			DEBUG(10,("is_locked: optimisation - level II oplock on file %s\n", fsp->fsp_name ));
 			ret = False;
 		} else {
-			struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+			struct byte_range_lock *br_lck = brl_get_locks(fsp);
 			if (!br_lck) {
 				return False;
 			}
@@ -111,10 +111,10 @@
 					count,
 					lock_type,
 					lock_flav);
-			TALLOC_FREE(br_lck);
+			byte_range_lock_destructor(br_lck);
 		}
 	} else {
-		struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+		struct byte_range_lock *br_lck = brl_get_locks(fsp);
 		if (!br_lck) {
 			return False;
 		}
@@ -125,7 +125,7 @@
 				count,
 				lock_type,
 				lock_flav);
-		TALLOC_FREE(br_lck);
+		byte_range_lock_destructor(br_lck);
 	}
 
 	DEBUG(10,("is_locked: flavour = %s brl start=%.0f len=%.0f %s for fnum %d file %s\n",
@@ -158,7 +158,7 @@
 		return NT_STATUS_OK;
 	}
 
-	br_lck = brl_get_locks(NULL, fsp);
+	br_lck = brl_get_locks(fsp);
 	if (!br_lck) {
 		return NT_STATUS_NO_MEMORY;
 	}
@@ -171,7 +171,7 @@
 			plock_type,
 			lock_flav);
 
-	TALLOC_FREE(br_lck);
+	byte_range_lock_destructor(br_lck);
 	return status;
 }
 
@@ -204,7 +204,7 @@
 		lock_flav_name(lock_flav), lock_type_name(lock_type),
 		(double)offset, (double)count, fsp->fnum, fsp->fsp_name ));
 
-	br_lck = brl_get_locks(NULL, fsp);
+	br_lck = brl_get_locks(fsp);
 	if (!br_lck) {
 		return NT_STATUS_NO_MEMORY;
 	}
@@ -218,7 +218,7 @@
 			lock_flav,
 			my_lock_ctx);
 
-	TALLOC_FREE(br_lck);
+	byte_range_lock_destructor(br_lck);
 	return status;
 }
 
@@ -305,7 +305,7 @@
 	DEBUG(10,("do_unlock: unlock start=%.0f len=%.0f requested for fnum %d file %s\n",
 		  (double)offset, (double)count, fsp->fnum, fsp->fsp_name ));
 
-	br_lck = brl_get_locks(NULL, fsp);
+	br_lck = brl_get_locks(fsp);
 	if (!br_lck) {
 		return NT_STATUS_NO_MEMORY;
 	}
@@ -317,7 +317,7 @@
 			count,
 			lock_flav);
    
-	TALLOC_FREE(br_lck);
+	byte_range_lock_destructor(br_lck);
 
 	if (!ok) {
 		DEBUG(10,("do_unlock: returning ERRlock.\n" ));
@@ -343,10 +343,10 @@
 	 * Just release all the brl locks, no need to release individually.
 	 */
 
-	br_lck = brl_get_locks(NULL,fsp);
+	br_lck = brl_get_locks(fsp);
 	if (br_lck) {
 		brl_close_fnum(br_lck, pid);
-		TALLOC_FREE(br_lck);
+		byte_range_lock_destructor(br_lck);
 	}
 
 	if(lp_posix_locking(SNUM(fsp->conn))) {

Modified: trunk/source/smbd/blocking.c
===================================================================
--- trunk/source/smbd/blocking.c	2006-04-13 15:57:56 UTC (rev 15081)
+++ trunk/source/smbd/blocking.c	2006-04-13 22:21:37 UTC (rev 15082)
@@ -121,7 +121,7 @@
 	memcpy(blr->inbuf, inbuf, length);
 	blr->length = length;
 
-	br_lck = brl_get_locks(NULL, blr->fsp);
+	br_lck = brl_get_locks(blr->fsp);
 	if (!br_lck) {
 		free_blocking_lock_record(blr);
 		return False;
@@ -136,7 +136,7 @@
 			PENDING_LOCK,
 			blr->lock_flav,
 			&my_lock_ctx);
-	TALLOC_FREE(br_lck);
+	byte_range_lock_destructor(br_lck);
 
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(0,("push_blocking_lock_request: failed to add PENDING_LOCK record.\n"));
@@ -625,7 +625,7 @@
 	for(blr = blocking_lock_queue; blr; blr = next) {
 		next = blr->next;
 		if(blr->fsp->fnum == fsp->fnum) {
-			struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+			struct byte_range_lock *br_lck = brl_get_locks(fsp);
 
 			if (br_lck) {
 				DEBUG(10,("remove_pending_lock_requests_by_fid - removing request type %d for \
@@ -637,7 +637,7 @@
 					blr->offset,
 					blr->count,
 					blr->lock_flav);
-				TALLOC_FREE(br_lck);
+				byte_range_lock_destructor(br_lck);
 
 			}
 
@@ -658,7 +658,7 @@
 		next = blr->next;
 		if(SVAL(blr->inbuf,smb_mid) == mid) {
 			files_struct *fsp = blr->fsp;
-			struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+			struct byte_range_lock *br_lck = brl_get_locks(fsp);
 
 			if (br_lck) {
 				DEBUG(10,("remove_pending_lock_requests_by_mid - removing request type %d for \
@@ -670,7 +670,7 @@
 					blr->offset,
 					blr->count,
 					blr->lock_flav);
-				TALLOC_FREE(br_lck);
+				byte_range_lock_destructor(br_lck);
 			}
 
 			blocking_lock_reply_error(blr,NT_STATUS_FILE_LOCK_CONFLICT);
@@ -754,7 +754,7 @@
 			fsp->fnum, fsp->fsp_name ));
 
 		if((blr->expire_time != -1) && (blr->expire_time <= t)) {
-			struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+			struct byte_range_lock *br_lck = brl_get_locks(fsp);
 
 			/*
 			 * Lock expired - throw away all previously
@@ -771,7 +771,7 @@
 					blr->offset,
 					blr->count,
 					blr->lock_flav);
-				TALLOC_FREE(br_lck);
+				byte_range_lock_destructor(br_lck);
 			}
 
 			blocking_lock_reply_error(blr,NT_STATUS_FILE_LOCK_CONFLICT);
@@ -780,7 +780,7 @@
 		}
 
 		if(!change_to_user(conn,vuid)) {
-			struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+			struct byte_range_lock *br_lck = brl_get_locks(fsp);
 
 			/*
 			 * Remove the entry and return an error to the client.
@@ -793,7 +793,7 @@
 					blr->offset,
 					blr->count,
 					blr->lock_flav);
-				TALLOC_FREE(br_lck);
+				byte_range_lock_destructor(br_lck);
 			}
 
 			DEBUG(0,("process_blocking_lock_queue: Unable to become user vuid=%d.\n",
@@ -804,7 +804,7 @@
 		}
 
 		if(!set_current_service(conn,SVAL(blr->inbuf,smb_flg),True)) {
-			struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+			struct byte_range_lock *br_lck = brl_get_locks(fsp);
 
 			/*
 			 * Remove the entry and return an error to the client.
@@ -817,7 +817,7 @@
 					blr->offset,
 					blr->count,
 					blr->lock_flav);
-				TALLOC_FREE(br_lck);
+				byte_range_lock_destructor(br_lck);
 			}
 
 			DEBUG(0,("process_blocking_lock_queue: Unable to become service Error was %s.\n", strerror(errno) ));
@@ -834,7 +834,7 @@
 		 */
 
 		if(blocking_lock_record_process(blr)) {
-			struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+			struct byte_range_lock *br_lck = brl_get_locks(fsp);
 
 			if (br_lck) {
 				brl_remove_pending_lock(br_lck,
@@ -843,7 +843,7 @@
 					blr->offset,
 					blr->count,
 					blr->lock_flav);
-				TALLOC_FREE(br_lck);
+				byte_range_lock_destructor(br_lck);
 			}
 
 			free_blocking_lock_record(blr);



More information about the samba-cvs mailing list