terom@33: #ifndef DBFS_TRANS_H terom@33: #define DBFS_TRANS_H terom@33: terom@33: /* terom@33: * Support for single-fuse_req transactions. terom@33: */ terom@33: terom@33: #include "dbfs.h" terom@33: terom@33: // forward-declaration terom@33: struct dbfs_trans; terom@33: terom@33: // generic callback terom@33: typedef void (*dbfs_trans_cb) (struct dbfs_trans *ctx); terom@33: terom@33: /* terom@33: * Request/transaction state. terom@33: */ terom@33: struct dbfs_trans { terom@33: struct fuse_req *req; terom@33: struct evsql_trans *trans; terom@33: terom@33: // called when the dbfs_trans is being free'd terom@33: dbfs_trans_cb free_fn; terom@33: terom@33: // called once the transaction is ready terom@33: dbfs_trans_cb begin_fn; terom@33: terom@33: // called once the transaction has been commited terom@33: dbfs_trans_cb commit_fn; terom@33: terom@33: // set by trans_error to EIO if !NULL terom@33: int *err_ptr; terom@33: }; terom@33: terom@33: /* terom@33: * Call from commit_fn once you've set req to NULL. Also called from trans_fail. terom@33: * terom@33: * Will call free_fn if present. terom@33: */ terom@33: void dbfs_trans_free (struct dbfs_trans *ctx); terom@33: terom@33: /* terom@33: * Fail the dbfs_trans, aborting any trans, erroring out any req and freeing the ctx. terom@33: */ terom@33: void dbfs_trans_fail (struct dbfs_trans *ctx, int err); terom@33: terom@33: /* terom@33: * Initialize the ctx with the given req (stays the same during the lifetime), and opens the transaction. terom@33: * terom@33: * You should set the callback functions after/before calling this. terom@33: * terom@33: * begin_fn will be called once the transaction is open, if that fails, the req will be errored for you. terom@33: * terom@33: * If opening the transaction fails, this will return nonzero and not touch req, otherwise zero. terom@33: */ terom@33: int dbfs_trans_init (struct dbfs_trans *ctx, struct fuse_req *req); terom@33: terom@33: /* terom@33: * Same as init, but allocates/frees-on-error the dbfs_trans for you. terom@33: */ terom@33: struct dbfs_trans *dbfs_trans_new (struct fuse_req *req); terom@33: terom@33: /* terom@33: * Commit the dbfs_trans. After calling this, the ctx may or may not be valid, and commit_fn may or may not be called. terom@33: */ terom@33: void dbfs_trans_commit (struct dbfs_trans *ctx); terom@33: terom@33: #endif /* DBFS_TRANS_H */