|
1 #ifndef DBFS_OP_BASE_H |
|
2 #define DBFS_OP_BASE_H |
|
3 |
|
4 #include "dbfs.h" |
|
5 |
|
6 // forward-declaration for callbacks |
|
7 struct dbfs_op; |
|
8 |
|
9 /* |
|
10 * Called by dbfs_op_free to release any resources when the op is free'd (i.e. not open anymore). |
|
11 */ |
|
12 typedef void (*dbfs_op_free_cb) (struct dbfs_op *op_base); |
|
13 |
|
14 /* |
|
15 * Called after the transaction has been opened, and before reply_open. |
|
16 * |
|
17 * You can do any at-open initialization here. |
|
18 */ |
|
19 typedef void (*dbfs_op_open_cb) (struct dbfs_op *op_base); |
|
20 |
|
21 // the base op state |
|
22 struct dbfs_op { |
|
23 struct fuse_file_info fi; |
|
24 struct fuse_req *req; |
|
25 |
|
26 struct evsql_trans *trans; |
|
27 |
|
28 // op target inode |
|
29 uint32_t ino; |
|
30 |
|
31 // open has returned and release hasn't been called yet |
|
32 int open; |
|
33 |
|
34 // callbacks |
|
35 dbfs_op_free_cb free_fn; |
|
36 dbfs_op_open_cb open_fn; |
|
37 }; |
|
38 |
|
39 /* |
|
40 * This will handle failures during requests. |
|
41 * |
|
42 * 1) if we have a trans, abort it |
|
43 * 2) fail the req (mandatory) with the given err |
|
44 * |
|
45 * If the op is open, then we don't release it, but if it's not open, then the op will be free'd completely. |
|
46 * |
|
47 */ |
|
48 void dbfs_op_fail (struct dbfs_op *op, int err); |
|
49 |
|
50 /* |
|
51 * Open the op, that is, store all the initial state, and open a new transaction. |
|
52 * |
|
53 * The op must be pre-allocated and zero-initialized. |
|
54 * |
|
55 * This will always set op->req, so op is safe for dbfs_op_fail after this. |
|
56 * |
|
57 * This does not fail the dirop, handle error replies yourself. |
|
58 * |
|
59 * Returns zero on success, err on failure. |
|
60 */ |
|
61 int dbfs_op_open (struct dbfs *ctx, struct dbfs_op *op, struct fuse_req *req, fuse_ino_t ino, struct fuse_file_info *fi, dbfs_op_free_cb free_fn, dbfs_op_open_cb ready_fn); |
|
62 |
|
63 /* |
|
64 * Should be called from open_fn to send the fuse_reply_open with fi and mark the op as open. |
|
65 * |
|
66 * If the op has failed earlier or fuse_reply_open fails, this will return nonzero. Fail the op yourself. |
|
67 */ |
|
68 int dbfs_op_open_reply (struct dbfs_op *op); |
|
69 |
|
70 /* |
|
71 * Start handling a normal op requests. |
|
72 * |
|
73 * Lookup the op for the given fi, validate params, and assign the new req. |
|
74 * |
|
75 * In case the op failed previously, this will error the req and return NULL, indicating that the req has been handled. |
|
76 */ |
|
77 struct dbfs_op *dbfs_op_req (struct fuse_req *req, fuse_ino_t ino, struct fuse_file_info *fi); |
|
78 |
|
79 /* |
|
80 * Done handling a request, adjust state accordingly. |
|
81 * |
|
82 * req *must* have been replied to. |
|
83 */ |
|
84 int dbfs_op_req_done (struct dbfs_op *op); |
|
85 |
|
86 /* |
|
87 * Handle the op release. |
|
88 * |
|
89 * This will take care of committing the transaction, sending any reply/error, closing the op and freeing it. |
|
90 */ |
|
91 void dbfs_op_release (struct fuse_req *req, fuse_ino_t, struct fuse_file_info *fi); |
|
92 |
|
93 |
|
94 #endif /* DBFS_OP_BASE_H */ |