[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Wed Sep 11 10:16:02 CEST 2013


The branch, master has been updated
       via  73278cd smbd: Convert br_lck->lock_data to talloc
       via  20cc710 smbd: Move "struct byte_range_lock" definition to brlock.c
       via  07948ef smbd: Add brl_fsp access function
       via  6bcfc1a smbd: Add brl_num_locks access function
       via  635c35d smbd: Use ZERO_STRUCT instead of memset
       via  e2bb3b0 smbd: Fix a typo
       via  2aa6844 smbd: Make brl_lock_failed static
       via  cca8faa smbd: Make brl_same_context static
       via  e533bf3 smbd: Fix blank line endings
      from  d809cf6 Raise the level of a debug.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 73278cd19bc80854a2b23ef787c3ebdc3fa56bfd
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 21:04:47 2013 +0200

    smbd: Convert br_lck->lock_data to talloc
    
    Autobuild-User(master): Volker Lendecke <vl at samba.org>
    Autobuild-Date(master): Wed Sep 11 10:15:38 CEST 2013 on sn-devel-104

commit 20cc710920d286f99f71bf0cf4ca95a7d17935dc
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 19:42:06 2013 +0200

    smbd: Move "struct byte_range_lock" definition to brlock.c

commit 07948ef6e12ac52ecbb23089495d3760028f019e
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 19:41:32 2013 +0200

    smbd: Add brl_fsp access function

commit 6bcfc1a9daad1432c45db816d32ac5076f748e81
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 19:40:43 2013 +0200

    smbd: Add brl_num_locks access function

commit 635c35dc8d0d7e9ee7f0a850552564896b7342d9
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 12:04:42 2013 +0000

    smbd: Use ZERO_STRUCT instead of memset

commit e2bb3b0c4a64ebfd7cd5143f50518fc534d020a2
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 12:01:58 2013 +0000

    smbd: Fix a typo

commit 2aa684453aea4739383257f53a0f13ea27759df2
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 11:41:39 2013 +0000

    smbd: Make brl_lock_failed static

commit cca8faa62194308001c029054578604d0a759967
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 11:39:52 2013 +0000

    smbd: Make brl_same_context static

commit e533bf3ef168424234a10331fa4edf98dacb3a4b
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 11:35:01 2013 +0000

    smbd: Fix blank line endings

-----------------------------------------------------------------------

Summary of changes:
 source3/include/locking.h                 |   22 ++----
 source3/locking/brlock.c                  |  119 +++++++++++++++++-----------
 source3/locking/locking.c                 |    2 +-
 source3/locking/proto.h                   |    6 +-
 source3/modules/vfs_full_audit.c          |    9 ++-
 source3/modules/vfs_time_audit.c          |    6 +-
 source3/rpc_server/srvsvc/srv_srvsvc_nt.c |    2 +-
 source3/smbd/blocking.c                   |   12 ++--
 source3/smbd/open.c                       |    2 +-
 9 files changed, 100 insertions(+), 80 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/locking.h b/source3/include/locking.h
index 32593af..97c138a 100644
--- a/source3/include/locking.h
+++ b/source3/include/locking.h
@@ -1,19 +1,19 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    SMB parameters and setup, plus a whole lot more.
-   
+
    Copyright (C) Jeremy Allison   2006
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -47,17 +47,9 @@ struct files_struct;
 
 #include "lib/file_id.h"
 
-struct byte_range_lock {
-	struct files_struct *fsp;
-	unsigned int num_locks;
-	bool modified;
-	bool read_only;
-	struct file_id key;
-	struct lock_struct *lock_data;
-	struct db_record *record;
-};
+struct byte_range_lock;
 
-/* Internal structure in brlock.tdb. 
+/* Internal structure in brlock.tdb.
    The data in brlock records is an unsorted linear array of these
    records.  It is unnecessary to store the count as tdb provides the
    size of the record */
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 865aaca..ac54767 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -1,4 +1,4 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    byte range locking code
    Updated to handle range splits/merges.
@@ -43,6 +43,16 @@
 
 static struct db_context *brlock_db;
 
+struct byte_range_lock {
+	struct files_struct *fsp;
+	unsigned int num_locks;
+	bool modified;
+	bool read_only;
+	struct file_id key;
+	struct lock_struct *lock_data;
+	struct db_record *record;
+};
+
 /****************************************************************************
  Debug info at level 10 for lock struct.
 ****************************************************************************/
@@ -63,11 +73,21 @@ static void print_lock_struct(unsigned int i, const struct lock_struct *pls)
 		lock_flav_name(pls->lock_flav) ));
 }
 
+unsigned int brl_num_locks(const struct byte_range_lock *brl)
+{
+	return brl->num_locks;
+}
+
+struct files_struct *brl_fsp(struct byte_range_lock *brl)
+{
+	return brl->fsp;
+}
+
 /****************************************************************************
  See if two locking contexts are equal.
 ****************************************************************************/
 
-bool brl_same_context(const struct lock_context *ctx1, 
+static bool brl_same_context(const struct lock_context *ctx1,
 			     const struct lock_context *ctx2)
 {
 	return (serverid_equal(&ctx1->pid, &ctx2->pid) &&
@@ -102,7 +122,7 @@ static bool brl_overlap(const struct lock_struct *lck1,
  See if lock2 can be added when lock1 is in place.
 ****************************************************************************/
 
-static bool brl_conflict(const struct lock_struct *lck1, 
+static bool brl_conflict(const struct lock_struct *lck1,
 			 const struct lock_struct *lck2)
 {
 	/* Ignore PENDING locks. */
@@ -123,7 +143,7 @@ static bool brl_conflict(const struct lock_struct *lck1,
 	}
 
 	return brl_overlap(lck1, lck2);
-} 
+}
 
 /****************************************************************************
  See if lock2 can be added when lock1 is in place - when both locks are POSIX
@@ -131,7 +151,7 @@ static bool brl_conflict(const struct lock_struct *lck1,
  know already match.
 ****************************************************************************/
 
-static bool brl_conflict_posix(const struct lock_struct *lck1, 
+static bool brl_conflict_posix(const struct lock_struct *lck1,
 			 	const struct lock_struct *lck2)
 {
 #if defined(DEVELOPER)
@@ -156,10 +176,10 @@ static bool brl_conflict_posix(const struct lock_struct *lck1,
 	/* One is read, the other write, or the context is different,
 	   do they overlap ? */
 	return brl_overlap(lck1, lck2);
-} 
+}
 
 #if ZERO_ZERO
-static bool brl_conflict1(const struct lock_struct *lck1, 
+static bool brl_conflict1(const struct lock_struct *lck1,
 			 const struct lock_struct *lck2)
 {
 	if (IS_PENDING_LOCK(lck1->lock_type) || IS_PENDING_LOCK(lck2->lock_type))
@@ -184,7 +204,7 @@ static bool brl_conflict1(const struct lock_struct *lck1,
 	}
 
 	return True;
-} 
+}
 #endif
 
 /****************************************************************************
@@ -198,7 +218,7 @@ static bool brl_conflict_other(const struct lock_struct *lck1, const struct lock
 	if (IS_PENDING_LOCK(lck1->lock_type) || IS_PENDING_LOCK(lck2->lock_type))
 		return False;
 
-	if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) 
+	if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK)
 		return False;
 
 	/* POSIX flavour locks never conflict here - this is only called
@@ -219,7 +239,7 @@ static bool brl_conflict_other(const struct lock_struct *lck1, const struct lock
 	}
 
 	return brl_overlap(lck1, lck2);
-} 
+}
 
 /****************************************************************************
  Check if an unlock overlaps a pending lock.
@@ -240,7 +260,9 @@ static bool brl_pending_overlap(const struct lock_struct *lock, const struct loc
  app depends on this ?
 ****************************************************************************/
 
-NTSTATUS brl_lock_failed(files_struct *fsp, const struct lock_struct *lock, bool blocking_lock)
+static NTSTATUS brl_lock_failed(files_struct *fsp,
+				const struct lock_struct *lock,
+				bool blocking_lock)
 {
 	if (lock->start >= 0xEF000000 && (lock->start >> 63) == 0) {
 		/* amazing the little things you learn with a test
@@ -314,7 +336,7 @@ void brl_shutdown(void)
  Compare two locks for sorting.
 ****************************************************************************/
 
-static int lock_compare(const struct lock_struct *lck1, 
+static int lock_compare(const struct lock_struct *lck1,
 			 const struct lock_struct *lck2)
 {
 	if (lck1->start != lck2->start) {
@@ -354,7 +376,7 @@ NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
 			return brl_lock_failed(fsp,plock,blocking_lock);
 		}
 #if ZERO_ZERO
-		if (plock->start == 0 && plock->size == 0 && 
+		if (plock->start == 0 && plock->size == 0 &&
 				locks[i].size == 0) {
 			break;
 		}
@@ -394,7 +416,8 @@ NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
 	}
 
 	/* no conflicts - add it to the list of locks */
-	locks = (struct lock_struct *)SMB_REALLOC(locks, (br_lck->num_locks + 1) * sizeof(*locks));
+	locks = talloc_realloc(br_lck, locks, struct lock_struct,
+			       (br_lck->num_locks + 1));
 	if (!locks) {
 		status = NT_STATUS_NO_MEMORY;
 		goto fail;
@@ -732,7 +755,7 @@ static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
 	   existing POSIX lock range into two, and add our lock,
 	   so we need at most 2 more entries. */
 
-	tp = SMB_MALLOC_ARRAY(struct lock_struct, (br_lck->num_locks + 2));
+	tp = talloc_array(br_lck, struct lock_struct, br_lck->num_locks + 2);
 	if (!tp) {
 		return NT_STATUS_NO_MEMORY;
 	}
@@ -753,7 +776,7 @@ static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
 			/* Do any Windows flavour locks conflict ? */
 			if (brl_conflict(curr_lock, plock)) {
 				/* No games with error messages. */
-				SAFE_FREE(tp);
+				TALLOC_FREE(tp);
 				/* Remember who blocked us. */
 				plock->context.smblctx = curr_lock->context.smblctx;
 				return NT_STATUS_FILE_LOCK_CONFLICT;
@@ -768,7 +791,7 @@ static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
 			if (brl_conflict_posix(curr_lock, plock)) {
 				/* Can't block ourselves with POSIX locks. */
 				/* No games with error messages. */
-				SAFE_FREE(tp);
+				TALLOC_FREE(tp);
 				/* Remember who blocked us. */
 				plock->context.smblctx = curr_lock->context.smblctx;
 				return NT_STATUS_FILE_LOCK_CONFLICT;
@@ -833,11 +856,11 @@ static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
 			plock->context.smblctx = 0xFFFFFFFFFFFFFFFFLL;
 
 			if (errno_ret == EACCES || errno_ret == EAGAIN) {
-				SAFE_FREE(tp);
+				TALLOC_FREE(tp);
 				status = NT_STATUS_FILE_LOCK_CONFLICT;
 				goto fail;
 			} else {
-				SAFE_FREE(tp);
+				TALLOC_FREE(tp);
 				status = map_nt_error_from_unix(errno);
 				goto fail;
 			}
@@ -847,7 +870,7 @@ static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
 	/* If we didn't use all the allocated size,
 	 * Realloc so we don't leak entries per lock call. */
 	if (count < br_lck->num_locks + 2) {
-		tp = (struct lock_struct *)SMB_REALLOC(tp, count * sizeof(*locks));
+		tp = talloc_realloc(br_lck, tp, struct lock_struct, count);
 		if (!tp) {
 			status = NT_STATUS_NO_MEMORY;
 			goto fail;
@@ -855,7 +878,7 @@ static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
 	}
 
 	br_lck->num_locks = count;
-	SAFE_FREE(br_lck->lock_data);
+	TALLOC_FREE(br_lck->lock_data);
 	br_lck->lock_data = tp;
 	locks = tp;
 	br_lck->modified = True;
@@ -913,7 +936,7 @@ NTSTATUS brl_lock(struct messaging_context *msg_ctx,
 		uint64_t smblctx,
 		struct server_id pid,
 		br_off start,
-		br_off size, 
+		br_off size,
 		enum brl_type lock_type,
 		enum brl_flavour lock_flav,
 		bool blocking_lock,
@@ -931,7 +954,7 @@ NTSTATUS brl_lock(struct messaging_context *msg_ctx,
 
 #ifdef DEVELOPER
 	/* Quieten valgrind on test. */
-	memset(&lock, '\0', sizeof(lock));
+	ZERO_STRUCT(lock);
 #endif
 
 	lock.context.smblctx = smblctx;
@@ -1031,7 +1054,7 @@ bool brl_unlock_windows_default(struct messaging_context *msg_ctx,
 
 	/* Actually delete the lock. */
 	if (i < br_lck->num_locks - 1) {
-		memmove(&locks[i], &locks[i+1], 
+		memmove(&locks[i], &locks[i+1],
 			sizeof(*locks)*((br_lck->num_locks-1) - i));
 	}
 
@@ -1101,7 +1124,7 @@ static bool brl_unlock_posix(struct messaging_context *msg_ctx,
 	   existing POSIX lock range into two, so we need at most
 	   1 more entry. */
 
-	tp = SMB_MALLOC_ARRAY(struct lock_struct, (br_lck->num_locks + 1));
+	tp = talloc_array(br_lck, struct lock_struct, br_lck->num_locks + 1);
 	if (!tp) {
 		DEBUG(10,("brl_unlock_posix: malloc fail\n"));
 		return False;
@@ -1123,7 +1146,7 @@ static bool brl_unlock_posix(struct messaging_context *msg_ctx,
 		if (lock->lock_flav == WINDOWS_LOCK) {
 			/* Do any Windows flavour locks conflict ? */
 			if (brl_conflict(lock, plock)) {
-				SAFE_FREE(tp);
+				TALLOC_FREE(tp);
 				return false;
 			}
 			/* Just copy the Windows lock into the new array. */
@@ -1168,7 +1191,7 @@ static bool brl_unlock_posix(struct messaging_context *msg_ctx,
 
 	if (!overlap_found) {
 		/* Just ignore - no change. */
-		SAFE_FREE(tp);
+		TALLOC_FREE(tp);
 		DEBUG(10,("brl_unlock_posix: No overlap - unlocked.\n"));
 		return True;
 	}
@@ -1185,14 +1208,14 @@ static bool brl_unlock_posix(struct messaging_context *msg_ctx,
 
 	/* Realloc so we don't leak entries per unlock call. */
 	if (count) {
-		tp = (struct lock_struct *)SMB_REALLOC(tp, count * sizeof(*locks));
+		tp = talloc_realloc(br_lck, tp, struct lock_struct, count);
 		if (!tp) {
 			DEBUG(10,("brl_unlock_posix: realloc fail\n"));
 			return False;
 		}
 	} else {
 		/* We deleted the last lock. */
-		SAFE_FREE(tp);
+		TALLOC_FREE(tp);
 		tp = NULL;
 	}
 
@@ -1200,7 +1223,7 @@ static bool brl_unlock_posix(struct messaging_context *msg_ctx,
 				   LEVEL2_CONTEND_POSIX_BRL);
 
 	br_lck->num_locks = count;
-	SAFE_FREE(br_lck->lock_data);
+	TALLOC_FREE(br_lck->lock_data);
 	locks = tp;
 	br_lck->lock_data = tp;
 	br_lck->modified = True;
@@ -1234,7 +1257,7 @@ bool smb_vfs_call_brl_unlock_windows(struct vfs_handle_struct *handle,
 				     const struct lock_struct *plock)
 {
 	VFS_FIND(brl_unlock_windows);
-	return handle->fns->brl_unlock_windows_fn(handle, msg_ctx, br_lck, 
+	return handle->fns->brl_unlock_windows_fn(handle, msg_ctx, br_lck,
 						  plock);
 }
 
@@ -1278,7 +1301,7 @@ bool brl_locktest(struct byte_range_lock *br_lck,
 		uint64_t smblctx,
 		struct server_id pid,
 		br_off start,
-		br_off size, 
+		br_off size,
 		enum brl_type lock_type,
 		enum brl_flavour lock_flav)
 {
@@ -1336,7 +1359,7 @@ NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
 		uint64_t *psmblctx,
 		struct server_id pid,
 		br_off *pstart,
-		br_off *psize, 
+		br_off *psize,
 		enum brl_type *plock_type,
 		enum brl_flavour lock_flav)
 {
@@ -1361,7 +1384,7 @@ NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
 
 		if (exlock->lock_flav == WINDOWS_LOCK) {
 			conflict = brl_conflict(exlock, &lock);
-		} else {	
+		} else {
 			conflict = brl_conflict_posix(exlock, &lock);
 		}
 
@@ -1468,7 +1491,7 @@ bool brl_lock_cancel_default(struct byte_range_lock *br_lck,
 
 	if (i < br_lck->num_locks - 1) {
 		/* Found this particular pending lock - delete it */
-		memmove(&locks[i], &locks[i+1], 
+		memmove(&locks[i], &locks[i+1],
 			sizeof(*locks)*((br_lck->num_locks-1) - i));
 	}
 
@@ -1655,7 +1678,8 @@ bool brl_reconnect_disconnected(struct files_struct *fsp)
 /****************************************************************************
  Ensure this set of lock entries is valid.
 ****************************************************************************/
-static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct **pplocks,
+static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
+				  unsigned int *pnum_entries, struct lock_struct **pplocks,
 				  bool keep_disconnected)
 {
 	unsigned int i;
@@ -1716,7 +1740,9 @@ static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct
 		struct lock_struct *new_lock_data = NULL;
 
 		if (num_valid_entries) {
-			new_lock_data = SMB_MALLOC_ARRAY(struct lock_struct, num_valid_entries);
+			new_lock_data = talloc_array(
+				mem_ctx, struct lock_struct,
+				num_valid_entries);
 			if (!new_lock_data) {
 				DEBUG(3, ("malloc fail\n"));
 				return False;
@@ -1735,7 +1761,7 @@ static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct
 			}
 		}
 
-		SAFE_FREE(*pplocks);
+		TALLOC_FREE(*pplocks);
 		*pplocks = new_lock_data;
 		*pnum_entries = num_valid_entries;
 	}
@@ -1774,7 +1800,8 @@ static int brl_traverse_fn(struct db_record *rec, void *state)
 	/* In a traverse function we must make a copy of
 	   dbuf before modifying it. */
 
-	locks = (struct lock_struct *)memdup(value.dptr, value.dsize);
+	locks = (struct lock_struct *)talloc_memdup(
+		talloc_tos(), value.dptr, value.dsize);
 	if (!locks) {
 		return -1; /* Terminate traversal. */
 	}
@@ -1784,8 +1811,8 @@ static int brl_traverse_fn(struct db_record *rec, void *state)
 
 	/* Ensure the lock db is clean of entries from invalid processes. */
 
-	if (!validate_lock_entries(&num_locks, &locks, true)) {
-		SAFE_FREE(locks);
+	if (!validate_lock_entries(talloc_tos(), &num_locks, &locks, true)) {
+		TALLOC_FREE(locks);
 		return -1; /* Terminate traversal */
 	}
 
@@ -1812,7 +1839,7 @@ static int brl_traverse_fn(struct db_record *rec, void *state)
 		}
 	}
 
-	SAFE_FREE(locks);
+	TALLOC_FREE(locks);
 	return 0;
 }
 
@@ -1894,7 +1921,6 @@ static void byte_range_lock_flush(struct byte_range_lock *br_lck)
 static int byte_range_lock_destructor(struct byte_range_lock *br_lck)
 {
 	byte_range_lock_flush(br_lck);
-	SAFE_FREE(br_lck->lock_data);
 	return 0;
 }
 
@@ -1958,8 +1984,8 @@ static struct byte_range_lock *brl_get_locks_internal(TALLOC_CTX *mem_ctx,
 	br_lck->num_locks = data.dsize / sizeof(struct lock_struct);
 
 	if (br_lck->num_locks != 0) {
-		br_lck->lock_data = SMB_MALLOC_ARRAY(struct lock_struct,
-						     br_lck->num_locks);
+		br_lck->lock_data = talloc_array(
+			br_lck, struct lock_struct, br_lck->num_locks);
 		if (br_lck->lock_data == NULL) {
 			DEBUG(0, ("malloc failed\n"));
 			TALLOC_FREE(br_lck);
@@ -1985,9 +2011,8 @@ static struct byte_range_lock *brl_get_locks_internal(TALLOC_CTX *mem_ctx,
 		 * So we need to clean the disconnected brl entry.
 		 */
 
-		if (!validate_lock_entries(&br_lck->num_locks,
+		if (!validate_lock_entries(br_lck, &br_lck->num_locks,
 					   &br_lck->lock_data, false)) {
-			SAFE_FREE(br_lck->lock_data);
 			TALLOC_FREE(br_lck);
 			return NULL;
 		}
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index ad56cb1..d4c68f8 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -411,7 +411,7 @@ void locking_close_file(struct messaging_context *msg_ctx,
 		return;
 	}
 
-	/* If we have not outstanding locks or pending
+	/* If we have no outstanding locks or pending
 	 * locks then we don't need to look in the lock db.
 	 */
 
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index 93fbea5..1573f6b 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -25,12 +25,12 @@
 
 /* The following definitions come from locking/brlock.c  */
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list