From 6ed40d973af62a2ef66a859361f24140a14d1289 Mon Sep 17 00:00:00 2001 From: Matthieu Dorier Date: Tue, 17 Oct 2017 13:52:12 -0500 Subject: [PATCH] cleaned up Makefiles and added write-op implementation --- Makefile.am | 14 ++--- include/libmobject-store.h | 8 +-- src/Makefile.subdir | 7 ++- src/write-actions.h | 102 +++++++++++++++++++++++++++++++++++++ src/write-op.c | 8 +-- src/write-op.h | 4 +- 6 files changed, 117 insertions(+), 26 deletions(-) create mode 100644 src/write-actions.h diff --git a/Makefile.am b/Makefile.am index 7034f1a..6002fdd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,18 +9,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include AM_CFLAGS = AM_CXXFLAGS = $(AM_CFLAGS) -lib_LTLIBRARIES = libmobject-store.la -libmobject_store_la_SOURCES = src/libmobject-store.c \ - src/completion.c \ - src/write-op.c \ - src/completion.h \ - src/log.h \ - src/write-op.h \ - include/rados-mobject-store.h \ - include/mobject-store.h +lib_LTLIBRARIES = src/libmobject-store.la -include_HEADERS = include/mobject-store.h -libmobject_la_CPPFLAGS = -I${srcdir}/include -I${srcdir}/src +include_HEADERS = include/libmobject-store.h +src_libmobject_la_CPPFLAGS = -I${srcdir}/include -I${srcdir}/src include Make.rules diff --git a/include/libmobject-store.h b/include/libmobject-store.h index a850255..9018874 100644 --- a/include/libmobject-store.h +++ b/include/libmobject-store.h @@ -135,8 +135,6 @@ typedef struct mobject_store_write_op *mobject_store_write_op_t; #define MOBJECT_WRITE_OP_NULL ((mobject_store_write_op_t)0) -#define MOBJECT_WRITE_OP_NULL ((void*)0) - /** * @typedef mobject_store_read_op_t * @@ -159,9 +157,7 @@ typedef struct mobject_store_write_op *mobject_store_write_op_t; */ typedef struct mobject_store_read_op *mobject_store_read_op_t; -#define MOBJECT_READ_OP_NULL ((void*)0) - -#define MOBJECT_READ_OP_NULL ((void*)0) +#define MOBJECT_READ_OP_NULL ((mobject_store_read_op_t)0) /** * @typedef mobject_store_completion_t @@ -173,8 +169,6 @@ typedef struct mobject_store_completion* mobject_store_completion_t; #define MOBJECT_COMPLETION_NULL ((mobject_store_completion_t)0) -#define MOBJECT_COMPLETION_NULL ((void*)0) - /***************************************** * mobject store setup/teardown routines * *****************************************/ diff --git a/src/Makefile.subdir b/src/Makefile.subdir index 596dce7..4cb5e55 100644 --- a/src/Makefile.subdir +++ b/src/Makefile.subdir @@ -1,5 +1,4 @@ -src_libmobject_store_la_SOURCES += \ +src_libmobject_store_la_SOURCES = \ src/libmobject-store.c \ - src/completion.c src/completion.h \ - src/log.h src/write-op.c src/write-op.h \ - include/libmobject-store.h + src/completion.c \ + src/log.h src/write-op.c diff --git a/src/write-actions.h b/src/write-actions.h new file mode 100644 index 0000000..97da094 --- /dev/null +++ b/src/write-actions.h @@ -0,0 +1,102 @@ +/* + * (C) 2017 The University of Chicago + * + * See COPYRIGHT in top-level directory. + */ +#ifndef __MOBJECT_WRITE_OPCODES_H +#define __MOBJECT_WRITE_OPCODES_H + +#include "mobject-store-config.h" + +typedef enum { + WRITE_OPCODE_BASE = 0, + WRITE_OPCODE_CREATE, + WRITE_OPCODE_WRITE, + WRITE_OPCODE_WRITE_FULL, + WRITE_OPCODE_WRITE_SAME, + WRITE_OPCODE_APPEND, + WRITE_OPCODE_REMOVE, + WRITE_OPCODE_TRUNCATE, + WRITE_OPCODE_ZERO, + WRITE_OPCODE_OMAP_SET, + WRITE_OPCODE_RM_KEYS +} write_op_code_t; + +#define WRITE_ACTION_DOWNCAST(child_obj, base_obj, child_category) \ + if(WRITE_OPCODE_ ## child_category != base_obj->type) {\ + MOBJECT_LOG("Downcast error: " #base_obj " is not of type WRITE_ACTION_" #child_category);\ + }\ + struct wr_action_ ## child_category * child_obj = (struct wr_action_ ## child_category *) base_obj; + +#define WRITE_ACTION_UPCAST(base_obj, child_obj) \ + struct wr_action_BASE* base_obj = (struct wr_action_BASE*) child_obj; + +typedef struct wr_action_BASE { + write_op_code_t type; + struct wr_action_base* prev; + struct wr_action_base* next; +}* wr_action_base_t; + +typedef struct wr_action_CREATE { + struct wr_action_BASE base; + int exclusive; +}* wr_action_create_t; + +typedef struct wr_action_WRITE { + struct wr_action_BASE base; + const char* buffer; + size_t len; + uint64_t offset; +}* wr_action_write_t; + +typedef struct wr_action_WRITE_FULL { + struct wr_action_BASE base; + const char* buffer; + size_t len; +}* wr_action_write_full_t; + +typedef struct wr_action_WRITE_SAME { + struct wr_action_BASE base; + const char* buffer; + size_t data_len; + size_t write_len; + uint64_t offset; +}* wr_action_write_same_t; + +typedef struct wr_action_APPEND { + struct wr_action_BASE base; + const char* buffer; + size_t len; +}* wr_action_append_t; + +typedef struct wr_action_REMOVE { + struct wr_action_BASE base; +}* wr_action_remove_t; + +typedef struct wr_action_TRUNCATE { + struct wr_action_BASE base; + uint64_t offset; +}* wr_action_truncate_t; + +typedef struct wr_action_ZERO { + struct wr_action_BASE base; + uint64_t offset; + uint64_t len; +}* wr_action_zero_t; + +typedef struct wr_action_OMAP_SET { + struct wr_action_BASE base; + char const* const* keys; + char const* const* vals; + const size_t* lens; + size_t num; +}* wr_action_omap_set_t; + +typedef struct wr_action_RM_KEYS { + struct wr_action_BASE base; + char const* const* keys; + size_t keys_len; +}* wr_action_rm_keys_t; + +#endif + diff --git a/src/write-op.c b/src/write-op.c index 8059a85..474aaa0 100644 --- a/src/write-op.c +++ b/src/write-op.c @@ -7,6 +7,7 @@ #include #include "mobject-store-config.h" #include "libmobject-store.h" +#include "log.h" #include "write-op.h" #include "completion.h" @@ -14,8 +15,9 @@ mobject_store_write_op_t mobject_store_create_write_op(void) { mobject_store_write_op_t write_op = (mobject_store_write_op_t)calloc(1, sizeof(struct mobject_store_write_op)); - // XXX assert result is valid - // TODO: set fields + MOBJECT_ASSERT(write_op != MOBJECT_WRITE_OP_NULL, "Could not allocate write_op"); + write_op->num_actions = 0; + write_op->actions = (wr_action_base_t)0; return write_op; } @@ -30,7 +32,7 @@ void mobject_store_write_op_create(mobject_store_write_op_t write_op, int exclusive, const char* category) { - + wr_action_create_t action = (wr_action_create_t)calloc(1, sizeof(*action)); } void mobject_store_write_op_write(mobject_store_write_op_t write_op, diff --git a/src/write-op.h b/src/write-op.h index 8d9dd50..7246c7c 100644 --- a/src/write-op.h +++ b/src/write-op.h @@ -7,9 +7,11 @@ #define __MOBJECT_WRITE_OP_H #include "mobject-store-config.h" +#include "write-actions.h" struct mobject_store_write_op { - // TODO + size_t num_actions; + wr_action_base_t actions; }; #endif -- 2.26.2