[PATCH] three small ones from my attic

Michael Adam obnox at samba.org
Thu Jul 14 15:17:41 UTC 2016


Pushed 2 and questions for the tdb patch:



> 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>

Pushed this one to autobuild.


> 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) {

Style-wise, I would like it better with tdb_read call
outside the if(...), and a helper variable for the ret,
but maybe you have good reasons for it?
(similar comments to the above calls to
tdb_unlock and tdb_unlock_record).

Regarding the call, the DOCONV() seems to be at least
different from the prior call to tdb_alloc_read()
(which internally sets 0 to the slot).
Is that something where the new code is better and
the alloc_read code needs fixing?

Otherwise - nice optimization!


> 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>

Pushed this one to autobuild.

Cheers - Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160714/bfda9c13/signature.sig>


More information about the samba-technical mailing list