[Sheepdog] [accord][PATCH] Move header files into $(includedir)/accord directory
Yunkai Zhang
qiushu.zyk at taobao.com
Thu Feb 2 10:32:41 CET 2012
Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com>
---
apps/queue/queue.c | 2 +-
conductor/acrdnet.c | 2 +-
conductor/acrdops.c | 2 +-
conductor/store.c | 2 +-
configure.ac | 1 +
include/Makefile.am | 6 +-
include/accord.h | 445 -----------------------------------------
include/accord/Makefile.am | 4 +
include/accord/accord.h | 445 +++++++++++++++++++++++++++++++++++++++++
include/accord/accord_proto.h | 248 +++++++++++++++++++++++
include/accord_proto.h | 248 -----------------------
include/net.h | 2 +-
lib/net.c | 2 +-
libacrd/libacrd.c | 2 +-
test/acrdbench.c | 2 +-
test/test-aio.c | 2 +-
test/test-concurrent.c | 2 +-
test/test-io.c | 2 +-
test/test-txn.c | 2 +-
test/test-watch.c | 2 +-
test/watch_files.c | 2 +-
test/watch_nodes.c | 2 +-
22 files changed, 716 insertions(+), 711 deletions(-)
delete mode 100644 include/accord.h
create mode 100644 include/accord/Makefile.am
create mode 100644 include/accord/accord.h
create mode 100644 include/accord/accord_proto.h
delete mode 100644 include/accord_proto.h
diff --git a/apps/queue/queue.c b/apps/queue/queue.c
index 7e92b25..8d5e81f 100644
--- a/apps/queue/queue.c
+++ b/apps/queue/queue.c
@@ -3,7 +3,7 @@
#include <pthread.h>
#include <sys/time.h>
-#include <accord.h>
+#include <accord/accord.h>
#include "util.h"
#include "coroutine.h"
#include "adler32.c"
diff --git a/conductor/acrdnet.c b/conductor/acrdnet.c
index 4f2c731..f095c55 100644
--- a/conductor/acrdnet.c
+++ b/conductor/acrdnet.c
@@ -19,7 +19,7 @@
#include <assert.h>
#include <errno.h>
-#include "accord_proto.h"
+#include <accord/accord_proto.h>
#include "list.h"
#include "work.h"
#include "logger.h"
diff --git a/conductor/acrdops.c b/conductor/acrdops.c
index ff1ef28..4758f6a 100644
--- a/conductor/acrdops.c
+++ b/conductor/acrdops.c
@@ -11,9 +11,9 @@
#include <stdio.h>
#include <corosync/cpg.h>
+#include <accord/accord_proto.h>
#include "store.h"
-#include "accord_proto.h"
#include "logger.h"
#include "util.h"
#include "acrd_priv.h"
diff --git a/conductor/store.c b/conductor/store.c
index 3ef80c1..84f0512 100644
--- a/conductor/store.c
+++ b/conductor/store.c
@@ -17,7 +17,7 @@
#include <errno.h>
#include <limits.h>
-#include "accord.h"
+#include <accord/accord.h>
#include "store.h"
#include "logger.h"
#include "util.h"
diff --git a/configure.ac b/configure.ac
index 0f2c634..77db467 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,7 @@ AC_CONFIG_FILES([Makefile
apps/queue/Makefile
conductor/Makefile
include/Makefile
+ include/accord/Makefile
lib/Makefile
libacrd/Makefile
libacrd/libacrd.pc
diff --git a/include/Makefile.am b/include/Makefile.am
index 150b2bc..98b5e6b 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,6 +1,6 @@
MAINTAINERCLEANFILES = Makefile.in config.h.in
-instdir = $(includedir)
-inst_HEADERS = accord.h accord_proto.h
-
+EXTRA_DIST = $(noinst_HEADERS)
noinst_HEADERS = coroutine.h event.h list.h net.h util.h work.h
+
+SUBDIRS = accord
diff --git a/include/accord.h b/include/accord.h
deleted file mode 100644
index 3fff476..0000000
--- a/include/accord.h
+++ /dev/null
@@ -1,445 +0,0 @@
-#ifndef __ACCORD_H__
-#define __ACCORD_H__
-
-#include <accord_proto.h>
-
-struct acrd_handle;
-struct acrd_tx;
-struct acrd_watch_info;
-struct acrd_aiocb;
-
-typedef void (*acrd_watch_cb_t)(struct acrd_handle *ah,
- struct acrd_watch_info *info, void *arg);
-
-
-/**
- * Callback function definition when a client joined/left.
- * Argument description is as follows :
- *
- * 'member_list' Array of connecting clients id.
- * 'member_list_entries' A size of array member_list.
- * 'nodeid' : A client id of left/joined node.
- * It is assured that the first callback of
- * join_cb from servers contains assigned nodeid from
- * Accord servers.
- * 'arg' An argument pointer which is set when acrd_init() is called.
- * return value is handler to call the other Accord APIs.
- */
-typedef void (*acrd_confchg_cb_t)(struct acrd_handle *ah,
- const uint64_t *member_list,
- size_t member_list_entries, uint64_t nodeid,
- void *arg);
-
-
-
-typedef void (*acrd_aio_cb_t)(struct acrd_handle *ah, struct acrd_aiocb *aiocb,
- void *arg);
-typedef void (*acrd_list_cb_t)(struct acrd_handle *ah, const char *path,
- void *arg);
-
-struct acrd_watch_info {
- struct acrd_handle *handle;
- const char *path; /* path the event occurs*/
- const void *data;
- unsigned int data_len;
- uint64_t offset; /* The changed file location */
- void *ctx;
- uint16_t events; /* An occured event number */
- acrd_watch_cb_t cb;
- uint32_t id;
- uint32_t mask;
-};
-
-struct acrd_aiocb {
- struct acrd_handle *handle;
- int done;
- uint32_t result;
- acrd_aio_cb_t cb;
- void *arg;
-};
-
-struct acrd_listcb {
- acrd_list_cb_t cb;
- void *arg;
-};
-
-/**
- * Create a new connection to the Accord servers
- *
- * This function is used to initialize a connection to the Accord
- * service. Each application may have several connections to the
- * Accord. This function returns a handle to uniquely identify the
- * connection. The handle is used in other function calls to identify
- * the connection to be used for communication with Accord.
- *
- * Every time other clients join to or leave from Accord, the
- * specified callback function, join_cb or leave_cb, is called.
- *
- * Returns a created handle on success, NULL on error,
- * See also : acrd_confchg_cb_t
- */
-struct acrd_handle *acrd_init(const char *hostname, int port,
- acrd_confchg_cb_t join_cb, acrd_confchg_cb_t leave_cb,
- void *arg);
-
-/**
- * Terminate a connection to the Accord servers
- *
- * This function closes a Accord handle and free up any resources.
- * Once the connection is closed, the handle may not be used again by
- * applications. No more callbacks will be called after this function
- * is called.
- *
- * Returns zero on success, -1 on error.
- */
-int acrd_close(struct acrd_handle *handle);
-
-
-/* Accord I/O API */
-
-/**
- * Write data to Accord
- *
- * This writes up to 'count' bytes from the buffer starting at 'data'.
- * The destination to save is a file 'path', 'offset' bytes.
- * This function blocks until the operation has been completed.
- *
- * Supported flags are as follows:
- *
- * ACRD_FLAG_CREATE
- * Create a new file on Accord. If a path has already exists, return
- * ACRD_ERR_EXIST.
- *
- * ACRD_FLAG_EXCL
- * Writes the file wether the file is exist or not.
- *
- * ACRD_FLAG_APPEND
- * If set, the file offset will be set to the end of the file prior to each write.
- *
- * ACRD_FLAG_SYNC
- * Writes IO is reported as completed after it has been flushed to the disks.
- * If NOT set ACRD_FLAG_SYNC, a response is returned when all servers are assured to
- * receive the write request.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_NOTFOUND if the specified
- * path does not exist but ACRD_FLAG_CREATE is not set to flags,
- * ACRD_ERR_EXIST if the specified path exists bug ACRD_FLAG_CREATE is
- * set to flags.
- *
- */
-int acrd_write(struct acrd_handle *h, const char *path, const void *data,
- uint32_t count, uint64_t offset, uint32_t flags);
-
-/**
- * Read data from Accord
- *
- * The source to read is a file 'path', 'offset' bytes.
- *
- * This function blocks until the operation has been completed.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_NOTFOUND if the specified
- * path is not found.
- */
-int acrd_read(struct acrd_handle *h, const char *path, void *data,
- uint32_t *count, uint64_t offset, uint32_t flags);
-
-/**
- * Delete the specified data from Accord
- *
- * This function blocks until the operation has been completed.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_NOTFOUND if the specified
- * path is not found.
- */
-int acrd_del(struct acrd_handle *h, const char *path, uint32_t flags);
-
-/**
- * Do a prefix search and list matching keys
- *
- * This function blocks until the operation has been completed.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_list(struct acrd_handle *h, const char *prefix, uint32_t flags,
- struct acrd_listcb *listcb);
-
-/**
- * Copy data on the Accord server
- *
- * This function blocks until the operation has been completed.
- *
- * On success, ACRD_SUCCESS is returned. If the src path is not found,
- * or the dst path does not exist but ACRD_FLAG_CREATE is not set to
- * flags, ACRD_ERR_NOTFOUND is returned. Returns ACRD_ERR_EXIST if the
- * dst path exists bug ACRD_FLAG_CREATE is set to flags
- */
-int acrd_copy(struct acrd_handle *h, const char *src, const char *dst,
- uint32_t flags);
-
-
-/* Accord asynchronous I/O API */
-
-/**
- * Create an asynchronous I/O control block
- *
- * This function creates an asynchronous I/O control block for the
- * asyncronous operation. Every AIO operations needs the aiocb
- * returned by this function. Each AIO operation is identified with
- * the aiocb. If you want to wait one of the AIO operations, call
- * acrd_aio_wait() with its aiocb.
- *
- * Returns a created aiocb on success, NULL on error.
- */
-struct acrd_aiocb *acrd_aio_setup(struct acrd_handle *h, acrd_aio_cb_t cb,
- void *arg);
-
-/**
- * Release an asynchronous I/O control block
- *
- * This function free up any resources used by the aiocb. This may
- * not be called before the AIO operation is finished. To ensure that
- * the operation is done, call acrd_aio_wait().
- */
-void acrd_aio_release(struct acrd_handle *h, struct acrd_aiocb *aiocb);
-
-/**
- * Wait for the AIO operation to be completed
- *
- * This function will wait until the specified AIO operation has
- * completed.
- */
-void acrd_aio_wait(struct acrd_handle *h, struct acrd_aiocb *aiocb);
-
-/**
- * Flush AIO operations
- *
- * This function flushes all pending AIO operations. This will block
- * until all outstanding AIO operations have been completed.
- */
-void acrd_aio_flush(struct acrd_handle *h);
-
-/**
- * Write data to Accord asynchronously
- *
- * This is the asynchronous version of acrd_write(). This call returns
- * as soon as the request has been enqueued.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- * See also : acrd_write()
- */
-int acrd_aio_write(struct acrd_handle *h, const char *path, const void *data,
- uint32_t count, uint64_t offset, uint32_t flags,
- struct acrd_aiocb *aiocb);
-
-/**
- * Read data from Accord asynchronously
- *
- * This is the asynchronous version of acrd_read(). This call returns
- * as soon as the request has been enqueued.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- * See also : acrd_read()
- */
-int acrd_aio_read(struct acrd_handle *h, const char *path, void *data,
- uint32_t *count, uint64_t offset, uint32_t flags,
- struct acrd_aiocb *aiocb);
-
-/**
- * Delete the specified data from Accord asynchronously
- *
- * This is the asynchronous version of acrd_del(). This call returns
- * as soon as the request has been enqueued.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_aio_del(struct acrd_handle *h, const char *path, uint32_t flags,
- struct acrd_aiocb *aiocb);
-
-/**
- * Do a prefix search and list matching keys asynchronously
- *
- * This is the asynchronous version of acrd_list(). This call returns
- * as soon as the request has been enqueued.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_aio_list(struct acrd_handle *h, const char *prefix, uint32_t flags,
- struct acrd_listcb *listcb, struct acrd_aiocb *aiocb);
-
-/**
- * Copy data on the Accord server asynchronously
- *
- * This is the asynchronous version of acrd_copy(). This call returns
- * as soon as the request has been enqueued.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_aio_copy(struct acrd_handle *h, const char *src, const char *dst,
- uint32_t flags, struct acrd_aiocb *aiocb);
-
-
-/* Accord transaction API */
-
-/**
- * Create a new transaction
- *
- * This function allocate transaction descriptor acrd_tx.
- * Note that acrd_tx_init() function doesn't start transaction
- * but just allocate memory for a new transaction.
- *
- * Returns a created acrd_tx on success, NULL on error.
- */
-struct acrd_tx *acrd_tx_init(struct acrd_handle *h);
-
-/**
- * Close a transaction
- *
- * This function closes a transaction and free up any resources.
- */
-void acrd_tx_close(struct acrd_tx *tx);
-
-/**
- * Add a write operation to the transaction
- *
- * This function is similar to acrd_write() but only used for a
- * transaction. If the operation fails, the transaction will be
- * aborted. This call returns as soon as the request has been added
- * to the transaction.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_tx_write(struct acrd_tx *tx, const char *path, const void *buf,
- uint32_t count, uint64_t offset, uint32_t flags);
-
-/**
- * Add a read operation to the transaction
- *
- * This function is similar to acrd_read() but only used for a
- * transaction. If the operation fails, the transaction will be
- * aborted. This call returns as soon as the request has been added
- * to the transaction.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_tx_read(struct acrd_tx *tx, const char *path, void *buf, uint32_t *count,
- uint64_t offset, uint32_t flags);
-
-/**
- * Add a delete operation to the transaction
- *
- * This function is similar to acrd_del() but only used for a
- * transaction. If the operation fails, the transaction will be
- * aborted. This call returns as soon as the request has been added
- * to the transaction.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_tx_del(struct acrd_tx *tx, const char *path, uint32_t flags);
-
-/**
- * Add a compare operation to the transaction
- *
- * This add a operation to compare data to a transaction. If the
- * content of 'path' doesn't equal to the first 'count' bytes of
- * 'buf', the transaction will be aborted. This call returns as soon
- * as the request has been added to the transaction.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_tx_cmp(struct acrd_tx *tx, const char *path, const void *buf,
- uint32_t count, uint32_t flags);
-
-/**
- * Add a server-side compare operation to the transaction
- *
- * This add a operation to compare data to a transaction. If the
- * content of 'path1' doesn't equal to the one of 'path2', the
- * transaction will be aborted. This call returns as soon as the
- * request has been added to the transaction.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_tx_scmp(struct acrd_tx *tx, const char *path1, const char *path2,
- uint32_t flags);
-
-/**
- * Add a copy operation to the transaction
- *
- * This function is similar to acrd_copy() but only used for a
- * transaction. If the operation fails, the transaction will be
- * aborted. This call returns as soon as the request has been added
- * to the transaction.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- */
-int acrd_tx_copy(struct acrd_tx *tx, const char *src, const char *dst,
- uint32_t flags);
-
-int acrd_tx_atomic_inc(struct acrd_tx *tx, const char *path, const void *buf,
- uint32_t count, uint32_t offset, uint32_t flags);
-
-/**
- * Commit a transaction
- *
- * This function commits a transaction. The maximum number of
- * operations which can be commited at once is 65535.
- *
- * If the transaction is commited, this returns ACRD_SUCCESS. If the
- * transaction is aborted, this returns the error code(abort reason).
- * Transaction related errors is as follows:
- *
- * acrd_tx_cmp() abort : ACRD_ERR_EXIST
- * acrd_tx_write() abort : ACRD_ERR_NOTFOUND/ACRD_ERR_EXIST/ACRD_ERR_STORE
- */
-int acrd_tx_commit(struct acrd_tx *tx, uint32_t flags);
-
-/**
- * Commit a transaction asynchronously
- *
- * This is the asynchronous version of acrd_tx_commit(). This function
- * returns as soon as the request has been enqueued.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
- *
- * See also : acrd_aio_setup(), acrd_tx_commit()
- */
-int acrd_tx_aio_commit(struct acrd_tx *tx, uint32_t flags,
- struct acrd_aiocb *aiocb);
-
-
-/* Accord watch API */
-
-/**
- * Start monitoring data on the Accord server
- *
- * This starts monitoring data change events. The events to be
- * monitored for 'path' are specified in the 'mask' bit-mask argument.
- * The following bits can be specified in 'mask':
- *
- * ACRD_EVENT_CREATED Data is created
- * ACRD_EVENT_DELETED Data is deleted
- * ACRD_EVENT_CHANGED Data is changed
- * ACRD_EVENT_COPIED Data is copied
- * ACRD_EVENT_ALL A bit mask of all of the above events
- *
- * If you set EVENT_PREFIX flag to the mask, you can watch multiple
- * files which start with 'path'.
- *
- * This returns acrd_watch_info on success, NULL on error.
- */
-struct acrd_watch_info *acrd_add_watch(struct acrd_handle *h, const char *path,
- uint32_t mask, acrd_watch_cb_t cb,
- void *arg);
-
-/**
- * Stop monitoring data on the Accord server
- *
- * This function removes the registered acrd_watch_info from ths Accord
- * server.
- *
- * Returns ACRD_SUCCESS on success, ACRD_ERR_NOTFOUND if the specified
- * acrd_watch_info is not registerd on the Accord server.
- */
-int acrd_rm_watch(struct acrd_handle *h, struct acrd_watch_info *bw);
-
-#endif /* __ACCORD_H__ */
diff --git a/include/accord/Makefile.am b/include/accord/Makefile.am
new file mode 100644
index 0000000..5dd921c
--- /dev/null
+++ b/include/accord/Makefile.am
@@ -0,0 +1,4 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+instdir = $(includedir)/accord
+inst_HEADERS = accord.h accord_proto.h
diff --git a/include/accord/accord.h b/include/accord/accord.h
new file mode 100644
index 0000000..41f7839
--- /dev/null
+++ b/include/accord/accord.h
@@ -0,0 +1,445 @@
+#ifndef __ACCORD_H__
+#define __ACCORD_H__
+
+#include <accord/accord_proto.h>
+
+struct acrd_handle;
+struct acrd_tx;
+struct acrd_watch_info;
+struct acrd_aiocb;
+
+typedef void (*acrd_watch_cb_t)(struct acrd_handle *ah,
+ struct acrd_watch_info *info, void *arg);
+
+
+/**
+ * Callback function definition when a client joined/left.
+ * Argument description is as follows :
+ *
+ * 'member_list' Array of connecting clients id.
+ * 'member_list_entries' A size of array member_list.
+ * 'nodeid' : A client id of left/joined node.
+ * It is assured that the first callback of
+ * join_cb from servers contains assigned nodeid from
+ * Accord servers.
+ * 'arg' An argument pointer which is set when acrd_init() is called.
+ * return value is handler to call the other Accord APIs.
+ */
+typedef void (*acrd_confchg_cb_t)(struct acrd_handle *ah,
+ const uint64_t *member_list,
+ size_t member_list_entries, uint64_t nodeid,
+ void *arg);
+
+
+
+typedef void (*acrd_aio_cb_t)(struct acrd_handle *ah, struct acrd_aiocb *aiocb,
+ void *arg);
+typedef void (*acrd_list_cb_t)(struct acrd_handle *ah, const char *path,
+ void *arg);
+
+struct acrd_watch_info {
+ struct acrd_handle *handle;
+ const char *path; /* path the event occurs*/
+ const void *data;
+ unsigned int data_len;
+ uint64_t offset; /* The changed file location */
+ void *ctx;
+ uint16_t events; /* An occured event number */
+ acrd_watch_cb_t cb;
+ uint32_t id;
+ uint32_t mask;
+};
+
+struct acrd_aiocb {
+ struct acrd_handle *handle;
+ int done;
+ uint32_t result;
+ acrd_aio_cb_t cb;
+ void *arg;
+};
+
+struct acrd_listcb {
+ acrd_list_cb_t cb;
+ void *arg;
+};
+
+/**
+ * Create a new connection to the Accord servers
+ *
+ * This function is used to initialize a connection to the Accord
+ * service. Each application may have several connections to the
+ * Accord. This function returns a handle to uniquely identify the
+ * connection. The handle is used in other function calls to identify
+ * the connection to be used for communication with Accord.
+ *
+ * Every time other clients join to or leave from Accord, the
+ * specified callback function, join_cb or leave_cb, is called.
+ *
+ * Returns a created handle on success, NULL on error,
+ * See also : acrd_confchg_cb_t
+ */
+struct acrd_handle *acrd_init(const char *hostname, int port,
+ acrd_confchg_cb_t join_cb, acrd_confchg_cb_t leave_cb,
+ void *arg);
+
+/**
+ * Terminate a connection to the Accord servers
+ *
+ * This function closes a Accord handle and free up any resources.
+ * Once the connection is closed, the handle may not be used again by
+ * applications. No more callbacks will be called after this function
+ * is called.
+ *
+ * Returns zero on success, -1 on error.
+ */
+int acrd_close(struct acrd_handle *handle);
+
+
+/* Accord I/O API */
+
+/**
+ * Write data to Accord
+ *
+ * This writes up to 'count' bytes from the buffer starting at 'data'.
+ * The destination to save is a file 'path', 'offset' bytes.
+ * This function blocks until the operation has been completed.
+ *
+ * Supported flags are as follows:
+ *
+ * ACRD_FLAG_CREATE
+ * Create a new file on Accord. If a path has already exists, return
+ * ACRD_ERR_EXIST.
+ *
+ * ACRD_FLAG_EXCL
+ * Writes the file wether the file is exist or not.
+ *
+ * ACRD_FLAG_APPEND
+ * If set, the file offset will be set to the end of the file prior to each write.
+ *
+ * ACRD_FLAG_SYNC
+ * Writes IO is reported as completed after it has been flushed to the disks.
+ * If NOT set ACRD_FLAG_SYNC, a response is returned when all servers are assured to
+ * receive the write request.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_NOTFOUND if the specified
+ * path does not exist but ACRD_FLAG_CREATE is not set to flags,
+ * ACRD_ERR_EXIST if the specified path exists bug ACRD_FLAG_CREATE is
+ * set to flags.
+ *
+ */
+int acrd_write(struct acrd_handle *h, const char *path, const void *data,
+ uint32_t count, uint64_t offset, uint32_t flags);
+
+/**
+ * Read data from Accord
+ *
+ * The source to read is a file 'path', 'offset' bytes.
+ *
+ * This function blocks until the operation has been completed.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_NOTFOUND if the specified
+ * path is not found.
+ */
+int acrd_read(struct acrd_handle *h, const char *path, void *data,
+ uint32_t *count, uint64_t offset, uint32_t flags);
+
+/**
+ * Delete the specified data from Accord
+ *
+ * This function blocks until the operation has been completed.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_NOTFOUND if the specified
+ * path is not found.
+ */
+int acrd_del(struct acrd_handle *h, const char *path, uint32_t flags);
+
+/**
+ * Do a prefix search and list matching keys
+ *
+ * This function blocks until the operation has been completed.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_list(struct acrd_handle *h, const char *prefix, uint32_t flags,
+ struct acrd_listcb *listcb);
+
+/**
+ * Copy data on the Accord server
+ *
+ * This function blocks until the operation has been completed.
+ *
+ * On success, ACRD_SUCCESS is returned. If the src path is not found,
+ * or the dst path does not exist but ACRD_FLAG_CREATE is not set to
+ * flags, ACRD_ERR_NOTFOUND is returned. Returns ACRD_ERR_EXIST if the
+ * dst path exists bug ACRD_FLAG_CREATE is set to flags
+ */
+int acrd_copy(struct acrd_handle *h, const char *src, const char *dst,
+ uint32_t flags);
+
+
+/* Accord asynchronous I/O API */
+
+/**
+ * Create an asynchronous I/O control block
+ *
+ * This function creates an asynchronous I/O control block for the
+ * asyncronous operation. Every AIO operations needs the aiocb
+ * returned by this function. Each AIO operation is identified with
+ * the aiocb. If you want to wait one of the AIO operations, call
+ * acrd_aio_wait() with its aiocb.
+ *
+ * Returns a created aiocb on success, NULL on error.
+ */
+struct acrd_aiocb *acrd_aio_setup(struct acrd_handle *h, acrd_aio_cb_t cb,
+ void *arg);
+
+/**
+ * Release an asynchronous I/O control block
+ *
+ * This function free up any resources used by the aiocb. This may
+ * not be called before the AIO operation is finished. To ensure that
+ * the operation is done, call acrd_aio_wait().
+ */
+void acrd_aio_release(struct acrd_handle *h, struct acrd_aiocb *aiocb);
+
+/**
+ * Wait for the AIO operation to be completed
+ *
+ * This function will wait until the specified AIO operation has
+ * completed.
+ */
+void acrd_aio_wait(struct acrd_handle *h, struct acrd_aiocb *aiocb);
+
+/**
+ * Flush AIO operations
+ *
+ * This function flushes all pending AIO operations. This will block
+ * until all outstanding AIO operations have been completed.
+ */
+void acrd_aio_flush(struct acrd_handle *h);
+
+/**
+ * Write data to Accord asynchronously
+ *
+ * This is the asynchronous version of acrd_write(). This call returns
+ * as soon as the request has been enqueued.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ * See also : acrd_write()
+ */
+int acrd_aio_write(struct acrd_handle *h, const char *path, const void *data,
+ uint32_t count, uint64_t offset, uint32_t flags,
+ struct acrd_aiocb *aiocb);
+
+/**
+ * Read data from Accord asynchronously
+ *
+ * This is the asynchronous version of acrd_read(). This call returns
+ * as soon as the request has been enqueued.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ * See also : acrd_read()
+ */
+int acrd_aio_read(struct acrd_handle *h, const char *path, void *data,
+ uint32_t *count, uint64_t offset, uint32_t flags,
+ struct acrd_aiocb *aiocb);
+
+/**
+ * Delete the specified data from Accord asynchronously
+ *
+ * This is the asynchronous version of acrd_del(). This call returns
+ * as soon as the request has been enqueued.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_aio_del(struct acrd_handle *h, const char *path, uint32_t flags,
+ struct acrd_aiocb *aiocb);
+
+/**
+ * Do a prefix search and list matching keys asynchronously
+ *
+ * This is the asynchronous version of acrd_list(). This call returns
+ * as soon as the request has been enqueued.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_aio_list(struct acrd_handle *h, const char *prefix, uint32_t flags,
+ struct acrd_listcb *listcb, struct acrd_aiocb *aiocb);
+
+/**
+ * Copy data on the Accord server asynchronously
+ *
+ * This is the asynchronous version of acrd_copy(). This call returns
+ * as soon as the request has been enqueued.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_aio_copy(struct acrd_handle *h, const char *src, const char *dst,
+ uint32_t flags, struct acrd_aiocb *aiocb);
+
+
+/* Accord transaction API */
+
+/**
+ * Create a new transaction
+ *
+ * This function allocate transaction descriptor acrd_tx.
+ * Note that acrd_tx_init() function doesn't start transaction
+ * but just allocate memory for a new transaction.
+ *
+ * Returns a created acrd_tx on success, NULL on error.
+ */
+struct acrd_tx *acrd_tx_init(struct acrd_handle *h);
+
+/**
+ * Close a transaction
+ *
+ * This function closes a transaction and free up any resources.
+ */
+void acrd_tx_close(struct acrd_tx *tx);
+
+/**
+ * Add a write operation to the transaction
+ *
+ * This function is similar to acrd_write() but only used for a
+ * transaction. If the operation fails, the transaction will be
+ * aborted. This call returns as soon as the request has been added
+ * to the transaction.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_tx_write(struct acrd_tx *tx, const char *path, const void *buf,
+ uint32_t count, uint64_t offset, uint32_t flags);
+
+/**
+ * Add a read operation to the transaction
+ *
+ * This function is similar to acrd_read() but only used for a
+ * transaction. If the operation fails, the transaction will be
+ * aborted. This call returns as soon as the request has been added
+ * to the transaction.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_tx_read(struct acrd_tx *tx, const char *path, void *buf, uint32_t *count,
+ uint64_t offset, uint32_t flags);
+
+/**
+ * Add a delete operation to the transaction
+ *
+ * This function is similar to acrd_del() but only used for a
+ * transaction. If the operation fails, the transaction will be
+ * aborted. This call returns as soon as the request has been added
+ * to the transaction.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_tx_del(struct acrd_tx *tx, const char *path, uint32_t flags);
+
+/**
+ * Add a compare operation to the transaction
+ *
+ * This add a operation to compare data to a transaction. If the
+ * content of 'path' doesn't equal to the first 'count' bytes of
+ * 'buf', the transaction will be aborted. This call returns as soon
+ * as the request has been added to the transaction.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_tx_cmp(struct acrd_tx *tx, const char *path, const void *buf,
+ uint32_t count, uint32_t flags);
+
+/**
+ * Add a server-side compare operation to the transaction
+ *
+ * This add a operation to compare data to a transaction. If the
+ * content of 'path1' doesn't equal to the one of 'path2', the
+ * transaction will be aborted. This call returns as soon as the
+ * request has been added to the transaction.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_tx_scmp(struct acrd_tx *tx, const char *path1, const char *path2,
+ uint32_t flags);
+
+/**
+ * Add a copy operation to the transaction
+ *
+ * This function is similar to acrd_copy() but only used for a
+ * transaction. If the operation fails, the transaction will be
+ * aborted. This call returns as soon as the request has been added
+ * to the transaction.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ */
+int acrd_tx_copy(struct acrd_tx *tx, const char *src, const char *dst,
+ uint32_t flags);
+
+int acrd_tx_atomic_inc(struct acrd_tx *tx, const char *path, const void *buf,
+ uint32_t count, uint32_t offset, uint32_t flags);
+
+/**
+ * Commit a transaction
+ *
+ * This function commits a transaction. The maximum number of
+ * operations which can be commited at once is 65535.
+ *
+ * If the transaction is commited, this returns ACRD_SUCCESS. If the
+ * transaction is aborted, this returns the error code(abort reason).
+ * Transaction related errors is as follows:
+ *
+ * acrd_tx_cmp() abort : ACRD_ERR_EXIST
+ * acrd_tx_write() abort : ACRD_ERR_NOTFOUND/ACRD_ERR_EXIST/ACRD_ERR_STORE
+ */
+int acrd_tx_commit(struct acrd_tx *tx, uint32_t flags);
+
+/**
+ * Commit a transaction asynchronously
+ *
+ * This is the asynchronous version of acrd_tx_commit(). This function
+ * returns as soon as the request has been enqueued.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_UNKNOWN on error.
+ *
+ * See also : acrd_aio_setup(), acrd_tx_commit()
+ */
+int acrd_tx_aio_commit(struct acrd_tx *tx, uint32_t flags,
+ struct acrd_aiocb *aiocb);
+
+
+/* Accord watch API */
+
+/**
+ * Start monitoring data on the Accord server
+ *
+ * This starts monitoring data change events. The events to be
+ * monitored for 'path' are specified in the 'mask' bit-mask argument.
+ * The following bits can be specified in 'mask':
+ *
+ * ACRD_EVENT_CREATED Data is created
+ * ACRD_EVENT_DELETED Data is deleted
+ * ACRD_EVENT_CHANGED Data is changed
+ * ACRD_EVENT_COPIED Data is copied
+ * ACRD_EVENT_ALL A bit mask of all of the above events
+ *
+ * If you set EVENT_PREFIX flag to the mask, you can watch multiple
+ * files which start with 'path'.
+ *
+ * This returns acrd_watch_info on success, NULL on error.
+ */
+struct acrd_watch_info *acrd_add_watch(struct acrd_handle *h, const char *path,
+ uint32_t mask, acrd_watch_cb_t cb,
+ void *arg);
+
+/**
+ * Stop monitoring data on the Accord server
+ *
+ * This function removes the registered acrd_watch_info from ths Accord
+ * server.
+ *
+ * Returns ACRD_SUCCESS on success, ACRD_ERR_NOTFOUND if the specified
+ * acrd_watch_info is not registerd on the Accord server.
+ */
+int acrd_rm_watch(struct acrd_handle *h, struct acrd_watch_info *bw);
+
+#endif /* __ACCORD_H__ */
diff --git a/include/accord/accord_proto.h b/include/accord/accord_proto.h
new file mode 100644
index 0000000..861d623
--- /dev/null
+++ b/include/accord/accord_proto.h
@@ -0,0 +1,248 @@
+#ifndef __ACCORD_PROTO_H__
+#define __ACCORD_PROTO_H__
+
+#include "stdint.h"
+#include "util.h"
+
+enum TYPE {
+ ACRD_MSG_REQUEST = 0x00,
+ ACRD_MSG_RESPONSE,
+ ACRD_MSG_NOTIFICATION
+};
+
+enum OPERATION {
+ ACRD_OP_WRITE = 0x00,
+ ACRD_OP_READ,
+ ACRD_OP_DEL,
+ ACRD_OP_TX,
+ ACRD_OP_CMP,
+ ACRD_OP_SCMP,
+ ACRD_OP_COPY,
+ ACRD_OP_ATOMIC_INC,
+ ACRD_OP_LIST,
+ ACRD_OP_ADD_WATCH,
+ ACRD_OP_RM_WATCH,
+ ACRD_OP_INVALID /* this op shouldn't be called */
+};
+
+enum RESULT {
+ ACRD_SUCCESS = 0,
+
+ /* unknown */
+ ACRD_ERR_UNKNOWN = 0x10,
+
+ /* common error */
+ ACRD_ERR_AGAIN = 0x20,
+
+ /* tcp connection error */
+ ACRD_ERR_CONN = 0x30,
+ ACRD_ERR_CONN_TIMEOUT,
+ ACRD_ERR_CONN_REFUSED,
+
+ /* msg related error */
+ ACRD_ERR_MSG = 0x40,
+ ACRD_ERR_MSG_HDR,
+
+ /* bdb related error */
+ ACRD_ERR_STORE = 0x50,
+ ACRD_ERR_EXIST,
+ ACRD_ERR_NOTFOUND,
+ ACRD_ERR_NOTEQUAL,
+};
+
+
+#define ACRD_EVENT_NONE 0x00000000
+
+#define ACRD_EVENT_CREATED 0x00000001
+#define ACRD_EVENT_DELETED 0x00000002
+#define ACRD_EVENT_CHANGED 0x00000004
+#define ACRD_EVENT_COPIED 0x00000008
+#define ACRD_EVENT_ALL 0x000000FF
+#define ACRD_EVENT_WATCH_MASK 0x000000FF
+
+#define ACRD_EVENT_JOINED 0x00000100
+#define ACRD_EVENT_LEFT 0x00000200
+#define ACRD_EVENT_CONFCHG_MASK 0x0000FF00
+
+#define ACRD_EVENT_PREFIX 0x01000000
+
+
+#define ACRD_FLAG_SYNC 0x0001 /* write IO is reported as completed,
+ * after it has been flushed to the disks. */
+#define ACRD_FLAG_CREATE 0x0002
+#define ACRD_FLAG_APPEND 0x0004
+#define ACRD_FLAG_EXCL 0x0008
+
+/**
+ * operation arguments
+ * PUT : path, data
+ * GET : path
+ * DEL : path
+ * TX : acrd_msg
+ */
+
+
+/**
+ * msg format :
+ * acrd_msg |hdr|
+ * arg1 |size|data|
+ * arg2 |size|data|
+ * arg3 |size|data|
+ *
+ * Sample : normal ops case
+ * write(fd, hdr, sizeof(acrd_msg));
+ * write(fd, arg1->size, sizeof(uint32_t));
+ * write(fd, arg1->data, sizeof(arg1->size));
+ * write(fd, arg2->size, sizeof(uint32_t));
+ * write(fd, arg2->data, sizeof(arg2->size));
+ * ...
+ * Sample2 : transaction case
+ * write(fd, hdr, sizeof(acrd_msg));
+ * write(fd, hdr1, sizeof(acrd_msg));
+ * write(fd, hdr2, sizeof(acrd_msg));
+ * write(fd, arg1->size, sizeof(uint32_t));
+ * write(fd, arg1->data, sizeof(arg1->size));
+ * write(fd, arg2->size, sizeof(uint32_t));
+ * write(fd, arg2->data, sizeof(arg2->size));
+ *
+ */
+
+struct acrd_common_hdr {
+ uint8_t proto_ver;
+ uint8_t type;
+ uint16_t rsvd;
+ uint32_t data_length; /* entire data length without hdr */
+ uint64_t offset;
+ uint32_t id;
+
+ uint32_t type_specific[3];
+
+ uint8_t data[0];
+};
+
+struct acrd_req {
+ uint8_t proto_ver;
+ uint8_t type;
+ uint16_t rsvd;
+ uint32_t data_length;
+ uint64_t offset;
+ uint32_t id;
+
+ /* request specific header */
+ uint8_t opcode;
+ uint8_t rsvd2;
+ uint16_t flags;
+ uint32_t size;
+ uint32_t rsvd3;
+
+ uint8_t data[0];
+};
+
+struct acrd_rsp {
+ uint8_t proto_ver;
+ uint8_t type;
+ uint16_t rsvd;
+ uint32_t data_length;
+ uint64_t offset;
+ uint32_t id;
+
+ /* response specific header */
+ int32_t result;
+ int64_t rsvd2;
+
+ uint8_t data[0];
+};
+
+struct acrd_ntfy {
+ uint8_t proto_ver;
+ uint8_t type;
+ uint16_t rsvd;
+ uint32_t data_length;
+ uint64_t offset;
+ uint32_t id;
+
+ /* notification specific header */
+ uint16_t events;
+ uint16_t rsvd2;
+ int64_t rsvd3;
+
+ uint8_t data[0];
+};
+
+
+struct acrd_arg {
+ uint32_t size;
+ char data[0];
+};
+
+#define for_each_arg(arg, hdr) \
+ for (arg = (struct acrd_arg *)hdr->data; \
+ (uint8_t *)arg < (hdr)->data + (hdr)->data_length; \
+ arg = (struct acrd_arg *)((uint8_t *)arg + \
+ sizeof(arg->size) + arg->size))
+
+/* Get the idx'th argument */
+static inline const struct acrd_arg *get_arg(const void *p, int idx)
+{
+ const struct acrd_common_hdr *hdr = p;
+ const struct acrd_arg *arg;
+ int i = 0;
+
+ for_each_arg(arg, hdr) {
+ if (i == idx)
+ return arg;
+ i++;
+ }
+
+ return NULL;
+}
+
+/* Add a new argument */
+static inline void *add_arg(void *p, const void *data, uint32_t data_len)
+{
+ struct acrd_common_hdr *hdr = p;
+ struct acrd_arg *arg;
+
+ hdr = realloc(hdr, sizeof(*hdr) + hdr->data_length +
+ sizeof(data_len) + data_len);
+ if (unlikely(!hdr)) {
+ fprintf(stderr, "oom\n");
+ return NULL;
+ }
+
+ arg = (struct acrd_arg *)(hdr->data + hdr->data_length);
+ arg->size = data_len;
+ memcpy(arg->data, data, data_len);
+
+ hdr->data_length += sizeof(data_len) + data_len;
+
+ return hdr;
+}
+
+/* Append data to the last argument. This doesn't add a new argument */
+static inline void *append_arg(void *p, const void *data, uint32_t data_len)
+{
+ struct acrd_common_hdr *hdr = p;
+ struct acrd_arg *arg, *last_arg = NULL;
+
+ if (hdr->data_length == 0)
+ return add_arg(p, data, data_len);
+
+ hdr = realloc(hdr, sizeof(*hdr) + hdr->data_length + data_len);
+ if (unlikely(!hdr)) {
+ fprintf(stderr, "oom\n");
+ return NULL;
+ }
+
+ for_each_arg(arg, hdr)
+ last_arg = arg;
+
+ memcpy(last_arg->data + last_arg->size, data, data_len);
+ last_arg->size += data_len;
+
+ hdr->data_length += data_len;
+
+ return hdr;
+}
+
+#endif /* __ACCORD_PROTO_H__ */
diff --git a/include/accord_proto.h b/include/accord_proto.h
deleted file mode 100644
index 861d623..0000000
--- a/include/accord_proto.h
+++ /dev/null
@@ -1,248 +0,0 @@
-#ifndef __ACCORD_PROTO_H__
-#define __ACCORD_PROTO_H__
-
-#include "stdint.h"
-#include "util.h"
-
-enum TYPE {
- ACRD_MSG_REQUEST = 0x00,
- ACRD_MSG_RESPONSE,
- ACRD_MSG_NOTIFICATION
-};
-
-enum OPERATION {
- ACRD_OP_WRITE = 0x00,
- ACRD_OP_READ,
- ACRD_OP_DEL,
- ACRD_OP_TX,
- ACRD_OP_CMP,
- ACRD_OP_SCMP,
- ACRD_OP_COPY,
- ACRD_OP_ATOMIC_INC,
- ACRD_OP_LIST,
- ACRD_OP_ADD_WATCH,
- ACRD_OP_RM_WATCH,
- ACRD_OP_INVALID /* this op shouldn't be called */
-};
-
-enum RESULT {
- ACRD_SUCCESS = 0,
-
- /* unknown */
- ACRD_ERR_UNKNOWN = 0x10,
-
- /* common error */
- ACRD_ERR_AGAIN = 0x20,
-
- /* tcp connection error */
- ACRD_ERR_CONN = 0x30,
- ACRD_ERR_CONN_TIMEOUT,
- ACRD_ERR_CONN_REFUSED,
-
- /* msg related error */
- ACRD_ERR_MSG = 0x40,
- ACRD_ERR_MSG_HDR,
-
- /* bdb related error */
- ACRD_ERR_STORE = 0x50,
- ACRD_ERR_EXIST,
- ACRD_ERR_NOTFOUND,
- ACRD_ERR_NOTEQUAL,
-};
-
-
-#define ACRD_EVENT_NONE 0x00000000
-
-#define ACRD_EVENT_CREATED 0x00000001
-#define ACRD_EVENT_DELETED 0x00000002
-#define ACRD_EVENT_CHANGED 0x00000004
-#define ACRD_EVENT_COPIED 0x00000008
-#define ACRD_EVENT_ALL 0x000000FF
-#define ACRD_EVENT_WATCH_MASK 0x000000FF
-
-#define ACRD_EVENT_JOINED 0x00000100
-#define ACRD_EVENT_LEFT 0x00000200
-#define ACRD_EVENT_CONFCHG_MASK 0x0000FF00
-
-#define ACRD_EVENT_PREFIX 0x01000000
-
-
-#define ACRD_FLAG_SYNC 0x0001 /* write IO is reported as completed,
- * after it has been flushed to the disks. */
-#define ACRD_FLAG_CREATE 0x0002
-#define ACRD_FLAG_APPEND 0x0004
-#define ACRD_FLAG_EXCL 0x0008
-
-/**
- * operation arguments
- * PUT : path, data
- * GET : path
- * DEL : path
- * TX : acrd_msg
- */
-
-
-/**
- * msg format :
- * acrd_msg |hdr|
- * arg1 |size|data|
- * arg2 |size|data|
- * arg3 |size|data|
- *
- * Sample : normal ops case
- * write(fd, hdr, sizeof(acrd_msg));
- * write(fd, arg1->size, sizeof(uint32_t));
- * write(fd, arg1->data, sizeof(arg1->size));
- * write(fd, arg2->size, sizeof(uint32_t));
- * write(fd, arg2->data, sizeof(arg2->size));
- * ...
- * Sample2 : transaction case
- * write(fd, hdr, sizeof(acrd_msg));
- * write(fd, hdr1, sizeof(acrd_msg));
- * write(fd, hdr2, sizeof(acrd_msg));
- * write(fd, arg1->size, sizeof(uint32_t));
- * write(fd, arg1->data, sizeof(arg1->size));
- * write(fd, arg2->size, sizeof(uint32_t));
- * write(fd, arg2->data, sizeof(arg2->size));
- *
- */
-
-struct acrd_common_hdr {
- uint8_t proto_ver;
- uint8_t type;
- uint16_t rsvd;
- uint32_t data_length; /* entire data length without hdr */
- uint64_t offset;
- uint32_t id;
-
- uint32_t type_specific[3];
-
- uint8_t data[0];
-};
-
-struct acrd_req {
- uint8_t proto_ver;
- uint8_t type;
- uint16_t rsvd;
- uint32_t data_length;
- uint64_t offset;
- uint32_t id;
-
- /* request specific header */
- uint8_t opcode;
- uint8_t rsvd2;
- uint16_t flags;
- uint32_t size;
- uint32_t rsvd3;
-
- uint8_t data[0];
-};
-
-struct acrd_rsp {
- uint8_t proto_ver;
- uint8_t type;
- uint16_t rsvd;
- uint32_t data_length;
- uint64_t offset;
- uint32_t id;
-
- /* response specific header */
- int32_t result;
- int64_t rsvd2;
-
- uint8_t data[0];
-};
-
-struct acrd_ntfy {
- uint8_t proto_ver;
- uint8_t type;
- uint16_t rsvd;
- uint32_t data_length;
- uint64_t offset;
- uint32_t id;
-
- /* notification specific header */
- uint16_t events;
- uint16_t rsvd2;
- int64_t rsvd3;
-
- uint8_t data[0];
-};
-
-
-struct acrd_arg {
- uint32_t size;
- char data[0];
-};
-
-#define for_each_arg(arg, hdr) \
- for (arg = (struct acrd_arg *)hdr->data; \
- (uint8_t *)arg < (hdr)->data + (hdr)->data_length; \
- arg = (struct acrd_arg *)((uint8_t *)arg + \
- sizeof(arg->size) + arg->size))
-
-/* Get the idx'th argument */
-static inline const struct acrd_arg *get_arg(const void *p, int idx)
-{
- const struct acrd_common_hdr *hdr = p;
- const struct acrd_arg *arg;
- int i = 0;
-
- for_each_arg(arg, hdr) {
- if (i == idx)
- return arg;
- i++;
- }
-
- return NULL;
-}
-
-/* Add a new argument */
-static inline void *add_arg(void *p, const void *data, uint32_t data_len)
-{
- struct acrd_common_hdr *hdr = p;
- struct acrd_arg *arg;
-
- hdr = realloc(hdr, sizeof(*hdr) + hdr->data_length +
- sizeof(data_len) + data_len);
- if (unlikely(!hdr)) {
- fprintf(stderr, "oom\n");
- return NULL;
- }
-
- arg = (struct acrd_arg *)(hdr->data + hdr->data_length);
- arg->size = data_len;
- memcpy(arg->data, data, data_len);
-
- hdr->data_length += sizeof(data_len) + data_len;
-
- return hdr;
-}
-
-/* Append data to the last argument. This doesn't add a new argument */
-static inline void *append_arg(void *p, const void *data, uint32_t data_len)
-{
- struct acrd_common_hdr *hdr = p;
- struct acrd_arg *arg, *last_arg = NULL;
-
- if (hdr->data_length == 0)
- return add_arg(p, data, data_len);
-
- hdr = realloc(hdr, sizeof(*hdr) + hdr->data_length + data_len);
- if (unlikely(!hdr)) {
- fprintf(stderr, "oom\n");
- return NULL;
- }
-
- for_each_arg(arg, hdr)
- last_arg = arg;
-
- memcpy(last_arg->data + last_arg->size, data, data_len);
- last_arg->size += data_len;
-
- hdr->data_length += data_len;
-
- return hdr;
-}
-
-#endif /* __ACCORD_PROTO_H__ */
diff --git a/include/net.h b/include/net.h
index 7bdebee..d4305e2 100644
--- a/include/net.h
+++ b/include/net.h
@@ -2,7 +2,7 @@
#define __NET_H__
#include <sys/socket.h>
-#include "accord_proto.h"
+#include <accord/accord_proto.h>
struct co_buffer {
int offset;
diff --git a/lib/net.c b/lib/net.c
index a943e18..3ff1b89 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -27,7 +27,7 @@
#include <sys/socket.h>
#include <coroutine.h>
-#include "accord_proto.h"
+#include <accord/accord_proto.h>
#include "util.h"
#include "event.h"
#include "net.h"
diff --git a/libacrd/libacrd.c b/libacrd/libacrd.c
index 4249a86..32feaf5 100644
--- a/libacrd/libacrd.c
+++ b/libacrd/libacrd.c
@@ -28,8 +28,8 @@
#include <pthread.h>
#include <assert.h>
+#include <accord/accord.h>
#include "list.h"
-#include "accord.h"
#include "util.h"
#include "net.h"
#include "event.h"
diff --git a/test/acrdbench.c b/test/acrdbench.c
index 9c7baf1..94beb99 100644
--- a/test/acrdbench.c
+++ b/test/acrdbench.c
@@ -22,7 +22,7 @@
#include <limits.h>
#include <pthread.h>
-#include <accord.h>
+#include <accord/accord.h>
#include "util.h"
#define dprintf(fmt, args...) \
diff --git a/test/test-aio.c b/test/test-aio.c
index c27ea26..56f20bd 100644
--- a/test/test-aio.c
+++ b/test/test-aio.c
@@ -12,7 +12,7 @@
#include <glib.h>
#include <string.h>
-#include "accord.h"
+#include <accord/accord.h>
#include "util.h"
#include "list.h"
diff --git a/test/test-concurrent.c b/test/test-concurrent.c
index 3c8f8fd..4f5b83c 100644
--- a/test/test-concurrent.c
+++ b/test/test-concurrent.c
@@ -13,7 +13,7 @@
#include <string.h>
#include <pthread.h>
-#include "accord.h"
+#include <accord/accord.h>
#include "util.h"
#include "coroutine.h"
diff --git a/test/test-io.c b/test/test-io.c
index a8296fa..f28cca4 100644
--- a/test/test-io.c
+++ b/test/test-io.c
@@ -12,7 +12,7 @@
#include <glib.h>
#include <string.h>
-#include "accord.h"
+#include <accord/accord.h>
#include "util.h"
#include "list.h"
diff --git a/test/test-txn.c b/test/test-txn.c
index 57e3bdd..396c95d 100644
--- a/test/test-txn.c
+++ b/test/test-txn.c
@@ -12,7 +12,7 @@
#include <glib.h>
#include <string.h>
-#include "accord.h"
+#include <accord/accord.h>
#include "util.h"
#include "list.h"
diff --git a/test/test-watch.c b/test/test-watch.c
index f92ba9b..dce66b7 100644
--- a/test/test-watch.c
+++ b/test/test-watch.c
@@ -12,7 +12,7 @@
#include <glib.h>
#include <string.h>
-#include "accord.h"
+#include <accord/accord.h>
#include "util.h"
#include "list.h"
diff --git a/test/watch_files.c b/test/watch_files.c
index 694f803..9946cb2 100644
--- a/test/watch_files.c
+++ b/test/watch_files.c
@@ -12,7 +12,7 @@
#include <stdio.h>
#include <unistd.h>
-#include "accord.h"
+#include <accord/accord.h>
static void watch_cb(struct acrd_handle *bh, struct acrd_watch_info *info, void *arg)
{
diff --git a/test/watch_nodes.c b/test/watch_nodes.c
index 9cbde57..b5eeab6 100644
--- a/test/watch_nodes.c
+++ b/test/watch_nodes.c
@@ -12,7 +12,7 @@
#include <stdio.h>
#include <unistd.h>
-#include "accord.h"
+#include <accord/accord.h>
static void join_cb(struct acrd_handle *bh, const uint64_t *memger_list,
size_t member_list_entries, uint64_t nodeid, void *arg)
--
1.7.7.6
More information about the sheepdog
mailing list