[PATCH] three small ones from my attic

Volker Lendecke vl at samba.org
Thu Jul 14 08:41:01 UTC 2016


Hi!

Review appreciated!

Thanks, Volker
-------------- next part --------------
>From 11045dc1dd53de35f1bd0dd1467ef82ef4bf434d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 26 Apr 2016 16:24:33 +0200
Subject: [PATCH 1/3] lib: Avoid a "procid_is_local" call

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/messages.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 5d90947..9901e30 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -545,7 +545,7 @@ int messaging_send_iov_from(struct messaging_context *msg_ctx,
 		return EINVAL;
 	}
 
-	if (!procid_is_local(&dst)) {
+	if (dst.vnn != msg_ctx->id.vnn) {
 		if (num_fds > 0) {
 			return ENOSYS;
 		}
-- 
1.9.1


>From eecbd8bacff900e236c98fc50f4ee84ec539d614 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 22 Jul 2015 11:19:08 +0200
Subject: [PATCH 2/3] tdb: Don't malloc for every record in traverse

This gains a few percent in tdbbackup

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/tdb/common/traverse.c | 45 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 6 deletions(-)

diff --git a/lib/tdb/common/traverse.c b/lib/tdb/common/traverse.c
index e18e3c3..fcb632d 100644
--- a/lib/tdb/common/traverse.c
+++ b/lib/tdb/common/traverse.c
@@ -148,6 +148,13 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
 	struct tdb_record rec;
 	int ret = 0, count = 0;
 	tdb_off_t off;
+	size_t recbuf_len;
+
+	recbuf_len = 4096;
+	key.dptr = malloc(recbuf_len);
+	if (key.dptr == NULL) {
+		return -1;
+	}
 
 	/* This was in the initialization, above, but the IRIX compiler
 	 * did not like it.  crh
@@ -159,15 +166,43 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
 
 	/* tdb_next_lock places locks on the record returned, and its chain */
 	while ((off = tdb_next_lock(tdb, tl, &rec)) != 0) {
+		tdb_len_t full_len = rec.key_len + rec.data_len;
+
+		if (full_len > recbuf_len) {
+			recbuf_len = full_len;
+
+			/*
+			 * No realloc, we don't need the old data and thus can
+			 * do without the memcpy
+			 */
+			free(key.dptr);
+			key.dptr = malloc(recbuf_len);
+
+			if (key.dptr == NULL) {
+				ret = -1;
+				if (tdb_unlock(tdb, tl->hash, tl->lock_rw)
+				    != 0) {
+					goto out;
+				}
+				if (tdb_unlock_record(tdb, tl->off) != 0) {
+					TDB_LOG((tdb, TDB_DEBUG_FATAL,
+						 "tdb_traverse: malloc "
+						 "failed and unlock_record "
+						 "failed!\n"));
+				}
+				goto out;
+			}
+		}
+
 		if (off == TDB_NEXT_LOCK_ERR) {
 			ret = -1;
 			goto out;
 		}
 		count++;
 		/* now read the full record */
-		key.dptr = tdb_alloc_read(tdb, tl->off + sizeof(rec),
-					  rec.key_len + rec.data_len);
-		if (!key.dptr) {
+		if (tdb->methods->tdb_read(
+			    tdb, tl->off + sizeof(rec), key.dptr, full_len,
+			    DOCONV()) == -1) {
 			ret = -1;
 			if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0)
 				goto out;
@@ -184,7 +219,6 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
 		/* Drop chain lock, call out */
 		if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0) {
 			ret = -1;
-			SAFE_FREE(key.dptr);
 			goto out;
 		}
 		if (fn && fn(tdb, key, dbuf, private_data)) {
@@ -194,13 +228,12 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
 				TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_traverse: unlock_record failed!\n"));;
 				ret = -1;
 			}
-			SAFE_FREE(key.dptr);
 			goto out;
 		}
-		SAFE_FREE(key.dptr);
 	}
 	tdb_trace(tdb, "tdb_traverse_end");
 out:
+	SAFE_FREE(key.dptr);
 	tdb->travlocks.next = tl->next;
 	if (ret < 0)
 		return -1;
-- 
1.9.1


>From 564318aa31df18520ede547a9651ca170ff9e88c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 23 Jun 2016 13:24:02 +0200
Subject: [PATCH 3/3] lib: Allow NULL blob for messaging_send()

... something I've wanted to do for ages :-)

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/messages.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 9901e30..693452c 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -511,10 +511,12 @@ NTSTATUS messaging_send(struct messaging_context *msg_ctx,
 			struct server_id server, uint32_t msg_type,
 			const DATA_BLOB *data)
 {
-	struct iovec iov;
+	struct iovec iov = {0};
 
-	iov.iov_base = data->data;
-	iov.iov_len = data->length;
+	if (data != NULL) {
+		iov.iov_base = data->data;
+		iov.iov_len = data->length;
+	};
 
 	return messaging_send_iov(msg_ctx, server, msg_type, &iov, 1, NULL, 0);
 }
-- 
1.9.1



More information about the samba-technical mailing list