[SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-2252-g37dabf9

Michael Adam obnox at samba.org
Wed Apr 30 10:43:19 GMT 2008


The branch, v3-3-test has been updated
       via  37dabf931727f00569725af0e34677d36bb7df99 (commit)
       via  7c5f1583cb43d473544f161aa9c864e1d78944e5 (commit)
       via  3ab5a2f1b3cf37c380ff3e45a957e62a8017814a (commit)
       via  207a0ece45d947608df3f764e6bd9b4525d41011 (commit)
       via  3316541ac9f1441294405fdd98f0ffafdec8bc2f (commit)
       via  78f924ca05ecef9f586254c00908c1f12272c30c (commit)
       via  97bed9a23608248f1a590c99fe40564d2fbfa3cc (commit)
       via  217233349b2d98d2506fcca47858373150e89924 (commit)
       via  1e4d2310d077c4d18470fd76f5ff9c010aadd3f0 (commit)
       via  569f9844e9d35324cf9a3a3094cd9791918a1441 (commit)
       via  87a58140f0073dfb5b18fb43655b255aebafbd02 (commit)
      from  067a6931a23631dfb902fb4a180f3c44a5455d51 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test


- Log -----------------------------------------------------------------
commit 37dabf931727f00569725af0e34677d36bb7df99
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 17:41:03 2008 +0200

    registry: skip writes of existing keys in init_registry_data().
    
    Michael

commit 7c5f1583cb43d473544f161aa9c864e1d78944e5
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 17:37:35 2008 +0200

    registry: save writes in init_registry_data() if data does already exist.
    
    This is done by first checking if all data (keys and values) exists
    (using new regdb_key_exists()) and kompletely skipping all writes if it does.
    
    Michael

commit 3ab5a2f1b3cf37c380ff3e45a957e62a8017814a
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 17:18:26 2008 +0200

    registry: check for existence of key init_registry_key and possibly save a write.
    
    Michael

commit 207a0ece45d947608df3f764e6bd9b4525d41011
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 17:17:02 2008 +0200

    registry: add function regdb_key_exists() to check for existence of a key.
    
    The existence of the registry key entry (and not the values entry!) is
    taken as the criterion for existence.
    
    Michael

commit 3316541ac9f1441294405fdd98f0ffafdec8bc2f
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 17:11:09 2008 +0200

    registry: use regdb_fetch_key_internal() in regdb_fetch_values().
    
    Michael

commit 78f924ca05ecef9f586254c00908c1f12272c30c
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 17:09:10 2008 +0200

    registry: use regdb_fetch_key_internal() in regdb_fetch_keys().
    
    Michael

commit 97bed9a23608248f1a590c99fe40564d2fbfa3cc
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 17:04:41 2008 +0200

    registry: add a function for fetching a tdb record for a given keystring
    
    regdb_fetch_key_internal()
    
    Michael

commit 217233349b2d98d2506fcca47858373150e89924
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 15:30:45 2008 +0200

    registry: combine talloc_strdup() and normalize_reg_path() in regdb_fetch_keys().
    
    the talloc_strdup() call is just and extra allocation here.
    
    Michael

commit 1e4d2310d077c4d18470fd76f5ff9c010aadd3f0
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 15:28:47 2008 +0200

    registry: use normalize_reg_path() in regdb_fetch_keys()
    
    instead of handcrafting normalization.
    
    Michael

commit 569f9844e9d35324cf9a3a3094cd9791918a1441
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 15:17:54 2008 +0200

    registry: use dbwrap_fetch_bystring() in regdb_fetch_values().
    
    Michael

commit 87a58140f0073dfb5b18fb43655b255aebafbd02
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 29 15:16:10 2008 +0200

    registry: use dbwrap_fetch_bystring() in regdb_fetch_keys().
    
    instead of using regdb->fetch and constructing tdb data
    from the registry key string by hand.
    
    Michael

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

Summary of changes:
 source/registry/reg_backend_db.c |  120 +++++++++++++++++++++++++------------
 1 files changed, 81 insertions(+), 39 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/registry/reg_backend_db.c b/source/registry/reg_backend_db.c
index bd28eb3..8ebe647 100644
--- a/source/registry/reg_backend_db.c
+++ b/source/registry/reg_backend_db.c
@@ -27,6 +27,8 @@
 static struct db_context *regdb = NULL;
 static int regdb_refcount;
 
+static bool regdb_key_exists(const char *key);
+
 /* List the deepest path into the registry.  All part components will be created.*/
 
 /* If you want to have a part of the path controlled by the tdb and part by
@@ -199,6 +201,10 @@ WERROR init_registry_key(const char *add_path)
 {
 	WERROR werr;
 
+	if (regdb_key_exists(add_path)) {
+		return WERR_OK;
+	}
+
 	if (regdb->transaction_start(regdb) != 0) {
 		DEBUG(0, ("init_registry_key: transaction_start failed\n"));
 		return WERR_REG_IO_FAILURE;
@@ -231,12 +237,45 @@ fail:
 WERROR init_registry_data(void)
 {
 	WERROR werr;
-	TALLOC_CTX *frame = NULL;
+	TALLOC_CTX *frame = talloc_stackframe();
 	REGVAL_CTR *values;
 	int i;
 	UNISTR2 data;
 
 	/*
+	 * First, check for the existence of the needed keys and values.
+	 * If all do already exist, we can save the writes.
+	 */
+	for (i=0; builtin_registry_paths[i] != NULL; i++) {
+		if (!regdb_key_exists(builtin_registry_paths[i])) {
+			goto do_init;
+		}
+	}
+
+	for (i=0; builtin_registry_values[i].path != NULL; i++) {
+		values = TALLOC_ZERO_P(frame, REGVAL_CTR);
+		if (values == NULL) {
+			werr = WERR_NOMEM;
+			goto done;
+		}
+
+		regdb_fetch_values(builtin_registry_values[i].path, values);
+		if (!regval_ctr_key_exists(values,
+					builtin_registry_values[i].valuename))
+		{
+			TALLOC_FREE(values);
+			goto do_init;
+		}
+
+		TALLOC_FREE(values);
+	}
+
+	werr = WERR_OK;
+	goto done;
+
+do_init:
+
+	/*
 	 * There are potentially quite a few store operations which are all
 	 * indiviually wrapped in tdb transactions. Wrapping them in a single
 	 * transaction gives just a single transaction_commit() to actually do
@@ -247,12 +286,16 @@ WERROR init_registry_data(void)
 	if (regdb->transaction_start(regdb) != 0) {
 		DEBUG(0, ("init_registry_data: tdb_transaction_start "
 			  "failed\n"));
-		return WERR_REG_IO_FAILURE;
+		werr = WERR_REG_IO_FAILURE;
+		goto done;
 	}
 
 	/* loop over all of the predefined paths and add each component */
 
 	for (i=0; builtin_registry_paths[i] != NULL; i++) {
+		if (regdb_key_exists(builtin_registry_paths[i])) {
+			continue;
+		}
 		werr = init_registry_key_internal(builtin_registry_paths[i]);
 		if (!W_ERROR_IS_OK(werr)) {
 			goto fail;
@@ -261,8 +304,6 @@ WERROR init_registry_data(void)
 
 	/* loop over all of the predefined values and add each component */
 
-	frame = talloc_stackframe();
-
 	for (i=0; builtin_registry_values[i].path != NULL; i++) {
 
 		values = TALLOC_ZERO_P(frame, REGVAL_CTR);
@@ -310,25 +351,24 @@ WERROR init_registry_data(void)
 		TALLOC_FREE(values);
 	}
 
-	TALLOC_FREE(frame);
-
 	if (regdb->transaction_commit(regdb) != 0) {
 		DEBUG(0, ("init_registry_data: Could not commit "
 			  "transaction\n"));
-		return WERR_REG_IO_FAILURE;
+		werr = WERR_REG_IO_FAILURE;
+	} else {
+		werr = WERR_OK;
 	}
 
-	return WERR_OK;
-
- fail:
-
-	TALLOC_FREE(frame);
+	goto done;
 
+fail:
 	if (regdb->transaction_cancel(regdb) != 0) {
 		smb_panic("init_registry_data: tdb_transaction_cancel "
 			  "failed\n");
 	}
 
+done:
+	TALLOC_FREE(frame);
 	return werr;
 }
 
@@ -713,6 +753,33 @@ fail:
 }
 
 
+static TDB_DATA regdb_fetch_key_internal(const char *key, TALLOC_CTX *mem_ctx)
+{
+	char *path = NULL;
+
+	path = normalize_reg_path(mem_ctx, key);
+	if (!path) {
+		return make_tdb_data(NULL, 0);
+	}
+
+	return dbwrap_fetch_bystring(regdb, mem_ctx, path);
+}
+
+
+static bool regdb_key_exists(const char *key)
+{
+	TALLOC_CTX *mem_ctx = talloc_stackframe();
+	TDB_DATA value;
+	bool ret;
+
+	value = regdb_fetch_key_internal(key, mem_ctx);
+	ret = (value.dptr != NULL);
+
+	TALLOC_FREE(mem_ctx);
+	return ret;
+}
+
+
 /***********************************************************************
  Retrieve an array of strings containing subkeys.  Memory should be
  released by the caller.
@@ -721,37 +788,20 @@ fail:
 int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
 {
 	WERROR werr;
-	char *path = NULL;
 	uint32 num_items;
 	uint8 *buf;
 	uint32 buflen, len;
 	int i;
 	fstring subkeyname;
 	int ret = -1;
-	int dbret = -1;
 	TALLOC_CTX *frame = talloc_stackframe();
 	TDB_DATA value;
 
 	DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL"));
 
-	path = talloc_strdup(frame, key);
-	if (!path) {
-		goto fail;
-	}
-
-	/* convert to key format */
-	path = talloc_string_sub(frame, path, "\\", "/");
-	if (!path) {
-		goto fail;
-	}
-	strupper_m(path);
-
 	ctr->seqnum = regdb_get_seqnum();
 
-	dbret = regdb->fetch(regdb, frame, string_term_tdb_data(path), &value);
-	if (dbret != 0) {
-		goto fail;
-	}
+	value = regdb_fetch_key_internal(key, frame);
 
 	buf = value.dptr;
 	buflen = value.dsize;
@@ -870,7 +920,6 @@ int regdb_fetch_values( const char* key, REGVAL_CTR *values )
 	char *keystr = NULL;
 	TALLOC_CTX *ctx = talloc_stackframe();
 	int ret = 0;
-	int dbret = -1;
 	TDB_DATA value;
 
 	DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key));
@@ -879,17 +928,10 @@ int regdb_fetch_values( const char* key, REGVAL_CTR *values )
 	if (!keystr) {
 		return 0;
 	}
-	keystr = normalize_reg_path(ctx, keystr);
-	if (!keystr) {
-		goto done;
-	}
 
 	values->seqnum = regdb_get_seqnum();
 
-	dbret = regdb->fetch(regdb, ctx, string_term_tdb_data(keystr), &value);
-	if (dbret != 0) {
-		goto done;
-	}
+	value = regdb_fetch_key_internal(keystr, ctx);
 
 	if (!value.dptr) {
 		/* all keys have zero values by default */


-- 
Samba Shared Repository


More information about the samba-cvs mailing list