s3:registry: use transaction wrapper in init_registry_data()
authorMichael Adam <obnox@samba.org>
Wed, 8 Jul 2009 11:10:37 +0000 (13:10 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 15 Jul 2009 12:01:51 +0000 (14:01 +0200)
Michael

source3/registry/reg_backend_db.c

index d2adc1ce08f6cc494e203e84c2d24778feacccfb..bed9535f17f990ee8b7356c9b4aade22b1c20f76 100644 (file)
@@ -240,74 +240,25 @@ WERROR init_registry_key(const char *add_path)
  Open the registry data in the tdb
  ***********************************************************************/
 
-WERROR init_registry_data(void)
+static NTSTATUS init_registry_data_action(struct db_context *db,
+                                         void *private_data)
 {
-       WERROR werr;
+       NTSTATUS status;
        TALLOC_CTX *frame = talloc_stackframe();
        struct 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(regdb, builtin_registry_paths[i])) {
-                       goto do_init;
-               }
-       }
-
-       for (i=0; builtin_registry_values[i].path != NULL; i++) {
-               values = TALLOC_ZERO_P(frame, struct regval_ctr);
-               if (values == NULL) {
-                       werr = WERR_NOMEM;
-                       goto done;
-               }
-
-               regdb_fetch_values_internal(regdb,
-                                           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
-        * its fsync()s. See tdb/common/transaction.c for info about nested
-        * transaction behaviour.
-        */
-
-       if (regdb->transaction_start(regdb) != 0) {
-               DEBUG(0, ("init_registry_data: tdb_transaction_start "
-                         "failed\n"));
-               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(regdb, builtin_registry_paths[i])) {
+               if (regdb_key_exists(db, builtin_registry_paths[i])) {
                        continue;
                }
-               werr = init_registry_key_internal(regdb,
-                                                 builtin_registry_paths[i]);
-               if (!W_ERROR_IS_OK(werr)) {
-                       goto fail;
+               status = werror_to_ntstatus(init_registry_key_internal(db,
+                                                 builtin_registry_paths[i]));
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto done;
                }
        }
 
@@ -317,11 +268,11 @@ do_init:
 
                values = TALLOC_ZERO_P(frame, struct regval_ctr);
                if (values == NULL) {
-                       werr = WERR_NOMEM;
-                       goto fail;
+                       status = NT_STATUS_NO_MEMORY;
+                       goto done;
                }
 
-               regdb_fetch_values_internal(regdb,
+               regdb_fetch_values_internal(db,
                                            builtin_registry_values[i].path,
                                            values);
 
@@ -356,29 +307,75 @@ do_init:
                                          "[%d]\n",
                                          builtin_registry_values[i].type));
                        }
-                       regdb_store_values_internal(regdb,
+                       regdb_store_values_internal(db,
                                        builtin_registry_values[i].path,
                                        values);
                }
                TALLOC_FREE(values);
        }
 
-       if (regdb->transaction_commit(regdb) != 0) {
-               DEBUG(0, ("init_registry_data: Could not commit "
-                         "transaction\n"));
-               werr = WERR_REG_IO_FAILURE;
-       } else {
-               werr = WERR_OK;
+       status = NT_STATUS_OK;
+
+done:
+
+       TALLOC_FREE(frame);
+       return status;
+}
+
+WERROR init_registry_data(void)
+{
+       WERROR werr;
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct regval_ctr *values;
+       int i;
+
+       /*
+        * 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(regdb, builtin_registry_paths[i])) {
+                       goto do_init;
+               }
        }
 
-       goto done;
+       for (i=0; builtin_registry_values[i].path != NULL; i++) {
+               values = TALLOC_ZERO_P(frame, struct regval_ctr);
+               if (values == NULL) {
+                       werr = WERR_NOMEM;
+                       goto done;
+               }
 
-fail:
-       if (regdb->transaction_cancel(regdb) != 0) {
-               smb_panic("init_registry_data: tdb_transaction_cancel "
-                         "failed\n");
+               regdb_fetch_values_internal(regdb,
+                                           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
+        * its fsync()s. See tdb/common/transaction.c for info about nested
+        * transaction behaviour.
+        */
+
+       werr = ntstatus_to_werror(dbwrap_trans_do(regdb,
+                                                 init_registry_data_action,
+                                                 NULL));
+
 done:
        TALLOC_FREE(frame);
        return werr;