dsdb/partition: Ensure metadata.tdb is opened early in partition_reload_if_required()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 16 May 2019 02:35:00 +0000 (14:35 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 20 May 2019 04:01:10 +0000 (04:01 +0000)
This allows metadata.tdb to be locked in the correct place in
in the lock order, as partition_reload_if_required() implicitly
calls partition_lock_read().

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
source4/dsdb/samdb/ldb_modules/partition_init.c
source4/dsdb/samdb/ldb_modules/partition_metadata.c

index 9a8bb7e211dc94d0d86a600df1aa5b13682774c8..7d076932665df5d0e68c511ee6cbe740f9e2fbc0 100644 (file)
@@ -409,6 +409,12 @@ int partition_reload_if_required(struct ldb_module *module,
                return LDB_SUCCESS;
        }
 
+       /* This loads metadata tdb. If it's missing, creates it */
+       ret = partition_metadata_init(module);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
        ret = partition_reload_metadata(module, data, mem_ctx, &msg, parent);
        if (ret != LDB_SUCCESS) {
                talloc_free(mem_ctx);
@@ -890,11 +896,5 @@ int partition_init(struct ldb_module *module)
                return ldb_operr(ldb);
        }
 
-       /* This loads metadata tdb. If it's missing, creates it */
-       ret = partition_metadata_init(module);
-       if (ret != LDB_SUCCESS) {
-               return ret;
-       }
-
        return ldb_next_init(module);
 }
index cf44c5d1218e61d77cf857d639c6f912a6497f7d..c0800f5e506b6631f5a84fcc40f38c0b91a639f2 100644 (file)
@@ -303,6 +303,10 @@ int partition_metadata_init(struct ldb_module *module)
        data = talloc_get_type_abort(ldb_module_get_private(module),
                                     struct partition_private_data);
 
+       if (data->metadata != NULL && data->metadata->db != NULL) {
+               return LDB_SUCCESS;
+       }
+
        data->metadata = talloc_zero(data, struct partition_metadata);
        if (data->metadata == NULL) {
                return ldb_module_oom(module);