]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb2.h
tdb2: don't cancel transaction when tdb_transaction_prepare_commit fails
[ccan] / ccan / tdb2 / tdb2.h
index 47ec3041b85723b49e45c8b10458ee57c1f8cacc..d78ef974b340cece0ac3306c7052edd21928deb5 100644 (file)
@@ -288,6 +288,9 @@ enum TDB_ERROR tdb_transaction_commit(struct tdb_context *tdb);
  * tdb_transaction_commit): if this succeeds then a transaction will only
  * fail if the write() or fsync() calls fail.
  *
+ * If this fails you must still call tdb_transaction_cancel() to cancel
+ * the transaction.
+ *
  * See Also:
  *     tdb_transaction_commit()
  */
@@ -606,7 +609,8 @@ enum tdb_attribute_type {
        TDB_ATTRIBUTE_LOG = 0,
        TDB_ATTRIBUTE_HASH = 1,
        TDB_ATTRIBUTE_SEED = 2,
-       TDB_ATTRIBUTE_STATS = 3
+       TDB_ATTRIBUTE_STATS = 3,
+       TDB_ATTRIBUTE_OPENHOOK = 4
 };
 
 /**
@@ -642,8 +646,8 @@ struct tdb_attribute_log {
        struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_LOG */
        void (*fn)(struct tdb_context *tdb,
                   enum tdb_log_level level,
-                  void *data,
-                  const char *message);
+                  const char *message,
+                  void *data);
        void *data;
 };
 
@@ -716,6 +720,22 @@ struct tdb_attribute_stats {
        uint64_t    lock_nonblock;
 };
 
+/**
+ * struct tdb_attribute_openhook - tdb special effects hook for open
+ *
+ * This attribute contains a function to call once we have the OPEN_LOCK
+ * for the tdb, but before we've examined its contents.  If this succeeds,
+ * the tdb will be populated if it's then zero-length.
+ *
+ * This is a hack to allow support for TDB1-style TDB_CLEAR_IF_FIRST
+ * behaviour.
+ */
+struct tdb_attribute_openhook {
+       struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_OPENHOOK */
+       enum TDB_ERROR (*fn)(int fd, void *data);
+       void *data;
+};
+
 /**
  * union tdb_attribute - tdb attributes.
  *
@@ -723,7 +743,8 @@ struct tdb_attribute_stats {
  *
  * See also:
  *     struct tdb_attribute_log, struct tdb_attribute_hash,
- *     struct tdb_attribute_seed, struct tdb_attribute_stats.
+ *     struct tdb_attribute_seed, struct tdb_attribute_stats,
+ *     struct tdb_attribute_openhook.
  */
 union tdb_attribute {
        struct tdb_attribute_base base;
@@ -731,6 +752,7 @@ union tdb_attribute {
        struct tdb_attribute_hash hash;
        struct tdb_attribute_seed seed;
        struct tdb_attribute_stats stats;
+       struct tdb_attribute_openhook openhook;
 };
 
 #ifdef  __cplusplus