Commit a3645a19 authored by Matthieu Dorier's avatar Matthieu Dorier

added a bunch of implementations of write_op functions

parent 6ed40d97
This diff is collapsed.
......@@ -19,7 +19,7 @@ typedef enum {
WRITE_OPCODE_TRUNCATE,
WRITE_OPCODE_ZERO,
WRITE_OPCODE_OMAP_SET,
WRITE_OPCODE_RM_KEYS
WRITE_OPCODE_OMAP_RM_KEYS
} write_op_code_t;
#define WRITE_ACTION_DOWNCAST(child_obj, base_obj, child_category) \
......@@ -33,8 +33,8 @@ typedef enum {
typedef struct wr_action_BASE {
write_op_code_t type;
struct wr_action_base* prev;
struct wr_action_base* next;
struct wr_action_BASE* prev;
struct wr_action_BASE* next;
}* wr_action_base_t;
typedef struct wr_action_CREATE {
......@@ -96,7 +96,7 @@ typedef struct wr_action_RM_KEYS {
struct wr_action_BASE base;
char const* const* keys;
size_t keys_len;
}* wr_action_rm_keys_t;
}* wr_action_omap_rm_keys_t;
#endif
......@@ -6,6 +6,7 @@
#include <stdlib.h>
#include "mobject-store-config.h"
#include "utlist.h"
#include "libmobject-store.h"
#include "log.h"
#include "write-op.h"
......@@ -24,7 +25,14 @@ mobject_store_write_op_t mobject_store_create_write_op(void)
void mobject_store_release_write_op(mobject_store_write_op_t write_op)
{
if(write_op == MOBJECT_WRITE_OP_NULL) return;
// TODO free internal fields
wr_action_base_t action, tmp;
DL_FOREACH_SAFE(write_op->actions, action, tmp) {
DL_DELETE(write_op->actions, action);
free(action);
}
free(write_op);
}
......@@ -32,7 +40,14 @@ void mobject_store_write_op_create(mobject_store_write_op_t write_op,
int exclusive,
const char* category)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_create_t action = (wr_action_create_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_CREATE;
action->exclusive = exclusive;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_write(mobject_store_write_op_t write_op,
......@@ -40,14 +55,31 @@ void mobject_store_write_op_write(mobject_store_write_op_t write_op,
size_t len,
uint64_t offset)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_write_t action = (wr_action_write_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_WRITE;
action->buffer = buffer;
action->len = len;
action->offset = offset;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_write_full(mobject_store_write_op_t write_op,
const char *buffer,
size_t len)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_write_full_t action = (wr_action_write_full_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_WRITE_FULL;
action->buffer = buffer;
action->len = len;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_writesame(mobject_store_write_op_t write_op,
......@@ -56,32 +88,70 @@ void mobject_store_write_op_writesame(mobject_store_write_op_t write_op,
size_t write_len,
uint64_t offset)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_write_same_t action = (wr_action_write_same_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_WRITE_SAME;
action->buffer = buffer;
action->data_len = data_len;
action->write_len = write_len;
action->offset = offset;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_append(mobject_store_write_op_t write_op,
const char *buffer,
size_t len)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_append_t action = (wr_action_append_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_APPEND;
action->buffer = buffer;
action->len = len;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_remove(mobject_store_write_op_t write_op)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_remove_t action = (wr_action_remove_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_REMOVE;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_truncate(mobject_store_write_op_t write_op,
uint64_t offset)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_truncate_t action = (wr_action_truncate_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_TRUNCATE;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_zero(mobject_store_write_op_t write_op,
uint64_t offset,
uint64_t len)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_zero_t action = (wr_action_zero_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_ZERO;
action->offset = offset;
action->len = len;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_omap_set(mobject_store_write_op_t write_op,
......@@ -90,14 +160,32 @@ void mobject_store_write_op_omap_set(mobject_store_write_op_t write_op,
const size_t *lens,
size_t num)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_omap_set_t action = (wr_action_omap_set_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_OMAP_SET;
action->keys = keys;
action->vals = vals;
action->lens = lens;
action->num = num;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
void mobject_store_write_op_omap_rm_keys(mobject_store_write_op_t write_op,
char const* const* keys,
size_t keys_len)
{
MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "invalid mobject_store_write_op_t obect");
wr_action_omap_rm_keys_t action = (wr_action_omap_rm_keys_t)calloc(1, sizeof(*action));
action->base.type = WRITE_OPCODE_OMAP_RM_KEYS;
action->keys = keys;
action->keys_len = keys_len;
WRITE_ACTION_UPCAST(base, action);
DL_APPEND(write_op->actions, base);
}
int mobject_store_write_op_operate(mobject_store_write_op_t write_op,
......@@ -106,7 +194,17 @@ int mobject_store_write_op_operate(mobject_store_write_op_t write_op,
time_t *mtime,
int flags)
{
int r;
mobject_store_completion_t completion = MOBJECT_COMPLETION_NULL;
r = mobject_store_aio_create_completion(NULL, NULL, NULL, &completion);
MOBJECT_ASSERT(0 == r, "Could not create completion object");
r = mobject_store_aio_write_op_operate(write_op, io, completion, oid, mtime, flags);
MOBJECT_ASSERT(0 == r, "Call to mobject_store_aio_write_op_operate failed");
r = mobject_store_aio_wait_for_complete(completion);
MOBJECT_ASSERT(0 == r, "Could not wait for completion");
int ret = mobject_store_aio_get_return_value(completion);
mobject_store_aio_release(completion);
return ret;
}
int mobject_store_aio_write_op_operate(mobject_store_write_op_t write_op,
......@@ -116,5 +214,5 @@ int mobject_store_aio_write_op_operate(mobject_store_write_op_t write_op,
time_t *mtime,
int flags)
{
// TODO
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment