cache/op.c
changeset 31 12d5361e7472
parent 30 33e464fd6773
child 33 b750e8865127
--- a/cache/op.c	Thu Aug 07 20:28:06 2008 +0300
+++ b/cache/op.c	Fri Aug 08 00:15:29 2008 +0300
@@ -1,8 +1,13 @@
-
+#include <stdlib.h>
 #include <sys/queue.h>
 #include <string.h>
+#include <assert.h>
 
+#include "../cache.h"
+#include "cache.h"
 #include "op.h"
+#include "req.h"
+#include "engine.h"
 #include "../common.h"
 
 int cache_op_init(struct cache_op *op, struct cache *cache, struct cache_key *key) {
@@ -11,30 +16,34 @@
     op->state = OP_STATE_INVALID;
 
     LIST_INIT(&op->req_list);
+
+    // add this to the cache's list of ops
+    LIST_INSERT_HEAD(&cache->op_list, op, node);
+
+    return 0;
 }
 
 struct cache_op *cache_op_find (struct cache *cache, struct cache_key *key) {
     struct cache_op *op;
 
-    for (op = cache->op_list.lh_first, op != NULL; op = op->node.le_next) {
-        if (op->key->length == key->length && memcmp(op->key->buf, key->buf, key->length))
+    for (op = cache->op_list.lh_first; op != NULL; op = op->node.le_next) {
+        if (op->key->length == key->length && memcmp(op->key->buf, key->buf, key->length) == 0)
             break;
     }
 
-    if (op)
-        cache_op_incref(op);
-
     return op;
 }
 
 int cache_op_register (struct cache_op *op, struct cache_req *req) {
     LIST_INSERT_HEAD(&op->req_list, req, node);
+
+    return 0;
 }
 
 static int _cache_op_notify (struct cache_op *op) {
     struct cache_req *req;
 
-    for (req = op->req_list.lh_first, req != NULL; req = req->node.le_next) {
+    for (req = op->req_list.lh_first; req != NULL; req = req->node.le_next) {
         if (cache_req_notify(req))
             goto error;
     }
@@ -45,6 +54,14 @@
     return -1;
 }
 
+int cache_op_begin_write (struct cache_op *op, size_t size_hint) {
+    return op->cache->engine->fn_op_begin_write(op, size_hint);
+}
+
+int cache_op_push (struct cache_op *op, int fd, size_t *size) {
+    return op->cache->engine->fn_op_push(op, fd, size);
+}
+
 int cache_op_lookup_done (struct cache_op *op, int found) {
     // modify state
     op->state = found ? OP_STATE_HIT : OP_STATE_MISS;
@@ -53,3 +70,23 @@
     return _cache_op_notify(op);
 }
 
+int cache_op_write_ready (struct cache_op *op) {
+    // modify state
+    op->state = OP_STATE_WRITE;
+
+    // notify waiting reqs
+    return _cache_op_notify(op);
+}
+
+int cache_op_data_available (struct cache_op *op) {
+    // notify waiting reqs
+    return _cache_op_notify(op);
+}
+
+int cache_op_write_done (struct cache_op *op) {
+    op->state = OP_STATE_DONE;
+
+    // notify waiting reqs
+    return _cache_op_notify(op);
+}
+