33
|
1 |
#ifndef DBFS_TRANS_H
|
|
2 |
#define DBFS_TRANS_H
|
|
3 |
|
|
4 |
/*
|
|
5 |
* Support for single-fuse_req transactions.
|
|
6 |
*/
|
|
7 |
|
|
8 |
#include "dbfs.h"
|
|
9 |
|
|
10 |
// forward-declaration
|
|
11 |
struct dbfs_trans;
|
|
12 |
|
|
13 |
// generic callback
|
|
14 |
typedef void (*dbfs_trans_cb) (struct dbfs_trans *ctx);
|
|
15 |
|
|
16 |
/*
|
|
17 |
* Request/transaction state.
|
|
18 |
*/
|
|
19 |
struct dbfs_trans {
|
|
20 |
struct fuse_req *req;
|
|
21 |
struct evsql_trans *trans;
|
|
22 |
|
|
23 |
// called when the dbfs_trans is being free'd
|
|
24 |
dbfs_trans_cb free_fn;
|
|
25 |
|
|
26 |
// called once the transaction is ready
|
|
27 |
dbfs_trans_cb begin_fn;
|
|
28 |
|
|
29 |
// called once the transaction has been commited
|
|
30 |
dbfs_trans_cb commit_fn;
|
|
31 |
|
|
32 |
// set by trans_error to EIO if !NULL
|
|
33 |
int *err_ptr;
|
|
34 |
};
|
|
35 |
|
|
36 |
/*
|
|
37 |
* Call from commit_fn once you've set req to NULL. Also called from trans_fail.
|
|
38 |
*
|
|
39 |
* Will call free_fn if present.
|
|
40 |
*/
|
|
41 |
void dbfs_trans_free (struct dbfs_trans *ctx);
|
|
42 |
|
|
43 |
/*
|
|
44 |
* Fail the dbfs_trans, aborting any trans, erroring out any req and freeing the ctx.
|
|
45 |
*/
|
|
46 |
void dbfs_trans_fail (struct dbfs_trans *ctx, int err);
|
|
47 |
|
|
48 |
/*
|
|
49 |
* Initialize the ctx with the given req (stays the same during the lifetime), and opens the transaction.
|
|
50 |
*
|
|
51 |
* You should set the callback functions after/before calling this.
|
|
52 |
*
|
|
53 |
* begin_fn will be called once the transaction is open, if that fails, the req will be errored for you.
|
|
54 |
*
|
|
55 |
* If opening the transaction fails, this will return nonzero and not touch req, otherwise zero.
|
|
56 |
*/
|
|
57 |
int dbfs_trans_init (struct dbfs_trans *ctx, struct fuse_req *req);
|
|
58 |
|
|
59 |
/*
|
|
60 |
* Same as init, but allocates/frees-on-error the dbfs_trans for you.
|
|
61 |
*/
|
|
62 |
struct dbfs_trans *dbfs_trans_new (struct fuse_req *req);
|
|
63 |
|
|
64 |
/*
|
|
65 |
* Commit the dbfs_trans. After calling this, the ctx may or may not be valid, and commit_fn may or may not be called.
|
|
66 |
*/
|
|
67 |
void dbfs_trans_commit (struct dbfs_trans *ctx);
|
|
68 |
|
|
69 |
#endif /* DBFS_TRANS_H */
|