LCOV - code coverage report
Current view: top level - source4/dsdb/samdb/ldb_modules - partition_metadata.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 210 263 79.8 %
Date: 2024-02-28 12:06:22 Functions: 14 14 100.0 %

          Line data    Source code
       1             : /*
       2             :    Partitions ldb module - management of metadata.tdb for sequence number
       3             : 
       4             :    Copyright (C) Amitay Isaacs <amitay@samba.org> 2011
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "dsdb/samdb/ldb_modules/partition.h"
      21             : #include "lib/ldb-samba/ldb_wrap.h"
      22             : #include "system/filesys.h"
      23             : #include "lib/util/smb_strtox.h"
      24             : 
      25             : #define LDB_METADATA_SEQ_NUM    "SEQ_NUM"
      26             : 
      27             : 
      28             : /*
      29             :  * Read a key with uint64 value
      30             :  */
      31     1273091 : static int partition_metadata_get_uint64(struct ldb_module *module,
      32             :                                          const char *key, uint64_t *value,
      33             :                                          uint64_t default_value)
      34             : {
      35       95545 :         struct partition_private_data *data;
      36       95545 :         struct tdb_context *tdb;
      37       95545 :         TDB_DATA tdb_key, tdb_data;
      38       95545 :         char *value_str;
      39     1273091 :         int error = 0;
      40             : 
      41     1273091 :         data = talloc_get_type_abort(ldb_module_get_private(module),
      42             :                                      struct partition_private_data);
      43             : 
      44     1273091 :         if (!data || !data->metadata || !data->metadata->db) {
      45           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
      46             :                                         "partition_metadata: metadata tdb not initialized");
      47             :         }
      48             : 
      49     1273091 :         tdb = data->metadata->db->tdb;
      50             : 
      51     1273091 :         tdb_key.dptr = (uint8_t *)discard_const_p(char, key);
      52     1273091 :         tdb_key.dsize = strlen(key);
      53             : 
      54     1273091 :         tdb_data = tdb_fetch(tdb, tdb_key);
      55     1273091 :         if (!tdb_data.dptr) {
      56         422 :                 if (tdb_error(tdb) == TDB_ERR_NOEXIST) {
      57         422 :                         *value = default_value;
      58         422 :                         return LDB_SUCCESS;
      59             :                 } else {
      60           0 :                         return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
      61             :                                                 tdb_errorstr(tdb));
      62             :                 }
      63             :         }
      64             : 
      65     1272669 :         value_str = talloc_strndup(NULL, (char *)tdb_data.dptr, tdb_data.dsize);
      66     1272669 :         SAFE_FREE(tdb_data.dptr);
      67     1272669 :         if (value_str == NULL) {
      68           0 :                 return ldb_module_oom(module);
      69             :         }
      70             : 
      71     1272669 :         *value = smb_strtoull(value_str, NULL, 10, &error, SMB_STR_STANDARD);
      72     1272669 :         talloc_free(value_str);
      73     1272669 :         if (error != 0) {
      74           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
      75             :                                         "partition_metadata: converision failed");
      76             :         }
      77             : 
      78     1177177 :         return LDB_SUCCESS;
      79             : }
      80             : 
      81             : 
      82             : /*
      83             :  * Write a key with uin64 value
      84             :  */
      85     1250419 : static int partition_metadata_set_uint64(struct ldb_module *module,
      86             :                                          const char *key, uint64_t value,
      87             :                                          bool insert)
      88             : {
      89       95543 :         struct partition_private_data *data;
      90       95543 :         struct tdb_context *tdb;
      91       95543 :         TDB_DATA tdb_key, tdb_data;
      92       95543 :         int tdb_flag;
      93       95543 :         char *value_str;
      94       95543 :         TALLOC_CTX *tmp_ctx;
      95             : 
      96     1250419 :         data = talloc_get_type_abort(ldb_module_get_private(module),
      97             :                                      struct partition_private_data);
      98             : 
      99     1250419 :         if (!data || !data->metadata || !data->metadata->db) {
     100           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     101             :                                         "partition_metadata: metadata tdb not initialized");
     102             :         }
     103             : 
     104     1250419 :         tmp_ctx = talloc_new(NULL);
     105     1250419 :         if (tmp_ctx == NULL) {
     106           0 :                 return ldb_module_oom(module);
     107             :         }
     108             : 
     109     1250419 :         tdb = data->metadata->db->tdb;
     110             : 
     111     1250419 :         value_str = talloc_asprintf(tmp_ctx, "%llu", (unsigned long long)value);
     112     1250419 :         if (value_str == NULL) {
     113           0 :                 talloc_free(tmp_ctx);
     114           0 :                 return ldb_module_oom(module);
     115             :         }
     116             : 
     117     1250419 :         tdb_key.dptr = (uint8_t *)discard_const_p(char, key);
     118     1250419 :         tdb_key.dsize = strlen(key);
     119             : 
     120     1250419 :         tdb_data.dptr = (uint8_t *)value_str;
     121     1250419 :         tdb_data.dsize = strlen(value_str);
     122             : 
     123     1250419 :         if (insert) {
     124         369 :                 tdb_flag = TDB_INSERT;
     125             :         } else {
     126     1249997 :                 tdb_flag = TDB_MODIFY;
     127             :         }
     128             : 
     129     1250419 :         if (tdb_store(tdb, tdb_key, tdb_data, tdb_flag) != 0) {
     130          24 :                 int ret;
     131         209 :                 char *error_string = talloc_asprintf(tmp_ctx, "%s: tdb_store of key %s failed: %s",
     132             :                                                      tdb_name(tdb), key, tdb_errorstr(tdb));
     133         209 :                 ret = ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     134             :                                        error_string);
     135         209 :                 talloc_free(tmp_ctx);
     136         209 :                 return ret;
     137             :         }
     138             : 
     139     1250210 :         talloc_free(tmp_ctx);
     140             : 
     141     1250210 :         return LDB_SUCCESS;
     142             : }
     143             : 
     144        2746 : int partition_metadata_inc_schema_sequence(struct ldb_module *module)
     145             : {
     146          47 :         struct partition_private_data *data;
     147          47 :         int ret;
     148        2746 :         uint64_t value = 0;
     149             : 
     150        2746 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     151             :                                     struct partition_private_data);
     152        2746 :         if (!data || !data->metadata) {
     153           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     154             :                                         "partition_metadata: metadata not initialized");
     155             :         }
     156             : 
     157        2746 :         if (data->metadata->in_transaction == 0) {
     158           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     159             :                                         "partition_metadata: increment sequence number without transaction");
     160             :         }
     161        2746 :         ret = partition_metadata_get_uint64(module, DSDB_METADATA_SCHEMA_SEQ_NUM, &value, 0);
     162        2746 :         if (ret != LDB_SUCCESS) {
     163           0 :                 return ret;
     164             :         }
     165             : 
     166        2746 :         value++;
     167        2746 :         ret = partition_metadata_set_uint64(module, DSDB_METADATA_SCHEMA_SEQ_NUM, value, false);
     168        2746 :         if (ret == LDB_ERR_OPERATIONS_ERROR) {
     169             :                 /* Modify failed, let's try the add */
     170         209 :                 ret = partition_metadata_set_uint64(module, DSDB_METADATA_SCHEMA_SEQ_NUM, value, true);
     171             :         }
     172        2699 :         return ret;
     173             : }
     174             : 
     175             : 
     176             : 
     177             : /*
     178             :  * Open sam.ldb.d/metadata.tdb.
     179             :  */
     180      179859 : static int partition_metadata_open(struct ldb_module *module, bool create)
     181             : {
     182      179859 :         struct ldb_context *ldb = ldb_module_get_ctx(module);
     183        6039 :         TALLOC_CTX *tmp_ctx;
     184        6039 :         struct partition_private_data *data;
     185        6039 :         struct loadparm_context *lp_ctx;
     186        6039 :         char *filename, *dirname;
     187        6039 :         int open_flags, tdb_flags, ldb_flags;
     188        6039 :         struct stat statbuf;
     189             : 
     190      179859 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     191             :                                      struct partition_private_data);
     192      179859 :         if (!data || !data->metadata) {
     193           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     194             :                                         "partition_metadata: metadata not initialized");
     195             :         }
     196             : 
     197      179859 :         tmp_ctx = talloc_new(NULL);
     198      179859 :         if (tmp_ctx == NULL) {
     199           0 :                 return ldb_module_oom(module);
     200             :         }
     201             : 
     202      179859 :         filename = ldb_relative_path(ldb,
     203             :                                      tmp_ctx,
     204             :                                      "sam.ldb.d/metadata.tdb");
     205             : 
     206      179859 :         if (!filename) {
     207           0 :                 talloc_free(tmp_ctx);
     208           0 :                 return ldb_oom(ldb);
     209             :         }
     210             : 
     211      179859 :         open_flags = O_RDWR;
     212      179859 :         if (create) {
     213         220 :                 open_flags |= O_CREAT;
     214             : 
     215             :                 /* While provisioning, sam.ldb.d directory may not exist,
     216             :                  * so create it. Ignore errors, if it already exists. */
     217         220 :                 dirname = ldb_relative_path(ldb,
     218             :                                             tmp_ctx,
     219             :                                             "sam.ldb.d");
     220         220 :                 if (!dirname) {
     221           0 :                         talloc_free(tmp_ctx);
     222           0 :                         return ldb_oom(ldb);
     223             :                 }
     224             : 
     225         220 :                 mkdir(dirname, 0700);
     226         220 :                 talloc_free(dirname);
     227             :         } else {
     228      179639 :                 if (stat(filename, &statbuf) != 0) {
     229         220 :                         talloc_free(tmp_ctx);
     230         220 :                         return LDB_ERR_OPERATIONS_ERROR;
     231             :                 }
     232             :         }
     233             : 
     234      179639 :         lp_ctx = talloc_get_type_abort(ldb_get_opaque(ldb, "loadparm"),
     235             :                                        struct loadparm_context);
     236             : 
     237      179639 :         tdb_flags = lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT|TDB_SEQNUM);
     238             : 
     239      179639 :         ldb_flags = ldb_module_flags(ldb);
     240             : 
     241      179639 :         if (ldb_flags & LDB_FLG_NOSYNC) {
     242      178946 :                 tdb_flags |= TDB_NOSYNC;
     243             :         }
     244             : 
     245      359278 :         data->metadata->db = tdb_wrap_open(
     246      179639 :                 data->metadata, filename, 10,
     247             :                 tdb_flags, open_flags, 0660);
     248      179639 :         if (data->metadata->db == NULL) {
     249           0 :                 talloc_free(tmp_ctx);
     250           0 :                 if (create) {
     251           0 :                         ldb_asprintf_errstring(ldb, "partition_metadata: Unable to create %s: %s",
     252           0 :                                                filename, strerror(errno));
     253             :                 } else {
     254           0 :                         ldb_asprintf_errstring(ldb, "partition_metadata: Unable to open %s: %s",
     255           0 :                                                filename, strerror(errno));
     256             :                 }
     257           0 :                 if (errno == EACCES || errno == EPERM) {
     258           0 :                         return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
     259             :                 }
     260           0 :                 return LDB_ERR_OPERATIONS_ERROR;
     261             :         }
     262             : 
     263      179639 :         talloc_free(tmp_ctx);
     264      179639 :         return LDB_SUCCESS;
     265             : }
     266             : 
     267             : 
     268             : /*
     269             :  * Set the sequence number calculated from older logic (sum of primary sequence
     270             :  * numbers for each partition) as LDB_METADATA_SEQ_NUM key.
     271             :  */
     272         213 : static int partition_metadata_set_sequence_number(struct ldb_module *module)
     273             : {
     274          29 :         int ret;
     275          29 :         uint64_t seq_number;
     276             : 
     277         213 :         ret = partition_sequence_number_from_partitions(module, &seq_number);
     278         213 :         if (ret != LDB_SUCCESS) {
     279           0 :                 return ret;
     280             :         }
     281             : 
     282         213 :         return partition_metadata_set_uint64(module, LDB_METADATA_SEQ_NUM, seq_number, true);
     283             : }
     284             : 
     285             : 
     286             : /*
     287             :  * Initialize metadata. Load metadata.tdb.
     288             :  * If missing, create it and fill in sequence number
     289             :  */
     290      181894 : int partition_metadata_init(struct ldb_module *module)
     291             : {
     292        6222 :         struct partition_private_data *data;
     293        6222 :         int ret;
     294             : 
     295      181894 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     296             :                                      struct partition_private_data);
     297             : 
     298      181894 :         if (data->metadata != NULL && data->metadata->db != NULL) {
     299        2037 :                 return LDB_SUCCESS;
     300             :         }
     301             : 
     302      179639 :         data->metadata = talloc_zero(data, struct partition_metadata);
     303      179639 :         if (data->metadata == NULL) {
     304           0 :                 return ldb_module_oom(module);
     305             :         }
     306             : 
     307      179639 :         ret = partition_metadata_open(module, false);
     308      179639 :         if (ret == LDB_SUCCESS) {
     309             :                 /* Great, we got the DB open */
     310      173450 :                 return LDB_SUCCESS;
     311             :         }
     312             : 
     313             :         /* metadata.tdb does not exist, create it */
     314         220 :         DEBUG(2, ("partition_metadata: Migrating partition metadata: "
     315             :                   "open of metadata.tdb gave: %s\n",
     316             :                   ldb_errstring(ldb_module_get_ctx(module))));
     317         220 :         ret = partition_metadata_open(module, true);
     318         220 :         if (ret != LDB_SUCCESS) {
     319           0 :                 ldb_asprintf_errstring(ldb_module_get_ctx(module),
     320             :                                        "partition_metadata: "
     321             :                                        "Migrating partition metadata: "
     322             :                                        "create of metadata.tdb gave: %s\n",
     323             :                                        ldb_errstring(ldb_module_get_ctx(module)));
     324           0 :                 TALLOC_FREE(data->metadata);
     325           0 :                 return ret;
     326             :         }
     327             : 
     328         185 :         return ret;
     329             : }
     330             : 
     331             : 
     332             : /*
     333             :  * Read the sequence number, default to 0 if LDB_METADATA_SEQ_NUM key is missing
     334             :  */
     335       22881 : int partition_metadata_sequence_number(struct ldb_module *module, uint64_t *value)
     336             : {
     337             : 
     338             :         /* We have to lock all the databases as otherwise we can
     339             :          * return a sequence number that is higher than the DB values
     340             :          * that we can see, as those transactions close after the
     341             :          * metadata.tdb transaction closes */
     342       22881 :         int ret = partition_read_lock(module);
     343       22881 :         if (ret != LDB_SUCCESS) {
     344           0 :                 return ret;
     345             :         }
     346             : 
     347             :         /*
     348             :          * This means we will give a 0 until the first write
     349             :          * transaction, which is actually pretty reasonable.
     350             :          *
     351             :          * All modern databases will have the metadata.tdb from
     352             :          * the time of the first transaction in provision anyway.
     353             :          */
     354       22881 :         ret = partition_metadata_get_uint64(module,
     355             :                                             LDB_METADATA_SEQ_NUM,
     356             :                                             value,
     357             :                                             0);
     358       22881 :         if (ret == LDB_SUCCESS) {
     359       22881 :                 ret = partition_read_unlock(module);
     360             :         } else {
     361             :                 /* Don't overwrite the error code */
     362           0 :                 partition_read_unlock(module);
     363             :         }
     364       22855 :         return ret;
     365             : 
     366             : }
     367             : 
     368             : 
     369             : /*
     370             :  * Increment the sequence number, returning the new sequence number
     371             :  */
     372     1247251 : int partition_metadata_sequence_number_increment(struct ldb_module *module, uint64_t *value)
     373             : {
     374       95443 :         struct partition_private_data *data;
     375       95443 :         int ret;
     376             : 
     377     1247251 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     378             :                                     struct partition_private_data);
     379     1247251 :         if (!data || !data->metadata) {
     380           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     381             :                                         "partition_metadata: metadata not initialized");
     382             :         }
     383             : 
     384     1247251 :         if (data->metadata->in_transaction == 0) {
     385           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     386             :                                         "partition_metadata: increment sequence number without transaction");
     387             :         }
     388             : 
     389     1247251 :         ret = partition_metadata_get_uint64(module, LDB_METADATA_SEQ_NUM, value, 0);
     390     1247251 :         if (ret != LDB_SUCCESS) {
     391           0 :                 return ret;
     392             :         }
     393             : 
     394     1247251 :         if (*value == 0) {
     395             :                 /*
     396             :                  * We are in a transaction now, so we can get the
     397             :                  * sequence number from the partitions.
     398             :                  */
     399         213 :                 ret = partition_metadata_set_sequence_number(module);
     400         213 :                 if (ret != LDB_SUCCESS) {
     401           0 :                         return ret;
     402             :                 }
     403             : 
     404         213 :                 ret = partition_metadata_get_uint64(module,
     405             :                                                     LDB_METADATA_SEQ_NUM,
     406             :                                                     value, 0);
     407         213 :                 if (ret != LDB_SUCCESS) {
     408           0 :                         return ret;
     409             :                 }
     410             :         }
     411             : 
     412     1247251 :         (*value)++;
     413     1247251 :         ret = partition_metadata_set_uint64(module, LDB_METADATA_SEQ_NUM, *value, false);
     414     1247251 :         return ret;
     415             : }
     416             : /*
     417             :   lock the database for read - use by partition_lock_read
     418             : */
     419    18743100 : int partition_metadata_read_lock(struct ldb_module *module)
     420             : {
     421     1120524 :         struct partition_private_data *data
     422    18743100 :                 = talloc_get_type_abort(ldb_module_get_private(module),
     423             :                                         struct partition_private_data);
     424    18743100 :         struct tdb_context *tdb = NULL;
     425    18743100 :         int tdb_ret = 0;
     426     1120524 :         int ret;
     427             : 
     428    18743100 :         if (!data || !data->metadata || !data->metadata->db) {
     429           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     430             :                                         "partition_metadata: metadata not initialized");
     431             :         }
     432    18743100 :         tdb = data->metadata->db->tdb;
     433             : 
     434    18743100 :         if (tdb_transaction_active(tdb) == false &&
     435    11856072 :             data->metadata->read_lock_count == 0) {
     436     9769515 :                 tdb_ret = tdb_lockall_read(tdb);
     437             :         }
     438    18029115 :         if (tdb_ret == 0) {
     439    18743100 :                 data->metadata->read_lock_count++;
     440    18743100 :                 return LDB_SUCCESS;
     441             :         } else {
     442             :                 /* Sadly we can't call ltdb_err_map(tdb_error(tdb)); */
     443           0 :                 ret = LDB_ERR_BUSY;
     444             :         }
     445           0 :         ldb_debug_set(ldb_module_get_ctx(module),
     446             :                       LDB_DEBUG_FATAL,
     447             :                       "Failure during partition_metadata_read_lock(): %s",
     448             :                       tdb_errorstr(tdb));
     449           0 :         return ret;
     450             : }
     451             : 
     452             : /*
     453             :   unlock the database after a partition_metadata_lock_read()
     454             : */
     455    18743100 : int partition_metadata_read_unlock(struct ldb_module *module)
     456             : {
     457     1120524 :         struct partition_private_data *data
     458    18743100 :                 = talloc_get_type_abort(ldb_module_get_private(module),
     459             :                                         struct partition_private_data);
     460    18743100 :         struct tdb_context *tdb = NULL;
     461             : 
     462    18743100 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     463             :                                      struct partition_private_data);
     464    18743100 :         if (!data || !data->metadata || !data->metadata->db) {
     465           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     466             :                                         "partition_metadata: metadata not initialized");
     467             :         }
     468    18743100 :         tdb = data->metadata->db->tdb;
     469             : 
     470    18743100 :         if (!tdb_transaction_active(tdb) &&
     471    11856072 :             data->metadata->read_lock_count == 1) {
     472     9769515 :                 tdb_unlockall_read(tdb);
     473     9769515 :                 data->metadata->read_lock_count--;
     474     9769515 :                 return 0;
     475             :         }
     476     8973585 :         data->metadata->read_lock_count--;
     477     8973585 :         return 0;
     478             : }
     479             : 
     480             : 
     481             : /*
     482             :  * Transaction start
     483             :  */
     484      348961 : int partition_metadata_start_trans(struct ldb_module *module)
     485             : {
     486        2187 :         struct partition_private_data *data;
     487        2187 :         struct tdb_context *tdb;
     488             : 
     489      348961 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     490             :                                      struct partition_private_data);
     491      348961 :         if (!data || !data->metadata || !data->metadata->db) {
     492           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     493             :                                         "partition_metadata: metadata not initialized");
     494             :         }
     495      348961 :         tdb = data->metadata->db->tdb;
     496             : 
     497      348961 :         if (tdb_transaction_start(tdb) != 0) {
     498           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     499             :                                         tdb_errorstr(tdb));
     500             :         }
     501             : 
     502      348961 :         data->metadata->in_transaction++;
     503             : 
     504      348961 :         return LDB_SUCCESS;
     505             : }
     506             : 
     507             : 
     508             : /*
     509             :  * Transaction prepare commit
     510             :  */
     511      303158 : int partition_metadata_prepare_commit(struct ldb_module *module)
     512             : {
     513        2182 :         struct partition_private_data *data;
     514        2182 :         struct tdb_context *tdb;
     515             : 
     516      303158 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     517             :                                      struct partition_private_data);
     518      303158 :         if (!data || !data->metadata || !data->metadata->db) {
     519           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     520             :                                         "partition_metadata: metadata not initialized");
     521             :         }
     522      303158 :         tdb = data->metadata->db->tdb;
     523             : 
     524      303158 :         if (data->metadata->in_transaction == 0) {
     525           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     526             :                                         "partition_metadata: not in transaction");
     527             :         }
     528             : 
     529      303158 :         if (tdb_transaction_prepare_commit(tdb) != 0) {
     530           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     531             :                                         tdb_errorstr(tdb));
     532             :         }
     533             : 
     534      300976 :         return LDB_SUCCESS;
     535             : }
     536             : 
     537             : 
     538             : /*
     539             :  * Transaction end
     540             :  */
     541      303591 : int partition_metadata_end_trans(struct ldb_module *module)
     542             : {
     543        2182 :         struct partition_private_data *data;
     544        2182 :         struct tdb_context *tdb;
     545             : 
     546      303591 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     547             :                                      struct partition_private_data);
     548      303591 :         if (!data || !data->metadata || !data->metadata->db) {
     549           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     550             :                                         "partition_metadata: metadata not initialized");
     551             :         }
     552      303591 :         tdb = data->metadata->db->tdb;
     553             : 
     554      303591 :         if (data->metadata->in_transaction == 0) {
     555           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     556             :                                         "partition_metadata: not in transaction");
     557             :         }
     558             : 
     559      303591 :         data->metadata->in_transaction--;
     560             : 
     561      303591 :         if (tdb_transaction_commit(tdb) != 0) {
     562           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     563             :                                         tdb_errorstr(tdb));
     564             :         }
     565             : 
     566      301409 :         return LDB_SUCCESS;
     567             : }
     568             : 
     569             : 
     570             : /*
     571             :  * Transaction delete
     572             :  */
     573       45368 : int partition_metadata_del_trans(struct ldb_module *module)
     574             : {
     575           4 :         struct partition_private_data *data;
     576           4 :         struct tdb_context *tdb;
     577             : 
     578       45368 :         data = talloc_get_type_abort(ldb_module_get_private(module),
     579             :                                      struct partition_private_data);
     580       45368 :         if (!data || !data->metadata || !data->metadata->db) {
     581           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     582             :                                         "partition_metadata: metadata not initialized");
     583             :         }
     584       45368 :         tdb = data->metadata->db->tdb;
     585             : 
     586       45368 :         if (data->metadata->in_transaction == 0) {
     587           0 :                 return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
     588             :                                         "partition_metadata: not in transaction");
     589             :         }
     590             : 
     591       45368 :         data->metadata->in_transaction--;
     592             : 
     593       45368 :         tdb_transaction_cancel(tdb);
     594             : 
     595       45368 :         return LDB_SUCCESS;
     596             : }

Generated by: LCOV version 1.14