[SCM] Samba Shared Repository - branch v3-2-test updated -
initial-v3-2-unstable-1164-g66be770
Volker Lendecke
vl at samba.org
Mon Jan 7 20:38:25 GMT 2008
The branch, v3-2-test has been updated
via 66be770993acf4e1673e9615bcddb21768c33e62 (commit)
via 88d82d0623e71ae1ef4f8fdefba10e3a230ea526 (commit)
via 921c8657e2eeb71d5b9ae2675255a852b26cc30d (commit)
via c0c2084d40b79e949dab7c68626aa665b9ea1a8e (commit)
from 079f2eba81886707ea4b18f103e097dbac994b2f (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit 66be770993acf4e1673e9615bcddb21768c33e62
Author: Volker Lendecke <vl at samba.org>
Date: Mon Jan 7 12:57:10 2008 +0100
Do not talloc_strdup filename and servicepath
commit 88d82d0623e71ae1ef4f8fdefba10e3a230ea526
Author: Volker Lendecke <vl at samba.org>
Date: Mon Jan 7 00:41:26 2008 +0100
make db_tdb_fetch use tdb_parse_record
commit 921c8657e2eeb71d5b9ae2675255a852b26cc30d
Author: Volker Lendecke <vl at samba.org>
Date: Mon Jan 7 00:14:24 2008 +0100
Change db_tdb_fetch_locked to use only one talloc
commit c0c2084d40b79e949dab7c68626aa665b9ea1a8e
Author: Volker Lendecke <vl at samba.org>
Date: Sun Jan 6 17:25:20 2008 +0100
talloc_stackframe only needs 1 talloc
-----------------------------------------------------------------------
Summary of changes:
source/lib/dbwrap_tdb.c | 132 +++++++++++++++++++++++++++++----------------
source/lib/talloc_stack.c | 18 +++----
source/locking/locking.c | 24 +++------
3 files changed, 100 insertions(+), 74 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/lib/dbwrap_tdb.c b/source/lib/dbwrap_tdb.c
index b24fd06..83a0d11 100644
--- a/source/lib/dbwrap_tdb.c
+++ b/source/lib/dbwrap_tdb.c
@@ -43,33 +43,50 @@ static int db_tdb_record_destr(struct db_record* data)
return 0;
}
-static struct db_record *db_tdb_fetch_locked(struct db_context *db,
- TALLOC_CTX *mem_ctx, TDB_DATA key)
-{
- struct db_tdb_ctx *ctx = talloc_get_type_abort(db->private_data,
- struct db_tdb_ctx);
+struct tdb_fetch_locked_state {
+ TALLOC_CTX *mem_ctx;
struct db_record *result;
- TDB_DATA value;
+};
- result = TALLOC_P(mem_ctx, struct db_record);
- if (result == NULL) {
- DEBUG(0, ("talloc failed\n"));
- return NULL;
+static int db_tdb_fetchlock_parse(TDB_DATA key, TDB_DATA data,
+ void *private_data)
+{
+ struct tdb_fetch_locked_state *state =
+ (struct tdb_fetch_locked_state *)private_data;
+
+ state->result = (struct db_record *)talloc_size(
+ state->mem_ctx,
+ sizeof(struct db_record) + key.dsize + data.dsize);
+
+ if (state->result == NULL) {
+ return 0;
}
- result->key.dsize = key.dsize;
- result->key.dptr = (uint8 *)talloc_memdup(result, key.dptr, key.dsize);
- if (result->key.dptr == NULL) {
- DEBUG(0, ("talloc failed\n"));
- TALLOC_FREE(result);
- return NULL;
+ state->result->key.dsize = key.dsize;
+ state->result->key.dptr = ((uint8 *)state->result)
+ + sizeof(struct db_record);
+ memcpy(state->result->key.dptr, key.dptr, key.dsize);
+
+ state->result->value.dsize = data.dsize;
+
+ if (data.dsize > 0) {
+ state->result->value.dptr = state->result->key.dptr+key.dsize;
+ memcpy(state->result->value.dptr, data.dptr, data.dsize);
}
+ else {
+ state->result->value.dptr = NULL;
+ }
+
+ return 0;
+}
- result->value.dptr = NULL;
- result->value.dsize = 0;
- result->private_data = talloc_reference(result, ctx);
- result->store = db_tdb_store;
- result->delete_rec = db_tdb_delete;
+static struct db_record *db_tdb_fetch_locked(struct db_context *db,
+ TALLOC_CTX *mem_ctx, TDB_DATA key)
+{
+ struct db_tdb_ctx *ctx = talloc_get_type_abort(db->private_data,
+ struct db_tdb_ctx);
+ struct tdb_fetch_locked_state state;
+ int res;
if (DEBUGLEVEL >= 10) {
char *keystr = hex_encode(NULL, key.dptr, key.dsize);
@@ -81,32 +98,56 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db,
if (tdb_chainlock(ctx->wtdb->tdb, key) != 0) {
DEBUG(3, ("tdb_chainlock failed\n"));
- TALLOC_FREE(result);
return NULL;
}
- talloc_set_destructor(result, db_tdb_record_destr);
+ state.mem_ctx = mem_ctx;
+ state.result = NULL;
- value = tdb_fetch(ctx->wtdb->tdb, key);
+ res = tdb_parse_record(ctx->wtdb->tdb, key, db_tdb_fetchlock_parse,
+ &state);
- if (value.dptr == NULL) {
- return result;
+ if (state.result == NULL) {
+ db_tdb_fetchlock_parse(key, tdb_null, &state);
}
- result->value.dsize = value.dsize;
- result->value.dptr = (uint8 *)talloc_memdup(result, value.dptr,
- value.dsize);
- if (result->value.dptr == NULL) {
- DEBUG(3, ("talloc failed\n"));
- TALLOC_FREE(result);
+ if (state.result == NULL) {
+ tdb_chainunlock(ctx->wtdb->tdb, key);
return NULL;
}
- SAFE_FREE(value.dptr);
+ talloc_set_destructor(state.result, db_tdb_record_destr);
- DEBUG(10, ("Allocated locked data 0x%p\n", result));
+ state.result->private_data = talloc_reference(state.result, ctx);
+ state.result->store = db_tdb_store;
+ state.result->delete_rec = db_tdb_delete;
- return result;
+ DEBUG(10, ("Allocated locked data 0x%p\n", state.result));
+
+ return state.result;
+}
+
+struct tdb_fetch_state {
+ TALLOC_CTX *mem_ctx;
+ int result;
+ TDB_DATA data;
+};
+
+static int db_tdb_fetch_parse(TDB_DATA key, TDB_DATA data,
+ void *private_data)
+{
+ struct tdb_fetch_state *state =
+ (struct tdb_fetch_state *)private_data;
+
+ state->data.dptr = (uint8 *)talloc_memdup(state->mem_ctx, data.dptr,
+ data.dsize);
+ if (state->data.dptr == NULL) {
+ state->result = -1;
+ return 0;
+ }
+
+ state->data.dsize = data.dsize;
+ return 0;
}
static int db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
@@ -115,23 +156,20 @@ static int db_tdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
struct db_tdb_ctx *ctx = talloc_get_type_abort(
db->private_data, struct db_tdb_ctx);
- TDB_DATA data;
-
- data = tdb_fetch(ctx->wtdb->tdb, key);
+ struct tdb_fetch_state state;
- if (data.dptr == NULL) {
- pdata->dptr = NULL;
- pdata->dsize = 0;
- return 0;
- }
+ state.mem_ctx = mem_ctx;
+ state.result = 0;
+ state.data.dptr = NULL;
+ state.data.dsize = 0;
- pdata->dptr = (uint8 *)talloc_memdup(mem_ctx, data.dptr, data.dsize);
- SAFE_FREE(data.dptr);
+ tdb_parse_record(ctx->wtdb->tdb, key, db_tdb_fetch_parse, &state);
- if (pdata->dptr == NULL) {
+ if (state.result == -1) {
return -1;
}
- pdata->dsize = data.dsize;
+
+ *pdata = state.data;
return 0;
}
diff --git a/source/lib/talloc_stack.c b/source/lib/talloc_stack.c
index e6e4ed3..cc7ce3a 100644
--- a/source/lib/talloc_stack.c
+++ b/source/lib/talloc_stack.c
@@ -41,16 +41,18 @@
static int talloc_stacksize;
static TALLOC_CTX **talloc_stack;
-static int talloc_pop(int *ptr)
+static int talloc_pop(TALLOC_CTX *frame)
{
- int tos = *ptr;
int i;
- for (i=talloc_stacksize-1; i>=tos; i--) {
+ for (i=talloc_stacksize-1; i>0; i--) {
+ if (frame == talloc_stack[i]) {
+ break;
+ }
talloc_free(talloc_stack[i]);
}
- talloc_stacksize = tos;
+ talloc_stacksize = i;
return 0;
}
@@ -64,7 +66,6 @@ static int talloc_pop(int *ptr)
TALLOC_CTX *talloc_stackframe(void)
{
TALLOC_CTX **tmp, *top;
- int *cleanup;
if (!(tmp = TALLOC_REALLOC_ARRAY(NULL, talloc_stack, TALLOC_CTX *,
talloc_stacksize + 1))) {
@@ -77,12 +78,7 @@ TALLOC_CTX *talloc_stackframe(void)
goto fail;
}
- if (!(cleanup = talloc(top, int))) {
- goto fail;
- }
-
- *cleanup = talloc_stacksize;
- talloc_set_destructor(cleanup, talloc_pop);
+ talloc_set_destructor(top, talloc_pop);
talloc_stack[talloc_stacksize++] = top;
diff --git a/source/locking/locking.c b/source/locking/locking.c
index 270c6d2..2ec8cd2 100644
--- a/source/locking/locking.c
+++ b/source/locking/locking.c
@@ -585,22 +585,14 @@ static bool parse_share_modes(TDB_DATA dbuf, struct share_mode_lock *lck)
}
/* Save off the associated service path and filename. */
- lck->servicepath = talloc_strdup(lck, (const char *)dbuf.dptr + sizeof(*data) +
- (lck->num_share_modes *
- sizeof(struct share_mode_entry)) +
- data->u.s.delete_token_size );
- if (lck->servicepath == NULL) {
- smb_panic("parse_share_modes: talloc_strdup failed");
- }
-
- lck->filename = talloc_strdup(lck, (const char *)dbuf.dptr + sizeof(*data) +
- (lck->num_share_modes *
- sizeof(struct share_mode_entry)) +
- data->u.s.delete_token_size +
- strlen(lck->servicepath) + 1 );
- if (lck->filename == NULL) {
- smb_panic("parse_share_modes: talloc_strdup failed");
- }
+ lck->servicepath = (const char *)dbuf.dptr + sizeof(*data) +
+ (lck->num_share_modes * sizeof(struct share_mode_entry)) +
+ data->u.s.delete_token_size;
+
+ lck->filename = (const char *)dbuf.dptr + sizeof(*data) +
+ (lck->num_share_modes * sizeof(struct share_mode_entry)) +
+ data->u.s.delete_token_size +
+ strlen(lck->servicepath) + 1;
/*
* Ensure that each entry has a real process attached.
--
Samba Shared Repository
More information about the samba-cvs
mailing list