author | Tero Marttila <terom@fixme.fi> |
Sat, 30 Aug 2008 19:13:15 +0300 | |
changeset 49 | 10c7dce1a043 |
parent 37 | f0188b445c84 |
permissions | -rw-r--r-- |
31 | 1 |
#include <stdlib.h> |
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
|
2 |
#include <sys/queue.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 |
#include <string.h> |
31 | 4 |
#include <assert.h> |
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
|
5 |
|
31 | 6 |
#include "../cache.h" |
7 |
#include "cache.h" |
|
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
|
8 |
#include "op.h" |
31 | 9 |
#include "req.h" |
10 |
#include "engine.h" |
|
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
|
11 |
#include "../common.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
|
12 |
|
33 | 13 |
void _cache_op_free (struct cache_op *op) { |
14 |
// check we have no reqs listed |
|
15 |
assert(op->req_list.lh_first == NULL); |
|
16 |
||
17 |
// remove it from the engine op_list |
|
18 |
LIST_REMOVE(op, node); |
|
19 |
||
20 |
// tell the engine to close/free the op |
|
21 |
if (op->cache->engine->fn_op_close(op)) |
|
22 |
WARNING("fn_op_close failed"); |
|
23 |
} |
|
24 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
25 |
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
|
26 |
op->cache = cache; |
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
|
27 |
op->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
|
28 |
op->state = 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
|
29 |
|
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
|
30 |
LIST_INIT(&op->req_list); |
31 | 31 |
|
32 |
// add this to the cache's list of ops |
|
33 |
LIST_INSERT_HEAD(&cache->op_list, op, node); |
|
34 |
||
35 |
return 0; |
|
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
|
36 |
} |
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
|
37 |
|
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
|
38 |
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
|
39 |
struct cache_op *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
|
40 |
|
31 | 41 |
for (op = cache->op_list.lh_first; op != NULL; op = op->node.le_next) { |
42 |
if (op->key->length == key->length && memcmp(op->key->buf, key->buf, key->length) == 0) |
|
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
|
43 |
break; |
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
|
44 |
} |
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
|
45 |
|
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
|
46 |
return 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
|
47 |
} |
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
|
48 |
|
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
|
49 |
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
|
50 |
LIST_INSERT_HEAD(&op->req_list, req, node); |
31 | 51 |
|
52 |
return 0; |
|
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
|
53 |
} |
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 |
|
33 | 55 |
int cache_op_deregister (struct cache_op *op, struct cache_req *req) { |
56 |
// XXX: check that the req is in our list of ops? |
|
57 |
||
58 |
LIST_REMOVE(req, node); |
|
59 |
||
60 |
if (op->req_list.lh_first == NULL) { |
|
61 |
// the op is now unused |
|
62 |
_cache_op_free(op); |
|
63 |
} |
|
64 |
||
65 |
return 0; |
|
66 |
} |
|
67 |
||
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
|
68 |
static int _cache_op_notify (struct cache_op *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
|
69 |
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
|
70 |
|
31 | 71 |
for (req = op->req_list.lh_first; req != NULL; req = req->node.le_next) { |
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 |
if (cache_req_notify(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
|
73 |
goto error; |
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 |
|
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
|
76 |
return 0; |
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 |
|
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
|
78 |
error: |
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 |
return -1; |
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 |
} |
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
|
81 |
|
33 | 82 |
int cache_op_available (struct cache_op *op, size_t *size, size_t *offset) { |
83 |
return op->cache->engine->fn_op_available(op, size, offset); |
|
84 |
} |
|
85 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
86 |
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
|
87 |
assert(op->state == OP_STATE_HIT); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
88 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
89 |
op->state = OP_STATE_OPEN_READ; |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
90 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
91 |
return op->cache->engine->fn_op_begin_read(op); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
92 |
} |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
93 |
|
31 | 94 |
int cache_op_begin_write (struct cache_op *op, size_t size_hint) { |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
95 |
assert(op->state == OP_STATE_MISS); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
96 |
|
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
97 |
op->state = OP_STATE_OPEN_WRITE; |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
98 |
|
31 | 99 |
return op->cache->engine->fn_op_begin_write(op, size_hint); |
100 |
} |
|
101 |
||
102 |
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
|
103 |
assert(op->state == OP_STATE_WRITE); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
104 |
|
31 | 105 |
return op->cache->engine->fn_op_push(op, fd, size); |
106 |
} |
|
107 |
||
37 | 108 |
int cache_op_pull (struct cache_op *op, int fd, size_t *offset, size_t *size) { |
109 |
assert(op->state == OP_STATE_READ || op->state == OP_STATE_WRITE); |
|
110 |
||
111 |
return op->cache->engine->fn_op_pull(op, fd, offset, size); |
|
112 |
} |
|
113 |
||
33 | 114 |
int cache_op_done (struct cache_op *op) { |
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
115 |
assert(op->state == OP_STATE_WRITE); |
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
116 |
|
33 | 117 |
return op->cache->engine->fn_op_done(op); |
118 |
} |
|
119 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
120 |
int _cache_op_lookup_done (struct cache_op *op, int 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
|
121 |
// modify 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
|
122 |
op->state = found ? OP_STATE_HIT : OP_STATE_MISS; |
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
|
123 |
|
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
|
124 |
// notify waiting reqs |
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
|
125 |
return _cache_op_notify(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
|
126 |
} |
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
|
127 |
|
37 | 128 |
int _cache_op_read_ready (struct cache_op *op) { |
129 |
// modify state |
|
130 |
op->state = OP_STATE_READ; |
|
131 |
||
132 |
// notify waiting reqs |
|
133 |
return _cache_op_notify(op); |
|
134 |
} |
|
135 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
136 |
int _cache_op_write_ready (struct cache_op *op) { |
31 | 137 |
// modify state |
138 |
op->state = OP_STATE_WRITE; |
|
139 |
||
140 |
// notify waiting reqs |
|
141 |
return _cache_op_notify(op); |
|
142 |
} |
|
143 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
144 |
int _cache_op_data_available (struct cache_op *op) { |
31 | 145 |
// notify waiting reqs |
146 |
return _cache_op_notify(op); |
|
147 |
} |
|
148 |
||
36
b4023990811e
rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
149 |
int _cache_op_write_done (struct cache_op *op) { |
33 | 150 |
op->state = OP_STATE_READ; |
31 | 151 |
|
152 |
// notify waiting reqs |
|
153 |
return _cache_op_notify(op); |
|
154 |
} |
|
155 |