author | Tero Marttila <terom@fixme.fi> |
Wed, 27 Aug 2008 21:30:32 +0300 | |
changeset 41 | 540737bf6bac |
parent 37 | f0188b445c84 |
permissions | -rw-r--r-- |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
1 |
#ifndef CACHE_OP_H |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
2 |
#define CACHE_OP_H |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
3 |
|
31 | 4 |
#include <sys/queue.h> |
5 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
6 |
// this duplicates the cache_state enum, but is indeed interpreted differently: |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
7 |
enum cache_op_state { |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
8 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
9 |
* The op is still in the state of being constructed, and it not yet valid. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
10 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
11 |
* This should not be encountered other than if the callback is called from within fn_op_start. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
12 |
*/ |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
13 |
OP_STATE_INVALID, |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
14 |
|
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
15 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
16 |
* In the process of looking up the key. The op should enter this state as soon as it is constructed. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
17 |
*/ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
18 |
OP_STATE_LOOKUP, |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
19 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
20 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
21 |
* The key was not found in the cache. You should call cache_op_begin_write next. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
22 |
*/ |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
23 |
OP_STATE_MISS, |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
24 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
25 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
26 |
* The key was found in the cache. You should call cache_op_begin_read next. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
27 |
*/ |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
28 |
OP_STATE_HIT, |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
29 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
30 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
31 |
* cache_op_begin_read has been called, but the op is not yet read for cache_op_pull. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
32 |
*/ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
33 |
OP_STATE_OPEN_READ, |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
34 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
35 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
36 |
* cache_op_begin_write has been called, but the op is not yet read for cache_op_push. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
37 |
*/ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
38 |
OP_STATE_OPEN_WRITE, |
31 | 39 |
|
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
40 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
41 |
* cache_op_begin_read has completed succesfully, and you may now call cache_op_pull. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
42 |
*/ |
33 | 43 |
OP_STATE_READ, |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
44 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
45 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
46 |
* cache_op_begin_write has completed succesfully, and you may now call cache_op_push/cache_op_done. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
47 |
*/ |
31 | 48 |
OP_STATE_WRITE, |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
49 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
50 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
51 |
* XXX: not used yet |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
52 |
*/ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
53 |
OP_STATE_ERROR, |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
54 |
}; |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
55 |
|
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
56 |
struct cache_op { |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
57 |
// reference to what cache this belongs to |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
58 |
struct cache *cache; |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
59 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
60 |
// used to store this in the cache->op_list |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
61 |
LIST_ENTRY(cache_op) node; |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
62 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
63 |
// a pointer to the key we are using |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
64 |
// XXX: object lifetime is currently broken (cache_req.key_copy of the first req atm) |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
65 |
// XXX: the key should probably be copied into this. |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
66 |
struct cache_key *key; |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
67 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
68 |
// the list of cache_req's that are using this op. |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
69 |
LIST_HEAD(cache_op_req_list_head, cache_req) req_list; |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
70 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
71 |
// our current state. |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
72 |
enum cache_op_state state; |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
73 |
}; |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
74 |
|
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
75 |
/* |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
76 |
* Used by the engine's fn_op_start implementation to initialize the basic cache op state. |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
77 |
*/ |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
78 |
int _cache_op_init(struct cache_op *op, struct cache *cache, struct cache_key *key); |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
79 |
|
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
80 |
/* |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
81 |
* Look for an existing cache_op with the given key in the given cache. Return NULL if not found, return pointer |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
82 |
* if found. |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
83 |
*/ |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
84 |
struct cache_op *cache_op_find (struct cache *cache, struct cache_key *key); |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
85 |
|
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
86 |
/* |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
87 |
* Add the given cache_req to the list of reqs using this op |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
88 |
*/ |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
89 |
int cache_op_register (struct cache_op *op, struct cache_req *req); |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
90 |
|
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
91 |
/* |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
92 |
* The given req is done and not using this op anymore. The op is closed if it was the only req left |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
93 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
94 |
* The op would normally be in the OP_STATE_READ state. |
33 | 95 |
*/ |
96 |
int cache_op_deregister (struct cache_op *op, struct cache_req *req); |
|
97 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
98 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
99 |
* Get info about the data available in this cache entry. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
100 |
* size - total size of the cache entry. 0 if unknown (not yet fully written). |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
101 |
* offset - how many bytes of the cache entry are currently stored. May be 0 |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
102 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
103 |
* size will be nonzero in the (OP_STATE_HIT | (OP_STATE_MISS -> OP_STATE_WRITE) -> ) OP_STATE_READ state. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
104 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
105 |
* This is valid in all states except OP_STATE_INVALID, OP_STATE_LOOKUP and OP_STATE_ERROR, but both values may very |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
106 |
* well be zero in many of these states. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
107 |
*/ |
33 | 108 |
int cache_op_available (struct cache_op *op, size_t *size, size_t *offset); |
109 |
||
110 |
/* |
|
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
111 |
* Prepare op for reading the data from it. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
112 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
113 |
* The op must be in the OP_SATE_HIT state, and will move ino the OP_STATE_OPEN_READ state, possibly also |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
114 |
* directly into the OP_STATE_READ state. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
115 |
*/ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
116 |
int cache_op_begin_read (struct cache_op *op); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
117 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
118 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
119 |
* Prepare op for writing data to it. If size_hint is nonzero, it is used to optimize resource preallocation. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
120 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
121 |
* The op must be in the OP_STATE_MISS state, and will move into the OP_STATE_OPEN_WRITE state, possibly also |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
122 |
* directly into the OP_STATE_WRITE state. |
31 | 123 |
*/ |
124 |
int cache_op_begin_write (struct cache_op *op, size_t size_hint); |
|
125 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
126 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
127 |
* Write some data into the cache by reading from the given fd. Size, if nonzero, tells how many bytes of data to read, |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
128 |
* otherwise, as much data as possible will be read. Size will be updated to the number of bytes actually pushed on |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
129 |
* return. This may be zero bytes (XXX: OP_STATE_PAUSE_WRITE). |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
130 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
131 |
* The op must be in the OP_STATE_WRITE state. All registered reqs will be notified, even if zero bytes were pushed. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
132 |
*/ |
31 | 133 |
int cache_op_push (struct cache_op *op, int fd, size_t *size); |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
134 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
135 |
/* |
37 | 136 |
* Read some data from the cache into the given fd. |
137 |
* |
|
138 |
* The data pulled from the cache entry should be *size bytes, starting at *offset. If the value of *size is zero, |
|
139 |
* then as much data as is available will be pulled, otherwise, pull the given number of bytes. If the cache entry |
|
140 |
* contains less bytes than requested, this is an error. Offset should be updated to point to what will be the next |
|
141 |
* unread data, and size should be updated to how many bytes were read (if it was given as zero). |
|
142 |
* |
|
143 |
* The op mustbe in the OP_STATE_READ or OP_STATE_WRITE state. |
|
144 |
*/ |
|
145 |
int cache_op_pull (struct cache_op *op, int fd, size_t *offset, size_t *size); |
|
146 |
||
147 |
/* |
|
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
148 |
* Indicate that the freshly written cache entry is now complete. This should be called after the last cache_op_push |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
149 |
* call, and no more cache_op_push calls may ensue. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
150 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
151 |
* The op must be in the OP_STATE_WRITE state, and will move into the OP_STATE_READ state (i.e. the op may still be |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
152 |
* read from). |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
153 |
*/ |
33 | 154 |
int cache_op_done (struct cache_op *op); |
31 | 155 |
|
156 |
/* |
|
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
157 |
* Used by the engines to notify of state transitions |
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
158 |
*/ |
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
159 |
|
31 | 160 |
/* |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
161 |
* cache_op_start completed, and the cache op is ready for begin_read/begin_write, based on `found`. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
162 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
163 |
* OP_STATE_LOOKUP -> (OP_STATE_HIT | OP_STATE_MISS) |
31 | 164 |
*/ |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
165 |
int _cache_op_lookup_done (struct cache_op *op, int found); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
166 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
167 |
/* |
37 | 168 |
* cache_op_begin_read completed, ad the cache op is ready for cache_op_pull |
169 |
* |
|
170 |
* OP_STATE_OPEN_READ -> OP_STATE_READ |
|
171 |
*/ |
|
172 |
int _cache_op_read_ready (struct cache_op *op); |
|
173 |
||
174 |
/* |
|
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
175 |
* cache_op_begin_write completed, and the cache op is ready for cache_op_push. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
176 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
177 |
* OP_STATE_OPEN_WRITE -> OP_STATE_WRITE |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
178 |
*/ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
179 |
int _cache_op_write_ready (struct cache_op *op); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
180 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
181 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
182 |
* There is new data available for reading. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
183 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
184 |
* OP_STATE_READ | OP_STATE_WRITE |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
185 |
*/ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
186 |
int _cache_op_data_available (struct cache_op *op); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
187 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
188 |
/* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
189 |
* cache_op_done completed, and the cache op now contains all the data that it ever will. |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
190 |
* |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
191 |
* OP_STATE_WRITE -> OP_STATE_READ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
192 |
*/ |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
193 |
int _cache_op_write_done (struct cache_op *op); |
31 | 194 |
|
30
33e464fd6773
my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff
changeset
|
195 |
#endif /* CACHE_OP_H */ |